@riocrypto/common-server 1.0.1912 → 1.0.1914

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.
@@ -54,7 +54,7 @@ class SecretManagerClient {
54
54
  });
55
55
  }
56
56
  getSecretValue(secretId) {
57
- var _a, _b, _c, _d;
57
+ var _a, _b;
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
59
  let file;
60
60
  if (this.env === common_1.RioEnv.Development) {
@@ -69,21 +69,37 @@ class SecretManagerClient {
69
69
  else if (this.env === common_1.RioEnv.Production) {
70
70
  file = "production-secrets";
71
71
  }
72
- try {
73
- // Access the secret version
74
- const [version] = yield this.client.accessSecretVersion({
75
- name: `projects/${this.projectId}/secrets/${file}/versions/latest`,
76
- });
77
- if (!((_b = (_a = version.payload) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.toString())) {
78
- throw new Error();
72
+ const maxRetries = 5;
73
+ let attempt = 0;
74
+ while (attempt < maxRetries) {
75
+ try {
76
+ // Access the secret version
77
+ const [version] = yield this.client.accessSecretVersion({
78
+ name: `projects/${this.projectId}/secrets/${file}/versions/latest`,
79
+ });
80
+ if (!((_b = (_a = version.payload) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.toString())) {
81
+ throw new Error("No payload data");
82
+ }
83
+ const secrets = JSON.parse(version.payload.data.toString());
84
+ return secrets[secretId];
85
+ }
86
+ catch (err) {
87
+ attempt++;
88
+ // Check if the error code is 13 (INTERNAL) and retry if so
89
+ if (err.code === 13 && attempt < maxRetries) {
90
+ console.warn(`Attempt ${attempt} failed with error code ${err.code}. Retrying in ${Math.pow(2, attempt)} seconds...`);
91
+ // Exponential backoff
92
+ yield new Promise((resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1000));
93
+ continue;
94
+ }
95
+ else {
96
+ console.error(`Failed to access secret ${secretId}:`, err);
97
+ return null;
98
+ }
79
99
  }
80
- const secrets = JSON.parse((_d = (_c = version.payload) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.toString());
81
- return secrets[secretId];
82
- }
83
- catch (err) {
84
- console.error(`Failed to access secret ${secretId}: ${err}`);
85
- return null;
86
100
  }
101
+ console.error(`Failed to access secret ${secretId} after ${maxRetries} attempts.`);
102
+ return null;
87
103
  });
88
104
  }
89
105
  }
@@ -75,12 +75,17 @@ class LoggerService {
75
75
  });
76
76
  this.requestMethodFilter = (0, winston_1.format)((info) => {
77
77
  const allowedMethods = ["POST", "PATCH", "DELETE"];
78
- if (info.meta &&
79
- info.meta.req &&
80
- allowedMethods.includes(info.meta.req.method)) {
81
- return info;
78
+ // Only apply filter if req.method is defined
79
+ if (info.meta && info.meta.req && info.meta.req.method) {
80
+ if (allowedMethods.includes(info.meta.req.method)) {
81
+ return info;
82
+ }
83
+ else {
84
+ return false; // Filter out logs for other methods
85
+ }
82
86
  }
83
- return false; // Filter out logs for other methods
87
+ // If there's no req.method, don't filter out the log
88
+ return info;
84
89
  });
85
90
  this.logger = null;
86
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1912",
3
+ "version": "1.0.1914",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",