polyapi 0.24.9 → 0.24.11

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,4 +1,4 @@
1
- const { axios } = require('../axios');
1
+ const { axios, scrub } = require('../axios');
2
2
  const set = require('lodash/set');
3
3
  const https = require('https');
4
4
  const fs = require('fs');
@@ -49,6 +49,7 @@ const handleError = (err) => {
49
49
  };
50
50
  }
51
51
 
52
+
52
53
  const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
53
54
  const requestServerStartTime = Date.now();
54
55
 
@@ -78,7 +79,8 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
78
79
  try {
79
80
  responseData = JSON.stringify(data.data);
80
81
  } catch (err) {}
81
- console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
82
+ scrub(requestArgs)
83
+ console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', scrubbedArgs, 'Response data:', responseData);
82
84
  }
83
85
 
84
86
  serverPreperationTimeMs = Number(polyHeaders['x-poly-execution-duration']);
@@ -96,6 +98,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
96
98
  })
97
99
  }).then(({ headers, data, status }) => {
98
100
  if (status && (status < 200 || status >= 300) && process.env.LOGS_ENABLED) {
101
+ scrub(requestArgs)
99
102
  console.error('Error direct executing api function with id:', id, 'Status code:', status, 'Request data:', requestArgs, 'Response data:', data.data);
100
103
  }
101
104
  const apiExecutionTimeMs = Date.now() - requestApiStartTime;
@@ -127,6 +130,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
127
130
  try {
128
131
  responseData = JSON.stringify(data.data);
129
132
  } catch (err) {}
133
+ scrub(requestArgs)
130
134
  console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
131
135
  }
132
136
  const serverExecutionTimeMs = Number(headers['x-poly-execution-duration']);
@@ -42,18 +42,45 @@ axios.interceptors.request.use(
42
42
  }
43
43
  );
44
44
 
45
+
46
+ const scrub = (data) => {
47
+ if (!data || typeof data !== 'object' ) return data;
48
+ const secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"];
49
+ if (Array.isArray(data)) {
50
+ return data.map(item => scrub(item))
51
+ }
52
+ else {
53
+ const temp = {};
54
+ for (const key of Object.keys(data)) {
55
+ if (typeof data[key] === 'object') {
56
+ temp[key] = scrub(data[key]);
57
+ } else if (secrets.includes(key.toLowerCase())) {
58
+ temp[key] = "********";
59
+ } else {
60
+ temp[key] = data[key];
61
+ }
62
+ }
63
+ return temp
64
+ }
65
+ }
66
+
67
+
45
68
  const scrubKeys = (err) => {
46
- if (err.request && typeof err.request.headers === 'object' && err.request.headers.Authorization) {
69
+ if (!err.request || typeof err.request.headers !== 'object') throw err
70
+ const temp = scrub(err.request.headers)
71
+ if (err.request.headers.Authorization) {
47
72
  // Scrub any credentials in the authorization header
48
73
  const [type, ...rest] = err.request.headers.Authorization.split(' ');
49
- err.request.headers.Authorization = rest.length && type
74
+ temp.Authorization = rest.length && type
50
75
  ? `${type} ********`
51
76
  : `********`;
52
77
  }
78
+ err.request.headers = temp
53
79
  throw err;
54
80
  };
55
81
 
56
82
  module.exports = {
57
83
  axios,
58
- scrubKeys
84
+ scrubKeys,
85
+ scrub
59
86
  };
@@ -43,14 +43,14 @@ type PolyCountQuery<T extends Record<string, unknown>> = Clean<{
43
43
 
44
44
  type PolySelectOneQuery<T extends Record<string, unknown>> = Clean<{
45
45
  where?: Where<T>;
46
- orderBy?: Record<keyof T, 'asc' | 'desc'>;
46
+ orderBy?: Partial<Record<keyof T, 'asc' | 'desc'>>;
47
47
  }>;
48
48
 
49
49
  type PolySelectManyQuery<T extends Record<string, unknown>> = Clean<{
50
50
  where?: Where<T>;
51
51
  limit?: number; // 1000 is max limit for now
52
52
  offset?: number;
53
- orderBy?: Record<keyof T, 'asc' | 'desc'>;
53
+ orderBy?: Partial<Record<keyof T, 'asc' | 'desc'>>;
54
54
  }>;
55
55
 
56
56
  type PolyDeleteQuery<T extends Record<string, unknown>> = Clean<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polyapi",
3
- "version": "0.24.9",
3
+ "version": "0.24.11",
4
4
  "description": "Poly is a CLI tool to help create and manage your Poly definitions.",
5
5
  "license": "MIT",
6
6
  "repository": {