@waffo/pancake-ts 0.2.0 → 0.2.2
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/CHANGELOG.md +27 -0
- package/dist/index.cjs +175 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -9
- package/dist/index.d.ts +34 -9
- package/dist/index.js +175 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,18 @@ interface WaffoPancakeConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link HttpClient.post}.
|
|
23
|
+
* Not exported publicly — used by resource classes.
|
|
24
|
+
*/
|
|
25
|
+
interface PostOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Time window in seconds for idempotency key rotation.
|
|
28
|
+
* When set, a floored timestamp is mixed into the key so identical params
|
|
29
|
+
* produce a new key after the window elapses (e.g. 60 = per-minute dedup).
|
|
30
|
+
*/
|
|
31
|
+
idempotencyWindow?: number;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Single error object within the `errors` array.
|
|
23
35
|
*
|
|
@@ -150,11 +162,14 @@ declare enum PaymentStatus {
|
|
|
150
162
|
*/
|
|
151
163
|
declare enum RefundTicketStatus {
|
|
152
164
|
Pending = "pending",
|
|
165
|
+
UnderReview = "under_review",
|
|
153
166
|
Approved = "approved",
|
|
154
167
|
Rejected = "rejected",
|
|
168
|
+
Returned = "returned",
|
|
155
169
|
Processing = "processing",
|
|
156
170
|
Succeeded = "succeeded",
|
|
157
|
-
Failed = "failed"
|
|
171
|
+
Failed = "failed",
|
|
172
|
+
Cancelled = "cancelled"
|
|
158
173
|
}
|
|
159
174
|
/**
|
|
160
175
|
* Refund status.
|
|
@@ -191,7 +206,9 @@ declare enum ErrorLayer {
|
|
|
191
206
|
GraphQL = "graphql",
|
|
192
207
|
Resource = "resource",
|
|
193
208
|
/** SDK-specific layer for email delivery errors (not part of the service-side error layers). */
|
|
194
|
-
Email = "email"
|
|
209
|
+
Email = "email",
|
|
210
|
+
/** SDK-side input validation (caught before network request). */
|
|
211
|
+
Sdk = "sdk"
|
|
195
212
|
}
|
|
196
213
|
/**
|
|
197
214
|
* Parameters for issuing a buyer session token.
|
|
@@ -367,7 +384,7 @@ interface UpdateRoleResult {
|
|
|
367
384
|
*
|
|
368
385
|
* @example
|
|
369
386
|
* // JPY ¥1000
|
|
370
|
-
* { amount: 1000, taxCategory: "software" }
|
|
387
|
+
* { amount: "1000", taxCategory: "software" }
|
|
371
388
|
*/
|
|
372
389
|
interface PriceInfo {
|
|
373
390
|
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
@@ -383,7 +400,7 @@ interface PriceInfo {
|
|
|
383
400
|
* @example
|
|
384
401
|
* {
|
|
385
402
|
* "USD": { amount: "9.99", taxCategory: "saas" },
|
|
386
|
-
* "EUR": { amount:
|
|
403
|
+
* "EUR": { amount: "8.99", taxCategory: "saas" }
|
|
387
404
|
* }
|
|
388
405
|
*/
|
|
389
406
|
type Prices = Record<string, PriceInfo>;
|
|
@@ -710,7 +727,7 @@ interface RefundTicket {
|
|
|
710
727
|
/** Submitter type (e.g., `"customer"`, `"merchant"`) */
|
|
711
728
|
submitterType: string;
|
|
712
729
|
/** Current version ID */
|
|
713
|
-
currentVersionId: string;
|
|
730
|
+
currentVersionId: string | null;
|
|
714
731
|
/** Reviewer ID (null if not yet reviewed) */
|
|
715
732
|
reviewerId: string | null;
|
|
716
733
|
/** Review timestamp (ISO 8601, null if not yet reviewed) */
|
|
@@ -724,9 +741,13 @@ interface RefundTicket {
|
|
|
724
741
|
/** Custom metadata */
|
|
725
742
|
metadata: Record<string, unknown>;
|
|
726
743
|
/** Current version number */
|
|
727
|
-
versionNumber: number;
|
|
744
|
+
versionNumber: number | null;
|
|
728
745
|
/** Current version data (includes reason, amount, etc.) */
|
|
729
|
-
versionData: Record<string, unknown
|
|
746
|
+
versionData: Record<string, unknown> | null;
|
|
747
|
+
/** Creation timestamp (ISO 8601) */
|
|
748
|
+
createdAt: string;
|
|
749
|
+
/** Last update timestamp (ISO 8601) */
|
|
750
|
+
updatedAt: string;
|
|
730
751
|
}
|
|
731
752
|
/**
|
|
732
753
|
* Parameters for anonymous checkout.
|
|
@@ -898,7 +919,7 @@ interface WebhookEventData {
|
|
|
898
919
|
* eventId: "PAY_5xK9mRtYvWnPqLsJ3hBfDe",
|
|
899
920
|
* storeId: "STO_2aUyqjCzEIiEcYMKj7TZtw",
|
|
900
921
|
* mode: "prod",
|
|
901
|
-
* data: { orderId: "...", buyerEmail: "...", currency: "USD", amount:
|
|
922
|
+
* data: { orderId: "...", buyerEmail: "...", currency: "USD", amount: "29.00", taxAmount: "2.90", productName: "Pro Plan" }
|
|
902
923
|
* }
|
|
903
924
|
*/
|
|
904
925
|
interface WebhookEvent<T = WebhookEventData> {
|
|
@@ -980,15 +1001,19 @@ declare class HttpClient {
|
|
|
980
1001
|
*
|
|
981
1002
|
* Behavior:
|
|
982
1003
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
1004
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
1005
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
983
1006
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
984
1007
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
985
1008
|
*
|
|
986
1009
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
987
1010
|
* @param body - Request body object
|
|
1011
|
+
* @param options - Optional settings
|
|
1012
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
988
1013
|
* @returns Parsed `data` field from the response
|
|
989
1014
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
990
1015
|
*/
|
|
991
|
-
post<T>(path: string, body: object): Promise<T>;
|
|
1016
|
+
post<T>(path: string, body: object, options?: PostOptions): Promise<T>;
|
|
992
1017
|
}
|
|
993
1018
|
|
|
994
1019
|
/** Authentication resource — issue session tokens for buyers. */
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,18 @@ interface WaffoPancakeConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link HttpClient.post}.
|
|
23
|
+
* Not exported publicly — used by resource classes.
|
|
24
|
+
*/
|
|
25
|
+
interface PostOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Time window in seconds for idempotency key rotation.
|
|
28
|
+
* When set, a floored timestamp is mixed into the key so identical params
|
|
29
|
+
* produce a new key after the window elapses (e.g. 60 = per-minute dedup).
|
|
30
|
+
*/
|
|
31
|
+
idempotencyWindow?: number;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Single error object within the `errors` array.
|
|
23
35
|
*
|
|
@@ -150,11 +162,14 @@ declare enum PaymentStatus {
|
|
|
150
162
|
*/
|
|
151
163
|
declare enum RefundTicketStatus {
|
|
152
164
|
Pending = "pending",
|
|
165
|
+
UnderReview = "under_review",
|
|
153
166
|
Approved = "approved",
|
|
154
167
|
Rejected = "rejected",
|
|
168
|
+
Returned = "returned",
|
|
155
169
|
Processing = "processing",
|
|
156
170
|
Succeeded = "succeeded",
|
|
157
|
-
Failed = "failed"
|
|
171
|
+
Failed = "failed",
|
|
172
|
+
Cancelled = "cancelled"
|
|
158
173
|
}
|
|
159
174
|
/**
|
|
160
175
|
* Refund status.
|
|
@@ -191,7 +206,9 @@ declare enum ErrorLayer {
|
|
|
191
206
|
GraphQL = "graphql",
|
|
192
207
|
Resource = "resource",
|
|
193
208
|
/** SDK-specific layer for email delivery errors (not part of the service-side error layers). */
|
|
194
|
-
Email = "email"
|
|
209
|
+
Email = "email",
|
|
210
|
+
/** SDK-side input validation (caught before network request). */
|
|
211
|
+
Sdk = "sdk"
|
|
195
212
|
}
|
|
196
213
|
/**
|
|
197
214
|
* Parameters for issuing a buyer session token.
|
|
@@ -367,7 +384,7 @@ interface UpdateRoleResult {
|
|
|
367
384
|
*
|
|
368
385
|
* @example
|
|
369
386
|
* // JPY ¥1000
|
|
370
|
-
* { amount: 1000, taxCategory: "software" }
|
|
387
|
+
* { amount: "1000", taxCategory: "software" }
|
|
371
388
|
*/
|
|
372
389
|
interface PriceInfo {
|
|
373
390
|
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
@@ -383,7 +400,7 @@ interface PriceInfo {
|
|
|
383
400
|
* @example
|
|
384
401
|
* {
|
|
385
402
|
* "USD": { amount: "9.99", taxCategory: "saas" },
|
|
386
|
-
* "EUR": { amount:
|
|
403
|
+
* "EUR": { amount: "8.99", taxCategory: "saas" }
|
|
387
404
|
* }
|
|
388
405
|
*/
|
|
389
406
|
type Prices = Record<string, PriceInfo>;
|
|
@@ -710,7 +727,7 @@ interface RefundTicket {
|
|
|
710
727
|
/** Submitter type (e.g., `"customer"`, `"merchant"`) */
|
|
711
728
|
submitterType: string;
|
|
712
729
|
/** Current version ID */
|
|
713
|
-
currentVersionId: string;
|
|
730
|
+
currentVersionId: string | null;
|
|
714
731
|
/** Reviewer ID (null if not yet reviewed) */
|
|
715
732
|
reviewerId: string | null;
|
|
716
733
|
/** Review timestamp (ISO 8601, null if not yet reviewed) */
|
|
@@ -724,9 +741,13 @@ interface RefundTicket {
|
|
|
724
741
|
/** Custom metadata */
|
|
725
742
|
metadata: Record<string, unknown>;
|
|
726
743
|
/** Current version number */
|
|
727
|
-
versionNumber: number;
|
|
744
|
+
versionNumber: number | null;
|
|
728
745
|
/** Current version data (includes reason, amount, etc.) */
|
|
729
|
-
versionData: Record<string, unknown
|
|
746
|
+
versionData: Record<string, unknown> | null;
|
|
747
|
+
/** Creation timestamp (ISO 8601) */
|
|
748
|
+
createdAt: string;
|
|
749
|
+
/** Last update timestamp (ISO 8601) */
|
|
750
|
+
updatedAt: string;
|
|
730
751
|
}
|
|
731
752
|
/**
|
|
732
753
|
* Parameters for anonymous checkout.
|
|
@@ -898,7 +919,7 @@ interface WebhookEventData {
|
|
|
898
919
|
* eventId: "PAY_5xK9mRtYvWnPqLsJ3hBfDe",
|
|
899
920
|
* storeId: "STO_2aUyqjCzEIiEcYMKj7TZtw",
|
|
900
921
|
* mode: "prod",
|
|
901
|
-
* data: { orderId: "...", buyerEmail: "...", currency: "USD", amount:
|
|
922
|
+
* data: { orderId: "...", buyerEmail: "...", currency: "USD", amount: "29.00", taxAmount: "2.90", productName: "Pro Plan" }
|
|
902
923
|
* }
|
|
903
924
|
*/
|
|
904
925
|
interface WebhookEvent<T = WebhookEventData> {
|
|
@@ -980,15 +1001,19 @@ declare class HttpClient {
|
|
|
980
1001
|
*
|
|
981
1002
|
* Behavior:
|
|
982
1003
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
1004
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
1005
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
983
1006
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
984
1007
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
985
1008
|
*
|
|
986
1009
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
987
1010
|
* @param body - Request body object
|
|
1011
|
+
* @param options - Optional settings
|
|
1012
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
988
1013
|
* @returns Parsed `data` field from the response
|
|
989
1014
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
990
1015
|
*/
|
|
991
|
-
post<T>(path: string, body: object): Promise<T>;
|
|
1016
|
+
post<T>(path: string, body: object, options?: PostOptions): Promise<T>;
|
|
992
1017
|
}
|
|
993
1018
|
|
|
994
1019
|
/** Authentication resource — issue session tokens for buyers. */
|
package/dist/index.js
CHANGED
|
@@ -179,18 +179,26 @@ var HttpClient = class {
|
|
|
179
179
|
*
|
|
180
180
|
* Behavior:
|
|
181
181
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
182
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
183
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
182
184
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
183
185
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
184
186
|
*
|
|
185
187
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
186
188
|
* @param body - Request body object
|
|
189
|
+
* @param options - Optional settings
|
|
190
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
187
191
|
* @returns Parsed `data` field from the response
|
|
188
192
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
189
193
|
*/
|
|
190
|
-
async post(path, body) {
|
|
194
|
+
async post(path, body, options) {
|
|
191
195
|
const bodyStr = JSON.stringify(body);
|
|
192
|
-
const
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
const timestampSec = Math.floor(now / 1e3);
|
|
198
|
+
const timestamp = timestampSec.toString();
|
|
193
199
|
const signature = signRequest("POST", path, timestamp, bodyStr, this.privateKey);
|
|
200
|
+
const idempotencyBase = `${this.merchantId}:${path}:${bodyStr}`;
|
|
201
|
+
const idempotencyInput = options?.idempotencyWindow ? `${idempotencyBase}:${Math.floor(timestampSec / options.idempotencyWindow)}` : idempotencyBase;
|
|
194
202
|
const response = await this._fetch(`${this.baseUrl}${path}`, {
|
|
195
203
|
method: "POST",
|
|
196
204
|
headers: {
|
|
@@ -198,7 +206,7 @@ var HttpClient = class {
|
|
|
198
206
|
"X-Merchant-Id": this.merchantId,
|
|
199
207
|
"X-Timestamp": timestamp,
|
|
200
208
|
"X-Signature": signature,
|
|
201
|
-
"X-Idempotency-Key": createHash2("sha256").update(
|
|
209
|
+
"X-Idempotency-Key": createHash2("sha256").update(idempotencyInput).digest("hex")
|
|
202
210
|
},
|
|
203
211
|
body: bodyStr
|
|
204
212
|
});
|
|
@@ -210,6 +218,105 @@ var HttpClient = class {
|
|
|
210
218
|
}
|
|
211
219
|
};
|
|
212
220
|
|
|
221
|
+
// src/validation.ts
|
|
222
|
+
var SHORT_ID_REGEX = /^[A-Z]{2,4}_[A-Za-z0-9]+$/;
|
|
223
|
+
var CURRENCY_CODE_REGEX = /^[A-Z]{3}$/;
|
|
224
|
+
var COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
|
|
225
|
+
var AMOUNT_STRING_REGEX = /^\d+(\.\d+)?$/;
|
|
226
|
+
var SHORT_ID_LABELS = {
|
|
227
|
+
STO: "Store",
|
|
228
|
+
PROD: "Product",
|
|
229
|
+
ORD: "Order",
|
|
230
|
+
PAY: "Payment",
|
|
231
|
+
REF: "Refund",
|
|
232
|
+
TKT: "Ticket",
|
|
233
|
+
MER: "Merchant"
|
|
234
|
+
};
|
|
235
|
+
function fail(message) {
|
|
236
|
+
throw new WaffoPancakeError(400, [{ message, layer: "sdk" }]);
|
|
237
|
+
}
|
|
238
|
+
function validateRequired(field, value) {
|
|
239
|
+
if (value === void 0 || value === null) {
|
|
240
|
+
fail(`Missing required field: ${field}`);
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
243
|
+
fail(`${field} cannot be empty`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function validateShortId(field, value, prefix) {
|
|
247
|
+
validateRequired(field, value);
|
|
248
|
+
const label = SHORT_ID_LABELS[prefix] ?? prefix;
|
|
249
|
+
if (!SHORT_ID_REGEX.test(value)) {
|
|
250
|
+
fail(`Invalid ${field}: expected ${label} Short ID format (${prefix}_xxx), got "${value}"`);
|
|
251
|
+
}
|
|
252
|
+
if (!value.startsWith(`${prefix}_`)) {
|
|
253
|
+
fail(`Invalid ${field}: expected ${prefix}_ prefix (${label}), got "${value.split("_")[0]}_"`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function validateCurrencyCode(field, value) {
|
|
257
|
+
validateRequired(field, value);
|
|
258
|
+
if (!CURRENCY_CODE_REGEX.test(value)) {
|
|
259
|
+
fail(`Invalid ${field}: expected 3-letter ISO 4217 currency code (e.g., "USD"), got "${value}"`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function validateAmountString(field, value) {
|
|
263
|
+
validateRequired(field, value);
|
|
264
|
+
if (!AMOUNT_STRING_REGEX.test(value)) {
|
|
265
|
+
fail(`Invalid ${field}: expected numeric string in display format (e.g., "9.99", "1000"), got "${value}"`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function validateEnum(field, value, allowed) {
|
|
269
|
+
validateRequired(field, value);
|
|
270
|
+
if (!allowed.includes(value)) {
|
|
271
|
+
fail(`Invalid ${field}: expected one of [${allowed.join(", ")}], got "${value}"`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function validatePositiveInteger(field, value) {
|
|
275
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
276
|
+
fail(`Invalid ${field}: expected positive integer, got ${value}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function validateCountryCode(field, value) {
|
|
280
|
+
validateRequired(field, value);
|
|
281
|
+
if (!COUNTRY_CODE_REGEX.test(value)) {
|
|
282
|
+
fail(`Invalid ${field}: expected 2-letter ISO 3166-1 country code (e.g., "US"), got "${value}"`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function validatePrices(field, prices) {
|
|
286
|
+
validateRequired(field, prices);
|
|
287
|
+
const entries = Object.entries(prices);
|
|
288
|
+
if (entries.length === 0) {
|
|
289
|
+
fail(`${field} must contain at least one currency`);
|
|
290
|
+
}
|
|
291
|
+
for (const [currency, info] of entries) {
|
|
292
|
+
validateCurrencyCode(`${field}.${currency} (key)`, currency);
|
|
293
|
+
validateAmountString(`${field}.${currency}.amount`, info.amount);
|
|
294
|
+
validateRequired(`${field}.${currency}.taxCategory`, info.taxCategory);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function validateBillingDetail(detail) {
|
|
298
|
+
validateCountryCode("billingDetail.country", detail.country);
|
|
299
|
+
if (typeof detail.isBusiness !== "boolean") {
|
|
300
|
+
fail(`Invalid billingDetail.isBusiness: expected boolean, got ${typeof detail.isBusiness}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function validateCheckoutCommon(params) {
|
|
304
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
305
|
+
validateShortId("productId", params.productId, "PROD");
|
|
306
|
+
validateEnum("productType", params.productType, ["onetime", "subscription"]);
|
|
307
|
+
validateCurrencyCode("currency", params.currency);
|
|
308
|
+
if (params.priceSnapshot) {
|
|
309
|
+
validateAmountString("priceSnapshot.amount", params.priceSnapshot.amount);
|
|
310
|
+
validateRequired("priceSnapshot.taxCategory", params.priceSnapshot.taxCategory);
|
|
311
|
+
}
|
|
312
|
+
if (params.billingDetail) {
|
|
313
|
+
validateBillingDetail(params.billingDetail);
|
|
314
|
+
}
|
|
315
|
+
if (params.expiresInSeconds !== void 0) {
|
|
316
|
+
validatePositiveInteger("expiresInSeconds", params.expiresInSeconds);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
213
320
|
// src/resources/auth.ts
|
|
214
321
|
var AuthResource = class {
|
|
215
322
|
constructor(http) {
|
|
@@ -228,6 +335,8 @@ var AuthResource = class {
|
|
|
228
335
|
* });
|
|
229
336
|
*/
|
|
230
337
|
async issueSessionToken(params) {
|
|
338
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
339
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
231
340
|
return this.http.post("/v1/actions/auth/issue-session-token", params);
|
|
232
341
|
}
|
|
233
342
|
};
|
|
@@ -251,6 +360,7 @@ var BuyerSession = class {
|
|
|
251
360
|
* // status: "canceled" (was pending) or "canceling" (was active)
|
|
252
361
|
*/
|
|
253
362
|
async cancelSubscription(params) {
|
|
363
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
254
364
|
return this.http.post(
|
|
255
365
|
"/v1/actions/subscription-order/cancel-order",
|
|
256
366
|
params
|
|
@@ -266,6 +376,7 @@ var BuyerSession = class {
|
|
|
266
376
|
* const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: "ORD_xxx" });
|
|
267
377
|
*/
|
|
268
378
|
async cancelOnetimeOrder(params) {
|
|
379
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
269
380
|
return this.http.post(
|
|
270
381
|
"/v1/actions/onetime-order/cancel-order",
|
|
271
382
|
params
|
|
@@ -282,6 +393,7 @@ var BuyerSession = class {
|
|
|
282
393
|
* // status: "active"
|
|
283
394
|
*/
|
|
284
395
|
async reactivateSubscription(params) {
|
|
396
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
285
397
|
return this.http.post(
|
|
286
398
|
"/v1/actions/subscription-order/reactivate-order",
|
|
287
399
|
params
|
|
@@ -301,6 +413,10 @@ var BuyerSession = class {
|
|
|
301
413
|
* });
|
|
302
414
|
*/
|
|
303
415
|
async createRefundTicket(params) {
|
|
416
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
417
|
+
validateRequired("reason", params.reason);
|
|
418
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
419
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
304
420
|
return this.http.post(
|
|
305
421
|
"/v1/actions/refund-ticket/create-ticket",
|
|
306
422
|
params
|
|
@@ -321,6 +437,11 @@ var BuyerSession = class {
|
|
|
321
437
|
* });
|
|
322
438
|
*/
|
|
323
439
|
async resubmitRefundTicket(params) {
|
|
440
|
+
validateShortId("ticketId", params.ticketId, "TKT");
|
|
441
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
442
|
+
validateRequired("reason", params.reason);
|
|
443
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
444
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
324
445
|
return this.http.post(
|
|
325
446
|
"/v1/actions/refund-ticket/resubmit-ticket",
|
|
326
447
|
params
|
|
@@ -343,6 +464,7 @@ var BuyerGraphQL = class {
|
|
|
343
464
|
* });
|
|
344
465
|
*/
|
|
345
466
|
async query(params) {
|
|
467
|
+
validateRequired("query", params.query);
|
|
346
468
|
return this.http.post("/v1/graphql", params);
|
|
347
469
|
}
|
|
348
470
|
};
|
|
@@ -368,9 +490,11 @@ var CheckoutAnonymousResource = class {
|
|
|
368
490
|
* // Redirect to result.checkoutUrl
|
|
369
491
|
*/
|
|
370
492
|
async create(params) {
|
|
493
|
+
validateCheckoutCommon(params);
|
|
371
494
|
return this.http.post(
|
|
372
495
|
"/v1/actions/checkout/create-session",
|
|
373
|
-
params
|
|
496
|
+
params,
|
|
497
|
+
{ idempotencyWindow: 60 }
|
|
374
498
|
);
|
|
375
499
|
}
|
|
376
500
|
};
|
|
@@ -403,16 +527,18 @@ var CheckoutAuthenticatedResource = class {
|
|
|
403
527
|
* // Redirect to result.checkoutUrl (includes #token=...)
|
|
404
528
|
*/
|
|
405
529
|
async create(params) {
|
|
530
|
+
validateCheckoutCommon(params);
|
|
531
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
406
532
|
const { buyerIdentity, buyerEmail, ...sessionFields } = params;
|
|
407
533
|
const [tokenResult, sessionResult] = await Promise.all([
|
|
408
534
|
this.http.post("/v1/actions/auth/issue-session-token", {
|
|
409
535
|
storeId: params.storeId,
|
|
410
536
|
buyerIdentity
|
|
411
|
-
}),
|
|
537
|
+
}, { idempotencyWindow: 60 }),
|
|
412
538
|
this.http.post("/v1/actions/checkout/create-session", {
|
|
413
539
|
...sessionFields,
|
|
414
540
|
buyerEmail: buyerEmail ?? buyerIdentity
|
|
415
|
-
})
|
|
541
|
+
}, { idempotencyWindow: 60 })
|
|
416
542
|
]);
|
|
417
543
|
return {
|
|
418
544
|
sessionId: sessionResult.sessionId,
|
|
@@ -455,7 +581,7 @@ var CheckoutResource = class {
|
|
|
455
581
|
* // Redirect to session.checkoutUrl
|
|
456
582
|
*/
|
|
457
583
|
async createSession(params) {
|
|
458
|
-
return this.http.post("/v1/actions/checkout/create-session", params);
|
|
584
|
+
return this.http.post("/v1/actions/checkout/create-session", params, { idempotencyWindow: 60 });
|
|
459
585
|
}
|
|
460
586
|
};
|
|
461
587
|
|
|
@@ -483,6 +609,7 @@ var GraphQLResource = class {
|
|
|
483
609
|
* });
|
|
484
610
|
*/
|
|
485
611
|
async query(params) {
|
|
612
|
+
validateRequired("query", params.query);
|
|
486
613
|
return this.http.post("/v1/graphql", params);
|
|
487
614
|
}
|
|
488
615
|
};
|
|
@@ -506,6 +633,9 @@ var OnetimeProductsResource = class {
|
|
|
506
633
|
* });
|
|
507
634
|
*/
|
|
508
635
|
async create(params) {
|
|
636
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
637
|
+
validateRequired("name", params.name);
|
|
638
|
+
validatePrices("prices", params.prices);
|
|
509
639
|
return this.http.post("/v1/actions/onetime-product/create-product", params);
|
|
510
640
|
}
|
|
511
641
|
/**
|
|
@@ -522,6 +652,9 @@ var OnetimeProductsResource = class {
|
|
|
522
652
|
* });
|
|
523
653
|
*/
|
|
524
654
|
async update(params) {
|
|
655
|
+
validateShortId("id", params.id, "PROD");
|
|
656
|
+
validateRequired("name", params.name);
|
|
657
|
+
validatePrices("prices", params.prices);
|
|
525
658
|
return this.http.post("/v1/actions/onetime-product/update-product", params);
|
|
526
659
|
}
|
|
527
660
|
/**
|
|
@@ -534,6 +667,7 @@ var OnetimeProductsResource = class {
|
|
|
534
667
|
* const { product } = await client.onetimeProducts.publish({ id: "PROD_xxx" });
|
|
535
668
|
*/
|
|
536
669
|
async publish(params) {
|
|
670
|
+
validateShortId("id", params.id, "PROD");
|
|
537
671
|
return this.http.post("/v1/actions/onetime-product/publish-product", params);
|
|
538
672
|
}
|
|
539
673
|
/**
|
|
@@ -549,6 +683,8 @@ var OnetimeProductsResource = class {
|
|
|
549
683
|
* });
|
|
550
684
|
*/
|
|
551
685
|
async updateStatus(params) {
|
|
686
|
+
validateShortId("id", params.id, "PROD");
|
|
687
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
552
688
|
return this.http.post("/v1/actions/onetime-product/update-status", params);
|
|
553
689
|
}
|
|
554
690
|
};
|
|
@@ -574,6 +710,7 @@ var OrdersResource = class {
|
|
|
574
710
|
* // status: "canceled" or "canceling"
|
|
575
711
|
*/
|
|
576
712
|
async cancelSubscription(params) {
|
|
713
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
577
714
|
return this.http.post("/v1/actions/subscription-order/cancel-order", params);
|
|
578
715
|
}
|
|
579
716
|
};
|
|
@@ -597,6 +734,9 @@ var StoreMerchantsResource = class {
|
|
|
597
734
|
* });
|
|
598
735
|
*/
|
|
599
736
|
async add(params) {
|
|
737
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
738
|
+
validateRequired("email", params.email);
|
|
739
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
600
740
|
return this.http.post("/v1/actions/store-merchant/add-merchant", params);
|
|
601
741
|
}
|
|
602
742
|
/**
|
|
@@ -612,6 +752,8 @@ var StoreMerchantsResource = class {
|
|
|
612
752
|
* });
|
|
613
753
|
*/
|
|
614
754
|
async remove(params) {
|
|
755
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
756
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
615
757
|
return this.http.post("/v1/actions/store-merchant/remove-merchant", params);
|
|
616
758
|
}
|
|
617
759
|
/**
|
|
@@ -628,6 +770,9 @@ var StoreMerchantsResource = class {
|
|
|
628
770
|
* });
|
|
629
771
|
*/
|
|
630
772
|
async updateRole(params) {
|
|
773
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
774
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
775
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
631
776
|
return this.http.post("/v1/actions/store-merchant/update-role", params);
|
|
632
777
|
}
|
|
633
778
|
};
|
|
@@ -647,6 +792,7 @@ var StoresResource = class {
|
|
|
647
792
|
* const { store } = await client.stores.create({ name: "My Store" });
|
|
648
793
|
*/
|
|
649
794
|
async create(params) {
|
|
795
|
+
validateRequired("name", params.name);
|
|
650
796
|
return this.http.post("/v1/actions/store/create-store", params);
|
|
651
797
|
}
|
|
652
798
|
/**
|
|
@@ -662,6 +808,7 @@ var StoresResource = class {
|
|
|
662
808
|
* });
|
|
663
809
|
*/
|
|
664
810
|
async update(params) {
|
|
811
|
+
validateShortId("id", params.id, "STO");
|
|
665
812
|
return this.http.post("/v1/actions/store/update-store", params);
|
|
666
813
|
}
|
|
667
814
|
/**
|
|
@@ -674,6 +821,7 @@ var StoresResource = class {
|
|
|
674
821
|
* const { store } = await client.stores.delete({ id: "STO_xxx" });
|
|
675
822
|
*/
|
|
676
823
|
async delete(params) {
|
|
824
|
+
validateShortId("id", params.id, "STO");
|
|
677
825
|
return this.http.post("/v1/actions/store/delete-store", params);
|
|
678
826
|
}
|
|
679
827
|
};
|
|
@@ -698,6 +846,8 @@ var SubscriptionProductGroupsResource = class {
|
|
|
698
846
|
* });
|
|
699
847
|
*/
|
|
700
848
|
async create(params) {
|
|
849
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
850
|
+
validateRequired("name", params.name);
|
|
701
851
|
return this.http.post("/v1/actions/subscription-product-group/create-group", params);
|
|
702
852
|
}
|
|
703
853
|
/**
|
|
@@ -713,6 +863,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
713
863
|
* });
|
|
714
864
|
*/
|
|
715
865
|
async update(params) {
|
|
866
|
+
validateRequired("id", params.id);
|
|
716
867
|
return this.http.post("/v1/actions/subscription-product-group/update-group", params);
|
|
717
868
|
}
|
|
718
869
|
/**
|
|
@@ -725,6 +876,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
725
876
|
* const { group } = await client.subscriptionProductGroups.delete({ id: "GRP_xxx" });
|
|
726
877
|
*/
|
|
727
878
|
async delete(params) {
|
|
879
|
+
validateRequired("id", params.id);
|
|
728
880
|
return this.http.post("/v1/actions/subscription-product-group/delete-group", params);
|
|
729
881
|
}
|
|
730
882
|
/**
|
|
@@ -737,6 +889,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
737
889
|
* const { group } = await client.subscriptionProductGroups.publish({ id: "GRP_xxx" });
|
|
738
890
|
*/
|
|
739
891
|
async publish(params) {
|
|
892
|
+
validateRequired("id", params.id);
|
|
740
893
|
return this.http.post("/v1/actions/subscription-product-group/publish-group", params);
|
|
741
894
|
}
|
|
742
895
|
};
|
|
@@ -761,6 +914,10 @@ var SubscriptionProductsResource = class {
|
|
|
761
914
|
* });
|
|
762
915
|
*/
|
|
763
916
|
async create(params) {
|
|
917
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
918
|
+
validateRequired("name", params.name);
|
|
919
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
920
|
+
validatePrices("prices", params.prices);
|
|
764
921
|
return this.http.post("/v1/actions/subscription-product/create-product", params);
|
|
765
922
|
}
|
|
766
923
|
/**
|
|
@@ -778,6 +935,10 @@ var SubscriptionProductsResource = class {
|
|
|
778
935
|
* });
|
|
779
936
|
*/
|
|
780
937
|
async update(params) {
|
|
938
|
+
validateShortId("id", params.id, "PROD");
|
|
939
|
+
validateRequired("name", params.name);
|
|
940
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
941
|
+
validatePrices("prices", params.prices);
|
|
781
942
|
return this.http.post("/v1/actions/subscription-product/update-product", params);
|
|
782
943
|
}
|
|
783
944
|
/**
|
|
@@ -790,6 +951,7 @@ var SubscriptionProductsResource = class {
|
|
|
790
951
|
* const { product } = await client.subscriptionProducts.publish({ id: "PROD_xxx" });
|
|
791
952
|
*/
|
|
792
953
|
async publish(params) {
|
|
954
|
+
validateShortId("id", params.id, "PROD");
|
|
793
955
|
return this.http.post("/v1/actions/subscription-product/publish-product", params);
|
|
794
956
|
}
|
|
795
957
|
/**
|
|
@@ -805,6 +967,8 @@ var SubscriptionProductsResource = class {
|
|
|
805
967
|
* });
|
|
806
968
|
*/
|
|
807
969
|
async updateStatus(params) {
|
|
970
|
+
validateShortId("id", params.id, "PROD");
|
|
971
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
808
972
|
return this.http.post("/v1/actions/subscription-product/update-status", params);
|
|
809
973
|
}
|
|
810
974
|
};
|
|
@@ -1073,11 +1237,14 @@ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus2) => {
|
|
|
1073
1237
|
})(PaymentStatus || {});
|
|
1074
1238
|
var RefundTicketStatus = /* @__PURE__ */ ((RefundTicketStatus2) => {
|
|
1075
1239
|
RefundTicketStatus2["Pending"] = "pending";
|
|
1240
|
+
RefundTicketStatus2["UnderReview"] = "under_review";
|
|
1076
1241
|
RefundTicketStatus2["Approved"] = "approved";
|
|
1077
1242
|
RefundTicketStatus2["Rejected"] = "rejected";
|
|
1243
|
+
RefundTicketStatus2["Returned"] = "returned";
|
|
1078
1244
|
RefundTicketStatus2["Processing"] = "processing";
|
|
1079
1245
|
RefundTicketStatus2["Succeeded"] = "succeeded";
|
|
1080
1246
|
RefundTicketStatus2["Failed"] = "failed";
|
|
1247
|
+
RefundTicketStatus2["Cancelled"] = "cancelled";
|
|
1081
1248
|
return RefundTicketStatus2;
|
|
1082
1249
|
})(RefundTicketStatus || {});
|
|
1083
1250
|
var RefundStatus = /* @__PURE__ */ ((RefundStatus2) => {
|
|
@@ -1105,6 +1272,7 @@ var ErrorLayer = /* @__PURE__ */ ((ErrorLayer2) => {
|
|
|
1105
1272
|
ErrorLayer2["GraphQL"] = "graphql";
|
|
1106
1273
|
ErrorLayer2["Resource"] = "resource";
|
|
1107
1274
|
ErrorLayer2["Email"] = "email";
|
|
1275
|
+
ErrorLayer2["Sdk"] = "sdk";
|
|
1108
1276
|
return ErrorLayer2;
|
|
1109
1277
|
})(ErrorLayer || {});
|
|
1110
1278
|
var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|