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

@archetypeapi/node

v1.0.77

Published

Archetype API Node

Downloads

34

Readme

Archetype Node Library

The Archetype Node library provides convenient access to the Archetype API from applications written in Node. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Archetype API.

The SDK has everything you need to build and manage API subscriptions, usage-based billing, tracking metered usage, issue volume based discounts, graduated pricing models and more.

About Archetype

Archetype is the revenue infrastruce that make API monetization quick and painless. It works by integrating powerful, reliable purchase server with cross-platform support. Our open-source framework provides a backend and a wrapper around payment processors like Stripe to save engineers months from having to build custom billing infrastructure for their APIs.

Whether you are building a new API or already have millions of customers, you can use Archetype to:

Sign up to get started.

Documentation

If looking to use our APIs directly, the API reference is here.

With Archetype, you can keep track of all your app transactions in one place — whether your customers are charged through iOS, Android, or the web. As the single source of truth for your API business, we make sure your customers' subscription status is always up to date.

Installation

Explore the docs and view the quickstart guide

You don't need this source code unless you want to modify the package. If you just want to use the package, just run:

yarn add @archetypeapi/node

or

npm install @archetypeapi/node

Requirements

Node 12.x.x+

Usage

The library needs to be configured with your account's app_id and secret_key which are available in your Archetype Dashboard.

You can set them up through your environment variables as shown below:

export ARCHETYPE_APP_ID=your_app_id
export ARCHETYPE_SECRET_KEY=your_secret_key

When you're ready to start using the SDK, initialize it as shown below:

const { Archetype } = require("@archetypeapi/node");

const ArchetypeSDK = new Archetype();

OR

You can also initialize the SDK with your app_id and secret_key directly:

const { Archetype } = require("@archetypeapi/node");

const appId = 'your_app_id'; // find in your Archetype Dashboard
const appSecret = 'your_secret_key'; // find in your Archetype Dashboard

const ArchetypeSDK = new Archetype(appId, appSecret);

The SDK can be used to create and configure billable metrics, products, token management, authorization and more. Check out the docs for more examples and use cases.

const express = require("express");
const router = express.Router();
const ArchetypeApi = require("@archetypeapi/node");

const appId = process.env.ARCHETYPE_APP_ID; // find in your Archetype Dashboard
const secretKey = process.env.ARCHETYPE_SECRET_KEY; // find in your Archetype Dashboard

const Archetype = new ArchetypeApi.Archetype(appId, appSecret);


// BASIC FUNCTIONS
// There are base functions (retrieve, all, create (new for customer), update, delete) that can be used 
// for all main objects (billableMetric, customer, endpoint, product).
// An example of each using product is below 

// retrieve specific product
const product = Archetype.product.retrieve(id: string, version: number = 1);

// log that product's id
console.log(product["product_id"]);

// list products
const products = Archetype.product.all(version: number = 1);

// log the first product's id
console.log(products[0]["product_id"]);

// create product
const product = Archetype.product.create(params: any, version: number = 1, );

// update product
const newProduct = Archetype.product.update(id: string, body: any = {}, version: number = 1, params: any);

// delete product
const deletedProduct = Archetype.product.delete(id: string, version: number = 1, params: any)

// create customer
const customer = Archetype.customer.new(customUid: string, email: string, name: string);

// OTHER AVAILABLE FUNCTIONS

// create checkout session
const checkoutSession = Archetype.customer.CreateCheckoutSession(customUid: string, productId: string, version: number);

// reset api key
const key = Archetype.customer.ResetAPIKey(customUid: string, apikey: string, version: number);

// create sandbox subscription
const subscription = Archetype.customer.CreateSandboxSubscription(customUid: string, productId: string, sandboxDuration: string, version: number);

// cancel subscription
const canceledSub = Archetype.customer.CancelSubscription(customUid: string, version: number = 1, params: any = {});

// create checkout session
const checkoutSession = Archetype.customer.CreateCheckoutSession("CUSTOM_UID", "PRODUCT_ID");

// update customer
const updatedCustomer = Archetype.customer.update("CUSTOM_UID", params); // example params: {email: "[email protected]"}

// list billable metrics
const billableMetrics = Archetype.billableMetric.all();

// retrieve billable metric
const billableMetric = Archetype.billableMetric.retrieve("BILLABLE_METRIC_ID");

// create billable metric
const billableMetric = Archetype.billableMetric.create({
                          name: "Storage",
                          description: "test",
                          unit: "GB",
                          aggregation_type: "SUM"
                        });

// Track a Metered Usage
Archetype.billableMetric.logUsage(
  "YOUR_CUSTOMER_ID",
  "BILLABLE_METRIC_ID",
  100 // amount (Float)
);

// get user token
const token = Archetype.token.get("CUSTOM_UID");

Middleware

The SDK can also be used as middleware in Express applications to authorize requests.

// Authorize an Express Request with Archetype Middelware
const express = require('express');
const { AuthMiddleware } = require('@archetypeapi/node');
const app = express();

const appId = process.env.ARCHETYPE_APP_ID; // find in your Archetype Dashboard
const secretKey = process.env.ARCHETYPE_SECRET_KEY; // find in your Archetype Dashboard

const ArchetypeAuth = AuthMiddleware(appId, appSecret);

app.get('/a', ArchetypeAuth, (req, res) => {
  res.send('Success!')
});

You can leverage the SDK to create and configure billable metrics, products, token management, authorization and more. Check out the docs for more examples and use cases.