@strata-ds/core 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +541 -438
  2. package/dist/components/DynamicComponentDebug.d.ts +0 -1
  3. package/dist/components/DynamicComponents.d.ts +0 -1
  4. package/dist/components/StrataErrorBoundary.d.ts +37 -0
  5. package/dist/components/card-ui/Card.d.ts +0 -1
  6. package/dist/components/card-ui/DefaultCard.d.ts +0 -1
  7. package/dist/components/index.d.ts +1 -1
  8. package/dist/data/index.d.ts +0 -1
  9. package/dist/data/mock.types.d.ts +2 -1
  10. package/dist/hook/useCardData.d.ts +0 -1
  11. package/dist/hook/useComponent.d.ts +0 -1
  12. package/dist/hook/useComponents.d.ts +0 -1
  13. package/dist/hook/useDynamicComponents.d.ts +0 -1
  14. package/dist/index.d.ts +414 -1
  15. package/dist/index.esm.js +298 -70
  16. package/dist/index.js +301 -68
  17. package/dist/providers/StrataProvider.d.ts +5 -1
  18. package/dist/providers/index.d.ts +0 -1
  19. package/dist/registry/ComponentFactory.d.ts +0 -1
  20. package/dist/registry/ComponentRegistry.d.ts +0 -1
  21. package/dist/types/card-types.d.ts +0 -1
  22. package/dist/utils/normalize-component.d.ts +14 -0
  23. package/package.json +74 -74
  24. package/dist/components/DynamicComponentDebug.d.ts.map +0 -1
  25. package/dist/components/DynamicComponents.d.ts.map +0 -1
  26. package/dist/components/card-ui/Card.d.ts.map +0 -1
  27. package/dist/components/card-ui/DefaultCard.d.ts.map +0 -1
  28. package/dist/components/index.d.ts.map +0 -1
  29. package/dist/data/index.d.ts.map +0 -1
  30. package/dist/data/mock.types.d.ts.map +0 -1
  31. package/dist/hook/useCardData.d.ts.map +0 -1
  32. package/dist/hook/useComponent.d.ts.map +0 -1
  33. package/dist/hook/useComponents.d.ts.map +0 -1
  34. package/dist/hook/useDesignSystemSync.d.ts +0 -1
  35. package/dist/hook/useDesignSystemSync.d.ts.map +0 -1
  36. package/dist/hook/useDynamicComponents.d.ts.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/index.esm.js.map +0 -1
  39. package/dist/index.js.map +0 -1
  40. package/dist/providers/StrataProvider.d.ts.map +0 -1
  41. package/dist/providers/index.d.ts.map +0 -1
  42. package/dist/registry/ComponentFactory.d.ts.map +0 -1
  43. package/dist/registry/ComponentRegistry.d.ts.map +0 -1
  44. package/dist/types/card-types.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,438 +1,541 @@
