@moonbase.sh/storefront-api 0.0.0-next-20260526085904

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 ADDED
@@ -0,0 +1,116 @@
1
+ # @moonbase.sh/storefront-api
2
+
3
+ Browser-first Moonbase SDK for storefront and customer flows: storefront data, identity, carts/orders, vouchers, inventory, and activation requests.
4
+ Learn more about our storefront API in our official docs: https://moonbase.sh/docs/storefronts/api/
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pnpm add @moonbase.sh/storefront-api
10
+ ```
11
+
12
+ ## Create a client
13
+
14
+ ```ts
15
+ import { MoonbaseClient } from '@moonbase.sh/storefront-api'
16
+
17
+ const client = new MoonbaseClient({
18
+ endpoint: 'https://demo.moonbase.sh',
19
+ persistUtm: true,
20
+ })
21
+ ```
22
+
23
+ Configuration notes:
24
+
25
+ - `endpoint`: your Moonbase storefront URL.
26
+ - `includeManifests`: include downloadable file manifests when available.
27
+ - `persistUtm`: store detected UTM values in localStorage instead of sessionStorage.
28
+
29
+ ## Common usage
30
+
31
+ ### Load storefront and create an order
32
+
33
+ ```ts
34
+ const storefront = await client.storefront.get()
35
+
36
+ const order = await client.orders.pushContent(
37
+ {
38
+ id: crypto.randomUUID(),
39
+ currency: storefront.suggestedCurrency,
40
+ items: [
41
+ {
42
+ type: 'Product',
43
+ productId: storefront.products[0].id,
44
+ variationId: storefront.products[0].defaultVariation?.id ?? '',
45
+ quantity: 1,
46
+ },
47
+ ],
48
+ },
49
+ {
50
+ returnUrl: `${window.location.origin}/checkout-complete`,
51
+ },
52
+ )
53
+
54
+ const redirectUrl = order.hostedCheckoutUrl ?? order.checkoutUrl
55
+ if (redirectUrl)
56
+ window.location.href = redirectUrl
57
+ ```
58
+
59
+ ### Sign in a customer
60
+
61
+ ```ts
62
+ await client.identity.signIn('jane@example.com', 'password')
63
+
64
+ const user = await client.identity.get()
65
+ console.log(user.email)
66
+ ```
67
+
68
+ ### Redeem a voucher
69
+
70
+ ```ts
71
+ const preview = await client.vouchers.peek('MY-CODE')
72
+ console.log(preview)
73
+
74
+ await client.identity.signIn('jane@example.com', 'password')
75
+ const redeemed = await client.vouchers.redeem('MY-CODE')
76
+ console.log(redeemed)
77
+ ```
78
+
79
+ ## Inventory flow
80
+
81
+ Most inventory endpoints require an authenticated user:
82
+
83
+ ```ts
84
+ const products = await client.inventory.products.getOwned()
85
+ const licenses = await client.inventory.licenses.get()
86
+ ```
87
+
88
+ Pagination on inventory endpoints is done by passing the `next` URL back into the same method:
89
+
90
+ ```ts
91
+ let page = await client.inventory.products.getOwned()
92
+
93
+ while (page.hasMore && page.next) {
94
+ page = await client.inventory.products.getOwned(page.next)
95
+ }
96
+ ```
97
+
98
+ ## Endpoint groups
99
+
100
+ `client.storefront`, `client.identity`, `client.orders`, `client.vouchers`, `client.inventory`, `client.activationRequests`, `client.vendor`.
101
+
102
+ ## Token storage and logging
103
+
104
+ By default, credentials are stored in localStorage (or in-memory if localStorage is unavailable).
105
+
106
+ You can inject your own storage/logger implementations:
107
+
108
+ ```ts
109
+ import { ConsoleLogger, InMemoryStore, LogLevel, MoonbaseClient } from '@moonbase.sh/storefront-api'
110
+
111
+ const client = new MoonbaseClient({
112
+ endpoint: 'https://demo.moonbase.sh',
113
+ store: new InMemoryStore(),
114
+ logger: new ConsoleLogger(LogLevel.Debug),
115
+ })
116
+ ```