@paxoslabs/amplify-sdk 0.1.1 → 0.2.0-alpha.1

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 (53) hide show
  1. package/CHANGELOG.md +0 -2
  2. package/README.md +42 -0
  3. package/dist/{chunk-REKEQLQA.mjs → chunk-4ORV7PFT.mjs} +3 -3
  4. package/dist/{chunk-REKEQLQA.mjs.map → chunk-4ORV7PFT.mjs.map} +1 -1
  5. package/dist/{chunk-GS7TDQXA.js → chunk-76SRRIGW.js} +8 -8
  6. package/dist/{chunk-GS7TDQXA.js.map → chunk-76SRRIGW.js.map} +1 -1
  7. package/dist/{chunk-XXHRCCZS.mjs → chunk-AQFFMJX7.mjs} +3 -3
  8. package/dist/chunk-AQFFMJX7.mjs.map +1 -0
  9. package/dist/{chunk-B2QCI6ET.js → chunk-EWJDKRSY.js} +308 -30
  10. package/dist/chunk-EWJDKRSY.js.map +1 -0
  11. package/dist/{chunk-HI44AMLC.mjs → chunk-LJPJWJ2Y.mjs} +24 -19
  12. package/dist/chunk-LJPJWJ2Y.mjs.map +1 -0
  13. package/dist/{chunk-ITB7FXG4.js → chunk-OJOKPBK7.js} +3 -3
  14. package/dist/chunk-OJOKPBK7.js.map +1 -0
  15. package/dist/{chunk-KYR6BFAE.js → chunk-SMIA4ULA.js} +38 -33
  16. package/dist/chunk-SMIA4ULA.js.map +1 -0
  17. package/dist/{chunk-DTFLXAZJ.js → chunk-TF3S7T6P.js} +147 -5
  18. package/dist/chunk-TF3S7T6P.js.map +1 -0
  19. package/dist/{chunk-VIULRHK6.mjs → chunk-UURNMLRT.mjs} +3 -3
  20. package/dist/{chunk-VIULRHK6.mjs.map → chunk-UURNMLRT.mjs.map} +1 -1
  21. package/dist/{chunk-LSNRG5Z2.js → chunk-WWTNCRXX.js} +4 -4
  22. package/dist/{chunk-LSNRG5Z2.js.map → chunk-WWTNCRXX.js.map} +1 -1
  23. package/dist/{chunk-ZILA73XN.mjs → chunk-Y3QNUDV6.mjs} +144 -4
  24. package/dist/chunk-Y3QNUDV6.mjs.map +1 -0
  25. package/dist/{chunk-CUGK4ZBJ.mjs → chunk-YDMFT2R7.mjs} +304 -30
  26. package/dist/chunk-YDMFT2R7.mjs.map +1 -0
  27. package/dist/core.js +16 -16
  28. package/dist/core.js.map +1 -1
  29. package/dist/core.mjs +6 -6
  30. package/dist/core.mjs.map +1 -1
  31. package/dist/display.d.mts +1 -1
  32. package/dist/display.d.ts +1 -1
  33. package/dist/display.js +12 -12
  34. package/dist/display.mjs +4 -4
  35. package/dist/{exchange-rate-BfPH_fQt.d.mts → exchange-rate-DCB2CY9v.d.mts} +5 -0
  36. package/dist/{exchange-rate-Cp1ddpw4.d.ts → exchange-rate-DOmoqut9.d.ts} +5 -0
  37. package/dist/index.d.mts +456 -8
  38. package/dist/index.d.ts +456 -8
  39. package/dist/index.js +402 -215
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.mjs +292 -123
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/utils.js +5 -5
  44. package/dist/utils.mjs +2 -2
  45. package/package.json +2 -1
  46. package/dist/chunk-B2QCI6ET.js.map +0 -1
  47. package/dist/chunk-CUGK4ZBJ.mjs.map +0 -1
  48. package/dist/chunk-DTFLXAZJ.js.map +0 -1
  49. package/dist/chunk-HI44AMLC.mjs.map +0 -1
  50. package/dist/chunk-ITB7FXG4.js.map +0 -1
  51. package/dist/chunk-KYR6BFAE.js.map +0 -1
  52. package/dist/chunk-XXHRCCZS.mjs.map +0 -1
  53. package/dist/chunk-ZILA73XN.mjs.map +0 -1
