@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
@@ -66,8 +66,9 @@ __export(PollingService_exports, {
66
66
  module.exports = __toCommonJS(PollingService_exports);
67
67
  var import_popup = require("../types/popup.js");
68
68
  var import_types = require("../utils/types.js");
69
+ var import_tracer = require("../telemetry/tracer.js");
69
70
  var import_constants = require("../constants.js");
70
- var _authService, _pregenWalletService, _walletService, _portalUrlService, _sessionManagementService, _paraCoreInterface, _activePollingOperations, _pollingCancelFlags, _openOAuthPopup;
71
+ var _authService, _pregenWalletService, _walletService, _portalUrlService, _sessionManagementService, _paraCoreInterface, _activePollingOperations, _pollingCancelFlags, _openOAuthPopup, _waitForOAuthEventImpl;
71
72
  class PollingService {
72
73
  constructor(paraCore) {
73
74
  __privateAdd(this, _authService);
@@ -130,85 +131,104 @@ class PollingService {
130
131
  isCanceled,
131
132
  id = "genericPolling"
132
133
  } = config;
133
- const pollingId = `${id}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
134
- __privateGet(this, _activePollingOperations).add(pollingId);
135
- const cancelFlag = { canceled: false };
136
- __privateGet(this, _pollingCancelFlags).set(pollingId, cancelFlag);
137
- const cleanup = () => {
138
- __privateGet(this, _activePollingOperations).delete(pollingId);
139
- __privateGet(this, _pollingCancelFlags).delete(pollingId);
140
- };
141
- const isOperationCanceled = () => {
142
- return cancelFlag.canceled || (isCanceled == null ? void 0 : isCanceled());
143
- };
144
- let pollCount = 0;
145
- let consecutiveErrors = 0;
146
- let hasInitialized = false;
147
- const startTime = Date.now();
148
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
149
- try {
150
- if (!hasInitialized && init) {
151
- yield init();
152
- hasInitialized = true;
153
- }
154
- while (pollCount < maxPolls) {
155
- if (isOperationCanceled()) {
156
- cleanup();
157
- onCancel == null ? void 0 : onCancel();
158
- return { type: "CANCEL" };
159
- }
160
- if (Date.now() - startTime > timeoutMs) {
161
- cleanup();
162
- onCancel == null ? void 0 : onCancel();
163
- return { type: "ERROR", error: "TIMEOUT" };
164
- }
134
+ return (0, import_tracer.wrapWithSpan)(
135
+ `polling.${id}`,
136
+ (span) => __async(this, null, function* () {
137
+ const pollingId = `${id}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
138
+ __privateGet(this, _activePollingOperations).add(pollingId);
139
+ const cancelFlag = { canceled: false };
140
+ __privateGet(this, _pollingCancelFlags).set(pollingId, cancelFlag);
141
+ const cleanup = () => {
142
+ __privateGet(this, _activePollingOperations).delete(pollingId);
143
+ __privateGet(this, _pollingCancelFlags).delete(pollingId);
144
+ };
145
+ const isOperationCanceled = () => {
146
+ return cancelFlag.canceled || (isCanceled == null ? void 0 : isCanceled());
147
+ };
148
+ let pollCount = 0;
149
+ let consecutiveErrors = 0;
150
+ let hasInitialized = false;
151
+ const startTime = Date.now();
152
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
153
+ const finalize = (result) => {
154
+ span.setAttribute("polling.poll_count", pollCount);
155
+ span.setAttribute("polling.duration_ms", Date.now() - startTime);
156
+ span.setAttribute("polling.result", result.type);
157
+ if (result.type === "ERROR") {
158
+ span.setAttribute("polling.error", result.error);
159
+ }
160
+ return result;
161
+ };
165
162
  try {
166
- const { finished, data } = yield checkCondition();
167
- consecutiveErrors = 0;
168
- if (finished) {
169
- cleanup();
170
- return { type: "COMPLETE", data };
163
+ if (!hasInitialized && init) {
164
+ yield init();
165
+ hasInitialized = true;
171
166
  }
172
- pollCount++;
173
- __privateGet(this, _paraCoreInterface).devLog(`[${id}] Poll iteration`, {
174
- pollCount,
175
- elapsedMs: Date.now() - startTime
176
- });
177
- onPoll == null ? void 0 : onPoll();
178
- if (pollCount < maxPolls) {
179
- yield sleep(intervalMs);
167
+ while (pollCount < maxPolls) {
168
+ if (isOperationCanceled()) {
169
+ cleanup();
170
+ onCancel == null ? void 0 : onCancel();
171
+ return finalize({ type: "CANCEL" });
172
+ }
173
+ if (Date.now() - startTime > timeoutMs) {
174
+ cleanup();
175
+ onCancel == null ? void 0 : onCancel();
176
+ return finalize({ type: "ERROR", error: "TIMEOUT" });
177
+ }
178
+ try {
179
+ const { finished, data } = yield checkCondition();
180
+ consecutiveErrors = 0;
181
+ if (finished) {
182
+ cleanup();
183
+ return finalize({ type: "COMPLETE", data });
184
+ }
185
+ pollCount++;
186
+ __privateGet(this, _paraCoreInterface).devLog(`[${id}] Poll iteration`, {
187
+ pollCount,
188
+ elapsedMs: Date.now() - startTime
189
+ });
190
+ onPoll == null ? void 0 : onPoll();
191
+ if (pollCount < maxPolls) {
192
+ yield sleep(intervalMs);
193
+ }
194
+ } catch (error) {
195
+ consecutiveErrors++;
196
+ if (consecutiveErrors >= 3) {
197
+ console.warn(`[${id}] ${consecutiveErrors} consecutive polling errors`, error);
198
+ }
199
+ pollCount++;
200
+ onPoll == null ? void 0 : onPoll();
201
+ if (pollCount < maxPolls) {
202
+ yield sleep(intervalMs);
203
+ }
204
+ }
180
205
  }
206
+ cleanup();
207
+ onCancel == null ? void 0 : onCancel();
208
+ return finalize({ type: "ERROR", error: "MAX_POLLS_EXCEEDED" });
181
209
  } catch (error) {
182
- consecutiveErrors++;
183
- if (consecutiveErrors >= 3) {
184
- console.warn(`[${id}] ${consecutiveErrors} consecutive polling errors`, error);
185
- }
186
- pollCount++;
187
- onPoll == null ? void 0 : onPoll();
188
- if (pollCount < maxPolls) {
189
- yield sleep(intervalMs);
190
- }
210
+ console.error("Polling initialization error:", error);
211
+ cleanup();
212
+ onCancel == null ? void 0 : onCancel();
213
+ return finalize({ type: "ERROR", error: "INITIALIZATION_FAILED" });
191
214
  }
192
- }
193
- cleanup();
194
- onCancel == null ? void 0 : onCancel();
195
- return { type: "ERROR", error: "MAX_POLLS_EXCEEDED" };
196
- } catch (error) {
197
- console.error("Polling initialization error:", error);
198
- cleanup();
199
- onCancel == null ? void 0 : onCancel();
200
- return { type: "ERROR", error: "INITIALIZATION_FAILED" };
201
- }
215
+ }),
216
+ { "polling.id": id, "polling.interval_ms": intervalMs, "polling.timeout_ms": timeoutMs }
217
+ );
202
218
  });
