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
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const axios = require('../axios');
|
|
2
|
-
const set = require('lodash/set');
|
|
3
|
-
const merge = require('lodash/merge');
|
|
4
|
-
const https = require('https');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
|
|
7
|
-
// Environment variables injected during generation
|
|
8
|
-
const env = {
|
|
9
|
-
directExecute: {{executionConfig.directExecute}},
|
|
10
|
-
mtls: {
|
|
11
|
-
certPath: '{{executionConfig.mtls.certPath}}',
|
|
12
|
-
keyPath: '{{executionConfig.mtls.keyPath}}',
|
|
13
|
-
caPath: '{{executionConfig.mtls.caPath}}',
|
|
14
|
-
rejectUnauthorized: {{executionConfig.mtls.rejectUnauthorized}},
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const functions = [
|
|
19
|
-
{{#each specifications}}
|
|
20
|
-
['{{#if context}}{{context}}.{{/if}}{{name}}', '{{id}}',{{#each function.arguments}}'{{name}}',{{/each}}],
|
|
21
|
-
{{/each}}
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
// Create MTLS agent if paths are provided
|
|
25
|
-
let httpsAgent = undefined;
|
|
26
|
-
const getHttpsAgent = () => {
|
|
27
|
-
if (httpsAgent) {
|
|
28
|
-
return httpsAgent;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { mtls } = env;
|
|
32
|
-
if (!mtls.certPath || !mtls.keyPath || !mtls.caPath) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
httpsAgent = new https.Agent({
|
|
37
|
-
cert: fs.readFileSync(mtls.certPath),
|
|
38
|
-
key: fs.readFileSync(mtls.keyPath),
|
|
39
|
-
ca: fs.readFileSync(mtls.caPath),
|
|
40
|
-
rejectUnauthorized: mtls.rejectUnauthorized,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return httpsAgent;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
module.exports = (clientID, polyCustom) => merge(
|
|
47
|
-
{},
|
|
48
|
-
functions.reduce(
|
|
49
|
-
(acc, [path, id, ...argKeys]) => set(
|
|
50
|
-
acc,
|
|
51
|
-
path,
|
|
52
|
-
(...args) => {
|
|
53
|
-
const requestServerStartTime = Date.now();
|
|
54
|
-
const requestArgs = argKeys.reduce((acc, key, index) => ({ ...acc, [key]: args[index] }), {});
|
|
55
|
-
|
|
56
|
-
// Check if direct execution is enabled
|
|
57
|
-
const { directExecute } = env;
|
|
58
|
-
|
|
59
|
-
if (directExecute === true) {
|
|
60
|
-
// Make direct API call
|
|
61
|
-
|
|
62
|
-
let polyHeaders;
|
|
63
|
-
let serverPreperationTimeMs;
|
|
64
|
-
let roundTripServerNetworkLatencyMs;
|
|
65
|
-
let requestApiStartTime;
|
|
66
|
-
|
|
67
|
-
return axios.post(
|
|
68
|
-
`/functions/api/${id}/direct-execute?clientId=${clientID}`,
|
|
69
|
-
requestArgs,
|
|
70
|
-
{
|
|
71
|
-
headers: {
|
|
72
|
-
'x-poly-execution-id': polyCustom.executionId,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
).then(({ headers, data }) => {
|
|
76
|
-
polyHeaders = headers;
|
|
77
|
-
if (data && (data.status < 200 || data.status >= 300)) {
|
|
78
|
-
let responseData = data.data;
|
|
79
|
-
try {
|
|
80
|
-
responseData = JSON.stringify(data.data);
|
|
81
|
-
} catch (err) {}
|
|
82
|
-
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
serverPreperationTimeMs = Number(polyHeaders['x-poly-execution-duration']);
|
|
86
|
-
roundTripServerNetworkLatencyMs = Date.now() - requestServerStartTime - serverPreperationTimeMs;
|
|
87
|
-
|
|
88
|
-
requestApiStartTime = Date.now();
|
|
89
|
-
const httpsAgent = getHttpsAgent();
|
|
90
|
-
|
|
91
|
-
return axios({
|
|
92
|
-
...data,
|
|
93
|
-
headers: {
|
|
94
|
-
...data.headers,
|
|
95
|
-
},
|
|
96
|
-
httpsAgent,
|
|
97
|
-
})
|
|
98
|
-
}).then(({ headers, data, status, ...args }) => {
|
|
99
|
-
if (status && (status < 200 || status >= 300)) {
|
|
100
|
-
console.error('Error direct executing api function with id:', id, 'Status code:', status, 'Request data:', requestArgs, 'Response data:', data.data);
|
|
101
|
-
}
|
|
102
|
-
const apiExecutionTimeMs = Date.now() - requestApiStartTime;
|
|
103
|
-
return {
|
|
104
|
-
data: data,
|
|
105
|
-
status: status,
|
|
106
|
-
headers: { ...headers },
|
|
107
|
-
metrics: {
|
|
108
|
-
roundTripServerNetworkLatencyMs,
|
|
109
|
-
serverPreperationTimeMs,
|
|
110
|
-
apiExecutionTimeMs,
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// default indirect execution
|
|
117
|
-
return axios.post(
|
|
118
|
-
`/functions/api/${id}/execute?clientId=${clientID}`,
|
|
119
|
-
{
|
|
120
|
-
...requestArgs,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
headers: {
|
|
124
|
-
'x-poly-execution-id': polyCustom.executionId,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
).then(({ headers, data }) => {
|
|
128
|
-
if (data && (data.status < 200 || data.status >= 300)) {
|
|
129
|
-
let responseData = data.data;
|
|
130
|
-
try {
|
|
131
|
-
responseData = JSON.stringify(data.data);
|
|
132
|
-
} catch (err) {}
|
|
133
|
-
console.error('Error executing api function with id:', id, 'Status code:', data.status, 'Request data:', requestArgs, 'Response data:', responseData);
|
|
134
|
-
}
|
|
135
|
-
const serverExecutionTimeMs = Number(headers['x-poly-execution-duration']);
|
|
136
|
-
const roundTripNetworkLatencyMs = Date.now() - requestServerStartTime - serverExecutionTimeMs;
|
|
137
|
-
return {
|
|
138
|
-
...data,
|
|
139
|
-
metrics: {
|
|
140
|
-
roundTripNetworkLatencyMs,
|
|
141
|
-
serverExecutionTimeMs,
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
}),
|
|
146
|
-
{}
|
|
147
|
-
)
|
|
148
|
-
);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const axios = require('../axios');
|
|
2
|
-
const set = require('lodash/set');
|
|
3
|
-
const merge = require('lodash/merge');
|
|
4
|
-
|
|
5
|
-
const serverFunctions = [
|
|
6
|
-
{{#each specifications}}
|
|
7
|
-
['{{#if context}}{{context}}.{{/if}}{{name}}', '{{id}}',{{#each function.arguments}}`{{name}}`,{{/each}}],
|
|
8
|
-
{{/each}}
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
module.exports = (clientID, polyCustom) => merge(
|
|
12
|
-
{},
|
|
13
|
-
serverFunctions.reduce(
|
|
14
|
-
(acc, [path, id, ...argKeys]) => set(
|
|
15
|
-
acc,
|
|
16
|
-
path,
|
|
17
|
-
(...args) => axios.post(
|
|
18
|
-
`/functions/server/${id}/execute?clientId=${clientID}`,
|
|
19
|
-
{
|
|
20
|
-
...argKeys.reduce((acc, key, index) => ({ ...acc, [key]: args[index] }), {})
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
headers: {
|
|
24
|
-
'x-poly-execution-id': polyCustom.executionId,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
).then(({ data }) => data)),
|
|
28
|
-
{}
|
|
29
|
-
)
|
|
30
|
-
);
|
|
File without changes
|