@htlkg/data 0.0.1
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/dist/client/index.d.ts +70 -0
- package/dist/client/index.js +33 -0
- package/dist/client/index.js.map +1 -0
- package/dist/content-collections/index.d.ts +246 -0
- package/dist/content-collections/index.js +337 -0
- package/dist/content-collections/index.js.map +1 -0
- package/dist/hooks/index.d.ts +200 -0
- package/dist/hooks/index.js +224 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +711 -0
- package/dist/index.js.map +1 -0
- package/dist/mutations/index.d.ts +231 -0
- package/dist/mutations/index.js +134 -0
- package/dist/mutations/index.js.map +1 -0
- package/dist/queries/index.d.ts +386 -0
- package/dist/queries/index.js +352 -0
- package/dist/queries/index.js.map +1 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
15
|
+
// ../../node_modules/.pnpm/aws-amplify@6.15.8/node_modules/aws-amplify/dist/esm/api/index.mjs
|
|
16
|
+
var api_exports = {};
|
|
17
|
+
__reExport(api_exports, api_star);
|
|
18
|
+
import * as api_star from "@aws-amplify/api";
|
|
19
|
+
|
|
20
|
+
// src/client/index.ts
|
|
21
|
+
function generateClient() {
|
|
22
|
+
return (0, api_exports.generateClient)();
|
|
23
|
+
}
|
|
24
|
+
function generateServerClient(options) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"[generateServerClient] Not yet implemented in modular architecture. Please use generateServerClient from @htlkg/shared/lib/graphql for now. This will be properly implemented when the Amplify Astro adapter is migrated."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/queries/brands.ts
|
|
31
|
+
async function getBrand(client, id) {
|
|
32
|
+
try {
|
|
33
|
+
const { data, errors } = await client.models.Brand.get({ id });
|
|
34
|
+
if (errors) {
|
|
35
|
+
console.error("[getBrand] GraphQL errors:", errors);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("[getBrand] Error fetching brand:", error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function listBrands(client, options) {
|
|
45
|
+
try {
|
|
46
|
+
const { data, errors, nextToken } = await client.models.Brand.list(
|
|
47
|
+
options
|
|
48
|
+
);
|
|
49
|
+
if (errors) {
|
|
50
|
+
console.error("[listBrands] GraphQL errors:", errors);
|
|
51
|
+
return { items: [], nextToken: void 0 };
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
items: data || [],
|
|
55
|
+
nextToken
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error("[listBrands] Error fetching brands:", error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function getBrandWithProducts(client, id) {
|
|
63
|
+
try {
|
|
64
|
+
const { data, errors } = await client.models.Brand.get(
|
|
65
|
+
{ id },
|
|
66
|
+
{
|
|
67
|
+
selectionSet: [
|
|
68
|
+
"id",
|
|
69
|
+
"name",
|
|
70
|
+
"accountId",
|
|
71
|
+
"logo",
|
|
72
|
+
"timezone",
|
|
73
|
+
"status",
|
|
74
|
+
"settings",
|
|
75
|
+
"productInstances.*"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
if (errors) {
|
|
80
|
+
console.error("[getBrandWithProducts] GraphQL errors:", errors);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return data;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error("[getBrandWithProducts] Error fetching brand:", error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function listBrandsByAccount(client, accountId, options) {
|
|
90
|
+
return listBrands(client, {
|
|
91
|
+
filter: { accountId: { eq: accountId } },
|
|
92
|
+
...options
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function listActiveBrands(client, options) {
|
|
96
|
+
return listBrands(client, {
|
|
97
|
+
filter: { status: { eq: "active" } },
|
|
98
|
+
...options
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/queries/accounts.ts
|
|
103
|
+
async function getAccount(client, id) {
|
|
104
|
+
try {
|
|
105
|
+
const { data, errors } = await client.models.Account.get({ id });
|
|
106
|
+
if (errors) {
|
|
107
|
+
console.error("[getAccount] GraphQL errors:", errors);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return data;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("[getAccount] Error fetching account:", error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function listAccounts(client, options) {
|
|
117
|
+
try {
|
|
118
|
+
const { data, errors, nextToken } = await client.models.Account.list(options);
|
|
119
|
+
if (errors) {
|
|
120
|
+
console.error("[listAccounts] GraphQL errors:", errors);
|
|
121
|
+
return { items: [], nextToken: void 0 };
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
items: data || [],
|
|
125
|
+
nextToken
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("[listAccounts] Error fetching accounts:", error);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function getAccountWithBrands(client, id) {
|
|
133
|
+
try {
|
|
134
|
+
const { data, errors } = await client.models.Account.get(
|
|
135
|
+
{ id },
|
|
136
|
+
{
|
|
137
|
+
selectionSet: [
|
|
138
|
+
"id",
|
|
139
|
+
"name",
|
|
140
|
+
"logo",
|
|
141
|
+
"subscription",
|
|
142
|
+
"settings",
|
|
143
|
+
"brands.*"
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
if (errors) {
|
|
148
|
+
console.error("[getAccountWithBrands] GraphQL errors:", errors);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return data;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error("[getAccountWithBrands] Error fetching account:", error);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/queries/users.ts
|
|
159
|
+
async function getUser(client, id) {
|
|
160
|
+
try {
|
|
161
|
+
const { data, errors } = await client.models.User.get({ id });
|
|
162
|
+
if (errors) {
|
|
163
|
+
console.error("[getUser] GraphQL errors:", errors);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return data;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("[getUser] Error fetching user:", error);
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async function getUserByCognitoId(client, cognitoId) {
|
|
173
|
+
try {
|
|
174
|
+
const { data, errors } = await client.models.User.list({
|
|
175
|
+
filter: { cognitoId: { eq: cognitoId } },
|
|
176
|
+
limit: 1
|
|
177
|
+
});
|
|
178
|
+
if (errors) {
|
|
179
|
+
console.error("[getUserByCognitoId] GraphQL errors:", errors);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return data?.[0];
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error("[getUserByCognitoId] Error fetching user:", error);
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function getUserByEmail(client, email) {
|
|
189
|
+
try {
|
|
190
|
+
const { data, errors } = await client.models.User.list({
|
|
191
|
+
filter: { email: { eq: email } },
|
|
192
|
+
limit: 1
|
|
193
|
+
});
|
|
194
|
+
if (errors) {
|
|
195
|
+
console.error("[getUserByEmail] GraphQL errors:", errors);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return data?.[0];
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error("[getUserByEmail] Error fetching user:", error);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function listUsers(client, options) {
|
|
205
|
+
try {
|
|
206
|
+
const { data, errors, nextToken } = await client.models.User.list(
|
|
207
|
+
options
|
|
208
|
+
);
|
|
209
|
+
if (errors) {
|
|
210
|
+
console.error("[listUsers] GraphQL errors:", errors);
|
|
211
|
+
return { items: [], nextToken: void 0 };
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
items: data || [],
|
|
215
|
+
nextToken
|
|
216
|
+
};
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error("[listUsers] Error fetching users:", error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async function listUsersByAccount(client, accountId, options) {
|
|
223
|
+
return listUsers(client, {
|
|
224
|
+
filter: { accountId: { eq: accountId } },
|
|
225
|
+
...options
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async function listActiveUsers(client, options) {
|
|
229
|
+
return listUsers(client, {
|
|
230
|
+
filter: { status: { eq: "active" } },
|
|
231
|
+
...options
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/queries/products.ts
|
|
236
|
+
async function getProduct(client, id) {
|
|
237
|
+
try {
|
|
238
|
+
const { data, errors } = await client.models.Product.get({ id });
|
|
239
|
+
if (errors) {
|
|
240
|
+
console.error("[getProduct] GraphQL errors:", errors);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return data;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error("[getProduct] Error fetching product:", error);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async function listProducts(client, options) {
|
|
250
|
+
try {
|
|
251
|
+
const { data, errors, nextToken } = await client.models.Product.list(options);
|
|
252
|
+
if (errors) {
|
|
253
|
+
console.error("[listProducts] GraphQL errors:", errors);
|
|
254
|
+
return { items: [], nextToken: void 0 };
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
items: data || [],
|
|
258
|
+
nextToken
|
|
259
|
+
};
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error("[listProducts] Error fetching products:", error);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function listActiveProducts(client, options) {
|
|
266
|
+
return listProducts(client, {
|
|
267
|
+
filter: { isActive: { eq: true } },
|
|
268
|
+
...options
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async function getProductInstance(client, id) {
|
|
272
|
+
try {
|
|
273
|
+
const { data, errors } = await client.models.ProductInstance.get({
|
|
274
|
+
id
|
|
275
|
+
});
|
|
276
|
+
if (errors) {
|
|
277
|
+
console.error("[getProductInstance] GraphQL errors:", errors);
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return data;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error("[getProductInstance] Error fetching product instance:", error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function listProductInstancesByBrand(client, brandId, options) {
|
|
287
|
+
try {
|
|
288
|
+
const { data, errors, nextToken } = await client.models.ProductInstance.list({
|
|
289
|
+
filter: { brandId: { eq: brandId } },
|
|
290
|
+
...options
|
|
291
|
+
});
|
|
292
|
+
if (errors) {
|
|
293
|
+
console.error("[listProductInstancesByBrand] GraphQL errors:", errors);
|
|
294
|
+
return { items: [], nextToken: void 0 };
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
items: data || [],
|
|
298
|
+
nextToken
|
|
299
|
+
};
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.error(
|
|
302
|
+
"[listProductInstancesByBrand] Error fetching product instances:",
|
|
303
|
+
error
|
|
304
|
+
);
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function listProductInstancesByAccount(client, accountId, options) {
|
|
309
|
+
try {
|
|
310
|
+
const { data, errors, nextToken } = await client.models.ProductInstance.list({
|
|
311
|
+
filter: { accountId: { eq: accountId } },
|
|
312
|
+
...options
|
|
313
|
+
});
|
|
314
|
+
if (errors) {
|
|
315
|
+
console.error("[listProductInstancesByAccount] GraphQL errors:", errors);
|
|
316
|
+
return { items: [], nextToken: void 0 };
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
items: data || [],
|
|
320
|
+
nextToken
|
|
321
|
+
};
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error(
|
|
324
|
+
"[listProductInstancesByAccount] Error fetching product instances:",
|
|
325
|
+
error
|
|
326
|
+
);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function listEnabledProductInstancesByBrand(client, brandId, options) {
|
|
331
|
+
try {
|
|
332
|
+
const { data, errors, nextToken } = await client.models.ProductInstance.list({
|
|
333
|
+
filter: {
|
|
334
|
+
brandId: { eq: brandId },
|
|
335
|
+
enabled: { eq: true }
|
|
336
|
+
},
|
|
337
|
+
...options
|
|
338
|
+
});
|
|
339
|
+
if (errors) {
|
|
340
|
+
console.error(
|
|
341
|
+
"[listEnabledProductInstancesByBrand] GraphQL errors:",
|
|
342
|
+
errors
|
|
343
|
+
);
|
|
344
|
+
return { items: [], nextToken: void 0 };
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
items: data || [],
|
|
348
|
+
nextToken
|
|
349
|
+
};
|
|
350
|
+
} catch (error) {
|
|
351
|
+
console.error(
|
|
352
|
+
"[listEnabledProductInstancesByBrand] Error fetching product instances:",
|
|
353
|
+
error
|
|
354
|
+
);
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/mutations/brands.ts
|
|
360
|
+
async function createBrand(client, input) {
|
|
361
|
+
try {
|
|
362
|
+
const { data, errors } = await client.models.Brand.create(input);
|
|
363
|
+
if (errors) {
|
|
364
|
+
console.error("[createBrand] GraphQL errors:", errors);
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
return data;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
console.error("[createBrand] Error creating brand:", error);
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
async function updateBrand(client, input) {
|
|
374
|
+
try {
|
|
375
|
+
const { data, errors } = await client.models.Brand.update(input);
|
|
376
|
+
if (errors) {
|
|
377
|
+
console.error("[updateBrand] GraphQL errors:", errors);
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
return data;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.error("[updateBrand] Error updating brand:", error);
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async function deleteBrand(client, id) {
|
|
387
|
+
try {
|
|
388
|
+
const { errors } = await client.models.Brand.delete({ id });
|
|
389
|
+
if (errors) {
|
|
390
|
+
console.error("[deleteBrand] GraphQL errors:", errors);
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return true;
|
|
394
|
+
} catch (error) {
|
|
395
|
+
console.error("[deleteBrand] Error deleting brand:", error);
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/mutations/accounts.ts
|
|
401
|
+
async function createAccount(client, input) {
|
|
402
|
+
try {
|
|
403
|
+
const { data, errors } = await client.models.Account.create(input);
|
|
404
|
+
if (errors) {
|
|
405
|
+
console.error("[createAccount] GraphQL errors:", errors);
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
return data;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.error("[createAccount] Error creating account:", error);
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function updateAccount(client, input) {
|
|
415
|
+
try {
|
|
416
|
+
const { data, errors } = await client.models.Account.update(input);
|
|
417
|
+
if (errors) {
|
|
418
|
+
console.error("[updateAccount] GraphQL errors:", errors);
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
return data;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
console.error("[updateAccount] Error updating account:", error);
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async function deleteAccount(client, id) {
|
|
428
|
+
try {
|
|
429
|
+
const { errors } = await client.models.Account.delete({ id });
|
|
430
|
+
if (errors) {
|
|
431
|
+
console.error("[deleteAccount] GraphQL errors:", errors);
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
return true;
|
|
435
|
+
} catch (error) {
|
|
436
|
+
console.error("[deleteAccount] Error deleting account:", error);
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/mutations/users.ts
|
|
442
|
+
async function createUser(client, input) {
|
|
443
|
+
try {
|
|
444
|
+
const { data, errors } = await client.models.User.create(input);
|
|
445
|
+
if (errors) {
|
|
446
|
+
console.error("[createUser] GraphQL errors:", errors);
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
return data;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.error("[createUser] Error creating user:", error);
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function updateUser(client, input) {
|
|
456
|
+
try {
|
|
457
|
+
const { data, errors } = await client.models.User.update(input);
|
|
458
|
+
if (errors) {
|
|
459
|
+
console.error("[updateUser] GraphQL errors:", errors);
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
return data;
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.error("[updateUser] Error updating user:", error);
|
|
465
|
+
throw error;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
async function deleteUser(client, id) {
|
|
469
|
+
try {
|
|
470
|
+
const { errors } = await client.models.User.delete({ id });
|
|
471
|
+
if (errors) {
|
|
472
|
+
console.error("[deleteUser] GraphQL errors:", errors);
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
return true;
|
|
476
|
+
} catch (error) {
|
|
477
|
+
console.error("[deleteUser] Error deleting user:", error);
|
|
478
|
+
throw error;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/hooks/useBrands.ts
|
|
483
|
+
import { ref, computed, onMounted } from "vue";
|
|
484
|
+
function useBrands(options = {}) {
|
|
485
|
+
const {
|
|
486
|
+
filter: baseFilter,
|
|
487
|
+
limit,
|
|
488
|
+
autoFetch = true,
|
|
489
|
+
accountId,
|
|
490
|
+
activeOnly
|
|
491
|
+
} = options;
|
|
492
|
+
const brands = ref([]);
|
|
493
|
+
const loading = ref(false);
|
|
494
|
+
const error = ref(null);
|
|
495
|
+
let filter = baseFilter || {};
|
|
496
|
+
if (accountId) {
|
|
497
|
+
filter = { ...filter, accountId: { eq: accountId } };
|
|
498
|
+
}
|
|
499
|
+
if (activeOnly) {
|
|
500
|
+
filter = { ...filter, status: { eq: "active" } };
|
|
501
|
+
}
|
|
502
|
+
const activeBrands = computed(
|
|
503
|
+
() => brands.value.filter((b) => b.status === "active")
|
|
504
|
+
);
|
|
505
|
+
async function fetch() {
|
|
506
|
+
loading.value = true;
|
|
507
|
+
error.value = null;
|
|
508
|
+
try {
|
|
509
|
+
const client = generateClient();
|
|
510
|
+
const { data, errors } = await client.models.Brand.list({
|
|
511
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
512
|
+
limit
|
|
513
|
+
});
|
|
514
|
+
if (errors) {
|
|
515
|
+
throw new Error(errors[0]?.message || "Failed to fetch brands");
|
|
516
|
+
}
|
|
517
|
+
brands.value = data || [];
|
|
518
|
+
} catch (e) {
|
|
519
|
+
error.value = e;
|
|
520
|
+
console.error("[useBrands] Error fetching brands:", e);
|
|
521
|
+
} finally {
|
|
522
|
+
loading.value = false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (autoFetch) {
|
|
526
|
+
onMounted(() => {
|
|
527
|
+
fetch();
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
brands,
|
|
532
|
+
activeBrands,
|
|
533
|
+
loading,
|
|
534
|
+
error,
|
|
535
|
+
refetch: fetch
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/hooks/useAccounts.ts
|
|
540
|
+
import { ref as ref2, onMounted as onMounted2 } from "vue";
|
|
541
|
+
function useAccounts(options = {}) {
|
|
542
|
+
const { filter, limit, autoFetch = true } = options;
|
|
543
|
+
const accounts = ref2([]);
|
|
544
|
+
const loading = ref2(false);
|
|
545
|
+
const error = ref2(null);
|
|
546
|
+
async function fetch() {
|
|
547
|
+
loading.value = true;
|
|
548
|
+
error.value = null;
|
|
549
|
+
try {
|
|
550
|
+
const client = generateClient();
|
|
551
|
+
const { data, errors } = await client.models.Account.list({
|
|
552
|
+
filter,
|
|
553
|
+
limit
|
|
554
|
+
});
|
|
555
|
+
if (errors) {
|
|
556
|
+
throw new Error(errors[0]?.message || "Failed to fetch accounts");
|
|
557
|
+
}
|
|
558
|
+
accounts.value = data || [];
|
|
559
|
+
} catch (e) {
|
|
560
|
+
error.value = e;
|
|
561
|
+
console.error("[useAccounts] Error fetching accounts:", e);
|
|
562
|
+
} finally {
|
|
563
|
+
loading.value = false;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (autoFetch) {
|
|
567
|
+
onMounted2(() => {
|
|
568
|
+
fetch();
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
accounts,
|
|
573
|
+
loading,
|
|
574
|
+
error,
|
|
575
|
+
refetch: fetch
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// src/hooks/useUsers.ts
|
|
580
|
+
import { ref as ref3, onMounted as onMounted3 } from "vue";
|
|
581
|
+
function useUsers(options = {}) {
|
|
582
|
+
const { filter: baseFilter, limit, autoFetch = true, brandId, accountId } = options;
|
|
583
|
+
const users = ref3([]);
|
|
584
|
+
const loading = ref3(false);
|
|
585
|
+
const error = ref3(null);
|
|
586
|
+
let filter = baseFilter || {};
|
|
587
|
+
if (brandId) {
|
|
588
|
+
filter = { ...filter, brandIds: { contains: brandId } };
|
|
589
|
+
}
|
|
590
|
+
if (accountId) {
|
|
591
|
+
filter = { ...filter, accountIds: { contains: accountId } };
|
|
592
|
+
}
|
|
593
|
+
async function fetch() {
|
|
594
|
+
loading.value = true;
|
|
595
|
+
error.value = null;
|
|
596
|
+
try {
|
|
597
|
+
const client = generateClient();
|
|
598
|
+
const { data, errors } = await client.models.User.list({
|
|
599
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
600
|
+
limit
|
|
601
|
+
});
|
|
602
|
+
if (errors) {
|
|
603
|
+
throw new Error(errors[0]?.message || "Failed to fetch users");
|
|
604
|
+
}
|
|
605
|
+
users.value = data || [];
|
|
606
|
+
} catch (e) {
|
|
607
|
+
error.value = e;
|
|
608
|
+
console.error("[useUsers] Error fetching users:", e);
|
|
609
|
+
} finally {
|
|
610
|
+
loading.value = false;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (autoFetch) {
|
|
614
|
+
onMounted3(() => {
|
|
615
|
+
fetch();
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
users,
|
|
620
|
+
loading,
|
|
621
|
+
error,
|
|
622
|
+
refetch: fetch
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/hooks/useProducts.ts
|
|
627
|
+
import { ref as ref4, computed as computed2, onMounted as onMounted4 } from "vue";
|
|
628
|
+
function useProducts(options = {}) {
|
|
629
|
+
const { filter: baseFilter, limit, autoFetch = true, activeOnly } = options;
|
|
630
|
+
const products = ref4([]);
|
|
631
|
+
const loading = ref4(false);
|
|
632
|
+
const error = ref4(null);
|
|
633
|
+
let filter = baseFilter || {};
|
|
634
|
+
if (activeOnly) {
|
|
635
|
+
filter = { ...filter, isActive: { eq: true } };
|
|
636
|
+
}
|
|
637
|
+
const activeProducts = computed2(
|
|
638
|
+
() => products.value.filter((p) => p.isActive === true)
|
|
639
|
+
);
|
|
640
|
+
async function fetch() {
|
|
641
|
+
loading.value = true;
|
|
642
|
+
error.value = null;
|
|
643
|
+
try {
|
|
644
|
+
const client = generateClient();
|
|
645
|
+
const { data, errors } = await client.models.Product.list({
|
|
646
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
647
|
+
limit
|
|
648
|
+
});
|
|
649
|
+
if (errors) {
|
|
650
|
+
throw new Error(errors[0]?.message || "Failed to fetch products");
|
|
651
|
+
}
|
|
652
|
+
products.value = data || [];
|
|
653
|
+
} catch (e) {
|
|
654
|
+
error.value = e;
|
|
655
|
+
console.error("[useProducts] Error fetching products:", e);
|
|
656
|
+
} finally {
|
|
657
|
+
loading.value = false;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (autoFetch) {
|
|
661
|
+
onMounted4(() => {
|
|
662
|
+
fetch();
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
products,
|
|
667
|
+
activeProducts,
|
|
668
|
+
loading,
|
|
669
|
+
error,
|
|
670
|
+
refetch: fetch
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
export {
|
|
674
|
+
createAccount,
|
|
675
|
+
createBrand,
|
|
676
|
+
createUser,
|
|
677
|
+
deleteAccount,
|
|
678
|
+
deleteBrand,
|
|
679
|
+
deleteUser,
|
|
680
|
+
generateClient,
|
|
681
|
+
generateServerClient,
|
|
682
|
+
getAccount,
|
|
683
|
+
getAccountWithBrands,
|
|
684
|
+
getBrand,
|
|
685
|
+
getBrandWithProducts,
|
|
686
|
+
getProduct,
|
|
687
|
+
getProductInstance,
|
|
688
|
+
getUser,
|
|
689
|
+
getUserByCognitoId,
|
|
690
|
+
getUserByEmail,
|
|
691
|
+
listAccounts,
|
|
692
|
+
listActiveBrands,
|
|
693
|
+
listActiveProducts,
|
|
694
|
+
listActiveUsers,
|
|
695
|
+
listBrands,
|
|
696
|
+
listBrandsByAccount,
|
|
697
|
+
listEnabledProductInstancesByBrand,
|
|
698
|
+
listProductInstancesByAccount,
|
|
699
|
+
listProductInstancesByBrand,
|
|
700
|
+
listProducts,
|
|
701
|
+
listUsers,
|
|
702
|
+
listUsersByAccount,
|
|
703
|
+
updateAccount,
|
|
704
|
+
updateBrand,
|
|
705
|
+
updateUser,
|
|
706
|
+
useAccounts,
|
|
707
|
+
useBrands,
|
|
708
|
+
useProducts,
|
|
709
|
+
useUsers
|
|
710
|
+
};
|
|
711
|
+
//# sourceMappingURL=index.js.map
|