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

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-73ac7343.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-60d45091.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);
@@ -40752,20 +40752,6 @@ var AgentsConfigurationSchema = z.array(AgentConfigurationSchema);
40752
40752
  var PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
40753
40753
  var AgentsSchema = z.array(AgentSchema);
40754
40754
  var PersonasSchema = z.array(PersonaSchema);
40755
- var Bus = z.object({
40756
- foo: z.string(),
40757
- bar: z["boolean"]().optional()
40758
- });
40759
- var Baz = z.object({
40760
- boo: z.object({
40761
- one: z.number(),
40762
- two: z.number().optional()
40763
- })
40764
- });
40765
- var TestSchema = z.object({
40766
- baz: Baz,
40767
- bus: Bus
40768
- });
40769
40755
 
40770
40756
  var ConversationContext = z.record(z.string(), z.any());
40771
40757
  var ConversationAnticipateSchema = z.object({
@@ -41369,15 +41355,6 @@ var responseInitSchema = z.object({
41369
41355
  statusText: z.string().optional(),
41370
41356
  headers: z.any().optional() // Headers can be complex; adjust as needed
41371
41357
  });
41372
-
41373
- /**
41374
- * @template T
41375
- * @typedef {object} IEventResponse
41376
- * @property {T} body - The body of the response.
41377
- * @property {ResponseInit} [init] - Additional options for the response.
41378
- * @property {Response} response - The response object.
41379
- * @property {T} data - The body of the response.
41380
- */
41381
41358
  var eventResponseSchema = z.object({
41382
41359
  body: z.any(),
41383
41360
  // Adjust as per your actual body structure
@@ -41541,85 +41518,31 @@ var Scout9ProjectBuildConfigSchema = Scout9ProjectConfigSchema.extend({
41541
41518
  workflows: WorkflowsConfigurationSchema
41542
41519
  });
41543
41520
 
41544
- /**
41545
- * @typedef {object} IApiFunctionParams
41546
- * @property {Object.<string, string|string[]>} searchParams
41547
- * @property {Record<string, string>} params
41548
- */
41549
41521
  var apiFunctionParamsSchema = z.object({
41550
41522
  searchParams: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
41551
41523
  params: z.record(z.string(), z.string())
41552
41524
  });
41553
-
41554
- /**
41555
- * @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
41556
- */
41557
41525
  apiFunctionParamsSchema.extend({
41558
41526
  id: z.string()
41559
41527
  });
41560
-
41561
- /**
41562
- * @template Params
41563
- * @template Response
41564
- * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
41565
- */
41566
41528
  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
41529
  var queryApiFunctionSchema = apiFunctionSchema;
41574
-
41575
- /**
41576
- * @template Params
41577
- * @template Response
41578
- * @typedef {IApiFunction<Params, Response>} GetApiFunction
41579
- */
41580
41530
  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
41531
  var postApiFunctionSchema = function postApiFunctionSchema(requestBodySchema) {
41589
41532
  return z["function"]().args(apiFunctionParamsSchema.extend({
41590
41533
  body: requestBodySchema.partial()
41591
41534
  })).returns(z.promise(eventResponseSchema));
41592
41535
  };
41593
-
41594
- /**
41595
- * @template Params
41596
- * @template RequestBody
41597
- * @template Response
41598
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
41599
- */
41600
41536
  var putApiFunctionSchema = function putApiFunctionSchema(requestBodySchema) {
41601
41537
  return z["function"]().args(apiFunctionParamsSchema.extend({
41602
41538
  body: requestBodySchema.partial()
41603
41539
  })).returns(z.promise(eventResponseSchema));
41604
41540
  };
41605
-
41606
- /**
41607
- * @template Params
41608
- * @template RequestBody
41609
- * @template Response
41610
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
41611
- */
41612
41541
  var patchApiFunctionSchema = function patchApiFunctionSchema(requestBodySchema) {
41613
41542
  return z["function"]().args(apiFunctionParamsSchema.extend({
41614
41543
  body: requestBodySchema.partial()
41615
41544
  })).returns(z.promise(eventResponseSchema));
41616
41545
  };
41617
-
41618
- /**
41619
- * @template Params
41620
- * @template Response
41621
- * @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
41622
- */
41623
41546
  var deleteApiFunctionSchema = apiFunctionSchema;
41624
41547
 
41625
41548
  var ContextExampleWithTrainingDataSchema = z.object({
@@ -48265,8 +48188,6 @@ exports.AgentConfigurationSchema = AgentConfigurationSchema;
48265
48188
  exports.AgentSchema = AgentSchema;
48266
48189
  exports.AgentsConfigurationSchema = AgentsConfigurationSchema;
48267
48190
  exports.AgentsSchema = AgentsSchema;
48268
- exports.Baz = Baz;
48269
- exports.Bus = Bus;
48270
48191
  exports.ContextExampleSchema = ContextExampleSchema;
48271
48192
  exports.ContextExampleWithTrainingDataSchema = ContextExampleWithTrainingDataSchema;
48272
48193
  exports.ConversationAnticipateSchema = ConversationAnticipateSchema;
@@ -48294,7 +48215,6 @@ exports.ProgressLogger = ProgressLogger;
48294
48215
  exports.Scout9ProjectBuildConfigSchema = Scout9ProjectBuildConfigSchema;
48295
48216
  exports.Scout9ProjectConfigSchema = Scout9ProjectConfigSchema;
48296
48217
  exports.Scout9Test = Scout9Test;
48297
- exports.TestSchema = TestSchema;
48298
48218
  exports.WorkflowConfigurationSchema = WorkflowConfigurationSchema;
48299
48219
  exports.WorkflowEventSchema = WorkflowEventSchema;
48300
48220
  exports.WorkflowFunctionSchema = WorkflowFunctionSchema;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var spirits = require("./spirits-76855e30.cjs");
4
- var dev = require("./dev-73ac7343.cjs");
4
+ var dev = require("./dev-60d45091.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-a55dfbdc.cjs"); });
29485
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-13a3f02b.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-6fd2c8cd.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-5ba79b93.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);
@@ -41964,7 +41964,7 @@ var EventResponse = /*#__PURE__*/function () {
41964
41964
  * @template T
41965
41965
  * @param {T} body - The body of the response.
41966
41966
  * @param {ResponseInit} [options] - Additional options for the response.
41967
- * @returns {EventResponse<T>} A new EventResponse instance.
41967
+ * @returns {EventResponse<T = any>} A new EventResponse instance.
41968
41968
  */
41969
41969
  function json(body, options) {
41970
41970
  return new EventResponse(body, options);
@@ -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-6fd2c8cd.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-5ba79b93.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-6fd2c8cd.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-5ba79b93.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-6fd2c8cd.cjs");
6
- var dev = require("./dev-73ac7343.cjs");
5
+ var index = require("./index-5ba79b93.cjs");
6
+ var dev = require("./dev-60d45091.cjs");
7
7
  require("./spirits-76855e30.cjs");
8
8
  require('fs');
9
9
  require('events');
@@ -51,8 +51,6 @@ exports.AgentConfigurationSchema = dev.AgentConfigurationSchema;
51
51
  exports.AgentSchema = dev.AgentSchema;
52
52
  exports.AgentsConfigurationSchema = dev.AgentsConfigurationSchema;
53
53
  exports.AgentsSchema = dev.AgentsSchema;
54
- exports.Baz = dev.Baz;
55
- exports.Bus = dev.Bus;
56
54
  exports.ContextExampleSchema = dev.ContextExampleSchema;
57
55
  exports.ContextExampleWithTrainingDataSchema = dev.ContextExampleWithTrainingDataSchema;
58
56
  exports.ConversationAnticipateSchema = dev.ConversationAnticipateSchema;
@@ -79,7 +77,6 @@ exports.PersonasSchema = dev.PersonasSchema;
79
77
  exports.Scout9ProjectBuildConfigSchema = dev.Scout9ProjectBuildConfigSchema;
80
78
  exports.Scout9ProjectConfigSchema = dev.Scout9ProjectConfigSchema;
81
79
  exports.Scout9Test = dev.Scout9Test;
82
- exports.TestSchema = dev.TestSchema;
83
80
  exports.WorkflowConfigurationSchema = dev.WorkflowConfigurationSchema;
84
81
  exports.WorkflowEventSchema = dev.WorkflowEventSchema;
85
82
  exports.WorkflowFunctionSchema = dev.WorkflowFunctionSchema;
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-6fd2c8cd.cjs");
5
+ var index = require("./index-5ba79b93.cjs");
6
6
  require("./spirits-76855e30.cjs");
7
- require("./dev-73ac7343.cjs");
7
+ require("./dev-60d45091.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-73ac7343.cjs");
5
+ var dev = require("./dev-60d45091.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.4",
3
+ "version": "1.0.0-alpha.0.2.5",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -5,7 +5,7 @@ import bodyParser from 'body-parser';
5
5
  import colors from 'kleur';
6
6
  import { config as dotenv } from 'dotenv';
7
7
  import { Configuration, Scout9Api } from '@scout9/admin';
8
- import { EventResponse, WorkflowEventSchema } from '@scout9/app';
8
+ import { EventResponse, WorkflowEventSchema, WorkflowResponseSchema } from '@scout9/app';
9
9
  import path, { resolve } from 'node:path';
10
10
  import fs from 'node:fs';
11
11
  import https from 'node:https';
@@ -179,7 +179,7 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
179
179
  const formattedErrors = error.format();
180
180
  res.writeHead(400, {'Content-Type': 'application/json'});
181
181
  res.end(JSON.stringify({
182
- status: 'WorkflowInvalidResponseType',
182
+ status: 'Invalid WorkflowEvent',
183
183
  errors: formattedErrors
184
184
  }));
185
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)}`));
@@ -195,15 +195,26 @@ app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
195
195
 
196
196
  try {
197
197
  const response = await projectApp(workflowEvent);
198
+ const formattedResponse = WorkflowEventSchema.parse(response);
198
199
  if (dev) {
199
200
  console.log(colors.green(`Workflow Sending Response:`));
200
- console.log(colors.grey(JSON.stringify(response, null, 2)));
201
+ console.log(colors.grey(JSON.stringify(formattedResponse, null, 2)));
201
202
  }
202
203
  res.writeHead(200, {'Content-Type': 'application/json'});
203
- res.end(JSON.stringify(response));
204
+ res.end(JSON.stringify(formattedResponse));
204
205
  } catch (error) {
205
- error.message = `Workflow Template Runtime Error: ` + error.message
206
- handleError(error, res);
206
+ if (error instanceof ZodError) {
207
+ const formattedErrors = error.format();
208
+ res.writeHead(500, {'Content-Type': 'application/json'});
209
+ res.end(JSON.stringify({
210
+ status: 'Invalid WorkflowResponse',
211
+ errors: formattedErrors
212
+ }));
213
+ console.log(colors.red(`${colors.bold(`Input Workflow Response`)}: Fix needed\n\n${JSON.stringify(formattedErrors, null, 2)}`));
214
+ } else {
215
+ error.message = `Workflow Template Runtime Error: ` + error.message
216
+ handleError(error, res);
217
+ }
207
218
  }
208
219
  });
209
220
 
package/src/public.d.ts CHANGED
@@ -25,7 +25,7 @@ export function run(event: WorkflowEvent, options: {
25
25
  * @param {ResponseInit | undefined} [init]
26
26
  * @returns {EventResponse<T>}
27
27
  */
28
- export function json<T>(data: T, init?: ResponseInit | undefined): EventResponse<T>;
28
+ export function json<T = any>(data: T, init?: ResponseInit | undefined): EventResponse<T>;
29
29
  /**
30
30
  * @param {WorkflowEvent} event - every workflow receives an event object
31
31
  * @param {Object} options
@@ -47,7 +47,7 @@ export function sendEvent(event: WorkflowEvent, options: {
47
47
  * Utility runtime class used to guide event output
48
48
  * @template T
49
49
  */
50
- export class EventResponse<T> {
50
+ export class EventResponse<T = any> {
51
51
  /**
52
52
  * Create a new EventResponse instance with a JSON body.
53
53
  * @template T
@@ -9,7 +9,7 @@ export class EventResponse {
9
9
  * @template T
10
10
  * @param {T} body - The body of the response.
11
11
  * @param {ResponseInit} [options] - Additional options for the response.
12
- * @returns {EventResponse<T>} A new EventResponse instance.
12
+ * @returns {EventResponse<T = any>} A new EventResponse instance.
13
13
  */
14
14
  static json(body, options) {
15
15
  return new EventResponse(body, options);
@@ -7,14 +7,6 @@ const responseInitSchema = z.object({
7
7
  headers: z.any().optional() // Headers can be complex; adjust as needed
8
8
  });
9
9
 
10
- /**
11
- * @template T
12
- * @typedef {object} IEventResponse
13
- * @property {T} body - The body of the response.
14
- * @property {ResponseInit} [init] - Additional options for the response.
15
- * @property {Response} response - The response object.
16
- * @property {T} data - The body of the response.
17
- */
18
10
  export const eventResponseSchema = z.object({
19
11
  body: z.any(), // Adjust as per your actual body structure
20
12
  init: responseInitSchema.optional()
@@ -2,85 +2,41 @@ import { z } from 'zod';
2
2
  import { eventResponseSchema } from './api.js';
3
3
 
4
4
 
5
- /**
6
- * @typedef {object} IApiFunctionParams
7
- * @property {Object.<string, string|string[]>} searchParams
8
- * @property {Record<string, string>} params
9
- */
10
5
  const apiFunctionParamsSchema = z.object({
11
6
  searchParams: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
12
7
  params: z.record(z.string(), z.string())
13
8
  });
14
9
 
15
- /**
16
- * @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
17
- */
18
10
  const apiEntityFunctionParamsSchema = apiFunctionParamsSchema.extend({
19
11
  id: z.string()
20
12
  });
21
13
 
22
- /**
23
- * @template Params
24
- * @template Response
25
- * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
26
- */
27
14
  export const apiFunctionSchema = z.function()
28
15
  .args(apiFunctionParamsSchema)
29
16
  .returns(z.promise(eventResponseSchema));
30
17
 
31
- /**
32
- * @template Params
33
- * @template Response
34
- * @typedef {IApiFunction<Params, Response>} IQueryApiFunction
35
- */
36
18
  export const queryApiFunctionSchema = apiFunctionSchema;
37
19
 
38
- /**
39
- * @template Params
40
- * @template Response
41
- * @typedef {IApiFunction<Params, Response>} GetApiFunction
42
- */
43
20
  export const getApiFunctionSchema = apiFunctionSchema;
44
21
 
45
- /**
46
- * @template Params
47
- * @template RequestBody
48
- * @template Response
49
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPostApiFunction
50
- */
51
22
  export const postApiFunctionSchema = (requestBodySchema) => z.function()
52
23
  .args(apiFunctionParamsSchema.extend({
53
24
  body: requestBodySchema.partial()
54
25
  }))
55
26
  .returns(z.promise(eventResponseSchema));
56
27
 
57
- /**
58
- * @template Params
59
- * @template RequestBody
60
- * @template Response
61
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
62
- */
28
+
63
29
  export const putApiFunctionSchema = (requestBodySchema) => z.function()
64
30
  .args(apiFunctionParamsSchema.extend({
65
31
  body: requestBodySchema.partial()
66
32
  }))
67
33
  .returns(z.promise(eventResponseSchema));
68
34
 
69
- /**
70
- * @template Params
71
- * @template RequestBody
72
- * @template Response
73
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
74
- */
35
+
75
36
  export const patchApiFunctionSchema = (requestBodySchema) => z.function()
76
37
  .args(apiFunctionParamsSchema.extend({
77
38
  body: requestBodySchema.partial()
78
39
  }))
79
40
  .returns(z.promise(eventResponseSchema));
80
41
 
81
- /**
82
- * @template Params
83
- * @template Response
84
- * @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
85
- */
86
42
  export const deleteApiFunctionSchema = apiFunctionSchema;
@@ -65,19 +65,3 @@ export const PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
65
65
  export const AgentsSchema = z.array(AgentSchema);
66
66
 
67
67
  export const PersonasSchema = z.array(PersonaSchema);
68
-
69
-
70
- export const Bus = z.object({
71
- foo: z.string(),
72
- bar: z.boolean().optional()
73
- });
74
- export const Baz = z.object({
75
- boo: z.object({
76
- one: z.number(),
77
- two: z.number().optional()
78
- })
79
- })
80
- export const TestSchema = z.object({
81
- baz: Baz,
82
- bus: Bus
83
- });
package/src/schemas.js ADDED
@@ -0,0 +1 @@
1
+ export * from './runtime/schemas/index.js';