@websolutespa/bom-mixer-store 1.1.0 → 1.1.1

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.
package/CHANGELOG.md CHANGED
@@ -1,61 +1,67 @@
1
- # @websolutespa/bom-mixer-store
2
-
3
- ## 1.1.0
4
-
5
- ### Minor Changes
6
-
7
- - Modified: store refactor.
8
-
9
- ## 1.0.1
10
-
11
- ### Patch Changes
12
-
13
- - Fixing: localhost url.
14
-
15
- ## 1.0.0
16
-
17
- ### Minor Changes
18
-
19
- - Modified routes, added redirects.
20
-
21
- ## 0.3.2
22
-
23
- ### Patch Changes
24
-
25
- - Modified: MockMenuService.
26
-
27
- ## 0.3.1
28
-
29
- ### Patch Changes
30
-
31
- - Added: source files.
32
-
33
- ## 0.3.0
34
-
35
- ### Minor Changes
36
-
37
- - Added: splat routes.
38
-
39
- ## 0.2.0
40
-
41
- ### Minor Changes
42
-
43
- - Added: @websolutespa/bom-core.
44
-
45
- ## 0.1.1
46
-
47
- ### Patch Changes
48
-
49
- - Modified: store service.
50
-
51
- ## 0.1.0
52
-
53
- ### Minor Changes
54
-
55
- - mock refactor.
56
-
57
- ## 0.0.2
58
-
59
- ### Patch Changes
60
-
61
- - Added: first release.
1
+ # @websolutespa/bom-mixer-store
2
+
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: check redirects by pattern.
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Modified: store refactor.
14
+
15
+ ## 1.0.1
16
+
17
+ ### Patch Changes
18
+
19
+ - Fixing: localhost url.
20
+
21
+ ## 1.0.0
22
+
23
+ ### Minor Changes
24
+
25
+ - Modified routes, added redirects.
26
+
27
+ ## 0.3.2
28
+
29
+ ### Patch Changes
30
+
31
+ - Modified: MockMenuService.
32
+
33
+ ## 0.3.1
34
+
35
+ ### Patch Changes
36
+
37
+ - Added: source files.
38
+
39
+ ## 0.3.0
40
+
41
+ ### Minor Changes
42
+
43
+ - Added: splat routes.
44
+
45
+ ## 0.2.0
46
+
47
+ ### Minor Changes
48
+
49
+ - Added: @websolutespa/bom-core.
50
+
51
+ ## 0.1.1
52
+
53
+ ### Patch Changes
54
+
55
+ - Modified: store service.
56
+
57
+ ## 0.1.0
58
+
59
+ ### Minor Changes
60
+
61
+ - mock refactor.
62
+
63
+ ## 0.0.2
64
+
65
+ ### Patch Changes
66
+
67
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -2,145 +2,145 @@ import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, IPageRe
2
2
  import { NextApiRequest, NextApiResponse } from 'next';
3
3
  import { NextRequest } from 'next/server';
4
4
 
5
- type ApiRequestOptions = FetchRequestOptions;
6
- declare const defaultApiRequestOptions: ApiRequestOptions;
5
+ type ApiRequestOptions = FetchRequestOptions;
6
+ declare const defaultApiRequestOptions: ApiRequestOptions;
7
7
  declare function getDefaultApiRequestOptions(): ApiRequestOptions;
8
8
 
9
- type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
10
- type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
11
- type IApiHandler = Record<ICrudMethod, IHandler>;
12
- declare function apiHandler(handler: IApiHandler): any;
9
+ type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
10
+ type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
11
+ type IApiHandler = Record<ICrudMethod, IHandler>;
12
+ declare function apiHandler(handler: IApiHandler): any;
13
13
  declare function errorHandler(error: any, response: NextApiResponse): Promise<any> | void;
14
14
 
15
15
  declare function fromCache<T = unknown>(callback: () => Promise<T>, key?: string): Promise<T>;
16
16
 