203
- this.waitForOAuthEvent = (_0) => __async(this, [_0], function* ({
204
- method,
205
- onOAuthPopup,
206
- onOAuthUrl,
207
- portalTheme,
208
- useShortUrls,
209
- isCanceled,
210
- appScheme
211
- }) {
219
+ this.waitForOAuthEvent = (params) => __async(this, null, function* () {
220
+ return (
221
+ // Wrap the whole OAuth wait — popup/url setup → event-listener resolution — so
222
+ // the trace shows the user's OAuth round-trip as a single bar with method tagged
223
+ // (Telegram vs Farcaster) and the resolution cause (success/failure/cancel/timeout)
224
+ // attached. Without this, the trace fragments into orphan HTTP spans for the
225
+ // portal URL fetch and nothing tying them to the wait phase.
226
+ (0, import_tracer.wrapWithSpan)(`polling.waitForOAuthEvent.${params.method}`, (span) => __privateGet(this, _waitForOAuthEventImpl).call(this, params, span), {
227
+ "polling.method": params.method
228
+ })
229
+ );
230
+ });
231
+ __privateAdd(this, _waitForOAuthEventImpl, (_0, _1) => __async(this, [_0, _1], function* ({ method, onOAuthPopup, onOAuthUrl, portalTheme, useShortUrls, isCanceled, appScheme }, parentSpan) {
212
232
  const oAuthConfigs = {
213
233
  TELEGRAM: {
214
234
  name: "Telegram",
@@ -274,12 +294,14 @@ class PollingService {
274
294
  const successHandler = (eventData) => {
275
295
  if (settled) return;
276
296
  settled = true;
297
+ parentSpan.setAttribute("polling.result", "success");
277
298
  cleanupAll();
278
299
  resolve({ authState: eventData.payload, opts: { portalTheme, useShortUrls } });
279
300
  };
280
301
  const errorHandler = () => {
281
302
  if (settled) return;
282
303
  settled = true;
304
+ parentSpan.setAttribute("polling.result", "failed");
283
305
  cleanupAll();
284
306
  reject(`${config.name} authentication failed`);
285
307
  };
@@ -297,6 +319,7 @@ class PollingService {
297
319
  if (isOperationCanceled()) {
298
320
  if (settled) return;
299
321
  settled = true;
322
+ parentSpan.setAttribute("polling.result", "canceled");
300
323
  cleanupAll();
301
324
  reject(`${config.name} authentication canceled`);
302
325
  }
@@ -304,11 +327,12 @@ class PollingService {
304
327
  timeoutId = setTimeout(() => {
305
328
  if (settled) return;
306
329
  settled = true;
330
+ parentSpan.setAttribute("polling.result", "timeout");
307
331
  cleanupAll();
308
332
  reject(`${config.name} authentication timed out`);
309
333
  }, import_constants.POLLING_TIMEOUT_MS);
310
334
  });
311
- });
335
+ }));
312
336
  this.waitForTelegramEvent = (params) => __async(this, null, function* () {
313
337
  return yield this.waitForOAuthEvent(__spreadProps(__spreadValues({}, params), { method: "TELEGRAM" }));
314
338
  });
@@ -442,6 +466,7 @@ _paraCoreInterface = new WeakMap();
442
466
  _activePollingOperations = new WeakMap();
443
467
  _pollingCancelFlags = new WeakMap();
444
468
  _openOAuthPopup = new WeakMap();
469
+ _waitForOAuthEventImpl = new WeakMap();
445
470
  // Annotate the CommonJS export names for ESM import in node:
446
471
  0 && (module.exports = {
447
472
  PollingService
@@ -66,10 +66,62 @@ __export(PortalUrlService_exports, {
66
66
  module.exports = __toCommonJS(PortalUrlService_exports);
67
67
  var import_user_management_client = require("@getpara/user-management-client");
68
68
  var import_url = require("../utils/url.js");
69
+ var import_configEncoding = require("../utils/configEncoding.js");
69
70
  var import_utils = require("../cryptography/utils.js");
70
71
  var import_phone = require("../utils/phone.js");
71
72
  var import_userManagementClient = require("../external/userManagementClient.js");
72
- var _authService, _pregenWalletService, _sessionManagementService, _walletService, _paraCoreInterface;
73
+ var import_tracer = require("../telemetry/tracer.js");
74
+ var import_modalSession = require("../telemetry/modalSession.js");
75
+ var import_api = require("@opentelemetry/api");
76
+ var _authService, _pregenWalletService, _sessionManagementService, _walletService, _paraCoreInterface, _getOAuthUrlImpl;
77
+ const ENCODE_THRESHOLD = 2500;
78
+ const SHORTEN_THRESHOLD = 3e3;
79
+ const CONFIG_PARAM_KEYS_FOR_BLOB = /* @__PURE__ */ new Set([
80
+ "portalBackgroundColor",
81
+ "portalForegroundColor",
82
+ "portalFont",
83
+ "portalBorderRadius",
84
+ "portalThemeMode",
85
+ "portalForegroundMixRatio",
86
+ "portalCssOverrides",
87
+ "appName",
88
+ "homepageUrl"
89
+ ]);
90
+ function buildThemeBlobFromParams(params) {
91
+ const hasAny = params.portalBackgroundColor || params.portalForegroundColor || params.portalFont || params.portalCssOverrides || params.portalThemeMode || params.portalBorderRadius || params.portalForegroundMixRatio;
92
+ if (!hasAny) return void 0;
93
+ let cssOverrides;
94
+ if (params.portalCssOverrides) {
95
+ try {
96
+ cssOverrides = JSON.parse(params.portalCssOverrides);
97
+ } catch (e) {
98
+ cssOverrides = void 0;
99
+ }
100
+ }
101
+ return {
102
+ backgroundColor: params.portalBackgroundColor || void 0,
103
+ foregroundColor: params.portalForegroundColor || void 0,
104
+ mode: params.portalThemeMode || void 0,
105
+ font: params.portalFont || void 0,
106
+ borderRadius: params.portalBorderRadius || void 0,
107
+ foregroundMixRatio: params.portalForegroundMixRatio ? parseFloat(params.portalForegroundMixRatio) : void 0,
108
+ cssOverrides
109
+ };
110
+ }
111
+ function buildAppBlobFromParams(params) {
112
+ if (!params.appName && !params.homepageUrl) return void 0;
113
+ return {
114
+ appName: params.appName || void 0,
115
+ homepageUrl: params.homepageUrl || void 0
116
+ };
117
+ }
118
+ function withoutConfigParams(params) {
119
+ const out = {};
120
+ for (const [k, v] of Object.entries(params)) {
121
+ if (!CONFIG_PARAM_KEYS_FOR_BLOB.has(k)) out[k] = v;
122
+ }
123
+ return out;
124
+ }
73
125
  class PortalUrlService {
74
126
  constructor(paraCore) {
75
127
  __privateAdd(this, _authService);
@@ -111,7 +163,7 @@ class PortalUrlService {
111
163
  return __privateGet(this, _paraCoreInterface).ctx.portalUrlOverride || (yield this.getPartnerURL()) || (0, import_url.getPortalBaseURL)(__privateGet(this, _paraCoreInterface).ctx, false, false, isLegacy);
112
164
  });
113
165
  this.constructPortalUrl = (_0, ..._1) => __async(this, [_0, ..._1], function* (type, opts = {}) {
114
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
166
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
115
167
  const [
116
168
  isCreate,
117
169
  isLogin,
@@ -253,24 +305,40 @@ class PortalUrlService {
253
305
  encryptionKey: (0, import_utils.getPublicKeyHex)(__privateGet(this, _paraCoreInterface).loginEncryptionKeyPair),
254
306
  sessionId
255
307
  };
256
- const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
308
+ const traceCarrier = {};
309
+ import_api.propagation.inject((_b = (0, import_modalSession.getModalSessionContext)()) != null ? _b : import_api.context.active(), traceCarrier);
310
+ const cfgTheme = __privateGet(this, _paraCoreInterface).config.themeConfig;
311
+ const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, traceCarrier), {
257
312
  apiKey: __privateGet(this, _paraCoreInterface).ctx.apiKey,
258
313
  partnerId: partner == null ? void 0 : partner.id
259
- }, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
260
- 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),
261
- portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _f.borderRadius),
262
- 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),
263
- 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(),
314
+ }), typeof window !== "undefined" && ((_c = window.location) == null ? void 0 : _c.origin) ? { origin: window.location.origin } : {}), {
315
+ 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),
316
+ 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),
317
+ 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),
318
+ 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(),
264
319
  portalCssOverrides: (() => {
265
- var _a2, _b2, _c2;
266
- const overrides = (_c2 = (_a2 = opts.portalTheme) == null ? void 0 : _a2.cssOverrides) != null ? _c2 : (_b2 = __privateGet(this, _paraCoreInterface).portalTheme) == null ? void 0 : _b2.cssOverrides;
320
+ var _a2, _b2, _c2, _d2;
321
+ 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;
267
322
  return overrides ? JSON.stringify(overrides) : void 0;
268
323
  })(),
269
- 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),
270
- 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,
324
+ 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),
325
+ 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,
271
326
  portalPrimaryButtonColor: __privateGet(this, _paraCoreInterface).portalPrimaryButtonColor,
