@getpara/core-sdk 3.0.0-alpha.0 → 3.0.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 +15 -8
  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 +46 -26
  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/config.js +15 -0
  21. package/dist/cjs/telemetry/init.js +185 -0
  22. package/dist/cjs/telemetry/modalSession.js +54 -0
  23. package/dist/cjs/telemetry/session.js +39 -0
  24. package/dist/cjs/telemetry/tracer.js +126 -0
  25. package/dist/cjs/telemetry/uxAction.js +30 -0
  26. package/dist/cjs/telemetry/uxBaggagePropagator.js +58 -0
  27. package/dist/cjs/telemetry/uxState.js +46 -0
  28. package/dist/cjs/telemetry/uxStateSpanProcessor.js +51 -0
  29. package/dist/cjs/utils/configEncoding.js +98 -0
  30. package/dist/cjs/utils/deprecation.js +13 -13
  31. package/dist/cjs/utils/formatting.js +5 -0
  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 +15 -8
  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 +46 -26
  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/config.js +0 -0
  57. package/dist/esm/telemetry/init.js +118 -0
  58. package/dist/esm/telemetry/modalSession.js +29 -0
  59. package/dist/esm/telemetry/session.js +16 -0
  60. package/dist/esm/telemetry/tracer.js +84 -0
  61. package/dist/esm/telemetry/uxAction.js +8 -0
  62. package/dist/esm/telemetry/uxBaggagePropagator.js +35 -0
  63. package/dist/esm/telemetry/uxState.js +21 -0
  64. package/dist/esm/telemetry/uxStateSpanProcessor.js +28 -0
  65. package/dist/esm/utils/configEncoding.js +45 -0
  66. package/dist/esm/utils/deprecation.js +11 -12
  67. package/dist/esm/utils/formatting.js +4 -0
  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/config.d.ts +4 -0
  87. package/dist/types/telemetry/init.d.ts +17 -0
  88. package/dist/types/telemetry/modalSession.d.ts +5 -0
  89. package/dist/types/telemetry/session.d.ts +2 -0
  90. package/dist/types/telemetry/tracer.d.ts +10 -0
  91. package/dist/types/telemetry/uxAction.d.ts +3 -0
  92. package/dist/types/telemetry/uxBaggagePropagator.d.ts +7 -0
  93. package/dist/types/telemetry/uxState.d.ts +8 -0
  94. package/dist/types/telemetry/uxStateSpanProcessor.d.ts +9 -0
  95. package/dist/types/types/config.d.ts +15 -3
  96. package/dist/types/types/coreApi.d.ts +7 -9
  97. package/dist/types/types/serviceInterfaces.d.ts +5 -3
  98. package/dist/types/types/util.d.ts +2 -15
  99. package/dist/types/utils/configEncoding.d.ts +51 -0
  100. package/dist/types/utils/deprecation.d.ts +3 -1
  101. package/dist/types/utils/formatting.d.ts +1 -0
  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 +14 -4
@@ -40,6 +40,7 @@ __export(enclave_exports, {
40
40
  EnclaveClient: () => EnclaveClient
41
41
  });
42
42
  module.exports = __toCommonJS(enclave_exports);
