@omni-commerce/sdk 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) OmniCommerce
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,125 @@
1
+ # @omni-commerce/sdk
2
+
3
+ TypeScript / JavaScript client for the [OmniCommerce API](https://docs.omnicommerce.sg/api-reference).
4
+
5
+ The client is generated from the public OpenAPI spec so every documented REST endpoint is typed. The npm org is `@omni-commerce` because the unscoped `omnicommerce` name is reserved.
6
+
7
+ The surface is a resource client with one request object per call, dual ESM/CJS builds, and typed HTTP errors.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ yarn add @omni-commerce/sdk
13
+ # or: npm install @omni-commerce/sdk
14
+ ```
15
+
16
+ Node 18+ (global `fetch`). Works in Node, Bun, and other fetch runtimes.
17
+
18
+ ## Usage
19
+
20
+ Named export only — there is no default export.
21
+
22
+ ```ts
23
+ import { OmniClient } from "@omni-commerce/sdk";
24
+
25
+ const client = new OmniClient({
26
+ apiKey: process.env.OMNI_API_KEY, // or omit to read OMNI_API_KEY
27
+ });
28
+
29
+ const products = await client.products.list({ q: "lamp" });
30
+
31
+ const job = await client.products.create({
32
+ product: {
33
+ sku: "SKU-100",
34
+ title: "Sample product",
35
+ price: 29.9,
36
+ currency: "SGD",
37
+ images: ["https://cdn.example.com/product.jpg"],
38
+ },
39
+ });
40
+
41
+ const created = await client.jobs.wait({ jobId: job.jobId });
42
+ ```
43
+
44
+ API keys are organization-scoped. Do not send `organizationId` on API-key requests.
45
+
46
+ ### Options
47
+
48
+ ```ts
49
+ const client = new OmniClient({
50
+ apiKey: "omni_sk_...",
51
+ environment: "http://localhost:3000", // default https://omnicommerce.sg
52
+ timeoutInSeconds: 60,
53
+ maxRetries: 2,
54
+ });
55
+ ```
56
+
57
+ Per-request overrides:
58
+
59
+ ```ts
60
+ await client.orders.get(
61
+ { orderId: "ord_123" },
62
+ { timeoutInSeconds: 15, abortSignal: controller.signal },
63
+ );
64
+ ```
65
+
66
+ `await request.withRawResponse()` returns `{ data, rawResponse }` with status and headers.
67
+
68
+ ## Resources
69
+
70
+ | Client | Examples |
71
+ | ----------------------------- | ------------------------------------------------------------------------------ |
72
+ | `client.products` | `list`, `create`, `get`, `update`, `delete`, `publish`, `bulkImport`, `enrich` |
73
+ | `client.orders` | `list`, `create`, `get`, `update` |
74
+ | `client.promotions` | `list`, `create`, `get`, `update`, `delete`, `sync` |
75
+ | `client.priceBooks` | `list`, `create`, `get`, `update`, `delete`, `preview` |
76
+ | `client.aop` | `create`, `execute`, `getConfig`, `updateConfig`, `retry` |
77
+ | `client.jobs` | `get`, `cancel`, `wait` |
78
+ | `client.webhooks` | `list`, `create` |
79
+ | `client.checkoutSessions` | `create`, `get`, `update`, `complete`, `cancel` |
80
+ | `client.ucp.checkoutSessions` | Universal Commerce Protocol checkout |
81
+ | `client.oauth` | `token`, `revoke` |
82
+
83
+ Every other documented tag (looks, returns, settlements, marketplaces, search, evaluate, monitor, sync, …) is exposed the same way.
84
+
85
+ ## Errors
86
+
87
+ Non-2xx responses throw a subclass of `OmniError`:
88
+
89
+ ```ts
90
+ import { OmniClient, NotFoundError, OmniError } from "@omni-commerce/sdk";
91
+
92
+ try {
93
+ await client.products.get({ productId: "missing" });
94
+ } catch (error) {
95
+ if (error instanceof NotFoundError) {
96
+ // 404
97
+ } else if (error instanceof OmniError) {
98
+ console.error(error.statusCode, error.body);
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## Webhooks
104
+
105
+ ```ts
106
+ import { constructEvent } from "@omni-commerce/sdk";
107
+
108
+ const event = await constructEvent(
109
+ rawBody,
110
+ headers,
111
+ process.env.OMNI_WEBHOOK_SECRET,
112
+ );
113
+ ```
114
+
115
+ Signature: HMAC-SHA256 over `{timestamp}.{rawBody}` compared to `X-Omni-Signature`.
116
+
117
+ ## Regenerate from OpenAPI
118
+
119
+ From the monorepo root:
120
+
121
+ ```bash
122
+ yarn sdk:generate
123
+ ```
124
+
125
+ That refreshes `docs/openapi.json`, the OpenAPI TypeScript types, and `src/generated/resources.ts`.