@sazito/checkout 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sazito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # @sazito/checkout
2
+
3
+ Headless checkout engine + React/Next UI for the Sazito platform, powered by
4
+ `@sazito/client-sdk`. RTL-first (fa) with en support.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ pnpm add @sazito/client-sdk @sazito/checkout react@18 react-dom@18
10
+ ```
11
+
12
+ ## Architecture
13
+
14
+ ```
15
+ @sazito/checkout/core framework-agnostic engine (store, operateCart port, effects, selectors)
16
+ @sazito/checkout/react CheckoutProvider + useCheckout() hook
17
+ @sazito/checkout/next <SazitoCheckoutPage /> — the drop-in checkout component
18
+ @sazito/checkout/styles.css self-contained, themeable, RTL/LTR styles
19
+ ```
20
+
21
+ The React package **uses the SDK client you provide**. Create the Sazito SDK in
22
+ your app, pass it through `<SazitoProvider client={sazito}>` or the
23
+ `client` prop on `<CheckoutProvider>`, and checkout restores any seeded
24
+ credentials on that same SDK instance. This avoids duplicate SDK clients and
25
+ keeps cart/invoice/payment credentials in one place.
26
+
27
+ ## Usage (Next.js)
28
+
29
+ ```tsx
30
+ 'use client';
31
+ import '@sazito/checkout/styles.css';
32
+ import { createSazitoClient } from '@sazito/client-sdk';
33
+ import { SazitoProvider, SazitoCheckoutPage } from '@sazito/checkout/next';
34
+
35
+ const sazito = createSazitoClient({ domain: 'shop.example.com' });
36
+
37
+ export default function Checkout() {
38
+ return (
39
+ <SazitoProvider client={sazito}>
40
+ <SazitoCheckoutPage
41
+ credentials={{ cart: { identifier: 'cart-identifier' } }}
42
+ config={{
43
+ locale: 'fa',
44
+ continueShoppingUrl: '/',
45
+ theme: {
46
+ accent: '#4f46e5',
47
+ accentForeground: '#ffffff',
48
+ background: '#ffffff',
49
+ foreground: '#0f172a',
50
+ card: '#ffffff',
51
+ border: '#e6e7eb',
52
+ summaryBackground: '#f6f6fb',
53
+ radius: 16
54
+ }
55
+ }}
56
+ />
57
+ </SazitoProvider>
58
+ );
59
+ }
60
+ ```
61
+
62
+ ### Theme variables
63
+
64
+ `config.theme` (or the `theme` prop on `SazitoCheckout`) accepts:
65
+
66
+ | Property | CSS variable | Purpose |
67
+ | --- | --- | --- |
68
+ | `accent` | `--szc-accent` | Buttons and active states |
69
+ | `accentForeground` | `--szc-accent-foreground` | Text/icons on the accent |
70
+ | `accentSoft` | `--szc-accent-soft` | Selected and soft-accent surfaces |
71
+ | `background` | `--szc-bg` | Checkout background |
72
+ | `foreground` | `--szc-fg` | Primary text |
73
+ | `muted` | `--szc-muted` | Muted surfaces |
74
+ | `mutedForeground` | `--szc-muted-fg` | Secondary text |
75
+ | `border` | `--szc-border` | Borders and dividers |
76
+ | `card` | `--szc-card` | Card and input surfaces |
77
+ | `summaryBackground` | `--szc-summary-bg` | Summary sidebar |
78
+ | `danger` | `--szc-danger` | Errors and destructive states |
79
+ | `success` | `--szc-success` | Completed and success states |
80
+
81
+ `radius` and `fontFamily` remain available for shape and typography. Shipping-rate icon colors continue to come from the shipping API.
82
+
83
+ The component **inherits the host font** (`--szc-font: inherit`). The demo app
84
+ loads Vazirmatn on `<body>`; that's all it takes for a Persian/RTL checkout.
85
+
86
+ ## Flow (v1 scope)
87
+
88
+ 4 states — `cart → shipping → payment → result`:
89
+
90
+ - **Cart** — editable line items (quantity ±, remove).
91
+ - **Shipping** — guest contact + address form; per-package **shipping-method
92
+ switching** for physical items; digital items skip shipping.
93
+ - **Payment** — payment-method selection + discount code; the **Finish purchase**
94
+ (پایان خرید) CTA places the order directly (redirect / POST / pending-poll).
95
+ - **Result** — success / failed / pending, with order reference.
96
+
97
+ Deferred (post-v1): card-to-card upload, invoice dynamic forms, wallet credit
98
+ UI (engine keeps `toggleCredit`), multi-rate item reallocation, the legacy
99
+ `addDetails` user comment.
100
+
101
+ ## Notes / deviations
102
+
103
+ - **Styling.** We originally planned Tailwind-authored components. Because the
104
+ package exposes `styles.css` and must work in any React/Next app without
105
+ forcing a Tailwind setup on consumers, the UI ships **self-contained CSS**
106
+ (CSS-variable theme tokens, logical properties for RTL). The demo's Tailwind
107
+ setup is untouched. Switching to Tailwind authoring later is possible without
108
+ changing the engine.
109
+ - **Local dev.** `exports` point at TypeScript source; the example consumes it
110
+ via Next `transpilePackages`. `rollup.config.js` exists for producing a
111
+ publishable `dist/` (point `exports` at `dist` before publishing).
112
+ - The engine is pure and emits typed effects; the React provider installs a
113
+ default browser executor (redirect / gateway POST / polling). SSR-safe.
114
+
115
+ ## Scripts
116
+
117
+ ```
118
+ pnpm test # vitest (store, selectors, format, engine contract)
119
+ pnpm typecheck # tsc --noEmit
120
+ pnpm build # rollup → dist (for publishing)
121
+ ```