272
327
  portalTextColor: __privateGet(this, _paraCoreInterface).portalTextColor,
273
328
  portalPrimaryButtonTextColor: __privateGet(this, _paraCoreInterface).portalPrimaryButtonTextColor,
329
+ // SDK-overridable branding threaded into the popup. `appName` is the
330
+ // load-bearing field for the V2 render sites that previously read
331
+ // `partner.displayName`; `homepageUrl` lights up the URL param
332
+ // ModalLayoutV2 already consumed.
333
+ appName: __privateGet(this, _paraCoreInterface).config.appName,
334
+ homepageUrl: (_u = __privateGet(this, _paraCoreInterface).config.partnerLinks) == null ? void 0 : _u.homepageUrl,
335
+ // The `authOAuthMethods` / `authDisableEmail` / `authDisablePhone` URL
336
+ // params were deleted here. Portal audit confirmed there is no
337
+ // auth-method-selection UI in V2 (every route lands on an already-chosen
338
+ // flow), so the params had no consumer. SDK-side gating in
339
+ // partnerConfigGating.ts is the sole enforcement point. If the portal
340
+ // ever grows method-selection UI, re-add via the `c` encoded blob (bump
341
+ // schema version) rather than as individual params.
274
342
  isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
275
343
  }), __privateGet(this, _authService).authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey || isTxReview) ? __spreadProps(__spreadValues({
276
344
  authInfo: JSON.stringify(__privateGet(this, _authService).authInfo)
@@ -297,12 +365,31 @@ class PortalUrlService {
297
365
  }), isExportPrivateKey || isTxReview ? {
298
366
  sessionId: thisDevice.sessionId
299
367
  } : {});
300
- const fullUrl = (0, import_url.constructUrl)({ base, path, params });
301
- if (opts.shorten) {
302
- const shortUrl = yield (0, import_url.shortenUrl)(__privateGet(this, _paraCoreInterface).ctx, fullUrl, shouldUseLegacyPortalUrl);
303
- return { url: shortUrl, fullUrl };
368
+ const plainUrl = (0, import_url.constructUrl)({ base, path, params });
369
+ if (plainUrl.length <= ENCODE_THRESHOLD) {
370
+ if (opts.shorten) {
371
+ const shortUrl = yield (0, import_url.shortenUrl)(__privateGet(this, _paraCoreInterface).ctx, plainUrl, shouldUseLegacyPortalUrl);
372
+ return { url: shortUrl, fullUrl: plainUrl };
373
+ }
374
+ return { url: plainUrl, fullUrl: plainUrl };
304
375
  }
305
- return { url: fullUrl, fullUrl };
376
+ const themeBlob = buildThemeBlobFromParams(params);
377
+ const appBlob = buildAppBlobFromParams(params);
378
+ let candidateUrl = plainUrl;
379
+ if (themeBlob || appBlob) {
380
+ const c = yield (0, import_configEncoding.encodeConfigParams)(__spreadValues(__spreadValues({
381
+ v: import_configEncoding.ENCODED_CONFIG_VERSION
382
+ }, themeBlob && { theme: themeBlob }), appBlob && { app: appBlob }));
383
+ if (c) {
384
+ const encodedParams = __spreadProps(__spreadValues({}, withoutConfigParams(params)), { c });
385
+ candidateUrl = (0, import_url.constructUrl)({ base, path, params: encodedParams });
386
+ }
387
+ }
388
+ if (opts.shorten || candidateUrl.length > SHORTEN_THRESHOLD) {
389
+ const shortUrl = yield (0, import_url.shortenUrl)(__privateGet(this, _paraCoreInterface).ctx, candidateUrl, shouldUseLegacyPortalUrl);
390
+ return { url: shortUrl, fullUrl: candidateUrl };
391
+ }
392
+ return { url: candidateUrl, fullUrl: candidateUrl };
306
393
  });
