@lasterp/shared 1.0.0-beta.17 → 1.0.0-beta.19
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/dist/index.cjs +59 -7
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +59 -7
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -63,16 +63,70 @@ __export(exports_src, {
|
|
|
63
63
|
useFrappeDeleteCall: () => useFrappeDeleteCall,
|
|
64
64
|
useFrappeCreateDoc: () => useFrappeCreateDoc,
|
|
65
65
|
useFrappeAuth: () => useFrappeAuth,
|
|
66
|
+
screenFormSchema: () => screenFormSchema,
|
|
67
|
+
modelFormSchema: () => modelFormSchema,
|
|
68
|
+
itemFormSchema: () => itemFormSchema,
|
|
66
69
|
equalsIgnoreCase: () => equalsIgnoreCase,
|
|
67
70
|
decamelizeKeys: () => import_humps.decamelizeKeys,
|
|
68
71
|
decamelize: () => import_humps.decamelize,
|
|
72
|
+
colourFormSchema: () => colourFormSchema,
|
|
69
73
|
camelizeKeys: () => import_humps.camelizeKeys,
|
|
70
74
|
camelize: () => import_humps.camelize,
|
|
71
75
|
LocaleProvider: () => LocaleProvider,
|
|
72
76
|
FrappeProvider: () => FrappeProvider,
|
|
73
|
-
FrappeContext: () => FrappeContext
|
|
77
|
+
FrappeContext: () => FrappeContext,
|
|
78
|
+
COLOR_SYSTEMS: () => COLOR_SYSTEMS,
|
|
79
|
+
ATTRIBUTES: () => ATTRIBUTES
|
|
74
80
|
});
|
|
75
81
|
module.exports = __toCommonJS(exports_src);
|
|
82
|
+
// src/catalog/schema.ts
|
|
83
|
+
var import_zod = require("zod");
|
|
84
|
+
var ATTRIBUTES = ["Colour", "Storage", "Memory", "Screen"];
|
|
85
|
+
var COLOR_SYSTEMS = [
|
|
86
|
+
"White",
|
|
87
|
+
"Black",
|
|
88
|
+
"Yellow",
|
|
89
|
+
"Red",
|
|
90
|
+
"Green",
|
|
91
|
+
"Blue",
|
|
92
|
+
"Purple",
|
|
93
|
+
"Orange",
|
|
94
|
+
"Pink",
|
|
95
|
+
"Brown",
|
|
96
|
+
"Gray",
|
|
97
|
+
"Silver",
|
|
98
|
+
"Gold"
|
|
99
|
+
];
|
|
100
|
+
var colourFormSchema = import_zod.z.object({
|
|
101
|
+
color: import_zod.z.string().min(1, "Color is required"),
|
|
102
|
+
color_hex: import_zod.z.string().optional(),
|
|
103
|
+
color_system: import_zod.z.enum(COLOR_SYSTEMS).optional(),
|
|
104
|
+
images: import_zod.z.array(import_zod.z.union([import_zod.z.instanceof(File), import_zod.z.string()])).default([])
|
|
105
|
+
});
|
|
106
|
+
var screenFormSchema = import_zod.z.object({
|
|
107
|
+
screen: import_zod.z.string().min(1, "Screen is required"),
|
|
108
|
+
height: import_zod.z.number().positive().optional(),
|
|
109
|
+
width: import_zod.z.number().positive().optional(),
|
|
110
|
+
weight: import_zod.z.number().positive().optional()
|
|
111
|
+
});
|
|
112
|
+
var modelFormSchema = import_zod.z.object({
|
|
113
|
+
model: import_zod.z.string().min(1, "Model is required"),
|
|
114
|
+
sim_card_type: import_zod.z.string().optional(),
|
|
115
|
+
connectivity: import_zod.z.array(import_zod.z.string())
|
|
116
|
+
});
|
|
117
|
+
var itemFormSchema = import_zod.z.object({
|
|
118
|
+
item_code: import_zod.z.string().min(1, "Item code is required"),
|
|
119
|
+
item_group: import_zod.z.string().optional(),
|
|
120
|
+
brand: import_zod.z.string().optional(),
|
|
121
|
+
os: import_zod.z.string().optional(),
|
|
122
|
+
release_year: import_zod.z.number().int().min(1900).max(2100).optional(),
|
|
123
|
+
attributes: import_zod.z.array(import_zod.z.enum(ATTRIBUTES)),
|
|
124
|
+
colours: import_zod.z.array(colourFormSchema),
|
|
125
|
+
storages: import_zod.z.array(import_zod.z.string()),
|
|
126
|
+
memories: import_zod.z.array(import_zod.z.string()),
|
|
127
|
+
screens: import_zod.z.array(screenFormSchema),
|
|
128
|
+
models: import_zod.z.array(modelFormSchema)
|
|
129
|
+
});
|
|
76
130
|
// src/frappe/provider.tsx
|
|
77
131
|
var import_react = require("react");
|
|
78
132
|
var import_frappe_js_sdk = require("frappe-js-sdk");
|
|
@@ -238,11 +292,9 @@ var useFrappeGetCall = (method, params, options, type = "GET") => {
|
|
|
238
292
|
queryFn: async () => {
|
|
239
293
|
if (type === "GET") {
|
|
240
294
|
const response = await call.get(method, params);
|
|
241
|
-
console.log("Response", response);
|
|
242
295
|
return response.message;
|
|
243
296
|
} else {
|
|
244
297
|
const response = await call.post(method, params);
|
|
245
|
-
console.log("Response", response);
|
|
246
298
|
return response.message;
|
|
247
299
|
}
|
|
248
300
|
},
|
|
@@ -458,7 +510,7 @@ var useFrappeGetDoc = (doctype, name, options) => {
|
|
|
458
510
|
const { data, error, isLoading, isFetching, refetch } = import_react_query7.useQuery({
|
|
459
511
|
queryKey,
|
|
460
512
|
queryFn: () => db.getDoc(doctype, name),
|
|
461
|
-
enabled:
|
|
513
|
+
enabled: options?.enabled ?? true,
|
|
462
514
|
staleTime: options?.staleTime ?? 5 * 60 * 1000,
|
|
463
515
|
retry: options?.retry ?? false
|
|
464
516
|
});
|
|
@@ -704,10 +756,10 @@ function LocaleProvider({
|
|
|
704
756
|
}, [language, storage]);
|
|
705
757
|
const { data, isLoading } = useFrappeGetCall(method, { lang: language }, { staleTime: Infinity });
|
|
706
758
|
import_react16.useEffect(() => {
|
|
707
|
-
if (!data
|
|
759
|
+
if (!data)
|
|
708
760
|
return;
|
|
709
|
-
setMessages(data
|
|
710
|
-
storage?.setItem(`locale:${language}`, JSON.stringify(data
|
|
761
|
+
setMessages(data);
|
|
762
|
+
storage?.setItem(`locale:${language}`, JSON.stringify(data));
|
|
711
763
|
}, [data, language, storage]);
|
|
712
764
|
const __ = import_react16.useCallback((message, replace) => translate(message, replace, messages), [messages]);
|
|
713
765
|
if (isLoading && Object.keys(messages).length === 0)
|
package/dist/index.d.cts
CHANGED
|
@@ -38,6 +38,14 @@ interface Image {
|
|
|
38
38
|
image: string;
|
|
39
39
|
color: string;
|
|
40
40
|
}
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
declare const ATTRIBUTES: readonly ["Colour", "Storage", "Memory", "Screen"];
|
|
43
|
+
declare const COLOR_SYSTEMS: readonly ["White", "Black", "Yellow", "Red", "Green", "Blue", "Purple", "Orange", "Pink", "Brown", "Gray", "Silver", "Gold"];
|
|
44
|
+
declare const colourFormSchema: unknown;
|
|
45
|
+
declare const screenFormSchema: unknown;
|
|
46
|
+
declare const modelFormSchema: unknown;
|
|
47
|
+
declare const itemFormSchema: unknown;
|
|
48
|
+
type ItemFormValues = z.infer<typeof itemFormSchema>;
|
|
41
49
|
interface Globals {
|
|
42
50
|
header: Header;
|
|
43
51
|
footer: Footer;
|
|
@@ -511,6 +519,7 @@ import { FrappeDoc as FrappeDoc2 } from "frappe-js-sdk/lib/db/types";
|
|
|
511
519
|
* return <div>{data?.name} - {data?.email}</div>
|
|
512
520
|
*/
|
|
513
521
|
declare const useFrappeGetDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
522
|
+
enabled?: boolean;
|
|
514
523
|
staleTime?: number;
|
|
515
524
|
retry?: boolean | number;
|
|
516
525
|
}) => {
|
|
@@ -710,4 +719,4 @@ interface ProductContext {
|
|
|
710
719
|
}
|
|
711
720
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
712
721
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
713
|
-
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
722
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, screenFormSchema, modelFormSchema, itemFormSchema, equalsIgnoreCase, decamelizeKeys, decamelize, colourFormSchema, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemFormValues, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, COLOR_SYSTEMS, Brand, Block, ATTRIBUTES };
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,14 @@ interface Image {
|
|
|
38
38
|
image: string;
|
|
39
39
|
color: string;
|
|
40
40
|
}
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
declare const ATTRIBUTES: readonly ["Colour", "Storage", "Memory", "Screen"];
|
|
43
|
+
declare const COLOR_SYSTEMS: readonly ["White", "Black", "Yellow", "Red", "Green", "Blue", "Purple", "Orange", "Pink", "Brown", "Gray", "Silver", "Gold"];
|
|
44
|
+
declare const colourFormSchema: unknown;
|
|
45
|
+
declare const screenFormSchema: unknown;
|
|
46
|
+
declare const modelFormSchema: unknown;
|
|
47
|
+
declare const itemFormSchema: unknown;
|
|
48
|
+
type ItemFormValues = z.infer<typeof itemFormSchema>;
|
|
41
49
|
interface Globals {
|
|
42
50
|
header: Header;
|
|
43
51
|
footer: Footer;
|
|
@@ -511,6 +519,7 @@ import { FrappeDoc as FrappeDoc2 } from "frappe-js-sdk/lib/db/types";
|
|
|
511
519
|
* return <div>{data?.name} - {data?.email}</div>
|
|
512
520
|
*/
|
|
513
521
|
declare const useFrappeGetDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
522
|
+
enabled?: boolean;
|
|
514
523
|
staleTime?: number;
|
|
515
524
|
retry?: boolean | number;
|
|
516
525
|
}) => {
|
|
@@ -710,4 +719,4 @@ interface ProductContext {
|
|
|
710
719
|
}
|
|
711
720
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
712
721
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
713
|
-
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
722
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, screenFormSchema, modelFormSchema, itemFormSchema, equalsIgnoreCase, decamelizeKeys, decamelize, colourFormSchema, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemFormValues, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, COLOR_SYSTEMS, Brand, Block, ATTRIBUTES };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,52 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
// src/catalog/schema.ts
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var ATTRIBUTES = ["Colour", "Storage", "Memory", "Screen"];
|
|
5
|
+
var COLOR_SYSTEMS = [
|
|
6
|
+
"White",
|
|
7
|
+
"Black",
|
|
8
|
+
"Yellow",
|
|
9
|
+
"Red",
|
|
10
|
+
"Green",
|
|
11
|
+
"Blue",
|
|
12
|
+
"Purple",
|
|
13
|
+
"Orange",
|
|
14
|
+
"Pink",
|
|
15
|
+
"Brown",
|
|
16
|
+
"Gray",
|
|
17
|
+
"Silver",
|
|
18
|
+
"Gold"
|
|
19
|
+
];
|
|
20
|
+
var colourFormSchema = z.object({
|
|
21
|
+
color: z.string().min(1, "Color is required"),
|
|
22
|
+
color_hex: z.string().optional(),
|
|
23
|
+
color_system: z.enum(COLOR_SYSTEMS).optional(),
|
|
24
|
+
images: z.array(z.union([z.instanceof(File), z.string()])).default([])
|
|
25
|
+
});
|
|
26
|
+
var screenFormSchema = z.object({
|
|
27
|
+
screen: z.string().min(1, "Screen is required"),
|
|
28
|
+
height: z.number().positive().optional(),
|
|
29
|
+
width: z.number().positive().optional(),
|
|
30
|
+
weight: z.number().positive().optional()
|
|
31
|
+
});
|
|
32
|
+
var modelFormSchema = z.object({
|
|
33
|
+
model: z.string().min(1, "Model is required"),
|
|
34
|
+
sim_card_type: z.string().optional(),
|
|
35
|
+
connectivity: z.array(z.string())
|
|
36
|
+
});
|
|
37
|
+
var itemFormSchema = z.object({
|
|
38
|
+
item_code: z.string().min(1, "Item code is required"),
|
|
39
|
+
item_group: z.string().optional(),
|
|
40
|
+
brand: z.string().optional(),
|
|
41
|
+
os: z.string().optional(),
|
|
42
|
+
release_year: z.number().int().min(1900).max(2100).optional(),
|
|
43
|
+
attributes: z.array(z.enum(ATTRIBUTES)),
|
|
44
|
+
colours: z.array(colourFormSchema),
|
|
45
|
+
storages: z.array(z.string()),
|
|
46
|
+
memories: z.array(z.string()),
|
|
47
|
+
screens: z.array(screenFormSchema),
|
|
48
|
+
models: z.array(modelFormSchema)
|
|
49
|
+
});
|
|
2
50
|
// src/frappe/provider.tsx
|
|
3
51
|
import { useMemo, createContext } from "react";
|
|
4
52
|
import { FrappeApp } from "frappe-js-sdk";
|
|
@@ -164,11 +212,9 @@ var useFrappeGetCall = (method, params, options, type = "GET") => {
|
|
|
164
212
|
queryFn: async () => {
|
|
165
213
|
if (type === "GET") {
|
|
166
214
|
const response = await call.get(method, params);
|
|
167
|
-
console.log("Response", response);
|
|
168
215
|
return response.message;
|
|
169
216
|
} else {
|
|
170
217
|
const response = await call.post(method, params);
|
|
171
|
-
console.log("Response", response);
|
|
172
218
|
return response.message;
|
|
173
219
|
}
|
|
174
220
|
},
|
|
@@ -384,7 +430,7 @@ var useFrappeGetDoc = (doctype, name, options) => {
|
|
|
384
430
|
const { data, error, isLoading, isFetching, refetch } = useQuery4({
|
|
385
431
|
queryKey,
|
|
386
432
|
queryFn: () => db.getDoc(doctype, name),
|
|
387
|
-
enabled:
|
|
433
|
+
enabled: options?.enabled ?? true,
|
|
388
434
|
staleTime: options?.staleTime ?? 5 * 60 * 1000,
|
|
389
435
|
retry: options?.retry ?? false
|
|
390
436
|
});
|
|
@@ -638,10 +684,10 @@ function LocaleProvider({
|
|
|
638
684
|
}, [language, storage]);
|
|
639
685
|
const { data, isLoading } = useFrappeGetCall(method, { lang: language }, { staleTime: Infinity });
|
|
640
686
|
useEffect4(() => {
|
|
641
|
-
if (!data
|
|
687
|
+
if (!data)
|
|
642
688
|
return;
|
|
643
|
-
setMessages(data
|
|
644
|
-
storage?.setItem(`locale:${language}`, JSON.stringify(data
|
|
689
|
+
setMessages(data);
|
|
690
|
+
storage?.setItem(`locale:${language}`, JSON.stringify(data));
|
|
645
691
|
}, [data, language, storage]);
|
|
646
692
|
const __ = useCallback5((message, replace) => translate(message, replace, messages), [messages]);
|
|
647
693
|
if (isLoading && Object.keys(messages).length === 0)
|
|
@@ -681,12 +727,18 @@ export {
|
|
|
681
727
|
useFrappeDeleteCall,
|
|
682
728
|
useFrappeCreateDoc,
|
|
683
729
|
useFrappeAuth,
|
|
730
|
+
screenFormSchema,
|
|
731
|
+
modelFormSchema,
|
|
732
|
+
itemFormSchema,
|
|
684
733
|
equalsIgnoreCase,
|
|
685
734
|
decamelizeKeys,
|
|
686
735
|
decamelize,
|
|
736
|
+
colourFormSchema,
|
|
687
737
|
camelizeKeys,
|
|
688
738
|
camelize,
|
|
689
739
|
LocaleProvider,
|
|
690
740
|
FrappeProvider,
|
|
691
|
-
FrappeContext
|
|
741
|
+
FrappeContext,
|
|
742
|
+
COLOR_SYSTEMS,
|
|
743
|
+
ATTRIBUTES
|
|
692
744
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lasterp/shared",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.19",
|
|
4
4
|
"description": "Shared repo for webapp and native app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"frappe-js-sdk": "^1.12.0",
|
|
47
47
|
"humps": "^2.0.1",
|
|
48
48
|
"socket.io-client": "^4.8.3",
|
|
49
|
+
"zod": "^4.3.6",
|
|
49
50
|
"zustand": "^5.0.11"
|
|
50
51
|
}
|
|
51
52
|
}
|