@alipay/ams-checkout 0.0.1788166152-dev.2 → 0.0.1788166152-dev.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.
@@ -0,0 +1,53 @@
1
+ declare const PRECONNECTION_REGIONS: readonly ["SG", "US", "DE"];
2
+ export type PreconnectionRegion = (typeof PRECONNECTION_REGIONS)[number];
3
+ export type GatewayPreconnectionStatus = 'running' | 'completed' | 'partial_failed' | 'failed';
4
+ type RegionResult = {
5
+ status: 'completed' | 'failed';
6
+ endTime: number;
7
+ };
8
+ export interface GatewayPreconnectionSnapshot {
9
+ mode: 'configured' | 'regional';
10
+ preconnectedRegions: readonly PreconnectionRegion[];
11
+ failedRegions: PreconnectionRegion[];
12
+ regionResults: Partial<Record<PreconnectionRegion, RegionResult>>;
13
+ gatewayUrl?: string;
14
+ actualRegion?: string;
15
+ predictionResult?: 'hit' | 'miss';
16
+ status: GatewayPreconnectionStatus;
17
+ preconnectionStartTime: number;
18
+ preconnectionEndTime?: number;
19
+ firstRpcStartTime?: number;
20
+ firstRpcEndTime?: number;
21
+ firstRpcTotalMs?: number;
22
+ preconnectionLeadTimeMs?: number;
23
+ preconnectionReadyBeforeFirstRpc?: boolean;
24
+ dnsDurationMs?: number;
25
+ tcpDurationMs?: number;
26
+ tlsDurationMs?: number;
27
+ }
28
+ export declare function startGatewayPreconnection(env: 'sandbox' | 'prod'): Promise<GatewayPreconnectionSnapshot>;
29
+ export declare function recordActualRegion(region: string, env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
30
+ export declare function recordFirstRpcStart(env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
31
+ export declare function recordFirstRpcEnd(env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
32
+ export declare function getGatewayPreconnectionSnapshot(env?: 'sandbox' | 'prod'): {
33
+ mode: "configured" | "regional";
34
+ preconnectedRegions: readonly PreconnectionRegion[];
35
+ failedRegions: PreconnectionRegion[];
36
+ regionResults: Partial<Record<PreconnectionRegion, RegionResult>>;
37
+ gatewayUrl?: string;
38
+ actualRegion?: string;
39
+ predictionResult?: "hit" | "miss";
40
+ status: GatewayPreconnectionStatus;
41
+ preconnectionStartTime: number;
42
+ preconnectionEndTime?: number;
43
+ firstRpcStartTime?: number;
44
+ firstRpcEndTime?: number;
45
+ firstRpcTotalMs?: number;
46
+ preconnectionLeadTimeMs?: number;
47
+ preconnectionReadyBeforeFirstRpc?: boolean;
48
+ dnsDurationMs?: number;
49
+ tcpDurationMs?: number;
50
+ tlsDurationMs?: number;
51
+ };
52
+ export declare function waitForGatewayPreconnection(env?: 'sandbox' | 'prod'): Promise<GatewayPreconnectionSnapshot>;
53
+ export {};
@@ -2,7 +2,7 @@ import type { AntomPreloadElement } from './config';
2
2
  export declare function preloadAntomElements(elements: readonly AntomPreloadElement[]): Promise<void>;
3
3
  export declare function getAntomPreloadTelemetry(element: AntomPreloadElement): {
4
4
  requested: boolean;
5
- phaseAtElementCreate: "resolving" | "failed" | "critical_completed" | "skipped" | "not_requested" | "running";
5
+ phaseAtElementCreate: "running" | "failed" | "resolving" | "critical_completed" | "skipped" | "not_requested";
6
6
  leadTimeMs: number;
7
7
  criticalDurationMs: number;
8
8
  taskId: string;
@@ -1,3 +1,6 @@
1
- import type { RequestOptions } from '@antintl/antom-toolset';
2
- /** Warm up the selected gateway without carrying payment-session data. */
3
- export declare function preConnection(payload?: Record<string, never>, extraParams?: Pick<RequestOptions, 'env' | 'hostSign' | 'timeout' | 'withCredentials'>): Promise<Record<string, unknown>>;
1
+ import { type RequestOptions } from '@antintl/antom-toolset';
2
+ /** Warm up the gateway selected by the shared request configuration. */
3
+ export declare function preConnection(payload?: Record<string, never>, extraParams?: RequestOptions): Promise<Record<string, unknown> & {
4
+ traceId?: string;
5
+ errorMessage?: string;
6
+ }>;
@@ -2,4 +2,4 @@ import type { AntomPreloadElement } from '../../preload/config';
2
2
  import type { PreloadTelemetryContext } from '../types';
3
3
  export declare function trackPreloadAtElementCreate(element: AntomPreloadElement, sessionData: string | undefined, env: 'sandbox' | 'prod'): void;
4
4
  export declare function getPreloadTelemetryContext(element: AntomPreloadElement, env: 'sandbox' | 'prod'): PreloadTelemetryContext;
5
- export declare function trackSgPreconnectionAtFirstRpcEnd(env: 'sandbox' | 'prod'): void;
5
+ export declare function trackGatewayPreconnectionAtFirstRpcEnd(env: 'sandbox' | 'prod'): void;
@@ -17,10 +17,11 @@ export interface PreloadTelemetryContext {
17
17
  leadTimeMs?: number;
18
18
  criticalDurationMs?: number;
19
19
  taskId?: string;
20
- predictedRegion?: 'SG';
20
+ preconnectedRegions?: readonly ('SG' | 'US' | 'DE')[];
21
+ preconnectionMode?: 'configured' | 'regional';
21
22
  actualRegion?: string;
22
23
  predictionResult?: 'hit' | 'miss';
23
- preconnectionStatus?: 'running' | 'completed' | 'failed';
24
+ preconnectionStatus?: 'running' | 'completed' | 'partial_failed' | 'failed';
24
25
  preconnectionLeadTimeMs?: number;
25
26
  preconnectionReadyBeforeFirstRpc?: boolean;
26
27
  }
@@ -16,6 +16,9 @@ export function getAntomPreloadRuntimeConfig() {
16
16
  }, {
17
17
  origin: 'https://marmot-local-pre.oss-accelerate.aliyuncs.com',
18
18
  pathnamePrefix: '/page/antom-web-checkout-v2/elements2/'
19
+ }, {
20
+ origin: 'https://marmot-local-dev.oss-accelerate.aliyuncs.com',
21
+ pathnamePrefix: '/page/antom-web-checkout-v2-'
19
22
  }]
20
23
  };
21
24
  }
@@ -0,0 +1,53 @@
1
+ declare const PRECONNECTION_REGIONS: readonly ["SG", "US", "DE"];
2
+ export type PreconnectionRegion = (typeof PRECONNECTION_REGIONS)[number];
3
+ export type GatewayPreconnectionStatus = 'running' | 'completed' | 'partial_failed' | 'failed';
4
+ type RegionResult = {
5
+ status: 'completed' | 'failed';
6
+ endTime: number;
7
+ };
8
+ export interface GatewayPreconnectionSnapshot {
9
+ mode: 'configured' | 'regional';
10
+ preconnectedRegions: readonly PreconnectionRegion[];
11
+ failedRegions: PreconnectionRegion[];
12
+ regionResults: Partial<Record<PreconnectionRegion, RegionResult>>;
13
+ gatewayUrl?: string;
14
+ actualRegion?: string;
15
+ predictionResult?: 'hit' | 'miss';
16
+ status: GatewayPreconnectionStatus;
17
+ preconnectionStartTime: number;
18
+ preconnectionEndTime?: number;
19
+ firstRpcStartTime?: number;
20
+ firstRpcEndTime?: number;
21
+ firstRpcTotalMs?: number;
22
+ preconnectionLeadTimeMs?: number;
23
+ preconnectionReadyBeforeFirstRpc?: boolean;
24
+ dnsDurationMs?: number;
25
+ tcpDurationMs?: number;
26
+ tlsDurationMs?: number;
27
+ }
28
+ export declare function startGatewayPreconnection(env: 'sandbox' | 'prod'): Promise<GatewayPreconnectionSnapshot>;
29
+ export declare function recordActualRegion(region: string, env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
30
+ export declare function recordFirstRpcStart(env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
31
+ export declare function recordFirstRpcEnd(env?: 'sandbox' | 'prod'): GatewayPreconnectionSnapshot | undefined;
32
+ export declare function getGatewayPreconnectionSnapshot(env?: 'sandbox' | 'prod'): {
33
+ mode: "configured" | "regional";
34
+ preconnectedRegions: readonly ("US" | "SG" | "DE")[];
35
+ failedRegions: ("US" | "SG" | "DE")[];
36
+ regionResults: Partial<Record<"US" | "SG" | "DE", RegionResult>>;
37
+ gatewayUrl?: string;
38
+ actualRegion?: string;
39
+ predictionResult?: "hit" | "miss";
40
+ status: GatewayPreconnectionStatus;
41
+ preconnectionStartTime: number;
42
+ preconnectionEndTime?: number;
43
+ firstRpcStartTime?: number;
44
+ firstRpcEndTime?: number;
45
+ firstRpcTotalMs?: number;
46
+ preconnectionLeadTimeMs?: number;
47
+ preconnectionReadyBeforeFirstRpc?: boolean;
48
+ dnsDurationMs?: number;
49
+ tcpDurationMs?: number;
50
+ tlsDurationMs?: number;
51
+ };
52
+ export declare function waitForGatewayPreconnection(env?: 'sandbox' | 'prod'): Promise<GatewayPreconnectionSnapshot>;
53
+ export {};
@@ -0,0 +1,213 @@
1
+ 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); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ 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); }
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
16
+ import { preConnection } from "../sdk/oneapi/iexpfront/preConnection";
17
+ import { getDevReqConfig } from "../sdk/tools/getDevReqConfig";
18
+ var REGISTRY_SYMBOL = Symbol.for('@antom/web-sdk.gateway-preconnection.v1');
19
+ var PRECONNECTION_REGIONS = ['SG', 'US', 'DE'];
20
+ function getRegistry() {
21
+ var _globalObject$REGISTR;
22
+ var globalObject = globalThis;
23
+ (_globalObject$REGISTR = globalObject[REGISTRY_SYMBOL]) !== null && _globalObject$REGISTR !== void 0 ? _globalObject$REGISTR : globalObject[REGISTRY_SYMBOL] = {
24
+ snapshots: new Map(),
25
+ promises: new Map()
26
+ };
27
+ return globalObject[REGISTRY_SYMBOL];
28
+ }
29
+ export function startGatewayPreconnection(env) {
30
+ var registry = getRegistry();
31
+ var existing = registry.promises.get(env);
32
+ if (existing) return existing;
33
+ var snapshot = {
34
+ mode: 'regional',
35
+ preconnectedRegions: PRECONNECTION_REGIONS,
36
+ failedRegions: [],
37
+ regionResults: {},
38
+ status: 'running',
39
+ preconnectionStartTime: now()
40
+ };
41
+ registry.snapshots.set(env, snapshot);
42
+ var promise = Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
43
+ var devRequestConfig, gatewayUrl, results, status;
44
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
45
+ while (1) switch (_context.prev = _context.next) {
46
+ case 0:
47
+ if (!(typeof window === 'undefined' || typeof navigator === 'undefined' || typeof screen === 'undefined')) {
48
+ _context.next = 2;
49
+ break;
50
+ }
51
+ throw new Error('Gateway preConnection is unavailable outside the browser');
52
+ case 2:
53
+ devRequestConfig = getDevReqConfig();
54
+ gatewayUrl = devRequestConfig === null || devRequestConfig === void 0 ? void 0 : devRequestConfig.baseURL;
55
+ if (!gatewayUrl) {
56
+ _context.next = 11;
57
+ break;
58
+ }
59
+ snapshot.mode = 'configured';
60
+ snapshot.preconnectedRegions = [];
61
+ snapshot.gatewayUrl = gatewayUrl;
62
+ _context.next = 10;
63
+ return preConnection({}, _objectSpread({
64
+ env: env,
65
+ timeout: 5000,
66
+ withCredentials: true
67
+ }, devRequestConfig));
68
+ case 10:
69
+ return _context.abrupt("return", finishPreconnection(env, 'completed'));
70
+ case 11:
71
+ _context.next = 13;
72
+ return Promise.allSettled(PRECONNECTION_REGIONS.map(function (hostSign) {
73
+ return warmRegion(env, hostSign, snapshot);
74
+ }));
75
+ case 13:
76
+ results = _context.sent;
77
+ snapshot.failedRegions = PRECONNECTION_REGIONS.filter(function (_, index) {
78
+ return results[index].status === 'rejected';
79
+ });
80
+ status = resolveRegionalStatus(snapshot.failedRegions.length);
81
+ return _context.abrupt("return", finishPreconnection(env, status));
82
+ case 17:
83
+ case "end":
84
+ return _context.stop();
85
+ }
86
+ }, _callee);
87
+ }))).catch(function () {
88
+ return finishPreconnection(env, 'failed');
89
+ });
90
+ registry.promises.set(env, promise);
91
+ return promise;
92
+ }
93
+ export function recordActualRegion(region) {
94
+ var env = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'prod';
95
+ var snapshot = getRegistry().snapshots.get(env);
96
+ if (!snapshot) return undefined;
97
+ snapshot.actualRegion = region || undefined;
98
+ updatePredictionResult(snapshot);
99
+ updateLeadTime(snapshot);
100
+ return _objectSpread({}, snapshot);
101
+ }
102
+ export function recordFirstRpcStart() {
103
+ var _snapshot$firstRpcSta;
104
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
105
+ var snapshot = getRegistry().snapshots.get(env);
106
+ if (!snapshot) return undefined;
107
+ (_snapshot$firstRpcSta = snapshot.firstRpcStartTime) !== null && _snapshot$firstRpcSta !== void 0 ? _snapshot$firstRpcSta : snapshot.firstRpcStartTime = now();
108
+ updateLeadTime(snapshot);
109
+ return _objectSpread({}, snapshot);
110
+ }
111
+ export function recordFirstRpcEnd() {
112
+ var _snapshot$firstRpcEnd;
113
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
114
+ var snapshot = getRegistry().snapshots.get(env);
115
+ if (!snapshot || snapshot.firstRpcStartTime === undefined) return snapshot ? _objectSpread({}, snapshot) : undefined;
116
+ (_snapshot$firstRpcEnd = snapshot.firstRpcEndTime) !== null && _snapshot$firstRpcEnd !== void 0 ? _snapshot$firstRpcEnd : snapshot.firstRpcEndTime = now();
117
+ snapshot.firstRpcTotalMs = snapshot.firstRpcEndTime - snapshot.firstRpcStartTime;
118
+ return _objectSpread({}, snapshot);
119
+ }
120
+ export function getGatewayPreconnectionSnapshot() {
121
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
122
+ var snapshot = getRegistry().snapshots.get(env);
123
+ return snapshot ? _objectSpread({}, snapshot) : undefined;
124
+ }
125
+ export function waitForGatewayPreconnection() {
126
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
127
+ return getRegistry().promises.get(env);
128
+ }
129
+ function resolveRegionalStatus(failedCount) {
130
+ if (failedCount === 0) return 'completed';
131
+ if (failedCount === PRECONNECTION_REGIONS.length) return 'failed';
132
+ return 'partial_failed';
133
+ }
134
+ function finishPreconnection(env, status) {
135
+ var snapshot = getRegistry().snapshots.get(env);
136
+ snapshot.status = status;
137
+ snapshot.preconnectionEndTime = now();
138
+ updatePredictionResult(snapshot);
139
+ updateLeadTime(snapshot);
140
+ Object.assign(snapshot, readGatewayResourceTiming(snapshot.gatewayUrl));
141
+ return _objectSpread({}, snapshot);
142
+ }
143
+ function warmRegion(env, hostSign, snapshot) {
144
+ return preConnection({}, {
145
+ env: env,
146
+ hostSign: hostSign,
147
+ timeout: 5000,
148
+ withCredentials: true
149
+ }).then(function (result) {
150
+ snapshot.regionResults[hostSign] = {
151
+ status: 'completed',
152
+ endTime: now()
153
+ };
154
+ updatePredictionResult(snapshot);
155
+ updateLeadTime(snapshot);
156
+ return result;
157
+ }, function (error) {
158
+ snapshot.regionResults[hostSign] = {
159
+ status: 'failed',
160
+ endTime: now()
161
+ };
162
+ updatePredictionResult(snapshot);
163
+ updateLeadTime(snapshot);
164
+ throw error;
165
+ });
166
+ }
167
+ function updatePredictionResult(snapshot) {
168
+ if (!snapshot.actualRegion) {
169
+ snapshot.predictionResult = undefined;
170
+ return;
171
+ }
172
+ if (snapshot.mode === 'configured') {
173
+ snapshot.predictionResult = snapshot.status === 'running' ? undefined : snapshot.status === 'completed' ? 'hit' : 'miss';
174
+ return;
175
+ }
176
+ var actualRegion = snapshot.actualRegion;
177
+ var result = snapshot.regionResults[actualRegion];
178
+ snapshot.predictionResult = result ? result.status === 'completed' ? 'hit' : 'miss' : undefined;
179
+ }
180
+ function updateLeadTime(snapshot) {
181
+ var _snapshot$regionResul, _snapshot$regionResul2;
182
+ if (snapshot.firstRpcStartTime === undefined) return;
183
+ var targetEndTime = snapshot.mode === 'configured' ? snapshot.status === 'completed' ? snapshot.preconnectionEndTime : undefined : snapshot.actualRegion ? ((_snapshot$regionResul = snapshot.regionResults[snapshot.actualRegion]) === null || _snapshot$regionResul === void 0 ? void 0 : _snapshot$regionResul.status) === 'completed' ? (_snapshot$regionResul2 = snapshot.regionResults[snapshot.actualRegion]) === null || _snapshot$regionResul2 === void 0 ? void 0 : _snapshot$regionResul2.endTime : undefined : undefined;
184
+ if (targetEndTime === undefined) {
185
+ snapshot.preconnectionLeadTimeMs = undefined;
186
+ snapshot.preconnectionReadyBeforeFirstRpc = false;
187
+ return;
188
+ }
189
+ snapshot.preconnectionLeadTimeMs = snapshot.firstRpcStartTime - targetEndTime;
190
+ snapshot.preconnectionReadyBeforeFirstRpc = snapshot.preconnectionLeadTimeMs >= 0;
191
+ }
192
+ function readGatewayResourceTiming(gatewayUrl) {
193
+ if (!gatewayUrl || typeof performance === 'undefined' || !performance.getEntriesByType) return {};
194
+ var gatewayOrigin;
195
+ try {
196
+ gatewayOrigin = new URL(gatewayUrl).origin;
197
+ } catch (_unused) {
198
+ return {};
199
+ }
200
+ var entries = performance.getEntriesByType('resource');
201
+ var timing = _toConsumableArray(entries).reverse().find(function (entry) {
202
+ return entry.name.startsWith(gatewayOrigin);
203
+ });
204
+ if (!timing) return {};
205
+ return {
206
+ dnsDurationMs: Math.max(0, timing.domainLookupEnd - timing.domainLookupStart),
207
+ tcpDurationMs: Math.max(0, timing.connectEnd - timing.connectStart),
208
+ tlsDurationMs: timing.secureConnectionStart > 0 ? Math.max(0, timing.connectEnd - timing.secureConnectionStart) : 0
209
+ };
210
+ }
211
+ function now() {
212
+ return Date.now();
213
+ }
@@ -2,7 +2,7 @@ import type { AntomPreloadElement } from './config';
2
2
  export declare function preloadAntomElements(elements: readonly AntomPreloadElement[]): Promise<void>;
3
3
  export declare function getAntomPreloadTelemetry(element: AntomPreloadElement): {
4
4
  requested: boolean;
5
- phaseAtElementCreate: "running" | "failed" | "skipped" | "not_requested" | "resolving" | "critical_completed";
5
+ phaseAtElementCreate: "running" | "failed" | "resolving" | "critical_completed" | "skipped" | "not_requested";
6
6
  leadTimeMs: number;
7
7
  criticalDurationMs: number;
8
8
  taskId: string;
@@ -1,8 +1,8 @@
1
+ import { startGatewayPreconnection } from "./gatewayPreconnection";
1
2
  import { preloadAntomElements } from "./preloadAntomElements";
2
- import { startDefaultSgPreconnection } from "./sgPreconnection";
3
3
  export function startAntomPreload(env, elements) {
4
4
  if (!(elements !== null && elements !== void 0 && elements.length)) return;
5
- void startDefaultSgPreconnection(env);
5
+ void startGatewayPreconnection(env);
6
6
  void preloadAntomElements(elements).catch(function () {
7
7
  return undefined;
8
8
  });