307
394
  this.getLoginUrl = (_0) => __async(this, [_0], function* ({ authMethod = "PASSKEY", shorten = false, portalTheme, sessionId }) {
308
395
  if (!sessionId) {
@@ -332,7 +419,12 @@ class PortalUrlService {
332
419
  portalTheme
333
420
  });
334
421
  });
335
- this.getOAuthUrl = (_0) => __async(this, [_0], function* ({
422
+ this.getOAuthUrl = (params) => __async(this, null, function* () {
423
+ return (0, import_tracer.wrapWithSpan)("auth.get_oauth_url", () => __privateGet(this, _getOAuthUrlImpl).call(this, params), {
424
+ "oauth.method": params.method
425
+ });
426
+ });
427
+ __privateAdd(this, _getOAuthUrlImpl, (_0) => __async(this, [_0], function* ({
336
428
  method,
337
429
  appScheme,
338
430
  accountLinkInProgress,
@@ -374,7 +466,7 @@ class PortalUrlService {
374
466
  linkedAccountId: __privateGet(this, _paraCoreInterface).accountLinkInProgress.id
375
467
  } : {}), callback && { callback })
376
468
  });
377
- });
469
+ }));
378
470
  __privateSet(this, _paraCoreInterface, paraCore.getPortalUrlServiceInterface());
379
471
  }
380
472
  }
@@ -383,6 +475,7 @@ _pregenWalletService = new WeakMap();
383
475
  _sessionManagementService = new WeakMap();
384
476
  _walletService = new WeakMap();
385
477
  _paraCoreInterface = new WeakMap();
478
+ _getOAuthUrlImpl = new WeakMap();
386
479
  // Annotate the CommonJS export names for ESM import in node:
387
480
  0 && (module.exports = {
388
481
  PortalUrlService