polyapi 0.23.18 → 0.23.20
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.
- package/build/api.d.ts.map +1 -1
- package/build/api.js +18 -16
- package/build/api.js.map +1 -1
- package/build/cli.js +38 -25
- package/build/cli.js.map +1 -1
- package/build/commands/function.d.ts.map +1 -1
- package/build/commands/function.js +6 -4
- package/build/commands/function.js.map +1 -1
- package/build/commands/generate/index.d.ts.map +1 -1
- package/build/commands/generate/index.js +25 -25
- package/build/commands/generate/index.js.map +1 -1
- package/build/commands/generate/schemaTypes.d.ts +4 -5
- package/build/commands/generate/schemaTypes.d.ts.map +1 -1
- package/build/commands/generate/schemaTypes.js +173 -88
- package/build/commands/generate/schemaTypes.js.map +1 -1
- package/build/commands/generate/types.d.ts.map +1 -1
- package/build/commands/generate/types.js +70 -31
- package/build/commands/generate/types.js.map +1 -1
- package/build/commands/model/generate.d.ts.map +1 -1
- package/build/commands/model/generate.js +26 -9
- package/build/commands/model/generate.js.map +1 -1
- package/build/commands/model/train.d.ts.map +1 -1
- package/build/commands/model/train.js +9 -3
- package/build/commands/model/train.js.map +1 -1
- package/build/commands/model/validate.d.ts.map +1 -1
- package/build/commands/model/validate.js +9 -3
- package/build/commands/model/validate.js.map +1 -1
- package/build/commands/prepare.d.ts.map +1 -1
- package/build/commands/prepare.js +11 -8
- package/build/commands/prepare.js.map +1 -1
- package/build/commands/setup.d.ts.map +1 -1
- package/build/commands/setup.js +10 -5
- package/build/commands/setup.js.map +1 -1
- package/build/commands/snippet.d.ts.map +1 -1
- package/build/commands/snippet.js +3 -1
- package/build/commands/snippet.js.map +1 -1
- package/build/commands/sync.d.ts.map +1 -1
- package/build/commands/sync.js +5 -3
- package/build/commands/sync.js.map +1 -1
- package/build/commands/tenant.d.ts.map +1 -1
- package/build/commands/tenant.js +6 -6
- package/build/commands/tenant.js.map +1 -1
- package/build/config.d.ts.map +1 -1
- package/build/config.js.map +1 -1
- package/build/dependencies.d.ts.map +1 -1
- package/build/dependencies.js +3 -1
- package/build/dependencies.js.map +1 -1
- package/build/deployables.d.ts.map +1 -1
- package/build/deployables.js +45 -22
- package/build/deployables.js.map +1 -1
- package/build/templates/api-functions.js.hbs +18 -0
- package/build/templates/api-index.js +153 -0
- package/build/templates/auth-function.js.hbs +2 -2
- package/build/templates/auth-index.js.hbs +9 -2
- package/build/templates/{axios.js.hbs → axios.js} +15 -3
- package/build/templates/constants.js.hbs +5 -0
- package/build/templates/{index.js.hbs → index.js} +8 -9
- package/build/templates/server-functions.js.hbs +7 -0
- package/build/templates/server-index.js +19 -0
- package/build/templates/vari/index.js.hbs +5 -5
- package/build/templates/webhook-handles.js.hbs +11 -0
- package/build/templates/{webhooks-index.js.hbs → webhooks-index.js} +4 -17
- package/build/transpiler.d.ts.map +1 -1
- package/build/transpiler.js +62 -40
- package/build/transpiler.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types/functions.d.ts.map +1 -1
- package/build/types/specifications.d.ts.map +1 -1
- package/build/types/templates.d.ts.map +1 -1
- package/build/utils.d.ts +1 -0
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +13 -7
- package/build/utils.js.map +1 -1
- package/package.json +2 -2
- package/build/templates/api-index.js.hbs +0 -148
- package/build/templates/server-index.js.hbs +0 -30
- /package/build/templates/{error-handler.js.hbs → error-handler.js} +0 -0
package/build/deployables.js
CHANGED
|
@@ -25,17 +25,17 @@ const prepareDeployableDirectory = async () => {
|
|
|
25
25
|
exports.prepareDeployableDirectory = prepareDeployableDirectory;
|
|
26
26
|
const loadDeployableRecords = async () => {
|
|
27
27
|
const cachedRecords = (await (0, promises_1.readdir)(exports.CACHE_DIR, { withFileTypes: true }))
|
|
28
|
-
.filter(d => d.isFile() && d.name.endsWith('.json'))
|
|
29
|
-
.map(d => d.name);
|
|
30
|
-
return Promise.all(cachedRecords.map(name => readJsonFile(`${exports.CACHE_DIR}/${name}`)));
|
|
28
|
+
.filter((d) => d.isFile() && d.name.endsWith('.json'))
|
|
29
|
+
.map((d) => d.name);
|
|
30
|
+
return Promise.all(cachedRecords.map((name) => readJsonFile(`${exports.CACHE_DIR}/${name}`)));
|
|
31
31
|
};
|
|
32
32
|
exports.loadDeployableRecords = loadDeployableRecords;
|
|
33
33
|
const saveDeployableRecords = async (records) => {
|
|
34
|
-
await Promise.all(records.map(record => writeJsonFile(`${exports.CACHE_DIR}/${record.context}.${record.name}.json`, record)));
|
|
34
|
+
await Promise.all(records.map((record) => writeJsonFile(`${exports.CACHE_DIR}/${record.context}.${record.name}.json`, record)));
|
|
35
35
|
};
|
|
36
36
|
exports.saveDeployableRecords = saveDeployableRecords;
|
|
37
37
|
const removeDeployableRecords = async (records) => {
|
|
38
|
-
shelljs_1.default.rm('-f', ...records.map(record => `${exports.CACHE_DIR}/${record.context}.${record.name}.json`));
|
|
38
|
+
shelljs_1.default.rm('-f', ...records.map((record) => `${exports.CACHE_DIR}/${record.context}.${record.name}.json`));
|
|
39
39
|
};
|
|
40
40
|
exports.removeDeployableRecords = removeDeployableRecords;
|
|
41
41
|
const readJsonFile = async (path) => {
|
|
@@ -44,15 +44,24 @@ const readJsonFile = async (path) => {
|
|
|
44
44
|
};
|
|
45
45
|
const writeJsonFile = async (path, contents) => {
|
|
46
46
|
await (0, promises_1.open)(path, 'w');
|
|
47
|
-
return (0, promises_1.writeFile)(path, JSON.stringify(contents, undefined, 2), {
|
|
47
|
+
return (0, promises_1.writeFile)(path, JSON.stringify(contents, undefined, 2), {
|
|
48
|
+
encoding: 'utf8',
|
|
49
|
+
flag: 'w',
|
|
50
|
+
});
|
|
48
51
|
};
|
|
49
52
|
const getAllDeployableFilesWindows = ({ typeNames, includeDirs, includeFilesOrExtensions, excludeDirs, }) => {
|
|
50
|
-
const includePattern = includeFilesOrExtensions.length > 0
|
|
53
|
+
const includePattern = includeFilesOrExtensions.length > 0
|
|
54
|
+
? includeFilesOrExtensions
|
|
55
|
+
.map((f) => (f.includes('.') ? f : `*.${f}`))
|
|
56
|
+
.join(' ')
|
|
57
|
+
: '*';
|
|
51
58
|
const excludePattern = excludeDirs.length > 0 ? excludeDirs.join('|') : '';
|
|
52
59
|
const pattern = typeNames.length > 0
|
|
53
60
|
? typeNames.map((name) => `polyConfig: ${name}`).join('|')
|
|
54
61
|
: 'polyConfig';
|
|
55
|
-
const excludeCommand = excludePattern
|
|
62
|
+
const excludeCommand = excludePattern
|
|
63
|
+
? ` | findstr /V /I "${excludePattern}"`
|
|
64
|
+
: '';
|
|
56
65
|
const searchCommand = ` | findstr /M /I /F:/ /C:"${pattern}"`;
|
|
57
66
|
let result = [];
|
|
58
67
|
for (const dir of includeDirs) {
|
|
@@ -69,26 +78,31 @@ const getAllDeployableFilesWindows = ({ typeNames, includeDirs, includeFilesOrEx
|
|
|
69
78
|
exports.getAllDeployableFilesWindows = getAllDeployableFilesWindows;
|
|
70
79
|
const getAllDeployableFilesLinux = ({ typeNames, includeDirs, includeFilesOrExtensions, excludeDirs, }) => {
|
|
71
80
|
const include = includeFilesOrExtensions.length
|
|
72
|
-
? includeFilesOrExtensions
|
|
81
|
+
? includeFilesOrExtensions
|
|
82
|
+
.map((f) => {
|
|
73
83
|
return `--include=${f.includes('.') ? f : `*.${f}`}`;
|
|
74
|
-
})
|
|
84
|
+
})
|
|
85
|
+
.join(' ')
|
|
75
86
|
: '';
|
|
76
|
-
const excludeDir = excludeDirs.length
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
const excludeDir = excludeDirs.length
|
|
88
|
+
? excludeDirs.map((dir) => `--exclude-dir=${dir}`).join(' ')
|
|
89
|
+
: '';
|
|
90
|
+
const searchPath = includeDirs.length ? includeDirs.join(' ') : '.';
|
|
80
91
|
const patterns = typeNames.length > 0
|
|
81
92
|
? typeNames.map((name) => `-e 'polyConfig: ${name}'`).join(' ')
|
|
82
|
-
:
|
|
93
|
+
: "-e 'polyConfig'";
|
|
83
94
|
const grepCommand = `grep ${include} ${excludeDir} -Rl ${patterns} ${searchPath}`;
|
|
84
95
|
const output = shelljs_1.default.exec(grepCommand).toString('utf8');
|
|
85
96
|
return output.split('\n').filter(Boolean);
|
|
86
97
|
};
|
|
87
98
|
exports.getAllDeployableFilesLinux = getAllDeployableFilesLinux;
|
|
88
99
|
const getAllDeployableFiles = (config = {}) => {
|
|
89
|
-
config.typeNames = config.typeNames = exports.DeployableTypeEntries.map(p => p[0]);
|
|
100
|
+
config.typeNames = config.typeNames = exports.DeployableTypeEntries.map((p) => p[0]);
|
|
90
101
|
config.includeDirs = config.includeDirs = ['.'];
|
|
91
|
-
config.includeFilesOrExtensions = config.includeFilesOrExtensions = [
|
|
102
|
+
config.includeFilesOrExtensions = config.includeFilesOrExtensions = [
|
|
103
|
+
'ts',
|
|
104
|
+
'js',
|
|
105
|
+
];
|
|
92
106
|
config.excludeDirs = config.excludeDirs = [
|
|
93
107
|
'node_modules',
|
|
94
108
|
'dist',
|
|
@@ -113,7 +127,10 @@ const getDeployableFileRevision = (fileContents) => (0, crypto_1.createHash)('sh
|
|
|
113
127
|
exports.getDeployableFileRevision = getDeployableFileRevision;
|
|
114
128
|
const getGitRevision = (branchOrTag = 'HEAD') => {
|
|
115
129
|
try {
|
|
116
|
-
const result = shelljs_1.default
|
|
130
|
+
const result = shelljs_1.default
|
|
131
|
+
.exec(`git rev-parse --short ${branchOrTag}`)
|
|
132
|
+
.toString('utf8')
|
|
133
|
+
.trim();
|
|
117
134
|
if (!result)
|
|
118
135
|
throw new Error('Failed to get git revision.');
|
|
119
136
|
return result;
|
|
@@ -151,15 +168,20 @@ const writeDeployComments = (deployments) => {
|
|
|
151
168
|
? 'polyui/collections'
|
|
152
169
|
: 'canopy/polyui/collections';
|
|
153
170
|
return deployments
|
|
154
|
-
.map(d => `// Poly deployed @ ${d.deployed} - ${d.context}.${d.name} - ${d.instance.endsWith(':8000')
|
|
171
|
+
.map((d) => `// Poly deployed @ ${d.deployed} - ${d.context}.${d.name} - ${d.instance.endsWith(':8000')
|
|
172
|
+
? d.instance.replace(':8000', ':3000')
|
|
173
|
+
: d.instance}/${canopyPath}/${d.type}s/${d.id} - ${d.fileRevision}`)
|
|
174
|
+
.join('\n');
|
|
155
175
|
};
|
|
156
176
|
exports.writeDeployComments = writeDeployComments;
|
|
157
177
|
const printJSDocFunctionComment = ({ description, params, returns }) => {
|
|
158
178
|
return `/**\n${[
|
|
159
179
|
...description.split('\n').filter(Boolean),
|
|
160
|
-
...params.map(p => `@param {${p.type}} ${p.name}${p.description ? ' - ' : ''}${p.description}`),
|
|
180
|
+
...params.map((p) => `@param {${p.type}} ${p.name}${p.description ? ' - ' : ''}${p.description}`),
|
|
161
181
|
`@returns {${returns.type}} ${returns.description}`,
|
|
162
|
-
]
|
|
182
|
+
]
|
|
183
|
+
.map((l) => ` * ${l}`)
|
|
184
|
+
.join('\n')}\n */\n`;
|
|
163
185
|
};
|
|
164
186
|
const updateDeploymentComments = (fileContent, deployable) => {
|
|
165
187
|
while (deployable.deploymentCommentRanges.length > 0) {
|
|
@@ -195,8 +217,9 @@ const writeUpdatedDeployable = async (deployable, disableDocs = false) => {
|
|
|
195
217
|
default:
|
|
196
218
|
throw new Error(`Unsupported deployable type: '${deployable.type}'`);
|
|
197
219
|
}
|
|
198
|
-
if (deployable.type !== 'webhook')
|
|
220
|
+
if (deployable.type !== 'webhook') {
|
|
199
221
|
fileContents = updateDeploymentComments(fileContents, deployable);
|
|
222
|
+
}
|
|
200
223
|
await (0, promises_1.writeFile)(deployable.file, fileContents, {
|
|
201
224
|
flag: 'w',
|
|
202
225
|
encoding: 'utf8',
|
package/build/deployables.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployables.js","sourceRoot":"","sources":["../src/deployables.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,2BAAgC;AAChC,+CAA6E;AAC7E,sDAA4B;AAC5B,mCAAoC;AAEvB,QAAA,kBAAkB,GAAG,2CAA2C,CAAC;AACjE,QAAA,SA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1
|
+
// Environment variables injected during generation
|
|
2
|
+
const env = {
|
|
3
|
+
directExecute: {{executionConfig.directExecute}},
|
|
4
|
+
mtls: {
|
|
5
|
+
certPath: '{{executionConfig.mtls.certPath}}',
|
|
6
|
+
keyPath: '{{executionConfig.mtls.keyPath}}',
|
|
7
|
+
caPath: '{{executionConfig.mtls.caPath}}',
|
|
8
|
+
rejectUnauthorized: {{executionConfig.mtls.rejectUnauthorized}},
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const functions = [
|
|
13
|
+
{{#each specifications}}
|
|
14
|
+
['{{#if context}}{{context}}.{{/if}}{{name}}', '{{id}}',{{#each function.arguments}}'{{name}}',{{/each}}],
|
|
15
|
+
{{/each}}
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
module.exports = { env, functions };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const { axios } = require('../axios');
|
|
2
|
+
const set = require('lodash/set');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { env, functions } = require('./functions');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// Create MTLS agent if paths are provided
|
|
9
|
+
let httpsAgent = undefined;
|
|
10
|
+
const getHttpsAgent = () => {
|
|
11
|
+
if (httpsAgent) {
|
|
12
|
+
return httpsAgent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { mtls } = env;
|
|
16
|
+
if (!mtls.certPath || !mtls.keyPath || !mtls.caPath) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
httpsAgent = new https.Agent({
|
|
21
|
+
cert: fs.readFileSync(mtls.certPath),
|
|
22
|
+
key: fs.readFileSync(mtls.keyPath),
|
|
23
|
+
ca: fs.readFileSync(mtls.caPath),
|
|
24
|
+
rejectUnauthorized: mtls.rejectUnauthorized,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return httpsAgent;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const handleError = (err) => {
|
|
32
|
+
if (err.response) {
|
|
33
|
+
// The request was made and the server responded with a status code
|
|
34
|
+
// that falls out of the range of 2xx
|
|
35
|
+
return {
|
|
36
|
+
data: err.response.data,
|
|
37
|
+
status: err.response.status,
|
|
38
|
+
headers: { ...err.response.headers },
|
|
39
|
+
metrics: {},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Either the request was made but no response was received
|
|
43
|
+
// Or something happened in setting up the request that triggered an Error
|
|
44
|
+
return {
|
|
45
|
+
data: err.message,
|
|
46
|
+
status: err.request ? 500 : 400,
|
|
47
|
+
headers: {},
|
|
48
|
+
metrics: {},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
|
|
53
|
+
const requestServerStartTime = Date.now();
|
|
54
|
+
|
|
55
|
+
// Check if direct execution is enabled
|
|
56
|
+
const { directExecute } = env;
|
|
57
|
+
|
|
58
|
+
if (directExecute === true) {
|
|
59
|
+
// Make direct API call
|
|
60
|
+
|
|
61
|
+
let polyHeaders;
|
|
62
|
+
let serverPreperationTimeMs;
|
|
63
|
+
let roundTripServerNetworkLatencyMs;
|
|
64
|
+
let requestApiStartTime;
|
|
65
|
+
|
|
66
|
+
return axios.post(
|
|
67
|
+
`/functions/api/${id}/direct-execute?clientId=${clientID}`,
|
|
68
|
+
requestArgs,
|
|
69
|
+
{
|
|
70
|
+
headers: {
|
|
71
|
+
'x-poly-execution-id': polyCustom.executionId,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
).then(({ headers, data }) => {
|
|
75
|
+
polyHeaders = headers;
|
|
76
|
+
if (data && (data.status < 200 || data.status >= 300)) {
|
|
77
|
+
let responseData = data.data;
|
|
78
|
+
try {
|
|
79
|
+
responseData = JSON.stringify(data.data);
|
|
80
|
+
} catch (err) {}
|
|
81
|
+
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
serverPreperationTimeMs = Number(polyHeaders['x-poly-execution-duration']);
|
|
85
|
+
roundTripServerNetworkLatencyMs = Date.now() - requestServerStartTime - serverPreperationTimeMs;
|
|
86
|
+
|
|
87
|
+
requestApiStartTime = Date.now();
|
|
88
|
+
const httpsAgent = getHttpsAgent();
|
|
89
|
+
|
|
90
|
+
return axios({
|
|
91
|
+
...data,
|
|
92
|
+
headers: {
|
|
93
|
+
...data.headers,
|
|
94
|
+
},
|
|
95
|
+
httpsAgent,
|
|
96
|
+
})
|
|
97
|
+
}).then(({ headers, data, status }) => {
|
|
98
|
+
if (status && (status < 200 || status >= 300)) {
|
|
99
|
+
console.error('Error direct executing api function with id:', id, 'Status code:', status, 'Request data:', requestArgs, 'Response data:', data.data);
|
|
100
|
+
}
|
|
101
|
+
const apiExecutionTimeMs = Date.now() - requestApiStartTime;
|
|
102
|
+
return {
|
|
103
|
+
data: data,
|
|
104
|
+
status: status,
|
|
105
|
+
headers: { ...headers },
|
|
106
|
+
metrics: {
|
|
107
|
+
roundTripServerNetworkLatencyMs,
|
|
108
|
+
serverPreperationTimeMs,
|
|
109
|
+
apiExecutionTimeMs,
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}).catch(handleError);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// default indirect execution
|
|
116
|
+
return axios.post(
|
|
117
|
+
`/functions/api/${id}/execute?clientId=${clientID}`,
|
|
118
|
+
requestArgs,
|
|
119
|
+
{
|
|
120
|
+
headers: {
|
|
121
|
+
'x-poly-execution-id': polyCustom.executionId,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
).then(({ headers, data }) => {
|
|
125
|
+
if (data && (data.status < 200 || data.status >= 300)) {
|
|
126
|
+
let responseData = data.data;
|
|
127
|
+
try {
|
|
128
|
+
responseData = JSON.stringify(data.data);
|
|
129
|
+
} catch (err) {}
|
|
130
|
+
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
|
|
131
|
+
}
|
|
132
|
+
const serverExecutionTimeMs = Number(headers['x-poly-execution-duration']);
|
|
133
|
+
const roundTripNetworkLatencyMs = Date.now() - requestServerStartTime - serverExecutionTimeMs;
|
|
134
|
+
return {
|
|
135
|
+
...data,
|
|
136
|
+
metrics: {
|
|
137
|
+
roundTripNetworkLatencyMs,
|
|
138
|
+
serverExecutionTimeMs,
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}).catch(handleError);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = (clientID, polyCustom) => functions.reduce(
|
|
145
|
+
(acc, [path, id, ...argKeys]) => set(
|
|
146
|
+
acc,
|
|
147
|
+
path,
|
|
148
|
+
(...args) => {
|
|
149
|
+
const requestArgs = argKeys.reduce((acc, key, index) => set(acc, key, args[index]), {});
|
|
150
|
+
return executeApiFunction(id, clientID, polyCustom, requestArgs);
|
|
151
|
+
}),
|
|
152
|
+
{}
|
|
153
|
+
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const axios = require('../axios');
|
|
1
|
+
const { axios, scrubKeys } = require('../axios');
|
|
2
2
|
|
|
3
3
|
module.exports = function(eventsClientId, getSocket, getApiKey, clientId, clientSecret, {{#if audienceRequired}}audience, scopes, callback, { callbackUrl, timeout = 120000, autoCloseOnToken = true, autoCloseOnUrl = false, userId } = {}{{else}}scopes, callback, { audience, callbackUrl, timeout = 120000, autoCloseOnToken = true, autoCloseOnUrl = false, userId } = {}{{/if}}) {
|
|
4
4
|
if (userId) {
|
|
@@ -60,7 +60,7 @@ module.exports = function(eventsClientId, getSocket, getApiKey, clientId, client
|
|
|
60
60
|
callback(null, null, { message: 'Timeout reached' });
|
|
61
61
|
}, timeout);
|
|
62
62
|
}
|
|
63
|
-
});
|
|
63
|
+
}).catch(scrubKeys);
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
66
|
close: closeEventHandler,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const axios = require('../axios');
|
|
1
|
+
const { axios, scrubKeys } = require('../axios');
|
|
2
2
|
const set = require('lodash/set');
|
|
3
3
|
const merge = require('lodash/merge');
|
|
4
4
|
|
|
@@ -28,7 +28,14 @@ module.exports = (clientID, getSocket, getApiKey) => merge(
|
|
|
28
28
|
{}
|
|
29
29
|
),
|
|
30
30
|
subResourceFunctions.reduce(
|
|
31
|
-
(acc, [path, resource]) => set(
|
|
31
|
+
(acc, [path, resource]) => set(
|
|
32
|
+
acc,
|
|
33
|
+
path,
|
|
34
|
+
(token) =>
|
|
35
|
+
axios.post(`/auth-providers/${resource}`, { clientID, token })
|
|
36
|
+
.then(({ data }) => data)
|
|
37
|
+
.catch(scrubKeys)
|
|
38
|
+
),
|
|
32
39
|
{}
|
|
33
40
|
)
|
|
34
41
|
);
|
|
@@ -4,6 +4,7 @@ const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const dotenv = require('dotenv');
|
|
6
6
|
const polyCustom = require('./poly-custom');
|
|
7
|
+
const { API_KEY, API_BASE_URL } = require('./constants');
|
|
7
8
|
|
|
8
9
|
dotenv.config();
|
|
9
10
|
|
|
@@ -12,7 +13,7 @@ const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy || process
|
|
|
12
13
|
const nodeEnv = process.env.NODE_ENV;
|
|
13
14
|
const isDevEnv = nodeEnv === 'development';
|
|
14
15
|
|
|
15
|
-
let baseURL =
|
|
16
|
+
let baseURL = API_BASE_URL;
|
|
16
17
|
if (!isDevEnv) {
|
|
17
18
|
baseURL = baseURL.replace(/^http:/, 'https:');
|
|
18
19
|
}
|
|
@@ -33,7 +34,7 @@ const axios = Axios.create({
|
|
|
33
34
|
});
|
|
34
35
|
axios.interceptors.request.use(
|
|
35
36
|
config => {
|
|
36
|
-
config.headers['Authorization'] = `Bearer ${polyCustom.executionApiKey ||
|
|
37
|
+
config.headers['Authorization'] = `Bearer ${polyCustom.executionApiKey || API_KEY}`;
|
|
37
38
|
return config;
|
|
38
39
|
},
|
|
39
40
|
error => {
|
|
@@ -41,4 +42,15 @@ axios.interceptors.request.use(
|
|
|
41
42
|
}
|
|
42
43
|
);
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
const scrubKeys = (err) => {
|
|
46
|
+
if (err.request) {
|
|
47
|
+
// Scrub the api key in the authorization header
|
|
48
|
+
err.request.headers['Authorization'] = `Bearer ********`;
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
axios,
|
|
55
|
+
scrubKeys
|
|
56
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const set = require('lodash/set');
|
|
2
1
|
const merge = require('lodash/merge');
|
|
3
2
|
const { io } = require('socket.io-client');
|
|
4
3
|
const apiFunctions = require('./api');
|
|
@@ -9,8 +8,8 @@ const serverFunctions = require('./server');
|
|
|
9
8
|
const vari = require('./vari');
|
|
10
9
|
const polyCustom = require('./poly-custom');
|
|
11
10
|
const { createErrorHandler, sendLocalErrorEvent } = require('./error-handler');
|
|
11
|
+
const { CLIENT_ID, API_KEY, API_BASE_URL } = require('./constants');
|
|
12
12
|
|
|
13
|
-
const clientID = '{{clientID}}';
|
|
14
13
|
const nodeEnv = process.env.NODE_ENV;
|
|
15
14
|
const isDevEnv = nodeEnv === 'development';
|
|
16
15
|
|
|
@@ -18,7 +17,7 @@ let socket = null;
|
|
|
18
17
|
let listenersCount = 0;
|
|
19
18
|
|
|
20
19
|
const getSocket = () => {
|
|
21
|
-
let apiBaseUrl =
|
|
20
|
+
let apiBaseUrl = API_BASE_URL;
|
|
22
21
|
if (!isDevEnv) {
|
|
23
22
|
apiBaseUrl = apiBaseUrl.replace(/^http:/, 'https:');
|
|
24
23
|
}
|
|
@@ -58,20 +57,20 @@ const getSocket = () => {
|
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
|
-
const getApiKey = () => polyCustom.executionApiKey ||
|
|
60
|
+
const getApiKey = () => polyCustom.executionApiKey || API_KEY;
|
|
62
61
|
const poly = {};
|
|
63
62
|
|
|
64
63
|
merge(
|
|
65
64
|
poly,
|
|
66
|
-
apiFunctions(
|
|
65
|
+
apiFunctions(CLIENT_ID, polyCustom),
|
|
67
66
|
clientFunctions(poly, sendLocalErrorEvent),
|
|
68
|
-
serverFunctions(
|
|
69
|
-
authFunctions(
|
|
70
|
-
webhooks(
|
|
67
|
+
serverFunctions(CLIENT_ID, polyCustom),
|
|
68
|
+
authFunctions(CLIENT_ID, getSocket, getApiKey),
|
|
69
|
+
webhooks(CLIENT_ID, getSocket, getApiKey),
|
|
71
70
|
),
|
|
72
71
|
module.exports = {
|
|
73
72
|
...poly,
|
|
74
73
|
errorHandler: createErrorHandler(getApiKey, getSocket),
|
|
75
|
-
vari: vari(
|
|
74
|
+
vari: vari(CLIENT_ID, getSocket, getApiKey),
|
|
76
75
|
polyCustom,
|
|
77
76
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { axios, scrubKeys } = require('../axios');
|
|
2
|
+
const set = require('lodash/set');
|
|
3
|
+
const { functions } = require('./functions');
|
|
4
|
+
|
|
5
|
+
module.exports = (clientID, polyCustom) => functions.reduce(
|
|
6
|
+
(acc, [path, id, ...argKeys]) => set(
|
|
7
|
+
acc,
|
|
8
|
+
path,
|
|
9
|
+
(...args) => axios.post(
|
|
10
|
+
`/functions/server/${id}/execute?clientId=${clientID}`,
|
|
11
|
+
argKeys.reduce((acc, key, index) => set(acc, key, args[index]), {}),
|
|
12
|
+
{
|
|
13
|
+
headers: {
|
|
14
|
+
'x-poly-execution-id': polyCustom.executionId,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
).then(({ data }) => data)).catch(scrubKeys),
|
|
18
|
+
{}
|
|
19
|
+
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const axios = require('../axios');
|
|
1
|
+
const { axios, scrubKeys } = require('../axios');
|
|
2
2
|
const set = require('lodash/set');
|
|
3
3
|
const get = require('lodash/get');
|
|
4
4
|
const merge = require('lodash/merge');
|
|
@@ -49,7 +49,7 @@ const getVariableHandlers = (clientID, getSocket, getApiKey) => {
|
|
|
49
49
|
} else {
|
|
50
50
|
return axios.get(
|
|
51
51
|
`/variables/${id}/value`
|
|
52
|
-
).then(({data}) => data);
|
|
52
|
+
).then(({data}) => data).catch(scrubKeys);
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
update: (value) => {
|
|
@@ -62,7 +62,7 @@ const getVariableHandlers = (clientID, getSocket, getApiKey) => {
|
|
|
62
62
|
status: response.status,
|
|
63
63
|
headers: response.headers,
|
|
64
64
|
};
|
|
65
|
-
});
|
|
65
|
+
}).catch(scrubKeys);
|
|
66
66
|
},
|
|
67
67
|
onUpdate: (callback) => {
|
|
68
68
|
const socket = getSocket();
|
|
@@ -181,7 +181,7 @@ const getPathHandlers = () => {
|
|
|
181
181
|
get: () => {
|
|
182
182
|
return axios.get(
|
|
183
183
|
`/variables/context/values`
|
|
184
|
-
).then(({data}) => data);
|
|
184
|
+
).then(({data}) => data).catch(scrubKeys);
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
contextPaths.forEach(path => {
|
|
@@ -189,7 +189,7 @@ const getPathHandlers = () => {
|
|
|
189
189
|
get: () => {
|
|
190
190
|
return axios.get(
|
|
191
191
|
`/variables/context/${path}/values`
|
|
192
|
-
).then(({data}) => data);
|
|
192
|
+
).then(({data}) => data).catch(scrubKeys);
|
|
193
193
|
},
|
|
194
194
|
});
|
|
195
195
|
});
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
const set = require('lodash/set');
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const webhookHandles = [
|
|
5
|
-
{{#each specifications}}
|
|
6
|
-
{{#if context}}
|
|
7
|
-
['{{context}}.{{name}}', '{{id}}'],
|
|
8
|
-
{{else}}
|
|
9
|
-
['{{name}}', '{{id}}'],
|
|
10
|
-
{{/if}}
|
|
11
|
-
{{/each}}
|
|
12
|
-
];
|
|
2
|
+
const { handles } = require('./handles');
|
|
13
3
|
|
|
14
4
|
const registerWebhookEventListener = (clientID, getSocket, getApiKey, webhookHandleID, options, callback) => {
|
|
15
5
|
const socket = getSocket();
|
|
@@ -55,10 +45,7 @@ const registerWebhookEventListener = (clientID, getSocket, getApiKey, webhookHan
|
|
|
55
45
|
}
|
|
56
46
|
};
|
|
57
47
|
|
|
58
|
-
module.exports = (clientID, getSocket, getApiKey) =>
|
|
59
|
-
{},
|
|
60
|
-
|
|
61
|
-
(acc, [path, id]) => set(acc, path, (callback, options = {}) => registerWebhookEventListener(clientID, getSocket, getApiKey, id, options, callback)),
|
|
62
|
-
{}
|
|
63
|
-
),
|
|
48
|
+
module.exports = (clientID, getSocket, getApiKey) => handles.reduce(
|
|
49
|
+
(acc, [path, id]) => set(acc, path, (callback, options = {}) => registerWebhookEventListener(clientID, getSocket, getApiKey, id, options, callback)),
|
|
50
|
+
{}
|
|
64
51
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../src/transpiler.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAIhB,UAAU,EAGX,MAAM,eAAe,CAAC;AA6CvB,eAAO,MAAM,WAAW,WAMvB,CAAC;AAEF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../src/transpiler.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAIhB,UAAU,EAGX,MAAM,eAAe,CAAC;AA6CvB,eAAO,MAAM,WAAW,WAMvB,CAAC;AAEF,eAAO,MAAM,YAAY,uBACqB,CAAC;AAmB/C,eAAO,MAAM,eAAe,SACpB,MAAM,YACF,MAAM,WACP,MAAM,GAAG,SAAS,aAwG5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,MAAM,WACP,MAAM,GAAG,SAAS,qBACR,MAAM,EAAE;;CAoN5B,CAAC;AAsDF,eAAO,MAAM,kBAAkB,YAAa,MAAM,KAAG,UAmBpD,CAAC;AA6PF,eAAO,MAAM,eAAe,aAChB,MAAM,WACP,MAAM,eACF,MAAM,KAClB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,CA6CpC,CAAC"}
|