@getpara/core-sdk 3.0.0-alpha.1 → 3.1.0

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.
Files changed (106) hide show
  1. package/dist/cjs/ParaCore.js +436 -86
  2. package/dist/cjs/constants.js +1 -1
  3. package/dist/cjs/cryptography/utils.js +5 -2
  4. package/dist/cjs/errors.js +10 -0
  5. package/dist/cjs/external/userManagementClient.js +21 -4
  6. package/dist/cjs/index.js +67 -1
  7. package/dist/cjs/services/AuthService.js +66 -47
  8. package/dist/cjs/services/LoginFlowService.js +30 -27
  9. package/dist/cjs/services/PollingService.js +100 -75
  10. package/dist/cjs/services/PortalUrlService.js +112 -19
  11. package/dist/cjs/services/PregenWalletService.js +125 -76
  12. package/dist/cjs/services/SessionManagementService.js +81 -10
  13. package/dist/cjs/services/SignupFlowService.js +52 -47
  14. package/dist/cjs/services/VerificationFlowService.js +13 -10
  15. package/dist/cjs/services/WalletService.js +51 -36
  16. package/dist/cjs/shares/enclave.js +44 -24
  17. package/dist/cjs/state/CoreStateManager.js +17 -5
  18. package/dist/cjs/state/actors/setupPara.js +4 -1
  19. package/dist/cjs/state/machines/walletStateMachine.js +22 -0
  20. package/dist/cjs/telemetry/BeaconSpanProcessor.js +99 -0
  21. package/dist/cjs/telemetry/config.js +15 -0
  22. package/dist/cjs/telemetry/init.js +193 -0
  23. package/dist/cjs/telemetry/modalSession.js +54 -0
  24. package/dist/cjs/telemetry/session.js +39 -0
  25. package/dist/cjs/telemetry/tracer.js +126 -0
  26. package/dist/cjs/telemetry/uxAction.js +30 -0
  27. package/dist/cjs/telemetry/uxBaggagePropagator.js +58 -0
  28. package/dist/cjs/telemetry/uxState.js +46 -0
  29. package/dist/cjs/telemetry/uxStateSpanProcessor.js +51 -0
  30. package/dist/cjs/utils/configEncoding.js +98 -0
  31. package/dist/cjs/utils/deprecation.js +13 -13
  32. package/dist/cjs/utils/index.js +11 -0
  33. package/dist/cjs/utils/partnerConfig.js +103 -0
  34. package/dist/cjs/utils/partnerConfigGating.js +83 -0
  35. package/dist/cjs/utils/stateErrorHelpers.js +6 -1
  36. package/dist/cjs/utils/url.js +10 -2
  37. package/dist/esm/ParaCore.js +441 -88
  38. package/dist/esm/constants.js +1 -1
  39. package/dist/esm/cryptography/utils.js +5 -2
  40. package/dist/esm/errors.js +9 -0
  41. package/dist/esm/external/userManagementClient.js +21 -4
  42. package/dist/esm/index.js +58 -4
  43. package/dist/esm/services/AuthService.js +66 -47
  44. package/dist/esm/services/LoginFlowService.js +30 -27
  45. package/dist/esm/services/PollingService.js +100 -75
  46. package/dist/esm/services/PortalUrlService.js +112 -19
  47. package/dist/esm/services/PregenWalletService.js +125 -76
  48. package/dist/esm/services/SessionManagementService.js +69 -11
  49. package/dist/esm/services/SignupFlowService.js +52 -47
  50. package/dist/esm/services/VerificationFlowService.js +13 -10
  51. package/dist/esm/services/WalletService.js +51 -36
  52. package/dist/esm/shares/enclave.js +44 -24
  53. package/dist/esm/state/CoreStateManager.js +17 -5
  54. package/dist/esm/state/actors/setupPara.js +4 -1
  55. package/dist/esm/state/machines/walletStateMachine.js +22 -0
  56. package/dist/esm/telemetry/BeaconSpanProcessor.js +74 -0
  57. package/dist/esm/telemetry/config.js +0 -0
  58. package/dist/esm/telemetry/init.js +130 -0
  59. package/dist/esm/telemetry/modalSession.js +29 -0
  60. package/dist/esm/telemetry/session.js +16 -0
  61. package/dist/esm/telemetry/tracer.js +84 -0
  62. package/dist/esm/telemetry/uxAction.js +8 -0
  63. package/dist/esm/telemetry/uxBaggagePropagator.js +35 -0
  64. package/dist/esm/telemetry/uxState.js +21 -0
  65. package/dist/esm/telemetry/uxStateSpanProcessor.js +28 -0
  66. package/dist/esm/utils/configEncoding.js +45 -0
  67. package/dist/esm/utils/deprecation.js +11 -12
  68. package/dist/esm/utils/index.js +6 -0
  69. package/dist/esm/utils/partnerConfig.js +67 -0
  70. package/dist/esm/utils/partnerConfigGating.js +61 -0
  71. package/dist/esm/utils/stateErrorHelpers.js +6 -1
  72. package/dist/esm/utils/url.js +10 -2
  73. package/dist/types/ParaCore.d.ts +101 -19
  74. package/dist/types/PlatformUtils.d.ts +1 -0
  75. package/dist/types/errors.d.ts +26 -0
  76. package/dist/types/external/userManagementClient.d.ts +2 -1
  77. package/dist/types/index.d.ts +15 -3
  78. package/dist/types/services/types/AuthServiceTypes.d.ts +10 -3
  79. package/dist/types/services/types/PortalUrlServiceTypes.d.ts +3 -3
  80. package/dist/types/services/types/WalletServiceTypes.d.ts +4 -0
  81. package/dist/types/state/actors/setupPara.d.ts +18 -0
  82. package/dist/types/state/machines/authStateMachine.d.ts +1 -1
  83. package/dist/types/state/machines/coreStateMachine.d.ts +30 -6
  84. package/dist/types/state/machines/walletStateMachine.d.ts +4 -0
  85. package/dist/types/state/types/core.d.ts +7 -1
  86. package/dist/types/telemetry/BeaconSpanProcessor.d.ts +10 -0
  87. package/dist/types/telemetry/config.d.ts +4 -0
  88. package/dist/types/telemetry/init.d.ts +17 -0
  89. package/dist/types/telemetry/modalSession.d.ts +5 -0
  90. package/dist/types/telemetry/session.d.ts +2 -0
  91. package/dist/types/telemetry/tracer.d.ts +10 -0
  92. package/dist/types/telemetry/uxAction.d.ts +3 -0
  93. package/dist/types/telemetry/uxBaggagePropagator.d.ts +7 -0
  94. package/dist/types/telemetry/uxState.d.ts +8 -0
  95. package/dist/types/telemetry/uxStateSpanProcessor.d.ts +9 -0
  96. package/dist/types/types/config.d.ts +15 -3
  97. package/dist/types/types/coreApi.d.ts +7 -9
  98. package/dist/types/types/serviceInterfaces.d.ts +5 -3
  99. package/dist/types/types/util.d.ts +2 -15
  100. package/dist/types/utils/configEncoding.d.ts +51 -0
  101. package/dist/types/utils/deprecation.d.ts +3 -1
  102. package/dist/types/utils/index.d.ts +2 -0
  103. package/dist/types/utils/partnerConfig.d.ts +28 -0
  104. package/dist/types/utils/partnerConfigGating.d.ts +48 -0
  105. package/dist/types/utils/url.d.ts +3 -2
  106. package/package.json +15 -4
