@riocrypto/common-server 1.0.1913 → 1.0.1918

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
  }
@@ -38,7 +38,7 @@ class LoggerService {
38
38
  key === "refreshToken" ||
39
39
  key === "adminRefreshToken" ||
40
40
  key === "phoneVerifiedJWT") {
41
- return `${key}=${this.maskValue(value)}`; // Mask the sensitive cookie
41
+ return `${key}=${this.maskValue(value, true)}`; // Mask the sensitive cookie
42
42
  }
43
43
  return cookie; // Return unmodified if not sensitive
44
44
  })
@@ -47,18 +47,25 @@ class LoggerService {
47
47
  }
48
48
  // Mask sensitive request body fields
49
49
  if (info.meta && info.meta.req && info.meta.req.body) {
50
- const requestBodyFieldsToMask = [
50
+ const requestBodyFieldsToMaskWithLastFour = [
51
+ "accountNumber",
52
+ "routingNumber",
53
+ ];
54
+ requestBodyFieldsToMaskWithLastFour.forEach((field) => {
55
+ if (info.meta.req.body.hasOwnProperty(field)) {
56
+ info.meta.req.body[field] = this.maskValue(info.meta.req.body[field], true);
57
+ }
58
+ });
59
+ const requestBodyFieldsToMaskWithoutLastFour = [
51
60
  "password",
52
61
  "newPassword",
53
62
  "securityAnswer",
54
- "accountNumber",
55
- "routingNumber",
56
63
  "code",
57
64
  "authenticatorCode",
58
65
  ];
59
- requestBodyFieldsToMask.forEach((field) => {
66
+ requestBodyFieldsToMaskWithoutLastFour.forEach((field) => {
60
67
  if (info.meta.req.body.hasOwnProperty(field)) {
61
- info.meta.req.body[field] = this.maskValue(info.meta.req.body[field]); // Use maskValue function
68
+ info.meta.req.body[field] = this.maskValue(info.meta.req.body[field]);
62
69
  }
63
70
  });
64
71
  }
@@ -89,10 +96,13 @@ class LoggerService {
89
96
  });
90
97
  this.logger = null;
91
98
  }
92
- maskValue(value) {
93
- return value.length > 4
94
- ? "*".repeat(value.length - 4) + value.slice(-4)
95
- : value;
99
+ maskValue(value, showLastFour = false) {
100
+ if (showLastFour) {
101
+ return value.length > 4 ? "*".repeat(12) + value.slice(-4) : value;
102
+ }
103
+ else {
104
+ return "************";
105
+ }
96
106
  }
97
107
  getLogger() {
98
108
  if (!this.logger) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1913",
3
+ "version": "1.0.1918",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",