@cimplify/sdk 0.38.0 → 0.38.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.
package/dist/mock/cli.mjs CHANGED
@@ -7839,11 +7839,19 @@ function createMockApp(options = {}) {
7839
7839
  app.use("*", async (c, next) => {
7840
7840
  const origin = c.req.header("origin") ?? "";
7841
7841
  const allow = corsOrigins === "*" ? "*" : corsOrigins.includes(origin) ? origin : corsOrigins[0] ?? "*";
7842
- c.header("Access-Control-Allow-Origin", allow);
7843
- c.header("Access-Control-Allow-Headers", "content-type,authorization,x-session-token,idempotency-key");
7844
- c.header("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS");
7845
- c.header("Access-Control-Expose-Headers", "x-session-token");
7846
- if (c.req.method === "OPTIONS") return new Response(null, { status: 204 });
7842
+ const headers = {
7843
+ "Access-Control-Allow-Origin": allow,
7844
+ "Access-Control-Allow-Credentials": "true",
7845
+ "Access-Control-Allow-Headers": c.req.header("access-control-request-headers") ?? "content-type,authorization,x-session-token,idempotency-key",
7846
+ "Access-Control-Allow-Methods": "GET,POST,PATCH,DELETE,OPTIONS",
7847
+ "Access-Control-Expose-Headers": "x-session-token",
7848
+ "Access-Control-Max-Age": "86400",
7849
+ Vary: "Origin"
7850
+ };
7851
+ if (c.req.method === "OPTIONS") {
7852
+ return new Response(null, { status: 204, headers });
7853
+ }
7854
+ for (const [k, v] of Object.entries(headers)) c.header(k, v);
7847
7855
  await next();
7848
7856
  });
7849
7857
  }
@@ -7207,11 +7207,19 @@ function createMockApp(options = {}) {
7207
7207
  app.use("*", async (c, next) => {
7208
7208
  const origin = c.req.header("origin") ?? "";
7209
7209
  const allow = corsOrigins === "*" ? "*" : corsOrigins.includes(origin) ? origin : corsOrigins[0] ?? "*";
7210
- c.header("Access-Control-Allow-Origin", allow);
7211
- c.header("Access-Control-Allow-Headers", "content-type,authorization,x-session-token,idempotency-key");
7212
- c.header("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS");
7213
- c.header("Access-Control-Expose-Headers", "x-session-token");
7214
- if (c.req.method === "OPTIONS") return new Response(null, { status: 204 });
7210
+ const headers = {
7211
+ "Access-Control-Allow-Origin": allow,
7212
+ "Access-Control-Allow-Credentials": "true",
7213
+ "Access-Control-Allow-Headers": c.req.header("access-control-request-headers") ?? "content-type,authorization,x-session-token,idempotency-key",
7214
+ "Access-Control-Allow-Methods": "GET,POST,PATCH,DELETE,OPTIONS",
7215
+ "Access-Control-Expose-Headers": "x-session-token",
7216
+ "Access-Control-Max-Age": "86400",
7217
+ Vary: "Origin"
7218
+ };
7219
+ if (c.req.method === "OPTIONS") {
7220
+ return new Response(null, { status: 204, headers });
7221
+ }
7222
+ for (const [k, v] of Object.entries(headers)) c.header(k, v);
7215
7223
  await next();
7216
7224
  });
7217
7225
  }
@@ -7205,11 +7205,19 @@ function createMockApp(options = {}) {
7205
7205
  app.use("*", async (c, next) => {
7206
7206
  const origin = c.req.header("origin") ?? "";
7207
7207
  const allow = corsOrigins === "*" ? "*" : corsOrigins.includes(origin) ? origin : corsOrigins[0] ?? "*";
7208
- c.header("Access-Control-Allow-Origin", allow);
7209
- c.header("Access-Control-Allow-Headers", "content-type,authorization,x-session-token,idempotency-key");
7210
- c.header("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS");
7211
- c.header("Access-Control-Expose-Headers", "x-session-token");
7212
- if (c.req.method === "OPTIONS") return new Response(null, { status: 204 });
7208
+ const headers = {
7209
+ "Access-Control-Allow-Origin": allow,
7210
+ "Access-Control-Allow-Credentials": "true",
7211
+ "Access-Control-Allow-Headers": c.req.header("access-control-request-headers") ?? "content-type,authorization,x-session-token,idempotency-key",
7212
+ "Access-Control-Allow-Methods": "GET,POST,PATCH,DELETE,OPTIONS",
7213
+ "Access-Control-Expose-Headers": "x-session-token",
7214
+ "Access-Control-Max-Age": "86400",
7215
+ Vary: "Origin"
7216
+ };
7217
+ if (c.req.method === "OPTIONS") {
7218
+ return new Response(null, { status: 204, headers });
7219
+ }
7220
+ for (const [k, v] of Object.entries(headers)) c.header(k, v);
7213
7221
  await next();
7214
7222
  });
7215
7223
  }
