@gethydra/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) 2026 Grant Capital Group
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,185 @@
1
+ # Hydra Node.js SDK
2
+
3
+ [![Version](https://img.shields.io/npm/v/@gethydra/sdk.svg)](https://www.npmjs.org/package/@gethydra/sdk)
4
+
5
+ The Hydra SDK provides typed access to the [Hydra Commerce API](https://hydrajs.dev) from server-side JavaScript and TypeScript applications.
6
+
7
+ For storefront client-side integration, see the [Checkout guide](https://hydrajs.dev/docs/guides/checkout).
8
+
9
+ ## Documentation
10
+
11
+ See the [API reference](https://hydrajs.dev/docs/api/products) for full endpoint documentation.
12
+
13
+ ## Requirements
14
+
15
+ Node.js 18 or later. The SDK is ESM-only.
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ npm install @gethydra/sdk
21
+ # or
22
+ bun add @gethydra/sdk
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Configure the client with your secret API key, available in the [Hydra admin panel](https://admin.myhydrastore.com).
28
+
29
+ ```ts
30
+ import { Hydra } from '@gethydra/sdk';
31
+
32
+ const hydra = new Hydra({ apiKey: 'sk_live_...' });
33
+
34
+ const { data: products } = await hydra.products.list({ limit: 10 });
35
+ console.log(products[0].title);
36
+ ```
37
+
38
+ ### Creating resources
39
+
40
+ ```ts
41
+ const { data: product } = await hydra.products.create({
42
+ title: 'Classic T-Shirt',
43
+ status: 'active',
44
+ variants: [
45
+ { title: 'Small', price: 2500, sku: 'TSHIRT-S' },
46
+ { title: 'Medium', price: 2500, sku: 'TSHIRT-M' },
47
+ ],
48
+ });
49
+ ```
50
+
51
+ ### Updating resources
52
+
53
+ ```ts
54
+ const { data: updated } = await hydra.products.update('prod_abc123', {
55
+ title: 'Premium T-Shirt',
56
+ });
57
+ ```
58
+
59
+ ### Error handling
60
+
61
+ ```ts
62
+ import { Hydra, HydraNotFoundError, HydraValidationError } from '@gethydra/sdk';
63
+
64
+ try {
65
+ await hydra.products.get('prod_nonexistent');
66
+ } catch (err) {
67
+ if (err instanceof HydraNotFoundError) {
68
+ console.log('Product not found');
69
+ } else if (err instanceof HydraValidationError) {
70
+ console.log('Validation:', err.message);
71
+ }
72
+ }
73
+ ```
74
+
75
+ ### Pagination
76
+
77
+ Each list resource has built-in `iterate()` and `toArray()` methods for cursor-based pagination:
78
+
79
+ ```ts
80
+ for await (const product of hydra.products.iterate({ limit: 50 })) {
81
+ console.log(product.title);
82
+ }
83
+ ```
84
+
85
+ Or collect all pages into an array:
86
+
87
+ ```ts
88
+ const all = await hydra.products.toArray({ status: 'active' });
89
+ ```
90
+
91
+ The low-level `paginate()` and `toArray()` helpers are also exported for advanced use:
92
+
93
+ ```ts
94
+ import { paginate } from '@gethydra/sdk';
95
+
96
+ for await (const product of paginate((cursor) =>
97
+ hydra.products.list({ limit: 50, cursor })
98
+ )) {
99
+ console.log(product.title);
100
+ }
101
+ ```
102
+
103
+ ### Webhook signature verification
104
+
105
+ ```ts
106
+ import { verifyWebhookSignature } from '@gethydra/sdk/webhooks';
107
+
108
+ const isValid = await verifyWebhookSignature(rawBody, signatureHeader, webhookSecret);
109
+ ```
110
+
111
+ ## Configuration
112
+
113
+ ```ts
114
+ const hydra = new Hydra({
115
+ apiKey: 'sk_live_...',
116
+ baseUrl: 'https://api.hydrajs.dev', // default
117
+ timeout: 80_000, // 80 seconds (default)
118
+ maxNetworkRetries: 1, // default
119
+ appInfo: {
120
+ name: 'MyApp',
121
+ version: '1.0.0',
122
+ },
123
+ });
124
+ ```
125
+
126
+ | Option | Default | Description |
127
+ | ------------------- | ---------------------------- | ---------------------------------------------- |
128
+ | `apiKey` | (required) | Your Hydra API key (`sk_live_*` or `sk_test_*`) |
129
+ | `baseUrl` | `https://api.hydrajs.dev` | API base URL |
130
+ | `timeout` | `80000` | Request timeout in milliseconds |
131
+ | `maxNetworkRetries` | `1` | Max automatic retries on network/server errors |
132
+ | `appInfo` | `undefined` | Integration metadata sent in User-Agent |
133
+
134
+ Both `timeout` and `maxNetworkRetries` can be overridden per-request.
135
+
136
+ ## Available resources
137
+
138
+ | Resource | Property | Description |
139
+ | -------------------- | ------------------ | ------------------------------------ |
140
+ | Products | `hydra.products` | Product catalog |
141
+ | Variants | `hydra.variants` | Product variants (size, color, etc.) |
142
+ | Collections | `hydra.collections`| Grouped product collections |
143
+ | Cart | `hydra.cart` | Shopping cart management |
144
+ | Checkout | `hydra.checkout` | Payment checkout flow |
145
+ | Search | `hydra.search` | Full-text search and suggestions |
146
+ | Orders | `hydra.orders` | Order management |
147
+ | Fulfillments | `hydra.fulfillments`| Shipment tracking |
148
+ | Refunds | `hydra.refunds` | Payment refunds |
149
+ | Returns | `hydra.returns` | Return requests |
150
+ | Draft Orders | `hydra.draftOrders`| Manual order drafts |
151
+ | Customers | `hydra.customers` | Customer management |
152
+ | Customer Groups | `hydra.customerGroups`| Customer segmentation |
153
+ | Addresses | `hydra.addresses` | Customer addresses |
154
+ | Store Credit | `hydra.storeCredit`| Credit balance and transactions |
155
+ | Inventory | `hydra.inventory` | Stock levels and adjustments |
156
+ | Locations | `hydra.locations` | Warehouse and store locations |
157
+ | Shipping | `hydra.shipping` | Zones and rates |
158
+ | Promotions | `hydra.promotions` | Automatic promotions |
159
+ | Discounts | `hydra.discounts` | Discount codes |
160
+ | Images | `hydra.images` | Media library |
161
+ | Webhooks | `hydra.webhooks` | Event subscriptions |
162
+ | Store | `hydra.store` | Store settings |
163
+ | Tags | `hydra.tags` | Resource tagging |
164
+ | Redirects | `hydra.redirects` | URL redirects |
165
+ | Companies | `hydra.companies` | B2B companies |
166
+ | Purchase Orders | `hydra.purchaseOrders`| Supplier purchase orders |
167
+ | Fulfillment Orders | `hydra.fulfillmentOrders`| Fulfillment routing |
168
+ | Metafields | `hydra.metafields` | Custom structured data |
169
+ | Tax | `hydra.tax` | Tax groups and rates |
170
+ | Exchange Rates | `hydra.exchangeRates`| Currency exchange rates |
171
+ | Navigation | `hydra.navigation` | Menu management |
172
+ | Notifications | `hydra.notifications`| Notification logs |
173
+ | Analytics | `hydra.analytics` | Sales and performance data |
174
+
175
+ ## TypeScript
176
+
177
+ The SDK is written in TypeScript and exports types for all API resources:
178
+
179
+ ```ts
180
+ import type { Product, Order, Customer } from '@gethydra/sdk';
181
+ ```
182
+
183
+ ## Support
184
+
185
+ For bug reports and feature requests, open an issue on [GitHub](https://github.com/Hydra-headless-commerce/website/issues).