@moonpay/platform-sdk-react-native 1.24.3 → 1.26.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 +140 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -4
- package/dist/index.d.ts +45 -4
- package/dist/index.js +138 -55
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -41,12 +41,14 @@ __export(index_exports, {
|
|
|
41
41
|
MoonPayConnectionCheck: () => MoonPayConnectionCheck,
|
|
42
42
|
MoonPayConnectionReset: () => MoonPayConnectionReset,
|
|
43
43
|
MoonPayCustomerExport: () => MoonPayCustomerExport,
|
|
44
|
+
MoonPayEnterpriseProvider: () => MoonPayEnterpriseProvider,
|
|
44
45
|
MoonPayFrame: () => MoonPayFrame,
|
|
45
46
|
MoonPayGooglePayButton: () => MoonPayGooglePayButton,
|
|
46
47
|
MoonPayProvider: () => MoonPayProvider,
|
|
47
48
|
MoonPayWidget: () => MoonPayWidget,
|
|
48
49
|
WebViewTransport: () => WebViewTransport,
|
|
49
|
-
useMoonPay: () => useMoonPay
|
|
50
|
+
useMoonPay: () => useMoonPay,
|
|
51
|
+
useMoonPayEnterprise: () => useMoonPayEnterprise
|
|
50
52
|
});
|
|
51
53
|
module.exports = __toCommonJS(index_exports);
|
|
52
54
|
var import_connection2 = require("@moonpay/platform-protocol/models/connection");
|
|
@@ -166,6 +168,7 @@ var googlePaySpec = {
|
|
|
166
168
|
var buyButtonSpec = {
|
|
167
169
|
channelPrefix: "buy-button",
|
|
168
170
|
path: import_platform_sdk_core.FRAME_PATHS.buyButton,
|
|
171
|
+
enterprise: true,
|
|
169
172
|
hidden: false,
|
|
170
173
|
buildParams: (ctx, props) => ({
|
|
171
174
|
clientToken: ctx.core.context.clientToken,
|
|
@@ -191,6 +194,11 @@ var buyButtonSpec = {
|
|
|
191
194
|
kind: "challenge",
|
|
192
195
|
payload: msg.payload
|
|
193
196
|
};
|
|
197
|
+
case "cancelled":
|
|
198
|
+
return {
|
|
199
|
+
kind: "cancelled",
|
|
200
|
+
payload: msg.payload
|
|
201
|
+
};
|
|
194
202
|
case "error":
|
|
195
203
|
return { kind: "error", payload: msg.payload };
|
|
196
204
|
default:
|
|
@@ -202,6 +210,14 @@ var buyButtonSpec = {
|
|
|
202
210
|
payload: { code: "generic", message }
|
|
203
211
|
})
|
|
204
212
|
};
|
|
213
|
+
var headlessBuyButtonSpec = {
|
|
214
|
+
...buyButtonSpec,
|
|
215
|
+
hidden: true,
|
|
216
|
+
buildParams: (ctx, props) => ({
|
|
217
|
+
...buyButtonSpec.buildParams?.(ctx, props),
|
|
218
|
+
headless: true
|
|
219
|
+
})
|
|
220
|
+
};
|
|
205
221
|
function applyCredentialsOnComplete(msg, ctx) {
|
|
206
222
|
if (msg.kind !== "complete" || !ctx.privateKey) return;
|
|
207
223
|
const connection = msg.payload;
|
|
@@ -390,6 +406,7 @@ var buySpec = {
|
|
|
390
406
|
var addCardSpec = {
|
|
391
407
|
channelPrefix: "add-card",
|
|
392
408
|
path: import_platform_sdk_core.FRAME_PATHS.addCard,
|
|
409
|
+
enterprise: true,
|
|
393
410
|
hidden: false,
|
|
394
411
|
buildParams: (ctx, props) => ({
|
|
395
412
|
clientToken: ctx.core.context.clientToken,
|
|
@@ -449,6 +466,7 @@ var challengeSpec = {
|
|
|
449
466
|
channelPrefix: "challenge",
|
|
450
467
|
path: import_platform_sdk_core.FRAME_PATHS.challenge,
|
|
451
468
|
// documentation only — buildUrl below wins
|
|
469
|
+
enterprise: true,
|
|
452
470
|
hidden: false,
|
|
453
471
|
resolveChannelId: (props, generated) => new URL(props.url).searchParams.get("channelId") || generated,
|
|
454
472
|
buildUrl: (ctx, props, channelId) => {
|
|
@@ -620,6 +638,9 @@ var FrameSessionDisposedError = class extends Error {
|
|
|
620
638
|
}
|
|
621
639
|
};
|
|
622
640
|
function createFrameSession(spec, ctx, props, overrides = {}) {
|
|
641
|
+
if (ctx.enterpriseClientToken && !spec.enterprise) {
|
|
642
|
+
throw new Error(`The ${spec.channelPrefix} frame is not available for enterprise clients`);
|
|
643
|
+
}
|
|
623
644
|
const generated = `${spec.channelPrefix}-${Date.now()}`;
|
|
624
645
|
const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
|
|
625
646
|
let keyPair;
|
|
@@ -823,12 +844,15 @@ async function setupBuy(deps, opts) {
|
|
|
823
844
|
var import_result5 = require("@moonpay/platform-protocol/result");
|
|
824
845
|
async function setupBuyButton(deps, opts) {
|
|
825
846
|
try {
|
|
826
|
-
const { handle, dispose } = await deps.mountSession(
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
847
|
+
const { handle, dispose } = await deps.mountSession(
|
|
848
|
+
opts.headless ? headlessBuyButtonSpec : buyButtonSpec,
|
|
849
|
+
{
|
|
850
|
+
quote: opts.quote,
|
|
851
|
+
externalTransactionId: opts.externalTransactionId,
|
|
852
|
+
applePayButtonSettings: opts.applePayButtonSettings,
|
|
853
|
+
presentation: opts.presentation
|
|
854
|
+
}
|
|
855
|
+
);
|
|
832
856
|
handle.onEvent((event) => opts.onEvent?.(event));
|
|
833
857
|
return (0, import_result5.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
834
858
|
} catch (e) {
|
|
@@ -1035,6 +1059,13 @@ function createRNClient(deps) {
|
|
|
1035
1059
|
submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
|
|
1036
1060
|
};
|
|
1037
1061
|
}
|
|
1062
|
+
function createRNEnterpriseClient(deps) {
|
|
1063
|
+
return {
|
|
1064
|
+
setupBuyButton: (opts) => setupBuyButton(deps, opts),
|
|
1065
|
+
setupChallenge: (opts) => setupChallenge(deps, opts),
|
|
1066
|
+
setupAddCard: (opts) => setupAddCard(deps, opts)
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1038
1069
|
|
|
1039
1070
|
// src/methods/mount-session.ts
|
|
1040
1071
|
var slotCounter = 0;
|
|
@@ -1269,23 +1300,20 @@ var styles = import_react_native2.StyleSheet.create({
|
|
|
1269
1300
|
|
|
1270
1301
|
// src/provider.tsx
|
|
1271
1302
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1303
|
+
var FrameHostContext = (0, import_react3.createContext)(null);
|
|
1272
1304
|
var MoonPayContext = (0, import_react3.createContext)(null);
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
apiBaseUrl,
|
|
1276
|
-
frameBaseUrl,
|
|
1277
|
-
theme,
|
|
1278
|
-
children
|
|
1279
|
-
}) {
|
|
1305
|
+
var MoonPayEnterpriseContext = (0, import_react3.createContext)(null);
|
|
1306
|
+
function useFrameSlots() {
|
|
1280
1307
|
const [frameSlots, setFrameSlots] = (0, import_react3.useState)([]);
|
|
1281
|
-
const [internalToken, setInternalToken] = (0, import_react3.useState)(void 0);
|
|
1282
|
-
const sessionToken = sessionTokenProp ?? internalToken;
|
|
1283
1308
|
const addSlot = (0, import_react3.useCallback)((slot) => {
|
|
1284
1309
|
setFrameSlots((prev) => [...prev, slot]);
|
|
1285
1310
|
}, []);
|
|
1286
1311
|
const removeSlot = (0, import_react3.useCallback)((id) => {
|
|
1287
1312
|
setFrameSlots((prev) => prev.filter((s) => s.id !== id));
|
|
1288
1313
|
}, []);
|
|
1314
|
+
return { frameSlots, addSlot, removeSlot };
|
|
1315
|
+
}
|
|
1316
|
+
function useCore(apiBaseUrl, frameBaseUrl) {
|
|
1289
1317
|
const coreRef = (0, import_react3.useRef)(null);
|
|
1290
1318
|
if (!coreRef.current) {
|
|
1291
1319
|
coreRef.current = (0, import_platform_sdk_core5.createClientCore)({
|
|
@@ -1294,7 +1322,38 @@ function MoonPayProvider({
|
|
|
1294
1322
|
createTransport: () => new WebViewTransport()
|
|
1295
1323
|
});
|
|
1296
1324
|
}
|
|
1297
|
-
|
|
1325
|
+
return coreRef.current;
|
|
1326
|
+
}
|
|
1327
|
+
function FrameSlots({
|
|
1328
|
+
frameSlots,
|
|
1329
|
+
removeSlot
|
|
1330
|
+
}) {
|
|
1331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1332
|
+
frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
|
|
1333
|
+
frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1334
|
+
VisibleFrameSlotSheet,
|
|
1335
|
+
{
|
|
1336
|
+
slot,
|
|
1337
|
+
onClose: () => {
|
|
1338
|
+
slot.dispose();
|
|
1339
|
+
removeSlot(slot.id);
|
|
1340
|
+
}
|
|
1341
|
+
},
|
|
1342
|
+
slot.id
|
|
1343
|
+
))
|
|
1344
|
+
] });
|
|
1345
|
+
}
|
|
1346
|
+
function MoonPayProvider({
|
|
1347
|
+
sessionToken: sessionTokenProp,
|
|
1348
|
+
apiBaseUrl,
|
|
1349
|
+
frameBaseUrl,
|
|
1350
|
+
theme,
|
|
1351
|
+
children
|
|
1352
|
+
}) {
|
|
1353
|
+
const { frameSlots, addSlot, removeSlot } = useFrameSlots();
|
|
1354
|
+
const [internalToken, setInternalToken] = (0, import_react3.useState)(void 0);
|
|
1355
|
+
const sessionToken = sessionTokenProp ?? internalToken;
|
|
1356
|
+
const core = useCore(apiBaseUrl, frameBaseUrl);
|
|
1298
1357
|
const initialize = (0, import_react3.useCallback)(
|
|
1299
1358
|
(token) => {
|
|
1300
1359
|
core.context.setAccessToken("");
|
|
@@ -1303,46 +1362,72 @@ function MoonPayProvider({
|
|
|
1303
1362
|
},
|
|
1304
1363
|
[core]
|
|
1305
1364
|
);
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1308
|
-
|
|
1365
|
+
const specCtx = (0, import_react3.useMemo)(
|
|
1366
|
+
() => ({ sessionToken, core, frameBaseUrl, theme }),
|
|
1367
|
+
[sessionToken, core, frameBaseUrl, theme?.appearance]
|
|
1368
|
+
);
|
|
1369
|
+
const client = (0, import_react3.useMemo)(
|
|
1370
|
+
() => createRNClient({
|
|
1309
1371
|
mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
|
|
1310
1372
|
core
|
|
1311
|
-
})
|
|
1312
|
-
|
|
1373
|
+
}),
|
|
1374
|
+
[specCtx, core, addSlot, removeSlot]
|
|
1375
|
+
);
|
|
1313
1376
|
const isInitialized = sessionToken !== void 0;
|
|
1314
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1315
|
-
|
|
1316
|
-
{
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FrameHostContext.Provider, { value: specCtx, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(MoonPayContext.Provider, { value: { client, initialize, isInitialized }, children: [
|
|
1378
|
+
children,
|
|
1379
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FrameSlots, { frameSlots, removeSlot })
|
|
1380
|
+
] }) });
|
|
1381
|
+
}
|
|
1382
|
+
function MoonPayEnterpriseProvider({
|
|
1383
|
+
clientToken,
|
|
1384
|
+
frameBaseUrl,
|
|
1385
|
+
theme,
|
|
1386
|
+
children
|
|
1387
|
+
}) {
|
|
1388
|
+
const { frameSlots, addSlot, removeSlot } = useFrameSlots();
|
|
1389
|
+
const core = useCore(void 0, frameBaseUrl);
|
|
1390
|
+
core.context.setClientToken(clientToken);
|
|
1391
|
+
const specCtx = (0, import_react3.useMemo)(
|
|
1392
|
+
() => ({ core, frameBaseUrl, theme, enterpriseClientToken: clientToken }),
|
|
1393
|
+
[clientToken, core, frameBaseUrl, theme?.appearance]
|
|
1394
|
+
);
|
|
1395
|
+
const value = (0, import_react3.useMemo)(
|
|
1396
|
+
() => ({
|
|
1397
|
+
client: createRNEnterpriseClient({
|
|
1398
|
+
mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
|
|
1399
|
+
core
|
|
1400
|
+
})
|
|
1401
|
+
}),
|
|
1402
|
+
[specCtx, core, addSlot, removeSlot]
|
|
1334
1403
|
);
|
|
1404
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FrameHostContext.Provider, { value: specCtx, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(MoonPayEnterpriseContext.Provider, { value, children: [
|
|
1405
|
+
children,
|
|
1406
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FrameSlots, { frameSlots, removeSlot })
|
|
1407
|
+
] }) });
|
|
1408
|
+
}
|
|
1409
|
+
function useFrameHostContext() {
|
|
1410
|
+
const ctx = (0, import_react3.useContext)(FrameHostContext);
|
|
1411
|
+
if (!ctx) {
|
|
1412
|
+
throw new Error(
|
|
1413
|
+
"MoonPay frame components must be used within a <MoonPayProvider> or <MoonPayEnterpriseProvider>"
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
return ctx;
|
|
1335
1417
|
}
|
|
1336
|
-
function
|
|
1418
|
+
function useMoonPay() {
|
|
1337
1419
|
const ctx = (0, import_react3.useContext)(MoonPayContext);
|
|
1338
1420
|
if (!ctx) {
|
|
1339
1421
|
throw new Error("useMoonPay must be used within a <MoonPayProvider>");
|
|
1340
1422
|
}
|
|
1341
1423
|
return ctx;
|
|
1342
1424
|
}
|
|
1343
|
-
function
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1425
|
+
function useMoonPayEnterprise() {
|
|
1426
|
+
const ctx = (0, import_react3.useContext)(MoonPayEnterpriseContext);
|
|
1427
|
+
if (!ctx) {
|
|
1428
|
+
throw new Error("useMoonPayEnterprise must be used within a <MoonPayEnterpriseProvider>");
|
|
1429
|
+
}
|
|
1430
|
+
return ctx;
|
|
1346
1431
|
}
|
|
1347
1432
|
|
|
1348
1433
|
// src/frame-view.tsx
|
|
@@ -1365,7 +1450,8 @@ function MoonPayFrameView({
|
|
|
1365
1450
|
webViewProps,
|
|
1366
1451
|
onRef
|
|
1367
1452
|
}) {
|
|
1368
|
-
const
|
|
1453
|
+
const frameHost = useFrameHostContext();
|
|
1454
|
+
const { sessionToken, enterpriseClientToken, core, frameBaseUrl } = frameHost;
|
|
1369
1455
|
const [transport, setTransport] = (0, import_react4.useState)(null);
|
|
1370
1456
|
const handleRef = (0, import_react4.useRef)(null);
|
|
1371
1457
|
const onEventRef = (0, import_react4.useRef)(onEvent);
|
|
@@ -1391,11 +1477,7 @@ function MoonPayFrameView({
|
|
|
1391
1477
|
}
|
|
1392
1478
|
appliedRef.current = applied;
|
|
1393
1479
|
try {
|
|
1394
|
-
session = createFrameSession(
|
|
1395
|
-
spec,
|
|
1396
|
-
{ sessionToken, core, frameBaseUrl, theme },
|
|
1397
|
-
propsRef.current
|
|
1398
|
-
);
|
|
1480
|
+
session = createFrameSession(spec, frameHost, propsRef.current);
|
|
1399
1481
|
} catch (e) {
|
|
1400
1482
|
onEventRef.current?.(
|
|
1401
1483
|
spec.errorEvent(e instanceof Error ? e.message : "Failed to create frame")
|
|
@@ -1424,7 +1506,7 @@ function MoonPayFrameView({
|
|
|
1424
1506
|
session.dispose();
|
|
1425
1507
|
setTransport(null);
|
|
1426
1508
|
};
|
|
1427
|
-
}, [mountKey, spec, sessionToken, core, frameBaseUrl]);
|
|
1509
|
+
}, [mountKey, spec, sessionToken, enterpriseClientToken, core, frameBaseUrl]);
|
|
1428
1510
|
(0, import_react4.useEffect)(() => {
|
|
1429
1511
|
const handle = handleRef.current;
|
|
1430
1512
|
if (!handle) return;
|
|
@@ -1500,6 +1582,7 @@ function MoonPayBuyButton({
|
|
|
1500
1582
|
quote,
|
|
1501
1583
|
externalTransactionId,
|
|
1502
1584
|
applePayButtonSettings,
|
|
1585
|
+
headless,
|
|
1503
1586
|
onEvent,
|
|
1504
1587
|
style,
|
|
1505
1588
|
webViewProps
|
|
@@ -1507,7 +1590,7 @@ function MoonPayBuyButton({
|
|
|
1507
1590
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1508
1591
|
MoonPayFrameView,
|
|
1509
1592
|
{
|
|
1510
|
-
spec: buyButtonSpec,
|
|
1593
|
+
spec: headless ? headlessBuyButtonSpec : buyButtonSpec,
|
|
1511
1594
|
props: { quote, externalTransactionId, applePayButtonSettings },
|
|
1512
1595
|
style,
|
|
1513
1596
|
defaultStyle: { height: 48 },
|
|
@@ -1692,11 +1775,13 @@ function MoonPayWidget({
|
|
|
1692
1775
|
MoonPayConnectionCheck,
|
|
1693
1776
|
MoonPayConnectionReset,
|
|
1694
1777
|
MoonPayCustomerExport,
|
|
1778
|
+
MoonPayEnterpriseProvider,
|
|
1695
1779
|
MoonPayFrame,
|
|
1696
1780
|
MoonPayGooglePayButton,
|
|
1697
1781
|
MoonPayProvider,
|
|
1698
1782
|
MoonPayWidget,
|
|
1699
1783
|
WebViewTransport,
|
|
1700
|
-
useMoonPay
|
|
1784
|
+
useMoonPay,
|
|
1785
|
+
useMoonPayEnterprise
|
|
1701
1786
|
});
|
|
1702
1787
|
//# sourceMappingURL=index.cjs.map
|