@moonpay/platform-sdk-node 0.0.0 → 0.2.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 +89 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -5
- package/README.md +0 -3
- package/index.js +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
createServerClient: () => createServerClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/create-session.ts
|
|
28
|
+
var import_platform_protocol = require("@moonpay/platform-protocol");
|
|
29
|
+
async function createSession(apiKey, params, baseUrl) {
|
|
30
|
+
const body = {
|
|
31
|
+
externalCustomerId: params.externalCustomerId,
|
|
32
|
+
deviceIp: params.deviceIp,
|
|
33
|
+
...params.email !== void 0 && { email: params.email },
|
|
34
|
+
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
35
|
+
};
|
|
36
|
+
const response = await fetch(`${baseUrl}/platform/v1/session`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
"Api-Key": apiKey
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify(body)
|
|
43
|
+
});
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
return (0, import_platform_protocol.err)({
|
|
47
|
+
code: data.code ?? "unknown_error",
|
|
48
|
+
message: data.message ?? "Failed to create session",
|
|
49
|
+
errors: data.errors
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return (0, import_platform_protocol.ok)(data);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/revoke-session.ts
|
|
56
|
+
var import_platform_protocol2 = require("@moonpay/platform-protocol");
|
|
57
|
+
async function revokeSession(apiKey, params, baseUrl) {
|
|
58
|
+
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
59
|
+
method: "DELETE",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
"Api-Key": apiKey
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({ sessionToken: params.sessionToken })
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const data = await response.json().catch(() => ({}));
|
|
68
|
+
return (0, import_platform_protocol2.err)({
|
|
69
|
+
code: data.code ?? "unknown_error",
|
|
70
|
+
message: data.message ?? "Failed to revoke session",
|
|
71
|
+
errors: data.errors
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return (0, import_platform_protocol2.ok)(void 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/server-client.ts
|
|
78
|
+
function createServerClient(options) {
|
|
79
|
+
const { apiKey, baseUrl = "https://api.moonpay.com" } = options;
|
|
80
|
+
return {
|
|
81
|
+
createSession: (params) => createSession(apiKey, params, baseUrl),
|
|
82
|
+
revokeSession: (params) => revokeSession(apiKey, params, baseUrl)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
createServerClient
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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 CreateSessionTokenReturnType,\n EmptyResult,\n Result,\n RevokeSessionError,\n} from '@moonpay/platform-protocol';\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 {\n type CreateSessionError,\n type CreateSessionTokenRequestBody,\n type CreateSessionTokenReturnType,\n err,\n ok,\n type Result,\n} from '@moonpay/platform-protocol';\n\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. */\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 externalCustomerId: params.externalCustomerId,\n deviceIp: params.deviceIp,\n ...(params.email !== undefined && { email: params.email }),\n ...(params.phoneNumber !== undefined && { phoneNumber: params.phoneNumber }),\n };\n\n const response = await fetch(`${baseUrl}/platform/v1/session`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n '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 EmptyResult, err, ok, type RevokeSessionError } from '@moonpay/platform-protocol';\n\nexport interface RevokeSessionParams {\n /** The session token to revoke. */\n sessionToken: string;\n}\n\nexport async function revokeSession(\n apiKey: string,\n params: RevokeSessionParams,\n baseUrl: string,\n): Promise<EmptyResult<RevokeSessionError>> {\n const response = await fetch(`${baseUrl}/platform/v1/sessions`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n 'Api-Key': apiKey,\n },\n body: JSON.stringify({ sessionToken: params.sessionToken }),\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 {\n CreateSessionError,\n CreateSessionTokenReturnType,\n EmptyResult,\n Result,\n RevokeSessionError,\n} from '@moonpay/platform-protocol';\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 a previously issued session token. */\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;;;ACAA,+BAOO;AAmBP,eAAsB,cACpB,QACA,QACA,SACmE;AACnE,QAAM,OAAsC;AAAA,IAC1C,oBAAoB,OAAO;AAAA,IAC3B,UAAU,OAAO;AAAA,IACjB,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,wBAAwB;AAAA,IAC7D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb;AAAA,IACA,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,MAAI,CAAC,SAAS,IAAI;AAChB,eAAO,8BAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,aAAO,6BAAG,IAAoC;AAChD;;;AC1DA,IAAAA,4BAAmE;AAOnE,eAAsB,cACpB,QACA,QACA,SAC0C;AAC1C,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,yBAAyB;AAAA,IAC9D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,cAAc,OAAO,aAAa,CAAC;AAAA,EAC5D,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,eAAO,+BAAI;AAAA,MACT,MAAM,KAAK,QAAQ;AAAA,MACnB,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,aAAO,8BAAG,MAAkB;AAC9B;;;ACCO,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_platform_protocol"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result, CreateSessionTokenReturnType, CreateSessionError, EmptyResult, RevokeSessionError } from '@moonpay/platform-protocol';
|
|
2
|
+
export { CreateSessionError, CreateSessionTokenReturnType, EmptyResult, Result, RevokeSessionError } from '@moonpay/platform-protocol';
|
|
3
|
+
|
|
4
|
+
interface CreateSessionParams {
|
|
5
|
+
/** Unique customer identifier from your system. */
|
|
6
|
+
externalCustomerId: string;
|
|
7
|
+
/** The customer's device IP address (IPv4 or IPv6). */
|
|
8
|
+
deviceIp: string;
|
|
9
|
+
/**
|
|
10
|
+
* The customer's email address. Required for 1-tap Apple Pay.
|
|
11
|
+
* If provided, `phoneNumber` must also be provided.
|
|
12
|
+
*/
|
|
13
|
+
email?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The customer's phone number in E.164 format. Required for 1-tap Apple Pay.
|
|
16
|
+
* If provided, `email` must also be provided.
|
|
17
|
+
*/
|
|
18
|
+
phoneNumber?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface RevokeSessionParams {
|
|
22
|
+
/** The session token to revoke. */
|
|
23
|
+
sessionToken: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface CreateServerClientOptions {
|
|
27
|
+
/** Your MoonPay secret API key. Never expose this client-side. */
|
|
28
|
+
apiKey: string;
|
|
29
|
+
/** Override the API base URL. Defaults to production. */
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
interface ServerClient {
|
|
33
|
+
/** Create a session token for a customer. */
|
|
34
|
+
createSession(params: CreateSessionParams): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;
|
|
35
|
+
/** Revoke a previously issued session token. */
|
|
36
|
+
revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a server-side MoonPay client for session management.
|
|
40
|
+
*
|
|
41
|
+
* This client uses your secret API key and must only be used in
|
|
42
|
+
* server-side environments (Node.js, edge functions, etc.).
|
|
43
|
+
*/
|
|
44
|
+
declare function createServerClient(options: CreateServerClientOptions): ServerClient;
|
|
45
|
+
|
|
46
|
+
export { type CreateServerClientOptions, type CreateSessionParams, type RevokeSessionParams, type ServerClient, createServerClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result, CreateSessionTokenReturnType, CreateSessionError, EmptyResult, RevokeSessionError } from '@moonpay/platform-protocol';
|
|
2
|
+
export { CreateSessionError, CreateSessionTokenReturnType, EmptyResult, Result, RevokeSessionError } from '@moonpay/platform-protocol';
|
|
3
|
+
|
|
4
|
+
interface CreateSessionParams {
|
|
5
|
+
/** Unique customer identifier from your system. */
|
|
6
|
+
externalCustomerId: string;
|
|
7
|
+
/** The customer's device IP address (IPv4 or IPv6). */
|
|
8
|
+
deviceIp: string;
|
|
9
|
+
/**
|
|
10
|
+
* The customer's email address. Required for 1-tap Apple Pay.
|
|
11
|
+
* If provided, `phoneNumber` must also be provided.
|
|
12
|
+
*/
|
|
13
|
+
email?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The customer's phone number in E.164 format. Required for 1-tap Apple Pay.
|
|
16
|
+
* If provided, `email` must also be provided.
|
|
17
|
+
*/
|
|
18
|
+
phoneNumber?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface RevokeSessionParams {
|
|
22
|
+
/** The session token to revoke. */
|
|
23
|
+
sessionToken: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface CreateServerClientOptions {
|
|
27
|
+
/** Your MoonPay secret API key. Never expose this client-side. */
|
|
28
|
+
apiKey: string;
|
|
29
|
+
/** Override the API base URL. Defaults to production. */
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
interface ServerClient {
|
|
33
|
+
/** Create a session token for a customer. */
|
|
34
|
+
createSession(params: CreateSessionParams): Promise<Result<CreateSessionTokenReturnType, CreateSessionError>>;
|
|
35
|
+
/** Revoke a previously issued session token. */
|
|
36
|
+
revokeSession(params: RevokeSessionParams): Promise<EmptyResult<RevokeSessionError>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a server-side MoonPay client for session management.
|
|
40
|
+
*
|
|
41
|
+
* This client uses your secret API key and must only be used in
|
|
42
|
+
* server-side environments (Node.js, edge functions, etc.).
|
|
43
|
+
*/
|
|
44
|
+
declare function createServerClient(options: CreateServerClientOptions): ServerClient;
|
|
45
|
+
|
|
46
|
+
export { type CreateServerClientOptions, type CreateSessionParams, type RevokeSessionParams, type ServerClient, createServerClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/create-session.ts
|
|
2
|
+
import {
|
|
3
|
+
err,
|
|
4
|
+
ok
|
|
5
|
+
} from "@moonpay/platform-protocol";
|
|
6
|
+
async function createSession(apiKey, params, baseUrl) {
|
|
7
|
+
const body = {
|
|
8
|
+
externalCustomerId: params.externalCustomerId,
|
|
9
|
+
deviceIp: params.deviceIp,
|
|
10
|
+
...params.email !== void 0 && { email: params.email },
|
|
11
|
+
...params.phoneNumber !== void 0 && { phoneNumber: params.phoneNumber }
|
|
12
|
+
};
|
|
13
|
+
const response = await fetch(`${baseUrl}/platform/v1/session`, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
"Api-Key": apiKey
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(body)
|
|
20
|
+
});
|
|
21
|
+
const data = await response.json();
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
return err({
|
|
24
|
+
code: data.code ?? "unknown_error",
|
|
25
|
+
message: data.message ?? "Failed to create session",
|
|
26
|
+
errors: data.errors
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return ok(data);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/revoke-session.ts
|
|
33
|
+
import { err as err2, ok as ok2 } from "@moonpay/platform-protocol";
|
|
34
|
+
async function revokeSession(apiKey, params, baseUrl) {
|
|
35
|
+
const response = await fetch(`${baseUrl}/platform/v1/sessions`, {
|
|
36
|
+
method: "DELETE",
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"Api-Key": apiKey
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify({ sessionToken: params.sessionToken })
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const data = await response.json().catch(() => ({}));
|
|
45
|
+
return err2({
|
|
46
|
+
code: data.code ?? "unknown_error",
|
|
47
|
+
message: data.message ?? "Failed to revoke session",
|
|
48
|
+
errors: data.errors
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return ok2(void 0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/server-client.ts
|
|
55
|
+
function createServerClient(options) {
|
|
56
|
+
const { apiKey, baseUrl = "https://api.moonpay.com" } = options;
|
|
57
|
+
return {
|
|
58
|
+
createSession: (params) => createSession(apiKey, params, baseUrl),
|
|
59
|
+
revokeSession: (params) => revokeSession(apiKey, params, baseUrl)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
createServerClient
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-session.ts","../src/revoke-session.ts","../src/server-client.ts"],"sourcesContent":["import {\n type CreateSessionError,\n type CreateSessionTokenRequestBody,\n type CreateSessionTokenReturnType,\n err,\n ok,\n type Result,\n} from '@moonpay/platform-protocol';\n\nexport interface CreateSessionParams {\n /** Unique customer identifier from your system. */\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 externalCustomerId: params.externalCustomerId,\n deviceIp: params.deviceIp,\n ...(params.email !== undefined && { email: params.email }),\n ...(params.phoneNumber !== undefined && { phoneNumber: params.phoneNumber }),\n };\n\n const response = await fetch(`${baseUrl}/platform/v1/session`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n '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 EmptyResult, err, ok, type RevokeSessionError } from '@moonpay/platform-protocol';\n\nexport interface RevokeSessionParams {\n /** The session token to revoke. */\n sessionToken: string;\n}\n\nexport async function revokeSession(\n apiKey: string,\n params: RevokeSessionParams,\n baseUrl: string,\n): Promise<EmptyResult<RevokeSessionError>> {\n const response = await fetch(`${baseUrl}/platform/v1/sessions`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n 'Api-Key': apiKey,\n },\n body: JSON.stringify({ sessionToken: params.sessionToken }),\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 {\n CreateSessionError,\n CreateSessionTokenReturnType,\n EmptyResult,\n Result,\n RevokeSessionError,\n} from '@moonpay/platform-protocol';\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 a previously issued session token. */\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,EAIE;AAAA,EACA;AAAA,OAEK;AAmBP,eAAsB,cACpB,QACA,QACA,SACmE;AACnE,QAAM,OAAsC;AAAA,IAC1C,oBAAoB,OAAO;AAAA,IAC3B,UAAU,OAAO;AAAA,IACjB,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,wBAAwB;AAAA,IAC7D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb;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;;;AC1DA,SAA2B,OAAAA,MAAK,MAAAC,WAAmC;AAOnE,eAAsB,cACpB,QACA,QACA,SAC0C;AAC1C,QAAM,WAAW,MAAM,MAAM,GAAG,OAAO,yBAAyB;AAAA,IAC9D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,cAAc,OAAO,aAAa,CAAC;AAAA,EAC5D,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;;;ACCO,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,10 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonpay/platform-sdk-node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MoonPay Platform SDK for Node.js
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "MoonPay Developer Platform server-side SDK for Node.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"clean": "rm -rf dist"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@moonpay/platform-protocol": "workspace:*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "8.0.0",
|
|
34
|
+
"typescript": "5.7.3"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"license": "MIT",
|
|
7
38
|
"publishConfig": {
|
|
8
|
-
"access": "
|
|
39
|
+
"access": "restricted"
|
|
9
40
|
}
|
|
10
41
|
}
|
package/README.md
DELETED
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|