@moonpay/platform-sdk-node 0.3.0 → 1.0.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 +59 -0
- package/dist/index.cjs +16 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @moonpay/platform-sdk-node
|
|
2
|
+
|
|
3
|
+
Server-side SDK for the [MoonPay Developer Platform](https://dev.moonpay.com). Creates and revokes customer sessions using your secret API key — the first step of every Platform integration. The resulting session token is what you pass to the browser ([`@moonpay/platform-sdk-web`](https://www.npmjs.com/package/@moonpay/platform-sdk-web)) or React Native ([`@moonpay/platform-sdk-react-native`](https://www.npmjs.com/package/@moonpay/platform-sdk-react-native)) SDK.
|
|
4
|
+
|
|
5
|
+
Your secret API key must never reach the client — use this package only in server-side environments (Node.js, edge functions).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @moonpay/platform-sdk-node
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createServerClient } from '@moonpay/platform-sdk-node';
|
|
17
|
+
|
|
18
|
+
const client = createServerClient({ apiKey: process.env.MOONPAY_API_KEY });
|
|
19
|
+
|
|
20
|
+
const result = await client.createSession({
|
|
21
|
+
externalCustomerId: 'customer-123', // your unique customer identifier
|
|
22
|
+
deviceIp: request.ip, // the customer's device IP
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!result.ok) {
|
|
26
|
+
console.error(result.error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Send to your frontend — single-use, expires after 24 hours
|
|
31
|
+
const { sessionToken } = result.value;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
All methods return a `Result<T, E>` discriminated union instead of throwing — check `result.ok` before using `result.value`.
|
|
35
|
+
|
|
36
|
+
## What the client provides
|
|
37
|
+
|
|
38
|
+
- **`createSession()`** — issue a session token for a customer. Pass `email` and `phoneNumber` together to support 1-tap Apple Pay.
|
|
39
|
+
- **`revokeSession()`** — revoke a previously issued session token.
|
|
40
|
+
|
|
41
|
+
## Related packages
|
|
42
|
+
|
|
43
|
+
| Package | Use it for |
|
|
44
|
+
|---------|------------|
|
|
45
|
+
| `@moonpay/platform-sdk-web` | Browser integrations |
|
|
46
|
+
| `@moonpay/platform-sdk-react-native` | React Native apps |
|
|
47
|
+
| `@moonpay/platform-protocol` | Shared protocol and API types |
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
Full guides and API reference: [dev.moonpay.com](https://dev.moonpay.com)
|
|
52
|
+
|
|
53
|
+
- [Introduction](https://dev.moonpay.com/platform/overview/introduction)
|
|
54
|
+
- [API & SDK credentials](https://dev.moonpay.com/platform/guides/api-and-sdk-credentials)
|
|
55
|
+
- [Connect a customer](https://dev.moonpay.com/platform/guides/connect-a-customer)
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -25,53 +25,55 @@ __export(src_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
27
|
// src/create-session.ts
|
|
28
|
-
var
|
|
28
|
+
var import_result = require("@moonpay/platform-protocol/result");
|
|
29
29
|
async function createSession(apiKey, params, baseUrl) {
|
|
30
30
|
const body = {
|
|
31
|
-
externalCustomerId: params.externalCustomerId,
|
|
32
31
|
deviceIp: params.deviceIp,
|
|
32
|
+
...params.externalCustomerId !== void 0 && {
|
|
33
|
+
externalCustomerId: params.externalCustomerId
|
|
34
|
+
},
|
|
33
35
|
...params.email !== void 0 && { email: params.email },
|
|
34
36
|
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
35
37
|
};
|
|
36
|
-
const response = await fetch(`${baseUrl}/platform/v1/
|
|
38
|
+
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
37
39
|
method: "POST",
|
|
38
40
|
headers: {
|
|
39
41
|
"Content-Type": "application/json",
|
|
40
|
-
"Api-Key": apiKey
|
|
42
|
+
"X-Api-Key": apiKey
|
|
41
43
|
},
|
|
42
44
|
body: JSON.stringify(body)
|
|
43
45
|
});
|
|
44
46
|
const data = await response.json();
|
|
45
47
|
if (!response.ok) {
|
|
46
|
-
return (0,
|
|
48
|
+
return (0, import_result.err)({
|
|
47
49
|
code: data.code ?? "unknown_error",
|
|
48
50
|
message: data.message ?? "Failed to create session",
|
|
49
51
|
errors: data.errors
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
return (0,
|
|
54
|
+
return (0, import_result.ok)(data);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
// src/revoke-session.ts
|
|
56
|
-
var
|
|
58
|
+
var import_result2 = require("@moonpay/platform-protocol/result");
|
|
57
59
|
async function revokeSession(apiKey, params, baseUrl) {
|
|
58
|
-
const
|
|
60
|
+
const url = new URL("/platform/v1/sessions", baseUrl);
|
|
61
|
+
url.searchParams.set("externalCustomerId", params.externalCustomerId);
|
|
62
|
+
const response = await fetch(url, {
|
|
59
63
|
method: "DELETE",
|
|
60
64
|
headers: {
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
body: JSON.stringify({ sessionToken: params.sessionToken })
|
|
65
|
+
"X-Api-Key": apiKey
|
|
66
|
+
}
|
|
65
67
|
});
|
|
66
68
|
if (!response.ok) {
|
|
67
69
|
const data = await response.json().catch(() => ({}));
|
|
68
|
-
return (0,
|
|
70
|
+
return (0, import_result2.err)({
|
|
69
71
|
code: data.code ?? "unknown_error",
|
|
70
72
|
message: data.message ?? "Failed to revoke session",
|
|
71
73
|
errors: data.errors
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
|
-
return (0,
|
|
76
|
+
return (0, import_result2.ok)(void 0);
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
// src/server-client.ts
|
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 {\n CreateSessionError,\n
|
|
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. Required for 1-tap Apple Pay.\n * If provided, `phoneNumber` must also be provided.\n */\n email?: string;\n /**\n * The customer's phone number in E.164 format. Required for 1-tap Apple Pay.\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
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
2
|
+
export { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
3
|
+
import { CreateSessionError, RevokeSessionError } from '@moonpay/platform-protocol/api/errors';
|
|
4
|
+
export { CreateSessionError, RevokeSessionError } from '@moonpay/platform-protocol/api/errors';
|
|
5
|
+
import { Result, EmptyResult } from '@moonpay/platform-protocol/result';
|
|
6
|
+
export { EmptyResult, Result } from '@moonpay/platform-protocol/result';
|
|
3
7
|
|
|
4
8
|
interface CreateSessionParams {
|
|
5
|
-
/** Unique customer identifier from your system. */
|
|
6
|
-
externalCustomerId
|
|
9
|
+
/** Unique customer identifier from your system. Optional — omit for anonymous sessions. */
|
|
10
|
+
externalCustomerId?: string;
|
|
7
11
|
/** The customer's device IP address (IPv4 or IPv6). */
|
|
8
12
|
deviceIp: string;
|
|
9
13
|
/**
|
|
@@ -19,8 +23,8 @@ interface CreateSessionParams {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
interface RevokeSessionParams {
|
|
22
|
-
/** The
|
|
23
|
-
|
|
26
|
+
/** The external customer identifier whose sessions should be revoked. */
|
|
27
|
+
externalCustomerId: string;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
interface CreateServerClientOptions {
|
|
@@ -32,7 +36,7 @@ interface CreateServerClientOptions {
|
|
|
32
36
|
interface ServerClient {
|
|
33
37
|
/** Create a session token for a customer. */
|
|
34
38
|
createSession(params: CreateSessionParams): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;
|
|
35
|
-
/** Revoke a
|
|
39
|
+
/** Revoke all sessions for a customer (by external customer ID). */
|
|
36
40
|
revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;
|
|
37
41
|
}
|
|
38
42
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
2
|
+
export { CreateSessionTokenReturnType } from '@moonpay/platform-protocol/api';
|
|
3
|
+
import { CreateSessionError, RevokeSessionError } from '@moonpay/platform-protocol/api/errors';
|
|
4
|
+
export { CreateSessionError, RevokeSessionError } from '@moonpay/platform-protocol/api/errors';
|
|
5
|
+
import { Result, EmptyResult } from '@moonpay/platform-protocol/result';
|
|
6
|
+
export { EmptyResult, Result } from '@moonpay/platform-protocol/result';
|
|
3
7
|
|
|
4
8
|
interface CreateSessionParams {
|
|
5
|
-
/** Unique customer identifier from your system. */
|
|
6
|
-
externalCustomerId
|
|
9
|
+
/** Unique customer identifier from your system. Optional — omit for anonymous sessions. */
|
|
10
|
+
externalCustomerId?: string;
|
|
7
11
|
/** The customer's device IP address (IPv4 or IPv6). */
|
|
8
12
|
deviceIp: string;
|
|
9
13
|
/**
|
|
@@ -19,8 +23,8 @@ interface CreateSessionParams {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
interface RevokeSessionParams {
|
|
22
|
-
/** The
|
|
23
|
-
|
|
26
|
+
/** The external customer identifier whose sessions should be revoked. */
|
|
27
|
+
externalCustomerId: string;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
interface CreateServerClientOptions {
|
|
@@ -32,7 +36,7 @@ interface CreateServerClientOptions {
|
|
|
32
36
|
interface ServerClient {
|
|
33
37
|
/** Create a session token for a customer. */
|
|
34
38
|
createSession(params: CreateSessionParams): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;
|
|
35
|
-
/** Revoke a
|
|
39
|
+
/** Revoke all sessions for a customer (by external customer ID). */
|
|
36
40
|
revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;
|
|
37
41
|
}
|
|
38
42
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
// src/create-session.ts
|
|
2
|
-
import {
|
|
3
|
-
err,
|
|
4
|
-
ok
|
|
5
|
-
} from "@moonpay/platform-protocol";
|
|
2
|
+
import { err, ok } from "@moonpay/platform-protocol/result";
|
|
6
3
|
async function createSession(apiKey, params, baseUrl) {
|
|
7
4
|
const body = {
|
|
8
|
-
externalCustomerId: params.externalCustomerId,
|
|
9
5
|
deviceIp: params.deviceIp,
|
|
6
|
+
...params.externalCustomerId !== void 0 && {
|
|
7
|
+
externalCustomerId: params.externalCustomerId
|
|
8
|
+
},
|
|
10
9
|
...params.email !== void 0 && { email: params.email },
|
|
11
10
|
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
12
11
|
};
|
|
13
|
-
const response = await fetch(`${baseUrl}/platform/v1/
|
|
12
|
+
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
14
13
|
method: "POST",
|
|
15
14
|
headers: {
|
|
16
15
|
"Content-Type": "application/json",
|
|
17
|
-
"Api-Key": apiKey
|
|
16
|
+
"X-Api-Key": apiKey
|
|
18
17
|
},
|
|
19
18
|
body: JSON.stringify(body)
|
|
20
19
|
});
|
|
@@ -30,15 +29,15 @@ async function createSession(apiKey, params, baseUrl) {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
// src/revoke-session.ts
|
|
33
|
-
import { err as err2, ok as ok2 } from "@moonpay/platform-protocol";
|
|
32
|
+
import { err as err2, ok as ok2 } from "@moonpay/platform-protocol/result";
|
|
34
33
|
async function revokeSession(apiKey, params, baseUrl) {
|
|
35
|
-
const
|
|
34
|
+
const url = new URL("/platform/v1/sessions", baseUrl);
|
|
35
|
+
url.searchParams.set("externalCustomerId", params.externalCustomerId);
|
|
36
|
+
const response = await fetch(url, {
|
|
36
37
|
method: "DELETE",
|
|
37
38
|
headers: {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
body: JSON.stringify({ sessionToken: params.sessionToken })
|
|
39
|
+
"X-Api-Key": apiKey
|
|
40
|
+
}
|
|
42
41
|
});
|
|
43
42
|
if (!response.ok) {
|
|
44
43
|
const data = await response.json().catch(() => ({}));
|
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 {\n
|
|
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. Required for 1-tap Apple Pay.\n * If provided, `phoneNumber` must also be provided.\n */\n email?: string;\n /**\n * The customer's phone number in E.164 format. Required for 1-tap Apple Pay.\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": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
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": "0.
|
|
31
|
+
"@moonpay/platform-protocol": "1.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"tsup": "8.0.0",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"sideEffects": false,
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"publishConfig": {
|
|
40
|
-
"access": "
|
|
40
|
+
"access": "public"
|
|
41
41
|
}
|
|
42
42
|
}
|