Skip to content

Commit

Permalink
Revert retry in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasia committed Jun 16, 2024
1 parent 63a967a commit 68cdc63
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
3 changes: 0 additions & 3 deletions packages/ops/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"@credbull/api": "workspace:^",
"@credbull/contracts": "workspace:^",
"@supabase/supabase-js": "^2.39.1",
"axios": "^1.7.2",
"axios-retry": "^4.4.0",
"axis": "^1.0.0",
"bottleneck": "^2.19.5",
"compression": "^1.7.4",
"crypto": "^1.0.1",
Expand Down
27 changes: 5 additions & 22 deletions packages/ops/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Database } from '@credbull/api';
import { SupabaseClient, createClient } from '@supabase/supabase-js';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import crypto from 'crypto';
import { Wallet, providers } from 'ethers';
import { SiweMessage, generateNonce } from 'siwe';
Expand All @@ -12,19 +10,6 @@ export const emailSchemaOptional = z.string().email().nullish().or(z.literal('')
export const addressSchema = z.string().regex(/^(0x)?[0-9a-fA-F]{40,40}$/);
export const upsideVaultSchema = z.union([addressSchema, z.string().regex(/^self$/)]).optional();

// Configure axios to use axios-retry
axiosRetry(axios, {
retries: 3, // Number of retries
retryDelay: (retryCount) => {
console.log(`Retry attempt: ${retryCount}`);
return retryCount * 300; // Time in ms between retries
},
retryCondition: (error) => {
// Retry on network errors or 5xx status codes
return axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status >= 500;
},
});

const supabaseConfigSchema = z.object({
services: z.object({ supabase: z.object({ url: z.string().url() }) }),
secret: z.object({
Expand Down Expand Up @@ -106,26 +91,24 @@ export const login = async (
_password = config.secret!.BOB_PASSWORD!;
}

const body = { email: _email, password: _password };
console.log(JSON.stringify(body));
const body = JSON.stringify({ email: _email, password: _password });

let signIn;

try {
signIn = await axios.post(`${config.api.url}/auth/api/sign-in`, body, headers());
signIn = await fetch(`${config.api.url}/auth/api/sign-in`, { method: 'POST', body, ...headers() });
} catch (error) {
console.error('Network error or server is down:', error);
throw error;
}

if (signIn.status < 200 || signIn.status >= 300) {
if (!signIn.ok) {
console.error(`HTTP error! status: ${signIn.status}`);
throw new Error(`Failed to login: ${signIn.statusText}`);
}

const data = await signIn.data;
const data = await signIn.json();
console.log(`sign in response: ${JSON.stringify(data)}`);

return data;
};

Expand All @@ -134,7 +117,7 @@ const linkWalletConfigSchema = z.object({ app: z.object({ url: z.string().url()
export const linkWalletMessage = async (config: any, signer: Wallet) => {
linkWalletConfigSchema.parse(config);

const appUrl = new URL(config.app.url);
let appUrl = new URL(config.app.url);
const chainId = await signer.getChainId();
const preMessage = new SiweMessage({
domain: appUrl.host,
Expand Down
30 changes: 1 addition & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ __metadata:
"@types/node": ^20.10.5
"@typescript-eslint/eslint-plugin": ^6.16.0
"@typescript-eslint/parser": ^6.16.0
axios: ^1.7.2
axios-retry: ^4.4.0
axis: ^1.0.0
bottleneck: ^2.19.5
compression: ^1.7.4
crypto: ^1.0.1
Expand Down Expand Up @@ -7249,18 +7246,7 @@ __metadata:
languageName: node
linkType: hard

"axios-retry@npm:^4.4.0":
version: 4.4.0
resolution: "axios-retry@npm:4.4.0"
dependencies:
is-retry-allowed: ^2.2.0
peerDependencies:
axios: 0.x || 1.x
checksum: 19b005bbd3e956080b27ee54fad658dbf7663fa6e884110a638b9f53db50a34c4870648143c8d9397354fedd0ede920693caa1e7c6a762d9477b4cbb48ca22f2
languageName: node
linkType: hard

"axios@npm:^1.5.1, axios@npm:^1.6.1, axios@npm:^1.6.5, axios@npm:^1.7.2":
"axios@npm:^1.5.1, axios@npm:^1.6.1, axios@npm:^1.6.5":
version: 1.7.2
resolution: "axios@npm:1.7.2"
dependencies:
Expand All @@ -7271,13 +7257,6 @@ __metadata:
languageName: node
linkType: hard

"axis@npm:^1.0.0":
version: 1.0.0
resolution: "axis@npm:1.0.0"
checksum: 6c1d151252a33ff12c7f390ff9168a44c95e5caa55e6f0441e8f4be8b90990903e511dbb4e0e26dda905def56111dac22df4f1023904447cbdfc4d27ff48b1cf
languageName: node
linkType: hard

"axobject-query@npm:^3.2.1":
version: 3.2.1
resolution: "axobject-query@npm:3.2.1"
Expand Down Expand Up @@ -12875,13 +12854,6 @@ __metadata:
languageName: node
linkType: hard

"is-retry-allowed@npm:^2.2.0":
version: 2.2.0
resolution: "is-retry-allowed@npm:2.2.0"
checksum: 3d1103a9290b5d03626756a41054844633eac78bc5d3e3a95b13afeae94fa3cfbcf7f0b5520d83f75f48a25ce7b142fdbac4217dc4b0630f3ea55e866ec3a029
languageName: node
linkType: hard

"is-set@npm:^2.0.2, is-set@npm:^2.0.3":
version: 2.0.3
resolution: "is-set@npm:2.0.3"
Expand Down

0 comments on commit 68cdc63

Please sign in to comment.