@scout9/app 1.0.0-alpha.0.2.1 → 1.0.0-alpha.0.2.4

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.
@@ -39939,7 +39939,7 @@ function _loadUserPackageJson() {
39939
39939
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
39940
39940
  _context2.t0 = JSON;
39941
39941
  _context2.next = 10;
39942
- 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('dev-df823c44.js', document.baseURI).href))), 'utf-8');
39942
+ 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('dev-73ac7343.js', document.baseURI).href))), 'utf-8');
39943
39943
  case 10:
39944
39944
  _context2.t1 = _context2.sent;
39945
39945
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -40749,9 +40749,9 @@ var PersonaConfigurationSchema = AgentConfigurationSchema.extend({
40749
40749
  })
40750
40750
  });
40751
40751
  var AgentsConfigurationSchema = z.array(AgentConfigurationSchema);
40752
- z.array(PersonaConfigurationSchema);
40752
+ var PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
40753
40753
  var AgentsSchema = z.array(AgentSchema);
40754
- z.array(PersonaSchema);
40754
+ var PersonasSchema = z.array(PersonaSchema);
40755
40755
  var Bus = z.object({
40756
40756
  foo: z.string(),
40757
40757
  bar: z["boolean"]().optional()
@@ -40762,7 +40762,7 @@ var Baz = z.object({
40762
40762
  two: z.number().optional()
40763
40763
  })
40764
40764
  });
