@websolutespa/bom-mixer-store 1.7.5 → 1.7.7

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,5 +1,17 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.7.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: getRemoteApiRequestOptions, getLocalApiRequestOptions
8
+
9
+ ## 1.7.6
10
+
11
+ ### Patch Changes
12
+
13
+ - 1b93080: Modified: default authorization api-key
14
+
3
15
  ## 1.7.5
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,8 +4,11 @@ import { NextRequest } from 'next/server';
4
4
  import * as _websolutespa_bom_mixer_store from '@websolutespa/bom-mixer-store';
5
5
 
6
6
  type ApiRequestOptions = FetchRequestOptions;
7
- declare const defaultApiRequestOptions: ApiRequestOptions;
8
- declare function getDefaultApiRequestOptions(): ApiRequestOptions;
7
+ /**
8
+ * !!! todo: evaluate authenticated end user bearer
9
+ */
10
+ declare function getLocalApiRequestOptions(): ApiRequestOptions;
11
+ declare function getRemoteApiRequestOptions(): ApiRequestOptions;
9
12
 
10
13
  type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
11
14
  type IHandler<T = any> = (request: NextApiRequest, response: NextApiResponse<T>) => Promise<NextApiResponse<T> | void>;
@@ -239,4 +242,4 @@ declare function getStore<T extends IStore>(): Promise<T>;
239
242
 
240
243
  declare function varsHandler(): _websolutespa_bom_mixer_store.IHandler<any>;
241
244
 