package/dist/mock/msw.js CHANGED
@@ -7205,11 +7205,19 @@ function createMockApp(options = {}) {
7205
7205
  app.use("*", async (c, next) => {
7206
7206
  const origin = c.req.header("origin") ?? "";
7207
7207
  const allow = corsOrigins === "*" ? "*" : corsOrigins.includes(origin) ? origin : corsOrigins[0] ?? "*";
7208
- c.header("Access-Control-Allow-Origin", allow);
7209
- c.header("Access-Control-Allow-Headers", "content-type,authorization,x-session-token,idempotency-key");
7210
- c.header("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS");
7211
- c.header("Access-Control-Expose-Headers", "x-session-token");
7212
- if (c.req.method === "OPTIONS") return new Response(null, { status: 204 });
7208
+ const headers = {
7209
+ "Access-Control-Allow-Origin": allow,
7210
+ "Access-Control-Allow-Credentials": "true",
7211
+ "Access-Control-Allow-Headers": c.req.header("access-control-request-headers") ?? "content-type,authorization,x-session-token,idempotency-key",
7212
+ "Access-Control-Allow-Methods": "GET,POST,PATCH,DELETE,OPTIONS",
7213
+ "Access-Control-Expose-Headers": "x-session-token",
7214
+ "Access-Control-Max-Age": "86400",
7215
+ Vary: "Origin"
7216
+ };
7217
+ if (c.req.method === "OPTIONS") {
7218
+ return new Response(null, { status: 204, headers });
7219
+ }
7220
+ for (const [k, v] of Object.entries(headers)) c.header(k, v);
7213
7221
  await next();
7214
7222
  });
7215
7223
  }
