@monei-js/components 2.1.3 → 2.1.4
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 -56
- package/dist/index.js +79 -56
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -111,7 +111,8 @@ const getLanguage = () => {
|
|
|
111
111
|
};
|
|
112
112
|
const safe = (fn) => {
|
|
113
113
|
try {
|
|
114
|
-
|
|
114
|
+
var _fn;
|
|
115
|
+
return String((_fn = fn()) !== null && _fn !== void 0 ? _fn : "");
|
|
115
116
|
} catch {
|
|
116
117
|
return "";
|
|
117
118
|
}
|
|
@@ -129,7 +130,10 @@ const getClientEnv = () => {
|
|
|
129
130
|
safe(() => navigator.deviceMemory),
|
|
130
131
|
safe(() => navigator.maxTouchPoints),
|
|
131
132
|
safe(() => navigator.platform),
|
|
132
|
-
safe(() =>
|
|
133
|
+
safe(() => {
|
|
134
|
+
var _navigator$languages;
|
|
135
|
+
return (_navigator$languages = navigator.languages) === null || _navigator$languages === void 0 ? void 0 : _navigator$languages.join(",");
|
|
136
|
+
})
|
|
133
137
|
].join("|");
|
|
134
138
|
return window.btoa(env);
|
|
135
139
|
};
|
|
@@ -162,8 +166,9 @@ const getPersistentSeed = async () => {
|
|
|
162
166
|
const thumbmark = new _thumbmarkjs_thumbmarkjs.Thumbmark({ logging: false });
|
|
163
167
|
thumbmark.includeComponent("persistent_seed", getPersistentSeed);
|
|
164
168
|
const getClientFingerprint = async () => {
|
|
169
|
+
var _result$thumbmark;
|
|
165
170
|
const [, result] = await withError(thumbmark.get());
|
|
166
|
-
return result
|
|
171
|
+
return (_result$thumbmark = result === null || result === void 0 ? void 0 : result.thumbmark) !== null && _result$thumbmark !== void 0 ? _result$thumbmark : "";
|
|
167
172
|
};
|
|
168
173
|
const withError = async (p) => {
|
|
169
174
|
try {
|
|
@@ -513,6 +518,7 @@ function createVue3Driver(ComponentClass) {
|
|
|
513
518
|
*/
|
|
514
519
|
function createAngularDriver(ComponentClass) {
|
|
515
520
|
return ({ Component: AngularComponent, NgModule, ElementRef, NgZone, Inject }) => {
|
|
521
|
+
var _options;
|
|
516
522
|
class ComponentInstance {
|
|
517
523
|
constructor(elementRef, zone) {
|
|
518
524
|
this.props = {};
|
|
@@ -549,7 +555,7 @@ function createAngularDriver(ComponentClass) {
|
|
|
549
555
|
}
|
|
550
556
|
ComponentInstance.parameters = [[new Inject(ElementRef)], [new Inject(NgZone)]];
|
|
551
557
|
ComponentInstance.annotations = [new AngularComponent({
|
|
552
|
-
selector: ComponentClass.prototype.__options
|
|
558
|
+
selector: ((_options = ComponentClass.prototype.__options) === null || _options === void 0 ? void 0 : _options.tag) || "bridge-component",
|
|
553
559
|
template: "<div></div>",
|
|
554
560
|
inputs: ["props"]
|
|
555
561
|
})];
|
|
@@ -585,10 +591,6 @@ function resolveDriver(name, ComponentClass, deps) {
|
|
|
585
591
|
return factory(ComponentClass)(deps);
|
|
586
592
|
}
|
|
587
593
|
//#endregion
|
|
588
|
-
//#region ../shared/lib/bridge-constants.ts
|
|
589
|
-
/** Protocol identifier for sync bootstrap messages between parent and child bridges */
|
|
590
|
-
const BRIDGE_INIT_MSG = "__monei_bridge_init__";
|
|
591
|
-
//#endregion
|
|
592
594
|
//#region src/bridge/constants.ts
|
|
593
595
|
/** Bridge lifecycle events (replaces zoid.EVENT) */
|
|
594
596
|
const EVENT = {
|
|
@@ -770,6 +772,7 @@ function attachRenderMethods(instance, options) {
|
|
|
770
772
|
* 8. createConnection — establish Penpal async RPC channel, deliver props via updateProps
|
|
771
773
|
*/
|
|
772
774
|
instance.render = async (container) => {
|
|
775
|
+
var _SANDBOX$options$tag;
|
|
773
776
|
if (renderState.destroyed) throw new Error("Component is destroyed");
|
|
774
777
|
if (renderState.frame) throw new Error("Component already rendered");
|
|
775
778
|
const targetEl = resolveContainer(container);
|
|
@@ -781,7 +784,7 @@ function attachRenderMethods(instance, options) {
|
|
|
781
784
|
frame.setAttribute("allowpaymentrequest", "true");
|
|
782
785
|
frame.setAttribute("allow", "payment");
|
|
783
786
|
frame.style.border = "none";
|
|
784
|
-
const sandbox = SANDBOX[options.tag]
|
|
787
|
+
const sandbox = (_SANDBOX$options$tag = SANDBOX[options.tag]) !== null && _SANDBOX$options$tag !== void 0 ? _SANDBOX$options$tag : "allow-scripts allow-forms allow-same-origin";
|
|
785
788
|
frame.setAttribute("sandbox", sandbox);
|
|
786
789
|
if (!lifecycleWired) {
|
|
787
790
|
wireLifecycleProps(instance.props, instance.event);
|
|
@@ -814,34 +817,40 @@ function attachRenderMethods(instance, options) {
|
|
|
814
817
|
let dataProps = {};
|
|
815
818
|
let functionNames = [];
|
|
816
819
|
try {
|
|
817
|
-
if (options.prerenderTemplate)
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
820
|
+
if (options.prerenderTemplate) {
|
|
821
|
+
var _options$dimensions;
|
|
822
|
+
placeholder = options.prerenderTemplate({
|
|
823
|
+
uid,
|
|
824
|
+
frame,
|
|
825
|
+
placeholder: void 0,
|
|
826
|
+
doc,
|
|
827
|
+
props: instance.props,
|
|
828
|
+
event: trackedEvent,
|
|
829
|
+
dimensions: (_options$dimensions = options.dimensions) !== null && _options$dimensions !== void 0 ? _options$dimensions : {
|
|
830
|
+
width: "100%",
|
|
831
|
+
height: "auto"
|
|
832
|
+
},
|
|
833
|
+
state: instance.state,
|
|
834
|
+
container: targetEl
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
if (options.containerTemplate) {
|
|
838
|
+
var _options$dimensions2;
|
|
839
|
+
containerNode = options.containerTemplate({
|
|
840
|
+
uid,
|
|
841
|
+
frame,
|
|
842
|
+
placeholder,
|
|
843
|
+
doc,
|
|
844
|
+
props: instance.props,
|
|
845
|
+
event: trackedEvent,
|
|
846
|
+
dimensions: (_options$dimensions2 = options.dimensions) !== null && _options$dimensions2 !== void 0 ? _options$dimensions2 : {
|
|
847
|
+
width: "100%",
|
|
848
|
+
height: "auto"
|
|
849
|
+
},
|
|
850
|
+
state: instance.state,
|
|
851
|
+
container: targetEl
|
|
852
|
+
});
|
|
853
|
+
}
|
|
845
854
|
({dataProps, functionNames} = buildDataPayload({
|
|
846
855
|
props: instance.props,
|
|
847
856
|
options,
|
|
@@ -865,8 +874,9 @@ function attachRenderMethods(instance, options) {
|
|
|
865
874
|
const targetOrigin = new URL(options.url).origin;
|
|
866
875
|
const sendInitialProps = () => {
|
|
867
876
|
try {
|
|
868
|
-
|
|
869
|
-
|
|
877
|
+
var _frame$contentWindow;
|
|
878
|
+
(_frame$contentWindow = frame.contentWindow) === null || _frame$contentWindow === void 0 || _frame$contentWindow.postMessage({
|
|
879
|
+
type: "__monei_bridge_init__",
|
|
870
880
|
props: dataProps,
|
|
871
881
|
functionNames
|
|
872
882
|
}, targetOrigin);
|
|
@@ -910,9 +920,10 @@ function attachRenderMethods(instance, options) {
|
|
|
910
920
|
await remote.updateProps(dataProps, functionNames);
|
|
911
921
|
if (renderState.destroyed) return;
|
|
912
922
|
if (renderState.pendingPropsUpdate) {
|
|
923
|
+
var _pending$functionName;
|
|
913
924
|
const pending = renderState.pendingPropsUpdate;
|
|
914
925
|
renderState.pendingPropsUpdate = null;
|
|
915
|
-
const retainedFns = new Set(pending.functionNames
|
|
926
|
+
const retainedFns = new Set((_pending$functionName = pending.functionNames) !== null && _pending$functionName !== void 0 ? _pending$functionName : []);
|
|
916
927
|
const flushRemovals = /* @__PURE__ */ new Map();
|
|
917
928
|
for (const key of Object.keys(pending.dataProps)) if (renderState.dispatchMap.has(key) && !retainedFns.has(key)) {
|
|
918
929
|
flushRemovals.set(key, renderState.dispatchMap.get(key));
|
|
@@ -1007,8 +1018,9 @@ function attachRenderMethods(instance, options) {
|
|
|
1007
1018
|
}
|
|
1008
1019
|
}
|
|
1009
1020
|
if (resolvedFunctionNames) {
|
|
1021
|
+
var _renderState$pendingP;
|
|
1010
1022
|
for (const name of resolvedFunctionNames) delete renderState.pendingPropsUpdate.dataProps[name];
|
|
1011
|
-
renderState.pendingPropsUpdate.functionNames = [...renderState.pendingPropsUpdate.functionNames
|
|
1023
|
+
renderState.pendingPropsUpdate.functionNames = [...(_renderState$pendingP = renderState.pendingPropsUpdate.functionNames) !== null && _renderState$pendingP !== void 0 ? _renderState$pendingP : [], ...resolvedFunctionNames];
|
|
1012
1024
|
}
|
|
1013
1025
|
}
|
|
1014
1026
|
};
|
|
@@ -1061,7 +1073,8 @@ function normalizeAliases(props, aliases) {
|
|
|
1061
1073
|
for (const [canonical, alias] of Object.entries(aliases)) reverseMap.set(alias, canonical);
|
|
1062
1074
|
const result = {};
|
|
1063
1075
|
for (const [key, value] of Object.entries(props)) {
|
|
1064
|
-
|
|
1076
|
+
var _reverseMap$get;
|
|
1077
|
+
const canonicalKey = (_reverseMap$get = reverseMap.get(key)) !== null && _reverseMap$get !== void 0 ? _reverseMap$get : key;
|
|
1065
1078
|
result[canonicalKey] = value;
|
|
1066
1079
|
}
|
|
1067
1080
|
return result;
|
|
@@ -1136,7 +1149,7 @@ function createContainerTemplate(config = {}) {
|
|
|
1136
1149
|
const div = doc.createElement("div");
|
|
1137
1150
|
div.setAttribute("id", uid);
|
|
1138
1151
|
const style = doc.createElement("style");
|
|
1139
|
-
if (props
|
|
1152
|
+
if (props === null || props === void 0 ? void 0 : props.cspNonce) style.setAttribute("nonce", props.cspNonce);
|
|
1140
1153
|
if (modal) {
|
|
1141
1154
|
const backdrop = doc.createElement("div");
|
|
1142
1155
|
backdrop.classList.add("backdrop");
|
|
@@ -1203,8 +1216,9 @@ function createContainerTemplate(config = {}) {
|
|
|
1203
1216
|
}
|
|
1204
1217
|
});
|
|
1205
1218
|
} else {
|
|
1206
|
-
|
|
1207
|
-
const
|
|
1219
|
+
var _innerStyle$base;
|
|
1220
|
+
const innerStyle = (props === null || props === void 0 ? void 0 : props.style) || (props === null || props === void 0 ? void 0 : props.innerStyle);
|
|
1221
|
+
const initialHeight = height === "0" ? "0" : toCSS((innerStyle === null || innerStyle === void 0 || (_innerStyle$base = innerStyle.base) === null || _innerStyle$base === void 0 ? void 0 : _innerStyle$base.height) || (innerStyle === null || innerStyle === void 0 ? void 0 : innerStyle.height) || (height === "auto" ? 45 : height));
|
|
1208
1222
|
const containerStyles = [
|
|
1209
1223
|
"display: block",
|
|
1210
1224
|
"position: relative",
|
|
@@ -1271,7 +1285,8 @@ const modalContainerTemplate = createContainerTemplate({ modal: true });
|
|
|
1271
1285
|
//#endregion
|
|
1272
1286
|
//#region src/card-input/index.ts
|
|
1273
1287
|
const getCreateTokenFunction = (ref) => {
|
|
1274
|
-
|
|
1288
|
+
var _ref$state;
|
|
1289
|
+
if ((_ref$state = ref.state) === null || _ref$state === void 0 ? void 0 : _ref$state.__createToken) return ref.state.__createToken;
|
|
1275
1290
|
throw new Error("Index is not registered");
|
|
1276
1291
|
};
|
|
1277
1292
|
const createToken = async (component, options) => {
|
|
@@ -1300,7 +1315,8 @@ const CardInput = createComponent({
|
|
|
1300
1315
|
} },
|
|
1301
1316
|
validate: validateComponentProps,
|
|
1302
1317
|
submit: (instance) => async (opts) => {
|
|
1303
|
-
|
|
1318
|
+
var _instance$state;
|
|
1319
|
+
const createTokenFn = (_instance$state = instance.state) === null || _instance$state === void 0 ? void 0 : _instance$state.__createToken;
|
|
1304
1320
|
if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
|
|
1305
1321
|
const { data } = await createTokenFn(opts);
|
|
1306
1322
|
return data;
|
|
@@ -1322,8 +1338,8 @@ const CardInput = createComponent({
|
|
|
1322
1338
|
div.style.height = "45px";
|
|
1323
1339
|
div.style.boxSizing = "border-box";
|
|
1324
1340
|
const style = props.style || props.innerStyle;
|
|
1325
|
-
if (style
|
|
1326
|
-
if (style
|
|
1341
|
+
if (style === null || style === void 0 ? void 0 : style.base) Object.assign(div.style, transformStyle(style.base));
|
|
1342
|
+
if (style === null || style === void 0 ? void 0 : style.loading) Object.assign(div.style, transformStyle(style.loading));
|
|
1327
1343
|
body.appendChild(div);
|
|
1328
1344
|
html.appendChild(body);
|
|
1329
1345
|
return html;
|
|
@@ -1366,7 +1382,7 @@ const confirmPayment = (params) => {
|
|
|
1366
1382
|
document.body.appendChild(rootNode);
|
|
1367
1383
|
let modal = null;
|
|
1368
1384
|
const cleanup = () => {
|
|
1369
|
-
modal
|
|
1385
|
+
modal === null || modal === void 0 || modal.destroy();
|
|
1370
1386
|
modal = null;
|
|
1371
1387
|
Object.assign(document.body.style, { overflow: bodyOverflow });
|
|
1372
1388
|
if (rootNode.parentNode) rootNode.parentNode.removeChild(rootNode);
|
|
@@ -1394,6 +1410,7 @@ const confirmPayment = (params) => {
|
|
|
1394
1410
|
//#region src/paypal/index.ts
|
|
1395
1411
|
const namespace = "monei-paypal";
|
|
1396
1412
|
const onLoadPaypal = async (props, state, src) => {
|
|
1413
|
+
var _props$style$borderRa, _props$style, _props$onLoad;
|
|
1397
1414
|
state.__scriptId = (await loadScript(src, props.cspNonce, {
|
|
1398
1415
|
namespace,
|
|
1399
1416
|
cspNonce: props.cspNonce
|
|
@@ -1403,18 +1420,19 @@ const onLoadPaypal = async (props, state, src) => {
|
|
|
1403
1420
|
tagline: false,
|
|
1404
1421
|
height: 45
|
|
1405
1422
|
};
|
|
1406
|
-
const radius = parsePx(props.style
|
|
1423
|
+
const radius = parsePx((_props$style$borderRa = (_props$style = props.style) === null || _props$style === void 0 ? void 0 : _props$style.borderRadius) !== null && _props$style$borderRa !== void 0 ? _props$style$borderRa : props.borderRadius);
|
|
1407
1424
|
if (radius) defaultStyle.borderRadius = radius;
|
|
1408
1425
|
const style = {
|
|
1409
1426
|
...defaultStyle,
|
|
1410
1427
|
...props.style
|
|
1411
1428
|
};
|
|
1412
1429
|
style.height = parsePx(style.height, 45);
|
|
1413
|
-
props.onLoad
|
|
1430
|
+
(_props$onLoad = props.onLoad) === null || _props$onLoad === void 0 || _props$onLoad.call(props, true);
|
|
1414
1431
|
let token;
|
|
1415
1432
|
await window[namespace].Buttons({
|
|
1416
1433
|
createOrder: async () => {
|
|
1417
1434
|
try {
|
|
1435
|
+
var _result$paypal;
|
|
1418
1436
|
const result = await createToken$1({
|
|
1419
1437
|
paymentId: props.paymentId,
|
|
1420
1438
|
accountId: props.accountId,
|
|
@@ -1425,15 +1443,19 @@ const onLoadPaypal = async (props, state, src) => {
|
|
|
1425
1443
|
paymentMethod: { paypal: {} }
|
|
1426
1444
|
});
|
|
1427
1445
|
({token} = result);
|
|
1428
|
-
return result.paypal
|
|
1446
|
+
return (_result$paypal = result.paypal) === null || _result$paypal === void 0 ? void 0 : _result$paypal.orderId;
|
|
1429
1447
|
} catch (error) {
|
|
1430
|
-
|
|
1448
|
+
var _props$onError;
|
|
1449
|
+
(_props$onError = props.onError) === null || _props$onError === void 0 || _props$onError.call(props, error);
|
|
1431
1450
|
return;
|
|
1432
1451
|
}
|
|
1433
1452
|
},
|
|
1434
1453
|
onApprove: function(data) {
|
|
1435
1454
|
if (data.orderID) props.onSubmit({ token });
|
|
1436
|
-
else
|
|
1455
|
+
else {
|
|
1456
|
+
var _props$onError2;
|
|
1457
|
+
(_props$onError2 = props.onError) === null || _props$onError2 === void 0 || _props$onError2.call(props, data);
|
|
1458
|
+
}
|
|
1437
1459
|
},
|
|
1438
1460
|
onClick: function(_data, actions) {
|
|
1439
1461
|
let shouldOpen = true;
|
|
@@ -1470,7 +1492,8 @@ const PayPal = createComponent({
|
|
|
1470
1492
|
if (!params.props.accountId && !params.props.paymentId) throw new Error("You need to provide paymentId or accountId");
|
|
1471
1493
|
const container = containerTemplate(params);
|
|
1472
1494
|
params.event.on(EVENT.DESTROY, () => {
|
|
1473
|
-
|
|
1495
|
+
var _namespace;
|
|
1496
|
+
(_namespace = window[namespace]) === null || _namespace === void 0 || (_namespace = _namespace.Buttons) === null || _namespace === void 0 || (_namespace = _namespace.instances) === null || _namespace === void 0 || _namespace.forEach((instance) => {
|
|
1474
1497
|
instance.close();
|
|
1475
1498
|
});
|
|
1476
1499
|
const scriptId = params.state.__scriptId;
|
package/dist/index.js
CHANGED
|
@@ -99,7 +99,8 @@ const getLanguage = () => {
|
|
|
99
99
|
};
|
|
100
100
|
const safe = (fn) => {
|
|
101
101
|
try {
|
|
102
|
-
|
|
102
|
+
var _fn;
|
|
103
|
+
return String((_fn = fn()) !== null && _fn !== void 0 ? _fn : "");
|
|
103
104
|
} catch {
|
|
104
105
|
return "";
|
|
105
106
|
}
|
|
@@ -117,7 +118,10 @@ const getClientEnv = () => {
|
|
|
117
118
|
safe(() => navigator.deviceMemory),
|
|
118
119
|
safe(() => navigator.maxTouchPoints),
|
|
119
120
|
safe(() => navigator.platform),
|
|
120
|
-
safe(() =>
|
|
121
|
+
safe(() => {
|
|
122
|
+
var _navigator$languages;
|
|
123
|
+
return (_navigator$languages = navigator.languages) === null || _navigator$languages === void 0 ? void 0 : _navigator$languages.join(",");
|
|
124
|
+
})
|
|
121
125
|
].join("|");
|
|
122
126
|
return window.btoa(env);
|
|
123
127
|
};
|
|
@@ -150,8 +154,9 @@ const getPersistentSeed = async () => {
|
|
|
150
154
|
const thumbmark = new Thumbmark({ logging: false });
|
|
151
155
|
thumbmark.includeComponent("persistent_seed", getPersistentSeed);
|
|
152
156
|
const getClientFingerprint = async () => {
|
|
157
|
+
var _result$thumbmark;
|
|
153
158
|
const [, result] = await withError(thumbmark.get());
|
|
154
|
-
return result
|
|
159
|
+
return (_result$thumbmark = result === null || result === void 0 ? void 0 : result.thumbmark) !== null && _result$thumbmark !== void 0 ? _result$thumbmark : "";
|
|
155
160
|
};
|
|
156
161
|
const withError = async (p) => {
|
|
157
162
|
try {
|
|
@@ -501,6 +506,7 @@ function createVue3Driver(ComponentClass) {
|
|
|
501
506
|
*/
|
|
502
507
|
function createAngularDriver(ComponentClass) {
|
|
503
508
|
return ({ Component: AngularComponent, NgModule, ElementRef, NgZone, Inject }) => {
|
|
509
|
+
var _options;
|
|
504
510
|
class ComponentInstance {
|
|
505
511
|
constructor(elementRef, zone) {
|
|
506
512
|
this.props = {};
|
|
@@ -537,7 +543,7 @@ function createAngularDriver(ComponentClass) {
|
|
|
537
543
|
}
|
|
538
544
|
ComponentInstance.parameters = [[new Inject(ElementRef)], [new Inject(NgZone)]];
|
|
539
545
|
ComponentInstance.annotations = [new AngularComponent({
|
|
540
|
-
selector: ComponentClass.prototype.__options
|
|
546
|
+
selector: ((_options = ComponentClass.prototype.__options) === null || _options === void 0 ? void 0 : _options.tag) || "bridge-component",
|
|
541
547
|
template: "<div></div>",
|
|
542
548
|
inputs: ["props"]
|
|
543
549
|
})];
|
|
@@ -573,10 +579,6 @@ function resolveDriver(name, ComponentClass, deps) {
|
|
|
573
579
|
return factory(ComponentClass)(deps);
|
|
574
580
|
}
|
|
575
581
|
//#endregion
|
|
576
|
-
//#region ../shared/lib/bridge-constants.ts
|
|
577
|
-
/** Protocol identifier for sync bootstrap messages between parent and child bridges */
|
|
578
|
-
const BRIDGE_INIT_MSG = "__monei_bridge_init__";
|
|
579
|
-
//#endregion
|
|
580
582
|
//#region src/bridge/constants.ts
|
|
581
583
|
/** Bridge lifecycle events (replaces zoid.EVENT) */
|
|
582
584
|
const EVENT = {
|
|
@@ -758,6 +760,7 @@ function attachRenderMethods(instance, options) {
|
|
|
758
760
|
* 8. createConnection — establish Penpal async RPC channel, deliver props via updateProps
|
|
759
761
|
*/
|
|
760
762
|
instance.render = async (container) => {
|
|
763
|
+
var _SANDBOX$options$tag;
|
|
761
764
|
if (renderState.destroyed) throw new Error("Component is destroyed");
|
|
762
765
|
if (renderState.frame) throw new Error("Component already rendered");
|
|
763
766
|
const targetEl = resolveContainer(container);
|
|
@@ -769,7 +772,7 @@ function attachRenderMethods(instance, options) {
|
|
|
769
772
|
frame.setAttribute("allowpaymentrequest", "true");
|
|
770
773
|
frame.setAttribute("allow", "payment");
|
|
771
774
|
frame.style.border = "none";
|
|
772
|
-
const sandbox = SANDBOX[options.tag]
|
|
775
|
+
const sandbox = (_SANDBOX$options$tag = SANDBOX[options.tag]) !== null && _SANDBOX$options$tag !== void 0 ? _SANDBOX$options$tag : "allow-scripts allow-forms allow-same-origin";
|
|
773
776
|
frame.setAttribute("sandbox", sandbox);
|
|
774
777
|
if (!lifecycleWired) {
|
|
775
778
|
wireLifecycleProps(instance.props, instance.event);
|
|
@@ -802,34 +805,40 @@ function attachRenderMethods(instance, options) {
|
|
|
802
805
|
let dataProps = {};
|
|
803
806
|
let functionNames = [];
|
|
804
807
|
try {
|
|
805
|
-
if (options.prerenderTemplate)
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
808
|
+
if (options.prerenderTemplate) {
|
|
809
|
+
var _options$dimensions;
|
|
810
|
+
placeholder = options.prerenderTemplate({
|
|
811
|
+
uid,
|
|
812
|
+
frame,
|
|
813
|
+
placeholder: void 0,
|
|
814
|
+
doc,
|
|
815
|
+
props: instance.props,
|
|
816
|
+
event: trackedEvent,
|
|
817
|
+
dimensions: (_options$dimensions = options.dimensions) !== null && _options$dimensions !== void 0 ? _options$dimensions : {
|
|
818
|
+
width: "100%",
|
|
819
|
+
height: "auto"
|
|
820
|
+
},
|
|
821
|
+
state: instance.state,
|
|
822
|
+
container: targetEl
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (options.containerTemplate) {
|
|
826
|
+
var _options$dimensions2;
|
|
827
|
+
containerNode = options.containerTemplate({
|
|
828
|
+
uid,
|
|
829
|
+
frame,
|
|
830
|
+
placeholder,
|
|
831
|
+
doc,
|
|
832
|
+
props: instance.props,
|
|
833
|
+
event: trackedEvent,
|
|
834
|
+
dimensions: (_options$dimensions2 = options.dimensions) !== null && _options$dimensions2 !== void 0 ? _options$dimensions2 : {
|
|
835
|
+
width: "100%",
|
|
836
|
+
height: "auto"
|
|
837
|
+
},
|
|
838
|
+
state: instance.state,
|
|
839
|
+
container: targetEl
|
|
840
|
+
});
|
|
841
|
+
}
|
|
833
842
|
({dataProps, functionNames} = buildDataPayload({
|
|
834
843
|
props: instance.props,
|
|
835
844
|
options,
|
|
@@ -853,8 +862,9 @@ function attachRenderMethods(instance, options) {
|
|
|
853
862
|
const targetOrigin = new URL(options.url).origin;
|
|
854
863
|
const sendInitialProps = () => {
|
|
855
864
|
try {
|
|
856
|
-
|
|
857
|
-
|
|
865
|
+
var _frame$contentWindow;
|
|
866
|
+
(_frame$contentWindow = frame.contentWindow) === null || _frame$contentWindow === void 0 || _frame$contentWindow.postMessage({
|
|
867
|
+
type: "__monei_bridge_init__",
|
|
858
868
|
props: dataProps,
|
|
859
869
|
functionNames
|
|
860
870
|
}, targetOrigin);
|
|
@@ -898,9 +908,10 @@ function attachRenderMethods(instance, options) {
|
|
|
898
908
|
await remote.updateProps(dataProps, functionNames);
|
|
899
909
|
if (renderState.destroyed) return;
|
|
900
910
|
if (renderState.pendingPropsUpdate) {
|
|
911
|
+
var _pending$functionName;
|
|
901
912
|
const pending = renderState.pendingPropsUpdate;
|
|
902
913
|
renderState.pendingPropsUpdate = null;
|
|
903
|
-
const retainedFns = new Set(pending.functionNames
|
|
914
|
+
const retainedFns = new Set((_pending$functionName = pending.functionNames) !== null && _pending$functionName !== void 0 ? _pending$functionName : []);
|
|
904
915
|
const flushRemovals = /* @__PURE__ */ new Map();
|
|
905
916
|
for (const key of Object.keys(pending.dataProps)) if (renderState.dispatchMap.has(key) && !retainedFns.has(key)) {
|
|
906
917
|
flushRemovals.set(key, renderState.dispatchMap.get(key));
|
|
@@ -995,8 +1006,9 @@ function attachRenderMethods(instance, options) {
|
|
|
995
1006
|
}
|
|
996
1007
|
}
|
|
997
1008
|
if (resolvedFunctionNames) {
|
|
1009
|
+
var _renderState$pendingP;
|
|
998
1010
|
for (const name of resolvedFunctionNames) delete renderState.pendingPropsUpdate.dataProps[name];
|
|
999
|
-
renderState.pendingPropsUpdate.functionNames = [...renderState.pendingPropsUpdate.functionNames
|
|
1011
|
+
renderState.pendingPropsUpdate.functionNames = [...(_renderState$pendingP = renderState.pendingPropsUpdate.functionNames) !== null && _renderState$pendingP !== void 0 ? _renderState$pendingP : [], ...resolvedFunctionNames];
|
|
1000
1012
|
}
|
|
1001
1013
|
}
|
|
1002
1014
|
};
|
|
@@ -1049,7 +1061,8 @@ function normalizeAliases(props, aliases) {
|
|
|
1049
1061
|
for (const [canonical, alias] of Object.entries(aliases)) reverseMap.set(alias, canonical);
|
|
1050
1062
|
const result = {};
|
|
1051
1063
|
for (const [key, value] of Object.entries(props)) {
|
|
1052
|
-
|
|
1064
|
+
var _reverseMap$get;
|
|
1065
|
+
const canonicalKey = (_reverseMap$get = reverseMap.get(key)) !== null && _reverseMap$get !== void 0 ? _reverseMap$get : key;
|
|
1053
1066
|
result[canonicalKey] = value;
|
|
1054
1067
|
}
|
|
1055
1068
|
return result;
|
|
@@ -1124,7 +1137,7 @@ function createContainerTemplate(config = {}) {
|
|
|
1124
1137
|
const div = doc.createElement("div");
|
|
1125
1138
|
div.setAttribute("id", uid);
|
|
1126
1139
|
const style = doc.createElement("style");
|
|
1127
|
-
if (props
|
|
1140
|
+
if (props === null || props === void 0 ? void 0 : props.cspNonce) style.setAttribute("nonce", props.cspNonce);
|
|
1128
1141
|
if (modal) {
|
|
1129
1142
|
const backdrop = doc.createElement("div");
|
|
1130
1143
|
backdrop.classList.add("backdrop");
|
|
@@ -1191,8 +1204,9 @@ function createContainerTemplate(config = {}) {
|
|
|
1191
1204
|
}
|
|
1192
1205
|
});
|
|
1193
1206
|
} else {
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1207
|
+
var _innerStyle$base;
|
|
1208
|
+
const innerStyle = (props === null || props === void 0 ? void 0 : props.style) || (props === null || props === void 0 ? void 0 : props.innerStyle);
|
|
1209
|
+
const initialHeight = height === "0" ? "0" : toCSS((innerStyle === null || innerStyle === void 0 || (_innerStyle$base = innerStyle.base) === null || _innerStyle$base === void 0 ? void 0 : _innerStyle$base.height) || (innerStyle === null || innerStyle === void 0 ? void 0 : innerStyle.height) || (height === "auto" ? 45 : height));
|
|
1196
1210
|
const containerStyles = [
|
|
1197
1211
|
"display: block",
|
|
1198
1212
|
"position: relative",
|
|
@@ -1259,7 +1273,8 @@ const modalContainerTemplate = createContainerTemplate({ modal: true });
|
|
|
1259
1273
|
//#endregion
|
|
1260
1274
|
//#region src/card-input/index.ts
|
|
1261
1275
|
const getCreateTokenFunction = (ref) => {
|
|
1262
|
-
|
|
1276
|
+
var _ref$state;
|
|
1277
|
+
if ((_ref$state = ref.state) === null || _ref$state === void 0 ? void 0 : _ref$state.__createToken) return ref.state.__createToken;
|
|
1263
1278
|
throw new Error("Index is not registered");
|
|
1264
1279
|
};
|
|
1265
1280
|
const createToken = async (component, options) => {
|
|
@@ -1288,7 +1303,8 @@ const CardInput = createComponent({
|
|
|
1288
1303
|
} },
|
|
1289
1304
|
validate: validateComponentProps,
|
|
1290
1305
|
submit: (instance) => async (opts) => {
|
|
1291
|
-
|
|
1306
|
+
var _instance$state;
|
|
1307
|
+
const createTokenFn = (_instance$state = instance.state) === null || _instance$state === void 0 ? void 0 : _instance$state.__createToken;
|
|
1292
1308
|
if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
|
|
1293
1309
|
const { data } = await createTokenFn(opts);
|
|
1294
1310
|
return data;
|
|
@@ -1310,8 +1326,8 @@ const CardInput = createComponent({
|
|
|
1310
1326
|
div.style.height = "45px";
|
|
1311
1327
|
div.style.boxSizing = "border-box";
|
|
1312
1328
|
const style = props.style || props.innerStyle;
|
|
1313
|
-
if (style
|
|
1314
|
-
if (style
|
|
1329
|
+
if (style === null || style === void 0 ? void 0 : style.base) Object.assign(div.style, transformStyle(style.base));
|
|
1330
|
+
if (style === null || style === void 0 ? void 0 : style.loading) Object.assign(div.style, transformStyle(style.loading));
|
|
1315
1331
|
body.appendChild(div);
|
|
1316
1332
|
html.appendChild(body);
|
|
1317
1333
|
return html;
|
|
@@ -1354,7 +1370,7 @@ const confirmPayment = (params) => {
|
|
|
1354
1370
|
document.body.appendChild(rootNode);
|
|
1355
1371
|
let modal = null;
|
|
1356
1372
|
const cleanup = () => {
|
|
1357
|
-
modal
|
|
1373
|
+
modal === null || modal === void 0 || modal.destroy();
|
|
1358
1374
|
modal = null;
|
|
1359
1375
|
Object.assign(document.body.style, { overflow: bodyOverflow });
|
|
1360
1376
|
if (rootNode.parentNode) rootNode.parentNode.removeChild(rootNode);
|
|
@@ -1382,6 +1398,7 @@ const confirmPayment = (params) => {
|
|
|
1382
1398
|
//#region src/paypal/index.ts
|
|
1383
1399
|
const namespace = "monei-paypal";
|
|
1384
1400
|
const onLoadPaypal = async (props, state, src) => {
|
|
1401
|
+
var _props$style$borderRa, _props$style, _props$onLoad;
|
|
1385
1402
|
state.__scriptId = (await loadScript(src, props.cspNonce, {
|
|
1386
1403
|
namespace,
|
|
1387
1404
|
cspNonce: props.cspNonce
|
|
@@ -1391,18 +1408,19 @@ const onLoadPaypal = async (props, state, src) => {
|
|
|
1391
1408
|
tagline: false,
|
|
1392
1409
|
height: 45
|
|
1393
1410
|
};
|
|
1394
|
-
const radius = parsePx(props.style
|
|
1411
|
+
const radius = parsePx((_props$style$borderRa = (_props$style = props.style) === null || _props$style === void 0 ? void 0 : _props$style.borderRadius) !== null && _props$style$borderRa !== void 0 ? _props$style$borderRa : props.borderRadius);
|
|
1395
1412
|
if (radius) defaultStyle.borderRadius = radius;
|
|
1396
1413
|
const style = {
|
|
1397
1414
|
...defaultStyle,
|
|
1398
1415
|
...props.style
|
|
1399
1416
|
};
|
|
1400
1417
|
style.height = parsePx(style.height, 45);
|
|
1401
|
-
props.onLoad
|
|
1418
|
+
(_props$onLoad = props.onLoad) === null || _props$onLoad === void 0 || _props$onLoad.call(props, true);
|
|
1402
1419
|
let token;
|
|
1403
1420
|
await window[namespace].Buttons({
|
|
1404
1421
|
createOrder: async () => {
|
|
1405
1422
|
try {
|
|
1423
|
+
var _result$paypal;
|
|
1406
1424
|
const result = await createToken$1({
|
|
1407
1425
|
paymentId: props.paymentId,
|
|
1408
1426
|
accountId: props.accountId,
|
|
@@ -1413,15 +1431,19 @@ const onLoadPaypal = async (props, state, src) => {
|
|
|
1413
1431
|
paymentMethod: { paypal: {} }
|
|
1414
1432
|
});
|
|
1415
1433
|
({token} = result);
|
|
1416
|
-
return result.paypal
|
|
1434
|
+
return (_result$paypal = result.paypal) === null || _result$paypal === void 0 ? void 0 : _result$paypal.orderId;
|
|
1417
1435
|
} catch (error) {
|
|
1418
|
-
|
|
1436
|
+
var _props$onError;
|
|
1437
|
+
(_props$onError = props.onError) === null || _props$onError === void 0 || _props$onError.call(props, error);
|
|
1419
1438
|
return;
|
|
1420
1439
|
}
|
|
1421
1440
|
},
|
|
1422
1441
|
onApprove: function(data) {
|
|
1423
1442
|
if (data.orderID) props.onSubmit({ token });
|
|
1424
|
-
else
|
|
1443
|
+
else {
|
|
1444
|
+
var _props$onError2;
|
|
1445
|
+
(_props$onError2 = props.onError) === null || _props$onError2 === void 0 || _props$onError2.call(props, data);
|
|
1446
|
+
}
|
|
1425
1447
|
},
|
|
1426
1448
|
onClick: function(_data, actions) {
|
|
1427
1449
|
let shouldOpen = true;
|
|
@@ -1458,7 +1480,8 @@ const PayPal = createComponent({
|
|
|
1458
1480
|
if (!params.props.accountId && !params.props.paymentId) throw new Error("You need to provide paymentId or accountId");
|
|
1459
1481
|
const container = containerTemplate(params);
|
|
1460
1482
|
params.event.on(EVENT.DESTROY, () => {
|
|
1461
|
-
|
|
1483
|
+
var _namespace;
|
|
1484
|
+
(_namespace = window[namespace]) === null || _namespace === void 0 || (_namespace = _namespace.Buttons) === null || _namespace === void 0 || (_namespace = _namespace.instances) === null || _namespace === void 0 || _namespace.forEach((instance) => {
|
|
1462
1485
|
instance.close();
|
|
1463
1486
|
});
|
|
1464
1487
|
const scriptId = params.state.__scriptId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monei-js/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"author": "MONEI <support@monei.com> (https://monei.com)",
|
|
5
5
|
"description": "MONEI UI Components enable you to collect sensitive payment information using customizable UI components.",
|
|
6
6
|
"homepage": "https://monei.com",
|