@moonpay/platform-sdk-node 1.24.0 → 1.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -17
- package/dist/index.d.ts +3 -17
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -18,8 +18,9 @@ import { createServerClient } from '@moonpay/platform-sdk-node';
|
|
|
18
18
|
const client = createServerClient({ apiKey: process.env.MOONPAY_API_KEY });
|
|
19
19
|
|
|
20
20
|
const result = await client.createSession({
|
|
21
|
-
externalCustomerId: 'customer-123', //
|
|
21
|
+
externalCustomerId: 'customer-123', // optional — omit for anonymous sessions
|
|
22
22
|
deviceIp: request.ip, // the customer's device IP
|
|
23
|
+
// termsAcceptedAt: '2026-01-15T12:00:00.000Z', // when you capture ToU in your UI
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
if (!result.ok) {
|
|
@@ -35,7 +36,7 @@ All methods return a `Result<T, E>` discriminated union instead of throwing —
|
|
|
35
36
|
|
|
36
37
|
## What the client provides
|
|
37
38
|
|
|
38
|
-
- **`createSession()`** — issue a session token for a customer. `email` and `phoneNumber`
|
|
39
|
+
- **`createSession()`** — issue a session token for a customer. `email` and `phoneNumber` are independently optional; pass `termsAcceptedAt` when you capture Terms of Use acceptance in your own UI ([terms acceptance guide](https://dev.moonpay.com/platform/guides/terms-acceptance)).
|
|
39
40
|
- **`revokeSession()`** — revoke a previously issued session token.
|
|
40
41
|
- **`exportCustomer()`** — exchange a one-time consent token (captured client-side via `setupCustomerExport()` in the web/RN SDK) for the customer's verified MoonPay identity.
|
|
41
42
|
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,8 @@ async function createSession(apiKey, params, baseUrl) {
|
|
|
33
33
|
externalCustomerId: params.externalCustomerId
|
|
34
34
|
},
|
|
35
35
|
...params.email !== void 0 && { email: params.email },
|
|
36
|
-
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
36
|
+
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber },
|
|
37
|
+
...params.termsAcceptedAt !== void 0 && { termsAcceptedAt: params.termsAcceptedAt }
|
|
37
38
|
};
|
|
38
39
|
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
39
40
|
method: "POST",
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/create-session.ts","../src/export-customer.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["// Re-export key types\nexport type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nexport type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nexport type {\n CreateSessionError,\n ExportCustomerError,\n RevokeSessionError,\n} from '@moonpay/platform-protocol/api/errors';\nexport type { EmptyResult, Result } from '@moonpay/platform-protocol/result';\n\nexport type { CreateSessionParams } from './create-session.js';\nexport type { ExportCustomerParams } from './export-customer.js';\nexport type { RevokeSessionParams } from './revoke-session.js';\nexport {\n type CreateServerClientOptions,\n createServerClient,\n type ServerClient,\n} from './server-client.js';\n","import type {\n CreateSessionTokenRequestBody,\n CreateSessionTokenReturnType,\n} from '@moonpay/platform-protocol/api';\nimport type { CreateSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-session.ts","../src/export-customer.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["// Re-export key types\nexport type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nexport type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nexport type {\n CreateSessionError,\n ExportCustomerError,\n RevokeSessionError,\n} from '@moonpay/platform-protocol/api/errors';\nexport type { EmptyResult, Result } from '@moonpay/platform-protocol/result';\n\nexport type { CreateSessionParams } from './create-session.js';\nexport type { ExportCustomerParams } from './export-customer.js';\nexport type { RevokeSessionParams } from './revoke-session.js';\nexport {\n type CreateServerClientOptions,\n createServerClient,\n type ServerClient,\n} from './server-client.js';\n","import type {\n CreateSessionTokenRequestBody,\n CreateSessionTokenReturnType,\n} from '@moonpay/platform-protocol/api';\nimport type { CreateSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\n/** Session creation input — aligned with `CreateSessionTokenRequestBody` from the Platform API. */\nexport type CreateSessionParams = CreateSessionTokenRequestBody;\n\nexport async function createSession(\n apiKey: string,\n params: CreateSessionParams,\n baseUrl: string,\n): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>> {\n const body: CreateSessionTokenRequestBody = {\n deviceIp: params.deviceIp,\n ...(params.externalCustomerId !== undefined && {\n externalCustomerId: params.externalCustomerId,\n }),\n ...(params.email !== undefined && { email: params.email }),\n ...(params.phoneNumber !== undefined && { phoneNumber: params.phoneNumber }),\n ...(params.termsAcceptedAt !== undefined && { termsAcceptedAt: params.termsAcceptedAt }),\n };\n\n const response = await fetch(`${baseUrl}/platform/v1/sessions`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Api-Key': apiKey,\n },\n body: JSON.stringify(body),\n });\n\n const data = await response.json();\n\n if (!response.ok) {\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to create session',\n errors: data.errors,\n });\n }\n\n return ok(data as CreateSessionTokenReturnType);\n}\n","import type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nimport type { ExportCustomerError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\nexport interface ExportCustomerParams {\n /**\n * One-time consent token from the customer-export frame's `complete`\n * event (web/RN SDK). Valid for 5 minutes.\n */\n consentToken: string;\n}\n\nexport async function exportCustomer(\n apiKey: string,\n params: ExportCustomerParams,\n baseUrl: string,\n): Promise<Result<{ data: CustomerExportIdentity }, ExportCustomerError>> {\n const response = await fetch(`${baseUrl}/platform/v1/customers/export`, {\n method: 'POST',\n headers: {\n 'X-Api-Key': apiKey,\n Authorization: `Bearer ${params.consentToken}`,\n },\n });\n\n const data = await response.json();\n\n if (!response.ok) {\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to export customer',\n errors: data.errors,\n });\n }\n\n return ok(data as { data: CustomerExportIdentity });\n}\n","import type { RevokeSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { EmptyResult } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\nexport interface RevokeSessionParams {\n /** The external customer identifier whose sessions should be revoked. */\n externalCustomerId: string;\n}\n\nexport async function revokeSession(\n apiKey: string,\n params: RevokeSessionParams,\n baseUrl: string,\n): Promise<EmptyResult<RevokeSessionError>> {\n const url = new URL('/platform/v1/sessions', baseUrl);\n url.searchParams.set('externalCustomerId', params.externalCustomerId);\n\n const response = await fetch(url, {\n method: 'DELETE',\n headers: {\n 'X-Api-Key': apiKey,\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to revoke session',\n errors: data.errors,\n });\n }\n\n return ok(undefined as never);\n}\n","import type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nimport type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nimport type {\n CreateSessionError,\n ExportCustomerError,\n RevokeSessionError,\n} from '@moonpay/platform-protocol/api/errors';\nimport type { EmptyResult, Result } from '@moonpay/platform-protocol/result';\nimport { type CreateSessionParams, createSession } from './create-session.js';\nimport { type ExportCustomerParams, exportCustomer } from './export-customer.js';\nimport { type RevokeSessionParams, revokeSession } from './revoke-session.js';\n\nexport interface CreateServerClientOptions {\n /** Your MoonPay secret API key. Never expose this client-side. */\n apiKey: string;\n /** Override the API base URL. Defaults to production. */\n baseUrl?: string;\n}\n\nexport interface ServerClient {\n /** Create a session token for a customer. */\n createSession(\n params: CreateSessionParams,\n ): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;\n /** Revoke all sessions for a customer (by external customer ID). */\n revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;\n /**\n * Exchange a one-time consent token (from the customer-export frame's\n * `complete` event, web/RN SDK) for the customer's verified MoonPay\n * identity. Call within the token's validity window.\n */\n exportCustomer(\n params: ExportCustomerParams,\n ): Promise<Result<{ data: CustomerExportIdentity }, ExportCustomerError>>;\n}\n\n/**\n * Creates a server-side MoonPay client for session management.\n *\n * This client uses your secret API key and must only be used in\n * server-side environments (Node.js, edge functions, etc.).\n */\nexport function createServerClient(options: CreateServerClientOptions): ServerClient {\n const { apiKey, baseUrl = 'https://api.moonpay.com' } = options;\n\n return {\n createSession: (params) => createSession(apiKey, params, baseUrl),\n revokeSession: (params) => revokeSession(apiKey, params, baseUrl),\n exportCustomer: (params) => exportCustomer(apiKey, params, baseUrl),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,oBAAwB;AAKxB,eAAsB,cACpB,QACA,QACA,SACmE;AACnE,QAAM,OAAsC;AAAA,IAC1C,UAAU,OAAO;AAAA,IACjB,GAAI,OAAO,uBAAuB,UAAa;AAAA,MAC7C,oBAAoB,OAAO;AAAA,IAC7B;AAAA,IACA,GAAI,OAAO,UAAU,UAAa,EAAE,OAAO,OAAO,MAAM;AAAA,IACxD,GAAI,OAAO,gBAAgB,UAAa,EAAE,aAAa,OAAO,YAAY;AAAA,IAC1E,GAAI,OAAO,oBAAoB,UAAa,EAAE,iBAAiB,OAAO,gBAAgB;AAAA,EACxF;AAEA,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,yBAAyB;AAAA,IAC9D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,IACA,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,MAAI,CAAC,SAAS,IAAI;AAChB,eAAO,mBAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,aAAO,kBAAG,IAAoC;AAChD;;;AC3CA,IAAAA,iBAAwB;AAUxB,eAAsB,eACpB,QACA,QACA,SACwE;AACxE,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,iCAAiC;AAAA,IACtE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,aAAa;AAAA,MACb,eAAe,UAAU,OAAO,YAAY;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,MAAI,CAAC,SAAS,IAAI;AAChB,eAAO,oBAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,aAAO,mBAAG,IAAwC;AACpD;;;ACnCA,IAAAC,iBAAwB;AAOxB,eAAsB,cACpB,QACA,QACA,SAC0C;AAC1C,QAAM,MAAM,IAAI,IAAI,yBAAyB,OAAO;AACpD,MAAI,aAAa,IAAI,sBAAsB,OAAO,kBAAkB;AAEpE,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,aAAa;AAAA,IACf;AAAA,EACF,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,eAAO,oBAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,aAAO,mBAAG,MAAkB;AAC9B;;;ACQO,SAAS,mBAAmB,SAAkD;AACnF,QAAM,EAAE,QAAQ,UAAU,0BAA0B,IAAI;AAExD,SAAO;AAAA,IACL,eAAe,CAAC,WAAW,cAAc,QAAQ,QAAQ,OAAO;AAAA,IAChE,eAAe,CAAC,WAAW,cAAc,QAAQ,QAAQ,OAAO;AAAA,IAChE,gBAAgB,CAAC,WAAW,eAAe,QAAQ,QAAQ,OAAO;AAAA,EACpE;AACF;","names":["import_result","import_result"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
1
|
+
import { CreateSessionTokenRequestBody, CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
2
2
|
export { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
3
3
|
import { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';
|
|
4
4
|
export { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';
|
|
@@ -7,22 +7,8 @@ export { CreateSessionError, ExportCustomerError, RevokeSessionError } from '@mo
|
|
|
7
7
|
import { Result, EmptyResult } from '@moonpay/platform-protocol/result';
|
|
8
8
|
export { EmptyResult, Result } from '@moonpay/platform-protocol/result';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
externalCustomerId?: string;
|
|
13
|
-
/** The customer's device IP address (IPv4 or IPv6). */
|
|
14
|
-
deviceIp: string;
|
|
15
|
-
/**
|
|
16
|
-
* The customer's email address.
|
|
17
|
-
* If provided, `phoneNumber` must also be provided.
|
|
18
|
-
*/
|
|
19
|
-
email?: string;
|
|
20
|
-
/**
|
|
21
|
-
* The customer's phone number in E.164 format.
|
|
22
|
-
* If provided, `email` must also be provided.
|
|
23
|
-
*/
|
|
24
|
-
phoneNumber?: string;
|
|
25
|
-
}
|
|
10
|
+
/** Session creation input — aligned with `CreateSessionTokenRequestBody` from the Platform API. */
|
|
11
|
+
type CreateSessionParams = CreateSessionTokenRequestBody;
|
|
26
12
|
|
|
27
13
|
interface ExportCustomerParams {
|
|
28
14
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
1
|
+
import { CreateSessionTokenRequestBody, CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
2
2
|
export { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
3
3
|
import { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';
|
|
4
4
|
export { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';
|
|
@@ -7,22 +7,8 @@ export { CreateSessionError, ExportCustomerError, RevokeSessionError } from '@mo
|
|
|
7
7
|
import { Result, EmptyResult } from '@moonpay/platform-protocol/result';
|
|
8
8
|
export { EmptyResult, Result } from '@moonpay/platform-protocol/result';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
externalCustomerId?: string;
|
|
13
|
-
/** The customer's device IP address (IPv4 or IPv6). */
|
|
14
|
-
deviceIp: string;
|
|
15
|
-
/**
|
|
16
|
-
* The customer's email address.
|
|
17
|
-
* If provided, `phoneNumber` must also be provided.
|
|
18
|
-
*/
|
|
19
|
-
email?: string;
|
|
20
|
-
/**
|
|
21
|
-
* The customer's phone number in E.164 format.
|
|
22
|
-
* If provided, `email` must also be provided.
|
|
23
|
-
*/
|
|
24
|
-
phoneNumber?: string;
|
|
25
|
-
}
|
|
10
|
+
/** Session creation input — aligned with `CreateSessionTokenRequestBody` from the Platform API. */
|
|
11
|
+
type CreateSessionParams = CreateSessionTokenRequestBody;
|
|
26
12
|
|
|
27
13
|
interface ExportCustomerParams {
|
|
28
14
|
/**
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,8 @@ async function createSession(apiKey, params, baseUrl) {
|
|
|
7
7
|
externalCustomerId: params.externalCustomerId
|
|
8
8
|
},
|
|
9
9
|
...params.email !== void 0 && { email: params.email },
|
|
10
|
-
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
10
|
+
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber },
|
|
11
|
+
...params.termsAcceptedAt !== void 0 && { termsAcceptedAt: params.termsAcceptedAt }
|
|
11
12
|
};
|
|
12
13
|
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
13
14
|
method: "POST",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-session.ts","../src/export-customer.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["import type {\n CreateSessionTokenRequestBody,\n CreateSessionTokenReturnType,\n} from '@moonpay/platform-protocol/api';\nimport type { CreateSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\
|
|
1
|
+
{"version":3,"sources":["../src/create-session.ts","../src/export-customer.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["import type {\n CreateSessionTokenRequestBody,\n CreateSessionTokenReturnType,\n} from '@moonpay/platform-protocol/api';\nimport type { CreateSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\n/** Session creation input — aligned with `CreateSessionTokenRequestBody` from the Platform API. */\nexport type CreateSessionParams = CreateSessionTokenRequestBody;\n\nexport async function createSession(\n apiKey: string,\n params: CreateSessionParams,\n baseUrl: string,\n): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>> {\n const body: CreateSessionTokenRequestBody = {\n deviceIp: params.deviceIp,\n ...(params.externalCustomerId !== undefined && {\n externalCustomerId: params.externalCustomerId,\n }),\n ...(params.email !== undefined && { email: params.email }),\n ...(params.phoneNumber !== undefined && { phoneNumber: params.phoneNumber }),\n ...(params.termsAcceptedAt !== undefined && { termsAcceptedAt: params.termsAcceptedAt }),\n };\n\n const response = await fetch(`${baseUrl}/platform/v1/sessions`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Api-Key': apiKey,\n },\n body: JSON.stringify(body),\n });\n\n const data = await response.json();\n\n if (!response.ok) {\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to create session',\n errors: data.errors,\n });\n }\n\n return ok(data as CreateSessionTokenReturnType);\n}\n","import type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nimport type { ExportCustomerError } from '@moonpay/platform-protocol/api/errors';\nimport type { Result } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\nexport interface ExportCustomerParams {\n /**\n * One-time consent token from the customer-export frame's `complete`\n * event (web/RN SDK). Valid for 5 minutes.\n */\n consentToken: string;\n}\n\nexport async function exportCustomer(\n apiKey: string,\n params: ExportCustomerParams,\n baseUrl: string,\n): Promise<Result<{ data: CustomerExportIdentity }, ExportCustomerError>> {\n const response = await fetch(`${baseUrl}/platform/v1/customers/export`, {\n method: 'POST',\n headers: {\n 'X-Api-Key': apiKey,\n Authorization: `Bearer ${params.consentToken}`,\n },\n });\n\n const data = await response.json();\n\n if (!response.ok) {\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to export customer',\n errors: data.errors,\n });\n }\n\n return ok(data as { data: CustomerExportIdentity });\n}\n","import type { RevokeSessionError } from '@moonpay/platform-protocol/api/errors';\nimport type { EmptyResult } from '@moonpay/platform-protocol/result';\nimport { err, ok } from '@moonpay/platform-protocol/result';\n\nexport interface RevokeSessionParams {\n /** The external customer identifier whose sessions should be revoked. */\n externalCustomerId: string;\n}\n\nexport async function revokeSession(\n apiKey: string,\n params: RevokeSessionParams,\n baseUrl: string,\n): Promise<EmptyResult<RevokeSessionError>> {\n const url = new URL('/platform/v1/sessions', baseUrl);\n url.searchParams.set('externalCustomerId', params.externalCustomerId);\n\n const response = await fetch(url, {\n method: 'DELETE',\n headers: {\n 'X-Api-Key': apiKey,\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n return err({\n code: data.code ?? 'unknown_error',\n message: data.message ?? 'Failed to revoke session',\n errors: data.errors,\n });\n }\n\n return ok(undefined as never);\n}\n","import type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nimport type { CustomerExportIdentity } from '@moonpay/platform-protocol/api/customer';\nimport type {\n CreateSessionError,\n ExportCustomerError,\n RevokeSessionError,\n} from '@moonpay/platform-protocol/api/errors';\nimport type { EmptyResult, Result } from '@moonpay/platform-protocol/result';\nimport { type CreateSessionParams, createSession } from './create-session.js';\nimport { type ExportCustomerParams, exportCustomer } from './export-customer.js';\nimport { type RevokeSessionParams, revokeSession } from './revoke-session.js';\n\nexport interface CreateServerClientOptions {\n /** Your MoonPay secret API key. Never expose this client-side. */\n apiKey: string;\n /** Override the API base URL. Defaults to production. */\n baseUrl?: string;\n}\n\nexport interface ServerClient {\n /** Create a session token for a customer. */\n createSession(\n params: CreateSessionParams,\n ): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;\n /** Revoke all sessions for a customer (by external customer ID). */\n revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;\n /**\n * Exchange a one-time consent token (from the customer-export frame's\n * `complete` event, web/RN SDK) for the customer's verified MoonPay\n * identity. Call within the token's validity window.\n */\n exportCustomer(\n params: ExportCustomerParams,\n ): Promise<Result<{ data: CustomerExportIdentity }, ExportCustomerError>>;\n}\n\n/**\n * Creates a server-side MoonPay client for session management.\n *\n * This client uses your secret API key and must only be used in\n * server-side environments (Node.js, edge functions, etc.).\n */\nexport function createServerClient(options: CreateServerClientOptions): ServerClient {\n const { apiKey, baseUrl = 'https://api.moonpay.com' } = options;\n\n return {\n createSession: (params) => createSession(apiKey, params, baseUrl),\n revokeSession: (params) => revokeSession(apiKey, params, baseUrl),\n exportCustomer: (params) => exportCustomer(apiKey, params, baseUrl),\n };\n}\n"],"mappings":";AAMA,SAAS,KAAK,UAAU;AAKxB,eAAsB,cACpB,QACA,QACA,SACmE;AACnE,QAAM,OAAsC;AAAA,IAC1C,UAAU,OAAO;AAAA,IACjB,GAAI,OAAO,uBAAuB,UAAa;AAAA,MAC7C,oBAAoB,OAAO;AAAA,IAC7B;AAAA,IACA,GAAI,OAAO,UAAU,UAAa,EAAE,OAAO,OAAO,MAAM;AAAA,IACxD,GAAI,OAAO,gBAAgB,UAAa,EAAE,aAAa,OAAO,YAAY;AAAA,IAC1E,GAAI,OAAO,oBAAoB,UAAa,EAAE,iBAAiB,OAAO,gBAAgB;AAAA,EACxF;AAEA,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,yBAAyB;AAAA,IAC9D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,IACA,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,MAAI,CAAC,SAAS,IAAI;AAChB,WAAO,IAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,SAAO,GAAG,IAAoC;AAChD;;;AC3CA,SAAS,OAAAA,MAAK,MAAAC,WAAU;AAUxB,eAAsB,eACpB,QACA,QACA,SACwE;AACxE,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,iCAAiC;AAAA,IACtE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,aAAa;AAAA,MACb,eAAe,UAAU,OAAO,YAAY;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,MAAI,CAAC,SAAS,IAAI;AAChB,WAAOD,KAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,SAAOC,IAAG,IAAwC;AACpD;;;ACnCA,SAAS,OAAAC,MAAK,MAAAC,WAAU;AAOxB,eAAsB,cACpB,QACA,QACA,SAC0C;AAC1C,QAAM,MAAM,IAAI,IAAI,yBAAyB,OAAO;AACpD,MAAI,aAAa,IAAI,sBAAsB,OAAO,kBAAkB;AAEpE,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,aAAa;AAAA,IACf;AAAA,EACF,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,WAAOD,KAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,SAAOC,IAAG,MAAkB;AAC9B;;;ACQO,SAAS,mBAAmB,SAAkD;AACnF,QAAM,EAAE,QAAQ,UAAU,0BAA0B,IAAI;AAExD,SAAO;AAAA,IACL,eAAe,CAAC,WAAW,cAAc,QAAQ,QAAQ,OAAO;AAAA,IAChE,eAAe,CAAC,WAAW,cAAc,QAAQ,QAAQ,OAAO;AAAA,IAChE,gBAAgB,CAAC,WAAW,eAAe,QAAQ,QAAQ,OAAO;AAAA,EACpE;AACF;","names":["err","ok","err","ok"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonpay/platform-sdk-node",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.2",
|
|
4
4
|
"description": "MoonPay Developer Platform server-side SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
"build": "tsup",
|
|
26
26
|
"dev": "tsup --watch --config tsup.config.dev.ts",
|
|
27
27
|
"typecheck": "tsc --noEmit",
|
|
28
|
-
"clean": "rm -rf dist"
|
|
28
|
+
"clean": "rm -rf dist",
|
|
29
|
+
"test": "bun test src"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@moonpay/platform-protocol": "1.24.
|
|
32
|
+
"@moonpay/platform-protocol": "1.24.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"tsup": "8.3.5",
|