@alipay/ams-checkout 0.0.1697942541-dev.1 → 0.0.1697942541-dev.2
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/umd/ams-checkout.min.js +1 -1
- package/esm/constant/index.d.ts +9 -0
- package/esm/constant/index.js +9 -0
- package/esm/plugin/component/index.d.ts +4 -1
- package/esm/plugin/component/index.js +55 -10
- package/esm/plugin/component/popupWindow.style.d.ts +6 -1
- package/esm/plugin/component/popupWindow.style.js +18 -9
- package/esm/types/index.d.ts +7 -0
- package/package.json +1 -1
package/esm/constant/index.d.ts
CHANGED
@@ -140,6 +140,15 @@ export declare const EVENT: {
|
|
140
140
|
dismissLoading: {
|
141
141
|
name: string;
|
142
142
|
};
|
143
|
+
popupWindow: {
|
144
|
+
name: string;
|
145
|
+
};
|
146
|
+
closePopup: {
|
147
|
+
name: string;
|
148
|
+
};
|
149
|
+
threedReady: {
|
150
|
+
name: string;
|
151
|
+
};
|
143
152
|
};
|
144
153
|
export declare const COMPONENT_CONTAINER_ID = "ams-component-container";
|
145
154
|
export declare const COMPONENT_SECTION_ID = "ams-component-section";
|
package/esm/constant/index.js
CHANGED
@@ -139,6 +139,15 @@ export var EVENT = {
|
|
139
139
|
},
|
140
140
|
dismissLoading: {
|
141
141
|
name: 'dismissLoading'
|
142
|
+
},
|
143
|
+
popupWindow: {
|
144
|
+
name: 'popupWindow'
|
145
|
+
},
|
146
|
+
closePopup: {
|
147
|
+
name: 'closePopup'
|
148
|
+
},
|
149
|
+
threedReady: {
|
150
|
+
name: 'threedReady'
|
142
151
|
}
|
143
152
|
};
|
144
153
|
export var COMPONENT_CONTAINER_ID = 'ams-component-container';
|
@@ -9,6 +9,8 @@ export default class ComponentApp {
|
|
9
9
|
_performanceData: any[];
|
10
10
|
_loadAppPromiseResolve: ((value: boolean) => void) | null;
|
11
11
|
_isInitComponent: boolean;
|
12
|
+
private _threedData?;
|
13
|
+
private popupWindow?;
|
12
14
|
private appDomain;
|
13
15
|
private createIframeNode;
|
14
16
|
private _selector;
|
@@ -51,6 +53,7 @@ export default class ComponentApp {
|
|
51
53
|
private createApp;
|
52
54
|
private listener;
|
53
55
|
private resizeListener;
|
56
|
+
private createPopupWindow;
|
54
57
|
/**
|
55
58
|
* @description Initialize subscription iframe message
|
56
59
|
*/
|
@@ -73,7 +76,7 @@ export default class ComponentApp {
|
|
73
76
|
*/
|
74
77
|
dispatchToApp(payload: {
|
75
78
|
context: eventPayloadContext;
|
76
|
-
}): any;
|
79
|
+
}, element?: any): any;
|
77
80
|
/**
|
78
81
|
* @description Subscribe to messages from SDK
|
79
82
|
*/
|
@@ -16,16 +16,18 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
16
16
|
*/
|
17
17
|
/* eslint-disable no-console */
|
18
18
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
19
|
+
import APDID from '@alipay/jshield-apdid';
|
20
|
+
import { marmptMap } from "../../config/index";
|
19
21
|
import { COMPONENTPLUGINID, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID } from "../../constant";
|
20
22
|
import { queryPaymentInfo } from "../../service";
|
21
23
|
import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, renderDisplayTypeEnum, targetEnum } from "../../types";
|
22
24
|
import { getType, isJsonString, isPC, queryParse } from "../../util";
|
23
25
|
import { isLocalMock } from "../../util/mock";
|
26
|
+
import { getAppname, getSecurityHost } from "../../util/security";
|
24
27
|
import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
|
25
28
|
import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
|
26
29
|
import { addPopupLoading, createBaseElement, createMockup, createRetentionPopup, handleDeclareInfo as _handleDeclareInfo, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup } from "./component.popup.style";
|
27
|
-
import
|
28
|
-
import { getSecurityHost, getAppname } from "../../util/security";
|
30
|
+
import { createModal, insertStyleSheet, destroyModal } from "./popupWindow.style";
|
29
31
|
var _ref = queryParse() || {},
|
30
32
|
preinit = _ref.preinit,
|
31
33
|
rebuild = _ref.rebuild,
|
@@ -41,6 +43,8 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
41
43
|
_defineProperty(this, "_performanceData", []);
|
42
44
|
_defineProperty(this, "_loadAppPromiseResolve", null);
|
43
45
|
_defineProperty(this, "_isInitComponent", void 0);
|
46
|
+
_defineProperty(this, "_threedData", void 0);
|
47
|
+
_defineProperty(this, "popupWindow", void 0);
|
44
48
|
_defineProperty(this, "appDomain", void 0);
|
45
49
|
_defineProperty(this, "createIframeNode", void 0);
|
46
50
|
_defineProperty(this, "_selector", void 0);
|
@@ -113,7 +117,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
113
117
|
APDID.initToken(appName, {
|
114
118
|
host: h5gateway
|
115
119
|
}, function (success, tokenResult, msg) {
|
116
|
-
console.log(
|
120
|
+
console.log('initToken result tokenResult', JSON.stringify(tokenResult));
|
117
121
|
});
|
118
122
|
}
|
119
123
|
|
@@ -145,6 +149,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
145
149
|
if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
|
146
150
|
var container = createInlineBaseElement(this._selector);
|
147
151
|
if (container) this.renderInlineLoading(renderParams, container);
|
152
|
+
insertStyleSheet();
|
148
153
|
}
|
149
154
|
if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
|
150
155
|
createBaseElement(this.platform, this.closeBtnFunc.bind(this));
|
@@ -302,6 +307,11 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
302
307
|
resolve(res);
|
303
308
|
}
|
304
309
|
}).catch(function (err) {
|
310
|
+
if (componentSignEnum.EASY_PAY_WALLET === _this3._componentSign) {
|
311
|
+
return resolve({
|
312
|
+
success: false
|
313
|
+
});
|
314
|
+
}
|
305
315
|
_this3.dispatchToSDK(EVENT.error.name, {
|
306
316
|
code: ERRORMESSAGE.CREATECOMPONENT_ERROR.code
|
307
317
|
});
|
@@ -423,6 +433,19 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
423
433
|
}
|
424
434
|
});
|
425
435
|
}
|
436
|
+
}, {
|
437
|
+
key: "createPopupWindow",
|
438
|
+
value: function createPopupWindow(data) {
|
439
|
+
var _this$_renderParams2;
|
440
|
+
this._threedData = data;
|
441
|
+
var sessionData = encodeURIComponent((_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.sessionData);
|
442
|
+
// const threedPageUrl = `http://192.168.1.5:5173/src/component-app/threedPage/demo.html?scene=threedWrapperPage&sessionData=${sessionData}&instanceId=${this.AMSSDK._instanceId}`
|
443
|
+
var threedPageUrl = "".concat(marmptMap[this.AMSSDK.options.env.environment], "/threedPage/index.html?scene=threedWrapperPage&sessionData=").concat(sessionData, "&instanceId=").concat(this.AMSSDK._instanceId);
|
444
|
+
this.popupWindow = createModal({
|
445
|
+
device: this.platform,
|
446
|
+
url: threedPageUrl
|
447
|
+
});
|
448
|
+
}
|
426
449
|
|
427
450
|
/**
|
428
451
|
* @description Initialize subscription iframe message
|
@@ -449,10 +472,28 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
449
472
|
}, {
|
450
473
|
key: "_handleAppMessage",
|
451
474
|
value: function _handleAppMessage(data) {
|
452
|
-
var eventKeyMap = [EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, EVENT.log.name, EVENT.close.name, EVENT.error.name, EVENT.eventCallback.name, EVENT.submitForm.name, EVENT.showCloseButton.name, EVENT.hideCloseButton.name, EVENT.setAllowRetention.name, EVENT.declareCheckoutInfo.name, EVENT.showPopup.name, EVENT.dismissLoading.name];
|
475
|
+
var eventKeyMap = [EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, EVENT.log.name, EVENT.close.name, EVENT.error.name, EVENT.eventCallback.name, EVENT.submitForm.name, EVENT.showCloseButton.name, EVENT.hideCloseButton.name, EVENT.setAllowRetention.name, EVENT.declareCheckoutInfo.name, EVENT.showPopup.name, EVENT.dismissLoading.name, EVENT.popupWindow.name, EVENT.threedReady.name, EVENT.closePopup.name];
|
453
476
|
if (!eventKeyMap.includes(data.context.event)) {
|
454
477
|
return;
|
455
478
|
}
|
479
|
+
if (data.context.event === EVENT.closePopup.name) {
|
480
|
+
destroyModal();
|
481
|
+
return;
|
482
|
+
}
|
483
|
+
if (data.context.event === EVENT.threedReady.name) {
|
484
|
+
this.dispatchToApp({
|
485
|
+
context: {
|
486
|
+
event: 'renderThreedPage',
|
487
|
+
data: this._threedData
|
488
|
+
}
|
489
|
+
}, this.popupWindow);
|
490
|
+
return;
|
491
|
+
}
|
492
|
+
if (data.context.event === EVENT.popupWindow.name) {
|
493
|
+
var _data$context;
|
494
|
+
this.createPopupWindow((_data$context = data.context) === null || _data$context === void 0 ? void 0 : _data$context.data);
|
495
|
+
return;
|
496
|
+
}
|
456
497
|
if (data.context.event === EVENT.dismissLoading.name) {
|
457
498
|
var _data$context$data;
|
458
499
|
this.dispatchToSDK(EVENT.eventCallback.name, {
|
@@ -643,12 +684,16 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
643
684
|
}, {
|
644
685
|
key: "dispatchToApp",
|
645
686
|
value: function dispatchToApp(payload) {
|
687
|
+
var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
646
688
|
var data = Object.assign({}, payload, {
|
647
689
|
name: messageName.SDK_TO_APP,
|
648
690
|
mode: this.AMSSDK.options.mode,
|
649
691
|
appId: COMPONENTPLUGINID,
|
650
692
|
instanceId: this.AMSSDK._instanceId
|
651
693
|
});
|
694
|
+
if (element && element.contentWindow) {
|
695
|
+
return element.contentWindow.postMessage(JSON.stringify(data), '*');
|
696
|
+
}
|
652
697
|
if (this.app && this.app.contentWindow) {
|
653
698
|
return this.app.contentWindow.postMessage(JSON.stringify(data), this.appDomain);
|
654
699
|
}
|
@@ -677,7 +722,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
677
722
|
key: "sendRenderEvent",
|
678
723
|
value: function () {
|
679
724
|
var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
680
|
-
var _this$
|
725
|
+
var _this$_renderParams3, _this$_renderParams4, _this$_renderParams5, _this$_renderParams6, _this$_renderParams7, res;
|
681
726
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
682
727
|
while (1) switch (_context.prev = _context.next) {
|
683
728
|
case 0:
|
@@ -701,12 +746,12 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
701
746
|
event: 'renderComponent',
|
702
747
|
data: {
|
703
748
|
queryResult: res,
|
704
|
-
sessionResult: (_this$
|
705
|
-
paymentSessionData: (_this$
|
749
|
+
sessionResult: (_this$_renderParams3 = this._renderParams) === null || _this$_renderParams3 === void 0 ? void 0 : _this$_renderParams3.paymentSessionMetaData,
|
750
|
+
paymentSessionData: (_this$_renderParams4 = this._renderParams) === null || _this$_renderParams4 === void 0 ? void 0 : _this$_renderParams4.sessionData,
|
706
751
|
heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
|
707
|
-
renderDisplayType: (_this$
|
708
|
-
appearance: (_this$
|
709
|
-
notRedirectAfterComplete: ((_this$
|
752
|
+
renderDisplayType: (_this$_renderParams5 = this._renderParams) === null || _this$_renderParams5 === void 0 ? void 0 : _this$_renderParams5.renderDisplayType,
|
753
|
+
appearance: (_this$_renderParams6 = this._renderParams) === null || _this$_renderParams6 === void 0 ? void 0 : _this$_renderParams6.appearance,
|
754
|
+
notRedirectAfterComplete: ((_this$_renderParams7 = this._renderParams) === null || _this$_renderParams7 === void 0 ? void 0 : _this$_renderParams7.notRedirectAfterComplete) === true,
|
710
755
|
envInfo: {
|
711
756
|
screenHeight: screen.height,
|
712
757
|
screenWidth: screen.width
|
@@ -1,33 +1,45 @@
|
|
1
1
|
import { AMSPOPUP_PREFIX, ANIMATION_TIME } from "../../constant";
|
2
2
|
|
3
3
|
// CSS样式字符串
|
4
|
-
var modalStyles = "\n .".concat(AMSPOPUP_PREFIX, "modal {\n /* \u6DFB\u52A0\u5F39\u7A97\u6837\u5F0F */\n
|
4
|
+
var modalStyles = "\n .".concat(AMSPOPUP_PREFIX, "modal {\n /* \u6DFB\u52A0\u5F39\u7A97\u6837\u5F0F */\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 9999; /* \u8BBE\u7F6E\u5F39\u7A97\u7684\u5C42\u7EA7\u4E3A 9999 */\n }\n\n .").concat(AMSPOPUP_PREFIX, "overlay {\n /* \u6DFB\u52A0\u8499\u5C42\u6837\u5F0F */\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.4);\n z-index: 999;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeIn {\n /* \u6DFB\u52A0\u6DE1\u5165\u52A8\u753B */\n animation: fadeIn ").concat(ANIMATION_TIME, "ms;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeOut {\n /* \u6DFB\u52A0\u6DE1\u51FA\u52A8\u753B */\n animation: fadeOut ").concat(ANIMATION_TIME, "ms;\n }\n\n /* \u5B9A\u4E49\u6DE1\u5165\u52A8\u753B */\n @keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n /* \u5B9A\u4E49\u6DE1\u51FA\u52A8\u753B */\n @keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n");
|
5
5
|
|
6
6
|
// 创建和插入样式表
|
7
|
-
var insertStyleSheet = function insertStyleSheet() {
|
7
|
+
export var insertStyleSheet = function insertStyleSheet() {
|
8
8
|
var style = document.createElement('style');
|
9
9
|
style.innerHTML = modalStyles;
|
10
10
|
document.head.appendChild(style);
|
11
11
|
};
|
12
12
|
|
13
13
|
// 插入弹窗
|
14
|
-
var createModal = function createModal() {
|
14
|
+
export var createModal = function createModal(_ref) {
|
15
|
+
var device = _ref.device,
|
16
|
+
url = _ref.url;
|
15
17
|
var overlay = document.createElement('div');
|
16
18
|
overlay.classList.add("".concat(AMSPOPUP_PREFIX, "overlay"), "".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
17
19
|
var modal = document.createElement('div');
|
18
20
|
modal.classList.add("".concat(AMSPOPUP_PREFIX, "modal"), "".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
21
|
+
if (device === 'desktop') {
|
22
|
+
modal.style.width = '600px';
|
23
|
+
modal.style.height = '464px';
|
24
|
+
modal.style.borderRadius = '12px';
|
25
|
+
} else {
|
26
|
+
modal.style.width = 'calc(100% - 16px)';
|
27
|
+
modal.style.height = '80%';
|
28
|
+
modal.style.borderRadius = '8px';
|
29
|
+
}
|
19
30
|
var iframe = document.createElement('iframe');
|
20
|
-
iframe.src =
|
31
|
+
iframe.src = url; // 替换为实际的 URL 地址
|
21
32
|
iframe.style.border = 'none';
|
22
33
|
iframe.style.width = '100%';
|
23
34
|
iframe.style.height = '100%';
|
24
35
|
modal.appendChild(iframe);
|
25
36
|
document.body.appendChild(overlay);
|
26
37
|
document.body.appendChild(modal);
|
38
|
+
return iframe;
|
27
39
|
};
|
28
40
|
|
29
41
|
// 销毁弹窗
|
30
|
-
var destroyModal = function destroyModal() {
|
42
|
+
export var destroyModal = function destroyModal() {
|
31
43
|
var overlay = document.querySelector(".".concat(AMSPOPUP_PREFIX, "overlay"));
|
32
44
|
var modal = document.querySelector(".".concat(AMSPOPUP_PREFIX, "modal"));
|
33
45
|
overlay.classList.remove("".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
@@ -38,7 +50,4 @@ var destroyModal = function destroyModal() {
|
|
38
50
|
overlay.parentNode.removeChild(overlay);
|
39
51
|
modal.parentNode.removeChild(modal);
|
40
52
|
}, ANIMATION_TIME);
|
41
|
-
};
|
42
|
-
|
43
|
-
// 在插入弹窗之前先插入样式表
|
44
|
-
insertStyleSheet();
|
53
|
+
};
|
package/esm/types/index.d.ts
CHANGED
@@ -286,6 +286,13 @@ export declare enum eventCodeEnum {
|
|
286
286
|
SDK_CALL_URL_ERROR = "SDK_CALL_URL_ERROR",
|
287
287
|
SDK_CALL_URL_SUCCESS = "SDK_CALL_URL_SUCCESS"
|
288
288
|
}
|
289
|
+
export interface ThreedData {
|
290
|
+
data: any;
|
291
|
+
method: string;
|
292
|
+
targetUrl: string;
|
293
|
+
pti?: number;
|
294
|
+
pt?: number;
|
295
|
+
}
|
289
296
|
declare global {
|
290
297
|
interface Window {
|
291
298
|
[key: string]: any;
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@alipay/ams-checkout","version":"0.0.1697942541-dev.
|
1
|
+
{"name":"@alipay/ams-checkout","version":"0.0.1697942541-dev.2","description":"","author":"","main":"esm/index.js","module":"esm/index.js","typings":"esm/index.d.ts","files":["dist","esm","LEGAL.md","LICENSE","README.md"],"scripts":{"build":"father build","ci":"npm run lint","cov":"jest --coverage","format":"prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"","lint":"eslint ./src","test":"jest"},"dependencies":{"axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@alipay/jshield-apdid":"^2.0.3","@babel/core":"^7.20.7","@babel/preset-env":"^7.20.2","@testing-library/jest-dom":"^5.1.1","@testing-library/react":"^9.5.0","@types/jest":"^29.2.4","@types/uuid":"^9.0.0","@typescript-eslint/eslint-plugin":"latest","@typescript-eslint/parser":"^5.60.0","babel-jest":"^29.3.1","babel-loader":"^9.1.0","babel-plugin-import":"^1.13.0","eslint":"^8.36.0","eslint-plugin-prettier":"latest","father":"^4.2.3","jest":"^29.5.0","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.4","prettier-plugin-organize-imports":"^3.2.3","prettier-plugin-packagejson":"^2.4.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.5"},"engines":{},"publishConfig":{"access":"public"}}
|