@vellumcharter/sdk 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -86,16 +86,46 @@ export interface CreateCustomerParams {
86
86
  customerId: string;
87
87
  email?: string;
88
88
  }
89
+ /** One pack to buy in a multi-denomination cart. */
90
+ export interface CreditCheckoutItem {
91
+ creditTypeId: string;
92
+ packId: string;
93
+ /** How many of this pack to buy (default 1); grants grantQty × quantity. */
94
+ quantity?: number;
95
+ }
89
96
  export interface CreditCheckoutParams {
90
97
  accountId: string;
91
98
  customerId: string;
92
- creditTypeId: string;
93
- packId: string;
94
- /** How many packs to buy at once (default 1); grants grantQty × quantity. */
99
+ /**
100
+ * Single-pack form: the pack to buy. Ignored when `items` is given. Use this
101
+ * or `items`, not both.
102
+ */
103
+ creditTypeId?: string;
104
+ packId?: string;
105
+ /** Single-pack form: how many packs to buy at once (default 1). */
95
106
  quantity?: number;
107
+ /**
108
+ * Multi-denomination form: buy several packs (denominations and credit types
109
+ * may be mixed) in one Checkout. Takes precedence over the single-pack fields.
110
+ */
111
+ items?: CreditCheckoutItem[];
96
112
  successUrl: string;
97
113
  cancelUrl: string;
98
114
  }
115
+ export interface CreditType {
116
+ creditTypeId: string;
117
+ name: string;
118
+ }
119
+ export interface CreditPack {
120
+ creditTypeId: string;
121
+ packId: string;
122
+ name: string;
123
+ /** Credits granted per unit purchased. */
124
+ grantQty: number;
125
+ /** Price in the currency's minor units (e.g. cents). */
126
+ amount?: number;
127
+ currency?: string;
128
+ }
99
129
  export interface CreditBalance {
100
130
  creditTypeId: string;
101
131
  balance: number;
@@ -220,10 +250,18 @@ export declare class VellumCharterClient {
220
250
  listInvoices(accountId: string, customerId?: string): Promise<Invoice[]>;
221
251
  /** Resolve the hosted-PDF URL for an invoice (follows the 302 `Location`). */
222
252
  invoicePdfUrl(accountId: string, invoiceId: string): Promise<string>;
223
- /** Create a one-time Checkout session to buy a credit pack for a customer. */
253
+ /**
254
+ * Create a one-time Checkout session to buy credit packs for a customer. Pass a
255
+ * single `creditTypeId` + `packId` (+ optional `quantity`), or `items` to buy
256
+ * several packs at once (multi-denomination; types may be mixed).
257
+ */
224
258
  createCreditCheckout(params: CreditCheckoutParams): Promise<{
225
259
  url: string;
226
260
  }>;
261
+ /** The tenant's credit types (the catalog of what can be bought). */
262
+ listCreditTypes(): Promise<CreditType[]>;
263
+ /** The packs (denominations) for sale within a credit type, with grant size + price. */
264
+ listCreditPacks(creditTypeId: string): Promise<CreditPack[]>;
227
265
  /** All of a customer's prepaid credit balances. */
228
266
  listCredits(customerId: string): Promise<CreditBalance[]>;
229
267
  /** One credit balance (0 if the customer has never bought this type). */
package/dist/index.js CHANGED
@@ -204,7 +204,11 @@ class VellumCharterClient {
204
204
  // Prepaid one-time-use credits. Uncached (a balance changes out-of-band via
205
205
  // purchase/consume, unlike getEntitlements). consume is idempotent on the
206
206
  // caller-supplied key and all-or-nothing.
207
- /** Create a one-time Checkout session to buy a credit pack for a customer. */
207
+ /**
208
+ * Create a one-time Checkout session to buy credit packs for a customer. Pass a
209
+ * single `creditTypeId` + `packId` (+ optional `quantity`), or `items` to buy
210
+ * several packs at once (multi-denomination; types may be mixed).
211
+ */
208
212
  async createCreditCheckout(params) {
209
213
  const { accountId, ...body } = params;
210
214
  const res = await this.billingFetch(`/accounts/${enc(accountId)}/credit-checkout`, {
@@ -213,6 +217,16 @@ class VellumCharterClient {
213
217
  });
214
218
  return this.parse(res);
215
219
  }
220
+ /** The tenant's credit types (the catalog of what can be bought). */
221
+ async listCreditTypes() {
222
+ const res = await this.billingFetch('/credit-types');
223
+ return (await this.parse(res)).creditTypes;
224
+ }
225
+ /** The packs (denominations) for sale within a credit type, with grant size + price. */
226
+ async listCreditPacks(creditTypeId) {
227
+ const res = await this.billingFetch(`/credit-types/${enc(creditTypeId)}/packs`);
228
+ return (await this.parse(res)).packs;
229
+ }
216
230
  /** All of a customer's prepaid credit balances. */
217
231
  async listCredits(customerId) {
218
232
  const res = await this.billingFetch(`/customers/${enc(customerId)}/credits`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumcharter/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Thin HTTP client for the VellumCharter entitlements + billing API",
5
5
  "license": "MIT",
6
6
  "author": "Todd Esposito",