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,152 @@
|
|
|
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 { TRIGGER_DISPLAY, type Webhook } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Create a new 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 create <url> [flags]
|
|
18
|
+
|
|
19
|
+
ARGUMENTS
|
|
20
|
+
<url> Webhook URL to receive events
|
|
21
|
+
|
|
22
|
+
FLAGS
|
|
23
|
+
-n, --name string Webhook name
|
|
24
|
+
-s, --secret string Secret for webhook signature
|
|
25
|
+
-t, --trigger string Trigger events (can be repeated)
|
|
26
|
+
-r, --repo string Repository domain
|
|
27
|
+
-h, --help Show help for command
|
|
28
|
+
|
|
29
|
+
TRIGGERS
|
|
30
|
+
document.published When documents are published
|
|
31
|
+
document.unpublished When documents are unpublished
|
|
32
|
+
release.created When a release is created
|
|
33
|
+
release.updated When a release is edited or deleted
|
|
34
|
+
tag.created When a tag is created
|
|
35
|
+
tag.deleted When a tag is deleted
|
|
36
|
+
|
|
37
|
+
If no triggers specified, all are enabled.
|
|
38
|
+
|
|
39
|
+
LEARN MORE
|
|
40
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
41
|
+
`.trim();
|
|
42
|
+
|
|
43
|
+
const VALID_TRIGGERS = Object.values(TRIGGER_DISPLAY);
|
|
44
|
+
|
|
45
|
+
export async function webhookCreate(): Promise<void> {
|
|
46
|
+
const {
|
|
47
|
+
values: { help, repo = await safeGetRepositoryFromConfig(), name, secret, trigger = [] },
|
|
48
|
+
positionals: [webhookUrl],
|
|
49
|
+
} = parseArgs({
|
|
50
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "create"
|
|
51
|
+
options: {
|
|
52
|
+
name: { type: "string", short: "n" },
|
|
53
|
+
secret: { type: "string", short: "s" },
|
|
54
|
+
trigger: { type: "string", multiple: true, short: "t" },
|
|
55
|
+
repo: { type: "string", short: "r" },
|
|
56
|
+
help: { type: "boolean", short: "h" },
|
|
57
|
+
},
|
|
58
|
+
allowPositionals: true,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (help) {
|
|
62
|
+
console.info(HELP);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!webhookUrl) {
|
|
67
|
+
console.error("Missing required argument: <url>");
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!repo) {
|
|
73
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
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
|
+
// Build trigger settings
|
|
95
|
+
const defaultValue = trigger.length > 0 ? false : true;
|
|
96
|
+
const triggers: Record<keyof typeof TRIGGER_DISPLAY, boolean> = {
|
|
97
|
+
documentsPublished: defaultValue,
|
|
98
|
+
documentsUnpublished: defaultValue,
|
|
99
|
+
releasesCreated: defaultValue,
|
|
100
|
+
releasesUpdated: defaultValue,
|
|
101
|
+
tagsCreated: defaultValue,
|
|
102
|
+
tagsDeleted: defaultValue,
|
|
103
|
+
};
|
|
104
|
+
for (const t of trigger) {
|
|
105
|
+
const [apiField] = Object.entries(TRIGGER_DISPLAY).find(([, display]) => t === display) ?? [];
|
|
106
|
+
if (!apiField) continue;
|
|
107
|
+
triggers[apiField as keyof typeof TRIGGER_DISPLAY] = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const response = await createWebhook(repo, {
|
|
111
|
+
url: webhookUrl,
|
|
112
|
+
name: name ?? null,
|
|
113
|
+
secret: secret ?? null,
|
|
114
|
+
...triggers,
|
|
115
|
+
});
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
118
|
+
handleUnauthenticated();
|
|
119
|
+
} else {
|
|
120
|
+
console.error(`Failed to create webhook: ${stringify(response.value)}`);
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.info(`Webhook created: ${webhookUrl}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function createWebhook(
|
|
130
|
+
repo: string,
|
|
131
|
+
config: Omit<Webhook["config"], "_id" | "active" | "headers">,
|
|
132
|
+
) {
|
|
133
|
+
const url = new URL("/app/settings/webhooks/create", await getRepoUrl(repo));
|
|
134
|
+
const body = new FormData();
|
|
135
|
+
body.set("url", config.url);
|
|
136
|
+
body.set("name", config.name ?? "");
|
|
137
|
+
body.set("secret", config.secret ?? "");
|
|
138
|
+
body.set("headers", JSON.stringify({}));
|
|
139
|
+
body.set("active", "on");
|
|
140
|
+
body.set("documentsPublished", config.documentsUnpublished.toString());
|
|
141
|
+
body.set("documentsUnpublished", config.documentsUnpublished.toString());
|
|
142
|
+
body.set("releasesCreated", config.documentsUnpublished.toString());
|
|
143
|
+
body.set("releasesUpdated", config.documentsUnpublished.toString());
|
|
144
|
+
body.set("tagsCreated", config.documentsUnpublished.toString());
|
|
145
|
+
body.set("documentsPublished", config.documentsUnpublished.toString());
|
|
146
|
+
return await request(url, { method: "POST", body });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handleUnauthenticated() {
|
|
150
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
151
|
+
process.exitCode = 1;
|
|
152
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Disable 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 disable <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 webhookDisable(): 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", "disable"
|
|
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 disable 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
|
+
if (!webhook.config.active) {
|
|
85
|
+
console.info(`Webhook already disabled: ${webhookUrl}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const updatedConfig = structuredClone(webhook.config);
|
|
90
|
+
updatedConfig.active = false;
|
|
91
|
+
|
|
92
|
+
const response = await updateWebhook(repo, webhook.config._id, updatedConfig);
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
95
|
+
handleUnauthenticated();
|
|
96
|
+
} else {
|
|
97
|
+
console.error(`Failed to disable webhook: ${stringify(response.value)}`);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.info(`Webhook disabled: ${webhookUrl}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function handleUnauthenticated() {
|
|
107
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import type { RequestResponse } from "./lib/request";
|
|
4
|
+
|
|
5
|
+
import { isAuthenticated } from "./lib/auth";
|
|
6
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
7
|
+
import { stringify } from "./lib/json";
|
|
8
|
+
import { ForbiddenRequestError, request } from "./lib/request";
|
|
9
|
+
import { getRepoUrl } from "./lib/url";
|
|
10
|
+
import { getWebhooks, type Webhook } from "./webhook-view";
|
|
11
|
+
|
|
12
|
+
const HELP = `
|
|
13
|
+
Enable a webhook in a Prismic repository.
|
|
14
|
+
|
|
15
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
16
|
+
project root.
|
|
17
|
+
|
|
18
|
+
USAGE
|
|
19
|
+
prismic webhook enable <url> [flags]
|
|
20
|
+
|
|
21
|
+
ARGUMENTS
|
|
22
|
+
<url> Webhook URL
|
|
23
|
+
|
|
24
|
+
FLAGS
|
|
25
|
+
-r, --repo string Repository domain
|
|
26
|
+
-h, --help Show help for command
|
|
27
|
+
|
|
28
|
+
LEARN MORE
|
|
29
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
30
|
+
`.trim();
|
|
31
|
+
|
|
32
|
+
export async function webhookEnable(): Promise<void> {
|
|
33
|
+
const {
|
|
34
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
35
|
+
positionals: [webhookUrl],
|
|
36
|
+
} = parseArgs({
|
|
37
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "enable"
|
|
38
|
+
options: {
|
|
39
|
+
repo: { type: "string", short: "r" },
|
|
40
|
+
help: { type: "boolean", short: "h" },
|
|
41
|
+
},
|
|
42
|
+
allowPositionals: true,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (help) {
|
|
46
|
+
console.info(HELP);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!webhookUrl) {
|
|
51
|
+
console.error("Missing required argument: <url>");
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!repo) {
|
|
57
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const authenticated = await isAuthenticated();
|
|
63
|
+
if (!authenticated) {
|
|
64
|
+
handleUnauthenticated();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const webhooksResponse = await getWebhooks(repo);
|
|
69
|
+
if (!webhooksResponse.ok) {
|
|
70
|
+
if (webhooksResponse.error instanceof ForbiddenRequestError) {
|
|
71
|
+
handleUnauthenticated();
|
|
72
|
+
} else {
|
|
73
|
+
console.error(`Failed to enable webhook: ${stringify(webhooksResponse.value)}`);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const webhook = webhooksResponse.value.find((w) => w.config.url === webhookUrl);
|
|
80
|
+
if (!webhook) {
|
|
81
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (webhook.config.active) {
|
|
87
|
+
console.info(`Webhook already enabled: ${webhookUrl}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const updatedConfig = structuredClone(webhook.config);
|
|
92
|
+
updatedConfig.active = true;
|
|
93
|
+
|
|
94
|
+
const response = await updateWebhook(repo, webhook.config._id, updatedConfig);
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
97
|
+
handleUnauthenticated();
|
|
98
|
+
} else {
|
|
99
|
+
console.error(`Failed to enable webhook: ${stringify(response.value)}`);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.info(`Webhook enabled: ${webhookUrl}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function updateWebhook(
|
|
109
|
+
repo: string,
|
|
110
|
+
webhookId: string,
|
|
111
|
+
config: Omit<Webhook["config"], "_id">,
|
|
112
|
+
): Promise<RequestResponse<unknown>> {
|
|
113
|
+
const url = new URL(`/app/settings/webhooks/${webhookId}`, await getRepoUrl(repo));
|
|
114
|
+
const body = new FormData();
|
|
115
|
+
body.set("url", config.url);
|
|
116
|
+
body.set("name", config.name ?? "");
|
|
117
|
+
body.set("secret", config.secret ?? "");
|
|
118
|
+
body.set("headers", JSON.stringify(config.headers ?? {}));
|
|
119
|
+
body.set("active", config.active ? "on" : "off");
|
|
120
|
+
body.set("documentsPublished", config.documentsUnpublished.toString());
|
|
121
|
+
body.set("documentsUnpublished", config.documentsUnpublished.toString());
|
|
122
|
+
body.set("releasesCreated", config.documentsUnpublished.toString());
|
|
123
|
+
body.set("releasesUpdated", config.documentsUnpublished.toString());
|
|
124
|
+
body.set("tagsCreated", config.documentsUnpublished.toString());
|
|
125
|
+
body.set("documentsPublished", config.documentsUnpublished.toString());
|
|
126
|
+
return await request(url, { method: "POST", body });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function handleUnauthenticated() {
|
|
130
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 } from "./lib/request";
|
|
8
|
+
import { getWebhooks } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
List all webhooks 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 list [flags]
|
|
18
|
+
|
|
19
|
+
FLAGS
|
|
20
|
+
--json Output as JSON
|
|
21
|
+
-r, --repo string Repository domain
|
|
22
|
+
-h, --help Show help for command
|
|
23
|
+
|
|
24
|
+
LEARN MORE
|
|
25
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
export async function webhookList(): Promise<void> {
|
|
29
|
+
const {
|
|
30
|
+
values: { help, repo = await safeGetRepositoryFromConfig(), json },
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "list"
|
|
33
|
+
options: {
|
|
34
|
+
json: { type: "boolean" },
|
|
35
|
+
repo: { type: "string", short: "r" },
|
|
36
|
+
help: { type: "boolean", short: "h" },
|
|
37
|
+
},
|
|
38
|
+
allowPositionals: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (help) {
|
|
42
|
+
console.info(HELP);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!repo) {
|
|
47
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const authenticated = await isAuthenticated();
|
|
53
|
+
if (!authenticated) {
|
|
54
|
+
handleUnauthenticated();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const response = await getWebhooks(repo);
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
61
|
+
handleUnauthenticated();
|
|
62
|
+
} else if (v.isValiError(response.error)) {
|
|
63
|
+
console.error(
|
|
64
|
+
`Failed to list webhooks: Invalid response: ${stringify(response.error.issues)}`,
|
|
65
|
+
);
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
} else {
|
|
68
|
+
console.error(`Failed to list webhooks: ${stringify(response.value)}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const webhooks = response.value;
|
|
75
|
+
if (json) {
|
|
76
|
+
console.info(stringify(webhooks.map((w) => w.config)));
|
|
77
|
+
} else {
|
|
78
|
+
if (webhooks.length === 0) {
|
|
79
|
+
console.info("No webhooks configured.");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const webhook of webhooks) {
|
|
83
|
+
const status = webhook.config.active ? "enabled" : "disabled";
|
|
84
|
+
const name = webhook.config.name ? ` (${webhook.config.name})` : "";
|
|
85
|
+
console.info(`${webhook.config.url}${name} [${status}]`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function handleUnauthenticated() {
|
|
91
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 } from "./webhook-view";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Remove a custom HTTP header from 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 remove-header <url> <key> [flags]
|
|
18
|
+
|
|
19
|
+
ARGUMENTS
|
|
20
|
+
<url> Webhook URL
|
|
21
|
+
<key> Header name
|
|
22
|
+
|
|
23
|
+
FLAGS
|
|
24
|
+
-r, --repo string Repository domain
|
|
25
|
+
-h, --help Show help for command
|
|
26
|
+
|
|
27
|
+
LEARN MORE
|
|
28
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
29
|
+
`.trim();
|
|
30
|
+
|
|
31
|
+
export async function webhookRemoveHeader(): Promise<void> {
|
|
32
|
+
const {
|
|
33
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
34
|
+
positionals: [webhookUrl, headerKey],
|
|
35
|
+
} = parseArgs({
|
|
36
|
+
args: process.argv.slice(4), // skip: node, script, "webhook", "remove-header"
|
|
37
|
+
options: {
|
|
38
|
+
repo: { type: "string", short: "r" },
|
|
39
|
+
help: { type: "boolean", short: "h" },
|
|
40
|
+
},
|
|
41
|
+
allowPositionals: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (help) {
|
|
45
|
+
console.info(HELP);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!webhookUrl) {
|
|
50
|
+
console.error("Missing required argument: <url>");
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!headerKey) {
|
|
56
|
+
console.error("Missing required argument: <key>");
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!repo) {
|
|
62
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const authenticated = await isAuthenticated();
|
|
68
|
+
if (!authenticated) {
|
|
69
|
+
handleUnauthenticated();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const webhooksResponse = await getWebhooks(repo);
|
|
74
|
+
if (!webhooksResponse.ok) {
|
|
75
|
+
if (webhooksResponse.error instanceof ForbiddenRequestError) {
|
|
76
|
+
handleUnauthenticated();
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`Failed to remove header: ${stringify(webhooksResponse.value)}`);
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const webhook = webhooksResponse.value.find((w) => w.config.url === webhookUrl);
|
|
85
|
+
if (!webhook) {
|
|
86
|
+
console.error(`Webhook not found: ${webhookUrl}`);
|
|
87
|
+
process.exitCode = 1;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!(headerKey in webhook.config.headers)) {
|
|
92
|
+
console.error(`Header not found: ${headerKey}`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const updatedConfig = structuredClone(webhook.config);
|
|
98
|
+
delete updatedConfig.headers[headerKey];
|
|
99
|
+
|
|
100
|
+
const response = await updateWebhook(repo, webhook.config._id, updatedConfig);
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
103
|
+
handleUnauthenticated();
|
|
104
|
+
} else {
|
|
105
|
+
console.error(`Failed to remove header: ${stringify(response.value)}`);
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.info(`Header removed: ${headerKey}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleUnauthenticated() {
|
|
115
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
}
|
|
@@ -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
|
+
Delete a webhook from 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 remove <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 webhookRemove(): 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", "remove"
|
|
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 remove 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 deleteWebhook(repo, webhook.config._id);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
87
|
+
handleUnauthenticated();
|
|
88
|
+
} else {
|
|
89
|
+
console.error(`Failed to remove webhook: ${stringify(response.value)}`);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.info(`Webhook removed: ${webhookUrl}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function deleteWebhook(repo: string, webhookId: string) {
|
|
99
|
+
const url = new URL(`/app/settings/webhooks/${webhookId}/delete`, 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
|
+
}
|