@unchainedshop/core-warehousing 3.0.0-alpha7 → 3.0.0-rc2

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 (33) hide show
  1. package/lib/db/TokenSurrogateCollection.d.ts +19 -1
  2. package/lib/db/TokenSurrogateCollection.d.ts.map +1 -1
  3. package/lib/db/TokenSurrogateCollection.js +6 -0
  4. package/lib/db/TokenSurrogateCollection.js.map +1 -1
  5. package/lib/db/WarehousingProvidersCollection.d.ts +15 -2
  6. package/lib/db/WarehousingProvidersCollection.d.ts.map +1 -1
  7. package/lib/db/WarehousingProvidersCollection.js +5 -0
  8. package/lib/db/WarehousingProvidersCollection.js.map +1 -1
  9. package/lib/director/WarehousingDirector.js +1 -1
  10. package/lib/director/WarehousingDirector.js.map +1 -1
  11. package/lib/module/configureWarehousingModule.d.ts +32 -53
  12. package/lib/module/configureWarehousingModule.d.ts.map +1 -1
  13. package/lib/module/configureWarehousingModule.js +23 -139
  14. package/lib/module/configureWarehousingModule.js.map +1 -1
  15. package/lib/types.d.ts +6 -8
  16. package/lib/types.d.ts.map +1 -1
  17. package/lib/types.js.map +1 -1
  18. package/lib/warehousing-index.d.ts +2 -5
  19. package/lib/warehousing-index.d.ts.map +1 -1
  20. package/lib/warehousing-index.js +2 -5
  21. package/lib/warehousing-index.js.map +1 -1
  22. package/package.json +9 -12
  23. package/src/db/TokenSurrogateCollection.ts +21 -1
  24. package/src/db/WarehousingProvidersCollection.ts +15 -2
  25. package/src/module/buildFindSelector.test.ts +1 -1
  26. package/src/module/configureWarehousingModule.ts +65 -289
  27. package/src/warehousing-index.ts +2 -6
  28. package/tsconfig.json +5 -7
  29. package/src/director/WarehousingAdapter.ts +0 -39
  30. package/src/director/WarehousingDirector.ts +0 -153
  31. package/src/director/WarehousingError.ts +0 -6
  32. package/src/director/WarehousingProviderType.ts +0 -4
  33. package/src/types.ts +0 -116
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-warehousing",
3
- "version": "3.0.0-alpha7",
3
+ "version": "3.0.0-rc2",
4
4
  "main": "lib/warehousing-index.js",
5
- "exports": {
6
- ".": "./lib/warehousing-index.js",
7
- "./*": "./lib/*"
8
- },
9
5
  "types": "lib/warehousing-index.d.ts",
10
6
  "type": "module",
11
7
  "scripts": {
12
- "clean": "rm -rf lib",
13
- "prepublishOnly": "npm run clean && tsc",
8
+ "clean": "tsc -b --clean",
9
+ "build": "tsc -b",
10
+ "prepublishOnly": "npm run clean && npm run build",
14
11
  "watch": "tsc -w",
15
12
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
16
13
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
@@ -31,14 +28,14 @@
31
28
  },
32
29
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
30
  "dependencies": {
34
- "@unchainedshop/events": "^3.0.0-alpha4",
35
- "@unchainedshop/logger": "^3.0.0-alpha4",
36
- "@unchainedshop/utils": "^3.0.0-alpha4"
31
+ "@unchainedshop/events": "^3.0.0-rc2",
32
+ "@unchainedshop/logger": "^3.0.0-rc2",
33
+ "@unchainedshop/utils": "^3.0.0-rc2"
37
34
  },
38
35
  "devDependencies": {
39
- "@types/node": "^22.8.1",
36
+ "@types/node": "^22.10.2",
40
37
  "jest": "^29.7.0",
41
38
  "ts-jest": "^29.2.5",
42
- "typescript": "^5.6.3"
39
+ "typescript": "^5.7.2"
43
40
  }
44
41
  }
@@ -1,5 +1,25 @@
1
1
  import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
