@scout9/app 1.0.0-alpha.0.1.9 → 1.0.0-alpha.0.1.91

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.
Files changed (70) hide show
  1. package/README.md +33 -0
  2. package/dist/{index-92deaa5f.cjs → exports-212ef6be.cjs} +46636 -4591
  3. package/dist/index.cjs +58 -15
  4. package/dist/{multipart-parser-090f08a9.cjs → multipart-parser-54a3ab5f.cjs} +13 -7
  5. package/dist/spirits-3b603262.cjs +1218 -0
  6. package/dist/spirits.cjs +9 -0
  7. package/dist/testing-tools.cjs +48 -0
  8. package/package.json +37 -8
  9. package/src/cli.js +162 -69
  10. package/src/core/config/agents.js +300 -7
  11. package/src/core/config/entities.js +58 -28
  12. package/src/core/config/index.js +37 -15
  13. package/src/core/config/project.js +160 -6
  14. package/src/core/config/workflow.js +13 -12
  15. package/src/core/data.js +27 -0
  16. package/src/core/index.js +386 -137
  17. package/src/core/sync.js +71 -0
  18. package/src/core/templates/Dockerfile +22 -0
  19. package/src/core/templates/app.js +453 -0
  20. package/src/core/templates/project-files.js +36 -0
  21. package/src/core/templates/template-package.json +13 -0
  22. package/src/exports.js +21 -17
  23. package/src/platform.js +189 -33
  24. package/src/public.d.ts.text +330 -0
  25. package/src/report.js +117 -0
  26. package/src/runtime/client/api.js +56 -159
  27. package/src/runtime/client/config.js +60 -11
  28. package/src/runtime/client/entity.js +19 -6
  29. package/src/runtime/client/index.js +5 -3
  30. package/src/runtime/client/message.js +13 -3
  31. package/src/runtime/client/platform.js +86 -0
  32. package/src/runtime/client/{agent.js → users.js} +35 -3
  33. package/src/runtime/client/utils.js +10 -9
  34. package/src/runtime/client/workflow.js +132 -9
  35. package/src/runtime/entry.js +2 -2
  36. package/src/testing-tools/dev.js +373 -0
  37. package/src/testing-tools/index.js +1 -0
  38. package/src/testing-tools/mocks.js +37 -5
  39. package/src/testing-tools/spirits.js +530 -0
  40. package/src/utils/audio-buffer.js +16 -0
  41. package/src/utils/audio-type.js +27 -0
  42. package/src/utils/configs/agents.js +68 -0
  43. package/src/utils/configs/entities.js +145 -0
  44. package/src/utils/configs/project.js +23 -0
  45. package/src/utils/configs/workflow.js +47 -0
  46. package/src/utils/file-type.js +569 -0
  47. package/src/utils/file.js +164 -0
  48. package/src/utils/glob.js +30 -0
  49. package/src/utils/image-buffer.js +23 -0
  50. package/src/utils/image-type.js +39 -0
  51. package/src/utils/index.js +1 -0
  52. package/src/utils/is-svg.js +37 -0
  53. package/src/utils/logger.js +111 -0
  54. package/src/utils/module.js +14 -25
  55. package/src/utils/project-templates.js +191 -0
  56. package/src/utils/project.js +387 -0
  57. package/src/utils/video-type.js +29 -0
  58. package/types/index.d.ts +7588 -206
  59. package/types/index.d.ts.map +97 -22
  60. package/dist/index-1b8d7dd2.cjs +0 -49555
  61. package/dist/index-2ccb115e.cjs +0 -49514
  62. package/dist/index-66b06a30.cjs +0 -49549
  63. package/dist/index-bc029a1d.cjs +0 -49528
  64. package/dist/index-d9a93523.cjs +0 -49527
  65. package/dist/multipart-parser-1508046a.cjs +0 -413
  66. package/dist/multipart-parser-7007403a.cjs +0 -413
  67. package/dist/multipart-parser-70c32c1d.cjs +0 -413
  68. package/dist/multipart-parser-71dec101.cjs +0 -413
  69. package/dist/multipart-parser-f15bf2e0.cjs +0 -414
  70. package/src/public.d.ts +0 -209
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var spirits = require("./spirits-3b603262.cjs");
6
+
7
+
8
+
9
+ exports.Spirits = spirits.Spirits;
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var exports$1 = require("./exports-212ef6be.cjs");
6
+ var spirits = require("./spirits-3b603262.cjs");
7
+ require('node:readline');
8
+ require('fs');
9
+ require('events');
10
+ require('path');
11
+ require('constants');
12
+ require('stream');
13
+ require('util');
14
+ require('assert');
15
+ require('buffer');
16
+ require('zlib');
17
+ require('url');
18
+ require('fs/promises');
19
+ require('string_decoder');
20
+ require('node:fs');
21
+ require('node:fs/promises');
22
+ require('node:path');
23
+ require('node:url');
24
+ require('node:http');
25
+ require('node:https');
26
+ require('node:zlib');
27
+ require('node:stream');
28
+ require('node:buffer');
29
+ require('http');
30
+ require('https');
31
+ require('tty');
32
+ require('os');
33
+ require('crypto');
34
+ require('node:process');
35
+ require('node:os');
36
+ require('node:util');
37
+ require('node:net');
38
+ require('node:vm');
39
+
40
+
41
+
42
+ exports.Scout9Test = exports$1.Scout9Test;
43
+ exports.createMockAgent = exports$1.createMockAgent;
44
+ exports.createMockConversation = exports$1.createMockConversation;
45
+ exports.createMockCustomer = exports$1.createMockCustomer;
46
+ exports.createMockMessage = exports$1.createMockMessage;
47
+ exports.createMockWorkflowEvent = exports$1.createMockWorkflowEvent;
48
+ exports.Spirits = spirits.Spirits;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.1.9",
4
- "description": "Build and deploy your Scout9 app for SMS auto reply",
3
+ "version": "1.0.0-alpha.0.1.91",
4
+ "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -10,14 +10,23 @@
10
10
  "url": "git://github.com/Scout9Official/scout9-nodejs.git"
