@moonbase.sh/storefront-api 1.0.1 → 1.0.6

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 (2) hide show
  1. package/README.md +115 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,115 @@
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
+ if (order.checkoutUrl)
55
+ window.location.href = order.checkoutUrl
56
+ ```
57
+
58
+ ### Sign in a customer
59
+
60
+ ```ts
61
+ await client.identity.signIn('jane@example.com', 'password')
62
+
63
+ const user = await client.identity.get()
64
+ console.log(user.email)
65
+ ```
66
+
67
+ ### Redeem a voucher
68
+
69
+ ```ts
70
+ const preview = await client.vouchers.peek('MY-CODE')
71
+ console.log(preview)
72
+
73
+ await client.identity.signIn('jane@example.com', 'password')
74
+ const redeemed = await client.vouchers.redeem('MY-CODE')
75
+ console.log(redeemed)
76
+ ```
77
+
78
+ ## Inventory flow
79
+
80
+ Most inventory endpoints require an authenticated user:
81
+
82
+ ```ts
83
+ const products = await client.inventory.products.getOwned()
84
+ const licenses = await client.inventory.licenses.get()
85
+ ```
86
+
87
+ Pagination on inventory endpoints is done by passing the `next` URL back into the same method:
88
+
89
+ ```ts
90
+ let page = await client.inventory.products.getOwned()
91
+
92
+ while (page.hasMore && page.next) {
93
+ page = await client.inventory.products.getOwned(page.next)
94
+ }
95
+ ```
96
+
97
+ ## Endpoint groups
98
+
99
+ `client.storefront`, `client.identity`, `client.orders`, `client.vouchers`, `client.inventory`, `client.activationRequests`, `client.vendor`.
100
+
101
+ ## Token storage and logging
102
+
103
+ By default, credentials are stored in localStorage (or in-memory if localStorage is unavailable).
104
+
105
+ You can inject your own storage/logger implementations:
106
+
107
+ ```ts
108
+ import { ConsoleLogger, InMemoryStore, LogLevel, MoonbaseClient } from '@moonbase.sh/storefront-api'
109
+
110
+ const client = new MoonbaseClient({
111
+ endpoint: 'https://demo.moonbase.sh',
112
+ store: new InMemoryStore(),
113
+ logger: new ConsoleLogger(LogLevel.Debug),
114
+ })
115
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.6",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",