### Install Planship Fetch SDK Source: https://github.com/planship/planship-js/blob/master/packages/fetch/README.md Install the Planship Fetch SDK using npm, yarn, or pnpm. ```sh npm install @planship/fetch # or yarn add @planship/fetch # or pnpm add @planship/fetch ``` -------------------------------- ### Install Planship SDKs Source: https://github.com/planship/planship-js/blob/master/README.md Use npm, yarn, or pnpm to install the desired Planship package. ```sh npm install @planship/axios # or yarn add @planship/fetch # or pnpm add @planship/fetch ``` -------------------------------- ### Install Planship SDK Source: https://context7.com/planship/planship-js/llms.txt Install the Planship SDK package using npm, yarn, or pnpm. Choose between `@planship/axios` or `@planship/fetch`. ```bash npm install @planship/axios # or npm install @planship/fetch ``` ```bash yarn add @planship/axios # or yarn add @planship/fetch ``` ```bash pnpm add @planship/axios # or pnpm add @planship/fetch ``` -------------------------------- ### Install Planship Axios SDK Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Install the Planship Axios SDK using npm, yarn, or pnpm. ```sh npm install @planship/axios # or yarn add @planship/axios # or pnpm add @planship/fetch ``` -------------------------------- ### GET /plans Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md Retrieve a list of plans for the current product. ```APIDOC ## GET /plans ### Description Retrieve a list of plans for the current product. ### Response #### Success Response (200) - **Plan** (array) - A list of ProductItem instances ``` -------------------------------- ### GET /plans Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Retrieve a list of plans for the current product. ```APIDOC ## GET /plans ### Description Retrieve a list of plans for the current product. ### Method GET ### Endpoint /plans ### Response #### Success Response (200) - **PlanInList[]** (array) - A list of ProductItem instances ``` -------------------------------- ### GET /product Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md Retrieve information about the current product. ```APIDOC ## GET /product ### Description Retrieve information about the current product. ### Response #### Success Response (200) - **Product** (object) - An instance of the Product class ``` -------------------------------- ### GET /product Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Retrieve information about the current product. ```APIDOC ## GET /product ### Description Retrieve information about the current product. ### Method GET ### Endpoint /product ### Response #### Success Response (200) - **Product** (object) - An instance of the Product class ``` -------------------------------- ### Get Product Information Source: https://context7.com/planship/planship-js/llms.txt Retrieve details about the current product configured in the Planship client. ```javascript const product = await planship.getProduct() console.log(product) // { // id: 'prod_abc123', // name: 'Clicker Demo', // slug: 'clicker-demo', // description: 'A demo product for testing Planship', // organizationId: 'org_xyz789' // } ``` -------------------------------- ### GET /api/product Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve information about the current product. ```APIDOC ## GET /api/product ### Description Retrieve information about the current product. ### Method GET ### Endpoint `/api/product` ### Response #### Success Response (200) - **Product** - An object containing product information. #### Response Example ```json { "product": "..." } ``` ``` -------------------------------- ### GET /getCustomer Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Get the customer with a given customer ID from Planship. ```APIDOC ## GET /getCustomer ### Description Get the customer with a given customer ID from Planship. ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID ### Response #### Success Response (200) - **CustomerInDbBase** (object) - A promise that resolves with the customer object ``` -------------------------------- ### GET /customers/{customerId} Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Get the customer with a given customer ID from Planship. ```APIDOC ## GET /customers/{customerId} ### Description Get the customer with a given customer ID from Planship. ### Method GET ### Endpoint /customers/{customerId} ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID ### Response #### Success Response (200) - **CustomerInDbBase** (object) - The customer object ``` -------------------------------- ### GET /getPlan Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Retrieve detailed information about the plan with a given slug. ```APIDOC ## GET /getPlan ### Description Retrieve detailed information about the plan with a given slug. ### Parameters #### Query Parameters - **planSlug** (string) - Required - plan slug - **entitlementsOrderBy** (string[]) - Optional - optional entitlements order by column ### Response #### Success Response (200) - **Plan** (object) - A promise that resolves with an instance of the PlanDetails class ``` -------------------------------- ### GET /api/plans Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve a list of all plans available for the current product. ```APIDOC ## GET /api/plans ### Description Retrieve a list of plans for the current product. ### Method GET ### Endpoint `/api/plans` ### Response #### Success Response (200) - **Plan[]** - A list of plan objects. #### Response Example ```json { "plans": "..." } ``` ``` -------------------------------- ### GET /plans/{planSlug} Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md Retrieve detailed information about a specific plan using its slug. ```APIDOC ## GET /plans/{planSlug} ### Description Retrieve detailed information about the plan with a given slug. ### Parameters #### Path Parameters - **planSlug** (string) - Required - plan slug #### Query Parameters - **entitlementsOrderBy** (string[]) - Optional - optional entitlements order by column ### Response #### Success Response (200) - **PlanDetails** (object) - An instance of the PlanDetails class ``` -------------------------------- ### GET /plans/{planSlug} Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Retrieve detailed information about a specific plan using its slug. ```APIDOC ## GET /plans/{planSlug} ### Description Retrieve detailed information about the plan with a given slug. ### Method GET ### Endpoint /plans/{planSlug} ### Parameters #### Path Parameters - **planSlug** (string) - Required - plan slug #### Query Parameters - **entitlementsOrderBy** (string[]) - Optional - optional entitlements order by column ### Response #### Success Response (200) - **Plan** (object) - An instance of the PlanDetails class ``` -------------------------------- ### Get Entitlements Source: https://context7.com/planship/planship-js/llms.txt Retrieves all product entitlements for a customer. Supports optional real-time updates via WebSocket. ```APIDOC ## Get Entitlements ### Description Retrieve all product entitlements for a customer with optional real-time WebSocket updates. ### Method GET ### Endpoint `/customers/{customerId}/entitlements` ### Parameters #### Path Parameters - **customerId** (string) - Required - The ID of the customer. #### Query Parameters - **subscribeToUpdates** (boolean) - Optional - If `true`, enables real-time WebSocket updates. ### Response #### Success Response (200) - Returns an object where keys are entitlement names and values are their status or limits. #### Response Example (Simple Retrieval) ```json { "api-calls": 10000, "storage-gb": 50, "advanced-analytics": true, "force-choke": { "limit": 100, "used": 15, "remaining": 85 } } ``` #### Response Example (Real-time Update Callback) (This is a conceptual example of how a callback might be used, not a direct API response) ```javascript // When entitlements update via WebSocket: (updatedEntitlements) => { console.log('Entitlements updated:', updatedEntitlements) // Handle real-time entitlement changes } ``` ``` -------------------------------- ### Get Subscription Source: https://context7.com/planship/planship-js/llms.txt Fetches detailed information for a specific subscription using customer and subscription IDs. ```javascript const subscription = await planship.getSubscription( 'cust_abc123def456', // Customer ID 'sub_xyz789' // Subscription ID ) console.log(subscription) ``` -------------------------------- ### Get Plan Details Source: https://context7.com/planship/planship-js/llms.txt Retrieve detailed information for a specific plan, including its entitlements. You can also specify custom ordering for entitlements. ```javascript const planDetails = await planship.getPlan('pro') console.log(planDetails) // { // name: 'Pro', // slug: 'pro', // description: 'Professional plan with advanced features', // order: 2, // entitlements: [ // { leverSlug: 'api-calls', value: 10000 }, // { leverSlug: 'storage-gb', value: 50 }, // { leverSlug: 'advanced-analytics', value: true } // ] // } // With custom entitlements ordering const planDetailsOrdered = await planship.getPlan('pro', ['order', 'name']) ``` -------------------------------- ### Initialize and Use PlanshipCustomer Client Source: https://github.com/planship/planship-js/blob/master/packages/fetch/README.md Demonstrates how to initialize the PlanshipCustomer client with product details and customer ID, and then use it to fetch subscriptions, change a plan, retrieve entitlements, and report usage. Ensure you have the necessary credentials and product slug. ```javascript import { PlanshipCustomer } from '@planship/fetch' const planshipCustomer = new Planship( 'clicker-demo', // Your Planship product slug 'vader@empire.gov', // Customer ID { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) // Fetch a list of subscriptions const subscriptions = await planshipCustomer.listSubscriptions() // Change the plan of the first subscription (if one exists) to a plan with the slug 'imperial' await planshipCustomer.changePlan( subscriptions?.[0].id, // ID of the first subscription 'imperial' // New plan slug ) // Retrieve customer entitlements const customerEntitlements = await planshipCustomer.getEntitlement() // Report usage for the customer await planshipCustomer.reportUsage( 'force-choke', // Metering ID 1, // Reported usage ) ``` -------------------------------- ### Instantiate PlanshipCustomer Client Source: https://github.com/planship/planship-js/blob/master/packages/axios/README.md Initialize the PlanshipCustomer client with product slug, customer ID, and authentication credentials. ```js import { PlanshipCustomer } from '@planship/axios' const planshipCustomer = new Planship( 'clicker-demo', // Your Planship product slug 'vader@empire.gov', // Customer ID { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) ``` -------------------------------- ### Initialize and Use Planship Client Source: https://github.com/planship/planship-js/blob/master/README.md Instantiate the Planship client and perform common operations like listing plans, creating subscriptions, and reporting usage. ```js import { Planship } from '@planship/axios' // or import { Planship } from '@planship/fetch' const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) // List product plans const plans = await planship.listPlans() // Create a customer with a given email, and subscribe them to a plan with the slug 'imperial' customer = await planship.createCustomer( { 'email': 'vader@empire.gov' } ).then((customer) => { planship.createSubscription( customer.id, // Customer ID 'imperial' // Plan slug ) return customer }) // Retrieve customer entitlements const customerEntitlements = await planship.getEntitlement( customer.id // Customer ID ) // Report usage for the customer await planship.reportUsage( customer.id, // Customer ID 'force-choke', // Metering ID 1 // Reported usage ) ``` -------------------------------- ### Create Customer and Subscribe to Plan Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Create a new customer with a given email and subscribe them to a specified plan. ```js // Create a customer with a given email, and subscribe them to a plan customer = await planship.createCustomer( { 'email': 'vader@empire.gov' } ).then((customer) => { planship.createSubscription( customer.id, // Customer ID 'imperial' // Plan slug ) return customer }) ``` -------------------------------- ### Instantiate PlanshipCustomer API Client Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Initialize the PlanshipCustomer client with product slug, customer ID, and authentication credentials. ```js import { PlanshipCustomer } from '@planship/axios' const planshipCustomer = new PlanshipCustomer( 'clicker-demo', // Your Planship product slug 'vader@empire.gov', // Customer ID { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) ``` -------------------------------- ### GET /levers Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md Retrieve a list of levers for the current product. ```APIDOC ## GET /levers ### Description Retrieve a list of levers for the current product. ### Parameters #### Query Parameters - **orderBy** (string[]) - Optional - optional order by column ### Response #### Success Response (200) - **LeverInList** (array) - A list of ProductItem instances ``` -------------------------------- ### Basic Planship API Operations Source: https://github.com/planship/planship-js/blob/master/packages/fetch/README.md Demonstrates listing plans, creating a customer and subscription, retrieving entitlements, and reporting usage. ```js // List product plans const plans = await planship.listPlans() // Create a customer with a given email, and subscribe them to a plan customer = await planship.createCustomer( { 'email': 'vader@empire.gov' } ).then((customer) => { planship.createSubscription( customer.id, // Customer ID 'imperial' // Plan slug ) return customer }) // Retrieve customer entitlements const customerEntitlements = await planship.getEntitlement( customer.id // Customer ID ) // Report usage for the customer await planship.reportUsage( customer.id, // Customer ID 'force-choke', // Metering ID 1 // Reported usage ) ``` -------------------------------- ### GET /levers Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Retrieve a list of levers for the current product. ```APIDOC ## GET /levers ### Description Retrieve a list of levers for the current product. ### Method GET ### Endpoint /levers ### Parameters #### Query Parameters - **orderBy** (string[]) - Optional - optional order by column ### Response #### Success Response (200) - **LeverInList[]** (array) - A list of ProductItem instances ``` -------------------------------- ### Initialize Planship Client with Custom Fetch API Source: https://github.com/planship/planship-js/blob/master/packages/fetch/README.md Configure the Planship client to use a custom Fetch API implementation by passing it in the constructor options. ```js // Client id/secret initialization const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret }, { extras: { fetchApi: myFetchApi // Custom Fetch API } } ) ``` -------------------------------- ### GET /api/levers Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve a list of levers for the current product. ```APIDOC ## GET /api/levers ### Description Retrieve a list of levers for the current product. ### Method GET ### Endpoint `/api/levers` ### Parameters #### Query Parameters - **orderBy** (string[]) - Optional - optional order by column ### Response #### Success Response (200) - **LeverInList** - A list of lever objects. #### Response Example ```json { "levers": "..." } ``` ``` -------------------------------- ### Initialize Client (Server-Side) Source: https://context7.com/planship/planship-js/llms.txt Initialize the Planship client with client credentials for server-side usage. The client automatically manages token acquisition and refresh. ```javascript import { Planship } from '@planship/axios' // or: import { Planship } from '@planship/fetch' const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) // The client automatically obtains and refreshes access tokens ``` -------------------------------- ### PlanshipCustomer Constructor Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/PlanshipCustomer.md Initializes a new PlanshipCustomer API client instance. This requires the product slug, customer ID, and authentication details. Optional planship client options can also be provided. ```APIDOC ## new PlanshipCustomer(productSlug, customerId, auth, options?) ### Description Create a PlanshipCustomer API client instance for a given product slug and a customer ID. Authentication configuration like client ID/secret or an access token promise are passed via the options parameter. ### Parameters #### Path Parameters - `productSlug` (string) - Required - product slug - `customerId` (string) - Required - customer ID - `auth` (TokenGetter | IClientCredentials) - Required - Auth credentials or access token getter - `options?` (IPlanshipOptions) - Optional - Planship client options ``` -------------------------------- ### GET /customers/{customerId} Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipBaseApi.md Retrieve details for a specific customer by their ID. ```APIDOC ## GET /customers/{customerId} ### Description Get the customer with a given customer ID from Planship. ### Method GET ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID ### Response #### Success Response (200) - **CustomerInDbBase** (object) - A promise that resolves with the customer object ``` -------------------------------- ### Create Customer Source: https://context7.com/planship/planship-js/llms.txt Registers a new customer with optional email, name, and metadata fields. ```javascript const customer = await planship.createCustomer({ email: 'vader@empire.gov', name: 'Darth Vader', alternativeId: 'user_12345', metadata: { department: 'Sith Operations', planet: 'Death Star' } }) console.log(customer) ``` -------------------------------- ### GET /api/subscriptions Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md List all subscriptions, optionally filtered by product slug. ```APIDOC ## GET /api/subscriptions ### Description List subscriptions. ### Method GET ### Endpoint `/api/subscriptions` ### Parameters #### Query Parameters - **productSlug** (string) - Optional - Planship product slug ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan[]** - A list of customer subscription objects. #### Response Example ```json { "subscriptions": "..." } ``` ``` -------------------------------- ### Planship API Client Constructor Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/Planship.md Initializes the Planship API client with product slug, authentication credentials, and optional options. ```APIDOC ## new Planship(productSlug, auth, options?) ### Description Create a Planship API client for a given product slug. Authentication configuration like client ID/secret or an access token promise are passed via the options parameter. ### Parameters #### Path Parameters - **productSlug** (string) - Required - product slug - **auth** (TokenGetter | IClientCredentials) - Required - Auth credentials or access token getter - **options?** (IPlanshipOptions) - Optional - Planship client options ``` -------------------------------- ### Create Subscription Source: https://context7.com/planship/planship-js/llms.txt Initializes a new subscription for a customer to a specific plan with optional configuration parameters. ```javascript const subscription = await planship.createSubscription( 'cust_abc123def456', // Customer ID 'imperial', // Plan slug { autoRenew: true, maxSubscribers: 10, isSubscriber: true, renewAt: new Date('2025-01-01'), metadata: { team: 'engineering' } } ) console.log(subscription) ``` -------------------------------- ### GET /subscriptions/{subscriptionId} Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Retrieve detailed information about the subscription with a given ID. ```APIDOC ## GET /subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID. ### Method GET ### Endpoint /subscriptions/{subscriptionId} ### Parameters #### Path Parameters - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan** (object) - An instance of the SubscriptionWithPlan class. ``` -------------------------------- ### Get Customer Source: https://context7.com/planship/planship-js/llms.txt Retrieves customer details using a unique customer ID. ```javascript const customer = await planship.getCustomer('cust_abc123def456') console.log(customer) ``` -------------------------------- ### POST /createCustomer Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Register a new customer with Planship. ```APIDOC ## POST /createCustomer ### Description Register a new customer with Planship. ### Parameters #### Request Body - **params** (CreateCustomerParameters) - Optional - Parameters for creating a customer ### Response #### Success Response (200) - **Customer** (object) - A promise that resolves with an instance of the Customer class ``` -------------------------------- ### List Plans Source: https://context7.com/planship/planship-js/llms.txt Retrieve a list of all available plans for the current product. ```javascript const plans = await planship.listPlans() console.log(plans) // [ // { name: 'Free', slug: 'free', description: 'Basic free tier', order: 1 }, // { name: 'Pro', slug: 'pro', description: 'Professional plan', order: 2 }, // { name: 'Imperial', slug: 'imperial', description: 'Enterprise tier', order: 3 } // ] ``` -------------------------------- ### GET /customers/{customerId}/subscriptions Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md List subscriptions for the customer with a given ID. ```APIDOC ## GET /customers/{customerId}/subscriptions ### Description List subscription the customer with a given ID. ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID #### Query Parameters - **productSlug** (string) - Optional - Planship product slug ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan** (array) - A list of CustomerSubscriptionWithPlan objects ``` -------------------------------- ### Instantiate Planship API Client (Server-Side) Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Initialize the Planship client on the server-side using client ID and secret for secure token acquisition. ```js const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) ``` -------------------------------- ### Get Subscription Details Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/interfaces/PlanshipApi.md Retrieves detailed information about a specific customer subscription. ```APIDOC ## GET /api/subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID for the customer with a given ID. ### Method GET ### Endpoint `/api/subscriptions/{subscriptionId}` ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **subscription** (CustomerSubscriptionWithPlan) - An instance of the SubscriptionWithPlan class. #### Response Example ```json { "subscription": { "plan": { "slug": "basic", "name": "Basic Plan" }, "status": "active", "autoRenew": true, "maxSubscribers": 10, "createdAt": "2023-01-01T12:00:00Z", "updatedAt": "2023-01-01T12:00:00Z" } } ``` ``` -------------------------------- ### Get Subscription Details Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/interfaces/PlanshipApi.md Retrieves detailed information about a specific customer subscription. ```APIDOC ## GET /api/subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID for the customer with a given ID. ### Method GET ### Endpoint `/api/subscriptions/{subscriptionId}` ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **subscription** (CustomerSubscriptionWithPlan) - An instance of the SubscriptionWithPlan class. #### Response Example ```json { "subscription": { "plan": { "slug": "basic", "name": "Basic Plan" }, "status": "active", "currentPeriodEnd": "2024-12-31T23:59:59Z", "autoRenew": true, "maxSubscribers": 10 } } ``` ``` -------------------------------- ### listPlans Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/PlanshipCustomer.md Retrieve a list of plans for the current product. ```APIDOC ## listPlans ### Description Retrieve a list of plans for the current product. ### Response - **Plan[]** (array) - A promise that resolves with a list of ProductItem instances ``` -------------------------------- ### POST /customers Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipBaseApi.md Register a new customer with Planship. ```APIDOC ## POST /customers ### Description Register a new customer with Planship. ### Method POST ### Parameters #### Request Body - **params** (CreateCustomerParameters) - Optional - Parameters for creating a new customer ### Response #### Success Response (200) - **Customer** (object) - A promise that resolves with an instance of the Customer class ``` -------------------------------- ### POST /customers Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipProductApi.md Register a new customer with Planship. ```APIDOC ## POST /customers ### Description Register a new customer with Planship. ### Method POST ### Endpoint /customers ### Parameters #### Request Body - **params** (CreateCustomerParameters) - Optional - Customer registration parameters ### Response #### Success Response (200) - **Customer** (object) - An instance of the Customer class ``` -------------------------------- ### GET /getLeverUsage Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Retrieve customer usage data for the metered lever with a given slug. ```APIDOC ## GET /getLeverUsage ### Description Retrieve customer usage data for the metered lever with a given slug. ### Parameters #### Path Parameters - **leverSlug** (string) - Required - lever slug ### Response #### Success Response (200) - **LeverUsage** (object) - A promise that resolves with CustomerLeverUsage object ``` -------------------------------- ### GET /api/metering/{meteringId}/usage Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/Planship.md Retrieve usage information for a specific metering ID. ```APIDOC ## GET /api/metering/{meteringId}/usage ### Description Retrieve usage information for a specific metering ID. ### Method GET ### Endpoint /api/metering/{meteringId}/usage ### Parameters #### Path Parameters - **meteringId** (string) - Required - The ID of the metering to retrieve usage for. ### Response #### Success Response (200) - **{ [key: string]: LeverUsage }** - An object where keys are strings and values are LeverUsage objects, representing the usage data. ### Response Example ```json { "usage-metric-1": { "currentUsage": 100, "limit": 200 } } ``` ``` -------------------------------- ### Initialize PlanshipCustomer for Customer-Scoped Operations Source: https://context7.com/planship/planship-js/llms.txt Instantiate the PlanshipCustomer class to perform operations scoped to a specific customer without needing to pass the customer ID repeatedly. Requires product slug, customer ID, and authentication credentials. ```javascript import { PlanshipCustomer } from '@planship/axios' const planshipCustomer = new PlanshipCustomer( 'clicker-demo', // Product slug 'cust_abc123def456', // Customer ID { clientId: '273N1SQ3GQFZ8JSFKIOK', clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' } ) // All methods automatically use the customer ID from initialization const subscriptions = await planshipCustomer.listSubscriptions() const entitlements = await planshipCustomer.getEntitlements() const subscription = await planshipCustomer.createSubscription('imperial') await planshipCustomer.reportUsage('force-choke', 1) await planshipCustomer.changeSubscriptionPlan('sub_xyz789', 'pro') const usage = await planshipCustomer.getLeverUsage('api-calls') console.log(usage) ``` -------------------------------- ### Initialize Client (Client-Side) Source: https://context7.com/planship/planship-js/llms.txt Initialize the Planship client with an access token getter function for client-side usage. This avoids exposing secrets by retrieving tokens from your server. ```javascript import { Planship } from '@planship/fetch' // Function that retrieves access token from your server async function getAccessTokenFromServer() { const response = await fetch('/api/planship-token') const data = await response.json() return data.accessToken } const planship = new Planship( 'clicker-demo', // Your Planship product slug getAccessTokenFromServer // Async function returning Planship access token ) ``` -------------------------------- ### Custom Fetch Implementation Source: https://context7.com/planship/planship-js/llms.txt Configure a custom fetch implementation for environments like SvelteKit or Node.js. ```APIDOC ## Custom Fetch Implementation Configure a custom fetch implementation for environments like SvelteKit or Node.js. ### Node.js Example ```javascript import { Planship } from '@planship/fetch' import nodeFetch from 'node-fetch' const planship = new Planship( 'clicker-demo', { clientId: '273N1SQ3GQFZ8JSFKIOK', clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' }, { extras: { fetchApi: nodeFetch // Custom Fetch API implementation } } ) ``` ### SvelteKit Example ```javascript // SvelteKit example with load function fetch export async function load({ fetch }) { const planship = new Planship( 'clicker-demo', getAccessTokenFn, // Assume getAccessTokenFn is defined elsewhere { extras: { fetchApi: fetch } } ) const plans = await planship.listPlans() return { plans } } ``` ``` -------------------------------- ### Configure Custom Fetch Implementation for Planship Source: https://context7.com/planship/planship-js/llms.txt Set up a custom fetch implementation for environments like Node.js or SvelteKit by passing the fetch API to the Planship constructor. This allows for tailored network request handling. ```javascript import { Planship } from '@planship/fetch' import nodeFetch from 'node-fetch' const planship = new Planship( 'clicker-demo', { clientId: '273N1SQ3GQFZ8JSFKIOK', clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' }, { extras: { fetchApi: nodeFetch // Custom Fetch API implementation } } ) // SvelteKit example with load function fetch export async function load({ fetch }) { const planship = new Planship( 'clicker-demo', getAccessTokenFn, { extras: { fetchApi: fetch } } ) const plans = await planship.listPlans() return { plans } } ``` -------------------------------- ### GET /api/subscriptions/{subscriptionId}/customers Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve a list of all customers belonging to a specific subscription. ```APIDOC ## GET /api/subscriptions/{subscriptionId}/customers ### Description Retrieve a list of all customers that belong to the subscription with a given ID. ### Method GET ### Endpoint `/api/subscriptions/{subscriptionId}/customers` ### Parameters #### Path Parameters - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **SubscriptionCustomer[]** - A list of subscription customer objects. #### Response Example ```json { "customers": "..." } ``` ``` -------------------------------- ### GET /api/subscriptions/{subscriptionId} Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve detailed information about a specific subscription using its ID. ```APIDOC ## GET /api/subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID. ### Method GET ### Endpoint `/api/subscriptions/{subscriptionId}` ### Parameters #### Path Parameters - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan** - An object containing subscription details. #### Response Example ```json { "subscription": "..." } ``` ``` -------------------------------- ### GET /api/plans/{planSlug} Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/PlanshipCustomer.md Retrieve detailed information about a specific plan using its slug. ```APIDOC ## GET /api/plans/{planSlug} ### Description Retrieve detailed information about the plan with a given slug. ### Method GET ### Endpoint `/api/plans/{planSlug}` ### Parameters #### Path Parameters - **planSlug** (string) - Required - plan slug #### Query Parameters - **entitlementsOrderBy** (string[]) - Optional - optional entitlements order by column ### Response #### Success Response (200) - **PlanDetails** - An object containing detailed plan information. #### Response Example ```json { "planDetails": "..." } ``` ``` -------------------------------- ### Instantiate Planship API Client (Client ID and Secret) Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Instantiate the Planship API client using your Planship product slug, client ID, and client secret for authentication. ```js import { Planship } from '@planship/axios' // Instantiate Planship API client using client ID and secret auth const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) ``` -------------------------------- ### Get Lever Usage Source: https://context7.com/planship/planship-js/llms.txt Retrieve usage data for a specific metered lever for a given customer. ```APIDOC ## Get Lever Usage Retrieve usage data for a specific metered lever. ### Method GET ### Endpoint `/api/v1/customers/{customerId}/levers/{leverSlug}/usage` ### Parameters #### Path Parameters - **customerId** (string) - Required - The unique identifier for the customer. - **leverSlug** (string) - Required - The slug of the metered lever. ### Response #### Success Response (200) - **total** (integer) - The total usage for the lever. - **byBucket** (object) - Usage broken down by bucket. - **bucketName** (integer) - Usage for a specific bucket. - **bySubscription** (object) - Usage broken down by subscription. - **subscriptionId** - Array of usage objects for a subscription. - **bucket** (string) - The bucket name. - **usage** (integer) - The usage amount. ### Response Example ```json { "total": 15, "byBucket": { "default": 10, "premium": 5 }, "bySubscription": { "sub_xyz789": [ { "bucket": "default", "usage": 10 }, { "bucket": "premium", "usage": 5 } ] } } ``` ``` -------------------------------- ### GET /subscriptions/{subscriptionId}/customers Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Retrieve a list of all customers that belong to the subscription with a given ID. ```APIDOC ## GET /subscriptions/{subscriptionId}/customers ### Description Retrieve a list of all customers that belong to the subscription with a given ID. ### Method GET ### Endpoint /subscriptions/{subscriptionId}/customers ### Parameters #### Path Parameters - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **SubscriptionCustomer[]** (array) - A list of SubscriptionCustomer objects. ``` -------------------------------- ### GET /getAccessToken Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipCustomerApi.md Obtain an access token using a client ID/secret pair stored by this instance. ```APIDOC ## GET /getAccessToken ### Description Obtain an access token using a client ID/secret pair stored by this instance. ### Response #### Success Response (200) - **TokenResponse** (object) - A promise that resolves with a TokenResponse object ``` -------------------------------- ### PlanSubscriptionCreate Interface Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanSubscriptionCreate.md Defines the properties required and optional for creating a plan subscription. ```APIDOC ## PlanSubscriptionCreate Interface ### Description The PlanSubscriptionCreate interface defines the data structure required when creating a new subscription within the Planship system. ### Properties - **customerId** (string) - Required - The unique identifier for the customer. - **autoRenew** (boolean) - Optional - Whether the subscription should automatically renew. - **isSubscriber** (boolean) - Optional - Indicates if the entity is currently a subscriber. - **maxSubscribers** (number) - Optional - The maximum number of subscribers allowed. - **metadata** (object) - Optional - Additional metadata associated with the subscription. - **renewAt** (Date) - Optional - The date and time when the subscription is set to renew. ``` -------------------------------- ### GET /customers/{customerId}/subscriptions/{subscriptionId} Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/classes/Planship.md Retrieve detailed information about a specific subscription for a customer. ```APIDOC ## GET /customers/{customerId}/subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID for the customer with a given ID. ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID - **subscriptionId** (string) - Required - Planship subscription ID ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan** (object) - An instance of the SubscriptionWithPlan class ``` -------------------------------- ### GET /auth/token Source: https://github.com/planship/planship-js/blob/master/packages/models/docs/interfaces/PlanshipBaseApi.md Obtain an access token using a client ID/secret pair stored by the instance. ```APIDOC ## GET /auth/token ### Description Obtain an access token using a client ID/secret pair stored by this instance. ### Method GET ### Response #### Success Response (200) - **TokenResponse** (object) - A promise that resolves with a TokenResponse object ``` -------------------------------- ### CustomerSubscriptionWithPlan Interface Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/interfaces/CustomerSubscriptionWithPlan.md Defines the structure of a customer's subscription, including associated plan details. ```APIDOC ## CustomerSubscriptionWithPlan Interface ### Description Represents a customer's subscription to a specific plan, including details about renewal, status, and associated customer information. ### Properties #### autoRenew (boolean) Indicates whether the subscription will automatically renew. #### customerId (string) The unique identifier for the customer. #### isActive (boolean) Indicates if the subscription is currently active. #### isAdministrator (boolean, Optional) Indicates if the customer has administrator privileges for this subscription. #### isSubscriber (boolean, Optional) Indicates if the customer is a subscriber. #### lastRenewedAt (Date) The date when the subscription was last renewed. #### maxSubscribers (number, Optional) The maximum number of subscribers allowed for this plan. #### metadata (object, Optional) Additional metadata associated with the subscription. #### plan (IdNameSlugOrmBase) Details of the plan associated with the subscription. #### renewAt (Date) The date when the subscription is set to renew. #### renewPlan (IdNameSlugOrmBase) Details of the plan to which the subscription will renew. #### subscriptionId (string) The unique identifier for the subscription. ``` -------------------------------- ### getProduct Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/PlanshipCustomer.md Retrieve information about the current product. ```APIDOC ## getProduct ### Description Retrieve information about the current product. ### Response - **Product** (object) - A promise that resolves with an instance of the Product class ``` -------------------------------- ### Server-Side Authentication Source: https://github.com/planship/planship-js/blob/master/README.md Initialize the Planship client using a client ID and secret for secure server-side environments. ```js const planship = new Planship( 'clicker-demo', // Your Planship product slug { clientId: '273N1SQ3GQFZ8JSFKIOK', // Planship API client ID clientSecret: 'GDSfzPD2NEM5PEzIl1JoXFRJNZm3uAhX' // Planship API client secret } ) ``` -------------------------------- ### GET /api/customers/{customerId}/subscriptions Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/Planship.md List all subscriptions for a given customer, optionally filtered by product slug. ```APIDOC ## GET /api/customers/{customerId}/subscriptions ### Description List subscriptions the customer with a given ID. ### Method GET ### Endpoint /api/customers/{customerId}/subscriptions ### Parameters #### Path Parameters - **customerId** (string) - Required - Planship customer ID. #### Query Parameters - **productSlug** (string) - Optional - Planship product slug to filter subscriptions. ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan[]** - An array of CustomerSubscriptionWithPlan objects. ### Response Example ```json [ { "id": "sub-xyz", "customerId": "cust-123", "plan": { "id": "plan-123", "name": "Basic Plan" } } ] ``` ``` -------------------------------- ### IPlanshipOptions Interface Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/interfaces/IPlanshipOptions.md Configuration options for the Planship JavaScript SDK. ```APIDOC ## Interface: IPlanshipOptions Planship options ### Properties #### baseUrl - **baseUrl** (string) - Optional - Custom URL for the Planship API. Default: https://api.planship.io #### debugLogging - **debugLogging** (boolean) - Optional - Enable/disable debug logging. Default: false #### extras - **extras** (Object) - Optional - Optional extra params e.g. custom provided FetchAPI - Index signature: [x: string]: any #### webSocketUrl - **webSocketUrl** (string) - Optional - Custom URL for the Planship API WebSocket. Default: wss://websockets-api.planship.io ``` -------------------------------- ### GET /api/customers/{customerId}/subscriptions/{subscriptionId}/customers Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/Planship.md Retrieve a list of all customers belonging to a specific subscription. ```APIDOC ## GET /api/customers/{customerId}/subscriptions/{subscriptionId}/customers ### Description Retrieve a list of all customers that belong to the subscription with a given ID. ### Method GET ### Endpoint /api/customers/{customerId}/subscriptions/{subscriptionId}/customers ### Parameters #### Path Parameters - **customerId** (string) - Required - The Planship customer ID. - **subscriptionId** (string) - Required - The Planship subscription ID. ### Response #### Success Response (200) - **SubscriptionCustomer[]** - An array of SubscriptionCustomer objects. ### Response Example ```json [ { "id": "cust-456", "name": "Customer B" } ] ``` ``` -------------------------------- ### GET /api/customers/{customerId}/subscriptions/{subscriptionId} Source: https://github.com/planship/planship-js/blob/master/packages/fetch/docs/classes/Planship.md Retrieve detailed information about a specific subscription for a given customer. ```APIDOC ## GET /api/customers/{customerId}/subscriptions/{subscriptionId} ### Description Retrieve detailed information about the subscription with a given ID for the customer with a given ID. ### Method GET ### Endpoint /api/customers/{customerId}/subscriptions/{subscriptionId} ### Parameters #### Path Parameters - **customerId** (string) - Required - The Planship customer ID. - **subscriptionId** (string) - Required - The Planship subscription ID. ### Response #### Success Response (200) - **CustomerSubscriptionWithPlan** - An object containing detailed subscription information including the associated plan. ### Response Example ```json { "subscription": { "id": "sub-xyz", "customerId": "cust-123", "plan": { "id": "plan-123", "name": "Basic Plan" } } } ``` ``` -------------------------------- ### List Product Plans Source: https://github.com/planship/planship-js/blob/master/packages/axios/docs/README.md Retrieve a list of available product plans from the Planship API. ```js // List product plans const plans = await planship.listPlans() ```