@vendure/core 3.3.8 → 3.4.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.
Files changed (83) hide show
  1. package/dist/api/api-internal-modules.js +2 -0
  2. package/dist/api/api-internal-modules.js.map +1 -1
  3. package/dist/api/config/get-final-vendure-schema.js +1 -1
  4. package/dist/api/config/get-final-vendure-schema.js.map +1 -1
  5. package/dist/api/config/graphql-custom-fields.js +15 -1
  6. package/dist/api/config/graphql-custom-fields.js.map +1 -1
  7. package/dist/api/resolvers/admin/facet.resolver.d.ts +5 -2
  8. package/dist/api/resolvers/admin/facet.resolver.js +45 -1
  9. package/dist/api/resolvers/admin/facet.resolver.js.map +1 -1
  10. package/dist/api/resolvers/admin/global-settings.resolver.js +14 -3
  11. package/dist/api/resolvers/admin/global-settings.resolver.js.map +1 -1
  12. package/dist/api/resolvers/admin/settings-store.resolver.d.ts +19 -0
  13. package/dist/api/resolvers/admin/settings-store.resolver.js +86 -0
  14. package/dist/api/resolvers/admin/settings-store.resolver.js.map +1 -0
  15. package/dist/api/resolvers/entity/product-option-entity.resolver.d.ts +1 -1
  16. package/dist/api/resolvers/entity/product-option-entity.resolver.js.map +1 -1
  17. package/dist/api/resolvers/entity/product-option-group-entity.resolver.d.ts +1 -1
  18. package/dist/api/resolvers/entity/product-option-group-entity.resolver.js.map +1 -1
  19. package/dist/api/resolvers/shop/shop-order.resolver.d.ts +5 -1
  20. package/dist/api/resolvers/shop/shop-order.resolver.js +18 -0
  21. package/dist/api/resolvers/shop/shop-order.resolver.js.map +1 -1
  22. package/dist/api/schema/admin-api/facet.api.graphql +7 -0
  23. package/dist/api/schema/admin-api/settings-store.api.graphql +34 -0
  24. package/dist/api/schema/common/common-error-results.graphql +10 -0
  25. package/dist/api/schema/common/common-types.graphql +1 -0
  26. package/dist/api/schema/common/custom-field-types.graphql +22 -0
  27. package/dist/api/schema/shop-api/shop.api.graphql +16 -0
  28. package/dist/bootstrap.js +3 -2
  29. package/dist/bootstrap.js.map +1 -1
  30. package/dist/config/config.service.d.ts +2 -0
  31. package/dist/config/config.service.js +4 -0
  32. package/dist/config/config.service.js.map +1 -1
  33. package/dist/config/custom-field/custom-field-types.d.ts +11 -2
  34. package/dist/config/default-config.js +4 -1
  35. package/dist/config/default-config.js.map +1 -1
  36. package/dist/config/index.d.ts +2 -0
  37. package/dist/config/index.js +2 -0
  38. package/dist/config/index.js.map +1 -1
  39. package/dist/config/settings-store/clean-orphaned-settings-store-task.d.ts +36 -0
  40. package/dist/config/settings-store/clean-orphaned-settings-store-task.js +73 -0
  41. package/dist/config/settings-store/clean-orphaned-settings-store-task.js.map +1 -0
  42. package/dist/config/settings-store/settings-store-types.d.ts +269 -0
  43. package/dist/config/settings-store/settings-store-types.js +55 -0
  44. package/dist/config/settings-store/settings-store-types.js.map +1 -0
  45. package/dist/config/vendure-config.d.ts +30 -0
  46. package/dist/entity/entities.d.ts +14 -12
  47. package/dist/entity/entities.js +14 -12
  48. package/dist/entity/entities.js.map +1 -1
  49. package/dist/entity/index.d.ts +7 -7
  50. package/dist/entity/index.js +7 -7
  51. package/dist/entity/index.js.map +1 -1
  52. package/dist/entity/order/order.entity.d.ts +1 -0
  53. package/dist/entity/order/order.entity.js +12 -1
  54. package/dist/entity/order/order.entity.js.map +1 -1
  55. package/dist/entity/order-modification/order-modification.entity.d.ts +1 -1
  56. package/dist/entity/order-modification/order-modification.entity.js +3 -3
  57. package/dist/entity/order-modification/order-modification.entity.js.map +1 -1
  58. package/dist/entity/settings-store-entry/settings-store-entry.entity.d.ts +29 -0
  59. package/dist/entity/settings-store-entry/settings-store-entry.entity.js +50 -0
  60. package/dist/entity/settings-store-entry/settings-store-entry.entity.js.map +1 -0
  61. package/dist/event-bus/events/customer-event.d.ts +1 -1
  62. package/dist/event-bus/events/customer-event.js +1 -1
  63. package/dist/event-bus/events/order-event.d.ts +17 -8
  64. package/dist/event-bus/events/order-event.js +13 -7
  65. package/dist/event-bus/events/order-event.js.map +1 -1
  66. package/dist/plugin/default-job-queue-plugin/job-record.entity.js +2 -0
  67. package/dist/plugin/default-job-queue-plugin/job-record.entity.js.map +1 -1
  68. package/dist/plugin/vendure-plugin.d.ts +3 -2
  69. package/dist/plugin/vendure-plugin.js.map +1 -1
  70. package/dist/service/helpers/order-modifier/order-modifier.js +2 -0
  71. package/dist/service/helpers/order-modifier/order-modifier.js.map +1 -1
  72. package/dist/service/helpers/settings-store/settings-store.service.d.ts +148 -0
  73. package/dist/service/helpers/settings-store/settings-store.service.js +389 -0
  74. package/dist/service/helpers/settings-store/settings-store.service.js.map +1 -0
  75. package/dist/service/index.d.ts +1 -0
  76. package/dist/service/index.js +1 -0
  77. package/dist/service/index.js.map +1 -1
  78. package/dist/service/service.module.js +2 -0
  79. package/dist/service/service.module.js.map +1 -1
  80. package/dist/service/services/order.service.js +15 -4
  81. package/dist/service/services/order.service.js.map +1 -1
  82. package/dist/service/services/product-option.service.js.map +1 -1
  83. package/package.json +3 -3
