@nowline/embed 0.4.1 → 0.5.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.
Files changed (42) hide show
  1. package/README.md +14 -26
  2. package/dist/auto-scan.d.ts +11 -0
  3. package/dist/auto-scan.d.ts.map +1 -1
  4. package/dist/auto-scan.js +28 -0
  5. package/dist/auto-scan.js.map +1 -1
  6. package/dist/index.d.ts +18 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +8 -20
  9. package/dist/index.js.map +1 -1
  10. package/dist/meta.json +116 -59
  11. package/dist/nowline.esm.js +1020 -133
  12. package/dist/nowline.esm.js.map +4 -4
  13. package/dist/nowline.min.js +82 -82
  14. package/dist/nowline.min.js.map +4 -4
  15. package/dist/share.d.ts +45 -0
  16. package/dist/share.d.ts.map +1 -0
  17. package/dist/share.js +75 -0
  18. package/dist/share.js.map +1 -0
  19. package/dist/theme.d.ts +3 -3
  20. package/dist/theme.d.ts.map +1 -1
  21. package/dist/theme.js +5 -3
  22. package/dist/theme.js.map +1 -1
  23. package/package.json +6 -7
  24. package/src/auto-scan.ts +42 -0
  25. package/src/index.ts +43 -31
  26. package/src/share.ts +108 -0
  27. package/src/theme.ts +7 -5
  28. package/dist/auth/allowlist.d.ts +0 -20
  29. package/dist/auth/allowlist.d.ts.map +0 -1
  30. package/dist/auth/allowlist.js +0 -33
  31. package/dist/auth/allowlist.js.map +0 -1
  32. package/dist/auth/env.d.ts +0 -23
  33. package/dist/auth/env.d.ts.map +0 -1
  34. package/dist/auth/env.js +0 -24
  35. package/dist/auth/env.js.map +0 -1
  36. package/dist/auth/firebase-auth.client.d.ts +0 -21
  37. package/dist/auth/firebase-auth.client.d.ts.map +0 -1
  38. package/dist/auth/firebase-auth.client.js +0 -142
  39. package/dist/auth/firebase-auth.client.js.map +0 -1
  40. package/src/auth/allowlist.ts +0 -32
  41. package/src/auth/env.ts +0 -37
  42. package/src/auth/firebase-auth.client.ts +0 -174
