@skalpgg/sdk 1.8.0 → 1.9.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/README.md +1 -0
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/types.d.ts +22 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +9 -2
- package/dist/esm/types.d.ts +22 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@ Create the key on the API keys page of your dashboard. Each key is bound to one
|
|
|
78
78
|
| `subscriptions.list({ externalRef?, status?, updatedSince?, limit?, offset? })` | `subscriptions:read` |
|
|
79
79
|
| `subscriptions.get(id)` | `subscriptions:read` |
|
|
80
80
|
| `subscriptions.changePlan(id, { productId \| productSlug })` | `subscriptions:write` |
|
|
81
|
+
| `subscriptions.update(id, { externalRef })` | `subscriptions:write` |
|
|
81
82
|
| `subscriptions.cancel(id)` | `subscriptions:write` |
|
|
82
83
|
| `subscriptions.createUsageCharge(id, { amount, currency, description, idempotencyKey, periodStart, periodEnd })` | `subscriptions:write` |
|
|
83
84
|
| `subscriptions.listInvoices(id)` | `subscriptions:read` |
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -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, 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';
|
|
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, UpdateSubscriptionParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams, WebhookEndpoint } from './types.js';
|
|
2
2
|
export type * from './types.js';
|
|
3
|
-
export declare const VERSION = "1.
|
|
3
|
+
export declare const VERSION = "1.9.0";
|
|
4
4
|
export interface SkalpOptions {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
webhookSecret?: string;
|
|
@@ -115,6 +115,7 @@ export declare class Skalp {
|
|
|
115
115
|
list: ({ externalRef, status, updatedSince, limit, offset }?: ListSubscriptionsParams) => Promise<SubscriptionList>;
|
|
116
116
|
get: (id: string) => Promise<Subscription>;
|
|
117
117
|
changePlan: (id: string, { productId, productSlug }: ChangeSubscriptionPlanParams) => Promise<Subscription>;
|
|
118
|
+
update: (id: string, { externalRef }: UpdateSubscriptionParams) => Promise<Subscription>;
|
|
118
119
|
cancel: (id: string) => Promise<Subscription>;
|
|
119
120
|
createUsageCharge: (id: string, { amount, currency, description, idempotencyKey, periodStart, periodEnd }: CreateUsageChargeParams) => Promise<UsageCharge>;
|
|
120
121
|
listInvoices: (id: string) => Promise<Invoice[]>;
|
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.
|
|
4
|
+
exports.VERSION = '1.9.0';
|
|
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
|
|
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 = [
|
|
@@ -275,6 +279,7 @@ class Skalp {
|
|
|
275
279
|
changePlan: (id, { productId, productSlug }) => this.#request('POST', `/v1/subscriptions/${segment(id)}/plan`, {
|
|
276
280
|
body: { productId, productSlug },
|
|
277
281
|
}),
|
|
282
|
+
update: (id, { externalRef }) => this.#request('PATCH', `/v1/subscriptions/${segment(id)}`, { body: { externalRef } }),
|
|
278
283
|
cancel: (id) => this.#request('DELETE', `/v1/subscriptions/${segment(id)}`),
|
|
279
284
|
createUsageCharge: (id, { amount, currency, description, idempotencyKey, periodStart, periodEnd }) => this.#request('POST', `/v1/subscriptions/${segment(id)}/usage-charges`, {
|
|
280
285
|
body: {
|
|
@@ -347,6 +352,8 @@ class Skalp {
|
|
|
347
352
|
if (auth && !this.#apiKey) {
|
|
348
353
|
throw new Error('Skalp: missing API key. Pass it to new Skalp(apiKey) or set SKALP_API_KEY.');
|
|
349
354
|
}
|
|
355
|
+
if (path.includes(INVALID_SEGMENT))
|
|
356
|
+
throw new Error('Skalp: an ID cannot be empty, "." or "..".');
|
|
350
357
|
const url = new URL(this.#baseUrl + path);
|
|
351
358
|
for (const [name, value] of Object.entries(query ?? {})) {
|
|
352
359
|
if (Array.isArray(value))
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export interface Order {
|
|
|
56
56
|
currency: Currency;
|
|
57
57
|
discountAmount: number;
|
|
58
58
|
serviceFee: number | null;
|
|
59
|
+
sellerPaymentFee: number | null;
|
|
59
60
|
couponCode: string | null;
|
|
60
61
|
productId: string;
|
|
61
62
|
productName: string;
|
|
@@ -729,6 +730,9 @@ export interface ChangeSubscriptionPlanParams {
|
|
|
729
730
|
productId?: string;
|
|
730
731
|
productSlug?: string;
|
|
731
732
|
}
|
|
733
|
+
export interface UpdateSubscriptionParams {
|
|
734
|
+
externalRef: string | null;
|
|
735
|
+
}
|
|
732
736
|
export interface ListSubscriptionsParams {
|
|
733
737
|
externalRef?: string;
|
|
734
738
|
status?: SubscriptionStatus;
|
|
@@ -1031,6 +1035,23 @@ export interface FeedbackReceivedData {
|
|
|
1031
1035
|
customerName: string | null;
|
|
1032
1036
|
createdAt: string;
|
|
1033
1037
|
}
|
|
1038
|
+
export interface SubscriptionCheckoutExpiredData {
|
|
1039
|
+
idempotencyKey: string;
|
|
1040
|
+
checkoutId: string;
|
|
1041
|
+
externalRef: string | null;
|
|
1042
|
+
status: 'EXPIRED';
|
|
1043
|
+
active: false;
|
|
1044
|
+
reason: 'payment_not_completed';
|
|
1045
|
+
storeId: string;
|
|
1046
|
+
productId: string;
|
|
1047
|
+
productSlug: string;
|
|
1048
|
+
productName: string;
|
|
1049
|
+
buyerId: string;
|
|
1050
|
+
buyerEmail: string | null;
|
|
1051
|
+
amount: number;
|
|
1052
|
+
currency: string;
|
|
1053
|
+
metadata: Record<string, unknown>;
|
|
1054
|
+
}
|
|
1034
1055
|
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 & {
|
|
1035
1056
|
amountDue: number;
|
|
1036
1057
|
nextPaymentAttempt: string | null;
|
|
@@ -1038,7 +1059,7 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1038
1059
|
invoiceId: string;
|
|
1039
1060
|
amountPaid: number;
|
|
1040
1061
|
periodExtendedTo: string;
|
|
1041
|
-
}> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1062
|
+
}> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1042
1063
|
invoiceId: string;
|
|
1043
1064
|
attemptCount: number;
|
|
1044
1065
|
nextPaymentAttempt: string | null;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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, 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';
|
|
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, UpdateSubscriptionParams, UpdateProductGroupParams, UpdateProductParams, UpdateStoreCategoryParams, UsageCharge, ValidateLicenseParams, VerifyLicenseParams, WebhookEndpoint } from './types.js';
|
|
2
2
|
export type * from './types.js';
|
|
3
|
-
export declare const VERSION = "1.
|
|
3
|
+
export declare const VERSION = "1.9.0";
|
|
4
4
|
export interface SkalpOptions {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
webhookSecret?: string;
|
|
@@ -115,6 +115,7 @@ export declare class Skalp {
|
|
|
115
115
|
list: ({ externalRef, status, updatedSince, limit, offset }?: ListSubscriptionsParams) => Promise<SubscriptionList>;
|
|
116
116
|
get: (id: string) => Promise<Subscription>;
|
|
117
117
|
changePlan: (id: string, { productId, productSlug }: ChangeSubscriptionPlanParams) => Promise<Subscription>;
|
|
118
|
+
update: (id: string, { externalRef }: UpdateSubscriptionParams) => Promise<Subscription>;
|
|
118
119
|
cancel: (id: string) => Promise<Subscription>;
|
|
119
120
|
createUsageCharge: (id: string, { amount, currency, description, idempotencyKey, periodStart, periodEnd }: CreateUsageChargeParams) => Promise<UsageCharge>;
|
|
120
121
|
listInvoices: (id: string) => Promise<Invoice[]>;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const VERSION = '1.
|
|
1
|
+
export const VERSION = '1.9.0';
|
|
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
|
|
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 = [
|
|
@@ -269,6 +273,7 @@ export class Skalp {
|
|
|
269
273
|
changePlan: (id, { productId, productSlug }) => this.#request('POST', `/v1/subscriptions/${segment(id)}/plan`, {
|
|
270
274
|
body: { productId, productSlug },
|
|
271
275
|
}),
|
|
276
|
+
update: (id, { externalRef }) => this.#request('PATCH', `/v1/subscriptions/${segment(id)}`, { body: { externalRef } }),
|
|
272
277
|
cancel: (id) => this.#request('DELETE', `/v1/subscriptions/${segment(id)}`),
|
|
273
278
|
createUsageCharge: (id, { amount, currency, description, idempotencyKey, periodStart, periodEnd }) => this.#request('POST', `/v1/subscriptions/${segment(id)}/usage-charges`, {
|
|
274
279
|
body: {
|
|
@@ -341,6 +346,8 @@ export class Skalp {
|
|
|
341
346
|
if (auth && !this.#apiKey) {
|
|
342
347
|
throw new Error('Skalp: missing API key. Pass it to new Skalp(apiKey) or set SKALP_API_KEY.');
|
|
343
348
|
}
|
|
349
|
+
if (path.includes(INVALID_SEGMENT))
|
|
350
|
+
throw new Error('Skalp: an ID cannot be empty, "." or "..".');
|
|
344
351
|
const url = new URL(this.#baseUrl + path);
|
|
345
352
|
for (const [name, value] of Object.entries(query ?? {})) {
|
|
346
353
|
if (Array.isArray(value))
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export interface Order {
|
|
|
56
56
|
currency: Currency;
|
|
57
57
|
discountAmount: number;
|
|
58
58
|
serviceFee: number | null;
|
|
59
|
+
sellerPaymentFee: number | null;
|
|
59
60
|
couponCode: string | null;
|
|
60
61
|
productId: string;
|
|
61
62
|
productName: string;
|
|
@@ -729,6 +730,9 @@ export interface ChangeSubscriptionPlanParams {
|
|
|
729
730
|
productId?: string;
|
|
730
731
|
productSlug?: string;
|
|
731
732
|
}
|
|
733
|
+
export interface UpdateSubscriptionParams {
|
|
734
|
+
externalRef: string | null;
|
|
735
|
+
}
|
|
732
736
|
export interface ListSubscriptionsParams {
|
|
733
737
|
externalRef?: string;
|
|
734
738
|
status?: SubscriptionStatus;
|
|
@@ -1031,6 +1035,23 @@ export interface FeedbackReceivedData {
|
|
|
1031
1035
|
customerName: string | null;
|
|
1032
1036
|
createdAt: string;
|
|
1033
1037
|
}
|
|
1038
|
+
export interface SubscriptionCheckoutExpiredData {
|
|
1039
|
+
idempotencyKey: string;
|
|
1040
|
+
checkoutId: string;
|
|
1041
|
+
externalRef: string | null;
|
|
1042
|
+
status: 'EXPIRED';
|
|
1043
|
+
active: false;
|
|
1044
|
+
reason: 'payment_not_completed';
|
|
1045
|
+
storeId: string;
|
|
1046
|
+
productId: string;
|
|
1047
|
+
productSlug: string;
|
|
1048
|
+
productName: string;
|
|
1049
|
+
buyerId: string;
|
|
1050
|
+
buyerEmail: string | null;
|
|
1051
|
+
amount: number;
|
|
1052
|
+
currency: string;
|
|
1053
|
+
metadata: Record<string, unknown>;
|
|
1054
|
+
}
|
|
1034
1055
|
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 & {
|
|
1035
1056
|
amountDue: number;
|
|
1036
1057
|
nextPaymentAttempt: string | null;
|
|
@@ -1038,7 +1059,7 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1038
1059
|
invoiceId: string;
|
|
1039
1060
|
amountPaid: number;
|
|
1040
1061
|
periodExtendedTo: string;
|
|
1041
|
-
}> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1062
|
+
}> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1042
1063
|
invoiceId: string;
|
|
1043
1064
|
attemptCount: number;
|
|
1044
1065
|
nextPaymentAttempt: string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skalpgg/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
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",
|