@@ -6,9 +6,10 @@ import {
6
6
  __spreadProps,
7
7
  __spreadValues
8
8
  } from "../chunk-7B52C2XE.js";
9
- var _authService, _pregenWalletService, _walletService, _portalUrlService, _sessionManagementService, _paraCoreInterface, _activePollingOperations, _pollingCancelFlags, _openOAuthPopup;
9
+ var _authService, _pregenWalletService, _walletService, _portalUrlService, _sessionManagementService, _paraCoreInterface, _activePollingOperations, _pollingCancelFlags, _openOAuthPopup, _waitForOAuthEventImpl;
10
10
  import { PopupType } from "../types/popup.js";
11
11
  import { isServerAuthState } from "../utils/types.js";
12
+ import { wrapWithSpan } from "../telemetry/tracer.js";
12
13
  import { POLLING_INTERVAL_MS, POLLING_TIMEOUT_MS } from "../constants.js";
13
14
  class PollingService {
14
15
  constructor(paraCore) {
@@ -72,85 +73,104 @@ class PollingService {
72
73
  isCanceled,
73
74
  id = "genericPolling"
74
75
  } = config;
75
- const pollingId = `${id}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
76
- __privateGet(this, _activePollingOperations).add(pollingId);
77
- const cancelFlag = { canceled: false };
78
- __privateGet(this, _pollingCancelFlags).set(pollingId, cancelFlag);
79
- const cleanup = () => {
80
- __privateGet(this, _activePollingOperations).delete(pollingId);
81
- __privateGet(this, _pollingCancelFlags).delete(pollingId);
82
- };
83
- const isOperationCanceled = () => {
84
- return cancelFlag.canceled || (isCanceled == null ? void 0 : isCanceled());
85
- };
86
- let pollCount = 0;
87
- let consecutiveErrors = 0;
88
- let hasInitialized = false;
89
- const startTime = Date.now();
90
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
91
- try {
92
- if (!hasInitialized && init) {
93
- yield init();
94
- hasInitialized = true;
95
- }
96
- while (pollCount < maxPolls) {
97
- if (isOperationCanceled()) {
98
- cleanup();
99
- onCancel == null ? void 0 : onCancel();
100
- return { type: "CANCEL" };
101
- }
102
- if (Date.now() - startTime > timeoutMs) {
103
- cleanup();
104
- onCancel == null ? void 0 : onCancel();
105
- return { type: "ERROR", error: "TIMEOUT" };
106
- }
76
+ return wrapWithSpan(
77
+ `polling.${id}`,
78
+ (span) => __async(this, null, function* () {
79
+ const pollingId = `${id}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
80
+ __privateGet(this, _activePollingOperations).add(pollingId);
81
+ const cancelFlag = { canceled: false };
82
+ __privateGet(this, _pollingCancelFlags).set(pollingId, cancelFlag);
83
+ const cleanup = () => {
84
+ __privateGet(this, _activePollingOperations).delete(pollingId);
85
+ __privateGet(this, _pollingCancelFlags).delete(pollingId);
86
+ };
87
+ const isOperationCanceled = () => {
88
+ return cancelFlag.canceled || (isCanceled == null ? void 0 : isCanceled());
89
+ };
90
+ let pollCount = 0;
91
+ let consecutiveErrors = 0;
92
+ let hasInitialized = false;
93
+ const startTime = Date.now();
94
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
95
+ const finalize = (result) => {
96
+ span.setAttribute("polling.poll_count", pollCount);
97
+ span.setAttribute("polling.duration_ms", Date.now() - startTime);
98
+ span.setAttribute("polling.result", result.type);
99
+ if (result.type === "ERROR") {
100
+ span.setAttribute("polling.error", result.error);
101
+ }
102
+ return result;
103
+ };
107
104
  try {
108
- const { finished, data } = yield checkCondition();
109
- consecutiveErrors = 0;
110
- if (finished) {
111
- cleanup();
112
- return { type: "COMPLETE", data };
105
+ if (!hasInitialized && init) {
106
+ yield init();
107
+ hasInitialized = true;
113
108
  }
114
- pollCount++;
115
- __privateGet(this, _paraCoreInterface).devLog(`[${id}] Poll iteration`, {
116
- pollCount,
117
- elapsedMs: Date.now() - startTime
118
- });
119
- onPoll == null ? void 0 : onPoll();
120
- if (pollCount < maxPolls) {
121
- yield sleep(intervalMs);
109
+ while (pollCount < maxPolls) {
110
+ if (isOperationCanceled()) {
111
+ cleanup();
112
+ onCancel == null ? void 0 : onCancel();
113
+ return finalize({ type: "CANCEL" });
114
+ }
115
+ if (Date.now() - startTime > timeoutMs) {
116
+ cleanup();
117
+ onCancel == null ? void 0 : onCancel();
118
+ return finalize({ type: "ERROR", error: "TIMEOUT" });
119
+ }
120
+ try {
121
+ const { finished, data } = yield checkCondition();
122
+ consecutiveErrors = 0;
123
+ if (finished) {
124
+ cleanup();
125
+ return finalize({ type: "COMPLETE", data });
126
+ }
127
+ pollCount++;
128
+ __privateGet(this, _paraCoreInterface).devLog(`[${id}] Poll iteration`, {
129
+ pollCount,
130
+ elapsedMs: Date.now() - startTime
131
+ });
132
+ onPoll == null ? void 0 : onPoll();
133
+ if (pollCount < maxPolls) {
134
+ yield sleep(intervalMs);
135
+ }
136
+ } catch (error) {
137
+ consecutiveErrors++;
138
+ if (consecutiveErrors >= 3) {
139
+ console.warn(`[${id}] ${consecutiveErrors} consecutive polling errors`, error);
140
+ }
141
+ pollCount++;
142
+ onPoll == null ? void 0 : onPoll();
143
+ if (pollCount < maxPolls) {
144
+ yield sleep(intervalMs);
145
+ }
146
+ }
122
147
  }
148
+ cleanup();
149
+ onCancel == null ? void 0 : onCancel();
150
+ return finalize({ type: "ERROR", error: "MAX_POLLS_EXCEEDED" });
123
151
  } catch (error) {
124
- consecutiveErrors++;
125
- if (consecutiveErrors >= 3) {
126
- console.warn(`[${id}] ${consecutiveErrors} consecutive polling errors`, error);
127
- }
128
- pollCount++;
129
- onPoll == null ? void 0 : onPoll();
130
- if (pollCount < maxPolls) {
131
- yield sleep(intervalMs);
132
- }
152
+ console.error("Polling initialization error:", error);
153
+ cleanup();
154
+ onCancel == null ? void 0 : onCancel();
155
+ return finalize({ type: "ERROR", error: "INITIALIZATION_FAILED" });
133
156
  }
134
- }
135
- cleanup();
136
- onCancel == null ? void 0 : onCancel();
137
- return { type: "ERROR", error: "MAX_POLLS_EXCEEDED" };
138
- } catch (error) {
139
- console.error("Polling initialization error:", error);
140
- cleanup();
141
- onCancel == null ? void 0 : onCancel();
142
- return { type: "ERROR", error: "INITIALIZATION_FAILED" };
143
- }
157
+ }),
158
+ { "polling.id": id, "polling.interval_ms": intervalMs, "polling.timeout_ms": timeoutMs }
159
+ );
144
160
  });