@@ -0,0 +1,148 @@
1
+ import { OnModuleInit } from '@nestjs/common';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { JsonCompatible } from '@vendure/common/lib/shared-types';
4
+ import { RequestContext } from '../../../api/common/request-context';
5
+ import { ConfigService } from '../../../config/config.service';
6
+ import { CleanupOrphanedSettingsStoreEntriesOptions, CleanupOrphanedSettingsStoreEntriesResult, OrphanedSettingsStoreEntry, SetSettingsStoreValueResult, SettingsStoreFieldConfig, SettingsStoreRegistration } from '../../../config/settings-store/settings-store-types';
7
+ import { TransactionalConnection } from '../../../connection/transactional-connection';
8
+ /**
9
+ * @description
10
+ * The SettingsStoreService provides a flexible settings storage system with support for
11
+ * scoping, permissions, and validation. It allows plugins and the core system to
12
+ * store and retrieve configuration data with fine-grained control over access and isolation.
13
+ *
14
+ * ## Usage
15
+ *
16
+ * Values are automatically scoped according to their field configuration:
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // In a service
21
+ * const userTheme = await this.settingsStoreService.get('dashboard.theme', ctx);
22
+ * await this.settingsStoreService.set('dashboard.theme', 'dark', ctx);
23
+ *
24
+ * // Get multiple values
25
+ * const settings = await this.settingsStoreService.getMany([
26
+ * 'dashboard.theme',
27
+ * 'dashboard.tableFilters'
28
+ * ], ctx);
29
+ * ```
30
+ *
31
+ * @docsCategory services
32
+ * @since 3.4.0
33
+ */
34
+ export declare class SettingsStoreService implements OnModuleInit {
35
+ private readonly connection;
36
+ private readonly moduleRef;
37
+ private readonly configService;
38
+ private readonly fieldRegistry;
39
+ private readonly injector;
40
+ constructor(connection: TransactionalConnection, moduleRef: ModuleRef, configService: ConfigService);
41
+ onModuleInit(): void;
42
+ /**
43
+ * @description
44
+ * Initialize field registrations from the Vendure configuration.
45
+ * Called during module initialization.
46
+ */
47
+ private initializeFieldRegistrations;
48
+ /**
49
+ * @description
50
+ * Register settings store fields. This is typically called during application
51
+ * bootstrap when processing the VendureConfig.
52
+ */
53
+ register(registration: SettingsStoreRegistration): void;
54
+ /**
55
+ * @description
56
+ * Get a value for the specified key. The value is automatically scoped
57
+ * according to the field's scope configuration.
58
+ *
59
+ * @param key - The full key (namespace.field)
60
+ * @param ctx - Request context for scoping and permissions
61
+ * @returns The stored value or undefined if not found or access denied
62
+ */
63
+ get<T = JsonCompatible<any>>(key: string, ctx: RequestContext): Promise<T | undefined>;
64
+ /**
65
+ * @description
66
+ * Get multiple values efficiently. Each key is scoped according to
67
+ * its individual field configuration.
68
+ *
69
+ * @param keys - Array of full keys to retrieve
70
+ * @param ctx - Request context for scoping and permissions
71
+ * @returns Object mapping keys to their values
72
+ */
73
+ getMany(keys: string[], ctx: RequestContext): Promise<Record<string, JsonCompatible<any>>>;
74
+ /**
75
+ * @description
76
+ * Set a value for the specified key with structured result feedback.
77
+ * This version returns detailed information about the success or failure
78
+ * of the operation instead of throwing errors.
79
+ *
80
+ * @param key - The full key (namespace.field)
81
+ * @param value - The value to store (must be JSON serializable)
82
+ * @param ctx - Request context for scoping and permissions
83
+ * @returns SetSettingsStoreValueResult with operation status and error details
84
+ */
85
+ set<T extends JsonCompatible<any> = JsonCompatible<any>>(key: string, value: T, ctx: RequestContext): Promise<SetSettingsStoreValueResult>;
86
+ /**
87
+ * @description
88
+ * Set multiple values with structured result feedback for each operation.
89
+ * This method will not throw errors but will return
90
+ * detailed results for each key-value pair.
91
+ *
92
+ * @param values - Object mapping keys to their values
93
+ * @param ctx - Request context for scoping and permissions
94
+ * @returns Array of SetSettingsStoreValueResult with operation status for each key
95
+ */
96
+ setMany(values: Record<string, JsonCompatible<any>>, ctx: RequestContext): Promise<SetSettingsStoreValueResult[]>;
97
+ /**
98
+ * @description
99
+ * Get the field configuration for a key.
100
+ */
101
+ getFieldDefinition(key: string): SettingsStoreFieldConfig | undefined;
102
+ /**
103
+ * @description
104
+ * Validate a value against its field definition.
105
+ */
106
+ validateValue(key: string, value: any, ctx: RequestContext): Promise<string | void>;
107
+ /**
108
+ * @description
109
+ * Generate the scope key for a given field and context.
110
+ */
111
+ private generateScope;
112
+ /**
113
+ * @description
114
+ * Get field configuration, throwing if not found.
115
+ */
116
+ private getFieldConfig;
117
+ /**
118
+ * @description
119
+ * Find orphaned settings store entries that no longer have corresponding field definitions.
120
+ *
121
+ * @param options - Options for filtering orphaned entries
122
+ * @returns Array of orphaned entries
123
+ */
124
+ findOrphanedEntries(options?: CleanupOrphanedSettingsStoreEntriesOptions): Promise<OrphanedSettingsStoreEntry[]>;
125
+ /**
126
+ * @description
127
+ * Clean up orphaned settings store entries from the database.
128
+ *
129
+ * @param options - Options for the cleanup operation
130
+ * @returns Result of the cleanup operation
131
+ */
132
+ cleanupOrphanedEntries(options?: CleanupOrphanedSettingsStoreEntriesOptions): Promise<CleanupOrphanedSettingsStoreEntriesResult>;
133
+ /**
134
+ * @description
135
+ * Parse a duration string (e.g., '7d', '30m', '2h') into a Date object.
136
+ */
137
+ private parseDuration;
138
+ /**
139
+ * @description
140
+ * Get a preview of a value for logging purposes, truncating if too large.
141
+ */
142
+ private getValuePreview;
143
+ /**
144
+ * @description
145
+ * Check if the current user has permission to access a field.
146
+ */
147
+ private hasPermission;
148
+ }
@@ -0,0 +1,389 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SettingsStoreService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const generated_types_1 = require("@vendure/common/lib/generated-types");
19
+ const ms_1 = __importDefault(require("ms"));
20
+ const errors_1 = require("../../../common/error/errors");
21
+ const injector_1 = require("../../../common/injector");
22
+ const config_service_1 = require("../../../config/config.service");
23
+ const vendure_logger_1 = require("../../../config/logger/vendure-logger");
24
+ const settings_store_types_1 = require("../../../config/settings-store/settings-store-types");
25
+ const transactional_connection_1 = require("../../../connection/transactional-connection");
26
+ const settings_store_entry_entity_1 = require("../../../entity/settings-store-entry/settings-store-entry.entity");
27
+ /**
28
+ * @description
29
+ * The SettingsStoreService provides a flexible settings storage system with support for
30
+ * scoping, permissions, and validation. It allows plugins and the core system to
31
+ * store and retrieve configuration data with fine-grained control over access and isolation.
32
+ *
33
+ * ## Usage
34
+ *
35
+ * Values are automatically scoped according to their field configuration:
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * // In a service
40
+ * const userTheme = await this.settingsStoreService.get('dashboard.theme', ctx);
41
+ * await this.settingsStoreService.set('dashboard.theme', 'dark', ctx);
42
+ *
43
+ * // Get multiple values
44
+ * const settings = await this.settingsStoreService.getMany([
45
+ * 'dashboard.theme',
46
+ * 'dashboard.tableFilters'
47
+ * ], ctx);
48
+ * ```
49
+ *
50
+ * @docsCategory services
51
+ * @since 3.4.0
52
+ */
53
+ let SettingsStoreService = class SettingsStoreService {
54
+ constructor(connection, moduleRef, configService) {
55
+ this.connection = connection;
56
+ this.moduleRef = moduleRef;
57
+ this.configService = configService;
58
+ this.fieldRegistry = new Map();
59
+ this.injector = new injector_1.Injector(this.moduleRef);
60
+ }
61
+ onModuleInit() {
62
+ this.initializeFieldRegistrations();
63
+ }
64
+ /**
65
+ * @description
66
+ * Initialize field registrations from the Vendure configuration.
67
+ * Called during module initialization.
68
+ */
69
+ initializeFieldRegistrations() {
70
+ const settingsStoreFields = this.configService.settingsStoreFields || {};
71
+ for (const [namespace, fields] of Object.entries(settingsStoreFields)) {
72
+ this.register({ namespace, fields });
73
+ }
74
+ }
75
+ /**
76
+ * @description
77
+ * Register settings store fields. This is typically called during application
78
+ * bootstrap when processing the VendureConfig.
79
+ */
80
+ register(registration) {
81
+ for (const field of registration.fields) {
82
+ const fullKey = `${registration.namespace}.${field.name}`;
83
+ this.fieldRegistry.set(fullKey, field);
84
+ vendure_logger_1.Logger.debug(`Registered settings store field: ${fullKey}`);
85
+ }
86
+ }
87
+ /**
88
+ * @description
89
+ * Get a value for the specified key. The value is automatically scoped
90
+ * according to the field's scope configuration.
91
+ *
92
+ * @param key - The full key (namespace.field)
93
+ * @param ctx - Request context for scoping and permissions
94
+ * @returns The stored value or undefined if not found or access denied
95
+ */
96
+ async get(key, ctx) {
97
+ const fieldConfig = this.getFieldConfig(key);
98
+ if (!this.hasPermission(ctx, fieldConfig)) {
99
+ return undefined;
100
+ }
101
+ const scope = this.generateScope(key, undefined, ctx, fieldConfig);
102
+ const entry = await this.connection.getRepository(ctx, settings_store_entry_entity_1.SettingsStoreEntry).findOne({
103
+ where: { key, scope },
104
+ });
105
+ return entry === null || entry === void 0 ? void 0 : entry.value;
106
+ }
107
+ /**
108
+ * @description
109
+ * Get multiple values efficiently. Each key is scoped according to
110
+ * its individual field configuration.
111
+ *
112
+ * @param keys - Array of full keys to retrieve
113
+ * @param ctx - Request context for scoping and permissions
114
+ * @returns Object mapping keys to their values
115
+ */
116
+ async getMany(keys, ctx) {
117
+ const result = {};
118
+ // Build array of key/scopeKey pairs for authorized keys
119
+ const queries = [];
120
+ for (const key of keys) {
121
+ const fieldConfig = this.getFieldConfig(key);
122
+ if (this.hasPermission(ctx, fieldConfig)) {
123
+ const scope = this.generateScope(key, undefined, ctx, fieldConfig);
124
+ queries.push({ key, scope });
125
+ }
126
+ }
127
+ if (queries.length === 0) {
128
+ return result;
129
+ }
130
+ // Execute single query for all authorized keys using OR conditions
131
+ const qb = this.connection.getRepository(ctx, settings_store_entry_entity_1.SettingsStoreEntry).createQueryBuilder('entry');
132
+ // Build OR conditions for each key/scope pair
133
+ const orConditions = queries
134
+ .map((q, index) => `(entry.key = :key${index} AND entry.scope = :scope${index})`)
135
+ .join(' OR ');
136
+ if (orConditions) {
137
+ qb.where(orConditions);
138
+ // Add parameters
139
+ queries.forEach((q, index) => {
140
+ qb.setParameter(`key${index}`, q.key);
141
+ qb.setParameter(`scope${index}`, q.scope);
142
+ });
143
+ }
144
+ const entries = await qb.getMany();
145
+ // Map results back to keys
146
+ for (const entry of entries) {
147
+ result[entry.key] = entry.value;
148
+ }
149
+ return result;
150
+ }
151
+ /**
152
+ * @description
153
+ * Set a value for the specified key with structured result feedback.
154
+ * This version returns detailed information about the success or failure
155
+ * of the operation instead of throwing errors.
156
+ *
157
+ * @param key - The full key (namespace.field)
158
+ * @param value - The value to store (must be JSON serializable)
159
+ * @param ctx - Request context for scoping and permissions
160
+ * @returns SetSettingsStoreValueResult with operation status and error details
161
+ */
162
+ async set(key, value, ctx) {
163
+ try {
164
+ const fieldConfig = this.getFieldConfig(key);
165
+ if (!this.hasPermission(ctx, fieldConfig)) {
166
+ return {
167
+ key,
168
+ result: false,
169
+ error: 'Insufficient permissions to set settings store value',
170
+ };
171
+ }
172
+ if (fieldConfig.readonly) {
173
+ return {
174
+ key,
175
+ result: false,
176
+ error: 'Cannot modify readonly settings store field via API',
177
+ };
178
+ }
179
+ // Validate the value
180
+ await this.validateValue(key, value, ctx);
181
+ const scope = this.generateScope(key, value, ctx, fieldConfig);
182
+ const repo = this.connection.getRepository(ctx, settings_store_entry_entity_1.SettingsStoreEntry);
183
+ // Find existing entry or create new one
184
+ const entry = await repo.findOne({
185
+ where: { key, scope },
186
+ });
187
+ if (entry) {
188
+ entry.value = value;
189
+ await repo.save(entry);
190
+ }
191
+ else {
192
+ await repo.save({
193
+ key,
194
+ scope,
195
+ value,
196
+ });
197
+ }
198
+ return {
199
+ key,
200
+ result: true,
201
+ };
202
+ }
203
+ catch (error) {
204
+ return {
205
+ key,
206
+ result: false,
207
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
208
+ };
209
+ }
210
+ }
211
+ /**
212
+ * @description
213
+ * Set multiple values with structured result feedback for each operation.
214
+ * This method will not throw errors but will return
215
+ * detailed results for each key-value pair.
216
+ *
217
+ * @param values - Object mapping keys to their values
218
+ * @param ctx - Request context for scoping and permissions
219
+ * @returns Array of SetSettingsStoreValueResult with operation status for each key
220
+ */
221
+ async setMany(values, ctx) {
222
+ const results = [];
223
+ for (const [key, value] of Object.entries(values)) {
224
+ const result = await this.set(key, value, ctx);
225
+ results.push(result);
226
+ }
227
+ return results;
228
+ }
229
+ /**
230
+ * @description
231
+ * Get the field configuration for a key.
232
+ */
233
+ getFieldDefinition(key) {
234
+ return this.fieldRegistry.get(key);
235
+ }
236
+ /**
237
+ * @description
238
+ * Validate a value against its field definition.
239
+ */
240
+ async validateValue(key, value, ctx) {
241
+ const fieldConfig = this.fieldRegistry.get(key);
242
+ if (!(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.validate)) {
243
+ return;
244
+ }
245
+ const result = await fieldConfig.validate(value, this.injector, ctx);
246
+ if (typeof result === 'string') {
247
+ throw new errors_1.UserInputError(`Validation failed for ${key}: ${result}`);
248
+ }
249
+ if (Array.isArray(result)) {
250
+ throw new errors_1.UserInputError(`Validation failed for ${key}: ${JSON.stringify(result)}`);
251
+ }
252
+ }
253
+ /**
254
+ * @description
255
+ * Generate the scope key for a given field and context.
256
+ */
257
+ generateScope(key, value, ctx, fieldConfig) {
258
+ const scopeFunction = fieldConfig.scope || settings_store_types_1.SettingsStoreScopes.global;
259
+ return scopeFunction({ key, value, ctx });
260
+ }
261
+ /**
262
+ * @description
263
+ * Get field configuration, throwing if not found.
264
+ */
265
+ getFieldConfig(key) {
266
+ const config = this.fieldRegistry.get(key);
267
+ if (!config) {
268
+ throw new errors_1.InternalServerError(`Settings store field not registered: ${key}`);
269
+ }
270
+ return config;
271
+ }
272
+ /**
273
+ * @description
274
+ * Find orphaned settings store entries that no longer have corresponding field definitions.
275
+ *
276
+ * @param options - Options for filtering orphaned entries
277
+ * @returns Array of orphaned entries
278
+ */
279
+ async findOrphanedEntries(options = {}) {
280
+ const { olderThan = '7d', maxDeleteCount = 1000 } = options;
281
+ // Parse duration to get cutoff date
282
+ const cutoffDate = this.parseDuration(olderThan);
283
+ const qb = this.connection.rawConnection
284
+ .getRepository(settings_store_entry_entity_1.SettingsStoreEntry)
285
+ .createQueryBuilder('entry')
286
+ .where('entry.updatedAt < :cutoffDate', { cutoffDate })
287
+ .orderBy('entry.updatedAt', 'ASC')
288
+ .limit(maxDeleteCount);
289
+ const allEntries = await qb.getMany();
290
+ const orphanedEntries = [];
291
+ // Check each entry against registered fields
292
+ for (const entry of allEntries) {
293
+ const fieldConfig = this.fieldRegistry.get(entry.key);
294
+ if (!fieldConfig) {
295
+ // This entry has no field definition - it's orphaned
296
+ orphanedEntries.push({
297
+ key: entry.key,
298
+ scope: entry.scope || '',
299
+ updatedAt: entry.updatedAt,
300
+ valuePreview: this.getValuePreview(entry.value),
301
+ });
302
+ }
303
+ }
304
+ return orphanedEntries;
305
+ }
306
+ /**
307
+ * @description
308
+ * Clean up orphaned settings store entries from the database.
309
+ *
310
+ * @param options - Options for the cleanup operation
311
+ * @returns Result of the cleanup operation
312
+ */
313
+ async cleanupOrphanedEntries(options = {}) {
314
+ const { dryRun = false, batchSize = 100, maxDeleteCount = 1000 } = options;
315
+ // Find orphaned entries first
316
+ const orphanedEntries = await this.findOrphanedEntries(options);
317
+ if (dryRun) {
318
+ return {
319
+ deletedCount: orphanedEntries.length,
320
+ dryRun: true,
321
+ deletedEntries: orphanedEntries.slice(0, 10), // Sample for preview
322
+ };
323
+ }
324
+ let totalDeleted = 0;
325
+ const sampleDeletedEntries = [];
326
+ // Delete in batches
327
+ for (let i = 0; i < orphanedEntries.length && totalDeleted < maxDeleteCount; i += batchSize) {
328
+ const batch = orphanedEntries.slice(i, i + batchSize);
329
+ // Extract keys and scopes for deletion
330
+ const conditions = batch.map(entry => ({ key: entry.key, scope: entry.scope }));
331
+ await this.connection.rawConnection.getRepository(settings_store_entry_entity_1.SettingsStoreEntry).delete(conditions);
332
+ totalDeleted += batch.length;
333
+ // Keep first batch as sample
334
+ if (i === 0) {
335
+ sampleDeletedEntries.push(...batch.slice(0, 10));
336
+ }
337
+ vendure_logger_1.Logger.verbose(`Deleted batch of ${batch.length} orphaned settings store entries`);
338
+ }
339
+ vendure_logger_1.Logger.info(`Cleanup completed: deleted ${totalDeleted} orphaned settings store entries`);
340
+ return {
341
+ deletedCount: totalDeleted,
342
+ dryRun: false,
343
+ deletedEntries: sampleDeletedEntries,
344
+ };
345
+ }
346
+ /**
347
+ * @description
348
+ * Parse a duration string (e.g., '7d', '30m', '2h') into a Date object.
349
+ */
350
+ parseDuration(duration) {
351
+ const milliseconds = (0, ms_1.default)(duration);
352
+ if (!milliseconds) {
353
+ throw new Error(`Invalid duration format: ${duration}. Use format like '7d', '2h', '30m'`);
354
+ }
355
+ return new Date(Date.now() - milliseconds);
356
+ }
357
+ /**
358
+ * @description
359
+ * Get a preview of a value for logging purposes, truncating if too large.
360
+ */
361
+ getValuePreview(value) {
362
+ const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
363
+ return stringValue.length > 100 ? stringValue.substring(0, 100) + '...' : stringValue;
364
+ }
365
+ /**
366
+ * @description
367
+ * Check if the current user has permission to access a field.
368
+ */
369
+ hasPermission(ctx, fieldConfig) {
370
+ // Admin API: check required permissions
371
+ const requiredPermissions = fieldConfig.requiresPermission;
372
+ if (requiredPermissions) {
373
+ const permissions = Array.isArray(requiredPermissions)
374
+ ? requiredPermissions
375
+ : [requiredPermissions];
376
+ return ctx.userHasPermissions(permissions);
377
+ }
378
+ // Default: require authentication
379
+ return ctx.userHasPermissions([generated_types_1.Permission.Authenticated]);
380
+ }
381
+ };
382
+ exports.SettingsStoreService = SettingsStoreService;
383
+ exports.SettingsStoreService = SettingsStoreService = __decorate([
384
+ (0, common_1.Injectable)(),
385
+ __metadata("design:paramtypes", [transactional_connection_1.TransactionalConnection,
386
+ core_1.ModuleRef,
387
+ config_service_1.ConfigService])
388
+ ], SettingsStoreService);
389
+ //# sourceMappingURL=settings-store.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-store.service.js","sourceRoot":"","sources":["../../../../src/service/helpers/settings-store/settings-store.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0D;AAC1D,uCAAyC;AACzC,yEAAiE;AAEjE,4CAAoB;AAGpB,yDAAmF;AACnF,uDAAoD;AACpD,mEAA+D;AAC/D,0EAA+D;AAC/D,8FAQ6D;AAC7D,2FAAuF;AACvF,kHAAsG;AAEtG;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAI7B,YACqB,UAAmC,EACnC,SAAoB,EACpB,aAA4B;QAF5B,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C,CAAC;YAC5B,OAAO,GAAG,CAAC,kBAAkB,CAAC,WAAkB,CAAC,CAAC;QACtD,CAAC;QAED,kCAAkC;QAClC,OAAO,GAAG,CAAC,kBAAkB,CAAC,CAAC,4BAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9D,CAAC;CACJ,CAAA;AApZY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAMwB,kDAAuB;QACxB,gBAAS;QACL,8BAAa;GAPxC,oBAAoB,CAoZhC"}
@@ -21,6 +21,7 @@ export * from './helpers/payment-state-machine/payment-state';
21
21
  export * from './helpers/product-price-applicator/product-price-applicator';