40765
- z.object({
40765
+ var TestSchema = z.object({
40766
40766
  baz: Baz,
40767
40767
  bus: Bus
40768
40768
  });
@@ -40852,7 +40852,7 @@ var WorkflowResponseMessageApiRequest = z.object({
40852
40852
  * If its a string, it will be sent as a static string.
40853
40853
  * If it's a object or WorkflowResponseMessageAPI - it will use
40854
40854
  */
40855
- z.union([z.string(),
40855
+ var WorkflowResponseMessage = z.union([z.string(),
40856
40856
  /**
40857
40857
  * An api call that should be called later, must return a string or {message: string}
40858
40858
  */
@@ -40861,7 +40861,7 @@ WorkflowResponseMessageApiRequest]);
40861
40861
  /**
40862
40862
  * The intended response provided by the WorkflowResponseMessageApiRequest
40863
40863
  */
40864
- z.union([z.string(), z.object({
40864
+ var WorkflowResponseMessageApiResponse = z.union([z.string(), z.object({
40865
40865
  message: z.string()
40866
40866
  }), z.object({
40867
40867
  text: z.string()
@@ -40971,7 +40971,7 @@ var WorkflowResponseSlotSchema = WorkflowResponseSlotBaseSchema.extend({
40971
40971
  * The workflow response to send in any given workflow
40972
40972
  */
40973
40973
  var WorkflowResponseSchema = z.union([WorkflowResponseSlotSchema, z.array(WorkflowResponseSlotSchema)]);
40974
- z["function"]().args(WorkflowEventSchema).returns(z.union([z.promise(WorkflowResponseSchema), WorkflowResponseSchema]));
40974
+ var WorkflowFunctionSchema = z["function"]().args(WorkflowEventSchema).returns(z.union([z.promise(WorkflowResponseSchema), WorkflowResponseSchema]));
40975
40975
 
40976
40976
  var _excluded$2 = ["success"];
40977
40977
  function MacroUtilsFactory() {
@@ -41443,7 +41443,7 @@ var EntityConfigurationSchema = _EntityConfigurationSchema.refine(function (data
41443
41443
  // Custom error message
41444
41444
  message: "If 'definitions' is provided, then 'training' must also be provided"
41445
41445
  });
41446
- z.array(EntityConfigurationSchema);
41446
+ var EntitiesRootConfigurationSchema = z.array(EntityConfigurationSchema);
41447
41447
  var EntityExtendedProjectConfigurationSchema = z.object({
41448
41448
  entities: z.array(zId('Entity Folder', z.string()), {
41449
41449
  description: 'Entity id association, used to handle route params'
@@ -41563,13 +41563,70 @@ apiFunctionParamsSchema.extend({
41563
41563
  * @template Response
41564
41564
  * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
41565
41565
  */
41566
- z["function"]().args(apiFunctionParamsSchema).returns(z.promise(eventResponseSchema));
41566
+ var apiFunctionSchema = z["function"]().args(apiFunctionParamsSchema).returns(z.promise(eventResponseSchema));
41567
+
41568
+ /**
41569
+ * @template Params
41570
+ * @template Response
41571
+ * @typedef {IApiFunction<Params, Response>} IQueryApiFunction
41572
+ */
41573
+ var queryApiFunctionSchema = apiFunctionSchema;
41574
+
41575
+ /**
41576
+ * @template Params
41577
+ * @template Response
41578
+ * @typedef {IApiFunction<Params, Response>} GetApiFunction
41579
+ */
41580
+ var getApiFunctionSchema = apiFunctionSchema;
41581
+
41582
+ /**
41583
+ * @template Params
41584
+ * @template RequestBody
41585
+ * @template Response
41586
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPostApiFunction
41587
+ */
41588
+ var postApiFunctionSchema = function postApiFunctionSchema(requestBodySchema) {
41589
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41590
+ body: requestBodySchema.partial()
41591
+ })).returns(z.promise(eventResponseSchema));
41592
+ };
41593
+
41594
+ /**
41595
+ * @template Params
41596
+ * @template RequestBody
41597
+ * @template Response
41598
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
41599
+ */
41600
+ var putApiFunctionSchema = function putApiFunctionSchema(requestBodySchema) {
41601
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41602
+ body: requestBodySchema.partial()
41603
+ })).returns(z.promise(eventResponseSchema));
41604
+ };
41605
+
41606
+ /**
41607
+ * @template Params
41608
+ * @template RequestBody
41609
+ * @template Response
41610
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
41611
+ */
41612
+ var patchApiFunctionSchema = function patchApiFunctionSchema(requestBodySchema) {
41613
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41614
+ body: requestBodySchema.partial()
41615
+ })).returns(z.promise(eventResponseSchema));
41616
+ };
41617
+
41618
+ /**
41619
+ * @template Params
41620
+ * @template Response
41621
+ * @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
41622
+ */
41623
+ var deleteApiFunctionSchema = apiFunctionSchema;
41567
41624
 
41568
41625
  var ContextExampleWithTrainingDataSchema = z.object({
41569
41626
  input: z.string(),
41570
41627
  output: z.array(z.record(z.string(), z.any()))
41571
41628
  });
41572
- z.union([z.array(ContextExampleWithTrainingDataSchema), z.array(z.record(z.string(), z.any()))]);
41629
+ var ContextExampleSchema = z.union([z.array(ContextExampleWithTrainingDataSchema), z.array(z.record(z.string(), z.any()))]);
41573
41630
 
41574
41631
  let FORCE_COLOR,
41575
41632
  NODE_DISABLE_COLORS,
@@ -48204,16 +48261,51 @@ var Scout9Test = /*#__PURE__*/function () {
48204
48261
  }();
48205
48262
 
48206
48263
  exports.$ = $$1;
48264
+ exports.AgentConfigurationSchema = AgentConfigurationSchema;
48265
+ exports.AgentSchema = AgentSchema;
48266
+ exports.AgentsConfigurationSchema = AgentsConfigurationSchema;
48267
+ exports.AgentsSchema = AgentsSchema;
48268
+ exports.Baz = Baz;
48269
+ exports.Bus = Bus;
48270
+ exports.ContextExampleSchema = ContextExampleSchema;
48271
+ exports.ContextExampleWithTrainingDataSchema = ContextExampleWithTrainingDataSchema;
48272
+ exports.ConversationAnticipateSchema = ConversationAnticipateSchema;
48273
+ exports.ConversationContext = ConversationContext;
48274
+ exports.ConversationSchema = ConversationSchema;
48275
+ exports.CustomerSchema = CustomerSchema;
48276
+ exports.CustomerValueSchema = CustomerValueSchema;
48277
+ exports.EntitiesRootConfigurationSchema = EntitiesRootConfigurationSchema;
48207
48278
  exports.EntitiesRootProjectConfigurationSchema = EntitiesRootProjectConfigurationSchema;
48208
48279
  exports.EntityApiConfigurationSchema = EntityApiConfigurationSchema;
48209
48280
  exports.EntityConfigurationSchema = EntityConfigurationSchema;
48210
48281
  exports.EntityRootProjectConfigurationSchema = EntityRootProjectConfigurationSchema;
48282
+ exports.FollowupBaseSchema = FollowupBaseSchema;
48283
+ exports.FollowupSchema = FollowupSchema;
48284
+ exports.ForwardSchema = ForwardSchema;
48285
+ exports.InstructionObjectSchema = InstructionObjectSchema;
48286
+ exports.InstructionSchema = InstructionSchema;
48287
+ exports.IntentWorkflowEventSchema = IntentWorkflowEventSchema;
48288
+ exports.MessageSchema = MessageSchema;
48289
+ exports.PersonaConfigurationSchema = PersonaConfigurationSchema;
48290
+ exports.PersonaSchema = PersonaSchema;
48291
+ exports.PersonasConfigurationSchema = PersonasConfigurationSchema;
48292
+ exports.PersonasSchema = PersonasSchema;
48211
48293
  exports.ProgressLogger = ProgressLogger;
48212
48294
  exports.Scout9ProjectBuildConfigSchema = Scout9ProjectBuildConfigSchema;
48295
+ exports.Scout9ProjectConfigSchema = Scout9ProjectConfigSchema;
48213
48296
  exports.Scout9Test = Scout9Test;
48297
+ exports.TestSchema = TestSchema;
48214
48298
  exports.WorkflowConfigurationSchema = WorkflowConfigurationSchema;
48215
48299
  exports.WorkflowEventSchema = WorkflowEventSchema;
48300
+ exports.WorkflowFunctionSchema = WorkflowFunctionSchema;
48301
+ exports.WorkflowResponseMessage = WorkflowResponseMessage;
48302
+ exports.WorkflowResponseMessageApiRequest = WorkflowResponseMessageApiRequest;
48303
+ exports.WorkflowResponseMessageApiResponse = WorkflowResponseMessageApiResponse;
48304
+ exports.WorkflowResponseSchema = WorkflowResponseSchema;
48305
+ exports.WorkflowResponseSlotBaseSchema = WorkflowResponseSlotBaseSchema;
48306
+ exports.WorkflowResponseSlotSchema = WorkflowResponseSlotSchema;
48216
48307
  exports.WorkflowsConfigurationSchema = WorkflowsConfigurationSchema;
48308
+ exports.apiFunctionSchema = apiFunctionSchema;
48217
48309
  exports.balancedMatch = balancedMatch;
48218
48310
  exports.build = build;
48219
48311
  exports.checkVariableType = checkVariableType;
@@ -48224,7 +48316,10 @@ exports.createMockConversation = createMockConversation;
48224
48316
  exports.createMockCustomer = createMockCustomer;
48225
48317
  exports.createMockMessage = createMockMessage;
48226
48318
  exports.createMockWorkflowEvent = createMockWorkflowEvent;
48319
+ exports.deleteApiFunctionSchema = deleteApiFunctionSchema;
48320
+ exports.eventResponseSchema = eventResponseSchema;
48227
48321
  exports.forward = forward;
48322
+ exports.getApiFunctionSchema = getApiFunctionSchema;
48228
48323
  exports.getAugmentedNamespace = getAugmentedNamespace;
48229
48324
  exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
48230
48325
  exports.globSync = globSync;
@@ -48233,7 +48328,11 @@ exports.loadConfig = loadConfig;
48233
48328
  exports.loadEnvConfig = loadEnvConfig;
48234
48329
  exports.loadUserPackageJson = loadUserPackageJson;
48235
48330
  exports.logUserValidationError = logUserValidationError;
48331
+ exports.patchApiFunctionSchema = patchApiFunctionSchema;
48332
+ exports.postApiFunctionSchema = postApiFunctionSchema;
48236
48333
  exports.projectTemplates = projectTemplates;
48334
+ exports.putApiFunctionSchema = putApiFunctionSchema;
48335
+ exports.queryApiFunctionSchema = queryApiFunctionSchema;
48237
48336
  exports.reply = reply;
48238
48337
  exports.report = report;
48239
48338
  exports.requireOptionalProjectFile = requireOptionalProjectFile;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var spirits = require("./spirits-76855e30.cjs");
4
- var dev = require("./dev-df823c44.cjs");
4
+ var dev = require("./dev-73ac7343.cjs");
5
5
  var require$$0 = require('fs');
6
6
  var require$$2$1 = require('events');
7
7
  var require$$1 = require('path');
@@ -29482,7 +29482,7 @@ class Body {
29482
29482
  }
29483
29483
  const {
29484
29484
  toFormData
29485
- } = await Promise.resolve().then(function () { return require("./multipart-parser-50a82502.cjs"); });
29485
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-a55dfbdc.cjs"); });
29486
29486
  return toFormData(this.body, ct);
29487
29487
  }
29488
29488
 
@@ -41891,7 +41891,7 @@ function _loadUserPackageJson() {
41891
41891
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
41892
41892
  _context.t0 = JSON;
41893
41893
  _context.next = 10;
41894
- 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-332067ab.js', document.baseURI).href))), 'utf-8');
41894
+ 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-6fd2c8cd.js', document.baseURI).href))), 'utf-8');
41895
41895
  case 10:
41896
41896
  _context.t1 = _context.sent;
41897
41897
  pkg = _context.t0.parse.call(_context.t0, _context.t1);
@@ -43097,7 +43097,7 @@ var ProjectFiles = /*#__PURE__*/function () {
43097
43097
  return ProjectFiles;
43098
43098
  }();
43099
43099
 
43100
- 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-332067ab.js', document.baseURI).href)));
43100
+ 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-6fd2c8cd.js', document.baseURI).href)));
43101
43101
  var __dirname$1 = path__default["default"].dirname(__filename$1);
43102
43102
  function zipDirectory(source, out) {
43103
43103
  var archive = archiver$1('tar', {
@@ -43312,7 +43312,7 @@ function _buildApp() {
43312
43312
  case 11:
43313
43313
  _context4.t0 = JSON;
43314
43314
  _context4.next = 14;
43315
- 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-332067ab.js', document.baseURI).href))), 'utf-8');
43315
+ 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-6fd2c8cd.js', document.baseURI).href))), 'utf-8');
43316
43316
  case 14:
43317
43317
  _context4.t1 = _context4.sent;
43318
43318
  packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
package/dist/index.cjs CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require("./index-332067ab.cjs");
6
- var dev = require("./dev-df823c44.cjs");
5
+ var index = require("./index-6fd2c8cd.cjs");
6
+ var dev = require("./dev-73ac7343.cjs");
7
7
  require("./spirits-76855e30.cjs");
8
8
  require('fs');
9
9
  require('events');
@@ -47,12 +47,62 @@ exports.did = index.did;
47
47
  exports.json = index.json;
48
48
  exports.run = index.run;
49
49
  exports.sendEvent = index.sendEvent;
50
+ exports.AgentConfigurationSchema = dev.AgentConfigurationSchema;
51
+ exports.AgentSchema = dev.AgentSchema;
52
+ exports.AgentsConfigurationSchema = dev.AgentsConfigurationSchema;
53
+ exports.AgentsSchema = dev.AgentsSchema;
54
+ exports.Baz = dev.Baz;
55
+ exports.Bus = dev.Bus;
56
+ exports.ContextExampleSchema = dev.ContextExampleSchema;
57
+ exports.ContextExampleWithTrainingDataSchema = dev.ContextExampleWithTrainingDataSchema;
58
+ exports.ConversationAnticipateSchema = dev.ConversationAnticipateSchema;
59
+ exports.ConversationContext = dev.ConversationContext;
60
+ exports.ConversationSchema = dev.ConversationSchema;
61
+ exports.CustomerSchema = dev.CustomerSchema;
62
+ exports.CustomerValueSchema = dev.CustomerValueSchema;
63
+ exports.EntitiesRootConfigurationSchema = dev.EntitiesRootConfigurationSchema;
64
+ exports.EntitiesRootProjectConfigurationSchema = dev.EntitiesRootProjectConfigurationSchema;
65
+ exports.EntityApiConfigurationSchema = dev.EntityApiConfigurationSchema;
66
+ exports.EntityConfigurationSchema = dev.EntityConfigurationSchema;
67
+ exports.EntityRootProjectConfigurationSchema = dev.EntityRootProjectConfigurationSchema;
68
+ exports.FollowupBaseSchema = dev.FollowupBaseSchema;
69
+ exports.FollowupSchema = dev.FollowupSchema;
70
+ exports.ForwardSchema = dev.ForwardSchema;
71
+ exports.InstructionObjectSchema = dev.InstructionObjectSchema;
72
+ exports.InstructionSchema = dev.InstructionSchema;
73
+ exports.IntentWorkflowEventSchema = dev.IntentWorkflowEventSchema;
74
+ exports.MessageSchema = dev.MessageSchema;
75
+ exports.PersonaConfigurationSchema = dev.PersonaConfigurationSchema;
76
+ exports.PersonaSchema = dev.PersonaSchema;
77
+ exports.PersonasConfigurationSchema = dev.PersonasConfigurationSchema;
78
+ exports.PersonasSchema = dev.PersonasSchema;
79
+ exports.Scout9ProjectBuildConfigSchema = dev.Scout9ProjectBuildConfigSchema;
80
+ exports.Scout9ProjectConfigSchema = dev.Scout9ProjectConfigSchema;
50
81
  exports.Scout9Test = dev.Scout9Test;
82
+ exports.TestSchema = dev.TestSchema;
83
+ exports.WorkflowConfigurationSchema = dev.WorkflowConfigurationSchema;
84
+ exports.WorkflowEventSchema = dev.WorkflowEventSchema;
85
+ exports.WorkflowFunctionSchema = dev.WorkflowFunctionSchema;
86
+ exports.WorkflowResponseMessage = dev.WorkflowResponseMessage;
87
+ exports.WorkflowResponseMessageApiRequest = dev.WorkflowResponseMessageApiRequest;
88
+ exports.WorkflowResponseMessageApiResponse = dev.WorkflowResponseMessageApiResponse;
89
+ exports.WorkflowResponseSchema = dev.WorkflowResponseSchema;
90
+ exports.WorkflowResponseSlotBaseSchema = dev.WorkflowResponseSlotBaseSchema;
91
+ exports.WorkflowResponseSlotSchema = dev.WorkflowResponseSlotSchema;
92
+ exports.WorkflowsConfigurationSchema = dev.WorkflowsConfigurationSchema;
93
+ exports.apiFunctionSchema = dev.apiFunctionSchema;
51
94
  exports.createMockAgent = dev.createMockAgent;
52
95
  exports.createMockConversation = dev.createMockConversation;
53
96
  exports.createMockCustomer = dev.createMockCustomer;
54
97
  exports.createMockMessage = dev.createMockMessage;
55
98
  exports.createMockWorkflowEvent = dev.createMockWorkflowEvent;
99
+ exports.deleteApiFunctionSchema = dev.deleteApiFunctionSchema;
100
+ exports.eventResponseSchema = dev.eventResponseSchema;
56
101
  exports.forward = dev.forward;
102
+ exports.getApiFunctionSchema = dev.getApiFunctionSchema;
57
103
  exports.instruct = dev.instruct;
104
+ exports.patchApiFunctionSchema = dev.patchApiFunctionSchema;
105
+ exports.postApiFunctionSchema = dev.postApiFunctionSchema;
106
+ exports.putApiFunctionSchema = dev.putApiFunctionSchema;
107
+ exports.queryApiFunctionSchema = dev.queryApiFunctionSchema;
58
108
  exports.reply = dev.reply;
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-332067ab.cjs");
5
+ var index = require("./index-6fd2c8cd.cjs");
6
6
  require("./spirits-76855e30.cjs");
7
- require("./dev-df823c44.cjs");
7
+ require("./dev-73ac7343.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dev = require("./dev-df823c44.cjs");
5
+ var dev = require("./dev-73ac7343.cjs");
6
6
  require("./spirits-76855e30.cjs");
7
7
  require('util');
8
8
  require('stream');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.2.1",
3
+ "version": "1.0.0-alpha.0.2.4",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,7 @@
19
19
  "postinstall": "node postinstall.js",
20
20
  "prepublishOnly": "npm run build",
21
21
  "generate:types": "node scripts/generate-dts.js",
22
- "prebuild": "rimraf dist/",
22
+ "prebuild": "rimraf dist/ && rimraf types/index.d.ts && rimraf types/index.d.ts.map",
23
23
  "build": "rollup -c",
24
24
  "postbuild": "npm run generate:types && node scripts/post-build.js && npx tsc --noEmit",
25
25
  "build-no-test": "npm run prebuild && rollup -c"
@@ -6,12 +6,14 @@ import colors from 'kleur';
6
6
  import { config as dotenv } from 'dotenv';
7
7
  import { Configuration, Scout9Api } from '@scout9/admin';
8
8
  import { EventResponse, WorkflowEventSchema } from '@scout9/app';
9
- import path from 'node:path';
9
+ import path, { resolve } from 'node:path';
10
10
  import fs from 'node:fs';
11
11
  import https from 'node:https';
12
12
  import { fileURLToPath, pathToFileURL } from 'node:url';
13
13
  import projectApp from './src/app.js';
14
14
  import config from './config.js';
15
+ import { readdir } from 'fs/promises';
16
+ import { ZodError } from 'zod';
15
17
 
16
18
  const __filename = fileURLToPath(import.meta.url);
17
19
  const __dirname = path.dirname(__filename);
@@ -92,6 +94,10 @@ const handleError = (e, res = undefined) => {
92
94
  }
93
95
  }
94
96
  console.log(colors.red(`${colors.bold(`${code} Error`)}: ${message}`));
97
+ if ('stack' in e) {
98
+ console.log(colors.grey(e.stack));
99
+ }
100
+ console.log(colors)
95
101
  if (res) {
96
102
  res.writeHead(code, {'Content-Type': 'application/json'});
97
103
  res.end(JSON.stringify({
@@ -161,17 +167,43 @@ if (dev) {
161
167
 
162
168
  // Root application POST endpoint will run the scout9 app
163
169
  app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
170
+ let workflowEvent;
164
171
  try {
165
- const event = WorkflowEventSchema.parse(req.body.event);
172
+ workflowEvent = WorkflowEventSchema.parse(req.body.event);
166
173
  globalThis.SCOUT9 = {
167
- ...event,
174
+ ...workflowEvent,
168
175
  $convo: req.body.$convo,
169
176
  }
170
- const response = await projectApp(event);
177
+ } catch (error) {
178
+ if (error instanceof ZodError) {
179
+ const formattedErrors = error.format();
180
+ res.writeHead(400, {'Content-Type': 'application/json'});
181
+ res.end(JSON.stringify({
182
+ status: 'WorkflowInvalidResponseType',
183
+ errors: formattedErrors
184
+ }));
185
+ console.log(colors.red(`${colors.bold(`Bad Input Event:`)}: Received: ${JSON.stringify(req.body.event, null, 2)}\n\nErrors:\n\n${JSON.stringify(formattedErrors, null, 2)}`));
186
+ } else {
187
+ error.message = `Workflow Template Event Parse Error: ` + error.message;
188
+ handleError(error, res);
189
+ }
190
+ return;
191
+ }
192
+ if (!workflowEvent) {
193
+ handleError(new Error('No workflowEvent defined'), res);
194
+ }
195
+
196
+ try {
197
+ const response = await projectApp(workflowEvent);
198
+ if (dev) {
199
+ console.log(colors.green(`Workflow Sending Response:`));
200
+ console.log(colors.grey(JSON.stringify(response, null, 2)));
201
+ }
171
202
  res.writeHead(200, {'Content-Type': 'application/json'});
172
203
  res.end(JSON.stringify(response));
173
- } catch (e) {
174
- handleError(e, res);
204
+ } catch (error) {
205
+ error.message = `Workflow Template Runtime Error: ` + error.message
206
+ handleError(error, res);
175
207
  }
176
208
  });
177
209
 
@@ -229,6 +261,7 @@ async function resolveEntityApi(entity, method) {
229
261
 
230
262
  }
231
263
 
264
+
232
265
  function extractParamsFromPath(path) {
233
266
  const segments = path.split('/').filter(Boolean); // Split and remove empty segments
234
267
  let params = {};
@@ -284,6 +317,86 @@ async function runEntityApi(req, res) {
284
317
  }
285
318
  }
286
319
 
320
+ async function getFilesRecursive(dir) {
321
+ let results = [];
322
+ const list = await readdir(dir, { withFileTypes: true });
323
+
324
+ for (const dirent of list) {
325
+ const res = resolve(dir, dirent.name);
326
+ if (dirent.isDirectory()) {
327
+ results = results.concat(await getFilesRecursive(res)); // Recursively get files from subdirectories
328
+ } else {
329
+ results.push(res); // Add file to results
330
+ }
331
+ }
332
+
333
+ return results;
334
+ }
335
+
336
+ async function runCommandApi(req, res) {
337
+ let file;
338
+ const {body, url} = req;
339
+ const params = url.split('/').slice(2).filter(Boolean);
340
+ const commandsDir = resolve(__dirname, `./src/commands`);
341
+
342
+ try {
343
+ const files = await getFilesRecursive(commandsDir).then(files => files.map(file => file.replace(commandsDir, '.')).filter(file => params.every(p => file.includes(p))))
344
+ file = files?.[0];
345
+ } catch (e) {
346
+ console.log('No commands found', e.message)
347
+ }
348
+
349
+
350
+ if (!file) {
351
+ throw new Error(`Unable to find command for ${url}`);
352
+ }
353
+
354
+ let mod;
355
+ try {
356
+ mod = await import(pathToFileURL(path.resolve(commandsDir, file)).href)
357
+ console.log(mod);
358
+ } catch (e) {
359
+ if ('code' in e) {
360
+ switch (e.code) {
361
+ case 'ERR_MODULE_NOT_FOUND':
362
+ case 'MODULE_NOT_FOUND':
363
+ console.error(e);
364
+ throw new Error(`Invalid command: no API method`);
365
+ }
366
+ }
367
+ console.error(e);
368
+ throw new Error(`Invalid command: Internal system error`);
369
+ }
370
+
371
+ if (!mod || !mod.default) {
372
+ throw new Error(`Command file "${file}" does not export a default command function`);
373
+ }
374
+
375
+ console.log(mod);
376
+
377
+ let result;
378
+
379
+ try {
380
+ result = await mod.default(body);
381
+ } catch (e) {
382
+ console.error('Failed to run command', e);
383
+ throw new Error(`Failed to run command: ${e.message}`)
384
+ }
385
+
386
+ if (result) {
387
+ if (typeof result === 'string') {
388
+ return {message: result};
389
+ } else if (typeof result === 'object' && 'message' in result) {
390
+ return result;
391
+ } else {
392
+ throw new Error(`Invalid Command Response, must either return a string or {"message": "<your message>"}`);
393
+ }
394
+ }
395
+ return {message: `${mod.default.name} Complete`};
396
+ }
397
+
398
+ app.post('/commands/:command', runCommandApi);
399
+ app.post('/commands/:command/*', runCommandApi);
287
400
  app.get('/entity/:entity', runEntityApi);
288
401
  app.put('/entity/:entity', runEntityApi);
289
402
  app.patch('/entity/:entity', runEntityApi);
package/src/exports.js CHANGED
@@ -5,6 +5,7 @@ export { EventResponse } from './runtime/index.js';
5
5
 
6
6
  export * from './testing-tools/index.js';
7
7
  export * from './runtime/client/index.js';
8
+ export * from './runtime/schemas/index.js';
8
9
  export * from './runtime/macros/index.js';
9
10
 
10
11
  /**