11
11
  },
12
12
  "scripts": {
13
+ "pretest:generate": "npm run build-no-test",
14
+ "test:generate": "npx rimraf src-test && echo \"Generate a new test project\" && npm create scout9@latest src-test",
15
+ "posttest:generate": "node scripts/test-project-build.js && node scripts/test-project-sync.js",
16
+ "pretest": "node scripts/test-project-build.js",
17
+ "test": "node --experimental-vm-modules ../../node_modules/.bin/jest --detectOpenHandles --forceExit",
18
+ "test:deploy": "node ./src/cli.js deploy",
13
19
  "postinstall": "node postinstall.js",
14
- "prepublishOnly": "npm run generate:types && npm run build",
20
+ "prepublishOnly": "npm run build",
15
21
  "generate:types": "node scripts/generate-dts.js",
16
- "build": "rollup -c && node scripts/post-build.js"
22
+ "prebuild": "rimraf dist/",
23
+ "build": "rollup -c",
24
+ "postbuild": "npm run generate:types && node scripts/post-build.js && npx tsc --noEmit && npm run test",
25
+ "build-no-test": "npm run prebuild && rollup -c"
17
26
  },
18
27
  "type": "module",
19
28
  "bin": {
20
- "scout9": "./scout9-app.js"
29
+ "scout9": "scout9-app.js"
21
30
  },
22
31
  "files": [
23
32
  "src",
@@ -37,6 +46,16 @@
37
46
  "types": "./types/index.d.ts",
38
47
  "import": "./src/exports.js",
39
48
  "require": "./dist/index.cjs"
49
+ },
50
+ "./testing-tools": {
51
+ "import": "./src/testing-tools/index.js",
52
+ "types": "./types/index.d.ts",
53
+ "require": "./dist/testing-tools.cjs"
54
+ },
55
+ "./spirits": {
56
+ "import": "./src/testing-tools/spirits.js",
57
+ "types": "./types/index.d.ts",
58
+ "require": "./dist/spirits.cjs"
40
59
  }
41
60
  },
42
61
  "keywords": [],
@@ -44,29 +63,39 @@
44
63
  "license": "ISC",