22
22
  export * from './helpers/refund-state-machine/refund-state';
23
23
  export * from './helpers/request-context/request-context.service';
24
+ export * from './helpers/settings-store/settings-store.service';
24
25
  export * from './helpers/translatable-saver/translatable-saver';
25
26
  export * from './helpers/translator/translator.service';
26
27
  export * from './helpers/utils/order-utils';
@@ -37,6 +37,7 @@ __exportStar(require("./helpers/payment-state-machine/payment-state"), exports);
37
37
  __exportStar(require("./helpers/product-price-applicator/product-price-applicator"), exports);
38
38
  __exportStar(require("./helpers/refund-state-machine/refund-state"), exports);
39
39
  __exportStar(require("./helpers/request-context/request-context.service"), exports);
40
+ __exportStar(require("./helpers/settings-store/settings-store.service"), exports);
40
41
  __exportStar(require("./helpers/translatable-saver/translatable-saver"), exports);
41
42
  __exportStar(require("./helpers/translator/translator.service"), exports);
42
43
  __exportStar(require("./helpers/utils/order-utils"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA4D;AAC5D,0EAAwD;AACxD,gGAA8E;AAC9E,wFAAsE;AACtE,oFAAkE;AAClE,uEAAqD;AACrD,oGAAkF;AAClF,oFAAkE;AAClE,wFAAsE;AACtE,kFAAgE;AAChE,0FAAwE;AACxE,8EAA4D;AAC5D,qEAAmD;AACnD,sEAAoD;AACpD,0EAAwD;AACxD,0EAAwD;AACxD,4EAA0D;AAC1D,oFAAkE;AAClE,4EAA0D;AAC1D,gFAA8D;AAC9D,8FAA4E;AAC5E,8EAA4D;AAC5D,oFAAkE;AAClE,kFAAgE;AAChE,0EAAwD;AACxD,8DAA4C;AAC5C,+DAA6C;AAC7C,mEAAiD;AACjD,sGAAoF;AACpF,mEAAiD;AACjD,2DAAyC;AACzC,0DAAwC;AACxC,6DAA2C;AAC3C,gEAA8C;AAC9C,6DAA2C;AAC3C,oEAAkD;AAClD,8DAA4C;AAC5C,iEAA+C;AAC/C,2DAAyC;AACzC,iEAA+C;AAC/C,qEAAmD;AACnD,6DAA2C;AAC3C,mEAAiD;AACjD,2DAAyC;AACzC,oEAAkD;AAClD,6DAA2C;AAC3C,0EAAwD;AACxD,oEAAkD;AAClD,qEAAmD;AACnD,6DAA2C;AAC3C,+DAA6C;AAC7C,0DAAwC;AACxC,4DAA0C;AAC1C,4DAA0C;AAC1C,6DAA2C;AAC3C,qEAAmD;AACnD,iEAA+C;AAC/C,oEAAkD;AAClD,oEAAkD;AAClD,yDAAuC;AACvC,kEAAgD;AAChD,8DAA4C;AAC5C,0DAAwC;AACxC,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA4D;AAC5D,0EAAwD;AACxD,gGAA8E;AAC9E,wFAAsE;AACtE,oFAAkE;AAClE,uEAAqD;AACrD,oGAAkF;AAClF,oFAAkE;AAClE,wFAAsE;AACtE,kFAAgE;AAChE,0FAAwE;AACxE,8EAA4D;AAC5D,qEAAmD;AACnD,sEAAoD;AACpD,0EAAwD;AACxD,0EAAwD;AACxD,4EAA0D;AAC1D,oFAAkE;AAClE,4EAA0D;AAC1D,gFAA8D;AAC9D,8FAA4E;AAC5E,8EAA4D;AAC5D,oFAAkE;AAClE,kFAAgE;AAChE,kFAAgE;AAChE,0EAAwD;AACxD,8DAA4C;AAC5C,+DAA6C;AAC7C,mEAAiD;AACjD,sGAAoF;AACpF,mEAAiD;AACjD,2DAAyC;AACzC,0DAAwC;AACxC,6DAA2C;AAC3C,gEAA8C;AAC9C,6DAA2C;AAC3C,oEAAkD;AAClD,8DAA4C;AAC5C,iEAA+C;AAC/C,2DAAyC;AACzC,iEAA+C;AAC/C,qEAAmD;AACnD,6DAA2C;AAC3C,mEAAiD;AACjD,2DAAyC;AACzC,oEAAkD;AAClD,6DAA2C;AAC3C,0EAAwD;AACxD,oEAAkD;AAClD,qEAAmD;AACnD,6DAA2C;AAC3C,+DAA6C;AAC7C,0DAAwC;AACxC,4DAA0C;AAC1C,4DAA0C;AAC1C,6DAA2C;AAC3C,qEAAmD;AACnD,iEAA+C;AAC/C,oEAAkD;AAClD,oEAAkD;AAClD,yDAAuC;AACvC,kEAAgD;AAChD,8DAA4C;AAC5C,0DAAwC;AACxC,0DAAwC"}
@@ -34,6 +34,7 @@ const payment_state_machine_1 = require("./helpers/payment-state-machine/payment
34
34
  const product_price_applicator_1 = require("./helpers/product-price-applicator/product-price-applicator");
35
35
  const refund_state_machine_1 = require("./helpers/refund-state-machine/refund-state-machine");
36
36
  const request_context_service_1 = require("./helpers/request-context/request-context.service");
37
+ const settings_store_service_1 = require("./helpers/settings-store/settings-store.service");
37
38
  const shipping_calculator_1 = require("./helpers/shipping-calculator/shipping-calculator");
38
39
  const slug_validator_1 = require("./helpers/slug-validator/slug-validator");
39
40
  const translatable_saver_1 = require("./helpers/translatable-saver/translatable-saver");
@@ -138,6 +139,7 @@ const helpers = [
138
139
  translator_service_1.TranslatorService,
139
140
  entity_duplicator_service_1.EntityDuplicatorService,
140
141
  facet_value_checker_1.FacetValueChecker,
142
+ settings_store_service_1.SettingsStoreService,
141
143
  ];
142
144
  /**
143
145
  * The ServiceCoreModule is imported internally by the ServiceModule. It is arranged in this way so that
@@ -1 +1 @@
1
- {"version":3,"file":"service.module.js","sourceRoot":"","sources":["../../src/service/service.module.ts"],"names":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BAAiB,CAAC;QAC5B,OAAO,EAAE,CAAC,iBAAiB,CAAC;KAC/B,CAAC;GACW,aAAa,CAAG"}
1
+ {"version":3,"file":"service.module.js","sourceRoot":"","sources":["../../src/service/service.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AAExC,wDAAoD;AACpD,2DAAuD;AACvD,uEAAmE;AACnE,oEAA+D;AAC/D,oEAA+D;AAC/D,oEAAgE;AAEhE,sFAAiF;AACjF,gFAA2E;AAC3E,iHAA2G;AAC3G,qGAAgG;AAChG,+FAAmF;AACnF,uHAAkH;AAClH,2FAAsF;AACtF,6GAAwG;AACxG,wFAAmF;AACnF,oGAA+F;AAC/F,kFAA8E;AAC9E,sEAAkE;AAClE,4EAAwE;AACxE,4EAAwE;AACxE,2FAAsF;AACtF,+EAA2E;AAC3E,iGAA4F;AAC5F,0GAAqG;AACrG,8FAAyF;AACzF,+FAA0F;AAC1F,4FAAuF;AACvF,2FAAuF;AACvF,4EAAwE;AACxE,wFAAoF;AACpF,gFAA4E;AAC5E,sHAAiH;AACjH,+DAA2D;AAC3D,4EAAwE;AACxE,4DAAwD;AACxD,0DAAsD;AACtD,gEAA4D;AAC5D,sEAAkE;AAClE,gEAA4D;AAC5D,8EAAyE;AACzE,kEAA8D;AAC9D,wEAAmE;AACnE,4DAAwD;AACxD,wEAAoE;AACpE,gFAA2E;AAC3E,gEAA4D;AAC5D,4EAAuE;AACvE,4DAAwD;AACxD,8EAAyE;AACzE,gEAA4D;AAC5D,0FAAoF;AACpF,8EAAyE;AACzE,gFAA2E;AAC3E,gEAA4D;AAC5D,oEAAgE;AAChE,0DAAsD;AACtD,8DAA0D;AAC1D,8DAA0D;AAC1D,gEAA4D;AAC5D,gFAA2E;AAC3E,wEAAmE;AACnE,8EAAyE;AACzE,8EAAyE;AACzE,wDAAoD;AACpD,0EAAqE;AACrE,kEAA6D;AAC7D,0DAAsD;AACtD,0DAAsD;AAEtD,MAAM,QAAQ,GAAG;IACb,4CAAoB;I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C,CAAC;GACW,iBAAiB,CAAG;AAEjC;;;;;;GAMG;AAKI,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAJzB,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,iBAAiB,CAAC;QAC5B,OAAO,EAAE,CAAC,iBAAiB,CAAC;KAC/B,CAAC;GACW,aAAa,CAAG"}
@@ -379,7 +379,7 @@ let OrderService = class OrderService {
379
379
  order = (0, patch_entity_1.patchEntity)(order, { customFields });
380
380
  const updatedOrder = await this.connection.getRepository(ctx, order_entity_1.Order).save(order);
381
381
  await this.customFieldRelationService.updateRelations(ctx, order_entity_1.Order, { customFields }, updatedOrder);
382
- await this.eventBus.publish(new order_event_1.OrderEvent(ctx, updatedOrder, 'updated'));
382
+ await this.eventBus.publish(new order_event_1.OrderEvent(ctx, updatedOrder, 'updated', { customFields }));
383
383
  return updatedOrder;
384
384
  }
385
385
  /**
@@ -410,7 +410,7 @@ let OrderService = class OrderService {
410
410
  });
411
411
  }
412
412
  const updatedOrder = await this.addCustomerToOrder(ctx, order.id, targetCustomer);
413
- await this.eventBus.publish(new order_event_1.OrderEvent(ctx, updatedOrder, 'updated'));
413
+ await this.eventBus.publish(new order_event_1.OrderEvent(ctx, updatedOrder, 'updated', targetCustomer));
414
414
  await this.historyService.createHistoryEntryForOrder({
415
415
  ctx,
416
416
  orderId,
@@ -585,8 +585,19 @@ let OrderService = class OrderService {
585
585
  }
586
586
  }
587
587
  if (customFields != null) {
588
- orderLine.customFields = customFields;
589
- await this.customFieldRelationService.updateRelations(ctx, order_line_entity_1.OrderLine, { customFields }, orderLine);
588
+ // Merge custom fields instead of replacing them entirely
589
+ // This preserves existing values while allowing updates and null-based unsetting
590
+ const existingCustomFields = orderLine.customFields || {};
591
+ const mergedCustomFields = Object.assign({}, existingCustomFields);
592
+ for (const [key, value] of Object.entries(customFields)) {
593
+ if (value !== undefined) {
594
+ // Update with the new value (including explicit null to unset)
595
+ mergedCustomFields[key] = value;
596
+ }
597
+ // If value is undefined, preserve the existing value (don't set it)
598
+ }
599
+ orderLine.customFields = mergedCustomFields;
600
+ await this.customFieldRelationService.updateRelations(ctx, order_line_entity_1.OrderLine, { customFields: mergedCustomFields }, orderLine);
590
601
  }
591
602
  const existingQuantityInOtherLines = (0, shared_utils_1.summate)(order.lines.filter(l => (0, utils_1.idsAreEqual)(l.productVariantId, orderLine.productVariantId) &&
592
603
  !(0, utils_1.idsAreEqual)(l.id, orderLineId)), 'quantity');