@managesales/storefront 1.0.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.
@@ -0,0 +1,316 @@
1
+ /**
2
+ * ManageSales Storefront SDK
3
+ * --------------------------
4
+ * Resource-based client for building online storefronts.
5
+ * Works with any framework: Next.js, Remix, Nuxt, Astro, plain HTML.
6
+ *
7
+ * Usage:
8
+ * import { createStorefrontClient } from "./managesales-storefront";
9
+ * const client = createStorefrontClient({ workspaceId: "<workspace_id>" });
10
+ * const products = await client.products.list();
11
+ */
12
+ interface StorefrontConfig {
13
+ /** Your workspace ID (required) */
14
+ workspaceId: string;
15
+ /** API base URL — defaults to production */
16
+ apiUrl?: string;
17
+ /** Custom fetch implementation (for SSR / edge) */
18
+ customFetch?: typeof fetch;
19
+ /** Default locale for content */
20
+ locale?: string;
21
+ }
22
+ interface ListParams {
23
+ page?: number;
24
+ limit?: number;
25
+ search?: string;
26
+ sort?: string;
27
+ order?: "asc" | "desc";
28
+ [key: string]: unknown;
29
+ }
30
+ interface PaginatedResponse<T> {
31
+ data: T[];
32
+ total: number;
33
+ page: number;
34
+ limit: number;
35
+ totalPages: number;
36
+ }
37
+ interface Product {
38
+ id: string;
39
+ name: string;
40
+ slug: string;
41
+ description: string;
42
+ status: string;
43
+ price: number;
44
+ compareAtPrice?: number;
45
+ currency: string;
46
+ images: ProductImage[];
47
+ variants: ProductVariant[];
48
+ category?: {
49
+ id: string;
50
+ name: string;
51
+ };
52
+ brand?: {
53
+ id: string;
54
+ name: string;
55
+ };
56
+ tags: string[];
57
+ metadata: Record<string, unknown>;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ }
61
+ interface ProductImage {
62
+ id: string;
63
+ url: string;
64
+ alt: string;
65
+ position: number;
66
+ }
67
+ interface ProductVariant {
68
+ id: string;
69
+ name: string;
70
+ sku: string;
71
+ price: number;
72
+ compareAtPrice?: number;
73
+ inventory: number;
74
+ options: Record<string, string>;
75
+ }
76
+ interface Collection {
77
+ id: string;
78
+ name: string;
79
+ slug: string;
80
+ description: string;
81
+ image?: string;
82
+ productCount: number;
83
+ }
84
+ interface CheckoutLineItem {
85
+ productId: string;
86
+ variantId?: string;
87
+ quantity: number;
88
+ }
89
+ interface CheckoutSession {
90
+ id: string;
91
+ status: "open" | "completed" | "expired";
92
+ items: CheckoutLineItem[];
93
+ subtotal: number;
94
+ tax: number;
95
+ shipping: number;
96
+ discount: number;
97
+ total: number;
98
+ currency: string;
99
+ couponCode?: string;
100
+ }
101
+ interface Order {
102
+ id: string;
103
+ orderNumber: string;
104
+ status: string;
105
+ total: number;
106
+ currency: string;
107
+ items: OrderItem[];
108
+ createdAt: string;
109
+ }
110
+ interface OrderItem {
111
+ productId: string;
112
+ name: string;
113
+ quantity: number;
114
+ price: number;
115
+ }
116
+ interface Customer {
117
+ id: string;
118
+ email: string;
119
+ name: string;
120
+ phone?: string;
121
+ createdAt: string;
122
+ }
123
+ interface AuthSession {
124
+ customer: Customer;
125
+ accessToken: string;
126
+ refreshToken: string;
127
+ }
128
+ interface Address {
129
+ id: string;
130
+ label?: string;
131
+ line1: string;
132
+ line2?: string;
133
+ city: string;
134
+ state: string;
135
+ postalCode: string;
136
+ country: string;
137
+ isDefault: boolean;
138
+ }
139
+ interface BlogPost {
140
+ id: string;
141
+ title: string;
142
+ slug: string;
143
+ excerpt: string;
144
+ content: string;
145
+ coverImage?: string;
146
+ tags: string[];
147
+ publishedAt: string;
148
+ }
149
+ interface BookableService {
150
+ id: string;
151
+ name: string;
152
+ duration: number;
153
+ price: number;
154
+ description: string;
155
+ }
156
+ interface TimeSlot {
157
+ start: string;
158
+ end: string;
159
+ available: boolean;
160
+ }
161
+ interface Booking {
162
+ id: string;
163
+ serviceId: string;
164
+ date: string;
165
+ startTime: string;
166
+ endTime: string;
167
+ status: string;
168
+ customer: {
169
+ name: string;
170
+ email: string;
171
+ };
172
+ }
173
+ interface FormDefinition {
174
+ id: string;
175
+ title: string;
176
+ description: string;
177
+ fields: FormField[];
178
+ }
179
+ interface FormField {
180
+ id: string;
181
+ type: string;
182
+ label: string;
183
+ required: boolean;
184
+ options?: string[];
185
+ placeholder?: string;
186
+ }
187
+ interface StoreConfig {
188
+ name: string;
189
+ slug: string;
190
+ logo?: string;
191
+ theme: Record<string, unknown>;
192
+ currency: string;
193
+ locale: string;
194
+ }
195
+ declare class StorefrontError extends Error {
196
+ status: number;
197
+ code: string;
198
+ details?: unknown;
199
+ constructor(status: number, code: string, message: string, details?: unknown);
200
+ }
201
+ declare function createStorefrontClient(config: StorefrontConfig): {
202
+ store: {
203
+ /** Resolve store config by workspace (returns theme, branding, currency) */
204
+ resolve(): Promise<StoreConfig>;
205
+ };
206
+ products: {
207
+ /** List published products with pagination and filters */
208
+ list(params?: ListParams): Promise<PaginatedResponse<Product>>;
209
+ /** Get a single product by ID or slug */
210
+ get(idOrSlug: string): Promise<Product>;
211
+ /** Search products (shorthand for list with search param) */
212
+ search(query: string, params?: ListParams): Promise<PaginatedResponse<Product>>;
213
+ };
214
+ collections: {
215
+ /** List published collections */
216
+ list(params?: ListParams): Promise<PaginatedResponse<Collection>>;
217
+ /** Get a collection with its products */
218
+ get(idOrSlug: string): Promise<Collection & {
219
+ products: Product[];
220
+ }>;
221
+ };
222
+ checkout: {
223
+ /** Create a checkout session from cart items */
224
+ create(items: CheckoutLineItem[]): Promise<CheckoutSession>;
225
+ /** Retrieve an existing checkout session */
226
+ get(checkoutId: string): Promise<CheckoutSession>;
227
+ /** Apply a coupon or discount code */
228
+ applyCoupon(checkoutId: string, couponCode: string): Promise<CheckoutSession>;
229
+ /** Complete checkout — process payment and create order */
230
+ complete(checkoutId: string, payment?: Record<string, unknown>): Promise<Order>;
231
+ };
232
+ auth: {
233
+ /** Register a new customer account */
234
+ register(data: {
235
+ email: string;
236
+ password: string;
237
+ name: string;
238
+ phone?: string;
239
+ }): Promise<AuthSession>;
240
+ /** Log in with email + password */
241
+ login(email: string, password: string): Promise<AuthSession>;
242
+ /** Log in with Google ID token */
243
+ loginWithGoogle(idToken: string): Promise<AuthSession>;
244
+ /** Log out and clear local session */
245
+ logout(): Promise<void>;
246
+ /** Refresh the access token */
247
+ refresh(): Promise<boolean>;
248
+ /** Check if client has a valid session */
249
+ isAuthenticated(): boolean;
250
+ /** Manually set tokens (e.g., from SSR or cookie restoration) */
251
+ setTokens(access: string, refresh: string): void;
252
+ };
253
+ customer: {
254
+ /** Get current customer profile */
255
+ me(): Promise<Customer>;
256
+ /** Get customer's order history */
257
+ orders(params?: ListParams): Promise<PaginatedResponse<Order>>;
258
+ /** Get customer's saved addresses */
259
+ addresses(): Promise<Address[]>;
260
+ };
261
+ blog: {
262
+ /** List published blog posts */
263
+ list(params?: ListParams & {
264
+ tags?: string;
265
+ }): Promise<PaginatedResponse<BlogPost>>;
266
+ /** Get a blog post by slug */
267
+ get(slug: string): Promise<BlogPost>;
268
+ };
269
+ bookings: {
270
+ /** List bookable services */
271
+ services(): Promise<BookableService[]>;
272
+ /** List bookable staff */
273
+ staff(): Promise<Array<{
274
+ id: string;
275
+ name: string;
276
+ avatar?: string;
277
+ }>>;
278
+ /** Check available time slots */
279
+ availability(params: {
280
+ serviceId: string;
281
+ date: string;
282
+ staffId?: string;
283
+ }): Promise<TimeSlot[]>;
284
+ /** Create a booking */
285
+ book(data: {
286
+ serviceId: string;
287
+ date: string;
288
+ startTime: string;
289
+ staffId?: string;
290
+ customer: {
291
+ name: string;
292
+ email: string;
293
+ phone?: string;
294
+ };
295
+ }): Promise<Booking>;
296
+ };
297
+ forms: {
298
+ /** Get a published form by ID or slug */
299
+ get(idOrSlug: string): Promise<FormDefinition>;
300
+ /** Submit form response */
301
+ submit(formId: string, data: Record<string, unknown>): Promise<{
302
+ id: string;
303
+ }>;
304
+ /** Upload file for a form file field */
305
+ uploadFile(formId: string, file: File): Promise<{
306
+ url: string;
307
+ }>;
308
+ };
309
+ cart: {
310
+ /** Recover an abandoned cart by recovery token */
311
+ recover(token: string): Promise<CheckoutSession>;
312
+ };
313
+ };
314
+ type StorefrontClient = ReturnType<typeof createStorefrontClient>;
315
+
316
+ export { type Address, type AuthSession, type BlogPost, type BookableService, type Booking, type CheckoutLineItem, type CheckoutSession, type Collection, type Customer, type FormDefinition, type FormField, type ListParams, type Order, type OrderItem, type PaginatedResponse, type Product, type ProductImage, type ProductVariant, type StoreConfig, type StorefrontClient, type StorefrontConfig, StorefrontError, type TimeSlot, createStorefrontClient };
@@ -0,0 +1,316 @@
1
+ /**
2
+ * ManageSales Storefront SDK
3
+ * --------------------------
4
+ * Resource-based client for building online storefronts.
5
+ * Works with any framework: Next.js, Remix, Nuxt, Astro, plain HTML.
6
+ *
7
+ * Usage:
8
+ * import { createStorefrontClient } from "./managesales-storefront";
9
+ * const client = createStorefrontClient({ workspaceId: "<workspace_id>" });
10
+ * const products = await client.products.list();
11
+ */
12
+ interface StorefrontConfig {
13
+ /** Your workspace ID (required) */
14
+ workspaceId: string;
15
+ /** API base URL — defaults to production */
16
+ apiUrl?: string;
17
+ /** Custom fetch implementation (for SSR / edge) */
18
+ customFetch?: typeof fetch;
19
+ /** Default locale for content */
20
+ locale?: string;
21
+ }
22
+ interface ListParams {
23
+ page?: number;
24
+ limit?: number;
25
+ search?: string;
26
+ sort?: string;
27
+ order?: "asc" | "desc";
28
+ [key: string]: unknown;
29
+ }
30
+ interface PaginatedResponse<T> {
31
+ data: T[];
32
+ total: number;
33
+ page: number;
34
+ limit: number;
35
+ totalPages: number;
36
+ }
37
+ interface Product {
38
+ id: string;
39
+ name: string;
40
+ slug: string;
41
+ description: string;
42
+ status: string;
43
+ price: number;
44
+ compareAtPrice?: number;
45
+ currency: string;
46
+ images: ProductImage[];
47
+ variants: ProductVariant[];
48
+ category?: {
49
+ id: string;
50
+ name: string;
51
+ };
52
+ brand?: {
53
+ id: string;
54
+ name: string;
55
+ };
56
+ tags: string[];
57
+ metadata: Record<string, unknown>;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ }
61
+ interface ProductImage {
62
+ id: string;
63
+ url: string;
64
+ alt: string;
65
+ position: number;
66
+ }
67
+ interface ProductVariant {
68
+ id: string;
69
+ name: string;
70
+ sku: string;
71
+ price: number;
72
+ compareAtPrice?: number;
73
+ inventory: number;
74
+ options: Record<string, string>;
75
+ }
76
+ interface Collection {
77
+ id: string;
78
+ name: string;
79
+ slug: string;
80
+ description: string;
81
+ image?: string;
82
+ productCount: number;
83
+ }
84
+ interface CheckoutLineItem {
85
+ productId: string;
86
+ variantId?: string;
87
+ quantity: number;
88
+ }
89
+ interface CheckoutSession {
90
+ id: string;
91
+ status: "open" | "completed" | "expired";
92
+ items: CheckoutLineItem[];
93
+ subtotal: number;
94
+ tax: number;
95
+ shipping: number;
96
+ discount: number;
97
+ total: number;
98
+ currency: string;
99
+ couponCode?: string;
100
+ }
101
+ interface Order {
102
+ id: string;
103
+ orderNumber: string;
104
+ status: string;
105
+ total: number;
106
+ currency: string;
107
+ items: OrderItem[];
108
+ createdAt: string;
109
+ }
110
+ interface OrderItem {
111
+ productId: string;
112
+ name: string;
113
+ quantity: number;
114
+ price: number;
115
+ }
116
+ interface Customer {
117
+ id: string;
118
+ email: string;
119
+ name: string;
120
+ phone?: string;
121
+ createdAt: string;
122
+ }
123
+ interface AuthSession {
124
+ customer: Customer;
125
+ accessToken: string;
126
+ refreshToken: string;
127
+ }
128
+ interface Address {
129
+ id: string;
130
+ label?: string;
131
+ line1: string;
132
+ line2?: string;
133
+ city: string;
134
+ state: string;
135
+ postalCode: string;
136
+ country: string;
137
+ isDefault: boolean;
138
+ }
139
+ interface BlogPost {
140
+ id: string;
141
+ title: string;
142
+ slug: string;
143
+ excerpt: string;
144
+ content: string;
145
+ coverImage?: string;
146
+ tags: string[];
147
+ publishedAt: string;
148
+ }
149
+ interface BookableService {
150
+ id: string;
151
+ name: string;
152
+ duration: number;
153
+ price: number;
154
+ description: string;
155
+ }
156
+ interface TimeSlot {
157
+ start: string;
158
+ end: string;
159
+ available: boolean;
160
+ }
161
+ interface Booking {
162
+ id: string;
163
+ serviceId: string;
164
+ date: string;
165
+ startTime: string;
166
+ endTime: string;
167
+ status: string;
168
+ customer: {
169
+ name: string;
170
+ email: string;
171
+ };
172
+ }
173
+ interface FormDefinition {
174
+ id: string;
175
+ title: string;
176
+ description: string;
177
+ fields: FormField[];
178
+ }
179
+ interface FormField {
180
+ id: string;
181
+ type: string;
182
+ label: string;
183
+ required: boolean;
184
+ options?: string[];
185
+ placeholder?: string;
186
+ }
187
+ interface StoreConfig {
188
+ name: string;
189
+ slug: string;
190
+ logo?: string;
191
+ theme: Record<string, unknown>;
192
+ currency: string;
193
+ locale: string;
194
+ }
195
+ declare class StorefrontError extends Error {
196
+ status: number;
197
+ code: string;
198
+ details?: unknown;
199
+ constructor(status: number, code: string, message: string, details?: unknown);
200
+ }
201
+ declare function createStorefrontClient(config: StorefrontConfig): {
202
+ store: {
203
+ /** Resolve store config by workspace (returns theme, branding, currency) */
204
+ resolve(): Promise<StoreConfig>;
205
+ };
206
+ products: {
207
+ /** List published products with pagination and filters */
208
+ list(params?: ListParams): Promise<PaginatedResponse<Product>>;
209
+ /** Get a single product by ID or slug */
210
+ get(idOrSlug: string): Promise<Product>;
211
+ /** Search products (shorthand for list with search param) */
212
+ search(query: string, params?: ListParams): Promise<PaginatedResponse<Product>>;
213
+ };
214
+ collections: {
215
+ /** List published collections */
216
+ list(params?: ListParams): Promise<PaginatedResponse<Collection>>;
217
+ /** Get a collection with its products */
218
+ get(idOrSlug: string): Promise<Collection & {
219
+ products: Product[];
220
+ }>;
221
+ };
222
+ checkout: {
223
+ /** Create a checkout session from cart items */
224
+ create(items: CheckoutLineItem[]): Promise<CheckoutSession>;
225
+ /** Retrieve an existing checkout session */
226
+ get(checkoutId: string): Promise<CheckoutSession>;
227
+ /** Apply a coupon or discount code */
228
+ applyCoupon(checkoutId: string, couponCode: string): Promise<CheckoutSession>;
229
+ /** Complete checkout — process payment and create order */
230
+ complete(checkoutId: string, payment?: Record<string, unknown>): Promise<Order>;
231
+ };
232
+ auth: {
233
+ /** Register a new customer account */
234
+ register(data: {
235
+ email: string;
236
+ password: string;
237
+ name: string;
238
+ phone?: string;
239
+ }): Promise<AuthSession>;
240
+ /** Log in with email + password */
241
+ login(email: string, password: string): Promise<AuthSession>;
242
+ /** Log in with Google ID token */
243
+ loginWithGoogle(idToken: string): Promise<AuthSession>;
244
+ /** Log out and clear local session */
245
+ logout(): Promise<void>;
246
+ /** Refresh the access token */
247
+ refresh(): Promise<boolean>;
248
+ /** Check if client has a valid session */
249
+ isAuthenticated(): boolean;
250
+ /** Manually set tokens (e.g., from SSR or cookie restoration) */
251
+ setTokens(access: string, refresh: string): void;
252
+ };
253
+ customer: {
254
+ /** Get current customer profile */
255
+ me(): Promise<Customer>;
256
+ /** Get customer's order history */
257
+ orders(params?: ListParams): Promise<PaginatedResponse<Order>>;
258
+ /** Get customer's saved addresses */
259
+ addresses(): Promise<Address[]>;
260
+ };
261
+ blog: {
262
+ /** List published blog posts */
263
+ list(params?: ListParams & {
264
+ tags?: string;
265
+ }): Promise<PaginatedResponse<BlogPost>>;
266
+ /** Get a blog post by slug */
267
+ get(slug: string): Promise<BlogPost>;
268
+ };
269
+ bookings: {
270
+ /** List bookable services */
271
+ services(): Promise<BookableService[]>;
272
+ /** List bookable staff */
273
+ staff(): Promise<Array<{
274
+ id: string;
275
+ name: string;
276
+ avatar?: string;
277
+ }>>;
278
+ /** Check available time slots */
279
+ availability(params: {
280
+ serviceId: string;
281
+ date: string;
282
+ staffId?: string;
283
+ }): Promise<TimeSlot[]>;
284
+ /** Create a booking */
285
+ book(data: {
286
+ serviceId: string;
287
+ date: string;
288
+ startTime: string;
289
+ staffId?: string;
290
+ customer: {
291
+ name: string;
292
+ email: string;
293
+ phone?: string;
294
+ };
295
+ }): Promise<Booking>;
296
+ };
297
+ forms: {
298
+ /** Get a published form by ID or slug */
299
+ get(idOrSlug: string): Promise<FormDefinition>;
300
+ /** Submit form response */
301
+ submit(formId: string, data: Record<string, unknown>): Promise<{
302
+ id: string;
303
+ }>;
304
+ /** Upload file for a form file field */
305
+ uploadFile(formId: string, file: File): Promise<{
306
+ url: string;
307
+ }>;
308
+ };
309
+ cart: {
310
+ /** Recover an abandoned cart by recovery token */
311
+ recover(token: string): Promise<CheckoutSession>;
312
+ };
313
+ };
314
+ type StorefrontClient = ReturnType<typeof createStorefrontClient>;
315
+
316
+ export { type Address, type AuthSession, type BlogPost, type BookableService, type Booking, type CheckoutLineItem, type CheckoutSession, type Collection, type Customer, type FormDefinition, type FormField, type ListParams, type Order, type OrderItem, type PaginatedResponse, type Product, type ProductImage, type ProductVariant, type StoreConfig, type StorefrontClient, type StorefrontConfig, StorefrontError, type TimeSlot, createStorefrontClient };