@businessdash/sdk 0.9.60 → 0.9.80
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 +991 -295
- package/assets/biab-sw.js +92 -0
- package/dist/account-core/index.d.ts +126 -0
- package/dist/account-core/index.d.ts.map +1 -0
- package/dist/account-core/index.js +191 -0
- package/dist/account-core/index.js.map +1 -0
- package/dist/account.d.ts +11 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +11 -0
- package/dist/account.js.map +1 -0
- package/dist/auth-handler.d.ts +1 -1
- package/dist/auth-links.d.ts +33 -0
- package/dist/auth-links.d.ts.map +1 -0
- package/dist/auth-links.js +64 -0
- package/dist/auth-links.js.map +1 -0
- package/dist/blog-core/index.d.ts +112 -0
- package/dist/blog-core/index.d.ts.map +1 -0
- package/dist/blog-core/index.js +330 -0
- package/dist/blog-core/index.js.map +1 -0
- package/dist/blog.d.ts +11 -0
- package/dist/blog.d.ts.map +1 -0
- package/dist/blog.js +11 -0
- package/dist/blog.js.map +1 -0
- package/dist/chat-core/index.d.ts +97 -0
- package/dist/chat-core/index.d.ts.map +1 -0
- package/dist/chat-core/index.js +237 -0
- package/dist/chat-core/index.js.map +1 -0
- package/dist/chat.d.ts +11 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +11 -0
- package/dist/chat.js.map +1 -0
- package/dist/checkout-core/index.d.ts +65 -0
- package/dist/checkout-core/index.d.ts.map +1 -0
- package/dist/checkout-core/index.js +159 -0
- package/dist/checkout-core/index.js.map +1 -0
- package/dist/checkout.d.ts +10 -0
- package/dist/checkout.d.ts.map +1 -0
- package/dist/checkout.js +10 -0
- package/dist/checkout.js.map +1 -0
- package/dist/cli.js +133 -25
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +622 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +888 -1
- package/dist/client.js.map +1 -1
- package/dist/consent-core/index.cjs +107 -0
- package/dist/consent-core/index.d.ts +103 -0
- package/dist/consent-core/index.d.ts.map +1 -0
- package/dist/consent-core/index.js +157 -0
- package/dist/consent-core/index.js.map +1 -0
- package/dist/contracts.d.ts +3526 -767
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +571 -4
- package/dist/contracts.js.map +1 -1
- package/dist/data-model-schema.d.ts +1 -1
- package/dist/data-model-schema.d.ts.map +1 -1
- package/dist/element.d.ts +30 -0
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +56 -0
- package/dist/element.js.map +1 -1
- package/dist/embed-protocol.d.ts +86 -0
- package/dist/embed-protocol.d.ts.map +1 -0
- package/dist/embed-protocol.js +60 -0
- package/dist/embed-protocol.js.map +1 -0
- package/dist/framework-support.d.ts +122 -0
- package/dist/framework-support.d.ts.map +1 -0
- package/dist/framework-support.js +323 -0
- package/dist/framework-support.js.map +1 -0
- package/dist/index.cjs +1355 -24
- package/dist/legal-core/index.cjs +115 -0
- package/dist/legal-core/index.d.ts +160 -0
- package/dist/legal-core/index.d.ts.map +1 -0
- package/dist/legal-core/index.js +220 -0
- package/dist/legal-core/index.js.map +1 -0
- package/dist/marketing-core/index.d.ts +66 -0
- package/dist/marketing-core/index.d.ts.map +1 -0
- package/dist/marketing-core/index.js +154 -0
- package/dist/marketing-core/index.js.map +1 -0
- package/dist/marketing.d.ts +7 -0
- package/dist/marketing.d.ts.map +1 -0
- package/dist/marketing.js +7 -0
- package/dist/marketing.js.map +1 -0
- package/dist/mcp-adapters/index.d.ts +135 -0
- package/dist/mcp-adapters/index.d.ts.map +1 -0
- package/dist/mcp-adapters/index.js +187 -0
- package/dist/mcp-adapters/index.js.map +1 -0
- package/dist/mcp-adapters.d.ts +7 -0
- package/dist/mcp-adapters.d.ts.map +1 -0
- package/dist/mcp-adapters.js +7 -0
- package/dist/mcp-adapters.js.map +1 -0
- package/dist/model3d-core/index.cjs +95 -0
- package/dist/model3d-core/index.d.ts +167 -0
- package/dist/model3d-core/index.d.ts.map +1 -0
- package/dist/model3d-core/index.js +158 -0
- package/dist/model3d-core/index.js.map +1 -0
- package/dist/notifications-core/index.cjs +315 -0
- package/dist/notifications-core/index.d.ts +229 -0
- package/dist/notifications-core/index.d.ts.map +1 -0
- package/dist/notifications-core/index.js +445 -0
- package/dist/notifications-core/index.js.map +1 -0
- package/dist/portal-core/index.d.ts +451 -0
- package/dist/portal-core/index.d.ts.map +1 -0
- package/dist/portal-core/index.js +819 -0
- package/dist/portal-core/index.js.map +1 -0
- package/dist/portal.d.ts +7 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +7 -0
- package/dist/portal.js.map +1 -0
- package/dist/push-core/index.cjs +171 -0
- package/dist/push-core/index.d.ts +149 -0
- package/dist/push-core/index.d.ts.map +1 -0
- package/dist/push-core/index.js +231 -0
- package/dist/push-core/index.js.map +1 -0
- package/dist/react-marketing.d.ts +1 -17
- package/dist/react-marketing.d.ts.map +1 -1
- package/dist/react-marketing.js +4 -0
- package/dist/react-marketing.js.map +1 -1
- package/dist/react.d.ts +294 -101
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +302 -246
- package/dist/react.js.map +1 -1
- package/dist/seed-core/index.d.ts +354 -0
- package/dist/seed-core/index.d.ts.map +1 -0
- package/dist/seed-core/index.js +420 -0
- package/dist/seed-core/index.js.map +1 -0
- package/dist/seed.d.ts +7 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +7 -0
- package/dist/seed.js.map +1 -0
- package/dist/seo-core/blog.d.ts +94 -0
- package/dist/seo-core/blog.d.ts.map +1 -0
- package/dist/seo-core/blog.js +149 -0
- package/dist/seo-core/blog.js.map +1 -0
- package/dist/seo-core/commerce.d.ts +64 -0
- package/dist/seo-core/commerce.d.ts.map +1 -0
- package/dist/seo-core/commerce.js +87 -0
- package/dist/seo-core/commerce.js.map +1 -0
- package/dist/seo-core/index.cjs +751 -0
- package/dist/seo-core/index.d.ts +226 -0
- package/dist/seo-core/index.d.ts.map +1 -0
- package/dist/seo-core/index.js +455 -0
- package/dist/seo-core/index.js.map +1 -0
- package/dist/seo-core/local.d.ts +181 -0
- package/dist/seo-core/local.d.ts.map +1 -0
- package/dist/seo-core/local.js +193 -0
- package/dist/seo-core/local.js.map +1 -0
- package/dist/sitemap-core/index.cjs +167 -0
- package/dist/sitemap-core/index.d.ts +155 -0
- package/dist/sitemap-core/index.d.ts.map +1 -0
- package/dist/sitemap-core/index.js +195 -0
- package/dist/sitemap-core/index.js.map +1 -0
- package/dist/social-core/index.d.ts +74 -0
- package/dist/social-core/index.d.ts.map +1 -0
- package/dist/social-core/index.js +72 -0
- package/dist/social-core/index.js.map +1 -0
- package/dist/social.d.ts +7 -0
- package/dist/social.d.ts.map +1 -0
- package/dist/social.js +7 -0
- package/dist/social.js.map +1 -0
- package/dist/solid-compat.d.ts +204 -0
- package/dist/solid-compat.d.ts.map +1 -0
- package/dist/solid-compat.js +221 -0
- package/dist/solid-compat.js.map +1 -0
- package/dist/store-core/index.d.ts +141 -0
- package/dist/store-core/index.d.ts.map +1 -0
- package/dist/store-core/index.js +277 -0
- package/dist/store-core/index.js.map +1 -0
- package/dist/store.d.ts +12 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +12 -0
- package/dist/store.js.map +1 -0
- package/dist/vanilla.d.ts +111 -0
- package/dist/vanilla.d.ts.map +1 -1
- package/dist/vanilla.js +206 -0
- package/dist/vanilla.js.map +1 -1
- package/dist/verify-core/index.d.ts +98 -0
- package/dist/verify-core/index.d.ts.map +1 -0
- package/dist/verify-core/index.js +186 -0
- package/dist/verify-core/index.js.map +1 -0
- package/dist/verify.d.ts +8 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +8 -0
- package/dist/verify.js.map +1 -0
- package/openapi.json +4516 -1311
- package/package.json +128 -11
- package/src/account-core/index.ts +309 -0
- package/src/account.ts +11 -0
- package/src/angular/headless.ts +519 -0
- package/src/angular/index.ts +3 -0
- package/src/auth-links.ts +76 -0
- package/src/blog-core/index.ts +423 -0
- package/src/blog.ts +11 -0
- package/src/chat-core/index.ts +335 -0
- package/src/chat.ts +11 -0
- package/src/checkout-core/index.ts +225 -0
- package/src/checkout.ts +10 -0
- package/src/cli.ts +184 -28
- package/src/client.ts +1097 -0
- package/src/consent-core/index.ts +213 -0
- package/src/contracts.ts +768 -11
- package/src/data-model-schema.ts +1 -1
- package/src/element.ts +102 -0
- package/src/embed-protocol.ts +100 -0
- package/src/framework-support.ts +440 -0
- package/src/legal-core/index.ts +276 -0
- package/src/marketing-core/index.ts +209 -0
- package/src/marketing.ts +7 -0
- package/src/mcp-adapters/index.ts +264 -0
- package/src/mcp-adapters.ts +7 -0
- package/src/model3d-core/index.ts +248 -0
- package/src/notifications-core/index.ts +650 -0
- package/src/portal-core/index.ts +1564 -0
- package/src/portal.ts +7 -0
- package/src/push-core/index.ts +335 -0
- package/src/qwik.tsx +602 -2
- package/src/react-marketing.tsx +5 -0
- package/src/react.tsx +434 -319
- package/src/seed-core/index.ts +735 -0
- package/src/seed.ts +7 -0
- package/src/seo-core/blog.ts +216 -0
- package/src/seo-core/commerce.ts +138 -0
- package/src/seo-core/index.ts +605 -0
- package/src/seo-core/local.ts +333 -0
- package/src/sitemap-core/index.ts +296 -0
- package/src/social-core/index.ts +103 -0
- package/src/social.ts +7 -0
- package/src/solid-compat.tsx +347 -0
- package/src/solid-surfaces.tsx +1311 -0
- package/src/solid.tsx +82 -60
- package/src/store-core/index.ts +426 -0
- package/src/store.ts +12 -0
- package/src/svelte/SocialLinks.svelte +84 -0
- package/src/svelte/headless.ts +435 -0
- package/src/svelte/index.ts +9 -0
- package/src/vanilla.ts +367 -0
- package/src/verify-core/index.ts +288 -0
- package/src/verify.ts +8 -0
- package/src/vue/headless.ts +527 -0
- package/src/vue/index.ts +3 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BusinessDash service worker.
|
|
3
|
+
*
|
|
4
|
+
* COPY THIS TO THE ROOT OF YOUR OWN SITE, e.g. `public/biab-sw.js`, so it is
|
|
5
|
+
* served from your domain. A push subscription belongs to an origin: a worker
|
|
6
|
+
* on someone else's domain — including ours — cannot receive your visitors'
|
|
7
|
+
* notifications.
|
|
8
|
+
*
|
|
9
|
+
* It must be served from the ROOT to control the whole site. A worker at
|
|
10
|
+
* `/assets/biab-sw.js` can only claim `/assets/` unless the response carries a
|
|
11
|
+
* `Service-Worker-Allowed` header, which is more setup than moving one file.
|
|
12
|
+
*
|
|
13
|
+
* Two responsibilities, and deliberately no `fetch` handler: adding one makes
|
|
14
|
+
* this a controlled-fetch worker with the whole cache lifecycle attached, and
|
|
15
|
+
* offline support should be a decision rather than a side effect of turning on
|
|
16
|
+
* notifications.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
self.addEventListener("install", () => {
|
|
20
|
+
// Take over immediately rather than waiting for every tab to close. A
|
|
21
|
+
// visitor who just granted permission expects it to work now, not after
|
|
22
|
+
// they next quit the browser.
|
|
23
|
+
self.skipWaiting();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
self.addEventListener("activate", (event) => {
|
|
27
|
+
event.waitUntil(self.clients.claim());
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
self.addEventListener("push", (event) => {
|
|
31
|
+
if (!event.data) return;
|
|
32
|
+
|
|
33
|
+
let payload = {};
|
|
34
|
+
try {
|
|
35
|
+
payload = event.data.json();
|
|
36
|
+
} catch {
|
|
37
|
+
// A non-JSON payload is still worth showing. Browsers require a visible
|
|
38
|
+
// notification for every push — staying silent here spends the site's
|
|
39
|
+
// permission budget and can get the subscription revoked.
|
|
40
|
+
payload = { title: event.data.text() };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const title = payload.title || "Notification";
|
|
44
|
+
event.waitUntil(
|
|
45
|
+
Promise.all([
|
|
46
|
+
// Relay to any open tab so the page can render the notification in
|
|
47
|
+
// its OWN toast component. `@businessdash/sdk/notifications` picks
|
|
48
|
+
// this up; a site that does not use it ignores the message and gets
|
|
49
|
+
// the system notification alone, which is the old behaviour.
|
|
50
|
+
self.clients
|
|
51
|
+
.matchAll({ type: "window", includeUncontrolled: true })
|
|
52
|
+
.then((clients) => {
|
|
53
|
+
for (const client of clients) {
|
|
54
|
+
client.postMessage({ type: "businessdash:push", payload });
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {
|
|
58
|
+
// A tab that went away mid-post is not an error worth
|
|
59
|
+
// failing the push over — the system notification below is
|
|
60
|
+
// the delivery that matters.
|
|
61
|
+
}),
|
|
62
|
+
self.registration.showNotification(title, {
|
|
63
|
+
body: payload.body || "",
|
|
64
|
+
icon: payload.icon,
|
|
65
|
+
badge: payload.badge,
|
|
66
|
+
// Same tag replaces rather than stacks — three updates about
|
|
67
|
+
// one order should be one notification, not three.
|
|
68
|
+
tag: payload.tag,
|
|
69
|
+
data: { url: payload.url, ...(payload.data || {}) },
|
|
70
|
+
}),
|
|
71
|
+
]),
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
self.addEventListener("notificationclick", (event) => {
|
|
76
|
+
event.notification.close();
|
|
77
|
+
const url = event.notification.data?.url;
|
|
78
|
+
if (!url) return;
|
|
79
|
+
|
|
80
|
+
event.waitUntil(
|
|
81
|
+
self.clients
|
|
82
|
+
.matchAll({ type: "window", includeUncontrolled: true })
|
|
83
|
+
.then((clients) => {
|
|
84
|
+
// Focus an existing tab on that URL rather than opening a fourth
|
|
85
|
+
// copy of the same page.
|
|
86
|
+
for (const client of clients) {
|
|
87
|
+
if (client.url === url && "focus" in client) return client.focus();
|
|
88
|
+
}
|
|
89
|
+
return self.clients.openWindow(url);
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/account` — headless customer session and followers.
|
|
3
|
+
*
|
|
4
|
+
* Two small controllers that were React-only (plus Solid) and had no reason to
|
|
5
|
+
* be: neither has any framework-specific logic.
|
|
6
|
+
*
|
|
7
|
+
* ## Session
|
|
8
|
+
*
|
|
9
|
+
* `createUserController` reads the auth handler's `/me` route with the session
|
|
10
|
+
* cookie. It never touches an API key — the handler the consumer mounts owns
|
|
11
|
+
* the credential, and this only asks it who is signed in.
|
|
12
|
+
*
|
|
13
|
+
* Sign-in, sign-up and sign-out are navigations, not requests, so they are
|
|
14
|
+
* plain functions over `buildAuthHref` rather than controller actions. Every
|
|
15
|
+
* one of them no-ops outside a browser instead of throwing, so an SSR render
|
|
16
|
+
* that touches them degrades rather than crashes.
|
|
17
|
+
*
|
|
18
|
+
* ## Followers
|
|
19
|
+
*
|
|
20
|
+
* `createFollowersController` wraps subscribe/unsubscribe with the local
|
|
21
|
+
* "this browser already subscribed" hint. The hint is a convenience for hiding
|
|
22
|
+
* a footer form without a round trip — it is NOT authority. `me()` is.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import type { TenantAuthMeResponse } from "../contracts.js";
|
|
27
|
+
export type UserStatus = "loading" | "signed-in" | "signed-out";
|
|
28
|
+
export type UserSnapshot = {
|
|
29
|
+
status: UserStatus;
|
|
30
|
+
user: TenantAuthMeResponse | null;
|
|
31
|
+
};
|
|
32
|
+
export type UserController = {
|
|
33
|
+
snapshot(): UserSnapshot;
|
|
34
|
+
subscribe(callback: (snapshot: UserSnapshot) => void): () => void;
|
|
35
|
+
/** Read `/me`. Called once by `start()`; call again to re-check. */
|
|
36
|
+
refresh(): Promise<UserSnapshot>;
|
|
37
|
+
/** Kick off the first read. Bindings call this on mount. */
|
|
38
|
+
start(): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
};
|
|
41
|
+
export type CreateUserControllerOptions = {
|
|
42
|
+
/** Where `createAuthHandler` is mounted. Defaults to `/api/biab-auth`. */
|
|
43
|
+
basePath?: string;
|
|
44
|
+
/** Injectable for tests; defaults to global `fetch`. */
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
};
|
|
47
|
+
export declare function createUserController(options?: CreateUserControllerOptions): UserController;
|
|
48
|
+
export type ProgrammaticAuthOptions = {
|
|
49
|
+
/** Where to send the customer afterwards. */
|
|
50
|
+
returnTo?: string;
|
|
51
|
+
/** Pre-fill the email on the hosted page (sign-in / sign-up only). */
|
|
52
|
+
loginHint?: string;
|
|
53
|
+
/** Override the auth-handler basePath. */
|
|
54
|
+
basePath?: string;
|
|
55
|
+
};
|
|
56
|
+
/** Href for the auth handler's sign-in route — render it in your own link. */
|
|
57
|
+
export declare function signInHref(options?: ProgrammaticAuthOptions): string;
|
|
58
|
+
/** Href for the auth handler's sign-up route. */
|
|
59
|
+
export declare function signUpHref(options?: ProgrammaticAuthOptions): string;
|
|
60
|
+
/** Href for the auth handler's sign-out route. */
|
|
61
|
+
export declare function signOutHref(options?: {
|
|
62
|
+
basePath?: string;
|
|
63
|
+
}): string;
|
|
64
|
+
/** Navigate to sign-in. No-ops outside a browser. */
|
|
65
|
+
export declare function signIn(options?: ProgrammaticAuthOptions): void;
|
|
66
|
+
/** Navigate to sign-up. No-ops outside a browser. */
|
|
67
|
+
export declare function signUp(options?: ProgrammaticAuthOptions): void;
|
|
68
|
+
/** Navigate to sign-out. No-ops outside a browser. */
|
|
69
|
+
export declare function signOut(options?: {
|
|
70
|
+
basePath?: string;
|
|
71
|
+
}): void;
|
|
72
|
+
export type FollowersCoreClient = {
|
|
73
|
+
followers: {
|
|
74
|
+
join(input: {
|
|
75
|
+
email: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
source?: string;
|
|
78
|
+
}): Promise<unknown>;
|
|
79
|
+
leave(input: {
|
|
80
|
+
email: string;
|
|
81
|
+
}): Promise<unknown>;
|
|
82
|
+
me(input: {
|
|
83
|
+
email: string;
|
|
84
|
+
}): Promise<unknown>;
|
|
85
|
+
edit(input: {
|
|
86
|
+
email: string;
|
|
87
|
+
patch: {
|
|
88
|
+
name?: string;
|
|
89
|
+
source?: string;
|
|
90
|
+
};
|
|
91
|
+
}): Promise<unknown>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
export type FollowersSnapshot = {
|
|
95
|
+
/** This browser already subscribed. A hint for hiding a form, not authority. */
|
|
96
|
+
subscribedLocally: boolean;
|
|
97
|
+
/** The email this browser subscribed with, or `null`. */
|
|
98
|
+
localEmail: string | null;
|
|
99
|
+
isPending: boolean;
|
|
100
|
+
error: Error | null;
|
|
101
|
+
};
|
|
102
|
+
export type FollowersController = {
|
|
103
|
+
snapshot(): FollowersSnapshot;
|
|
104
|
+
subscribe(callback: (snapshot: FollowersSnapshot) => void): () => void;
|
|
105
|
+
join(input: {
|
|
106
|
+
email: string;
|
|
107
|
+
name?: string;
|
|
108
|
+
source?: string;
|
|
109
|
+
}): Promise<unknown>;
|
|
110
|
+
leave(email: string): Promise<unknown>;
|
|
111
|
+
/** Authoritative status for an email — unlike `subscribedLocally`. */
|
|
112
|
+
me(email: string): Promise<unknown>;
|
|
113
|
+
edit(email: string, patch: {
|
|
114
|
+
name?: string;
|
|
115
|
+
source?: string;
|
|
116
|
+
}): Promise<unknown>;
|
|
117
|
+
destroy(): void;
|
|
118
|
+
};
|
|
119
|
+
export type CreateFollowersControllerOptions = {
|
|
120
|
+
client: FollowersCoreClient;
|
|
121
|
+
/** Site id — namespaces the local hint so two sites don't share it. */
|
|
122
|
+
siteId: string;
|
|
123
|
+
onError?: (error: Error) => void;
|
|
124
|
+
};
|
|
125
|
+
export declare function createFollowersController(options: CreateFollowersControllerOptions): FollowersController;
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/account-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAWH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAI5D,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,CAAC;AAEhE,MAAM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AE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,sEAAsE;IACtE,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CACH,KAAK,EAAE,MAAM,EACb,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACvC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,OAAO,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC9C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,gCAAgC,GACvC,mBAAmB,CA6FrB"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/account` — headless customer session and followers.
|
|
3
|
+
*
|
|
4
|
+
* Two small controllers that were React-only (plus Solid) and had no reason to
|
|
5
|
+
* be: neither has any framework-specific logic.
|
|
6
|
+
*
|
|
7
|
+
* ## Session
|
|
8
|
+
*
|
|
9
|
+
* `createUserController` reads the auth handler's `/me` route with the session
|
|
10
|
+
* cookie. It never touches an API key — the handler the consumer mounts owns
|
|
11
|
+
* the credential, and this only asks it who is signed in.
|
|
12
|
+
*
|
|
13
|
+
* Sign-in, sign-up and sign-out are navigations, not requests, so they are
|
|
14
|
+
* plain functions over `buildAuthHref` rather than controller actions. Every
|
|
15
|
+
* one of them no-ops outside a browser instead of throwing, so an SSR render
|
|
16
|
+
* that touches them degrades rather than crashes.
|
|
17
|
+
*
|
|
18
|
+
* ## Followers
|
|
19
|
+
*
|
|
20
|
+
* `createFollowersController` wraps subscribe/unsubscribe with the local
|
|
21
|
+
* "this browser already subscribed" hint. The hint is a convenience for hiding
|
|
22
|
+
* a footer form without a round trip — it is NOT authority. `me()` is.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { buildAuthHref, clearLocalFollow, DEFAULT_AUTH_BASE_PATH, followerStoreKey, readLocalFollow, writeLocalFollow, } from "../auth-links.js";
|
|
27
|
+
export function createUserController(options = {}) {
|
|
28
|
+
const basePath = (options.basePath ?? DEFAULT_AUTH_BASE_PATH).replace(/\/$/, "");
|
|
29
|
+
const doFetch = options.fetchImpl ?? globalThis.fetch;
|
|
30
|
+
let destroyed = false;
|
|
31
|
+
const subscribers = new Set();
|
|
32
|
+
let state = { status: "loading", user: null };
|
|
33
|
+
function notify() {
|
|
34
|
+
if (destroyed)
|
|
35
|
+
return;
|
|
36
|
+
for (const cb of subscribers)
|
|
37
|
+
cb(state);
|
|
38
|
+
}
|
|
39
|
+
async function refresh() {
|
|
40
|
+
if (destroyed)
|
|
41
|
+
return state;
|
|
42
|
+
try {
|
|
43
|
+
const res = await doFetch(`${basePath}/me`, { credentials: "include" });
|
|
44
|
+
const body = res.ok ? (await res.json()) : null;
|
|
45
|
+
if (destroyed)
|
|
46
|
+
return state;
|
|
47
|
+
state = body
|
|
48
|
+
? { status: "signed-in", user: body }
|
|
49
|
+
: { status: "signed-out", user: null };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// A network failure is indistinguishable from "not signed in" from the
|
|
53
|
+
// page's point of view, and treating it as an error would leave every
|
|
54
|
+
// consumer writing the same fallback.
|
|
55
|
+
if (!destroyed)
|
|
56
|
+
state = { status: "signed-out", user: null };
|
|
57
|
+
}
|
|
58
|
+
notify();
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
snapshot: () => state,
|
|
63
|
+
subscribe(callback) {
|
|
64
|
+
subscribers.add(callback);
|
|
65
|
+
return () => {
|
|
66
|
+
subscribers.delete(callback);
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
refresh,
|
|
70
|
+
start() {
|
|
71
|
+
void refresh();
|
|
72
|
+
},
|
|
73
|
+
destroy() {
|
|
74
|
+
destroyed = true;
|
|
75
|
+
subscribers.clear();
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Href for the auth handler's sign-in route — render it in your own link. */
|
|
80
|
+
export function signInHref(options = {}) {
|
|
81
|
+
return buildAuthHref("sign-in", options);
|
|
82
|
+
}
|
|
83
|
+
/** Href for the auth handler's sign-up route. */
|
|
84
|
+
export function signUpHref(options = {}) {
|
|
85
|
+
return buildAuthHref("sign-up", options);
|
|
86
|
+
}
|
|
87
|
+
/** Href for the auth handler's sign-out route. */
|
|
88
|
+
export function signOutHref(options = {}) {
|
|
89
|
+
return buildAuthHref("sign-out", options);
|
|
90
|
+
}
|
|
91
|
+
/** Navigate to sign-in. No-ops outside a browser. */
|
|
92
|
+
export function signIn(options = {}) {
|
|
93
|
+
if (typeof window === "undefined")
|
|
94
|
+
return;
|
|
95
|
+
window.location.assign(signInHref(options));
|
|
96
|
+
}
|
|
97
|
+
/** Navigate to sign-up. No-ops outside a browser. */
|
|
98
|
+
export function signUp(options = {}) {
|
|
99
|
+
if (typeof window === "undefined")
|
|
100
|
+
return;
|
|
101
|
+
window.location.assign(signUpHref(options));
|
|
102
|
+
}
|
|
103
|
+
/** Navigate to sign-out. No-ops outside a browser. */
|
|
104
|
+
export function signOut(options = {}) {
|
|
105
|
+
if (typeof window === "undefined")
|
|
106
|
+
return;
|
|
107
|
+
window.location.assign(signOutHref(options));
|
|
108
|
+
}
|
|
109
|
+
export function createFollowersController(options) {
|
|
110
|
+
const { client, siteId, onError } = options;
|
|
111
|
+
const storeKey = followerStoreKey(siteId);
|
|
112
|
+
let destroyed = false;
|
|
113
|
+
const subscribers = new Set();
|
|
114
|
+
let local = readLocalFollow(storeKey);
|
|
115
|
+
let isPending = false;
|
|
116
|
+
let error = null;
|
|
117
|
+
let cached = null;
|
|
118
|
+
function snapshot() {
|
|
119
|
+
if (!cached) {
|
|
120
|
+
cached = {
|
|
121
|
+
subscribedLocally: local !== null,
|
|
122
|
+
localEmail: local?.email ?? null,
|
|
123
|
+
isPending,
|
|
124
|
+
error,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return cached;
|
|
128
|
+
}
|
|
129
|
+
function notify() {
|
|
130
|
+
if (destroyed)
|
|
131
|
+
return;
|
|
132
|
+
cached = null;
|
|
133
|
+
const next = snapshot();
|
|
134
|
+
for (const cb of subscribers)
|
|
135
|
+
cb(next);
|
|
136
|
+
}
|
|
137
|
+
async function run(work, fallback) {
|
|
138
|
+
isPending = true;
|
|
139
|
+
error = null;
|
|
140
|
+
notify();
|
|
141
|
+
try {
|
|
142
|
+
return await work();
|
|
143
|
+
}
|
|
144
|
+
catch (cause) {
|
|
145
|
+
const err = cause instanceof Error ? cause : new Error(fallback);
|
|
146
|
+
error = err;
|
|
147
|
+
onError?.(err);
|
|
148
|
+
throw err;
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
isPending = false;
|
|
152
|
+
notify();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
snapshot,
|
|
157
|
+
subscribe(callback) {
|
|
158
|
+
subscribers.add(callback);
|
|
159
|
+
return () => {
|
|
160
|
+
subscribers.delete(callback);
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
join(input) {
|
|
164
|
+
return run(async () => {
|
|
165
|
+
const res = await client.followers.join(input);
|
|
166
|
+
local = { email: input.email, at: Date.now() };
|
|
167
|
+
writeLocalFollow(storeKey, local);
|
|
168
|
+
return res;
|
|
169
|
+
}, "Could not subscribe.");
|
|
170
|
+
},
|
|
171
|
+
leave(email) {
|
|
172
|
+
return run(async () => {
|
|
173
|
+
const res = await client.followers.leave({ email });
|
|
174
|
+
clearLocalFollow(storeKey);
|
|
175
|
+
local = null;
|
|
176
|
+
return res;
|
|
177
|
+
}, "Could not unsubscribe.");
|
|
178
|
+
},
|
|
179
|
+
me(email) {
|
|
180
|
+
return run(() => client.followers.me({ email }), "Could not read status.");
|
|
181
|
+
},
|
|
182
|
+
edit(email, patch) {
|
|
183
|
+
return run(() => client.followers.edit({ email, patch }), "Could not update the subscription.");
|
|
184
|
+
},
|
|
185
|
+
destroy() {
|
|
186
|
+
destroyed = true;
|
|
187
|
+
subscribers.clear();
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/account-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACN,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAEhB,eAAe,EACf,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AA6B1B,MAAM,UAAU,oBAAoB,CACnC,UAAuC,EAAE;IAEzC,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,sBAAsB,CAAC,CAAC,OAAO,CACpE,KAAK,EACL,EAAE,CACF,CAAC;IACF,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;IAEtD,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;IACzD,IAAI,KAAK,GAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAE5D,SAAS,MAAM;QACd,IAAI,SAAS;YAAE,OAAO;QACtB,KAAK,MAAM,EAAE,IA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,IAAI,CAAC;YACjB,WAAW,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/account` — the framework-agnostic customer session and
|
|
3
|
+
* followers cores.
|
|
4
|
+
*
|
|
5
|
+
* Source-shipped bindings import through this public subpath, as they do for
|
|
6
|
+
* `forms`, `store`, `chat` and `blog`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
export * from "./account-core/index.js";
|
|
11
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,yBAAyB,CAAC"}
|
package/dist/account.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/account` — the framework-agnostic customer session and
|
|
3
|
+
* followers cores.
|
|
4
|
+
*
|
|
5
|
+
* Source-shipped bindings import through this public subpath, as they do for
|
|
6
|
+
* `forms`, `store`, `chat` and `blog`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
export * from "./account-core/index.js";
|
|
11
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,yBAAyB,CAAC"}
|
package/dist/auth-handler.d.ts
CHANGED
|
@@ -79,13 +79,13 @@ export declare function getTenantSession(input: {
|
|
|
79
79
|
siteOrigin?: string;
|
|
80
80
|
fetch?: BiabDevClientOptions["fetch"];
|
|
81
81
|
}): Promise<{
|
|
82
|
+
role: string | null;
|
|
82
83
|
user: {
|
|
83
84
|
email: string | null;
|
|
84
85
|
id: string;
|
|
85
86
|
firstName: string | null;
|
|
86
87
|
lastName: string | null;
|
|
87
88
|
};
|
|
88
|
-
role: string | null;
|
|
89
89
|
organizationId: string;
|
|
90
90
|
} | null>;
|
|
91
91
|
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL construction for the tenant auth handler, shared by every binding.
|
|
3
|
+
*
|
|
4
|
+
* The handler (`createAuthHandler`) is the one server-side piece a consumer
|
|
5
|
+
* mounts; the sign-in / sign-up / sign-out surfaces in each framework are just
|
|
6
|
+
* links into it. Framework-free so a second binding doesn't fork the
|
|
7
|
+
* query-parameter contract.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/** Where `createAuthHandler` is mounted unless the consumer says otherwise. */
|
|
12
|
+
export declare const DEFAULT_AUTH_BASE_PATH = "/api/biab-auth";
|
|
13
|
+
export type AuthHrefOptions = {
|
|
14
|
+
/** Where to send the user after auth completes. */
|
|
15
|
+
returnTo?: string | undefined;
|
|
16
|
+
/** Pre-fill the email field on the platform-hosted page. */
|
|
17
|
+
loginHint?: string | undefined;
|
|
18
|
+
/** Override the basePath the auth handler is mounted at. */
|
|
19
|
+
basePath?: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
/** Build the href for one of the auth handler's routes. */
|
|
22
|
+
export declare function buildAuthHref(subroute: "sign-in" | "sign-up" | "sign-out", options: AuthHrefOptions): string;
|
|
23
|
+
/** Local-storage bookkeeping for the "this browser already subscribed" hint. */
|
|
24
|
+
export type LocalFollow = {
|
|
25
|
+
email: string;
|
|
26
|
+
at: number;
|
|
27
|
+
};
|
|
28
|
+
export declare const FOLLOWER_STORE_PREFIX = "biab.followers.";
|
|
29
|
+
export declare function followerStoreKey(siteId: string): string;
|
|
30
|
+
export declare function readLocalFollow(key: string): LocalFollow | null;
|
|
31
|
+
export declare function writeLocalFollow(key: string, value: LocalFollow): void;
|
|
32
|
+
export declare function clearLocalFollow(key: string): void;
|
|
33
|
+
//# sourceMappingURL=auth-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-links.d.ts","sourceRoot":"","sources":["../src/auth-links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF,2DAA2D;AAC3D,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,EAC5C,OAAO,EAAE,eAAe,GACtB,MAAM,CAOR;AAED,gFAAgF;AAChF,MAAM,MAAM,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAY/D;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAOtE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAOlD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL construction for the tenant auth handler, shared by every binding.
|
|
3
|
+
*
|
|
4
|
+
* The handler (`createAuthHandler`) is the one server-side piece a consumer
|
|
5
|
+
* mounts; the sign-in / sign-up / sign-out surfaces in each framework are just
|
|
6
|
+
* links into it. Framework-free so a second binding doesn't fork the
|
|
7
|
+
* query-parameter contract.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/** Where `createAuthHandler` is mounted unless the consumer says otherwise. */
|
|
12
|
+
export const DEFAULT_AUTH_BASE_PATH = "/api/biab-auth";
|
|
13
|
+
/** Build the href for one of the auth handler's routes. */
|
|
14
|
+
export function buildAuthHref(subroute, options) {
|
|
15
|
+
const base = (options.basePath ?? DEFAULT_AUTH_BASE_PATH).replace(/\/$/, "");
|
|
16
|
+
const params = new URLSearchParams();
|
|
17
|
+
if (options.returnTo)
|
|
18
|
+
params.set("returnTo", options.returnTo);
|
|
19
|
+
if (options.loginHint)
|
|
20
|
+
params.set("loginHint", options.loginHint);
|
|
21
|
+
const qs = params.toString();
|
|
22
|
+
return `${base}/${subroute}${qs ? `?${qs}` : ""}`;
|
|
23
|
+
}
|
|
24
|
+
export const FOLLOWER_STORE_PREFIX = "biab.followers.";
|
|
25
|
+
export function followerStoreKey(siteId) {
|
|
26
|
+
return `${FOLLOWER_STORE_PREFIX}${siteId}`;
|
|
27
|
+
}
|
|
28
|
+
export function readLocalFollow(key) {
|
|
29
|
+
if (typeof window === "undefined")
|
|
30
|
+
return null;
|
|
31
|
+
try {
|
|
32
|
+
const raw = window.localStorage.getItem(key);
|
|
33
|
+
if (!raw)
|
|
34
|
+
return null;
|
|
35
|
+
const parsed = JSON.parse(raw);
|
|
36
|
+
return typeof parsed?.email === "string"
|
|
37
|
+
? { email: parsed.email, at: Number(parsed.at) || 0 }
|
|
38
|
+
: null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function writeLocalFollow(key, value) {
|
|
45
|
+
if (typeof window === "undefined")
|
|
46
|
+
return;
|
|
47
|
+
try {
|
|
48
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// storage disabled / quota — the local hint is best-effort.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function clearLocalFollow(key) {
|
|
55
|
+
if (typeof window === "undefined")
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
window.localStorage.removeItem(key);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// ignore
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=auth-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-links.js","sourceRoot":"","sources":["../src/auth-links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAWvD,2DAA2D;AAC3D,MAAM,UAAU,aAAa,CAC5B,QAA4C,EAC5C,OAAwB;IAExB,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,sBAAsB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7E,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAI,OAAO,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/D,IAAI,OAAO,CAAC,SAAS;QAAE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAClE,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC7B,OAAO,GAAG,IAAI,IAAI,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACnD,CAAC;AAKD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC9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