@lasterp/shared 1.0.0-alpha.2 → 1.0.0-alpha.3
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.d.ts +2 -298
- package/dist/index.js +5 -336
- package/dist/node/index.d.ts +98 -0
- package/dist/node/index.js +7 -0
- package/dist/rn/index.d.ts +98 -0
- package/dist/rn/index.js +7 -0
- package/package.json +28 -37
- package/dist/index.cjs +0 -386
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -298
- package/dist/index.js.map +0 -1
- package/src/client/context.tsx +0 -74
- package/src/client/core.ts +0 -261
- package/src/client/hooks.tsx +0 -57
- package/src/client/index.ts +0 -20
- package/src/client/storage.ts +0 -76
- package/src/client/types.ts +0 -24
- package/src/common/index.ts +0 -1
- package/src/common/types.ts +0 -15
- package/src/design/block/types.ts +0 -8
- package/src/design/globals/footer.ts +0 -20
- package/src/design/globals/header.ts +0 -43
- package/src/design/globals/types.ts +0 -7
- package/src/design/index.ts +0 -8
- package/src/design/page/api.ts +0 -11
- package/src/design/page/types.ts +0 -15
- package/src/index.ts +0 -5
- package/src/lasterp/catalog/types.ts +0 -24
- package/src/lasterp/index.ts +0 -5
- package/src/lasterp/shop/api.ts +0 -32
- package/src/lasterp/shop/hooks.tsx +0 -42
- package/src/lasterp/shop/types.ts +0 -42
- package/src/utils/catalog.ts +0 -8
- package/src/utils/index.ts +0 -10
- package/src/utils/types.ts +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,298 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { decamelize as camelToSnake, decamelizeKeys as objectCamelToSnake, camelizeKeys as objectSnakeToCamel, camelize as snakeToCamel } from 'humps';
|
|
4
|
-
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
|
-
import { UseQueryOptions } from '@tanstack/react-query';
|
|
6
|
-
|
|
7
|
-
interface FrappeDoc {
|
|
8
|
-
name: string;
|
|
9
|
-
creation?: string;
|
|
10
|
-
modified?: string;
|
|
11
|
-
modifiedBy?: string;
|
|
12
|
-
owner?: string;
|
|
13
|
-
docStatus?: number;
|
|
14
|
-
idx?: number;
|
|
15
|
-
}
|
|
16
|
-
interface FrappeChildDoc extends FrappeDoc {
|
|
17
|
-
parent: string;
|
|
18
|
-
parentType: string;
|
|
19
|
-
parentField: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface FrappeResponse<T = any> {
|
|
23
|
-
message?: T;
|
|
24
|
-
docs?: T[];
|
|
25
|
-
exc?: string;
|
|
26
|
-
exc_type?: string;
|
|
27
|
-
_server_messages?: string;
|
|
28
|
-
_error_message?: string;
|
|
29
|
-
}
|
|
30
|
-
interface FrappeError {
|
|
31
|
-
message: string;
|
|
32
|
-
statusCode?: number;
|
|
33
|
-
exc?: string;
|
|
34
|
-
excType?: string;
|
|
35
|
-
serverMessages?: string;
|
|
36
|
-
}
|
|
37
|
-
interface AuthOptions {
|
|
38
|
-
token?: string;
|
|
39
|
-
apiKey?: {
|
|
40
|
-
key: string;
|
|
41
|
-
secret: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
declare function frappeCall<T = any>(baseUrl: string, method: string, args?: Record<string, any>, auth?: AuthOptions): Promise<T>;
|
|
46
|
-
declare function frappeCallGet<T = any>(baseUrl: string, method: string, args?: Record<string, any>, auth?: AuthOptions): Promise<T>;
|
|
47
|
-
declare function getList<T = any>(baseUrl: string, params: {
|
|
48
|
-
doctype: string;
|
|
49
|
-
fields?: string[];
|
|
50
|
-
filters?: Record<string, any>;
|
|
51
|
-
orderBy?: string;
|
|
52
|
-
limitStart?: number;
|
|
53
|
-
limitPageLength?: number;
|
|
54
|
-
}, auth?: AuthOptions): Promise<T[]>;
|
|
55
|
-
declare function getDoc<T = any>(baseUrl: string, doctype: string, name: string, auth?: AuthOptions): Promise<T>;
|
|
56
|
-
declare function createDoc<T = any>(baseUrl: string, doctype: string, doc: Record<string, any>, auth?: AuthOptions): Promise<T>;
|
|
57
|
-
declare function updateDoc<T = any>(baseUrl: string, doctype: string, name: string, doc: Record<string, any>, auth?: AuthOptions): Promise<T>;
|
|
58
|
-
declare function deleteDoc(baseUrl: string, doctype: string, name: string, auth?: AuthOptions): Promise<void>;
|
|
59
|
-
declare function getValue<T = any>(baseUrl: string, doctype: string, name: string, fieldname: string, auth?: AuthOptions): Promise<T>;
|
|
60
|
-
declare function setValue<T = any>(baseUrl: string, doctype: string, name: string, fieldname: string, value: any, auth?: AuthOptions): Promise<T>;
|
|
61
|
-
declare function getCount(baseUrl: string, doctype: string, filters?: Record<string, any>, auth?: AuthOptions): Promise<number>;
|
|
62
|
-
declare function getCurrentUser(baseUrl: string, auth?: AuthOptions): Promise<any>;
|
|
63
|
-
|
|
64
|
-
interface FrappeContextValue {
|
|
65
|
-
baseUrl: string;
|
|
66
|
-
token?: string;
|
|
67
|
-
apiKey?: {
|
|
68
|
-
key: string;
|
|
69
|
-
secret: string;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
interface FrappeProviderProps {
|
|
73
|
-
baseUrl: string;
|
|
74
|
-
token?: string;
|
|
75
|
-
apiKey?: {
|
|
76
|
-
key: string;
|
|
77
|
-
secret: string;
|
|
78
|
-
};
|
|
79
|
-
autoLoadAuth?: boolean;
|
|
80
|
-
onLoadAuth?: () => Promise<{
|
|
81
|
-
token?: string;
|
|
82
|
-
apiKey?: {
|
|
83
|
-
key: string;
|
|
84
|
-
secret: string;
|
|
85
|
-
};
|
|
86
|
-
}> | {
|
|
87
|
-
token?: string;
|
|
88
|
-
apiKey?: {
|
|
89
|
-
key: string;
|
|
90
|
-
secret: string;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
children: ReactNode;
|
|
94
|
-
}
|
|
95
|
-
declare function FrappeProvider({ baseUrl, token: initialToken, apiKey: initialApiKey, autoLoadAuth, onLoadAuth, children, }: FrappeProviderProps): react_jsx_runtime.JSX.Element;
|
|
96
|
-
declare function useFrappeConfig(): FrappeContextValue;
|
|
97
|
-
|
|
98
|
-
declare function useFrappe(): {
|
|
99
|
-
call: <T = any>(method: string, args?: Record<string, any>) => Promise<T>;
|
|
100
|
-
callGet: <T = any>(method: string, args?: Record<string, any>) => Promise<T>;
|
|
101
|
-
getList: <T = any>(params: {
|
|
102
|
-
doctype: string;
|
|
103
|
-
fields?: string[];
|
|
104
|
-
filters?: Record<string, any>;
|
|
105
|
-
orderBy?: string;
|
|
106
|
-
limitStart?: number;
|
|
107
|
-
limitPageLength?: number;
|
|
108
|
-
}) => Promise<T[]>;
|
|
109
|
-
getDoc: <T = any>(doctype: string, name: string) => Promise<T>;
|
|
110
|
-
createDoc: <T = any>(doctype: string, doc: Record<string, any>) => Promise<T>;
|
|
111
|
-
updateDoc: <T = any>(doctype: string, name: string, doc: Record<string, any>) => Promise<T>;
|
|
112
|
-
deleteDoc: (doctype: string, name: string) => Promise<void>;
|
|
113
|
-
baseUrl: string;
|
|
114
|
-
auth: AuthOptions;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
interface StorageAdapter {
|
|
118
|
-
getItem(key: string): string | null | Promise<string | null>;
|
|
119
|
-
setItem(key: string, value: string): void | Promise<void>;
|
|
120
|
-
removeItem(key: string): void | Promise<void>;
|
|
121
|
-
}
|
|
122
|
-
declare const webStorageAdapter: StorageAdapter;
|
|
123
|
-
declare function setStorageAdapter(adapter: StorageAdapter): void;
|
|
124
|
-
declare function getStorageAdapter(): StorageAdapter;
|
|
125
|
-
declare function getToken(): string | null | Promise<string | null>;
|
|
126
|
-
declare function setToken(token: string): void | Promise<void>;
|
|
127
|
-
declare function clearToken(): void | Promise<void>;
|
|
128
|
-
declare function getApiKey(): Promise<{
|
|
129
|
-
key: string;
|
|
130
|
-
secret: string;
|
|
131
|
-
} | null>;
|
|
132
|
-
declare function setApiKey(key: string, secret: string): Promise<void>;
|
|
133
|
-
declare function clearApiKey(): Promise<void>;
|
|
134
|
-
declare function clearAuth(): Promise<void>;
|
|
135
|
-
declare function isAuthenticated(): Promise<boolean>;
|
|
136
|
-
|
|
137
|
-
interface Brand {
|
|
138
|
-
brandImage?: string;
|
|
139
|
-
}
|
|
140
|
-
interface NavbarItem {
|
|
141
|
-
label: string;
|
|
142
|
-
enableDropdown: boolean;
|
|
143
|
-
enableLink: boolean;
|
|
144
|
-
link?: string;
|
|
145
|
-
dropdownDescription?: string;
|
|
146
|
-
dropdownCta?: string;
|
|
147
|
-
groups?: NavbarSubItemGroup[];
|
|
148
|
-
}
|
|
149
|
-
interface NavbarSubItemGroup {
|
|
150
|
-
title?: string;
|
|
151
|
-
items: NavbarSubItem[];
|
|
152
|
-
}
|
|
153
|
-
interface NavbarSubItem {
|
|
154
|
-
label: string;
|
|
155
|
-
description?: string;
|
|
156
|
-
image?: string;
|
|
157
|
-
link?: string;
|
|
158
|
-
}
|
|
159
|
-
interface Topbar {
|
|
160
|
-
topbarEnabled?: boolean;
|
|
161
|
-
items: TopbarItem[];
|
|
162
|
-
}
|
|
163
|
-
interface TopbarItem {
|
|
164
|
-
icon?: string;
|
|
165
|
-
label: string;
|
|
166
|
-
link?: string;
|
|
167
|
-
}
|
|
168
|
-
interface Header {
|
|
169
|
-
brand: Brand;
|
|
170
|
-
headerType?: string;
|
|
171
|
-
tabs: NavbarItem[];
|
|
172
|
-
topbar: Topbar;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
interface FooterItemGroup {
|
|
176
|
-
title: string;
|
|
177
|
-
items: FooterItem[];
|
|
178
|
-
}
|
|
179
|
-
interface FooterItem {
|
|
180
|
-
label: string;
|
|
181
|
-
link?: string;
|
|
182
|
-
}
|
|
183
|
-
interface Footer {
|
|
184
|
-
footerType?: string;
|
|
185
|
-
groups: FooterItemGroup[];
|
|
186
|
-
copyright?: string;
|
|
187
|
-
address?: string;
|
|
188
|
-
country?: string;
|
|
189
|
-
phone?: string;
|
|
190
|
-
email?: string;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
interface Globals {
|
|
194
|
-
header: Header;
|
|
195
|
-
footer: Footer;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
interface Hero {
|
|
199
|
-
type: string;
|
|
200
|
-
data: Record<string, unknown>;
|
|
201
|
-
}
|
|
202
|
-
interface Block {
|
|
203
|
-
type: string;
|
|
204
|
-
data?: Record<string, unknown>;
|
|
205
|
-
}
|
|
206
|
-
interface Page {
|
|
207
|
-
slug: string;
|
|
208
|
-
hero?: Hero;
|
|
209
|
-
blocks: Block[];
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
declare function getPage(baseUrl: string, slug: string, auth?: AuthOptions): Promise<Page>;
|
|
213
|
-
|
|
214
|
-
interface AaveFeatureSlidesData {
|
|
215
|
-
feature1Title: string;
|
|
216
|
-
feature1Description: string;
|
|
217
|
-
feature1Cta?: string;
|
|
218
|
-
feature2Title: string;
|
|
219
|
-
feature2Description: string;
|
|
220
|
-
feature2Cta?: string;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
interface Item {
|
|
224
|
-
itemCode: string;
|
|
225
|
-
region: string;
|
|
226
|
-
grade: string;
|
|
227
|
-
gradeIssuer: string;
|
|
228
|
-
color: string;
|
|
229
|
-
storage: string;
|
|
230
|
-
memory: string;
|
|
231
|
-
network: string;
|
|
232
|
-
}
|
|
233
|
-
interface ItemVariant extends Item {
|
|
234
|
-
itemVariant: string;
|
|
235
|
-
}
|
|
236
|
-
interface ModelNumber {
|
|
237
|
-
modelNumber: string;
|
|
238
|
-
simCardType: string;
|
|
239
|
-
}
|
|
240
|
-
interface Colour {
|
|
241
|
-
name: string;
|
|
242
|
-
color: string;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
interface Category {
|
|
246
|
-
name: string;
|
|
247
|
-
categoryName: string;
|
|
248
|
-
sequenceId: number;
|
|
249
|
-
itemCode: string[];
|
|
250
|
-
itemGroup: string[];
|
|
251
|
-
brand: string[];
|
|
252
|
-
os: string[];
|
|
253
|
-
}
|
|
254
|
-
interface Product extends Item {
|
|
255
|
-
name: string;
|
|
256
|
-
image: string;
|
|
257
|
-
}
|
|
258
|
-
interface ProductVariant extends ItemVariant {
|
|
259
|
-
id: string;
|
|
260
|
-
specs: Record<string, string>;
|
|
261
|
-
price: number;
|
|
262
|
-
stock: number;
|
|
263
|
-
}
|
|
264
|
-
interface ShopContext {
|
|
265
|
-
title?: string;
|
|
266
|
-
categories?: Category[];
|
|
267
|
-
selectedCategory?: Category;
|
|
268
|
-
grades?: string[];
|
|
269
|
-
selectedGrade?: string;
|
|
270
|
-
products: Product[];
|
|
271
|
-
}
|
|
272
|
-
interface ProductContext {
|
|
273
|
-
currency: string;
|
|
274
|
-
product: Product;
|
|
275
|
-
specs: Record<string, string[]>;
|
|
276
|
-
variants: ProductVariant[];
|
|
277
|
-
modelNumbers: Record<string, ModelNumber>;
|
|
278
|
-
colours: Record<string, Colour>;
|
|
279
|
-
variantImages: Record<string, string[]>;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
declare function getShopContext(baseUrl: string, params?: {
|
|
283
|
-
categoryName?: string;
|
|
284
|
-
gradeName?: string;
|
|
285
|
-
}, auth?: AuthOptions): Promise<ShopContext>;
|
|
286
|
-
declare function getProductContext(baseUrl: string, productName: string, auth?: AuthOptions): Promise<ProductContext>;
|
|
287
|
-
|
|
288
|
-
declare function useShopContext(params?: {
|
|
289
|
-
categoryName?: string;
|
|
290
|
-
gradeName?: string;
|
|
291
|
-
}, options?: Omit<UseQueryOptions<ShopContext, Error>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ShopContext, Error>;
|
|
292
|
-
declare function useProductContext(productName: string, options?: Omit<UseQueryOptions<ProductContext, Error>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ProductContext, Error>;
|
|
293
|
-
|
|
294
|
-
declare function toDescription(modelNumber: ModelNumber): string | null;
|
|
295
|
-
|
|
296
|
-
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
297
|
-
|
|
298
|
-
export { type AaveFeatureSlidesData, type AuthOptions, type Block, type Brand, type Category, type Colour, type Footer, type FooterItem, type FooterItemGroup, type FrappeChildDoc, type FrappeContextValue, type FrappeDoc, type FrappeError, FrappeProvider, type FrappeProviderProps, type FrappeResponse, type Globals, type Header, type Hero, type Item, type ItemVariant, type ModelNumber, type NavbarItem, type NavbarSubItem, type NavbarSubItemGroup, type Page, type Product, type ProductContext, type ProductVariant, type ShopContext, type StorageAdapter, type Topbar, type TopbarItem, clearApiKey, clearAuth, clearToken, createDoc, deleteDoc, equalsIgnoreCase, frappeCall, frappeCallGet, getApiKey, getCount, getCurrentUser, getDoc, getList, getPage, getProductContext, getShopContext, getStorageAdapter, getToken, getValue, isAuthenticated, setApiKey, setStorageAdapter, setToken, setValue, toDescription, updateDoc, useFrappe, useFrappeConfig, useProductContext, useShopContext, webStorageAdapter };
|
|
1
|
+
declare function greet(name: string): string;
|
|
2
|
+
export { greet };
|
package/dist/index.js
CHANGED
|
@@ -1,338 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
import { useQuery } from '@tanstack/react-query';
|
|
6
|
-
|
|
7
|
-
async function request(baseUrl, endpoint, options = {}, auth) {
|
|
8
|
-
const url = `${baseUrl}${endpoint}`;
|
|
9
|
-
const headers = {
|
|
10
|
-
"Content-Type": "application/json",
|
|
11
|
-
Accept: "application/json",
|
|
12
|
-
...options.headers
|
|
13
|
-
};
|
|
14
|
-
if (auth?.token) {
|
|
15
|
-
headers["Authorization"] = `Bearer ${auth.token}`;
|
|
16
|
-
} else if (auth?.apiKey) {
|
|
17
|
-
headers["Authorization"] = `token ${auth.apiKey.key}:${auth.apiKey.secret}`;
|
|
18
|
-
}
|
|
19
|
-
const response = await fetch(url, {
|
|
20
|
-
...options,
|
|
21
|
-
headers,
|
|
22
|
-
credentials: "include"
|
|
23
|
-
});
|
|
24
|
-
const rawData = await response.json();
|
|
25
|
-
if (!response.ok || rawData.exc) {
|
|
26
|
-
const errorMessage = rawData._error_message || rawData.exc || "Request failed";
|
|
27
|
-
const error = new Error(errorMessage);
|
|
28
|
-
error.message = errorMessage;
|
|
29
|
-
error.statusCode = response.status;
|
|
30
|
-
if (rawData.exc) {
|
|
31
|
-
error.exc = rawData.exc;
|
|
32
|
-
}
|
|
33
|
-
if (rawData._server_messages) {
|
|
34
|
-
error.serverMessages = rawData._server_messages;
|
|
35
|
-
}
|
|
36
|
-
if (rawData.exc_type) {
|
|
37
|
-
error.excType = rawData.exc_type;
|
|
38
|
-
}
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
const result = rawData.message ?? rawData;
|
|
42
|
-
return camelizeKeys(result);
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function greet(name) {
|
|
3
|
+
return `Hello, ${name}!`;
|
|
43
4
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return request(
|
|
47
|
-
baseUrl,
|
|
48
|
-
`/api/method/${method}`,
|
|
49
|
-
{
|
|
50
|
-
method: "POST",
|
|
51
|
-
body: JSON.stringify(snakeArgs)
|
|
52
|
-
},
|
|
53
|
-
auth
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
async function frappeCallGet(baseUrl, method, args, auth) {
|
|
57
|
-
const snakeArgs = decamelizeKeys(args ?? {});
|
|
58
|
-
const queryParams = new URLSearchParams();
|
|
59
|
-
Object.entries(snakeArgs).forEach(([key, value]) => {
|
|
60
|
-
queryParams.append(
|
|
61
|
-
key,
|
|
62
|
-
typeof value === "string" ? value : JSON.stringify(value)
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
const endpoint = `/api/method/${method}?${queryParams.toString()}`;
|
|
66
|
-
return request(baseUrl, endpoint, { method: "GET" }, auth);
|
|
67
|
-
}
|
|
68
|
-
async function getList(baseUrl, params, auth) {
|
|
69
|
-
const {
|
|
70
|
-
doctype,
|
|
71
|
-
fields = ["name"],
|
|
72
|
-
filters = {},
|
|
73
|
-
orderBy = "modified desc",
|
|
74
|
-
limitStart = 0,
|
|
75
|
-
limitPageLength = 20
|
|
76
|
-
} = params;
|
|
77
|
-
const snakeFilters = decamelizeKeys(filters);
|
|
78
|
-
const queryParams = new URLSearchParams({
|
|
79
|
-
fields: JSON.stringify(fields),
|
|
80
|
-
filters: JSON.stringify(snakeFilters),
|
|
81
|
-
order_by: orderBy,
|
|
82
|
-
limit_start: limitStart.toString(),
|
|
83
|
-
limit_page_length: limitPageLength.toString()
|
|
84
|
-
});
|
|
85
|
-
const endpoint = `/api/resource/${doctype}?${queryParams.toString()}`;
|
|
86
|
-
const response = await request(baseUrl, endpoint, {}, auth);
|
|
87
|
-
return response.data || [];
|
|
88
|
-
}
|
|
89
|
-
async function getDoc(baseUrl, doctype, name, auth) {
|
|
90
|
-
const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;
|
|
91
|
-
const response = await request(baseUrl, endpoint, {}, auth);
|
|
92
|
-
return response.data;
|
|
93
|
-
}
|
|
94
|
-
async function createDoc(baseUrl, doctype, doc, auth) {
|
|
95
|
-
const snakeDoc = decamelizeKeys(doc);
|
|
96
|
-
const endpoint = `/api/resource/${doctype}`;
|
|
97
|
-
const response = await request(
|
|
98
|
-
baseUrl,
|
|
99
|
-
endpoint,
|
|
100
|
-
{
|
|
101
|
-
method: "POST",
|
|
102
|
-
body: JSON.stringify(snakeDoc)
|
|
103
|
-
},
|
|
104
|
-
auth
|
|
105
|
-
);
|
|
106
|
-
return response.data;
|
|
107
|
-
}
|
|
108
|
-
async function updateDoc(baseUrl, doctype, name, doc, auth) {
|
|
109
|
-
const snakeDoc = decamelizeKeys(doc);
|
|
110
|
-
const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;
|
|
111
|
-
const response = await request(
|
|
112
|
-
baseUrl,
|
|
113
|
-
endpoint,
|
|
114
|
-
{
|
|
115
|
-
method: "PUT",
|
|
116
|
-
body: JSON.stringify(snakeDoc)
|
|
117
|
-
},
|
|
118
|
-
auth
|
|
119
|
-
);
|
|
120
|
-
return response.data;
|
|
121
|
-
}
|
|
122
|
-
async function deleteDoc(baseUrl, doctype, name, auth) {
|
|
123
|
-
const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;
|
|
124
|
-
await request(
|
|
125
|
-
baseUrl,
|
|
126
|
-
endpoint,
|
|
127
|
-
{
|
|
128
|
-
method: "DELETE"
|
|
129
|
-
},
|
|
130
|
-
auth
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
async function getValue(baseUrl, doctype, name, fieldname, auth) {
|
|
134
|
-
const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}?fields=["${fieldname}"]`;
|
|
135
|
-
const response = await request(
|
|
136
|
-
baseUrl,
|
|
137
|
-
endpoint,
|
|
138
|
-
{},
|
|
139
|
-
auth
|
|
140
|
-
);
|
|
141
|
-
const value = response.data[fieldname];
|
|
142
|
-
if (value === void 0) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
`Field "${fieldname}" not found in document "${doctype}/${name}"`
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
async function setValue(baseUrl, doctype, name, fieldname, value, auth) {
|
|
150
|
-
return updateDoc(baseUrl, doctype, name, { [fieldname]: value }, auth);
|
|
151
|
-
}
|
|
152
|
-
async function getCount(baseUrl, doctype, filters = {}, auth) {
|
|
153
|
-
return frappeCall(
|
|
154
|
-
baseUrl,
|
|
155
|
-
"frappe.client.get_count",
|
|
156
|
-
{
|
|
157
|
-
doctype,
|
|
158
|
-
filters
|
|
159
|
-
},
|
|
160
|
-
auth
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
async function getCurrentUser(baseUrl, auth) {
|
|
164
|
-
return frappeCallGet(baseUrl, "frappe.auth.get_logged_user", {}, auth);
|
|
165
|
-
}
|
|
166
|
-
var FrappeContext = createContext(null);
|
|
167
|
-
function FrappeProvider({
|
|
168
|
-
baseUrl,
|
|
169
|
-
token: initialToken,
|
|
170
|
-
apiKey: initialApiKey,
|
|
171
|
-
autoLoadAuth = true,
|
|
172
|
-
onLoadAuth,
|
|
173
|
-
children
|
|
174
|
-
}) {
|
|
175
|
-
const [token, setToken2] = useState(initialToken);
|
|
176
|
-
const [apiKey, setApiKey2] = useState(
|
|
177
|
-
initialApiKey
|
|
178
|
-
);
|
|
179
|
-
useEffect(() => {
|
|
180
|
-
if (autoLoadAuth && !initialToken && !initialApiKey && onLoadAuth) {
|
|
181
|
-
Promise.resolve(onLoadAuth()).then((auth) => {
|
|
182
|
-
if (auth.token) {
|
|
183
|
-
setToken2(auth.token);
|
|
184
|
-
} else if (auth.apiKey) {
|
|
185
|
-
setApiKey2(auth.apiKey);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}, [autoLoadAuth, initialToken, initialApiKey, onLoadAuth]);
|
|
190
|
-
const value = {
|
|
191
|
-
baseUrl,
|
|
192
|
-
...token !== void 0 && { token },
|
|
193
|
-
...apiKey !== void 0 && { apiKey }
|
|
194
|
-
};
|
|
195
|
-
return /* @__PURE__ */ jsx(FrappeContext.Provider, { value, children });
|
|
196
|
-
}
|
|
197
|
-
function useFrappeConfig() {
|
|
198
|
-
const context = useContext(FrappeContext);
|
|
199
|
-
if (!context) {
|
|
200
|
-
throw new Error("useFrappeConfig must be used within FrappeProvider");
|
|
201
|
-
}
|
|
202
|
-
return context;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/client/hooks.tsx
|
|
206
|
-
function useFrappe() {
|
|
207
|
-
const { baseUrl, token, apiKey } = useFrappeConfig();
|
|
208
|
-
const auth = {
|
|
209
|
-
...token && { token },
|
|
210
|
-
...apiKey && { apiKey }
|
|
211
|
-
};
|
|
212
|
-
return {
|
|
213
|
-
call: (method, args) => frappeCall(baseUrl, method, args, auth),
|
|
214
|
-
callGet: (method, args) => frappeCallGet(baseUrl, method, args, auth),
|
|
215
|
-
getList: (params) => getList(baseUrl, params, auth),
|
|
216
|
-
getDoc: (doctype, name) => getDoc(baseUrl, doctype, name, auth),
|
|
217
|
-
createDoc: (doctype, doc) => createDoc(baseUrl, doctype, doc, auth),
|
|
218
|
-
updateDoc: (doctype, name, doc) => updateDoc(baseUrl, doctype, name, doc, auth),
|
|
219
|
-
deleteDoc: (doctype, name) => deleteDoc(baseUrl, doctype, name, auth),
|
|
220
|
-
baseUrl,
|
|
221
|
-
auth
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// src/client/storage.ts
|
|
226
|
-
var webStorageAdapter = {
|
|
227
|
-
getItem: (key) => {
|
|
228
|
-
if (typeof window === "undefined") return null;
|
|
229
|
-
return localStorage.getItem(key);
|
|
230
|
-
},
|
|
231
|
-
setItem: (key, value) => {
|
|
232
|
-
if (typeof window === "undefined") return;
|
|
233
|
-
localStorage.setItem(key, value);
|
|
234
|
-
},
|
|
235
|
-
removeItem: (key) => {
|
|
236
|
-
if (typeof window === "undefined") return;
|
|
237
|
-
localStorage.removeItem(key);
|
|
238
|
-
}
|
|
5
|
+
export {
|
|
6
|
+
greet
|
|
239
7
|
};
|
|
240
|
-
var currentAdapter = webStorageAdapter;
|
|
241
|
-
function setStorageAdapter(adapter) {
|
|
242
|
-
currentAdapter = adapter;
|
|
243
|
-
}
|
|
244
|
-
function getStorageAdapter() {
|
|
245
|
-
return currentAdapter;
|
|
246
|
-
}
|
|
247
|
-
var TOKEN_KEY = "frappe_token";
|
|
248
|
-
var API_KEY_KEY = "frappe_api_key";
|
|
249
|
-
var API_SECRET_KEY = "frappe_api_secret";
|
|
250
|
-
function getToken() {
|
|
251
|
-
return currentAdapter.getItem(TOKEN_KEY);
|
|
252
|
-
}
|
|
253
|
-
function setToken(token) {
|
|
254
|
-
return currentAdapter.setItem(TOKEN_KEY, token);
|
|
255
|
-
}
|
|
256
|
-
function clearToken() {
|
|
257
|
-
return currentAdapter.removeItem(TOKEN_KEY);
|
|
258
|
-
}
|
|
259
|
-
async function getApiKey() {
|
|
260
|
-
const key = await currentAdapter.getItem(API_KEY_KEY);
|
|
261
|
-
const secret = await currentAdapter.getItem(API_SECRET_KEY);
|
|
262
|
-
if (!key || !secret) return null;
|
|
263
|
-
return { key, secret };
|
|
264
|
-
}
|
|
265
|
-
async function setApiKey(key, secret) {
|
|
266
|
-
await currentAdapter.setItem(API_KEY_KEY, key);
|
|
267
|
-
await currentAdapter.setItem(API_SECRET_KEY, secret);
|
|
268
|
-
}
|
|
269
|
-
async function clearApiKey() {
|
|
270
|
-
await currentAdapter.removeItem(API_KEY_KEY);
|
|
271
|
-
await currentAdapter.removeItem(API_SECRET_KEY);
|
|
272
|
-
}
|
|
273
|
-
async function clearAuth() {
|
|
274
|
-
await clearToken();
|
|
275
|
-
await clearApiKey();
|
|
276
|
-
}
|
|
277
|
-
async function isAuthenticated() {
|
|
278
|
-
const token = await getToken();
|
|
279
|
-
const apiKey = await getApiKey();
|
|
280
|
-
return !!token || !!apiKey;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// src/design/page/api.ts
|
|
284
|
-
async function getPage(baseUrl, slug, auth) {
|
|
285
|
-
return getDoc(baseUrl, "Design Page", slug, auth);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// src/utils/catalog.ts
|
|
289
|
-
function toDescription(modelNumber) {
|
|
290
|
-
if (!modelNumber) {
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
return modelNumber.simCardType;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/utils/types.ts
|
|
297
|
-
function equalsIgnoreCase(str1, str2) {
|
|
298
|
-
return str1.localeCompare(str2, void 0, { sensitivity: "accent" }) === 0;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// src/lasterp/shop/api.ts
|
|
302
|
-
async function getShopContext(baseUrl, params, auth) {
|
|
303
|
-
return frappeCall(
|
|
304
|
-
baseUrl,
|
|
305
|
-
"lasterp.shop.controllers.shop_controller.get_context",
|
|
306
|
-
params,
|
|
307
|
-
auth
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
async function getProductContext(baseUrl, productName, auth) {
|
|
311
|
-
return frappeCall(
|
|
312
|
-
baseUrl,
|
|
313
|
-
"lasterp.shop.controllers.product_controller.get_context",
|
|
314
|
-
{ productName },
|
|
315
|
-
auth
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
function useShopContext(params, options) {
|
|
319
|
-
const { baseUrl, auth } = useFrappe();
|
|
320
|
-
return useQuery({
|
|
321
|
-
queryKey: ["shop-context", params],
|
|
322
|
-
queryFn: () => getShopContext(baseUrl, params, auth),
|
|
323
|
-
...options
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
function useProductContext(productName, options) {
|
|
327
|
-
const { baseUrl, auth } = useFrappe();
|
|
328
|
-
return useQuery({
|
|
329
|
-
queryKey: ["product-context", productName],
|
|
330
|
-
queryFn: () => getProductContext(baseUrl, productName, auth),
|
|
331
|
-
enabled: !!productName,
|
|
332
|
-
...options
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export { FrappeProvider, clearApiKey, clearAuth, clearToken, createDoc, deleteDoc, equalsIgnoreCase, frappeCall, frappeCallGet, getApiKey, getCount, getCurrentUser, getDoc, getList, getPage, getProductContext, getShopContext, getStorageAdapter, getToken, getValue, isAuthenticated, setApiKey, setStorageAdapter, setToken, setValue, toDescription, updateDoc, useFrappe, useFrappeConfig, useProductContext, useShopContext, webStorageAdapter };
|
|
337
|
-
//# sourceMappingURL=index.js.map
|
|
338
|
-
//# sourceMappingURL=index.js.map
|