npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

corefront-admin

v1.0.96

Published

Hey 👋

Downloads

4

Readme

Core Developer Documentation

Hey 👋

Welcome to the corefront-admin sdk.

Get started by exploring our Documentation.

Install the SDK

To get started, install corefront-admin in with npm:

npm i --save corefront-admin

Setup the SDK

Next, go to your developer dashboard and create your first API Key. We recommend naming it after your app. Thereby you can see which calls come from which app.

  1. Click on your profile image and go to Api Keys
  2. Click on new key and enter a name for this key
  3. Click on Create and copy the api key afterwards

In your entry point file of your node application (e.g. server.js), enter the following code:

const corefront = require('corefront-admin')
corefront.setup('YOUR API KEY HERE')

When starting the server, the sdk will check if this API key is valid and store it for your calls.

Create a subscription

When asking a merchant to pay for your app, Shopify sends the merchant to a specific URL where the merchant can confirm the charge.

Normally you would have to create a GraphQL request based on the pricing of your app. In the response from that request, you would have a confirmationUrl, where you can redirect the user.

With the corefront-admin sdk, you can get the confirmation url way easier. First, let's setup your pricing in your developer dashboard:

Create a product

  1. Click on Products in the navigation bar
  2. Create a new product and enter your details
  3. Click on Save product and copy the product id

Right now, we only support recurring subscriptions (more to come). You can decide between annual and monthly payments. We recommend offering a trial to merchants.

Create a charge

Now that you've created a product, you can redirect the user to the confirmation url from Shopify:

//The merchant will be redirected to the return url after they confirmed the charge
const returnUrl = `https://${shop}/admin/apps/${process.env.HANDLE}/welcome`

const options = {
	test: true,
}

const chargeUrl = await corefront.billing().getChargeUrl(
	shop, 
	accessToken, 
	'YOUR PRODUCT ID', 
	returnUrl, 
	options
)

ctx.redirect(chargeUrl)

The getChargeUrl() function will return a promise. You'll get a confirmation url if the request was accepted. If something went wrong, you will get an error. So make sure to wrap this function in a try-catch block or using .then().catch().

When user is logged in that isn't the admin for this shop, the function will return an error.

Note that with the options object in this call, you can decide whether or not this will be a test charge. We recommend filtering out staff members of Shopify & enabling test charges for them, so they can use your app for free.

Get the subscription status

After you've asked the merchant to accept the subscription charges, you can get the subscription status for the specified shop by calling:

const subscription = await corefront.billing().getCurrentSubscription(shop, accessToken)

If a user doesn't have an active charge, the function will return null. Otherwise you will get an object with additional information.

Subscription object

isTrial

Indicates if the merchant is still in trial.

  • Bool

name

The name of your charge (same as in your dashboard)

  • String

price

The price the user is paying

  • Number

type

"recurring"

  • String

Create special deals with discount codes

Creating special deals for specific audiences can be a huge growth factor. However it's a lot of work to build that in with GraphQL requests. We recommend offering a longer trial or a discount on your plans.

In the Corefront developer dashboard you can create discount codes for your app in a matter of seconds.

Create a discount code

  1. Click on Discount Codes
  2. Fill out the information and click on Save discount

Discount Codes are case insensitive. If you created a discount code (e.g.: START100), your merchants can enter start100, Start100 or START100 - all of them will work.

Now, create a component in your app where merchants can enter this discount code.

Apply a discount code

You can use the discount code when getting the charge url for the subscription:

const exampleDiscount = 'START100'

const options = {
	test: true,
	discountCode: exampleDiscount,
}

const chargeUrl = await corefront.billing().getChargeUrl(
	shop, 
	accessToken, 
	'YOUR PRODUCT ID', 
	returnUrl, 
	options
)

Depending on the settings for this discount code in your developer dashboard, the merchant will get a longer trial or a percentage off of your product.

If the discount code is not valid, the merchant will receive the normal product you've created in your developer dashboard.

Roadmap

This SDK will help you save time when developing your Shopify App. We would appreciate your feedback on what other features would make your life easier.

There are a couple of things we are currently working on. For example:

  • AppUsage charges
  • One time charges
  • App credits

We also want to make it easier for you to implement pricing components in your react code, so reusable react components are also high priority for us.

Got feedback or need help setting up the SDK? Write us an email: [email protected]