instant-cli 1.0.33 → 1.0.34
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/.turbo/turbo-build.log +1 -1
- package/__tests__/multiSelect.test.ts +236 -0
- package/__tests__/select.test.ts +224 -0
- package/__tests__/webhooks.test.ts +728 -0
- package/dist/commands/webhooks/add.d.ts +9 -0
- package/dist/commands/webhooks/add.d.ts.map +1 -0
- package/dist/commands/webhooks/add.js +75 -0
- package/dist/commands/webhooks/add.js.map +1 -0
- package/dist/commands/webhooks/delete.d.ts +6 -0
- package/dist/commands/webhooks/delete.d.ts.map +1 -0
- package/dist/commands/webhooks/delete.js +17 -0
- package/dist/commands/webhooks/delete.js.map +1 -0
- package/dist/commands/webhooks/disable.d.ts +7 -0
- package/dist/commands/webhooks/disable.d.ts.map +1 -0
- package/dist/commands/webhooks/disable.js +18 -0
- package/dist/commands/webhooks/disable.js.map +1 -0
- package/dist/commands/webhooks/enable.d.ts +6 -0
- package/dist/commands/webhooks/enable.d.ts.map +1 -0
- package/dist/commands/webhooks/enable.js +18 -0
- package/dist/commands/webhooks/enable.js.map +1 -0
- package/dist/commands/webhooks/events/list.d.ts +7 -0
- package/dist/commands/webhooks/events/list.d.ts.map +1 -0
- package/dist/commands/webhooks/events/list.js +31 -0
- package/dist/commands/webhooks/events/list.js.map +1 -0
- package/dist/commands/webhooks/events/payload.d.ts +8 -0
- package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
- package/dist/commands/webhooks/events/payload.js +39 -0
- package/dist/commands/webhooks/events/payload.js.map +1 -0
- package/dist/commands/webhooks/events/resend.d.ts +8 -0
- package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
- package/dist/commands/webhooks/events/resend.js +43 -0
- package/dist/commands/webhooks/events/resend.js.map +1 -0
- package/dist/commands/webhooks/list.d.ts +8 -0
- package/dist/commands/webhooks/list.d.ts.map +1 -0
- package/dist/commands/webhooks/list.js +29 -0
- package/dist/commands/webhooks/list.js.map +1 -0
- package/dist/commands/webhooks/shared.d.ts +40 -0
- package/dist/commands/webhooks/shared.d.ts.map +1 -0
- package/dist/commands/webhooks/shared.js +248 -0
- package/dist/commands/webhooks/shared.js.map +1 -0
- package/dist/commands/webhooks/update.d.ts +10 -0
- package/dist/commands/webhooks/update.d.ts.map +1 -0
- package/dist/commands/webhooks/update.js +189 -0
- package/dist/commands/webhooks/update.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -1
- package/dist/layer.d.ts +2 -2
- package/dist/layer.d.ts.map +1 -1
- package/dist/layer.js +30 -1
- package/dist/layer.js.map +1 -1
- package/dist/lib/webhooks.d.ts +28 -0
- package/dist/lib/webhooks.d.ts.map +1 -0
- package/dist/lib/webhooks.js +102 -0
- package/dist/lib/webhooks.js.map +1 -0
- package/dist/ui/index.d.ts +39 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +387 -25
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/lib.d.ts +7 -0
- package/dist/ui/lib.d.ts.map +1 -1
- package/dist/ui/lib.js +40 -1
- package/dist/ui/lib.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/webhooks/add.ts +111 -0
- package/src/commands/webhooks/delete.ts +23 -0
- package/src/commands/webhooks/disable.ts +24 -0
- package/src/commands/webhooks/enable.ts +24 -0
- package/src/commands/webhooks/events/list.ts +38 -0
- package/src/commands/webhooks/events/payload.ts +56 -0
- package/src/commands/webhooks/events/resend.ts +66 -0
- package/src/commands/webhooks/list.ts +41 -0
- package/src/commands/webhooks/shared.ts +339 -0
- package/src/commands/webhooks/update.ts +276 -0
- package/src/index.ts +242 -0
- package/src/layer.ts +33 -1
- package/src/lib/webhooks.ts +127 -0
- package/src/ui/index.ts +465 -32
- package/src/ui/lib.ts +41 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instant-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.34",
|
|
5
5
|
"description": "Instant's CLI",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/cli",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"strip-ansi": "^7.1.2",
|
|
51
51
|
"supports-hyperlinks": "^4.4.0",
|
|
52
52
|
"unconfig": "^7.5.0",
|
|
53
|
-
"@instantdb/core": "1.0.
|
|
54
|
-
"@instantdb/
|
|
55
|
-
"@instantdb/
|
|
53
|
+
"@instantdb/core": "1.0.34",
|
|
54
|
+
"@instantdb/platform": "1.0.34",
|
|
55
|
+
"@instantdb/version": "1.0.34"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@babel/core": "^7.17.9",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type { WebhookAction } from '@instantdb/platform';
|
|
4
|
+
import type { OptsFromCommand, webhooksAddDef } from '../../index.ts';
|
|
5
|
+
import { Args } from '../../lib/args.ts';
|
|
6
|
+
import { runUIEffect } from '../../lib/ui.ts';
|
|
7
|
+
import { clearPromptTrail, UI } from '../../ui/index.ts';
|
|
8
|
+
import {
|
|
9
|
+
getRemoteNamespaces,
|
|
10
|
+
parseActions,
|
|
11
|
+
parseNamespaces,
|
|
12
|
+
useWebhooksManager,
|
|
13
|
+
WEBHOOK_ACTIONS,
|
|
14
|
+
} from '../../lib/webhooks.ts';
|
|
15
|
+
import { BadArgsError } from '../../errors.ts';
|
|
16
|
+
import { GlobalOpts } from '../../context/globalOpts.ts';
|
|
17
|
+
import { logWebhookEvent, validateWebhookUrl } from './shared.ts';
|
|
18
|
+
|
|
19
|
+
export const webhooksAddCmd = Effect.fn(
|
|
20
|
+
function* (opts: OptsFromCommand<typeof webhooksAddDef>) {
|
|
21
|
+
const { yes } = yield* GlobalOpts;
|
|
22
|
+
|
|
23
|
+
const url = yield* Args.text(opts, 'url').pipe(
|
|
24
|
+
Args.prompt({
|
|
25
|
+
prompt: 'Webhook URL:',
|
|
26
|
+
placeholder: 'https://...',
|
|
27
|
+
validate: validateWebhookUrl,
|
|
28
|
+
modifyOutput: UI.modifiers.piped([
|
|
29
|
+
UI.modifiers.topPadding,
|
|
30
|
+
UI.modifiers.dimOnComplete,
|
|
31
|
+
]),
|
|
32
|
+
}),
|
|
33
|
+
Args.validate(validateWebhookUrl),
|
|
34
|
+
Args.required(),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
let namespaces = yield* parseNamespaces(opts.namespaces);
|
|
38
|
+
if (!namespaces) {
|
|
39
|
+
if (yes) {
|
|
40
|
+
return yield* BadArgsError.make({
|
|
41
|
+
message:
|
|
42
|
+
'Missing required value for --namespaces (comma-separated list)',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const available = yield* getRemoteNamespaces;
|
|
46
|
+
if (available && available.length > 0) {
|
|
47
|
+
namespaces = yield* runUIEffect(
|
|
48
|
+
new UI.MultiSelect<string>({
|
|
49
|
+
options: available.map((name) => ({ value: name, label: name })),
|
|
50
|
+
promptText: 'Namespaces to listen to:',
|
|
51
|
+
minSelected: 1,
|
|
52
|
+
modifyOutput: UI.modifiers.dimOnComplete,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
} else {
|
|
56
|
+
const raw = yield* runUIEffect(
|
|
57
|
+
new UI.TextInput({
|
|
58
|
+
prompt: 'Namespaces (comma-separated):',
|
|
59
|
+
placeholder: 'posts,comments',
|
|
60
|
+
modifyOutput: UI.modifiers.piped([
|
|
61
|
+
UI.modifiers.topPadding,
|
|
62
|
+
UI.modifiers.dimOnComplete,
|
|
63
|
+
]),
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
namespaces = yield* parseNamespaces(raw);
|
|
67
|
+
if (!namespaces) {
|
|
68
|
+
return yield* BadArgsError.make({
|
|
69
|
+
message: '--namespaces must include at least one namespace',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let actions = yield* parseActions(opts.actions);
|
|
76
|
+
if (!actions) {
|
|
77
|
+
if (yes) {
|
|
78
|
+
return yield* BadArgsError.make({
|
|
79
|
+
message:
|
|
80
|
+
'Missing required value for --actions (comma-separated list of create,update,delete)',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
actions = yield* runUIEffect(
|
|
84
|
+
new UI.MultiSelect<WebhookAction>({
|
|
85
|
+
options: WEBHOOK_ACTIONS.map((a) => ({ value: a, label: a })),
|
|
86
|
+
promptText: 'Actions to trigger on:',
|
|
87
|
+
minSelected: 1,
|
|
88
|
+
modifyOutput: UI.modifiers.dimOnComplete,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const webhook = yield* useWebhooksManager(
|
|
94
|
+
(m) => m.create({ url, namespaces, actions }),
|
|
95
|
+
'Error creating webhook',
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
yield* Effect.sync(clearPromptTrail);
|
|
99
|
+
yield* logWebhookEvent('added', webhook);
|
|
100
|
+
},
|
|
101
|
+
Effect.catchTag('BadArgsError', (e) =>
|
|
102
|
+
Effect.gen(function* () {
|
|
103
|
+
yield* Effect.logError(e.message);
|
|
104
|
+
yield* Effect.log(
|
|
105
|
+
chalk.dim(
|
|
106
|
+
'hint: run `instant-cli webhook add --help` for available arguments',
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
}),
|
|
110
|
+
),
|
|
111
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { OptsFromCommand, webhooksDeleteDef } from '../../index.ts';
|
|
3
|
+
import { useWebhooksManager } from '../../lib/webhooks.ts';
|
|
4
|
+
import { logWebhookEvent, resolveWebhookId } from './shared.ts';
|
|
5
|
+
|
|
6
|
+
export const webhooksDeleteCmd = Effect.fn(function* (
|
|
7
|
+
opts: OptsFromCommand<typeof webhooksDeleteDef>,
|
|
8
|
+
) {
|
|
9
|
+
const id = yield* resolveWebhookId({
|
|
10
|
+
id: opts.id,
|
|
11
|
+
picker: {
|
|
12
|
+
promptText: 'Select a webhook to delete:',
|
|
13
|
+
emptyMessage: 'No webhooks configured.',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
if (!id) return;
|
|
17
|
+
|
|
18
|
+
const webhook = yield* useWebhooksManager(
|
|
19
|
+
(m) => m.delete(id),
|
|
20
|
+
'Error deleting webhook',
|
|
21
|
+
);
|
|
22
|
+
yield* logWebhookEvent('deleted', webhook);
|
|
23
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { OptsFromCommand, webhooksDisableDef } from '../../index.ts';
|
|
3
|
+
import { useWebhooksManager } from '../../lib/webhooks.ts';
|
|
4
|
+
import { logWebhookEvent, resolveWebhookId } from './shared.ts';
|
|
5
|
+
|
|
6
|
+
export const webhooksDisableCmd = Effect.fn(function* (
|
|
7
|
+
opts: OptsFromCommand<typeof webhooksDisableDef>,
|
|
8
|
+
) {
|
|
9
|
+
const id = yield* resolveWebhookId({
|
|
10
|
+
id: opts.id,
|
|
11
|
+
picker: {
|
|
12
|
+
promptText: 'Select a webhook to disable:',
|
|
13
|
+
emptyMessage: 'No active webhooks.',
|
|
14
|
+
filter: (w) => w.status === 'active',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!id) return;
|
|
18
|
+
|
|
19
|
+
const webhook = yield* useWebhooksManager(
|
|
20
|
+
(m) => m.disable(id, opts.reason ? { reason: opts.reason } : undefined),
|
|
21
|
+
'Error disabling webhook',
|
|
22
|
+
);
|
|
23
|
+
yield* logWebhookEvent('disabled', webhook);
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { OptsFromCommand, webhooksEnableDef } from '../../index.ts';
|
|
3
|
+
import { useWebhooksManager } from '../../lib/webhooks.ts';
|
|
4
|
+
import { logWebhookEvent, resolveWebhookId } from './shared.ts';
|
|
5
|
+
|
|
6
|
+
export const webhooksEnableCmd = Effect.fn(function* (
|
|
7
|
+
opts: OptsFromCommand<typeof webhooksEnableDef>,
|
|
8
|
+
) {
|
|
9
|
+
const id = yield* resolveWebhookId({
|
|
10
|
+
id: opts.id,
|
|
11
|
+
picker: {
|
|
12
|
+
promptText: 'Select a webhook to enable:',
|
|
13
|
+
emptyMessage: 'No disabled webhooks.',
|
|
14
|
+
filter: (w) => w.status === 'disabled',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!id) return;
|
|
18
|
+
|
|
19
|
+
const webhook = yield* useWebhooksManager(
|
|
20
|
+
(m) => m.enable(id),
|
|
21
|
+
'Error enabling webhook',
|
|
22
|
+
);
|
|
23
|
+
yield* logWebhookEvent('enabled', webhook);
|
|
24
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { OptsFromCommand, webhooksEventsListDef } from '../../../index.ts';
|
|
3
|
+
import { fetchRecentEvents } from '../../../lib/webhooks.ts';
|
|
4
|
+
import { logEventDetail, resolveWebhookId } from '../shared.ts';
|
|
5
|
+
|
|
6
|
+
const EVENT_LIMIT = 100;
|
|
7
|
+
|
|
8
|
+
export const webhooksEventsListCmd = Effect.fn(function* (
|
|
9
|
+
opts: OptsFromCommand<typeof webhooksEventsListDef>,
|
|
10
|
+
) {
|
|
11
|
+
const webhookId = yield* resolveWebhookId({
|
|
12
|
+
id: opts.webhookId,
|
|
13
|
+
flagName: '--webhook-id',
|
|
14
|
+
picker: {
|
|
15
|
+
promptText: 'Select a webhook to inspect:',
|
|
16
|
+
emptyMessage: 'No webhooks configured.',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
if (!webhookId) return;
|
|
20
|
+
|
|
21
|
+
const events = yield* fetchRecentEvents(webhookId, EVENT_LIMIT);
|
|
22
|
+
|
|
23
|
+
if (opts.json) {
|
|
24
|
+
yield* Effect.log(JSON.stringify(events, null, 2));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (events.length === 0) {
|
|
29
|
+
yield* Effect.log('No events for this webhook.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const event of events) {
|
|
34
|
+
for (const line of logEventDetail(event)) {
|
|
35
|
+
yield* Effect.log(line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type {
|
|
4
|
+
OptsFromCommand,
|
|
5
|
+
webhooksEventsPayloadDef,
|
|
6
|
+
} from '../../../index.ts';
|
|
7
|
+
import { GlobalOpts } from '../../../context/globalOpts.ts';
|
|
8
|
+
import { BadArgsError } from '../../../errors.ts';
|
|
9
|
+
import { useWebhooksManager } from '../../../lib/webhooks.ts';
|
|
10
|
+
import { pickEvent, resolveWebhookId } from '../shared.ts';
|
|
11
|
+
|
|
12
|
+
export const webhooksEventsPayloadCmd = Effect.fn(
|
|
13
|
+
function* (opts: OptsFromCommand<typeof webhooksEventsPayloadDef>) {
|
|
14
|
+
const { yes } = yield* GlobalOpts;
|
|
15
|
+
|
|
16
|
+
const webhookId = yield* resolveWebhookId({
|
|
17
|
+
id: opts.webhookId,
|
|
18
|
+
flagName: '--webhook-id',
|
|
19
|
+
picker: {
|
|
20
|
+
promptText: 'Select a webhook:',
|
|
21
|
+
emptyMessage: 'No webhooks configured.',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (!webhookId) return;
|
|
25
|
+
|
|
26
|
+
let isn = opts.isn;
|
|
27
|
+
if (!isn) {
|
|
28
|
+
if (yes) {
|
|
29
|
+
return yield* BadArgsError.make({ message: 'Must specify --isn' });
|
|
30
|
+
}
|
|
31
|
+
const picked = yield* pickEvent({
|
|
32
|
+
webhookId,
|
|
33
|
+
promptText: 'Select an event:',
|
|
34
|
+
emptyMessage: 'No events for this webhook.',
|
|
35
|
+
});
|
|
36
|
+
if (!picked) return;
|
|
37
|
+
isn = picked.isn;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const payload = yield* useWebhooksManager(
|
|
41
|
+
(m) => m.getPayload(webhookId, isn!),
|
|
42
|
+
'Error fetching event payload',
|
|
43
|
+
);
|
|
44
|
+
yield* Effect.log(JSON.stringify(payload, null, 2));
|
|
45
|
+
},
|
|
46
|
+
Effect.catchTag('BadArgsError', (e) =>
|
|
47
|
+
Effect.gen(function* () {
|
|
48
|
+
yield* Effect.logError(e.message);
|
|
49
|
+
yield* Effect.log(
|
|
50
|
+
chalk.dim(
|
|
51
|
+
'hint: run `instant-cli webhook event payload --help` for available arguments',
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type {
|
|
4
|
+
OptsFromCommand,
|
|
5
|
+
webhooksEventsResendDef,
|
|
6
|
+
} from '../../../index.ts';
|
|
7
|
+
import { GlobalOpts } from '../../../context/globalOpts.ts';
|
|
8
|
+
import { BadArgsError } from '../../../errors.ts';
|
|
9
|
+
import { useWebhooksManager } from '../../../lib/webhooks.ts';
|
|
10
|
+
import {
|
|
11
|
+
colorStatus,
|
|
12
|
+
logEventDetail,
|
|
13
|
+
pickEvent,
|
|
14
|
+
resolveWebhookId,
|
|
15
|
+
} from '../shared.ts';
|
|
16
|
+
|
|
17
|
+
export const webhooksEventsResendCmd = Effect.fn(
|
|
18
|
+
function* (opts: OptsFromCommand<typeof webhooksEventsResendDef>) {
|
|
19
|
+
const { yes } = yield* GlobalOpts;
|
|
20
|
+
|
|
21
|
+
const webhookId = yield* resolveWebhookId({
|
|
22
|
+
id: opts.webhookId,
|
|
23
|
+
flagName: '--webhook-id',
|
|
24
|
+
picker: {
|
|
25
|
+
promptText: 'Select a webhook:',
|
|
26
|
+
emptyMessage: 'No webhooks configured.',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (!webhookId) return;
|
|
30
|
+
|
|
31
|
+
let isn = opts.isn;
|
|
32
|
+
if (!isn) {
|
|
33
|
+
if (yes) {
|
|
34
|
+
return yield* BadArgsError.make({ message: 'Must specify --isn' });
|
|
35
|
+
}
|
|
36
|
+
const picked = yield* pickEvent({
|
|
37
|
+
webhookId,
|
|
38
|
+
promptText: 'Select an event to resend:',
|
|
39
|
+
emptyMessage: 'No events for this webhook.',
|
|
40
|
+
});
|
|
41
|
+
if (!picked) return;
|
|
42
|
+
isn = picked.isn;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const event = yield* useWebhooksManager(
|
|
46
|
+
(m) => m.resendEvent(webhookId, isn!),
|
|
47
|
+
'Error resending event',
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
yield* Effect.log(`Resent event ${chalk.cyan(event.isn)}`);
|
|
51
|
+
yield* Effect.log(`Status: ${colorStatus(event.status)}`);
|
|
52
|
+
for (const line of logEventDetail(event).slice(1)) {
|
|
53
|
+
yield* Effect.log(line);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
Effect.catchTag('BadArgsError', (e) =>
|
|
57
|
+
Effect.gen(function* () {
|
|
58
|
+
yield* Effect.logError(e.message);
|
|
59
|
+
yield* Effect.log(
|
|
60
|
+
chalk.dim(
|
|
61
|
+
'hint: run `instant-cli webhook event resend --help` for available arguments',
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type { WebhookInfo } from '@instantdb/platform';
|
|
4
|
+
import type { OptsFromCommand, webhooksListDef } from '../../index.ts';
|
|
5
|
+
import { useWebhooksManager } from '../../lib/webhooks.ts';
|
|
6
|
+
import { joinActions, joinNamespaces } from './shared.ts';
|
|
7
|
+
|
|
8
|
+
export const renderWebhook = (webhook: WebhookInfo) =>
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
yield* Effect.log(chalk.cyan(webhook.sink.url));
|
|
11
|
+
yield* Effect.log(` ID: ${webhook.id}`);
|
|
12
|
+
yield* Effect.log(` Status: ${webhook.status}`);
|
|
13
|
+
yield* Effect.log(` Actions: ${joinActions(webhook.actions)}`);
|
|
14
|
+
yield* Effect.log(` Namespaces: ${joinNamespaces(webhook.namespaces)}`);
|
|
15
|
+
if (webhook.disabledReason) {
|
|
16
|
+
yield* Effect.log(` Disabled reason: ${webhook.disabledReason}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const webhooksListCmd = Effect.fn(function* (
|
|
21
|
+
opts: OptsFromCommand<typeof webhooksListDef>,
|
|
22
|
+
) {
|
|
23
|
+
const webhooks = yield* useWebhooksManager(
|
|
24
|
+
(m) => m.list(),
|
|
25
|
+
'Error listing webhooks',
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
yield* Effect.log(JSON.stringify(webhooks, null, 2));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (webhooks.length === 0) {
|
|
34
|
+
yield* Effect.log('No webhooks configured.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const webhook of webhooks) {
|
|
39
|
+
yield* renderWebhook(webhook);
|
|
40
|
+
}
|
|
41
|
+
});
|