@vibiz/cli 0.0.0-stage → 0.1.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 +36 -2
- package/dist/chunk-NWL4LVVI.js +1015 -0
- package/dist/src-BOTTM5XC.js +2230 -0
- package/dist/vibiz.js +3302 -0
- package/package.json +37 -4
- package/templates/nextjs-saas/.env.example +13 -0
- package/templates/nextjs-saas/README.md +106 -0
- package/templates/nextjs-saas/_gitignore +8 -0
- package/templates/nextjs-saas/_npmrc +1 -0
- package/templates/nextjs-saas/app/api/auth/[...path]/route.ts +30 -0
- package/templates/nextjs-saas/app/api/chat/route.ts +76 -0
- package/templates/nextjs-saas/app/dashboard/actions.ts +32 -0
- package/templates/nextjs-saas/app/dashboard/page.tsx +130 -0
- package/templates/nextjs-saas/app/globals.css +17 -0
- package/templates/nextjs-saas/app/layout.tsx +28 -0
- package/templates/nextjs-saas/app/not-found.tsx +13 -0
- package/templates/nextjs-saas/app/page.tsx +63 -0
- package/templates/nextjs-saas/app/sign-in/page.tsx +8 -0
- package/templates/nextjs-saas/app/sign-up/page.tsx +8 -0
- package/templates/nextjs-saas/app.config.ts +15 -0
- package/templates/nextjs-saas/components/analytics.tsx +20 -0
- package/templates/nextjs-saas/components/auth-form.tsx +144 -0
- package/templates/nextjs-saas/components/auth-page.tsx +30 -0
- package/templates/nextjs-saas/components/chat-box.tsx +95 -0
- package/templates/nextjs-saas/components/header.tsx +24 -0
- package/templates/nextjs-saas/components/not-configured.tsx +17 -0
- package/templates/nextjs-saas/components/replay-consent.tsx +75 -0
- package/templates/nextjs-saas/components/replay-identify.tsx +21 -0
- package/templates/nextjs-saas/components/sign-out-button.tsx +25 -0
- package/templates/nextjs-saas/components/ui.tsx +47 -0
- package/templates/nextjs-saas/db/migrate.ts +21 -0
- package/templates/nextjs-saas/db/schema.ts +18 -0
- package/templates/nextjs-saas/lib/auth/client.ts +6 -0
- package/templates/nextjs-saas/lib/auth/server.ts +44 -0
- package/templates/nextjs-saas/lib/db.ts +32 -0
- package/templates/nextjs-saas/lib/env.ts +36 -0
- package/templates/nextjs-saas/lib/replay.ts +55 -0
- package/templates/nextjs-saas/next.config.ts +9 -0
- package/templates/nextjs-saas/package-lock.json +5359 -0
- package/templates/nextjs-saas/package.json +32 -0
- package/templates/nextjs-saas/postcss.config.mjs +3 -0
- package/templates/nextjs-saas/proxy.ts +18 -0
- package/templates/nextjs-saas/tsconfig.json +21 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session replay, only with the visitor's consent. The choice is kept in
|
|
3
|
+
* localStorage (after they make it), and nothing is recorded before it.
|
|
4
|
+
* Replay itself is the `replay` resource: without NEXT_PUBLIC_VIBIZ_REPLAY
|
|
5
|
+
* none of this renders.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type Vibiz = ((...args: unknown[]) => void) & { q?: unknown[][] };
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
vibiz?: Vibiz;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CONSENT_KEY = 'vibiz-replay-consent';
|
|
16
|
+
/** Fired when the choice changes, so parts of the page can react. */
|
|
17
|
+
export const CONSENT_EVENT = 'vibiz-replay-consent';
|
|
18
|
+
export type Consent = 'granted' | 'denied' | null;
|
|
19
|
+
|
|
20
|
+
export const replayEnabled = () =>
|
|
21
|
+
Boolean(
|
|
22
|
+
process.env.NEXT_PUBLIC_VIBIZ_REPLAY &&
|
|
23
|
+
process.env.NEXT_PUBLIC_VIBIZ_ANALYTICS_KEY &&
|
|
24
|
+
process.env.NEXT_PUBLIC_VIBIZ_ANALYTICS_URL,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export function readConsent(): Consent {
|
|
28
|
+
try {
|
|
29
|
+
const v = window.localStorage.getItem(CONSENT_KEY);
|
|
30
|
+
return v === 'granted' || v === 'denied' ? v : null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function writeConsent(value: Exclude<Consent, null>) {
|
|
37
|
+
try {
|
|
38
|
+
window.localStorage.setItem(CONSENT_KEY, value);
|
|
39
|
+
} catch {
|
|
40
|
+
// storage blocked: the choice holds for this page only
|
|
41
|
+
}
|
|
42
|
+
window.dispatchEvent(new Event(CONSENT_EVENT));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `vibiz('replay', …)`, queued until the analytics script has loaded. */
|
|
46
|
+
export function replay(command: 'start' | 'always' | 'stop') {
|
|
47
|
+
if (!window.vibiz) {
|
|
48
|
+
const stub: Vibiz = (...args: unknown[]) => {
|
|
49
|
+
stub.q = stub.q ?? [];
|
|
50
|
+
stub.q.push(args);
|
|
51
|
+
};
|
|
52
|
+
window.vibiz = stub;
|
|
53
|
+
}
|
|
54
|
+
window.vibiz('replay', command);
|
|
55
|
+
}
|