@leandrosk/dashboard 3.5.5 → 3.5.6

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.
Files changed (71) hide show
  1. package/dist/plugin/api/api-extensions.d.ts +1 -0
  2. package/dist/plugin/api/api-extensions.js +35 -0
  3. package/dist/plugin/api/metrics.resolver.d.ts +8 -0
  4. package/dist/plugin/api/metrics.resolver.js +40 -0
  5. package/dist/plugin/config/metrics-strategies.d.ts +39 -0
  6. package/dist/plugin/config/metrics-strategies.js +74 -0
  7. package/dist/plugin/constants.d.ts +8 -0
  8. package/dist/plugin/constants.js +33 -0
  9. package/dist/plugin/dashboard.plugin.d.ts +115 -0
  10. package/dist/plugin/dashboard.plugin.js +339 -0
  11. package/dist/plugin/default-page.html +193 -0
  12. package/dist/plugin/index.d.ts +2 -0
  13. package/dist/plugin/index.js +18 -0
  14. package/dist/plugin/package.json +3 -0
  15. package/dist/plugin/service/metrics.service.d.ts +15 -0
  16. package/dist/plugin/service/metrics.service.js +129 -0
  17. package/dist/plugin/types.d.ts +20 -0
  18. package/dist/plugin/types.js +9 -0
  19. package/dist/vite/constants.d.ts +5 -0
  20. package/dist/vite/constants.js +279 -0
  21. package/dist/vite/index.d.ts +1 -0
  22. package/dist/vite/index.js +1 -0
  23. package/dist/vite/types.d.ts +79 -0
  24. package/dist/vite/types.js +1 -0
  25. package/dist/vite/utils/ast-utils.d.ts +5 -0
  26. package/dist/vite/utils/ast-utils.js +29 -0
  27. package/dist/vite/utils/ast-utils.spec.d.ts +1 -0
  28. package/dist/vite/utils/ast-utils.spec.js +45 -0
  29. package/dist/vite/utils/compiler.d.ts +23 -0
  30. package/dist/vite/utils/compiler.js +191 -0
  31. package/dist/vite/utils/get-dashboard-paths.d.ts +5 -0
  32. package/dist/vite/utils/get-dashboard-paths.js +20 -0
  33. package/dist/vite/utils/logger.d.ts +3 -0
  34. package/dist/vite/utils/logger.js +39 -0
  35. package/dist/vite/utils/path-transformer.d.ts +20 -0
  36. package/dist/vite/utils/path-transformer.js +116 -0
  37. package/dist/vite/utils/plugin-discovery.d.ts +27 -0
  38. package/dist/vite/utils/plugin-discovery.js +399 -0
  39. package/dist/vite/utils/schema-generator.d.ts +10 -0
  40. package/dist/vite/utils/schema-generator.js +35 -0
  41. package/dist/vite/utils/tsconfig-utils.d.ts +9 -0
  42. package/dist/vite/utils/tsconfig-utils.js +51 -0
  43. package/dist/vite/utils/ui-config.d.ts +3 -0
  44. package/dist/vite/utils/ui-config.js +44 -0
  45. package/dist/vite/vite-plugin-admin-api-schema.d.ts +24 -0
  46. package/dist/vite/vite-plugin-admin-api-schema.js +82 -0
  47. package/dist/vite/vite-plugin-config-loader.d.ts +16 -0
  48. package/dist/vite/vite-plugin-config-loader.js +70 -0
  49. package/dist/vite/vite-plugin-config.d.ts +4 -0
  50. package/dist/vite/vite-plugin-config.js +60 -0
  51. package/dist/vite/vite-plugin-dashboard-metadata.d.ts +7 -0
  52. package/dist/vite/vite-plugin-dashboard-metadata.js +61 -0
  53. package/dist/vite/vite-plugin-gql-tada.d.ts +6 -0
  54. package/dist/vite/vite-plugin-gql-tada.js +51 -0
  55. package/dist/vite/vite-plugin-hmr.d.ts +8 -0
  56. package/dist/vite/vite-plugin-hmr.js +34 -0
  57. package/dist/vite/vite-plugin-lingui-babel.d.ts +40 -0
  58. package/dist/vite/vite-plugin-lingui-babel.js +168 -0
  59. package/dist/vite/vite-plugin-tailwind-source.d.ts +7 -0
  60. package/dist/vite/vite-plugin-tailwind-source.js +48 -0
  61. package/dist/vite/vite-plugin-theme.d.ts +55 -0
  62. package/dist/vite/vite-plugin-theme.js +130 -0
  63. package/dist/vite/vite-plugin-transform-index.d.ts +11 -0
  64. package/dist/vite/vite-plugin-transform-index.js +40 -0
  65. package/dist/vite/vite-plugin-translations.d.ts +31 -0
  66. package/dist/vite/vite-plugin-translations.js +177 -0
  67. package/dist/vite/vite-plugin-ui-config.d.ts +181 -0
  68. package/dist/vite/vite-plugin-ui-config.js +36 -0
  69. package/dist/vite/vite-plugin-vendure-dashboard.d.ts +142 -0
  70. package/dist/vite/vite-plugin-vendure-dashboard.js +170 -0
  71. package/package.json +5 -4
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MetricsService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@vendure/core");
15
+ const crypto_1 = require("crypto");
16
+ const date_fns_1 = require("date-fns");
17
+ const metrics_strategies_js_1 = require("../config/metrics-strategies.js");
18
+ const constants_js_1 = require("../constants.js");
19
+ let MetricsService = class MetricsService {
20
+ constructor(connection, cacheService) {
21
+ this.connection = connection;
22
+ this.cacheService = cacheService;
23
+ this.metricCalculations = [
24
+ new metrics_strategies_js_1.AverageOrderValueMetric(),
25
+ new metrics_strategies_js_1.OrderCountMetric(),
26
+ new metrics_strategies_js_1.OrderTotalMetric(),
27
+ ];
28
+ }
29
+ async getMetrics(ctx, { types, refresh, startDate, endDate }) {
30
+ const calculatedStartDate = (0, date_fns_1.startOfDay)(new Date(startDate));
31
+ const calculatedEndDate = (0, date_fns_1.endOfDay)(new Date(endDate));
32
+ // Check if we have cached result
33
+ const hash = (0, crypto_1.createHash)('sha1')
34
+ .update(JSON.stringify({
35
+ startDate: calculatedStartDate,
36
+ endDate: calculatedEndDate,
37
+ types: types.sort(),
38
+ channel: ctx.channel.token,
39
+ }))
40
+ .digest('base64');
41
+ const cacheKey = `MetricsService:${hash}`;
42
+ const cachedMetricList = await this.cacheService.get(cacheKey);
43
+ if (cachedMetricList && refresh !== true) {
44
+ core_1.Logger.verbose(`Returning cached metrics for channel ${ctx.channel.token}`, constants_js_1.loggerCtx);
45
+ return cachedMetricList;
46
+ }
47
+ // No cache, calculating new metrics
48
+ core_1.Logger.verbose(`No cache hit, calculating metrics from ${calculatedStartDate.toISOString()} to ${calculatedEndDate.toISOString()} for channel ${ctx.channel.token} for all orders`, constants_js_1.loggerCtx);
49
+ const data = await this.loadData(ctx, calculatedStartDate, calculatedEndDate);
50
+ const metrics = [];
51
+ for (const type of types) {
52
+ const metric = this.metricCalculations.find(m => m.type === type);
53
+ if (!metric) {
54
+ continue;
55
+ }
56
+ // Calculate entries for each day
57
+ const entries = [];
58
+ data.forEach(dataPerDay => {
59
+ entries.push(metric.calculateEntry(ctx, dataPerDay));
60
+ });
61
+ // Create metric with calculated entries
62
+ metrics.push({
63
+ title: metric.getTitle(ctx),
64
+ type: metric.type,
65
+ entries,
66
+ });
67
+ }
68
+ await this.cacheService.set(cacheKey, metrics, { ttl: 1000 * 60 * 60 * 2 }); // 2 hours
69
+ return metrics;
70
+ }
71
+ async loadData(ctx, startDate, endDate) {
72
+ const orderRepo = this.connection.getRepository(ctx, core_1.Order);
73
+ // Calculate number of days between start and end
74
+ const diffTime = Math.abs(endDate.getTime() - startDate.getTime());
75
+ const nrOfDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1;
76
+ // Get orders in a loop until we have all
77
+ let skip = 0;
78
+ const take = 1000;
79
+ let hasMoreOrders = true;
80
+ const orders = [];
81
+ while (hasMoreOrders) {
82
+ const query = orderRepo
83
+ .createQueryBuilder('order')
84
+ .leftJoin('order.channels', 'orderChannel')
85
+ .where('orderChannel.id=:channelId', { channelId: ctx.channelId })
86
+ .andWhere('order.orderPlacedAt >= :startDate', {
87
+ startDate: startDate.toISOString(),
88
+ })
89
+ .andWhere('order.orderPlacedAt <= :endDate', {
90
+ endDate: endDate.toISOString(),
91
+ })
92
+ .skip(skip)
93
+ .take(take);
94
+ const [items, nrOfOrders] = await query.getManyAndCount();
95
+ orders.push(...items);
96
+ core_1.Logger.verbose(`Fetched orders ${skip}-${skip + take} for channel ${ctx.channel.token} for date range metrics`, constants_js_1.loggerCtx);
97
+ skip += items.length;
98
+ if (orders.length >= nrOfOrders) {
99
+ hasMoreOrders = false;
100
+ }
101
+ }
102
+ core_1.Logger.verbose(`Finished fetching all ${orders.length} orders for channel ${ctx.channel.token} for date range metrics`, constants_js_1.loggerCtx);
103
+ const dataPerDay = new Map();
104
+ // Create a map entry for each day in the range
105
+ for (let i = 0; i < nrOfDays; i++) {
106
+ const currentDate = new Date(startDate);
107
+ currentDate.setDate(startDate.getDate() + i);
108
+ const dateKey = currentDate.toISOString().split('T')[0]; // YYYY-MM-DD format
109
+ // Filter orders for this specific day
110
+ const ordersForDay = orders.filter(order => {
111
+ if (!order.orderPlacedAt)
112
+ return false;
113
+ const orderDate = new Date(order.orderPlacedAt).toISOString().split('T')[0];
114
+ return orderDate === dateKey;
115
+ });
116
+ dataPerDay.set(dateKey, {
117
+ orders: ordersForDay,
118
+ date: currentDate,
119
+ });
120
+ }
121
+ return dataPerDay;
122
+ }
123
+ };
124
+ exports.MetricsService = MetricsService;
125
+ exports.MetricsService = MetricsService = __decorate([
126
+ (0, common_1.Injectable)(),
127
+ __metadata("design:paramtypes", [core_1.TransactionalConnection,
128
+ core_1.CacheService])
129
+ ], MetricsService);
@@ -0,0 +1,20 @@
1
+ export type DashboardMetricSummary = {
2
+ type: DashboardMetricType;
3
+ title: string;
4
+ entries: DashboardMetricSummaryEntry[];
5
+ };
6
+ export declare enum DashboardMetricType {
7
+ OrderCount = "OrderCount",
8
+ OrderTotal = "OrderTotal",
9
+ AverageOrderValue = "AverageOrderValue"
10
+ }
11
+ export type DashboardMetricSummaryEntry = {
12
+ label: string;
13
+ value: number;
14
+ };
15
+ export interface DashboardMetricSummaryInput {
16
+ types: DashboardMetricType[];
17
+ refresh?: boolean;
18
+ startDate: string;
19
+ endDate: string;
20
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DashboardMetricType = void 0;
4
+ var DashboardMetricType;
5
+ (function (DashboardMetricType) {
6
+ DashboardMetricType["OrderCount"] = "OrderCount";
7
+ DashboardMetricType["OrderTotal"] = "OrderTotal";
8
+ DashboardMetricType["AverageOrderValue"] = "AverageOrderValue";
9
+ })(DashboardMetricType || (exports.DashboardMetricType = DashboardMetricType = {}));
@@ -0,0 +1,5 @@
1
+ import { LanguageCode } from '@vendure/core';
2
+ export declare const defaultLanguage = LanguageCode.en;
3
+ export declare const defaultLocale: undefined;
4
+ export declare const defaultAvailableLanguages: LanguageCode[];
5
+ export declare const defaultAvailableLocales: string[];
@@ -0,0 +1,279 @@
1
+ import { LanguageCode } from '@vendure/core';
2
+ export const defaultLanguage = LanguageCode.en;
3
+ export const defaultLocale = undefined;
4
+ export const defaultAvailableLanguages = [
5
+ LanguageCode.he,
6
+ LanguageCode.ar,
7
+ LanguageCode.de,
8
+ LanguageCode.en,
9
+ LanguageCode.es,
10
+ LanguageCode.pl,
11
+ LanguageCode.zh_Hans,
12
+ LanguageCode.zh_Hant,
13
+ LanguageCode.pt_BR,
14
+ LanguageCode.pt_PT,
15
+ LanguageCode.cs,
16
+ LanguageCode.fr,
17
+ LanguageCode.ru,
18
+ LanguageCode.uk,
19
+ LanguageCode.it,
20
+ LanguageCode.fa,
21
+ LanguageCode.ne,
22
+ LanguageCode.hr,
23
+ LanguageCode.sv,
24
+ LanguageCode.nb,
25
+ LanguageCode.tr,
26
+ LanguageCode.bg,
27
+ LanguageCode.nl,
28
+ ];
29
+ export const defaultAvailableLocales = [
30
+ 'AF',
31
+ 'AL',
32
+ 'DZ',
33
+ 'AS',
34
+ 'AD',
35
+ 'AO',
36
+ 'AI',
37
+ 'AQ',
38
+ 'AG',
39
+ 'AR',
40
+ 'AM',
41
+ 'AW',
42
+ 'AU',
43
+ 'AT',
44
+ 'AZ',
45
+ 'BS',
46
+ 'BH',
47
+ 'BD',
48
+ 'BB',
49
+ 'BY',
50
+ 'BE',
51
+ 'BZ',
52
+ 'BJ',
53
+ 'BM',
54
+ 'BT',
55
+ 'BO',
56
+ 'BQ',
57
+ 'BA',
58
+ 'BW',
59
+ 'BV',
60
+ 'BR',
61
+ 'IO',
62
+ 'BN',
63
+ 'BG',
64
+ 'BF',
65
+ 'BI',
66
+ 'CV',
67
+ 'KH',
68
+ 'CM',
69
+ 'CA',
70
+ 'KY',
71
+ 'CF',
72
+ 'TD',
73
+ 'CL',
74
+ 'CN',
75
+ 'CX',
76
+ 'CC',
77
+ 'CO',
78
+ 'KM',
79
+ 'CD',
80
+ 'CG',
81
+ 'CK',
82
+ 'CR',
83
+ 'HR',
84
+ 'CU',
85
+ 'CW',
86
+ 'CY',
87
+ 'CZ',
88
+ 'CI',
89
+ 'DK',
90
+ 'DJ',
91
+ 'DM',
92
+ 'DO',
93
+ 'EC',
94
+ 'EG',
95
+ 'SV',
96
+ 'GQ',
97
+ 'ER',
98
+ 'EE',
99
+ 'SZ',
100
+ 'ET',
101
+ 'FK',
102
+ 'FO',
103
+ 'FJ',
104
+ 'FI',
105
+ 'FR',
106
+ 'GF',
107
+ 'PF',
108
+ 'TF',
109
+ 'GA',
110
+ 'GM',
111
+ 'GE',
112
+ 'DE',
113
+ 'GH',
114
+ 'GI',
115
+ 'GR',
116
+ 'GL',
117
+ 'GD',
118
+ 'GP',
119
+ 'GU',
120
+ 'GT',
121
+ 'GG',
122
+ 'GN',
123
+ 'GW',
124
+ 'GY',
125
+ 'HT',
126
+ 'HM',
127
+ 'VA',
128
+ 'HN',
129
+ 'HK',
130
+ 'HU',
131
+ 'IS',
132
+ 'IN',
133
+ 'ID',
134
+ 'IR',
135
+ 'IQ',
136
+ 'IE',
137
+ 'IM',
138
+ 'IL',
139
+ 'IT',
140
+ 'JM',
141
+ 'JP',
142
+ 'JE',
143
+ 'JO',
144
+ 'KZ',
145
+ 'KE',
146
+ 'KI',
147
+ 'KP',
148
+ 'KR',
149
+ 'KW',
150
+ 'KG',
151
+ 'LA',
152
+ 'LV',
153
+ 'LB',
154
+ 'LS',
155
+ 'LR',
156
+ 'LY',
157
+ 'LI',
158
+ 'LT',
159
+ 'LU',
160
+ 'MO',
161
+ 'MG',
162
+ 'MW',
163
+ 'MY',
164
+ 'MV',
165
+ 'ML',
166
+ 'MT',
167
+ 'MH',
168
+ 'MQ',
169
+ 'MR',
170
+ 'MU',
171
+ 'YT',
172
+ 'MX',
173
+ 'FM',
174
+ 'MD',
175
+ 'MC',
176
+ 'MN',
177
+ 'ME',
178
+ 'MS',
179
+ 'MA',
180
+ 'MZ',
181
+ 'MM',
182
+ 'NA',
183
+ 'NR',
184
+ 'NP',
185
+ 'NL',
186
+ 'NC',
187
+ 'NZ',
188
+ 'NI',
189
+ 'NE',
190
+ 'NG',
191
+ 'NU',
192
+ 'NF',
193
+ 'MK',
194
+ 'MP',
195
+ 'NO',
196
+ 'OM',
197
+ 'PK',
198
+ 'PW',
199
+ 'PS',
200
+ 'PA',
201
+ 'PG',
202
+ 'PY',
203
+ 'PE',
204
+ 'PH',
205
+ 'PN',
206
+ 'PL',
207
+ 'PT',
208
+ 'PR',
209
+ 'QA',
210
+ 'RO',
211
+ 'RU',
212
+ 'RW',
213
+ 'RE',
214
+ 'BL',
215
+ 'SH',
216
+ 'KN',
217
+ 'LC',
218
+ 'MF',
219
+ 'PM',
220
+ 'VC',
221
+ 'WS',
222
+ 'SM',
223
+ 'ST',
224
+ 'SA',
225
+ 'SN',
226
+ 'RS',
227
+ 'SC',
228
+ 'SL',
229
+ 'SG',
230
+ 'SX',
231
+ 'SK',
232
+ 'SI',
233
+ 'SB',
234
+ 'SO',
235
+ 'ZA',
236
+ 'GS',
237
+ 'SS',
238
+ 'ES',
239
+ 'LK',
240
+ 'SD',
241
+ 'SR',
242
+ 'SJ',
243
+ 'SE',
244
+ 'CH',
245
+ 'SY',
246
+ 'TW',
247
+ 'TJ',
248
+ 'TZ',
249
+ 'TH',
250
+ 'TL',
251
+ 'TG',
252
+ 'TK',
253
+ 'TO',
254
+ 'TT',
255
+ 'TN',
256
+ 'TR',
257
+ 'TM',
258
+ 'TC',
259
+ 'TV',
260
+ 'UG',
261
+ 'UA',
262
+ 'AE',
263
+ 'GB',
264
+ 'UM',
265
+ 'US',
266
+ 'UY',
267
+ 'UZ',
268
+ 'VU',
269
+ 'VE',
270
+ 'VN',
271
+ 'VG',
272
+ 'VI',
273
+ 'WF',
274
+ 'EH',
275
+ 'YE',
276
+ 'ZM',
277
+ 'ZW',
278
+ 'AX',
279
+ ];
@@ -0,0 +1 @@
1
+ export { vendureDashboardPlugin } from './vite-plugin-vendure-dashboard.js';
@@ -0,0 +1 @@
1
+ export { vendureDashboardPlugin } from './vite-plugin-vendure-dashboard.js';
@@ -0,0 +1,79 @@
1
+ export type Logger = {
2
+ info: (message: string) => void;
3
+ warn: (message: string) => void;
4
+ debug: (message: string) => void;
5
+ error: (message: string) => void;
6
+ };
7
+ export type PluginInfo = {
8
+ name: string;
9
+ pluginPath: string;
10
+ dashboardEntryPath: string | undefined;
11
+ /** The original source path of the plugin, only set for local plugins that are compiled */
12
+ sourcePluginPath?: string;
13
+ };
14
+ export type GetCompiledConfigPathFn = (params: {
15
+ inputRootDir: string;
16
+ outputPath: string;
17
+ configFileName: string;
18
+ }) => string;
19
+ export type TransformTsConfigPathMappingsFn = (params: {
20
+ phase: 'compiling' | 'loading';
21
+ alias: string;
22
+ patterns: string[];
23
+ }) => string[];
24
+ /**
25
+ * @description
26
+ * The PathAdapter interface allows customization of how paths are handled
27
+ * when compiling the Vendure config and its imports.
28
+ *
29
+ * It enables support for more complex repository structures, such as
30
+ * monorepos, where the Vendure server configuration file may not
31
+ * be located in the root directory of the project.
32
+ *
33
+ * If you get compilation errors like "Error loading Vendure config: Cannot find module",
34
+ * you probably need to provide a custom `pathAdapter` to resolve the paths correctly.
35
+ *
36
+ * This can take some trial-and-error. Try logging values from the functions to figure out
37
+ * the exact settings that you need for your repo setup.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * vendureDashboardPlugin({
42
+ * pathAdapter: {
43
+ * getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
44
+ * const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
45
+ * const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
46
+ * const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
47
+ * return path.join(compiledConfigFilePath, configFileName);
48
+ * },
49
+ * transformTsConfigPathMappings: ({ phase, patterns }) => {
50
+ * // "loading" phase is when the compiled Vendure code is being loaded by
51
+ * // the plugin, in order to introspect the configuration of your app.
52
+ * if (phase === 'loading') {
53
+ * return patterns.map((p) =>
54
+ * p.replace('libs/', '').replace(/.ts$/, '.js'),
55
+ * );
56
+ * }
57
+ * return patterns;
58
+ * },
59
+ * },
60
+ * // ...
61
+ * }),
62
+ * ```
63
+ *
64
+ * @docsCategory vite-plugin
65
+ * @docsPage vendureDashboardPlugin
66
+ * @since 3.4.0
67
+ */
68
+ export interface PathAdapter {
69
+ /**
70
+ * @description
71
+ * A function to determine the path to the compiled Vendure config file.
72
+ */
73
+ getCompiledConfigPath?: GetCompiledConfigPathFn;
74
+ /**
75
+ * If your project makes use of the TypeScript `paths` configuration, the compiler will
76
+ * attempt to use these paths when compiling the Vendure config and its imports.
77
+ */
78
+ transformTsConfigPathMappings?: TransformTsConfigPathMappingsFn;
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
4
+ */
5
+ export declare function findConfigExport(sourceFile: ts.SourceFile): string | undefined;
@@ -0,0 +1,29 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
4
+ */
5
+ export function findConfigExport(sourceFile) {
6
+ let exportedSymbolName;
7
+ function visit(node) {
8
+ var _a;
9
+ if (ts.isVariableStatement(node) &&
10
+ ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.ExportKeyword))) {
11
+ node.declarationList.declarations.forEach(declaration => {
12
+ if (ts.isVariableDeclaration(declaration)) {
13
+ const typeNode = declaration.type;
14
+ if (typeNode && ts.isTypeReferenceNode(typeNode)) {
15
+ const typeName = typeNode.typeName;
16
+ if (ts.isIdentifier(typeName) && typeName.text === 'VendureConfig') {
17
+ if (ts.isIdentifier(declaration.name)) {
18
+ exportedSymbolName = declaration.name.text;
19
+ }
20
+ }
21
+ }
22
+ }
23
+ });
24
+ }
25
+ ts.forEachChild(node, visit);
26
+ }
27
+ visit(sourceFile);
28
+ return exportedSymbolName;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ import ts from 'typescript';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { findConfigExport } from './ast-utils.js';
4
+ describe('findConfigExport', () => {
5
+ it('should return undefined when no VendureConfig export is found', { timeout: 30000 }, () => {
6
+ const sourceText = `
7
+ export const notConfig = {
8
+ some: 'value'
9
+ };
10
+ `;
11
+ const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
12
+ const result = findConfigExport(sourceFile);
13
+ expect(result).toBeUndefined();
14
+ });
15
+ it('should find exported variable with VendureConfig type', { timeout: 30000 }, () => {
16
+ const sourceText = `
17
+ import { VendureConfig } from '@vendure/core';
18
+
19
+ export const config: VendureConfig = {
20
+ authOptions: {
21
+ tokenMethod: 'bearer'
22
+ }
23
+ };
24
+ `;
25
+ const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
26
+ const result = findConfigExport(sourceFile);
27
+ expect(result).toBe('config');
28
+ });
29
+ it('should find exported variable with VendureConfig type among other exports', { timeout: 30000 }, () => {
30
+ const sourceText = `
31
+ import { VendureConfig } from '@vendure/core';
32
+
33
+ export const otherExport = 'value';
34
+ export const config: VendureConfig = {
35
+ authOptions: {
36
+ tokenMethod: 'bearer'
37
+ }
38
+ };
39
+ export const anotherExport = 123;
40
+ `;
41
+ const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
42
+ const result = findConfigExport(sourceFile);
43
+ expect(result).toBe('config');
44
+ });
45
+ });
@@ -0,0 +1,23 @@
1
+ import { VendureConfig } from '@vendure/core';
2
+ import { Logger, PathAdapter, PluginInfo } from '../types.js';
3
+ export interface PackageScannerConfig {
4
+ nodeModulesRoot?: string;
5
+ }
6
+ export interface CompilerOptions {
7
+ vendureConfigPath: string;
8
+ outputPath: string;
9
+ pathAdapter?: PathAdapter;
10
+ logger?: Logger;
11
+ pluginPackageScanner?: PackageScannerConfig;
12
+ module?: 'commonjs' | 'esm';
13
+ }
14
+ export interface CompileResult {
15
+ vendureConfig: VendureConfig;
16
+ exportedSymbolName: string;
17
+ pluginInfo: PluginInfo[];
18
+ }
19
+ /**
20
+ * Compiles TypeScript files and discovers Vendure plugins in both the compiled output
21
+ * and in node_modules.
22
+ */
23
+ export declare function compile(options: CompilerOptions): Promise<CompileResult>;