package/dist/mock/msw.mjs CHANGED
@@ -7203,11 +7203,19 @@ function createMockApp(options = {}) {
7203
7203
  app.use("*", async (c, next) => {
7204
7204
  const origin = c.req.header("origin") ?? "";
7205
7205
  const allow = corsOrigins === "*" ? "*" : corsOrigins.includes(origin) ? origin : corsOrigins[0] ?? "*";
7206
- c.header("Access-Control-Allow-Origin", allow);
7207
- c.header("Access-Control-Allow-Headers", "content-type,authorization,x-session-token,idempotency-key");
7208
- c.header("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS");
7209
- c.header("Access-Control-Expose-Headers", "x-session-token");
7210
- if (c.req.method === "OPTIONS") return new Response(null, { status: 204 });
7206
+ const headers = {
7207
+ "Access-Control-Allow-Origin": allow,
7208
+ "Access-Control-Allow-Credentials": "true",
7209
+ "Access-Control-Allow-Headers": c.req.header("access-control-request-headers") ?? "content-type,authorization,x-session-token,idempotency-key",
7210
+ "Access-Control-Allow-Methods": "GET,POST,PATCH,DELETE,OPTIONS",
7211
+ "Access-Control-Expose-Headers": "x-session-token",
7212
+ "Access-Control-Max-Age": "86400",
7213
+ Vary: "Origin"
7214
+ };
7215
+ if (c.req.method === "OPTIONS") {
7216
+ return new Response(null, { status: 204, headers });
7217
+ }
7218
+ for (const [k, v] of Object.entries(headers)) c.header(k, v);
7211
7219
  await next();
7212
7220
  });
7213
7221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cimplify/sdk",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "description": "Cimplify Commerce SDK for storefronts",
5
5
  "keywords": [
6
6
  "cimplify",
@@ -11,16 +11,18 @@
11
11
  "preview": "vite preview"
12
12
  },
13
13
  "dependencies": {
14
- "@cimplify/sdk": "^0.37.0",
14
+ "@cimplify/sdk": "^0.38.1",
15
15
  "react": "^19.2.5",
16
16
  "react-dom": "^19.2.5",
17
17
  "react-router-dom": "^7.9.0"
18
18
  },
19
19
  "devDependencies": {
20
+ "@tailwindcss/vite": "^4.2.4",
20
21
  "@types/react": "^19.2.14",
21
22
  "@types/react-dom": "^19.2.3",
22
23
  "@vitejs/plugin-react": "^5.0.0",
23
24
  "concurrently": "^9.0.0",
25
+ "tailwindcss": "^4.2.4",
24
26
  "typescript": "^5.9.3",
25
27
  "vite": "^7.0.0"
26
28
  }
@@ -1,18 +1,45 @@
1
+ import { useEffect, useState } from "react";
1
2
  import { Routes, Route, NavLink, useNavigate } from "react-router-dom";
2
- import { CataloguePage, CartPage, CheckoutPage, useCimplify } from "@cimplify/sdk/react";
3
- import type { Product } from "@cimplify/sdk";
3
+ import { CataloguePage, CartPage, CheckoutPage, useCimplifyClient } from "@cimplify/sdk/react";
4
+ import type { Product, Category } from "@cimplify/sdk";
4
5
 
5
- function CartPill() {
6
- const cim = useCimplify();
7
- const total = cim?.cart?.totalItems ?? 0;
8
- return <span className="cimplify-storefront__cart-pill">Cart · {total}</span>;
6
+ function CartPill({ count }: { count: number }) {
7
+ return <span className="cimplify-storefront__cart-pill">Cart · {count}</span>;
9
8
  }
10
9
 
11
10
  function Catalogue() {
12
11
  const navigate = useNavigate();
12
+ const { client } = useCimplifyClient();
13
+ const [products, setProducts] = useState<Product[] | undefined>(undefined);
14
+ const [categories, setCategories] = useState<Category[] | undefined>(undefined);
15
+ const [loading, setLoading] = useState(true);
16
+
17
+ useEffect(() => {
18
+ let cancelled = false;
19
+ void (async () => {
20
+ try {
21
+ const [p, c] = await Promise.all([
22
+ client.catalogue.getProducts({ limit: 50 }),
23
+ client.catalogue.getCategories(),
24
+ ]);
25
+ if (cancelled) return;
26
+ if (p.ok) setProducts(p.value.items);
27
+ if (c.ok) setCategories(c.value);
28
+ } finally {
29
+ if (!cancelled) setLoading(false);
30
+ }
31
+ })();
32
+ return () => {
33
+ cancelled = true;
34
+ };
35
+ }, [client]);
36
+
37
+ if (loading) return <p>Loading shop…</p>;
13
38
  return (
14
39
  <CataloguePage
15
40
  title="Shop"
41
+ products={products}
42
+ categories={categories}
16
43
  onProductClick={(p: Product) => navigate(`/products/${p.id}`)}
17
44
  />
18
45
  );
@@ -52,14 +79,23 @@ function OrderConfirmation() {
52
79
  }
53
80
 
54
81
  export function App() {
82
+ const [cartCount, setCartCount] = useState(0);
83
+ const { client } = useCimplifyClient();
84
+
85
+ useEffect(() => {
86
+ void client.cart.getCount().then((r) => {
87
+ if (r.ok) setCartCount(r.value);
88
+ });
89
+ }, [client]);
90
+
55
91
  return (
56
92
  <div className="cimplify-storefront">
57
93
  <header className="cimplify-storefront__nav">
58
- <NavLink to="/"><h1>__STOREFRONT_NAME__</h1></NavLink>
94
+ <NavLink to="/"><h1>cimplify-store</h1></NavLink>
59
95
  <nav>
60
96
  <NavLink to="/" end>Shop</NavLink>
61
97
  <NavLink to="/cart">Cart</NavLink>
62
- <CartPill />
98
+ <CartPill count={cartCount} />
63
99
  </nav>
64
100
  </header>
65
101
 
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom/client";
3
3
  import { BrowserRouter } from "react-router-dom";
4
+ import { createCimplifyClient } from "@cimplify/sdk";
4
5
  import { CimplifyProvider } from "@cimplify/sdk/react";
5
6
  import { App } from "./App";
6
7
 
@@ -8,12 +9,18 @@ import "@cimplify/sdk/styles.css";
8
9
  import "./styles.css";
9
10
 
10
11
  const baseUrl = import.meta.env.VITE_CIMPLIFY_API_URL ?? "http://127.0.0.1:8787";
11
- const businessId = import.meta.env.VITE_CIMPLIFY_BUSINESS_ID ?? "bus_default_akua_bakery";
12
+ const publicKey = import.meta.env.VITE_CIMPLIFY_PUBLIC_KEY ?? "mock-dev";
13
+
14
+ const client = createCimplifyClient({
15
+ baseUrl,
16
+ publicKey,
17
+ suppressPublicKeyWarning: true,
18
+ });
12
19
 
13
20
  ReactDOM.createRoot(document.getElementById("root")!).render(
14
21
  <React.StrictMode>
15
22
  <BrowserRouter>
16
- <CimplifyProvider config={{ baseUrl, apiKey: "mock-dev", businessId }}>
23
+ <CimplifyProvider client={client}>
17
24
  <App />
18
25
  </CimplifyProvider>
19
26
  </BrowserRouter>
@@ -1,3 +1,5 @@
1
+ @import "tailwindcss";
2
+
1
3
  html, body {
2
4
  margin: 0;
3
5
  padding: 0;
@@ -7,7 +9,6 @@ html, body {
7
9
  }
8
10
 
9
11
  * { box-sizing: border-box; }
10
-
11
12
  a { color: inherit; text-decoration: none; }
12
13
 
13
14
  .cimplify-storefront {
@@ -57,3 +58,8 @@ a { color: inherit; text-decoration: none; }
57
58
  border-top: 1px solid #e2e8f0;
58
59
  background: white;
59
60
  }
61
+
62
+ .cimplify-storefront__main svg {
63
+ max-width: 64px;
64
+ max-height: 64px;
65
+ }
@@ -1,10 +1,8 @@
1
1
  import { defineConfig } from "vite";
2
2
  import react from "@vitejs/plugin-react";
3
+ import tailwindcss from "@tailwindcss/vite";
3
4
 
4
5
  export default defineConfig({
5
- plugins: [react()],
6
- server: {
7
- port: 5173,
8
- open: true,
9
- },
6
+ plugins: [react(), tailwindcss()],
7
+ server: { port: 5173, open: false, strictPort: false },
10
8
  });