@scout9/app 1.0.0-alpha.0.2.0 → 1.0.0-alpha.0.2.2
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/{index-7460cfee.cjs → index-332067ab.cjs} +5 -6
- package/dist/index.cjs +1 -1
- package/dist/{multipart-parser-d080fdee.cjs → multipart-parser-50a82502.cjs} +1 -1
- package/package.json +2 -2
- package/src/cli.js +0 -1
- package/src/core/templates/app.js +83 -1
- package/src/platform.js +0 -2
- package/src/public.d.ts +128 -2930
- package/types/index.d.ts +633 -3436
- package/types/index.d.ts.map +25 -20
|
@@ -29482,7 +29482,7 @@ class Body {
|
|
|
29482
29482
|
}
|
|
29483
29483
|
const {
|
|
29484
29484
|
toFormData
|
|
29485
|
-
} = await Promise.resolve().then(function () { return require("./multipart-parser-
|
|
29485
|
+
} = await Promise.resolve().then(function () { return require("./multipart-parser-50a82502.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-
|
|
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');
|
|
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-
|
|
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)));
|
|
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-
|
|
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');
|
|
43316
43316
|
case 14:
|
|
43317
43317
|
_context4.t1 = _context4.sent;
|
|
43318
43318
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
|
@@ -44046,7 +44046,6 @@ var Scout9Platform = {
|
|
|
44046
44046
|
* @param {string} [params.cwd=process.cwd()] - the working directory
|
|
44047
44047
|
* @param {string} [params.src='./src'] - the source directory
|
|
44048
44048
|
* @param {string} [params.dest='/tmp/project'] - the destination directory
|
|
44049
|
-
* @param {'development' | 'production'} [params.mode='production'] - the build mode
|
|
44050
44049
|
* @param {boolean} [params.sync=true] - whether to sync the project after deploying
|
|
44051
44050
|
* @returns {Promise<Scout9ProjectBuildConfig>}
|
|
44052
44051
|
*/
|
|
@@ -44072,7 +44071,7 @@ var Scout9Platform = {
|
|
|
44072
44071
|
return spirits._regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
44073
44072
|
while (1) switch (_context2.prev = _context2.next) {
|
|
44074
44073
|
case 0:
|
|
44075
|
-
_ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$cwd = _ref2.cwd, cwd = _ref2$cwd === void 0 ? process.cwd() : _ref2$cwd, _ref2$src = _ref2.src, src = _ref2$src === void 0 ? './src' : _ref2$src, _ref2$dest = _ref2.dest, dest = _ref2$dest === void 0 ? '/tmp/project' : _ref2$dest, _ref2
|
|
44074
|
+
_ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$cwd = _ref2.cwd, cwd = _ref2$cwd === void 0 ? process.cwd() : _ref2$cwd, _ref2$src = _ref2.src, src = _ref2$src === void 0 ? './src' : _ref2$src, _ref2$dest = _ref2.dest, dest = _ref2$dest === void 0 ? '/tmp/project' : _ref2$dest, _ref2$sync = _ref2.sync, sync$1 = _ref2$sync === void 0 ? true : _ref2$sync;
|
|
44076
44075
|
logger = new dev.ProgressLogger();
|
|
44077
44076
|
messages = [];
|
|
44078
44077
|
_context2.prev = 3;
|
package/dist/index.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scout9/app",
|
|
3
|
-
"version": "1.0.0-alpha.0.2.
|
|
3
|
+
"version": "1.0.0-alpha.0.2.2",
|
|
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"
|
package/src/cli.js
CHANGED
|
@@ -84,7 +84,6 @@ prog
|
|
|
84
84
|
prog
|
|
85
85
|
.command('deploy')
|
|
86
86
|
.describe('Deploy your scout9 app')
|
|
87
|
-
.option('--mode', 'Specify a mode for loading environment variables', 'production')
|
|
88
87
|
.option('--src', 'Project source code folder', 'src')
|
|
89
88
|
.option('--sync, -s', 'Syncs project after deploying (overwriting code)', true)
|
|
90
89
|
.option('--dest', 'Project local destination', './build')
|
|
@@ -6,12 +6,13 @@ 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';
|
|
15
16
|
|
|
16
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
17
18
|
const __dirname = path.dirname(__filename);
|
|
@@ -229,6 +230,7 @@ async function resolveEntityApi(entity, method) {
|
|
|
229
230
|
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
|
|
232
234
|
function extractParamsFromPath(path) {
|
|
233
235
|
const segments = path.split('/').filter(Boolean); // Split and remove empty segments
|
|
234
236
|
let params = {};
|
|
@@ -284,6 +286,86 @@ async function runEntityApi(req, res) {
|
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
288
|
|
|
289
|
+
async function getFilesRecursive(dir) {
|
|
290
|
+
let results = [];
|
|
291
|
+
const list = await readdir(dir, { withFileTypes: true });
|
|
292
|
+
|
|
293
|
+
for (const dirent of list) {
|
|
294
|
+
const res = resolve(dir, dirent.name);
|
|
295
|
+
if (dirent.isDirectory()) {
|
|
296
|
+
results = results.concat(await getFilesRecursive(res)); // Recursively get files from subdirectories
|
|
297
|
+
} else {
|
|
298
|
+
results.push(res); // Add file to results
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return results;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function runCommandApi(req, res) {
|
|
306
|
+
let file;
|
|
307
|
+
const {body, url} = req;
|
|
308
|
+
const params = url.split('/').slice(2).filter(Boolean);
|
|
309
|
+
const commandsDir = resolve(__dirname, `./src/commands`);
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
const files = await getFilesRecursive(commandsDir).then(files => files.map(file => file.replace(commandsDir, '.')).filter(file => params.every(p => file.includes(p))))
|
|
313
|
+
file = files?.[0];
|
|
314
|
+
} catch (e) {
|
|
315
|
+
console.log('No commands found', e.message)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
if (!file) {
|
|
320
|
+
throw new Error(`Unable to find command for ${url}`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let mod;
|
|
324
|
+
try {
|
|
325
|
+
mod = await import(pathToFileURL(path.resolve(commandsDir, file)).href)
|
|
326
|
+
console.log(mod);
|
|
327
|
+
} catch (e) {
|
|
328
|
+
if ('code' in e) {
|
|
329
|
+
switch (e.code) {
|
|
330
|
+
case 'ERR_MODULE_NOT_FOUND':
|
|
331
|
+
case 'MODULE_NOT_FOUND':
|
|
332
|
+
console.error(e);
|
|
333
|
+
throw new Error(`Invalid command: no API method`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
console.error(e);
|
|
337
|
+
throw new Error(`Invalid command: Internal system error`);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!mod || !mod.default) {
|
|
341
|
+
throw new Error(`Command file "${file}" does not export a default command function`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
console.log(mod);
|
|
345
|
+
|
|
346
|
+
let result;
|
|
347
|
+
|
|
348
|
+
try {
|
|
349
|
+
result = await mod.default(body);
|
|
350
|
+
} catch (e) {
|
|
351
|
+
console.error('Failed to run command', e);
|
|
352
|
+
throw new Error(`Failed to run command: ${e.message}`)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (result) {
|
|
356
|
+
if (typeof result === 'string') {
|
|
357
|
+
return {message: result};
|
|
358
|
+
} else if (typeof result === 'object' && 'message' in result) {
|
|
359
|
+
return result;
|
|
360
|
+
} else {
|
|
361
|
+
throw new Error(`Invalid Command Response, must either return a string or {"message": "<your message>"}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return {message: `${mod.default.name} Complete`};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
app.post('/commands/:command', runCommandApi);
|
|
368
|
+
app.post('/commands/:command/*', runCommandApi);
|
|
287
369
|
app.get('/entity/:entity', runEntityApi);
|
|
288
370
|
app.put('/entity/:entity', runEntityApi);
|
|
289
371
|
app.patch('/entity/:entity', runEntityApi);
|
package/src/platform.js
CHANGED
|
@@ -52,7 +52,6 @@ export const Scout9Platform = {
|
|
|
52
52
|
* @param {string} [params.cwd=process.cwd()] - the working directory
|
|
53
53
|
* @param {string} [params.src='./src'] - the source directory
|
|
54
54
|
* @param {string} [params.dest='/tmp/project'] - the destination directory
|
|
55
|
-
* @param {'development' | 'production'} [params.mode='production'] - the build mode
|
|
56
55
|
* @param {boolean} [params.sync=true] - whether to sync the project after deploying
|
|
57
56
|
* @returns {Promise<Scout9ProjectBuildConfig>}
|
|
58
57
|
*/
|
|
@@ -61,7 +60,6 @@ export const Scout9Platform = {
|
|
|
61
60
|
cwd = process.cwd(),
|
|
62
61
|
src = './src',
|
|
63
62
|
dest = '/tmp/project',
|
|
64
|
-
mode = 'production',
|
|
65
63
|
sync = true
|
|
66
64
|
} = {}
|
|
67
65
|
) {
|