@websolutespa/bom-mixer-models 0.0.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +17 -0
  2. package/CHANGELOG.md +7 -0
  3. package/dist/index.d.ts +409 -0
  4. package/dist/index.js +2574 -0
  5. package/dist/index.mjs +2519 -0
  6. package/package.json +54 -0
  7. package/src/cart/cart.ts +31 -0
  8. package/src/category/category.service.ts +43 -0
  9. package/src/category/category.ts +26 -0
  10. package/src/checkout/checkout.service.ts +351 -0
  11. package/src/checkout/checkout.ts +65 -0
  12. package/src/country/country.service.ts +9 -0
  13. package/src/feature_type/feature_type.service.ts +10 -0
  14. package/src/feature_type/feature_type.ts +13 -0
  15. package/src/index.ts +33 -0
  16. package/src/label/label.service.ts +24 -0
  17. package/src/label/label.ts +7 -0
  18. package/src/layout/layout.service.ts +51 -0
  19. package/src/layout/layout.ts +27 -0
  20. package/src/link/link.ts +7 -0
  21. package/src/list/list.service.ts +19 -0
  22. package/src/list/list.ts +11 -0
  23. package/src/locale/locale.service.ts +11 -0
  24. package/src/locale/locale.ts +9 -0
  25. package/src/market/market.service.ts +10 -0
  26. package/src/market/market.ts +11 -0
  27. package/src/media/media.ts +14 -0
  28. package/src/menu/menu.service.ts +22 -0
  29. package/src/menu/menu.ts +11 -0
  30. package/src/order/order.service.ts +29 -0
  31. package/src/order/order.ts +31 -0
  32. package/src/page/page.service.ts +132 -0
  33. package/src/page/page.ts +53 -0
  34. package/src/province/province.service.ts +9 -0
  35. package/src/region/region.service.ts +9 -0
  36. package/src/route/route.interceptor.ts +30 -0
  37. package/src/route/route.service.ts +203 -0
  38. package/src/route/route.ts +29 -0
  39. package/src/store/store.ts +24 -0
  40. package/src/user/user.ts +57 -0
  41. package/tsconfig.json +16 -0
