@faable/faable 1.32.1 → 1.33.0

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.
@@ -2,6 +2,7 @@ import { actions_create } from './create.js';
2
2
  import { actions_get } from './get.js';
3
3
  import { actions_list } from './list.js';
4
4
  import { actions_rm } from './rm.js';
5
+ import { actions_update } from './update.js';
5
6
 
6
7
  const actions = {
7
8
  command: 'actions',
@@ -10,6 +11,7 @@ const actions = {
10
11
  .command(actions_list)
11
12
  .command(actions_get)
12
13
  .command(actions_create)
14
+ .command(actions_update)
13
15
  .command(actions_rm)
14
16
  .demandCommand(1)
15
17
  .showHelpOnFail(false),
@@ -0,0 +1,62 @@
1
+ import fs from 'fs-extra';
2
+ import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
3
+ import { log } from '../../../log.js';
4
+ import { json_option, tenant_options } from '../options.js';
5
+ import { print_json } from '../render.js';
6
+
7
+ const actions_update = {
8
+ command: 'update <action_id>',
9
+ describe: 'Update an action (code, name, order, enabled)',
10
+ builder: yargs => json_option(tenant_options(yargs))
11
+ .positional('action_id', {
12
+ type: 'string',
13
+ demandOption: true,
14
+ description: 'Action identifier'
15
+ })
16
+ .option('name', {
17
+ alias: 'n',
18
+ type: 'string',
19
+ description: 'New action name (max 200 chars)'
20
+ })
21
+ .option('code-file', {
22
+ alias: 'f',
23
+ type: 'string',
24
+ description: 'Path to a JS file with the new action code'
25
+ })
26
+ .option('order', {
27
+ type: 'number',
28
+ description: 'Execution order (lower runs first)'
29
+ })
30
+ .option('enabled', {
31
+ type: 'boolean',
32
+ description: 'Enable (--enabled) or disable (--no-enabled) the action'
33
+ })
34
+ .example('$0 auth actions update action_abc123 -f ./gate.js', "Replace an action's code from a file")
35
+ .example('$0 auth actions update action_abc123 --no-enabled', 'Disable an action without touching its code')
36
+ .showHelpOnFail(false),
37
+ handler: withAuthHints(async (args) => {
38
+ let code;
39
+ if (args.codeFile) {
40
+ if (!(await fs.pathExists(args.codeFile))) {
41
+ throw new Error(`Code file not found: ${args.codeFile}`);
42
+ }
43
+ code = await fs.readFile(args.codeFile, 'utf8');
44
+ }
45
+ const patch = {
46
+ ...(args.name !== undefined ? { name: args.name } : {}),
47
+ ...(code !== undefined ? { code } : {}),
48
+ ...(args.order !== undefined ? { order: args.order } : {}),
49
+ ...(args.enabled !== undefined ? { enabled: args.enabled } : {})
50
+ };
51
+ if (Object.keys(patch).length === 0) {
52
+ throw new Error('Nothing to update — pass at least one of --name, --code-file, --order, --enabled');
53
+ }
54
+ const api = await requireAuthAdmin(args);
55
+ const action = await api.actionUpdate(args.action_id, patch);
56
+ if (args.json)
57
+ return print_json(action);
58
+ log.info(`✅ Updated action ${action.id} (${action.name}, trigger ${action.trigger}, enabled: ${action.enabled ? '✓' : '✗'})`);
59
+ })
60
+ };
61
+
62
+ export { actions_update };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "1.32.1",
3
+ "version": "1.33.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",