45
64
  "devDependencies": {
46
65
  "@babel/cli": "^7.23.4",
47
- "@babel/core": "^7.23.6",
48
- "@babel/preset-env": "^7.23.6",
66
+ "@babel/core": "^7.23.7",
67
+ "@babel/preset-env": "^7.23.7",
49
68
  "@rollup/plugin-commonjs": "^25.0.7",
50
69
  "@rollup/plugin-json": "^6.1.0",
51
70
  "@rollup/plugin-node-resolve": "^15.2.3",
52
71
  "@types/archiver": "^6.0.2",
53
72
  "@types/jest": "^29.5.11",
73
+ "babel-jest": "^29.7.0",
54
74
  "babel-preset-minify": "^0.5.2",
55
75
  "dts-buddy": "^0.4.3",
76
+ "jest": "^29.7.0",
56
77
  "rollup": "^2.79.1",
57
78
  "rollup-plugin-babel": "^4.4.0",
58
- "ts-jest": "^29.1.1",
59
79
  "typescript": "^5.3.3"
60
80
  },
61
81
  "dependencies": {
82
+ "@scout9/admin": "^1.0.0-alpha.0.0.39",
83
+ "@scout9/crm": "^1.0.0-alpha.0.0.4",
62
84
  "archiver": "^6.0.1",
85
+ "body-parser": "^1.20.2",
86
+ "compression": "^1.7.4",
63
87
  "decompress": "^4.2.1",
64
88
  "dotenv": "^16.3.1",
89
+ "fast-xml-parser": "^4.3.5",
65
90
  "glob": "^10.3.10",
91
+ "graphql-request": "^6.1.0",
66
92
  "kleur": "^4.1.5",
93
+ "log-update": "^6.0.0",
67
94
  "moment": "^2.29.4",
68
95
  "node-fetch": "^3.3.2",
96
+ "polka": "^0.5.2",
69
97
  "sade": "^1.8.1",
98
+ "sirv": "^2.0.4",
70
99
  "zod": "^3.22.4"
71
100
  },
72
101
  "engines": {
package/src/cli.js CHANGED
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import sade from 'sade';
3
3
  import colors from 'kleur';
4
4
  import path from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
5
6
  import { Scout9Platform } from './platform.js';
6
7
  import { coalesceToError } from './utils/index.js';
7
8
 
@@ -10,100 +11,192 @@ const prog = sade('scout9').version(pkg.version);
10
11
 
11
12
  /** @param {unknown} e */
12
13
  function handle_error(e) {
13
- const error = coalesceToError(e);
14
+ const error = coalesceToError(e);
14
15
 
15
- if (error.name === 'SyntaxError') throw error;
16
+ if (error.name === 'SyntaxError') throw error;
16
17
 
17
- console.error(colors.bold().red(`> ${error.message}`));
18
- if (error.stack) {
19
- console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
20
- }
18
+ console.error(colors.bold().red(`> ${error.message}`));
19
+ if (error.stack) {
20
+ console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
21
+ }
21
22
 
22
- process.exit(1);
23
+ process.exit(1);
23
24
  }
24
25
 
25
26
  /** @param {string} mode */
26
27
  const coerceMode = (mode) => {
27
- const x = mode.toLowerCase().trim();
28
- const dmodes = ['development', 'dev', 'd'];
29
- const pmodes = ['production', 'prod', 'p'];
30
- if (dmodes.includes(x)) {
31
- return 'development';
32
- } else if (pmodes.includes(x)) {
33
- return 'production';
34
- } else {
35
- throw new Error(`Invalid mode "${mode}"`);
36
- }
37
- }
28
+ const x = mode.toLowerCase().trim();
29
+ const dmodes = ['development', 'dev', 'd'];
30
+ const pmodes = ['production', 'prod', 'p'];
31
+ if (dmodes.includes(x)) {
32
+ return 'development';
33
+ } else if (pmodes.includes(x)) {
34
+ return 'production';
35
+ } else {
36
+ throw new Error(`Invalid mode "${mode}"`);
37
+ }
38
+ };
38
39
 
39
40
  prog
