prismic 0.0.0-canary.2cfb4a8
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-CSAFppyU.mjs +97 -0
- package/dist/framework-AxGiKSX9.mjs +17 -0
- package/dist/index.mjs +87 -0
- package/dist/nextjs-D4viImqE.mjs +312 -0
- package/dist/nuxt-CbBJIJw1.mjs +59 -0
- package/dist/sveltekit-BuNy6sKm.mjs +226 -0
- package/package.json +58 -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 +90 -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/login.ts +45 -0
- package/src/logout.ts +36 -0
- package/src/sync.ts +259 -0
- package/src/whoami.ts +62 -0
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
|
+
}
|