@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,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/store` — the headless storefront + cart controller.
|
|
3
|
+
*
|
|
4
|
+
* ## Why this exists
|
|
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
|
+
const DEFAULT_PAGE_SIZE = 24;
|
|
32
|
+
function toError(cause, fallback) {
|
|
33
|
+
return cause instanceof Error ? cause : new Error(fallback);
|
|
34
|
+
}
|
|
35
|
+
export function createStoreController(options) {
|
|
36
|
+
const { client, onError } = options;
|
|
37
|
+
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
38
|
+
let destroyed = false;
|
|
39
|
+
let cursor = null;
|
|
40
|
+
/**
|
|
41
|
+
* Guards against a stale page landing after the category changed. Every
|
|
42
|
+
* product fetch captures the token it started under and drops its result if
|
|
43
|
+
* the token moved on — otherwise clicking two categories quickly can leave
|
|
44
|
+
* the second one's products under the first one's heading.
|
|
45
|
+
*/
|
|
46
|
+
let requestToken = 0;
|
|
47
|
+
const subscribers = new Set();
|
|
48
|
+
const state = {
|
|
49
|
+
status: "idle",
|
|
50
|
+
products: [],
|
|
51
|
+
categories: [],
|
|
52
|
+
cart: null,
|
|
53
|
+
activeProduct: null,
|
|
54
|
+
categoryId: options.categoryId ?? null,
|
|
55
|
+
hasMore: false,
|
|
56
|
+
error: null,
|
|
57
|
+
pending: {
|
|
58
|
+
products: false,
|
|
59
|
+
categories: false,
|
|
60
|
+
product: false,
|
|
61
|
+
cart: false,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
let cached = null;
|
|
65
|
+
function snapshot() {
|
|
66
|
+
if (!cached) {
|
|
67
|
+
cached = {
|
|
68
|
+
status: state.status,
|
|
69
|
+
products: state.products,
|
|
70
|
+
categories: state.categories,
|
|
71
|
+
cart: state.cart,
|
|
72
|
+
activeProduct: state.activeProduct,
|
|
73
|
+
categoryId: state.categoryId,
|
|
74
|
+
hasMore: state.hasMore,
|
|
75
|
+
error: state.error,
|
|
76
|
+
pending: state.pending,
|
|
77
|
+
itemCount: state.cart?.itemCount ?? 0,
|
|
78
|
+
subtotal: state.cart?.subtotal ?? 0,
|
|
79
|
+
currency: state.cart?.currency ?? null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return cached;
|
|
83
|
+
}
|
|
84
|
+
function notify() {
|
|
85
|
+
if (destroyed)
|
|
86
|
+
return;
|
|
87
|
+
cached = null;
|
|
88
|
+
const next = snapshot();
|
|
89
|
+
for (const cb of subscribers)
|
|
90
|
+
cb(next);
|
|
91
|
+
}
|
|
92
|
+
function fail(cause, fallback) {
|
|
93
|
+
const error = toError(cause, fallback);
|
|
94
|
+
state.error = error;
|
|
95
|
+
if (state.status !== "ready")
|
|
96
|
+
state.status = "error";
|
|
97
|
+
onError?.(error);
|
|
98
|
+
}
|
|
99
|
+
/** Run a cart mutation, keeping `pending.cart` honest even on failure. */
|
|
100
|
+
async function cartAction(run, fallback) {
|
|
101
|
+
if (destroyed)
|
|
102
|
+
return;
|
|
103
|
+
state.pending.cart = true;
|
|
104
|
+
state.error = null;
|
|
105
|
+
notify();
|
|
106
|
+
try {
|
|
107
|
+
const cart = await run();
|
|
108
|
+
if (destroyed)
|
|
109
|
+
return;
|
|
110
|
+
state.cart = cart;
|
|
111
|
+
}
|
|
112
|
+
catch (cause) {
|
|
113
|
+
if (destroyed)
|
|
114
|
+
return;
|
|
115
|
+
fail(cause, fallback);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
if (!destroyed) {
|
|
119
|
+
state.pending.cart = false;
|
|
120
|
+
notify();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function fetchProducts(append) {
|
|
125
|
+
const token = ++requestToken;
|
|
126
|
+
state.pending.products = true;
|
|
127
|
+
if (!append)
|
|
128
|
+
state.error = null;
|
|
129
|
+
notify();
|
|
130
|
+
try {
|
|
131
|
+
const page = await client.storefront.listProducts({
|
|
132
|
+
limit: pageSize,
|
|
133
|
+
...(append && cursor !== null ? { cursor } : {}),
|
|
134
|
+
...(state.categoryId ? { categoryId: state.categoryId } : {}),
|
|
135
|
+
});
|
|
136
|
+
// A newer request superseded this one — its result is now wrong.
|
|
137
|
+
if (destroyed || token !== requestToken)
|
|
138
|
+
return;
|
|
139
|
+
state.products = append ? [...state.products, ...page.items] : page.items;
|
|
140
|
+
cursor = page.nextCursor;
|
|
141
|
+
state.hasMore = page.nextCursor !== null;
|
|
142
|
+
state.status = "ready";
|
|
143
|
+
}
|
|
144
|
+
catch (cause) {
|
|
145
|
+
if (destroyed || token !== requestToken)
|
|
146
|
+
return;
|
|
147
|
+
fail(cause, "Failed to load products.");
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
if (!destroyed && token === requestToken) {
|
|
151
|
+
state.pending.products = false;
|
|
152
|
+
notify();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
snapshot,
|
|
158
|
+
subscribe(callback) {
|
|
159
|
+
subscribers.add(callback);
|
|
160
|
+
return () => {
|
|
161
|
+
subscribers.delete(callback);
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
async load() {
|
|
165
|
+
if (destroyed)
|
|
166
|
+
return;
|
|
167
|
+
if (state.status === "idle")
|
|
168
|
+
state.status = "loading";
|
|
169
|
+
state.pending.categories = true;
|
|
170
|
+
notify();
|
|
171
|
+
// Categories and the cart are independent of the product page, so all
|
|
172
|
+
// three go out together rather than waterfalling.
|
|
173
|
+
const categories = client.storefront
|
|
174
|
+
.listCategories()
|
|
175
|
+
.then((res) => {
|
|
176
|
+
if (destroyed)
|
|
177
|
+
return;
|
|
178
|
+
state.categories = res.items;
|
|
179
|
+
})
|
|
180
|
+
.catch((cause) => {
|
|
181
|
+
if (!destroyed)
|
|
182
|
+
fail(cause, "Failed to load categories.");
|
|
183
|
+
})
|
|
184
|
+
.finally(() => {
|
|
185
|
+
if (!destroyed)
|
|
186
|
+
state.pending.categories = false;
|
|
187
|
+
});
|
|
188
|
+
const cart = client.cart
|
|
189
|
+
.get()
|
|
190
|
+
.then((res) => {
|
|
191
|
+
if (destroyed)
|
|
192
|
+
return;
|
|
193
|
+
state.cart = res;
|
|
194
|
+
})
|
|
195
|
+
.catch((cause) => {
|
|
196
|
+
// A visitor with no cart yet is normal, not an error worth
|
|
197
|
+
// surfacing — leave `cart` null and let the products render.
|
|
198
|
+
void cause;
|
|
199
|
+
});
|
|
200
|
+
await Promise.all([fetchProducts(false), categories, cart]);
|
|
201
|
+
if (!destroyed)
|
|
202
|
+
notify();
|
|
203
|
+
},
|
|
204
|
+
async loadMore() {
|
|
205
|
+
if (destroyed || !state.hasMore || state.pending.products)
|
|
206
|
+
return;
|
|
207
|
+
await fetchProducts(true);
|
|
208
|
+
},
|
|
209
|
+
async filterByCategory(categoryId) {
|
|
210
|
+
if (destroyed)
|
|
211
|
+
return;
|
|
212
|
+
state.categoryId = categoryId;
|
|
213
|
+
cursor = null;
|
|
214
|
+
await fetchProducts(false);
|
|
215
|
+
},
|
|
216
|
+
async openProduct(productId) {
|
|
217
|
+
if (destroyed)
|
|
218
|
+
return;
|
|
219
|
+
state.pending.product = true;
|
|
220
|
+
state.error = null;
|
|
221
|
+
notify();
|
|
222
|
+
try {
|
|
223
|
+
const detail = await client.storefront.getProduct(productId);
|
|
224
|
+
if (destroyed)
|
|
225
|
+
return;
|
|
226
|
+
state.activeProduct = detail;
|
|
227
|
+
}
|
|
228
|
+
catch (cause) {
|
|
229
|
+
if (!destroyed)
|
|
230
|
+
fail(cause, "Failed to load the product.");
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
if (!destroyed) {
|
|
234
|
+
state.pending.product = false;
|
|
235
|
+
notify();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
closeProduct() {
|
|
240
|
+
if (destroyed)
|
|
241
|
+
return;
|
|
242
|
+
state.activeProduct = null;
|
|
243
|
+
notify();
|
|
244
|
+
},
|
|
245
|
+
addToCart(input) {
|
|
246
|
+
return cartAction(() => client.cart.addItem(input), "Failed to add the item to the cart.");
|
|
247
|
+
},
|
|
248
|
+
updateQuantity(itemId, quantity) {
|
|
249
|
+
// The API treats 0 as a removal; going through `removeItem` keeps that
|
|
250
|
+
// explicit rather than relying on every binding knowing the convention.
|
|
251
|
+
if (quantity <= 0) {
|
|
252
|
+
return cartAction(() => client.cart.removeItem(itemId), "Failed to remove the item.");
|
|
253
|
+
}
|
|
254
|
+
return cartAction(() => client.cart.updateItem(itemId, { quantity }), "Failed to update the quantity.");
|
|
255
|
+
},
|
|
256
|
+
removeItem(itemId) {
|
|
257
|
+
return cartAction(() => client.cart.removeItem(itemId), "Failed to remove the item.");
|
|
258
|
+
},
|
|
259
|
+
applyCoupon(code) {
|
|
260
|
+
return cartAction(() => client.cart.applyCoupon({ code }), "That coupon could not be applied.");
|
|
261
|
+
},
|
|
262
|
+
removeCoupon() {
|
|
263
|
+
return cartAction(() => client.cart.removeCoupon(), "Failed to remove the coupon.");
|
|
264
|
+
},
|
|
265
|
+
clearCart() {
|
|
266
|
+
return cartAction(() => client.cart.clear(), "Failed to clear the cart.");
|
|
267
|
+
},
|
|
268
|
+
refreshCart() {
|
|
269
|
+
return cartAction(() => client.cart.get(), "Failed to read the cart.");
|
|
270
|
+
},
|
|
271
|
+
destroy() {
|
|
272
|
+
destroyed = true;
|
|
273
|
+
subscribers.clear();
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAqHH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,SAAS,OAAO,CAAC,KAAc,EAAE,QAAgB;IAChD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,qBAAqB,CACpC,OAAqC;IAErC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,iBAAiB,CAAC;IAEvD,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,MAAM,GAAkB,IAAI,CAAC;IACjC;;;;;OAKG;IACH,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,MAAM,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE1D,MAAM,KAAK,GAUP;QACH,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,IAAI;QACV,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAI;QACtC,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,IAAI;QACX,OAAO,EAAE;YACR,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,KAAK;YACjB,OAAO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,4BAA4B,CAC5B,CAAC;YACH,CAAC;YACD,OAAO,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,EAClD,gCAAgC,CAChC,CAAC;QACH,CAAC;QAED,UAAU,CAAC,MAAM;YAChB,OAAO,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EACpC,4BAA4B,CAC5B,CAAC;QACH,CAAC;QAED,WAAW,CAAC,IAAI;YACf,OAAO,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,EACvC,mCAAmC,CACnC,CAAC;QACH,CAAC;QAED,YAAY;YACX,OAAO,UAAU,CAChB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAChC,8BAA8B,CAC9B,CAAC;QACH,CAAC;QAED,SAAS;YACR,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,2BAA2B,CAAC,CAAC;QAC3E,CAAC;QAED,WAAW;YACV,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,0BAA0B,CAAC,CAAC;QACxE,CAAC;QAED,OAAO;YACN,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/store` — the framework-agnostic storefront + cart core.
|
|
3
|
+
*
|
|
4
|
+
* Bindings shipped as SOURCE (Vue / Svelte / Solid / Qwik / Angular) import
|
|
5
|
+
* through this public subpath rather than a relative path, so the consumer's
|
|
6
|
+
* bundler resolves it exactly as their own code would. `forms` works the same
|
|
7
|
+
* way.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export * from "./store-core/index.js";
|
|
12
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,uBAAuB,CAAC"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@businessdash/sdk/store` — the framework-agnostic storefront + cart core.
|
|
3
|
+
*
|
|
4
|
+
* Bindings shipped as SOURCE (Vue / Svelte / Solid / Qwik / Angular) import
|
|
5
|
+
* through this public subpath rather than a relative path, so the consumer's
|
|
6
|
+
* bundler resolves it exactly as their own code would. `forms` works the same
|
|
7
|
+
* way.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export * from "./store-core/index.js";
|
|
12
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,uBAAuB,CAAC"}
|
package/dist/vanilla.d.ts
CHANGED
|
@@ -74,4 +74,115 @@ export interface BiabFormInstance {
|
|
|
74
74
|
destroy(): void;
|
|
75
75
|
}
|
|
76
76
|
export declare function mountBiabForm(elOrSelector: Element | string, opts: MountBiabFormOptions): BiabFormInstance;
|
|
77
|
+
import { type ChatController } from "./chat-core/index.js";
|
|
78
|
+
import { type StoreController } from "./store-core/index.js";
|
|
79
|
+
export type CreateStorefrontOptions = {
|
|
80
|
+
apiKey: string;
|
|
81
|
+
baseUrl: string;
|
|
82
|
+
pageSize?: number;
|
|
83
|
+
categoryId?: string | null;
|
|
84
|
+
onError?: (error: Error) => void;
|
|
85
|
+
};
|
|
86
|
+
/** Headless storefront + cart. Call `load()` to populate it. */
|
|
87
|
+
export declare function createStorefront(options: CreateStorefrontOptions): StoreController;
|
|
88
|
+
export type CreateChatOptions = {
|
|
89
|
+
apiKey: string;
|
|
90
|
+
baseUrl: string;
|
|
91
|
+
onError?: (error: Error) => void;
|
|
92
|
+
};
|
|
93
|
+
/** Headless Front Desk chat — the native alternative to the iframe widget. */
|
|
94
|
+
export declare function createChat(options: CreateChatOptions): ChatController;
|
|
95
|
+
export type { ChatController, ChatSnapshot } from "./chat-core/index.js";
|
|
96
|
+
export type { StoreController, StoreSnapshot, } from "./store-core/index.js";
|
|
97
|
+
import { type BlogController } from "./blog-core/index.js";
|
|
98
|
+
export type CreateBlogOptions = {
|
|
99
|
+
apiKey: string;
|
|
100
|
+
baseUrl: string;
|
|
101
|
+
pageSize?: number;
|
|
102
|
+
commentPageSize?: number;
|
|
103
|
+
categoryId?: string | null;
|
|
104
|
+
onError?: (error: Error) => void;
|
|
105
|
+
};
|
|
106
|
+
/** Headless blog — posts, taxonomy, a single post, comments and likes. */
|
|
107
|
+
export declare function createBlog(options: CreateBlogOptions): BlogController;
|
|
108
|
+
export type { BlogController, BlogSnapshot } from "./blog-core/index.js";
|
|
109
|
+
import { type FollowersController, type UserController } from "./account-core/index.js";
|
|
110
|
+
import { type CheckoutController } from "./checkout-core/index.js";
|
|
111
|
+
/** Headless checkout — mint a Stripe session, then `redirect()` or render it. */
|
|
112
|
+
export declare function createCheckout(options: {
|
|
113
|
+
apiKey: string;
|
|
114
|
+
baseUrl: string;
|
|
115
|
+
onError?: (error: Error) => void;
|
|
116
|
+
}): CheckoutController;
|
|
117
|
+
/** The signed-in customer, read from the auth handler's `/me`. */
|
|
118
|
+
export declare function createUser(options?: {
|
|
119
|
+
basePath?: string;
|
|
120
|
+
}): UserController;
|
|
121
|
+
/** Newsletter / follower subscribe, bound to a publishable token. */
|
|
122
|
+
export declare function createFollowers(options: {
|
|
123
|
+
token: string;
|
|
124
|
+
siteId: string;
|
|
125
|
+
baseUrl?: string;
|
|
126
|
+
onError?: (error: Error) => void;
|
|
127
|
+
}): FollowersController;
|
|
128
|
+
export type { FollowersController, FollowersSnapshot, UserController, UserSnapshot, } from "./account-core/index.js";
|
|
129
|
+
export { signIn, signInHref, signOut, signOutHref, signUp, signUpHref, } from "./account-core/index.js";
|
|
130
|
+
export type { CheckoutController, CheckoutSnapshot, } from "./checkout-core/index.js";
|
|
131
|
+
import { type MarketingController } from "./marketing-core/index.js";
|
|
132
|
+
import { type CreateVerifyControllerOptions, type VerifyController } from "./verify-core/index.js";
|
|
133
|
+
/**
|
|
134
|
+
* Headless marketing pages — the index, plus one page at a time.
|
|
135
|
+
*
|
|
136
|
+
* Bound to the PUBLISHABLE client, like followers: marketing pages are a
|
|
137
|
+
* browser-readable surface keyed by site, so they need a `siteId` and work with
|
|
138
|
+
* an origin-locked `pk_…` token.
|
|
139
|
+
*/
|
|
140
|
+
export declare function createMarketing(options: {
|
|
141
|
+
token: string;
|
|
142
|
+
siteId: string;
|
|
143
|
+
baseUrl?: string;
|
|
144
|
+
onError?: (error: Error) => void;
|
|
145
|
+
}): MarketingController;
|
|
146
|
+
/** Headless email / phone verification. Read `flow` before rendering a field. */
|
|
147
|
+
export declare function createVerify(options: {
|
|
148
|
+
apiKey: string;
|
|
149
|
+
baseUrl: string;
|
|
150
|
+
} & Omit<CreateVerifyControllerOptions, "client">): VerifyController;
|
|
151
|
+
export type { MarketingController, MarketingSnapshot, } from "./marketing-core/index.js";
|
|
152
|
+
export type { VerifyController, VerifyFlow, VerifySnapshot, } from "./verify-core/index.js";
|
|
153
|
+
import { type PortalController } from "./portal-core/index.js";
|
|
154
|
+
/**
|
|
155
|
+
* The signed-in customer's portal. `sessionToken` is required — every portal
|
|
156
|
+
* route is scoped to the customer, and without one it renders empty rather than
|
|
157
|
+
* signed-out.
|
|
158
|
+
*/
|
|
159
|
+
export declare function createPortal(options: {
|
|
160
|
+
apiKey: string;
|
|
161
|
+
baseUrl: string;
|
|
162
|
+
sessionToken: string;
|
|
163
|
+
onError?: (error: Error) => void;
|
|
164
|
+
}): PortalController;
|
|
165
|
+
export type { PortalController, PortalSnapshot } from "./portal-core/index.js";
|
|
166
|
+
export type MountSocialLinksOptions = {
|
|
167
|
+
socials: unknown;
|
|
168
|
+
/** Icon colour — hex without `#`, or a CSS keyword. */
|
|
169
|
+
color?: string;
|
|
170
|
+
/** Icon edge length in px. Default 20. */
|
|
171
|
+
size?: number;
|
|
172
|
+
class?: string;
|
|
173
|
+
linkClass?: string;
|
|
174
|
+
iconClass?: string;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Render a company's social links into `target`, replacing its contents.
|
|
178
|
+
*
|
|
179
|
+
* Returns a `destroy()` that empties the element again, so a single-page app
|
|
180
|
+
* can tear it down. Renders nothing at all when there are no profiles — an
|
|
181
|
+
* empty `<ul>` in a footer is worse than no list.
|
|
182
|
+
*/
|
|
183
|
+
export declare function mountSocialLinks(target: Element, options: MountSocialLinksOptions): {
|
|
184
|
+
destroy: () => void;
|
|
185
|
+
};
|
|
186
|
+
export type { SocialLinkRow } from "./social-core/index.js";
|
|
187
|
+
export { resolveSocialLinks } from "./social-core/index.js";
|
|
77
188
|
//# sourceMappingURL=vanilla.d.ts.map
|
package/dist/vanilla.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vanilla.d.ts","sourceRoot":"","sources":["../src/vanilla.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,EAKN,KAAK,cAAc,EAEnB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,UAAU,EAEV,UAAU,EACV,gBAAgB,EAChB,MAAM,UAAU,CAAC;AAGlB,cAAc,uBAAuB,CAAC;AAMtC,MAAM,WAAW,oBAAoB;IACpC;sEACkE;IAClE,MAAM,CAA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Y,CAAC,OAAO,EAAE;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACjC,GAAG,gBAAgB,CASnB;AAED,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAS/E,MAAM,MAAM,uBAAuB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,uBAAuB,GAC9B;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA4BzB;AA0CD,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/vanilla.js
CHANGED
|
@@ -900,4 +900,210 @@ function observeReveal(node) {
|
|
|
900
900
|
}, { threshold: 0.15, rootMargin: "0px 0px -8% 0px" });
|
|
901
901
|
obs.observe(node);
|
|
902
902
|
}
|
|
903
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
904
|
+
// Native storefront + chat, framework-free
|
|
905
|
+
//
|
|
906
|
+
// There is no reactivity system here to bridge into, so the controllers ARE the
|
|
907
|
+
// binding: subscribe, render, call the actions. That is also why these are the
|
|
908
|
+
// reference implementations — every framework binding is a wrapper around
|
|
909
|
+
// exactly these objects.
|
|
910
|
+
//
|
|
911
|
+
// const store = createStorefront({ apiKey, baseUrl });
|
|
912
|
+
// store.subscribe((s) => render(s.products));
|
|
913
|
+
// await store.load();
|
|
914
|
+
//
|
|
915
|
+
// Remember to `destroy()` when the surface goes away.
|
|
916
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
917
|
+
import { createChatController, } from "./chat-core/index.js";
|
|
918
|
+
import { BiabDevClient as BiabDevClientForSurfaces } from "./client.js";
|
|
919
|
+
import { createStoreController, } from "./store-core/index.js";
|
|
920
|
+
/** Headless storefront + cart. Call `load()` to populate it. */
|
|
921
|
+
export function createStorefront(options) {
|
|
922
|
+
return createStoreController({
|
|
923
|
+
client: new BiabDevClientForSurfaces({
|
|
924
|
+
apiKey: options.apiKey,
|
|
925
|
+
baseUrl: options.baseUrl,
|
|
926
|
+
}),
|
|
927
|
+
...(options.pageSize ? { pageSize: options.pageSize } : {}),
|
|
928
|
+
...(options.categoryId ? { categoryId: options.categoryId } : {}),
|
|
929
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
/** Headless Front Desk chat — the native alternative to the iframe widget. */
|
|
933
|
+
export function createChat(options) {
|
|
934
|
+
return createChatController({
|
|
935
|
+
client: new BiabDevClientForSurfaces({
|
|
936
|
+
apiKey: options.apiKey,
|
|
937
|
+
baseUrl: options.baseUrl,
|
|
938
|
+
}),
|
|
939
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
import { createBlogController, } from "./blog-core/index.js";
|
|
943
|
+
/** Headless blog — posts, taxonomy, a single post, comments and likes. */
|
|
944
|
+
export function createBlog(options) {
|
|
945
|
+
return createBlogController({
|
|
946
|
+
client: new BiabDevClientForSurfaces({
|
|
947
|
+
apiKey: options.apiKey,
|
|
948
|
+
baseUrl: options.baseUrl,
|
|
949
|
+
}),
|
|
950
|
+
...(options.pageSize ? { pageSize: options.pageSize } : {}),
|
|
951
|
+
...(options.commentPageSize
|
|
952
|
+
? { commentPageSize: options.commentPageSize }
|
|
953
|
+
: {}),
|
|
954
|
+
...(options.categoryId ? { categoryId: options.categoryId } : {}),
|
|
955
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
import { createFollowersController, createUserController, } from "./account-core/index.js";
|
|
959
|
+
import { createCheckoutController, } from "./checkout-core/index.js";
|
|
960
|
+
import { createBiabClient as createBiabClientForFollowers } from "./sdk.js";
|
|
961
|
+
/** Headless checkout — mint a Stripe session, then `redirect()` or render it. */
|
|
962
|
+
export function createCheckout(options) {
|
|
963
|
+
return createCheckoutController({
|
|
964
|
+
client: new BiabDevClientForSurfaces({
|
|
965
|
+
apiKey: options.apiKey,
|
|
966
|
+
baseUrl: options.baseUrl,
|
|
967
|
+
}),
|
|
968
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
/** The signed-in customer, read from the auth handler's `/me`. */
|
|
972
|
+
export function createUser(options = {}) {
|
|
973
|
+
return createUserController(options);
|
|
974
|
+
}
|
|
975
|
+
/** Newsletter / follower subscribe, bound to a publishable token. */
|
|
976
|
+
export function createFollowers(options) {
|
|
977
|
+
// Followers hang off the PUBLISHABLE client (`createBiabClient`), not
|
|
978
|
+
// `BiabDevClient`: they are the one surface a browser calls directly with an
|
|
979
|
+
// origin-locked `pk_…` token and no backend.
|
|
980
|
+
return createFollowersController({
|
|
981
|
+
client: createBiabClientForFollowers({
|
|
982
|
+
apiKey: options.token,
|
|
983
|
+
siteId: options.siteId,
|
|
984
|
+
baseUrl: options.baseUrl ?? DEFAULT_PACKAGE_BASE_URL_FOR_SURFACES,
|
|
985
|
+
}),
|
|
986
|
+
siteId: options.siteId,
|
|
987
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
export { signIn, signInHref, signOut, signOutHref, signUp, signUpHref, } from "./account-core/index.js";
|
|
991
|
+
/** Production package-API base, used when a surface doesn't specify one. */
|
|
992
|
+
const DEFAULT_PACKAGE_BASE_URL_FOR_SURFACES = "https://businessdash.us/api/package/v1";
|
|
993
|
+
import { createMarketingController, } from "./marketing-core/index.js";
|
|
994
|
+
import { createVerifyController, } from "./verify-core/index.js";
|
|
995
|
+
/**
|
|
996
|
+
* Headless marketing pages — the index, plus one page at a time.
|
|
997
|
+
*
|
|
998
|
+
* Bound to the PUBLISHABLE client, like followers: marketing pages are a
|
|
999
|
+
* browser-readable surface keyed by site, so they need a `siteId` and work with
|
|
1000
|
+
* an origin-locked `pk_…` token.
|
|
1001
|
+
*/
|
|
1002
|
+
export function createMarketing(options) {
|
|
1003
|
+
return createMarketingController({
|
|
1004
|
+
client: createBiabClientForFollowers({
|
|
1005
|
+
apiKey: options.token,
|
|
1006
|
+
siteId: options.siteId,
|
|
1007
|
+
baseUrl: options.baseUrl ?? DEFAULT_PACKAGE_BASE_URL_FOR_SURFACES,
|
|
1008
|
+
}),
|
|
1009
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
/** Headless email / phone verification. Read `flow` before rendering a field. */
|
|
1013
|
+
export function createVerify(options) {
|
|
1014
|
+
const { apiKey, baseUrl, ...rest } = options;
|
|
1015
|
+
return createVerifyController({
|
|
1016
|
+
client: new BiabDevClientForSurfaces({ apiKey, baseUrl }),
|
|
1017
|
+
...rest,
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
import { createPortalController, } from "./portal-core/index.js";
|
|
1021
|
+
/**
|
|
1022
|
+
* The signed-in customer's portal. `sessionToken` is required — every portal
|
|
1023
|
+
* route is scoped to the customer, and without one it renders empty rather than
|
|
1024
|
+
* signed-out.
|
|
1025
|
+
*/
|
|
1026
|
+
export function createPortal(options) {
|
|
1027
|
+
return createPortalController({
|
|
1028
|
+
client: new BiabDevClientForSurfaces({
|
|
1029
|
+
apiKey: options.apiKey,
|
|
1030
|
+
baseUrl: options.baseUrl,
|
|
1031
|
+
}),
|
|
1032
|
+
sessionToken: options.sessionToken,
|
|
1033
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
import { resolveSocialLinks, SOCIAL_FALLBACK_GLYPH, SOCIAL_LIST_STYLE, } from "./social-core/index.js";
|
|
1037
|
+
/**
|
|
1038
|
+
* Render a company's social links into `target`, replacing its contents.
|
|
1039
|
+
*
|
|
1040
|
+
* Returns a `destroy()` that empties the element again, so a single-page app
|
|
1041
|
+
* can tear it down. Renders nothing at all when there are no profiles — an
|
|
1042
|
+
* empty `<ul>` in a footer is worse than no list.
|
|
1043
|
+
*/
|
|
1044
|
+
export function mountSocialLinks(target, options) {
|
|
1045
|
+
const size = options.size ?? 20;
|
|
1046
|
+
const rows = resolveSocialLinks(options.socials, { color: options.color });
|
|
1047
|
+
target.replaceChildren();
|
|
1048
|
+
if (rows.length === 0)
|
|
1049
|
+
return { destroy: () => target.replaceChildren() };
|
|
1050
|
+
const ul = document.createElement("ul");
|
|
1051
|
+
if (options.class)
|
|
1052
|
+
ul.className = options.class;
|
|
1053
|
+
for (const [prop, value] of Object.entries(SOCIAL_LIST_STYLE)) {
|
|
1054
|
+
ul.style.setProperty(prop, value);
|
|
1055
|
+
}
|
|
1056
|
+
for (const row of rows) {
|
|
1057
|
+
const li = document.createElement("li");
|
|
1058
|
+
const a = document.createElement("a");
|
|
1059
|
+
a.href = row.url;
|
|
1060
|
+
a.target = "_blank";
|
|
1061
|
+
a.rel = "noopener noreferrer";
|
|
1062
|
+
a.title = row.label;
|
|
1063
|
+
a.setAttribute("aria-label", row.label);
|
|
1064
|
+
if (options.linkClass)
|
|
1065
|
+
a.className = options.linkClass;
|
|
1066
|
+
a.append(socialGlyph(row, size, options.iconClass));
|
|
1067
|
+
li.append(a);
|
|
1068
|
+
ul.append(li);
|
|
1069
|
+
}
|
|
1070
|
+
target.append(ul);
|
|
1071
|
+
return { destroy: () => target.replaceChildren() };
|
|
1072
|
+
}
|
|
1073
|
+
/** Brand icon when the platform has one, generic globe when it doesn't. */
|
|
1074
|
+
function socialGlyph(row, size, iconClass) {
|
|
1075
|
+
if (row.iconUrl) {
|
|
1076
|
+
const img = document.createElement("img");
|
|
1077
|
+
img.src = row.iconUrl;
|
|
1078
|
+
img.alt = row.label;
|
|
1079
|
+
img.width = size;
|
|
1080
|
+
img.height = size;
|
|
1081
|
+
img.loading = "lazy";
|
|
1082
|
+
if (iconClass)
|
|
1083
|
+
img.className = iconClass;
|
|
1084
|
+
return img;
|
|
1085
|
+
}
|
|
1086
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
1087
|
+
const svg = document.createElementNS(ns, "svg");
|
|
1088
|
+
svg.setAttribute("viewBox", SOCIAL_FALLBACK_GLYPH.viewBox);
|
|
1089
|
+
svg.setAttribute("width", String(size));
|
|
1090
|
+
svg.setAttribute("height", String(size));
|
|
1091
|
+
svg.setAttribute("fill", "none");
|
|
1092
|
+
svg.setAttribute("stroke", "currentColor");
|
|
1093
|
+
svg.setAttribute("stroke-width", String(SOCIAL_FALLBACK_GLYPH.strokeWidth));
|
|
1094
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1095
|
+
if (iconClass)
|
|
1096
|
+
svg.setAttribute("class", iconClass);
|
|
1097
|
+
const title = document.createElementNS(ns, "title");
|
|
1098
|
+
title.textContent = row.label;
|
|
1099
|
+
const circle = document.createElementNS(ns, "circle");
|
|
1100
|
+
circle.setAttribute("cx", String(SOCIAL_FALLBACK_GLYPH.circle.cx));
|
|
1101
|
+
circle.setAttribute("cy", String(SOCIAL_FALLBACK_GLYPH.circle.cy));
|
|
1102
|
+
circle.setAttribute("r", String(SOCIAL_FALLBACK_GLYPH.circle.r));
|
|
1103
|
+
const path = document.createElementNS(ns, "path");
|
|
1104
|
+
path.setAttribute("d", SOCIAL_FALLBACK_GLYPH.path);
|
|
1105
|
+
svg.append(title, circle, path);
|
|
1106
|
+
return svg;
|
|
1107
|
+
}
|
|
1108
|
+
export { resolveSocialLinks } from "./social-core/index.js";
|
|
903
1109
|
//# sourceMappingURL=vanilla.js.map
|