17
- declare function getLocalApiUrl(pathname: string): string;
18
- declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
19
- locale: string;
20
- market: string;
21
- }): Promise<T>;
22
- declare function localApiGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
23
- locale: string;
24
- market: string;
25
- }): Promise<T>;
26
- declare function localApiPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
27
- locale: string;
28
- market: string;
29
- }): Promise<T>;
30
- declare function localApiPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
31
- locale: string;
32
- market: string;
33
- }): Promise<T>;
34
- declare function localApiPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
35
- locale: string;
36
- market: string;
37
- }): Promise<T>;
38
- declare function localApiDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
39
- locale: string;
40
- market: string;
17
+ declare function getLocalApiUrl(pathname: string): string;
18
+ declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
19
+ locale: string;
20
+ market: string;
21
+ }): Promise<T>;
22
+ declare function localApiGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
23
+ locale: string;
24
+ market: string;
25
+ }): Promise<T>;
26
+ declare function localApiPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
27
+ locale: string;
28
+ market: string;
29
+ }): Promise<T>;
30
+ declare function localApiPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
31
+ locale: string;
32
+ market: string;
33
+ }): Promise<T>;
34
+ declare function localApiPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
35
+ locale: string;
36
+ market: string;
37
+ }): Promise<T>;
38
+ declare function localApiDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
39
+ locale: string;
40
+ market: string;
41
41
  }): Promise<T>;
42
42
 
43
- declare function isStaticRequest(request: NextRequest): boolean;
44
- declare function isNextRequest(request: NextRequest): boolean;
43
+ declare function isStaticRequest(request: NextRequest): boolean;
44
+ declare function isNextRequest(request: NextRequest): boolean;
45
45
  declare function isApiRequest(request: NextRequest): boolean;
46
46
 
47
- declare function mockApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
48
- declare function mockApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
49
- declare function mockApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
50
- declare function mockApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
51
- declare function mockApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
47
+ declare function mockApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
48
+ declare function mockApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
49
+ declare function mockApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
50
+ declare function mockApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
51
+ declare function mockApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
52
52
  declare function mockApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
53
53
 
54
54
  declare function mockHandler(): any;
55
55
 
56
- declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
57
- store: IStore;
58
- constructor(items: T[], store: IStore);
59
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
60
- }
61
- declare function isObject(item: unknown): item is Record<string, unknown>;
56
+ declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
57
+ store: IStore;
58
+ constructor(items: T[], store: IStore);
59
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
60
+ }
61
+ declare function isObject(item: unknown): item is Record<string, unknown>;
62
62
  declare function isRelation(item: unknown): item is IPageRelation;
63
63
 
64
64
  declare function getMockStore<T extends IStore = IStore>(): Promise<T>;
65
65
 
66
- declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
67
- declare function remoteApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
68
- declare function remoteApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
69
- declare function remoteApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
70
- declare function remoteApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
66
+ declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
67
+ declare function remoteApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
68
+ declare function remoteApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
69
+ declare function remoteApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
70
+ declare function remoteApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
71
71
  declare function remoteApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
72
72
 
73
- /**
74
- * This service handle call to remote api (bowl or over)
75
- */
76
- declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T> {
77
- key: string;
78
- constructor(key: string);
79
- findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
80
- findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
81
- findPaged<B extends T = T>(params?: QueryParams): Promise<{
82
- docs: B[];
83
- } & Pagination>;
84
- create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
85
- update<B extends T = T>(payload: Partial<B>): Promise<B>;
86
- delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
87
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
73
+ /**
74
+ * This service handle call to remote api (bowl or over)
75
+ */
76
+ declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T> {
77
+ key: string;
78
+ constructor(key: string);
79
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
80
+ findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
81
+ findPaged<B extends T = T>(params?: QueryParams): Promise<{
82
+ docs: B[];
83
+ } & Pagination>;
84
+ create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
85
+ update<B extends T = T>(payload: Partial<B>): Promise<B>;
86
+ delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
87
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
88
88
  }
89
89
 
90
90
  declare function getRemoteStore<T extends IStore>(): Promise<T>;
91
91
 
92
- type IField = {
93
- name: string;
94
- type: 'text' | 'number' | 'relationship';
95
- localized?: boolean;
96
- relationTo?: string;
97
- hasMany?: boolean;
98
- required?: boolean;
99
- };
100
- type MapTo = Record<string, string>;
101
- type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
102
- type StaticServiceConfig<T extends IEntity = IEntity> = {
103
- src: StaticServiceSrc<T>;
104
- slug: string;
105
- fields: IField[];
106
- map?: MapTo;
107
- };
92
+ type IField = {
93
+ name: string;
94
+ type: 'text' | 'number' | 'relationship';
95
+ localized?: boolean;
96
+ relationTo?: string;
97
+ hasMany?: boolean;
98
+ required?: boolean;
99
+ };
100
+ type MapTo = Record<string, string>;
101
+ type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
102
+ type StaticServiceConfig<T extends IEntity = IEntity> = {
103
+ src: StaticServiceSrc<T>;
104
+ slug: string;
105
+ fields: IField[];
106
+ map?: MapTo;
107
+ };
108
108
  declare const staticCollections: StaticServiceConfig[];
109
109
 
110
- declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
111
- loaded: boolean;
112
- config: StaticServiceConfig<T>;
113
- store: IStore;
114
- constructor(config: StaticServiceConfig<T>, store: IStore);
115
- getItems<B extends T = T>(): Promise<B[]>;
116
- findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
117
- protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
118
- protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
119
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
110
+ declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
111
+ loaded: boolean;
112
+ config: StaticServiceConfig<T>;
113
+ store: IStore;
114
+ constructor(config: StaticServiceConfig<T>, store: IStore);
115
+ getItems<B extends T = T>(): Promise<B[]>;
116
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
117
+ protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
118
+ protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
119
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
120
120
  }
