@moonpay/platform-sdk-core 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +74 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +71 -29
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Customer } from '@moonpay/platform-protocol/api/customer';
|
|
2
|
+
import { GetCustomerError, GetCustomerUploadUrlError, SubmitCustomerFilesError, SubmitCustomerKycError, DevPlatformApiError, GetAssetsError, GetQuoteError, GetTransactionsError, CreateIdentityError, GetIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError, UpdateIdentityError, VerifyIdentityError, GetPaymentMethodsError } from '@moonpay/platform-protocol/api/errors';
|
|
3
|
+
import { IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, UpdateIdentityRequestBody, CreateIdentityRequestBody, Identity, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
|
|
2
4
|
import { Result } from '@moonpay/platform-protocol/result';
|
|
3
5
|
import { ListAssetsResponse, GetQuoteParams, Quote, TransactionWithStages, Transaction, PaginationInfo, ListPaymentMethodsResponse } from '@moonpay/platform-protocol/api';
|
|
4
|
-
import { CreateIdentityRequestBody, Identity, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, UpdateIdentityRequestBody, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
|
|
5
6
|
import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
|
|
6
7
|
import { DecryptedCredentials } from '@moonpay/platform-protocol/models/connection';
|
|
7
8
|
|
|
@@ -19,6 +20,18 @@ interface ClientContextOptions {
|
|
|
19
20
|
}
|
|
20
21
|
declare function createClientContext(options?: ClientContextOptions): ClientContext;
|
|
21
22
|
|
|
23
|
+
/** The API wraps each customer response in a `{ data: ... }` envelope. */
|
|
24
|
+
interface CustomerEnvelope {
|
|
25
|
+
data: Customer;
|
|
26
|
+
}
|
|
27
|
+
interface UploadUrlEnvelope$1 {
|
|
28
|
+
data: IdentityFileUploadUrl;
|
|
29
|
+
}
|
|
30
|
+
declare function getCustomer(ctx: ClientContext, id: string): Promise<Result<CustomerEnvelope, GetCustomerError>>;
|
|
31
|
+
declare function submitCustomerKyc(ctx: ClientContext, id: string, body: UpdateIdentityRequestBody): Promise<Result<CustomerEnvelope, SubmitCustomerKycError>>;
|
|
32
|
+
declare function getCustomerUploadUrl(ctx: ClientContext, id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<UploadUrlEnvelope$1, GetCustomerUploadUrlError>>;
|
|
33
|
+
declare function submitCustomerFiles(ctx: ClientContext, id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<CustomerEnvelope, SubmitCustomerFilesError>>;
|
|
34
|
+
|
|
22
35
|
/** Typed fetch that wraps responses in Result<T, E>. */
|
|
23
36
|
declare function apiFetch<T>(ctx: ClientContext, path: string, options?: RequestInit): Promise<Result<T, DevPlatformApiError>>;
|
|
24
37
|
|
|
@@ -67,14 +80,22 @@ interface UploadUrlEnvelope {
|
|
|
67
80
|
/**
|
|
68
81
|
* Create an identity. Returns the created identity, or `null` when the
|
|
69
82
|
* customer has no outstanding requirements (the API returns 204).
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Customers are created automatically now — call `getCustomer`
|
|
85
|
+
* directly instead.
|
|
70
86
|
*/
|
|
71
87
|
declare function createIdentity(ctx: ClientContext, body: CreateIdentityRequestBody): Promise<Result<{
|
|
72
88
|
data: Identity | null;
|
|
73
89
|
}, CreateIdentityError>>;
|
|
90
|
+
/** @deprecated Use `getCustomer` instead. */
|
|
74
91
|
declare function getIdentity(ctx: ClientContext, id: string): Promise<Result<IdentityEnvelope, GetIdentityError>>;
|
|
92
|
+
/** @deprecated Use `submitCustomerKyc` instead. */
|
|
75
93
|
declare function updateIdentity(ctx: ClientContext, id: string, body: UpdateIdentityRequestBody): Promise<Result<IdentityEnvelope, UpdateIdentityError>>;
|
|
94
|
+
/** @deprecated No longer needed — Customer API verification has no direct replacement call. */
|
|
76
95
|
declare function verifyIdentity(ctx: ClientContext, id: string): Promise<Result<VerificationEnvelope, VerifyIdentityError>>;
|
|
96
|
+
/** @deprecated Use `getCustomerUploadUrl` instead. */
|
|
77
97
|
declare function getIdentityUploadUrl(ctx: ClientContext, id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<UploadUrlEnvelope, GetIdentityUploadUrlError>>;
|
|
98
|
+
/** @deprecated Use `submitCustomerFiles` instead. */
|
|
78
99
|
declare function submitIdentityFiles(ctx: ClientContext, id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<IdentityEnvelope, SubmitIdentityFilesError>>;
|
|
79
100
|
|
|
80
101
|
declare function getPaymentMethods(ctx: ClientContext): Promise<Result<{
|
|
@@ -119,6 +140,7 @@ declare const FRAME_PATHS: {
|
|
|
119
140
|
readonly challenge: "/platform/v1/challenge";
|
|
120
141
|
readonly addCard: "/platform/v1/add-card";
|
|
121
142
|
readonly reset: "/platform/v1/reset";
|
|
143
|
+
readonly customerExport: "/v2/customer-export";
|
|
122
144
|
};
|
|
123
145
|
interface UrlBuilderOptions {
|
|
124
146
|
/** Base URL for MoonPay frames. Defaults to production. */
|
|
@@ -177,21 +199,39 @@ interface CoreClient {
|
|
|
177
199
|
data: TransactionWithStages;
|
|
178
200
|
}, GetTransactionsError>>;
|
|
179
201
|
deletePaymentMethod(id: string): Promise<Result<void, DevPlatformApiError>>;
|
|
202
|
+
getCustomer(id: string): Promise<Result<{
|
|
203
|
+
data: Customer;
|
|
204
|
+
}, GetCustomerError>>;
|
|
205
|
+
submitCustomerKyc(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
|
|
206
|
+
data: Customer;
|
|
207
|
+
}, SubmitCustomerKycError>>;
|
|
208
|
+
getCustomerUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
|
|
209
|
+
data: IdentityFileUploadUrl;
|
|
210
|
+
}, GetCustomerUploadUrlError>>;
|
|
211
|
+
submitCustomerFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
|
|
212
|
+
data: Customer;
|
|
213
|
+
}, SubmitCustomerFilesError>>;
|
|
214
|
+
/** @deprecated Customers are created automatically now — call `getCustomer` directly instead. */
|
|
180
215
|
createIdentity(body: CreateIdentityRequestBody): Promise<Result<{
|
|
181
216
|
data: Identity | null;
|
|
182
217
|
}, CreateIdentityError>>;
|
|
218
|
+
/** @deprecated Use `getCustomer` instead. */
|
|
183
219
|
getIdentity(id: string): Promise<Result<{
|
|
184
220
|
data: Identity;
|
|
185
221
|
}, GetIdentityError>>;
|
|
222
|
+
/** @deprecated Use `submitCustomerKyc` instead. */
|
|
186
223
|
updateIdentity(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
|
|
187
224
|
data: Identity;
|
|
188
225
|
}, UpdateIdentityError>>;
|
|
226
|
+
/** @deprecated No longer needed — Customer API verification has no direct replacement call. */
|
|
189
227
|
verifyIdentity(id: string): Promise<Result<{
|
|
190
228
|
data: IdentityVerificationResponse;
|
|
191
229
|
}, VerifyIdentityError>>;
|
|
230
|
+
/** @deprecated Use `getCustomerUploadUrl` instead. */
|
|
192
231
|
getIdentityUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
|
|
193
232
|
data: IdentityFileUploadUrl;
|
|
194
233
|
}, GetIdentityUploadUrlError>>;
|
|
234
|
+
/** @deprecated Use `submitCustomerFiles` instead. */
|
|
195
235
|
submitIdentityFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
|
|
196
236
|
data: Identity;
|
|
197
237
|
}, SubmitIdentityFilesError>>;
|
|
@@ -246,4 +286,31 @@ interface FrameHandle {
|
|
|
246
286
|
*/
|
|
247
287
|
declare function createFrameOrchestrator(options: FrameOrchestratorOptions): Promise<FrameHandle>;
|
|
248
288
|
|
|
249
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Trusted MoonPay frame origins.
|
|
291
|
+
*
|
|
292
|
+
* This set is the single source of truth for two boundaries that MUST stay
|
|
293
|
+
* aligned so an accepted frame can both render *and* complete the postMessage
|
|
294
|
+
* handshake (SE-3808):
|
|
295
|
+
*
|
|
296
|
+
* 1. Which URLs `setupChallenge()` — and, defensively, the transports — will
|
|
297
|
+
* load into a frame.
|
|
298
|
+
* 2. Which postMessage origins a transport accepts messages from.
|
|
299
|
+
*
|
|
300
|
+
* Each pattern encodes its scheme, so MoonPay origins require `https:` and only
|
|
301
|
+
* `localhost` is permitted over `http:` for local development. This mirrors the
|
|
302
|
+
* `isTrustedMoonPayUrl()` trust pattern used for `apiBaseUrl`, but the allowlist
|
|
303
|
+
* is intentionally the frame (postMessage) set rather than the API set.
|
|
304
|
+
*/
|
|
305
|
+
declare const TRUSTED_FRAME_ORIGIN_PATTERNS: readonly RegExp[];
|
|
306
|
+
/** True if `origin` (e.g. `https://platform.moonpay.com`) is a trusted MoonPay frame origin. */
|
|
307
|
+
declare function isTrustedFrameOrigin(origin: string): boolean;
|
|
308
|
+
/**
|
|
309
|
+
* True if `value` is a well-formed URL served from a trusted MoonPay frame
|
|
310
|
+
* origin. Fails closed on unparseable input or an untrusted/off-protocol origin,
|
|
311
|
+
* so a partner-supplied challenge URL can never load non-MoonPay content into a
|
|
312
|
+
* trusted frame container (SE-3808).
|
|
313
|
+
*/
|
|
314
|
+
declare function isTrustedFrameUrl(value: string): boolean;
|
|
315
|
+
|
|
316
|
+
export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type KeyPair, type ListAssetsParams, type ListTransactionsParams, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Customer } from '@moonpay/platform-protocol/api/customer';
|
|
2
|
+
import { GetCustomerError, GetCustomerUploadUrlError, SubmitCustomerFilesError, SubmitCustomerKycError, DevPlatformApiError, GetAssetsError, GetQuoteError, GetTransactionsError, CreateIdentityError, GetIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError, UpdateIdentityError, VerifyIdentityError, GetPaymentMethodsError } from '@moonpay/platform-protocol/api/errors';
|
|
3
|
+
import { IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, UpdateIdentityRequestBody, CreateIdentityRequestBody, Identity, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
|
|
2
4
|
import { Result } from '@moonpay/platform-protocol/result';
|
|
3
5
|
import { ListAssetsResponse, GetQuoteParams, Quote, TransactionWithStages, Transaction, PaginationInfo, ListPaymentMethodsResponse } from '@moonpay/platform-protocol/api';
|
|
4
|
-
import { CreateIdentityRequestBody, Identity, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, UpdateIdentityRequestBody, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
|
|
5
6
|
import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
|
|
6
7
|
import { DecryptedCredentials } from '@moonpay/platform-protocol/models/connection';
|
|
7
8
|
|
|
@@ -19,6 +20,18 @@ interface ClientContextOptions {
|
|
|
19
20
|
}
|
|
20
21
|
declare function createClientContext(options?: ClientContextOptions): ClientContext;
|
|
21
22
|
|
|
23
|
+
/** The API wraps each customer response in a `{ data: ... }` envelope. */
|
|
24
|
+
interface CustomerEnvelope {
|
|
25
|
+
data: Customer;
|
|
26
|
+
}
|
|
27
|
+
interface UploadUrlEnvelope$1 {
|
|
28
|
+
data: IdentityFileUploadUrl;
|
|
29
|
+
}
|
|
30
|
+
declare function getCustomer(ctx: ClientContext, id: string): Promise<Result<CustomerEnvelope, GetCustomerError>>;
|
|
31
|
+
declare function submitCustomerKyc(ctx: ClientContext, id: string, body: UpdateIdentityRequestBody): Promise<Result<CustomerEnvelope, SubmitCustomerKycError>>;
|
|
32
|
+
declare function getCustomerUploadUrl(ctx: ClientContext, id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<UploadUrlEnvelope$1, GetCustomerUploadUrlError>>;
|
|
33
|
+
declare function submitCustomerFiles(ctx: ClientContext, id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<CustomerEnvelope, SubmitCustomerFilesError>>;
|
|
34
|
+
|
|
22
35
|
/** Typed fetch that wraps responses in Result<T, E>. */
|
|
23
36
|
declare function apiFetch<T>(ctx: ClientContext, path: string, options?: RequestInit): Promise<Result<T, DevPlatformApiError>>;
|
|
24
37
|
|
|
@@ -67,14 +80,22 @@ interface UploadUrlEnvelope {
|
|
|
67
80
|
/**
|
|
68
81
|
* Create an identity. Returns the created identity, or `null` when the
|
|
69
82
|
* customer has no outstanding requirements (the API returns 204).
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Customers are created automatically now — call `getCustomer`
|
|
85
|
+
* directly instead.
|
|
70
86
|
*/
|
|
71
87
|
declare function createIdentity(ctx: ClientContext, body: CreateIdentityRequestBody): Promise<Result<{
|
|
72
88
|
data: Identity | null;
|
|
73
89
|
}, CreateIdentityError>>;
|
|
90
|
+
/** @deprecated Use `getCustomer` instead. */
|
|
74
91
|
declare function getIdentity(ctx: ClientContext, id: string): Promise<Result<IdentityEnvelope, GetIdentityError>>;
|
|
92
|
+
/** @deprecated Use `submitCustomerKyc` instead. */
|
|
75
93
|
declare function updateIdentity(ctx: ClientContext, id: string, body: UpdateIdentityRequestBody): Promise<Result<IdentityEnvelope, UpdateIdentityError>>;
|
|
94
|
+
/** @deprecated No longer needed — Customer API verification has no direct replacement call. */
|
|
76
95
|
declare function verifyIdentity(ctx: ClientContext, id: string): Promise<Result<VerificationEnvelope, VerifyIdentityError>>;
|
|
96
|
+
/** @deprecated Use `getCustomerUploadUrl` instead. */
|
|
77
97
|
declare function getIdentityUploadUrl(ctx: ClientContext, id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<UploadUrlEnvelope, GetIdentityUploadUrlError>>;
|
|
98
|
+
/** @deprecated Use `submitCustomerFiles` instead. */
|
|
78
99
|
declare function submitIdentityFiles(ctx: ClientContext, id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<IdentityEnvelope, SubmitIdentityFilesError>>;
|
|
79
100
|
|
|
80
101
|
declare function getPaymentMethods(ctx: ClientContext): Promise<Result<{
|
|
@@ -119,6 +140,7 @@ declare const FRAME_PATHS: {
|
|
|
119
140
|
readonly challenge: "/platform/v1/challenge";
|
|
120
141
|
readonly addCard: "/platform/v1/add-card";
|
|
121
142
|
readonly reset: "/platform/v1/reset";
|
|
143
|
+
readonly customerExport: "/v2/customer-export";
|
|
122
144
|
};
|
|
123
145
|
interface UrlBuilderOptions {
|
|
124
146
|
/** Base URL for MoonPay frames. Defaults to production. */
|
|
@@ -177,21 +199,39 @@ interface CoreClient {
|
|
|
177
199
|
data: TransactionWithStages;
|
|
178
200
|
}, GetTransactionsError>>;
|
|
179
201
|
deletePaymentMethod(id: string): Promise<Result<void, DevPlatformApiError>>;
|
|
202
|
+
getCustomer(id: string): Promise<Result<{
|
|
203
|
+
data: Customer;
|
|
204
|
+
}, GetCustomerError>>;
|
|
205
|
+
submitCustomerKyc(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
|
|
206
|
+
data: Customer;
|
|
207
|
+
}, SubmitCustomerKycError>>;
|
|
208
|
+
getCustomerUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
|
|
209
|
+
data: IdentityFileUploadUrl;
|
|
210
|
+
}, GetCustomerUploadUrlError>>;
|
|
211
|
+
submitCustomerFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
|
|
212
|
+
data: Customer;
|
|
213
|
+
}, SubmitCustomerFilesError>>;
|
|
214
|
+
/** @deprecated Customers are created automatically now — call `getCustomer` directly instead. */
|
|
180
215
|
createIdentity(body: CreateIdentityRequestBody): Promise<Result<{
|
|
181
216
|
data: Identity | null;
|
|
182
217
|
}, CreateIdentityError>>;
|
|
218
|
+
/** @deprecated Use `getCustomer` instead. */
|
|
183
219
|
getIdentity(id: string): Promise<Result<{
|
|
184
220
|
data: Identity;
|
|
185
221
|
}, GetIdentityError>>;
|
|
222
|
+
/** @deprecated Use `submitCustomerKyc` instead. */
|
|
186
223
|
updateIdentity(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
|
|
187
224
|
data: Identity;
|
|
188
225
|
}, UpdateIdentityError>>;
|
|
226
|
+
/** @deprecated No longer needed — Customer API verification has no direct replacement call. */
|
|
189
227
|
verifyIdentity(id: string): Promise<Result<{
|
|
190
228
|
data: IdentityVerificationResponse;
|
|
191
229
|
}, VerifyIdentityError>>;
|
|
230
|
+
/** @deprecated Use `getCustomerUploadUrl` instead. */
|
|
192
231
|
getIdentityUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
|
|
193
232
|
data: IdentityFileUploadUrl;
|
|
194
233
|
}, GetIdentityUploadUrlError>>;
|
|
234
|
+
/** @deprecated Use `submitCustomerFiles` instead. */
|
|
195
235
|
submitIdentityFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
|
|
196
236
|
data: Identity;
|
|
197
237
|
}, SubmitIdentityFilesError>>;
|
|
@@ -246,4 +286,31 @@ interface FrameHandle {
|
|
|
246
286
|
*/
|
|
247
287
|
declare function createFrameOrchestrator(options: FrameOrchestratorOptions): Promise<FrameHandle>;
|
|
248
288
|
|
|
249
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Trusted MoonPay frame origins.
|
|
291
|
+
*
|
|
292
|
+
* This set is the single source of truth for two boundaries that MUST stay
|
|
293
|
+
* aligned so an accepted frame can both render *and* complete the postMessage
|
|
294
|
+
* handshake (SE-3808):
|
|
295
|
+
*
|
|
296
|
+
* 1. Which URLs `setupChallenge()` — and, defensively, the transports — will
|
|
297
|
+
* load into a frame.
|
|
298
|
+
* 2. Which postMessage origins a transport accepts messages from.
|
|
299
|
+
*
|
|
300
|
+
* Each pattern encodes its scheme, so MoonPay origins require `https:` and only
|
|
301
|
+
* `localhost` is permitted over `http:` for local development. This mirrors the
|
|
302
|
+
* `isTrustedMoonPayUrl()` trust pattern used for `apiBaseUrl`, but the allowlist
|
|
303
|
+
* is intentionally the frame (postMessage) set rather than the API set.
|
|
304
|
+
*/
|
|
305
|
+
declare const TRUSTED_FRAME_ORIGIN_PATTERNS: readonly RegExp[];
|
|
306
|
+
/** True if `origin` (e.g. `https://platform.moonpay.com`) is a trusted MoonPay frame origin. */
|
|
307
|
+
declare function isTrustedFrameOrigin(origin: string): boolean;
|
|
308
|
+
/**
|
|
309
|
+
* True if `value` is a well-formed URL served from a trusted MoonPay frame
|
|
310
|
+
* origin. Fails closed on unparseable input or an untrusted/off-protocol origin,
|
|
311
|
+
* so a partner-supplied challenge URL can never load non-MoonPay content into a
|
|
312
|
+
* trusted frame container (SE-3808).
|
|
313
|
+
*/
|
|
314
|
+
declare function isTrustedFrameUrl(value: string): boolean;
|
|
315
|
+
|
|
316
|
+
export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type KeyPair, type ListAssetsParams, type ListTransactionsParams, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,8 @@ function isTrustedMoonPayUrl(value) {
|
|
|
8
8
|
} catch {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
|
-
if (hostname === "localhost" || hostname === "127.0.0.1")
|
|
12
|
-
|
|
13
|
-
if (protocol !== "https:")
|
|
14
|
-
return false;
|
|
11
|
+
if (hostname === "localhost" || hostname === "127.0.0.1") return true;
|
|
12
|
+
if (protocol !== "https:") return false;
|
|
15
13
|
return hostname === "moonpay.com" || hostname.endsWith(".moonpay.com") || hostname === "moonpay.dev" || hostname.endsWith(".moonpay.dev") || hostname === "moonpay-dev.com" || hostname.endsWith(".moonpay-dev.com") || hostname === "moonpaycloud.com" || hostname.endsWith(".moonpaycloud.com");
|
|
16
14
|
}
|
|
17
15
|
function createClientContext(options = {}) {
|
|
@@ -61,17 +59,37 @@ async function apiFetch(ctx, path, options) {
|
|
|
61
59
|
return ok(data);
|
|
62
60
|
}
|
|
63
61
|
|
|
62
|
+
// src/api/customer.ts
|
|
63
|
+
async function getCustomer(ctx, id) {
|
|
64
|
+
return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}`);
|
|
65
|
+
}
|
|
66
|
+
async function submitCustomerKyc(ctx, id, body) {
|
|
67
|
+
return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}/kyc`, {
|
|
68
|
+
method: "PATCH",
|
|
69
|
+
body: JSON.stringify(body)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function getCustomerUploadUrl(ctx, id, body) {
|
|
73
|
+
return apiFetch(
|
|
74
|
+
ctx,
|
|
75
|
+
`/platform/v1/customers/${encodeURIComponent(id)}/files/upload-url`,
|
|
76
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
async function submitCustomerFiles(ctx, id, body) {
|
|
80
|
+
return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}/files`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: JSON.stringify(body)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
64
86
|
// src/api/get-assets.ts
|
|
65
87
|
async function getAssets(ctx, params = {}) {
|
|
66
88
|
const searchParams = new URLSearchParams();
|
|
67
|
-
if (params.source)
|
|
68
|
-
|
|
69
|
-
if (params.
|
|
70
|
-
|
|
71
|
-
if (params.cursor)
|
|
72
|
-
searchParams.set("cursor", params.cursor);
|
|
73
|
-
if (params.limit != null)
|
|
74
|
-
searchParams.set("limit", String(params.limit));
|
|
89
|
+
if (params.source) searchParams.set("source", params.source);
|
|
90
|
+
if (params.code) searchParams.set("code", params.code);
|
|
91
|
+
if (params.cursor) searchParams.set("cursor", params.cursor);
|
|
92
|
+
if (params.limit != null) searchParams.set("limit", String(params.limit));
|
|
75
93
|
const query = searchParams.toString();
|
|
76
94
|
const path = `/platform/v1/assets${query ? `?${query}` : ""}`;
|
|
77
95
|
return apiFetch(ctx, path);
|
|
@@ -88,14 +106,10 @@ async function getQuote(ctx, params) {
|
|
|
88
106
|
// src/api/get-transactions.ts
|
|
89
107
|
async function listTransactions(ctx, params = {}) {
|
|
90
108
|
const searchParams = new URLSearchParams();
|
|
91
|
-
if (params.startDate)
|
|
92
|
-
|
|
93
|
-
if (params.
|
|
94
|
-
|
|
95
|
-
if (params.cursor)
|
|
96
|
-
searchParams.set("cursor", params.cursor);
|
|
97
|
-
if (params.limit != null)
|
|
98
|
-
searchParams.set("limit", String(params.limit));
|
|
109
|
+
if (params.startDate) searchParams.set("startDate", params.startDate);
|
|
110
|
+
if (params.endDate) searchParams.set("endDate", params.endDate);
|
|
111
|
+
if (params.cursor) searchParams.set("cursor", params.cursor);
|
|
112
|
+
if (params.limit != null) searchParams.set("limit", String(params.limit));
|
|
99
113
|
const query = searchParams.toString();
|
|
100
114
|
const path = `/platform/v1/transactions${query ? `?${query}` : ""}`;
|
|
101
115
|
return apiFetch(ctx, path);
|
|
@@ -198,6 +212,10 @@ function createClientCore(options) {
|
|
|
198
212
|
listTransactions: (params) => listTransactions(ctx, params),
|
|
199
213
|
getTransaction: (id) => getTransaction(ctx, id),
|
|
200
214
|
deletePaymentMethod: (id) => deletePaymentMethod(ctx, id),
|
|
215
|
+
getCustomer: (id) => getCustomer(ctx, id),
|
|
216
|
+
submitCustomerKyc: (id, body) => submitCustomerKyc(ctx, id, body),
|
|
217
|
+
getCustomerUploadUrl: (id, body) => getCustomerUploadUrl(ctx, id, body),
|
|
218
|
+
submitCustomerFiles: (id, body) => submitCustomerFiles(ctx, id, body),
|
|
201
219
|
createIdentity: (body) => createIdentity(ctx, body),
|
|
202
220
|
getIdentity: (id) => getIdentity(ctx, id),
|
|
203
221
|
updateIdentity: (id, body) => updateIdentity(ctx, id, body),
|
|
@@ -1538,8 +1556,7 @@ function createFrameOrchestrator(options) {
|
|
|
1538
1556
|
}
|
|
1539
1557
|
}, handshakeTimeout);
|
|
1540
1558
|
const unsubHandshake = transport.onMessage((msg) => {
|
|
1541
|
-
if (msg.meta?.channelId !== channelId)
|
|
1542
|
-
return;
|
|
1559
|
+
if (msg.meta?.channelId !== channelId) return;
|
|
1543
1560
|
if (!handshakeComplete && msg.kind === HANDSHAKE_REQUEST_KIND) {
|
|
1544
1561
|
handshakeComplete = true;
|
|
1545
1562
|
clearTimeout(timer);
|
|
@@ -1565,8 +1582,7 @@ function createFrameOrchestrator(options) {
|
|
|
1565
1582
|
messageHandlers.push(handler);
|
|
1566
1583
|
return () => {
|
|
1567
1584
|
const idx = messageHandlers.indexOf(handler);
|
|
1568
|
-
if (idx >= 0)
|
|
1569
|
-
messageHandlers.splice(idx, 1);
|
|
1585
|
+
if (idx >= 0) messageHandlers.splice(idx, 1);
|
|
1570
1586
|
};
|
|
1571
1587
|
},
|
|
1572
1588
|
dispose() {
|
|
@@ -1580,6 +1596,26 @@ function createFrameOrchestrator(options) {
|
|
|
1580
1596
|
});
|
|
1581
1597
|
}
|
|
1582
1598
|
|
|
1599
|
+
// src/frames/frame-origin.ts
|
|
1600
|
+
var TRUSTED_FRAME_ORIGIN_PATTERNS = [
|
|
1601
|
+
/^https:\/\/([a-zA-Z0-9-]+\.)*moonpay\.com$/,
|
|
1602
|
+
/^https:\/\/([a-zA-Z0-9-]+\.)*moonpaycloud\.com$/,
|
|
1603
|
+
/^https:\/\/([a-zA-Z0-9-]+\.)*preview\.moonpay-dev\.com$/,
|
|
1604
|
+
/^http:\/\/localhost(:\d+)?$/
|
|
1605
|
+
];
|
|
1606
|
+
function isTrustedFrameOrigin(origin) {
|
|
1607
|
+
return TRUSTED_FRAME_ORIGIN_PATTERNS.some((pattern) => pattern.test(origin));
|
|
1608
|
+
}
|
|
1609
|
+
function isTrustedFrameUrl(value) {
|
|
1610
|
+
let origin;
|
|
1611
|
+
try {
|
|
1612
|
+
({ origin } = new URL(value));
|
|
1613
|
+
} catch {
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
return isTrustedFrameOrigin(origin);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1583
1619
|
// src/frames/url-builder.ts
|
|
1584
1620
|
var FRAME_PATHS = {
|
|
1585
1621
|
connect: "/platform/v1/connect",
|
|
@@ -1592,12 +1628,12 @@ var FRAME_PATHS = {
|
|
|
1592
1628
|
buyButton: "/platform/v1/buy-button",
|
|
1593
1629
|
challenge: "/platform/v1/challenge",
|
|
1594
1630
|
addCard: "/platform/v1/add-card",
|
|
1595
|
-
reset: "/platform/v1/reset"
|
|
1631
|
+
reset: "/platform/v1/reset",
|
|
1632
|
+
customerExport: "/v2/customer-export"
|
|
1596
1633
|
};
|
|
1597
1634
|
var DEFAULT_FRAME_BASE_URL = "https://platform.moonpay.com";
|
|
1598
1635
|
function stringifyQueryValue(value) {
|
|
1599
|
-
if (value == null)
|
|
1600
|
-
return null;
|
|
1636
|
+
if (value == null) return null;
|
|
1601
1637
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1602
1638
|
return String(value);
|
|
1603
1639
|
}
|
|
@@ -1621,8 +1657,7 @@ function themeParams(theme) {
|
|
|
1621
1657
|
return theme?.appearance ? { theme: theme.appearance } : {};
|
|
1622
1658
|
}
|
|
1623
1659
|
function applyThemeParam(url, theme) {
|
|
1624
|
-
if (!theme?.appearance)
|
|
1625
|
-
return url;
|
|
1660
|
+
if (!theme?.appearance) return url;
|
|
1626
1661
|
const parsed = new URL(url);
|
|
1627
1662
|
if (!parsed.searchParams.has("theme")) {
|
|
1628
1663
|
parsed.searchParams.set("theme", theme.appearance);
|
|
@@ -1631,6 +1666,7 @@ function applyThemeParam(url, theme) {
|
|
|
1631
1666
|
}
|
|
1632
1667
|
export {
|
|
1633
1668
|
FRAME_PATHS,
|
|
1669
|
+
TRUSTED_FRAME_ORIGIN_PATTERNS,
|
|
1634
1670
|
apiFetch,
|
|
1635
1671
|
applyThemeParam,
|
|
1636
1672
|
buildFrameUrl,
|
|
@@ -1642,12 +1678,18 @@ export {
|
|
|
1642
1678
|
deletePaymentMethod,
|
|
1643
1679
|
generateKeyPair,
|
|
1644
1680
|
getAssets,
|
|
1681
|
+
getCustomer,
|
|
1682
|
+
getCustomerUploadUrl,
|
|
1645
1683
|
getIdentity,
|
|
1646
1684
|
getIdentityUploadUrl,
|
|
1647
1685
|
getPaymentMethods,
|
|
1648
1686
|
getQuote,
|
|
1649
1687
|
getTransaction,
|
|
1688
|
+
isTrustedFrameOrigin,
|
|
1689
|
+
isTrustedFrameUrl,
|
|
1650
1690
|
listTransactions,
|
|
1691
|
+
submitCustomerFiles,
|
|
1692
|
+
submitCustomerKyc,
|
|
1651
1693
|
submitIdentityFiles,
|
|
1652
1694
|
themeParams,
|
|
1653
1695
|
updateIdentity,
|