@unito/integration-sdk 2.3.2 → 2.3.3

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.
@@ -170,7 +170,16 @@ class Logger {
170
170
  static snakifyKeys(value) {
171
171
  const result = {};
172
172
  for (const key in value) {
173
- const deepValue = typeof value[key] === 'object' ? this.snakifyKeys(value[key]) : value[key];
173
+ let deepValue;
174
+ if (Array.isArray(value[key])) {
175
+ deepValue = value[key].map(item => this.snakifyKeys(item));
176
+ }
177
+ else if (typeof value[key] === 'object' && value[key] !== null) {
178
+ deepValue = this.snakifyKeys(value[key]);
179
+ }
180
+ else {
181
+ deepValue = value[key];
182
+ }
174
183
  const snakifiedKey = key.replace(/[\w](?<!_)([A-Z])/g, k => `${k[0]}_${k[1]}`).toLowerCase();
175
184
  result[snakifiedKey] = deepValue;
176
185
  }
@@ -183,7 +192,10 @@ class Logger {
183
192
  prunedMetadata[key] = '[REDACTED]';
184
193
  (topLevelMeta ?? prunedMetadata).has_sensitive_attribute = true;
185
194
  }
186
- else if (typeof metadata[key] === 'object') {
195
+ else if (Array.isArray(metadata[key])) {
196
+ prunedMetadata[key] = metadata[key].map(value => Logger.pruneSensitiveMetadata(value, topLevelMeta ?? prunedMetadata));
197
+ }
198
+ else if (typeof metadata[key] === 'object' && metadata[key] !== null) {
187
199
  prunedMetadata[key] = Logger.pruneSensitiveMetadata(metadata[key], topLevelMeta ?? prunedMetadata);
188
200
  }
189
201
  else {
@@ -1,6 +1,6 @@
1
1
  type PrimitiveValue = undefined | null | string | string[] | number | number[] | boolean | boolean[];
2
2
  type Value = {
3
- [key: string]: PrimitiveValue | Value;
3
+ [key: string]: PrimitiveValue | Value | PrimitiveValue[] | Value[];
4
4
  };
5
5
  export type Metadata = Value & {
6
6
  message?: never;
@@ -142,7 +142,16 @@ export default class Logger {
142
142
  static snakifyKeys(value) {
143
143
  const result = {};
144
144
  for (const key in value) {
145
- const deepValue = typeof value[key] === 'object' ? this.snakifyKeys(value[key]) : value[key];
145
+ let deepValue;
146
+ if (Array.isArray(value[key])) {
147
+ deepValue = value[key].map(item => this.snakifyKeys(item));
148
+ }
149
+ else if (typeof value[key] === 'object' && value[key] !== null) {
150
+ deepValue = this.snakifyKeys(value[key]);
151
+ }
152
+ else {
153
+ deepValue = value[key];
154
+ }
146
155
  const snakifiedKey = key.replace(/[\w](?<!_)([A-Z])/g, k => `${k[0]}_${k[1]}`).toLowerCase();
147
156
  result[snakifiedKey] = deepValue;
148
157
  }
@@ -155,7 +164,10 @@ export default class Logger {
155
164
  prunedMetadata[key] = '[REDACTED]';
156
165
  (topLevelMeta ?? prunedMetadata).has_sensitive_attribute = true;
157
166
  }
158
- else if (typeof metadata[key] === 'object') {
167
+ else if (Array.isArray(metadata[key])) {
168
+ prunedMetadata[key] = metadata[key].map(value => Logger.pruneSensitiveMetadata(value, topLevelMeta ?? prunedMetadata));
169
+ }
170
+ else if (typeof metadata[key] === 'object' && metadata[key] !== null) {
159
171
  prunedMetadata[key] = Logger.pruneSensitiveMetadata(metadata[key], topLevelMeta ?? prunedMetadata);
160
172
  }
161
173
  else {
@@ -106,7 +106,14 @@ describe('Logger', () => {
106
106
  it('snakify keys of Message and Metadata', testContext => {
107
107
  const logSpy = testContext.mock.method(global.console, 'log', () => { });
108
108
  assert.strictEqual(logSpy.mock.calls.length, 0);
109
- const metadata = { correlationId: '123456789', http: { method: 'GET', statusCode: 200 } };
109
+ const metadata = {
110
+ correlationId: '123456789',
111
+ http: { method: 'GET', statusCode: 200 },
112
+ links: [
113
+ { id: 1, organizationId: 'a' },
114
+ { id: 2, organizationId: 'b' },
115
+ ],
116
+ };
110
117
  const logger = new Logger(metadata);
111
118
  logger.log('test', { errorContext: { errorCode: 200, errorMessage: 'Page Not Found' } });
112
119
  assert.strictEqual(logSpy.mock.calls.length, 1);
@@ -117,8 +124,12 @@ describe('Logger', () => {
117
124
  assert.equal(actual['status'], 'log');
118
125
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200 });
119
126
  assert.deepEqual(actual['error_context'], { error_code: 200, error_message: 'Page Not Found' });
127
+ assert.deepEqual(actual['links'], [
128
+ { id: 1, organization_id: 'a' },
129
+ { id: 2, organization_id: 'b' },
130
+ ]);
120
131
  });
121
- it('prunes sensitive Metadata', testContext => {
132
+ it('prunes sensitive Metadata', { only: true }, testContext => {
122
133
  const logSpy = testContext.mock.method(global.console, 'log', () => { });
123
134
  assert.strictEqual(logSpy.mock.calls.length, 0);
124
135
  const metadata = {
@@ -126,6 +137,10 @@ describe('Logger', () => {
126
137
  http: { method: 'GET', statusCode: 200, jwt: 'deepSecret' },
127
138
  user: { contact: { email: 'deep_deep_deep@email.address', firstName: 'should be snakify then hidden' } },
128
139
  access_token: 'secret',
140
+ items: [
141
+ { id: 1, organizationId: 'a' },
142
+ { id: 2, organizationId: 'b' },
143
+ ],
129
144
  };
130
145
  const logger = new Logger(metadata);
131
146
  logger.log('test', { errorContext: { errorCode: 200, errorMessage: 'Page Not Found' } });
@@ -139,6 +154,10 @@ describe('Logger', () => {
139
154
  assert.equal(actual['access_token'], '[REDACTED]');
140
155
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200, jwt: '[REDACTED]' });
141
156
  assert.deepEqual(actual['user']['contact'], { email: '[REDACTED]', first_name: '[REDACTED]' });
157
+ assert.deepEqual(actual['items'], [
158
+ { id: 1, organization_id: 'a' },
159
+ { id: 2, organization_id: 'b' },
160
+ ]);
142
161
  });
143
162
  it(`NULL_LOGGER should not log`, testContext => {
144
163
  const logger = NULL_LOGGER;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -8,7 +8,7 @@ const enum LogLevel {
8
8
 
9
9
  type PrimitiveValue = undefined | null | string | string[] | number | number[] | boolean | boolean[];
10
10
  type Value = {
11
- [key: string]: PrimitiveValue | Value;
11
+ [key: string]: PrimitiveValue | Value | PrimitiveValue[] | Value[];
12
12
  };
13
13
 
14
14
  export type Metadata = Value & { message?: never };
@@ -172,7 +172,16 @@ export default class Logger {
172
172
  const result: Value = {};
173
173
 
174
174
  for (const key in value) {
175
- const deepValue = typeof value[key] === 'object' ? this.snakifyKeys(value[key] as Value) : value[key];
175
+ let deepValue;
176
+
177
+ if (Array.isArray(value[key])) {
178
+ deepValue = value[key].map(item => this.snakifyKeys(item as Value));
179
+ } else if (typeof value[key] === 'object' && value[key] !== null) {
180
+ deepValue = this.snakifyKeys(value[key] as Value);
181
+ } else {
182
+ deepValue = value[key];
183
+ }
184
+
176
185
  const snakifiedKey = key.replace(/[\w](?<!_)([A-Z])/g, k => `${k[0]}_${k[1]}`).toLowerCase();
177
186
  result[snakifiedKey] = deepValue;
178
187
  }
@@ -187,7 +196,11 @@ export default class Logger {
187
196
  if (LOGMETA_BLACKLIST.includes(key)) {
188
197
  prunedMetadata[key] = '[REDACTED]';
189
198
  (topLevelMeta ?? prunedMetadata).has_sensitive_attribute = true;
190
- } else if (typeof metadata[key] === 'object') {
199
+ } else if (Array.isArray(metadata[key])) {
200
+ prunedMetadata[key] = metadata[key].map(value =>
201
+ Logger.pruneSensitiveMetadata(value as Value, topLevelMeta ?? prunedMetadata),
202
+ );
203
+ } else if (typeof metadata[key] === 'object' && metadata[key] !== null) {
191
204
  prunedMetadata[key] = Logger.pruneSensitiveMetadata(metadata[key] as Value, topLevelMeta ?? prunedMetadata);
192
205
  } else {
193
206
  prunedMetadata[key] = metadata[key];
@@ -129,7 +129,14 @@ describe('Logger', () => {
129
129
  const logSpy = testContext.mock.method(global.console, 'log', () => {});
130
130
  assert.strictEqual(logSpy.mock.calls.length, 0);
131
131
 
132
- const metadata = { correlationId: '123456789', http: { method: 'GET', statusCode: 200 } };
132
+ const metadata = {
133
+ correlationId: '123456789',
134
+ http: { method: 'GET', statusCode: 200 },
135
+ links: [
136
+ { id: 1, organizationId: 'a' },
137
+ { id: 2, organizationId: 'b' },
138
+ ],
139
+ };
133
140
  const logger = new Logger(metadata);
134
141
  logger.log('test', { errorContext: { errorCode: 200, errorMessage: 'Page Not Found' } });
135
142
  assert.strictEqual(logSpy.mock.calls.length, 1);
@@ -142,9 +149,13 @@ describe('Logger', () => {
142
149
  assert.equal(actual['status'], 'log');
143
150
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200 });
144
151
  assert.deepEqual(actual['error_context'], { error_code: 200, error_message: 'Page Not Found' });
152
+ assert.deepEqual(actual['links'], [
153
+ { id: 1, organization_id: 'a' },
154
+ { id: 2, organization_id: 'b' },
155
+ ]);
145
156
  });
146
157
 
147
- it('prunes sensitive Metadata', testContext => {
158
+ it('prunes sensitive Metadata', { only: true }, testContext => {
148
159
  const logSpy = testContext.mock.method(global.console, 'log', () => {});
149
160
  assert.strictEqual(logSpy.mock.calls.length, 0);
150
161
 
@@ -153,6 +164,10 @@ describe('Logger', () => {
153
164
  http: { method: 'GET', statusCode: 200, jwt: 'deepSecret' },
154
165
  user: { contact: { email: 'deep_deep_deep@email.address', firstName: 'should be snakify then hidden' } },
155
166
  access_token: 'secret',
167
+ items: [
168
+ { id: 1, organizationId: 'a' },
169
+ { id: 2, organizationId: 'b' },
170
+ ],
156
171
  };
157
172
  const logger = new Logger(metadata);
158
173
  logger.log('test', { errorContext: { errorCode: 200, errorMessage: 'Page Not Found' } });
@@ -167,6 +182,10 @@ describe('Logger', () => {
167
182
  assert.equal(actual['access_token'], '[REDACTED]');
168
183
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200, jwt: '[REDACTED]' });
169
184
  assert.deepEqual(actual['user']['contact'], { email: '[REDACTED]', first_name: '[REDACTED]' });
185
+ assert.deepEqual(actual['items'], [
186
+ { id: 1, organization_id: 'a' },
187
+ { id: 2, organization_id: 'b' },
188
+ ]);
170
189
  });
171
190
 
172
191
  it(`NULL_LOGGER should not log`, testContext => {