@moonpay/platform-sdk-react-native 1.25.0 → 1.26.1
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 +135 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +133 -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,
|
|
@@ -207,6 +210,14 @@ var buyButtonSpec = {
|
|
|
207
210
|
payload: { code: "generic", message }
|
|
208
211
|
})
|
|
209
212
|
};
|
|
213
|
+
var headlessBuyButtonSpec = {
|
|
214
|
+
...buyButtonSpec,
|
|
215
|
+
hidden: true,
|
|
216
|
+
buildParams: (ctx, props) => ({
|
|
217
|
+
...buyButtonSpec.buildParams?.(ctx, props),
|
|
218
|
+
headless: true
|
|
219
|
+
})
|
|
220
|
+
};
|
|
210
221
|
function applyCredentialsOnComplete(msg, ctx) {
|
|
211
222
|
if (msg.kind !== "complete" || !ctx.privateKey) return;
|
|
212
223
|
const connection = msg.payload;
|
|
@@ -395,6 +406,7 @@ var buySpec = {
|
|
|
395
406
|
var addCardSpec = {
|
|
396
407
|
channelPrefix: "add-card",
|
|
397
408
|
path: import_platform_sdk_core.FRAME_PATHS.addCard,
|
|
409
|
+
enterprise: true,
|
|
398
410
|
hidden: false,
|
|
399
411
|
buildParams: (ctx, props) => ({
|
|
400
412
|
clientToken: ctx.core.context.clientToken,
|
|
@@ -454,6 +466,7 @@ var challengeSpec = {
|
|
|
454
466
|
channelPrefix: "challenge",
|
|
455
467
|
path: import_platform_sdk_core.FRAME_PATHS.challenge,
|
|
456
468
|
// documentation only — buildUrl below wins
|
|
469
|
+
enterprise: true,
|
|
457
470
|
hidden: false,
|
|
458
471
|
resolveChannelId: (props, generated) => new URL(props.url).searchParams.get("channelId") || generated,
|
|
459
472
|
buildUrl: (ctx, props, channelId) => {
|
|
@@ -625,6 +638,9 @@ var FrameSessionDisposedError = class extends Error {
|
|
|
625
638
|
}
|
|
626
639
|
};
|
|
627
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
|
+
}
|
|
628
644
|
const generated = `${spec.channelPrefix}-${Date.now()}`;
|
|
629
645
|
const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
|
|
630
646
|
let keyPair;
|
|
@@ -828,12 +844,15 @@ async function setupBuy(deps, opts) {
|
|
|
828
844
|
var import_result5 = require("@moonpay/platform-protocol/result");
|
|
829
845
|
async function setupBuyButton(deps, opts) {
|
|
830
846
|
try {
|
|
831
|
-
const { handle, dispose } = await deps.mountSession(
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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
|
+
);
|
|
837
856
|
handle.onEvent((event) => opts.onEvent?.(event));
|
|
838
857
|
return (0, import_result5.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
839
858
|
} catch (e) {
|
|
@@ -1040,6 +1059,13 @@ function createRNClient(deps) {
|
|
|
1040
1059
|
submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
|
|
1041
1060
|
};
|
|
1042
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
|
+
}
|
|
1043
1069
|
|
|
1044
1070
|
// src/methods/mount-session.ts
|
|
1045
1071
|
var slotCounter = 0;
|
|
@@ -1274,23 +1300,20 @@ var styles = import_react_native2.StyleSheet.create({
|
|
|
1274
1300
|
|
|
1275
1301
|
// src/provider.tsx
|
|
1276
1302
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1303
|
+
var FrameHostContext = (0, import_react3.createContext)(null);
|
|
1277
1304
|
var MoonPayContext = (0, import_react3.createContext)(null);
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
apiBaseUrl,
|
|
1281
|
-
frameBaseUrl,
|
|
1282
|
-
theme,
|
|
1283
|
-
children
|
|
1284
|
-
}) {
|
|
1305
|
+
var MoonPayEnterpriseContext = (0, import_react3.createContext)(null);
|
|
1306
|
+
function useFrameSlots() {
|
|
1285
1307
|
const [frameSlots, setFrameSlots] = (0, import_react3.useState)([]);
|
|
1286
|
-
const [internalToken, setInternalToken] = (0, import_react3.useState)(void 0);
|
|
1287
|
-
const sessionToken = sessionTokenProp ?? internalToken;
|
|
1288
1308
|
const addSlot = (0, import_react3.useCallback)((slot) => {
|
|
1289
1309
|
setFrameSlots((prev) => [...prev, slot]);
|
|
1290
1310
|
}, []);
|
|
1291
1311
|
const removeSlot = (0, import_react3.useCallback)((id) => {
|
|
1292
1312
|
setFrameSlots((prev) => prev.filter((s) => s.id !== id));
|
|
1293
1313
|
}, []);
|
|
1314
|
+
return { frameSlots, addSlot, removeSlot };
|
|
1315
|
+
}
|
|
1316
|
+
function useCore(apiBaseUrl, frameBaseUrl) {
|
|
1294
1317
|
const coreRef = (0, import_react3.useRef)(null);
|
|
1295
1318
|
if (!coreRef.current) {
|
|
1296
1319
|
coreRef.current = (0, import_platform_sdk_core5.createClientCore)({
|
|
@@ -1299,7 +1322,38 @@ function MoonPayProvider({
|
|
|
1299
1322
|
createTransport: () => new WebViewTransport()
|
|
1300
1323
|
});
|
|
1301
1324
|
}
|
|
1302
|
-
|
|
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);
|
|
1303
1357
|
const initialize = (0, import_react3.useCallback)(
|
|
1304
1358
|
(token) => {
|
|
1305
1359
|
core.context.setAccessToken("");
|
|
@@ -1308,46 +1362,72 @@ function MoonPayProvider({
|
|
|
1308
1362
|
},
|
|
1309
1363
|
[core]
|
|
1310
1364
|
);
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1313
|
-
|
|
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({
|
|
1314
1371
|
mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
|
|
1315
1372
|
core
|
|
1316
|
-
})
|
|
1317
|
-
|
|
1373
|
+
}),
|
|
1374
|
+
[specCtx, core, addSlot, removeSlot]
|
|
1375
|
+
);
|
|
1318
1376
|
const isInitialized = sessionToken !== void 0;
|
|
1319
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1320
|
-
|
|
1321
|
-
{
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
))
|
|
1337
|
-
]
|
|
1338
|
-
}
|
|
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]
|
|
1339
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]
|
|
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
|
+
] }) });
|
|
1340
1408
|
}
|
|
1341
|
-
function
|
|
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;
|
|
1417
|
+
}
|
|
1418
|
+
function useMoonPay() {
|
|
1342
1419
|
const ctx = (0, import_react3.useContext)(MoonPayContext);
|
|
1343
1420
|
if (!ctx) {
|
|
1344
1421
|
throw new Error("useMoonPay must be used within a <MoonPayProvider>");
|
|
1345
1422
|
}
|
|
1346
1423
|
return ctx;
|
|
1347
1424
|
}
|
|
1348
|
-
function
|
|
1349
|
-
const
|
|
1350
|
-
|
|
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;
|
|
1351
1431
|
}
|
|
1352
1432
|
|
|
1353
1433
|
// src/frame-view.tsx
|
|
@@ -1370,7 +1450,8 @@ function MoonPayFrameView({
|
|
|
1370
1450
|
webViewProps,
|
|
1371
1451
|
onRef
|
|
1372
1452
|
}) {
|
|
1373
|
-
const
|
|
1453
|
+
const frameHost = useFrameHostContext();
|
|
1454
|
+
const { sessionToken, enterpriseClientToken, core, frameBaseUrl } = frameHost;
|
|
1374
1455
|
const [transport, setTransport] = (0, import_react4.useState)(null);
|
|
1375
1456
|
const handleRef = (0, import_react4.useRef)(null);
|
|
1376
1457
|
const onEventRef = (0, import_react4.useRef)(onEvent);
|
|
@@ -1396,11 +1477,7 @@ function MoonPayFrameView({
|
|
|
1396
1477
|
}
|
|
1397
1478
|
appliedRef.current = applied;
|
|
1398
1479
|
try {
|
|
1399
|
-
session = createFrameSession(
|
|
1400
|
-
spec,
|
|
1401
|
-
{ sessionToken, core, frameBaseUrl, theme },
|
|
1402
|
-
propsRef.current
|
|
1403
|
-
);
|
|
1480
|
+
session = createFrameSession(spec, frameHost, propsRef.current);
|
|
1404
1481
|
} catch (e) {
|
|
1405
1482
|
onEventRef.current?.(
|
|
1406
1483
|
spec.errorEvent(e instanceof Error ? e.message : "Failed to create frame")
|
|
@@ -1429,7 +1506,7 @@ function MoonPayFrameView({
|
|
|
1429
1506
|
session.dispose();
|
|
1430
1507
|
setTransport(null);
|
|
1431
1508
|
};
|
|
1432
|
-
}, [mountKey, spec, sessionToken, core, frameBaseUrl]);
|
|
1509
|
+
}, [mountKey, spec, sessionToken, enterpriseClientToken, core, frameBaseUrl]);
|
|
1433
1510
|
(0, import_react4.useEffect)(() => {
|
|
1434
1511
|
const handle = handleRef.current;
|
|
1435
1512
|
if (!handle) return;
|
|
@@ -1505,6 +1582,7 @@ function MoonPayBuyButton({
|
|
|
1505
1582
|
quote,
|
|
1506
1583
|
externalTransactionId,
|
|
1507
1584
|
applePayButtonSettings,
|
|
1585
|
+
headless,
|
|
1508
1586
|
onEvent,
|
|
1509
1587
|
style,
|
|
1510
1588
|
webViewProps
|
|
@@ -1512,7 +1590,7 @@ function MoonPayBuyButton({
|
|
|
1512
1590
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1513
1591
|
MoonPayFrameView,
|
|
1514
1592
|
{
|
|
1515
|
-
spec: buyButtonSpec,
|
|
1593
|
+
spec: headless ? headlessBuyButtonSpec : buyButtonSpec,
|
|
1516
1594
|
props: { quote, externalTransactionId, applePayButtonSettings },
|
|
1517
1595
|
style,
|
|
1518
1596
|
defaultStyle: { height: 48 },
|
|
@@ -1697,11 +1775,13 @@ function MoonPayWidget({
|
|
|
1697
1775
|
MoonPayConnectionCheck,
|
|
1698
1776
|
MoonPayConnectionReset,
|
|
1699
1777
|
MoonPayCustomerExport,
|
|
1778
|
+
MoonPayEnterpriseProvider,
|
|
1700
1779
|
MoonPayFrame,
|
|
1701
1780
|
MoonPayGooglePayButton,
|
|
1702
1781
|
MoonPayProvider,
|
|
1703
1782
|
MoonPayWidget,
|
|
1704
1783
|
WebViewTransport,
|
|
1705
|
-
useMoonPay
|
|
1784
|
+
useMoonPay,
|
|
1785
|
+
useMoonPayEnterprise
|
|
1706
1786
|
});
|
|
1707
1787
|
//# sourceMappingURL=index.cjs.map
|