restale 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/README.md +56 -0
- package/dist/index.d.mts +316 -0
- package/dist/index.mjs +102 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# restale
|
|
2
|
+
|
|
3
|
+
Typed SDK for the Restale storefront API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add restale
|
|
9
|
+
# or
|
|
10
|
+
npm install restale
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Restale } from "restale"
|
|
17
|
+
|
|
18
|
+
const restale = new Restale("rst_live_...", {
|
|
19
|
+
baseUrl: "https://your-restale-instance.com",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const products = await restale.products.list({})
|
|
23
|
+
|
|
24
|
+
const product = await restale.products.get({
|
|
25
|
+
handle: "classic-burger",
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
new Restale(apiKey, {
|
|
33
|
+
baseUrl,
|
|
34
|
+
headers,
|
|
35
|
+
fetch,
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- `baseUrl` — your Restale API origin. Defaults to `https://api.restale.dev`.
|
|
40
|
+
- `headers` — additional headers to send with every request.
|
|
41
|
+
- `fetch` — custom `fetch` implementation (useful for tests or non-browser runtimes).
|
|
42
|
+
|
|
43
|
+
## Low-level client
|
|
44
|
+
|
|
45
|
+
If you need to configure the transport yourself, import the factory:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { createRestaleClient } from "restale"
|
|
49
|
+
|
|
50
|
+
const client = createRestaleClient(apiKey, { baseUrl })
|
|
51
|
+
await client.products.list({})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import * as _$_orpc_contract0 from "@orpc/contract";
|
|
2
|
+
import { ContractRouterClient, InferContractRouterInputs, InferContractRouterOutputs } from "@orpc/contract";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import * as _$zod_v4_core0 from "zod/v4/core";
|
|
5
|
+
|
|
6
|
+
//#region src/products/schemas.d.ts
|
|
7
|
+
declare const productStatusSchema: z.ZodEnum<{
|
|
8
|
+
draft: "draft";
|
|
9
|
+
active: "active";
|
|
10
|
+
inactive: "inactive";
|
|
11
|
+
archived: "archived";
|
|
12
|
+
}>;
|
|
13
|
+
declare const modifierStatusSchema: z.ZodEnum<{
|
|
14
|
+
active: "active";
|
|
15
|
+
inactive: "inactive";
|
|
16
|
+
archived: "archived";
|
|
17
|
+
}>;
|
|
18
|
+
declare const productMediaSchema: z.ZodObject<{
|
|
19
|
+
id: z.ZodUUID;
|
|
20
|
+
url: z.ZodString;
|
|
21
|
+
optionValueId: z.ZodNullable<z.ZodUUID>;
|
|
22
|
+
type: z.ZodString;
|
|
23
|
+
sortOrder: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
declare const productOptionValueSchema: z.ZodObject<{
|
|
26
|
+
id: z.ZodUUID;
|
|
27
|
+
value: z.ZodString;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
declare const productOptionSchema: z.ZodObject<{
|
|
30
|
+
id: z.ZodUUID;
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
values: z.ZodArray<z.ZodObject<{
|
|
33
|
+
id: z.ZodUUID;
|
|
34
|
+
value: z.ZodString;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
declare const productVariantSchema: z.ZodObject<{
|
|
38
|
+
id: z.ZodUUID;
|
|
39
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
40
|
+
price: z.ZodString;
|
|
41
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
42
|
+
isAvailable: z.ZodBoolean;
|
|
43
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
declare const modifierSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodUUID;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
priceDelta: z.ZodString;
|
|
49
|
+
maxQuantity: z.ZodNullable<z.ZodNumber>;
|
|
50
|
+
imageUrl: z.ZodNullable<z.ZodString>;
|
|
51
|
+
status: z.ZodEnum<{
|
|
52
|
+
active: "active";
|
|
53
|
+
inactive: "inactive";
|
|
54
|
+
archived: "archived";
|
|
55
|
+
}>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
declare const modifierGroupSchema: z.ZodObject<{
|
|
58
|
+
id: z.ZodUUID;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
handle: z.ZodString;
|
|
61
|
+
minSelections: z.ZodNumber;
|
|
62
|
+
maxSelections: z.ZodNullable<z.ZodNumber>;
|
|
63
|
+
modifiers: z.ZodArray<z.ZodObject<{
|
|
64
|
+
id: z.ZodUUID;
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
priceDelta: z.ZodString;
|
|
67
|
+
maxQuantity: z.ZodNullable<z.ZodNumber>;
|
|
68
|
+
imageUrl: z.ZodNullable<z.ZodString>;
|
|
69
|
+
status: z.ZodEnum<{
|
|
70
|
+
active: "active";
|
|
71
|
+
inactive: "inactive";
|
|
72
|
+
archived: "archived";
|
|
73
|
+
}>;
|
|
74
|
+
}, z.core.$strip>>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
declare const productVariantWithModifiersSchema: z.ZodObject<{
|
|
77
|
+
id: z.ZodUUID;
|
|
78
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
79
|
+
price: z.ZodString;
|
|
80
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
81
|
+
isAvailable: z.ZodBoolean;
|
|
82
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
83
|
+
modifierGroups: z.ZodArray<z.ZodObject<{
|
|
84
|
+
id: z.ZodUUID;
|
|
85
|
+
name: z.ZodString;
|
|
86
|
+
handle: z.ZodString;
|
|
87
|
+
minSelections: z.ZodNumber;
|
|
88
|
+
maxSelections: z.ZodNullable<z.ZodNumber>;
|
|
89
|
+
modifiers: z.ZodArray<z.ZodObject<{
|
|
90
|
+
id: z.ZodUUID;
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
priceDelta: z.ZodString;
|
|
93
|
+
maxQuantity: z.ZodNullable<z.ZodNumber>;
|
|
94
|
+
imageUrl: z.ZodNullable<z.ZodString>;
|
|
95
|
+
status: z.ZodEnum<{
|
|
96
|
+
active: "active";
|
|
97
|
+
inactive: "inactive";
|
|
98
|
+
archived: "archived";
|
|
99
|
+
}>;
|
|
100
|
+
}, z.core.$strip>>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
declare const productListItemSchema: z.ZodObject<{
|
|
104
|
+
id: z.ZodUUID;
|
|
105
|
+
handle: z.ZodString;
|
|
106
|
+
name: z.ZodString;
|
|
107
|
+
description: z.ZodNullable<z.ZodString>;
|
|
108
|
+
status: z.ZodEnum<{
|
|
109
|
+
draft: "draft";
|
|
110
|
+
active: "active";
|
|
111
|
+
inactive: "inactive";
|
|
112
|
+
archived: "archived";
|
|
113
|
+
}>;
|
|
114
|
+
media: z.ZodArray<z.ZodObject<{
|
|
115
|
+
id: z.ZodUUID;
|
|
116
|
+
url: z.ZodString;
|
|
117
|
+
optionValueId: z.ZodNullable<z.ZodUUID>;
|
|
118
|
+
type: z.ZodString;
|
|
119
|
+
sortOrder: z.ZodNumber;
|
|
120
|
+
}, z.core.$strip>>;
|
|
121
|
+
options: z.ZodArray<z.ZodObject<{
|
|
122
|
+
id: z.ZodUUID;
|
|
123
|
+
name: z.ZodString;
|
|
124
|
+
values: z.ZodArray<z.ZodObject<{
|
|
125
|
+
id: z.ZodUUID;
|
|
126
|
+
value: z.ZodString;
|
|
127
|
+
}, z.core.$strip>>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
130
|
+
id: z.ZodUUID;
|
|
131
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
132
|
+
price: z.ZodString;
|
|
133
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
134
|
+
isAvailable: z.ZodBoolean;
|
|
135
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
declare const productDetailsSchema: z.ZodObject<{
|
|
139
|
+
id: z.ZodUUID;
|
|
140
|
+
handle: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
description: z.ZodNullable<z.ZodString>;
|
|
143
|
+
status: z.ZodEnum<{
|
|
144
|
+
draft: "draft";
|
|
145
|
+
active: "active";
|
|
146
|
+
inactive: "inactive";
|
|
147
|
+
archived: "archived";
|
|
148
|
+
}>;
|
|
149
|
+
media: z.ZodArray<z.ZodObject<{
|
|
150
|
+
id: z.ZodUUID;
|
|
151
|
+
url: z.ZodString;
|
|
152
|
+
optionValueId: z.ZodNullable<z.ZodUUID>;
|
|
153
|
+
type: z.ZodString;
|
|
154
|
+
sortOrder: z.ZodNumber;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
options: z.ZodArray<z.ZodObject<{
|
|
157
|
+
id: z.ZodUUID;
|
|
158
|
+
name: z.ZodString;
|
|
159
|
+
values: z.ZodArray<z.ZodObject<{
|
|
160
|
+
id: z.ZodUUID;
|
|
161
|
+
value: z.ZodString;
|
|
162
|
+
}, z.core.$strip>>;
|
|
163
|
+
}, z.core.$strip>>;
|
|
164
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
165
|
+
id: z.ZodUUID;
|
|
166
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
167
|
+
price: z.ZodString;
|
|
168
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
169
|
+
isAvailable: z.ZodBoolean;
|
|
170
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
171
|
+
modifierGroups: z.ZodArray<z.ZodObject<{
|
|
172
|
+
id: z.ZodUUID;
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
handle: z.ZodString;
|
|
175
|
+
minSelections: z.ZodNumber;
|
|
176
|
+
maxSelections: z.ZodNullable<z.ZodNumber>;
|
|
177
|
+
modifiers: z.ZodArray<z.ZodObject<{
|
|
178
|
+
id: z.ZodUUID;
|
|
179
|
+
name: z.ZodString;
|
|
180
|
+
priceDelta: z.ZodString;
|
|
181
|
+
maxQuantity: z.ZodNullable<z.ZodNumber>;
|
|
182
|
+
imageUrl: z.ZodNullable<z.ZodString>;
|
|
183
|
+
status: z.ZodEnum<{
|
|
184
|
+
active: "active";
|
|
185
|
+
inactive: "inactive";
|
|
186
|
+
archived: "archived";
|
|
187
|
+
}>;
|
|
188
|
+
}, z.core.$strip>>;
|
|
189
|
+
}, z.core.$strip>>;
|
|
190
|
+
}, z.core.$strip>>;
|
|
191
|
+
}, z.core.$strip>;
|
|
192
|
+
type ProductStatus = z.infer<typeof productStatusSchema>;
|
|
193
|
+
type ModifierStatus = z.infer<typeof modifierStatusSchema>;
|
|
194
|
+
type ProductMedia = z.infer<typeof productMediaSchema>;
|
|
195
|
+
type ProductOptionValue = z.infer<typeof productOptionValueSchema>;
|
|
196
|
+
type ProductOption = z.infer<typeof productOptionSchema>;
|
|
197
|
+
type ProductVariant = z.infer<typeof productVariantSchema>;
|
|
198
|
+
type Modifier = z.infer<typeof modifierSchema>;
|
|
199
|
+
type ModifierGroup = z.infer<typeof modifierGroupSchema>;
|
|
200
|
+
type ProductVariantWithModifiers = z.infer<typeof productVariantWithModifiersSchema>;
|
|
201
|
+
type ProductListItem = z.infer<typeof productListItemSchema>;
|
|
202
|
+
type ProductDetails = z.infer<typeof productDetailsSchema>;
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/index.d.ts
|
|
205
|
+
declare const contract: {
|
|
206
|
+
products: {
|
|
207
|
+
list: _$_orpc_contract0.ContractProcedureBuilderWithInputOutput<z.ZodOptional<z.ZodObject<{}, _$zod_v4_core0.$strip>>, z.ZodArray<z.ZodObject<{
|
|
208
|
+
id: z.ZodUUID;
|
|
209
|
+
handle: z.ZodString;
|
|
210
|
+
name: z.ZodString;
|
|
211
|
+
description: z.ZodNullable<z.ZodString>;
|
|
212
|
+
status: z.ZodEnum<{
|
|
213
|
+
draft: "draft";
|
|
214
|
+
active: "active";
|
|
215
|
+
inactive: "inactive";
|
|
216
|
+
archived: "archived";
|
|
217
|
+
}>;
|
|
218
|
+
media: z.ZodArray<z.ZodObject<{
|
|
219
|
+
id: z.ZodUUID;
|
|
220
|
+
url: z.ZodString;
|
|
221
|
+
optionValueId: z.ZodNullable<z.ZodUUID>;
|
|
222
|
+
type: z.ZodString;
|
|
223
|
+
sortOrder: z.ZodNumber;
|
|
224
|
+
}, _$zod_v4_core0.$strip>>;
|
|
225
|
+
options: z.ZodArray<z.ZodObject<{
|
|
226
|
+
id: z.ZodUUID;
|
|
227
|
+
name: z.ZodString;
|
|
228
|
+
values: z.ZodArray<z.ZodObject<{
|
|
229
|
+
id: z.ZodUUID;
|
|
230
|
+
value: z.ZodString;
|
|
231
|
+
}, _$zod_v4_core0.$strip>>;
|
|
232
|
+
}, _$zod_v4_core0.$strip>>;
|
|
233
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
234
|
+
id: z.ZodUUID;
|
|
235
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
236
|
+
price: z.ZodString;
|
|
237
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
238
|
+
isAvailable: z.ZodBoolean;
|
|
239
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
240
|
+
}, _$zod_v4_core0.$strip>>;
|
|
241
|
+
}, _$zod_v4_core0.$strip>>, Record<never, never>, Record<never, never>>;
|
|
242
|
+
get: _$_orpc_contract0.ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
243
|
+
handle: z.ZodString;
|
|
244
|
+
}, _$zod_v4_core0.$strip>, z.ZodNullable<z.ZodObject<{
|
|
245
|
+
id: z.ZodUUID;
|
|
246
|
+
handle: z.ZodString;
|
|
247
|
+
name: z.ZodString;
|
|
248
|
+
description: z.ZodNullable<z.ZodString>;
|
|
249
|
+
status: z.ZodEnum<{
|
|
250
|
+
draft: "draft";
|
|
251
|
+
active: "active";
|
|
252
|
+
inactive: "inactive";
|
|
253
|
+
archived: "archived";
|
|
254
|
+
}>;
|
|
255
|
+
media: z.ZodArray<z.ZodObject<{
|
|
256
|
+
id: z.ZodUUID;
|
|
257
|
+
url: z.ZodString;
|
|
258
|
+
optionValueId: z.ZodNullable<z.ZodUUID>;
|
|
259
|
+
type: z.ZodString;
|
|
260
|
+
sortOrder: z.ZodNumber;
|
|
261
|
+
}, _$zod_v4_core0.$strip>>;
|
|
262
|
+
options: z.ZodArray<z.ZodObject<{
|
|
263
|
+
id: z.ZodUUID;
|
|
264
|
+
name: z.ZodString;
|
|
265
|
+
values: z.ZodArray<z.ZodObject<{
|
|
266
|
+
id: z.ZodUUID;
|
|
267
|
+
value: z.ZodString;
|
|
268
|
+
}, _$zod_v4_core0.$strip>>;
|
|
269
|
+
}, _$zod_v4_core0.$strip>>;
|
|
270
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
271
|
+
id: z.ZodUUID;
|
|
272
|
+
sku: z.ZodNullable<z.ZodString>;
|
|
273
|
+
price: z.ZodString;
|
|
274
|
+
compareAtPrice: z.ZodNullable<z.ZodString>;
|
|
275
|
+
isAvailable: z.ZodBoolean;
|
|
276
|
+
optionValueIds: z.ZodArray<z.ZodUUID>;
|
|
277
|
+
modifierGroups: z.ZodArray<z.ZodObject<{
|
|
278
|
+
id: z.ZodUUID;
|
|
279
|
+
name: z.ZodString;
|
|
280
|
+
handle: z.ZodString;
|
|
281
|
+
minSelections: z.ZodNumber;
|
|
282
|
+
maxSelections: z.ZodNullable<z.ZodNumber>;
|
|
283
|
+
modifiers: z.ZodArray<z.ZodObject<{
|
|
284
|
+
id: z.ZodUUID;
|
|
285
|
+
name: z.ZodString;
|
|
286
|
+
priceDelta: z.ZodString;
|
|
287
|
+
maxQuantity: z.ZodNullable<z.ZodNumber>;
|
|
288
|
+
imageUrl: z.ZodNullable<z.ZodString>;
|
|
289
|
+
status: z.ZodEnum<{
|
|
290
|
+
active: "active";
|
|
291
|
+
inactive: "inactive";
|
|
292
|
+
archived: "archived";
|
|
293
|
+
}>;
|
|
294
|
+
}, _$zod_v4_core0.$strip>>;
|
|
295
|
+
}, _$zod_v4_core0.$strip>>;
|
|
296
|
+
}, _$zod_v4_core0.$strip>>;
|
|
297
|
+
}, _$zod_v4_core0.$strip>>, Record<never, never>, Record<never, never>>;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
type Contract = typeof contract;
|
|
301
|
+
type ContractInputs = InferContractRouterInputs<Contract>;
|
|
302
|
+
type ContractOutputs = InferContractRouterOutputs<Contract>;
|
|
303
|
+
type RestaleClient = ContractRouterClient<Contract>;
|
|
304
|
+
type RestaleOptions = {
|
|
305
|
+
baseUrl?: string;
|
|
306
|
+
headers?: Record<string, string>;
|
|
307
|
+
fetch?: typeof fetch;
|
|
308
|
+
};
|
|
309
|
+
declare function createRestaleClient(apiKey: string, options?: RestaleOptions): RestaleClient;
|
|
310
|
+
declare class Restale {
|
|
311
|
+
readonly products: RestaleClient["products"];
|
|
312
|
+
constructor(apiKey: string, options?: RestaleOptions);
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
export { Contract, ContractInputs, ContractOutputs, Modifier, ModifierGroup, ModifierStatus, ProductDetails, ProductListItem, ProductMedia, ProductOption, ProductOptionValue, ProductStatus, ProductVariant, ProductVariantWithModifiers, Restale, RestaleClient, RestaleOptions, contract, createRestaleClient, modifierGroupSchema, modifierSchema, modifierStatusSchema, productDetailsSchema, productListItemSchema, productMediaSchema, productOptionSchema, productOptionValueSchema, productStatusSchema, productVariantSchema, productVariantWithModifiersSchema };
|
|
316
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createORPCClient } from "@orpc/client";
|
|
2
|
+
import { OpenAPILink } from "@orpc/openapi-client/fetch";
|
|
3
|
+
import { oc } from "@orpc/contract";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
//#region src/products/schemas.ts
|
|
6
|
+
const productStatusSchema = z.enum([
|
|
7
|
+
"draft",
|
|
8
|
+
"active",
|
|
9
|
+
"inactive",
|
|
10
|
+
"archived"
|
|
11
|
+
]);
|
|
12
|
+
const modifierStatusSchema = z.enum([
|
|
13
|
+
"active",
|
|
14
|
+
"inactive",
|
|
15
|
+
"archived"
|
|
16
|
+
]);
|
|
17
|
+
const productMediaSchema = z.object({
|
|
18
|
+
id: z.uuid(),
|
|
19
|
+
url: z.string(),
|
|
20
|
+
optionValueId: z.uuid().nullable(),
|
|
21
|
+
type: z.string(),
|
|
22
|
+
sortOrder: z.number().int()
|
|
23
|
+
});
|
|
24
|
+
const productOptionValueSchema = z.object({
|
|
25
|
+
id: z.uuid(),
|
|
26
|
+
value: z.string()
|
|
27
|
+
});
|
|
28
|
+
const productOptionSchema = z.object({
|
|
29
|
+
id: z.uuid(),
|
|
30
|
+
name: z.string(),
|
|
31
|
+
values: z.array(productOptionValueSchema)
|
|
32
|
+
});
|
|
33
|
+
const productVariantSchema = z.object({
|
|
34
|
+
id: z.uuid(),
|
|
35
|
+
sku: z.string().nullable(),
|
|
36
|
+
price: z.string(),
|
|
37
|
+
compareAtPrice: z.string().nullable(),
|
|
38
|
+
isAvailable: z.boolean(),
|
|
39
|
+
optionValueIds: z.array(z.uuid())
|
|
40
|
+
});
|
|
41
|
+
const modifierSchema = z.object({
|
|
42
|
+
id: z.uuid(),
|
|
43
|
+
name: z.string(),
|
|
44
|
+
priceDelta: z.string(),
|
|
45
|
+
maxQuantity: z.number().int().nullable(),
|
|
46
|
+
imageUrl: z.string().nullable(),
|
|
47
|
+
status: modifierStatusSchema
|
|
48
|
+
});
|
|
49
|
+
const modifierGroupSchema = z.object({
|
|
50
|
+
id: z.uuid(),
|
|
51
|
+
name: z.string(),
|
|
52
|
+
handle: z.string(),
|
|
53
|
+
minSelections: z.number().int(),
|
|
54
|
+
maxSelections: z.number().int().nullable(),
|
|
55
|
+
modifiers: z.array(modifierSchema)
|
|
56
|
+
});
|
|
57
|
+
const productVariantWithModifiersSchema = productVariantSchema.extend({ modifierGroups: z.array(modifierGroupSchema) });
|
|
58
|
+
const productListItemSchema = z.object({
|
|
59
|
+
id: z.uuid(),
|
|
60
|
+
handle: z.string(),
|
|
61
|
+
name: z.string(),
|
|
62
|
+
description: z.string().nullable(),
|
|
63
|
+
status: productStatusSchema,
|
|
64
|
+
media: z.array(productMediaSchema),
|
|
65
|
+
options: z.array(productOptionSchema),
|
|
66
|
+
variants: z.array(productVariantSchema)
|
|
67
|
+
});
|
|
68
|
+
const productDetailsSchema = productListItemSchema.extend({ variants: z.array(productVariantWithModifiersSchema) });
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/index.ts
|
|
71
|
+
const contract = { products: {
|
|
72
|
+
list: oc.route({
|
|
73
|
+
method: "GET",
|
|
74
|
+
path: "/products"
|
|
75
|
+
}).input(z.object({}).optional()).output(z.array(productListItemSchema)),
|
|
76
|
+
get: oc.route({
|
|
77
|
+
method: "GET",
|
|
78
|
+
path: "/products/:handle"
|
|
79
|
+
}).input(z.object({ handle: z.string().trim().min(1) })).output(productDetailsSchema.nullable())
|
|
80
|
+
} };
|
|
81
|
+
const DEFAULT_BASE_URL = "https://api.restale.dev";
|
|
82
|
+
function createRestaleClient(apiKey, options = {}) {
|
|
83
|
+
return createORPCClient(new OpenAPILink(contract, {
|
|
84
|
+
url: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
85
|
+
headers: () => ({
|
|
86
|
+
"x-api-key": apiKey,
|
|
87
|
+
...options.headers
|
|
88
|
+
}),
|
|
89
|
+
fetch: options.fetch
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
var Restale = class {
|
|
93
|
+
products;
|
|
94
|
+
constructor(apiKey, options = {}) {
|
|
95
|
+
const client = createRestaleClient(apiKey, options);
|
|
96
|
+
this.products = client.products;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { Restale, contract, createRestaleClient, modifierGroupSchema, modifierSchema, modifierStatusSchema, productDetailsSchema, productListItemSchema, productMediaSchema, productOptionSchema, productOptionValueSchema, productStatusSchema, productVariantSchema, productVariantWithModifiersSchema };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/products/schemas.ts","../src/products/index.ts","../src/index.ts"],"sourcesContent":["import * as z from \"zod\"\n\nexport const productStatusSchema = z.enum([\n \"draft\",\n \"active\",\n \"inactive\",\n \"archived\",\n])\n\nexport const modifierStatusSchema = z.enum([\"active\", \"inactive\", \"archived\"])\n\nexport const productMediaSchema = z.object({\n id: z.uuid(),\n url: z.string(),\n optionValueId: z.uuid().nullable(),\n type: z.string(),\n sortOrder: z.number().int(),\n})\n\nexport const productOptionValueSchema = z.object({\n id: z.uuid(),\n value: z.string(),\n})\n\nexport const productOptionSchema = z.object({\n id: z.uuid(),\n name: z.string(),\n values: z.array(productOptionValueSchema),\n})\n\nexport const productVariantSchema = z.object({\n id: z.uuid(),\n sku: z.string().nullable(),\n price: z.string(),\n compareAtPrice: z.string().nullable(),\n isAvailable: z.boolean(),\n optionValueIds: z.array(z.uuid()),\n})\n\nexport const modifierSchema = z.object({\n id: z.uuid(),\n name: z.string(),\n priceDelta: z.string(),\n maxQuantity: z.number().int().nullable(),\n imageUrl: z.string().nullable(),\n status: modifierStatusSchema,\n})\n\nexport const modifierGroupSchema = z.object({\n id: z.uuid(),\n name: z.string(),\n handle: z.string(),\n minSelections: z.number().int(),\n maxSelections: z.number().int().nullable(),\n modifiers: z.array(modifierSchema),\n})\n\nexport const productVariantWithModifiersSchema = productVariantSchema.extend({\n modifierGroups: z.array(modifierGroupSchema),\n})\n\nexport const productListItemSchema = z.object({\n id: z.uuid(),\n handle: z.string(),\n name: z.string(),\n description: z.string().nullable(),\n status: productStatusSchema,\n media: z.array(productMediaSchema),\n options: z.array(productOptionSchema),\n variants: z.array(productVariantSchema),\n})\n\nexport const productDetailsSchema = productListItemSchema.extend({\n variants: z.array(productVariantWithModifiersSchema),\n})\n\nexport type ProductStatus = z.infer<typeof productStatusSchema>\nexport type ModifierStatus = z.infer<typeof modifierStatusSchema>\nexport type ProductMedia = z.infer<typeof productMediaSchema>\nexport type ProductOptionValue = z.infer<typeof productOptionValueSchema>\nexport type ProductOption = z.infer<typeof productOptionSchema>\nexport type ProductVariant = z.infer<typeof productVariantSchema>\nexport type Modifier = z.infer<typeof modifierSchema>\nexport type ModifierGroup = z.infer<typeof modifierGroupSchema>\nexport type ProductVariantWithModifiers = z.infer<\n typeof productVariantWithModifiersSchema\n>\nexport type ProductListItem = z.infer<typeof productListItemSchema>\nexport type ProductDetails = z.infer<typeof productDetailsSchema>\n","import { oc } from \"@orpc/contract\"\nimport * as z from \"zod\"\n\nimport { productDetailsSchema, productListItemSchema } from \"./schemas\"\n\nexport const listProductsContract = oc\n .route({ method: \"GET\", path: \"/products\" })\n .input(z.object({}).optional())\n .output(z.array(productListItemSchema))\n\nexport const getProductContract = oc\n .route({ method: \"GET\", path: \"/products/:handle\" })\n .input(z.object({ handle: z.string().trim().min(1) }))\n .output(productDetailsSchema.nullable())\n\nexport const productsContract = {\n list: listProductsContract,\n get: getProductContract,\n}\n","import { createORPCClient } from \"@orpc/client\"\nimport type {\n ContractRouterClient,\n InferContractRouterInputs,\n InferContractRouterOutputs,\n} from \"@orpc/contract\"\nimport { OpenAPILink } from \"@orpc/openapi-client/fetch\"\n\nimport { productsContract } from \"./products\"\n\nexport const contract = {\n products: productsContract,\n}\n\nexport type Contract = typeof contract\nexport type ContractInputs = InferContractRouterInputs<Contract>\nexport type ContractOutputs = InferContractRouterOutputs<Contract>\nexport type RestaleClient = ContractRouterClient<Contract>\n\nexport type RestaleOptions = {\n baseUrl?: string\n headers?: Record<string, string>\n fetch?: typeof fetch\n}\n\nconst DEFAULT_BASE_URL = \"https://api.restale.dev\"\n\nexport function createRestaleClient(\n apiKey: string,\n options: RestaleOptions = {}\n): RestaleClient {\n const link = new OpenAPILink(contract, {\n url: options.baseUrl ?? DEFAULT_BASE_URL,\n headers: () => ({\n \"x-api-key\": apiKey,\n ...options.headers,\n }),\n fetch: options.fetch,\n })\n\n return createORPCClient(link)\n}\n\nexport class Restale {\n readonly products: RestaleClient[\"products\"]\n\n constructor(apiKey: string, options: RestaleOptions = {}) {\n const client = createRestaleClient(apiKey, options)\n this.products = client.products\n }\n}\n\nexport * from \"./products/schemas\"\n"],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "restale",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Typed SDK and contract for the Restale storefront API.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@orpc/client": "^1.13.13",
|
|
25
|
+
"@orpc/contract": "^1.13.13",
|
|
26
|
+
"@orpc/openapi-client": "^1.13.13",
|
|
27
|
+
"zod": "4.3.6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^9.39.4",
|
|
31
|
+
"prettier": "^3.8.1",
|
|
32
|
+
"tsdown": "^0.21.9",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"release": "pnpm publish --access public",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"format": "prettier --write \"**/*.ts\"",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|