create-ailk 0.35.1 → 0.37.0
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/README.md +1 -1
- package/component-catalog.json +51 -1
- package/component-catalog.md +8 -5
- package/dist/lib/env-catalog.js +8 -0
- package/dist/surfaces.js +66 -22
- package/dist/topology.d.ts +4 -4
- package/dist/topology.js +104 -60
- package/dist/update.d.ts +19 -1
- package/dist/update.js +293 -35
- package/package.json +3 -3
- package/templates/.env.example +38 -0
- package/templates/apps/api/.env.example +45 -0
- package/templates/apps/api/CLAUDE.md +12 -4
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/.env.example +16 -0
- package/templates/apps/web/CLAUDE.md +73 -5
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +241 -66
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +377 -151
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +20 -4
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +323 -73
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +97 -53
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +9 -6
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +21 -22
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
- package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +24 -75
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
- package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
- package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
- package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +738 -7
- package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
- package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
- package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
- package/templates/apps/web/auth.ts +133 -6
- package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
- package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
- package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
- package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
- package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
- package/templates/apps/web/lib/account-config.ts +132 -8
- package/templates/apps/web/lib/auth-email.ts +62 -6
- package/templates/apps/web/lib/auth-env.ts +13 -0
- package/templates/apps/web/lib/auth-routes.ts +11 -6
- package/templates/apps/web/lib/auth-sms.ts +180 -0
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
- package/templates/apps/web/lib/hub-session/config.ts +7 -1
- package/templates/apps/web/lib/hub-session/entry.ts +238 -0
- package/templates/apps/web/lib/hub-session/index.ts +1 -4
- package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
- package/templates/apps/web/lib/hub-session/session.ts +120 -2
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
- package/templates/apps/web/lib/offerings-pricing.ts +4 -1
- package/templates/apps/web/lib/site-header.ts +14 -1
- package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
- package/templates/apps/web/lib/topology.generated.ts +39 -0
- package/templates/apps/web/messages/en.json +264 -96
- package/templates/apps/web/middleware.ts +34 -2
- package/templates/apps/web/security-headers.config.ts +21 -0
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
- package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
- package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
- package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
- package/templates/apps/web/components/signed-in-nav.tsx +0 -79
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phone plugin's outbound text (#11106, spec
|
|
3
|
+
* docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
|
|
4
|
+
*
|
|
5
|
+
* Better Auth's phone plugin generates a verification code and calls
|
|
6
|
+
* `sendOTP`. `apps/web` sends no text itself: like `lib/auth-email.ts`, this
|
|
7
|
+
* file serializes one body, signs it, and POSTs it to `apps/api`'s
|
|
8
|
+
* `/v1/auth/transactional-sms`, which sends one fixed text. The signed bytes
|
|
9
|
+
* and the sent bytes are one string (`buildAuthSmsRequest`).
|
|
10
|
+
*
|
|
11
|
+
* The base string is domain-separated (`transactional-sms.<ts>.<rawBody>`),
|
|
12
|
+
* so a body signed here never verifies at the email relay or the confirm hop,
|
|
13
|
+
* nor the reverse. The secret is the email relay's.
|
|
14
|
+
*
|
|
15
|
+
* The transport is a bare `fetch` to the API origin `@working-theory/api-client`
|
|
16
|
+
* resolves (`getApiBase()`), the `app/openapi.json/route.ts` precedent: the
|
|
17
|
+
* client package carries no SMS namespace, and this unit adds none.
|
|
18
|
+
*
|
|
19
|
+
* PII BOUNDARY: a log line carries `userId`, `kind` and `reason` — never the
|
|
20
|
+
* number and never the code. NOTHING HERE THROWS: a failed send is a log line,
|
|
21
|
+
* and the person asks for another code.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { createHmac } from "node:crypto";
|
|
25
|
+
|
|
26
|
+
import { getApiBase } from "@working-theory/api-client";
|
|
27
|
+
|
|
28
|
+
/** The relay's base-string domain (`packages/api/src/routes/auth/transactional-sms.ts`). */
|
|
29
|
+
export const SMS_SIGNATURE_DOMAIN = "transactional-sms.";
|
|
30
|
+
|
|
31
|
+
/** Bounds the call so a hung apps/api cannot pin an apps/web worker. */
|
|
32
|
+
const SEND_TIMEOUT_MS = 10_000;
|
|
33
|
+
|
|
34
|
+
/** E.164: a plus, a non-zero first digit, eight to fifteen digits in all. */
|
|
35
|
+
export const E164_PATTERN = /^\+[1-9]\d{7,14}$/;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `AILK_SMS_COUNTRY_CODES`: the calling codes a code may be texted to,
|
|
39
|
+
* comma-separated, default `1`. The relay re-checks the same list.
|
|
40
|
+
*/
|
|
41
|
+
export function smsCountryCodes(raw = process.env.AILK_SMS_COUNTRY_CODES): string[] {
|
|
42
|
+
const codes = (raw ?? "")
|
|
43
|
+
.split(",")
|
|
44
|
+
.map((code) => code.trim().replace(/^\+/, ""))
|
|
45
|
+
.filter((code) => /^[1-9]\d{0,2}$/.test(code));
|
|
46
|
+
return codes.length > 0 ? codes : ["1"];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The plugin's `phoneNumberValidator` (SEC-11106-2): E.164 only, and only a
|
|
51
|
+
* calling code on the list, so a premium-rate destination elsewhere is
|
|
52
|
+
* refused before any code is generated or sent. Calling codes are
|
|
53
|
+
* prefix-free, so a prefix match names one country code.
|
|
54
|
+
*/
|
|
55
|
+
export function isAllowedPhoneNumber(phone: string): boolean {
|
|
56
|
+
if (!E164_PATTERN.test(phone)) return false;
|
|
57
|
+
return smsCountryCodes().some((code) => phone.startsWith(`+${code}`));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface AuthSmsPayload {
|
|
61
|
+
kind: "phone-verification";
|
|
62
|
+
userId: string;
|
|
63
|
+
to: string;
|
|
64
|
+
code: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface AuthSmsRequest {
|
|
68
|
+
rawBody: string;
|
|
69
|
+
headers: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Sign one body; its `ts` is the signed timestamp, so neither moves alone. */
|
|
73
|
+
export function buildAuthSmsRequest(
|
|
74
|
+
payload: AuthSmsPayload,
|
|
75
|
+
secret: string,
|
|
76
|
+
nowSeconds = Math.floor(Date.now() / 1000),
|
|
77
|
+
): AuthSmsRequest {
|
|
78
|
+
const rawBody = JSON.stringify({
|
|
79
|
+
kind: payload.kind,
|
|
80
|
+
userId: payload.userId,
|
|
81
|
+
to: payload.to,
|
|
82
|
+
code: payload.code,
|
|
83
|
+
ts: nowSeconds,
|
|
84
|
+
});
|
|
85
|
+
const timestamp = String(nowSeconds);
|
|
86
|
+
const signature = `sha256=${createHmac("sha256", secret)
|
|
87
|
+
.update(`${SMS_SIGNATURE_DOMAIN}${timestamp}.${rawBody}`, "utf8")
|
|
88
|
+
.digest("hex")}`;
|
|
89
|
+
return {
|
|
90
|
+
rawBody,
|
|
91
|
+
headers: {
|
|
92
|
+
"x-ailk-auth-sms-signature": signature,
|
|
93
|
+
"x-ailk-auth-sms-timestamp": timestamp,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The transport seam; resolves the relay's HTTP status, 0 for no answer. */
|
|
99
|
+
export type AuthSmsTransport = (
|
|
100
|
+
rawBody: string,
|
|
101
|
+
headers: Record<string, string>,
|
|
102
|
+
) => Promise<{ status: number }>;
|
|
103
|
+
|
|
104
|
+
export interface AuthSmsLog {
|
|
105
|
+
warn: (fields: Record<string, unknown>) => void;
|
|
106
|
+
info: (fields: Record<string, unknown>) => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const defaultLog: AuthSmsLog = {
|
|
110
|
+
warn: (fields) => console.warn(`[auth-sms] ${JSON.stringify(fields)}`),
|
|
111
|
+
info: (fields) => console.info(`[auth-sms] ${JSON.stringify(fields)}`),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** The production transport: one POST of the exact signed bytes. */
|
|
115
|
+
export const authSmsTransport: AuthSmsTransport = async (rawBody, headers) => {
|
|
116
|
+
try {
|
|
117
|
+
const res = await fetch(`${getApiBase()}/v1/auth/transactional-sms`, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
120
|
+
body: rawBody,
|
|
121
|
+
signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
|
|
122
|
+
});
|
|
123
|
+
await res.body?.cancel().catch(() => undefined);
|
|
124
|
+
return { status: res.status };
|
|
125
|
+
} catch {
|
|
126
|
+
return { status: 0 };
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export interface SendPhoneOtpDeps {
|
|
131
|
+
send?: AuthSmsTransport;
|
|
132
|
+
log?: AuthSmsLog;
|
|
133
|
+
/** The signed-in person the code is for — the plugin's verify step binds it. */
|
|
134
|
+
sessionUserId: (ctx: unknown) => Promise<string | null>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The plugin's `sendOTP`. The phone before-hook in `auth.ts` has already
|
|
139
|
+
* refused a caller without a verified-email session, so a missing session
|
|
140
|
+
* here is logged and sends nothing.
|
|
141
|
+
*/
|
|
142
|
+
export function makeSendPhoneOtp(deps: SendPhoneOtpDeps) {
|
|
143
|
+
const send = deps.send ?? authSmsTransport;
|
|
144
|
+
const log = deps.log ?? defaultLog;
|
|
145
|
+
return async (
|
|
146
|
+
{ phoneNumber, code }: { phoneNumber: string; code: string },
|
|
147
|
+
ctx?: unknown,
|
|
148
|
+
): Promise<void> => {
|
|
149
|
+
const base = { kind: "phone-verification" };
|
|
150
|
+
const secret = process.env.AUTH_EMAIL_WEBHOOK_SECRET;
|
|
151
|
+
if (!secret) {
|
|
152
|
+
log.warn({ ...base, reason: "not_configured" });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
let userId: string | null;
|
|
156
|
+
try {
|
|
157
|
+
userId = await deps.sessionUserId(ctx);
|
|
158
|
+
} catch {
|
|
159
|
+
userId = null;
|
|
160
|
+
}
|
|
161
|
+
if (userId === null) {
|
|
162
|
+
log.warn({ ...base, reason: "no_session" });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
let request: AuthSmsRequest;
|
|
166
|
+
try {
|
|
167
|
+
request = buildAuthSmsRequest({ kind: "phone-verification", userId, to: phoneNumber, code }, secret);
|
|
168
|
+
} catch {
|
|
169
|
+
log.warn({ ...base, userId, reason: "send_failed", errorKind: "signing_failed" });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const { status } = await send(request.rawBody, request.headers);
|
|
173
|
+
if (status >= 200 && status < 300) {
|
|
174
|
+
log.info({ ...base, userId, reason: "sent" });
|
|
175
|
+
} else {
|
|
176
|
+
// The status only — the relay's body is never read.
|
|
177
|
+
log.warn({ ...base, userId, reason: "send_failed", status });
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -158,9 +158,21 @@ describe("hubSessionConfig", () => {
|
|
|
158
158
|
siteOrigin: "http://127.0.0.1:3100",
|
|
159
159
|
redirectUri: "http://127.0.0.1:3100/api/hub-session/callback",
|
|
160
160
|
secure: false,
|
|
161
|
+
oneTap: false,
|
|
161
162
|
});
|
|
162
163
|
});
|
|
163
164
|
|
|
165
|
+
// #11096 D10 — One Tap is on only for exactly `on`.
|
|
166
|
+
it.each([
|
|
167
|
+
["on", true],
|
|
168
|
+
["ON", false],
|
|
169
|
+
["1", false],
|
|
170
|
+
["", false],
|
|
171
|
+
])("AILK_HUB_ONE_TAP=%p reads oneTap %p", (value, expected) => {
|
|
172
|
+
configure({ AILK_HUB_ONE_TAP: value });
|
|
173
|
+
expect(hubSessionConfig()?.oneTap).toBe(expected);
|
|
174
|
+
});
|
|
175
|
+
|
|
164
176
|
it("is secure on an https site", () => {
|
|
165
177
|
configure({ NEXT_PUBLIC_BASE_URL: "https://spoke.example.com/" });
|
|
166
178
|
expect(hubSessionConfig()).toMatchObject({
|
|
@@ -403,3 +415,19 @@ describe("#8232 AC-5 — resealHubSession", () => {
|
|
|
403
415
|
await expect(resealHubSession()).resolves.toBe("failed");
|
|
404
416
|
});
|
|
405
417
|
});
|
|
418
|
+
|
|
419
|
+
describe("readBodyText (#11096) — the spoke's body read caps BYTES, not characters", () => {
|
|
420
|
+
const post = (body: string): Request =>
|
|
421
|
+
new Request("https://spoke.example/api/hub-session/email", { method: "POST", body });
|
|
422
|
+
|
|
423
|
+
it("reads a body within 8 KB", async () => {
|
|
424
|
+
const { readBodyText } = await import("../entry");
|
|
425
|
+
await expect(readBodyText(post("a".repeat(8_192)))).resolves.toBe("a".repeat(8_192));
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("refuses a body under 8 K characters but over 8 KB of UTF-8", async () => {
|
|
429
|
+
const { readBodyText } = await import("../entry");
|
|
430
|
+
// 3 000 three-byte characters: 3 000 characters, 9 000 bytes.
|
|
431
|
+
await expect(readBodyText(post("€".repeat(3_000)))).resolves.toBeNull();
|
|
432
|
+
});
|
|
433
|
+
});
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spoke's own signed-out account page (#11096 D1, D3, D9, D10; spec
|
|
3
|
+
* docs/specs/11096-the-spoke-hosts-the-sign-spec.md AC-1, AC-4, AC-5, AC-6).
|
|
4
|
+
*
|
|
5
|
+
* `SpokeSignIn` is a server component the generated gate seam renders for
|
|
6
|
+
* every signed-out `(authed)` path on a spoke that signs in through its hub.
|
|
7
|
+
* It reads its state from the middleware's `x-search` and the hub web's
|
|
8
|
+
* sign-up facts (`GET /api/auth/hub/sign-up`, the mocked `fetch`); the hub
|
|
9
|
+
* API's client info (One Tap's client id) comes through the api-client.
|
|
10
|
+
* `OneTap` is the one client island; its own cases are at the end.
|
|
11
|
+
*/
|
|
12
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
13
|
+
|
|
14
|
+
jest.mock("next-intl/server", () => {
|
|
15
|
+
const msgs: unknown = require("../../../messages/en.json");
|
|
16
|
+
const dig = (obj: unknown, path: string): unknown =>
|
|
17
|
+
path.split(".").reduce<unknown>(
|
|
18
|
+
(acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
|
|
19
|
+
obj,
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
__esModule: true,
|
|
23
|
+
getTranslations: async (arg: string | { namespace?: string }) => {
|
|
24
|
+
const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
|
|
25
|
+
const messages = dig(msgs, ns);
|
|
26
|
+
return (key: string, values?: Record<string, unknown>): string => {
|
|
27
|
+
const value = dig(messages, key);
|
|
28
|
+
if (typeof value !== "string") return `${ns}.${key}`;
|
|
29
|
+
return value.replace(/\{(\w+)\}/g, (m, name: string) =>
|
|
30
|
+
values && name in values ? String(values[name]) : m,
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const mockClientInfo = jest.fn();
|
|
38
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
39
|
+
__esModule: true,
|
|
40
|
+
hubSignIn: { clientInfo: (...args: unknown[]) => mockClientInfo(...args) },
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
import { resetHubEntryReads } from "../entry";
|
|
44
|
+
import { loadGoogle, OneTap, oneTapNavigation } from "../one-tap";
|
|
45
|
+
import { SpokeSignIn } from "../spoke-sign-in";
|
|
46
|
+
|
|
47
|
+
const HUB = "https://hub.example";
|
|
48
|
+
const SITE = "https://spoke.example";
|
|
49
|
+
const ENV = process.env;
|
|
50
|
+
|
|
51
|
+
const AGREEMENT = {
|
|
52
|
+
purposeId: "account_terms",
|
|
53
|
+
statement: "I accept the [Terms](terms) and the [Privacy Policy](privacy).",
|
|
54
|
+
policies: { terms: `${HUB}/terms`, privacy: `${HUB}/privacy` },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const mockFetch = jest.fn();
|
|
58
|
+
const realFetch = global.fetch;
|
|
59
|
+
|
|
60
|
+
/** A `fetch` answer (jsdom has no `Response`): the two members the code reads. */
|
|
61
|
+
function signUpAnswer(body: unknown, status = 200): { ok: boolean; status: number; json: () => Promise<unknown> } {
|
|
62
|
+
return { ok: status >= 200 && status < 300, status, json: async () => body };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function renderGate(search = "", pathname = "/account"): Promise<void> {
|
|
66
|
+
const headers = new Headers({ "x-pathname": pathname, "x-search": search });
|
|
67
|
+
render(await SpokeSignIn({ locale: "en", requestHeaders: headers }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
process.env = {
|
|
72
|
+
...ENV,
|
|
73
|
+
AILK_HUB_SIGN_IN_URL: HUB,
|
|
74
|
+
AILK_HUB_CLIENT_ID: "spoke_0001",
|
|
75
|
+
AILK_HUB_CLIENT_SECRET: `ailk_hcs_${"c".repeat(43)}`,
|
|
76
|
+
AILK_HUB_SESSION_SECRET: "s".repeat(43),
|
|
77
|
+
NEXT_PUBLIC_BASE_URL: SITE,
|
|
78
|
+
};
|
|
79
|
+
resetHubEntryReads();
|
|
80
|
+
mockFetch.mockReset().mockResolvedValue(
|
|
81
|
+
signUpAnswer({ signUpOpen: true, google: true, agreements: [AGREEMENT] }),
|
|
82
|
+
);
|
|
83
|
+
// eslint-disable-next-line no-restricted-syntax -- a jest.fn stands in for the global fetch, the hub web's HTTP boundary; its call signature is not fetch's own.
|
|
84
|
+
global.fetch = mockFetch as unknown as typeof fetch;
|
|
85
|
+
mockClientInfo.mockReset().mockResolvedValue({
|
|
86
|
+
ok: true,
|
|
87
|
+
body: { clientId: "spoke_0001", name: "Spoke", origin: SITE, oneTapClientId: "g-client.apps" },
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterEach(() => {
|
|
92
|
+
process.env = ENV;
|
|
93
|
+
global.fetch = realFetch;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("AC-1 — the spoke's own form", () => {
|
|
97
|
+
it("renders email, one agreement and Google, and no link to the hub's sign-in", async () => {
|
|
98
|
+
await renderGate();
|
|
99
|
+
expect(screen.getByTestId("auth-email")).toHaveAttribute("name", "email");
|
|
100
|
+
// The visible label names the field (Field's htmlFor → the input's id).
|
|
101
|
+
expect(screen.getByLabelText("Email")).toBe(screen.getByTestId("auth-email"));
|
|
102
|
+
expect(screen.getByTestId("spoke-sign-in-agreement-account_terms")).toBeInTheDocument();
|
|
103
|
+
expect(screen.getByTestId("spoke-sign-in-google")).toHaveAttribute(
|
|
104
|
+
"href",
|
|
105
|
+
"/api/hub-session/sign-in?next=%2Faccount&provider=google",
|
|
106
|
+
);
|
|
107
|
+
// The only hub URLs on the page are the agreement's own policy links
|
|
108
|
+
// (D3: the policies are the hub's); nothing links to a hub sign-in page.
|
|
109
|
+
const hubHrefs = Array.from(document.querySelectorAll("[href]"))
|
|
110
|
+
.filter((el) => (el.getAttribute("href") ?? "").includes("hub.example"))
|
|
111
|
+
.map((el) => el.getAttribute("data-testid"));
|
|
112
|
+
expect(hubHrefs).toEqual(["consent-policy-link-terms", "consent-policy-link-privacy"]);
|
|
113
|
+
expect(document.querySelector('[href*="hub.example/sign-in"]')).toBeNull();
|
|
114
|
+
expect(document.querySelector('[href*="/api/auth/hub/"]')).toBeNull();
|
|
115
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
116
|
+
`${HUB}/api/auth/hub/sign-up?locale=en`,
|
|
117
|
+
expect.anything(),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("the form posts natively to the spoke's email route, carrying next", async () => {
|
|
122
|
+
await renderGate("", "/account/inbox");
|
|
123
|
+
const form = screen.getByTestId("spoke-sign-in-form");
|
|
124
|
+
expect(form.tagName).toBe("FORM");
|
|
125
|
+
expect(form).toHaveAttribute("method", "post");
|
|
126
|
+
expect(form).toHaveAttribute("action", "/api/hub-session/email");
|
|
127
|
+
expect(form.querySelector('input[name="next"]')).toHaveAttribute("value", "/account/inbox");
|
|
128
|
+
// The ticked agreement posts its purpose id under `agreements`, unticked by default.
|
|
129
|
+
const box = screen.getByTestId("spoke-sign-in-agreement-account_terms");
|
|
130
|
+
expect(box).toHaveAttribute("aria-checked", "false");
|
|
131
|
+
expect(screen.getByTestId("spoke-sign-in-submit")).toHaveAttribute("type", "submit");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("?sent=1 renders the sent state and no form", async () => {
|
|
135
|
+
await renderGate("?sent=1");
|
|
136
|
+
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Check your email");
|
|
137
|
+
expect(screen.getByTestId("spoke-sign-in-sent")).toBeInTheDocument();
|
|
138
|
+
expect(screen.queryByTestId("spoke-sign-in-form")).not.toBeInTheDocument();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it.each([
|
|
142
|
+
["?error=agreements", "spoke-sign-in-agreements-error"],
|
|
143
|
+
["?error=unavailable", "spoke-sign-in-unavailable"],
|
|
144
|
+
["?error=exists", "spoke-sign-in-exists"],
|
|
145
|
+
["?error=claim", "spoke-sign-in-claim-error"],
|
|
146
|
+
])("%s renders its line above the form", async (search, testId) => {
|
|
147
|
+
await renderGate(search);
|
|
148
|
+
expect(screen.getByTestId(testId)).toBeInTheDocument();
|
|
149
|
+
expect(screen.getByTestId("spoke-sign-in-form")).toBeInTheDocument();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("a failed sign-up read renders the form with no agreements and no Google", async () => {
|
|
153
|
+
mockFetch.mockResolvedValue(signUpAnswer({ error: "x" }, 503));
|
|
154
|
+
await renderGate();
|
|
155
|
+
expect(screen.getByTestId("spoke-sign-in-form")).toBeInTheDocument();
|
|
156
|
+
expect(screen.queryByTestId("spoke-sign-in-agreement-account_terms")).not.toBeInTheDocument();
|
|
157
|
+
expect(screen.queryByTestId("spoke-sign-in-google")).not.toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("sign-up closed hides the agreements; Google off hides its button", async () => {
|
|
161
|
+
mockFetch.mockResolvedValue(signUpAnswer({ signUpOpen: false, google: false, agreements: [AGREEMENT] }));
|
|
162
|
+
await renderGate();
|
|
163
|
+
expect(screen.queryByTestId("spoke-sign-in-agreement-account_terms")).not.toBeInTheDocument();
|
|
164
|
+
expect(screen.queryByTestId("spoke-sign-in-google")).not.toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("not configured: says sign-in isn't available and renders no form", async () => {
|
|
168
|
+
delete process.env.AILK_HUB_CLIENT_SECRET;
|
|
169
|
+
await renderGate();
|
|
170
|
+
expect(screen.getByTestId("account-sign-in-gate")).toHaveTextContent("Sign-in isn't available yet");
|
|
171
|
+
expect(screen.queryByTestId("spoke-sign-in-form")).not.toBeInTheDocument();
|
|
172
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("AC-6 — no password on the spoke", () => {
|
|
177
|
+
it("the form has no password input", async () => {
|
|
178
|
+
await renderGate();
|
|
179
|
+
expect(document.querySelector("input[type=password]")).toBeNull();
|
|
180
|
+
expect(document.querySelector('[name="password"]')).toBeNull();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("AC-4 — the purchase link's open state (D9)", () => {
|
|
185
|
+
const CLAIM = "C".repeat(120);
|
|
186
|
+
|
|
187
|
+
it("renders Open my account under the statement, in a POST form to the open route, with no checkbox", async () => {
|
|
188
|
+
await renderGate(`?claim=${CLAIM}`);
|
|
189
|
+
const open = screen.getByTestId("spoke-sign-in-open");
|
|
190
|
+
const form = open.closest("form");
|
|
191
|
+
expect(form).toHaveAttribute("method", "post");
|
|
192
|
+
expect(form).toHaveAttribute("action", "/api/hub-session/open");
|
|
193
|
+
expect(form?.querySelector('input[name="claim"]')).toHaveAttribute("value", CLAIM);
|
|
194
|
+
expect(screen.getByTestId("spoke-sign-in-open-terms")).toHaveTextContent(
|
|
195
|
+
"I accept the Terms and the Privacy Policy.",
|
|
196
|
+
);
|
|
197
|
+
expect(document.querySelector('[role="checkbox"]')).toBeNull();
|
|
198
|
+
expect(screen.queryByTestId("spoke-sign-in-form")).not.toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("rendering it makes no hub call but the sign-up read", async () => {
|
|
202
|
+
await renderGate(`?claim=${CLAIM}`);
|
|
203
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
204
|
+
expect(String(mockFetch.mock.calls[0]?.[0])).toBe(`${HUB}/api/auth/hub/sign-up?locale=en`);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("a malformed claim renders the form instead", async () => {
|
|
208
|
+
await renderGate("?claim=not%20a%20claim");
|
|
209
|
+
expect(screen.queryByTestId("spoke-sign-in-open")).not.toBeInTheDocument();
|
|
210
|
+
expect(screen.getByTestId("spoke-sign-in-form")).toBeInTheDocument();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("without the hub's agreements it offers no button, only the unavailable line", async () => {
|
|
214
|
+
mockFetch.mockResolvedValue(signUpAnswer({}, 503));
|
|
215
|
+
await renderGate(`?claim=${CLAIM}`);
|
|
216
|
+
expect(screen.queryByTestId("spoke-sign-in-open")).not.toBeInTheDocument();
|
|
217
|
+
expect(screen.getByTestId("spoke-sign-in-unavailable")).toBeInTheDocument();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("AC-5 — One Tap on the spoke (D10)", () => {
|
|
222
|
+
it("with AILK_HUB_ONE_TAP=on and the hub's client id, renders the island with that id", async () => {
|
|
223
|
+
process.env.AILK_HUB_ONE_TAP = "on";
|
|
224
|
+
await renderGate();
|
|
225
|
+
expect(screen.getByTestId("spoke-sign-in-one-tap")).toHaveAttribute(
|
|
226
|
+
"data-client-id",
|
|
227
|
+
"g-client.apps",
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it.each([
|
|
232
|
+
["the spoke's setting off", () => undefined],
|
|
233
|
+
[
|
|
234
|
+
"the hub sending no client id",
|
|
235
|
+
() => {
|
|
236
|
+
process.env.AILK_HUB_ONE_TAP = "on";
|
|
237
|
+
mockClientInfo.mockResolvedValue({ ok: true, body: { clientId: "spoke_0001", name: "Spoke", origin: SITE } });
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
])("with %s, renders no island", async (_label, arrange) => {
|
|
241
|
+
arrange();
|
|
242
|
+
await renderGate();
|
|
243
|
+
expect(screen.queryByTestId("spoke-sign-in-one-tap")).not.toBeInTheDocument();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe("the island", () => {
|
|
247
|
+
type Init = { client_id: string; nonce: string; callback: (r: { credential: string }) => void };
|
|
248
|
+
let initialize: jest.Mock;
|
|
249
|
+
let prompt: jest.Mock;
|
|
250
|
+
let assign: jest.SpyInstance;
|
|
251
|
+
|
|
252
|
+
/** Google's Identity Services global, as its script would leave it. */
|
|
253
|
+
const gsiWindow = window as Window & { google?: unknown };
|
|
254
|
+
|
|
255
|
+
beforeEach(() => {
|
|
256
|
+
initialize = jest.fn();
|
|
257
|
+
prompt = jest.fn();
|
|
258
|
+
gsiWindow.google = { accounts: { id: { initialize, prompt } } };
|
|
259
|
+
assign = jest.spyOn(oneTapNavigation, "assign").mockImplementation(() => undefined);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
afterEach(() => {
|
|
263
|
+
delete gsiWindow.google;
|
|
264
|
+
assign.mockRestore();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
async function started(): Promise<Init> {
|
|
268
|
+
mockFetch.mockReset().mockResolvedValueOnce(signUpAnswer({ nonce: "n".repeat(43) }));
|
|
269
|
+
render(<OneTap clientId="g-client.apps" next="/account/inbox" />);
|
|
270
|
+
await waitFor(() => expect(initialize).toHaveBeenCalledTimes(1));
|
|
271
|
+
expect(prompt).toHaveBeenCalledTimes(1);
|
|
272
|
+
return initialize.mock.calls[0]?.[0] as Init;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
it("asks the nonce route, then initializes Google with the client id and that nonce", async () => {
|
|
276
|
+
const init = await started();
|
|
277
|
+
expect(String(mockFetch.mock.calls[0]?.[0])).toBe("/api/hub-session/one-tap/nonce");
|
|
278
|
+
expect(init.client_id).toBe("g-client.apps");
|
|
279
|
+
expect(init.nonce).toBe("n".repeat(43));
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("navigates to next only after the spoke route answers { ok: true }", async () => {
|
|
283
|
+
const init = await started();
|
|
284
|
+
mockFetch.mockResolvedValueOnce(signUpAnswer({ ok: false }, 401));
|
|
285
|
+
await act(async () => {
|
|
286
|
+
init.callback({ credential: "a.b.c" });
|
|
287
|
+
});
|
|
288
|
+
expect(assign).not.toHaveBeenCalled();
|
|
289
|
+
|
|
290
|
+
mockFetch.mockResolvedValueOnce(signUpAnswer({ ok: true }));
|
|
291
|
+
await act(async () => {
|
|
292
|
+
init.callback({ credential: "a.b.c" });
|
|
293
|
+
});
|
|
294
|
+
await waitFor(() => expect(assign).toHaveBeenCalledWith("/account/inbox"));
|
|
295
|
+
const [url, request] = mockFetch.mock.calls[2] as [string, RequestInit];
|
|
296
|
+
expect(url).toBe("/api/hub-session/one-tap");
|
|
297
|
+
expect(JSON.parse(String(request.body))).toEqual({ credential: "a.b.c" });
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe("loadGoogle always settles", () => {
|
|
302
|
+
const gsiWindow = window as Window & { google?: unknown };
|
|
303
|
+
const SRC = "https://accounts.google.com/gsi/client";
|
|
304
|
+
|
|
305
|
+
afterEach(() => {
|
|
306
|
+
jest.useRealTimers();
|
|
307
|
+
delete gsiWindow.google;
|
|
308
|
+
document.querySelectorAll(`script[src="${SRC}"]`).forEach((node) => node.remove());
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("resolves at once when Google's global is already there", async () => {
|
|
312
|
+
gsiWindow.google = { accounts: { id: { initialize: jest.fn(), prompt: jest.fn() } } };
|
|
313
|
+
await expect(loadGoogle()).resolves.toBeUndefined();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("rejects when the script loads but leaves no google.accounts.id", async () => {
|
|
317
|
+
const loading = loadGoogle();
|
|
318
|
+
document.querySelector(`script[src="${SRC}"]`)?.dispatchEvent(new Event("load"));
|
|
319
|
+
await expect(loading).rejects.toThrow("gsi");
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("rejects after 10 s when a script tag already on the page never loads again", async () => {
|
|
323
|
+
jest.useFakeTimers();
|
|
324
|
+
const tag = document.createElement("script");
|
|
325
|
+
tag.setAttribute("src", SRC);
|
|
326
|
+
document.head.appendChild(tag);
|
|
327
|
+
const loading = loadGoogle();
|
|
328
|
+
jest.advanceTimersByTime(10_000);
|
|
329
|
+
await expect(loading).rejects.toThrow("gsi");
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* - `AILK_HUB_CLIENT_SECRET` — the secret `spokes sign-in-client` printed;
|
|
13
13
|
* - `AILK_HUB_SESSION_SECRET` — this site's own cookie key material (at
|
|
14
14
|
* least 32 characters). It never derives from
|
|
15
|
-
* the client secret (`seal.ts`)
|
|
15
|
+
* the client secret (`seal.ts`);
|
|
16
|
+
* - `AILK_HUB_ONE_TAP` — `on` turns on Google One Tap for a
|
|
17
|
+
* returning person (#11096 D10); anything
|
|
18
|
+
* else, or unset, leaves it off.
|
|
16
19
|
*
|
|
17
20
|
* The site's own origin is `resolveBaseUrl()` — `NEXT_PUBLIC_BASE_URL`, else
|
|
18
21
|
* the site's `baseUrl` — never a request header, so a forged `Host` cannot move
|
|
@@ -44,6 +47,8 @@ export interface HubSessionConfig {
|
|
|
44
47
|
redirectUri: string;
|
|
45
48
|
/** Whether the site origin is https — the cookies are then `__Host-` and `Secure`. */
|
|
46
49
|
secure: boolean;
|
|
50
|
+
/** Whether Google One Tap is on for this spoke (`AILK_HUB_ONE_TAP=on`, #11096 D10). */
|
|
51
|
+
oneTap: boolean;
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
/**
|
|
@@ -100,5 +105,6 @@ export function hubSessionConfig(): HubSessionConfig | null {
|
|
|
100
105
|
siteOrigin,
|
|
101
106
|
redirectUri: `${siteOrigin}${HUB_SESSION_CALLBACK_PATH}`,
|
|
102
107
|
secure: siteOrigin.startsWith("https:"),
|
|
108
|
+
oneTap: process.env.AILK_HUB_ONE_TAP === "on",
|
|
103
109
|
};
|
|
104
110
|
}
|