@scout9/app 1.0.0-alpha.0.3.6 → 1.0.0-alpha.0.3.8
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/dist/{dev-689cc6fd.cjs → dev-0876e8d1.cjs} +3282 -3216
- package/dist/{index-0b4fa4ce.cjs → index-4b5094a1.cjs} +7 -15
- package/dist/index.cjs +3 -3
- package/dist/{macros-7c18e049.cjs → macros-e4105c56.cjs} +1 -0
- package/dist/{multipart-parser-4603e570.cjs → multipart-parser-723d74f7.cjs} +3 -3
- package/dist/schemas.cjs +1 -1
- package/dist/testing-tools.cjs +2 -2
- package/package.json +3 -2
- package/src/core/templates/app.js +42 -10
- package/src/runtime/macros/event.js +64 -23
- package/src/utils/error.js +10 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var spirits = require("./spirits-5c9243a1.cjs");
|
|
4
|
-
var dev = require("./dev-
|
|
5
|
-
var macros = require("./macros-
|
|
4
|
+
var dev = require("./dev-0876e8d1.cjs");
|
|
5
|
+
var macros = require("./macros-e4105c56.cjs");
|
|
6
6
|
var require$$0 = require('fs');
|
|
7
7
|
var require$$2$1 = require('events');
|
|
8
8
|
var require$$1 = require('path');
|
|
@@ -29483,7 +29483,7 @@ class Body {
|
|
|
29483
29483
|
}
|
|
29484
29484
|
const {
|
|
29485
29485
|
toFormData
|
|
29486
|
-
} = await Promise.resolve().then(function () { return require("./multipart-parser-
|
|
29486
|
+
} = await Promise.resolve().then(function () { return require("./multipart-parser-723d74f7.cjs"); });
|
|
29487
29487
|
return toFormData(this.body, ct);
|
|
29488
29488
|
}
|
|
29489
29489
|
|
|
@@ -31176,14 +31176,6 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
31176
31176
|
});
|
|
31177
31177
|
}
|
|
31178
31178
|
|
|
31179
|
-
/**
|
|
31180
|
-
* @param {unknown} err
|
|
31181
|
-
* @return {Error}
|
|
31182
|
-
*/
|
|
31183
|
-
function coalesceToError(err) {
|
|
31184
|
-
return err instanceof Error || err && /** @type {any} */err.name && /** @type {any} */err.message ? /** @type {Error} */err : new Error(JSON.stringify(err));
|
|
31185
|
-
}
|
|
31186
|
-
|
|
31187
31179
|
var fileType$6 = input => {
|
|
31188
31180
|
const buf = new Uint8Array(input);
|
|
31189
31181
|
if (!(buf && buf.length > 1)) {
|
|
@@ -41892,7 +41884,7 @@ function _loadUserPackageJson() {
|
|
|
41892
41884
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
41893
41885
|
_context.t0 = JSON;
|
|
41894
41886
|
_context.next = 10;
|
|
41895
|
-
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
41887
|
+
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-4b5094a1.js', document.baseURI).href))), 'utf-8');
|
|
41896
41888
|
case 10:
|
|
41897
41889
|
_context.t1 = _context.sent;
|
|
41898
41890
|
pkg = _context.t0.parse.call(_context.t0, _context.t1);
|
|
@@ -43115,7 +43107,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43115
43107
|
return ProjectFiles;
|
|
43116
43108
|
}();
|
|
43117
43109
|
|
|
43118
|
-
var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
43110
|
+
var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-4b5094a1.js', document.baseURI).href)));
|
|
43119
43111
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43120
43112
|
function zipDirectory(source, out) {
|
|
43121
43113
|
var archive = archiver$1('tar', {
|
|
@@ -43330,7 +43322,7 @@ function _buildApp() {
|
|
|
43330
43322
|
case 11:
|
|
43331
43323
|
_context4.t0 = JSON;
|
|
43332
43324
|
_context4.next = 14;
|
|
43333
|
-
return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
43325
|
+
return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-4b5094a1.js', document.baseURI).href))), 'utf-8');
|
|
43334
43326
|
case 14:
|
|
43335
43327
|
_context4.t1 = _context4.sent;
|
|
43336
43328
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
|
@@ -44436,7 +44428,7 @@ var Scout9Platform = {
|
|
|
44436
44428
|
return run;
|
|
44437
44429
|
}(),
|
|
44438
44430
|
handleError: function handleError(e) {
|
|
44439
|
-
var error = coalesceToError(e);
|
|
44431
|
+
var error = dev.coalesceToError(e);
|
|
44440
44432
|
switch (error.name) {
|
|
44441
44433
|
case 'AxiosError':
|
|
44442
44434
|
var request = error.request,
|
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require("./index-
|
|
6
|
-
var dev = require("./dev-
|
|
5
|
+
var index = require("./index-4b5094a1.cjs");
|
|
6
|
+
var dev = require("./dev-0876e8d1.cjs");
|
|
7
7
|
require("./spirits-5c9243a1.cjs");
|
|
8
|
-
require("./macros-
|
|
8
|
+
require("./macros-e4105c56.cjs");
|
|
9
9
|
require('fs');
|
|
10
10
|
require('events');
|
|
11
11
|
require('path');
|
|
@@ -4580,6 +4580,7 @@ exports.WorkflowResponseSchema = WorkflowResponseSchema;
|
|
|
4580
4580
|
exports.WorkflowResponseSlotBaseSchema = WorkflowResponseSlotBaseSchema;
|
|
4581
4581
|
exports.WorkflowResponseSlotSchema = WorkflowResponseSlotSchema;
|
|
4582
4582
|
exports.WorkflowsConfigurationSchema = WorkflowsConfigurationSchema;
|
|
4583
|
+
exports.ZodIssueCode = ZodIssueCode;
|
|
4583
4584
|
exports.apiFunctionSchema = apiFunctionSchema;
|
|
4584
4585
|
exports.deleteApiFunctionSchema = deleteApiFunctionSchema;
|
|
4585
4586
|
exports.eventResponseSchema = eventResponseSchema;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require('node:fs');
|
|
4
4
|
require('node:path');
|
|
5
|
-
var index = require("./index-
|
|
5
|
+
var index = require("./index-4b5094a1.cjs");
|
|
6
6
|
require("./spirits-5c9243a1.cjs");
|
|
7
|
-
require("./dev-
|
|
7
|
+
require("./dev-0876e8d1.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
|
@@ -25,7 +25,7 @@ require('node:stream');
|
|
|
25
25
|
require('node:string_decoder');
|
|
26
26
|
require('node:readline');
|
|
27
27
|
require('node:process');
|
|
28
|
-
require("./macros-
|
|
28
|
+
require("./macros-e4105c56.cjs");
|
|
29
29
|
require('node:os');
|
|
30
30
|
require('fs/promises');
|
|
31
31
|
require('constants');
|
package/dist/schemas.cjs
CHANGED
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dev = require("./dev-
|
|
5
|
+
var dev = require("./dev-0876e8d1.cjs");
|
|
6
6
|
require("./spirits-5c9243a1.cjs");
|
|
7
7
|
require('util');
|
|
8
8
|
require('stream');
|
|
@@ -26,7 +26,7 @@ require('node:stream');
|
|
|
26
26
|
require('node:string_decoder');
|
|
27
27
|
require('node:readline');
|
|
28
28
|
require('node:process');
|
|
29
|
-
require("./macros-
|
|
29
|
+
require("./macros-e4105c56.cjs");
|
|
30
30
|
require('node:os');
|
|
31
31
|
require('fs/promises');
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scout9/app",
|
|
3
|
-
"version": "1.0.0-alpha.0.3.
|
|
3
|
+
"version": "1.0.0-alpha.0.3.8",
|
|
4
4
|
"description": "Build and deploy your Scout9 app for SMS auto replies",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -102,7 +102,8 @@
|
|
|
102
102
|
"polka": "^0.5.2",
|
|
103
103
|
"sade": "^1.8.1",
|
|
104
104
|
"sirv": "^2.0.4",
|
|
105
|
-
"zod": "^3.22.4"
|
|
105
|
+
"zod": "^3.22.4",
|
|
106
|
+
"zod-validation-error": "^3.4.0"
|
|
106
107
|
},
|
|
107
108
|
"engines": {
|
|
108
109
|
"node": ">=18.13"
|
|
@@ -15,6 +15,9 @@ import projectApp from './src/app.js';
|
|
|
15
15
|
import config from './config.js';
|
|
16
16
|
import { readdir } from 'fs/promises';
|
|
17
17
|
import { ZodError } from 'zod';
|
|
18
|
+
import { fromError } from 'zod-validation-error';
|
|
19
|
+
|
|
20
|
+
|
|
18
21
|
|
|
19
22
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
23
|
const __dirname = path.dirname(__filename);
|
|
@@ -71,8 +74,15 @@ const scout9 = new Scout9Api(configuration);
|
|
|
71
74
|
const cache = new ServerCache();
|
|
72
75
|
cache.reset();
|
|
73
76
|
|
|
77
|
+
const simplifyZodError = (error, tag = undefined) => {
|
|
78
|
+
const validationError = fromError(error);
|
|
79
|
+
if (tag) {
|
|
80
|
+
validationError.message = validationError.message.replace('Validation error', tag);
|
|
81
|
+
}
|
|
82
|
+
return validationError;
|
|
83
|
+
}
|
|
74
84
|
|
|
75
|
-
const handleError = (e, res = undefined, tag = undefined) => {
|
|
85
|
+
const handleError = (e, res = undefined, tag = undefined, body = undefined) => {
|
|
76
86
|
let name = e?.name || 'Runtime Error';
|
|
77
87
|
let message = e?.message || 'Unknown error';
|
|
78
88
|
let code = typeof e?.code === 'number'
|
|
@@ -94,14 +104,22 @@ const handleError = (e, res = undefined, tag = undefined) => {
|
|
|
94
104
|
message = response.body;
|
|
95
105
|
}
|
|
96
106
|
}
|
|
107
|
+
if (body) {
|
|
108
|
+
console.log(colors.grey(JSON.stringify(body, null, 2)));
|
|
109
|
+
}
|
|
97
110
|
if (tag && typeof tag === 'string') {
|
|
98
111
|
message = `${tag}: ${message}`;
|
|
99
112
|
}
|
|
113
|
+
if (typeof e?.constructor?.name === 'string') {
|
|
114
|
+
message = `(${e?.constructor?.name}) ${message}`;
|
|
115
|
+
}
|
|
100
116
|
console.log(colors.red(`${colors.bold(`${code} Error`)}: ${message}`));
|
|
101
117
|
if ('stack' in e) {
|
|
102
|
-
console.log(colors.grey(e.stack));
|
|
118
|
+
console.log('STACK:', colors.grey(e.stack));
|
|
119
|
+
}
|
|
120
|
+
if (body) {
|
|
121
|
+
console.log('INPUT:', colors.grey(JSON.stringify(body, null, 2)));
|
|
103
122
|
}
|
|
104
|
-
console.log(colors);
|
|
105
123
|
if (res) {
|
|
106
124
|
res.writeHead(code, {'Content-Type': 'application/json'});
|
|
107
125
|
res.end(JSON.stringify({
|
|
@@ -115,22 +133,24 @@ const handleError = (e, res = undefined, tag = undefined) => {
|
|
|
115
133
|
const handleZodError = ({error, res = undefined, code = 500, status, name, bodyLabel = 'Provided Input', body = undefined, action = ''}) => {
|
|
116
134
|
res?.writeHead?.(code, {'Content-Type': 'application/json'});
|
|
117
135
|
if (error instanceof ZodError) {
|
|
118
|
-
const
|
|
136
|
+
const formattedError = simplifyZodError(error);
|
|
119
137
|
res?.end?.(JSON.stringify({
|
|
120
138
|
status,
|
|
121
|
-
|
|
139
|
+
error: formattedError.message,
|
|
140
|
+
errors: [formattedError.message]
|
|
122
141
|
}));
|
|
123
142
|
console.log(colors.red(`${colors.bold(`${name}`)}:`));
|
|
124
143
|
if (body) {
|
|
125
144
|
console.log(colors.grey(`${bodyLabel}:`));
|
|
126
145
|
console.log(colors.grey(JSON.stringify(body, null, 2)));
|
|
127
146
|
}
|
|
128
|
-
console.log(colors.red(`${action}${
|
|
147
|
+
console.log(colors.red(`${action}${formattedError}`));
|
|
129
148
|
} else {
|
|
130
149
|
console.error(error);
|
|
131
150
|
error.message = `${name}: ` + error.message;
|
|
132
151
|
res?.end?.(JSON.stringify({
|
|
133
152
|
status,
|
|
153
|
+
error: error.message,
|
|
134
154
|
errors: [error.message]
|
|
135
155
|
}));
|
|
136
156
|
throw new Error(`${name}: Provided error was not a ZodError`);
|
|
@@ -216,13 +236,13 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
|
|
|
216
236
|
status: 'Invalid WorkflowEvent Input'
|
|
217
237
|
});
|
|
218
238
|
} else {
|
|
219
|
-
handleError(error, res, 'Workflow Template Event Parse Error');
|
|
239
|
+
handleError(error, res, 'Workflow Template Event Parse Error', req.body.event);
|
|
220
240
|
}
|
|
221
241
|
return;
|
|
222
242
|
}
|
|
223
243
|
|
|
224
244
|
if (!workflowEvent) {
|
|
225
|
-
handleError(new Error('No workflowEvent defined'), res);
|
|
245
|
+
handleError(new Error('No workflowEvent defined'), res, req.body.event, 'Workflow Template Event No Event');
|
|
226
246
|
}
|
|
227
247
|
let response;
|
|
228
248
|
try {
|
|
@@ -235,7 +255,19 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
|
|
|
235
255
|
}
|
|
236
256
|
})
|
|
237
257
|
} catch (error) {
|
|
238
|
-
|
|
258
|
+
if (error instanceof ZodError) {
|
|
259
|
+
handleZodError({
|
|
260
|
+
error,
|
|
261
|
+
name: 'Workflow Template Event Request Parse Error',
|
|
262
|
+
body: req.body.event,
|
|
263
|
+
bodyLabel: 'Provided WorkflowEvent',
|
|
264
|
+
code: 400,
|
|
265
|
+
res,
|
|
266
|
+
status: 'Invalid WorkflowEvent Input'
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
handleError(error, res, 'Workflow Template Runtime Error', workflowEvent);
|
|
270
|
+
}
|
|
239
271
|
return;
|
|
240
272
|
}
|
|
241
273
|
|
|
@@ -263,7 +295,7 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
|
|
|
263
295
|
status: 'Invalid WorkflowResponse Output'
|
|
264
296
|
});
|
|
265
297
|
} else {
|
|
266
|
-
handleError(error, res, 'Workflow Template Runtime Parse Error');
|
|
298
|
+
handleError(error, res, 'Workflow Template Runtime Parse Error', response);
|
|
267
299
|
}
|
|
268
300
|
}
|
|
269
301
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WorkflowResponseSlotBaseSchema, WorkflowResponseSlotSchema } from '../schemas/workflow.js';
|
|
2
2
|
import { MacroUtils } from './utils.js';
|
|
3
|
+
import { simplifyError } from '../../utils/index.js';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -79,12 +80,19 @@ function EventMacrosFactory() {
|
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* Sets context into the conversation context for later use
|
|
82
|
-
* @param {Record<string,
|
|
83
|
+
* @param {Record<string, string | boolean | null | number | Array<string | boolean | null | number>>} updates
|
|
83
84
|
* @return {EventMacros}
|
|
84
85
|
*/
|
|
85
86
|
upsert(updates) {
|
|
86
|
-
const slot = {contextUpsert: updates}
|
|
87
|
-
|
|
87
|
+
const slot = {contextUpsert: updates};
|
|
88
|
+
try {
|
|
89
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
throw simplifyError(
|
|
92
|
+
e,
|
|
93
|
+
'Invalid upsert, input must be a Record<string, string | boolean | null | number | Array<string | boolean | null | number>>'
|
|
94
|
+
);
|
|
95
|
+
}
|
|
88
96
|
return this;
|
|
89
97
|
},
|
|
90
98
|
|
|
@@ -99,7 +107,8 @@ function EventMacrosFactory() {
|
|
|
99
107
|
followup(instruction, options) {
|
|
100
108
|
let slot;
|
|
101
109
|
if (!options) {
|
|
102
|
-
throw new Error(
|
|
110
|
+
throw new Error(
|
|
111
|
+
'Missing second argument in followup(instruction, options) \'options\' argument needs to be included');
|
|
103
112
|
}
|
|
104
113
|
// Check if it's date value
|
|
105
114
|
const {success, ...rest} = MacroUtils.scheduledToUnixSafe(options);
|
|
@@ -116,7 +125,7 @@ function EventMacrosFactory() {
|
|
|
116
125
|
followup: {
|
|
117
126
|
scheduled: MacroUtils.scheduledToUnix(options.scheduled)
|
|
118
127
|
}
|
|
119
|
-
}
|
|
128
|
+
};
|
|
120
129
|
if (options.literal) {
|
|
121
130
|
slot.followup.message = instruction;
|
|
122
131
|
} else {
|
|
@@ -136,10 +145,14 @@ function EventMacrosFactory() {
|
|
|
136
145
|
instructions: instruction,
|
|
137
146
|
scheduled: rest.data
|
|
138
147
|
}
|
|
139
|
-
}
|
|
148
|
+
};
|
|
140
149
|
|
|
141
150
|
}
|
|
142
|
-
|
|
151
|
+
try {
|
|
152
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
153
|
+
} catch (e) {
|
|
154
|
+
throw simplifyError(e, 'Invalid followup() input');
|
|
155
|
+
}
|
|
143
156
|
return this;
|
|
144
157
|
},
|
|
145
158
|
|
|
@@ -158,7 +171,7 @@ function EventMacrosFactory() {
|
|
|
158
171
|
anticipate(instruction, yes, no) {
|
|
159
172
|
const slot = {
|
|
160
173
|
anticipate: []
|
|
161
|
-
}
|
|
174
|
+
};
|
|
162
175
|
if (Array.isArray(instruction)) {
|
|
163
176
|
for (const _slot of instruction) {
|
|
164
177
|
if (!Array.isArray(_slot.keywords) || _slot.keywords.length < 1) {
|
|
@@ -173,41 +186,61 @@ function EventMacrosFactory() {
|
|
|
173
186
|
if (!no) {
|
|
174
187
|
throw new Error('Missing "no" option for anticipate');
|
|
175
188
|
}
|
|
189
|
+
let yesParsed, noParsed;
|
|
190
|
+
try {
|
|
191
|
+
yesParsed = WorkflowResponseSlotBaseSchema.parse(yes);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
throw simplifyError(e, 'Invalid anticipate.yes input');
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
noParsed = WorkflowResponseSlotBaseSchema.parse(no);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
throw simplifyError(e, 'Invalid anticipate.no input');
|
|
199
|
+
}
|
|
200
|
+
|
|
176
201
|
slot.anticipate = {
|
|
177
202
|
did: instruction,
|
|
178
|
-
yes:
|
|
179
|
-
no:
|
|
180
|
-
}
|
|
203
|
+
yes: yesParsed,
|
|
204
|
+
no: noParsed
|
|
205
|
+
};
|
|
181
206
|
} else {
|
|
182
207
|
throw new Error(`Instruction is not of type "string" or "array"`);
|
|
183
208
|
}
|
|
184
|
-
|
|
209
|
+
try {
|
|
210
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
211
|
+
} catch (e) {
|
|
212
|
+
throw simplifyError(e, 'Invalid anticipate() input');
|
|
213
|
+
}
|
|
185
214
|
return this;
|
|
186
215
|
},
|
|
187
216
|
|
|
188
217
|
/**
|
|
189
218
|
* Return instructions to guide next auto reply response
|
|
190
219
|
* @param {string} instruction
|
|
191
|
-
* @param {
|
|
220
|
+
* @param {OptionsInstruct} [options]
|
|
192
221
|
* @return {EventMacros}
|
|
193
222
|
*/
|
|
194
223
|
instruct(instruction, options = {}) {
|
|
195
224
|
const slot = {};
|
|
196
225
|
if (Object.keys(options).length > 0) {
|
|
197
226
|
const instructionObj = {
|
|
198
|
-
content: instruction
|
|
199
|
-
}
|
|
227
|
+
content: instruction
|
|
228
|
+
};
|
|
200
229
|
if (options.id) {
|
|
201
|
-
instructionObj.id = options.id
|
|
230
|
+
instructionObj.id = options.id;
|
|
202
231
|
}
|
|
203
232
|
if (typeof options.persist === 'boolean') {
|
|
204
|
-
instructionObj.persist = options.persist
|
|
233
|
+
instructionObj.persist = options.persist;
|
|
205
234
|
}
|
|
206
235
|
slot.instructions = instructionObj;
|
|
207
236
|
} else {
|
|
208
237
|
slot.instructions = instruction;
|
|
209
238
|
}
|
|
210
|
-
|
|
239
|
+
try {
|
|
240
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
241
|
+
} catch (e) {
|
|
242
|
+
throw simplifyError(e, 'Invalid instruct() input');
|
|
243
|
+
}
|
|
211
244
|
return this;
|
|
212
245
|
},
|
|
213
246
|
/**
|
|
@@ -232,7 +265,11 @@ function EventMacrosFactory() {
|
|
|
232
265
|
slot.secondsDelay = delay;
|
|
233
266
|
}
|
|
234
267
|
}
|
|
235
|
-
|
|
268
|
+
try {
|
|
269
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
270
|
+
} catch (e) {
|
|
271
|
+
throw simplifyError(e, 'Invalid reply() input');
|
|
272
|
+
}
|
|
236
273
|
return this;
|
|
237
274
|
},
|
|
238
275
|
/**
|
|
@@ -250,7 +287,7 @@ function EventMacrosFactory() {
|
|
|
250
287
|
note: message ?? defaultForward
|
|
251
288
|
},
|
|
252
289
|
forwardNote: message ?? defaultForward
|
|
253
|
-
}
|
|
290
|
+
};
|
|
254
291
|
if (options.to) {
|
|
255
292
|
slot.forward.to = options.to;
|
|
256
293
|
}
|
|
@@ -261,9 +298,13 @@ function EventMacrosFactory() {
|
|
|
261
298
|
slot = {
|
|
262
299
|
forward: true,
|
|
263
300
|
forwardNote: message ?? defaultForward
|
|
264
|
-
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
305
|
+
} catch (e) {
|
|
306
|
+
throw simplifyError(e, 'Invalid forward() input');
|
|
265
307
|
}
|
|
266
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
267
308
|
return this;
|
|
268
309
|
},
|
|
269
310
|
/**
|
|
@@ -279,7 +320,7 @@ function EventMacrosFactory() {
|
|
|
279
320
|
} else {
|
|
280
321
|
return slots;
|
|
281
322
|
}
|
|
282
|
-
}
|
|
323
|
+
}
|
|
283
324
|
};
|
|
284
325
|
}
|
|
285
326
|
|
package/src/utils/error.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { fromError } from 'zod-validation-error';
|
|
2
|
+
|
|
3
|
+
export function simplifyError(error, tag = undefined) {
|
|
4
|
+
const validationError = fromError(error);
|
|
5
|
+
if (tag) {
|
|
6
|
+
validationError.message = validationError.message.replace('Validation error', tag);
|
|
7
|
+
}
|
|
8
|
+
return validationError;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* @param {unknown} err
|
|
3
13
|
* @return {Error}
|