2
- import { TokenSurrogate } from '../types.js';
2
+
3
+ export type TokenSurrogate = {
4
+ _id?: string;
5
+ userId?: string;
6
+ walletAddress?: string;
7
+ invalidatedDate?: Date;
8
+ expiryDate?: Date;
9
+ quantity: number;
10
+ contractAddress: string;
11
+ chainId: string;
12
+ chainTokenId: string;
13
+ productId: string;
14
+ orderPositionId: string;
15
+ meta: any;
16
+ };
17
+
18
+ export enum TokenStatus {
19
+ CENTRALIZED = 'CENTRALIZED',
20
+ EXPORTING = 'EXPORTING',
21
+ DECENTRALIZED = 'DECENTRALIZED',
22
+ }
3
23
 
4
24
  export const TokenSurrogateCollection = async (db: mongodb.Db) => {
5
25
  const TokenSurrogates = db.collection<TokenSurrogate>('token_surrogates');
@@ -1,5 +1,18 @@
1
- import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
2
- import { WarehousingProvider } from '../types.js';
1
+ import { mongodb, buildDbIndexes, TimestampFields } from '@unchainedshop/mongodb';
2
+
3
+ export enum WarehousingProviderType {
4
+ PHYSICAL = 'PHYSICAL',
5
+ VIRTUAL = 'VIRTUAL',
6
+ }
7
+
8
+ export type WarehousingConfiguration = Array<{ key: string; value: string }>;
9
+
10
+ export type WarehousingProvider = {
11
+ _id?: string;
12
+ type: WarehousingProviderType;
13
+ adapterKey: string;
14
+ configuration: WarehousingConfiguration;
15
+ } & TimestampFields;
3
16
 
4
17
  export const WarehousingProvidersCollection = async (db: mongodb.Db) => {
5
18
  const WarehousingProviders = db.collection<WarehousingProvider>('warehousing-providers');
@@ -1,4 +1,4 @@
1
- import { WarehousingProviderType } from '../warehousing-index.js';
1
+ import { WarehousingProviderType } from '../db/WarehousingProvidersCollection.js';
2
2
  import { buildFindSelector } from './configureWarehousingModule.js';
3
3
 
4
4
  describe('Warehousing', () => {
@@ -1,102 +1,14 @@
1
- import type { User } from '@unchainedshop/core-users';
2
-
3
- import { UnchainedCore } from '@unchainedshop/core';
1
+ import { emit, registerEvents } from '@unchainedshop/events';
2
+ import { generateDbFilterById, generateDbObjectId, mongodb, ModuleInput } from '@unchainedshop/mongodb';
4
3
  import {
5
- WarehousingContext,
6
4
  WarehousingProvider,
7
- WarehousingProviderQuery,
5
+ WarehousingProvidersCollection,
8
6
  WarehousingProviderType,
9
- } from '../types.js';
10
- import { emit, registerEvents } from '@unchainedshop/events';
11
- import { generateDbFilterById, generateDbObjectId, mongodb, ModuleInput } from '@unchainedshop/mongodb';
12
- import { WarehousingProvidersCollection } from '../db/WarehousingProvidersCollection.js';
13
- import { WarehousingDirector } from '../director/WarehousingDirector.js';
14
- import { TokenSurrogateCollection } from '../db/TokenSurrogateCollection.js';
15
- import { EstimatedDispatch, EstimatedStock, TokenSurrogate, WarehousingInterface } from '../types.js';
16
- import { WarehousingError } from '../warehousing-index.js';
17
- import { Order } from '@unchainedshop/core-orders';
18
- import { OrderPosition } from '@unchainedshop/core-orders';
19
- import { Product } from '@unchainedshop/core-products';
20
-
21
- export type WarehousingModule = {
22
- // Queries
23
- findProvider: (
24
- query: { warehousingProviderId: string },
25
- options?: mongodb.FindOptions,
26
- ) => Promise<WarehousingProvider>;
27
- findToken: (query: { tokenId: string }, options?: mongodb.FindOptions) => Promise<TokenSurrogate>;
28
- findTokensForUser: (user: User, options?: mongodb.FindOptions) => Promise<Array<TokenSurrogate>>;
29
- findTokens: (query: any, options?: mongodb.FindOptions) => Promise<Array<TokenSurrogate>>;
30
- findProviders: (
31
- query: WarehousingProviderQuery,
32
- options?: mongodb.FindOptions,
33
- ) => Promise<Array<WarehousingProvider>>;
34
- count: (query: WarehousingProviderQuery) => Promise<number>;
35
- providerExists: (query: { warehousingProviderId: string }) => Promise<boolean>;
36
-
37
- // Adapter
38
-
39
- findSupported: (
40
- warehousingContext: WarehousingContext,
41
- unchainedAPI: UnchainedCore,
42
- ) => Promise<Array<WarehousingProvider>>;
43
- findInterface: (query: WarehousingProvider) => WarehousingInterface;
44
- findInterfaces: (query: WarehousingProviderQuery) => Array<WarehousingInterface>;
45
- configurationError: (
46
- provider: WarehousingProvider,
47
- unchainedAPI: UnchainedCore,
48
- ) => Promise<WarehousingError>;
49
- isActive: (provider: WarehousingProvider, unchainedAPI: UnchainedCore) => Promise<boolean>;
50
-
51
- estimatedDispatch: (
52
- provider: WarehousingProvider,
53
- context: WarehousingContext,
54
- unchainedAPI: UnchainedCore,
55
- ) => Promise<EstimatedDispatch>;
56
-
57
- estimatedStock: (
58
- provider: WarehousingProvider,
59
- context: WarehousingContext,
60
- unchainedAPI: UnchainedCore,
61
- ) => Promise<EstimatedStock>;
62
-
63
- updateTokenOwnership: (input: {
64
- tokenId: string;
65
- userId: string;
66
- walletAddress: string;
67
- }) => Promise<void>;
68
-
69
- invalidateToken: (tokenId: string) => Promise<void>;
70
-
71
- buildAccessKeyForToken: (tokenId: string) => Promise<string>;
72
-
73
- tokenizeItems: (
74
- order: Order,
75
- params: {
76
- items: Array<{
77
- orderPosition: OrderPosition;
78
- product: Product;
79
- }>;
80
- },
81
- unchainedAPI: UnchainedCore,
82
- ) => Promise<void>;
83
-
84
- tokenMetadata: (
85
- chainTokenId: string,
86
- params: { product: Product; token: TokenSurrogate; referenceDate: Date; locale: Intl.Locale },
87
- unchainedAPI: UnchainedCore,
88
- ) => Promise<any>;
7
+ } from '../db/WarehousingProvidersCollection.js';
8
+ import { TokenSurrogate, TokenSurrogateCollection } from '../db/TokenSurrogateCollection.js';
89
9
 
90
- isInvalidateable: (
91
- chainTokenId: string,
92
- params: { product: Product; token: TokenSurrogate; referenceDate: Date },
93
- unchainedAPI: UnchainedCore,
94
- ) => Promise<boolean>;
95
-
96
- // Mutations
97
- delete: (providerId: string) => Promise<WarehousingProvider>;
98
- update: (_id: string, doc: WarehousingProvider) => Promise<string>;
99
- create: (doc: WarehousingProvider) => Promise<string | null>;
10
+ type WarehousingProviderQuery = {
11
+ type?: WarehousingProviderType;
100
12
  };
101
13
 
102
14
  const WAREHOUSING_PROVIDER_EVENTS: string[] = [
@@ -112,15 +24,7 @@ export const buildFindSelector = ({ type }: WarehousingProviderQuery = {}) => {
112
24
  return query;
113
25
  };
114
26
 
115
- const asyncFilter = async (arr, predicate) => {
116
- const results = await Promise.all(arr.map(predicate));
117
-
118
- return arr.filter((_v, index) => results[index]);
119
- };
120
-
121
- export const configureWarehousingModule = async ({
122
- db,
123
- }: ModuleInput<Record<string, never>>): Promise<WarehousingModule> => {
27
+ export const configureWarehousingModule = async ({ db }: ModuleInput<Record<string, never>>) => {
124
28
  registerEvents(WAREHOUSING_PROVIDER_EVENTS);
125
29
 
126
30
  const WarehousingProviders = await WarehousingProvidersCollection(db);
@@ -128,49 +32,68 @@ export const configureWarehousingModule = async ({
128
32
 
129
33
  return {
130
34
  // Queries
131
- count: async (query) => {
35
+ count: async (query: WarehousingProviderQuery): Promise<number> => {
132
36
  const providerCount = await WarehousingProviders.countDocuments(buildFindSelector(query));
133
37
  return providerCount;
134
38
  },
135
39
 
136
- findProvider: async ({ warehousingProviderId }, options) => {
40
+ createTokens: async (tokens: TokenSurrogate[]): Promise<void> => {
41
+ await TokenSurrogates.insertMany(tokens);
42
+ },
43
+
44
+ findProvider: async (
45
+ { warehousingProviderId }: { warehousingProviderId: string },
46
+ options?: mongodb.FindOptions,
47
+ ): Promise<WarehousingProvider> => {
137
48
  return WarehousingProviders.findOne(generateDbFilterById(warehousingProviderId), options);
138
49
  },
139
50
 
140
- findToken: async ({ tokenId }, options) => {
141
- return TokenSurrogates.findOne(generateDbFilterById(tokenId), options);
51
+ findToken: async (
52
+ { tokenId }: { tokenId: string },
53
+ options?: mongodb.FindOptions,
54
+ ): Promise<TokenSurrogate> => {
55
+ return TokenSurrogates.findOne({ _id: tokenId }, options);
142
56
  },
143
57
 
144
- findTokens: async (selector, options) => {
58
+ findTokens: async (selector: any, options?: mongodb.FindOptions): Promise<Array<TokenSurrogate>> => {
145
59
  return TokenSurrogates.find(selector, options).toArray();
146
60
  },
147
61
 
148
- findTokensForUser: async (user, options) => {
149
- const addresses =
150
- user.services?.web3?.flatMap((service) => {
151
- return service.verified ? [service.address] : [];
152
- }) || [];
62
+ findTokensForUser: async (
63
+ params: { userId: string } | { walletAddresses: string[] },
64
+ options?: mongodb.FindOptions,
65
+ ): Promise<Array<TokenSurrogate>> => {
66
+ const { userId, walletAddresses } = params as any;
67
+ if (!userId && !walletAddresses)
68
+ throw new Error('userId or walletAddresses must be provided for findTokensForUser');
153
69
  const selector = {
154
70
  $or: [
155
- {
156
- walletAddress: { $in: addresses || [] },
71
+ walletAddresses && {
72
+ walletAddress: { $in: walletAddresses || [] },
157
73
  },
158
- {
159
- userId: user._id,
74
+ userId && {
75
+ userId,
160
76
  },
161
- ],
77
+ ].filter(Boolean),
162
78
  };
163
79
 
164
80
  const userTokens = await TokenSurrogates.find(selector, options).toArray();
165
81
  return userTokens;
166
82
  },
167
83
 
168
- findProviders: async (query, options = { sort: { created: 1 } }) => {
84
+ findProviders: async (
85
+ query: WarehousingProviderQuery,
86
+ options: mongodb.FindOptions = { sort: { created: 1 } },
87
+ ): Promise<Array<WarehousingProvider>> => {
169
88
  const providers = WarehousingProviders.find(buildFindSelector(query), options);
170
89
  return providers.toArray();
171
90
  },
172
91
 
173
- providerExists: async ({ warehousingProviderId }) => {
92
+ providerExists: async ({
93
+ warehousingProviderId,
94
+ }: {
95
+ warehousingProviderId: string;
96
+ }): Promise<boolean> => {
174
97
  const providerCount = await WarehousingProviders.countDocuments(
175
98
  generateDbFilterById(warehousingProviderId, { deleted: null }),
176
99
  { limit: 1 },
@@ -178,63 +101,15 @@ export const configureWarehousingModule = async ({
178
101
  return !!providerCount;
179
102
  },
180
103
 
181
- // Adapter
182
-
183
- findInterface: (warehousingProvider) => {
184
- const Adapter = WarehousingDirector.getAdapter(warehousingProvider.adapterKey);
185
- if (!Adapter) return null;
186
- return {
187
- _id: Adapter.key,
188
- label: Adapter.label,
189
- version: Adapter.version,
190
- };
191
- },
192
-
193
- findInterfaces: ({ type }) => {
194
- return WarehousingDirector.getAdapters({
195
- adapterFilter: (Adapter) => Adapter.typeSupported(type),
196
- }).map((Adapter) => ({
197
- _id: Adapter.key,
198
- label: Adapter.label,
199
- version: Adapter.version,
200
- }));
201
- },
202
-
203
- findSupported: async (warehousingContext, unchainedAPI) => {
204
- const allProviders = await WarehousingProviders.find(buildFindSelector({})).toArray();
205
-
206
- const providers = asyncFilter(allProviders, async (provider) => {
207
- const director = await WarehousingDirector.actions(provider, warehousingContext, unchainedAPI);
208
- return director.isActive();
209
- });
210
-
211
- return providers;
212
- },
213
-
214
- configurationError: async (warehousingProvider, unchainedAPI) => {
215
- const actions = await WarehousingDirector.actions(warehousingProvider, {}, unchainedAPI);
216
- return actions.configurationError();
217
- },
218
-
219
- estimatedDispatch: async (warehousingProvider, warehousingContext, unchainedAPI) => {
220
- const director = await WarehousingDirector.actions(
221
- warehousingProvider,
222
- warehousingContext,
223
- unchainedAPI,
224
- );
225
- return director.estimatedDispatch();
226
- },
227
-
228
- estimatedStock: async (warehousingProvider, warehousingContext, unchainedAPI) => {
229
- const director = await WarehousingDirector.actions(
230
- warehousingProvider,
231
- warehousingContext,
232
- unchainedAPI,
233
- );
234
- return director.estimatedStock();
235
- },
236
-
237
- updateTokenOwnership: async ({ tokenId, userId, walletAddress }) => {
104
+ updateTokenOwnership: async ({
105
+ tokenId,
106
+ userId,
107
+ walletAddress,
108
+ }: {
109
+ tokenId: string;
110
+ userId: string;
111
+ walletAddress: string;
112
+ }): Promise<TokenSurrogate> => {
238
113
  const token = await TokenSurrogates.findOneAndUpdate(
239
114
  { _id: tokenId },
240
115
  {
@@ -246,100 +121,10 @@ export const configureWarehousingModule = async ({
246
121
  { returnDocument: 'after' },
247
122
  );
248
123
  await emit('TOKEN_OWNERSHIP_CHANGED', { token });
124
+ return token;
249
125
  },
250
126
 
251
- tokenizeItems: async (order, { items }, unchainedAPI) => {
252
- const virtualProviders = await WarehousingProviders.find(
253
- buildFindSelector({ type: WarehousingProviderType.VIRTUAL }),
254
- ).toArray();
255
-
256
- const tokenizers = await Promise.all(
257
- items.flatMap(({ orderPosition, product }) => {
258
- const warehousingContext: WarehousingContext = {
259
- order,
260
- orderPosition,
261
- product,
262
- quantity: orderPosition.quantity,
263
- referenceDate: order.ordered,
264
- };
265
- return virtualProviders.map(async (provider) => {
266
- const director = await WarehousingDirector.actions(
267
- provider,
268
- warehousingContext,
269
- unchainedAPI,
270
- );
271
- const isActive = await director.isActive();
272
- if (isActive) return director.tokenize;
273
- return (async () => []) as typeof director.tokenize;
274
- });
275
- }),
276
- );
277
-
278
- // Tokenize linearly so that after every tokenized item, the db is updated
279
- await tokenizers.reduce(async (lastPromise, tokenizer) => {
280
- await lastPromise;
281
- const tokenSurrogates = await tokenizer();
282
- await TokenSurrogates.insertMany(tokenSurrogates);
283
- return true;
284
- }, Promise.resolve(false));
285
- },
286
-
287
- tokenMetadata: async (chainTokenId, { token, product, locale, referenceDate }, unchainedAPI) => {
288
- const virtualProviders = await WarehousingProviders.find(
289
- buildFindSelector({ type: WarehousingProviderType.VIRTUAL }),
290
- ).toArray();
291
-
292
- const warehousingContext: WarehousingContext = {
293
- product,
294
- token,
295
- locale,
296
- quantity: token?.quantity || 1,
297
- referenceDate,
298
- };
299
- return virtualProviders.reduce(async (lastPromise, provider) => {
300
- const last = await lastPromise;
301
- if (last) return last;
302
- const currentDirector = await WarehousingDirector.actions(
303
- provider,
304
- warehousingContext,
305
- unchainedAPI,
306
- );
307
- const isActive = await currentDirector.isActive();
308
- if (isActive) {
309
- return currentDirector.tokenMetadata(chainTokenId);
310
- }
311
- return null;
312
- }, Promise.resolve(null));
313
- },
314
-
315
- isInvalidateable: async (chainTokenId, { token, product, referenceDate }, unchainedAPI) => {
316
- const virtualProviders = await WarehousingProviders.find(
317
- buildFindSelector({ type: WarehousingProviderType.VIRTUAL }),
318
- ).toArray();
319
-
320
- const warehousingContext: WarehousingContext = {
321
- product,
322
- token,
323
- quantity: token?.quantity || 1,
324
- referenceDate,
325
- };
326
- return virtualProviders.reduce(async (lastPromise, provider) => {
327
- const last = await lastPromise;
328
- if (last) return last;
329
- const currentDirector = await WarehousingDirector.actions(
330
- provider,
331
- warehousingContext,
332
- unchainedAPI,
333
- );
334
- const isActive = await currentDirector.isActive();
335
- if (isActive) {
336
- return currentDirector.isInvalidateable(chainTokenId);
337
- }
338
- return null;
339
- }, Promise.resolve(null));
340
- },
341
-
342
- invalidateToken: async (tokenId) => {
127
+ invalidateToken: async (tokenId: string): Promise<TokenSurrogate> => {
343
128
  const token = await TokenSurrogates.findOneAndUpdate(
344
129
  { _id: tokenId, invalidatedDate: null },
345
130
  {
@@ -354,9 +139,10 @@ export const configureWarehousingModule = async ({
354
139
  if (token) {
355
140
  await emit('TOKEN_INVALIDATED', { token });
356
141
  }
142
+ return token;
357
143
  },
358
144
 
359
- buildAccessKeyForToken: async (tokenId) => {
145
+ buildAccessKeyForToken: async (tokenId: string): Promise<string> => {
360
146
  const token = await TokenSurrogates.findOne(generateDbFilterById(tokenId));
361
147
  const payload = [
362
148
  token._id,
@@ -371,33 +157,22 @@ export const configureWarehousingModule = async ({
371
157
  return hashHex;
372
158
  },
373
159
 
374
- isActive: async (warehousingProvider, unchainedAPI) => {
375
- const actions = await WarehousingDirector.actions(warehousingProvider, {}, unchainedAPI);
376
- return actions.isActive();
377
- },
378
-
379
160
  // Mutations
380
- create: async (doc) => {
381
- const Adapter = WarehousingDirector.getAdapter(doc.adapterKey);
382
- if (!Adapter) return null;
383
-
161
+ create: async (doc: WarehousingProvider): Promise<WarehousingProvider> => {
384
162
  const { insertedId: warehousingProviderId } = await WarehousingProviders.insertOne({
385
163
  _id: generateDbObjectId(),
386
164
  created: new Date(),
387
- configuration: Adapter.initialConfiguration,
388
165
  ...doc,
389
166
  });
390
167
 
391
- const warehousingProvider = await WarehousingProviders.findOne(
392
- generateDbFilterById(warehousingProviderId),
393
- );
168
+ const warehousingProvider = await WarehousingProviders.findOne({ _id: warehousingProviderId });
394
169
  await emit('WAREHOUSING_PROVIDER_CREATE', { warehousingProvider });
395
- return warehousingProviderId;
170
+ return warehousingProvider;
396
171
  },
397
172
 
398
173
  update: async (warehousingProviderId: string, doc: WarehousingProvider) => {
399
174
  const warehousingProvider = await WarehousingProviders.findOneAndUpdate(
400
- generateDbFilterById(warehousingProviderId),
175
+ { _id: warehousingProviderId },
401
176
  {
402
177
  $set: {
403
178
  updated: new Date(),
@@ -410,10 +185,10 @@ export const configureWarehousingModule = async ({
410
185
  if (!warehousingProvider) return null;
411
186
 
412
187
  await emit('WAREHOUSING_PROVIDER_UPDATE', { warehousingProvider });
413
- return warehousingProviderId;
188
+ return warehousingProvider;
414
189
  },
415
190
 
416
- delete: async (providerId) => {
191
+ delete: async (providerId: string): Promise<WarehousingProvider> => {
417
192
  const warehousingProvider = await WarehousingProviders.findOneAndUpdate(
418
193
  generateDbFilterById(providerId),
419
194
  {
@@ -425,8 +200,9 @@ export const configureWarehousingModule = async ({
425
200
  );
426
201
 
427
202
  await emit('WAREHOUSING_PROVIDER_REMOVE', { warehousingProvider });
428
-
429
203
  return warehousingProvider;
430
204
  },
431
205
  };
432
206
  };
207
+
208
+ export type WarehousingModule = Awaited<ReturnType<typeof configureWarehousingModule>>;
@@ -1,7 +1,3 @@
1
- export * from './types.js';
2
1
  export * from './module/configureWarehousingModule.js';
3
-
4
- export { WarehousingDirector } from './director/WarehousingDirector.js';
5
- export { WarehousingAdapter } from './director/WarehousingAdapter.js';
6
- export { WarehousingError } from './director/WarehousingError.js';
7
- export { WarehousingProviderType } from './director/WarehousingProviderType.js';
2
+ export * from './db/TokenSurrogateCollection.js';
3
+ export * from './db/WarehousingProvidersCollection.js';
package/tsconfig.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "extends": "../shared/base.tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "lib",
4
+ "declarationDir": "./lib",
5
+ "rootDir": "./src",
6
+ "outDir": "./lib"
6
7
  },
7
- "exclude": ["**/*.test.ts", "**/*.test.js", "tests"],
8
- "include": [
9
- "./src"
10
- ]
11
- }
8
+ "exclude": ["**/*.test.ts", "**/*.test.js", "tests", "lib"]
9
+ }
@@ -1,39 +0,0 @@
1
- import { IWarehousingAdapter } from '../types.js';
2
- import { log, LogLevel } from '@unchainedshop/logger';
3
-
4
- import { WarehousingError } from './WarehousingError.js';
5
-
6
- export const WarehousingAdapter: Omit<IWarehousingAdapter, 'key' | 'label' | 'version'> = {
7
- orderIndex: 0,
8
-
9
- typeSupported: () => {
10
- return false;
11
- },
12
-
13
- initialConfiguration: [],
14
-
15
- actions: () => {
16
- return {
17
- configurationError: () => WarehousingError.NOT_IMPLEMENTED,
18
-
19
- isActive: () => false,
20
-
21
- stock: async () => 0,
22
-
23
- productionTime: async () => 0,
24
-
25
- commissioningTime: async () => 0,
26
-
27
- tokenize: async () => [],
28
-
29
- tokenMetadata: async () => ({}),
30
-
31
- isInvalidateable: async () => true,
32
- };
33
- },
34
-
35
- log(message, { level = LogLevel.Debug, ...options } = {}) {
36
- // eslint-disable-line
37
- return log(message, { level, ...options });
38
- },
39
- };