@unchainedshop/core-warehousing 4.4.0 → 4.5.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.
@@ -1,35 +1,21 @@
1
1
  import { type mongodb, type ModuleInput } from '@unchainedshop/mongodb';
2
- import { type WarehousingProvider } from '../db/WarehousingProvidersCollection.ts';
2
+ import { type WarehousingProvider, type WarehousingProviderType } from '../db/WarehousingProvidersCollection.ts';
3
3
  import { type TokenSurrogate } from '../db/TokenSurrogateCollection.ts';
4
4
  interface TokenQuery {
5
5
  queryString?: string;
6
6
  userId?: string;
7
+ walletAddressExists?: boolean;
7
8
  }
8
- export declare const buildFindSelector: ({ includeDeleted, ...rest }?: mongodb.Filter<WarehousingProvider> & {
9
+ export interface WarehousingProviderQuery {
10
+ warehousingProviderIds?: string[];
11
+ type?: WarehousingProviderType;
9
12
  includeDeleted?: boolean;
10
- }) => {
11
- type?: mongodb.Condition<import("../db/WarehousingProvidersCollection.ts").WarehousingProviderType> | undefined;
12
- created?: mongodb.Condition<Date> | undefined;
13
- deleted?: Date | mongodb.FilterOperators<Date | null | undefined> | null | undefined;
14
- adapterKey?: mongodb.Condition<string> | undefined;
15
- configuration?: mongodb.Condition<import("../db/WarehousingProvidersCollection.ts").WarehousingConfiguration> | undefined;
16
- updated?: mongodb.Condition<Date | undefined>;
17
- _id?: mongodb.Condition<string> | undefined;
18
- $and?: mongodb.Filter<mongodb.WithId<WarehousingProvider>>[] | undefined;
19
- $nor?: mongodb.Filter<mongodb.WithId<WarehousingProvider>>[] | undefined;
20
- $or?: mongodb.Filter<mongodb.WithId<WarehousingProvider>>[] | undefined;
21
- $text?: {
22
- $search: string;
23
- $language?: string;
24
- $caseSensitive?: boolean;
25
- $diacriticSensitive?: boolean;
26
- };
27
- $where?: string | ((this: mongodb.WithId<WarehousingProvider>) => boolean) | undefined;
28
- $comment?: string | mongodb.BSON.Document;
29
- };
30
- export declare const buildTokenFindSelector: ({ queryString, ...rest }: TokenQuery) => mongodb.Filter<TokenSurrogate>;
13
+ queryString?: string;
14
+ }
15
+ export declare const buildFindSelector: ({ includeDeleted, queryString, warehousingProviderIds, type, }?: WarehousingProviderQuery) => mongodb.Filter<WarehousingProvider>;
16
+ export declare const buildTokenFindSelector: ({ queryString, walletAddressExists, ...rest }: TokenQuery) => mongodb.Filter<TokenSurrogate>;
31
17
  export declare const configureWarehousingModule: ({ db }: ModuleInput<Record<string, never>>) => Promise<{
32
- count: (query: mongodb.Filter<WarehousingProvider>) => Promise<number>;
18
+ count: (query?: WarehousingProviderQuery) => Promise<number>;
33
19
  createTokens: (tokens: TokenSurrogate[]) => Promise<void>;
34
20
  findProvider: ({ warehousingProviderId }: {
35
21
  warehousingProviderId: string;
@@ -44,9 +30,7 @@ export declare const configureWarehousingModule: ({ db }: ModuleInput<Record<str
44
30
  } | {
45
31
  walletAddresses: string[];
46
32
  }, options?: mongodb.FindOptions) => Promise<TokenSurrogate[]>;
47
- findProviders: (query: mongodb.Filter<WarehousingProvider> & {
48
- includeDeleted?: boolean;
49
- }, options?: mongodb.FindOptions) => Promise<WarehousingProvider[]>;
33
+ findProviders: (query?: WarehousingProviderQuery, options?: mongodb.FindOptions) => Promise<WarehousingProvider[]>;
50
34
  allProviders: () => Promise<mongodb.WithId<WarehousingProvider>[]>;
51
35
  providerExists: ({ warehousingProviderId, }: {
52
36
  warehousingProviderId: string;
@@ -12,15 +12,29 @@ const WAREHOUSING_PROVIDER_EVENTS = [
12
12
  'TOKEN_INVALIDATED',
13
13
  ];
14
14
  const allProvidersCache = new ExpiryMap(process.env.NODE_ENV === 'production' ? 60000 : 1);
15
- export const buildFindSelector = ({ includeDeleted = false, ...rest } = {}) => {
16
- return { ...(includeDeleted ? {} : { deleted: null }), ...rest };
15
+ export const buildFindSelector = ({ includeDeleted = false, queryString, warehousingProviderIds, type, } = {}) => {
16
+ const selector = includeDeleted ? {} : { deleted: null };
17
+ if (warehousingProviderIds) {
18
+ selector._id = { $in: warehousingProviderIds };
19
+ }
20
+ if (type) {
21
+ selector.type = type;
22
+ }
23
+ if (queryString) {
24
+ const regex = new RegExp(queryString, 'i');
25
+ selector.$or = [{ _id: regex }, { adapterKey: regex }];
26
+ }
27
+ return selector;
17
28
  };
18
- export const buildTokenFindSelector = ({ queryString, ...rest }) => {
29
+ export const buildTokenFindSelector = ({ queryString, walletAddressExists, ...rest }) => {
19
30
  const selector = { ...(rest || {}) };
20
31
  if (queryString) {
21
32
  assertDocumentDBCompatMode();
22
33
  selector.$text = { $search: queryString };
23
34
  }
35
+ if (walletAddressExists !== undefined) {
36
+ selector.walletAddress = walletAddressExists ? { $exists: true } : { $exists: false };
37
+ }
24
38
  return selector;
25
39
  };
26
40
  export const configureWarehousingModule = async ({ db }) => {
@@ -28,7 +42,7 @@ export const configureWarehousingModule = async ({ db }) => {
28
42
  const WarehousingProviders = await WarehousingProvidersCollection(db);
29
43
  const TokenSurrogates = await TokenSurrogateCollection(db);
30
44
  return {
31
- count: async (query) => {
45
+ count: async (query = {}) => {
32
46
  const providerCount = await WarehousingProviders.countDocuments(buildFindSelector(query));
33
47
  return providerCount;
34
48
  },
@@ -65,7 +79,7 @@ export const configureWarehousingModule = async ({ db }) => {
65
79
  const userTokens = await TokenSurrogates.find(selector, options).toArray();
66
80
  return userTokens;
67
81
  },
68
- findProviders: async (query, options = { sort: { created: 1 } }) => {
82
+ findProviders: async (query = {}, options = { sort: { created: 1 } }) => {
69
83
  const providers = WarehousingProviders.find(buildFindSelector(query), options);
70
84
  return providers.toArray();
71
85
  },
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-warehousing",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "main": "lib/warehousing-index.js",
5
5
  "types": "lib/warehousing-index.d.ts",
6
6
  "type": "module",
7
+ "sideEffects": false,
7
8
  "scripts": {
8
9
  "clean": "tsc -b --clean",
9
10
  "build": "tsc -b",
@@ -33,9 +34,9 @@
33
34
  },
34
35
  "homepage": "https://github.com/unchainedshop/unchained#readme",
35
36
  "dependencies": {
36
- "@unchainedshop/events": "^4.4.0",
37
- "@unchainedshop/logger": "^4.4.0",
38
- "@unchainedshop/utils": "^4.4.0",
37
+ "@unchainedshop/events": "^4.5.0",
38
+ "@unchainedshop/logger": "^4.5.0",
39
+ "@unchainedshop/utils": "^4.5.0",
39
40
  "expiry-map": "^2.0.0",
40
41
  "p-memoize": "^8.0.0"
41
42
  },