121
121
 
122
- declare enum StoreStrategy {
123
- Api = "api",
124
- Data = "data",
125
- Mock = "mock"
126
- }
127
- declare const storeStrategy: StoreStrategy;
128
- declare const MOCK_COLLECTIONS: string[];
129
- declare const STATIC_COLLECTIONS: string[];
130
- declare const KNOWN_COLLECTIONS: string[];
122
+ declare enum StoreStrategy {
123
+ Api = "api",
124
+ Data = "data",
125
+ Mock = "mock"
126
+ }
127
+ declare const storeStrategy: StoreStrategy;
128
+ declare const MOCK_COLLECTIONS: string[];
129
+ declare const STATIC_COLLECTIONS: string[];
130
+ declare const KNOWN_COLLECTIONS: string[];
131
131
  declare const COLLECTIONS: string[];
132
132
 
133
- declare function storeApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
134
- declare function storeApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
135
- declare function storeApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
136
- declare function storeApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
133
+ declare function storeApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
134
+ declare function storeApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
135
+ declare function storeApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
136
+ declare function storeApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
137
137
  declare function storeApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
138
138
 
139
- declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
140
- declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
141
- declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
142
- declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
143
- declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
139
+ declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
140
+ declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
141
+ declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
142
+ declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
143
+ declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
144
144
  declare function routePost(store: IStore, request: NextApiRequest, response: NextApiResponse): Promise<void>;
145
145
 
146
146
  declare function getStore<T extends IStore>(): Promise<T>;
package/dist/index.js CHANGED
@@ -1350,9 +1350,10 @@ async function routePost(store, request, response) {
1350
1350
  }
1351
1351
  };
1352
1352
  redirects.forEach((x) => {
1353
- x.from = x.from.replace(/\*/g, (...rest) => {
1354
- return "(.*)";
1355
- });
1353
+ let expression = x.from;
1354
+ expression = expression.replace(/\*(?!\))/g, "(.*)");
1355
+ expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
1356
+ x.from = expression;
1356
1357
  });
1357
1358
  const firstMatch = redirects.find((x) => href.match(x.from));
1358
1359
  if (firstMatch) {
package/dist/index.mjs CHANGED
@@ -1271,9 +1271,10 @@ async function routePost(store, request, response) {
1271
1271
  }
1272
1272
  };
1273
1273
  redirects.forEach((x) => {
1274
- x.from = x.from.replace(/\*/g, (...rest) => {
1275
- return "(.*)";
1276
- });
1274
+ let expression = x.from;
1275
+ expression = expression.replace(/\*(?!\))/g, "(.*)");
1276
+ expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
1277
+ x.from = expression;
1277
1278
  });
1278
1279
  const firstMatch = redirects.find((x) => href.match(x.from));
1279
1280
  if (firstMatch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -235,9 +235,12 @@ export async function routePost(store: IStore, request: NextApiRequest, response
235
235
  };
236
236
  // check redirects by pattern
237
237
  redirects.forEach(x => {
238
- x.from = x.from.replace(/\*/g, (...rest) => {
239
- return '(.*)';
240
- });
238
+ let expression = x.from;
239
+ // wrapping catchall in (.*)
240
+ expression = expression.replace(/\*(?!\))/g, '(.*)');
241
+ // wrapping expression in ^...$
242
+ expression = `^${expression.replace(/(^\^)|(\$$)/g, '')}$`;
243
+ x.from = expression;
241
244
  });
242
245
  // check if a regex pattern redirect does match
243
246
  const firstMatch = redirects.find(x => href.match(x.from));