40
- .command('sync')
41
- .describe('Sync your project with your Scout9 account (copies any missing personas and entities into your project)')
42
- .example('sync')
43
- .option('--mode', 'Specify a mode for loading environment variables', 'production')
44
- .action(async ({mode}) => {
45
- if (!fs.existsSync('.env')) {
46
- console.warn(`Missing ${path.resolve('.env')} — skipping`);
47
- return;
48
- }
49
- try {
50
- return Scout9Platform.sync({cwd: process.cwd(), mode: coerceMode(mode)});
51
- } catch (e) {
52
- handle_error(e);
53
- }
54
- });
41
+ .command('sync')
42
+ .describe('Sync your project with your Scout9 account (copies any missing personas and entities into your project)')
43
+ .example('sync')
44
+ .option('--mode', 'Specify a mode for loading environment variables', 'production')
45
+ .option('--src', 'Project source code folder', 'src')
46
+ .action(async ({mode, src}) => {
47
+ if (!fs.existsSync('.env')) {
48
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
49
+ return;
50
+ }
51
+ mode = coerceMode(mode);
52
+ try {
53
+ await Scout9Platform.sync({cwd: process.cwd(), mode: coerceMode(mode), src});
54
+ process.exit(0);
55
+ } catch (e) {
56
+ handle_error(e);
57
+ }
58
+ });
55
59
 
56
60
  prog
57
- .command('build')
58
- .describe('Builds your scout9 auto reply app')
59
- .example('build')
60
- .example('build --mode development')
61
- .example('build --mode production')
62
- .option('--mode', 'Specify a mode for loading environment variables', 'production')
63
- .action(async ({ mode }) => {
64
- if (!fs.existsSync('.env')) {
65
- console.warn(`Missing ${path.resolve('.env')} skipping`);
66
- return;
67
- }
68
- try {
69
- await Scout9Platform.build({cwd: process.cwd(), mode: coerceMode(mode)});
70
- } catch (e) {
71
- handle_error(e);
72
- }
73
- });
61
+ .command('build')
62
+ .describe('Builds your scout9 auto reply app')
63
+ .example('build')
64
+ .example('build --mode development')
65
+ .example('build --mode production')
66
+ .option('--dest', 'Project local destination', './build')
67
+ .option('--mode', 'Specify a mode for loading environment variables', 'production')
68
+ .option('--src', 'Project source code fold', 'src')
69
+ .action(async ({mode, src, dest}) => {
70
+ if (!fs.existsSync('.env')) {
71
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
72
+ return;
73
+ }
74
+ mode = coerceMode(mode);
75
+ try {
76
+ await Scout9Platform.build({cwd: process.cwd(), mode, src, dest});
77
+ process.exit(0);
78
+ } catch (e) {
79
+ handle_error(e);
80
+ }
81
+ });
74
82
 
75
83
 
76
84
  prog
77
- .command('deploy')
78
- .describe('Deploy your scout9 auto reply app')
85
+ .command('deploy')
86
+ .describe('Deploy your scout9 app')
87
+ .option('--mode', 'Specify a mode for loading environment variables', 'production')
88
+ .option('--src', 'Project source code folder', 'src')
89
+ .option('--sync, -s', 'Syncs project after deploying (overwriting code)', true)
90
+ .option('--dest', 'Project local destination', './build')
91
+ .action(async ({mode, src, dest, sync}) => {
92
+ if (!fs.existsSync('.env')) {
93
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
94
+ return;
95
+ }
96
+ mode = coerceMode(mode);
97
+ try {
98
+ await Scout9Platform.deploy({cwd: process.cwd(), mode: coerceMode(mode), src, dest, sync});
99
+ process.exit(0);
100
+ } catch (e) {
101
+ handle_error(e);
102
+ }
103
+ });
104
+
105
+ prog
106
+ .command('test')
107
+ .describe('Test your scout9 app')
79
108
  .option('--mode', 'Specify a mode for loading environment variables', 'production')