242
- export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, findRoute, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
245
+ export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
package/dist/index.js CHANGED
@@ -69,14 +69,14 @@ __export(src_exports, {
69
69
  decorateSchemas_: () => decorateSchemas_,
70
70
  decorateStaticRelation_: () => decorateStaticRelation_,
71
71
  decorateStaticRelations_: () => decorateStaticRelations_,
72
- defaultApiRequestOptions: () => defaultApiRequestOptions,
73
72
  errorHandler: () => errorHandler,
74
73
  findRoute: () => findRoute,
75
74
  fromCache: () => fromCache,
76
- getDefaultApiRequestOptions: () => getDefaultApiRequestOptions,
75
+ getLocalApiRequestOptions: () => getLocalApiRequestOptions,
77
76
  getLocalApiUrl: () => getLocalApiUrl,
78
77
  getMockStore: () => getMockStore,
79
78
  getMockStoreFromData_: () => getMockStoreFromData_,
79
+ getRemoteApiRequestOptions: () => getRemoteApiRequestOptions,
80
80
  getRemoteApiUrl: () => getRemoteApiUrl,
81
81
  getRemoteStore: () => getRemoteStore,
82
82
  getStore: () => getStore,
@@ -121,18 +121,23 @@ __export(src_exports, {
121
121
  module.exports = __toCommonJS(src_exports);
122
122
 
123
123
  // src/api/api.ts
124
- var STORE_BEARER = process.env.STORE_BEARER;
125
- var defaultApiRequestOptions = {
126
- // mode: 'cors',
127
- headers: {
128
- Authorization: `Bearer ${STORE_BEARER}`
129
- }
130
- };
131
- function getDefaultApiRequestOptions() {
124
+ function getLocalApiRequestOptions() {
125
+ return {
126
+ headers: {}
127
+ };
128
+ }
129
+ function getRemoteApiRequestOptions() {
132
130
  return {
133
131
  // mode: 'cors',
134
132
  headers: {
135
- Authorization: `Bearer ${process.env.STORE_BEARER}`
133
+ /**
134
+ * guest user api key (users)
135
+ */
136
+ Authorization: `users API-Key ${process.env.STORE_API_KEY}`
137
+ /**
138
+ * authenticated end user bearer (end_users)
139
+ */
140
+ // Authorization: `Bearer ${bearer}`,
136
141
  }
137
142
  };
138
143
  }
@@ -422,6 +427,7 @@ function decorateMenuRoute_(item) {
422
427
  type: "route",
423
428
  title: item.title,
424
429
  href: item.id,
430
+ media: item.media,
425
431
  page: item.page,
426
432
  schema: item.schema,
427
433
  items: []
@@ -626,7 +632,7 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
626
632
  url.searchParams.append("locale", serviceOptions.locale);
627
633
  url.searchParams.append("market", serviceOptions.market);
628
634
  }
629
- const apiOptions = (0, import_bom_core6.merge)({ ...getDefaultApiRequestOptions() }, options);
635
+ const apiOptions = (0, import_bom_core6.merge)({ ...getLocalApiRequestOptions() }, options);
630
636
  console.log("localApiFetch", apiOptions.method, url.href);
631
637
  const apiResponse = await (0, import_bom_core6.httpFetch)(url.href, apiOptions);
632
638
  return apiResponse;
@@ -763,7 +769,7 @@ function getMockApiUrl(pathname) {
763
769
  }
764
770
  async function mockApiFetch(pathname, options = {}) {
765
771
  const url = getMockApiUrl(pathname);
766
- const apiOptions = (0, import_bom_core8.merge)({ ...getDefaultApiRequestOptions() }, options);
772
+ const apiOptions = (0, import_bom_core8.merge)({ ...getLocalApiRequestOptions() }, options);
767
773
  console.log("mockApiFetch", apiOptions.method, url);
768
774
  const apiResponse = await (0, import_bom_core8.httpFetch)(url, apiOptions);
769
775
  return apiResponse;
@@ -1359,7 +1365,7 @@ function getRemoteApiUrl(pathname) {
1359
1365
  }
1360
1366
  async function remoteApiFetch(pathname, options = {}) {
1361
1367
  const url = getRemoteApiUrl(pathname);
1362
- const apiOptions = (0, import_bom_core12.merge)({ ...getDefaultApiRequestOptions() }, options);
1368
+ const apiOptions = (0, import_bom_core12.merge)({ ...getRemoteApiRequestOptions() }, options);
1363
1369
  console.log("remoteApiFetch", apiOptions.method, url);
1364
1370
  const apiResponse = await (0, import_bom_core12.httpFetch)(url, apiOptions);
1365
1371
  return apiResponse;
@@ -2335,14 +2341,14 @@ function varsHandler() {
2335
2341
  decorateSchemas_,
2336
2342
  decorateStaticRelation_,
2337
2343
  decorateStaticRelations_,
2338
- defaultApiRequestOptions,
2339
2344
  errorHandler,
2340
2345
  findRoute,
2341
2346
  fromCache,
2342
- getDefaultApiRequestOptions,
2347
+ getLocalApiRequestOptions,
2343
2348
  getLocalApiUrl,
2344
2349
  getMockStore,
2345
2350
  getMockStoreFromData_,
2351
+ getRemoteApiRequestOptions,
2346
2352
  getRemoteApiUrl,
2347
2353
  getRemoteStore,
2348
2354
  getStore,
package/dist/index.mjs CHANGED
@@ -7,18 +7,23 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  });
8
8
 
9
9
  // src/api/api.ts
10
- var STORE_BEARER = process.env.STORE_BEARER;
11
- var defaultApiRequestOptions = {
12
- // mode: 'cors',
13
- headers: {
14
- Authorization: `Bearer ${STORE_BEARER}`
15
- }
16
- };
17
- function getDefaultApiRequestOptions() {
10
+ function getLocalApiRequestOptions() {
11
+ return {
12
+ headers: {}
13
+ };
14
+ }
15
+ function getRemoteApiRequestOptions() {
18
16
  return {
19
17
  // mode: 'cors',
20
18
  headers: {
21
- Authorization: `Bearer ${process.env.STORE_BEARER}`
19
+ /**
20
+ * guest user api key (users)
21
+ */
22
+ Authorization: `users API-Key ${process.env.STORE_API_KEY}`
23
+ /**
24
+ * authenticated end user bearer (end_users)
25
+ */
26
+ // Authorization: `Bearer ${bearer}`,
22
27
  }
23
28
  };
24
29
  }
@@ -312,6 +317,7 @@ function decorateMenuRoute_(item) {
312
317
  type: "route",
313
318
  title: item.title,
314
319
  href: item.id,
320
+ media: item.media,
315
321
  page: item.page,
316
322
  schema: item.schema,
317
323
  items: []
@@ -516,7 +522,7 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
516
522
  url.searchParams.append("locale", serviceOptions.locale);
517
523
  url.searchParams.append("market", serviceOptions.market);
518
524
  }
519
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
525
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
520
526
  console.log("localApiFetch", apiOptions.method, url.href);
521
527
  const apiResponse = await httpFetch(url.href, apiOptions);
522
528
  return apiResponse;
@@ -653,7 +659,7 @@ function getMockApiUrl(pathname) {
653
659
  }
654
660
  async function mockApiFetch(pathname, options = {}) {
655
661
  const url = getMockApiUrl(pathname);
656
- const apiOptions = merge2({ ...getDefaultApiRequestOptions() }, options);
662
+ const apiOptions = merge2({ ...getLocalApiRequestOptions() }, options);
657
663
  console.log("mockApiFetch", apiOptions.method, url);
658
664
  const apiResponse = await httpFetch2(url, apiOptions);
659
665
  return apiResponse;
@@ -1249,7 +1255,7 @@ function getRemoteApiUrl(pathname) {
1249
1255
  }
1250
1256
  async function remoteApiFetch(pathname, options = {}) {
1251
1257
  const url = getRemoteApiUrl(pathname);
1252
- const apiOptions = merge3({ ...getDefaultApiRequestOptions() }, options);
1258
+ const apiOptions = merge3({ ...getRemoteApiRequestOptions() }, options);
1253
1259
  console.log("remoteApiFetch", apiOptions.method, url);
1254
1260
  const apiResponse = await httpFetch3(url, apiOptions);
1255
1261
  return apiResponse;
@@ -2224,14 +2230,14 @@ export {
2224
2230
  decorateSchemas_,
2225
2231
  decorateStaticRelation_,
2226
2232
  decorateStaticRelations_,
2227
- defaultApiRequestOptions,
2228
2233
  errorHandler,
2229
2234
  findRoute,
2230
2235
  fromCache,
2231
- getDefaultApiRequestOptions,
2236
+ getLocalApiRequestOptions,
2232
2237
  getLocalApiUrl,
2233
2238
  getMockStore,
2234
2239
  getMockStoreFromData_,
2240
+ getRemoteApiRequestOptions,
2235
2241
  getRemoteApiUrl,
2236
2242
  getRemoteStore,
2237
2243
  getStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
package/src/api/api.ts CHANGED
@@ -2,20 +2,29 @@ import { FetchRequestOptions } from '@websolutespa/bom-core';
2
2
 
3
3
  export type ApiRequestOptions = FetchRequestOptions;
4
4
 
5
- const STORE_BEARER = process.env.STORE_BEARER;
5
+ /**
6
+ * !!! todo: evaluate authenticated end user bearer
7
+ */
6
8
 
7
- export const defaultApiRequestOptions: ApiRequestOptions = {
8
- // mode: 'cors',
9
- headers: {
10
- Authorization: `Bearer ${STORE_BEARER}`,
11
- },
12
- };
9
+ export function getLocalApiRequestOptions(): ApiRequestOptions {
10
+ return {
11
+ headers: {
12
+ },
13
+ };
14
+ }
13
15
 
14
- export function getDefaultApiRequestOptions(): ApiRequestOptions {
16
+ export function getRemoteApiRequestOptions(): ApiRequestOptions {
15
17
  return {
16
18
  // mode: 'cors',
17
19
  headers: {
18
- Authorization: `Bearer ${process.env.STORE_BEARER}`,
20
+ /**
21
+ * guest user api key (users)
22
+ */
23
+ Authorization: `users API-Key ${process.env.STORE_API_KEY}`,
24
+ /**
25
+ * authenticated end user bearer (end_users)
26
+ */
27
+ // Authorization: `Bearer ${bearer}`,
19
28
  },
20
29
  };
21
30
  }
@@ -168,6 +168,7 @@ function decorateMenuRoute_(
168
168
  type: 'route',
169
169
  title: item.title,
170
170
  href: item.id,
171
+ media: item.media,
171
172
  page: item.page,
172
173
  schema: item.schema,
173
174
  items: [],
@@ -1,5 +1,5 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getLocalApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to local api (mixer)
@@ -27,7 +27,7 @@ export async function localApiFetch<T = unknown>(pathname: string, options: ApiR
27
27
  url.searchParams.append('locale', serviceOptions.locale);
28
28
  url.searchParams.append('market', serviceOptions.market);
29
29
  }
30
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
30
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
31
31
  console.log('localApiFetch', apiOptions.method, url.href);
32
32
  const apiResponse = await httpFetch(url.href, apiOptions);
33
33
  // console.log('localApiFetch', pathname, apiResponse);
@@ -1,10 +1,9 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getLocalApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to local /api/_mock data
6
6
  */
7
-
8
7
  const API_URL = process.env.NEXT_PUBLIC_URL;
9
8
  const API_BASE = process.env.NEXT_PUBLIC_API || '/api';
10
9
 
@@ -18,7 +17,7 @@ function getMockApiUrl(pathname: string): string {
18
17
 
19
18
  export async function mockApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}): Promise<T> {
20
19
  const url = getMockApiUrl(pathname);
21
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
20
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
22
21
  console.log('mockApiFetch', apiOptions.method, url);
23
22
  const apiResponse = await httpFetch(url, apiOptions);
24
23
  return apiResponse;
@@ -1,5 +1,5 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getRemoteApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to remote api (bowl or over)
@@ -18,7 +18,7 @@ export function getRemoteApiUrl(pathname: string): string {
18
18
 
19
19
  export async function remoteApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}): Promise<T> {
20
20
  const url = getRemoteApiUrl(pathname);
21
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
21
+ const apiOptions = merge({ ...getRemoteApiRequestOptions() }, options);
22
22
  console.log('remoteApiFetch', apiOptions.method, url);
23
23
  const apiResponse = await httpFetch(url, apiOptions);
24
24
  return apiResponse;