@turnkey/core 1.11.0 → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/__clients__/core.d.ts.map +1 -1
  2. package/dist/__clients__/core.js +32 -107
  3. package/dist/__clients__/core.js.map +1 -1
  4. package/dist/__clients__/core.mjs +34 -109
  5. package/dist/__clients__/core.mjs.map +1 -1
  6. package/dist/__generated__/sdk-client-base.d.ts +29 -0
  7. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  8. package/dist/__generated__/sdk-client-base.js +106 -38
  9. package/dist/__generated__/sdk-client-base.js.map +1 -1
  10. package/dist/__generated__/sdk-client-base.mjs +106 -38
  11. package/dist/__generated__/sdk-client-base.mjs.map +1 -1
  12. package/dist/__generated__/version.d.ts +1 -1
  13. package/dist/__generated__/version.js +1 -1
  14. package/dist/__generated__/version.mjs +1 -1
  15. package/dist/__stampers__/api/base.d.ts +0 -1
  16. package/dist/__stampers__/api/base.d.ts.map +1 -1
  17. package/dist/__stampers__/api/base.js +0 -6
  18. package/dist/__stampers__/api/base.js.map +1 -1
  19. package/dist/__stampers__/api/base.mjs +0 -6
  20. package/dist/__stampers__/api/base.mjs.map +1 -1
  21. package/dist/__stampers__/api/mobile/stamper.d.ts +1 -1
  22. package/dist/__stampers__/api/mobile/stamper.d.ts.map +1 -1
  23. package/dist/__stampers__/api/mobile/stamper.js +41 -10
  24. package/dist/__stampers__/api/mobile/stamper.js.map +1 -1
  25. package/dist/__stampers__/api/mobile/stamper.mjs +41 -10
  26. package/dist/__stampers__/api/mobile/stamper.mjs.map +1 -1
  27. package/dist/__stampers__/api/web/stamper.d.ts +0 -1
  28. package/dist/__stampers__/api/web/stamper.d.ts.map +1 -1
  29. package/dist/__stampers__/api/web/stamper.js +0 -13
  30. package/dist/__stampers__/api/web/stamper.js.map +1 -1
  31. package/dist/__stampers__/api/web/stamper.mjs +0 -13
  32. package/dist/__stampers__/api/web/stamper.mjs.map +1 -1
  33. package/dist/__storage__/mobile/storage.js +1 -1
  34. package/dist/__storage__/mobile/storage.js.map +1 -1
  35. package/dist/__storage__/mobile/storage.mjs +1 -1
  36. package/dist/__storage__/mobile/storage.mjs.map +1 -1
  37. package/dist/__types__/auth.d.ts +0 -1
  38. package/dist/__types__/auth.d.ts.map +1 -1
  39. package/dist/__types__/external-wallets.d.ts +9 -1
  40. package/dist/__types__/external-wallets.d.ts.map +1 -1
  41. package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -1
  42. package/dist/__wallet__/web/native/ethereum.js +13 -5
  43. package/dist/__wallet__/web/native/ethereum.js.map +1 -1
  44. package/dist/__wallet__/web/native/ethereum.mjs +13 -5
  45. package/dist/__wallet__/web/native/ethereum.mjs.map +1 -1
  46. package/dist/__wallet__/web/native/solana.d.ts.map +1 -1
  47. package/dist/__wallet__/web/native/solana.js +17 -9
  48. package/dist/__wallet__/web/native/solana.js.map +1 -1
  49. package/dist/__wallet__/web/native/solana.mjs +17 -9
  50. package/dist/__wallet__/web/native/solana.mjs.map +1 -1
  51. package/dist/utils.d.ts +14 -1
  52. package/dist/utils.d.ts.map +1 -1
  53. package/dist/utils.js +46 -9
  54. package/dist/utils.js.map +1 -1
  55. package/dist/utils.mjs +46 -10
  56. package/dist/utils.mjs.map +1 -1
  57. package/package.json +9 -9
@@ -1533,7 +1533,7 @@ class TurnkeySDKClientBase {
1533
1533
  this.config.organizationId,
1534
1534
  timestampMs: timestampMs ?? String(Date.now()),
1535
1535
  type: "ACTIVITY_TYPE_CREATE_PRIVATE_KEYS_V2",
1536
- }, "createPrivateKeysResult", stampWith);
1536
+ }, "createPrivateKeysResultV2", stampWith);
1537
1537
  };
