@faable/faable 1.40.0 → 2.0.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.
- package/dist/commands/auth/actions/create.js +11 -18
- package/dist/commands/auth/actions/get.js +1 -1
- package/dist/commands/auth/actions/list.js +2 -2
- package/dist/commands/auth/actions/rm.js +2 -1
- package/dist/commands/auth/actions/triggers.js +13 -0
- package/dist/commands/auth/actions/update.js +3 -2
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
|
|
|
3
3
|
import { log } from '../../../log.js';
|
|
4
4
|
import { json_option, tenant_options } from '../options.js';
|
|
5
5
|
import { print_json } from '../render.js';
|
|
6
|
+
import { formatTriggers } from './triggers.js';
|
|
6
7
|
|
|
7
8
|
const actions_create = {
|
|
8
9
|
command: 'create',
|
|
@@ -13,18 +14,12 @@ const actions_create = {
|
|
|
13
14
|
type: 'string',
|
|
14
15
|
demandOption: true,
|
|
15
16
|
description: 'Action name (max 200 chars)'
|
|
16
|
-
})
|
|
17
|
-
.option('trigger', {
|
|
18
|
-
alias: 't',
|
|
19
|
-
type: 'string',
|
|
20
|
-
choices: ['post-login', 'continue', 'client-credentials'],
|
|
21
|
-
demandOption: true,
|
|
22
|
-
description: 'Trigger point (client-credentials runs on M2M token grants: no user, no redirect)'
|
|
23
17
|
})
|
|
24
18
|
.option('code-file', {
|
|
25
19
|
alias: 'f',
|
|
26
20
|
type: 'string',
|
|
27
|
-
|
|
21
|
+
demandOption: true,
|
|
22
|
+
description: 'Path to a JS file with the action code. The triggers are derived from the hooks it exports (exports.onExecutePostLogin / onExecuteContinue / onExecuteClientCredentials)'
|
|
28
23
|
})
|
|
29
24
|
.option('disabled', {
|
|
30
25
|
type: 'boolean',
|
|
@@ -35,27 +30,25 @@ const actions_create = {
|
|
|
35
30
|
type: 'number',
|
|
36
31
|
description: 'Execution order (lower runs first, default 0)'
|
|
37
32
|
})
|
|
38
|
-
.example('$0 auth actions create -n add-claims -
|
|
33
|
+
.example('$0 auth actions create -n add-claims -f ./claims.js', 'Create an action from a file; its triggers follow the exported hooks')
|
|
39
34
|
.showHelpOnFail(false),
|
|
40
35
|
handler: withAuthHints(async (args) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!(await fs.pathExists(args.codeFile))) {
|
|
44
|
-
throw new Error(`Code file not found: ${args.codeFile}`);
|
|
45
|
-
}
|
|
46
|
-
code = await fs.readFile(args.codeFile, 'utf8');
|
|
36
|
+
if (!(await fs.pathExists(args.codeFile))) {
|
|
37
|
+
throw new Error(`Code file not found: ${args.codeFile}`);
|
|
47
38
|
}
|
|
39
|
+
const code = await fs.readFile(args.codeFile, 'utf8');
|
|
48
40
|
const api = await requireAuthAdmin(args);
|
|
49
41
|
const action = await api.actionCreate({
|
|
50
42
|
name: args.name,
|
|
51
|
-
|
|
52
|
-
...(code !== undefined ? { code } : {}),
|
|
43
|
+
code,
|
|
53
44
|
...(args.disabled ? { enabled: false } : {}),
|
|
54
45
|
...(args.order !== undefined ? { order: args.order } : {})
|
|
46
|
+
// `trigger` is gone from the API (auth ≥ v1.58): triggers are derived
|
|
47
|
+
// from the code. Cast until the SDK types catch up with that release.
|
|
55
48
|
});
|
|
56
49
|
if (args.json)
|
|
57
50
|
return print_json(action);
|
|
58
|
-
log.info(`✅ Created action ${action.id} (${action.name},
|
|
51
|
+
log.info(`✅ Created action ${action.id} (${action.name}, triggers ${formatTriggers(action)})`);
|
|
59
52
|
})
|
|
60
53
|
};
|
|
61
54
|
|
|
@@ -25,7 +25,7 @@ const actions_get = {
|
|
|
25
25
|
return print_json(action);
|
|
26
26
|
log.info(`⚙️ ${action.id}`);
|
|
27
27
|
log.info(` Name: ${action.name ?? '-'}`);
|
|
28
|
-
log.info(`
|
|
28
|
+
log.info(` Triggers: ${formatTriggers(action)}`);
|
|
29
29
|
log.info(` Enabled: ${yes_no(action.enabled)}`);
|
|
30
30
|
log.info(` Order: ${action.order ?? 0}`);
|
|
31
31
|
log.info(` Revision: ${action.revision ?? 1} (updated ${action.updatedAt ?? '-'})`);
|
|
@@ -10,7 +10,7 @@ const actions_list = {
|
|
|
10
10
|
builder: yargs => json_option(list_options(tenant_options(yargs)))
|
|
11
11
|
.option('query', {
|
|
12
12
|
type: 'string',
|
|
13
|
-
description: 'FaableQL filter, e.g. "
|
|
13
|
+
description: 'FaableQL filter, e.g. "enabled:true"'
|
|
14
14
|
})
|
|
15
15
|
.showHelpOnFail(false),
|
|
16
16
|
handler: withAuthHints(async (args) => {
|
|
@@ -26,7 +26,7 @@ const actions_list = {
|
|
|
26
26
|
const rows = items.map(a => [
|
|
27
27
|
a.id ?? '-',
|
|
28
28
|
a.name ?? '-',
|
|
29
|
-
a
|
|
29
|
+
formatTriggers(a),
|
|
30
30
|
yes_no(a.enabled),
|
|
31
31
|
String(a.order ?? 0),
|
|
32
32
|
when(a.createdAt)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import prompts from 'prompts';
|
|
2
2
|
import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
|
|
3
3
|
import { log } from '../../../log.js';
|
|
4
|
+
import { formatTriggers } from './triggers.js';
|
|
4
5
|
import { tenant_options } from '../options.js';
|
|
5
6
|
|
|
6
7
|
const actions_rm = {
|
|
@@ -27,7 +28,7 @@ const actions_rm = {
|
|
|
27
28
|
const { confirm } = await prompts({
|
|
28
29
|
type: 'toggle',
|
|
29
30
|
name: 'confirm',
|
|
30
|
-
message: `Delete action "${action.name}" (${action.id},
|
|
31
|
+
message: `Delete action "${action.name}" (${action.id}, triggers ${formatTriggers(action)})?`,
|
|
31
32
|
initial: false,
|
|
32
33
|
active: 'yes',
|
|
33
34
|
inactive: 'no'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// `triggers` (auth ≥ v1.58) replaced the hand-picked `trigger`: an action runs
|
|
2
|
+
// on every trigger whose hook its code exports. Tolerates both shapes so the
|
|
3
|
+
// CLI prints something sensible against either server version.
|
|
4
|
+
const formatTriggers = (action) => {
|
|
5
|
+
const list = action.triggers?.length
|
|
6
|
+
? action.triggers
|
|
7
|
+
: action.trigger
|
|
8
|
+
? [action.trigger]
|
|
9
|
+
: [];
|
|
10
|
+
return list.length ? list.join(',') : '-';
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { formatTriggers };
|
|
@@ -3,6 +3,7 @@ import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
|
|
|
3
3
|
import { log } from '../../../log.js';
|
|
4
4
|
import { json_option, tenant_options } from '../options.js';
|
|
5
5
|
import { print_json } from '../render.js';
|
|
6
|
+
import { formatTriggers } from './triggers.js';
|
|
6
7
|
|
|
7
8
|
const actions_update = {
|
|
8
9
|
command: 'update <action_id>',
|
|
@@ -21,7 +22,7 @@ const actions_update = {
|
|
|
21
22
|
.option('code-file', {
|
|
22
23
|
alias: 'f',
|
|
23
24
|
type: 'string',
|
|
24
|
-
description: 'Path to a JS file with the new action code'
|
|
25
|
+
description: 'Path to a JS file with the new action code (triggers are re-derived from the hooks it exports)'
|
|
25
26
|
})
|
|
26
27
|
.option('order', {
|
|
27
28
|
type: 'number',
|
|
@@ -55,7 +56,7 @@ const actions_update = {
|
|
|
55
56
|
const action = await api.actionUpdate(args.action_id, patch);
|
|
56
57
|
if (args.json)
|
|
57
58
|
return print_json(action);
|
|
58
|
-
log.info(`✅ Updated action ${action.id} (${action.name},
|
|
59
|
+
log.info(`✅ Updated action ${action.id} (${action.name}, triggers ${formatTriggers(action)}, enabled: ${action.enabled ? '✓' : '✗'}, revision ${action.revision ?? '-'})`);
|
|
59
60
|
})
|
|
60
61
|
};
|
|
61
62
|
|