@@ -1,29 +1,91 @@
1
1
  import { defineChain } from 'viem';
2
2
  import { swellchain, sei, plumeMainnet, form, boba, mainnet } from 'viem/chains';
3
3
 
4
- // src/types/amplify-sdk-api.ts
5
- var APIError = class _APIError extends Error {
6
- constructor(message, options) {
7
- super(message);
8
- this.name = "APIError";
9
- this.statusCode = options?.statusCode;
10
- this.endpoint = options?.endpoint;
11
- this.cause = options?.cause;
12
- if (Error.captureStackTrace) {
13
- Error.captureStackTrace(this, _APIError);
4
+ // src/types/telemetry.ts
5
+ var LogLevel = {
6
+ DEBUG: 0,
7
+ INFO: 1,
8
+ WARN: 2,
9
+ ERROR: 3,
10
+ NONE: 4
11
+ };
12
+
13
+ // src/lib/logger.ts
14
+ var ConsoleLogger = class {
15
+ constructor(level = LogLevel.ERROR) {
16
+ this.level = level;
17
+ }
18
+ /**
19
+ * Update log level
20
+ */
21
+ setLevel(level) {
22
+ this.level = level;
23
+ }
24
+ /**
25
+ * Get current log level
26
+ */
27
+ getLevel() {
28
+ return this.level;
29
+ }
30
+ debug(message, context) {
31
+ if (this.level <= LogLevel.DEBUG) {
32
+ if (context) {
33
+ console.debug("[Amplify SDK]", message, context);
34
+ } else {
35
+ console.debug("[Amplify SDK]", message);
36
+ }
37
+ }
38
+ }
39
+ info(message, context) {
40
+ if (this.level <= LogLevel.INFO) {
41
+ if (context) {
42
+ console.info("[Amplify SDK]", message, context);
43
+ } else {
44
+ console.info("[Amplify SDK]", message);
45
+ }
46
+ }
47
+ }
48
+ warn(message, context) {
49
+ if (this.level <= LogLevel.WARN) {
50
+ if (context) {
51
+ console.warn("[Amplify SDK]", message, context);
52
+ } else {
53
+ console.warn("[Amplify SDK]", message);
54
+ }
55
+ }
56
+ }
57
+ error(message, context) {
58
+ if (this.level <= LogLevel.ERROR) {
59
+ if (context) {
60
+ console.error("[Amplify SDK]", message, context);
61
+ } else {
62
+ console.error("[Amplify SDK]", message);
63
+ }
14
64
  }
15
65
  }
16
66
  };
17
- function isValidYieldType(value) {
18
- return typeof value === "string" && (value === "PRIME" || value === "TBILL" || value === "LENDING");
67
+ var currentLogger = new ConsoleLogger(LogLevel.ERROR);
68
+ var defaultLogger = currentLogger;
69
+ function setLogger(logger) {
70
+ currentLogger = logger;
19
71
  }
20
- function isValidAddress(value) {
21
- return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
72
+ function getLogger() {
73
+ return currentLogger;
22
74
  }
23
- function isValidChainId(value) {
24
- return typeof value === "number" && value > 0 && Number.isInteger(value);
75
+ function setLogLevel(level) {
76
+ if (defaultLogger && typeof defaultLogger.setLevel === "function") {
77
+ defaultLogger.setLevel(level);
78
+ }
25
79
  }
26
80
 
81
+ // src/constants/index.ts
82
+ var ATOMIC_QUEUE_CONTRACT_ADDRESS = "0x228c44bb4885c6633f4b6c83f14622f37d5112e5";
83
+ var DEFAULT_DEADLINE = 3;
84
+ var NATIVE_TOKEN_FOR_BRIDGE_FEE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
85
+ var CHAINLINK_ADDRESS = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
86
+ var DEFAULT_APPROVAL_AMOUNT = BigInt(2) ** BigInt(256) - BigInt(1);
87
+ var API_BASE_URL = "https://api.paxoslabs.com";
88
+
27
89
  // src/lib/vault-cache.ts
28
90
  var DEFAULT_TTL = 6e5;
29
91
  var VaultCache = class {
@@ -191,7 +253,6 @@ var VaultCache = class {
191
253
  };
192
254
 
193
255
  // src/api/amplify-sdk-client.ts
194
- var API_BASE_URL = "https://api.paxoslabs.com";
195
256
  var DEFAULT_TIMEOUT = 1e4;
196
257
  function createTimeoutSignal(timeoutMs) {
197
258
  const controller = new AbortController();
@@ -617,7 +678,8 @@ var sdkConfig = {
617
678
  isInitialized: false,
618
679
  initializedAt: null,
619
680
  isInitializing: false,
620
- initPromise: null
681
+ initPromise: null,
682
+ telemetryEnabled: true
621
683
  };
622
684
  var ERROR_MESSAGES = {
623
685
  INVALID_API_KEY: "Invalid API key format. Expected format: pxl_<type>_<string>",
@@ -650,6 +712,8 @@ function clearConfig() {
650
712
  sdkConfig.initializedAt = null;
651
713
  sdkConfig.isInitializing = false;
652
714
  sdkConfig.initPromise = null;
715
+ sdkConfig.telemetryEnabled = true;
716
+ resetTelemetry();
653
717
  }
654
718
  function getRequestHeaders() {
655
719
  const apiKey = getAPIKey();
@@ -661,7 +725,7 @@ function getRequestHeaders() {
661
725
  }
662
726
  return headers;
663
727
  }
664
- async function initAmplifySDK(apiKey) {
728
+ async function initAmplifySDK(apiKey, options) {
665
729
  validateAPIKey(apiKey);
666
730
  if (sdkConfig.isInitialized && sdkConfig.apiKey === apiKey) {
667
731
  return;
@@ -674,6 +738,13 @@ async function initAmplifySDK(apiKey) {
674
738
  clearConfig();
675
739
  clearCache();
676
740
  }
741
+ if (options?.logger) {
742
+ setLogger(options.logger);
743
+ }
744
+ if (options?.logLevel !== void 0) {
745
+ setLogLevel(options.logLevel);
746
+ }
747
+ sdkConfig.telemetryEnabled = options?.telemetry !== false;
677
748
  sdkConfig.isInitializing = true;
678
749
  sdkConfig.initPromise = (async () => {
679
750
  try {
@@ -682,6 +753,10 @@ async function initAmplifySDK(apiKey) {
682
753
  await cache.refresh();
683
754
  sdkConfig.isInitialized = true;
684
755
  sdkConfig.initializedAt = /* @__PURE__ */ new Date();
756
+ if (sdkConfig.telemetryEnabled) {
757
+ initTelemetry(apiKey).catch(() => {
758
+ });
759
+ }
685
760
  } catch (error) {
686
761
  clearConfig();
687
762
  clearCache();
@@ -699,6 +774,213 @@ async function initAmplifySDK(apiKey) {
699
774
  })();
700
775
  await sdkConfig.initPromise;
701
776
  }
777
+
778
+ // src/lib/telemetry.ts
779
+ var SDK_VERSION = "0.1.1-beta.1";
780
+ var MAX_ERROR_BUFFER_SIZE = 10;
781
+ var CONFIG_FETCH_TIMEOUT = 5e3;
782
+ var telemetryState = {
783
+ enabled: false,
784
+ isInitialized: false,
785
+ isInitializing: false,
786
+ initPromise: null,
787
+ config: null,
788
+ apiKey: null
789
+ };
790
+ var posthogClient = null;
791
+ var errorBuffer = [];
792
+ var bufferFullWarningLogged = false;
793
+ function createTimeoutSignal2(timeoutMs) {
794
+ const controller = new AbortController();
795
+ setTimeout(() => controller.abort(), timeoutMs);
796
+ return controller.signal;
797
+ }
798
+ function hashApiKey(apiKey) {
799
+ const FNV_OFFSET = BigInt("0xcbf29ce484222325");
800
+ const FNV_PRIME = BigInt("0x100000001b3");
801
+ let hash = FNV_OFFSET;
802
+ for (let i = 0; i < apiKey.length; i++) {
803
+ hash ^= BigInt(apiKey.charCodeAt(i));
804
+ hash = hash * FNV_PRIME & BigInt("0xffffffffffffffff");
805
+ }
806
+ return `sdk_${hash.toString(16).slice(0, 12)}`;
807
+ }
808
+ async function fetchTelemetryConfig(apiKey) {
809
+ const endpoint = "/v1/earn-sdk/config";
810
+ const url = `${API_BASE_URL}${endpoint}`;
811
+ try {
812
+ const headers = getRequestHeaders();
813
+ if (!headers["x-api-key"]) {
814
+ headers["x-api-key"] = apiKey;
815
+ }
816
+ const response = await fetch(url, {
817
+ method: "GET",
818
+ headers,
819
+ signal: createTimeoutSignal2(CONFIG_FETCH_TIMEOUT)
820
+ });
821
+ if (!response.ok) {
822
+ return null;
823
+ }
824
+ const data = await response.json();
825
+ if (!data || typeof data.posthogApiKey !== "string") {
826
+ return null;
827
+ }
828
+ return {
829
+ posthogApiKey: data.posthogApiKey,
830
+ posthogHost: data.posthogHost || "https://us.i.posthog.com"
831
+ };
832
+ } catch {
833
+ return null;
834
+ }
835
+ }
836
+ async function flushErrorBuffer() {
837
+ if (errorBuffer.length === 0 || !posthogClient) {
838
+ return;
839
+ }
840
+ for (const bufferedError of errorBuffer) {
841
+ const payload = {
842
+ error_type: bufferedError.name,
843
+ error_message: bufferedError.message,
844
+ error_code: bufferedError.code,
845
+ sdk_version: SDK_VERSION,
846
+ buffered: true,
847
+ ...bufferedError.context
848
+ };
849
+ posthogClient.capture("sdk_error", payload);
850
+ }
851
+ errorBuffer.length = 0;
852
+ }
853
+ async function initTelemetry(apiKey) {
854
+ if (telemetryState.isInitialized) {
855
+ return;
856
+ }
857
+ if (telemetryState.isInitializing && telemetryState.initPromise) {
858
+ await telemetryState.initPromise;
859
+ return;
860
+ }
861
+ telemetryState.isInitializing = true;
862
+ telemetryState.apiKey = apiKey;
863
+ telemetryState.initPromise = (async () => {
864
+ try {
865
+ const config = await fetchTelemetryConfig(apiKey);
866
+ if (!config) {
867
+ telemetryState.enabled = false;
868
+ telemetryState.isInitialized = true;
869
+ return;
870
+ }
871
+ telemetryState.config = config;
872
+ const posthogModule = await import('posthog-js');
873
+ const posthog = posthogModule.default;
874
+ posthog.init(config.posthogApiKey, {
875
+ api_host: config.posthogHost,
876
+ autocapture: false,
877
+ capture_pageview: false,
878
+ capture_pageleave: false,
879
+ disable_session_recording: true,
880
+ persistence: "memory",
881
+ // Don't persist to localStorage
882
+ loaded: (ph) => {
883
+ ph.identify(hashApiKey(apiKey));
884
+ }
885
+ });
886
+ posthogClient = posthog;
887
+ telemetryState.enabled = true;
888
+ telemetryState.isInitialized = true;
889
+ await flushErrorBuffer();
890
+ posthog.capture("sdk_initialized", {
891
+ sdk_version: SDK_VERSION
892
+ });
893
+ } catch (error) {
894
+ const logger = getLogger();
895
+ logger.warn("Telemetry initialization failed", {
896
+ error: error instanceof Error ? error.message : String(error)
897
+ });
898
+ telemetryState.enabled = false;
899
+ telemetryState.isInitialized = true;
900
+ } finally {
901
+ telemetryState.isInitializing = false;
902
+ telemetryState.initPromise = null;
903
+ }
904
+ })();
905
+ await telemetryState.initPromise;
906
+ }
907
+ function trackError(error, context) {
908
+ const logger = getLogger();
909
+ logger.error(error.message, {
910
+ name: error.name,
911
+ stack: error.stack,
912
+ ...context
913
+ });
914
+ const errorDetails = {
915
+ name: error.name,
916
+ message: error.message,
917
+ code: error.code,
918
+ context: context || {},
919
+ timestamp: Date.now()
920
+ };
921
+ if (!posthogClient || !telemetryState.enabled) {
922
+ if (errorBuffer.length < MAX_ERROR_BUFFER_SIZE) {
923
+ errorBuffer.push(errorDetails);
924
+ } else if (!bufferFullWarningLogged) {
925
+ logger.warn(
926
+ `Telemetry error buffer full (${MAX_ERROR_BUFFER_SIZE} errors). Additional errors will not be tracked until telemetry initializes.`
927
+ );
928
+ bufferFullWarningLogged = true;
929
+ }
930
+ return;
931
+ }
932
+ const payload = {
933
+ error_type: error.name,
934
+ error_message: error.message,
935
+ error_code: error.code,
936
+ endpoint: error.endpoint,
937
+ status_code: error.statusCode,
938
+ sdk_version: SDK_VERSION,
939
+ ...context
940
+ };
941
+ posthogClient.capture("sdk_error", payload);
942
+ }
943
+ function resetTelemetry() {
944
+ telemetryState.enabled = false;
945
+ telemetryState.isInitialized = false;
946
+ telemetryState.isInitializing = false;
947
+ telemetryState.initPromise = null;
948
+ telemetryState.config = null;
949
+ telemetryState.apiKey = null;
950
+ posthogClient = null;
951
+ errorBuffer.length = 0;
952
+ bufferFullWarningLogged = false;
953
+ }
954
+
955
+ // src/types/amplify-sdk-api.ts
956
+ var APIError = class _APIError extends Error {
957
+ constructor(message, options) {
958
+ super(message);
959
+ this.name = "APIError";
960
+ this.statusCode = options?.statusCode;
961
+ this.endpoint = options?.endpoint;
962
+ this.cause = options?.cause;
963
+ if (Error.captureStackTrace) {
964
+ Error.captureStackTrace(this, _APIError);
965
+ }
966
+ try {
967
+ trackError(this, {
968
+ endpoint: this.endpoint,
969
+ statusCode: this.statusCode
970
+ });
971
+ } catch {
972
+ }
973
+ }
974
+ };
975
+ function isValidYieldType(value) {
976
+ return typeof value === "string" && (value === "PRIME" || value === "TBILL" || value === "LENDING");
977
+ }
978
+ function isValidAddress(value) {
979
+ return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
980
+ }
981
+ function isValidChainId(value) {
982
+ return typeof value === "number" && value > 0 && Number.isInteger(value);
983
+ }
702
984
  var rari = defineChain({
703
985
  id: 1380012617,
704
986
  name: "Rari Chain",
@@ -801,14 +1083,6 @@ function clearChainsCache() {
801
1083
  chainsCache = null;
802
1084
  }
803
1085
 
804
- // src/constants/index.ts
805
- var ATOMIC_QUEUE_CONTRACT_ADDRESS = "0x228c44bb4885c6633f4b6c83f14622f37d5112e5";
806
- var DEFAULT_DEADLINE = 3;
807
- var NATIVE_TOKEN_FOR_BRIDGE_FEE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
808
- var CHAINLINK_ADDRESS = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
809
- var DEFAULT_APPROVAL_AMOUNT = BigInt(2) ** BigInt(256) - BigInt(1);
810
- var NUCLEUS_BASE_URL = "https://backend.nucleusearn.io/v1/protocol";
811
-
812
- export { APIError, ATOMIC_QUEUE_CONTRACT_ADDRESS, CHAINLINK_ADDRESS, DEFAULT_APPROVAL_AMOUNT, DEFAULT_DEADLINE, NATIVE_TOKEN_FOR_BRIDGE_FEE, NUCLEUS_BASE_URL, clearChainsCache, fetchSupportedAssets, fetchVaults, findVaultByConfig, getAssetsFromCache, getCache, getChainFromConfig, getWithdrawSupportedAssets, initAmplifySDK, initializeCache, refreshVaultCache };
813
- //# sourceMappingURL=chunk-CUGK4ZBJ.mjs.map
814
- //# sourceMappingURL=chunk-CUGK4ZBJ.mjs.map
1086
+ export { APIError, API_BASE_URL, ATOMIC_QUEUE_CONTRACT_ADDRESS, CHAINLINK_ADDRESS, DEFAULT_APPROVAL_AMOUNT, DEFAULT_DEADLINE, LogLevel, NATIVE_TOKEN_FOR_BRIDGE_FEE, clearChainsCache, fetchSupportedAssets, fetchVaults, findVaultByConfig, getAssetsFromCache, getCache, getChainFromConfig, getLogger, getWithdrawSupportedAssets, initAmplifySDK, initializeCache, refreshVaultCache, setLogLevel, setLogger };
1087
+ //# sourceMappingURL=chunk-YDMFT2R7.mjs.map
1088
+ //# sourceMappingURL=chunk-YDMFT2R7.mjs.map