80
- .action(async ({ mode }) => {
109
+ .option('--src', 'Project source code folder', 'src')
110
+ .option('--dest', 'Project local destination', './build')
111
+ .action(async ({mode, src, dest}) => {
81
112
  if (!fs.existsSync('.env')) {
82
113
  console.warn(`Missing ${path.resolve('.env')} — skipping`);
83
114
  return;
84
115
  }
116
+ mode = coerceMode(mode);
85
117
  try {
86
- await Scout9Platform.deploy({cwd: process.cwd(), mode: coerceMode(mode)});
118
+ await Scout9Platform.test({cwd: process.cwd(), mode: coerceMode(mode), src, dest});
119
+ process.exit(0);
87
120
  } catch (e) {
88
121
  handle_error(e);
89
122
  }
90
123
  });
91
124
 
92
125
  prog
93
- .command('dev')
94
- .describe('Run your scout9 auto reply app locally')
95
- .option('--mode', 'Specify a mode for loading environment variables', 'development')
96
- .action(async ({ mode }) => {
97
- if (!fs.existsSync('.env')) {
98
- console.warn(`Missing ${path.resolve('.env')} — skipping`);
99
- return;
100
- }
101
- try {
102
- throw new Error('Dev server not available yet');
103
- } catch (e) {
104
- handle_error(e);
105
- }
106
- })
126
+ .command('dev')
127
+ .describe('Builds and runs your scout9 auto reply app locally')
128
+ .option('--mode', 'Specify a mode for loading environment variables', 'development')
129
+ .option('--src', 'Project source code folder', 'src')
130
+ .option('--open', 'Where to open website by default of not', true)
131
+ .option('--dest', 'Project local destination', './build')
132
+ .action(async ({mode, src, dest}) => {
133
+ if (!fs.existsSync('.env')) {
134
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
135
+ return;
136
+ }
137
+ mode = coerceMode(mode);
138
+ try {
139
+ process.env.DEV_MODE = "true";
140
+ const cwd = process.cwd();
141
+ await Scout9Platform.build({cwd, mode, src, dest});
142
+ await import(pathToFileURL(path.join(cwd, `${dest}/app.js`)));
143
+ } catch (e) {
144
+ handle_error(e);
145
+ }
146
+ });
147
+
148
+ prog
149
+ .command('config')
150
+ .describe('Prints the project configuration')
151
+ .option('--mode', 'Specify a mode for loading environment variables', 'production')
152
+ .option('--local', 'Prints the local configuration', false)
153
+ .option('--src', 'Project source code folder', 'src')
154
+ .action(async ({mode, local, src}) => {
155
+ if (!fs.existsSync('.env')) {
156
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
157
+ return;
158
+ }
159
+ mode = coerceMode(mode);
160
+ try {
161
+ const config = await Scout9Platform.config({cwd: process.cwd(), mode: coerceMode(mode), src, local});
162
+ console.log(JSON.stringify(config, null, 2));
163
+ process.exit(0);
164
+ } catch (e) {
165
+ handle_error(e);
166
+ }
167
+ });
168
+
169
+ prog
170
+ .command('run <eventPath>')
171
+ .describe('Runs the project locally with a given workflow event')
172
+ .option('--mode', 'Specify a mode for loading environment variables', 'development')
173
+ .option('--src', 'Project source code folder', './src')
174
+ .action(async (eventPath, {mode, src}) => {
175
+ if (!fs.existsSync('.env')) {
176
+ console.warn(`Missing ${path.resolve('.env')} — skipping`);
177
+ return;
178
+ }
179
+ mode = coerceMode(mode);
180
+ if (!fs.existsSync(eventPath)) {
181
+ console.error(`Event file not found: ${eventPath}`);
182
+ process.exit(1);
183
+ }
184
+ try {
185
+ const event = JSON.parse(fs.readFileSync(eventPath, 'utf-8'));
186
+ const result = await Scout9Platform.run(event, {cwd: process.cwd(), mode: coerceMode(mode), eventSource: eventPath, src});
187
+ console.log(JSON.stringify(result, null, 2));
188
+ process.exit(0);
189
+ } catch (e) {
190
+ handle_error(e);
191
+ }
192
+ });
193
+
194
+ prog
195
+ .command('message')
196
+ .describe('Send a test message to an agent')
197
+
198
+
107
199
 
200
+ // @TODO would be dope if I could test by sending a message to an agent with the cli tool
108
201
 
109
- prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
202
+ prog.parse(process.argv, {unknown: (arg) => `Unknown option: ${arg}`});