@skalpgg/sdk 1.9.0 → 1.11.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 +40 -0
- package/dist/cjs/index.d.ts +8 -2
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/types.d.ts +85 -4
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +10 -1
- package/dist/esm/types.d.ts +85 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,9 @@ Create the key on the API keys page of your dashboard. Each key is bound to one
|
|
|
67
67
|
| `coupons.create({ code, discountType?, discountPercent?, discountAmount?, validFrom?, validTo?, maxUses?, subscriptionDuration?, subscriptionMonths?, ... })` / `coupons.update(id, { ... })` / `coupons.delete(id)` | `coupons:write` |
|
|
68
68
|
| `customers.list({ search?, limit?, offset? })` / `customers.get(id)` | `customers:read` |
|
|
69
69
|
| `customers.create({ email, name?, note? })` / `customers.update(id, { name?, note? })` / `customers.delete(id)` | `customers:write` |
|
|
70
|
+
| `levels.get()` / `levels.customer(email)` | `customers:read` |
|
|
71
|
+
| `levels.giveXp(email, amount, reason?)` | `customers:write` |
|
|
72
|
+
| `levels.setProductRule(productIds, rule)` | `products:write` |
|
|
70
73
|
| `feedback.list({ productId?, rating?, limit?, offset? })` / `feedback.get(id)` | `feedback:read` |
|
|
71
74
|
| `feedback.reply(id, { message })` / `feedback.appeal(id, { reason })` | `feedback:write` |
|
|
72
75
|
| `queries.list({ status?, limit?, offset? })` / `queries.get(id)` | `queries:read` |
|
|
@@ -143,6 +146,33 @@ Coupons take `validFrom`, `validTo` as an ISO string or a `Date`; `coupons.updat
|
|
|
143
146
|
|
|
144
147
|
`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.
|
|
145
148
|
|
|
149
|
+
## Buyer levels
|
|
150
|
+
|
|
151
|
+
When a store has levels on, buyers earn 10 XP for every unit of store currency they spend. `levels.get()` returns the ladder and any running XP boost. `levels.customer(email)` returns one buyer's XP, level and level discount. An email without an account comes back at level 1 with 0 XP. `levels.giveXp` adds XP, or takes it away with a negative amount, up to 1,000,000 at a time. The buyer needs a Skalp account, and a store with levels off answers 400 `LEVELS_DISABLED`.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const { level, xpToNext } = await skalp.levels.giveXp('buyer@example.com', 250, 'Won the weekend event')
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Each tier carries its perks: `discountPercent`, a one-time `gift` coupon, a Discord role, `gemMultiplier` for Ametysty and `gameReward` (only its `label`; the command stays private). `badgeUrl` is the image the seller uploaded for the level, or `null` for the built-in badge. `levels.customer` returns the buyer's `gemMultiplier` and `badgeUrl` too.
|
|
158
|
+
|
|
159
|
+
### Level-locked products
|
|
160
|
+
|
|
161
|
+
A product with `minLevel` can only be bought from that level up. Buyers below it still see it. Pick one of three rules:
|
|
162
|
+
|
|
163
|
+
- Level only: `minLevel` alone. The lock stays until you clear it.
|
|
164
|
+
- Early access: `minLevel` plus `earlyAccessHours` (1 to 720). That level buys first, everyone else after the hours run out. On a product that is not out yet, the hours start when it goes live; on a live product they start now and come back as `minLevelUntil`.
|
|
165
|
+
- Until a date: `minLevel` plus `minLevelUntil`.
|
|
166
|
+
|
|
167
|
+
Send `earlyAccessHours` or `minLevelUntil`, not both (400 `LEVEL_RULE_CONFLICT`). `minLevel: null` clears the rule. `products.create` and `products.update` take these fields; `levels.setProductRule` sets one rule on up to 100 products at once and returns every product that has a rule. `earlyAccessHours` is only in your own API responses, never on the storefront.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
await skalp.levels.setProductRule(['prod_1', 'prod_2'], { minLevel: 4, earlyAccessHours: 48 })
|
|
171
|
+
await skalp.levels.setProductRule(['prod_1'], null)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`customer.level_up` and `customer.level_down` are not in the default webhook list: subscribe to them by name. `data` carries `email`, `userId`, `level`, `previousLevel`, `xp` and the `tier` the buyer is on now.
|
|
175
|
+
|
|
146
176
|
## Support and access rules
|
|
147
177
|
|
|
148
178
|
`feedback` and `queries` expose product reviews and buyer conversations. `queries.reply`, `close` and `reopen` return the whole conversation with its `messages`. `blacklist` and `whitelist` use the same calls, each with its own read and write scope; a whitelisted buyer is never blocked by a blacklist rule.
|
|
@@ -196,6 +226,16 @@ A webhook with the default events receives every purchase as both `order.paid` a
|
|
|
196
226
|
|
|
197
227
|
`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.
|
|
198
228
|
|
|
229
|
+
### Renewal grace period
|
|
230
|
+
|
|
231
|
+
A store can give buyers a few days after a failed renewal. During that time the subscription is `PAST_DUE`, `graceUntil` holds the moment it ends, and the buyer keeps access until then. `currentPeriodEnd` stays at the last paid day. `subscription.past_due` comes once with `graceUntil`; a payment inside the grace sends `subscription.renewed` and clears it, and when the grace runs out `subscription.canceled` follows with `cancelReason: 'payment_failure'`. With no grace set, `graceUntil` is `null` and a failed renewal ends the subscription at once.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
if (event.type === 'subscription.past_due' && event.data.graceUntil) {
|
|
235
|
+
await keepAccessUntil(event.data.subscriptionId, new Date(event.data.graceUntil))
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
199
239
|
`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.
|
|
200
240
|
|
|
201
241
|
## Errors
|
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, UpdateSubscriptionParams, 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, CustomerLevel, LevelProductRule, LevelProducts, 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, StoreLevels, 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.11.0";
|
|
4
4
|
export interface SkalpOptions {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
webhookSecret?: string;
|
|
@@ -82,6 +82,12 @@ export declare class Skalp {
|
|
|
82
82
|
update: (id: string, { name, note }: UpdateCustomerParams) => Promise<Customer>;
|
|
83
83
|
delete: (id: string) => Promise<Deleted>;
|
|
84
84
|
};
|
|
85
|
+
readonly levels: {
|
|
86
|
+
get: () => Promise<StoreLevels>;
|
|
87
|
+
customer: (email: string) => Promise<CustomerLevel>;
|
|
88
|
+
giveXp: (email: string, amount: number, reason?: string) => Promise<CustomerLevel>;
|
|
89
|
+
setProductRule: (productIds: Array<string>, rule: LevelProductRule | null) => Promise<LevelProducts>;
|
|
90
|
+
};
|
|
85
91
|
readonly feedback: {
|
|
86
92
|
list: ({ productId, rating, limit, offset }?: ListFeedbackParams) => Promise<FeedbackList>;
|
|
87
93
|
get: (id: string) => Promise<Feedback>;
|
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.11.0';
|
|
5
5
|
const SIGNATURE_HEADER = 'skalp-signature';
|
|
6
6
|
const SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
7
7
|
const PRODUCT_PAGE = 100;
|
|
@@ -83,6 +83,9 @@ const PRODUCT_FIELDS = [
|
|
|
83
83
|
'customFields',
|
|
84
84
|
'minQuantity',
|
|
85
85
|
'maxQuantity',
|
|
86
|
+
'minLevel',
|
|
87
|
+
'minLevelUntil',
|
|
88
|
+
'earlyAccessHours',
|
|
86
89
|
'volumeDiscounts',
|
|
87
90
|
'upsells',
|
|
88
91
|
'prices',
|
|
@@ -233,6 +236,12 @@ class Skalp {
|
|
|
233
236
|
update: (id, { name, note }) => this.#request('PATCH', `/v1/customers/${segment(id)}`, { body: { name, note } }),
|
|
234
237
|
delete: (id) => this.#request('DELETE', `/v1/customers/${segment(id)}`),
|
|
235
238
|
};
|
|
239
|
+
levels = {
|
|
240
|
+
get: () => this.#request('GET', '/v1/levels'),
|
|
241
|
+
customer: (email) => this.#request('GET', `/v1/levels/customers/${segment(email)}`),
|
|
242
|
+
giveXp: (email, amount, reason) => this.#request('POST', `/v1/levels/customers/${segment(email)}/xp`, { body: { amount, reason } }),
|
|
243
|
+
setProductRule: (productIds, rule) => this.#request('PATCH', '/v1/levels/products', { body: { productIds, rule } }),
|
|
244
|
+
};
|
|
236
245
|
feedback = {
|
|
237
246
|
list: ({ productId, rating, limit, offset } = {}) => this.#request('GET', '/v1/feedback', { query: { productId, rating, limit, offset } }),
|
|
238
247
|
get: (id) => this.#request('GET', `/v1/feedback/${segment(id)}`),
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export interface Order {
|
|
|
58
58
|
serviceFee: number | null;
|
|
59
59
|
sellerPaymentFee: number | null;
|
|
60
60
|
couponCode: string | null;
|
|
61
|
+
levelDiscount?: {
|
|
62
|
+
level: number;
|
|
63
|
+
percent: number;
|
|
64
|
+
amount: number;
|
|
65
|
+
} | null;
|
|
61
66
|
productId: string;
|
|
62
67
|
productName: string;
|
|
63
68
|
productSlug: string;
|
|
@@ -249,6 +254,9 @@ export interface Product {
|
|
|
249
254
|
minQuantity: number;
|
|
250
255
|
/** null allows up to 1000. */
|
|
251
256
|
maxQuantity: number | null;
|
|
257
|
+
minLevel: number | null;
|
|
258
|
+
minLevelUntil: string | null;
|
|
259
|
+
earlyAccessHours: number | null;
|
|
252
260
|
volumeDiscounts: Array<VolumeDiscount>;
|
|
253
261
|
/** Products offered on this product's checkout page. */
|
|
254
262
|
upsells: Array<ProductUpsell>;
|
|
@@ -322,6 +330,9 @@ interface ProductFields {
|
|
|
322
330
|
/** SERIAL, LICENSE, SERVICE and GAME one-time products only. */
|
|
323
331
|
minQuantity?: number;
|
|
324
332
|
maxQuantity?: number | null;
|
|
333
|
+
minLevel?: number | null;
|
|
334
|
+
minLevelUntil?: string | Date | null;
|
|
335
|
+
earlyAccessHours?: number | null;
|
|
325
336
|
/** Up to 10 tiers; the list replaces the old one, [] or null removes them all. */
|
|
326
337
|
volumeDiscounts?: Array<VolumeDiscount> | null;
|
|
327
338
|
/** Up to 3 one-time products of the store; the list replaces the old one, [] or null removes them all. */
|
|
@@ -580,6 +591,65 @@ export interface UpdateCustomerParams {
|
|
|
580
591
|
name?: string | null;
|
|
581
592
|
note?: string | null;
|
|
582
593
|
}
|
|
594
|
+
export type LevelGiftType = 'PERCENT' | 'FIXED';
|
|
595
|
+
export interface LevelGift {
|
|
596
|
+
type: LevelGiftType;
|
|
597
|
+
value: number;
|
|
598
|
+
}
|
|
599
|
+
export interface LevelTier {
|
|
600
|
+
level: number;
|
|
601
|
+
xp: number;
|
|
602
|
+
name: string | null;
|
|
603
|
+
discountPercent: number;
|
|
604
|
+
gift: LevelGift | null;
|
|
605
|
+
discordRoleId: string | null;
|
|
606
|
+
discordRoleName: string | null;
|
|
607
|
+
gemMultiplier: number;
|
|
608
|
+
gameReward: LevelGameReward | null;
|
|
609
|
+
badgeUrl: string | null;
|
|
610
|
+
}
|
|
611
|
+
export interface LevelGameReward {
|
|
612
|
+
label: string;
|
|
613
|
+
}
|
|
614
|
+
export interface LevelBoost {
|
|
615
|
+
multiplier: number;
|
|
616
|
+
endsAt: string;
|
|
617
|
+
}
|
|
618
|
+
export interface StoreLevels {
|
|
619
|
+
enabled: boolean;
|
|
620
|
+
xpPerUnit: number;
|
|
621
|
+
tiers: Array<LevelTier>;
|
|
622
|
+
boost: LevelBoost | null;
|
|
623
|
+
}
|
|
624
|
+
export interface LevelProductRule {
|
|
625
|
+
minLevel: number;
|
|
626
|
+
minLevelUntil?: string | Date | null;
|
|
627
|
+
earlyAccessHours?: number | null;
|
|
628
|
+
}
|
|
629
|
+
export interface LevelProduct {
|
|
630
|
+
id: string;
|
|
631
|
+
name: string;
|
|
632
|
+
slug: string;
|
|
633
|
+
status: ProductStatus;
|
|
634
|
+
image: string | null;
|
|
635
|
+
minLevel: number | null;
|
|
636
|
+
minLevelUntil: string | null;
|
|
637
|
+
earlyAccessHours: number | null;
|
|
638
|
+
}
|
|
639
|
+
export interface LevelProducts {
|
|
640
|
+
products: Array<LevelProduct>;
|
|
641
|
+
}
|
|
642
|
+
export interface CustomerLevel {
|
|
643
|
+
email: string;
|
|
644
|
+
xp: number;
|
|
645
|
+
level: number;
|
|
646
|
+
next: LevelTier | null;
|
|
647
|
+
xpToNext: number;
|
|
648
|
+
progress: number;
|
|
649
|
+
discountPercent: number;
|
|
650
|
+
gemMultiplier: number;
|
|
651
|
+
badgeUrl: string | null;
|
|
652
|
+
}
|
|
583
653
|
export interface FeedbackReply {
|
|
584
654
|
id: string;
|
|
585
655
|
content: string;
|
|
@@ -721,6 +791,7 @@ export interface Subscription {
|
|
|
721
791
|
cancelAtPeriodEnd: boolean;
|
|
722
792
|
canceledAt: string | null;
|
|
723
793
|
trialEnd: string | null;
|
|
794
|
+
graceUntil: string | null;
|
|
724
795
|
buyerEmail: string;
|
|
725
796
|
metadata: Metadata;
|
|
726
797
|
createdAt: string;
|
|
@@ -962,6 +1033,7 @@ export interface SubscriptionEventData {
|
|
|
962
1033
|
cancelAtPeriodEnd: boolean;
|
|
963
1034
|
canceledAt: string | null;
|
|
964
1035
|
trialEnd: string | null;
|
|
1036
|
+
graceUntil: string | null;
|
|
965
1037
|
metadata: Metadata;
|
|
966
1038
|
identifier: string | null;
|
|
967
1039
|
steamhex: string | null;
|
|
@@ -1052,6 +1124,15 @@ export interface SubscriptionCheckoutExpiredData {
|
|
|
1052
1124
|
currency: string;
|
|
1053
1125
|
metadata: Record<string, unknown>;
|
|
1054
1126
|
}
|
|
1127
|
+
export interface CustomerLevelEventData {
|
|
1128
|
+
storeId: string;
|
|
1129
|
+
email: string | null;
|
|
1130
|
+
userId: string;
|
|
1131
|
+
level: number;
|
|
1132
|
+
previousLevel: number;
|
|
1133
|
+
xp: number;
|
|
1134
|
+
tier: LevelTier;
|
|
1135
|
+
}
|
|
1055
1136
|
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 & {
|
|
1056
1137
|
amountDue: number;
|
|
1057
1138
|
nextPaymentAttempt: string | null;
|
|
@@ -1060,9 +1141,9 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1060
1141
|
amountPaid: number;
|
|
1061
1142
|
periodExtendedTo: string;
|
|
1062
1143
|
}> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1063
|
-
invoiceId
|
|
1064
|
-
attemptCount
|
|
1065
|
-
nextPaymentAttempt
|
|
1144
|
+
invoiceId?: string;
|
|
1145
|
+
attemptCount?: number;
|
|
1146
|
+
nextPaymentAttempt?: string | null;
|
|
1066
1147
|
}> | Envelope<'subscription.canceled', SubscriptionEventData & {
|
|
1067
1148
|
endedAt: string | null;
|
|
1068
1149
|
cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe' | 'expired';
|
|
@@ -1076,6 +1157,6 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1076
1157
|
disputeId: string;
|
|
1077
1158
|
disputeStatus: 'open' | 'won' | 'lost';
|
|
1078
1159
|
disputeReason: string | null;
|
|
1079
|
-
}> | Envelope<'product.created' | 'product.updated', ProductEventData> | Envelope<'product.stock', ProductStockData> | Envelope<'query.created' | 'query.replied', QueryEventData> | Envelope<'feedback.received', FeedbackReceivedData> | Envelope<'webhook.test', WebhookTestData>;
|
|
1160
|
+
}> | Envelope<'product.created' | 'product.updated', ProductEventData> | Envelope<'product.stock', ProductStockData> | Envelope<'query.created' | 'query.replied', QueryEventData> | Envelope<'feedback.received', FeedbackReceivedData> | Envelope<'customer.level_up' | 'customer.level_down', CustomerLevelEventData> | Envelope<'webhook.test', WebhookTestData>;
|
|
1080
1161
|
export type SkalpEventType = SkalpEvent['type'];
|
|
1081
1162
|
export {};
|
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, UpdateSubscriptionParams, 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, CustomerLevel, LevelProductRule, LevelProducts, 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, StoreLevels, 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.11.0";
|
|
4
4
|
export interface SkalpOptions {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
webhookSecret?: string;
|
|
@@ -82,6 +82,12 @@ export declare class Skalp {
|
|
|
82
82
|
update: (id: string, { name, note }: UpdateCustomerParams) => Promise<Customer>;
|
|
83
83
|
delete: (id: string) => Promise<Deleted>;
|
|
84
84
|
};
|
|
85
|
+
readonly levels: {
|
|
86
|
+
get: () => Promise<StoreLevels>;
|
|
87
|
+
customer: (email: string) => Promise<CustomerLevel>;
|
|
88
|
+
giveXp: (email: string, amount: number, reason?: string) => Promise<CustomerLevel>;
|
|
89
|
+
setProductRule: (productIds: Array<string>, rule: LevelProductRule | null) => Promise<LevelProducts>;
|
|
90
|
+
};
|
|
85
91
|
readonly feedback: {
|
|
86
92
|
list: ({ productId, rating, limit, offset }?: ListFeedbackParams) => Promise<FeedbackList>;
|
|
87
93
|
get: (id: string) => Promise<Feedback>;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const VERSION = '1.
|
|
1
|
+
export const VERSION = '1.11.0';
|
|
2
2
|
const SIGNATURE_HEADER = 'skalp-signature';
|
|
3
3
|
const SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
4
4
|
const PRODUCT_PAGE = 100;
|
|
@@ -77,6 +77,9 @@ const PRODUCT_FIELDS = [
|
|
|
77
77
|
'customFields',
|
|
78
78
|
'minQuantity',
|
|
79
79
|
'maxQuantity',
|
|
80
|
+
'minLevel',
|
|
81
|
+
'minLevelUntil',
|
|
82
|
+
'earlyAccessHours',
|
|
80
83
|
'volumeDiscounts',
|
|
81
84
|
'upsells',
|
|
82
85
|
'prices',
|
|
@@ -227,6 +230,12 @@ export class Skalp {
|
|
|
227
230
|
update: (id, { name, note }) => this.#request('PATCH', `/v1/customers/${segment(id)}`, { body: { name, note } }),
|
|
228
231
|
delete: (id) => this.#request('DELETE', `/v1/customers/${segment(id)}`),
|
|
229
232
|
};
|
|
233
|
+
levels = {
|
|
234
|
+
get: () => this.#request('GET', '/v1/levels'),
|
|
235
|
+
customer: (email) => this.#request('GET', `/v1/levels/customers/${segment(email)}`),
|
|
236
|
+
giveXp: (email, amount, reason) => this.#request('POST', `/v1/levels/customers/${segment(email)}/xp`, { body: { amount, reason } }),
|
|
237
|
+
setProductRule: (productIds, rule) => this.#request('PATCH', '/v1/levels/products', { body: { productIds, rule } }),
|
|
238
|
+
};
|
|
230
239
|
feedback = {
|
|
231
240
|
list: ({ productId, rating, limit, offset } = {}) => this.#request('GET', '/v1/feedback', { query: { productId, rating, limit, offset } }),
|
|
232
241
|
get: (id) => this.#request('GET', `/v1/feedback/${segment(id)}`),
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export interface Order {
|
|
|
58
58
|
serviceFee: number | null;
|
|
59
59
|
sellerPaymentFee: number | null;
|
|
60
60
|
couponCode: string | null;
|
|
61
|
+
levelDiscount?: {
|
|
62
|
+
level: number;
|
|
63
|
+
percent: number;
|
|
64
|
+
amount: number;
|
|
65
|
+
} | null;
|
|
61
66
|
productId: string;
|
|
62
67
|
productName: string;
|
|
63
68
|
productSlug: string;
|
|
@@ -249,6 +254,9 @@ export interface Product {
|
|
|
249
254
|
minQuantity: number;
|
|
250
255
|
/** null allows up to 1000. */
|
|
251
256
|
maxQuantity: number | null;
|
|
257
|
+
minLevel: number | null;
|
|
258
|
+
minLevelUntil: string | null;
|
|
259
|
+
earlyAccessHours: number | null;
|
|
252
260
|
volumeDiscounts: Array<VolumeDiscount>;
|
|
253
261
|
/** Products offered on this product's checkout page. */
|
|
254
262
|
upsells: Array<ProductUpsell>;
|
|
@@ -322,6 +330,9 @@ interface ProductFields {
|
|
|
322
330
|
/** SERIAL, LICENSE, SERVICE and GAME one-time products only. */
|
|
323
331
|
minQuantity?: number;
|
|
324
332
|
maxQuantity?: number | null;
|
|
333
|
+
minLevel?: number | null;
|
|
334
|
+
minLevelUntil?: string | Date | null;
|
|
335
|
+
earlyAccessHours?: number | null;
|
|
325
336
|
/** Up to 10 tiers; the list replaces the old one, [] or null removes them all. */
|
|
326
337
|
volumeDiscounts?: Array<VolumeDiscount> | null;
|
|
327
338
|
/** Up to 3 one-time products of the store; the list replaces the old one, [] or null removes them all. */
|
|
@@ -580,6 +591,65 @@ export interface UpdateCustomerParams {
|
|
|
580
591
|
name?: string | null;
|
|
581
592
|
note?: string | null;
|
|
582
593
|
}
|
|
594
|
+
export type LevelGiftType = 'PERCENT' | 'FIXED';
|
|
595
|
+
export interface LevelGift {
|
|
596
|
+
type: LevelGiftType;
|
|
597
|
+
value: number;
|
|
598
|
+
}
|
|
599
|
+
export interface LevelTier {
|
|
600
|
+
level: number;
|
|
601
|
+
xp: number;
|
|
602
|
+
name: string | null;
|
|
603
|
+
discountPercent: number;
|
|
604
|
+
gift: LevelGift | null;
|
|
605
|
+
discordRoleId: string | null;
|
|
606
|
+
discordRoleName: string | null;
|
|
607
|
+
gemMultiplier: number;
|
|
608
|
+
gameReward: LevelGameReward | null;
|
|
609
|
+
badgeUrl: string | null;
|
|
610
|
+
}
|
|
611
|
+
export interface LevelGameReward {
|
|
612
|
+
label: string;
|
|
613
|
+
}
|
|
614
|
+
export interface LevelBoost {
|
|
615
|
+
multiplier: number;
|
|
616
|
+
endsAt: string;
|
|
617
|
+
}
|
|
618
|
+
export interface StoreLevels {
|
|
619
|
+
enabled: boolean;
|
|
620
|
+
xpPerUnit: number;
|
|
621
|
+
tiers: Array<LevelTier>;
|
|
622
|
+
boost: LevelBoost | null;
|
|
623
|
+
}
|
|
624
|
+
export interface LevelProductRule {
|
|
625
|
+
minLevel: number;
|
|
626
|
+
minLevelUntil?: string | Date | null;
|
|
627
|
+
earlyAccessHours?: number | null;
|
|
628
|
+
}
|
|
629
|
+
export interface LevelProduct {
|
|
630
|
+
id: string;
|
|
631
|
+
name: string;
|
|
632
|
+
slug: string;
|
|
633
|
+
status: ProductStatus;
|
|
634
|
+
image: string | null;
|
|
635
|
+
minLevel: number | null;
|
|
636
|
+
minLevelUntil: string | null;
|
|
637
|
+
earlyAccessHours: number | null;
|
|
638
|
+
}
|
|
639
|
+
export interface LevelProducts {
|
|
640
|
+
products: Array<LevelProduct>;
|
|
641
|
+
}
|
|
642
|
+
export interface CustomerLevel {
|
|
643
|
+
email: string;
|
|
644
|
+
xp: number;
|
|
645
|
+
level: number;
|
|
646
|
+
next: LevelTier | null;
|
|
647
|
+
xpToNext: number;
|
|
648
|
+
progress: number;
|
|
649
|
+
discountPercent: number;
|
|
650
|
+
gemMultiplier: number;
|
|
651
|
+
badgeUrl: string | null;
|
|
652
|
+
}
|
|
583
653
|
export interface FeedbackReply {
|
|
584
654
|
id: string;
|
|
585
655
|
content: string;
|
|
@@ -721,6 +791,7 @@ export interface Subscription {
|
|
|
721
791
|
cancelAtPeriodEnd: boolean;
|
|
722
792
|
canceledAt: string | null;
|
|
723
793
|
trialEnd: string | null;
|
|
794
|
+
graceUntil: string | null;
|
|
724
795
|
buyerEmail: string;
|
|
725
796
|
metadata: Metadata;
|
|
726
797
|
createdAt: string;
|
|
@@ -962,6 +1033,7 @@ export interface SubscriptionEventData {
|
|
|
962
1033
|
cancelAtPeriodEnd: boolean;
|
|
963
1034
|
canceledAt: string | null;
|
|
964
1035
|
trialEnd: string | null;
|
|
1036
|
+
graceUntil: string | null;
|
|
965
1037
|
metadata: Metadata;
|
|
966
1038
|
identifier: string | null;
|
|
967
1039
|
steamhex: string | null;
|
|
@@ -1052,6 +1124,15 @@ export interface SubscriptionCheckoutExpiredData {
|
|
|
1052
1124
|
currency: string;
|
|
1053
1125
|
metadata: Record<string, unknown>;
|
|
1054
1126
|
}
|
|
1127
|
+
export interface CustomerLevelEventData {
|
|
1128
|
+
storeId: string;
|
|
1129
|
+
email: string | null;
|
|
1130
|
+
userId: string;
|
|
1131
|
+
level: number;
|
|
1132
|
+
previousLevel: number;
|
|
1133
|
+
xp: number;
|
|
1134
|
+
tier: LevelTier;
|
|
1135
|
+
}
|
|
1055
1136
|
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 & {
|
|
1056
1137
|
amountDue: number;
|
|
1057
1138
|
nextPaymentAttempt: string | null;
|
|
@@ -1060,9 +1141,9 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1060
1141
|
amountPaid: number;
|
|
1061
1142
|
periodExtendedTo: string;
|
|
1062
1143
|
}> | Envelope<'subscription.checkout_expired', SubscriptionCheckoutExpiredData> | Envelope<'subscription.past_due', SubscriptionEventData & {
|
|
1063
|
-
invoiceId
|
|
1064
|
-
attemptCount
|
|
1065
|
-
nextPaymentAttempt
|
|
1144
|
+
invoiceId?: string;
|
|
1145
|
+
attemptCount?: number;
|
|
1146
|
+
nextPaymentAttempt?: string | null;
|
|
1066
1147
|
}> | Envelope<'subscription.canceled', SubscriptionEventData & {
|
|
1067
1148
|
endedAt: string | null;
|
|
1068
1149
|
cancelReason: 'requested' | 'payment_failure' | 'dispute' | 'stripe' | 'expired';
|
|
@@ -1076,6 +1157,6 @@ export type SkalpEvent = Envelope<'order.created' | 'order.updated' | 'order.can
|
|
|
1076
1157
|
disputeId: string;
|
|
1077
1158
|
disputeStatus: 'open' | 'won' | 'lost';
|
|
1078
1159
|
disputeReason: string | null;
|
|
1079
|
-
}> | Envelope<'product.created' | 'product.updated', ProductEventData> | Envelope<'product.stock', ProductStockData> | Envelope<'query.created' | 'query.replied', QueryEventData> | Envelope<'feedback.received', FeedbackReceivedData> | Envelope<'webhook.test', WebhookTestData>;
|
|
1160
|
+
}> | Envelope<'product.created' | 'product.updated', ProductEventData> | Envelope<'product.stock', ProductStockData> | Envelope<'query.created' | 'query.replied', QueryEventData> | Envelope<'feedback.received', FeedbackReceivedData> | Envelope<'customer.level_up' | 'customer.level_down', CustomerLevelEventData> | Envelope<'webhook.test', WebhookTestData>;
|
|
1080
1161
|
export type SkalpEventType = SkalpEvent['type'];
|
|
1081
1162
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skalpgg/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|