@mneepay/sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/client.d.ts +45 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +213 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +240 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks.d.ts +84 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +72 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# MNEE SDK (Node)
|
|
2
|
+
|
|
3
|
+
Lightweight TypeScript client for the MNEE API. This SDK targets Node 18+.
|
|
4
|
+
|
|
5
|
+
## Install (local)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
cd sdk
|
|
9
|
+
bun install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { MneeClient } from '@mneepay/sdk'
|
|
16
|
+
|
|
17
|
+
const client = new MneeClient({
|
|
18
|
+
baseUrl: 'https://mnee.to',
|
|
19
|
+
apiKey: process.env.MNEE_API_KEY,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const products = await client.listProducts()
|
|
23
|
+
if (products.error) {
|
|
24
|
+
throw new Error(products.error.message)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log(products.data)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Included endpoints
|
|
31
|
+
|
|
32
|
+
- Products: list/create/get/update/delete
|
|
33
|
+
- Customers: list/create/get/update/delete
|
|
34
|
+
- Invoices: list/create/get/update/delete
|
|
35
|
+
- Invoices: HTML + PDF render
|
|
36
|
+
- Branding: get/update
|
|
37
|
+
- Payouts: get/update
|
|
38
|
+
- Subscriptions: lookup
|
|
39
|
+
|
|
40
|
+
## Webhook events
|
|
41
|
+
|
|
42
|
+
Webhook deliveries POST JSON payloads with a shared envelope:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {
|
|
46
|
+
parseWebhookEvent,
|
|
47
|
+
verifyWebhookSignature,
|
|
48
|
+
isInvoicePaidEvent,
|
|
49
|
+
isProductPurchaseOneTimeEvent,
|
|
50
|
+
isSubscriptionCreatedEvent,
|
|
51
|
+
isSubscriptionRenewedEvent,
|
|
52
|
+
} from 'mnee-sdk'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const signature = req.headers['x-mnee-signature']
|
|
57
|
+
if (!verifyWebhookSignature(req.body, signature, process.env.MNEE_WEBHOOK_SECRET)) {
|
|
58
|
+
throw new Error('Invalid signature')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const event = parseWebhookEvent(req.body)
|
|
62
|
+
|
|
63
|
+
if (isInvoicePaidEvent(event)) {
|
|
64
|
+
// event.data.invoiceId, event.data.amountCents, ...
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Signature header format: `x-mnee-signature: t=timestamp,v1=hex`.
|
|
69
|
+
|
|
70
|
+
Excluded: auth endpoints, `openapi.yml`, and Alchemy webhook.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ApiResponse, Branding, BrandingUpdateInput, Customer, CustomerCreateInput, CustomerUpdateInput, Invoice, InvoiceCreateInput, InvoiceUpdateInput, InvoiceWithItems, PayoutSettings, PayoutSettingsUpdateInput, Product, ProductCreateInput, ProductUpdateInput, SubscriptionLookupResponse } from './types.js';
|
|
2
|
+
export type MneeClientConfig = {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
};
|
|
7
|
+
export type RequestOptions = {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export declare class MneeClient {
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private apiKey?;
|
|
14
|
+
private readonly fetcher;
|
|
15
|
+
constructor(config: MneeClientConfig);
|
|
16
|
+
setApiKey(apiKey?: string): void;
|
|
17
|
+
listProducts(options?: RequestOptions): Promise<ApiResponse<Product[]>>;
|
|
18
|
+
createProduct(body: ProductCreateInput, options?: RequestOptions): Promise<ApiResponse<Product>>;
|
|
19
|
+
getProduct(id: string, options?: RequestOptions): Promise<ApiResponse<Product>>;
|
|
20
|
+
updateProduct(id: string, body: ProductUpdateInput, options?: RequestOptions): Promise<ApiResponse<Product>>;
|
|
21
|
+
deleteProduct(id: string, options?: RequestOptions): Promise<ApiResponse<Product>>;
|
|
22
|
+
listCustomers(options?: RequestOptions): Promise<ApiResponse<Customer[]>>;
|
|
23
|
+
createCustomer(body: CustomerCreateInput, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
24
|
+
getCustomer(id: string, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
25
|
+
updateCustomer(id: string, body: CustomerUpdateInput, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
26
|
+
deleteCustomer(id: string, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
27
|
+
listInvoices(options?: RequestOptions): Promise<ApiResponse<Invoice[]>>;
|
|
28
|
+
createInvoice(body: InvoiceCreateInput, options?: RequestOptions): Promise<ApiResponse<InvoiceWithItems>>;
|
|
29
|
+
getInvoice(id: string, options?: RequestOptions): Promise<ApiResponse<InvoiceWithItems>>;
|
|
30
|
+
updateInvoice(id: string, body: InvoiceUpdateInput, options?: RequestOptions): Promise<ApiResponse<InvoiceWithItems>>;
|
|
31
|
+
deleteInvoice(id: string, options?: RequestOptions): Promise<ApiResponse<Invoice>>;
|
|
32
|
+
getInvoiceHtml(id: string, options?: RequestOptions): Promise<string>;
|
|
33
|
+
getInvoicePdf(id: string, options?: RequestOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
34
|
+
getBranding(options?: RequestOptions): Promise<ApiResponse<Branding>>;
|
|
35
|
+
updateBranding(body: BrandingUpdateInput, options?: RequestOptions): Promise<ApiResponse<Branding>>;
|
|
36
|
+
getPayouts(options?: RequestOptions): Promise<ApiResponse<PayoutSettings>>;
|
|
37
|
+
updatePayouts(body: PayoutSettingsUpdateInput, options?: RequestOptions): Promise<ApiResponse<PayoutSettings>>;
|
|
38
|
+
lookupSubscription(customerId: string, productId: string, options?: RequestOptions): Promise<ApiResponse<SubscriptionLookupResponse>>;
|
|
39
|
+
private requestJson;
|
|
40
|
+
private requestText;
|
|
41
|
+
private requestBinary;
|
|
42
|
+
private buildHeaders;
|
|
43
|
+
private buildUrl;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,QAAQ,EACR,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,EACP,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,yBAAyB,EACzB,OAAO,EACP,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,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,MAAM,EAAE,OAAO,GAAE,cAAmB;IAOvD,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAOtD,WAAW,CAAC,OAAO,GAAE,cAAmB;IAIxC,cAAc,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,GAAE,cAAmB;IAQtE,UAAU,CAAC,OAAO,GAAE,cAAmB;IAIvC,aAAa,CAAC,IAAI,EAAE,yBAAyB,EAAE,OAAO,GAAE,cAAmB;IAQ3E,kBAAkB,CACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,cAAmB;YAYhB,WAAW;YA2BX,WAAW;YAoBX,aAAa;IAqB3B,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,QAAQ;CAIjB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
export class MneeClient {
|
|
2
|
+
baseUrl;
|
|
3
|
+
apiKey;
|
|
4
|
+
fetcher;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
7
|
+
this.apiKey = config.apiKey;
|
|
8
|
+
this.fetcher = config.fetch ?? globalThis.fetch;
|
|
9
|
+
if (!this.fetcher) {
|
|
10
|
+
throw new Error('Fetch is not available. Provide a fetch implementation.');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
setApiKey(apiKey) {
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
}
|
|
16
|
+
async listProducts(options = {}) {
|
|
17
|
+
return this.requestJson('/api/products/', {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
...options,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async createProduct(body, options = {}) {
|
|
23
|
+
return this.requestJson('/api/products/', {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
body,
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async getProduct(id, options = {}) {
|
|
30
|
+
return this.requestJson(`/api/products/${encodeURIComponent(id)}`, {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
...options,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async updateProduct(id, body, options = {}) {
|
|
36
|
+
return this.requestJson(`/api/products/${encodeURIComponent(id)}`, {
|
|
37
|
+
method: 'PUT',
|
|
38
|
+
body,
|
|
39
|
+
...options,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async deleteProduct(id, options = {}) {
|
|
43
|
+
return this.requestJson(`/api/products/${encodeURIComponent(id)}`, {
|
|
44
|
+
method: 'DELETE',
|
|
45
|
+
...options,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async listCustomers(options = {}) {
|
|
49
|
+
return this.requestJson('/api/customers/', {
|
|
50
|
+
method: 'GET',
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async createCustomer(body, options = {}) {
|
|
55
|
+
return this.requestJson('/api/customers/', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
body,
|
|
58
|
+
...options,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async getCustomer(id, options = {}) {
|
|
62
|
+
return this.requestJson(`/api/customers/${encodeURIComponent(id)}`, {
|
|
63
|
+
method: 'GET',
|
|
64
|
+
...options,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async updateCustomer(id, body, options = {}) {
|
|
68
|
+
return this.requestJson(`/api/customers/${encodeURIComponent(id)}`, {
|
|
69
|
+
method: 'PUT',
|
|
70
|
+
body,
|
|
71
|
+
...options,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async deleteCustomer(id, options = {}) {
|
|
75
|
+
return this.requestJson(`/api/customers/${encodeURIComponent(id)}`, {
|
|
76
|
+
method: 'DELETE',
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async listInvoices(options = {}) {
|
|
81
|
+
return this.requestJson('/api/invoices/', {
|
|
82
|
+
method: 'GET',
|
|
83
|
+
...options,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async createInvoice(body, options = {}) {
|
|
87
|
+
return this.requestJson('/api/invoices/', {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
body,
|
|
90
|
+
...options,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async getInvoice(id, options = {}) {
|
|
94
|
+
return this.requestJson(`/api/invoices/${encodeURIComponent(id)}`, {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
...options,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async updateInvoice(id, body, options = {}) {
|
|
100
|
+
return this.requestJson(`/api/invoices/${encodeURIComponent(id)}`, {
|
|
101
|
+
method: 'PUT',
|
|
102
|
+
body,
|
|
103
|
+
...options,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async deleteInvoice(id, options = {}) {
|
|
107
|
+
return this.requestJson(`/api/invoices/${encodeURIComponent(id)}`, {
|
|
108
|
+
method: 'DELETE',
|
|
109
|
+
...options,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async getInvoiceHtml(id, options = {}) {
|
|
113
|
+
return this.requestText(`/api/invoices/${encodeURIComponent(id)}/html`, {
|
|
114
|
+
method: 'GET',
|
|
115
|
+
...options,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async getInvoicePdf(id, options = {}) {
|
|
119
|
+
return this.requestBinary(`/api/invoices/${encodeURIComponent(id)}/pdf`, {
|
|
120
|
+
method: 'GET',
|
|
121
|
+
...options,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async getBranding(options = {}) {
|
|
125
|
+
return this.requestJson('/api/branding', { method: 'GET', ...options });
|
|
126
|
+
}
|
|
127
|
+
async updateBranding(body, options = {}) {
|
|
128
|
+
return this.requestJson('/api/branding', {
|
|
129
|
+
method: 'PUT',
|
|
130
|
+
body,
|
|
131
|
+
...options,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async getPayouts(options = {}) {
|
|
135
|
+
return this.requestJson('/api/payouts', { method: 'GET', ...options });
|
|
136
|
+
}
|
|
137
|
+
async updatePayouts(body, options = {}) {
|
|
138
|
+
return this.requestJson('/api/payouts', {
|
|
139
|
+
method: 'PUT',
|
|
140
|
+
body,
|
|
141
|
+
...options,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async lookupSubscription(customerId, productId, options = {}) {
|
|
145
|
+
const query = new URLSearchParams({ customerId, productId });
|
|
146
|
+
return this.requestJson(`/api/subscriptions/lookup?${query.toString()}`, {
|
|
147
|
+
method: 'GET',
|
|
148
|
+
...options,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async requestJson(path, options) {
|
|
152
|
+
const response = await this.fetcher(this.buildUrl(path), {
|
|
153
|
+
method: options.method,
|
|
154
|
+
headers: this.buildHeaders(options.headers, Boolean(options.body)),
|
|
155
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
156
|
+
signal: options.signal,
|
|
157
|
+
});
|
|
158
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
159
|
+
if (!contentType.includes('application/json')) {
|
|
160
|
+
const text = await response.text().catch(() => '');
|
|
161
|
+
throw new Error(`Expected JSON response (${response.status}). ${text ? `Body: ${text}` : ''}`.trim());
|
|
162
|
+
}
|
|
163
|
+
const payload = (await response.json());
|
|
164
|
+
if (!response.ok && !payload.error) {
|
|
165
|
+
payload.error = { message: `Request failed (${response.status}).` };
|
|
166
|
+
}
|
|
167
|
+
return payload;
|
|
168
|
+
}
|
|
169
|
+
async requestText(path, options) {
|
|
170
|
+
const response = await this.fetcher(this.buildUrl(path), {
|
|
171
|
+
method: options.method,
|
|
172
|
+
headers: this.buildHeaders(options.headers, false),
|
|
173
|
+
signal: options.signal,
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
const text = await response.text().catch(() => '');
|
|
177
|
+
throw new Error(`Request failed (${response.status}). ${text ? `Body: ${text}` : ''}`.trim());
|
|
178
|
+
}
|
|
179
|
+
return await response.text();
|
|
180
|
+
}
|
|
181
|
+
async requestBinary(path, options) {
|
|
182
|
+
const response = await this.fetcher(this.buildUrl(path), {
|
|
183
|
+
method: options.method,
|
|
184
|
+
headers: this.buildHeaders(options.headers, false),
|
|
185
|
+
signal: options.signal,
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
const text = await response.text().catch(() => '');
|
|
189
|
+
throw new Error(`Request failed (${response.status}). ${text ? `Body: ${text}` : ''}`.trim());
|
|
190
|
+
}
|
|
191
|
+
const buffer = await response.arrayBuffer();
|
|
192
|
+
return new Uint8Array(buffer);
|
|
193
|
+
}
|
|
194
|
+
buildHeaders(extra, hasBody) {
|
|
195
|
+
const headers = {
|
|
196
|
+
...(hasBody ? { 'Content-Type': 'application/json' } : {}),
|
|
197
|
+
...extra,
|
|
198
|
+
};
|
|
199
|
+
if (this.apiKey) {
|
|
200
|
+
headers['x-api-key'] = this.apiKey;
|
|
201
|
+
}
|
|
202
|
+
return headers;
|
|
203
|
+
}
|
|
204
|
+
buildUrl(path) {
|
|
205
|
+
if (path.startsWith('http'))
|
|
206
|
+
return path;
|
|
207
|
+
return `${this.baseUrl}${path.startsWith('/') ? '' : '/'}${path}`;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function normalizeBaseUrl(baseUrl) {
|
|
211
|
+
return baseUrl.replace(/\/+$/, '');
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,UAAU;IACJ,OAAO,CAAQ;IACxB,MAAM,CAAS;IACN,OAAO,CAAc;IAEtC,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CA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AAM,QAAQ,CAAC,WAAW,EAAE,CAAA;QAC3C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;IAEO,YAAY,CAClB,KAA8B,EAC9B,OAAiB;QAEjB,MAAM,OAAO,GAA2B;YACtC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,KAAK;SACT,CAAA;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;QACpC,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAEO,QAAQ,CAAC,IAAY;QAC3B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAA;QACxC,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,EAAE,CAAA;IACnE,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,mBAAmB,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
export type ApiError = {
|
|
2
|
+
message: string;
|
|
3
|
+
};
|
|
4
|
+
export type ApiResponse<T> = {
|
|
5
|
+
data: T;
|
|
6
|
+
error?: ApiError;
|
|
7
|
+
};
|
|
8
|
+
export type Customer = {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
email: string;
|
|
12
|
+
website: string | null;
|
|
13
|
+
address: string | null;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
};
|
|
16
|
+
export type Product = {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string | null;
|
|
20
|
+
imageBase64: string | null;
|
|
21
|
+
priceCents: number | null;
|
|
22
|
+
currency: string;
|
|
23
|
+
active: boolean;
|
|
24
|
+
billingType: 'one_time' | 'recurring';
|
|
25
|
+
recurringInterval: string | null;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
plans: ProductPlan[];
|
|
28
|
+
};
|
|
29
|
+
export type ProductPlan = {
|
|
30
|
+
id: string;
|
|
31
|
+
productId: string;
|
|
32
|
+
name: string;
|
|
33
|
+
description: string | null;
|
|
34
|
+
priceCents: number;
|
|
35
|
+
active: boolean;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
};
|
|
38
|
+
export type ProductPlanInput = {
|
|
39
|
+
name: string;
|
|
40
|
+
description?: string | null;
|
|
41
|
+
priceCents: number;
|
|
42
|
+
active?: boolean;
|
|
43
|
+
};
|
|
44
|
+
export type Invoice = {
|
|
45
|
+
id: string;
|
|
46
|
+
customerId: string;
|
|
47
|
+
subscriptionId?: string | null;
|
|
48
|
+
amountCents: number;
|
|
49
|
+
currency: string;
|
|
50
|
+
status: string;
|
|
51
|
+
paidAt?: string | null;
|
|
52
|
+
issuedAt: string | null;
|
|
53
|
+
dueAt: string | null;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
};
|
|
56
|
+
export type InvoiceItem = {
|
|
57
|
+
id: string;
|
|
58
|
+
invoiceId: string;
|
|
59
|
+
productId: string | null;
|
|
60
|
+
name: string;
|
|
61
|
+
description: string | null;
|
|
62
|
+
unitPriceCents: number;
|
|
63
|
+
quantity: number;
|
|
64
|
+
currency: string;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
};
|
|
67
|
+
export type Purchase = {
|
|
68
|
+
id: string;
|
|
69
|
+
userId: string;
|
|
70
|
+
customerId: string;
|
|
71
|
+
productId: string;
|
|
72
|
+
invoiceId?: string | null;
|
|
73
|
+
amountCents: number;
|
|
74
|
+
currency: string;
|
|
75
|
+
paidAt: string;
|
|
76
|
+
createdAt: string;
|
|
77
|
+
};
|
|
78
|
+
export type Event = {
|
|
79
|
+
id: string;
|
|
80
|
+
userId: string;
|
|
81
|
+
customerId?: string | null;
|
|
82
|
+
type: string;
|
|
83
|
+
resourceType: string;
|
|
84
|
+
resourceId: string;
|
|
85
|
+
payload: Record<string, unknown>;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
};
|
|
88
|
+
export type WebhookSettings = {
|
|
89
|
+
id: string;
|
|
90
|
+
userId: string;
|
|
91
|
+
url: string;
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
signingSecret: string;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
};
|
|
97
|
+
export type WebhookUpdateInput = {
|
|
98
|
+
url?: string;
|
|
99
|
+
enabled?: boolean;
|
|
100
|
+
};
|
|
101
|
+
export type WebhookDelivery = {
|
|
102
|
+
id: string;
|
|
103
|
+
eventId: string;
|
|
104
|
+
webhookId: string;
|
|
105
|
+
status: 'pending' | 'success' | 'failed';
|
|
106
|
+
attempts: number;
|
|
107
|
+
nextAttemptAt: string;
|
|
108
|
+
lastAttemptAt?: string | null;
|
|
109
|
+
lastError?: string | null;
|
|
110
|
+
responseCode?: number | null;
|
|
111
|
+
responseBody?: string | null;
|
|
112
|
+
createdAt: string;
|
|
113
|
+
updatedAt: string;
|
|
114
|
+
};
|
|
115
|
+
export type PaymentIntent = {
|
|
116
|
+
id: string;
|
|
117
|
+
userId: string;
|
|
118
|
+
customerId?: string | null;
|
|
119
|
+
pid: string;
|
|
120
|
+
resourceType: string;
|
|
121
|
+
resourceId: string;
|
|
122
|
+
amountWei: string;
|
|
123
|
+
tokenSymbol: string;
|
|
124
|
+
tokenAddress: string;
|
|
125
|
+
chainId: number;
|
|
126
|
+
fromAddress?: string | null;
|
|
127
|
+
toAddress: string;
|
|
128
|
+
txHash?: string | null;
|
|
129
|
+
status: 'created' | 'submitted' | 'confirmed' | 'failed' | 'expired';
|
|
130
|
+
confirmations: number;
|
|
131
|
+
confirmationTarget: number;
|
|
132
|
+
metadata: Record<string, unknown>;
|
|
133
|
+
submittedAt?: string | null;
|
|
134
|
+
confirmedAt?: string | null;
|
|
135
|
+
createdAt: string;
|
|
136
|
+
updatedAt: string;
|
|
137
|
+
};
|
|
138
|
+
export type InvoiceWithItems = Invoice & {
|
|
139
|
+
items: InvoiceItem[];
|
|
140
|
+
};
|
|
141
|
+
export type Subscription = {
|
|
142
|
+
id: string;
|
|
143
|
+
userId: string;
|
|
144
|
+
customerId: string;
|
|
145
|
+
productId: string;
|
|
146
|
+
planId: string;
|
|
147
|
+
status: string;
|
|
148
|
+
currentPeriodStart: string;
|
|
149
|
+
currentPeriodEnd: string;
|
|
150
|
+
cancelAtPeriodEnd: boolean;
|
|
151
|
+
createdAt: string;
|
|
152
|
+
updatedAt: string;
|
|
153
|
+
};
|
|
154
|
+
export type SubscriptionWithPlan = Subscription & {
|
|
155
|
+
plan: ProductPlan;
|
|
156
|
+
};
|
|
157
|
+
export type CustomerCreateInput = {
|
|
158
|
+
name: string;
|
|
159
|
+
email: string;
|
|
160
|
+
website?: string | null;
|
|
161
|
+
address?: string | null;
|
|
162
|
+
};
|
|
163
|
+
export type CustomerUpdateInput = Partial<CustomerCreateInput>;
|
|
164
|
+
export type ProductCreateInput = {
|
|
165
|
+
name: string;
|
|
166
|
+
description?: string | null;
|
|
167
|
+
imageBase64?: string | null;
|
|
168
|
+
priceCents?: number | null;
|
|
169
|
+
currency?: string;
|
|
170
|
+
active?: boolean;
|
|
171
|
+
billingType?: 'one_time' | 'recurring';
|
|
172
|
+
recurringInterval?: string | null;
|
|
173
|
+
plans?: ProductPlanInput[];
|
|
174
|
+
};
|
|
175
|
+
export type ProductUpdateInput = Partial<ProductCreateInput>;
|
|
176
|
+
export type InvoiceCreateInput = {
|
|
177
|
+
customerId: string;
|
|
178
|
+
items: InvoiceItemInput[];
|
|
179
|
+
status?: string;
|
|
180
|
+
issuedAt?: string | null;
|
|
181
|
+
dueAt?: string | null;
|
|
182
|
+
};
|
|
183
|
+
export type InvoiceItemInput = {
|
|
184
|
+
productId?: string | null;
|
|
185
|
+
planId?: string | null;
|
|
186
|
+
name?: string;
|
|
187
|
+
description?: string | null;
|
|
188
|
+
unitPriceCents?: number;
|
|
189
|
+
quantity?: number;
|
|
190
|
+
};
|
|
191
|
+
export type InvoiceUpdateInput = Partial<InvoiceCreateInput> & {
|
|
192
|
+
status?: string;
|
|
193
|
+
issuedAt?: string | null;
|
|
194
|
+
dueAt?: string | null;
|
|
195
|
+
};
|
|
196
|
+
export type Branding = {
|
|
197
|
+
id: string;
|
|
198
|
+
userId: string;
|
|
199
|
+
businessName: string;
|
|
200
|
+
businessEmail: string | null;
|
|
201
|
+
businessWebsite: string | null;
|
|
202
|
+
businessPhone: string | null;
|
|
203
|
+
businessAddress: string | null;
|
|
204
|
+
iconBase64: string | null;
|
|
205
|
+
primaryColor: string;
|
|
206
|
+
accentColor: string;
|
|
207
|
+
createdAt: string;
|
|
208
|
+
updatedAt: string;
|
|
209
|
+
};
|
|
210
|
+
export type BrandingUpdateInput = {
|
|
211
|
+
businessName?: string;
|
|
212
|
+
businessEmail?: string | null;
|
|
213
|
+
businessWebsite?: string | null;
|
|
214
|
+
businessPhone?: string | null;
|
|
215
|
+
businessAddress?: string | null;
|
|
216
|
+
iconBase64?: string | null;
|
|
217
|
+
primaryColor?: string;
|
|
218
|
+
accentColor?: string;
|
|
219
|
+
};
|
|
220
|
+
export type PayoutSettings = {
|
|
221
|
+
id: string;
|
|
222
|
+
userId: string;
|
|
223
|
+
walletAddress: string | null;
|
|
224
|
+
network: string;
|
|
225
|
+
tokenSymbol: string;
|
|
226
|
+
createdAt: string;
|
|
227
|
+
updatedAt: string;
|
|
228
|
+
};
|
|
229
|
+
export type PayoutSettingsUpdateInput = {
|
|
230
|
+
walletAddress?: string | null;
|
|
231
|
+
};
|
|
232
|
+
export type SubscriptionLookupResponse = {
|
|
233
|
+
subscription: SubscriptionWithPlan | null;
|
|
234
|
+
suggestedPeriod: {
|
|
235
|
+
start: string;
|
|
236
|
+
end: string;
|
|
237
|
+
} | null;
|
|
238
|
+
lastInvoiceStatus: string | null;
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,CAAC,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,UAAU,EAAE,MAAM,GAAG,IA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":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type WebhookEventType = 'invoice.paid' | 'product.purchase.one_time' | 'subscription.created' | 'subscription.renewed';
|
|
2
|
+
export type WebhookEventResource = {
|
|
3
|
+
type: string;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export type WebhookEventBase = {
|
|
7
|
+
id: string;
|
|
8
|
+
type: WebhookEventType | string;
|
|
9
|
+
created: string;
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
resource: WebhookEventResource;
|
|
12
|
+
customerId: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type InvoicePaidData = {
|
|
15
|
+
invoiceId: string;
|
|
16
|
+
customerId?: string;
|
|
17
|
+
subscriptionId?: string;
|
|
18
|
+
amountCents?: number;
|
|
19
|
+
currency?: string;
|
|
20
|
+
};
|
|
21
|
+
export type ProductPurchaseOneTimeData = {
|
|
22
|
+
purchaseId: string;
|
|
23
|
+
productId: string;
|
|
24
|
+
customerId: string;
|
|
25
|
+
invoiceId?: string;
|
|
26
|
+
amountCents: number;
|
|
27
|
+
currency: string;
|
|
28
|
+
};
|
|
29
|
+
export type SubscriptionCreatedData = {
|
|
30
|
+
subscriptionId: string;
|
|
31
|
+
productId: string;
|
|
32
|
+
planId: string;
|
|
33
|
+
customerId: string;
|
|
34
|
+
};
|
|
35
|
+
export type SubscriptionRenewedData = {
|
|
36
|
+
subscriptionId: string;
|
|
37
|
+
customerId: string;
|
|
38
|
+
};
|
|
39
|
+
export type InvoicePaidEvent = WebhookEventBase & {
|
|
40
|
+
type: 'invoice.paid';
|
|
41
|
+
data: InvoicePaidData;
|
|
42
|
+
resource: {
|
|
43
|
+
type: 'invoice';
|
|
44
|
+
id: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type ProductPurchaseOneTimeEvent = WebhookEventBase & {
|
|
48
|
+
type: 'product.purchase.one_time';
|
|
49
|
+
data: ProductPurchaseOneTimeData;
|
|
50
|
+
resource: {
|
|
51
|
+
type: 'purchase';
|
|
52
|
+
id: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export type SubscriptionCreatedEvent = WebhookEventBase & {
|
|
56
|
+
type: 'subscription.created';
|
|
57
|
+
data: SubscriptionCreatedData;
|
|
58
|
+
resource: {
|
|
59
|
+
type: 'subscription';
|
|
60
|
+
id: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export type SubscriptionRenewedEvent = WebhookEventBase & {
|
|
64
|
+
type: 'subscription.renewed';
|
|
65
|
+
data: SubscriptionRenewedData;
|
|
66
|
+
resource: {
|
|
67
|
+
type: 'subscription';
|
|
68
|
+
id: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export type WebhookEvent = InvoicePaidEvent | ProductPurchaseOneTimeEvent | SubscriptionCreatedEvent | SubscriptionRenewedEvent | WebhookEventBase;
|
|
72
|
+
export type WebhookSignature = {
|
|
73
|
+
timestamp: number;
|
|
74
|
+
signature: string;
|
|
75
|
+
};
|
|
76
|
+
export declare function parseWebhookEvent(payload: string | unknown): WebhookEvent;
|
|
77
|
+
export declare function parseWebhookSignature(header: string): WebhookSignature;
|
|
78
|
+
export declare function verifyWebhookSignature(payload: string, header: string, secret: string, toleranceSec?: number): boolean;
|
|
79
|
+
export declare function isWebhookEvent(value: unknown): value is WebhookEventBase;
|
|
80
|
+
export declare function isInvoicePaidEvent(event: WebhookEventBase): event is InvoicePaidEvent;
|
|
81
|
+
export declare function isProductPurchaseOneTimeEvent(event: WebhookEventBase): event is ProductPurchaseOneTimeEvent;
|
|
82
|
+
export declare function isSubscriptionCreatedEvent(event: WebhookEventBase): event is SubscriptionCreatedEvent;
|
|
83
|
+
export declare function isSubscriptionRenewedEvent(event: WebhookEventBase): event is SubscriptionRenewedEvent;
|
|
84
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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M,GAAG,gBAAgB,CAiBtE;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,SAAM,GACjB,OAAO,CAwBT;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAYxE;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,GACtB,KAAK,IAAI,gBAAgB,CAE3B;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,gBAAgB,GACtB,KAAK,IAAI,2BAA2B,CAEtC;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,GACtB,KAAK,IAAI,wBAAwB,CAEnC;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,GACtB,KAAK,IAAI,wBAAwB,CAEnC"}
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
export function parseWebhookEvent(payload) {
|
|
3
|
+
const value = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
|
4
|
+
if (!isWebhookEvent(value)) {
|
|
5
|
+
throw new Error('Invalid webhook event payload.');
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function parseWebhookSignature(header) {
|
|
10
|
+
const parts = header.split(',').map((part) => part.trim());
|
|
11
|
+
const parsed = {};
|
|
12
|
+
for (const part of parts) {
|
|
13
|
+
const [key, value] = part.split('=');
|
|
14
|
+
if (key && value)
|
|
15
|
+
parsed[key] = value;
|
|
16
|
+
}
|
|
17
|
+
const timestamp = Number(parsed.t);
|
|
18
|
+
const signature = parsed.v1;
|
|
19
|
+
if (!Number.isFinite(timestamp) || !signature) {
|
|
20
|
+
throw new Error('Invalid signature header.');
|
|
21
|
+
}
|
|
22
|
+
return { timestamp, signature };
|
|
23
|
+
}
|
|
24
|
+
export function verifyWebhookSignature(payload, header, secret, toleranceSec = 300) {
|
|
25
|
+
if (!payload || !header || !secret)
|
|
26
|
+
return false;
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = parseWebhookSignature(header);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const now = Math.floor(Date.now() / 1000);
|
|
35
|
+
if (Math.abs(now - parsed.timestamp) > toleranceSec) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const signedPayload = `${parsed.timestamp}.${payload}`;
|
|
39
|
+
const expected = createHmac('sha256', secret)
|
|
40
|
+
.update(signedPayload, 'utf8')
|
|
41
|
+
.digest('hex');
|
|
42
|
+
const expectedBuffer = Buffer.from(expected, 'utf8');
|
|
43
|
+
const providedBuffer = Buffer.from(parsed.signature, 'utf8');
|
|
44
|
+
if (expectedBuffer.length !== providedBuffer.length)
|
|
45
|
+
return false;
|
|
46
|
+
return timingSafeEqual(expectedBuffer, providedBuffer);
|
|
47
|
+
}
|
|
48
|
+
export function isWebhookEvent(value) {
|
|
49
|
+
if (!value || typeof value !== 'object')
|
|
50
|
+
return false;
|
|
51
|
+
const record = value;
|
|
52
|
+
return (typeof record.id === 'string' &&
|
|
53
|
+
typeof record.type === 'string' &&
|
|
54
|
+
typeof record.created === 'string' &&
|
|
55
|
+
typeof record.data === 'object' &&
|
|
56
|
+
record.data !== null &&
|
|
57
|
+
typeof record.resource === 'object' &&
|
|
58
|
+
record.resource !== null);
|
|
59
|
+
}
|
|
60
|
+
export function isInvoicePaidEvent(event) {
|
|
61
|
+
return event.type === 'invoice.paid';
|
|
62
|
+
}
|
|
63
|
+
export function isProductPurchaseOneTimeEvent(event) {
|
|
64
|
+
return event.type === 'product.purchase.one_time';
|
|
65
|
+
}
|
|
66
|
+
export function isSubscriptionCreatedEvent(event) {
|
|
67
|
+
return event.type === 'subscription.created';
|
|
68
|
+
}
|
|
69
|
+
export function isSubscriptionRenewedEvent(event) {
|
|
70
|
+
return event.type === 'subscription.renewed';
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAuFzD,MAAM,UAAU,iBAAiB,CAAC,OAAyB;IACzD,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;IACzE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACnD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1D,MAAM,MAAM,GAA2B,EAAE,CAAA;IAEzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACpC,IAAI,GAAG,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACvC,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAA;IAE3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,S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,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACrD,MAAM,MAAM,GAAG,KAAgC,CAAA;IAC/C,OAAO,CACL,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ;QAClC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ;QACnC,MAAM,CAAC,QAAQ,KAAK,IAAI,CACzB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,KAAuB;IAEvB,OAAO,KAAK,CAAC,IAAI,KAAK,cAAc,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAAuB;IAEvB,OAAO,KAAK,CAAC,IAAI,KAAK,2BAA2B,CAAA;AACnD,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAuB;IAEvB,OAAO,KAAK,CAAC,IAAI,KAAK,sBAAsB,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAuB;IAEvB,OAAO,KAAK,CAAC,IAAI,KAAK,sBAAsB,CAAA;AAC9C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mneepay/sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.10.2"
|
|
24
|
+
}
|
|
25
|
+
}
|