@alipay/ams-checkout 0.0.1779094014-dev.0 → 0.0.1779094014-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/ams-checkout.js +4 -3
- package/dist/ams-checkout.min.js +2 -1
- package/dist/ams-checkout.min.js.map +1 -0
- package/esm/constant/element.d.ts +2 -1
- package/esm/constant/element.js +1 -0
- package/esm/core/component/element/elementController/index.d.ts +3 -3
- package/esm/core/component/element/index.d.ts +1 -1
- package/esm/core/component/element/index.js +11 -1
- package/esm/core/component/element/modernElementController/adapter.d.ts +19 -0
- package/esm/core/component/element/modernElementController/adapter.js +74 -0
- package/esm/core/component/element/modernElementController/index.d.ts +80 -0
- package/esm/core/component/element/modernElementController/index.js +679 -0
- package/esm/core/component/element/type.d.ts +10 -0
- package/esm/foundation/service/event-center.js +1 -1
- package/esm/modern/index.js +1 -1
- package/esm/modern/oneapi/iexpfront/PaymentSessionService.d.ts +23 -0
- package/esm/modern/oneapi/iexpfront/PaymentSessionService.js +55 -0
- package/esm/modern/oneapi/iexpfront/definitions.d.ts +3656 -0
- package/esm/modern/oneapi/iexpfront/definitions.js +1 -0
- package/esm/modern/tools/AntomSDKError.d.ts +47 -0
- package/esm/modern/tools/AntomSDKError.js +47 -0
- package/esm/modern/tools/buildPageUrl.d.ts +4 -0
- package/esm/modern/tools/buildPageUrl.js +19 -0
- package/esm/modern/tools/getDevReqConfig.d.ts +2 -0
- package/esm/modern/tools/getDevReqConfig.js +16 -0
- package/esm/modern/tools/getLocaleFromRenderData.d.ts +6 -0
- package/esm/modern/tools/getLocaleFromRenderData.js +20 -0
- package/esm/modern/tools/getMetaData.d.ts +102 -0
- package/esm/modern/tools/getMetaData.js +7 -0
- package/esm/modern/tools/openModal.d.ts +20 -0
- package/esm/modern/tools/openModal.js +221 -0
- package/esm/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/types.d.ts +2 -149
- package/types.untrimmed.d.ts +2 -152
- package/esm/modern/stageName.d.ts +0 -3
- package/esm/modern/stageName.js +0 -1
|
@@ -22,5 +22,6 @@ export declare enum ELEMENT_PAGE_URL {
|
|
|
22
22
|
INSTRUCTION_GUIDE = "/elements/pages/instruction-guide/index.html",
|
|
23
23
|
THREED_PAGE = "/elements/pages/threed-page/index.html",
|
|
24
24
|
ELEMENT_AUTH = "/auth-element/pages/element_auth/index.html",
|
|
25
|
-
ADDRESS = "/element-address/pages/address/index.html"
|
|
25
|
+
ADDRESS = "/element-address/pages/address/index.html",
|
|
26
|
+
NEW_ELEMENT_PAYMENT = "/elements2/pages/element_payment/index.html"
|
|
26
27
|
}
|
package/esm/constant/element.js
CHANGED
|
@@ -26,5 +26,6 @@ export var ELEMENT_PAGE_URL = /*#__PURE__*/function (ELEMENT_PAGE_URL) {
|
|
|
26
26
|
ELEMENT_PAGE_URL["THREED_PAGE"] = "/elements/pages/threed-page/index.html";
|
|
27
27
|
ELEMENT_PAGE_URL["ELEMENT_AUTH"] = "/auth-element/pages/element_auth/index.html";
|
|
28
28
|
ELEMENT_PAGE_URL["ADDRESS"] = "/element-address/pages/address/index.html";
|
|
29
|
+
ELEMENT_PAGE_URL["NEW_ELEMENT_PAYMENT"] = "/elements2/pages/element_payment/index.html";
|
|
29
30
|
return ELEMENT_PAGE_URL;
|
|
30
31
|
}({});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
|
|
2
|
-
declare class ElementController {
|
|
1
|
+
import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementController, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
|
|
2
|
+
declare class ElementController implements IElementController {
|
|
3
3
|
private options;
|
|
4
4
|
private elementContainer;
|
|
5
5
|
private serviceMap;
|
|
@@ -42,7 +42,7 @@ declare class ElementController {
|
|
|
42
42
|
private getErrorFromResponse;
|
|
43
43
|
private areAllContainersReady;
|
|
44
44
|
private sendReady;
|
|
45
|
-
updatePayment(paymentSessionData:
|
|
45
|
+
updatePayment(paymentSessionData: string): Promise<boolean>;
|
|
46
46
|
private destroyHandle;
|
|
47
47
|
destroy(): void;
|
|
48
48
|
private setControllerStatusOrView;
|
|
@@ -3,7 +3,7 @@ export declare class ElementComponent {
|
|
|
3
3
|
private options;
|
|
4
4
|
private controller;
|
|
5
5
|
constructor(options: IElementOptions);
|
|
6
|
-
updatePayment(paymentSessionData: any): Promise<
|
|
6
|
+
updatePayment(paymentSessionData: any): Promise<boolean>;
|
|
7
7
|
mount(renderOptions: PaymentMountOptions, sdkSelector: string): Promise<import("./type").ICommonApiResponse>;
|
|
8
8
|
validateFields(): Promise<{
|
|
9
9
|
isValid: boolean;
|
|
@@ -10,7 +10,9 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
10
10
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import { getMetaData } from "../../../modern/tools/getMetaData";
|
|
13
14
|
import ElementController from "./elementController";
|
|
15
|
+
import { ModernElementController } from "./modernElementController";
|
|
14
16
|
import { InvalidElementConfigError } from "./type";
|
|
15
17
|
import { formatElementOption, validateElementOption } from "./util";
|
|
16
18
|
export var ElementComponent = /*#__PURE__*/function () {
|
|
@@ -23,7 +25,15 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
|
23
25
|
throw new InvalidElementConfigError(validate.errors);
|
|
24
26
|
}
|
|
25
27
|
this.options = formatElementOption(options);
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
// 核心分流逻辑
|
|
30
|
+
var parseData = getMetaData(options.sessionData);
|
|
31
|
+
if (parseData !== null && parseData !== void 0 && parseData.modernWeb) {
|
|
32
|
+
console.log('新payment');
|
|
33
|
+
this.controller = new ModernElementController(this.options);
|
|
34
|
+
} else {
|
|
35
|
+
this.controller = new ElementController(this.options);
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
38
|
_createClass(ElementComponent, [{
|
|
29
39
|
key: "updatePayment",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorPayload } from '@antintl/opensdk-core';
|
|
2
|
+
import type { IPaymentApiResponse } from '../type';
|
|
3
|
+
import { EventCallbackCode } from '../type';
|
|
4
|
+
import type { SubmitResult } from "../../../../modern/sdk/types";
|
|
5
|
+
export declare function adaptSubmitResult(result: SubmitResult): IPaymentApiResponse;
|
|
6
|
+
export declare function adaptErrorToEventCallback(error: ErrorPayload): {
|
|
7
|
+
code: EventCallbackCode;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 将老架构的 appearance 格式转换为新架构格式
|
|
12
|
+
*
|
|
13
|
+
* 转换规则:
|
|
14
|
+
* 1. theme: kebab-case → camelCase(如 'nostalgic-gray' → 'nostalgicGray'),其余保持不变
|
|
15
|
+
* 2. variables: 直接透传(kebab-case CSS 变量 key-value)
|
|
16
|
+
* 3. card.showBrandIcon → displaySetting.showCardBrandIcon
|
|
17
|
+
* 4. layout: 直接透传
|
|
18
|
+
*/
|
|
19
|
+
export declare function adaptAppearance(appearance?: any): any;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
7
|
+
import { EventCallbackCode } from "../type";
|
|
8
|
+
export function adaptSubmitResult(result) {
|
|
9
|
+
return {
|
|
10
|
+
status: result.status || 'FAIL',
|
|
11
|
+
error: result.status === 'FAIL' || result.code ? {
|
|
12
|
+
code: result.code || 'UNKNOWN_ERROR',
|
|
13
|
+
message: result.message || ''
|
|
14
|
+
} : undefined,
|
|
15
|
+
userCanceled3D: result.userCanceled3D
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function adaptErrorToEventCallback(error) {
|
|
19
|
+
return {
|
|
20
|
+
code: error.code || EventCallbackCode.SDK_PAYMENT_ERROR,
|
|
21
|
+
message: error.message || ''
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 老架构 theme (kebab-case) → 新架构 theme (camelCase) 映射表
|
|
27
|
+
*/
|
|
28
|
+
var THEME_MAP = {
|
|
29
|
+
'nostalgic-gray': 'nostalgicGray',
|
|
30
|
+
'cherry-blossom-pink': 'cherryBlossomPink',
|
|
31
|
+
'gaming-purple': 'gamingPurple',
|
|
32
|
+
'agate-green': 'agateGreen'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 将老架构的 appearance 格式转换为新架构格式
|
|
37
|
+
*
|
|
38
|
+
* 转换规则:
|
|
39
|
+
* 1. theme: kebab-case → camelCase(如 'nostalgic-gray' → 'nostalgicGray'),其余保持不变
|
|
40
|
+
* 2. variables: 直接透传(kebab-case CSS 变量 key-value)
|
|
41
|
+
* 3. card.showBrandIcon → displaySetting.showCardBrandIcon
|
|
42
|
+
* 4. layout: 直接透传
|
|
43
|
+
*/
|
|
44
|
+
export function adaptAppearance(appearance) {
|
|
45
|
+
var _appearance$card;
|
|
46
|
+
if (!appearance) return undefined;
|
|
47
|
+
var result = {};
|
|
48
|
+
|
|
49
|
+
// Theme mapping: kebab-case → camelCase
|
|
50
|
+
if (appearance.theme) {
|
|
51
|
+
result.theme = THEME_MAP[appearance.theme] || appearance.theme;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Variables: 直接透传
|
|
55
|
+
if (appearance.variables && _typeof(appearance.variables) === 'object') {
|
|
56
|
+
var filtered = _objectSpread({}, appearance.variables);
|
|
57
|
+
if (Object.keys(filtered).length > 0) {
|
|
58
|
+
result.variables = filtered;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// card.showBrandIcon → displaySetting.showCardBrandIcon
|
|
63
|
+
if (((_appearance$card = appearance.card) === null || _appearance$card === void 0 ? void 0 : _appearance$card.showBrandIcon) !== undefined) {
|
|
64
|
+
result.displaySetting = {
|
|
65
|
+
showCardBrandIcon: appearance.card.showBrandIcon
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Layout: 直接透传
|
|
70
|
+
if (appearance.layout) {
|
|
71
|
+
result.layout = _objectSpread({}, appearance.layout);
|
|
72
|
+
}
|
|
73
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
74
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IElementController, IElementOptions, ICommonApiResponse, IPaymentApiResponse, PaymentMountOptions, SubmitFuncParams, EVENTNAME, EventDataMap } from '../type';
|
|
2
|
+
/**
|
|
3
|
+
* ModernElementController 使用 opensdk-core 的 HostBridge 实现新架构通信。
|
|
4
|
+
*
|
|
5
|
+
* Mount 流程(正确):
|
|
6
|
+
* 1. setup() — 解析 sessionData 获取 metaData,准备 HANDSHAKE 配置
|
|
7
|
+
* 2. 创建 iframe,设置 src
|
|
8
|
+
* 3. 将 iframe 添加到容器
|
|
9
|
+
* 4. 监听 READY_HANDSHAKE → setTarget(iframe.contentWindow) → send(HANDSHAKE, mergedConfig)
|
|
10
|
+
* 5. 等待 HANDSHAKE_ACK → 设置 status = 'ready'
|
|
11
|
+
* 6. ready 后发送缓存的消息
|
|
12
|
+
*/
|
|
13
|
+
export declare class ModernElementController implements IElementController {
|
|
14
|
+
private options;
|
|
15
|
+
private bridge;
|
|
16
|
+
private iframe;
|
|
17
|
+
private status;
|
|
18
|
+
private eventListeners;
|
|
19
|
+
private cachedSend;
|
|
20
|
+
private modalIframe;
|
|
21
|
+
private modalBridge;
|
|
22
|
+
private modalDestroy;
|
|
23
|
+
private _closeConfirmResolve;
|
|
24
|
+
constructor(options: IElementOptions);
|
|
25
|
+
mount(renderOptions: PaymentMountOptions, sdkSelector: string): Promise<ICommonApiResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* setup() — 解析 sessionData 获取 metaData,发起 sdkQuery 获取渲染数据,准备 HANDSHAKE 配置
|
|
28
|
+
*
|
|
29
|
+
* 完整实现:
|
|
30
|
+
* 1. 解析 sessionData 获取 paymentSessionConfig
|
|
31
|
+
* 2. 初始化 request 全局配置(hostSign, env, sdkVersion)
|
|
32
|
+
* 3. 调用 sdkQuery 获取 renderData
|
|
33
|
+
* 4. 处理请求错误,将错误信息放入 renderDataError(不阻塞 mount 流程)
|
|
34
|
+
* 5. 从 renderData 中提取 preferredLocale
|
|
35
|
+
*/
|
|
36
|
+
private setup;
|
|
37
|
+
/**
|
|
38
|
+
* 执行握手流程:
|
|
39
|
+
* - 监听 READY_HANDSHAKE → setTarget → send(HANDSHAKE, mergedConfig)
|
|
40
|
+
* - 等待 HANDSHAKE_ACK → resolve
|
|
41
|
+
*/
|
|
42
|
+
private performHandshake;
|
|
43
|
+
/**
|
|
44
|
+
* 绑定持续监听的 bridge 事件
|
|
45
|
+
*/
|
|
46
|
+
private bindBridgeEvents;
|
|
47
|
+
submitPayment(params: SubmitFuncParams): Promise<IPaymentApiResponse>;
|
|
48
|
+
validateFields(): Promise<{
|
|
49
|
+
isValid: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
updatePayment(paymentSessionData: string): Promise<boolean>;
|
|
52
|
+
on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
private cleanup;
|
|
55
|
+
/**
|
|
56
|
+
* 带缓存的消息发送:当 status 不是 ready 时,缓存消息;ready 后由 flushCachedMessages 批量发送
|
|
57
|
+
*/
|
|
58
|
+
private send;
|
|
59
|
+
/**
|
|
60
|
+
* 批量发送缓存的消息
|
|
61
|
+
*/
|
|
62
|
+
private flushCachedMessages;
|
|
63
|
+
/**
|
|
64
|
+
* 处理 webapp 请求打开 modal 弹窗
|
|
65
|
+
*
|
|
66
|
+
* 流程(参照 BaseFactory 桥接流程):
|
|
67
|
+
* 1. 调用 openModal 工具函数创建 modal DOM(overlay + modal + iframe + 动画 + close icon + loading)
|
|
68
|
+
* 2. 为 modal 创建独立的 HostBridge 用于通信
|
|
69
|
+
* 3. iframe 加载后 setTarget 到 modal iframe 的 contentWindow
|
|
70
|
+
* 4. 监听 modal 的 READY_HANDSHAKE → 发送配置消息
|
|
71
|
+
* 5. 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送
|
|
72
|
+
* 6. 如果 payload 有 closeConfirm,创建 MessageChannel port 用于确认关闭
|
|
73
|
+
*/
|
|
74
|
+
private handleOpenModal;
|
|
75
|
+
/**
|
|
76
|
+
* 销毁 modal bridge、调用 openModal 返回的 destroy 方法清理 modal DOM
|
|
77
|
+
*/
|
|
78
|
+
private handleCloseModal;
|
|
79
|
+
private buildIframeUrl;
|
|
80
|
+
}
|