@unchainedshop/core-assortments 4.4.0 → 4.6.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.
@@ -7,5 +7,5 @@ export interface AssortmentsSettings {
7
7
  getCachedProductIds: (assortmentId: string) => Promise<string[] | undefined>;
8
8
  configureSettings: (options: AssortmentsSettingsOptions, db: mongodb.Db) => void;
9
9
  }
10
- export type AssortmentsSettingsOptions = Partial<Omit<AssortmentsSettings, 'configureSettings'>>;
10
+ export type AssortmentsSettingsOptions = Omit<Partial<AssortmentsSettings>, 'configureSettings'>;
11
11
  export declare const assortmentsSettings: AssortmentsSettings;
@@ -39,7 +39,6 @@ export type AssortmentFilter = {
39
39
  export type Assortment = {
40
40
  _id: string;
41
41
  isActive: boolean;
42
- isBase: boolean;
43
42
  isRoot: boolean;
44
43
  meta?: any;
45
44
  sequence: number;
@@ -17,6 +17,7 @@ export const AssortmentsCollection = async (db) => {
17
17
  ]);
18
18
  }
19
19
  await buildDbIndexes(Assortments, [
20
+ { index: { deleted: 1 } },
20
21
  { index: { isActive: 1 } },
21
22
  { index: { isRoot: 1 } },
22
23
  { index: { sequence: 1 } },
@@ -4,8 +4,9 @@ export declare const configureAssortmentMediaModule: ({ db }: ModuleInput<Record
4
4
  findAssortmentMedia: ({ assortmentMediaId }: {
5
5
  assortmentMediaId: string;
6
6
  }) => Promise<mongodb.WithId<AssortmentMediaType> | null>;
7
- findAssortmentMedias: ({ assortmentId, tags, offset, limit, }: {
8
- assortmentId?: mongodb.Filter<AssortmentMediaType>["assortmentId"];
7
+ findAssortmentMedias: ({ assortmentId, assortmentIds, tags, offset, limit, }: {
8
+ assortmentId?: string;
9
+ assortmentIds?: string[];
9
10
  limit?: number;
10
11
  offset?: number;
11
12
  tags?: string[];
@@ -25,7 +26,10 @@ export declare const configureAssortmentMediaModule: ({ db }: ModuleInput<Record
25
26
  }[];
26
27
  }) => Promise<AssortmentMediaType[]>;
27
28
  texts: {
28
- findMediaTexts: ({ assortmentMediaId }: mongodb.Filter<AssortmentMediaText>, options?: mongodb.FindOptions) => Promise<AssortmentMediaText[]>;
29
+ findMediaTexts: (query: {
30
+ assortmentMediaId?: string;
31
+ assortmentMediaIds?: string[];
32
+ }, options?: mongodb.FindOptions) => Promise<AssortmentMediaText[]>;
29
33
  findLocalizedMediaText: ({ assortmentMediaId, locale, }: {
30
34
  assortmentMediaId: string;
31
35
  locale: Intl.Locale;
@@ -40,8 +40,14 @@ export const configureAssortmentMediaModule = async ({ db }) => {
40
40
  findAssortmentMedia: async ({ assortmentMediaId }) => {
41
41
  return AssortmentMedia.findOne(generateDbFilterById(assortmentMediaId), {});
42
42
  },
43
- findAssortmentMedias: async ({ assortmentId, tags, offset, limit, }, options) => {
44
- const selector = assortmentId ? { assortmentId } : {};
43
+ findAssortmentMedias: async ({ assortmentId, assortmentIds, tags, offset, limit, }, options) => {
44
+ const selector = {};
45
+ if (assortmentId) {
46
+ selector.assortmentId = assortmentId;
47
+ }
48
+ if (assortmentIds) {
49
+ selector.assortmentId = { $in: assortmentIds };
50
+ }
45
51
  if (tags && tags.length > 0) {
46
52
  selector.tags = { $all: tags };
47
53
  }
@@ -126,8 +132,15 @@ export const configureAssortmentMediaModule = async ({ db }) => {
126
132
  return assortmentMedias;
127
133
  },
128
134
  texts: {
129
- findMediaTexts: async ({ assortmentMediaId }, options) => {
130
- return AssortmentMediaTexts.find({ assortmentMediaId }, options).toArray();
135
+ findMediaTexts: async (query, options) => {
136
+ const selector = {};
137
+ if (query.assortmentMediaId) {
138
+ selector.assortmentMediaId = query.assortmentMediaId;
139
+ }
140
+ if (query.assortmentMediaIds) {
141
+ selector.assortmentMediaId = { $in: query.assortmentMediaIds };
142
+ }
143
+ return AssortmentMediaTexts.find(selector, options).toArray();
131
144
  },
132
145
  findLocalizedMediaText: async ({ assortmentMediaId, locale, }) => {
133
146
  const text = await findLocalizedText(AssortmentMediaTexts, { assortmentMediaId }, locale);
@@ -4,7 +4,11 @@ export declare const configureAssortmentTextsModule: ({ Assortments, AssortmentT
4
4
  Assortments: mongodb.Collection<Assortment>;
5
5
  AssortmentTexts: mongodb.Collection<AssortmentText>;
6
6
  }) => {
7
- findTexts: (query: mongodb.Filter<AssortmentText>, options?: mongodb.FindOptions) => Promise<AssortmentText[]>;
7
+ findTexts: (query: {
8
+ assortmentId?: string;
9
+ assortmentIds?: string[];
10
+ queryString?: string;
11
+ }, options?: mongodb.FindOptions) => Promise<AssortmentText[]>;
8
12
  findLocalizedText: ({ assortmentId, locale, }: {
9
13
  assortmentId: string;
10
14
  locale: Intl.Locale;
@@ -74,7 +74,17 @@ export const configureAssortmentTextsModule = ({ Assortments, AssortmentTexts, }
74
74
  };
75
75
  return {
76
76
  findTexts: async (query, options) => {
77
- const texts = AssortmentTexts.find(query, options);
77
+ const selector = {};
78
+ if (query.assortmentId) {
79
+ selector.assortmentId = query.assortmentId;
80
+ }
81
+ if (query.assortmentIds) {
82
+ selector.assortmentId = { $in: query.assortmentIds };
83
+ }
84
+ if (query.queryString) {
85
+ selector.$text = { $search: query.queryString };
86
+ }
87
+ const texts = AssortmentTexts.find(selector, options);
78
88
  return texts.toArray();
79
89
  },
80
90
  findLocalizedText: async ({ assortmentId, locale, }) => {
@@ -44,7 +44,7 @@ export declare const configureAssortmentsModule: (moduleInput: ModuleInput<Assor
44
44
  }) => Promise<{
45
45
  links: AssortmentPathLink[];
46
46
  }[]>;
47
- create: ({ _id, isActive, isBase, isRoot, meta, sequence, ...rest }: Omit<Assortment, "_id" | "created"> & Pick<Partial<Assortment>, "_id">) => Promise<Assortment>;
47
+ create: ({ _id, isActive, isRoot, meta, sequence, ...rest }: Omit<Assortment, "_id" | "created"> & Pick<Partial<Assortment>, "_id">) => Promise<Assortment>;
48
48
  update: (assortmentId: string, doc: Partial<Assortment>, options?: {
49
49
  skipInvalidation?: boolean;
50
50
  }) => Promise<mongodb.WithId<Assortment> | null>;
@@ -52,7 +52,6 @@ export declare const configureAssortmentsModule: (moduleInput: ModuleInput<Assor
52
52
  skipInvalidation?: boolean;
53
53
  }) => Promise<mongodb.WithId<Assortment> | null>;
54
54
  invalidateCache: InvalidateCacheFn;
55
- setBase: (assortmentId: string) => Promise<void>;
56
55
  search: {
57
56
  findFilteredAssortments: ({ limit, offset, assortmentIds, assortmentSelector, sort, }: {
58
57
  assortmentIds: string[];
@@ -66,8 +65,9 @@ export declare const configureAssortmentsModule: (moduleInput: ModuleInput<Assor
66
65
  findAssortmentMedia: ({ assortmentMediaId }: {
67
66
  assortmentMediaId: string;
68
67
  }) => Promise<mongodb.WithId<import("../assortments-index.ts").AssortmentMediaType> | null>;
69
- findAssortmentMedias: ({ assortmentId, tags, offset, limit, }: {
70
- assortmentId?: mongodb.Filter<import("../assortments-index.ts").AssortmentMediaType>["assortmentId"];
68
+ findAssortmentMedias: ({ assortmentId, assortmentIds, tags, offset, limit, }: {
69
+ assortmentId?: string;
70
+ assortmentIds?: string[];
71
71
  limit?: number;
72
72
  offset?: number;
73
73
  tags?: string[];
@@ -87,7 +87,10 @@ export declare const configureAssortmentsModule: (moduleInput: ModuleInput<Assor
87
87
  }[];
88
88
  }) => Promise<import("../assortments-index.ts").AssortmentMediaType[]>;
89
89
  texts: {
90
- findMediaTexts: ({ assortmentMediaId }: mongodb.Filter<import("../assortments-index.ts").AssortmentMediaText>, options?: mongodb.FindOptions) => Promise<import("../assortments-index.ts").AssortmentMediaText[]>;
90
+ findMediaTexts: (query: {
91
+ assortmentMediaId?: string;
92
+ assortmentMediaIds?: string[];
93
+ }, options?: mongodb.FindOptions) => Promise<import("../assortments-index.ts").AssortmentMediaText[]>;
91
94
  findLocalizedMediaText: ({ assortmentMediaId, locale, }: {
92
95
  assortmentMediaId: string;
93
96
  locale: Intl.Locale;
@@ -201,7 +204,11 @@ export declare const configureAssortmentsModule: (moduleInput: ModuleInput<Assor
201
204
  }) => Promise<AssortmentProduct[]>;
202
205
  };
203
206
  texts: {
204
- findTexts: (query: mongodb.Filter<import("../db/AssortmentsCollection.ts").AssortmentText>, options?: mongodb.FindOptions) => Promise<import("../db/AssortmentsCollection.ts").AssortmentText[]>;
207
+ findTexts: (query: {
208
+ assortmentId?: string;
209
+ assortmentIds?: string[];
210
+ queryString?: string;
211
+ }, options?: mongodb.FindOptions) => Promise<import("../db/AssortmentsCollection.ts").AssortmentText[]>;
205
212
  findLocalizedText: ({ assortmentId, locale, }: {
206
213
  assortmentId: string;
207
214
  locale: Intl.Locale;
@@ -11,12 +11,7 @@ import { configureAssortmentTextsModule } from "./configureAssortmentTextsModule
11
11
  import { configureAssortmentMediaModule } from "./configureAssortmentMediaModule.js";
12
12
  import { makeAssortmentBreadcrumbsBuilder } from "../utils/breadcrumbs/makeAssortmentBreadcrumbsBuilder.js";
13
13
  const logger = createLogger('unchained:core');
14
- const ASSORTMENT_EVENTS = [
15
- 'ASSORTMENT_CREATE',
16
- 'ASSORTMENT_REMOVE',
17
- 'ASSORTMENT_SET_BASE',
18
- 'ASSORTMENT_UPDATE',
19
- ];
14
+ const ASSORTMENT_EVENTS = ['ASSORTMENT_CREATE', 'ASSORTMENT_REMOVE', 'ASSORTMENT_UPDATE'];
20
15
  export const buildFindSelector = ({ assortmentIds, assortmentSelector, slugs, tags, includeLeaves = false, includeInactive = false, queryString, }) => {
21
16
  const selector = assortmentSelector || {};
22
17
  selector.deleted = null;
@@ -202,14 +197,13 @@ export const configureAssortmentsModule = async (moduleInput) => {
202
197
  });
203
198
  return buildBreadcrumbs(params);
204
199
  },
205
- create: async ({ _id, isActive = true, isBase = false, isRoot = false, meta = {}, sequence, ...rest }) => {
200
+ create: async ({ _id, isActive = true, isRoot = false, meta = {}, sequence, ...rest }) => {
206
201
  if (_id)
207
202
  await Assortments.deleteOne({ _id, deleted: { $ne: null } });
208
203
  const { insertedId: assortmentId } = await Assortments.insertOne({
209
204
  _id: _id || generateDbObjectId(),
210
205
  created: new Date(),
211
206
  sequence: sequence || (await Assortments.countDocuments({})) + 10,
212
- isBase,
213
207
  isActive,
214
208
  isRoot,
215
209
  meta,
@@ -256,21 +250,6 @@ export const configureAssortmentsModule = async (moduleInput) => {
256
250
  return deletedAssortment;
257
251
  },
258
252
  invalidateCache,
259
- setBase: async (assortmentId) => {
260
- await Assortments.updateMany({ isBase: true }, {
261
- $set: {
262
- isBase: false,
263
- updated: new Date(),
264
- },
265
- });
266
- await Assortments.updateOne(generateDbFilterById(assortmentId), {
267
- $set: {
268
- isBase: true,
269
- updated: new Date(),
270
- },
271
- });
272
- await emit('ASSORTMENT_SET_BASE', { assortmentId });
273
- },
274
253
  search: {
275
254
  findFilteredAssortments: async ({ limit, offset, assortmentIds, assortmentSelector, sort, }) => {
276
255
  const assortments = await findPreservingIds(Assortments)(assortmentSelector, assortmentIds, {
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-assortments",
3
- "version": "4.4.0",
3
+ "description": "Assortment and category management module for the Unchained Engine",
4
+ "version": "4.6.0",
4
5
  "main": "lib/assortments-index.js",
5
6
  "types": "lib/assortments-index.d.ts",
6
7
  "type": "module",
@@ -34,10 +35,10 @@
34
35
  },
35
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
36
37
  "dependencies": {
37
- "@unchainedshop/events": "^4.4.0",
38
- "@unchainedshop/file-upload": "^4.4.0",
39
- "@unchainedshop/logger": "^4.4.0",
40
- "@unchainedshop/utils": "^4.4.0"
38
+ "@unchainedshop/events": "^4.6.0",
39
+ "@unchainedshop/file-upload": "^4.6.0",
40
+ "@unchainedshop/logger": "^4.6.0",
41
+ "@unchainedshop/utils": "^4.6.0"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@types/node": "^25.0.0",