@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AstroCookies } from 'astro';
|
|
2
|
+
import { generateClient as generateClient$1 } from 'aws-amplify/data';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL Client for @htlkg/data
|
|
6
|
+
*
|
|
7
|
+
* Provides both client-side and server-side GraphQL capabilities using AWS Amplify Data.
|
|
8
|
+
* The server-side functions use the Amplify Astro adapter for proper SSR support.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generate a client-side GraphQL client for use in Vue components and browser contexts
|
|
13
|
+
* This is SSR-safe and should be called within a component's setup function or after hydration
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import type { Schema } from '@backend/data/resource';
|
|
18
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
19
|
+
*
|
|
20
|
+
* const client = generateClient<Schema>();
|
|
21
|
+
* const { data: brands } = await client.models.Brand.list();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function generateClient<TSchema extends Record<string, unknown> = Record<string, unknown>>(): ReturnType<typeof generateClient$1<TSchema>>;
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for Amplify Astro adapter
|
|
27
|
+
*/
|
|
28
|
+
interface AstroAmplifyConfig {
|
|
29
|
+
API?: {
|
|
30
|
+
GraphQL?: {
|
|
31
|
+
endpoint: string;
|
|
32
|
+
region: string;
|
|
33
|
+
defaultAuthMode: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
Auth?: {
|
|
37
|
+
Cognito?: {
|
|
38
|
+
userPoolId: string;
|
|
39
|
+
userPoolClientId: string;
|
|
40
|
+
identityPoolId?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate a server-side GraphQL client with cookie-based authentication
|
|
46
|
+
* Use this in Astro pages and API routes for server-side GraphQL operations
|
|
47
|
+
*
|
|
48
|
+
* Note: This is a placeholder that will be properly implemented once the
|
|
49
|
+
* Amplify Astro adapter is migrated to the modular architecture.
|
|
50
|
+
* For now, import generateServerClient from @htlkg/shared/lib/graphql directly.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import type { Schema } from '../amplify/data/resource';
|
|
55
|
+
* import { generateServerClient } from '@htlkg/data/client';
|
|
56
|
+
* import outputs from '../amplify_outputs.json';
|
|
57
|
+
*
|
|
58
|
+
* const client = generateServerClient<Schema>({
|
|
59
|
+
* cookies: Astro.cookies,
|
|
60
|
+
* config: outputs
|
|
61
|
+
* });
|
|
62
|
+
* const { data: brands } = await client.models.Brand.list();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function generateServerClient<TSchema extends Record<string, unknown> = Record<string, unknown>>(options: {
|
|
66
|
+
cookies: AstroCookies;
|
|
67
|
+
config: AstroAmplifyConfig;
|
|
68
|
+
}): any;
|
|
69
|
+
|
|
70
|
+
export { type AstroAmplifyConfig, generateClient, generateServerClient };
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
export {
|
|
30
|
+
generateClient,
|
|
31
|
+
generateServerClient
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../node_modules/.pnpm/aws-amplify@6.15.8/node_modules/aws-amplify/dist/esm/api/index.mjs","../../src/client/index.ts"],"sourcesContent":["export * from '@aws-amplify/api';\n//# sourceMappingURL=index.mjs.map\n","/**\n * GraphQL Client for @htlkg/data\n *\n * Provides both client-side and server-side GraphQL capabilities using AWS Amplify Data.\n * The server-side functions use the Amplify Astro adapter for proper SSR support.\n */\n\nimport type { AstroCookies } from \"astro\";\nimport { generateClient as generateDataClient } from \"aws-amplify/data\";\n\n/**\n * Generate a client-side GraphQL client for use in Vue components and browser contexts\n * This is SSR-safe and should be called within a component's setup function or after hydration\n *\n * @example\n * ```typescript\n * import type { Schema } from '@backend/data/resource';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const { data: brands } = await client.models.Brand.list();\n * ```\n */\nexport function generateClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(): ReturnType<typeof generateDataClient<TSchema>> {\n\treturn generateDataClient<TSchema>();\n}\n\n/**\n * Configuration for Amplify Astro adapter\n */\nexport interface AstroAmplifyConfig {\n\tAPI?: {\n\t\tGraphQL?: {\n\t\t\tendpoint: string;\n\t\t\tregion: string;\n\t\t\tdefaultAuthMode: string;\n\t\t};\n\t};\n\tAuth?: {\n\t\tCognito?: {\n\t\t\tuserPoolId: string;\n\t\t\tuserPoolClientId: string;\n\t\t\tidentityPoolId?: string;\n\t\t};\n\t};\n}\n\n/**\n * Generate a server-side GraphQL client with cookie-based authentication\n * Use this in Astro pages and API routes for server-side GraphQL operations\n *\n * Note: This is a placeholder that will be properly implemented once the\n * Amplify Astro adapter is migrated to the modular architecture.\n * For now, import generateServerClient from @htlkg/shared/lib/graphql directly.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { generateServerClient } from '@htlkg/data/client';\n * import outputs from '../amplify_outputs.json';\n *\n * const client = generateServerClient<Schema>({\n * cookies: Astro.cookies,\n * config: outputs\n * });\n * const { data: brands } = await client.models.Brand.list();\n * ```\n */\nexport function generateServerClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(options: { cookies: AstroCookies; config: AstroAmplifyConfig }): any {\n\tthrow new Error(\n\t\t\"[generateServerClient] Not yet implemented in modular architecture. \" +\n\t\t\"Please use generateServerClient from @htlkg/shared/lib/graphql for now. \" +\n\t\t\"This will be properly implemented when the Amplify Astro adapter is migrated.\",\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc;;;ACuBP,SAAS,iBAEoC;AACnD,aAAO,YAAAA,gBAA4B;AACpC;AA2CO,SAAS,qBAEd,SAAqE;AACtE,QAAM,IAAI;AAAA,IACT;AAAA,EAGD;AACD;","names":["generateDataClient"]}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AppSync Sync for Content Collections
|
|
5
|
+
*
|
|
6
|
+
* Fetches data from Admin's AppSync API for use in Content Collections.
|
|
7
|
+
*/
|
|
8
|
+
interface SyncOptions {
|
|
9
|
+
/** AppSync API configuration */
|
|
10
|
+
apiConfig: {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
region: string;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
};
|
|
15
|
+
/** Authorization mode (default: 'apiKey') */
|
|
16
|
+
authMode?: "apiKey" | "userPool" | "iam";
|
|
17
|
+
/** Limit for list queries */
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
interface SyncResult<T> {
|
|
21
|
+
data: T[];
|
|
22
|
+
errors: Array<{
|
|
23
|
+
message: string;
|
|
24
|
+
}> | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fetch brands from AppSync
|
|
28
|
+
*/
|
|
29
|
+
declare function fetchBrands(options: SyncOptions): Promise<SyncResult<any>>;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch accounts from AppSync
|
|
32
|
+
*/
|
|
33
|
+
declare function fetchAccounts(options: SyncOptions): Promise<SyncResult<any>>;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch product instances from AppSync
|
|
36
|
+
*/
|
|
37
|
+
declare function fetchProductInstances(options: SyncOptions): Promise<SyncResult<any>>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetch products from AppSync
|
|
40
|
+
*/
|
|
41
|
+
declare function fetchProducts(options: SyncOptions): Promise<SyncResult<any>>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Content Collections Generator
|
|
45
|
+
*
|
|
46
|
+
* Generates Astro Content Collections from AppSync data.
|
|
47
|
+
* Fetches brands, accounts, and product instances and writes them as JSON files.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
interface GeneratorOptions extends SyncOptions {
|
|
51
|
+
/** Output directory for content collections (default: 'src/content') */
|
|
52
|
+
outputDir?: string;
|
|
53
|
+
/** Whether to validate data against schemas (default: true) */
|
|
54
|
+
validate?: boolean;
|
|
55
|
+
/** Whether to continue on errors (default: true) */
|
|
56
|
+
continueOnError?: boolean;
|
|
57
|
+
}
|
|
58
|
+
interface GeneratorResult {
|
|
59
|
+
brands: {
|
|
60
|
+
count: number;
|
|
61
|
+
errors: string[];
|
|
62
|
+
};
|
|
63
|
+
accounts: {
|
|
64
|
+
count: number;
|
|
65
|
+
errors: string[];
|
|
66
|
+
};
|
|
67
|
+
productInstances: {
|
|
68
|
+
count: number;
|
|
69
|
+
errors: string[];
|
|
70
|
+
};
|
|
71
|
+
products: {
|
|
72
|
+
count: number;
|
|
73
|
+
errors: string[];
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Generate Content Collections from AppSync
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { generateContentCollections } from '@htlkg/data/content-collections';
|
|
82
|
+
*
|
|
83
|
+
* const result = await generateContentCollections({
|
|
84
|
+
* apiConfig: {
|
|
85
|
+
* endpoint: process.env.APPSYNC_ENDPOINT,
|
|
86
|
+
* region: 'us-east-1',
|
|
87
|
+
* apiKey: process.env.APPSYNC_API_KEY
|
|
88
|
+
* },
|
|
89
|
+
* outputDir: 'src/content'
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* console.log(`Generated ${result.brands.count} brands`);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function generateContentCollections(options: GeneratorOptions): Promise<GeneratorResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Sync data from AppSync (alias for generateContentCollections)
|
|
98
|
+
*/
|
|
99
|
+
declare const syncFromAppSync: typeof generateContentCollections;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Zod Schemas for Content Collections
|
|
103
|
+
*
|
|
104
|
+
* Defines validation schemas for brands, accounts, and product instances
|
|
105
|
+
* that will be synced from AppSync to Astro Content Collections.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Brand schema for content collections
|
|
110
|
+
*/
|
|
111
|
+
declare const brandSchema: z.ZodObject<{
|
|
112
|
+
id: z.ZodString;
|
|
113
|
+
name: z.ZodString;
|
|
114
|
+
accountId: z.ZodString;
|
|
115
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
116
|
+
timezone: z.ZodString;
|
|
117
|
+
status: z.ZodEnum<["active", "inactive", "maintenance", "suspended"]>;
|
|
118
|
+
settings: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
119
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
120
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
121
|
+
}, "strip", z.ZodTypeAny, {
|
|
122
|
+
id: string;
|
|
123
|
+
name: string;
|
|
124
|
+
accountId: string;
|
|
125
|
+
timezone: string;
|
|
126
|
+
status: "active" | "inactive" | "maintenance" | "suspended";
|
|
127
|
+
settings: Record<string, any>;
|
|
128
|
+
logo?: string | undefined;
|
|
129
|
+
createdAt?: string | undefined;
|
|
130
|
+
updatedAt?: string | undefined;
|
|
131
|
+
}, {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
accountId: string;
|
|
135
|
+
timezone: string;
|
|
136
|
+
status: "active" | "inactive" | "maintenance" | "suspended";
|
|
137
|
+
logo?: string | undefined;
|
|
138
|
+
settings?: Record<string, any> | undefined;
|
|
139
|
+
createdAt?: string | undefined;
|
|
140
|
+
updatedAt?: string | undefined;
|
|
141
|
+
}>;
|
|
142
|
+
type BrandData = z.infer<typeof brandSchema>;
|
|
143
|
+
/**
|
|
144
|
+
* Account schema for content collections
|
|
145
|
+
*/
|
|
146
|
+
declare const accountSchema: z.ZodObject<{
|
|
147
|
+
id: z.ZodString;
|
|
148
|
+
name: z.ZodString;
|
|
149
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
150
|
+
subscription: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
151
|
+
settings: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
152
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
153
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
id: string;
|
|
156
|
+
name: string;
|
|
157
|
+
settings: Record<string, any>;
|
|
158
|
+
subscription: Record<string, any>;
|
|
159
|
+
logo?: string | undefined;
|
|
160
|
+
createdAt?: string | undefined;
|
|
161
|
+
updatedAt?: string | undefined;
|
|
162
|
+
}, {
|
|
163
|
+
id: string;
|
|
164
|
+
name: string;
|
|
165
|
+
logo?: string | undefined;
|
|
166
|
+
settings?: Record<string, any> | undefined;
|
|
167
|
+
createdAt?: string | undefined;
|
|
168
|
+
updatedAt?: string | undefined;
|
|
169
|
+
subscription?: Record<string, any> | undefined;
|
|
170
|
+
}>;
|
|
171
|
+
type AccountData = z.infer<typeof accountSchema>;
|
|
172
|
+
/**
|
|
173
|
+
* Product Instance schema for content collections
|
|
174
|
+
*/
|
|
175
|
+
declare const productInstanceSchema: z.ZodObject<{
|
|
176
|
+
id: z.ZodString;
|
|
177
|
+
productId: z.ZodString;
|
|
178
|
+
productName: z.ZodString;
|
|
179
|
+
brandId: z.ZodString;
|
|
180
|
+
accountId: z.ZodString;
|
|
181
|
+
enabled: z.ZodBoolean;
|
|
182
|
+
config: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
183
|
+
version: z.ZodString;
|
|
184
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
185
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
186
|
+
}, "strip", z.ZodTypeAny, {
|
|
187
|
+
id: string;
|
|
188
|
+
accountId: string;
|
|
189
|
+
productId: string;
|
|
190
|
+
productName: string;
|
|
191
|
+
brandId: string;
|
|
192
|
+
enabled: boolean;
|
|
193
|
+
config: Record<string, any>;
|
|
194
|
+
version: string;
|
|
195
|
+
createdAt?: string | undefined;
|
|
196
|
+
updatedAt?: string | undefined;
|
|
197
|
+
}, {
|
|
198
|
+
id: string;
|
|
199
|
+
accountId: string;
|
|
200
|
+
productId: string;
|
|
201
|
+
productName: string;
|
|
202
|
+
brandId: string;
|
|
203
|
+
enabled: boolean;
|
|
204
|
+
version: string;
|
|
205
|
+
createdAt?: string | undefined;
|
|
206
|
+
updatedAt?: string | undefined;
|
|
207
|
+
config?: Record<string, any> | undefined;
|
|
208
|
+
}>;
|
|
209
|
+
type ProductInstanceData = z.infer<typeof productInstanceSchema>;
|
|
210
|
+
/**
|
|
211
|
+
* Product schema for content collections
|
|
212
|
+
*/
|
|
213
|
+
declare const productSchema: z.ZodObject<{
|
|
214
|
+
id: z.ZodString;
|
|
215
|
+
name: z.ZodString;
|
|
216
|
+
version: z.ZodString;
|
|
217
|
+
schema: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
218
|
+
uiSchema: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
219
|
+
defaultConfig: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
220
|
+
isActive: z.ZodBoolean;
|
|
221
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
222
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
223
|
+
}, "strip", z.ZodTypeAny, {
|
|
224
|
+
id: string;
|
|
225
|
+
name: string;
|
|
226
|
+
version: string;
|
|
227
|
+
schema: Record<string, any>;
|
|
228
|
+
uiSchema: Record<string, any>;
|
|
229
|
+
defaultConfig: Record<string, any>;
|
|
230
|
+
isActive: boolean;
|
|
231
|
+
createdAt?: string | undefined;
|
|
232
|
+
updatedAt?: string | undefined;
|
|
233
|
+
}, {
|
|
234
|
+
id: string;
|
|
235
|
+
name: string;
|
|
236
|
+
version: string;
|
|
237
|
+
isActive: boolean;
|
|
238
|
+
createdAt?: string | undefined;
|
|
239
|
+
updatedAt?: string | undefined;
|
|
240
|
+
schema?: Record<string, any> | undefined;
|
|
241
|
+
uiSchema?: Record<string, any> | undefined;
|
|
242
|
+
defaultConfig?: Record<string, any> | undefined;
|
|
243
|
+
}>;
|
|
244
|
+
type ProductData = z.infer<typeof productSchema>;
|
|
245
|
+
|
|
246
|
+
export { type AccountData, type BrandData, type GeneratorOptions, type GeneratorResult, type ProductData, type ProductInstanceData, type SyncOptions, type SyncResult, accountSchema, brandSchema, fetchAccounts, fetchBrands, fetchProductInstances, fetchProducts, generateContentCollections, productInstanceSchema, productSchema, syncFromAppSync };
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// src/content-collections/generator.ts
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
|
|
5
|
+
// src/content-collections/sync.ts
|
|
6
|
+
import { generateClient } from "@aws-amplify/api";
|
|
7
|
+
async function fetchBrands(options) {
|
|
8
|
+
try {
|
|
9
|
+
const client = generateClient({
|
|
10
|
+
authMode: options.authMode || "apiKey"
|
|
11
|
+
});
|
|
12
|
+
const { data, errors } = await client.models.Brand.list({
|
|
13
|
+
limit: options.limit || 1e3
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
data: data || [],
|
|
17
|
+
errors: errors || null
|
|
18
|
+
};
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error("[fetchBrands] Error:", error);
|
|
21
|
+
return {
|
|
22
|
+
data: [],
|
|
23
|
+
errors: [{ message: error.message }]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function fetchAccounts(options) {
|
|
28
|
+
try {
|
|
29
|
+
const client = generateClient({
|
|
30
|
+
authMode: options.authMode || "apiKey"
|
|
31
|
+
});
|
|
32
|
+
const { data, errors } = await client.models.Account.list({
|
|
33
|
+
limit: options.limit || 1e3
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
data: data || [],
|
|
37
|
+
errors: errors || null
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("[fetchAccounts] Error:", error);
|
|
41
|
+
return {
|
|
42
|
+
data: [],
|
|
43
|
+
errors: [{ message: error.message }]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function fetchProductInstances(options) {
|
|
48
|
+
try {
|
|
49
|
+
const client = generateClient({
|
|
50
|
+
authMode: options.authMode || "apiKey"
|
|
51
|
+
});
|
|
52
|
+
const { data, errors } = await client.models.ProductInstance.list(
|
|
53
|
+
{
|
|
54
|
+
limit: options.limit || 1e3
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
return {
|
|
58
|
+
data: data || [],
|
|
59
|
+
errors: errors || null
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("[fetchProductInstances] Error:", error);
|
|
63
|
+
return {
|
|
64
|
+
data: [],
|
|
65
|
+
errors: [{ message: error.message }]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function fetchProducts(options) {
|
|
70
|
+
try {
|
|
71
|
+
const client = generateClient({
|
|
72
|
+
authMode: options.authMode || "apiKey"
|
|
73
|
+
});
|
|
74
|
+
const { data, errors } = await client.models.Product.list({
|
|
75
|
+
limit: options.limit || 1e3
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
data: data || [],
|
|
79
|
+
errors: errors || null
|
|
80
|
+
};
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("[fetchProducts] Error:", error);
|
|
83
|
+
return {
|
|
84
|
+
data: [],
|
|
85
|
+
errors: [{ message: error.message }]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/content-collections/schemas.ts
|
|
91
|
+
import { z } from "zod";
|
|
92
|
+
var brandSchema = z.object({
|
|
93
|
+
id: z.string(),
|
|
94
|
+
name: z.string(),
|
|
95
|
+
accountId: z.string(),
|
|
96
|
+
logo: z.string().optional(),
|
|
97
|
+
timezone: z.string(),
|
|
98
|
+
status: z.enum(["active", "inactive", "maintenance", "suspended"]),
|
|
99
|
+
settings: z.record(z.any()).optional().default({}),
|
|
100
|
+
createdAt: z.string().optional(),
|
|
101
|
+
updatedAt: z.string().optional()
|
|
102
|
+
});
|
|
103
|
+
var accountSchema = z.object({
|
|
104
|
+
id: z.string(),
|
|
105
|
+
name: z.string(),
|
|
106
|
+
logo: z.string().optional(),
|
|
107
|
+
subscription: z.record(z.any()).optional().default({}),
|
|
108
|
+
settings: z.record(z.any()).optional().default({}),
|
|
109
|
+
createdAt: z.string().optional(),
|
|
110
|
+
updatedAt: z.string().optional()
|
|
111
|
+
});
|
|
112
|
+
var productInstanceSchema = z.object({
|
|
113
|
+
id: z.string(),
|
|
114
|
+
productId: z.string(),
|
|
115
|
+
productName: z.string(),
|
|
116
|
+
brandId: z.string(),
|
|
117
|
+
accountId: z.string(),
|
|
118
|
+
enabled: z.boolean(),
|
|
119
|
+
config: z.record(z.any()).optional().default({}),
|
|
120
|
+
version: z.string(),
|
|
121
|
+
createdAt: z.string().optional(),
|
|
122
|
+
updatedAt: z.string().optional()
|
|
123
|
+
});
|
|
124
|
+
var productSchema = z.object({
|
|
125
|
+
id: z.string(),
|
|
126
|
+
name: z.string(),
|
|
127
|
+
version: z.string(),
|
|
128
|
+
schema: z.record(z.any()).optional().default({}),
|
|
129
|
+
uiSchema: z.record(z.any()).optional().default({}),
|
|
130
|
+
defaultConfig: z.record(z.any()).optional().default({}),
|
|
131
|
+
isActive: z.boolean(),
|
|
132
|
+
createdAt: z.string().optional(),
|
|
133
|
+
updatedAt: z.string().optional()
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// src/content-collections/generator.ts
|
|
137
|
+
async function generateContentCollections(options) {
|
|
138
|
+
const {
|
|
139
|
+
outputDir = "src/content",
|
|
140
|
+
validate = true,
|
|
141
|
+
continueOnError = true
|
|
142
|
+
} = options;
|
|
143
|
+
const result = {
|
|
144
|
+
brands: { count: 0, errors: [] },
|
|
145
|
+
accounts: { count: 0, errors: [] },
|
|
146
|
+
productInstances: { count: 0, errors: [] },
|
|
147
|
+
products: { count: 0, errors: [] }
|
|
148
|
+
};
|
|
149
|
+
const brandsDir = join(outputDir, "brands");
|
|
150
|
+
const accountsDir = join(outputDir, "accounts");
|
|
151
|
+
const productInstancesDir = join(outputDir, "product-instances");
|
|
152
|
+
const productsDir = join(outputDir, "products");
|
|
153
|
+
for (const dir of [brandsDir, accountsDir, productInstancesDir, productsDir]) {
|
|
154
|
+
if (!existsSync(dir)) {
|
|
155
|
+
mkdirSync(dir, { recursive: true });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
console.log("[generateContentCollections] Fetching brands...");
|
|
160
|
+
const brandsResult = await fetchBrands(options);
|
|
161
|
+
if (brandsResult.errors && !continueOnError) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Failed to fetch brands: ${brandsResult.errors[0]?.message}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (brandsResult.errors) {
|
|
167
|
+
result.brands.errors.push(
|
|
168
|
+
...brandsResult.errors.map((e) => e.message)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
for (const brand of brandsResult.data) {
|
|
172
|
+
try {
|
|
173
|
+
if (validate) {
|
|
174
|
+
brandSchema.parse(brand);
|
|
175
|
+
}
|
|
176
|
+
const filename = join(brandsDir, `${brand.id}.json`);
|
|
177
|
+
writeFileSync(filename, JSON.stringify(brand, null, 2));
|
|
178
|
+
result.brands.count++;
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const errorMsg = `Failed to process brand ${brand.id}: ${error.message}`;
|
|
181
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
182
|
+
result.brands.errors.push(errorMsg);
|
|
183
|
+
if (!continueOnError) {
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
console.log(
|
|
189
|
+
`[generateContentCollections] Generated ${result.brands.count} brands`
|
|
190
|
+
);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
const errorMsg = `Failed to generate brands: ${error.message}`;
|
|
193
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
194
|
+
result.brands.errors.push(errorMsg);
|
|
195
|
+
if (!continueOnError) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
console.log("[generateContentCollections] Fetching accounts...");
|
|
201
|
+
const accountsResult = await fetchAccounts(options);
|
|
202
|
+
if (accountsResult.errors && !continueOnError) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`Failed to fetch accounts: ${accountsResult.errors[0]?.message}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (accountsResult.errors) {
|
|
208
|
+
result.accounts.errors.push(
|
|
209
|
+
...accountsResult.errors.map((e) => e.message)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
for (const account of accountsResult.data) {
|
|
213
|
+
try {
|
|
214
|
+
if (validate) {
|
|
215
|
+
accountSchema.parse(account);
|
|
216
|
+
}
|
|
217
|
+
const filename = join(accountsDir, `${account.id}.json`);
|
|
218
|
+
writeFileSync(filename, JSON.stringify(account, null, 2));
|
|
219
|
+
result.accounts.count++;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
const errorMsg = `Failed to process account ${account.id}: ${error.message}`;
|
|
222
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
223
|
+
result.accounts.errors.push(errorMsg);
|
|
224
|
+
if (!continueOnError) {
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
console.log(
|
|
230
|
+
`[generateContentCollections] Generated ${result.accounts.count} accounts`
|
|
231
|
+
);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
const errorMsg = `Failed to generate accounts: ${error.message}`;
|
|
234
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
235
|
+
result.accounts.errors.push(errorMsg);
|
|
236
|
+
if (!continueOnError) {
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
console.log("[generateContentCollections] Fetching product instances...");
|
|
242
|
+
const productInstancesResult = await fetchProductInstances(options);
|
|
243
|
+
if (productInstancesResult.errors && !continueOnError) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Failed to fetch product instances: ${productInstancesResult.errors[0]?.message}`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (productInstancesResult.errors) {
|
|
249
|
+
result.productInstances.errors.push(
|
|
250
|
+
...productInstancesResult.errors.map((e) => e.message)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
for (const instance of productInstancesResult.data) {
|
|
254
|
+
try {
|
|
255
|
+
if (validate) {
|
|
256
|
+
productInstanceSchema.parse(instance);
|
|
257
|
+
}
|
|
258
|
+
const filename = join(productInstancesDir, `${instance.id}.json`);
|
|
259
|
+
writeFileSync(filename, JSON.stringify(instance, null, 2));
|
|
260
|
+
result.productInstances.count++;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
const errorMsg = `Failed to process product instance ${instance.id}: ${error.message}`;
|
|
263
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
264
|
+
result.productInstances.errors.push(errorMsg);
|
|
265
|
+
if (!continueOnError) {
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
console.log(
|
|
271
|
+
`[generateContentCollections] Generated ${result.productInstances.count} product instances`
|
|
272
|
+
);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
const errorMsg = `Failed to generate product instances: ${error.message}`;
|
|
275
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
276
|
+
result.productInstances.errors.push(errorMsg);
|
|
277
|
+
if (!continueOnError) {
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
console.log("[generateContentCollections] Fetching products...");
|
|
283
|
+
const productsResult = await fetchProducts(options);
|
|
284
|
+
if (productsResult.errors && !continueOnError) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
`Failed to fetch products: ${productsResult.errors[0]?.message}`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
if (productsResult.errors) {
|
|
290
|
+
result.products.errors.push(
|
|
291
|
+
...productsResult.errors.map((e) => e.message)
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
for (const product of productsResult.data) {
|
|
295
|
+
try {
|
|
296
|
+
if (validate) {
|
|
297
|
+
productSchema.parse(product);
|
|
298
|
+
}
|
|
299
|
+
const filename = join(productsDir, `${product.id}.json`);
|
|
300
|
+
writeFileSync(filename, JSON.stringify(product, null, 2));
|
|
301
|
+
result.products.count++;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const errorMsg = `Failed to process product ${product.id}: ${error.message}`;
|
|
304
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
305
|
+
result.products.errors.push(errorMsg);
|
|
306
|
+
if (!continueOnError) {
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
console.log(
|
|
312
|
+
`[generateContentCollections] Generated ${result.products.count} products`
|
|
313
|
+
);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
const errorMsg = `Failed to generate products: ${error.message}`;
|
|
316
|
+
console.error(`[generateContentCollections] ${errorMsg}`);
|
|
317
|
+
result.products.errors.push(errorMsg);
|
|
318
|
+
if (!continueOnError) {
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
var syncFromAppSync = generateContentCollections;
|
|
325
|
+
export {
|
|
326
|
+
accountSchema,
|
|
327
|
+
brandSchema,
|
|
328
|
+
fetchAccounts,
|
|
329
|
+
fetchBrands,
|
|
330
|
+
fetchProductInstances,
|
|
331
|
+
fetchProducts,
|
|
332
|
+
generateContentCollections,
|
|
333
|
+
productInstanceSchema,
|
|
334
|
+
productSchema,
|
|
335
|
+
syncFromAppSync
|
|
336
|
+
};
|
|
337
|
+
//# sourceMappingURL=index.js.map
|