43
+ var import_tracer = require("../telemetry/tracer.js");
43
44
  class EnclaveClient {
44
45
  constructor({
45
46
  userManagementClient,
@@ -211,40 +212,59 @@ ${exportedAsBase64}
211
212
  * Persist key shares to the enclave
212
213
  * @param shares Array of share data to persist
213
214
  */
215
+ // enclave.persist_shares wraps the encrypt + POST /enclave/key-shares pair so
216
+ // both the (CPU-bound) ECIES encryption and the network call show up under a
217
+ // named parent in the trace. Encryption can dominate the wall time so it's
218
+ // worth spelling out separately from the POST itself.
214
219
  persistShares(shares) {
215
220
  return __async(this, null, function* () {
216
- const payload = {
217
- shares,
218
- jwt: this.retrieveJwt()
219
- };
220
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
221
- const encryptedPayloadStr = JSON.stringify(encryptedPayload);
222
- return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
221
+ return (0, import_tracer.wrapWithSpan)(
222
+ "enclave.persist_shares",
223
+ () => __async(this, null, function* () {
224
+ const payload = {
225
+ shares,
226
+ jwt: this.retrieveJwt()
227
+ };
228
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
229
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
230
+ return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
231
+ }),
232
+ { "enclave.share_count": shares.length }
233
+ );
223
234
  });
224
235
  }
225
236
  /**
226
237
  * Retrieve key shares from the enclave
227
238
  * @param query Query parameters for finding shares (single query or array of queries)
228
239
  */
240
+ // enclave.retrieve_shares wraps the JWT issue + ECDH keypair gen + GET
241
+ // /enclave/key-shares + decrypt pipeline. The decrypt step can be slow on
242
+ // many-share accounts so a named span makes that latency easy to spot.
229
243
  retrieveShares(query) {
230
244
  return __async(this, null, function* () {
231
- yield this.issueEnclaveJwt();
232
- const frontendKeyPair = yield this.generateFrontendKeyPair();
233
- const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
234
- const fullQuery = query.map((q) => ({
235
- userId: q.userId
236
- }));
237
- const payload = {
238
- query: fullQuery,
239
- responsePublicKey: responsePublicKeyPEM,
240
- jwt: this.retrieveJwt()
241
- };
242
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
243
- const encryptedPayloadStr = JSON.stringify(encryptedPayload);
244
- const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
245
- const encryptedResponse = JSON.parse(response.payload);
246
- const decryptedData = yield this.decryptForFrontend(encryptedResponse);
247
- return decryptedData.shares;
245
+ return (0, import_tracer.wrapWithSpan)(
246
+ "enclave.retrieve_shares",
247
+ () => __async(this, null, function* () {
248
+ yield this.issueEnclaveJwt();
249
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
250
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
251
+ const fullQuery = query.map((q) => ({
252
+ userId: q.userId
253
+ }));
254
+ const payload = {
255
+ query: fullQuery,
256
+ responsePublicKey: responsePublicKeyPEM,
257
+ jwt: this.retrieveJwt()
258
+ };
259
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
260
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
261
+ const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
262
+ const encryptedResponse = JSON.parse(response.payload);
263
+ const decryptedData = yield this.decryptForFrontend(encryptedResponse);
264
+ return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
265
+ }),
266
+ { "enclave.query_count": query.length }
267
+ );
248
268
  });
249
269
  }
250
270
  deleteShares() {
@@ -286,13 +306,13 @@ ${exportedAsBase64}
286
306
  };
287
307
  const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
288
308
  const encryptedPayloadStr = JSON.stringify(encryptedPayload);
289
- const response = yield this.userManagementClient.getPregenShares(encryptedPayloadStr);
309
+ const response = yield this.userManagementClient.getPregenShares(encryptedPayloadStr, query.walletIds);
290
310
  if (!response.payload) {
291
311
  return [];
292
312
  }
293
313
  const encryptedResponse = JSON.parse(response.payload);
294
314
  const decryptedData = yield this.decryptForFrontend(encryptedResponse);
295
- return decryptedData.shares;
315
+ return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
296
316
  } catch (error) {
297
317
  throw new Error(
298
318
  `Failed to retrieve pregen shares for user ${query.userId}: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -115,7 +115,7 @@ const _CoreStateManager = class _CoreStateManager {
115
115
  * Extracts all data needed by UI consumers from authStateResult.
116
116
  */
117
117
  computeAuthStateInfo(authContext, walletContext) {
118
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
118
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
119
119
  const defaultAuthStateInfo = {
120
120
  userId: null,
121
121
  isPasskeySupported: false,
@@ -133,6 +133,9 @@ const _CoreStateManager = class _CoreStateManager {
133
133
  passkeyId: null,
134
134
  verificationUrl: null,
135
135
  verificationFullUrl: null,
136
+ deliveryChannel: null,
137
+ fallbackUsed: false,
138
+ fallbackChannel: null,
136
139
  externalWalletVerification: null,
137
140
  recoverySecret: null,
138
141
  isNewUser: false
@@ -172,6 +175,9 @@ const _CoreStateManager = class _CoreStateManager {
172
175
  let verificationFullUrl = null;
173
176
  let passkeyHints = null;
174
177
  let passkeyId = null;
178
+ let deliveryChannel = null;
179
+ let fallbackUsed = false;
180
+ let fallbackChannel = null;
175
181
  if (stage === "login") {
176
182
  const loginState = authStateResult;
177
183
  const authMethods = (_j = loginState.loginAuthMethods) != null ? _j : [];
@@ -205,6 +211,9 @@ const _CoreStateManager = class _CoreStateManager {
205
211
  const verifyState = authStateResult;
206
212
  verificationUrl = (_C = verifyState.loginUrl) != null ? _C : null;
207
213
  verificationFullUrl = (_D = verifyState.loginFullUrl) != null ? _D : null;
214
+ deliveryChannel = (_E = verifyState.deliveryChannel) != null ? _E : null;
215
+ fallbackUsed = (_F = verifyState.fallbackUsed) != null ? _F : false;
216
+ fallbackChannel = (_G = verifyState.fallbackChannel) != null ? _G : null;
208
217
  }
209
218
  return {
210
219
  userId,
@@ -223,10 +232,13 @@ const _CoreStateManager = class _CoreStateManager {
223
232
  passkeyId,
224
233
  verificationUrl,
225
234
  verificationFullUrl,
235
+ deliveryChannel,
236
+ fallbackUsed,
237
+ fallbackChannel,
226
238
  externalWalletVerification: externalWalletVerification ? {
227
- signatureVerificationMessage: (_E = externalWalletVerification.signatureVerificationMessage) != null ? _E : "",
228
- walletAddress: (_G = (_F = externalWalletVerification.externalWallet) == null ? void 0 : _F.address) != null ? _G : "",
229
- walletType: (_I = (_H = externalWalletVerification.externalWallet) == null ? void 0 : _H.type) != null ? _I : ""
239
+ signatureVerificationMessage: (_H = externalWalletVerification.signatureVerificationMessage) != null ? _H : "",
240
+ walletAddress: (_J = (_I = externalWalletVerification.externalWallet) == null ? void 0 : _I.address) != null ? _J : "",
241
+ walletType: (_L = (_K = externalWalletVerification.externalWallet) == null ? void 0 : _K.type) != null ? _L : ""
230
242
  } : null,
231
243
  recoverySecret,
232
244
  isNewUser
@@ -288,7 +300,7 @@ const _CoreStateManager = class _CoreStateManager {
288
300
  }
289
301
  authStateInfoEqual(a, b) {
290
302
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
291
- return a.userId === b.userId && a.isPasskeySupported === b.isPasskeySupported && a.hasPasskey === b.hasPasskey && a.hasPassword === b.hasPassword && a.hasPin === b.hasPin && a.passkeyUrl === b.passkeyUrl && a.passkeyFullUrl === b.passkeyFullUrl && a.passkeyKnownDeviceUrl === b.passkeyKnownDeviceUrl && a.passwordUrl === b.passwordUrl && a.passwordFullUrl === b.passwordFullUrl && a.pinUrl === b.pinUrl && a.pinFullUrl === b.pinFullUrl && a.passkeyId === b.passkeyId && a.verificationUrl === b.verificationUrl && a.verificationFullUrl === b.verificationFullUrl && a.recoverySecret === b.recoverySecret && a.isNewUser === b.isNewUser && ((_a = a.externalWalletVerification) == null ? void 0 : _a.signatureVerificationMessage) === ((_b = b.externalWalletVerification) == null ? void 0 : _b.signatureVerificationMessage) && ((_c = a.externalWalletVerification) == null ? void 0 : _c.walletAddress) === ((_d = b.externalWalletVerification) == null ? void 0 : _d.walletAddress) && ((_e = a.externalWalletVerification) == null ? void 0 : _e.walletType) === ((_f = b.externalWalletVerification) == null ? void 0 : _f.walletType) && ((_g = a.passkeyHints) == null ? void 0 : _g.length) === ((_h = b.passkeyHints) == null ? void 0 : _h.length) && ((_i = a.passkeyHints) != null ? _i : []).every(
303
+ return a.userId === b.userId && a.isPasskeySupported === b.isPasskeySupported && a.hasPasskey === b.hasPasskey && a.hasPassword === b.hasPassword && a.hasPin === b.hasPin && a.passkeyUrl === b.passkeyUrl && a.passkeyFullUrl === b.passkeyFullUrl && a.passkeyKnownDeviceUrl === b.passkeyKnownDeviceUrl && a.passwordUrl === b.passwordUrl && a.passwordFullUrl === b.passwordFullUrl && a.pinUrl === b.pinUrl && a.pinFullUrl === b.pinFullUrl && a.passkeyId === b.passkeyId && a.verificationUrl === b.verificationUrl && a.verificationFullUrl === b.verificationFullUrl && a.deliveryChannel === b.deliveryChannel && a.fallbackUsed === b.fallbackUsed && a.fallbackChannel === b.fallbackChannel && a.recoverySecret === b.recoverySecret && a.isNewUser === b.isNewUser && ((_a = a.externalWalletVerification) == null ? void 0 : _a.signatureVerificationMessage) === ((_b = b.externalWalletVerification) == null ? void 0 : _b.signatureVerificationMessage) && ((_c = a.externalWalletVerification) == null ? void 0 : _c.walletAddress) === ((_d = b.externalWalletVerification) == null ? void 0 : _d.walletAddress) && ((_e = a.externalWalletVerification) == null ? void 0 : _e.walletType) === ((_f = b.externalWalletVerification) == null ? void 0 : _f.walletType) && ((_g = a.passkeyHints) == null ? void 0 : _g.length) === ((_h = b.passkeyHints) == null ? void 0 : _h.length) && ((_i = a.passkeyHints) != null ? _i : []).every(
292
304
  (hint, i) => hint.useragent === b.passkeyHints[i].useragent && hint.aaguid === b.passkeyHints[i].aaguid
293
305
  );
294
306
  }
@@ -42,7 +42,10 @@ __export(setupPara_exports, {
42
42
  module.exports = __toCommonJS(setupPara_exports);
43
43
  var import_xstate = require("xstate");
44
44
  const createSetupParaActor = (paraCoreInterface) => (0, import_xstate.fromPromise)(() => __async(void 0, null, function* () {
45
- yield paraCoreInterface.setup();
45
+ const eagerPartnerLoad = paraCoreInterface.isPortal() ? Promise.resolve() : paraCoreInterface.sessionManagementService.touchSession().catch((e) => {
46
+ paraCoreInterface.devLog("setupPara: eager partner load via touchSession failed; will retry lazily", e);
47
+ });
48
+ yield Promise.all([paraCoreInterface.setup(), eagerPartnerLoad]);
46
49
  }));
47
50
  // Annotate the CommonJS export names for ESM import in node:
48
51
  0 && (module.exports = {
@@ -215,6 +215,28 @@ function createWalletStateMachine(paraCoreInterface) {
215
215
  ]
216
216
  },
217
217
  needs_wallets: {
218
+ // `needs_wallets` is otherwise a passive state that waits for the consumer
219
+ // to dispatch `WAIT_FOR_WALLET_CREATION`. That contract is fine for
220
+ // `isNewUser` reaching this state without auto-create (`checking_wallet_state`
221
+ // guard at line ~127), but it traps existing users who landed here via
222
+ // `waiting_for_wallets` COMPLETE with `needsWallet=true` — i.e., an
223
+ // authenticated user whose wallets don't satisfy the partner's
224
+ // `supportedWalletTypes` (e.g. EVM-only user logging into a Solana-only
225
+ // partner). Their auth flow set `shouldAutoCreateWallets: true` via
226
+ // `authenticateWithOAuth` / `authenticateWithEmailOrPhone`, but the
227
+ // existing `claiming_wallets` guard requires `isNewUser ||
228
+ // shouldClaimGuestWallets`, neither of which is true for them, so
229
+ // auto-create silently never happens.
230
+ //
231
+ // When `shouldAutoCreate` is true, route directly to `creating_wallets`.
232
+ // `createWalletPerType` is partner-aware via `#getMissingTypes`, so it
233
+ // provisions exactly the missing required types (no duplicates).
234
+ always: [
235
+ {
236
+ target: "creating_wallets",
237
+ guard: "shouldAutoCreate"
238
+ }
239
+ ],
218
240
  on: {
219
241
  WAIT_FOR_WALLET_CREATION: {
220
242
  target: "claiming_wallets",
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var config_exports = {};
15
+ module.exports = __toCommonJS(config_exports);
@@ -0,0 +1,185 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+ var init_exports = {};
63
+ __export(init_exports, {
64
+ __resetTelemetryForTests: () => __resetTelemetryForTests,
65
+ flushTelemetry: () => flushTelemetry,
66
+ initTelemetry: () => initTelemetry,
67
+ isTelemetryInitialized: () => isTelemetryInitialized,
68
+ onTelemetryReady: () => onTelemetryReady
69
+ });
70
+ module.exports = __toCommonJS(init_exports);
71
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
72
+ var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
73
+ var import_resources = require("@opentelemetry/resources");
74
+ var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
75
+ var import_api = require("@opentelemetry/api");
76
+ var import_core = require("@opentelemetry/core");
77
+ var import_uxStateSpanProcessor = require("./uxStateSpanProcessor.js");
78
+ var import_uxBaggagePropagator = require("./uxBaggagePropagator.js");
79
+ let initialized = false;
80
+ let tracerProvider;
81
+ const readyCallbacks = [];
82
+ function onTelemetryReady(cb) {
83
+ if (initialized) {
84
+ cb();
85
+ return;
86
+ }
87
+ readyCallbacks.push(cb);
88
+ }
89
+ function initTelemetry(opts) {
90
+ return __async(this, null, function* () {
91
+ if (initialized) return;
92
+ initialized = true;
93
+ const isWeb = opts.sdkType === "WEB" && typeof window !== "undefined";
94
+ if (isWeb && !opts.isPortal) {
95
+ try {
96
+ const { ZoneContextManager } = yield import("@opentelemetry/context-zone");
97
+ const zoneManager = new ZoneContextManager().enable();
98
+ import_api.context.setGlobalContextManager(zoneManager);
99
+ } catch (e) {
100
+ }
101
+ }
102
+ const resource = (0, import_resources.resourceFromAttributes)(__spreadValues(__spreadValues({
103
+ [import_semantic_conventions.ATTR_SERVICE_NAME]: opts.isPortal ? "para-portal" : "para-sdk",
104
+ [import_semantic_conventions.ATTR_SERVICE_VERSION]: opts.sdkVersion,
105
+ "para.platform": opts.sdkType
106
+ }, opts.partnerId ? { "para.partner_id": opts.partnerId } : {}), opts.resourceAttributes));
107
+ const exporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
108
+ url: opts.tunnelUrl
109
+ // No auth header — the tunnel is a dumb proxy. Per-IP rate limit + body cap on the
110
+ // BE side keep abuse contained.
111
+ });
112
+ const sampler = new import_sdk_trace_base.TraceIdRatioBasedSampler(Math.max(0, Math.min(1, opts.sampleRate)));
113
+ tracerProvider = new import_sdk_trace_base.BasicTracerProvider({
114
+ resource,
115
+ sampler,
116
+ spanProcessors: [new import_uxStateSpanProcessor.UxStateSpanProcessor(), new import_sdk_trace_base.BatchSpanProcessor(exporter)]
117
+ });
118
+ import_api.trace.setGlobalTracerProvider(tracerProvider);
119
+ import_api.propagation.setGlobalPropagator(
120
+ new import_core.CompositePropagator({
121
+ propagators: [new import_core.W3CTraceContextPropagator(), new import_uxBaggagePropagator.UxBaggagePropagator()]
122
+ })
123
+ );
124
+ if (isWeb) {
125
+ try {
126
+ const [{ registerInstrumentations }, { FetchInstrumentation }, { XMLHttpRequestInstrumentation }] = yield Promise.all([
127
+ import("@opentelemetry/instrumentation"),
128
+ import("@opentelemetry/instrumentation-fetch"),
129
+ import("@opentelemetry/instrumentation-xml-http-request")
130
+ ]);
131
+ const propagateTraceHeaderCorsUrls = [
132
+ /^https?:\/\/api\.[^/]*getpara\.com/,
133
+ /^https?:\/\/api\.[^/]*usecapsule\.com/
134
+ ];
135
+ if (opts.isDev) {
136
+ propagateTraceHeaderCorsUrls.push(/^https?:\/\/localhost/);
137
+ }
138
+ registerInstrumentations({
139
+ // Both fetch and XHR are instrumented because axios uses XHR by default in
140
+ // the browser and `window.fetch` for first-party SDK code paths that opt in.
141
+ // Without XHR instrumentation, axios calls don't produce client spans AND
142
+ // Zone-tracked traceparent injection through our manual interceptor isn't
143
+ // always reliable on native async/await — the auto-instrumentation handles
144
+ // both span creation and W3C propagation in one pass.
145
+ instrumentations: [
146
+ new FetchInstrumentation({ propagateTraceHeaderCorsUrls }),
147
+ new XMLHttpRequestInstrumentation({ propagateTraceHeaderCorsUrls })
148
+ ]
149
+ });
150
+ } catch (e) {
151
+ }
152
+ }
153
+ while (readyCallbacks.length) {
154
+ const cb = readyCallbacks.shift();
155
+ try {
156
+ cb();
157
+ } catch (e) {
158
+ }
159
+ }
160
+ });
161
+ }
162
+ function isTelemetryInitialized() {
163
+ return initialized;
164
+ }
165
+ function flushTelemetry() {
166
+ return __async(this, null, function* () {
167
+ if (!tracerProvider) return;
168
+ try {
169
+ yield tracerProvider.forceFlush();
170
+ } catch (e) {
171
+ }
172
+ });
173
+ }
174
+ function __resetTelemetryForTests() {
175
+ initialized = false;
176
+ tracerProvider = void 0;
177
+ }
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ __resetTelemetryForTests,
181
+ flushTelemetry,
182
+ initTelemetry,
183
+ isTelemetryInitialized,
184
+ onTelemetryReady
185
+ });
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var modalSession_exports = {};
19
+ __export(modalSession_exports, {
20
+ __resetModalSessionForTests: () => __resetModalSessionForTests,
21
+ endModalSession: () => endModalSession,
22
+ getModalSessionContext: () => getModalSessionContext,
23
+ startModalSession: () => startModalSession
24
+ });
25
+ module.exports = __toCommonJS(modalSession_exports);
26
+ var import_api = require("@opentelemetry/api");
27
+ const TRACER_NAME = "para-sdk";
28
+ let activeSpan;
29
+ let activeCtx;
30
+ function startModalSession() {
31
+ if (activeSpan) return;
32
+ activeSpan = import_api.trace.getTracer(TRACER_NAME).startSpan("ui.modal.session");
33
+ activeCtx = import_api.trace.setSpan(import_api.context.active(), activeSpan);
34
+ }
35
+ function endModalSession() {
36
+ activeSpan == null ? void 0 : activeSpan.end();
37
+ activeSpan = void 0;
38
+ activeCtx = void 0;
39
+ }
40
+ function getModalSessionContext() {
41
+ return activeCtx;
42
+ }
43
+ function __resetModalSessionForTests() {
44
+ activeSpan == null ? void 0 : activeSpan.end();
45
+ activeSpan = void 0;
46
+ activeCtx = void 0;
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ __resetModalSessionForTests,
51
+ endModalSession,
52
+ getModalSessionContext,
53
+ startModalSession
54
+ });
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var session_exports = {};
19
+ __export(session_exports, {
20
+ __resetSessionForTests: () => __resetSessionForTests,
21
+ getOrCreateSessionId: () => getOrCreateSessionId
22
+ });
23
+ module.exports = __toCommonJS(session_exports);
24
+ var import_uuid = require("uuid");
25
+ let sessionId;
26
+ function getOrCreateSessionId() {
27
+ if (!sessionId) {
28
+ sessionId = (0, import_uuid.v4)();
29
+ }
30
+ return sessionId;
31
+ }
32
+ function __resetSessionForTests() {
33
+ sessionId = void 0;
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ __resetSessionForTests,
38
+ getOrCreateSessionId
39
+ });
@@ -0,0 +1,126 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __async = (__this, __arguments, generator) => {
19
+ return new Promise((resolve, reject) => {
20
+ var fulfilled = (value) => {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ };
27
+ var rejected = (value) => {
28
+ try {
29
+ step(generator.throw(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ };
34
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
+ step((generator = generator.apply(__this, __arguments)).next());
36
+ });
37
+ };
38
+ var tracer_exports = {};
39
+ __export(tracer_exports, {
40
+ SpanStatusCode: () => import_api2.SpanStatusCode,
41
+ extractTraceContextFromUrl: () => extractTraceContextFromUrl,
42
+ getDefaultParentContext: () => getDefaultParentContext,
43
+ getTracer: () => getTracer,
44
+ getUrlTraceCarrier: () => getUrlTraceCarrier,
45
+ setDefaultParentContext: () => setDefaultParentContext,
46
+ wrapWithSpan: () => wrapWithSpan,
47
+ wrapWithSpanInContext: () => wrapWithSpanInContext
48
+ });
49
+ module.exports = __toCommonJS(tracer_exports);
50
+ var import_api = require("@opentelemetry/api");
51
+ var import_modalSession = require("./modalSession.js");
52
+ var import_api2 = require("@opentelemetry/api");
53
+ const TRACER_NAME = "para-sdk";
54
+ function getTracer() {
55
+ return import_api.trace.getTracer(TRACER_NAME);
56
+ }
57
+ let defaultParentContext;
58
+ function setDefaultParentContext(ctx) {
59
+ defaultParentContext = ctx;
60
+ }
61
+ function getDefaultParentContext() {
62
+ return defaultParentContext;
63
+ }
64
+ function wrapWithSpan(name, fn, attributes) {
65
+ return __async(this, null, function* () {
66
+ var _a, _b;
67
+ const active = import_api.context.active();
68
+ const activeSpan = import_api.trace.getSpan(active);
69
+ const parentCtx = activeSpan ? active : (_b = (_a = (0, import_modalSession.getModalSessionContext)()) != null ? _a : defaultParentContext) != null ? _b : active;
70
+ return import_api.context.with(
71
+ parentCtx,
72
+ () => getTracer().startActiveSpan(name, { attributes }, (span) => __async(this, null, function* () {
73
+ try {
74
+ const result = yield fn(span);
75
+ return result;
76
+ } catch (err) {
77
+ span.recordException(err);
78
+ span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: err.message });
79
+ throw err;
80
+ } finally {
81
+ span.end();
82
+ }
83
+ }))
84
+ );
85
+ });
86
+ }
87
+ function extractTraceContextFromUrl(search) {
88
+ return import_api.propagation.extract(import_api.context.active(), getUrlTraceCarrier(search));
89
+ }
90
+ function getUrlTraceCarrier(search) {
91
+ const url = search != null ? search : typeof window !== "undefined" ? window.location.search : "";
92
+ const params = new URLSearchParams(url);
93
+ const carrier = {};
94
+ const tp = params.get("traceparent");
95
+ const ts = params.get("tracestate");
96
+ if (tp) carrier.traceparent = tp;
97
+ if (ts) carrier.tracestate = ts;
98
+ return carrier;
99
+ }
100
+ function wrapWithSpanInContext(parentContext, name, fn) {
101
+ return __async(this, null, function* () {
102
+ return import_api.context.with(
103
+ parentContext,
104
+ () => wrapWithSpan(name, (span) => {
105
+ const traceHeaders = {};
106
+ import_api.propagation.inject(import_api.context.active(), traceHeaders, {
107
+ set: (carrier, key, value) => {
108
+ carrier[key] = value;
109
+ }
110
+ });
111
+ return fn(span, traceHeaders);
112
+ })
113
+ );
114
+ });
115
+ }
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ SpanStatusCode,
119
+ extractTraceContextFromUrl,
120
+ getDefaultParentContext,
121
+ getTracer,
122
+ getUrlTraceCarrier,
123
+ setDefaultParentContext,
124
+ wrapWithSpan,
125
+ wrapWithSpanInContext
126
+ });
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var uxAction_exports = {};
19
+ __export(uxAction_exports, {
20
+ recordActionOnSpan: () => recordActionOnSpan
21
+ });
22
+ module.exports = __toCommonJS(uxAction_exports);
23
+ function recordActionOnSpan(span, targetId, outcome) {
24
+ span.setAttribute("ui.target_id", targetId);
25
+ span.setAttribute("ui.outcome", outcome);
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ recordActionOnSpan
30
+ });