polyapi 0.24.9 → 0.24.10
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.
|
@@ -49,6 +49,28 @@ const handleError = (err) => {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const scrub = (data) => {
|
|
53
|
+
if (!data || typeof data !== 'object' ) return data;
|
|
54
|
+
const secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"];
|
|
55
|
+
if (Array.isArray(data)) {
|
|
56
|
+
return data.map(item => scrub(item))
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const temp = {};
|
|
60
|
+
for (const key of Object.keys(data)) {
|
|
61
|
+
if (typeof data[key] === 'object') {
|
|
62
|
+
temp[key] = scrub(data[key]);
|
|
63
|
+
} else if (secrets.includes(key.toLowerCase())) {
|
|
64
|
+
temp[key] = "********";
|
|
65
|
+
} else {
|
|
66
|
+
temp[key] = data[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return temp
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
52
74
|
const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
|
|
53
75
|
const requestServerStartTime = Date.now();
|
|
54
76
|
|
|
@@ -78,7 +100,8 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
|
|
|
78
100
|
try {
|
|
79
101
|
responseData = JSON.stringify(data.data);
|
|
80
102
|
} catch (err) {}
|
|
81
|
-
|
|
103
|
+
scrub(requestArgs)
|
|
104
|
+
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', scrubbedArgs, 'Response data:', responseData);
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
serverPreperationTimeMs = Number(polyHeaders['x-poly-execution-duration']);
|
|
@@ -96,6 +119,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
|
|
|
96
119
|
})
|
|
97
120
|
}).then(({ headers, data, status }) => {
|
|
98
121
|
if (status && (status < 200 || status >= 300) && process.env.LOGS_ENABLED) {
|
|
122
|
+
scrub(requestArgs)
|
|
99
123
|
console.error('Error direct executing api function with id:', id, 'Status code:', status, 'Request data:', requestArgs, 'Response data:', data.data);
|
|
100
124
|
}
|
|
101
125
|
const apiExecutionTimeMs = Date.now() - requestApiStartTime;
|
|
@@ -127,6 +151,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
|
|
|
127
151
|
try {
|
|
128
152
|
responseData = JSON.stringify(data.data);
|
|
129
153
|
} catch (err) {}
|
|
154
|
+
scrub(requestArgs)
|
|
130
155
|
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
|
|
131
156
|
}
|
|
132
157
|
const serverExecutionTimeMs = Number(headers['x-poly-execution-duration']);
|
package/build/templates/axios.js
CHANGED
|
@@ -5,6 +5,7 @@ const https = require('https');
|
|
|
5
5
|
const dotenv = require('dotenv');
|
|
6
6
|
const polyCustom = require('./poly-custom');
|
|
7
7
|
const { API_KEY, API_BASE_URL } = require('./constants');
|
|
8
|
+
import { scrub } from './api-index.js'
|
|
8
9
|
|
|
9
10
|
dotenv.config();
|
|
10
11
|
|
|
@@ -43,13 +44,16 @@ axios.interceptors.request.use(
|
|
|
43
44
|
);
|
|
44
45
|
|
|
45
46
|
const scrubKeys = (err) => {
|
|
46
|
-
if (err.request
|
|
47
|
+
if (!err.request || typeof err.request.headers !== 'object') throw err
|
|
48
|
+
const temp = scrub(err.request.headers)
|
|
49
|
+
if (err.request.headers.Authorization) {
|
|
47
50
|
// Scrub any credentials in the authorization header
|
|
48
51
|
const [type, ...rest] = err.request.headers.Authorization.split(' ');
|
|
49
|
-
|
|
52
|
+
temp.Authorization = rest.length && type
|
|
50
53
|
? `${type} ********`
|
|
51
54
|
: `********`;
|
|
52
55
|
}
|
|
56
|
+
err.request.headers = temp
|
|
53
57
|
throw err;
|
|
54
58
|
};
|
|
55
59
|
|
|
@@ -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<{
|