@anthusai/papyrus 2.0.0-next.106 → 2.0.0-next.107
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import { handleCliLoginDiscovery } from "../../../lib/cli-login-discovery";
|
|
3
|
+
|
|
4
|
+
export const dynamic = "force-dynamic";
|
|
5
|
+
export const runtime = "nodejs";
|
|
6
|
+
|
|
7
|
+
export function GET(request: NextRequest) {
|
|
8
|
+
return handleCliLoginDiscovery(request);
|
|
9
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
2
|
+
import { readAmplifyOutputsFile } from "./amplify-outputs-path";
|
|
3
|
+
import { SiteOriginNotConfiguredError, publicSiteOrigin, siteOriginNotConfiguredResponse } from "./site-origin";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The public values `papyrus login <site>` needs, served at `/.well-known/papyrus-cli.json`.
|
|
7
|
+
* Every value is public (Cognito pool/client ids, hosted-UI domain, API URL). Nothing here is a
|
|
8
|
+
* secret, and the file only exists for a site whose web client registers the CLI callback.
|
|
9
|
+
*/
|
|
10
|
+
export const CLI_LOGIN_PATH = "/.well-known/papyrus-cli.json";
|
|
11
|
+
|
|
12
|
+
export interface CliLoginDocument {
|
|
13
|
+
publication: string;
|
|
14
|
+
issuer: string;
|
|
15
|
+
client_id: string;
|
|
16
|
+
oauth_domain: string;
|
|
17
|
+
graphql_endpoint: string;
|
|
18
|
+
callback_uri: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AmplifyOutputsForCliLogin {
|
|
22
|
+
auth?: {
|
|
23
|
+
user_pool_id?: string;
|
|
24
|
+
user_pool_client_id?: string;
|
|
25
|
+
aws_region?: string;
|
|
26
|
+
oauth?: { domain?: string; redirect_sign_in_uri?: string[] };
|
|
27
|
+
};
|
|
28
|
+
data?: { url?: string };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The CLI signs in through the site's existing public web app client, which every app-shell site
|
|
33
|
+
* registers with this callback (infra/amplify-app-shell/lib/site-config.ts). No separate client exists.
|
|
34
|
+
*/
|
|
35
|
+
export const CLI_CALLBACK_URI = "http://localhost:3001/";
|
|
36
|
+
|
|
37
|
+
export function cliLoginDocumentFromOutputs(outputs: AmplifyOutputsForCliLogin | null, siteOrigin: string): CliLoginDocument | null {
|
|
38
|
+
const userPoolId = outputs?.auth?.user_pool_id;
|
|
39
|
+
const clientId = outputs?.auth?.user_pool_client_id;
|
|
40
|
+
const domain = outputs?.auth?.oauth?.domain;
|
|
41
|
+
const endpoint = outputs?.data?.url;
|
|
42
|
+
if (!userPoolId || !clientId || !domain || !endpoint || !endpoint.startsWith("https://")) return null;
|
|
43
|
+
// Only when the client really registers the callback; otherwise the sign-in could never complete.
|
|
44
|
+
if (!outputs?.auth?.oauth?.redirect_sign_in_uri?.includes(CLI_CALLBACK_URI)) return null;
|
|
45
|
+
const region = outputs?.auth?.aws_region ?? userPoolId.split("_")[0];
|
|
46
|
+
return {
|
|
47
|
+
publication: siteOrigin,
|
|
48
|
+
issuer: `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`,
|
|
49
|
+
client_id: clientId,
|
|
50
|
+
oauth_domain: `https://${domain}`,
|
|
51
|
+
graphql_endpoint: endpoint,
|
|
52
|
+
callback_uri: CLI_CALLBACK_URI,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface CliLoginDiscoveryOptions {
|
|
57
|
+
readOutputs?: () => AmplifyOutputsForCliLogin | null;
|
|
58
|
+
environment?: Record<string, string | undefined>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function handleCliLoginDiscovery(request: Pick<NextRequest, "nextUrl">, options: CliLoginDiscoveryOptions = {}): NextResponse {
|
|
62
|
+
let origin: string;
|
|
63
|
+
try {
|
|
64
|
+
origin = publicSiteOrigin(request, options.environment ?? process.env);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error instanceof SiteOriginNotConfiguredError) return siteOriginNotConfiguredResponse(error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
const outputs = (options.readOutputs ?? (() => readAmplifyOutputsFile() as AmplifyOutputsForCliLogin | null))();
|
|
70
|
+
const document = cliLoginDocumentFromOutputs(outputs, origin);
|
|
71
|
+
if (!document) {
|
|
72
|
+
return NextResponse.json(
|
|
73
|
+
{ error: "cli_login_not_configured", message: "This site does not register the CLI sign-in callback." },
|
|
74
|
+
{ status: 404, headers: { "cache-control": "public, max-age=60" } },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return NextResponse.json(document, { headers: { "cache-control": "public, max-age=300" } });
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -194,6 +194,7 @@
|
|
|
194
194
|
"./lib/category-dashboard": "./lib/category-dashboard.ts",
|
|
195
195
|
"./lib/category-repository": "./lib/category-repository.ts",
|
|
196
196
|
"./lib/chrome-text": "./lib/chrome-text.ts",
|
|
197
|
+
"./lib/cli-login-discovery": "./lib/cli-login-discovery.ts",
|
|
197
198
|
"./lib/console-chat-client": "./lib/console-chat-client.ts",
|
|
198
199
|
"./lib/console-web-context": "./lib/console-web-context.ts",
|
|
199
200
|
"./lib/content-actions-client": "./lib/content-actions-client.ts",
|
|
@@ -356,6 +357,7 @@
|
|
|
356
357
|
"./renderers/pretext/rhythm-blog-presentation": "./renderers/pretext/rhythm-blog-presentation.tsx",
|
|
357
358
|
"./renderers/pretext/rhythm-shell-style": "./renderers/pretext/rhythm-shell-style.ts",
|
|
358
359
|
"./app/%5F_preview/[[...path]]/route": "./app/%5F_preview/[[...path]]/route.ts",
|
|
360
|
+
"./app/.well-known/papyrus-cli.json/route": "./app/.well-known/papyrus-cli.json/route.ts",
|
|
359
361
|
"./app/[year]/[month]/[day]/[articleSlug]/page": "./app/[year]/[month]/[day]/[articleSlug]/page.tsx",
|
|
360
362
|
"./app/[year]/[month]/[day]/page": "./app/[year]/[month]/[day]/page.tsx",
|
|
361
363
|
"./app/[year]/[month]/[day]/page/[pageNumber]/page": "./app/[year]/[month]/[day]/page/[pageNumber]/page.tsx",
|
|
@@ -456,7 +458,7 @@
|
|
|
456
458
|
"optional": true
|
|
457
459
|
}
|
|
458
460
|
},
|
|
459
|
-
"version": "2.0.0-next.
|
|
461
|
+
"version": "2.0.0-next.107",
|
|
460
462
|
"dependencies": {
|
|
461
463
|
"@aws-amplify/adapter-nextjs": "^1.7.3",
|
|
462
464
|
"@aws-crypto/sha256-js": "5.2.0",
|
package/routes.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.0-next.
|
|
2
|
+
"version": "2.0.0-next.107",
|
|
3
3
|
"routes": [
|
|
4
4
|
{
|
|
5
5
|
"file": "app/%5F_preview/[[...path]]/route.ts",
|
|
@@ -11,6 +11,17 @@
|
|
|
11
11
|
"dynamic": "\"force-dynamic\""
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
"file": "app/.well-known/papyrus-cli.json/route.ts",
|
|
16
|
+
"hasDefault": false,
|
|
17
|
+
"exports": [
|
|
18
|
+
"GET"
|
|
19
|
+
],
|
|
20
|
+
"config": {
|
|
21
|
+
"dynamic": "\"force-dynamic\"",
|
|
22
|
+
"runtime": "\"nodejs\""
|
|
23
|
+
}
|
|
24
|
+
},
|
|
14
25
|
{
|
|
15
26
|
"file": "app/[year]/[month]/[day]/[articleSlug]/page.tsx",
|
|
16
27
|
"reader": true,
|
package/src/with-papyrus.mjs
CHANGED
|
@@ -50,7 +50,7 @@ export function staticGenerationSettings() {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export const DEFAULT_TRANSPILE_PACKAGES = ["@anthusai/papyrus", "cyclotron", "chatticus"];
|
|
53
|
+
export const DEFAULT_TRANSPILE_PACKAGES = ["@anthusai/papyrus", "cyclotron", "chatticus", "lucide-react"];
|
|
54
54
|
|
|
55
55
|
export function mergeTranspilePackages(existing = []) {
|
|
56
56
|
return [...new Set([...existing, ...DEFAULT_TRANSPILE_PACKAGES])];
|