@moonpay/platform-sdk-core 0.2.1 → 0.3.0-next.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 +79 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -2
- package/dist/index.d.ts +43 -2
- package/dist/index.js +72 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,19 @@ __export(src_exports, {
|
|
|
36
36
|
createClientContext: () => createClientContext,
|
|
37
37
|
createClientCore: () => createClientCore,
|
|
38
38
|
createFrameOrchestrator: () => createFrameOrchestrator,
|
|
39
|
+
createIdentity: () => createIdentity,
|
|
39
40
|
decryptCredentials: () => decryptCredentials,
|
|
40
41
|
deletePaymentMethod: () => deletePaymentMethod,
|
|
41
42
|
generateKeyPair: () => generateKeyPair,
|
|
43
|
+
getIdentity: () => getIdentity,
|
|
44
|
+
getIdentityUploadUrl: () => getIdentityUploadUrl,
|
|
42
45
|
getPaymentMethods: () => getPaymentMethods,
|
|
43
46
|
getQuote: () => getQuote,
|
|
44
47
|
getTransaction: () => getTransaction,
|
|
45
|
-
listTransactions: () => listTransactions
|
|
48
|
+
listTransactions: () => listTransactions,
|
|
49
|
+
submitIdentityFiles: () => submitIdentityFiles,
|
|
50
|
+
updateIdentity: () => updateIdentity,
|
|
51
|
+
verifyIdentity: () => verifyIdentity
|
|
46
52
|
});
|
|
47
53
|
module.exports = __toCommonJS(src_exports);
|
|
48
54
|
|
|
@@ -124,8 +130,60 @@ async function getTransaction(ctx, id) {
|
|
|
124
130
|
);
|
|
125
131
|
}
|
|
126
132
|
|
|
127
|
-
// src/api/
|
|
133
|
+
// src/api/identity.ts
|
|
128
134
|
var import_platform_protocol2 = require("@moonpay/platform-protocol");
|
|
135
|
+
async function createIdentity(ctx, body) {
|
|
136
|
+
const response = await ctx.fetch("/platform/v1/identities", {
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: JSON.stringify(body)
|
|
139
|
+
});
|
|
140
|
+
if (response.status === 204) {
|
|
141
|
+
return (0, import_platform_protocol2.ok)({ data: null });
|
|
142
|
+
}
|
|
143
|
+
const parsed = await response.json().catch(() => ({}));
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
const error = parsed;
|
|
146
|
+
return (0, import_platform_protocol2.err)({
|
|
147
|
+
code: error.code ?? "unknown_error",
|
|
148
|
+
message: error.message ?? "Failed to create identity",
|
|
149
|
+
errors: error.errors
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return (0, import_platform_protocol2.ok)(parsed);
|
|
153
|
+
}
|
|
154
|
+
async function getIdentity(ctx, id) {
|
|
155
|
+
return apiFetch(ctx, `/platform/v1/identities/${encodeURIComponent(id)}`);
|
|
156
|
+
}
|
|
157
|
+
async function updateIdentity(ctx, id, body) {
|
|
158
|
+
return apiFetch(ctx, `/platform/v1/identities/${encodeURIComponent(id)}`, {
|
|
159
|
+
method: "PATCH",
|
|
160
|
+
body: JSON.stringify(body)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
async function verifyIdentity(ctx, id) {
|
|
164
|
+
return apiFetch(
|
|
165
|
+
ctx,
|
|
166
|
+
`/platform/v1/identities/${encodeURIComponent(id)}/verifications`,
|
|
167
|
+
{ method: "POST" }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
async function getIdentityUploadUrl(ctx, id, body) {
|
|
171
|
+
return apiFetch(
|
|
172
|
+
ctx,
|
|
173
|
+
`/platform/v1/identities/${encodeURIComponent(id)}/files/upload-url`,
|
|
174
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
async function submitIdentityFiles(ctx, id, body) {
|
|
178
|
+
return apiFetch(
|
|
179
|
+
ctx,
|
|
180
|
+
`/platform/v1/identities/${encodeURIComponent(id)}/files`,
|
|
181
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/api/payment-methods.ts
|
|
186
|
+
var import_platform_protocol3 = require("@moonpay/platform-protocol");
|
|
129
187
|
async function getPaymentMethods(ctx) {
|
|
130
188
|
return apiFetch(ctx, "/platform/v1/payment-methods");
|
|
131
189
|
}
|
|
@@ -136,12 +194,12 @@ async function deletePaymentMethod(ctx, paymentMethodId) {
|
|
|
136
194
|
);
|
|
137
195
|
if (!response.ok) {
|
|
138
196
|
const data = await response.json().catch(() => ({}));
|
|
139
|
-
return (0,
|
|
197
|
+
return (0, import_platform_protocol3.err)({
|
|
140
198
|
code: data.code ?? "unknown_error",
|
|
141
199
|
message: data.message ?? "Failed to delete payment method"
|
|
142
200
|
});
|
|
143
201
|
}
|
|
144
|
-
return (0,
|
|
202
|
+
return (0, import_platform_protocol3.ok)(void 0);
|
|
145
203
|
}
|
|
146
204
|
|
|
147
205
|
// src/client.ts
|
|
@@ -161,7 +219,13 @@ function createClientCore(options) {
|
|
|
161
219
|
getPaymentMethods: () => getPaymentMethods(ctx),
|
|
162
220
|
listTransactions: (params) => listTransactions(ctx, params),
|
|
163
221
|
getTransaction: (id) => getTransaction(ctx, id),
|
|
164
|
-
deletePaymentMethod: (id) => deletePaymentMethod(ctx, id)
|
|
222
|
+
deletePaymentMethod: (id) => deletePaymentMethod(ctx, id),
|
|
223
|
+
createIdentity: (body) => createIdentity(ctx, body),
|
|
224
|
+
getIdentity: (id) => getIdentity(ctx, id),
|
|
225
|
+
updateIdentity: (id, body) => updateIdentity(ctx, id, body),
|
|
226
|
+
verifyIdentity: (id) => verifyIdentity(ctx, id),
|
|
227
|
+
getIdentityUploadUrl: (id, body) => getIdentityUploadUrl(ctx, id, body),
|
|
228
|
+
submitIdentityFiles: (id, body) => submitIdentityFiles(ctx, id, body)
|
|
165
229
|
};
|
|
166
230
|
}
|
|
167
231
|
|
|
@@ -1481,7 +1545,7 @@ function generateKeyPair() {
|
|
|
1481
1545
|
}
|
|
1482
1546
|
|
|
1483
1547
|
// src/frames/frame-orchestrator.ts
|
|
1484
|
-
var
|
|
1548
|
+
var import_platform_protocol4 = require("@moonpay/platform-protocol");
|
|
1485
1549
|
function createFrameOrchestrator(options) {
|
|
1486
1550
|
const { transport, channelId, url, container, hidden, handshakeTimeout = 15e3 } = options;
|
|
1487
1551
|
return new Promise((resolve, reject) => {
|
|
@@ -1496,13 +1560,13 @@ function createFrameOrchestrator(options) {
|
|
|
1496
1560
|
const unsubHandshake = transport.onMessage((msg) => {
|
|
1497
1561
|
if (msg.meta?.channelId !== channelId)
|
|
1498
1562
|
return;
|
|
1499
|
-
if (!handshakeComplete && msg.kind ===
|
|
1563
|
+
if (!handshakeComplete && msg.kind === import_platform_protocol4.HANDSHAKE_REQUEST_KIND) {
|
|
1500
1564
|
handshakeComplete = true;
|
|
1501
1565
|
clearTimeout(timer);
|
|
1502
1566
|
transport.sendMessage({
|
|
1503
1567
|
version: 2,
|
|
1504
1568
|
meta: { channelId },
|
|
1505
|
-
kind:
|
|
1569
|
+
kind: import_platform_protocol4.HANDSHAKE_ACK_KIND
|
|
1506
1570
|
});
|
|
1507
1571
|
resolve(handle);
|
|
1508
1572
|
return;
|
|
@@ -1580,13 +1644,19 @@ function buildFrameUrl(path, query = {}, options = {}) {
|
|
|
1580
1644
|
createClientContext,
|
|
1581
1645
|
createClientCore,
|
|
1582
1646
|
createFrameOrchestrator,
|
|
1647
|
+
createIdentity,
|
|
1583
1648
|
decryptCredentials,
|
|
1584
1649
|
deletePaymentMethod,
|
|
1585
1650
|
generateKeyPair,
|
|
1651
|
+
getIdentity,
|
|
1652
|
+
getIdentityUploadUrl,
|
|
1586
1653
|
getPaymentMethods,
|
|
1587
1654
|
getQuote,
|
|
1588
1655
|
getTransaction,
|
|
1589
|
-
listTransactions
|
|
1656
|
+
listTransactions,
|
|
1657
|
+
submitIdentityFiles,
|
|
1658
|
+
updateIdentity,
|
|
1659
|
+
verifyIdentity
|
|
1590
1660
|
});
|
|
1591
1661
|
/*! Bundled license information:
|
|
1592
1662
|
|