@skalpgg/sdk 1.7.0 → 1.8.1

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/README.md CHANGED
@@ -41,7 +41,8 @@ Create the key on the API keys page of your dashboard. Each key is bound to one
41
41
 
42
42
  | Method | Scope |
43
43
  | --- | --- |
44
- | `checkout.create({ productId, quantity?, customerEmail?, metadata?, couponCode?, returnUrl?, customFields? })` | `checkout:write` |
44
+ | `me()` | none |
45
+ | `checkout.create({ productId, quantity?, customerEmail?, metadata?, couponCode?, returnUrl?, customFields?, player? })` | `checkout:write` |
45
46
  | `checkout.get(id)` | `checkout:read` |
46
47
  | `orders.list({ status?, productId?, email?, identifier?, createdAfter?, createdBefore?, updatedSince?, limit?, offset? })` | `orders:read` |
47
48
  | `orders.get(id)` | `orders:read` |
@@ -63,7 +64,7 @@ Create the key on the API keys page of your dashboard. Each key is bound to one
63
64
  | `groups.list()` / `groups.get(id)` | `products:read` |
64
65
  | `groups.create({ title, productIds, ... })` / `groups.update(id, { ... })` / `groups.delete(id)` | `products:write` |
65
66
  | `coupons.list()` / `coupons.get(id)` | `coupons:read` |
66
- | `coupons.create({ code, discountType?, discountPercent?, discountAmount?, validFrom?, validTo?, maxUses?, ... })` / `coupons.update(id, { ... })` / `coupons.delete(id)` | `coupons:write` |
67
+ | `coupons.create({ code, discountType?, discountPercent?, discountAmount?, validFrom?, validTo?, maxUses?, subscriptionDuration?, subscriptionMonths?, ... })` / `coupons.update(id, { ... })` / `coupons.delete(id)` | `coupons:write` |
67
68
  | `customers.list({ search?, limit?, offset? })` / `customers.get(id)` | `customers:read` |
68
69
  | `customers.create({ email, name?, note? })` / `customers.update(id, { name?, note? })` / `customers.delete(id)` | `customers:write` |
69
70
  | `feedback.list({ productId?, rating?, limit?, offset? })` / `feedback.get(id)` | `feedback:read` |
@@ -86,6 +87,8 @@ Create the key on the API keys page of your dashboard. Each key is bound to one
86
87
  | `licenses.resetDevices({ key, hardwareId? })` | `licenses:write` |
87
88
  | `licenses.verify({ licenseKey, serverIp, serverKey, serverPort? })` | none |
88
89
  | `licenses.heartbeat({ licenseKey, serverIp })` | none |
90
+ | `webhooks.list()` | `webhooks:read` |
91
+ | `webhooks.create({ url, events, productIds? })` / `webhooks.delete(id)` | `webhooks:write` |
89
92
  | `webhooks.constructEvent(rawBody, headers)` | none |
90
93
  | `webhooks.verify(rawBody, headers)` | none |
91
94
 
