prismic 0.0.0-pr.28.59bf330
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/LICENSE +202 -0
- package/README.md +69 -0
- package/dist/builders-hKD4IrLX-DsO7BUQw.mjs +97 -0
- package/dist/dist-B11B2hHn.mjs +1 -0
- package/dist/dist-DT8CtumB.mjs +1 -0
- package/dist/framework-CfjEoVk0.mjs +17 -0
- package/dist/index.mjs +2537 -0
- package/dist/nextjs-9z7YrSnS.mjs +312 -0
- package/dist/nuxt-KoJ61G2q.mjs +59 -0
- package/dist/sveltekit-DjXKCG78.mjs +226 -0
- package/package.json +58 -0
- package/src/codegen-types.ts +82 -0
- package/src/codegen.ts +45 -0
- package/src/custom-type-add-field-boolean.ts +185 -0
- package/src/custom-type-add-field-color.ts +168 -0
- package/src/custom-type-add-field-date.ts +171 -0
- package/src/custom-type-add-field-embed.ts +168 -0
- package/src/custom-type-add-field-geo-point.ts +165 -0
- package/src/custom-type-add-field-group.ts +142 -0
- package/src/custom-type-add-field-image.ts +168 -0
- package/src/custom-type-add-field-key-text.ts +168 -0
- package/src/custom-type-add-field-link.ts +191 -0
- package/src/custom-type-add-field-number.ts +200 -0
- package/src/custom-type-add-field-rich-text.ts +192 -0
- package/src/custom-type-add-field-select.ts +174 -0
- package/src/custom-type-add-field-timestamp.ts +171 -0
- package/src/custom-type-add-field-uid.ts +151 -0
- package/src/custom-type-add-field.ts +116 -0
- package/src/custom-type-connect-slice.ts +178 -0
- package/src/custom-type-create.ts +98 -0
- package/src/custom-type-disconnect-slice.ts +134 -0
- package/src/custom-type-list.ts +110 -0
- package/src/custom-type-remove-field.ts +135 -0
- package/src/custom-type-remove.ts +103 -0
- package/src/custom-type-set-name.ts +102 -0
- package/src/custom-type-view.ts +118 -0
- package/src/custom-type.ts +85 -0
- package/src/docs-fetch.ts +146 -0
- package/src/docs-list.ts +131 -0
- package/src/docs.ts +54 -0
- package/src/env.d.ts +12 -0
- package/src/framework/index.ts +399 -0
- package/src/framework/nextjs.templates.ts +426 -0
- package/src/framework/nextjs.ts +216 -0
- package/src/framework/nuxt.templates.ts +74 -0
- package/src/framework/nuxt.ts +250 -0
- package/src/framework/sveltekit.templates.ts +278 -0
- package/src/framework/sveltekit.ts +241 -0
- package/src/index.ts +155 -0
- package/src/init.ts +173 -0
- package/src/lib/auth.ts +200 -0
- package/src/lib/browser.ts +11 -0
- package/src/lib/config.ts +111 -0
- package/src/lib/custom-types-api.ts +385 -0
- package/src/lib/field-path.ts +81 -0
- package/src/lib/file.ts +49 -0
- package/src/lib/json.ts +3 -0
- package/src/lib/packageJson.ts +35 -0
- package/src/lib/profile.ts +39 -0
- package/src/lib/request.ts +116 -0
- package/src/lib/segment.ts +145 -0
- package/src/lib/sentry.ts +63 -0
- package/src/lib/string.ts +10 -0
- package/src/lib/url.ts +31 -0
- package/src/locale-add.ts +116 -0
- package/src/locale-list.ts +107 -0
- package/src/locale-remove.ts +88 -0
- package/src/locale-set-default.ts +131 -0
- package/src/locale.ts +60 -0
- package/src/login.ts +45 -0
- package/src/logout.ts +36 -0
- package/src/page-type-add-field-boolean.ts +179 -0
- package/src/page-type-add-field-color.ts +165 -0
- package/src/page-type-add-field-date.ts +168 -0
- package/src/page-type-add-field-embed.ts +165 -0
- package/src/page-type-add-field-geo-point.ts +162 -0
- package/src/page-type-add-field-group.ts +139 -0
- package/src/page-type-add-field-image.ts +165 -0
- package/src/page-type-add-field-key-text.ts +165 -0
- package/src/page-type-add-field-link.ts +188 -0
- package/src/page-type-add-field-number.ts +197 -0
- package/src/page-type-add-field-rich-text.ts +189 -0
- package/src/page-type-add-field-select.ts +171 -0
- package/src/page-type-add-field-timestamp.ts +168 -0
- package/src/page-type-add-field-uid.ts +148 -0
- package/src/page-type-add-field.ts +116 -0
- package/src/page-type-connect-slice.ts +178 -0
- package/src/page-type-create.ts +128 -0
- package/src/page-type-disconnect-slice.ts +134 -0
- package/src/page-type-list.ts +109 -0
- package/src/page-type-remove-field.ts +135 -0
- package/src/page-type-remove.ts +103 -0
- package/src/page-type-set-name.ts +102 -0
- package/src/page-type-set-repeatable.ts +111 -0
- package/src/page-type-view.ts +118 -0
- package/src/page-type.ts +90 -0
- package/src/preview-add.ts +126 -0
- package/src/preview-get-simulator.ts +104 -0
- package/src/preview-list.ts +106 -0
- package/src/preview-remove-simulator.ts +80 -0
- package/src/preview-remove.ts +109 -0
- package/src/preview-set-name.ts +137 -0
- package/src/preview-set-simulator.ts +116 -0
- package/src/preview.ts +75 -0
- package/src/pull.ts +236 -0
- package/src/push.ts +409 -0
- package/src/repo-create.ts +175 -0
- package/src/repo-get-access.ts +86 -0
- package/src/repo-list.ts +100 -0
- package/src/repo-set-access.ts +100 -0
- package/src/repo-set-name.ts +102 -0
- package/src/repo-view.ts +113 -0
- package/src/repo.ts +70 -0
- package/src/slice-add-field-boolean.ts +219 -0
- package/src/slice-add-field-color.ts +205 -0
- package/src/slice-add-field-date.ts +205 -0
- package/src/slice-add-field-embed.ts +205 -0
- package/src/slice-add-field-geo-point.ts +202 -0
- package/src/slice-add-field-group.ts +170 -0
- package/src/slice-add-field-image.ts +202 -0
- package/src/slice-add-field-key-text.ts +205 -0
- package/src/slice-add-field-link.ts +224 -0
- package/src/slice-add-field-number.ts +205 -0
- package/src/slice-add-field-rich-text.ts +229 -0
- package/src/slice-add-field-select.ts +211 -0
- package/src/slice-add-field-timestamp.ts +205 -0
- package/src/slice-add-field.ts +111 -0
- package/src/slice-add-variation.ts +142 -0
- package/src/slice-create.ts +164 -0
- package/src/slice-list-variations.ts +71 -0
- package/src/slice-list.ts +60 -0
- package/src/slice-remove-field.ts +125 -0
- package/src/slice-remove-variation.ts +113 -0
- package/src/slice-remove.ts +92 -0
- package/src/slice-rename.ts +104 -0
- package/src/slice-set-screenshot.ts +239 -0
- package/src/slice-view.ts +83 -0
- package/src/slice.ts +95 -0
- package/src/status.ts +834 -0
- package/src/sync.ts +259 -0
- package/src/token-create.ts +203 -0
- package/src/token-delete.ts +182 -0
- package/src/token-list.ts +223 -0
- package/src/token-set-name.ts +193 -0
- package/src/token.ts +60 -0
- package/src/webhook-add-header.ts +118 -0
- package/src/webhook-create.ts +152 -0
- package/src/webhook-disable.ts +109 -0
- package/src/webhook-enable.ts +132 -0
- package/src/webhook-list.ts +93 -0
- package/src/webhook-remove-header.ts +117 -0
- package/src/webhook-remove.ts +106 -0
- package/src/webhook-set-triggers.ts +148 -0
- package/src/webhook-status.ts +90 -0
- package/src/webhook-test.ts +106 -0
- package/src/webhook-view.ts +147 -0
- package/src/webhook.ts +95 -0
- package/src/whoami.ts +62 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { isAuthenticated } from "./lib/auth";
|
|
4
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
5
|
+
import { stringify } from "./lib/json";
|
|
6
|
+
import { ForbiddenRequestError } from "./lib/request";
|
|
7
|
+
import { updateWebhook } from "./webhook-enable";
|
|
8
|
+
import { getWebhooks, TRIGGER_DISPLAY } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Update which events trigger a webhook.
|
|
12
|
+
|
|
13
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
14
|
+
project root.
|
|
15
|
+
|
|
16
|
+
USAGE
|
|
17
|
+
prismic webhook set-triggers <url> [flags]
|
|
18
|
+
|
|
19
|
+
ARGUMENTS
|
|
20
|
+
<url> Webhook URL
|
|
21
|
+
|
|
22
|
+
FLAGS
|
|
23
|
+
-t, --trigger string Trigger events (can be repeated, at least one required)
|
|
24
|
+
-r, --repo string Repository domain
|
|
25
|
+
-h, --help Show help for command
|
|
26
|
+
|
|
27
|
+
TRIGGERS
|
|
28
|
+
document.published When documents are published
|
|
29
|
+
document.unpublished When documents are unpublished
|
|
30
|
+
release.created When a release is created
|
|
31
|
+
release.updated When a release is edited or deleted
|
|
32
|
+
tag.created When a tag is created
|
|
33
|
+
tag.deleted When a tag is deleted
|
|
34
|
+
|
|
35
|
+
LEARN MORE
|
|
36
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
37
|
+
`.trim();
|
|
38
|
+
|
|
39
|
+
const VALID_TRIGGERS = Object.values(TRIGGER_DISPLAY);
|
|
40
|
+
|
|
41
|
+
export async function webhookSetTriggers(): Promise<void> {
|
|
42
|
+
const {
|
|
43
|
+
values: { help, repo = await safeGetRepositoryFromConfig(), trigger },
|
|
44
|
+
positionals: [webhookUrl],
|
|
45
|
+
} = parseArgs({
|
|
46
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "set-triggers"
|
|
47
|
+
options: {
|
|
48
|
+
trigger: { type: "string", multiple: true, short: "t" },
|
|
49
|
+
repo: { type: "string", short: "r" },
|
|
50
|
+
help: { type: "boolean", short: "h" },
|
|
51
|
+
},
|
|
52
|
+
allowPositionals: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (help) {
|
|
56
|
+
console.info(HELP);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!webhookUrl) {
|
|
61
|
+
console.error("Missing required argument: <url>");
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!repo) {
|
|
67
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!trigger || trigger.length === 0) {
|
|
73
|
+
console.error("Missing required option: --trigger");
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Validate triggers
|
|
79
|
+
for (const t of trigger) {
|
|
80
|
+
if (!VALID_TRIGGERS.includes(t)) {
|
|
81
|
+
console.error(`Invalid trigger: ${t}`);
|
|
82
|
+
console.error(`Valid triggers: ${VALID_TRIGGERS.join(", ")}`);
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const authenticated = await isAuthenticated();
|
|
89
|
+
if (!authenticated) {
|
|
90
|
+
handleUnauthenticated();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const webhooksResponse = await getWebhooks(repo);
|
|
95
|
+
if (!webhooksResponse.ok) {
|
|
96
|
+
if (webhooksResponse.error instanceof ForbiddenRequestError) {
|
|
97
|
+
handleUnauthenticated();
|
|
98
|
+
} else {
|
|
99
|
+
console.error(`Failed to update webhook triggers: ${stringify(webhooksResponse.value)}`);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const webhook = webhooksResponse.value.find((w) => w.config.url === webhookUrl);
|
|
106
|
+
if (!webhook) {
|
|
107
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Build trigger settings: all false, then enable specified ones
|
|
113
|
+
const defaultValue = trigger.length > 0 ? false : true;
|
|
114
|
+
const triggers: Record<keyof typeof TRIGGER_DISPLAY, boolean> = {
|
|
115
|
+
documentsPublished: defaultValue,
|
|
116
|
+
documentsUnpublished: defaultValue,
|
|
117
|
+
releasesCreated: defaultValue,
|
|
118
|
+
releasesUpdated: defaultValue,
|
|
119
|
+
tagsCreated: defaultValue,
|
|
120
|
+
tagsDeleted: defaultValue,
|
|
121
|
+
};
|
|
122
|
+
for (const t of trigger) {
|
|
123
|
+
const [apiField] = Object.entries(TRIGGER_DISPLAY).find(([, display]) => t === display) ?? [];
|
|
124
|
+
if (!apiField) continue;
|
|
125
|
+
triggers[apiField as keyof typeof TRIGGER_DISPLAY] = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const response = await updateWebhook(repo, webhook.config._id, {
|
|
129
|
+
...webhook.config,
|
|
130
|
+
...triggers,
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
134
|
+
handleUnauthenticated();
|
|
135
|
+
} else {
|
|
136
|
+
console.error(`Failed to update webhook triggers: ${stringify(response.value)}`);
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
console.info(`Webhook triggers updated: ${trigger.join(", ")}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function handleUnauthenticated() {
|
|
146
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
147
|
+
process.exitCode = 1;
|
|
148
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { isAuthenticated } from "./lib/auth";
|
|
4
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
5
|
+
import { stringify } from "./lib/json";
|
|
6
|
+
import { ForbiddenRequestError } from "./lib/request";
|
|
7
|
+
import { getWebhooks } from "./webhook-view";
|
|
8
|
+
|
|
9
|
+
const HELP = `
|
|
10
|
+
Show the enabled/disabled status of a webhook.
|
|
11
|
+
|
|
12
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
13
|
+
project root.
|
|
14
|
+
|
|
15
|
+
USAGE
|
|
16
|
+
prismic webhook status <url> [flags]
|
|
17
|
+
|
|
18
|
+
ARGUMENTS
|
|
19
|
+
<url> Webhook URL
|
|
20
|
+
|
|
21
|
+
FLAGS
|
|
22
|
+
-r, --repo string Repository domain
|
|
23
|
+
-h, --help Show help for command
|
|
24
|
+
|
|
25
|
+
LEARN MORE
|
|
26
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
27
|
+
`.trim();
|
|
28
|
+
|
|
29
|
+
export async function webhookStatus(): Promise<void> {
|
|
30
|
+
const {
|
|
31
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
32
|
+
positionals: [webhookUrl],
|
|
33
|
+
} = parseArgs({
|
|
34
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "status"
|
|
35
|
+
options: {
|
|
36
|
+
repo: { type: "string", short: "r" },
|
|
37
|
+
help: { type: "boolean", short: "h" },
|
|
38
|
+
},
|
|
39
|
+
allowPositionals: true,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (help) {
|
|
43
|
+
console.info(HELP);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!webhookUrl) {
|
|
48
|
+
console.error("Missing required argument: <url>");
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!repo) {
|
|
54
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const authenticated = await isAuthenticated();
|
|
60
|
+
if (!authenticated) {
|
|
61
|
+
handleUnauthenticated();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const response = await getWebhooks(repo);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
68
|
+
handleUnauthenticated();
|
|
69
|
+
} else {
|
|
70
|
+
console.error(`Failed to get webhook status: ${stringify(response.value)}`);
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const webhook = response.value.find((w) => w.config.url === webhookUrl);
|
|
77
|
+
if (!webhook) {
|
|
78
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const status = webhook.config.active ? "enabled" : "disabled";
|
|
84
|
+
console.info(status);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handleUnauthenticated() {
|
|
88
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { isAuthenticated } from "./lib/auth";
|
|
4
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
5
|
+
import { stringify } from "./lib/json";
|
|
6
|
+
import { ForbiddenRequestError, request } from "./lib/request";
|
|
7
|
+
import { getRepoUrl } from "./lib/url";
|
|
8
|
+
import { getWebhooks } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Trigger a test webhook in a Prismic repository.
|
|
12
|
+
|
|
13
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
14
|
+
project root.
|
|
15
|
+
|
|
16
|
+
USAGE
|
|
17
|
+
prismic webhook test <url> [flags]
|
|
18
|
+
|
|
19
|
+
ARGUMENTS
|
|
20
|
+
<url> Webhook URL
|
|
21
|
+
|
|
22
|
+
FLAGS
|
|
23
|
+
-r, --repo string Repository domain
|
|
24
|
+
-h, --help Show help for command
|
|
25
|
+
|
|
26
|
+
LEARN MORE
|
|
27
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
28
|
+
`.trim();
|
|
29
|
+
|
|
30
|
+
export async function webhookTest(): Promise<void> {
|
|
31
|
+
const {
|
|
32
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
33
|
+
positionals: [webhookUrl],
|
|
34
|
+
} = parseArgs({
|
|
35
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "test"
|
|
36
|
+
options: {
|
|
37
|
+
repo: { type: "string", short: "r" },
|
|
38
|
+
help: { type: "boolean", short: "h" },
|
|
39
|
+
},
|
|
40
|
+
allowPositionals: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (help) {
|
|
44
|
+
console.info(HELP);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!webhookUrl) {
|
|
49
|
+
console.error("Missing required argument: <url>");
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!repo) {
|
|
55
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
56
|
+
process.exitCode = 1;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const authenticated = await isAuthenticated();
|
|
61
|
+
if (!authenticated) {
|
|
62
|
+
handleUnauthenticated();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const webhooksResponse = await getWebhooks(repo);
|
|
67
|
+
if (!webhooksResponse.ok) {
|
|
68
|
+
if (webhooksResponse.error instanceof ForbiddenRequestError) {
|
|
69
|
+
handleUnauthenticated();
|
|
70
|
+
} else {
|
|
71
|
+
console.error(`Failed to test webhook: ${stringify(webhooksResponse.value)}`);
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const webhook = webhooksResponse.value.find((w) => w.config.url === webhookUrl);
|
|
78
|
+
if (!webhook) {
|
|
79
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const response = await triggerWebhook(repo, webhook.config._id);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
87
|
+
handleUnauthenticated();
|
|
88
|
+
} else {
|
|
89
|
+
console.error(`Failed to test webhook: ${stringify(response.value)}`);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.info(`Test webhook triggered: ${webhookUrl}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function triggerWebhook(repo: string, webhookId: string) {
|
|
99
|
+
const url = new URL(`/app/settings/webhooks/${webhookId}/trigger`, await getRepoUrl(repo));
|
|
100
|
+
return await request(url, { method: "POST" });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleUnauthenticated() {
|
|
104
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
import { isAuthenticated } from "./lib/auth";
|
|
5
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
6
|
+
import { stringify } from "./lib/json";
|
|
7
|
+
import { ForbiddenRequestError, type ParsedRequestResponse, request } from "./lib/request";
|
|
8
|
+
import { getRepoUrl } from "./lib/url";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
View details of a webhook in a Prismic repository.
|
|
12
|
+
|
|
13
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
14
|
+
project root.
|
|
15
|
+
|
|
16
|
+
USAGE
|
|
17
|
+
prismic webhook view <url> [flags]
|
|
18
|
+
|
|
19
|
+
ARGUMENTS
|
|
20
|
+
<url> Webhook URL
|
|
21
|
+
|
|
22
|
+
FLAGS
|
|
23
|
+
-r, --repo string Repository domain
|
|
24
|
+
-h, --help Show help for command
|
|
25
|
+
|
|
26
|
+
LEARN MORE
|
|
27
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
28
|
+
`.trim();
|
|
29
|
+
|
|
30
|
+
export const TRIGGER_DISPLAY = {
|
|
31
|
+
documentsPublished: "document.published",
|
|
32
|
+
documentsUnpublished: "document.unpublished",
|
|
33
|
+
releasesCreated: "release.created",
|
|
34
|
+
releasesUpdated: "release.updated",
|
|
35
|
+
tagsCreated: "tag.created",
|
|
36
|
+
tagsDeleted: "tag.deleted",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export async function webhookView(): Promise<void> {
|
|
40
|
+
const {
|
|
41
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
42
|
+
positionals: [webhookUrl],
|
|
43
|
+
} = parseArgs({
|
|
44
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "view"
|
|
45
|
+
options: {
|
|
46
|
+
repo: { type: "string", short: "r" },
|
|
47
|
+
help: { type: "boolean", short: "h" },
|
|
48
|
+
},
|
|
49
|
+
allowPositionals: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (help) {
|
|
53
|
+
console.info(HELP);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!webhookUrl) {
|
|
58
|
+
console.error("Missing required argument: <url>");
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!repo) {
|
|
64
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const authenticated = await isAuthenticated();
|
|
70
|
+
if (!authenticated) {
|
|
71
|
+
handleUnauthenticated();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const response = await getWebhooks(repo);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
78
|
+
handleUnauthenticated();
|
|
79
|
+
} else {
|
|
80
|
+
console.error(`Failed to view webhook: ${stringify(response.value)}`);
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const webhook = response.value.find((w) => w.config.url === webhookUrl);
|
|
87
|
+
if (!webhook) {
|
|
88
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const { config } = webhook;
|
|
94
|
+
|
|
95
|
+
console.info(`URL: ${config.url}`);
|
|
96
|
+
console.info(`Name: ${config.name || "(none)"}`);
|
|
97
|
+
console.info(`Status: ${config.active ? "enabled" : "disabled"}`);
|
|
98
|
+
console.info(`Secret: ${config.secret ? "(set)" : "(none)"}`);
|
|
99
|
+
|
|
100
|
+
// Show triggers
|
|
101
|
+
const enabledTriggers: string[] = [];
|
|
102
|
+
for (const [apiField, displayName] of Object.entries(TRIGGER_DISPLAY)) {
|
|
103
|
+
if (config[apiField as keyof typeof config]) {
|
|
104
|
+
enabledTriggers.push(displayName);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
console.info(`Triggers: ${enabledTriggers.length > 0 ? enabledTriggers.join(", ") : "(none)"}`);
|
|
108
|
+
|
|
109
|
+
// Show headers
|
|
110
|
+
const headerKeys = Object.keys(config.headers);
|
|
111
|
+
if (headerKeys.length > 0) {
|
|
112
|
+
console.info("Headers:");
|
|
113
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
114
|
+
console.info(` ${key}: ${value}`);
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
console.info("Headers: (none)");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function handleUnauthenticated() {
|
|
122
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const WebhookSchema = v.object({
|
|
127
|
+
config: v.object({
|
|
128
|
+
_id: v.string(),
|
|
129
|
+
url: v.string(),
|
|
130
|
+
active: v.boolean(),
|
|
131
|
+
name: v.nullable(v.string()),
|
|
132
|
+
secret: v.nullable(v.string()),
|
|
133
|
+
headers: v.record(v.string(), v.string()),
|
|
134
|
+
documentsPublished: v.boolean(),
|
|
135
|
+
documentsUnpublished: v.boolean(),
|
|
136
|
+
releasesCreated: v.boolean(),
|
|
137
|
+
releasesUpdated: v.boolean(),
|
|
138
|
+
tagsCreated: v.boolean(),
|
|
139
|
+
tagsDeleted: v.boolean(),
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
export type Webhook = v.InferOutput<typeof WebhookSchema>;
|
|
143
|
+
|
|
144
|
+
export async function getWebhooks(repo: string): Promise<ParsedRequestResponse<Webhook[]>> {
|
|
145
|
+
const url = new URL("/app/settings/webhooks", await getRepoUrl(repo));
|
|
146
|
+
return await request(url, { schema: v.array(WebhookSchema) });
|
|
147
|
+
}
|
package/src/webhook.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { webhookAddHeader } from "./webhook-add-header";
|
|
4
|
+
import { webhookCreate } from "./webhook-create";
|
|
5
|
+
import { webhookDisable } from "./webhook-disable";
|
|
6
|
+
import { webhookEnable } from "./webhook-enable";
|
|
7
|
+
import { webhookList } from "./webhook-list";
|
|
8
|
+
import { webhookRemove } from "./webhook-remove";
|
|
9
|
+
import { webhookRemoveHeader } from "./webhook-remove-header";
|
|
10
|
+
import { webhookSetTriggers } from "./webhook-set-triggers";
|
|
11
|
+
import { webhookStatus } from "./webhook-status";
|
|
12
|
+
import { webhookTest } from "./webhook-test";
|
|
13
|
+
import { webhookView } from "./webhook-view";
|
|
14
|
+
|
|
15
|
+
const HELP = `
|
|
16
|
+
Manage webhooks in a Prismic repository.
|
|
17
|
+
|
|
18
|
+
USAGE
|
|
19
|
+
prismic webhook <command> [flags]
|
|
20
|
+
|
|
21
|
+
COMMANDS
|
|
22
|
+
list List all webhooks
|
|
23
|
+
create Create a new webhook
|
|
24
|
+
view View webhook details
|
|
25
|
+
remove Delete a webhook
|
|
26
|
+
test Trigger a test webhook
|
|
27
|
+
enable Enable a webhook
|
|
28
|
+
disable Disable a webhook
|
|
29
|
+
status Show webhook enabled/disabled status
|
|
30
|
+
add-header Add a custom HTTP header
|
|
31
|
+
remove-header Remove a custom HTTP header
|
|
32
|
+
set-triggers Update webhook triggers
|
|
33
|
+
|
|
34
|
+
FLAGS
|
|
35
|
+
-h, --help Show help for command
|
|
36
|
+
|
|
37
|
+
LEARN MORE
|
|
38
|
+
Use \`prismic webhook <command> --help\` for more information about a command.
|
|
39
|
+
`.trim();
|
|
40
|
+
|
|
41
|
+
export async function webhook(): Promise<void> {
|
|
42
|
+
const {
|
|
43
|
+
positionals: [subcommand],
|
|
44
|
+
} = parseArgs({
|
|
45
|
+
args: process.argv.slice(3), // skip: node, script, "webhook"
|
|
46
|
+
options: {
|
|
47
|
+
help: { type: "boolean", short: "h" },
|
|
48
|
+
},
|
|
49
|
+
allowPositionals: true,
|
|
50
|
+
strict: false,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
switch (subcommand) {
|
|
54
|
+
case "list":
|
|
55
|
+
await webhookList();
|
|
56
|
+
break;
|
|
57
|
+
case "create":
|
|
58
|
+
await webhookCreate();
|
|
59
|
+
break;
|
|
60
|
+
case "view":
|
|
61
|
+
await webhookView();
|
|
62
|
+
break;
|
|
63
|
+
case "remove":
|
|
64
|
+
await webhookRemove();
|
|
65
|
+
break;
|
|
66
|
+
case "test":
|
|
67
|
+
await webhookTest();
|
|
68
|
+
break;
|
|
69
|
+
case "enable":
|
|
70
|
+
await webhookEnable();
|
|
71
|
+
break;
|
|
72
|
+
case "disable":
|
|
73
|
+
await webhookDisable();
|
|
74
|
+
break;
|
|
75
|
+
case "status":
|
|
76
|
+
await webhookStatus();
|
|
77
|
+
break;
|
|
78
|
+
case "add-header":
|
|
79
|
+
await webhookAddHeader();
|
|
80
|
+
break;
|
|
81
|
+
case "remove-header":
|
|
82
|
+
await webhookRemoveHeader();
|
|
83
|
+
break;
|
|
84
|
+
case "set-triggers":
|
|
85
|
+
await webhookSetTriggers();
|
|
86
|
+
break;
|
|
87
|
+
default: {
|
|
88
|
+
if (subcommand) {
|
|
89
|
+
console.error(`Unknown webhook subcommand: ${subcommand}\n`);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
console.info(HELP);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/whoami.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
import { isAuthenticated } from "./lib/auth";
|
|
5
|
+
import { ForbiddenRequestError, request } from "./lib/request";
|
|
6
|
+
import { getUserServiceUrl } from "./lib/url";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Show the currently logged in user.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic whoami [flags]
|
|
13
|
+
|
|
14
|
+
FLAGS
|
|
15
|
+
-h, --help Show help for command
|
|
16
|
+
|
|
17
|
+
LEARN MORE
|
|
18
|
+
Use \`prismic <command> --help\` for more information about a command.
|
|
19
|
+
`.trim();
|
|
20
|
+
|
|
21
|
+
export async function whoami(): Promise<void> {
|
|
22
|
+
const {
|
|
23
|
+
values: { help },
|
|
24
|
+
} = parseArgs({
|
|
25
|
+
args: process.argv.slice(3),
|
|
26
|
+
options: { help: { type: "boolean", short: "h" } },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (help) {
|
|
30
|
+
console.info(HELP);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const authenticated = await isAuthenticated();
|
|
35
|
+
if (!authenticated) {
|
|
36
|
+
handleUnauthenticated();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const response = await getProfile();
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
43
|
+
handleUnauthenticated();
|
|
44
|
+
} else {
|
|
45
|
+
console.error("Failed to fetch user profile.");
|
|
46
|
+
}
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.info(response.value.email);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function getProfile() {
|
|
55
|
+
const url = new URL("profile", await getUserServiceUrl());
|
|
56
|
+
return await request(url, { schema: v.object({ email: v.string() }) });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleUnauthenticated() {
|
|
60
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
}
|