@unchainedshop/core 4.8.25 → 4.8.27

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.
@@ -15,7 +15,7 @@ export declare const ProductCreateSpecificationSchema: z.ZodMiniObject<{
15
15
  readonly ACTIVE: "ACTIVE";
16
16
  readonly DELETED: "DELETED";
17
17
  }>>>;
18
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
18
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
19
19
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
20
20
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
21
21
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -76,7 +76,7 @@ export declare const ProductCreatePayloadSchema: z.ZodMiniObject<{
76
76
  readonly ACTIVE: "ACTIVE";
77
77
  readonly DELETED: "DELETED";
78
78
  }>>>;
79
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
79
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
80
80
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
81
81
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
82
82
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -183,7 +183,7 @@ declare namespace createProduct {
183
183
  readonly ACTIVE: "ACTIVE";
184
184
  readonly DELETED: "DELETED";
185
185
  }>>>;
186
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
186
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
187
187
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
188
188
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
189
189
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -8,7 +8,7 @@ export const ProductCreateSpecificationSchema = z.object({
8
8
  type: z.enum(ProductType),
9
9
  sequence: z.optional(z.number()),
10
10
  status: z.nullish(z.enum(ProductStatus)),
11
- published: z.nullish(z.iso.datetime()),
11
+ published: z.nullish(z.string().check(z.refine((value) => !Number.isNaN(new Date(value).getTime()), 'Invalid date'))),
12
12
  tags: z.optional(z.array(z.string())),
13
13
  commerce: z.optional(z.object({
14
14
  pricing: z.array(z.object({
@@ -9,7 +9,7 @@ export declare const ProductUpdateSpecificationSchema: z.ZodMiniObject<{
9
9
  readonly ACTIVE: "ACTIVE";
10
10
  readonly DELETED: "DELETED";
11
11
  }>>>;
12
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
12
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
13
13
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
14
14
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
15
15
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -64,7 +64,7 @@ export declare const ProductUpdatePayloadSchema: z.ZodMiniObject<{
64
64
  readonly ACTIVE: "ACTIVE";
65
65
  readonly DELETED: "DELETED";
66
66
  }>>>;
67
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
67
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
68
68
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
69
69
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
70
70
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -165,7 +165,7 @@ declare namespace updateProduct {
165
165
  readonly ACTIVE: "ACTIVE";
166
166
  readonly DELETED: "DELETED";
167
167
  }>>>;
168
- published: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
168
+ published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
169
169
  tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
170
170
  commerce: z.ZodMiniOptional<z.ZodMiniObject<{
171
171
  pricing: z.ZodMiniArray<z.ZodMiniObject<{
@@ -8,7 +8,7 @@ export const ProductUpdateSpecificationSchema = z.object({
8
8
  type: z.optional(z.string()),
9
9
  sequence: z.optional(z.number()),
10
10
  status: z.nullish(z.enum(ProductStatus)),
11
- published: z.nullish(z.iso.datetime()),
11
+ published: z.nullish(z.string().check(z.refine((value) => !Number.isNaN(new Date(value).getTime()), 'Invalid date'))),
12
12
  tags: z.optional(z.array(z.string())),
13
13
  commerce: z.optional(z.object({
14
14
  pricing: z.array(z.object({
@@ -18,6 +18,12 @@ export type IWorkerDirector = IBaseDirector<IWorkerAdapter<any, any>> & {
18
18
  configureAutoscheduling: (workScheduleConfiguration: WorkScheduleConfiguration) => void;
19
19
  getAutoSchedules: () => [string, WorkScheduleConfiguration][];
20
20
  doWork: (work: Work, unchainedAPI: any) => Promise<WorkResult>;
21
+ allocateWork: (unchainedAPI: {
22
+ modules: Modules;
23
+ }, options?: {
24
+ types?: string[] | null;
25
+ worker?: string;
26
+ }) => Promise<Work | null>;
21
27
  processNextWork: (unchainedAPI: {
22
28
  modules: Modules;
23
29
  }, workerId?: string) => Promise<Work | null>;
@@ -64,22 +64,34 @@ export const WorkerDirector = {
64
64
  return errorOutput;
65
65
  }
66
66
  },
67
+ allocateWork: async (unchainedAPI, { types: requestedTypes, worker = unchainedAPI.modules.worker.workerId } = {}) => {
68
+ const lock = await unchainedAPI.modules.orders.acquireLock('allocation', 'worker');
69
+ try {
70
+ const adapters = WorkerDirector.getAdapters();
71
+ const allocationMap = await unchainedAPI.modules.worker.allocationMap();
72
+ const types = adapters
73
+ .filter((adapter) => {
74
+ if (requestedTypes && !requestedTypes.includes(adapter.type))
75
+ return false;
76
+ if (adapter.maxParallelAllocations &&
77
+ adapter.maxParallelAllocations <= allocationMap[adapter.type])
78
+ return false;
79
+ return true;
80
+ })
81
+ .map((adapter) => adapter.type);
82
+ return await unchainedAPI.modules.worker.allocateWork({
83
+ types,
84
+ worker,
85
+ });
86
+ }
87
+ finally {
88
+ await lock.release();
89
+ }
90
+ },
67
91
  processNextWork: async (unchainedAPI, workerId) => {
68
- const adapters = WorkerDirector.getAdapters();
69
- const allocationMap = await unchainedAPI.modules.worker.allocationMap();
70
- const types = adapters
71
- .filter((adapter) => {
72
- if (adapter.external)
73
- return false;
74
- if (adapter.maxParallelAllocations &&
75
- adapter.maxParallelAllocations <= allocationMap[adapter.type])
76
- return false;
77
- return true;
78
- })
79
- .map((adapter) => adapter.type);
80
92
  const worker = workerId ?? unchainedAPI.modules.worker.workerId;
81
- const work = await unchainedAPI.modules.worker.allocateWork({
82
- types,
93
+ const work = await WorkerDirector.allocateWork(unchainedAPI, {
94
+ types: WorkerDirector.getActivePluginTypes({ external: false }),
83
95
  worker,
84
96
  });
85
97
  if (work) {
@@ -0,0 +1,8 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function bulkAssignProductsToAssortmentService(this: Modules, { assortmentId, productIds }: {
3
+ assortmentId: string;
4
+ productIds: string[];
5
+ }): Promise<{
6
+ successIds: string[];
7
+ failedIds: string[];
8
+ }>;
@@ -0,0 +1,11 @@
1
+ import { executeBulkOperation } from '@unchainedshop/utils';
2
+ export async function bulkAssignProductsToAssortmentService({ assortmentId, productIds }) {
3
+ const result = await executeBulkOperation(productIds, async (productId) => {
4
+ if (!(await this.products.productExists({ productId })))
5
+ throw new Error('not-found');
6
+ const assignment = await this.assortments.products.create({ assortmentId, productId });
7
+ if (!assignment)
8
+ throw new Error('create-failed');
9
+ });
10
+ return result;
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function bulkDeleteUsersService(this: Modules, { userIds }: {
3
+ userIds: string[];
4
+ }): Promise<{
5
+ successIds: string[];
6
+ failedIds: string[];
7
+ }>;
@@ -0,0 +1,11 @@
1
+ import { executeBulkOperation } from '@unchainedshop/utils';
2
+ import { deleteUserService } from "./deleteUser.js";
3
+ export async function bulkDeleteUsersService({ userIds }) {
4
+ return executeBulkOperation(userIds, async (userId) => {
5
+ if (!(await this.users.userExists({ userId })))
6
+ throw new Error('not-found');
7
+ const result = await deleteUserService.call(this, { userId });
8
+ if (!result)
9
+ throw new Error('delete-failed');
10
+ });
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function bulkRemoveFiltersService(this: Modules, { filterIds }: {
3
+ filterIds: string[];
4
+ }): Promise<{
5
+ successIds: string[];
6
+ failedIds: string[];
7
+ }>;
@@ -0,0 +1,10 @@
1
+ import { executeBulkOperation } from '@unchainedshop/utils';
2
+ import { removeFilterService } from "./removeFilter.js";
3
+ export async function bulkRemoveFiltersService({ filterIds }) {
4
+ return executeBulkOperation(filterIds, async (filterId) => {
5
+ const filter = await this.filters.findFilter({ filterId });
6
+ if (!filter)
7
+ throw new Error('not-found');
8
+ await removeFilterService.call(this, { filter });
9
+ });
10
+ }
@@ -0,0 +1,7 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function bulkRemoveProductsService(this: Modules, { productIds }: {
3
+ productIds: string[];
4
+ }): Promise<{
5
+ successIds: string[];
6
+ failedIds: string[];
7
+ }>;
@@ -0,0 +1,23 @@
1
+ import { executeBulkOperation } from '@unchainedshop/utils';
2
+ import { removeProductService } from "./removeProduct.js";
3
+ export async function bulkRemoveProductsService({ productIds }) {
4
+ return executeBulkOperation(productIds, async (productId) => {
5
+ if (!(await this.products.productExists({ productId })))
6
+ throw new Error('not-found');
7
+ if (await this.products.firstActiveProductBundle(productId)) {
8
+ throw new Error('linked-to-active-bundle');
9
+ }
10
+ if (await this.products.firstActiveProductProxy(productId)) {
11
+ throw new Error('linked-to-active-variation');
12
+ }
13
+ if (await this.quotations.openQuotationWithProduct({ productId })) {
14
+ throw new Error('linked-to-quotation');
15
+ }
16
+ if (await this.enrollments.openEnrollmentWithProduct({ productId })) {
17
+ throw new Error('linked-to-enrollment');
18
+ }
19
+ const result = await removeProductService.call(this, { productId });
20
+ if (!result)
21
+ throw new Error('already-deleted');
22
+ });
23
+ }
@@ -0,0 +1,8 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function bulkSetFilterActiveService(this: Modules, { filterIds, isActive }: {
3
+ filterIds: string[];
4
+ isActive: boolean;
5
+ }): Promise<{
6
+ successIds: string[];
7
+ failedIds: string[];
8
+ }>;
@@ -0,0 +1,12 @@
1
+ import { executeBulkOperation } from '@unchainedshop/utils';
2
+ import { updateFilterService } from "./updateFilter.js";
3
+ export async function bulkSetFilterActiveService({ filterIds, isActive }) {
4
+ return executeBulkOperation(filterIds, async (filterId) => {
5
+ const filter = await this.filters.findFilter({ filterId });
6
+ if (!filter)
7
+ throw new Error('not-found');
8
+ if (!(await updateFilterService.call(this, filterId, { isActive }))) {
9
+ throw new Error('update-failed');
10
+ }
11
+ });
12
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core",
3
3
  "description": "Core orchestration package for the Unchained Engine with business services and directors",
4
- "version": "4.8.25",
4
+ "version": "4.8.27",
5
5
  "main": "lib/core-index.js",
6
6
  "types": "lib/core-index.d.ts",
7
7
  "type": "module",
@@ -35,28 +35,28 @@
35
35
  },
36
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
37
  "dependencies": {
38
- "@unchainedshop/core-assortments": "^4.8.12",
39
- "@unchainedshop/core-bookmarks": "^4.8.12",
40
- "@unchainedshop/core-countries": "^4.8.12",
41
- "@unchainedshop/core-currencies": "^4.8.12",
42
- "@unchainedshop/core-delivery": "^4.8.12",
43
- "@unchainedshop/core-enrollments": "^4.8.12",
44
- "@unchainedshop/core-events": "^4.8.12",
45
- "@unchainedshop/core-files": "^4.8.12",
46
- "@unchainedshop/core-filters": "^4.8.12",
47
- "@unchainedshop/core-languages": "^4.8.12",
48
- "@unchainedshop/core-orders": "^4.8.12",
49
- "@unchainedshop/core-payment": "^4.8.12",
50
- "@unchainedshop/core-products": "^4.8.12",
51
- "@unchainedshop/core-quotations": "^4.8.12",
52
- "@unchainedshop/core-users": "^4.8.12",
53
- "@unchainedshop/core-warehousing": "^4.8.12",
54
- "@unchainedshop/core-worker": "^4.8.12",
55
- "@unchainedshop/events": "^4.8.12",
56
- "@unchainedshop/file-upload": "^4.8.12",
57
- "@unchainedshop/logger": "^4.8.12",
58
- "@unchainedshop/mongodb": "^4.8.12",
59
- "@unchainedshop/utils": "^4.8.12",
38
+ "@unchainedshop/core-assortments": "^4.8.27",
39
+ "@unchainedshop/core-bookmarks": "^4.8.27",
40
+ "@unchainedshop/core-countries": "^4.8.27",
41
+ "@unchainedshop/core-currencies": "^4.8.27",
42
+ "@unchainedshop/core-delivery": "^4.8.27",
43
+ "@unchainedshop/core-enrollments": "^4.8.27",
44
+ "@unchainedshop/core-events": "^4.8.27",
45
+ "@unchainedshop/core-files": "^4.8.27",
46
+ "@unchainedshop/core-filters": "^4.8.27",
47
+ "@unchainedshop/core-languages": "^4.8.27",
48
+ "@unchainedshop/core-orders": "^4.8.27",
49
+ "@unchainedshop/core-payment": "^4.8.27",
50
+ "@unchainedshop/core-products": "^4.8.27",
51
+ "@unchainedshop/core-quotations": "^4.8.27",
52
+ "@unchainedshop/core-users": "^4.8.27",
53
+ "@unchainedshop/core-warehousing": "^4.8.27",
54
+ "@unchainedshop/core-worker": "^4.8.27",
55
+ "@unchainedshop/events": "^4.8.27",
56
+ "@unchainedshop/file-upload": "^4.8.27",
57
+ "@unchainedshop/logger": "^4.8.27",
58
+ "@unchainedshop/mongodb": "^4.8.27",
59
+ "@unchainedshop/utils": "^4.8.27",
60
60
  "minipass-json-stream": "^1.0.2",
61
61
  "zod": "^4.2.0"
62
62
  },