@@ -1,23 +0,0 @@
1
- /**
2
- * Build-time environment helpers for `@nowline/embed`.
3
- *
4
- * `__NOWLINE_EMBED_ENV__` is substituted at bundle time by esbuild's
5
- * `define` (see `packages/embed/scripts/bundle.mjs`). The substitution
6
- * lets the prod minified bundle dead-code-eliminate the dev auth gate
7
- * and its Firebase imports — when the constant folds to the literal
8
- * string `"prod"`, every `IS_DEV` branch becomes `false` and esbuild's
9
- * minifier strips the dynamic-import site that pulls in `firebase/app`
10
- * + `firebase/auth`.
11
- *
12
- * The `typeof` guards keep this module safe to import under vitest,
13
- * where esbuild's define never runs and the identifier is undeclared.
14
- */
15
- export type EmbedEnv = 'dev' | 'prod';
16
- export declare const EMBED_ENV: EmbedEnv;
17
- export declare const IS_DEV: boolean;
18
- export declare const IS_PROD: boolean;
19
- export declare const EMBED_VERSION: string;
20
- export declare const EMBED_SHA: string;
21
- export declare const PROD_ORIGIN = "https://embed.nowline.io";
22
- export declare const DEV_ORIGIN = "https://embed.nowline.dev";
23
- //# sourceMappingURL=env.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/auth/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEtC,eAAO,MAAM,SAAS,EAAE,QAGR,CAAC;AAEjB,eAAO,MAAM,MAAM,EAAE,OAA6B,CAAC;AACnD,eAAO,MAAM,OAAO,EAAE,OAA8B,CAAC;AAErD,eAAO,MAAM,aAAa,EAAE,MAC8D,CAAC;AAE3F,eAAO,MAAM,SAAS,EAAE,MAC4D,CAAC;AAErF,eAAO,MAAM,WAAW,6BAA6B,CAAC;AACtD,eAAO,MAAM,UAAU,8BAA8B,CAAC"}
package/dist/auth/env.js DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * Build-time environment helpers for `@nowline/embed`.
3
- *
4
- * `__NOWLINE_EMBED_ENV__` is substituted at bundle time by esbuild's
5
- * `define` (see `packages/embed/scripts/bundle.mjs`). The substitution
6
- * lets the prod minified bundle dead-code-eliminate the dev auth gate
7
- * and its Firebase imports — when the constant folds to the literal
8
- * string `"prod"`, every `IS_DEV` branch becomes `false` and esbuild's
9
- * minifier strips the dynamic-import site that pulls in `firebase/app`
10
- * + `firebase/auth`.
11
- *
12
- * The `typeof` guards keep this module safe to import under vitest,
13
- * where esbuild's define never runs and the identifier is undeclared.
14
- */
15
- export const EMBED_ENV = typeof __NOWLINE_EMBED_ENV__ !== 'undefined' && __NOWLINE_EMBED_ENV__ === 'dev'
16
- ? 'dev'
17
- : 'prod';
18
- export const IS_DEV = EMBED_ENV === 'dev';
19
- export const IS_PROD = EMBED_ENV === 'prod';
20
- export const EMBED_VERSION = typeof __NOWLINE_EMBED_VERSION__ !== 'undefined' ? __NOWLINE_EMBED_VERSION__ : '0.0.0';
21
- export const EMBED_SHA = typeof __NOWLINE_EMBED_SHA__ !== 'undefined' ? __NOWLINE_EMBED_SHA__ : 'unknown';
22
- export const PROD_ORIGIN = 'https://embed.nowline.io';
23
- export const DEV_ORIGIN = 'https://embed.nowline.dev';
24
- //# sourceMappingURL=env.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/auth/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,MAAM,CAAC,MAAM,SAAS,GAClB,OAAO,qBAAqB,KAAK,WAAW,IAAI,qBAAqB,KAAK,KAAK;IAC3E,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,MAAM,CAAC;AAEjB,MAAM,CAAC,MAAM,MAAM,GAAY,SAAS,KAAK,KAAK,CAAC;AACnD,MAAM,CAAC,MAAM,OAAO,GAAY,SAAS,KAAK,MAAM,CAAC;AAErD,MAAM,CAAC,MAAM,aAAa,GACtB,OAAO,yBAAyB,KAAK,WAAW,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC;AAE3F,MAAM,CAAC,MAAM,SAAS,GAClB,OAAO,qBAAqB,KAAK,WAAW,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC;AAErF,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,2BAA2B,CAAC"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Client-side Firebase Auth gate for the dev embed bundle.
3
- *
4
- * Mirrors the commercial site's `firebase-auth.client.ts` so the
5
- * two Lolay dev surfaces share one allowlist UX. Loaded only on the
6
- * dev build (when `__NOWLINE_EMBED_ENV__ === 'dev'`); the prod build
7
- * tree-shakes the dynamic import in `src/index.ts` and never pulls
8
- * `firebase/app` or `firebase/auth` into the IIFE.
9
- *
10
- * Renders a full-viewport overlay with z-index 2147483647 so it sits
11
- * above any host-page content. Until the visitor signs in with an
12
- * allowlisted Google account, the overlay stays put; once allowlisted,
13
- * it removes itself and the embed's auto-scan reaches the rendered
14
- * SVG underneath. The host page is told nothing — the gate is purely
15
- * client-side, opaque to the embedder.
16
- *
17
- * See specs/embed.md § Bootstrap status (dev auth gate) and
18
- * the infrastructure deploy runbook § 4 for the deploy-side wiring.
19
- */
20
- export declare function startDevAuthGate(): void;
21
- //# sourceMappingURL=firebase-auth.client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"firebase-auth.client.d.ts","sourceRoot":"","sources":["../../src/auth/firebase-auth.client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAyGH,wBAAgB,gBAAgB,IAAI,IAAI,CAkDvC"}
@@ -1,142 +0,0 @@
1
- /**
2
- * Client-side Firebase Auth gate for the dev embed bundle.
3
- *
4
- * Mirrors the commercial site's `firebase-auth.client.ts` so the
5
- * two Lolay dev surfaces share one allowlist UX. Loaded only on the
6
- * dev build (when `__NOWLINE_EMBED_ENV__ === 'dev'`); the prod build
7
- * tree-shakes the dynamic import in `src/index.ts` and never pulls
8
- * `firebase/app` or `firebase/auth` into the IIFE.
9
- *
10
- * Renders a full-viewport overlay with z-index 2147483647 so it sits
11
- * above any host-page content. Until the visitor signs in with an
12
- * allowlisted Google account, the overlay stays put; once allowlisted,
13
- * it removes itself and the embed's auto-scan reaches the rendered
14
- * SVG underneath. The host page is told nothing — the gate is purely
15
- * client-side, opaque to the embedder.
16
- *
17
- * See specs/embed.md § Bootstrap status (dev auth gate) and
18
- * the infrastructure deploy runbook § 4 for the deploy-side wiring.
19
- */
20
- import { initializeApp } from 'firebase/app';
21
- import { GoogleAuthProvider, getAuth, onAuthStateChanged, signInWithPopup, signOut, } from 'firebase/auth';
22
- import { isAllowlisted } from './allowlist.js';
23
- const config = {
24
- apiKey: typeof __NOWLINE_FIREBASE_API_KEY__ !== 'undefined' ? __NOWLINE_FIREBASE_API_KEY__ : '',
25
- authDomain: typeof __NOWLINE_FIREBASE_AUTH_DOMAIN__ !== 'undefined'
26
- ? __NOWLINE_FIREBASE_AUTH_DOMAIN__
27
- : '',
28
- projectId: typeof __NOWLINE_FIREBASE_PROJECT_ID__ !== 'undefined'
29
- ? __NOWLINE_FIREBASE_PROJECT_ID__
30
- : '',
31
- appId: typeof __NOWLINE_FIREBASE_APP_ID__ !== 'undefined' ? __NOWLINE_FIREBASE_APP_ID__ : '',
32
- };
33
- const OVERLAY_ID = 'nowline-embed-dev-auth-overlay';
34
- let app = null;
35
- let auth = null;
36
- function getOrCreateOverlay() {
37
- let overlay = document.getElementById(OVERLAY_ID);
38
- if (overlay)
39
- return overlay;
40
- overlay = document.createElement('div');
41
- overlay.id = OVERLAY_ID;
42
- overlay.setAttribute('role', 'dialog');
43
- overlay.setAttribute('aria-modal', 'true');
44
- overlay.setAttribute('aria-label', 'Internal preview sign-in');
45
- overlay.style.cssText = [
46
- 'position: fixed',
47
- 'inset: 0',
48
- 'z-index: 2147483647',
49
- 'background-color: #ffffff',
50
- 'color: #1a1a2e',
51
- 'display: flex',
52
- 'align-items: center',
53
- 'justify-content: center',
54
- 'padding: 1.5rem',
55
- 'font-family: system-ui, -apple-system, "Segoe UI", sans-serif',
56
- ].join(';');
57
- document.body.appendChild(overlay);
58
- return overlay;
59
- }
60
- function removeOverlay() {
61
- const overlay = document.getElementById(OVERLAY_ID);
62
- overlay?.remove();
63
- }
64
- function renderSignIn(overlay, onClick) {
65
- overlay.innerHTML = `
66
- <div style="max-width: 28rem; text-align: center;">
67
- <div style="font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: #5a5a6a; margin-bottom: 0.75rem;">embed.nowline.dev &mdash; internal preview</div>
68
- <h1 style="font-size: 1.875rem; font-weight: 700; margin: 0 0 0.75rem;">Sign in to continue</h1>
69
- <p style="margin: 0 0 1.5rem; color: #5a5a6a;">Access is limited to allowlisted Lolay accounts. Production embed is at <a href="https://embed.nowline.io" style="color: #1a4ed8;">embed.nowline.io</a>.</p>
70
- <button type="button" id="nowline-embed-dev-signin-btn" style="display: inline-block; padding: 0.75rem 1.5rem; border-radius: 8px; background-color: #e53e3e; color: #ffffff; font-weight: 700; border: 1px solid transparent; cursor: pointer; font-size: 1rem;">Sign in with Google</button>
71
- </div>
72
- `;
73
- const btn = overlay.querySelector('#nowline-embed-dev-signin-btn');
74
- btn?.addEventListener('click', onClick);
75
- }
76
- function renderDenied(overlay, email, onSignOut) {
77
- overlay.innerHTML = `
78
- <div style="max-width: 28rem; text-align: center;">
79
- <div style="font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: #5a5a6a; margin-bottom: 0.75rem;">embed.nowline.dev &mdash; internal preview</div>
80
- <h1 style="font-size: 1.875rem; font-weight: 700; margin: 0 0 0.75rem;">Access denied</h1>
81
- <p style="margin: 0 0 1.5rem; color: #5a5a6a;">${escapeHtml(email)} is not on the allowlist for this preview environment. Production embed is publicly available at <a href="https://embed.nowline.io" style="color: #1a4ed8;">embed.nowline.io</a>.</p>
82
- <button type="button" id="nowline-embed-dev-signout-btn" style="display: inline-block; padding: 0.75rem 1.5rem; border-radius: 8px; background-color: transparent; color: #1a1a2e; font-weight: 700; border: 1px solid #c0c0c0; cursor: pointer; font-size: 1rem;">Sign out</button>
83
- </div>
84
- `;
85
- const btn = overlay.querySelector('#nowline-embed-dev-signout-btn');
86
- btn?.addEventListener('click', onSignOut);
87
- }
88
- function escapeHtml(value) {
89
- return value
90
- .replace(/&/g, '&amp;')
91
- .replace(/</g, '&lt;')
92
- .replace(/>/g, '&gt;')
93
- .replace(/"/g, '&quot;')
94
- .replace(/'/g, '&#39;');
95
- }
96
- export function startDevAuthGate() {
97
- if (typeof window === 'undefined' || typeof document === 'undefined')
98
- return;
99
- if (!config.apiKey || !config.authDomain || !config.projectId || !config.appId) {
100
- // No firebase config baked in. Likely a local `pnpm bundle` without
101
- // PUBLIC_FIREBASE_* exported (CI deploys always set them). Skip the
102
- // overlay rather than render an unrecoverable dialog so devs aren't
103
- // locked out of their own local builds.
104
- console.warn('[nowline-embed-dev-auth-gate] Missing PUBLIC_FIREBASE_* env vars at build time; gate is disabled. Configure them in .github/workflows/embed-cdn.yml or your local environment to enable.');
105
- return;
106
- }
107
- // Create the overlay up front so it covers content while Firebase
108
- // initialises; subsequent renders call getOrCreateOverlay() again
109
- // to find the same element.
110
- getOrCreateOverlay();
111
- app ??= initializeApp(config);
112
- auth ??= getAuth(app);
113
- const provider = new GoogleAuthProvider();
114
- const handleSignIn = async () => {
115
- try {
116
- await signInWithPopup(auth, provider);
117
- }
118
- catch (err) {
119
- console.error('[nowline-embed-dev-auth-gate] Sign-in failed:', err);
120
- }
121
- };
122
- const handleSignOut = async () => {
123
- try {
124
- await signOut(auth);
125
- }
126
- catch (err) {
127
- console.error('[nowline-embed-dev-auth-gate] Sign-out failed:', err);
128
- }
129
- };
130
- onAuthStateChanged(auth, (user) => {
131
- if (!user) {
132
- renderSignIn(getOrCreateOverlay(), handleSignIn);
133
- return;
134
- }
135
- if (!isAllowlisted(user.email)) {
136
- renderDenied(getOrCreateOverlay(), user.email ?? 'unknown', handleSignOut);
137
- return;
138
- }
139
- removeOverlay();
140
- });
141
- }
142
- //# sourceMappingURL=firebase-auth.client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"firebase-auth.client.js","sourceRoot":"","sources":["../../src/auth/firebase-auth.client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAoB,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAEH,kBAAkB,EAClB,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,OAAO,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAU/C,MAAM,MAAM,GAAG;IACX,MAAM,EAAE,OAAO,4BAA4B,KAAK,WAAW,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,EAAE;IAC/F,UAAU,EACN,OAAO,gCAAgC,KAAK,WAAW;QACnD,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,EAAE;IACZ,SAAS,EACL,OAAO,+BAA+B,KAAK,WAAW;QAClD,CAAC,CAAC,+BAA+B;QACjC,CAAC,CAAC,EAAE;IACZ,KAAK,EAAE,OAAO,2BAA2B,KAAK,WAAW,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE;CAC/F,CAAC;AAEF,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAEpD,IAAI,GAAG,GAAuB,IAAI,CAAC;AACnC,IAAI,IAAI,GAAgB,IAAI,CAAC;AAE7B,SAAS,kBAAkB;IACvB,IAAI,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAA0B,CAAC;IAC3E,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAE5B,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC;IACxB,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;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,kBAAkB,CAAC,IAAY,EAAE,CAAC,IAAiB,EAAE,EAAE;QACnD,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,YAAY,CAAC,kBAAkB,EAAE,EAAE,YAAY,CAAC,CAAC;YACjD,OAAO;QACX,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,YAAY,CAAC,kBAAkB,EAAE,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS,EAAE,aAAa,CAAC,CAAC;YAC3E,OAAO;QACX,CAAC;QACD,aAAa,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1,32 +0,0 @@
1
- /**
2
- * Allowlist for the dev embed bundle's Firebase Auth gate.
3
- *
4
- * An email is allowlisted if either:
5
- * 1. Its domain is in ALLOWED_DOMAINS (e.g. anything @nowline.io), OR
6
- * 2. The exact lowercase email is in ALLOWED_EMAILS.
7
- *
8
- * Mirrors the commercial site's `auth-allowlist.ts` so both Lolay
9
- * dev surfaces (the marketing site and the embed CDN dev tier) share
10
- * one allowlist policy. Keep this short; when it grows past ~5 entries,
11
- * migrate to Firebase custom claims (Admin SDK) or a Firestore
12
- * `allowlist` collection.
13
- *
14
- * See specs/embed.md § Bootstrap status (dev auth gate) and
15
- * the infrastructure deploy runbook § 4 for the deploy-side wiring.
16
- */
17
-
18
- export const ALLOWED_DOMAINS: readonly string[] = ['nowline.io'];
19
-
20
- export const ALLOWED_EMAILS: readonly string[] = [
21
- // Add additional allowlisted Google account emails here, one per line.
22
- ];
23
-
24
- export function isAllowlisted(email: string | null | undefined): boolean {
25
- if (!email) return false;
26
- const normalized = email.trim().toLowerCase();
27
- if (ALLOWED_EMAILS.includes(normalized)) return true;
28
- const at = normalized.lastIndexOf('@');
29
- if (at === -1) return false;
30
- const domain = normalized.slice(at + 1);
31
- return ALLOWED_DOMAINS.includes(domain);
32
- }
package/src/auth/env.ts DELETED
@@ -1,37 +0,0 @@
1
- /**
2
- * Build-time environment helpers for `@nowline/embed`.
3
- *
4
- * `__NOWLINE_EMBED_ENV__` is substituted at bundle time by esbuild's
5
- * `define` (see `packages/embed/scripts/bundle.mjs`). The substitution
6
- * lets the prod minified bundle dead-code-eliminate the dev auth gate
7
- * and its Firebase imports — when the constant folds to the literal
8
- * string `"prod"`, every `IS_DEV` branch becomes `false` and esbuild's
9
- * minifier strips the dynamic-import site that pulls in `firebase/app`
10
- * + `firebase/auth`.
11
- *
12
- * The `typeof` guards keep this module safe to import under vitest,
13
- * where esbuild's define never runs and the identifier is undeclared.
14
- */
15
-
16
- declare const __NOWLINE_EMBED_ENV__: string;
17
- declare const __NOWLINE_EMBED_VERSION__: string;
18
- declare const __NOWLINE_EMBED_SHA__: string;
19
-
20
- export type EmbedEnv = 'dev' | 'prod';
21
-
22
- export const EMBED_ENV: EmbedEnv =
23
- typeof __NOWLINE_EMBED_ENV__ !== 'undefined' && __NOWLINE_EMBED_ENV__ === 'dev'
24
- ? 'dev'
25
- : 'prod';
26
-
27
- export const IS_DEV: boolean = EMBED_ENV === 'dev';
28
- export const IS_PROD: boolean = EMBED_ENV === 'prod';
29
-
30
- export const EMBED_VERSION: string =
31
- typeof __NOWLINE_EMBED_VERSION__ !== 'undefined' ? __NOWLINE_EMBED_VERSION__ : '0.0.0';
32
-
33
- export const EMBED_SHA: string =
34
- typeof __NOWLINE_EMBED_SHA__ !== 'undefined' ? __NOWLINE_EMBED_SHA__ : 'unknown';
35
-
36
- export const PROD_ORIGIN = 'https://embed.nowline.io';
37
- export const DEV_ORIGIN = 'https://embed.nowline.dev';
@@ -1,174 +0,0 @@
1
- /**
2
- * Client-side Firebase Auth gate for the dev embed bundle.
3
- *
4
- * Mirrors the commercial site's `firebase-auth.client.ts` so the
5
- * two Lolay dev surfaces share one allowlist UX. Loaded only on the
6
- * dev build (when `__NOWLINE_EMBED_ENV__ === 'dev'`); the prod build
7
- * tree-shakes the dynamic import in `src/index.ts` and never pulls
8
- * `firebase/app` or `firebase/auth` into the IIFE.
9
- *
10
- * Renders a full-viewport overlay with z-index 2147483647 so it sits
11
- * above any host-page content. Until the visitor signs in with an
12
- * allowlisted Google account, the overlay stays put; once allowlisted,
13
- * it removes itself and the embed's auto-scan reaches the rendered
14
- * SVG underneath. The host page is told nothing — the gate is purely
15
- * client-side, opaque to the embedder.
16
- *
17
- * See specs/embed.md § Bootstrap status (dev auth gate) and
18
- * the infrastructure deploy runbook § 4 for the deploy-side wiring.
19
- */
20
-
21
- import { type FirebaseApp, initializeApp } from 'firebase/app';
22
- import {
23
- type Auth,
24
- GoogleAuthProvider,
25
- getAuth,
26
- onAuthStateChanged,
27
- signInWithPopup,
28
- signOut,
29
- type User,
30
- } from 'firebase/auth';
31
- import { isAllowlisted } from './allowlist.js';
32
-
33
- // esbuild-substituted at build time from PUBLIC_FIREBASE_* env vars in
34
- // .github/workflows/embed-cdn.yml (sourced from the `embed-dev` GitHub
35
- // environment-scoped variables — see the infrastructure deploy runbook § 2.5).
36
- declare const __NOWLINE_FIREBASE_API_KEY__: string;
37
- declare const __NOWLINE_FIREBASE_AUTH_DOMAIN__: string;
38
- declare const __NOWLINE_FIREBASE_PROJECT_ID__: string;
39
- declare const __NOWLINE_FIREBASE_APP_ID__: string;
40
-
41
- const config = {
42
- apiKey: typeof __NOWLINE_FIREBASE_API_KEY__ !== 'undefined' ? __NOWLINE_FIREBASE_API_KEY__ : '',
43
- authDomain:
44
- typeof __NOWLINE_FIREBASE_AUTH_DOMAIN__ !== 'undefined'
45
- ? __NOWLINE_FIREBASE_AUTH_DOMAIN__
46
- : '',
47
- projectId:
48
- typeof __NOWLINE_FIREBASE_PROJECT_ID__ !== 'undefined'
49
- ? __NOWLINE_FIREBASE_PROJECT_ID__
50
- : '',
51
- appId: typeof __NOWLINE_FIREBASE_APP_ID__ !== 'undefined' ? __NOWLINE_FIREBASE_APP_ID__ : '',
52
- };
53
-
54
- const OVERLAY_ID = 'nowline-embed-dev-auth-overlay';
55
-
56
- let app: FirebaseApp | null = null;
57
- let auth: Auth | null = null;
58
-
59
- function getOrCreateOverlay(): HTMLDivElement {
60
- let overlay = document.getElementById(OVERLAY_ID) as HTMLDivElement | null;
61
- if (overlay) return overlay;
62
-
63
- overlay = document.createElement('div');
64
- overlay.id = OVERLAY_ID;
65
- overlay.setAttribute('role', 'dialog');
66
- overlay.setAttribute('aria-modal', 'true');
67
- overlay.setAttribute('aria-label', 'Internal preview sign-in');
68
- overlay.style.cssText = [
69
- 'position: fixed',
70
- 'inset: 0',
71
- 'z-index: 2147483647',
72
- 'background-color: #ffffff',
73
- 'color: #1a1a2e',
74
- 'display: flex',
75
- 'align-items: center',
76
- 'justify-content: center',
77
- 'padding: 1.5rem',
78
- 'font-family: system-ui, -apple-system, "Segoe UI", sans-serif',
79
- ].join(';');
80
- document.body.appendChild(overlay);
81
- return overlay;
82
- }
83
-
84
- function removeOverlay(): void {
85
- const overlay = document.getElementById(OVERLAY_ID);
86
- overlay?.remove();
87
- }
88
-
89
- function renderSignIn(overlay: HTMLDivElement, onClick: () => void): void {
90
- overlay.innerHTML = `
91
- <div style="max-width: 28rem; text-align: center;">
92
- <div style="font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: #5a5a6a; margin-bottom: 0.75rem;">embed.nowline.dev &mdash; internal preview</div>
93
- <h1 style="font-size: 1.875rem; font-weight: 700; margin: 0 0 0.75rem;">Sign in to continue</h1>
94
- <p style="margin: 0 0 1.5rem; color: #5a5a6a;">Access is limited to allowlisted Lolay accounts. Production embed is at <a href="https://embed.nowline.io" style="color: #1a4ed8;">embed.nowline.io</a>.</p>
95
- <button type="button" id="nowline-embed-dev-signin-btn" style="display: inline-block; padding: 0.75rem 1.5rem; border-radius: 8px; background-color: #e53e3e; color: #ffffff; font-weight: 700; border: 1px solid transparent; cursor: pointer; font-size: 1rem;">Sign in with Google</button>
96
- </div>
97
- `;
98
- const btn = overlay.querySelector<HTMLButtonElement>('#nowline-embed-dev-signin-btn');
99
- btn?.addEventListener('click', onClick);
100
- }
101
-
102
- function renderDenied(overlay: HTMLDivElement, email: string, onSignOut: () => void): void {
103
- overlay.innerHTML = `
104
- <div style="max-width: 28rem; text-align: center;">
105
- <div style="font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: #5a5a6a; margin-bottom: 0.75rem;">embed.nowline.dev &mdash; internal preview</div>
106
- <h1 style="font-size: 1.875rem; font-weight: 700; margin: 0 0 0.75rem;">Access denied</h1>
107
- <p style="margin: 0 0 1.5rem; color: #5a5a6a;">${escapeHtml(email)} is not on the allowlist for this preview environment. Production embed is publicly available at <a href="https://embed.nowline.io" style="color: #1a4ed8;">embed.nowline.io</a>.</p>
108
- <button type="button" id="nowline-embed-dev-signout-btn" style="display: inline-block; padding: 0.75rem 1.5rem; border-radius: 8px; background-color: transparent; color: #1a1a2e; font-weight: 700; border: 1px solid #c0c0c0; cursor: pointer; font-size: 1rem;">Sign out</button>
109
- </div>
110
- `;
111
- const btn = overlay.querySelector<HTMLButtonElement>('#nowline-embed-dev-signout-btn');
112
- btn?.addEventListener('click', onSignOut);
113
- }
114
-
115
- function escapeHtml(value: string): string {
116
- return value
117
- .replace(/&/g, '&amp;')
118
- .replace(/</g, '&lt;')
119
- .replace(/>/g, '&gt;')
120
- .replace(/"/g, '&quot;')
121
- .replace(/'/g, '&#39;');
122
- }
123
-
124
- export function startDevAuthGate(): void {
125
- if (typeof window === 'undefined' || typeof document === 'undefined') return;
126
- if (!config.apiKey || !config.authDomain || !config.projectId || !config.appId) {
127
- // No firebase config baked in. Likely a local `pnpm bundle` without
128
- // PUBLIC_FIREBASE_* exported (CI deploys always set them). Skip the
129
- // overlay rather than render an unrecoverable dialog so devs aren't
130
- // locked out of their own local builds.
131
- console.warn(
132
- '[nowline-embed-dev-auth-gate] Missing PUBLIC_FIREBASE_* env vars at build time; gate is disabled. Configure them in .github/workflows/embed-cdn.yml or your local environment to enable.',
133
- );
134
- return;
135
- }
136
-
137
- // Create the overlay up front so it covers content while Firebase
138
- // initialises; subsequent renders call getOrCreateOverlay() again
139
- // to find the same element.
140
- getOrCreateOverlay();
141
-
142
- app ??= initializeApp(config);
143
- auth ??= getAuth(app);
144
-
145
- const provider = new GoogleAuthProvider();
146
-
147
- const handleSignIn = async (): Promise<void> => {
148
- try {
149
- await signInWithPopup(auth as Auth, provider);
150
- } catch (err) {
151
- console.error('[nowline-embed-dev-auth-gate] Sign-in failed:', err);
152
- }
153
- };
154
-
155
- const handleSignOut = async (): Promise<void> => {
156
- try {
157
- await signOut(auth as Auth);
158
- } catch (err) {
159
- console.error('[nowline-embed-dev-auth-gate] Sign-out failed:', err);
160
- }
161
- };
162
-
163
- onAuthStateChanged(auth as Auth, (user: User | null) => {
164
- if (!user) {
165
- renderSignIn(getOrCreateOverlay(), handleSignIn);
166
- return;
167
- }
168
- if (!isAllowlisted(user.email)) {
169
- renderDenied(getOrCreateOverlay(), user.email ?? 'unknown', handleSignOut);
170
- return;
171
- }
172
- removeOverlay();
173
- });
174
- }