145
- this.waitForOAuthEvent = (_0) => __async(this, [_0], function* ({
146
- method,
147
- onOAuthPopup,
148
- onOAuthUrl,
149
- portalTheme,
150
- useShortUrls,
151
- isCanceled,
152
- appScheme
153
- }) {
161
+ this.waitForOAuthEvent = (params) => __async(this, null, function* () {
162
+ return (
163
+ // Wrap the whole OAuth wait — popup/url setup → event-listener resolution — so
164
+ // the trace shows the user's OAuth round-trip as a single bar with method tagged
165
+ // (Telegram vs Farcaster) and the resolution cause (success/failure/cancel/timeout)
166
+ // attached. Without this, the trace fragments into orphan HTTP spans for the
167
+ // portal URL fetch and nothing tying them to the wait phase.
168
+ wrapWithSpan(`polling.waitForOAuthEvent.${params.method}`, (span) => __privateGet(this, _waitForOAuthEventImpl).call(this, params, span), {
169
+ "polling.method": params.method
170
+ })
171
+ );
172
+ });
173
+ __privateAdd(this, _waitForOAuthEventImpl, (_0, _1) => __async(this, [_0, _1], function* ({ method, onOAuthPopup, onOAuthUrl, portalTheme, useShortUrls, isCanceled, appScheme }, parentSpan) {
154
174
  const oAuthConfigs = {
155
175
  TELEGRAM: {
156
176
  name: "Telegram",
@@ -216,12 +236,14 @@ class PollingService {
216
236
  const successHandler = (eventData) => {
217
237
  if (settled) return;
218
238
  settled = true;
239
+ parentSpan.setAttribute("polling.result", "success");
219
240
  cleanupAll();
220
241
  resolve({ authState: eventData.payload, opts: { portalTheme, useShortUrls } });
221
242
  };
222
243
  const errorHandler = () => {
223
244
  if (settled) return;
224
245
  settled = true;
246
+ parentSpan.setAttribute("polling.result", "failed");
225
247
  cleanupAll();
226
248
  reject(`${config.name} authentication failed`);
227
249
  };
@@ -239,6 +261,7 @@ class PollingService {
239
261
  if (isOperationCanceled()) {
240
262
  if (settled) return;
241
263
  settled = true;
264
+ parentSpan.setAttribute("polling.result", "canceled");
242
265
  cleanupAll();
243
266
  reject(`${config.name} authentication canceled`);
244
267
  }
@@ -246,11 +269,12 @@ class PollingService {
246
269
  timeoutId = setTimeout(() => {
247
270
  if (settled) return;
248
271
  settled = true;
272
+ parentSpan.setAttribute("polling.result", "timeout");
249
273
  cleanupAll();
250
274
  reject(`${config.name} authentication timed out`);
251
275
  }, POLLING_TIMEOUT_MS);
252
276
  });
253
- });
277
+ }));
254
278
  this.waitForTelegramEvent = (params) => __async(this, null, function* () {
255
279
  return yield this.waitForOAuthEvent(__spreadProps(__spreadValues({}, params), { method: "TELEGRAM" }));
256
280
  });
@@ -384,6 +408,7 @@ _paraCoreInterface = new WeakMap();
384
408
  _activePollingOperations = new WeakMap();
385
409
  _pollingCancelFlags = new WeakMap();
386
410
  _openOAuthPopup = new WeakMap();
411
+ _waitForOAuthEventImpl = new WeakMap();
387
412
  export {
388
413
  PollingService
389
414
  };
@@ -6,12 +6,64 @@ import {
6
6
  __spreadProps,
7
7
  __spreadValues
8
8
  } from "../chunk-7B52C2XE.js";
9
- var _authService, _pregenWalletService, _sessionManagementService, _walletService, _paraCoreInterface;
9
+ var _authService, _pregenWalletService, _sessionManagementService, _walletService, _paraCoreInterface, _getOAuthUrlImpl;
10
10
  import { isPhone } from "@getpara/user-management-client";
11
11
  import { constructUrl, getPortalBaseURL, shortenUrl } from "../utils/url.js";
12
+ import { encodeConfigParams, ENCODED_CONFIG_VERSION } from "../utils/configEncoding.js";
12
13
  import { getPublicKeyHex } from "../cryptography/utils.js";
13
14
  import { splitPhoneNumber } from "../utils/phone.js";
14
15
  import { getBaseOAuthUrl } from "../external/userManagementClient.js";
16
+ import { wrapWithSpan } from "../telemetry/tracer.js";
17
+ import { getModalSessionContext } from "../telemetry/modalSession.js";
18
+ import { context, propagation } from "@opentelemetry/api";
19
+ const ENCODE_THRESHOLD = 2500;
20
+ const SHORTEN_THRESHOLD = 3e3;
21
+ const CONFIG_PARAM_KEYS_FOR_BLOB = /* @__PURE__ */ new Set([
22
+ "portalBackgroundColor",
23
+ "portalForegroundColor",
24
+ "portalFont",
25
+ "portalBorderRadius",
26
+ "portalThemeMode",
27
+ "portalForegroundMixRatio",
28
+ "portalCssOverrides",
29
+ "appName",
30
+ "homepageUrl"
31
+ ]);
32
+ function buildThemeBlobFromParams(params) {
33
+ const hasAny = params.portalBackgroundColor || params.portalForegroundColor || params.portalFont || params.portalCssOverrides || params.portalThemeMode || params.portalBorderRadius || params.portalForegroundMixRatio;
34
+ if (!hasAny) return void 0;
35
+ let cssOverrides;
36
+ if (params.portalCssOverrides) {
37
+ try {
38
+ cssOverrides = JSON.parse(params.portalCssOverrides);
39
+ } catch (e) {
40
+ cssOverrides = void 0;
41
+ }
42
+ }
43
+ return {
44
+ backgroundColor: params.portalBackgroundColor || void 0,
45
+ foregroundColor: params.portalForegroundColor || void 0,
46
+ mode: params.portalThemeMode || void 0,
47
+ font: params.portalFont || void 0,
48
+ borderRadius: params.portalBorderRadius || void 0,
49
+ foregroundMixRatio: params.portalForegroundMixRatio ? parseFloat(params.portalForegroundMixRatio) : void 0,
50
+ cssOverrides
51
+ };
52
+ }
53
+ function buildAppBlobFromParams(params) {
54
+ if (!params.appName && !params.homepageUrl) return void 0;
55
+ return {
56
+ appName: params.appName || void 0,
57
+ homepageUrl: params.homepageUrl || void 0
58
+ };
59
+ }
60
+ function withoutConfigParams(params) {
61
+ const out = {};
62
+ for (const [k, v] of Object.entries(params)) {
63
+ if (!CONFIG_PARAM_KEYS_FOR_BLOB.has(k)) out[k] = v;
64
+ }
65
+ return out;
66
+ }
15
67
  class PortalUrlService {
16
68
  constructor(paraCore) {
17
69
  __privateAdd(this, _authService);
@@ -53,7 +105,7 @@ class PortalUrlService {
53
105
  return __privateGet(this, _paraCoreInterface).ctx.portalUrlOverride || (yield this.getPartnerURL()) || getPortalBaseURL(__privateGet(this, _paraCoreInterface).ctx, false, false, isLegacy);
54
106
  });
55
107
  this.constructPortalUrl = (_0, ..._1) => __async(this, [_0, ..._1], function* (type, opts = {}) {
56
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
57
109
  const [
58
110
  isCreate,
59
111
  isLogin,
@@ -195,24 +247,40 @@ class PortalUrlService {
195
247
  encryptionKey: getPublicKeyHex(__privateGet(this, _paraCoreInterface).loginEncryptionKeyPair),
196
248
  sessionId
197
249
  };
198
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
250
+ const traceCarrier = {};
251
+ propagation.inject((_b = getModalSessionContext()) != null ? _b : context.active(), traceCarrier);
252
+ const cfgTheme = __privateGet(this, _paraCoreInterface).config.themeConfig;
253
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, traceCarrier), {
199
254
  apiKey: __privateGet(this, _paraCoreInterface).ctx.apiKey,
200
255
  partnerId: partner == null ? void 0 : partner.id
201
- }, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
202
- portalFont: ((_c = opts.portalTheme) == null ? void 0 : _c.font) || ((_d = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _d.font) || (partner == null ? void 0 : partner.font),
203
- portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _f.borderRadius),
204
- portalThemeMode: ((_g = opts.portalTheme) == null ? void 0 : _g.mode) || ((_h = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _h.mode) || (partner == null ? void 0 : partner.themeMode),
205
- portalForegroundMixRatio: (_l = (_k = (_i = opts.portalTheme) == null ? void 0 : _i.foregroundMixRatio) != null ? _k : (_j = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _j.foregroundMixRatio) == null ? void 0 : _l.toString(),
256
+ }), typeof window !== "undefined" && ((_c = window.location) == null ? void 0 : _c.origin) ? { origin: window.location.origin } : {}), {
257
+ portalFont: ((_d = opts.portalTheme) == null ? void 0 : _d.font) || (cfgTheme == null ? void 0 : cfgTheme.font) || ((_e = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _e.font) || (partner == null ? void 0 : partner.font),
258
+ portalBorderRadius: ((_f = opts.portalTheme) == null ? void 0 : _f.borderRadius) || (cfgTheme == null ? void 0 : cfgTheme.borderRadius) || ((_g = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _g.borderRadius),
259
+ portalThemeMode: ((_h = opts.portalTheme) == null ? void 0 : _h.mode) || (cfgTheme == null ? void 0 : cfgTheme.mode) || ((_i = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _i.mode) || (partner == null ? void 0 : partner.themeMode),
260
+ portalForegroundMixRatio: (_n = (_m = (_k = (_j = opts.portalTheme) == null ? void 0 : _j.foregroundMixRatio) != null ? _k : cfgTheme == null ? void 0 : cfgTheme.foregroundMixRatio) != null ? _m : (_l = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _l.foregroundMixRatio) == null ? void 0 : _n.toString(),
206
261
  portalCssOverrides: (() => {
207
- var _a2, _b2, _c2;
208
- const overrides = (_c2 = (_a2 = opts.portalTheme) == null ? void 0 : _a2.cssOverrides) != null ? _c2 : (_b2 = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _b2.cssOverrides;
262
+ var _a2, _b2, _c2, _d2;
263
+ const overrides = (_d2 = (_b2 = (_a2 = opts.portalTheme) == null ? void 0 : _a2.cssOverrides) != null ? _b2 : cfgTheme == null ? void 0 : cfgTheme.cssOverrides) != null ? _d2 : (_c2 = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _c2.cssOverrides;
209
264
  return overrides ? JSON.stringify(overrides) : void 0;
210
265
  })(),
211
- portalForegroundColor: ((_m = opts.portalTheme) == null ? void 0 : _m.accentColor) || ((_n = opts.portalTheme) == null ? void 0 : _n.foregroundColor) || ((_o = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _o.accentColor) || ((_p = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _p.foregroundColor) || (partner == null ? void 0 : partner.accentColor) || (partner == null ? void 0 : partner.foregroundColor),
212
- portalBackgroundColor: ((_q = opts.portalTheme) == null ? void 0 : _q.backgroundColor) || ((_r = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _r.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || __privateGet(this, _paraCoreInterface).portalBackgroundColor,
266
+ portalForegroundColor: ((_o = opts.portalTheme) == null ? void 0 : _o.accentColor) || ((_p = opts.portalTheme) == null ? void 0 : _p.foregroundColor) || (cfgTheme == null ? void 0 : cfgTheme.accentColor) || (cfgTheme == null ? void 0 : cfgTheme.foregroundColor) || ((_q = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _q.accentColor) || ((_r = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _r.foregroundColor) || (partner == null ? void 0 : partner.accentColor) || (partner == null ? void 0 : partner.foregroundColor),
267
+ portalBackgroundColor: ((_s = opts.portalTheme) == null ? void 0 : _s.backgroundColor) || (cfgTheme == null ? void 0 : cfgTheme.backgroundColor) || ((_t = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _t.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || __privateGet(this, _paraCoreInterface).portalBackgroundColor,
213
268
  portalPrimaryButtonColor: __privateGet(this, _paraCoreInterface).portalPrimaryButtonColor,
214
269
  portalTextColor: __privateGet(this, _paraCoreInterface).portalTextColor,
215
270
  portalPrimaryButtonTextColor: __privateGet(this, _paraCoreInterface).portalPrimaryButtonTextColor,
271
+ // SDK-overridable branding threaded into the popup. `appName` is the
272
+ // load-bearing field for the V2 render sites that previously read
273
+ // `partner.displayName`; `homepageUrl` lights up the URL param
274
+ // ModalLayoutV2 already consumed.
275
+ appName: __privateGet(this, _paraCoreInterface).config.appName,
276
+ homepageUrl: (_u = __privateGet(this, _paraCoreInterface).config.partnerLinks) == null ? void 0 : _u.homepageUrl,
277
+ // The `authOAuthMethods` / `authDisableEmail` / `authDisablePhone` URL
278
+ // params were deleted here. Portal audit confirmed there is no
279
+ // auth-method-selection UI in V2 (every route lands on an already-chosen
280
+ // flow), so the params had no consumer. SDK-side gating in
281
+ // partnerConfigGating.ts is the sole enforcement point. If the portal
282
+ // ever grows method-selection UI, re-add via the `c` encoded blob (bump
283
+ // schema version) rather than as individual params.
216
284
  isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
217
285
  }), __privateGet(this, _authService).authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey || isTxReview) ? __spreadProps(__spreadValues({
218
286
  authInfo: JSON.stringify(__privateGet(this, _authService).authInfo)
@@ -239,12 +307,31 @@ class PortalUrlService {
239
307
  }), isExportPrivateKey || isTxReview ? {
240
308
  sessionId: thisDevice.sessionId
241
309
  } : {});
242
- const fullUrl = constructUrl({ base, path, params });
243
- if (opts.shorten) {
244
- const shortUrl = yield shortenUrl(__privateGet(this, _paraCoreInterface).ctx, fullUrl, shouldUseLegacyPortalUrl);
245
- return { url: shortUrl, fullUrl };
310
+ const plainUrl = constructUrl({ base, path, params });
311
+ if (plainUrl.length <= ENCODE_THRESHOLD) {
312
+ if (opts.shorten) {
313
+ const shortUrl = yield shortenUrl(__privateGet(this, _paraCoreInterface).ctx, plainUrl, shouldUseLegacyPortalUrl);
314
+ return { url: shortUrl, fullUrl: plainUrl };
315
+ }
316
+ return { url: plainUrl, fullUrl: plainUrl };
246
317
  }
247
- return { url: fullUrl, fullUrl };
318
+ const themeBlob = buildThemeBlobFromParams(params);
319
+ const appBlob = buildAppBlobFromParams(params);
320
+ let candidateUrl = plainUrl;
321
+ if (themeBlob || appBlob) {
322
+ const c = yield encodeConfigParams(__spreadValues(__spreadValues({
323
+ v: ENCODED_CONFIG_VERSION
324
+ }, themeBlob && { theme: themeBlob }), appBlob && { app: appBlob }));
325
+ if (c) {
326
+ const encodedParams = __spreadProps(__spreadValues({}, withoutConfigParams(params)), { c });
327
+ candidateUrl = constructUrl({ base, path, params: encodedParams });
328
+ }
329
+ }
330
+ if (opts.shorten || candidateUrl.length > SHORTEN_THRESHOLD) {
331
+ const shortUrl = yield shortenUrl(__privateGet(this, _paraCoreInterface).ctx, candidateUrl, shouldUseLegacyPortalUrl);
332
+ return { url: shortUrl, fullUrl: candidateUrl };
333
+ }
334
+ return { url: candidateUrl, fullUrl: candidateUrl };
248
335
  });
249
336
  this.getLoginUrl = (_0) => __async(this, [_0], function* ({ authMethod = "PASSKEY", shorten = false, portalTheme, sessionId }) {
250
337
  if (!sessionId) {
@@ -274,7 +361,12 @@ class PortalUrlService {
274
361
  portalTheme
275
362
  });
276
363
  });
277
- this.getOAuthUrl = (_0) => __async(this, [_0], function* ({
364
+ this.getOAuthUrl = (params) => __async(this, null, function* () {
365
+ return wrapWithSpan("auth.get_oauth_url", () => __privateGet(this, _getOAuthUrlImpl).call(this, params), {
366
+ "oauth.method": params.method
367
+ });
368
+ });
369
+ __privateAdd(this, _getOAuthUrlImpl, (_0) => __async(this, [_0], function* ({
278
370
  method,
279
371
  appScheme,
280
372
  accountLinkInProgress,
@@ -316,7 +408,7 @@ class PortalUrlService {
316
408
  linkedAccountId: __privateGet(this, _paraCoreInterface).accountLinkInProgress.id
317
409
  } : {}), callback && { callback })
318
410
  });
319
- });
411
+ }));
320
412
  __privateSet(this, _paraCoreInterface, paraCore.getPortalUrlServiceInterface());
321
413
  }
322
414
  }
@@ -325,6 +417,7 @@ _pregenWalletService = new WeakMap();
325
417
  _sessionManagementService = new WeakMap();
326
418
  _walletService = new WeakMap();
327
419
  _paraCoreInterface = new WeakMap();
420
+ _getOAuthUrlImpl = new WeakMap();
328
421
  export {
329
422
  PortalUrlService
330
423
  };