@settlemint/sdk-js 2.4.0-pr3f71e882 → 2.4.0-pr3fd1ae9a

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.
@@ -1,3 +1,4 @@
1
+ /* SettleMint SDK - Main Package */
1
2
  import { fetchWithRetry } from "@settlemint/sdk-utils/http";
2
3
  import { ensureServer } from "@settlemint/sdk-utils/runtime";
3
4
  import { AccessTokenSchema, IdSchema, LOCAL_INSTANCE, STANDALONE_INSTANCE, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
@@ -118,7 +119,9 @@ const workspaceList = (gqlClient) => {
118
119
  const { workspaces } = await gqlClient.request(getWorkspacesAndApplications);
119
120
  const allWorkspaces = workspaces.reduce((acc, workspace) => {
120
121
  acc.push(workspace);
121
- if (workspace.childWorkspaces) acc.push(...workspace.childWorkspaces);
122
+ if (workspace.childWorkspaces) {
123
+ acc.push(...workspace.childWorkspaces);
124
+ }
122
125
  return acc;
123
126
  }, []);
124
127
  return allWorkspaces.sort((a, b) => a.name.localeCompare(b.name));
@@ -173,7 +176,9 @@ const workspaceDelete = (gqlClient) => {
173
176
  const workspaceAddCredits = (gqlClient) => {
174
177
  return async (workspaceId, amount) => {
175
178
  const id = validate(IdSchema, workspaceId);
176
- if (amount <= 0) throw new Error("Credit amount must be a positive number");
179
+ if (amount <= 0) {
180
+ throw new Error("Credit amount must be a positive number");
181
+ }
177
182
  const { addCredits: result } = await gqlClient.request(addCredits, {
178
183
  workspaceId: id,
179
184
  amount
@@ -350,7 +355,9 @@ const applicationAccessTokenCreate = (gqlClient) => {
350
355
  ...otherArgs,
351
356
  applicationId: application.id
352
357
  });
353
- if (!applicationAccessToken.token) throw new Error("Failed to create application access token");
358
+ if (!applicationAccessToken.token) {
359
+ throw new Error("Failed to create application access token");
360
+ }
354
361
  return applicationAccessToken.token;
355
362
  };
356
363
  };
@@ -381,15 +388,17 @@ function setClusterServiceDefaults(args) {
381
388
  */
382
389
  function setNetworkDefaults(args) {
383
390
  const clusterServiceArgs = setClusterServiceDefaults(args);
384
- if (args.consensusAlgorithm === "BESU_QBFT") return {
385
- ...clusterServiceArgs,
386
- chainId: args.chainId ?? 46040,
387
- contractSizeLimit: args.contractSizeLimit ?? 2147483647,
388
- evmStackSize: args.evmStackSize ?? 2048,
389
- gasLimit: args.gasLimit ?? "9007199254740991",
390
- gasPrice: args.gasPrice ?? 0,
391
- secondsPerBlock: args.secondsPerBlock ?? 2
392
- };
391
+ if (args.consensusAlgorithm === "BESU_QBFT") {
392
+ return {
393
+ ...clusterServiceArgs,
394
+ chainId: args.chainId ?? 46040,
395
+ contractSizeLimit: args.contractSizeLimit ?? 2147483647,
396
+ evmStackSize: args.evmStackSize ?? 2048,
397
+ gasLimit: args.gasLimit ?? "9007199254740991",
398
+ gasPrice: args.gasPrice ?? 0,
399
+ secondsPerBlock: args.secondsPerBlock ?? 2
400
+ };
401
+ }
393
402
  return clusterServiceArgs;
394
403
  }
395
404
 
@@ -1508,8 +1517,8 @@ const insightsCreate = (gqlClient) => {
1508
1517
  const { applicationUniqueName, blockchainNodeUniqueName, loadBalancerUniqueName,...otherArgs } = args;
1509
1518
  const [application, blockchainNode, loadBalancer] = await Promise.all([
1510
1519
  applicationRead(gqlClient)(applicationUniqueName),
1511
- blockchainNodeUniqueName ? blockchainNodeRead(gqlClient)(blockchainNodeUniqueName) : Promise.resolve(void 0),
1512
- loadBalancerUniqueName ? loadBalancerRead(gqlClient)(loadBalancerUniqueName) : Promise.resolve(void 0)
1520
+ blockchainNodeUniqueName ? blockchainNodeRead(gqlClient)(blockchainNodeUniqueName) : Promise.resolve(undefined),
1521
+ loadBalancerUniqueName ? loadBalancerRead(gqlClient)(loadBalancerUniqueName) : Promise.resolve(undefined)
1513
1522
  ]);
1514
1523
  const { createInsights: insights } = await gqlClient.request(createInsights, {
1515
1524
  ...otherArgs,
@@ -2116,9 +2125,9 @@ const middlewareCreate = (gqlClient) => {
2116
2125
  const { applicationUniqueName, blockchainNodeUniqueName, loadBalancerUniqueName, storageUniqueName,...otherArgs } = args;
2117
2126
  const [application, blockchainNode, loadBalancer, storage] = await Promise.all([
2118
2127
  applicationRead(gqlClient)(applicationUniqueName),
2119
- blockchainNodeUniqueName ? blockchainNodeRead(gqlClient)(blockchainNodeUniqueName) : Promise.resolve(void 0),
2120
- loadBalancerUniqueName ? loadBalancerRead(gqlClient)(loadBalancerUniqueName) : Promise.resolve(void 0),
2121
- storageUniqueName ? storageRead(gqlClient)(storageUniqueName) : Promise.resolve(void 0)
2128
+ blockchainNodeUniqueName ? blockchainNodeRead(gqlClient)(blockchainNodeUniqueName) : Promise.resolve(undefined),
2129
+ loadBalancerUniqueName ? loadBalancerRead(gqlClient)(loadBalancerUniqueName) : Promise.resolve(undefined),
2130
+ storageUniqueName ? storageRead(gqlClient)(storageUniqueName) : Promise.resolve(undefined)
2122
2131
  ]);
2123
2132
  const { createMiddleware: middleware } = await gqlClient.request(createMiddleware, {
2124
2133
  ...otherArgs,
@@ -2384,7 +2393,7 @@ const privateKeyCreate = (gqlClient) => {
2384
2393
  const { applicationUniqueName, blockchainNodeUniqueNames, relayerKeyUniqueName,...otherArgs } = args;
2385
2394
  const application = await applicationRead(gqlClient)(applicationUniqueName);
2386
2395
  const blockchainNodes = blockchainNodeUniqueNames ? await Promise.all(blockchainNodeUniqueNames.map((uniqueName) => blockchainNodeRead(gqlClient)(uniqueName))) : [];
2387
- const relayerKey = relayerKeyUniqueName ? await privatekeyRead(gqlClient)(relayerKeyUniqueName) : void 0;
2396
+ const relayerKey = relayerKeyUniqueName ? await privatekeyRead(gqlClient)(relayerKeyUniqueName) : undefined;
2388
2397
  const platformConfig = await getPlatformConfig(gqlClient)();
2389
2398
  const defaultProvider = platformConfig.deploymentEngineTargets.find((target) => !target.disabled && target.clusters.some((cluster) => !cluster.disabled));
2390
2399
  const defaultRegion = defaultProvider?.clusters.find((cluster) => !cluster.disabled);
@@ -2471,7 +2480,9 @@ async function getPincodeVerificationChallenges({ userWalletAddress, accessToken
2471
2480
  }
2472
2481
  });
2473
2482
  if (!response.ok) {
2474
- if (response.status === 404) throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
2483
+ if (response.status === 404) {
2484
+ throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
2485
+ }
2475
2486
  throw new Error("Failed to get verification challenge");
2476
2487
  }
2477
2488
  const verificationChallenges = await response.json();
@@ -2484,7 +2495,9 @@ async function getPincodeVerificationChallenges({ userWalletAddress, accessToken
2484
2495
  * @returns The pincode verification challenge response.
2485
2496
  */
2486
2497
  function getPincodeVerificationChallengeResponse({ verificationChallenge, pincode }) {
2487
- if (!verificationChallenge?.challenge?.secret || !verificationChallenge?.challenge?.salt) throw new Error("Could not authenticate pin code, invalid challenge format");
2498
+ if (!verificationChallenge?.challenge?.secret || !verificationChallenge?.challenge?.salt) {
2499
+ throw new Error("Could not authenticate pin code, invalid challenge format");
2500
+ }
2488
2501
  const { secret, salt } = verificationChallenge.challenge;
2489
2502
  return generateResponse(pincode, salt, secret);
2490
2503
  }
@@ -2517,8 +2530,13 @@ function getPincodeVerificationChallengeResponse({ verificationChallenge, pincod
2517
2530
  */
2518
2531
  function createSettleMintClient(options) {
2519
2532
  ensureServer();
2520
- if (options.instance === STANDALONE_INSTANCE || options.instance === LOCAL_INSTANCE) if (options.anonymous) options.instance = "https://console.settlemint.com";
2521
- else throw new Error("Standalone and local instances cannot connect to the SettleMint platform");
2533
+ if (options.instance === STANDALONE_INSTANCE || options.instance === LOCAL_INSTANCE) {
2534
+ if (options.anonymous) {
2535
+ options.instance = "https://console.settlemint.com";
2536
+ } else {
2537
+ throw new Error("Standalone and local instances cannot connect to the SettleMint platform");
2538
+ }
2539
+ }
2522
2540
  const validatedOptions = options.anonymous ? validate(z.object({
2523
2541
  ...ClientOptionsSchema.shape,
2524
2542
  accessToken: z.literal("")