1538
1538
  this.stampCreatePrivateKeys = async (input, stampWith) => {
1539
1539
  const activeStamper = this.getStamper(stampWith);
@@ -1601,7 +1601,7 @@ class TurnkeySDKClientBase {
1601
1601
  this.config.organizationId,
1602
1602
  timestampMs: timestampMs ?? String(Date.now()),
1603
1603
  type: "ACTIVITY_TYPE_CREATE_READ_WRITE_SESSION_V2",
1604
- }, "createReadWriteSessionResult", stampWith);
1604
+ }, "createReadWriteSessionResultV2", stampWith);
1605
1605
  };
1606
1606
  this.stampCreateReadWriteSession = async (input, stampWith) => {
1607
1607
  const activeStamper = this.getStamper(stampWith);
@@ -1670,7 +1670,7 @@ class TurnkeySDKClientBase {
1670
1670
  this.config.organizationId,
1671
1671
  timestampMs: timestampMs ?? String(Date.now()),
1672
1672
  type: "ACTIVITY_TYPE_CREATE_SUB_ORGANIZATION_V7",
1673
- }, "createSubOrganizationResult", stampWith);
1673
+ }, "createSubOrganizationResultV7", stampWith);
1674
1674
  };
1675
1675
  this.stampCreateSubOrganization = async (input, stampWith) => {
1676
1676
  const activeStamper = this.getStamper(stampWith);
@@ -2794,7 +2794,7 @@ class TurnkeySDKClientBase {
2794
2794
  this.config.organizationId,
2795
2795
  timestampMs: timestampMs ?? String(Date.now()),
2796
2796
  type: "ACTIVITY_TYPE_INIT_OTP_AUTH_V3",
2797
- }, "initOtpAuthResult", stampWith);
2797
+ }, "initOtpAuthResultV2", stampWith);
2798
2798
  };
2799
2799
  this.stampInitOtpAuth = async (input, stampWith) => {
2800
2800
  const activeStamper = this.getStamper(stampWith);
@@ -3373,7 +3373,7 @@ class TurnkeySDKClientBase {
3373
3373
  this.config.organizationId,
3374
3374
  timestampMs: timestampMs ?? String(Date.now()),
3375
3375
  type: "ACTIVITY_TYPE_UPDATE_POLICY_V2",
3376
- }, "updatePolicyResult", stampWith);
3376
+ }, "updatePolicyResultV2", stampWith);
3377
3377
  };
3378
3378
  this.stampUpdatePolicy = async (input, stampWith) => {
3379
3379
  const activeStamper = this.getStamper(stampWith);
@@ -3805,10 +3805,57 @@ class TurnkeySDKClientBase {
3805
3805
  return this.apiKeyStamper;
3806
3806
  }
3807
3807
  }
