@misiki/gocommerce-connector 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 misiki-in
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,188 @@
1
+ # @misiki/gocommerce-connector
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@misiki/gocommerce-connector.svg)](https://www.npmjs.com/package/@misiki/gocommerce-connector)
4
+ [![License](https://img.shields.io/npm/l/@misiki/gocommerce-connector.svg)](https://github.com/misiki-in/gocommerce-connector/blob/main/LICENSE)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ **The Official TypeScript API Connector for connecting `svelte-commerce` to a GoCommerce backend.**
8
+
9
+ `@misiki/gocommerce-connector` bridges [svelte-commerce](https://github.com/misiki-in/svelte-commerce) storefronts with [GoCommerce](https://github.com/itswadesh/gocommerce) — "a small, composable commerce engine for Go" — as part of the [Litekart](https://litekart.in) connector suite, mirroring the full 43-service surface of [`@misiki/litekart-connector`](https://github.com/misiki-in/litekart-connector). It is written against the server's own OpenAPI document (`GET /doc` on a running store).
10
+
11
+ > **Coverage:** 10 of 43 services are wired to the live GoCommerce API — catalogue, search, cart,
12
+ > checkout, payment methods and orders. That is the honest ceiling, not a to-do list: GoCommerce is
13
+ > guest-checkout only by design, so there are no accounts, wishlists, reviews, coupons or CMS to
14
+ > wire. Those services answer with empty lists, and their writes throw a named message rather than
15
+ > succeeding silently.
16
+
17
+ ---
18
+
19
+ ## 🚀 Step-by-Step Integration Guide
20
+
21
+ ### 1. Install the Connector
22
+
23
+ Inside your `svelte-commerce` project directory, run:
24
+
25
+ ```bash
26
+ bun i @misiki/gocommerce-connector
27
+ ```
28
+
29
+ *(Or using npm / pnpm / yarn):*
30
+ ```bash
31
+ npm install @misiki/gocommerce-connector
32
+ # or
33
+ pnpm add @misiki/gocommerce-connector
34
+ ```
35
+
36
+ ### 2. Configure `kitcommerce.config.ts`
37
+
38
+ In `svelte-commerce`, open `kitcommerce.config.ts` and point the `services` export at the GoCommerce
39
+ override module:
40
+
41
+ ```typescript
42
+ // kitcommerce.config.ts
43
+ export * as services from './src/lib/core/connectors/gocommerce'
44
+
45
+ export default {
46
+ // store identity overrides — name, logo, favicon, currencyCode, menus, plugins …
47
+ }
48
+ ```
49
+
50
+ ### 3. Configure Credentials
51
+
52
+ The connector needs one thing: the base URL of the GoCommerce server.
53
+
54
+ ```env
55
+ PUBLIC_GOCOMMERCE_API_URL='http://127.0.0.1:8080'
56
+ ```
57
+
58
+ `svelte-commerce` hands that variable to the connector at boot. Outside the storefront, set it
59
+ directly:
60
+
61
+ ```ts
62
+ import { BaseService, productService } from '@misiki/gocommerce-connector'
63
+
64
+ BaseService.setCredentials({ apiUrl: 'http://127.0.0.1:8080' })
65
+
66
+ const products = await productService.list({ page: 1 })
67
+ ```
68
+
69
+ ### 4. Register store identity
70
+
71
+ GoCommerce is a commerce engine, not a CMS: it has no record for the store's name, logo, currency,
72
+ menus, plugin toggles or theme variables. The connector reads them from a provider the storefront
73
+ registers once at boot:
74
+
75
+ ```ts
76
+ import { setStaticStore } from '@misiki/gocommerce-connector'
77
+
78
+ setStaticStore(async () => ({ name: 'My Store', currencyCode: 'USD', /* … */ }))
79
+ ```
80
+
81
+ `svelte-commerce` does this for you in `src/lib/core/connectors/gocommerce.ts`, merging
82
+ `default-store.json` under the `kitcommerce.config.ts` default export.
83
+
84
+ ---
85
+
86
+ ## How it works
87
+
88
+ ### The browser cannot call GoCommerce directly
89
+
90
+ GoCommerce sends no `Access-Control-Allow-Origin` header and answers a preflight with `405`. So in
91
+ the browser every call is sent to `API_PROXY_PREFIX` (`/proxy/gocommerce`) on the storefront's own
92
+ origin, and the storefront forwards it to the API. Server-side calls go straight to
93
+ `PUBLIC_GOCOMMERCE_API_URL`. The rule lives in `BaseService.apiUrl`; media URLs always resolve
94
+ through the proxy, because a server-rendered `<img src>` is still fetched by the browser.
95
+
96
+ `svelte-commerce` ships that proxy at `src/routes/proxy/gocommerce/[...path]/+server.ts`. Any other
97
+ host needs an equivalent route.
98
+
99
+ ### Money
100
+
101
+ GoCommerce sends money as an integer count of the currency's minor unit plus its code
102
+ (`{ amount_minor: 2500, currency: "USD" }`). `fromMoney` converts once, against the currency the
103
+ amount arrived with, into the plain major-unit number the storefront's components print.
104
+
105
+ ### The cart
106
+
107
+ A cart is an opaque token and possessing it is the whole authorisation. The connector persists it as
108
+ `cart_id`. A write that fails is followed by a re-read: if the cart is gone or no longer `open`, the
109
+ token is dropped and the item goes into a fresh cart; if the cart is alive, the failure was real and
110
+ is passed straight through.
111
+
112
+ ### The address step, sessions and the address book
113
+
114
+ GoCommerce has no address on a cart — the delivery address is an argument to
115
+ `POST /api/checkout/{code}`. The connector holds the shopper's details in the browser against the
116
+ cart id (`checkout-details`) and spends them when the order is placed. Saved addresses are likewise
117
+ browser-local (`address-book`); they never leave the device except as part of that call.
118
+
119
+ Because there are no accounts, a `connect.sid` / `me` cookie can only be left over from another
120
+ backend. `hasPhantomSession` / `clearPhantomSession` let the storefront drop them at load.
121
+
122
+ ### Checkout, payment and orders
123
+
124
+ `GET /api/checkout` lists the installed payment codes; `POST /api/checkout/{code}` validates the
125
+ cart, reserves inventory and creates the order in one transaction, with an `Idempotency-Key`.
126
+ Gateway fields ride on `payment.client_data` and are spread onto the return value. Only `cod` is
127
+ verified end to end. The order's `access_token`, returned once, is stored so "my orders" is every
128
+ order placed from this browser.
129
+
130
+ ### Catalogue and search
131
+
132
+ The shopper-facing catalogue takes `q`, `limit`, `page` and a category or collection slug — no sort,
133
+ no tag filter, no price range. Sorting and facets are applied in the connector over one window of
134
+ 200 products, the API's own `limit` ceiling. Product images are read from both `image_url` and each
135
+ variant's `image`, because the former is missing from the OpenAPI document while the server returns
136
+ it on every read.
137
+
138
+ ---
139
+
140
+ ## Service behaviour
141
+
142
+ | Service | Behaviour |
143
+ | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
144
+ | `ProductService`, `SearchService` | `/api/products`, `/api/products/slug/{slug}`, `/api/categories/{slug}`; sort and facets local |
145
+ | `CategoryService`, `CollectionService` | `/api/categories`, `/api/collections` and their slug lookups |
146
+ | `MeilisearchService`, `AutocompleteService` | `?q=` on the catalogue — GoCommerce ships no separate search engine |
147
+ | `CartService` | `/api/carts` and its line-items; the address step is held in the browser |
148
+ | `CheckoutService`, `PaymentMethodService` | `GET /api/checkout`, `POST /api/checkout/{code}` |
149
+ | `OrderService` | `/api/orders/{number}?token=…`; the confirmation page falls back to the converted cart |
150
+ | `StoreService`, `MenuService`, `CurrencyService`, `PluginService`, `SettingService`, `RegionService`, … | The registered static store |
151
+ | `AuthService`, `UserService`, `ProfileService` | No accounts exist — reads answer empty, writes explain why |
152
+ | `AddressService` | A browser-local address book |
153
+ | `PageService`, `BlogService`, `BannerService`, `GalleryService`, `ReelsService` | Empty — no CMS |
154
+ | `WishlistService`, `CouponService`, `ReviewService`, `VendorService` | Empty lists; writes throw a named message |
155
+ | `ContactService`, `EnquiryService`, `UploadService` | Throw — there is no inbox behind them |
156
+
157
+ ---
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ bun install
163
+ bun run typecheck
164
+ bun run build # tsup → dist/ (ESM + CJS + d.ts)
165
+ bun p # build and publish
166
+ ```
167
+
168
+ Source layout (`src/services/`):
169
+
170
+ | File | Purpose |
171
+ | --------------------- | ---------------------------------------------------------- |
172
+ | `base.ts` | transport, credentials, the `{ data, meta }` envelope |
173
+ | `types.ts` | GoCommerce's wire shapes, from its own OpenAPI document |
174
+ | `money.ts` | minor units → the numbers components print |
175
+ | `mappers.ts` | GoCommerce → the storefront's (Litekart-shaped) models |
176
+ | `catalog.ts` | products, categories, collections, listing search |
177
+ | `cart.ts` | the cart token and its lines |
178
+ | `checkout-details.ts` | what checkout needs that a GoCommerce cart cannot hold |
179
+ | `address-book.ts` | the saved addresses GoCommerce has nowhere to put |
180
+ | `checkout.ts` | `POST /api/checkout/{code}` and the installed payment methods |
181
+ | `orders.ts` | guest order lookup by access token |
182
+ | `store.ts` | store identity from the registered static config |
183
+ | `static-store.ts` | the static store provider and the feature toggles forced off |
184
+ | `unsupported.ts` | what GoCommerce deliberately does not have |
185
+
186
+ ## License
187
+
188
+ MIT