@@ -135,7 +138,9 @@ const { replacements } = await skalp.orders.replace(order.id, { reason: 'Key doe
135
138
 
136
139
  `updatedSince` lists oldest change first, so you can page through it and keep the last `updatedAt` as your cursor; without it, newest orders come first. Amounts are in major units (`19.5`).
137
140
 
138
- Coupons take `validFrom`, `validTo` as an ISO string or a `Date`; `coupons.update` accepts `null` to clear `validTo`, `maxUses`, `minPurchaseAmount` and `description`.
141
+ Coupons take `validFrom`, `validTo` as an ISO string or a `Date`; `coupons.update` accepts `null` to clear `validTo`, `maxUses`, `minPurchaseAmount`, `subscriptionMonths` and `description`. On a subscription, `subscriptionDuration` sets how long the discount lasts: `ONCE` (the default), `REPEATING` for `subscriptionMonths` (1 to 36) or `FOREVER`.
142
+
143
+ `me()` returns the store and the key you are using, with its scopes. `checkout.create` takes `player`, a `name` and game `ids` such as `steamid64` or `mc_name`, when your server already knows who gets the order. Orders carry `serviceFee`, the buyer fee included in `amount`, and customers carry `spent`, one total per currency.
139
144
 
140
145
  ## Support and access rules
141
146
 
@@ -180,9 +185,15 @@ export async function POST(request: Request) {
180
185
  }
181
186
  ```
182
187
 
188
+ `webhooks.create` returns the endpoint's signing `secret` once, so store it then. `events` takes event names or `'*'` for all of them.
189
+
190
+ ```ts
191
+ const { id, secret } = await skalp.webhooks.create({ url: 'https://example.com/skalp', events: ['order.paid', 'subscription.renewed'] })
192
+ ```
193
+
183
194
  A webhook with the default events receives every purchase as both `order.paid` and its legacy name `purchase.completed`. Handle `order.paid` and deduplicate on `data.idempotencyKey`.
184
195
 
185
- `order.created`, `order.updated`, `order.canceled`, `order.replaced`, `query.created`, `query.replied`, `feedback.received` and the subscription events `subscription.updated`, `subscription.trial_started`, `subscription.trial_ended` and `subscription.upcoming` are not in the default list either: subscribe the webhook to them by name, and `event.type` narrows `event.data` to the right payload. `order.created`, `order.updated` and `order.canceled` carry the order as `orders.get` returns it, plus `previousStatus`; `order.replaced` adds `reason` and the new keys in `replacements[].key`. Every one of them, like `query.created`, `query.replied` and `feedback.received`, carries a `data.idempotencyKey` that stays the same on every retry of the same event, so deduplicate on it. `subscription.trial_started` follows `subscription.created` when a subscription starts with a trial, free or paid, `subscription.trial_ended` comes when the trial is over, and `subscription.upcoming` comes before a renewal is charged.
196
+ `order.created`, `order.updated`, `order.canceled`, `order.replaced`, `query.created`, `query.replied`, `feedback.received` and the subscription events `subscription.trial_started`, `subscription.trial_ended` and `subscription.upcoming` are not in the default list either: subscribe the webhook to them by name, and `event.type` narrows `event.data` to the right payload. `order.created`, `order.updated` and `order.canceled` carry the order as `orders.get` returns it, plus `previousStatus`; `order.replaced` adds `reason` and the new keys in `replacements[].key`. Every one of them, like `query.created`, `query.replied` and `feedback.received`, carries a `data.idempotencyKey` that stays the same on every retry of the same event, so deduplicate on it. `subscription.trial_started` follows `subscription.created` when a subscription starts with a trial, free or paid, `subscription.trial_ended` comes when the trial is over, and `subscription.upcoming` comes before a renewal is charged.
186
197
 
187
198
  `product.created`, `product.updated` and `product.stock` are not in the default list: subscribe the webhook to them by name. `product.stock` carries `stock`, `previousStock` and `change` whenever the number of available keys changes.
188
199
 
@@ -1,6 +1,6 @@
1
- import type { AccessRule, AddAccessRuleParams, AddSerialsParams, AddSerialsResult, AppealFeedbackParams, ChangeSubscriptionPlanParams, CheckoutSession, CheckoutSessionStatus, CoinCheckout, CoinCheckoutStatus, Coupon, CreateCheckoutParams, CreateCoinCheckoutParams, CreateCouponParams, CreateCustomerParams, CreateProductGroupParams, CreateProductParams, CreateStoreCategoryParams, CreateSubscriptionCheckoutParams, CreateUsageChargeParams, Customer, CustomerDetails, CustomerList, Deleted, Feedback, FeedbackList, HeartbeatParams, Invoice, LicenseKeyInfo, LicenseValidation, LicenseVerification, ListAccessRulesParams, ListCustomersParams, ListFeedbackParams, ListOrdersParams, ListProductsParams, ListQueriesParams, ListSerialsParams, ListSubscriptionsParams, Order, OrderKeysReplaced, OrderList, Product, ProductGroup, ProductStock, ReplaceOrderKeysParams, ReplyParams, SerialList, SkalpEvent, StoreCategory, StoreCategoryWithCount, Subscription, SubscriptionCheckout, SubscriptionCheckoutStatus, SubscriptionList, SupportQueryDetails, SupportQueryList, ResetLicenseDevicesParams, UpdateCouponParams, UpdateCustomerParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams } from './types.js';
1
+ import type { AccessRule, AddAccessRuleParams, AddSerialsParams, AddSerialsResult, AppealFeedbackParams, ChangeSubscriptionPlanParams, CheckoutSession, CheckoutSessionStatus, CoinCheckout, CoinCheckoutStatus, Coupon, CreateCheckoutParams, CreateCoinCheckoutParams, CreateCouponParams, CreateCustomerParams, CreateProductGroupParams, CreateProductParams, CreateStoreCategoryParams, CreateSubscriptionCheckoutParams, CreateUsageChargeParams, CreateWebhookParams, CreatedWebhookEndpoint, Customer, CustomerDetails, CustomerList, Deleted, Feedback, FeedbackList, HeartbeatParams, Invoice, LicenseKeyInfo, LicenseValidation, LicenseVerification, ListAccessRulesParams, ListCustomersParams, ListFeedbackParams, ListOrdersParams, ListProductsParams, ListQueriesParams, ListSerialsParams, ListSubscriptionsParams, Me, Order, OrderKeysReplaced, OrderList, Product, ProductGroup, ProductStock, ReplaceOrderKeysParams, ReplyParams, SerialList, SkalpEvent, StoreCategory, StoreCategoryWithCount, Subscription, SubscriptionCheckout, SubscriptionCheckoutStatus, SubscriptionList, SupportQueryDetails, SupportQueryList, ResetLicenseDevicesParams, UpdateCouponParams, UpdateCustomerParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams, WebhookEndpoint } from './types.js';
2
2
  export type * from './types.js';
3
- export declare const VERSION = "1.7.0";
3
+ export declare const VERSION = "1.8.1";
4
4
  export interface SkalpOptions {
5
5
  apiKey?: string;
6
6
  webhookSecret?: string;
@@ -31,8 +31,9 @@ export declare class SkalpSignatureError extends Error {
31
31
  export declare class Skalp {
32
32
  #private;
33
33
  constructor(options?: string | SkalpOptions);
34
+ readonly me: () => Promise<Me>;
34
35
  readonly checkout: {
35
- create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields }: CreateCheckoutParams) => Promise<CheckoutSession>;
36
+ create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields, player }: CreateCheckoutParams) => Promise<CheckoutSession>;
36
37
  get: (id: string) => Promise<CheckoutSessionStatus>;
37
38
  };
38
39
  readonly orders: {
@@ -129,6 +130,12 @@ export declare class Skalp {
129
130
  }>;
130
131
  };
131
132
  readonly webhooks: {
133
+ list: () => Promise<WebhookEndpoint[]>;
134
+ create: ({ url, events, productIds }: CreateWebhookParams) => Promise<CreatedWebhookEndpoint>;
135
+ delete: (id: string) => Promise<{
136
+ id: string;
137
+ deleted: true;
138
+ }>;
132
139
  verify: (payload: WebhookPayload, signature: SignatureSource, secret?: string) => Promise<boolean>;
133
140
  constructEvent: (payload: WebhookPayload, signature: SignatureSource, secret?: string) => Promise<SkalpEvent>;
134
141
  };
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Skalp = exports.SkalpSignatureError = exports.SkalpConnectionError = exports.SkalpError = exports.VERSION = void 0;
4
- exports.VERSION = '1.7.0';
4
+ exports.VERSION = '1.8.1';
5
5
  const SIGNATURE_HEADER = 'skalp-signature';
6
6
  const SIGNATURE_TOLERANCE_SECONDS = 300;
7
7
  const PRODUCT_PAGE = 100;
@@ -40,7 +40,11 @@ class SkalpSignatureError extends Error {
40
40
  }
41
41
  exports.SkalpSignatureError = SkalpSignatureError;
42
42
  const env = (name) => globalThis.process?.env?.[name];
43
- const segment = (id) => encodeURIComponent(id);
43
+ const INVALID_SEGMENT = '\0';
44
+ const segment = (id) => {
45
+ const encoded = encodeURIComponent(id);
46
+ return encoded === '' || encoded === '.' || encoded === '..' ? INVALID_SEGMENT : encoded;
47
+ };
44
48
  const isoDate = (value) => (value instanceof Date ? value.toISOString() : value);
45
49
  const optionalDate = (value) => value instanceof Date ? value.toISOString() : value;
46
50
  const PRODUCT_FIELDS = [
@@ -82,6 +86,9 @@ const PRODUCT_FIELDS = [
82
86
  'volumeDiscounts',
83
87
  'upsells',
84
88
  'prices',
89
+ 'poolsEnabled',
90
+ 'upgradeFrom',
91
+ 'includes',
85
92
  ];
86
93
  const COUPON_FIELDS = [
87
94
  'discountType',
@@ -93,6 +100,8 @@ const COUPON_FIELDS = [
93
100
  'maxUses',
94
101
  'minPurchaseAmount',
95
102
  'oneTimePerUser',
103
+ 'subscriptionDuration',
104
+ 'subscriptionMonths',
96
105
  ];
97
106
  const GROUP_FIELDS = ['title', 'productIds', 'description', 'image', 'sortPriority', 'unlisted'];
98
107
  function pick(source, keys) {
@@ -123,9 +132,10 @@ class Skalp {
123
132
  throw new Error('Skalp: your API key is a secret and must never reach the browser. Call the SDK from server code, or pass dangerouslyAllowBrowser: true if you really know what you are doing.');
124
133
  }
125
134
  }
135
+ me = () => this.#request('GET', '/v1/me');
126
136
  checkout = {
127
- create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields }) => this.#request('POST', '/v1/checkout/sessions', {
128
- body: { items: [{ productId, quantity }], customerEmail, metadata, couponCode, returnUrl, customFields },
137
+ create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields, player }) => this.#request('POST', '/v1/checkout/sessions', {
138
+ body: { items: [{ productId, quantity }], customerEmail, metadata, couponCode, returnUrl, customFields, player },
129
139
  }),
130
140
  get: (id) => this.#request('GET', `/v1/checkout/sessions/${segment(id)}`),
131
141
  };
@@ -303,6 +313,9 @@ class Skalp {
303
313
  }),
304
314
  };
305
315
  webhooks = {
316
+ list: () => this.#request('GET', '/v1/webhooks'),
317
+ create: ({ url, events, productIds }) => this.#request('POST', '/v1/webhooks', { body: { url, events, productIds } }),
318
+ delete: (id) => this.#request('DELETE', `/v1/webhooks/${segment(id)}`),
306
319
  verify: async (payload, signature, secret) => (await this.#checkSignature(payload, signature, secret)) === undefined,
307
320
  constructEvent: async (payload, signature, secret) => {
308
321
  const failure = await this.#checkSignature(payload, signature, secret);
@@ -338,6 +351,8 @@ class Skalp {
338
351
  if (auth && !this.#apiKey) {
339
352
  throw new Error('Skalp: missing API key. Pass it to new Skalp(apiKey) or set SKALP_API_KEY.');
340
353
  }
354
+ if (path.includes(INVALID_SEGMENT))
355
+ throw new Error('Skalp: an ID cannot be empty, "." or "..".');
341
356
  const url = new URL(this.#baseUrl + path);
342
357
  for (const [name, value] of Object.entries(query ?? {})) {
343
358
  if (Array.isArray(value))
@@ -416,10 +431,10 @@ function parseSignature(header) {
416
431
  function toBytes(payload, encoder) {
417
432
  if (typeof payload === 'string')
418
433
  return encoder.encode(payload);
419
- if (payload instanceof ArrayBuffer)
434
+ if (ArrayBuffer.isView(payload))
435
+ return new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength);
436
+ if (Object.prototype.toString.call(payload) === '[object ArrayBuffer]')
420
437
  return new Uint8Array(payload);
421
- if (payload instanceof Uint8Array)
422
- return payload;
423
438
  throw new TypeError('Skalp: webhook payload must be the raw request body (string, Buffer or ArrayBuffer). A parsed JSON object cannot be verified, because re-serializing it changes the bytes that were signed.');
424
439
  }
425
440
  function retryAfterSeconds(res, attempt) {
@@ -5,10 +5,19 @@ export type ProductType = 'ONE_TIME' | 'RECURRING' | 'COINS';
5
5
  export type Game = 'fivem' | 'minecraft' | 'rust';
6
6
  export type BillingInterval = 'WEEK' | 'MONTH' | 'QUARTER' | 'HALF_YEAR' | 'YEAR';
7
7
  export type OrderStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'REFUNDED' | 'DISPUTED' | 'CANCELED';
8
- export type PaymentProvider = 'STRIPE' | 'NOWPAYMENTS' | 'PAYPAL';
8
+ export type PaymentProvider = 'STRIPE' | 'NOWPAYMENTS' | 'PAYPAL' | 'PAYSSION';
9
9
  export type DeliveryStatus = 'PENDING' | 'PROCESSING' | 'DELIVERED' | 'FAILED';
10
10
  export type SubscriptionStatus = 'ACTIVE' | 'CANCELED' | 'PAST_DUE' | 'UNPAID' | 'INCOMPLETE' | 'INCOMPLETE_EXPIRED' | 'TRIALING' | 'PAUSED';
11
11
  export type Metadata = Record<string, string>;
12
+ export type PlayerIdKey = 'fivem' | 'license2' | 'steam' | 'discord' | 'xbl' | 'live' | 'fivemId' | 'mc_uuid' | 'mc_name' | 'steamid64';
13
+ export interface PlayerInput {
14
+ name?: string;
15
+ ids?: Partial<Record<PlayerIdKey, string>>;
16
+ }
17
+ export interface Player {
18
+ name: string | null;
19
+ ids: Partial<Record<PlayerIdKey, string>>;
20
+ }
12
21
  export interface CreateCheckoutParams {
13
22
  productId: string;
14
23
  /** Units to sell, within the product's minQuantity and maxQuantity. Defaults to minQuantity. */
@@ -19,6 +28,7 @@ export interface CreateCheckoutParams {
19
28
  returnUrl?: string;
20
29
  /** Answers you already have, by field key; the buyer adds the rest on the pay page. */
21
30
  customFields?: Record<string, string>;
31
+ player?: PlayerInput;
22
32
  }
23
33
  export interface CheckoutSession {
24
34
  id: string;
@@ -28,7 +38,7 @@ export interface CheckoutSession {
28
38
  }
29
39
  export interface CheckoutSessionStatus {
30
40
  id: string;
31
- status: 'pending' | 'completed' | 'failed';
41
+ status: 'pending' | 'completed' | 'failed' | 'canceled';
32
42
  orderNumber: string;
33
43
  amount: number;
34
44
  currency: Currency;
@@ -45,23 +55,25 @@ export interface Order {
45
55
  vatRate: number | null;
46
56
  currency: Currency;
47
57
  discountAmount: number;
58
+ serviceFee: number | null;
59
+ sellerPaymentFee: number | null;
48
60
  couponCode: string | null;
49
61
  productId: string;
50
62
  productName: string;
51
63
  productSlug: string;
52
64
  /** Units of productId. */
53
65
  quantity: number;
54
- fulfillmentType: FulfillmentType;
66
+ fulfillmentType: FulfillmentType | null;
55
67
  bundleId: string | null;
56
68
  buyerEmail: string;
57
69
  buyerCountry: string | null;
58
70
  paymentProvider: PaymentProvider | null;
59
71
  isGift: boolean;
60
- granted?: boolean;
72
+ granted: boolean;
61
73
  deliveryStatus: DeliveryStatus | null;
62
74
  serialsCount?: number;
63
75
  serialsReplaced?: number;
64
- /** Delivered and replaced keys by id, never their values. Only orders.get and orders.cancel fill it in. */
76
+ /** Delivered and replaced keys by id, never their values. Filled in by orders.get, orders.cancel and orders.redeliver. */
65
77
  serials?: Array<OrderSerial>;
66
78
  createdAt: string;
67
79
  updatedAt: string;
@@ -240,6 +252,9 @@ export interface Product {
240
252
  volumeDiscounts: Array<VolumeDiscount>;
241
253
  /** Products offered on this product's checkout page. */
242
254
  upsells: Array<ProductUpsell>;
255
+ poolsEnabled: boolean | null;
256
+ upgradeFrom: Array<string>;
257
+ includes: Array<string>;
243
258
  stock: number | null;
244
259
  sale: ProductSale | null;
245
260
  salesCount: number;
@@ -313,6 +328,9 @@ interface ProductFields {
313
328
  upsells?: Array<ProductUpsellInput> | null;
314
329
  /** Up to 3 currencies other than the store currency, not for coin packs; the list replaces the old one, [] or null removes them all. */
315
330
  prices?: Array<ProductPrice> | null;
331
+ poolsEnabled?: boolean;
332
+ upgradeFrom?: Array<string>;
333
+ includes?: Array<string>;
316
334
  }
317
335
  export interface CreateProductParams extends ProductFields {
318
336
  name: string;
@@ -370,6 +388,39 @@ export interface Deleted {
370
388
  id: string;
371
389
  deleted: true;
372
390
  }
391
+ export interface Me {
392
+ store: {
393
+ id: string;
394
+ name: string;
395
+ slug: string;
396
+ currency: Currency;
397
+ url: string;
398
+ };
399
+ key: {
400
+ name: string;
401
+ scopes: Array<string>;
402
+ };
403
+ }
404
+ export type WebhookEventName = SkalpEventType | '*';
405
+ export interface WebhookEndpoint {
406
+ id: string;
407
+ url: string;
408
+ events: Array<WebhookEventName>;
409
+ format: 'skalp' | (string & {});
410
+ isActive: boolean;
411
+ createdAt: string;
412
+ }
413
+ export interface CreateWebhookParams {
414
+ url: string;
415
+ events: Array<WebhookEventName>;
416
+ productIds?: Array<string>;
417
+ }
418
+ export interface CreatedWebhookEndpoint {
419
+ id: string;
420
+ url: string;
421
+ events: Array<WebhookEventName>;
422
+ secret: string;
423
+ }
373
424
  export interface StoreCategory {
374
425
  id: string;
375
426
  name: string;
@@ -423,6 +474,7 @@ export interface UpdateProductGroupParams {
423
474
  unlisted?: boolean;
424
475
  }
425
476
  export type CouponDiscountType = 'PERCENT' | 'FIXED';
477
+ export type CouponDuration = 'ONCE' | 'REPEATING' | 'FOREVER';
426
478
  export interface Coupon {
427
479
  id: string;
428
480
  code: string;
@@ -432,6 +484,8 @@ export interface Coupon {
432
484
  discountAmount: number | null;
433
485
  productIds: Array<string>;
434
486
  disabledWithVolumeDiscounts: boolean;
487
+ subscriptionDuration: CouponDuration;
488
+ subscriptionMonths: number | null;
435
489
  validFrom: string;
436
490
  validTo: string | null;
437
491
  maxUses: number | null;
@@ -455,6 +509,8 @@ export interface CreateCouponParams {
455
509
  maxUses?: number;
456
510
  minPurchaseAmount?: number;
457
511
  oneTimePerUser?: boolean;
512
+ subscriptionDuration?: CouponDuration;
513
+ subscriptionMonths?: number;
458
514
  }
459
515
  export interface UpdateCouponParams {
460
516
  discountType?: CouponDiscountType;
@@ -469,6 +525,8 @@ export interface UpdateCouponParams {
469
525
  minPurchaseAmount?: number | null;
470
526
  oneTimePerUser?: boolean;
471
527
  isActive?: boolean;
528
+ subscriptionDuration?: CouponDuration;
529
+ subscriptionMonths?: number | null;
472
530
  }
473
531
  export interface Customer {
474
532
  id: string;
@@ -479,6 +537,10 @@ export interface Customer {
479
537
  ordersCount: number;
480
538
  totalSpent: number;
481
539
  currency: Currency;
540
+ spent: Array<{
541
+ currency: Currency;
542
+ amount: number;
543
+ }>;
482
544
  firstOrderAt: string | null;
483
545
  lastOrderAt: string | null;
484
546
  createdAt: string;
@@ -486,6 +548,17 @@ export interface Customer {
486
548
  }
487
549
  export interface CustomerDetails extends Customer {
488
550
  recentOrders: Array<Order>;
551
+ recentSubscriptionPayments: Array<SubscriptionPayment>;
552
+ }
553
+ export interface SubscriptionPayment {
554
+ id: string;
555
+ orderNumber: string | null;
556
+ status: 'COMPLETED' | 'REFUNDED';
557
+ amount: number;
558
+ currency: Currency;
559
+ productName: string;
560
+ subscriptionId: string;
561
+ createdAt: string;
489
562
  }
490
563
  export interface ListCustomersParams {
491
564
  search?: string;
@@ -615,7 +688,7 @@ export interface CreateSubscriptionCheckoutParams {
615
688
  customerEmail?: string;
616
689
  externalRef?: string;
617
690
  metadata?: Metadata;
618
- currency?: 'EUR' | 'USD' | 'PLN';
691
+ currency?: 'EUR' | 'USD' | 'PLN' | 'BRL';
619
692
  returnUrl?: string;
620
693
  }
621
694
  export interface SubscriptionCheckout {
@@ -692,7 +765,7 @@ export interface Invoice {
692
765
  }
693
766
  export interface CreateUsageChargeParams {
694
767
  amount: number;
695
- currency: 'EUR' | 'USD' | 'PLN';
768
+ currency: Currency;
696
769
  description: string;
697
770
  idempotencyKey: string;
698
771
  periodStart: string | Date;
@@ -824,6 +897,7 @@ export interface OrderPaidData {
824
897
  customFields: Record<string, string>;
825
898
  deliveryType?: string;
826
899
  deliveryCommand?: string;
900
+ player?: Player;
827
901
  }
828
902
  export interface OrderRefundedData {
829
903
  orderId: string;
@@ -839,6 +913,8 @@ export interface OrderRefundedData {
839
913
  fullRefund: boolean;
840
914
  licenses: Array<WebhookLicense>;
841
915
  revocations: Array<Revocation>;
916
+ upgradedTo?: string;
917
+ player?: Player;
842
918
  }
843
919
  export interface Revocation {
844
920
  productId: string;
@@ -891,6 +967,9 @@ export interface SubscriptionEventData {
891
967
  licenseKey: string | null;
892
968
  licenseStatus: string | null;
893
969
  licenseExpiresAt: string | null;
970
+ deliveryType?: string;
971
+ deliveryCommand?: string;
972
+ player?: Player;
894
973
  }
895
974
  export interface ProductEventData {
896
975
  productId: string;
@@ -953,17 +1032,37 @@ export interface FeedbackReceivedData {
953
1032
  customerName: string | null;
954
1033
  createdAt: string;
955
1034
  }
956
- export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.canceled', OrderEventData> | Envelope<'order.replaced', OrderReplacedData> | Envelope<'order.paid' | 'purchase.completed', OrderPaidData> | Envelope<'order.refunded', OrderRefundedData> | Envelope<'order.disputed' | 'account.suspend', OrderDisputedData> | Envelope<'account.restore', AccountRestoreData> | Envelope<'subscription.created' | 'subscription.updated' | 'subscription.trial_started' | 'subscription.trial_ended' | 'subscription.upcoming', SubscriptionEventData> | Envelope<'subscription.renewed', SubscriptionEventData & {
1035
+ export interface SubscriptionCheckoutExpiredData {
1036
+ idempotencyKey: string;
1037
+ checkoutId: string;
1038
+ externalRef: string | null;
1039
+ status: 'EXPIRED';
1040
+ active: false;
1041
+ reason: 'payment_not_completed';
1042
+ storeId: string;
1043
+ productId: string;
1044
+ productSlug: string;
1045
+ productName: string;
1046
+ buyerId: string;
1047
+ buyerEmail: string | null;
1048
+ amount: number;
1049
+ currency: string;
1050
+ metadata: Record<string, unknown>;
1051
+ }
1052
+ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.canceled', OrderEventData> | Envelope<'order.replaced', OrderReplacedData> | Envelope<'order.paid' | 'purchase.completed', OrderPaidData> | Envelope<'order.refunded', OrderRefundedData> | Envelope<'order.disputed' | 'account.suspend', OrderDisputedData> | Envelope<'account.restore', AccountRestoreData> | Envelope<'subscription.created' | 'subscription.updated' | 'subscription.trial_started' | 'subscription.trial_ended', SubscriptionEventData> | Envelope<'subscription.upcoming', SubscriptionEventData & {
1053
+ amountDue: number;
1054
+ nextPaymentAttempt: string | null;
1055
+ }> | Envelope<'subscription.renewed', SubscriptionEventData & {
957
1056
  invoiceId: string;
958
1057
  amountPaid: number;
959
1058
  periodExtendedTo: string;
960
- }> | Envelope<'subscription.past_due', SubscriptionEventData & {
1059
+ }> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
961
1060
  invoiceId: string;
962
1061
  attemptCount: number;
963
1062
  nextPaymentAttempt: string | null;
964
1063
  }> | Envelope<'subscription.canceled', SubscriptionEventData & {
965
1064
  endedAt: string | null;
966
- cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe';
1065
+ cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe' | 'expired';
967
1066
  revokeCommand?: string;
968
1067
  }> | Envelope<'subscription.refunded', SubscriptionEventData & {
969
1068
  invoiceId: string;
@@ -1,6 +1,6 @@
1
- import type { AccessRule, AddAccessRuleParams, AddSerialsParams, AddSerialsResult, AppealFeedbackParams, ChangeSubscriptionPlanParams, CheckoutSession, CheckoutSessionStatus, CoinCheckout, CoinCheckoutStatus, Coupon, CreateCheckoutParams, CreateCoinCheckoutParams, CreateCouponParams, CreateCustomerParams, CreateProductGroupParams, CreateProductParams, CreateStoreCategoryParams, CreateSubscriptionCheckoutParams, CreateUsageChargeParams, Customer, CustomerDetails, CustomerList, Deleted, Feedback, FeedbackList, HeartbeatParams, Invoice, LicenseKeyInfo, LicenseValidation, LicenseVerification, ListAccessRulesParams, ListCustomersParams, ListFeedbackParams, ListOrdersParams, ListProductsParams, ListQueriesParams, ListSerialsParams, ListSubscriptionsParams, Order, OrderKeysReplaced, OrderList, Product, ProductGroup, ProductStock, ReplaceOrderKeysParams, ReplyParams, SerialList, SkalpEvent, StoreCategory, StoreCategoryWithCount, Subscription, SubscriptionCheckout, SubscriptionCheckoutStatus, SubscriptionList, SupportQueryDetails, SupportQueryList, ResetLicenseDevicesParams, UpdateCouponParams, UpdateCustomerParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams } from './types.js';
1
+ import type { AccessRule, AddAccessRuleParams, AddSerialsParams, AddSerialsResult, AppealFeedbackParams, ChangeSubscriptionPlanParams, CheckoutSession, CheckoutSessionStatus, CoinCheckout, CoinCheckoutStatus, Coupon, CreateCheckoutParams, CreateCoinCheckoutParams, CreateCouponParams, CreateCustomerParams, CreateProductGroupParams, CreateProductParams, CreateStoreCategoryParams, CreateSubscriptionCheckoutParams, CreateUsageChargeParams, CreateWebhookParams, CreatedWebhookEndpoint, Customer, CustomerDetails, CustomerList, Deleted, Feedback, FeedbackList, HeartbeatParams, Invoice, LicenseKeyInfo, LicenseValidation, LicenseVerification, ListAccessRulesParams, ListCustomersParams, ListFeedbackParams, ListOrdersParams, ListProductsParams, ListQueriesParams, ListSerialsParams, ListSubscriptionsParams, Me, Order, OrderKeysReplaced, OrderList, Product, ProductGroup, ProductStock, ReplaceOrderKeysParams, ReplyParams, SerialList, SkalpEvent, StoreCategory, StoreCategoryWithCount, Subscription, SubscriptionCheckout, SubscriptionCheckoutStatus, SubscriptionList, SupportQueryDetails, SupportQueryList, ResetLicenseDevicesParams, UpdateCouponParams, UpdateCustomerParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams, WebhookEndpoint } from './types.js';
2
2
  export type * from './types.js';
3
- export declare const VERSION = "1.7.0";
3
+ export declare const VERSION = "1.8.1";
4
4
  export interface SkalpOptions {
5
5
  apiKey?: string;
6
6
  webhookSecret?: string;
@@ -31,8 +31,9 @@ export declare class SkalpSignatureError extends Error {
31
31
  export declare class Skalp {
32
32
  #private;
33
33
  constructor(options?: string | SkalpOptions);
34
+ readonly me: () => Promise<Me>;
34
35
  readonly checkout: {
35
- create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields }: CreateCheckoutParams) => Promise<CheckoutSession>;
36
+ create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields, player }: CreateCheckoutParams) => Promise<CheckoutSession>;
36
37
  get: (id: string) => Promise<CheckoutSessionStatus>;
37
38
  };
38
39
  readonly orders: {
@@ -129,6 +130,12 @@ export declare class Skalp {
129
130
  }>;
130
131
  };
131
132
  readonly webhooks: {
133
+ list: () => Promise<WebhookEndpoint[]>;
134
+ create: ({ url, events, productIds }: CreateWebhookParams) => Promise<CreatedWebhookEndpoint>;
135
+ delete: (id: string) => Promise<{
136
+ id: string;
137
+ deleted: true;
138
+ }>;
132
139
  verify: (payload: WebhookPayload, signature: SignatureSource, secret?: string) => Promise<boolean>;
133
140
  constructEvent: (payload: WebhookPayload, signature: SignatureSource, secret?: string) => Promise<SkalpEvent>;
134
141
  };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = '1.7.0';
1
+ export const VERSION = '1.8.1';
2
2
  const SIGNATURE_HEADER = 'skalp-signature';
3
3
  const SIGNATURE_TOLERANCE_SECONDS = 300;
4
4
  const PRODUCT_PAGE = 100;
@@ -34,7 +34,11 @@ export class SkalpSignatureError extends Error {
34
34
  }
35
35
  }
36
36
  const env = (name) => globalThis.process?.env?.[name];
37
- const segment = (id) => encodeURIComponent(id);
37
+ const INVALID_SEGMENT = '\0';
38
+ const segment = (id) => {
39
+ const encoded = encodeURIComponent(id);
40
+ return encoded === '' || encoded === '.' || encoded === '..' ? INVALID_SEGMENT : encoded;
41
+ };
38
42
  const isoDate = (value) => (value instanceof Date ? value.toISOString() : value);
39
43
  const optionalDate = (value) => value instanceof Date ? value.toISOString() : value;
40
44
  const PRODUCT_FIELDS = [
@@ -76,6 +80,9 @@ const PRODUCT_FIELDS = [
76
80
  'volumeDiscounts',
77
81
  'upsells',
78
82
  'prices',
83
+ 'poolsEnabled',
84
+ 'upgradeFrom',
85
+ 'includes',
79
86
  ];
80
87
  const COUPON_FIELDS = [
81
88
  'discountType',
@@ -87,6 +94,8 @@ const COUPON_FIELDS = [
87
94
  'maxUses',
88
95
  'minPurchaseAmount',
89
96
  'oneTimePerUser',
97
+ 'subscriptionDuration',
98
+ 'subscriptionMonths',
90
99
  ];
91
100
  const GROUP_FIELDS = ['title', 'productIds', 'description', 'image', 'sortPriority', 'unlisted'];
92
101
  function pick(source, keys) {
@@ -117,9 +126,10 @@ export class Skalp {
117
126
  throw new Error('Skalp: your API key is a secret and must never reach the browser. Call the SDK from server code, or pass dangerouslyAllowBrowser: true if you really know what you are doing.');
118
127
  }
119
128
  }
129
+ me = () => this.#request('GET', '/v1/me');
120
130
  checkout = {
121
- create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields }) => this.#request('POST', '/v1/checkout/sessions', {
122
- body: { items: [{ productId, quantity }], customerEmail, metadata, couponCode, returnUrl, customFields },
131
+ create: ({ productId, quantity, customerEmail, metadata, couponCode, returnUrl, customFields, player }) => this.#request('POST', '/v1/checkout/sessions', {
132
+ body: { items: [{ productId, quantity }], customerEmail, metadata, couponCode, returnUrl, customFields, player },
123
133
  }),
124
134
  get: (id) => this.#request('GET', `/v1/checkout/sessions/${segment(id)}`),
125
135
  };
@@ -297,6 +307,9 @@ export class Skalp {
297
307
  }),
298
308
  };
299
309
  webhooks = {
310
+ list: () => this.#request('GET', '/v1/webhooks'),
311
+ create: ({ url, events, productIds }) => this.#request('POST', '/v1/webhooks', { body: { url, events, productIds } }),
312
+ delete: (id) => this.#request('DELETE', `/v1/webhooks/${segment(id)}`),
300
313
  verify: async (payload, signature, secret) => (await this.#checkSignature(payload, signature, secret)) === undefined,
301
314
  constructEvent: async (payload, signature, secret) => {
302
315
  const failure = await this.#checkSignature(payload, signature, secret);
@@ -332,6 +345,8 @@ export class Skalp {
332
345
  if (auth && !this.#apiKey) {
333
346
  throw new Error('Skalp: missing API key. Pass it to new Skalp(apiKey) or set SKALP_API_KEY.');
334
347
  }
348
+ if (path.includes(INVALID_SEGMENT))
349
+ throw new Error('Skalp: an ID cannot be empty, "." or "..".');
335
350
  const url = new URL(this.#baseUrl + path);
336
351
  for (const [name, value] of Object.entries(query ?? {})) {
337
352
  if (Array.isArray(value))
@@ -409,10 +424,10 @@ function parseSignature(header) {
409
424
  function toBytes(payload, encoder) {
410
425
  if (typeof payload === 'string')
411
426
  return encoder.encode(payload);
412
- if (payload instanceof ArrayBuffer)
427
+ if (ArrayBuffer.isView(payload))
428
+ return new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength);
429
+ if (Object.prototype.toString.call(payload) === '[object ArrayBuffer]')
413
430
  return new Uint8Array(payload);
414
- if (payload instanceof Uint8Array)
415
- return payload;
416
431
  throw new TypeError('Skalp: webhook payload must be the raw request body (string, Buffer or ArrayBuffer). A parsed JSON object cannot be verified, because re-serializing it changes the bytes that were signed.');
417
432
  }
418
433
  function retryAfterSeconds(res, attempt) {
@@ -5,10 +5,19 @@ export type ProductType = 'ONE_TIME' | 'RECURRING' | 'COINS';
5
5
  export type Game = 'fivem' | 'minecraft' | 'rust';
6
6
  export type BillingInterval = 'WEEK' | 'MONTH' | 'QUARTER' | 'HALF_YEAR' | 'YEAR';
7
7
  export type OrderStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'REFUNDED' | 'DISPUTED' | 'CANCELED';
8
- export type PaymentProvider = 'STRIPE' | 'NOWPAYMENTS' | 'PAYPAL';
8
+ export type PaymentProvider = 'STRIPE' | 'NOWPAYMENTS' | 'PAYPAL' | 'PAYSSION';
9
9
  export type DeliveryStatus = 'PENDING' | 'PROCESSING' | 'DELIVERED' | 'FAILED';
10
10
  export type SubscriptionStatus = 'ACTIVE' | 'CANCELED' | 'PAST_DUE' | 'UNPAID' | 'INCOMPLETE' | 'INCOMPLETE_EXPIRED' | 'TRIALING' | 'PAUSED';
11
11
  export type Metadata = Record<string, string>;
12
+ export type PlayerIdKey = 'fivem' | 'license2' | 'steam' | 'discord' | 'xbl' | 'live' | 'fivemId' | 'mc_uuid' | 'mc_name' | 'steamid64';
13
+ export interface PlayerInput {
14
+ name?: string;
15
+ ids?: Partial<Record<PlayerIdKey, string>>;
16
+ }
17
+ export interface Player {
18
+ name: string | null;
19
+ ids: Partial<Record<PlayerIdKey, string>>;
20
+ }
12
21
  export interface CreateCheckoutParams {
13
22
  productId: string;
14
23
  /** Units to sell, within the product's minQuantity and maxQuantity. Defaults to minQuantity. */
@@ -19,6 +28,7 @@ export interface CreateCheckoutParams {
19
28
  returnUrl?: string;
20
29
  /** Answers you already have, by field key; the buyer adds the rest on the pay page. */
21
30
  customFields?: Record<string, string>;
31
+ player?: PlayerInput;
22
32
  }
23
33
  export interface CheckoutSession {
24
34
  id: string;
@@ -28,7 +38,7 @@ export interface CheckoutSession {
28
38
  }
29
39
  export interface CheckoutSessionStatus {
30
40
  id: string;
31
- status: 'pending' | 'completed' | 'failed';
41
+ status: 'pending' | 'completed' | 'failed' | 'canceled';
32
42
  orderNumber: string;
33
43
  amount: number;
34
44
  currency: Currency;
@@ -45,23 +55,25 @@ export interface Order {
45
55
  vatRate: number | null;
46
56
  currency: Currency;
47
57
  discountAmount: number;
58
+ serviceFee: number | null;
59
+ sellerPaymentFee: number | null;
48
60
  couponCode: string | null;
49
61
  productId: string;
50
62
  productName: string;
51
63
  productSlug: string;
52
64
  /** Units of productId. */
53
65
  quantity: number;
54
- fulfillmentType: FulfillmentType;
66
+ fulfillmentType: FulfillmentType | null;
55
67
  bundleId: string | null;
56
68
  buyerEmail: string;
57
69
  buyerCountry: string | null;
58
70
  paymentProvider: PaymentProvider | null;
59
71
  isGift: boolean;
60
- granted?: boolean;
72
+ granted: boolean;
61
73
  deliveryStatus: DeliveryStatus | null;
62
74
  serialsCount?: number;
63
75
  serialsReplaced?: number;
64
- /** Delivered and replaced keys by id, never their values. Only orders.get and orders.cancel fill it in. */
76
+ /** Delivered and replaced keys by id, never their values. Filled in by orders.get, orders.cancel and orders.redeliver. */
65
77
  serials?: Array<OrderSerial>;
66
78
  createdAt: string;
67
79
  updatedAt: string;
@@ -240,6 +252,9 @@ export interface Product {
240
252
  volumeDiscounts: Array<VolumeDiscount>;
241
253
  /** Products offered on this product's checkout page. */
242
254
  upsells: Array<ProductUpsell>;
255
+ poolsEnabled: boolean | null;
256
+ upgradeFrom: Array<string>;
257
+ includes: Array<string>;
243
258
  stock: number | null;
244
259
  sale: ProductSale | null;
245
260
  salesCount: number;
@@ -313,6 +328,9 @@ interface ProductFields {
313
328
  upsells?: Array<ProductUpsellInput> | null;
314
329
  /** Up to 3 currencies other than the store currency, not for coin packs; the list replaces the old one, [] or null removes them all. */
315
330
  prices?: Array<ProductPrice> | null;
331
+ poolsEnabled?: boolean;
332
+ upgradeFrom?: Array<string>;
333
+ includes?: Array<string>;
316
334
  }
317
335
  export interface CreateProductParams extends ProductFields {
318
336
  name: string;
@@ -370,6 +388,39 @@ export interface Deleted {
370
388
  id: string;
371
389
  deleted: true;
372
390
  }
391
+ export interface Me {
392
+ store: {
393
+ id: string;
394
+ name: string;
395
+ slug: string;
396
+ currency: Currency;
397
+ url: string;
398
+ };
399
+ key: {
400
+ name: string;
401
+ scopes: Array<string>;
402
+ };
403
+ }
404
+ export type WebhookEventName = SkalpEventType | '*';
405
+ export interface WebhookEndpoint {
406
+ id: string;
407
+ url: string;
408
+ events: Array<WebhookEventName>;
409
+ format: 'skalp' | (string & {});
410
+ isActive: boolean;
411
+ createdAt: string;
412
+ }
413
+ export interface CreateWebhookParams {
414
+ url: string;
415
+ events: Array<WebhookEventName>;
416
+ productIds?: Array<string>;
417
+ }
418
+ export interface CreatedWebhookEndpoint {
419
+ id: string;
420
+ url: string;
421
+ events: Array<WebhookEventName>;
422
+ secret: string;
423
+ }
373
424
  export interface StoreCategory {
374
425
  id: string;
375
426
  name: string;
@@ -423,6 +474,7 @@ export interface UpdateProductGroupParams {
423
474
  unlisted?: boolean;
424
475
  }
425
476
  export type CouponDiscountType = 'PERCENT' | 'FIXED';
477
+ export type CouponDuration = 'ONCE' | 'REPEATING' | 'FOREVER';
426
478
  export interface Coupon {
427
479
  id: string;
428
480
  code: string;
@@ -432,6 +484,8 @@ export interface Coupon {
432
484
  discountAmount: number | null;
433
485
  productIds: Array<string>;
434
486
  disabledWithVolumeDiscounts: boolean;
487
+ subscriptionDuration: CouponDuration;
488
+ subscriptionMonths: number | null;
435
489
  validFrom: string;
436
490
  validTo: string | null;
437
491
  maxUses: number | null;
@@ -455,6 +509,8 @@ export interface CreateCouponParams {
455
509
  maxUses?: number;
456
510
  minPurchaseAmount?: number;
457
511
  oneTimePerUser?: boolean;
512
+ subscriptionDuration?: CouponDuration;
513
+ subscriptionMonths?: number;
458
514
  }
459
515
  export interface UpdateCouponParams {
460
516
  discountType?: CouponDiscountType;
@@ -469,6 +525,8 @@ export interface UpdateCouponParams {
469
525
  minPurchaseAmount?: number | null;
470
526
  oneTimePerUser?: boolean;
471
527
  isActive?: boolean;
528
+ subscriptionDuration?: CouponDuration;
529
+ subscriptionMonths?: number | null;
472
530
  }
473
531
  export interface Customer {
474
532
  id: string;
@@ -479,6 +537,10 @@ export interface Customer {
479
537
  ordersCount: number;
480
538
  totalSpent: number;
481
539
  currency: Currency;
540
+ spent: Array<{
541
+ currency: Currency;
542
+ amount: number;
543
+ }>;
482
544
  firstOrderAt: string | null;
483
545
  lastOrderAt: string | null;
484
546
  createdAt: string;
@@ -486,6 +548,17 @@ export interface Customer {
486
548
  }
487
549
  export interface CustomerDetails extends Customer {
488
550
  recentOrders: Array<Order>;
551
+ recentSubscriptionPayments: Array<SubscriptionPayment>;
552
+ }
553
+ export interface SubscriptionPayment {
554
+ id: string;
555
+ orderNumber: string | null;
556
+ status: 'COMPLETED' | 'REFUNDED';
557
+ amount: number;
558
+ currency: Currency;
559
+ productName: string;
560
+ subscriptionId: string;
561
+ createdAt: string;
489
562
  }
490
563
  export interface ListCustomersParams {
491
564
  search?: string;
@@ -615,7 +688,7 @@ export interface CreateSubscriptionCheckoutParams {
615
688
  customerEmail?: string;
616
689
  externalRef?: string;
617
690
  metadata?: Metadata;
618
- currency?: 'EUR' | 'USD' | 'PLN';
691
+ currency?: 'EUR' | 'USD' | 'PLN' | 'BRL';
619
692
  returnUrl?: string;
620
693
  }
621
694
  export interface SubscriptionCheckout {
@@ -692,7 +765,7 @@ export interface Invoice {
692
765
  }
693
766
  export interface CreateUsageChargeParams {
694
767
  amount: number;
695
- currency: 'EUR' | 'USD' | 'PLN';
768
+ currency: Currency;
696
769
  description: string;
697
770
  idempotencyKey: string;
698
771
  periodStart: string | Date;
@@ -824,6 +897,7 @@ export interface OrderPaidData {
824
897
  customFields: Record<string, string>;
825
898
  deliveryType?: string;
826
899
  deliveryCommand?: string;
900
+ player?: Player;
827
901
  }
828
902
  export interface OrderRefundedData {
829
903
  orderId: string;
@@ -839,6 +913,8 @@ export interface OrderRefundedData {
839
913
  fullRefund: boolean;
840
914
  licenses: Array<WebhookLicense>;
841
915
  revocations: Array<Revocation>;
916
+ upgradedTo?: string;
917
+ player?: Player;
842
918
  }
843
919
  export interface Revocation {
844
920
  productId: string;
@@ -891,6 +967,9 @@ export interface SubscriptionEventData {
891
967
  licenseKey: string | null;
892
968
  licenseStatus: string | null;
893
969
  licenseExpiresAt: string | null;
970
+ deliveryType?: string;
971
+ deliveryCommand?: string;
972
+ player?: Player;
894
973
  }
895
974
  export interface ProductEventData {
896
975
  productId: string;
@@ -953,17 +1032,37 @@ export interface FeedbackReceivedData {
953
1032
  customerName: string | null;
954
1033
  createdAt: string;
955
1034
  }
956
- export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.canceled', OrderEventData> | Envelope<'order.replaced', OrderReplacedData> | Envelope<'order.paid' | 'purchase.completed', OrderPaidData> | Envelope<'order.refunded', OrderRefundedData> | Envelope<'order.disputed' | 'account.suspend', OrderDisputedData> | Envelope<'account.restore', AccountRestoreData> | Envelope<'subscription.created' | 'subscription.updated' | 'subscription.trial_started' | 'subscription.trial_ended' | 'subscription.upcoming', SubscriptionEventData> | Envelope<'subscription.renewed', SubscriptionEventData & {
1035
+ export interface SubscriptionCheckoutExpiredData {
1036
+ idempotencyKey: string;
1037
+ checkoutId: string;
1038
+ externalRef: string | null;
1039
+ status: 'EXPIRED';
1040
+ active: false;
1041
+ reason: 'payment_not_completed';
1042
+ storeId: string;
1043
+ productId: string;
1044
+ productSlug: string;
1045
+ productName: string;
1046
+ buyerId: string;
1047
+ buyerEmail: string | null;
1048
+ amount: number;
1049
+ currency: string;
1050
+ metadata: Record<string, unknown>;
1051
+ }
1052
+ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.canceled', OrderEventData> | Envelope<'order.replaced', OrderReplacedData> | Envelope<'order.paid' | 'purchase.completed', OrderPaidData> | Envelope<'order.refunded', OrderRefundedData> | Envelope<'order.disputed' | 'account.suspend', OrderDisputedData> | Envelope<'account.restore', AccountRestoreData> | Envelope<'subscription.created' | 'subscription.updated' | 'subscription.trial_started' | 'subscription.trial_ended', SubscriptionEventData> | Envelope<'subscription.upcoming', SubscriptionEventData & {
1053
+ amountDue: number;
1054
+ nextPaymentAttempt: string | null;
1055
+ }> | Envelope<'subscription.renewed', SubscriptionEventData & {
957
1056
  invoiceId: string;
958
1057
  amountPaid: number;
959
1058
  periodExtendedTo: string;
960
- }> | Envelope<'subscription.past_due', SubscriptionEventData & {
1059
+ }> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
961
1060
  invoiceId: string;
962
1061
  attemptCount: number;
963
1062
  nextPaymentAttempt: string | null;
964
1063
  }> | Envelope<'subscription.canceled', SubscriptionEventData & {
965
1064
  endedAt: string | null;
966
- cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe';
1065
+ cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe' | 'expired';
967
1066
  revokeCommand?: string;
968
1067
  }> | Envelope<'subscription.refunded', SubscriptionEventData & {
969
1068
  invoiceId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalpgg/sdk",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Official Skalp SDK for Node.js and edge runtimes: checkout, subscriptions, catalog and key stock, webhooks and license verification.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://skalp.gg/docs/sdk",