@moonpay/platform-sdk-node 1.4.1 → 1.5.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/README.md +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ All methods return a `Result<T, E>` discriminated union instead of throwing —
|
|
|
35
35
|
|
|
36
36
|
## What the client provides
|
|
37
37
|
|
|
38
|
-
- **`createSession()`** — issue a session token for a customer.
|
|
38
|
+
- **`createSession()`** — issue a session token for a customer. `email` and `phoneNumber` must be passed together when provided.
|
|
39
39
|
- **`revokeSession()`** — revoke a previously issued session token.
|
|
40
40
|
|
|
41
41
|
## Related packages
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/create-session.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["// Re-export key types\nexport type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nexport type {\n CreateSessionError,\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 { 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\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. Optional — omit for anonymous sessions. */\n externalCustomerId?: string;\n /** The customer's device IP address (IPv4 or IPv6). */\n deviceIp: string;\n /**\n * The customer's email address
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-session.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["// Re-export key types\nexport type { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';\nexport type {\n CreateSessionError,\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 { 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\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. Optional — omit for anonymous sessions. */\n externalCustomerId?: string;\n /** The customer's device IP address (IPv4 or IPv6). */\n deviceIp: string;\n /**\n * The customer's email address.\n * If provided, `phoneNumber` must also be provided.\n */\n email?: string;\n /**\n * The customer's phone number in E.164 format.\n * If provided, `email` must also be provided.\n */\n phoneNumber?: string;\n}\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 };\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 { 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 { CreateSessionError, RevokeSessionError } 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 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\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 };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,oBAAwB;AAmBxB,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,EAC5E;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;;;ACzDA,IAAAA,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;;;ACNO,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,EAClE;AACF;","names":["import_result"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -11,12 +11,12 @@ interface CreateSessionParams {
|
|
|
11
11
|
/** The customer's device IP address (IPv4 or IPv6). */
|
|
12
12
|
deviceIp: string;
|
|
13
13
|
/**
|
|
14
|
-
* The customer's email address.
|
|
14
|
+
* The customer's email address.
|
|
15
15
|
* If provided, `phoneNumber` must also be provided.
|
|
16
16
|
*/
|
|
17
17
|
email?: string;
|
|
18
18
|
/**
|
|
19
|
-
* The customer's phone number in E.164 format.
|
|
19
|
+
* The customer's phone number in E.164 format.
|
|
20
20
|
* If provided, `email` must also be provided.
|
|
21
21
|
*/
|
|
22
22
|
phoneNumber?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,12 +11,12 @@ interface CreateSessionParams {
|
|
|
11
11
|
/** The customer's device IP address (IPv4 or IPv6). */
|
|
12
12
|
deviceIp: string;
|
|
13
13
|
/**
|
|
14
|
-
* The customer's email address.
|
|
14
|
+
* The customer's email address.
|
|
15
15
|
* If provided, `phoneNumber` must also be provided.
|
|
16
16
|
*/
|
|
17
17
|
email?: string;
|
|
18
18
|
/**
|
|
19
|
-
* The customer's phone number in E.164 format.
|
|
19
|
+
* The customer's phone number in E.164 format.
|
|
20
20
|
* If provided, `email` must also be provided.
|
|
21
21
|
*/
|
|
22
22
|
phoneNumber?: string;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-session.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\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. Optional — omit for anonymous sessions. */\n externalCustomerId?: string;\n /** The customer's device IP address (IPv4 or IPv6). */\n deviceIp: string;\n /**\n * The customer's email address
|
|
1
|
+
{"version":3,"sources":["../src/create-session.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\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. Optional — omit for anonymous sessions. */\n externalCustomerId?: string;\n /** The customer's device IP address (IPv4 or IPv6). */\n deviceIp: string;\n /**\n * The customer's email address.\n * If provided, `phoneNumber` must also be provided.\n */\n email?: string;\n /**\n * The customer's phone number in E.164 format.\n * If provided, `email` must also be provided.\n */\n phoneNumber?: string;\n}\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 };\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 { 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 { CreateSessionError, RevokeSessionError } 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 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\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 };\n}\n"],"mappings":";AAMA,SAAS,KAAK,UAAU;AAmBxB,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,EAC5E;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;;;ACzDA,SAAS,OAAAA,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;;;ACNO,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,EAClE;AACF;","names":["err","ok"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonpay/platform-sdk-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "MoonPay Developer Platform server-side SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"clean": "rm -rf dist"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@moonpay/platform-protocol": "1.
|
|
31
|
+
"@moonpay/platform-protocol": "1.5.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"tsup": "8.0.0",
|