@b3dotfun/sdk 0.1.68-alpha.3 → 0.1.68-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anyspend/platform/client.d.ts +35 -0
- package/dist/cjs/anyspend/platform/client.js +158 -0
- package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
- package/dist/cjs/anyspend/platform/errors.js +77 -0
- package/dist/cjs/anyspend/platform/index.d.ts +87 -0
- package/dist/cjs/anyspend/platform/index.js +85 -0
- package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
- package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
- package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/events.js +16 -0
- package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
- package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
- package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/cjs/anyspend/platform/resources/products.js +31 -0
- package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
- package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
- package/dist/cjs/anyspend/platform/types.d.ts +478 -0
- package/dist/cjs/anyspend/platform/types.js +5 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
- package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +128 -11
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +13 -12
- package/dist/cjs/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/checkout/KycGate.js +181 -0
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +9 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +42 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.js +113 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +3 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -1
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/cjs/global-account/react/hooks/useAuth.js +1 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/cjs/global-account/react/stores/useModalStore.js +2 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.js +17 -0
- package/dist/esm/anyspend/platform/client.d.ts +35 -0
- package/dist/esm/anyspend/platform/client.js +153 -0
- package/dist/esm/anyspend/platform/errors.d.ts +38 -0
- package/dist/esm/anyspend/platform/errors.js +67 -0
- package/dist/esm/anyspend/platform/index.d.ts +87 -0
- package/dist/esm/anyspend/platform/index.js +75 -0
- package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
- package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/esm/anyspend/platform/resources/customers.js +30 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
- package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/events.js +12 -0
- package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
- package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/organization.js +11 -0
- package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
- package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/esm/anyspend/platform/resources/products.js +27 -0
- package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
- package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
- package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
- package/dist/esm/anyspend/platform/types.d.ts +478 -0
- package/dist/esm/anyspend/platform/types.js +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
- package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +129 -12
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +13 -12
- package/dist/esm/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/esm/anyspend/react/components/checkout/KycGate.js +145 -0
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +9 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +42 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.js +107 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +3 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -1
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/esm/global-account/react/hooks/useAuth.js +2 -2
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/global-account/react/stores/useModalStore.js +2 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.js +16 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/platform/client.d.ts +35 -0
- package/dist/types/anyspend/platform/errors.d.ts +38 -0
- package/dist/types/anyspend/platform/index.d.ts +87 -0
- package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/types/anyspend/platform/types.d.ts +478 -0
- package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +3 -1
- package/dist/types/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +42 -0
- package/dist/types/anyspend/services/anyspend.d.ts +3 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/package.json +7 -1
- package/src/anyspend/platform/client.ts +198 -0
- package/src/anyspend/platform/errors.ts +92 -0
- package/src/anyspend/platform/index.ts +129 -0
- package/src/anyspend/platform/resources/analytics.ts +10 -0
- package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
- package/src/anyspend/platform/resources/customers.ts +54 -0
- package/src/anyspend/platform/resources/discount-codes.ts +63 -0
- package/src/anyspend/platform/resources/events.ts +22 -0
- package/src/anyspend/platform/resources/notifications.ts +37 -0
- package/src/anyspend/platform/resources/organization.ts +24 -0
- package/src/anyspend/platform/resources/payment-links.ts +74 -0
- package/src/anyspend/platform/resources/products.ts +59 -0
- package/src/anyspend/platform/resources/transactions.ts +33 -0
- package/src/anyspend/platform/resources/webhooks.ts +47 -0
- package/src/anyspend/platform/resources/widgets.ts +63 -0
- package/src/anyspend/platform/types.ts +532 -0
- package/src/anyspend/platform/utils/idempotency.ts +15 -0
- package/src/anyspend/platform/utils/pagination.ts +32 -0
- package/src/anyspend/react/components/AnySpend.tsx +150 -13
- package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +16 -13
- package/src/anyspend/react/components/checkout/KycGate.tsx +351 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +10 -0
- package/src/anyspend/react/hooks/useKycStatus.ts +140 -0
- package/src/anyspend/services/anyspend.ts +4 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +0 -2
- package/src/global-account/react/components/ManageAccount/BottomNavigation.tsx +7 -7
- package/src/global-account/react/hooks/useAuth.ts +2 -2
- package/src/global-account/react/stores/useModalStore.ts +6 -0
- package/src/global-account/react/utils/createWagmiConfig.tsx +18 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core HTTP client for the AnySpend Platform API.
|
|
3
|
+
* Handles authentication, retries, error parsing, and idempotency.
|
|
4
|
+
*/
|
|
5
|
+
export interface ClientConfig {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
idempotencyKeyGenerator?: () => string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_BASE_URL = "https://platform-api.anyspend.com/api/v1";
|
|
12
|
+
export declare class HttpClient {
|
|
13
|
+
private apiKey;
|
|
14
|
+
private baseUrl;
|
|
15
|
+
private timeout;
|
|
16
|
+
private maxRetries;
|
|
17
|
+
private generateIdempotencyKey;
|
|
18
|
+
constructor(apiKey: string, config?: ClientConfig);
|
|
19
|
+
get<T>(path: string, params?: object): Promise<T>;
|
|
20
|
+
post<T>(path: string, body?: object): Promise<T>;
|
|
21
|
+
patch<T>(path: string, body: object): Promise<T>;
|
|
22
|
+
delete<T>(path: string, body?: object): Promise<T>;
|
|
23
|
+
postFormData<T>(path: string, formData: FormData): Promise<T>;
|
|
24
|
+
private buildUrl;
|
|
25
|
+
private request;
|
|
26
|
+
private requestRaw;
|
|
27
|
+
private executeWithRetry;
|
|
28
|
+
private sleep;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Static HTTP client for unauthenticated requests (quick-pay).
|
|
32
|
+
*/
|
|
33
|
+
export declare class StaticHttpClient {
|
|
34
|
+
static post<T>(baseUrl: string, path: string, body: Record<string, unknown>): Promise<T>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core HTTP client for the AnySpend Platform API.
|
|
4
|
+
* Handles authentication, retries, error parsing, and idempotency.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.StaticHttpClient = exports.HttpClient = exports.DEFAULT_BASE_URL = void 0;
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const idempotency_1 = require("./utils/idempotency");
|
|
10
|
+
exports.DEFAULT_BASE_URL = "https://platform-api.anyspend.com/api/v1";
|
|
11
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
12
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
13
|
+
class HttpClient {
|
|
14
|
+
constructor(apiKey, config = {}) {
|
|
15
|
+
this.apiKey = apiKey;
|
|
16
|
+
this.baseUrl = (config.baseUrl || exports.DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
17
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
18
|
+
this.maxRetries = config.maxRetries || DEFAULT_MAX_RETRIES;
|
|
19
|
+
this.generateIdempotencyKey = config.idempotencyKeyGenerator || idempotency_1.generateIdempotencyKey;
|
|
20
|
+
}
|
|
21
|
+
async get(path, params) {
|
|
22
|
+
const url = this.buildUrl(path, params);
|
|
23
|
+
return this.request("GET", url);
|
|
24
|
+
}
|
|
25
|
+
async post(path, body) {
|
|
26
|
+
const url = this.buildUrl(path);
|
|
27
|
+
return this.request("POST", url, body);
|
|
28
|
+
}
|
|
29
|
+
async patch(path, body) {
|
|
30
|
+
const url = this.buildUrl(path);
|
|
31
|
+
return this.request("PATCH", url, body);
|
|
32
|
+
}
|
|
33
|
+
async delete(path, body) {
|
|
34
|
+
const url = this.buildUrl(path);
|
|
35
|
+
return this.request("DELETE", url, body);
|
|
36
|
+
}
|
|
37
|
+
async postFormData(path, formData) {
|
|
38
|
+
const url = this.buildUrl(path);
|
|
39
|
+
return this.requestRaw("POST", url, formData);
|
|
40
|
+
}
|
|
41
|
+
buildUrl(path, params) {
|
|
42
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
43
|
+
if (params) {
|
|
44
|
+
for (const [key, value] of Object.entries(params)) {
|
|
45
|
+
if (value !== undefined && value !== null)
|
|
46
|
+
url.searchParams.set(key, String(value));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return url.toString();
|
|
50
|
+
}
|
|
51
|
+
async request(method, url, body) {
|
|
52
|
+
const headers = {
|
|
53
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
};
|
|
56
|
+
// Auto-generate idempotency key for POST/PATCH
|
|
57
|
+
if (method === "POST" || method === "PATCH") {
|
|
58
|
+
headers["Idempotency-Key"] = this.generateIdempotencyKey();
|
|
59
|
+
}
|
|
60
|
+
return this.executeWithRetry(method, url, headers, body ? JSON.stringify(body) : undefined);
|
|
61
|
+
}
|
|
62
|
+
async requestRaw(method, url, body) {
|
|
63
|
+
const headers = {
|
|
64
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
65
|
+
};
|
|
66
|
+
return this.executeWithRetry(method, url, headers, body);
|
|
67
|
+
}
|
|
68
|
+
async executeWithRetry(method, url, headers, body) {
|
|
69
|
+
let lastError;
|
|
70
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
71
|
+
try {
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
74
|
+
const response = await fetch(url, {
|
|
75
|
+
method,
|
|
76
|
+
headers,
|
|
77
|
+
body,
|
|
78
|
+
signal: controller.signal,
|
|
79
|
+
});
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
if (response.ok) {
|
|
82
|
+
// Handle CSV/text responses
|
|
83
|
+
const contentType = response.headers.get("Content-Type") || "";
|
|
84
|
+
if (contentType.includes("text/csv")) {
|
|
85
|
+
return (await response.text());
|
|
86
|
+
}
|
|
87
|
+
return (await response.json());
|
|
88
|
+
}
|
|
89
|
+
// Parse error response
|
|
90
|
+
const errorBody = (await response.json().catch(() => ({
|
|
91
|
+
error: { type: "api_error", code: "internal_error", message: "Unknown error" },
|
|
92
|
+
})));
|
|
93
|
+
const error = (0, errors_1.parseApiError)(response.status, errorBody, response.headers);
|
|
94
|
+
// Don't retry 4xx errors (except 429 rate limits)
|
|
95
|
+
if (response.status < 500 && response.status !== 429) {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
// For 429, wait the specified retry-after time
|
|
99
|
+
if (response.status === 429) {
|
|
100
|
+
const retryAfter = parseInt(response.headers.get("Retry-After") || "1", 10);
|
|
101
|
+
await this.sleep(retryAfter * 1000);
|
|
102
|
+
lastError = error;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// For 5xx, retry with exponential backoff
|
|
106
|
+
lastError = error;
|
|
107
|
+
if (attempt < this.maxRetries) {
|
|
108
|
+
await this.sleep(Math.pow(2, attempt) * 1000);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
113
|
+
lastError = new Error(`Request timed out after ${this.timeout}ms`);
|
|
114
|
+
}
|
|
115
|
+
else if (err instanceof Error && "type" in err) {
|
|
116
|
+
// Already a parsed ApiError, re-throw
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
121
|
+
}
|
|
122
|
+
if (attempt < this.maxRetries) {
|
|
123
|
+
await this.sleep(Math.pow(2, attempt) * 1000);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw lastError || new Error("Request failed after retries");
|
|
128
|
+
}
|
|
129
|
+
sleep(ms) {
|
|
130
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.HttpClient = HttpClient;
|
|
134
|
+
/**
|
|
135
|
+
* Static HTTP client for unauthenticated requests (quick-pay).
|
|
136
|
+
*/
|
|
137
|
+
class StaticHttpClient {
|
|
138
|
+
static async post(baseUrl, path, body) {
|
|
139
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
140
|
+
const controller = new AbortController();
|
|
141
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
142
|
+
const response = await fetch(url, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: { "Content-Type": "application/json" },
|
|
145
|
+
body: JSON.stringify(body),
|
|
146
|
+
signal: controller.signal,
|
|
147
|
+
});
|
|
148
|
+
clearTimeout(timeoutId);
|
|
149
|
+
if (response.ok) {
|
|
150
|
+
return (await response.json());
|
|
151
|
+
}
|
|
152
|
+
const errorBody = (await response.json().catch(() => ({
|
|
153
|
+
error: { type: "api_error", code: "internal_error", message: "Unknown error" },
|
|
154
|
+
})));
|
|
155
|
+
throw (0, errors_1.parseApiError)(response.status, errorBody, response.headers);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.StaticHttpClient = StaticHttpClient;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error classes for the AnySpend Platform API client.
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiErrorResponse {
|
|
5
|
+
error: {
|
|
6
|
+
type: string;
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
param?: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare class ApiError extends Error {
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
readonly param?: string;
|
|
17
|
+
constructor(status: number, body: ApiErrorResponse);
|
|
18
|
+
}
|
|
19
|
+
export declare class AuthenticationError extends ApiError {
|
|
20
|
+
constructor(status: number, body: ApiErrorResponse);
|
|
21
|
+
}
|
|
22
|
+
export declare class PermissionError extends ApiError {
|
|
23
|
+
constructor(status: number, body: ApiErrorResponse);
|
|
24
|
+
}
|
|
25
|
+
export declare class RateLimitError extends ApiError {
|
|
26
|
+
readonly retryAfter: number;
|
|
27
|
+
constructor(status: number, body: ApiErrorResponse, retryAfter: number);
|
|
28
|
+
}
|
|
29
|
+
export declare class NotFoundError extends ApiError {
|
|
30
|
+
constructor(status: number, body: ApiErrorResponse);
|
|
31
|
+
}
|
|
32
|
+
export declare class IdempotencyError extends ApiError {
|
|
33
|
+
constructor(status: number, body: ApiErrorResponse);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse an API error response into the appropriate typed error class.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseApiError(status: number, body: ApiErrorResponse, headers?: Headers): ApiError;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed error classes for the AnySpend Platform API client.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IdempotencyError = exports.NotFoundError = exports.RateLimitError = exports.PermissionError = exports.AuthenticationError = exports.ApiError = void 0;
|
|
7
|
+
exports.parseApiError = parseApiError;
|
|
8
|
+
class ApiError extends Error {
|
|
9
|
+
constructor(status, body) {
|
|
10
|
+
super(body.error.message);
|
|
11
|
+
this.name = "ApiError";
|
|
12
|
+
this.type = body.error.type;
|
|
13
|
+
this.code = body.error.code;
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.param = body.error.param;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ApiError = ApiError;
|
|
19
|
+
class AuthenticationError extends ApiError {
|
|
20
|
+
constructor(status, body) {
|
|
21
|
+
super(status, body);
|
|
22
|
+
this.name = "AuthenticationError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.AuthenticationError = AuthenticationError;
|
|
26
|
+
class PermissionError extends ApiError {
|
|
27
|
+
constructor(status, body) {
|
|
28
|
+
super(status, body);
|
|
29
|
+
this.name = "PermissionError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.PermissionError = PermissionError;
|
|
33
|
+
class RateLimitError extends ApiError {
|
|
34
|
+
constructor(status, body, retryAfter) {
|
|
35
|
+
super(status, body);
|
|
36
|
+
this.name = "RateLimitError";
|
|
37
|
+
this.retryAfter = retryAfter;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.RateLimitError = RateLimitError;
|
|
41
|
+
class NotFoundError extends ApiError {
|
|
42
|
+
constructor(status, body) {
|
|
43
|
+
super(status, body);
|
|
44
|
+
this.name = "NotFoundError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.NotFoundError = NotFoundError;
|
|
48
|
+
class IdempotencyError extends ApiError {
|
|
49
|
+
constructor(status, body) {
|
|
50
|
+
super(status, body);
|
|
51
|
+
this.name = "IdempotencyError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.IdempotencyError = IdempotencyError;
|
|
55
|
+
/**
|
|
56
|
+
* Parse an API error response into the appropriate typed error class.
|
|
57
|
+
*/
|
|
58
|
+
function parseApiError(status, body, headers) {
|
|
59
|
+
const type = body.error?.type;
|
|
60
|
+
if (status === 401 || type === "authentication_error") {
|
|
61
|
+
return new AuthenticationError(status, body);
|
|
62
|
+
}
|
|
63
|
+
if (status === 403 || type === "permission_error") {
|
|
64
|
+
return new PermissionError(status, body);
|
|
65
|
+
}
|
|
66
|
+
if (status === 429 || type === "rate_limit_error") {
|
|
67
|
+
const retryAfter = parseInt(headers?.get("Retry-After") || "60", 10);
|
|
68
|
+
return new RateLimitError(status, body, retryAfter);
|
|
69
|
+
}
|
|
70
|
+
if (status === 404 || type === "not_found_error") {
|
|
71
|
+
return new NotFoundError(status, body);
|
|
72
|
+
}
|
|
73
|
+
if (type === "idempotency_error") {
|
|
74
|
+
return new IdempotencyError(status, body);
|
|
75
|
+
}
|
|
76
|
+
return new ApiError(status, body);
|
|
77
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnySpend Platform API Client
|
|
3
|
+
*
|
|
4
|
+
* A headless TypeScript client for the AnySpend Platform REST API.
|
|
5
|
+
* Works in any runtime with `fetch` (Node.js, browsers, Cloudflare Workers, Deno, Bun).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AnySpendPlatformClient } from '../../anyspend/platform';
|
|
10
|
+
*
|
|
11
|
+
* const platform = new AnySpendPlatformClient('asp_your_api_key_here');
|
|
12
|
+
*
|
|
13
|
+
* // Create a payment link
|
|
14
|
+
* const link = await platform.paymentLinks.create({
|
|
15
|
+
* name: 'Summer Sale',
|
|
16
|
+
* amount: '10000000',
|
|
17
|
+
* token_address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
18
|
+
* chain_id: 8453,
|
|
19
|
+
* recipient_address: '0x...',
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Quick pay (no API key needed)
|
|
23
|
+
* const quickLink = await AnySpendPlatformClient.quickPay({
|
|
24
|
+
* recipient_address: '0x...',
|
|
25
|
+
* amount: '5000000',
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { type ClientConfig } from "./client";
|
|
30
|
+
import { PaymentLinksResource } from "./resources/payment-links";
|
|
31
|
+
import { ProductsResource } from "./resources/products";
|
|
32
|
+
import { CustomersResource } from "./resources/customers";
|
|
33
|
+
import { TransactionsResource } from "./resources/transactions";
|
|
34
|
+
import { CheckoutSessionsResource } from "./resources/checkout-sessions";
|
|
35
|
+
import { WebhooksResource } from "./resources/webhooks";
|
|
36
|
+
import { DiscountCodesResource } from "./resources/discount-codes";
|
|
37
|
+
import { NotificationsResource } from "./resources/notifications";
|
|
38
|
+
import { WidgetsResource } from "./resources/widgets";
|
|
39
|
+
import { OrganizationResource } from "./resources/organization";
|
|
40
|
+
import { AnalyticsResource } from "./resources/analytics";
|
|
41
|
+
import { EventsResource } from "./resources/events";
|
|
42
|
+
import type { QuickPayParams, PaymentLink } from "./types";
|
|
43
|
+
export declare class AnySpendPlatformClient {
|
|
44
|
+
private client;
|
|
45
|
+
/** Payment Links - Create, manage, and track payment links */
|
|
46
|
+
readonly paymentLinks: PaymentLinksResource;
|
|
47
|
+
/** Products - Manage your product catalog */
|
|
48
|
+
readonly products: ProductsResource;
|
|
49
|
+
/** Customers - Manage customer records */
|
|
50
|
+
readonly customers: CustomersResource;
|
|
51
|
+
/** Transactions - View transaction history and stats */
|
|
52
|
+
readonly transactions: TransactionsResource;
|
|
53
|
+
/** Checkout Sessions - Server-side checkout management */
|
|
54
|
+
readonly checkoutSessions: CheckoutSessionsResource;
|
|
55
|
+
/** Webhooks - Configure webhook endpoints */
|
|
56
|
+
readonly webhooks: WebhooksResource;
|
|
57
|
+
/** Discount Codes - Create and validate discounts */
|
|
58
|
+
readonly discountCodes: DiscountCodesResource;
|
|
59
|
+
/** Notifications - Email and Telegram settings */
|
|
60
|
+
readonly notifications: NotificationsResource;
|
|
61
|
+
/** Widgets - Embeddable widget configurations */
|
|
62
|
+
readonly widgets: WidgetsResource;
|
|
63
|
+
/** Organization - Org settings and defaults */
|
|
64
|
+
readonly organization: OrganizationResource;
|
|
65
|
+
/** Analytics - Revenue and conversion analytics */
|
|
66
|
+
readonly analytics: AnalyticsResource;
|
|
67
|
+
/** Events - API audit trail */
|
|
68
|
+
readonly events: EventsResource;
|
|
69
|
+
/**
|
|
70
|
+
* Create a new AnySpend Platform API client.
|
|
71
|
+
*
|
|
72
|
+
* @param apiKey - Your API key (starts with `asp_`)
|
|
73
|
+
* @param config - Optional configuration
|
|
74
|
+
*/
|
|
75
|
+
constructor(apiKey: string, config?: ClientConfig);
|
|
76
|
+
/**
|
|
77
|
+
* Create a quick payment link without authentication.
|
|
78
|
+
* Rate limited to 5 requests per minute per IP.
|
|
79
|
+
*
|
|
80
|
+
* @param params - Quick pay parameters
|
|
81
|
+
* @param baseUrl - Optional API base URL (defaults to production)
|
|
82
|
+
*/
|
|
83
|
+
static quickPay(params: QuickPayParams, baseUrl?: string): Promise<PaymentLink>;
|
|
84
|
+
}
|
|
85
|
+
export type { ClientConfig } from "./client";
|
|
86
|
+
export { ApiError, AuthenticationError, PermissionError, RateLimitError, NotFoundError, IdempotencyError, } from "./errors";
|
|
87
|
+
export type * from "./types";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AnySpend Platform API Client
|
|
4
|
+
*
|
|
5
|
+
* A headless TypeScript client for the AnySpend Platform REST API.
|
|
6
|
+
* Works in any runtime with `fetch` (Node.js, browsers, Cloudflare Workers, Deno, Bun).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { AnySpendPlatformClient } from '../../anyspend/platform';
|
|
11
|
+
*
|
|
12
|
+
* const platform = new AnySpendPlatformClient('asp_your_api_key_here');
|
|
13
|
+
*
|
|
14
|
+
* // Create a payment link
|
|
15
|
+
* const link = await platform.paymentLinks.create({
|
|
16
|
+
* name: 'Summer Sale',
|
|
17
|
+
* amount: '10000000',
|
|
18
|
+
* token_address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
19
|
+
* chain_id: 8453,
|
|
20
|
+
* recipient_address: '0x...',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Quick pay (no API key needed)
|
|
24
|
+
* const quickLink = await AnySpendPlatformClient.quickPay({
|
|
25
|
+
* recipient_address: '0x...',
|
|
26
|
+
* amount: '5000000',
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.IdempotencyError = exports.NotFoundError = exports.RateLimitError = exports.PermissionError = exports.AuthenticationError = exports.ApiError = exports.AnySpendPlatformClient = void 0;
|
|
32
|
+
const client_1 = require("./client");
|
|
33
|
+
const payment_links_1 = require("./resources/payment-links");
|
|
34
|
+
const products_1 = require("./resources/products");
|
|
35
|
+
const customers_1 = require("./resources/customers");
|
|
36
|
+
const transactions_1 = require("./resources/transactions");
|
|
37
|
+
const checkout_sessions_1 = require("./resources/checkout-sessions");
|
|
38
|
+
const webhooks_1 = require("./resources/webhooks");
|
|
39
|
+
const discount_codes_1 = require("./resources/discount-codes");
|
|
40
|
+
const notifications_1 = require("./resources/notifications");
|
|
41
|
+
const widgets_1 = require("./resources/widgets");
|
|
42
|
+
const organization_1 = require("./resources/organization");
|
|
43
|
+
const analytics_1 = require("./resources/analytics");
|
|
44
|
+
const events_1 = require("./resources/events");
|
|
45
|
+
class AnySpendPlatformClient {
|
|
46
|
+
/**
|
|
47
|
+
* Create a new AnySpend Platform API client.
|
|
48
|
+
*
|
|
49
|
+
* @param apiKey - Your API key (starts with `asp_`)
|
|
50
|
+
* @param config - Optional configuration
|
|
51
|
+
*/
|
|
52
|
+
constructor(apiKey, config) {
|
|
53
|
+
this.client = new client_1.HttpClient(apiKey, config);
|
|
54
|
+
this.paymentLinks = new payment_links_1.PaymentLinksResource(this.client);
|
|
55
|
+
this.products = new products_1.ProductsResource(this.client);
|
|
56
|
+
this.customers = new customers_1.CustomersResource(this.client);
|
|
57
|
+
this.transactions = new transactions_1.TransactionsResource(this.client);
|
|
58
|
+
this.checkoutSessions = new checkout_sessions_1.CheckoutSessionsResource(this.client);
|
|
59
|
+
this.webhooks = new webhooks_1.WebhooksResource(this.client);
|
|
60
|
+
this.discountCodes = new discount_codes_1.DiscountCodesResource(this.client);
|
|
61
|
+
this.notifications = new notifications_1.NotificationsResource(this.client);
|
|
62
|
+
this.widgets = new widgets_1.WidgetsResource(this.client);
|
|
63
|
+
this.organization = new organization_1.OrganizationResource(this.client);
|
|
64
|
+
this.analytics = new analytics_1.AnalyticsResource(this.client);
|
|
65
|
+
this.events = new events_1.EventsResource(this.client);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a quick payment link without authentication.
|
|
69
|
+
* Rate limited to 5 requests per minute per IP.
|
|
70
|
+
*
|
|
71
|
+
* @param params - Quick pay parameters
|
|
72
|
+
* @param baseUrl - Optional API base URL (defaults to production)
|
|
73
|
+
*/
|
|
74
|
+
static async quickPay(params, baseUrl = client_1.DEFAULT_BASE_URL) {
|
|
75
|
+
return client_1.StaticHttpClient.post(baseUrl, "/quick-pay", params);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.AnySpendPlatformClient = AnySpendPlatformClient;
|
|
79
|
+
var errors_1 = require("./errors");
|
|
80
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return errors_1.ApiError; } });
|
|
81
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
82
|
+
Object.defineProperty(exports, "PermissionError", { enumerable: true, get: function () { return errors_1.PermissionError; } });
|
|
83
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
84
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_1.NotFoundError; } });
|
|
85
|
+
Object.defineProperty(exports, "IdempotencyError", { enumerable: true, get: function () { return errors_1.IdempotencyError; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import type { AnalyticsOverview } from "../types";
|
|
3
|
+
export declare class AnalyticsResource {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: HttpClient);
|
|
6
|
+
overview(period?: "7d" | "30d" | "90d" | "all"): Promise<AnalyticsOverview>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnalyticsResource = void 0;
|
|
4
|
+
class AnalyticsResource {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async overview(period) {
|
|
9
|
+
return this.client.get("/analytics/overview", period !== undefined ? { period } : undefined);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.AnalyticsResource = AnalyticsResource;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import type { CheckoutSession, ListResponse, CreateCheckoutSessionParams, PaginationParams } from "../types";
|
|
3
|
+
export interface ListCheckoutSessionsParams extends PaginationParams {
|
|
4
|
+
status?: "open" | "processing" | "completed" | "expired" | "failed";
|
|
5
|
+
payment_link_id?: string;
|
|
6
|
+
from?: number;
|
|
7
|
+
to?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class CheckoutSessionsResource {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(client: HttpClient);
|
|
12
|
+
list(params?: ListCheckoutSessionsParams): Promise<ListResponse<CheckoutSession>>;
|
|
13
|
+
listAutoPaginate(params?: Omit<ListCheckoutSessionsParams, "page">): AsyncGenerator<CheckoutSession>;
|
|
14
|
+
create(params: CreateCheckoutSessionParams): Promise<CheckoutSession>;
|
|
15
|
+
get(id: string): Promise<CheckoutSession>;
|
|
16
|
+
expire(id: string): Promise<CheckoutSession>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckoutSessionsResource = void 0;
|
|
4
|
+
const pagination_1 = require("../utils/pagination");
|
|
5
|
+
class CheckoutSessionsResource {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async list(params) {
|
|
10
|
+
return this.client.get("/checkout-sessions", params);
|
|
11
|
+
}
|
|
12
|
+
async *listAutoPaginate(params) {
|
|
13
|
+
yield* (0, pagination_1.autoPaginate)((page, limit) => this.list({ ...params, page, limit }), {
|
|
14
|
+
limit: params?.limit,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async create(params) {
|
|
18
|
+
return this.client.post("/checkout-sessions", params);
|
|
19
|
+
}
|
|
20
|
+
async get(id) {
|
|
21
|
+
return this.client.get(`/checkout-sessions/${id}`);
|
|
22
|
+
}
|
|
23
|
+
async expire(id) {
|
|
24
|
+
return this.client.post(`/checkout-sessions/${id}/expire`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.CheckoutSessionsResource = CheckoutSessionsResource;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import type { Customer, Transaction, ListResponse, DeletedResponse, CreateCustomerParams, UpdateCustomerParams, ExportCustomersParams, PaginationParams } from "../types";
|
|
3
|
+
export interface ListCustomersParams extends PaginationParams {
|
|
4
|
+
search?: string;
|
|
5
|
+
sort?: "created_at" | "updated_at" | "total_paid" | "transaction_count";
|
|
6
|
+
order?: "asc" | "desc";
|
|
7
|
+
}
|
|
8
|
+
export declare class CustomersResource {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: HttpClient);
|
|
11
|
+
list(params?: ListCustomersParams): Promise<ListResponse<Customer>>;
|
|
12
|
+
listAutoPaginate(params?: Omit<ListCustomersParams, "page">): AsyncGenerator<Customer>;
|
|
13
|
+
create(params: CreateCustomerParams): Promise<Customer>;
|
|
14
|
+
get(id: string): Promise<Customer>;
|
|
15
|
+
update(id: string, params: UpdateCustomerParams): Promise<Customer>;
|
|
16
|
+
delete(id: string): Promise<DeletedResponse>;
|
|
17
|
+
transactions(id: string, params?: PaginationParams): Promise<ListResponse<Transaction>>;
|
|
18
|
+
export(params?: ExportCustomersParams): Promise<string>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomersResource = void 0;
|
|
4
|
+
const pagination_1 = require("../utils/pagination");
|
|
5
|
+
class CustomersResource {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async list(params) {
|
|
10
|
+
return this.client.get("/customers", params);
|
|
11
|
+
}
|
|
12
|
+
async *listAutoPaginate(params) {
|
|
13
|
+
yield* (0, pagination_1.autoPaginate)((page, limit) => this.list({ ...params, page, limit }), { limit: params?.limit });
|
|
14
|
+
}
|
|
15
|
+
async create(params) {
|
|
16
|
+
return this.client.post("/customers", params);
|
|
17
|
+
}
|
|
18
|
+
async get(id) {
|
|
19
|
+
return this.client.get(`/customers/${id}`);
|
|
20
|
+
}
|
|
21
|
+
async update(id, params) {
|
|
22
|
+
return this.client.patch(`/customers/${id}`, params);
|
|
23
|
+
}
|
|
24
|
+
async delete(id) {
|
|
25
|
+
return this.client.delete(`/customers/${id}`);
|
|
26
|
+
}
|
|
27
|
+
async transactions(id, params) {
|
|
28
|
+
return this.client.get(`/customers/${id}/transactions`, params);
|
|
29
|
+
}
|
|
30
|
+
async export(params) {
|
|
31
|
+
return this.client.get("/customers/export", params);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.CustomersResource = CustomersResource;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import type { DiscountCode, ListResponse, DeletedResponse, CreateDiscountCodeParams, BatchCreateDiscountCodesParams, ValidateDiscountResult, BatchCreateResult, PaginationParams } from "../types";
|
|
3
|
+
export interface ListDiscountCodesParams extends PaginationParams {
|
|
4
|
+
payment_link_id?: string;
|
|
5
|
+
active?: "true" | "false";
|
|
6
|
+
search?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateDiscountCodeParams {
|
|
9
|
+
is_active?: boolean;
|
|
10
|
+
max_uses?: number;
|
|
11
|
+
min_order_amount?: string;
|
|
12
|
+
expires_at?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ValidateDiscountParams {
|
|
15
|
+
code: string;
|
|
16
|
+
payment_link_id?: string;
|
|
17
|
+
amount?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class DiscountCodesResource {
|
|
20
|
+
private client;
|
|
21
|
+
constructor(client: HttpClient);
|
|
22
|
+
list(params?: ListDiscountCodesParams): Promise<ListResponse<DiscountCode>>;
|
|
23
|
+
listAutoPaginate(params?: Omit<ListDiscountCodesParams, "page">): AsyncGenerator<DiscountCode>;
|
|
24
|
+
create(params: CreateDiscountCodeParams): Promise<DiscountCode>;
|
|
25
|
+
update(id: string, params: UpdateDiscountCodeParams): Promise<DiscountCode>;
|
|
26
|
+
delete(id: string): Promise<DeletedResponse>;
|
|
27
|
+
validate(params: ValidateDiscountParams): Promise<ValidateDiscountResult>;
|
|
28
|
+
batchCreate(params: BatchCreateDiscountCodesParams): Promise<BatchCreateResult>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscountCodesResource = void 0;
|
|
4
|
+
const pagination_1 = require("../utils/pagination");
|
|
5
|
+
class DiscountCodesResource {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async list(params) {
|
|
10
|
+
return this.client.get("/discount-codes", params);
|
|
11
|
+
}
|
|
12
|
+
async *listAutoPaginate(params) {
|
|
13
|
+
yield* (0, pagination_1.autoPaginate)((page, limit) => this.list({ ...params, page, limit }), { limit: params?.limit });
|
|
14
|
+
}
|
|
15
|
+
async create(params) {
|
|
16
|
+
return this.client.post("/discount-codes", params);
|
|
17
|
+
}
|
|
18
|
+
async update(id, params) {
|
|
19
|
+
return this.client.patch(`/discount-codes/${id}`, params);
|
|
20
|
+
}
|
|
21
|
+
async delete(id) {
|
|
22
|
+
return this.client.delete(`/discount-codes/${id}`);
|
|
23
|
+
}
|
|
24
|
+
async validate(params) {
|
|
25
|
+
return this.client.post("/discount-codes/validate", params);
|
|
26
|
+
}
|
|
27
|
+
async batchCreate(params) {
|
|
28
|
+
return this.client.post("/discount-codes/batch", params);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.DiscountCodesResource = DiscountCodesResource;
|