@websolutespa/bom-core 0.2.1 → 0.3.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +25 -21
- package/dist/index.mjs +24 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -138,7 +138,8 @@ type FetchRequestOptions = {
|
|
|
138
138
|
keepalive?: boolean;
|
|
139
139
|
signal?: AbortSignal;
|
|
140
140
|
};
|
|
141
|
-
type FetchService<T =
|
|
141
|
+
type FetchService<T = unknown> = (url: string, options?: FetchRequestOptions, serviceOptions?: any) => Promise<T>;
|
|
142
|
+
type FetchError = any;
|
|
142
143
|
|
|
143
144
|
type ILabel = IEntity & {
|
|
144
145
|
id: IEquatable;
|
|
@@ -539,10 +540,10 @@ declare const isDevelopment: boolean;
|
|
|
539
540
|
declare const isProduction: boolean;
|
|
540
541
|
declare const isStage: boolean;
|
|
541
542
|
declare const isBrowser: boolean;
|
|
543
|
+
declare function getEnv(): Record<string, Json>;
|
|
542
544
|
declare function withSchema<Component extends {}, Schema>(component: Component, schema: Schema): Component & Schema;
|
|
543
545
|
declare function asServerProps(props: any): any;
|
|
544
546
|
declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
|
|
545
|
-
declare function merge(target: any, source: any): any;
|
|
546
|
-
declare function deepCopy<T>(source: T): T;
|
|
547
|
+
declare function merge(target: any, source: any): any;
|
|
547
548
|
|
|
548
|
-
export { FetchRequestOptions, FetchService, FindParams, FindWhereParams, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, Json, JsonService, LiteralUnion, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, collectRoutes, consoleWarn,
|
|
549
|
+
export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, Json, JsonService, LiteralUnion, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, collectRoutes, consoleWarn, deserializeKey, deserializeValue, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isBrowser, isCategory, isDevelopment, isLocalizedString, isProduction, isStage, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, qsDeserialize, qsSerialize, textToSlug, toDisplayName, toFindParams, toPluralName, toTitleCase, toValidCollectionName, withSchema };
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,6 @@ __export(src_exports, {
|
|
|
40
40
|
camelToSnakeCase: () => camelToSnakeCase,
|
|
41
41
|
collectRoutes: () => collectRoutes,
|
|
42
42
|
consoleWarn: () => consoleWarn,
|
|
43
|
-
deepCopy: () => deepCopy,
|
|
44
43
|
deserializeKey: () => deserializeKey,
|
|
45
44
|
deserializeValue: () => deserializeValue,
|
|
46
45
|
eachCategorized: () => eachCategorized,
|
|
@@ -50,6 +49,7 @@ __export(src_exports, {
|
|
|
50
49
|
getCategorySegmentsByCategory: () => getCategorySegmentsByCategory,
|
|
51
50
|
getClassNames: () => getClassNames,
|
|
52
51
|
getCollectionDescription: () => getCollectionDescription,
|
|
52
|
+
getEnv: () => getEnv,
|
|
53
53
|
getIsDevelopment: () => getIsDevelopment,
|
|
54
54
|
getIsProduction: () => getIsProduction,
|
|
55
55
|
getParentCategoriesById: () => getParentCategoriesById,
|
|
@@ -270,6 +270,14 @@ var isDevelopment = getIsDevelopment();
|
|
|
270
270
|
var isProduction = getIsProduction();
|
|
271
271
|
var isStage = !isProduction && !isDevelopment;
|
|
272
272
|
var isBrowser = typeof window !== "undefined";
|
|
273
|
+
function getEnv() {
|
|
274
|
+
const env = {};
|
|
275
|
+
const keys = Object.keys(process.env).sort();
|
|
276
|
+
keys.forEach((key) => {
|
|
277
|
+
env[key] = process.env[key];
|
|
278
|
+
});
|
|
279
|
+
return env;
|
|
280
|
+
}
|
|
273
281
|
function withSchema(component, schema) {
|
|
274
282
|
return Object.assign(component, schema);
|
|
275
283
|
}
|
|
@@ -303,19 +311,6 @@ function merge(target, source) {
|
|
|
303
311
|
}
|
|
304
312
|
return target;
|
|
305
313
|
}
|
|
306
|
-
function deepCopy(source) {
|
|
307
|
-
if (Array.isArray(source)) {
|
|
308
|
-
return source.map((x) => deepCopy(x));
|
|
309
|
-
} else if (source && typeof source === "object") {
|
|
310
|
-
const copy = {};
|
|
311
|
-
Object.keys(source).forEach((key) => {
|
|
312
|
-
copy[key] = deepCopy(source[key]);
|
|
313
|
-
});
|
|
314
|
-
return copy;
|
|
315
|
-
} else {
|
|
316
|
-
return source;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
314
|
|
|
320
315
|
// src/http/http.service.ts
|
|
321
316
|
var defaultOptions = {
|
|
@@ -332,13 +327,22 @@ var defaultOptions = {
|
|
|
332
327
|
// body: JSON.stringify(data) // body data type must match 'Content-Type' header
|
|
333
328
|
};
|
|
334
329
|
async function httpFetch(url, options = {}, serviceOptions) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
330
|
+
try {
|
|
331
|
+
const httpOptions = merge({ ...defaultOptions }, options);
|
|
332
|
+
const httpResponse = await fetch(url, httpOptions);
|
|
333
|
+
if (!httpResponse.ok) {
|
|
334
|
+
throw httpResponse;
|
|
335
|
+
}
|
|
336
|
+
const response = await httpResponse.json();
|
|
337
|
+
return response;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (typeof error === "object" && error.status) {
|
|
340
|
+
console.log("httpFetch.error", options.method, url, error.status, error.statusText);
|
|
341
|
+
} else {
|
|
342
|
+
console.log("httpFetch.error", options.method, url, error);
|
|
343
|
+
}
|
|
344
|
+
throw error;
|
|
339
345
|
}
|
|
340
|
-
const response = await httpResponse.json();
|
|
341
|
-
return response;
|
|
342
346
|
}
|
|
343
347
|
async function httpGet(url, options = {}) {
|
|
344
348
|
return await httpFetch(url, { ...options, method: "GET" });
|
|
@@ -875,7 +879,6 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
875
879
|
camelToSnakeCase,
|
|
876
880
|
collectRoutes,
|
|
877
881
|
consoleWarn,
|
|
878
|
-
deepCopy,
|
|
879
882
|
deserializeKey,
|
|
880
883
|
deserializeValue,
|
|
881
884
|
eachCategorized,
|
|
@@ -885,6 +888,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
885
888
|
getCategorySegmentsByCategory,
|
|
886
889
|
getClassNames,
|
|
887
890
|
getCollectionDescription,
|
|
891
|
+
getEnv,
|
|
888
892
|
getIsDevelopment,
|
|
889
893
|
getIsProduction,
|
|
890
894
|
getParentCategoriesById,
|
package/dist/index.mjs
CHANGED
|
@@ -183,6 +183,14 @@ var isDevelopment = getIsDevelopment();
|
|
|
183
183
|
var isProduction = getIsProduction();
|
|
184
184
|
var isStage = !isProduction && !isDevelopment;
|
|
185
185
|
var isBrowser = typeof window !== "undefined";
|
|
186
|
+
function getEnv() {
|
|
187
|
+
const env = {};
|
|
188
|
+
const keys = Object.keys(process.env).sort();
|
|
189
|
+
keys.forEach((key) => {
|
|
190
|
+
env[key] = process.env[key];
|
|
191
|
+
});
|
|
192
|
+
return env;
|
|
193
|
+
}
|
|
186
194
|
function withSchema(component, schema) {
|
|
187
195
|
return Object.assign(component, schema);
|
|
188
196
|
}
|
|
@@ -216,19 +224,6 @@ function merge(target, source) {
|
|
|
216
224
|
}
|
|
217
225
|
return target;
|
|
218
226
|
}
|
|
219
|
-
function deepCopy(source) {
|
|
220
|
-
if (Array.isArray(source)) {
|
|
221
|
-
return source.map((x) => deepCopy(x));
|
|
222
|
-
} else if (source && typeof source === "object") {
|
|
223
|
-
const copy = {};
|
|
224
|
-
Object.keys(source).forEach((key) => {
|
|
225
|
-
copy[key] = deepCopy(source[key]);
|
|
226
|
-
});
|
|
227
|
-
return copy;
|
|
228
|
-
} else {
|
|
229
|
-
return source;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
227
|
|
|
233
228
|
// src/http/http.service.ts
|
|
234
229
|
var defaultOptions = {
|
|
@@ -245,13 +240,22 @@ var defaultOptions = {
|
|
|
245
240
|
// body: JSON.stringify(data) // body data type must match 'Content-Type' header
|
|
246
241
|
};
|
|
247
242
|
async function httpFetch(url, options = {}, serviceOptions) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
243
|
+
try {
|
|
244
|
+
const httpOptions = merge({ ...defaultOptions }, options);
|
|
245
|
+
const httpResponse = await fetch(url, httpOptions);
|
|
246
|
+
if (!httpResponse.ok) {
|
|
247
|
+
throw httpResponse;
|
|
248
|
+
}
|
|
249
|
+
const response = await httpResponse.json();
|
|
250
|
+
return response;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (typeof error === "object" && error.status) {
|
|
253
|
+
console.log("httpFetch.error", options.method, url, error.status, error.statusText);
|
|
254
|
+
} else {
|
|
255
|
+
console.log("httpFetch.error", options.method, url, error);
|
|
256
|
+
}
|
|
257
|
+
throw error;
|
|
252
258
|
}
|
|
253
|
-
const response = await httpResponse.json();
|
|
254
|
-
return response;
|
|
255
259
|
}
|
|
256
260
|
async function httpGet(url, options = {}) {
|
|
257
261
|
return await httpFetch(url, { ...options, method: "GET" });
|
|
@@ -787,7 +791,6 @@ export {
|
|
|
787
791
|
camelToSnakeCase,
|
|
788
792
|
collectRoutes,
|
|
789
793
|
consoleWarn,
|
|
790
|
-
deepCopy,
|
|
791
794
|
deserializeKey,
|
|
792
795
|
deserializeValue,
|
|
793
796
|
eachCategorized,
|
|
@@ -797,6 +800,7 @@ export {
|
|
|
797
800
|
getCategorySegmentsByCategory,
|
|
798
801
|
getClassNames,
|
|
799
802
|
getCollectionDescription,
|
|
803
|
+
getEnv,
|
|
800
804
|
getIsDevelopment,
|
|
801
805
|
getIsProduction,
|
|
802
806
|
getParentCategoriesById,
|