diff --git a/package-lock.json b/package-lock.json index 29111cc..17d1b65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "polyapi", - "version": "0.24.8", + "version": "0.24.17", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "polyapi", - "version": "0.24.8", + "version": "0.24.17", "license": "MIT", "dependencies": { "@guanghechen/helper-string": "4.7.1", diff --git a/package.json b/package.json index b0ee3a3..7fba3c0 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "polyapi", - "version": "0.24.8", + "version": "0.24.17", "description": "Poly is a CLI tool to help create and manage your Poly definitions.", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/polyapi/poly-alpha", + "url": "https://github.com/polyapi/polyapi-typescript", "directory": "packages/client" }, "files": [ diff --git a/src/commands/generate/schemaTypes.ts b/src/commands/generate/schemaTypes.ts index 2fd0522..99ef2fc 100644 --- a/src/commands/generate/schemaTypes.ts +++ b/src/commands/generate/schemaTypes.ts @@ -5,6 +5,8 @@ import { EOL } from 'node:os'; import { SchemaRef, SchemaSpecification } from '../../types'; import { echoGenerationError } from '../../utils'; import { setGenerationErrors } from './types'; +import shell from 'shelljs' +import chalk from 'chalk'; const unsafeCharacters = /(?:^\d)|[^0-9a-zA-Z_]/gi; const unescapedSingleQuote = /\b'\b/gi; @@ -678,6 +680,9 @@ const fillInUnresolvedSchemas = (specs: SchemaSpec[]): SchemaSpec[] => { visibility: 'ENVIRONMENT', }, }; + // shell.echo( + // chalk.yellow(`WARNING: Schema '${unresolved.path}' referenced from '${spec.contextName}' is unresolved. Falling back to 'unknown' type for '${unresolved.path}'.`) + // ); schemas.set(unresolved.path, fillerSpec); } } @@ -704,6 +709,9 @@ const fillInUnresolvedSchemas = (specs: SchemaSpec[]): SchemaSpec[] => { visibility: 'ENVIRONMENT', }, }; + // shell.echo( + // chalk.yellow(`WARNING: Schema '${contextName}' referenced from '${spec.contextName}' is unresolved. Falling back to 'unknown' type for '${contextName}'.`) + // ); schemas.set(contextName, fillerSpec); } } diff --git a/templates/api-index.js b/templates/api-index.js index 22c3cf1..bc1307e 100644 --- a/templates/api-index.js +++ b/templates/api-index.js @@ -1,4 +1,4 @@ -const { axios } = require('../axios'); +const { axios, scrub } = require('../axios'); const set = require('lodash/set'); const https = require('https'); const fs = require('fs'); @@ -78,7 +78,8 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => { try { responseData = JSON.stringify(data.data); } catch (err) {} - console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData); + requestArgs = scrub(requestArgs) + console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', scrubbedArgs, 'Response data:', responseData); } serverPreperationTimeMs = Number(polyHeaders['x-poly-execution-duration']); @@ -96,6 +97,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => { }) }).then(({ headers, data, status }) => { if (status && (status < 200 || status >= 300) && process.env.LOGS_ENABLED) { + requestArgs = scrub(requestArgs) console.error('Error direct executing api function with id:', id, 'Status code:', status, 'Request data:', requestArgs, 'Response data:', data.data); } const apiExecutionTimeMs = Date.now() - requestApiStartTime; @@ -127,6 +129,7 @@ const executeApiFunction = (id, clientID, polyCustom, requestArgs) => { try { responseData = JSON.stringify(data.data); } catch (err) {} + requestArgs = scrub(requestArgs) console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData); } const serverExecutionTimeMs = Number(headers['x-poly-execution-duration']); diff --git a/templates/axios.js b/templates/axios.js index def97c4..55587b7 100644 --- a/templates/axios.js +++ b/templates/axios.js @@ -42,18 +42,45 @@ axios.interceptors.request.use( } ); + +const scrub = (data) => { + if (!data || typeof data !== 'object' ) return data; + const secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"]; + if (Array.isArray(data)) { + return data.map(item => scrub(item)) + } + else { + const temp = {}; + for (const key of Object.keys(data)) { + if (typeof data[key] === 'object') { + temp[key] = scrub(data[key]); + } else if (secrets.includes(key.toLowerCase())) { + temp[key] = "********"; + } else { + temp[key] = data[key]; + } + } + return temp + } +} + + const scrubKeys = (err) => { - if (err.request && typeof err.request.headers === 'object' && err.request.headers.Authorization) { + if (!err.request || typeof err.request.headers !== 'object') throw err + const temp = scrub(err.request.headers) + if (err.request.headers.Authorization) { // Scrub any credentials in the authorization header const [type, ...rest] = err.request.headers.Authorization.split(' '); - err.request.headers.Authorization = rest.length && type + temp.Authorization = rest.length && type ? `${type} ********` : `********`; } + err.request.headers = temp throw err; }; module.exports = { axios, - scrubKeys + scrubKeys, + scrub }; diff --git a/templates/tabi/types.d.ts b/templates/tabi/types.d.ts index c4a6391..675b10e 100644 --- a/templates/tabi/types.d.ts +++ b/templates/tabi/types.d.ts @@ -43,14 +43,14 @@ type PolyCountQuery> = Clean<{ type PolySelectOneQuery> = Clean<{ where?: Where; - orderBy?: Record; + orderBy?: Partial>; }>; type PolySelectManyQuery> = Clean<{ where?: Where; limit?: number; // 1000 is max limit for now offset?: number; - orderBy?: Record; + orderBy?: Partial>; }>; type PolyDeleteQuery> = Clean<{