1
- # @strata-ds/core
2
-
3
- > The runtime component library for [Strata](https://strata.charisol.io) — connect your React app to your design system and ship updates live.
4
-
5
- `@strata-ds/core` is a dynamic React component library and stylesheet runtime. It enables teams to consume design tokens and components directly from a centralised Strata design system, ensuring that what designers create is exactly what developers ship — consistently, across platforms, and in real time.
6
-
7
- > Design once in Strata. Ship everywhere.
8
-
9
- ## Why @strata-ds/core?
10
-
11
- ### The Problem
12
-
13
- Design and engineering teams often drift apart:
14
-
15
- - Designers update Figma files
16
- - Developers re-implement styles manually
17
- - Components slowly diverge from the original design
18
- - Consistency breaks across products and platforms
19
-
20
- This results in duplicate work, inconsistent UI, broken design intent, and slow iteration.
21
-
22
- ### The Solution
23
-
24
- `@strata-ds/core` bridges this gap by acting as:
25
-
26
- - A component library
27
- - A stylesheet generator runtime
28
- - A live consumer of design tokens and components
29
-
30
- All powered by your **Strata** project.
31
-
32
- Instead of hardcoding styles, **components dynamically reference design tokens** fetched from the design system. This establishes a single **source of truth** for design.
33
-
34
- ## Core Principles
35
-
36
- ### 1. Separation of Concerns
37
-
38
- `@strata-ds/core` strictly separates:
39
-
40
- - **Variables (Design Tokens)** — Colors, spacing, typography, radii, shadows, etc.
41
- - **Components** — Buttons, Cards, Forms, Navbars, etc.
42
-
43
- Components never own styles directly — they reference tokens.
44
-
45
- ### 2. Single Source of Truth
46
-
47
- Design tokens live in your Strata project, not inside applications.
48
-
49
- - Tokens are defined once
50
- - Components reference them dynamically
51
- - Updates propagate automatically
52
-
53
- ### 3. Dynamic & Real-Time Sync
54
-
55
- `@strata-ds/core` can:
56
-
57
- - Fetch updated tokens and components from the Strata backend
58
- - Detect changes via checksum
59
- - Rebuild styles automatically
60
- - Fall back to cached data when offline
61
-
62
- ## Architecture Overview
63
-
64
- ```
65
- Figma / Style Dictionary
66
- ↓
67
- Strata Design System
68
- ↓
69
- Machine-parseable JSON
70
- ↓
71
- @strata-ds/core Component Library
72
- ↓
73
- Your React Application
74
- ```
75
-
76
- ## Quick Start
77
-
78
- ### 1. Create a Strata project
79
-
80
- Go to [strata.charisol.io](https://strata.charisol.io), create a project, and import your design tokens (Style Dictionary JSON or Figma).
81
-
82
- ### 2. Get your sync URL
83
-
84
- Once your tokens are imported, your project's sync URL is shown on the project page:
85
-
86
- ```
87
- https://api-production-charisol-design-system-be.aws.charisol.io/v1/project/YOUR_PROJECT_ID/data
88
- ```
89
-
90
- Copy it — you'll need it in step 4.
91
-
92
- ### 3. Install
93
-
94
- ```bash
95
- npm install @strata-ds/core
96
- # or
97
- yarn add @strata-ds/core
98
- ```
99
-
100
- ### 4. Wrap your app
101
-
102
- **CDN Snapshot Sync (recommended — 1 request per poll, edge-cached):**
103
-
104
- ```tsx
105
- "use client"; // Next.js App Router only
106
- import { StrataProvider } from "@strata-ds/core";
107
-
108
- export default function RootLayout({
109
- children,
110
- }: {
111
- children: React.ReactNode;
112
- }) {
113
- return (
114
- <StrataProvider
115
- syncEnabled={true}
116
- projectId="YOUR_PROJECT_ID"
117
- snapshotCdnBase="https://cdn.strata.charisol.io"
118
- syncToken="pt_live_your_token_here"
119
- syncInterval={5000}
120
- >
121
- {children}
122
- </StrataProvider>
123
- );
124
- }
125
- ```
126
-
127
- > 💡 Get your `projectId` and `syncToken` from the **Publish & Sync** tab on your Strata project dashboard.
128
-
129
- ### Legacy sync (syncUrl — still supported, not recommended for new projects)
130
-
131
- ```tsx
132
- "use client"; // Next.js App Router only
133
- import { StrataProvider } from "@strata-ds/core";
134
-
135
- export default function RootLayout({
136
- children,
137
- }: {
138
- children: React.ReactNode;
139
- }) {
140
- return (
141
- <StrataProvider
142
- syncEnabled={true}
143
- syncUrl="https://api-production-charisol-design-system-be.aws.charisol.io/v1/project/YOUR_PROJECT_ID/data"
144
- syncToken="pt_live_your_token_here"
145
- syncInterval={3000}
146
- >
147
- {children}
148
- </StrataProvider>
149
- );
150
- }
151
- ```
152
-
153
- > 💡 Replace `YOUR_PROJECT_ID` with the ID from your Strata project dashboard. Get your `syncToken` from the **Publish & Sync** tab — it starts with `pt_live_`.
154
-
155
- ### 5. Use your components
156
-
157
- ```tsx
158
- "use client";
159
- import { useComponents } from "@strata-ds/core";
160
-
161
- function App() {
162
- // Components you created in your Strata project
163
- const { Button, Navbar } = useComponents();
164
-
165
- return (
166
- <>
167
- {Button && (
168
- <Button onClick={() => console.log("clicked")}>Click me</Button>
169
- )}
170
- {Navbar && <Navbar />}
171
- </>
172
- );
173
- }
174
- ```
175
-
176
- ## Installation
177
-
178
- ```bash
179
- npm install @strata-ds/core
180
- # or
181
- yarn add @strata-ds/core
182
- ```
183
-
184
- ## Project Setup (React)
185
-
186
- `@strata-ds/core` works with React 18+, Next.js (App Router or Pages Router), and any standard React setup.
187
-
188
- ### 1. Create a new project
189
-
190
- ```bash
191
- npx create-next-app@latest my-strata-app --typescript
192
- cd my-strata-app
193
- npm install @strata-ds/core
194
- ```
195
-
196
- ### 2. Integrate the StrataProvider
197
-
198
- Wrap your application's root component with `StrataProvider`. This provider manages the connection to the Strata backend.
199
-
200
- | Prop | Type | Description |
201
- | :----------------- | :------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
202
- | `syncEnabled` | `boolean` | If `true`, the library will fetch and sync tokens/components from the server. |
203
- | `snapshotCdnBase` | `string` | **Recommended.** Base CDN URL for snapshot files (e.g. `"https://cdn.strata.charisol.io"`). When set together with `projectId`, the provider fetches a single `strata.json` snapshot per poll cycle instead of 3 API calls. Takes precedence over `syncUrl`. |
204
- | `projectId` | `string` | Your Strata project ID (shown in the dashboard URL and project settings). Required when using `snapshotCdnBase`. |
205
- | `syncUrl` | `string` | Legacy base sync URL. `StrataProvider` will append `/variables`, `/components`, and `/custom` to this URL. Ignored when `snapshotCdnBase` + `projectId` are provided. |
206
- | `syncInterval` | `number` | Polling interval in milliseconds to check for design system updates. Default: `3000`. |
207
- | `syncToken` | `string` | Sync token from your project dashboard. When set, all sync requests carry `Authorization: Bearer <token>`. Required if your project is not fully public. |
208
- | `initialData` | `DesignSystemData` | Initial design system data to use before the first sync. |
209
- | `userDesignSystem` | `DesignSystemData` | Override design system data — useful for storybook, testing, or static mode. Takes precedence over `initialData`. |
210
- | `onSyncError` | `(error: { code: number; message: string; source: string }) => void` | Callback invoked when a sync cycle fails. `code` is the HTTP status (0 for non-HTTP errors), `message` is a human-readable description, and `source` is `"cdn"` or `"sync"`. |
211
- | `onSyncSuccess` | `(data: DesignSystemData) => void` | Callback invoked whenever a sync cycle succeeds with new data. |
212
-
213
- ```tsx
214
- // app/layout.tsx (Next.js App Router)
215
- "use client";
216
- import { StrataProvider } from "@strata-ds/core";
217
-
218
- export default function RootLayout({
219
- children,
220
- }: {
221
- children: React.ReactNode;
222
- }) {
223
- return (
224
- <html lang="en">
225
- <body>
226
- <StrataProvider
227
- syncEnabled={true}
228
- projectId="YOUR_PROJECT_ID"
229
- snapshotCdnBase="https://cdn.strata.charisol.io"
230
- syncInterval={5000}
231
- >
232
- {children}
233
- </StrataProvider>
234
- </body>
235
- </html>
236
- );
237
- }
238
- ```
239
-
240
- > 💡 Replace `YOUR_PROJECT_ID` with the ID from your Strata project dashboard. For private projects, add `syncToken="pt_live_your_token_here"` (get it from the **Publish & Sync** tab).
241
-
242
- ### Sync token authentication
243
-
244
- If your project has a sync token set in the Strata dashboard, pass it as `syncToken`. Every polling request will automatically include `Authorization: Bearer <token>`.
245
-
246
- Projects with `syncToken` set are only readable by clients that present the correct token. This is the recommended way to gate read access to your design system without managing user accounts.
247
-
248
- ```tsx
249
- <StrataProvider
250
- syncEnabled={true}
251
- projectId="YOUR_PROJECT_ID"
252
- snapshotCdnBase="https://cdn.strata.charisol.io"
253
- syncToken="pt_live_your_token_here"
254
- syncInterval={5000}
255
- >
256
- {children}
257
- </StrataProvider>
258
- ```
259
-
260
- ## Using Design System Components
261
-
262
- `@strata-ds/core` provides dynamic access to your components defined in Strata.
263
-
264
- ### Accessing Components with `useComponents`
265
-
266
- ```tsx
267
- "use client";
268
- import { useComponents } from "@strata-ds/core";
269
-
270
- function AppContent() {
271
- // Components are named exactly as you defined them in your Strata project
272
- const { Button, Navbar, Card } = useComponents();
273
-
274
- return (
275
- <>
276
- {/* Render conditionally while components are loading */}
277
- {Button && (
278
- <Button onClick={() => console.log("clicked")}>Click me</Button>
279
- )}
280
-
281
- {Card && <Card style={{ padding: "20px" }}>Card content here</Card>}
282
- </>
283
- );
284
- }
285
- ```
286
-
287
- ### Accessing Design System Context with `useStrata`
288
-
289
- ```tsx
290
- "use client";
291
- import { useStrata } from "@strata-ds/core";
292
-
293
- function StatusBar() {
294
- const { designSystem, syncStatus, lastSynced } = useStrata();
295
-
296
- return (
297
- <div>
298
- <p>Sync status: {syncStatus}</p>
299
- <p>Last synced: {lastSynced?.toLocaleTimeString() || "Never"}</p>
300
- <p>Components: {Object.keys(designSystem.components).join(", ")}</p>
301
- </div>
302
- );
303
- }
304
- ```
305
-
306
- ### Customisation and Overrides
307
-
308
- **Token-Driven Styling (Default)**
309
-
310
- By default, all components are styled based on the latest tokens fetched from your Strata project. This ensures perfect design-to-code fidelity.
311
-
312
- **Local Overrides**
313
-
314
- Override any style locally using standard React props:
315
-
316
- ```tsx
317
- <Button
318
- style={{ backgroundColor: "#007bff", color: "white" }}
319
- className="my-custom-class"
320
- >
321
- Custom styled button
322
- </Button>
323
- ```
324
-
325
- ### Dynamic Updates (Hot-Reloading)
326
-
327
- `@strata-ds/core` intelligently handles design updates:
328
-
329
- 1. A designer makes a change in Strata (e.g., updates a colour token or modifies a component).
330
- 2. Strata generates a new checksum.
331
- 3. Your `StrataProvider` (via `syncInterval`) polls the `syncUrl`.
332
- 4. If the checksum has changed, the library fetches new design tokens and component configurations, and your app's components are dynamically restyled — without a page refresh.
333
-
334
- ## Debugging & Inspection
335
-
336
- ### `StrataDebug`
337
-
338
- The `<StrataDebug />` component renders a debug panel showing the active sync mode, connection details, and the component registry. Useful during development to verify that tokens and components have loaded correctly.
339
-
340
- ```tsx
341
- import { StrataDebug } from "@strata-ds/core";
342
-
343
- // Place anywhere inside StrataProvider
344
- <StrataDebug />;
345
- ```
346
-
347
- The panel automatically displays the relevant fields for the active sync mode:
348
-
349
- - **CDN mode** (`snapshotCdnBase` + `projectId` set): shows `✅ CDN Snapshot`, Project ID, resolved Snapshot URL, token presence, and sync interval.
350
- - **Legacy mode** (`syncUrl` set): shows `⚠️ Legacy (3 requests/poll)`, Sync URL, token presence, and sync interval.
351
- - **Disabled**: shows `❌ Disabled`.
352
-
353
- > 🔒 The `syncToken` value is **never** rendered — the panel only shows `✅ Present` or `❌ None`.
354
-
355
- ### Programmatic inspection
356
-
357
- ```tsx
358
- import { useStrata, useDynamicComponents } from "@strata-ds/core";
359
-
360
- function DebugPanel() {
361
- const { designSystem, syncStatus, syncUrl, syncEnabled } = useStrata();
362
- const dynamicComponents = useDynamicComponents();
363
-
364
- return (
365
- <pre>
366
- {JSON.stringify(
367
- {
368
- syncStatus,
369
- syncEnabled,
370
- syncUrl,
371
- designSystemComponents: Object.keys(designSystem.components),
372
- registryComponents: Object.keys(dynamicComponents),
373
- },
374
- null,
375
- 2,
376
- )}
377
- </pre>
378
- );
379
- }
380
- ```
381
-
382
- ### Hooks reference
383
-
384
- | Hook / Property | Description |
385
- | :----------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
386
- | `useStrata()` | Returns full context: `designSystem`, `syncStatus`, `lastSynced`, `syncUrl`, `snapshotCdnBase`, `projectId`, `syncEnabled`, `forceSync`. |
387
- | `useComponents()` | Returns ready-to-use React components by PascalCase name. |
388
- | `useDynamicComponents()` | Returns the raw component registry map. |
389
-
390
- ## Network Debugging
391
-
392
- If components are not loading, check your browser's Network tab:
393
-
394
- - **CDN pattern:** When `snapshotCdnBase` and `projectId` are set, the provider makes a single request to `${snapshotCdnBase}/snapshots/${projectId}/strata.json` per poll cycle. Verify the response is a JSON object with `variables`, `components`, and `custom` keys.
395
- - **Legacy pattern:** When `syncUrl` is set, the provider makes 3 requests per poll cycle: `${syncUrl}/variables`, `${syncUrl}/components`, and `${syncUrl}/custom`. Each should return the corresponding JSON object.
396
- - **Errors:** Check the console for `❌ Sync failed:` messages.
397
-
398
- ## Registry API
399
-
400
- `strataRegistry` is the underlying singleton registry that stores all registered components.
401
-
402
- ```tsx
403
- import { strataRegistry } from "@strata-ds/core";
404
-
405
- // Check if a component is registered
406
- strataRegistry.hasComponent("Button");
407
-
408
- // Get a component by name
409
- const ButtonComponent = strataRegistry.getComponent("Button");
410
- ```
411
-
412
- ## Component Factory
413
-
414
- `StrataComponentFactory` creates React components from Strata component definitions.
415
-
416
- ```tsx
417
- import { StrataComponentFactory } from "@strata-ds/core";
418
-
419
- const MyComponent = StrataComponentFactory.createComponent(
420
- "MyComponent",
421
- componentData,
422
- designSystem,
423
- );
424
- ```
425
-
426
- ## Key Features
427
-
428
- - 🔁 Live sync with Strata backend
429
- - 🧠 Token-driven styling
430
- - 🧩 Dynamic component registry
431
- - 🛠 Inline style overrides supported
432
- - 📦 Installable via npm
433
- - 📴 Offline-first fallback
434
- - 🧪 Debug tools included (`StrataDebug`)
435
-
436
- ## License
437
-
438
- MIT © [Charisol](https://strata.charisol.io)
1
+ # @strata-ds/core
2
+
3
+ > The runtime component library for [Strata](https://strata.charisol.io) — connect your React app to your design system and ship updates live.
4
+
5
+ `@strata-ds/core` is a dynamic React component library and stylesheet runtime. It enables teams to consume design tokens and components directly from a centralised Strata design system, ensuring that what designers create is exactly what developers ship — consistently, across platforms, and in real time.
6
+
7
+ > Design once in Strata. Ship everywhere.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Why @strata-ds/core?](#why-strata-dscore)
12
+ - [Quick Start (< 5 Minutes)](#quick-start--5-minutes)
13
+ - [5-Minute Integration Checklist](#5-minute-integration-checklist)
14
+ - [Project Setup (React)](#project-setup-react)
15
+ - [Using Design System Components](#using-design-system-components)
16
+ - [Debugging and Troubleshooting](#debugging-and-troubleshooting)
17
+ - [Customisation and Overrides](#customisation-and-overrides)
18
+ - [Dynamic Updates (Hot-Reloading)](#dynamic-updates-hot-reloading)
19
+ - [Registry API](#registry-api)
20
+ - [Component Factory](#component-factory)
21
+ - [Key Features](#key-features)
22
+
23
+ ## Why @strata-ds/core?
24
+
25
+ ### The Problem
26
+
27
+ Design and engineering teams often drift apart:
28
+
29
+ - Designers update Figma files
30
+ - Developers re-implement styles manually
31
+ - Components slowly diverge from the original design
32
+ - Consistency breaks across products and platforms
33
+
34
+ This results in duplicate work, inconsistent UI, broken design intent, and slow iteration.
35
+
36
+ ### The Solution
37
+
38
+ `@strata-ds/core` bridges this gap by acting as:
39
+
40
+ - A component library
41
+ - A stylesheet generator runtime
42
+ - A live consumer of design tokens and components
43
+
44
+ All powered by your **Strata** project.
45
+
46
+ Instead of hardcoding styles, **components dynamically reference design tokens** fetched from the design system. This establishes a single **source of truth** for design.
47
+
48
+ ### Who Is This For?
49
+
50
+ | Persona | Value |
51
+ |---------|-------|
52
+ | **Solopreneurs** | "I don't need a designer — I can sync from Figma and ship brand-consistent UI myself." |
53
+ | **Frontend Engineers** | "Design tokens live in one place. No more manual style updates across 10 repositories." |
54
+ | **Entrepreneurs** | "My team ships faster because design changes propagate automatically." |
55
+ | **Designers** | "What I create in Strata is exactly what users see — no 'lost in translation' moments." |
56
+
57
+ ## Core Principles
58
+
59
+ ### 1. Separation of Concerns
60
+
61
+ `@strata-ds/core` strictly separates:
62
+
63
+ - **Variables (Design Tokens)** — Colors, spacing, typography, radii, shadows, etc.
64
+ - **Components** — Buttons, Cards, Forms, Navbars, etc.
65
+
66
+ Components never own styles directly — they reference tokens.
67
+
68
+ ### 2. Single Source of Truth
69
+
70
+ Design tokens live in your Strata project, not inside applications.
71
+
72
+ - Tokens are defined once
73
+ - Components reference them dynamically
74
+ - Updates propagate automatically
75
+
76
+ ### 3. Dynamic & Real-Time Sync
77
+
78
+ `@strata-ds/core` can:
79
+
80
+ - Fetch updated tokens and components from the Strata backend
81
+ - Detect changes via checksum
82
+ - Rebuild styles automatically
83
+ - Fall back to cached data when offline
84
+
85
+ ## Architecture Overview
86
+
87
+ ```text
88
+ Figma / Style Dictionary
89
+ ↓
90
+ Strata Design System
91
+ ↓
92
+ Machine-parseable JSON
93
+ ↓
94
+ @strata-ds/core Component Library
95
+ ↓
96
+ Your React Application
97
+ ```
98
+
99
+ ## Quick Start (< 5 Minutes)
100
+
101
+ > 🚀 **New to Strata?** Get your first component rendering in 4 steps.
102
+
103
+ ### Step 1: Install
104
+
105
+ ```bash
106
+ npm install @strata-ds/core
107
+ # or
108
+ yarn add @strata-ds/core
109
+ ```
110
+
111
+ ### Step 2: Get Your Credentials
112
+
113
+ Go to [strata.charisol.io](https://strata.charisol.io) → **Your Project** → **Publish & Sync** tab:
114
+
115
+ - Copy your **Project ID** (e.g., `abc123def456`)
116
+ - Copy your **Sync Token** (starts with `pt_live_`)
117
+
118
+ ### Step 3: Wrap Your App
119
+
120
+ **✅ Recommended: CDN Snapshot Sync** (1 request per poll, edge-cached)
121
+
122
+ ```tsx
123
+ "use client"; // Next.js App Router only
124
+ import { StrataProvider } from "@strata-ds/core";
125
+
126
+ export default function RootLayout({
127
+ children,
128
+ }: {
129
+ children: React.ReactNode;
130
+ }) {
131
+ return (
132
+ <StrataProvider
133
+ syncEnabled={true}
134
+ projectId="YOUR_PROJECT_ID"
135
+ snapshotCdnBase="https://cdn.strata.charisol.io"
136
+ syncToken="pt_live_your_token_here"
137
+ syncInterval={5000}
138
+ >
139
+ {children}
140
+ </StrataProvider>
141
+ );
142
+ }
143
+ ```
144
+
145
+ > 💡 Replace `YOUR_PROJECT_ID` and `pt_live_your_token_here` with values from **Step 2**.
146
+
147
+ ---
148
+
149
+ <details>
150
+ <summary><strong>⚠️ Legacy Sync</strong> (3 requests per poll — for migration only)</summary>
151
+
152
+ ```tsx
153
+ "use client";
154
+ import { StrataProvider } from "@strata-ds/core";
155
+
156
+ export default function RootLayout({
157
+ children,
158
+ }: {
159
+ children: React.ReactNode;
160
+ }) {
161
+ return (
162
+ <StrataProvider
163
+ syncEnabled={true}
164
+ syncUrl="https://api-production-charisol-design-system-be.aws.charisol.io/v1/project/YOUR_PROJECT_ID/data"
165
+ syncToken="pt_live_your_token_here"
166
+ syncInterval={3000}
167
+ >
168
+ {children}
169
+ </StrataProvider>
170
+ );
171
+ }
172
+ ```
173
+
174
+ **Why CDN is better:**
175
+
176
+ - ✅ 1 request instead of 3 (faster, cheaper)
177
+ - ✅ Edge-cached for global performance
178
+ - ✅ Atomic updates (no partial states)
179
+
180
+ </details>
181
+
182
+ ---
183
+
184
+ ### Step 4: Use Your Components
185
+
186
+ ```tsx
187
+ "use client";
188
+ import { useComponents } from "@strata-ds/core";
189
+
190
+ function App() {
191
+ const { Button, Navbar } = useComponents();
192
+
193
+ return (
194
+ <>
195
+ {Button && (
196
+ <Button onClick={() => console.log("clicked")}>Click me</Button>
197
+ )}
198
+ {Navbar && <Navbar />}
199
+ </>
200
+ );
201
+ }
202
+ ```
203
+
204
+ **Not seeing components?** → Jump to [Debugging and Troubleshooting](#debugging-and-troubleshooting).
205
+
206
+ ## 5-Minute Integration Checklist
207
+
208
+ Use this checklist to verify your setup after following [Quick Start](#quick-start--5-minutes) above.
209
+
210
+ **Before you start:**
211
+
212
+ - [ ] Created a project at [strata.charisol.io](https://strata.charisol.io)
213
+ - [ ] Imported your design tokens (Style Dictionary JSON or Figma)
214
+ - [ ] Published your project (dashboard shows "✅ Published")
215
+
216
+ **Integration:**
217
+
218
+ - [ ] Installed `@strata-ds/core` via npm/yarn
219
+ - [ ] Copied `projectId` from dashboard URL or project settings
220
+ - [ ] Copied `syncToken` from **Publish & Sync** tab (starts with `pt_live_`)
221
+ - [ ] Wrapped app with `<StrataProvider>` using **CDN Snapshot Sync** (recommended)
222
+ - [ ] Imported `@strata-ds/core/dist/styles.css` in root layout
223
+ - [ ] Rendered first component with `useComponents()`
224
+
225
+ **Verification:**
226
+
227
+ - [ ] Opened DevTools → Console and saw `🔄 Starting design system sync...`
228
+ - [ ] Console shows `📊 Components available: ...`
229
+ - [ ] Component renders on screen with correct styles
230
+ - [ ] Added `<StrataDebug />` and verified connection status is **✅ Connected**
231
+
232
+ **Stuck?** → Jump to [Debugging and Troubleshooting](#debugging-and-troubleshooting).
233
+
234
+ ## Project Setup (React)
235
+
236
+ `@strata-ds/core` works with React 18+, Next.js (App Router or Pages Router), and any standard React setup.
237
+
238
+ ### 1. Create a new project
239
+
240
+ ```bash
241
+ npx create-next-app@latest my-strata-app --typescript
242
+ cd my-strata-app
243
+ npm install @strata-ds/core
244
+ ```
245
+
246
+ ### 2. Integrate the StrataProvider
247
+
248
+ Wrap your application's root component with `StrataProvider`. This provider manages the connection to the Strata backend.
249
+
250
+ | Prop | Type | Description |
251
+ | :----------------- | :------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
252
+ | `syncEnabled` | `boolean` | If `true`, the library will fetch and sync tokens/components from the server. |
253
+ | `snapshotCdnBase` | `string` | **Recommended.** Base CDN URL for snapshot files (e.g. `"https://cdn.strata.charisol.io"`). When set together with `projectId`, the provider fetches a single `strata.json` snapshot per poll cycle instead of 3 API calls. Takes precedence over `syncUrl`. |
254
+ | `projectId` | `string` | Your Strata project ID (shown in the dashboard URL and project settings). Required when using `snapshotCdnBase`. |
255
+ | `syncUrl` | `string` | Legacy base sync URL. `StrataProvider` will append `/variables`, `/components`, and `/custom` to this URL. Ignored when `snapshotCdnBase` + `projectId` are provided. |
256
+ | `syncInterval` | `number` | Polling interval in milliseconds to check for design system updates. Default: `3000`. |
257
+ | `syncToken` | `string` | Sync token from your project dashboard. When set, all sync requests carry `Authorization: Bearer <token>`. Required if your project is not fully public. |
258
+ | `initialData` | `DesignSystemData` | Initial design system data to use before the first sync. |
259
+ | `userDesignSystem` | `DesignSystemData` | Override design system data — useful for storybook, testing, or static mode. Takes precedence over `initialData`. |
260
+ | `onSyncError` | `(error: { code: number; message: string; source: string }) => void` | Callback invoked when a sync cycle fails. `code` is the HTTP status (0 for non-HTTP errors), `message` is a human-readable description, and `source` is `"cdn"` or `"sync"`. |
261
+ | `onSyncSuccess` | `(data: DesignSystemData) => void` | Callback invoked whenever a sync cycle succeeds with new data. |
262
+
263
+ ```tsx
264
+ // app/layout.tsx (Next.js App Router)
265
+ "use client";
266
+ import { StrataProvider } from "@strata-ds/core";
267
+
268
+ export default function RootLayout({
269
+ children,
270
+ }: {
271
+ children: React.ReactNode;
272
+ }) {
273
+ return (
274
+ <html lang="en">
275
+ <body>
276
+ <StrataProvider
277
+ syncEnabled={true}
278
+ projectId="YOUR_PROJECT_ID"
279
+ snapshotCdnBase="https://cdn.strata.charisol.io"
280
+ syncInterval={5000}
281
+ >
282
+ {children}
283
+ </StrataProvider>
284
+ </body>
285
+ </html>
286
+ );
287
+ }
288
+ ```
289
+
290
+ > 💡 Replace `YOUR_PROJECT_ID` with the ID from your Strata project dashboard. For private projects, add `syncToken="pt_live_your_token_here"` (get it from the **Publish & Sync** tab).
291
+
292
+ ### Sync token authentication
293
+
294
+ If your project has a sync token set in the Strata dashboard, pass it as `syncToken`. Every polling request will automatically include `Authorization: Bearer <token>`.
295
+
296
+ Projects with `syncToken` set are only readable by clients that present the correct token. This is the recommended way to gate read access to your design system without managing user accounts.
297
+
298
+ ```tsx
299
+ <StrataProvider
300
+ syncEnabled={true}
301
+ projectId="YOUR_PROJECT_ID"
302
+ snapshotCdnBase="https://cdn.strata.charisol.io"
303
+ syncToken="pt_live_your_token_here"
304
+ syncInterval={5000}
305
+ >
306
+ {children}
307
+ </StrataProvider>
308
+ ```
309
+
310
+ ## Using Design System Components
311
+
312
+ `@strata-ds/core` provides dynamic access to your components defined in Strata.
313
+
314
+ ### Accessing Components with `useComponents`
315
+
316
+ ```tsx
317
+ "use client";
318
+ import { useComponents } from "@strata-ds/core";
319
+
320
+ function AppContent() {
321
+ // Components are named exactly as you defined them in your Strata project
322
+ const { Button, Navbar, Card } = useComponents();
323
+
324
+ return (
325
+ <>
326
+ {/* Render conditionally while components are loading */}
327
+ {Button && (
328
+ <Button onClick={() => console.log("clicked")}>Click me</Button>
329
+ )}
330
+
331
+ {Card && <Card style={{ padding: "20px" }}>Card content here</Card>}
332
+ </>
333
+ );
334
+ }
335
+ ```
336
+
337
+ ### Accessing Design System Context with `useStrata`
338
+
339
+ ```tsx
340
+ "use client";
341
+ import { useStrata } from "@strata-ds/core";
342
+
343
+ function StatusBar() {
344
+ const { designSystem, syncStatus, lastSynced } = useStrata();
345
+
346
+ return (
347
+ <div>
348
+ <p>Sync status: {syncStatus}</p>
349
+ <p>Last synced: {lastSynced?.toLocaleTimeString() || "Never"}</p>
350
+ <p>Components: {Object.keys(designSystem.components).join(", ")}</p>
351
+ </div>
352
+ );
353
+ }
354
+ ```
355
+
356
+ ## Debugging and Troubleshooting
357
+
358
+ ### Quick Debug Panel
359
+
360
+ Add `<StrataDebug />` anywhere inside `<StrataProvider>` to inspect:
361
+
362
+ - ✅ Active sync mode (CDN vs Legacy)
363
+ - ✅ Connection status
364
+ - ✅ Loaded components
365
+ - ✅ Sync token presence (never shows the actual token)
366
+
367
+ ```tsx
368
+ "use client";
369
+ import { StrataDebug } from "@strata-ds/core";
370
+
371
+ function App() {
372
+ return (
373
+ <>
374
+ <StrataDebug />
375
+ {/* Your app content */}
376
+ </>
377
+ );
378
+ }
379
+ ```
380
+
381
+ The panel automatically displays the relevant fields for the active sync mode:
382
+
383
+ - **CDN mode** (`snapshotCdnBase` + `projectId` set): shows `✅ CDN Snapshot`, Project ID, resolved Snapshot URL, token presence, and sync interval.
384
+ - **Legacy mode** (`syncUrl` set): shows `⚠️ Legacy (3 requests/poll)`, Sync URL, token presence, and sync interval.
385
+ - **Disabled**: shows `❌ Disabled`.
386
+
387
+ > 🔒 The `syncToken` value is **never** rendered — the panel only shows `✅ Present` or `❌ None`.
388
+
389
+ ---
390
+
391
+ ### Common Issues
392
+
393
+ | Problem | Solution |
394
+ |---------|----------|
395
+ | **401 Unauthorized** | Your `syncToken` is invalid or expired. Go to **Publish & Sync** tab in your Strata project and copy a fresh token. |
396
+ | **403 Forbidden** | Your project has CORS restrictions. Add your domain to `allowedOrigins` in your Strata project settings. |
397
+ | **Components not rendering** | 1. Check `projectId` matches your dashboard URL<br>2. Verify components exist in your Strata project<br>3. Open DevTools → Console and look for `🔄 Starting design system sync...` |
398
+ | **Styles broken / unstyled** | You forgot to import CSS! Add to your root layout: `import "@strata-ds/core/dist/styles.css";` |
399
+ | **TypeScript errors** | Your component names must match exactly (case-sensitive). Check `useComponents()` return type in DevTools. |
400
+
401
+ ---
402
+
403
+ ### Network Debugging
404
+
405
+ Open **DevTools → Network tab** and filter by:
406
+
407
+ **CDN Mode** (`snapshotCdnBase` + `projectId` set):
408
+
409
+ - Look for: `https://cdn.strata.charisol.io/snapshots/YOUR_PROJECT_ID/strata.json`
410
+ - Status should be **200 OK** or **304 Not Modified**
411
+ - Response should be a JSON object with `variables`, `components`, `custom`
412
+
413
+ **Legacy Mode** (`syncUrl` set):
414
+
415
+ - Look for 3 requests:
416
+ - `${syncUrl}/variables` → returns `{}`
417
+ - `${syncUrl}/components` → returns `{}`
418
+ - `${syncUrl}/custom` → returns `{}`
419
+ - All should return **200 OK**
420
+
421
+ ---
422
+
423
+ ### Console Debugging
424
+
425
+ Check for these messages:
426
+
427
+ - ✅ `🔄 Starting design system sync...` → Sync is working
428
+ - ✅ `📊 Components available: Button, Navbar, Card` → Components loaded
429
+ - ✅ `🎨 Variables available: colors, spacing, typography` → Tokens loaded
430
+ - ❌ `❌ Sync failed: 401` → Token issue (see table above)
431
+ - ❌ `❌ Sync failed: 403` → CORS issue (see table above)
432
+
433
+ ---
434
+
435
+ ### Programmatic Inspection
436
+
437
+ ```tsx
438
+ "use client";
439
+ import { useStrata } from "@strata-ds/core";
440
+
441
+ function DebugPanel() {
442
+ const { designSystem, syncStatus, lastSynced, projectId, syncEnabled } =
443
+ useStrata();
444
+
445
+ return (
446
+ <div style={{ padding: "1rem", background: "#f9fafb", borderRadius: 8 }}>
447
+ <h3>🔍 Strata Debug Info</h3>
448
+ <pre>
449
+ {JSON.stringify(
450
+ {
451
+ syncStatus,
452
+ syncEnabled,
453
+ projectId,
454
+ lastSynced: lastSynced?.toLocaleTimeString() || "Never",
455
+ componentsLoaded: Object.keys(designSystem.components),
456
+ variablesLoaded: Object.keys(designSystem.variables),
457
+ },
458
+ null,
459
+ 2,
460
+ )}
461
+ </pre>
462
+ </div>
463
+ );
464
+ }
465
+ ```
466
+
467
+ ### Hooks Reference
468
+
469
+ | Hook / Property | Description |
470
+ | :----------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
471
+ | `useStrata()` | Returns full context: `designSystem`, `syncStatus`, `lastSynced`, `syncUrl`, `snapshotCdnBase`, `projectId`, `syncEnabled`, `forceSync`. |
472
+ | `useComponents()` | Returns ready-to-use React components by PascalCase name. |
473
+ | `useDynamicComponents()` | Returns the raw component registry map. |
474
+
475
+ ## Customisation and Overrides
476
+
477
+ By default, all components are styled based on the latest tokens fetched from your Strata project. This ensures perfect design-to-code fidelity.
478
+
479
+ **Local Overrides**
480
+
481
+ Override any style locally using standard React props:
482
+
483
+ ```tsx
484
+ <Button
485
+ style={{ backgroundColor: "#007bff", color: "white" }}
486
+ className="my-custom-class"
487
+ >
488
+ Custom styled button
489
+ </Button>
490
+ ```
491
+
492
+ ## Dynamic Updates (Hot-Reloading)
493
+
494
+ `@strata-ds/core` intelligently handles design updates:
495
+
496
+ 1. A designer makes a change in Strata (e.g., updates a colour token or modifies a component).
497
+ 2. Strata generates a new checksum.
498
+ 3. Your `StrataProvider` (via `syncInterval`) polls the `syncUrl`.
499
+ 4. If the checksum has changed, the library fetches new design tokens and component configurations, and your app's components are dynamically restyled — without a page refresh.
500
+
501
+ ## Registry API
502
+
503
+ `strataRegistry` is the underlying singleton registry that stores all registered components.
504
+
505
+ ```tsx
506
+ import { strataRegistry } from "@strata-ds/core";
507
+
508
+ // Check if a component is registered
509
+ strataRegistry.hasComponent("Button");
510
+
511
+ // Get a component by name
512
+ const ButtonComponent = strataRegistry.getComponent("Button");
513
+ ```
514
+
515
+ ## Component Factory
516
+
517
+ `StrataComponentFactory` creates React components from Strata component definitions.
518
+
519
+ ```tsx
520
+ import { StrataComponentFactory } from "@strata-ds/core";
521
+
522
+ const MyComponent = StrataComponentFactory.createComponent(
523
+ "MyComponent",
524
+ componentData,
525
+ designSystem,
526
+ );
527
+ ```
528
+
529
+ ## Key Features
530
+
531
+ - 🔁 Live sync with Strata backend
532
+ - 🧠 Token-driven styling
533
+ - 🧩 Dynamic component registry
534
+ - 🛠 Inline style overrides supported
535
+ - 📦 Installable via npm
536
+ - 📴 Offline-first fallback
537
+ - 🧪 Debug tools included (`StrataDebug`)
538
+
539
+ ## License
540
+
541
+ MIT © [Charisol](https://strata.charisol.io)