@businessdash/sdk 0.9.60 → 0.9.70
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 +1012 -186
- 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 +567 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +807 -1
- package/dist/client.js.map +1 -1
- package/dist/contracts.d.ts +3309 -761
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +541 -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 +1244 -5
- 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 +4316 -1313
- package/package.json +121 -9
- 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 +998 -0
- package/src/contracts.ts +730 -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,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of Solid this SDK uses, written so one binding works on **both**
|
|
3
|
+
* Solid 1 and Solid 2.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists
|
|
6
|
+
*
|
|
7
|
+
* Solid 2 reorganised its public API. Measured against the published packages
|
|
8
|
+
* rather than assumed:
|
|
9
|
+
*
|
|
10
|
+
* | symbol | Solid 1 | Solid 2 |
|
|
11
|
+
* |---|---|---|
|
|
12
|
+
* | `createSignal` `createMemo` `createEffect` | `solid-js` | `solid-js` |
|
|
13
|
+
* | `createContext` `useContext` `onCleanup` | `solid-js` | `solid-js` |
|
|
14
|
+
* | `mapArray` `children` `untrack` | `solid-js` | `solid-js` |
|
|
15
|
+
* | `For` `Show` `Switch` `Match` | `solid-js` | **`@solidjs/web`** |
|
|
16
|
+
* | `onMount` `createUniqueId` `from` | `solid-js` | **gone** |
|
|
17
|
+
* | `Accessor` `JSX` (types) | `solid-js` | **gone** |
|
|
18
|
+
*
|
|
19
|
+
* A static import cannot branch on which version is installed, and the build
|
|
20
|
+
* here is plain `tsc` with no aliasing step — so the two-entry-point trick is
|
|
21
|
+
* not available either. What IS available is the intersection: every primitive
|
|
22
|
+
* in the first three rows exists, unchanged, in both versions.
|
|
23
|
+
*
|
|
24
|
+
* So this module rebuilds the missing pieces on top of that intersection. The
|
|
25
|
+
* binding then imports control flow from here instead of from `solid-js`, and
|
|
26
|
+
* the same compiled output runs on either version.
|
|
27
|
+
*
|
|
28
|
+
* ## Why not just use plain JSX instead
|
|
29
|
+
*
|
|
30
|
+
* `{items().map(...)}` would have been less code. It also throws away `For`'s
|
|
31
|
+
* keyed reconciliation — Solid re-creates every row when the array identity
|
|
32
|
+
* changes, instead of moving the DOM nodes it already has. That is a real
|
|
33
|
+
* performance characteristic of a form renderer with 200 fields, not sugar, so
|
|
34
|
+
* `For` here is built over `mapArray`, which is the same primitive Solid's own
|
|
35
|
+
* `For` uses and which exists in both versions.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* A reactive getter. `Accessor` in Solid 1; nothing in Solid 2, where it is
|
|
41
|
+
* spelled as the plain function type it always was.
|
|
42
|
+
*/
|
|
43
|
+
export type Accessor<T> = () => T;
|
|
44
|
+
/**
|
|
45
|
+
* Anything Solid will render.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately not `JSX.Element`: that type lives in `solid-js` on 1 and in
|
|
48
|
+
* `@solidjs/web` on 2, so naming it would reintroduce the split this module
|
|
49
|
+
* exists to remove. Written structurally instead, as the union both versions
|
|
50
|
+
* accept — measured from their `jsx.d.ts`:
|
|
51
|
+
*
|
|
52
|
+
* Solid 1: `Node | ArrayElement | (string & {}) | number | boolean | null | undefined`
|
|
53
|
+
* Solid 2: `SolidElement | Node | ArrayElement`
|
|
54
|
+
*
|
|
55
|
+
* The function arm matters: every component here returns a `createMemo`, and a
|
|
56
|
+
* memo is a function. Solid renders it lazily, which is what keeps unselected
|
|
57
|
+
* `Switch` branches from evaluating.
|
|
58
|
+
*/
|
|
59
|
+
export type SolidNode = unknown;
|
|
60
|
+
/**
|
|
61
|
+
* Hand a `SolidNode` back to JSX.
|
|
62
|
+
*
|
|
63
|
+
* One cast, in one place, and it is unavoidable rather than lazy: the two
|
|
64
|
+
* versions disagree about what `JSX.Element` IS — Solid 2 adds a
|
|
65
|
+
* `RenderedElement` arm Solid 1 has never heard of — so no single named type
|
|
66
|
+
* is assignable in both directions. Accepting children permissively and
|
|
67
|
+
* narrowing once at the boundary is what Solid's own components do, and it
|
|
68
|
+
* keeps the cast auditable instead of scattering `as` through the render tree.
|
|
69
|
+
*/
|
|
70
|
+
export declare function renderNode(node: SolidNode): Node;
|
|
71
|
+
/**
|
|
72
|
+
* What these components RETURN.
|
|
73
|
+
*
|
|
74
|
+
* `Node` rather than `SolidNode`, because TypeScript checks a component's
|
|
75
|
+
* return type against the installed version's `JSX.Element`, and `Node` is the
|
|
76
|
+
* only arm those two unions share:
|
|
77
|
+
*
|
|
78
|
+
* Solid 1: `Node | ArrayElement | (string & {}) | number | boolean | null | undefined`
|
|
79
|
+
* Solid 2: `SolidElement | Node | ArrayElement`
|
|
80
|
+
*
|
|
81
|
+
* The values really returned are memos — functions — which Solid renders
|
|
82
|
+
* lazily. Solid's own `For` does the same thing and casts for the same reason;
|
|
83
|
+
* the cast is at the JSX boundary only, and every value flowing THROUGH these
|
|
84
|
+
* components stays typed as `SolidNode`.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* An inline style object.
|
|
88
|
+
*
|
|
89
|
+
* `JSX.CSSProperties` lives in `solid-js` on Solid 1 and `@solidjs/web` on
|
|
90
|
+
* Solid 2, so naming it would reintroduce the split. Solid accepts a plain
|
|
91
|
+
* record of CSS property names to values, which is all these are.
|
|
92
|
+
*/
|
|
93
|
+
export type SolidStyle = Record<string, string | number | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Keyed list rendering.
|
|
96
|
+
*
|
|
97
|
+
* `mapArray` is the primitive under Solid's own `For` and is exported by both
|
|
98
|
+
* versions, so this keeps the reconciliation behaviour rather than degrading
|
|
99
|
+
* to a re-render on every array identity change.
|
|
100
|
+
*/
|
|
101
|
+
export declare function For<T>(props: {
|
|
102
|
+
each: readonly T[] | undefined | null;
|
|
103
|
+
children: (item: T, index: Accessor<number>) => SolidNode;
|
|
104
|
+
}): Node;
|
|
105
|
+
/**
|
|
106
|
+
* Conditional rendering.
|
|
107
|
+
*
|
|
108
|
+
* The children are only evaluated when the condition holds, which is the whole
|
|
109
|
+
* point — an eagerly-evaluated branch would run effects and fetches for UI
|
|
110
|
+
* nobody is looking at.
|
|
111
|
+
*/
|
|
112
|
+
export declare function Show<T>(props: {
|
|
113
|
+
when: T | undefined | null | false;
|
|
114
|
+
fallback?: SolidNode;
|
|
115
|
+
children: (item: Accessor<NonNullable<T>>) => SolidNode;
|
|
116
|
+
}): Node;
|
|
117
|
+
export declare function Show<T>(props: {
|
|
118
|
+
when: T | undefined | null | false;
|
|
119
|
+
fallback?: SolidNode;
|
|
120
|
+
children: SolidNode;
|
|
121
|
+
}): Node;
|
|
122
|
+
/**
|
|
123
|
+
* One branch of a `Switch`.
|
|
124
|
+
*
|
|
125
|
+
* Returns a descriptor rather than DOM. `children` is a GETTER so the branch
|
|
126
|
+
* body is not evaluated unless `Switch` picks it — Solid's props are lazy, and
|
|
127
|
+
* forwarding that laziness is what keeps unselected branches inert.
|
|
128
|
+
*/
|
|
129
|
+
export declare function Match(props: {
|
|
130
|
+
when: unknown;
|
|
131
|
+
children: SolidNode;
|
|
132
|
+
}): Node;
|
|
133
|
+
/**
|
|
134
|
+
* First matching branch wins, else `fallback`.
|
|
135
|
+
*
|
|
136
|
+
* `children()` resolves the JSX children — which invokes each `Match` and
|
|
137
|
+
* yields its marker — and the memo re-picks whenever any `when` changes.
|
|
138
|
+
*/
|
|
139
|
+
export declare function Switch(props: {
|
|
140
|
+
fallback?: SolidNode;
|
|
141
|
+
children: SolidNode;
|
|
142
|
+
}): Node;
|
|
143
|
+
/**
|
|
144
|
+
* Run once, after the first render.
|
|
145
|
+
*
|
|
146
|
+
* Solid 2 dropped `onMount`; it was always `createEffect` with the body
|
|
147
|
+
* untracked and a guard. Written out rather than imported so the binding does
|
|
148
|
+
* not care which version it is on.
|
|
149
|
+
*/
|
|
150
|
+
export declare function onMount(fn: () => void): void;
|
|
151
|
+
/**
|
|
152
|
+
* The provider component for a context, on either Solid version.
|
|
153
|
+
*
|
|
154
|
+
* Solid 1 hangs a `.Provider` off the context object. Solid 2 makes the
|
|
155
|
+
* context object **its own provider** — you write `<Ctx value={x}>` where you
|
|
156
|
+
* used to write `<Ctx.Provider value={x}>`.
|
|
157
|
+
*
|
|
158
|
+
* Unlike the import differences, this one CAN be resolved at runtime: the
|
|
159
|
+
* shape is inspectable. `.Provider` when it exists, the context itself
|
|
160
|
+
* otherwise.
|
|
161
|
+
*/
|
|
162
|
+
export declare function providerFor<T>(context: unknown): (props: {
|
|
163
|
+
value: T;
|
|
164
|
+
children: SolidNode;
|
|
165
|
+
}) => Node;
|
|
166
|
+
/**
|
|
167
|
+
* Build a `class` string from a base plus conditional modifiers.
|
|
168
|
+
*
|
|
169
|
+
* Replaces Solid 1's `classList={{ "mod": cond }}`, which Solid 2 removed —
|
|
170
|
+
* verified against both versions' `jsx.d.ts`, where `classList` is declared in
|
|
171
|
+
* 1 and absent in 2.
|
|
172
|
+
*
|
|
173
|
+
* A plain `class` string behaves identically on both, so this is the portable
|
|
174
|
+
* spelling rather than a workaround.
|
|
175
|
+
*/
|
|
176
|
+
export declare function cx(base: string | undefined, modifiers?: Record<string, boolean | undefined>): string;
|
|
177
|
+
/**
|
|
178
|
+
* A stable id for `for`/`aria-*` pairs.
|
|
179
|
+
*
|
|
180
|
+
* Solid 2 dropped `createUniqueId`. A module-level counter is enough here
|
|
181
|
+
* because these ids are only ever used to link a label to its own input within
|
|
182
|
+
* one document — they are not persisted, sent anywhere, or compared across
|
|
183
|
+
* renders.
|
|
184
|
+
*
|
|
185
|
+
* The `biab-` prefix keeps them from colliding with ids the consumer's own
|
|
186
|
+
* page already uses.
|
|
187
|
+
*/
|
|
188
|
+
export declare function createUniqueId(): string;
|
|
189
|
+
/**
|
|
190
|
+
* Bridge an external store into a signal.
|
|
191
|
+
*
|
|
192
|
+
* Replaces Solid 1's `from`, which Solid 2 dropped. The shape is exactly what
|
|
193
|
+
* every shared core exposes — `snapshot()` / `subscribe()` / `destroy()` — so
|
|
194
|
+
* this is the one seam where the framework-agnostic controllers meet Solid.
|
|
195
|
+
*
|
|
196
|
+
* `subscribe` does NOT replay, so the initial value is read separately. A
|
|
197
|
+
* bridge that waited for the first notification would render empty until
|
|
198
|
+
* something happened to change, which on a quiet screen is forever.
|
|
199
|
+
*/
|
|
200
|
+
export declare function fromStore<T>(store: {
|
|
201
|
+
snapshot: () => T;
|
|
202
|
+
subscribe: (listener: () => void) => () => void;
|
|
203
|
+
}): Accessor<T>;
|
|
204
|
+
//# sourceMappingURL=solid-compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-compat.d.ts","sourceRoot":"","sources":["../src/solid-compat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAWH;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAElC;;;;;;;;;;;;;;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AE;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACpB,GAAG,IAAI,CAUP;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAO5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,OAAO,EAAE,OAAO,GACd,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,KAAK,IAAI,CAQpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,EAAE,CACjB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,GAC7C,MAAM,CAQR;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAGvC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE;IACnC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAChD,GAAG,QAAQ,CAAC,CAAC,CAAC,CAqBd"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of Solid this SDK uses, written so one binding works on **both**
|
|
3
|
+
* Solid 1 and Solid 2.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists
|
|
6
|
+
*
|
|
7
|
+
* Solid 2 reorganised its public API. Measured against the published packages
|
|
8
|
+
* rather than assumed:
|
|
9
|
+
*
|
|
10
|
+
* | symbol | Solid 1 | Solid 2 |
|
|
11
|
+
* |---|---|---|
|
|
12
|
+
* | `createSignal` `createMemo` `createEffect` | `solid-js` | `solid-js` |
|
|
13
|
+
* | `createContext` `useContext` `onCleanup` | `solid-js` | `solid-js` |
|
|
14
|
+
* | `mapArray` `children` `untrack` | `solid-js` | `solid-js` |
|
|
15
|
+
* | `For` `Show` `Switch` `Match` | `solid-js` | **`@solidjs/web`** |
|
|
16
|
+
* | `onMount` `createUniqueId` `from` | `solid-js` | **gone** |
|
|
17
|
+
* | `Accessor` `JSX` (types) | `solid-js` | **gone** |
|
|
18
|
+
*
|
|
19
|
+
* A static import cannot branch on which version is installed, and the build
|
|
20
|
+
* here is plain `tsc` with no aliasing step — so the two-entry-point trick is
|
|
21
|
+
* not available either. What IS available is the intersection: every primitive
|
|
22
|
+
* in the first three rows exists, unchanged, in both versions.
|
|
23
|
+
*
|
|
24
|
+
* So this module rebuilds the missing pieces on top of that intersection. The
|
|
25
|
+
* binding then imports control flow from here instead of from `solid-js`, and
|
|
26
|
+
* the same compiled output runs on either version.
|
|
27
|
+
*
|
|
28
|
+
* ## Why not just use plain JSX instead
|
|
29
|
+
*
|
|
30
|
+
* `{items().map(...)}` would have been less code. It also throws away `For`'s
|
|
31
|
+
* keyed reconciliation — Solid re-creates every row when the array identity
|
|
32
|
+
* changes, instead of moving the DOM nodes it already has. That is a real
|
|
33
|
+
* performance characteristic of a form renderer with 200 fields, not sugar, so
|
|
34
|
+
* `For` here is built over `mapArray`, which is the same primitive Solid's own
|
|
35
|
+
* `For` uses and which exists in both versions.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
38
|
+
*/
|
|
39
|
+
import { children, createMemo, createSignal, mapArray, onCleanup, untrack, } from "solid-js";
|
|
40
|
+
/**
|
|
41
|
+
* Hand a `SolidNode` back to JSX.
|
|
42
|
+
*
|
|
43
|
+
* One cast, in one place, and it is unavoidable rather than lazy: the two
|
|
44
|
+
* versions disagree about what `JSX.Element` IS — Solid 2 adds a
|
|
45
|
+
* `RenderedElement` arm Solid 1 has never heard of — so no single named type
|
|
46
|
+
* is assignable in both directions. Accepting children permissively and
|
|
47
|
+
* narrowing once at the boundary is what Solid's own components do, and it
|
|
48
|
+
* keeps the cast auditable instead of scattering `as` through the render tree.
|
|
49
|
+
*/
|
|
50
|
+
export function renderNode(node) {
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Keyed list rendering.
|
|
55
|
+
*
|
|
56
|
+
* `mapArray` is the primitive under Solid's own `For` and is exported by both
|
|
57
|
+
* versions, so this keeps the reconciliation behaviour rather than degrading
|
|
58
|
+
* to a re-render on every array identity change.
|
|
59
|
+
*/
|
|
60
|
+
export function For(props) {
|
|
61
|
+
// `props.each` is read inside the memo so the list stays reactive; reading
|
|
62
|
+
// it here would snapshot it once and never update.
|
|
63
|
+
const mapped = createMemo(mapArray(() => props.each ?? [], (item, index) => props.children(item, index)));
|
|
64
|
+
return mapped;
|
|
65
|
+
}
|
|
66
|
+
export function Show(props) {
|
|
67
|
+
const condition = createMemo(() => props.when);
|
|
68
|
+
return createMemo(() => {
|
|
69
|
+
const value = condition();
|
|
70
|
+
if (!value)
|
|
71
|
+
return props.fallback;
|
|
72
|
+
const body = props.children;
|
|
73
|
+
if (typeof body !== "function")
|
|
74
|
+
return body;
|
|
75
|
+
// An accessor, matching Solid's own signature: the child is written as
|
|
76
|
+
// `{(item) => <b>{item()}</b>}` and calling it keeps the read tracked
|
|
77
|
+
// inside the child rather than at the boundary.
|
|
78
|
+
const accessor = () => condition();
|
|
79
|
+
return untrack(() => body(accessor));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function isMatchMarker(value) {
|
|
83
|
+
return (typeof value === "object" &&
|
|
84
|
+
value !== null &&
|
|
85
|
+
value.__biabMatch === true);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One branch of a `Switch`.
|
|
89
|
+
*
|
|
90
|
+
* Returns a descriptor rather than DOM. `children` is a GETTER so the branch
|
|
91
|
+
* body is not evaluated unless `Switch` picks it — Solid's props are lazy, and
|
|
92
|
+
* forwarding that laziness is what keeps unselected branches inert.
|
|
93
|
+
*/
|
|
94
|
+
export function Match(props) {
|
|
95
|
+
const marker = {
|
|
96
|
+
__biabMatch: true,
|
|
97
|
+
get when() {
|
|
98
|
+
return props.when;
|
|
99
|
+
},
|
|
100
|
+
get children() {
|
|
101
|
+
return props.children;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
return marker;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* First matching branch wins, else `fallback`.
|
|
108
|
+
*
|
|
109
|
+
* `children()` resolves the JSX children — which invokes each `Match` and
|
|
110
|
+
* yields its marker — and the memo re-picks whenever any `when` changes.
|
|
111
|
+
*/
|
|
112
|
+
export function Switch(props) {
|
|
113
|
+
const resolved = children(() => props.children);
|
|
114
|
+
return createMemo(() => {
|
|
115
|
+
const list = resolved.toArray();
|
|
116
|
+
for (const entry of list) {
|
|
117
|
+
if (!isMatchMarker(entry))
|
|
118
|
+
continue;
|
|
119
|
+
if (entry.when)
|
|
120
|
+
return entry.children;
|
|
121
|
+
}
|
|
122
|
+
return props.fallback;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Run once, after the first render.
|
|
127
|
+
*
|
|
128
|
+
* Solid 2 dropped `onMount`; it was always `createEffect` with the body
|
|
129
|
+
* untracked and a guard. Written out rather than imported so the binding does
|
|
130
|
+
* not care which version it is on.
|
|
131
|
+
*/
|
|
132
|
+
export function onMount(fn) {
|
|
133
|
+
const [mounted, setMounted] = createSignal(false);
|
|
134
|
+
createMemo(() => {
|
|
135
|
+
if (mounted())
|
|
136
|
+
return;
|
|
137
|
+
setMounted(true);
|
|
138
|
+
untrack(fn);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The provider component for a context, on either Solid version.
|
|
143
|
+
*
|
|
144
|
+
* Solid 1 hangs a `.Provider` off the context object. Solid 2 makes the
|
|
145
|
+
* context object **its own provider** — you write `<Ctx value={x}>` where you
|
|
146
|
+
* used to write `<Ctx.Provider value={x}>`.
|
|
147
|
+
*
|
|
148
|
+
* Unlike the import differences, this one CAN be resolved at runtime: the
|
|
149
|
+
* shape is inspectable. `.Provider` when it exists, the context itself
|
|
150
|
+
* otherwise.
|
|
151
|
+
*/
|
|
152
|
+
export function providerFor(context) {
|
|
153
|
+
const withProvider = context;
|
|
154
|
+
return (withProvider.Provider ??
|
|
155
|
+
context);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build a `class` string from a base plus conditional modifiers.
|
|
159
|
+
*
|
|
160
|
+
* Replaces Solid 1's `classList={{ "mod": cond }}`, which Solid 2 removed —
|
|
161
|
+
* verified against both versions' `jsx.d.ts`, where `classList` is declared in
|
|
162
|
+
* 1 and absent in 2.
|
|
163
|
+
*
|
|
164
|
+
* A plain `class` string behaves identically on both, so this is the portable
|
|
165
|
+
* spelling rather than a workaround.
|
|
166
|
+
*/
|
|
167
|
+
export function cx(base, modifiers) {
|
|
168
|
+
const parts = base ? [base] : [];
|
|
169
|
+
if (modifiers) {
|
|
170
|
+
for (const [name, on] of Object.entries(modifiers)) {
|
|
171
|
+
if (on)
|
|
172
|
+
parts.push(name);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return parts.join(" ");
|
|
176
|
+
}
|
|
177
|
+
let uniqueIdCounter = 0;
|
|
178
|
+
/**
|
|
179
|
+
* A stable id for `for`/`aria-*` pairs.
|
|
180
|
+
*
|
|
181
|
+
* Solid 2 dropped `createUniqueId`. A module-level counter is enough here
|
|
182
|
+
* because these ids are only ever used to link a label to its own input within
|
|
183
|
+
* one document — they are not persisted, sent anywhere, or compared across
|
|
184
|
+
* renders.
|
|
185
|
+
*
|
|
186
|
+
* The `biab-` prefix keeps them from colliding with ids the consumer's own
|
|
187
|
+
* page already uses.
|
|
188
|
+
*/
|
|
189
|
+
export function createUniqueId() {
|
|
190
|
+
uniqueIdCounter += 1;
|
|
191
|
+
return `biab-${uniqueIdCounter}`;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Bridge an external store into a signal.
|
|
195
|
+
*
|
|
196
|
+
* Replaces Solid 1's `from`, which Solid 2 dropped. The shape is exactly what
|
|
197
|
+
* every shared core exposes — `snapshot()` / `subscribe()` / `destroy()` — so
|
|
198
|
+
* this is the one seam where the framework-agnostic controllers meet Solid.
|
|
199
|
+
*
|
|
200
|
+
* `subscribe` does NOT replay, so the initial value is read separately. A
|
|
201
|
+
* bridge that waited for the first notification would render empty until
|
|
202
|
+
* something happened to change, which on a quiet screen is forever.
|
|
203
|
+
*/
|
|
204
|
+
export function fromStore(store) {
|
|
205
|
+
// Boxed, and not for tidiness: Solid 2 types the value overload of
|
|
206
|
+
// `createSignal` as `Exclude<T, Function>`, because a bare function
|
|
207
|
+
// argument is read as a compute function instead of a value. A snapshot
|
|
208
|
+
// type that could be callable is therefore rejected outright. A wrapper
|
|
209
|
+
// object is never a Function, so the same call compiles on both versions
|
|
210
|
+
// and cannot be mistaken for a computation.
|
|
211
|
+
const [box, setBox] = createSignal({ value: store.snapshot() }, {
|
|
212
|
+
// Snapshots are replaced wholesale, and two structurally-equal
|
|
213
|
+
// snapshots are still a real update to the controller. Comparing
|
|
214
|
+
// would drop legitimate notifications.
|
|
215
|
+
equals: false,
|
|
216
|
+
});
|
|
217
|
+
const unsubscribe = store.subscribe(() => setBox({ value: store.snapshot() }));
|
|
218
|
+
onCleanup(unsubscribe);
|
|
219
|
+
return () => box().value;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=solid-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-compat.js","sourceRoot":"","sources":["../src/solid-compat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EACN,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,OAAO,GACP,MAAM,UAAU,CAAC;AAyBlB;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,IAAe;IACzC,OAAO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
|
5
|
+
*
|
|
6
|
+
* Until now the only storefront the SDK offered was `<Storefront>`: a
|
|
7
|
+
* BusinessDash-hosted page in a sandboxed iframe. It works, and it ships fast,
|
|
8
|
+
* but it renders OUR markup inside YOUR app — your design system stops at the
|
|
9
|
+
* iframe boundary, and there is no way to put a product card in your own grid.
|
|
10
|
+
* That was true in every binding, React included.
|
|
11
|
+
*
|
|
12
|
+
* This is the native path. It owns all of the behaviour — pagination, category
|
|
13
|
+
* filtering, the cart, coupons, the product detail — and none of the markup.
|
|
14
|
+
* Exactly the split `createFormController` already uses for forms: one
|
|
15
|
+
* framework-agnostic controller, and a thin reactive view per framework.
|
|
16
|
+
*
|
|
17
|
+
* A binding subscribes to `snapshot()` and renders it. That is the whole
|
|
18
|
+
* contract, and it is why React, Solid, Vue, Svelte, Qwik, Angular and plain
|
|
19
|
+
* DOM can each expose a native storefront without any of them reimplementing
|
|
20
|
+
* what "add to cart" means.
|
|
21
|
+
*
|
|
22
|
+
* ## Money
|
|
23
|
+
*
|
|
24
|
+
* Every price crossing this boundary is an INTEGER of the currency's minor unit
|
|
25
|
+
* — cents for USD. The controller never divides, rounds or formats: it passes
|
|
26
|
+
* what the API sent straight to your renderer. Format at the edge, where you
|
|
27
|
+
* know the locale.
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
import type { CartAddItemInput, CartSnapshot, StorefrontCategory, StorefrontProductDetail, StorefrontProductRow } from "../contracts.js";
|
|
32
|
+
/**
|
|
33
|
+
* The client surface this controller needs. Declared structurally rather than
|
|
34
|
+
* importing `BiabDevClient`, so a consumer can hand in a same-origin proxy, a
|
|
35
|
+
* test double, or a narrowed client without the controller caring.
|
|
36
|
+
*/
|
|
37
|
+
export type StoreCoreClient = {
|
|
38
|
+
storefront: {
|
|
39
|
+
listProducts(input?: {
|
|
40
|
+
limit?: number;
|
|
41
|
+
cursor?: number | null;
|
|
42
|
+
categoryId?: string;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
items: StorefrontProductRow[];
|
|
45
|
+
nextCursor: number | null;
|
|
46
|
+
}>;
|
|
47
|
+
listCategories(): Promise<{
|
|
48
|
+
items: StorefrontCategory[];
|
|
49
|
+
}>;
|
|
50
|
+
getProduct(productId: string): Promise<StorefrontProductDetail>;
|
|
51
|
+
};
|
|
52
|
+
cart: {
|
|
53
|
+
get(): Promise<CartSnapshot>;
|
|
54
|
+
addItem(input: CartAddItemInput): Promise<CartSnapshot>;
|
|
55
|
+
updateItem(itemId: string, input: {
|
|
56
|
+
quantity: number;
|
|
57
|
+
}): Promise<CartSnapshot>;
|
|
58
|
+
removeItem(itemId: string): Promise<CartSnapshot>;
|
|
59
|
+
applyCoupon(input: {
|
|
60
|
+
code: string;
|
|
61
|
+
}): Promise<CartSnapshot>;
|
|
62
|
+
removeCoupon(): Promise<CartSnapshot>;
|
|
63
|
+
clear(): Promise<CartSnapshot>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export type StoreStatus = "idle" | "loading" | "ready" | "error";
|
|
67
|
+
/**
|
|
68
|
+
* What a binding renders. Field names are STABLE and load-bearing for every
|
|
69
|
+
* framework binding — renaming one is a breaking change in eight places.
|
|
70
|
+
*/
|
|
71
|
+
export type StoreSnapshot = {
|
|
72
|
+
status: StoreStatus;
|
|
73
|
+
/** The current page of products, accumulated across `loadMore()`. */
|
|
74
|
+
products: readonly StorefrontProductRow[];
|
|
75
|
+
categories: readonly StorefrontCategory[];
|
|
76
|
+
/** `null` until the first cart read resolves. */
|
|
77
|
+
cart: CartSnapshot | null;
|
|
78
|
+
/** The product opened via `openProduct()`, if any. */
|
|
79
|
+
activeProduct: StorefrontProductDetail | null;
|
|
80
|
+
/** Active category filter, or `null` for everything. */
|
|
81
|
+
categoryId: string | null;
|
|
82
|
+
/** Whether `loadMore()` would fetch anything. */
|
|
83
|
+
hasMore: boolean;
|
|
84
|
+
/** Last failure. Cleared on the next successful action. */
|
|
85
|
+
error: Error | null;
|
|
86
|
+
/**
|
|
87
|
+
* In-flight work, so a binding can disable a button without inventing its
|
|
88
|
+
* own loading state. `cart` covers every mutation — add, update, remove,
|
|
89
|
+
* coupon, clear — because they all serialise onto the same cart.
|
|
90
|
+
*/
|
|
91
|
+
pending: {
|
|
92
|
+
products: boolean;
|
|
93
|
+
categories: boolean;
|
|
94
|
+
product: boolean;
|
|
95
|
+
cart: boolean;
|
|
96
|
+
};
|
|
97
|
+
/** Convenience mirrors of `cart`, so a badge doesn't need a null check. */
|
|
98
|
+
itemCount: number;
|
|
99
|
+
subtotal: number;
|
|
100
|
+
currency: string | null;
|
|
101
|
+
};
|
|
102
|
+
export type StoreController = {
|
|
103
|
+
snapshot(): StoreSnapshot;
|
|
104
|
+
/**
|
|
105
|
+
* Subscribe to snapshot changes. Returns an unsubscribe function. The
|
|
106
|
+
* callback is NOT invoked on subscribe — read `snapshot()` for the initial
|
|
107
|
+
* value, the same contract `createFormController` uses.
|
|
108
|
+
*/
|
|
109
|
+
subscribe(callback: (snapshot: StoreSnapshot) => void): () => void;
|
|
110
|
+
/** Fetch products, categories and the cart. Safe to call more than once. */
|
|
111
|
+
load(): Promise<void>;
|
|
112
|
+
/** Append the next page. No-op when `hasMore` is false or a page is in flight. */
|
|
113
|
+
loadMore(): Promise<void>;
|
|
114
|
+
/** Filter by category (or `null` for all) and reset pagination. */
|
|
115
|
+
filterByCategory(categoryId: string | null): Promise<void>;
|
|
116
|
+
/** Load one product's detail into `activeProduct`. */
|
|
117
|
+
openProduct(productId: string): Promise<void>;
|
|
118
|
+
closeProduct(): void;
|
|
119
|
+
addToCart(input: CartAddItemInput): Promise<void>;
|
|
120
|
+
/** Quantity 0 removes the line, matching the API's own semantics. */
|
|
121
|
+
updateQuantity(itemId: string, quantity: number): Promise<void>;
|
|
122
|
+
removeItem(itemId: string): Promise<void>;
|
|
123
|
+
applyCoupon(code: string): Promise<void>;
|
|
124
|
+
removeCoupon(): Promise<void>;
|
|
125
|
+
clearCart(): Promise<void>;
|
|
126
|
+
/** Re-read the cart without touching products. */
|
|
127
|
+
refreshCart(): Promise<void>;
|
|
128
|
+
/** Stop notifying and drop all subscribers. */
|
|
129
|
+
destroy(): void;
|
|
130
|
+
};
|
|
131
|
+
export type CreateStoreControllerOptions = {
|
|
132
|
+
client: StoreCoreClient;
|
|
133
|
+
/** Products per page. Default 24. */
|
|
134
|
+
pageSize?: number;
|
|
135
|
+
/** Start filtered to a category. */
|
|
136
|
+
categoryId?: string | null;
|
|
137
|
+
/** Called on every failure, in addition to landing in `snapshot().error`. */
|
|
138
|
+
onError?: (error: Error) => void;
|
|
139
|
+
};
|
|
140
|
+
export declare function createStoreController(options: CreateStoreControllerOptions): StoreController;
|
|
141
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AAEzB;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE;QACX,YAAY,CAAC,KAAK,CAAC,EAAE;YACpB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YACvB,UAAU,CAAC,EAAE,MAAM,CAAC;SACpB,GAAG,OAAO,CAAC;YAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;YAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAC,CAAC;QAC1E,cAAc,IAAI,OAAO,CAAC;YAAE,KAAK,EAAE,kBAAkB,EAAE,CAAA;SAAE,CAAC,CAAC;QAC3D,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;KAChE,CA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