@@ -0,0 +1,203 @@
1
+ import { isLocalizedString, localizedToString, QueryParams } from '@websolutespa/bom-mixer-core';
2
+ import { getStore } from '@websolutespa/bom-mixer-store';
3
+ import { ICategory } from '../category/category';
4
+ import { IModelStore } from '../store/store';
5
+ import { IRoute, IRouteLink } from './route';
6
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
7
+
8
+ export async function getRoutes(params: QueryParams = {}): Promise<IRoute[]> {
9
+ const store = await getStore<IModelStore>();
10
+ const routes = await store.route.findMany(params);
11
+ return routes;
12
+ }
13
+
14
+ export async function getRoute(id: string): Promise<IRoute | undefined> {
15
+ const store = await getStore<IModelStore>();
16
+ const route = await store.route.findOne({
17
+ where: {
18
+ id: {
19
+ equals: id,
20
+ }
21
+ }
22
+ });
23
+ // console.log('RouteService.getRoute', id, '->', route);
24
+ return route;
25
+ }
26
+
27
+ export async function getRoutesForSchemas(schemas: string[], market?: string, locale?: string): Promise<{ [key: string]: string; }> {
28
+ const store = await getStore<IModelStore>();
29
+ const routes = await store.route.findMany({
30
+ where: {
31
+ schema: {
32
+ in: schemas,
33
+ },
34
+ market: {
35
+ equals: market,
36
+ },
37
+ locale: {
38
+ equals: locale,
39
+ },
40
+ }, market, locale
41
+ });
42
+ const items: {
43
+ [key: string]: string;
44
+ } = {};
45
+ routes.forEach(route => {
46
+ items[route.schema] = route.id;
47
+ });
48
+ return items;
49
+ }
50
+
51
+ export async function getRoutesForTemplates(templates: string[], market?: string, locale?: string): Promise<{ [key: string]: string; }> {
52
+ const store = await getStore<IModelStore>();
53
+ const routes = await store.route.findMany({
54
+ where: {
55
+ template: {
56
+ in: templates,
57
+ },
58
+ market: {
59
+ equals: market,
60
+ },
61
+ locale: {
62
+ equals: locale,
63
+ },
64
+ }, market, locale
65
+ });
66
+ const items: {
67
+ [key: string]: string;
68
+ } = {};
69
+ routes.forEach(route => {
70
+ if (route.template) {
71
+ items[route.template] = route.id;
72
+ }
73
+ });
74
+ return items;
75
+ }
76
+
77
+ export async function getStaticPathsForSchema(schema: string): Promise<StaticPath[]> {
78
+ const store = await getStore<IModelStore>();
79
+ const routes = await store.route.findMany({
80
+ where: {
81
+ schema: {
82
+ equals: schema
83
+ }
84
+ }
85
+ });
86
+ return routes.map((x: any) => ({ params: { id: x.page.toString(), market: x.market, locale: x.locale } }));
87
+ }
88
+
89
+ export async function decorateHref(item: any, market: string = 'ww', locale: string = 'en'): Promise<any> {
90
+ const routes = await getRoutes({
91
+ where: {
92
+ schema: {
93
+ equals: item.schema
94
+ },
95
+ page: {
96
+ equals: item.id
97
+ },
98
+ market: {
99
+ equals: market
100
+ },
101
+ locale: {
102
+ equals: locale
103
+ },
104
+ }
105
+ });
106
+ const href = routes.length ? routes[0].id : null;
107
+ return { ...item, href };
108
+ }
109
+
110
+ export async function getBreadcrumbFromSegments(segments: ICategory[], market: string = 'ww', locale: string = 'en'): Promise<IRouteLink[]> {
111
+ const routes: IRoute[] = await getRoutes({
112
+ where: {
113
+ market: {
114
+ equals: market
115
+ },
116
+ locale: {
117
+ equals: locale
118
+ },
119
+ }
120
+ });
121
+ const tree: IRouteLink[] = segments.map(segment => {
122
+ const route = segment.schema && segment.page ? routes.find(r =>
123
+ r.schema === segment.schema &&
124
+ r.page === segment.page
125
+ ) : undefined;
126
+ const href = route ? route.id.toString() : '/#';
127
+ return { segment, href };
128
+ }).map(x => {
129
+ const segment: ICategory = x.segment;
130
+ const href: string = x.href;
131
+ let title = segment.title || 'untitled';
132
+ if (isLocalizedString(title)) {
133
+ title = localizedToString(title, locale);
134
+ }
135
+ return {
136
+ id: segment.id,
137
+ title: title,
138
+ href,
139
+ items: [],
140
+ };
141
+ });
142
+ return tree;
143
+ }
144
+
145
+ export async function getRouteLinkTree(market: string = 'ww', locale: string = 'en'): Promise<IRouteLink | undefined> {
146
+ const store = await getStore<IModelStore>();
147
+ const routes = await store.route.findMany({
148
+ where: {
149
+ market: {
150
+ equals: market,
151
+ },
152
+ locale: {
153
+ equals: locale,
154
+ },
155
+ }, market, locale
156
+ });
157
+ const categories = await store.category.findMany();
158
+ /*
159
+ const routes: Route[] = await getRoutes();
160
+ const categories = await getCategories();
161
+ */
162
+ const homepage = categories.find(x => x.id === 'homepage');
163
+ if (homepage) {
164
+ const root = categoryToRouteLink(routes, categories, homepage, locale);
165
+ // console.log('getRouteLinkTree', root);
166
+ return root;
167
+ }
168
+ return undefined;
169
+ }
170
+
171
+ export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string = 'en'): IRouteLink {
172
+ const route = routes.find(r =>
173
+ r.category === category.id
174
+ );
175
+ const href = route ? route.id.toString() : '/#';
176
+ let title = category.title || 'untitled';
177
+ if (isLocalizedString(title)) {
178
+ title = localizedToString(title, locale);
179
+ }
180
+ const childCategories = categories.filter(x => {
181
+ const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
182
+ return category.id === 'homepage' ?
183
+ (x.id !== 'homepage' && (parentId === category.id || !parentId)) :
184
+ parentId === category.id;
185
+ });
186
+ // console.log('childCategories', category.id, childCategories);
187
+ return {
188
+ id: category.id,
189
+ title,
190
+ href,
191
+ media: category.media,
192
+ items: childCategories.map(x => categoryToRouteLink(routes, categories, x, locale)),
193
+ };
194
+ }
195
+
196
+ export function resolveRoute(route: IRoute) {
197
+ const routepath: string = route.template ? route.template : route.schema;
198
+ const resolvedPathname = `/${route.market}/${route.locale}/${routepath}/${route.page}`;
199
+ // console.log('resolveRoute', route.schema, resolvedPathname);
200
+ return resolvedPathname;
201
+ }
202
+
203
+ export type StaticPath = { params: { [key: string]: string } };
@@ -0,0 +1,29 @@
1
+ import { IEquatable } from '@websolutespa/bom-mixer-core';
2
+ import { IMedia } from '../media/media';
3
+
4
+ export type IRoute = {
5
+ id: string;
6
+ market: string;
7
+ locale: string;
8
+ category: string;
9
+ page: IEquatable;
10
+ schema: string;
11
+ template?: string;
12
+ };
13
+
14
+ export type IRouteLink = {
15
+ id: IEquatable;
16
+ href: string;
17
+ title: string;
18
+ items?: IRouteLink[];
19
+ media?: IMedia;
20
+ };
21
+
22
+ export type IRouteParams = {
23
+ id: IEquatable,
24
+ market: string,
25
+ locale: string,
26
+ [key: string]: any,
27
+ };
28
+
29
+ export type SchemaType = string;
@@ -0,0 +1,24 @@
1
+ import { IEntity, INamedEntity, IQuerable } from '@websolutespa/bom-mixer-core';
2
+ import { ICategory } from '../category/category';
3
+ import { IFeatureType } from '../feature_type/feature_type';
4
+ import { ILabel } from '../label/label';
5
+ import { IList } from '../list/list';
6
+ import { ILocale } from '../locale/locale';
7
+ import { IMarket } from '../market/market';
8
+ import { IMenu } from '../menu/menu';
9
+ import { IRoute } from '../route/route';
10
+
11
+ export type IModelStore = {
12
+ category: IQuerable<ICategory>;
13
+ feature_type: IQuerable<IFeatureType>;
14
+ label: IQuerable<ILabel>;
15
+ list: IQuerable<IList>;
16
+ locale: IQuerable<ILocale>;
17
+ market: IQuerable<IMarket>;
18
+ menu: IQuerable<IMenu>;
19
+ route: IQuerable<IRoute>;
20
+ i18n_country: IQuerable<INamedEntity>;
21
+ i18n_province: IQuerable<INamedEntity>;
22
+ i18n_region: IQuerable<INamedEntity>;
23
+ [key: string]: IQuerable<IEntity>;
24
+ };
@@ -0,0 +1,57 @@
1
+ import { IEquatable, IOption, ISchema } from '@websolutespa/bom-mixer-core';
2
+
3
+ export type IUserLogin = {
4
+ email: string;
5
+ password: string;
6
+ rememberMe: boolean;
7
+ };
8
+
9
+ export type IUserRegister = {
10
+ firstName: string;
11
+ lastName: string;
12
+ email: string;
13
+ password: string;
14
+ confirmPassword: string;
15
+ privacy: boolean;
16
+ };
17
+
18
+ export type IUserForgot = {
19
+ email: string;
20
+ };
21
+
22
+ export type IUserChangePassword = {
23
+ oldPassword: string;
24
+ newPassword: string;
25
+ confirmNewPassword: string;
26
+ };
27
+
28
+ export type IUser = ISchema & {
29
+ id: IEquatable;
30
+ firstName: string;
31
+ lastName: string;
32
+ email: string;
33
+ };
34
+
35
+ export type IAddress = {
36
+ name: string;
37
+ firstName: string;
38
+ lastName: string;
39
+ address: string,
40
+ streetNumber: string,
41
+ zipCode: string;
42
+ city: string;
43
+ country: IOption;
44
+ region?: IOption,
45
+ province?: IOption,
46
+ email: string;
47
+ phoneNumber: string;
48
+ };
49
+
50
+ export type IAddressOptions = {
51
+ countries: IOption[];
52
+ regions: IOption[];
53
+ provinces: IOption[];
54
+ };
55
+
56
+ export type IUserAddress = Omit<IAddress, 'name'>;
57
+ export type ICompanyAddress = Omit<IAddress, 'firstName' | 'lastName'>;
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "@websolutespa/tsconfig/tsnode.json",
3
+ "include": [
4
+ "."
5
+ ],
6
+ "exclude": [
7
+ "node_modules",
8
+ "dist",
9
+ "build",
10
+ "coverage"
11
+ ],
12
+ "compilerOptions": {
13
+ "baseUrl": ".",
14
+ "rootDir": "."
15
+ }
16
+ }