3808
+ sleep(ms) {
3809
+ return new Promise((resolve) => setTimeout(resolve, ms));
3810
+ }
3811
+ /**
3812
+ * Poll for activity completion until terminal status or max retries.
3813
+ * @internal
3814
+ */
3815
+ async pollForCompletion(activityId, stampWith) {
3816
+ const pollingDuration = this.config.activityPoller?.intervalMs ?? 1000;
3817
+ const maxRetries = this.config.activityPoller?.numRetries ?? 3;
3818
+ let attempts = 0;
3819
+ let activityData;
3820
+ do {
3821
+ await this.sleep(pollingDuration);
3822
+ activityData = (await this.getActivity({ activityId }, stampWith));
3823
+ attempts++;
3824
+ } while (!TERMINAL_ACTIVITY_STATUSES.includes(activityData.activity.status) &&
3825
+ attempts < maxRetries);
3826
+ return activityData;
3827
+ }
3828
+ /**
3829
+ * Extract and flatten result fields from a completed activity response.
3830
+ * @internal
3831
+ */
3832
+ handleActivityResponse(activityData, resultKey) {
3833
+ const { result, status } = activityData.activity;
3834
+ if (status === "ACTIVITY_STATUS_COMPLETED" && result) {
3835
+ // If a specific resultKey was provided, use it
3836
+ if (resultKey && result[resultKey]) {
3837
+ return {
3838
+ ...result[resultKey],
3839
+ ...activityData,
3840
+ };
3841
+ }
3842
+ // Otherwise, try to find any result field and flatten it
3843
+ for (const key of Object.keys(result)) {
3844
+ if (key.endsWith("Result") && result[key]) {
3845
+ return {
3846
+ ...result[key],
3847
+ ...activityData,
3848
+ };
3849
+ }
3850
+ }
3851
+ }
3852
+ return activityData;
3853
+ }
3808
3854
  async request(url, body, stampWith) {
3809
3855
  const fullUrl = this.config.apiBaseUrl + url;
3810
3856
  const stringifiedBody = JSON.stringify(body);
3811
3857
  var headers = {
3858
+ "Content-Type": "application/json",
3812
3859
  "X-Client-Version": VERSION,
3813
3860
  };
3814
3861
  // Use the specified stamper for this request
@@ -3837,40 +3884,13 @@ class TurnkeySDKClientBase {
3837
3884
  return data;
3838
3885
  }
3839
3886
  async activity(url, body, resultKey, stampWith) {
3840
- const pollingDuration = this.config.activityPoller?.intervalMs ?? 1000;
3841
- const maxRetries = this.config.activityPoller?.numRetries ?? 3;
3842
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
3843
- const handleResponse = (activityData) => {
3844
- const { result, status } = activityData.activity;
3845
- if (status === "ACTIVITY_STATUS_COMPLETED") {
3846
- return {
3847
- ...result[`${resultKey}`],
3848
- ...activityData,
3849
- };
3850
- }
3851
- return activityData;
3852
- };
3853
- let attempts = 0;
3854
- const pollStatus = async (activityId) => {
3855
- const pollBody = { activityId };
3856
- // Pass the stampWith parameter to getActivity
3857
- const pollData = (await this.getActivity(pollBody, stampWith));
3858
- if (attempts > maxRetries) {
3859
- return handleResponse(pollData);
3860
- }
3861
- attempts += 1;
3862
- if (!TERMINAL_ACTIVITY_STATUSES.includes(pollData.activity.status)) {
3863
- await sleep(pollingDuration);
3864
- return pollStatus(activityId);
3865
- }
3866
- return handleResponse(pollData);
3867
- };
3868
- // Use the specified stamper for the initial request
3869
- const responseData = (await this.request(url, body, stampWith));
3870
- if (!TERMINAL_ACTIVITY_STATUSES.includes(responseData.activity.status)) {
3871
- return pollStatus(responseData.activity.id);
3887
+ // Make the initial request
3888
+ let activityData = await this.request(url, body, stampWith);
3889
+ // Poll if not in terminal status
3890
+ if (!TERMINAL_ACTIVITY_STATUSES.includes(activityData.activity.status)) {
3891
+ activityData = await this.pollForCompletion(activityData.activity.id, stampWith);
3872
3892
  }
3873
- return handleResponse(responseData);
3893
+ return this.handleActivityResponse(activityData, resultKey);
3874
3894
  }
3875
3895
  async activityDecision(url, body, stampWith) {
3876
3896
  // Use the specified stamper for this request
@@ -3908,6 +3928,54 @@ class TurnkeySDKClientBase {
3908
3928
  const data = await response.json();
3909
3929
  return data;
3910
3930
  }
3931
+ /**
3932
+ * Submit a pre-signed request to Turnkey.
3933
+ *
3934
+ * Use this method to execute any TSignedRequest returned by the SDK's
3935
+ * stamping methods (stampCreateApiKeys, stampGetPolicies, stampGetWallets, etc.).
3936
+ *
3937
+ * Works for both query and activity requests:
3938
+ * - For queries: returns the response directly
3939
+ * - For activities: automatically polls until completion and extracts the result
3940
+ *
3941
+ * @param signedRequest - A TSignedRequest object returned by a stamping method
3942
+ * @param options - Optional configuration for the request
3943
+ * @param options.resultKey - For activity requests, the key to extract from the result (e.g., "createApiKeysResultV2")
3944
+ * @returns The parsed response, with activity result fields flattened if applicable
3945
+ */
3946
+ async sendSignedRequest(signedRequest, options) {
3947
+ const headers = {
3948
+ "Content-Type": "application/json",
3949
+ "X-Client-Version": VERSION,
3950
+ [signedRequest.stamp.stampHeaderName]: signedRequest.stamp.stampHeaderValue,
3951
+ };
3952
+ const response = await fetch(signedRequest.url, {
3953
+ method: "POST",
3954
+ headers,
3955
+ body: signedRequest.body,
3956
+ });
3957
+ if (!response.ok) {
3958
+ let res;
3959
+ try {
3960
+ res = await response.json();
3961
+ }
3962
+ catch (_) {
3963
+ throw new Error(`${response.status} ${response.statusText}`);
3964
+ }
3965
+ throw new TurnkeyRequestError(res);
3966
+ }
3967
+ const data = await response.json();
3968
+ // Check if this is an activity response that needs polling
3969
+ if (data.activity) {
3970
+ let activityData = data;
3971
+ // Poll if not in terminal status
3972
+ if (!TERMINAL_ACTIVITY_STATUSES.includes(activityData.activity.status)) {
3973
+ activityData = await this.pollForCompletion(activityData.activity.id);
3974
+ }
3975
+ return this.handleActivityResponse(activityData, options?.resultKey);
3976
+ }
3977
+ return data;
3978
+ }
3911
3979
  }
3912
3980
 
3913
3981
  export { TurnkeySDKClientBase };