@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.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/core.ts","../src/client/context.tsx","../src/client/hooks.tsx","../src/client/storage.ts","../src/design/page/api.ts","../src/utils/catalog.ts","../src/utils/types.ts","../src/lasterp/shop/api.ts","../src/lasterp/shop/hooks.tsx"],"names":["camelizeKeys","decamelizeKeys","createContext","setToken","useState","setApiKey","useEffect","jsx","useContext","useQuery"],"mappings":";;;;;;;AAGA,eAAe,QACb,OAAA,EACA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AAAA,GACF;AACF;ACxBO,SAAS,cAAA,CACd,QAIA,OAAA,EAIA;AACA,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,SAAA,EAAU;AAEpC,EAAA,OAAOC,mBAAA,CAA6B;AAAA,IAClC,QAAA,EAAU,CAAC,cAAA,EAAgB,MAAM,CAAA;AAAA,IACjC,OAAA,EAAS,MAAM,cAAA,CAAe,OAAA,EAAS,QAAQ,IAAI,CAAA;AAAA,IACnD,GAAG;AAAA,GACJ,CAAA;AACH;AAEO,SAAS,iBAAA,CACd,aACA,OAAA,EAIA;AACA,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,SAAA,EAAU;AAEpC,EAAA,OAAOA,mBAAA,CAAgC;AAAA,IACrC,QAAA,EAAU,CAAC,iBAAA,EAAmB,WAAW,CAAA;AAAA,IACzC,OAAA,EAAS,MAAM,iBAAA,CAAkB,OAAA,EAAS,aAAa,IAAI,CAAA;AAAA,IAC3D,OAAA,EAAS,CAAC,CAAC,WAAA;AAAA,IACX,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.cjs","sourcesContent":["import { camelizeKeys, decamelizeKeys } from 'humps';\nimport type { FrappeResponse, FrappeError, AuthOptions } from './types';\n\nasync function request<T = any>(\n baseUrl: string,\n endpoint: string,\n options: RequestInit = {},\n auth?: AuthOptions\n): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...(options.headers as Record<string, string>),\n };\n\n if (auth?.token) {\n headers['Authorization'] = `Bearer ${auth.token}`;\n } else if (auth?.apiKey) {\n headers['Authorization'] = `token ${auth.apiKey.key}:${auth.apiKey.secret}`;\n }\n\n const response = await fetch(url, {\n ...options,\n headers,\n credentials: 'include',\n });\n\n const rawData: FrappeResponse<any> = await response.json();\n\n if (!response.ok || rawData.exc) {\n // Create a proper Error object for better serialization in Next.js\n const errorMessage = rawData._error_message || rawData.exc || 'Request failed';\n const error = new Error(errorMessage) as Error & FrappeError;\n\n error.message = errorMessage;\n error.statusCode = response.status;\n\n if (rawData.exc) {\n error.exc = rawData.exc;\n }\n\n if (rawData._server_messages) {\n error.serverMessages = rawData._server_messages;\n }\n\n if (rawData.exc_type) {\n error.excType = rawData.exc_type;\n }\n\n throw error;\n }\n\n const result = rawData.message ?? rawData;\n return camelizeKeys(result) as T;\n}\n\nexport async function frappeCall<T = any>(\n baseUrl: string,\n method: string,\n args?: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeArgs = decamelizeKeys(args ?? {});\n\n return request<T>(\n baseUrl,\n `/api/method/${method}`,\n {\n method: 'POST',\n body: JSON.stringify(snakeArgs),\n },\n auth\n );\n}\n\nexport async function frappeCallGet<T = any>(\n baseUrl: string,\n method: string,\n args?: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeArgs = decamelizeKeys(args ?? {});\n const queryParams = new URLSearchParams();\n\n Object.entries(snakeArgs).forEach(([key, value]) => {\n queryParams.append(\n key,\n typeof value === 'string' ? value : JSON.stringify(value)\n );\n });\n\n const endpoint = `/api/method/${method}?${queryParams.toString()}`;\n return request<T>(baseUrl, endpoint, { method: 'GET' }, auth);\n}\n\nexport async function getList<T = any>(\n baseUrl: string,\n params: {\n doctype: string;\n fields?: string[];\n filters?: Record<string, any>;\n orderBy?: string;\n limitStart?: number;\n limitPageLength?: number;\n },\n auth?: AuthOptions\n): Promise<T[]> {\n const {\n doctype,\n fields = ['name'],\n filters = {},\n orderBy = 'modified desc',\n limitStart = 0,\n limitPageLength = 20,\n } = params;\n\n const snakeFilters = decamelizeKeys(filters);\n\n const queryParams = new URLSearchParams({\n fields: JSON.stringify(fields),\n filters: JSON.stringify(snakeFilters),\n order_by: orderBy,\n limit_start: limitStart.toString(),\n limit_page_length: limitPageLength.toString(),\n });\n\n const endpoint = `/api/resource/${doctype}?${queryParams.toString()}`;\n const response = await request<{ data: T[] }>(baseUrl, endpoint, {}, auth);\n return response.data || [];\n}\n\nexport async function getDoc<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n auth?: AuthOptions\n): Promise<T> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n const response = await request<{ data: T }>(baseUrl, endpoint, {}, auth);\n return response.data;\n}\n\nexport async function createDoc<T = any>(\n baseUrl: string,\n doctype: string,\n doc: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeDoc = decamelizeKeys(doc);\n const endpoint = `/api/resource/${doctype}`;\n const response = await request<{ data: T }>(\n baseUrl,\n endpoint,\n {\n method: 'POST',\n body: JSON.stringify(snakeDoc),\n },\n auth\n );\n return response.data;\n}\n\nexport async function updateDoc<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n doc: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeDoc = decamelizeKeys(doc);\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n const response = await request<{ data: T }>(\n baseUrl,\n endpoint,\n {\n method: 'PUT',\n body: JSON.stringify(snakeDoc),\n },\n auth\n );\n return response.data;\n}\n\nexport async function deleteDoc(\n baseUrl: string,\n doctype: string,\n name: string,\n auth?: AuthOptions\n): Promise<void> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n await request(\n baseUrl,\n endpoint,\n {\n method: 'DELETE',\n },\n auth\n );\n}\n\nexport async function getValue<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n fieldname: string,\n auth?: AuthOptions\n): Promise<T> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}?fields=[\"${fieldname}\"]`;\n const response = await request<{ data: Record<string, T> }>(\n baseUrl,\n endpoint,\n {},\n auth\n );\n const value = response.data[fieldname];\n\n if (value === undefined) {\n throw new Error(\n `Field \"${fieldname}\" not found in document \"${doctype}/${name}\"`\n );\n }\n\n return value;\n}\n\nexport async function setValue<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n fieldname: string,\n value: any,\n auth?: AuthOptions\n): Promise<T> {\n return updateDoc<T>(baseUrl, doctype, name, { [fieldname]: value }, auth);\n}\n\nexport async function getCount(\n baseUrl: string,\n doctype: string,\n filters: Record<string, any> = {},\n auth?: AuthOptions\n): Promise<number> {\n return frappeCall<number>(\n baseUrl,\n 'frappe.client.get_count',\n {\n doctype,\n filters,\n },\n auth\n );\n}\n\nexport async function getCurrentUser(\n baseUrl: string,\n auth?: AuthOptions\n): Promise<any> {\n return frappeCallGet(baseUrl, 'frappe.auth.get_logged_user', {}, auth);\n}\n","'use client';\n\nimport { createContext, useContext, useEffect, useState, type ReactNode } from 'react';\n\nexport interface FrappeContextValue {\n baseUrl: string;\n token?: string;\n apiKey?: {\n key: string;\n secret: string;\n };\n}\n\nconst FrappeContext = createContext<FrappeContextValue | null>(null);\n\nexport interface FrappeProviderProps {\n baseUrl: string;\n token?: string;\n apiKey?: {\n key: string;\n secret: string;\n };\n autoLoadAuth?: boolean;\n onLoadAuth?: () => Promise<{ token?: string; apiKey?: { key: string; secret: string } }> | { token?: string; apiKey?: { key: string; secret: string } };\n children: ReactNode;\n}\n\nexport function FrappeProvider({\n baseUrl,\n token: initialToken,\n apiKey: initialApiKey,\n autoLoadAuth = true,\n onLoadAuth,\n children,\n}: FrappeProviderProps) {\n const [token, setToken] = useState<string | undefined>(initialToken);\n const [apiKey, setApiKey] = useState<{ key: string; secret: string } | undefined>(\n initialApiKey\n );\n\n useEffect(() => {\n if (autoLoadAuth && !initialToken && !initialApiKey && onLoadAuth) {\n Promise.resolve(onLoadAuth()).then((auth) => {\n if (auth.token) {\n setToken(auth.token);\n } else if (auth.apiKey) {\n setApiKey(auth.apiKey);\n }\n });\n }\n }, [autoLoadAuth, initialToken, initialApiKey, onLoadAuth]);\n\n const value: FrappeContextValue = {\n baseUrl,\n ...(token !== undefined && { token }),\n ...(apiKey !== undefined && { apiKey }),\n };\n\n return (\n <FrappeContext.Provider value={value}>\n {children}\n </FrappeContext.Provider>\n );\n}\n\nexport function useFrappeConfig(): FrappeContextValue {\n const context = useContext(FrappeContext);\n\n if (!context) {\n throw new Error('useFrappeConfig must be used within FrappeProvider');\n }\n\n return context;\n}\n","'use client';\n\nimport { useFrappeConfig } from './context';\nimport {\n frappeCall as frappeCallCore,\n frappeCallGet as frappeCallGetCore,\n getDoc as getDocCore,\n getList as getListCore,\n createDoc as createDocCore,\n updateDoc as updateDocCore,\n deleteDoc as deleteDocCore,\n} from './core';\nimport type { AuthOptions } from './types';\n\nexport function useFrappe() {\n const { baseUrl, token, apiKey } = useFrappeConfig();\n\n const auth: AuthOptions = {\n ...(token && { token }),\n ...(apiKey && { apiKey }),\n };\n\n return {\n call: <T = any>(method: string, args?: Record<string, any>) =>\n frappeCallCore<T>(baseUrl, method, args, auth),\n\n callGet: <T = any>(method: string, args?: Record<string, any>) =>\n frappeCallGetCore<T>(baseUrl, method, args, auth),\n\n getList: <T = any>(params: {\n doctype: string;\n fields?: string[];\n filters?: Record<string, any>;\n orderBy?: string;\n limitStart?: number;\n limitPageLength?: number;\n }) => getListCore<T>(baseUrl, params, auth),\n\n getDoc: <T = any>(doctype: string, name: string) =>\n getDocCore<T>(baseUrl, doctype, name, auth),\n\n createDoc: <T = any>(doctype: string, doc: Record<string, any>) =>\n createDocCore<T>(baseUrl, doctype, doc, auth),\n\n updateDoc: <T = any>(\n doctype: string,\n name: string,\n doc: Record<string, any>\n ) => updateDocCore<T>(baseUrl, doctype, name, doc, auth),\n\n deleteDoc: (doctype: string, name: string) =>\n deleteDocCore(baseUrl, doctype, name, auth),\n\n baseUrl,\n auth,\n };\n}\n","export interface StorageAdapter {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport const webStorageAdapter: StorageAdapter = {\n getItem: (key: string) => {\n if (typeof window === 'undefined') return null;\n return localStorage.getItem(key);\n },\n setItem: (key: string, value: string) => {\n if (typeof window === 'undefined') return;\n localStorage.setItem(key, value);\n },\n removeItem: (key: string) => {\n if (typeof window === 'undefined') return;\n localStorage.removeItem(key);\n },\n};\n\nlet currentAdapter: StorageAdapter = webStorageAdapter;\n\nexport function setStorageAdapter(adapter: StorageAdapter) {\n currentAdapter = adapter;\n}\n\nexport function getStorageAdapter(): StorageAdapter {\n return currentAdapter;\n}\n\nconst TOKEN_KEY = 'frappe_token';\nconst API_KEY_KEY = 'frappe_api_key';\nconst API_SECRET_KEY = 'frappe_api_secret';\n\nexport function getToken(): string | null | Promise<string | null> {\n return currentAdapter.getItem(TOKEN_KEY);\n}\n\nexport function setToken(token: string): void | Promise<void> {\n return currentAdapter.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken(): void | Promise<void> {\n return currentAdapter.removeItem(TOKEN_KEY);\n}\n\nexport async function getApiKey(): Promise<{ key: string; secret: string } | null> {\n const key = await currentAdapter.getItem(API_KEY_KEY);\n const secret = await currentAdapter.getItem(API_SECRET_KEY);\n\n if (!key || !secret) return null;\n\n return { key, secret };\n}\n\nexport async function setApiKey(key: string, secret: string): Promise<void> {\n await currentAdapter.setItem(API_KEY_KEY, key);\n await currentAdapter.setItem(API_SECRET_KEY, secret);\n}\n\nexport async function clearApiKey(): Promise<void> {\n await currentAdapter.removeItem(API_KEY_KEY);\n await currentAdapter.removeItem(API_SECRET_KEY);\n}\n\nexport async function clearAuth(): Promise<void> {\n await clearToken();\n await clearApiKey();\n}\n\nexport async function isAuthenticated(): Promise<boolean> {\n const token = await getToken();\n const apiKey = await getApiKey();\n return !!token || !!apiKey;\n}\n","import { getDoc } from '../../client'\nimport type { AuthOptions } from '../../client'\nimport type { Page } from './types'\n\nexport async function getPage(\n baseUrl: string,\n slug: string,\n auth?: AuthOptions\n): Promise<Page> {\n return getDoc<Page>(baseUrl, 'Design Page', slug, auth)\n}\n","import type {ModelNumber} from \"../lasterp\";\n\nexport function toDescription(modelNumber: ModelNumber) {\n if (!modelNumber) {\n return null;\n }\n return modelNumber.simCardType;\n}\n","export function equalsIgnoreCase(str1: string, str2: string): boolean {\n return str1.localeCompare(str2, undefined, { sensitivity: 'accent' }) === 0;\n};\n","import { frappeCall } from '../../client';\nimport type { AuthOptions } from '../../client';\nimport type { ShopContext, ProductContext } from './types';\n\nexport async function getShopContext(\n baseUrl: string,\n params?: {\n categoryName?: string;\n gradeName?: string;\n },\n auth?: AuthOptions\n): Promise<ShopContext> {\n return frappeCall<ShopContext>(\n baseUrl,\n 'lasterp.shop.controllers.shop_controller.get_context',\n params,\n auth\n );\n}\n\nexport async function getProductContext(\n baseUrl: string,\n productName: string,\n auth?: AuthOptions\n): Promise<ProductContext> {\n return frappeCall<ProductContext>(\n baseUrl,\n 'lasterp.shop.controllers.product_controller.get_context',\n { productName },\n auth\n );\n}\n","'use client';\n\nimport { useQuery, type UseQueryOptions } from '@tanstack/react-query';\nimport { useFrappe } from '../../client';\nimport { getShopContext, getProductContext } from './api';\nimport type { ShopContext, ProductContext } from './types';\n\nexport function useShopContext(\n params?: {\n categoryName?: string;\n gradeName?: string;\n },\n options?: Omit<\n UseQueryOptions<ShopContext, Error>,\n 'queryKey' | 'queryFn'\n >\n) {\n const { baseUrl, auth } = useFrappe();\n\n return useQuery<ShopContext, Error>({\n queryKey: ['shop-context', params],\n queryFn: () => getShopContext(baseUrl, params, auth),\n ...options,\n });\n}\n\nexport function useProductContext(\n productName: string,\n options?: Omit<\n UseQueryOptions<ProductContext, Error>,\n 'queryKey' | 'queryFn'\n >\n) {\n const { baseUrl, auth } = useFrappe();\n\n return useQuery<ProductContext, Error>({\n queryKey: ['product-context', productName],\n queryFn: () => getProductContext(baseUrl, productName, auth),\n enabled: !!productName,\n ...options,\n });\n}\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
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 };
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/core.ts","../src/client/context.tsx","../src/client/hooks.tsx","../src/client/storage.ts","../src/design/page/api.ts","../src/utils/catalog.ts","../src/utils/types.ts","../src/lasterp/shop/api.ts","../src/lasterp/shop/hooks.tsx"],"names":["setToken","setApiKey"],"mappings":";;;;;;AAGA,eAAe,QACb,OAAA,EACA,QAAA,EACA,OAAA,GAAuB,IACvB,IAAA,EACY;AACZ,EAAA,MAAM,GAAA,GAAM,CAAA,EAAG,OAAO,CAAA,EAAG,QAAQ,CAAA,CAAA;AAEjC,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,cAAA,EAAgB,kBAAA;AAAA,IAChB,MAAA,EAAQ,kBAAA;AAAA,IACR,GAAI,OAAA,CAAQ;AAAA,GACd;AAEA,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,IACnD,GAAG;AAAA,GACJ,CAAA;AACH;AAEO,SAAS,iBAAA,CACd,aACA,OAAA,EAIA;AACA,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,SAAA,EAAU;AAEpC,EAAA,OAAO,QAAA,CAAgC;AAAA,IACrC,QAAA,EAAU,CAAC,iBAAA,EAAmB,WAAW,CAAA;AAAA,IACzC,OAAA,EAAS,MAAM,iBAAA,CAAkB,OAAA,EAAS,aAAa,IAAI,CAAA;AAAA,IAC3D,OAAA,EAAS,CAAC,CAAC,WAAA;AAAA,IACX,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.js","sourcesContent":["import { camelizeKeys, decamelizeKeys } from 'humps';\nimport type { FrappeResponse, FrappeError, AuthOptions } from './types';\n\nasync function request<T = any>(\n baseUrl: string,\n endpoint: string,\n options: RequestInit = {},\n auth?: AuthOptions\n): Promise<T> {\n const url = `${baseUrl}${endpoint}`;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...(options.headers as Record<string, string>),\n };\n\n if (auth?.token) {\n headers['Authorization'] = `Bearer ${auth.token}`;\n } else if (auth?.apiKey) {\n headers['Authorization'] = `token ${auth.apiKey.key}:${auth.apiKey.secret}`;\n }\n\n const response = await fetch(url, {\n ...options,\n headers,\n credentials: 'include',\n });\n\n const rawData: FrappeResponse<any> = await response.json();\n\n if (!response.ok || rawData.exc) {\n // Create a proper Error object for better serialization in Next.js\n const errorMessage = rawData._error_message || rawData.exc || 'Request failed';\n const error = new Error(errorMessage) as Error & FrappeError;\n\n error.message = errorMessage;\n error.statusCode = response.status;\n\n if (rawData.exc) {\n error.exc = rawData.exc;\n }\n\n if (rawData._server_messages) {\n error.serverMessages = rawData._server_messages;\n }\n\n if (rawData.exc_type) {\n error.excType = rawData.exc_type;\n }\n\n throw error;\n }\n\n const result = rawData.message ?? rawData;\n return camelizeKeys(result) as T;\n}\n\nexport async function frappeCall<T = any>(\n baseUrl: string,\n method: string,\n args?: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeArgs = decamelizeKeys(args ?? {});\n\n return request<T>(\n baseUrl,\n `/api/method/${method}`,\n {\n method: 'POST',\n body: JSON.stringify(snakeArgs),\n },\n auth\n );\n}\n\nexport async function frappeCallGet<T = any>(\n baseUrl: string,\n method: string,\n args?: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeArgs = decamelizeKeys(args ?? {});\n const queryParams = new URLSearchParams();\n\n Object.entries(snakeArgs).forEach(([key, value]) => {\n queryParams.append(\n key,\n typeof value === 'string' ? value : JSON.stringify(value)\n );\n });\n\n const endpoint = `/api/method/${method}?${queryParams.toString()}`;\n return request<T>(baseUrl, endpoint, { method: 'GET' }, auth);\n}\n\nexport async function getList<T = any>(\n baseUrl: string,\n params: {\n doctype: string;\n fields?: string[];\n filters?: Record<string, any>;\n orderBy?: string;\n limitStart?: number;\n limitPageLength?: number;\n },\n auth?: AuthOptions\n): Promise<T[]> {\n const {\n doctype,\n fields = ['name'],\n filters = {},\n orderBy = 'modified desc',\n limitStart = 0,\n limitPageLength = 20,\n } = params;\n\n const snakeFilters = decamelizeKeys(filters);\n\n const queryParams = new URLSearchParams({\n fields: JSON.stringify(fields),\n filters: JSON.stringify(snakeFilters),\n order_by: orderBy,\n limit_start: limitStart.toString(),\n limit_page_length: limitPageLength.toString(),\n });\n\n const endpoint = `/api/resource/${doctype}?${queryParams.toString()}`;\n const response = await request<{ data: T[] }>(baseUrl, endpoint, {}, auth);\n return response.data || [];\n}\n\nexport async function getDoc<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n auth?: AuthOptions\n): Promise<T> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n const response = await request<{ data: T }>(baseUrl, endpoint, {}, auth);\n return response.data;\n}\n\nexport async function createDoc<T = any>(\n baseUrl: string,\n doctype: string,\n doc: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeDoc = decamelizeKeys(doc);\n const endpoint = `/api/resource/${doctype}`;\n const response = await request<{ data: T }>(\n baseUrl,\n endpoint,\n {\n method: 'POST',\n body: JSON.stringify(snakeDoc),\n },\n auth\n );\n return response.data;\n}\n\nexport async function updateDoc<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n doc: Record<string, any>,\n auth?: AuthOptions\n): Promise<T> {\n const snakeDoc = decamelizeKeys(doc);\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n const response = await request<{ data: T }>(\n baseUrl,\n endpoint,\n {\n method: 'PUT',\n body: JSON.stringify(snakeDoc),\n },\n auth\n );\n return response.data;\n}\n\nexport async function deleteDoc(\n baseUrl: string,\n doctype: string,\n name: string,\n auth?: AuthOptions\n): Promise<void> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}`;\n await request(\n baseUrl,\n endpoint,\n {\n method: 'DELETE',\n },\n auth\n );\n}\n\nexport async function getValue<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n fieldname: string,\n auth?: AuthOptions\n): Promise<T> {\n const endpoint = `/api/resource/${doctype}/${encodeURIComponent(name)}?fields=[\"${fieldname}\"]`;\n const response = await request<{ data: Record<string, T> }>(\n baseUrl,\n endpoint,\n {},\n auth\n );\n const value = response.data[fieldname];\n\n if (value === undefined) {\n throw new Error(\n `Field \"${fieldname}\" not found in document \"${doctype}/${name}\"`\n );\n }\n\n return value;\n}\n\nexport async function setValue<T = any>(\n baseUrl: string,\n doctype: string,\n name: string,\n fieldname: string,\n value: any,\n auth?: AuthOptions\n): Promise<T> {\n return updateDoc<T>(baseUrl, doctype, name, { [fieldname]: value }, auth);\n}\n\nexport async function getCount(\n baseUrl: string,\n doctype: string,\n filters: Record<string, any> = {},\n auth?: AuthOptions\n): Promise<number> {\n return frappeCall<number>(\n baseUrl,\n 'frappe.client.get_count',\n {\n doctype,\n filters,\n },\n auth\n );\n}\n\nexport async function getCurrentUser(\n baseUrl: string,\n auth?: AuthOptions\n): Promise<any> {\n return frappeCallGet(baseUrl, 'frappe.auth.get_logged_user', {}, auth);\n}\n","'use client';\n\nimport { createContext, useContext, useEffect, useState, type ReactNode } from 'react';\n\nexport interface FrappeContextValue {\n baseUrl: string;\n token?: string;\n apiKey?: {\n key: string;\n secret: string;\n };\n}\n\nconst FrappeContext = createContext<FrappeContextValue | null>(null);\n\nexport interface FrappeProviderProps {\n baseUrl: string;\n token?: string;\n apiKey?: {\n key: string;\n secret: string;\n };\n autoLoadAuth?: boolean;\n onLoadAuth?: () => Promise<{ token?: string; apiKey?: { key: string; secret: string } }> | { token?: string; apiKey?: { key: string; secret: string } };\n children: ReactNode;\n}\n\nexport function FrappeProvider({\n baseUrl,\n token: initialToken,\n apiKey: initialApiKey,\n autoLoadAuth = true,\n onLoadAuth,\n children,\n}: FrappeProviderProps) {\n const [token, setToken] = useState<string | undefined>(initialToken);\n const [apiKey, setApiKey] = useState<{ key: string; secret: string } | undefined>(\n initialApiKey\n );\n\n useEffect(() => {\n if (autoLoadAuth && !initialToken && !initialApiKey && onLoadAuth) {\n Promise.resolve(onLoadAuth()).then((auth) => {\n if (auth.token) {\n setToken(auth.token);\n } else if (auth.apiKey) {\n setApiKey(auth.apiKey);\n }\n });\n }\n }, [autoLoadAuth, initialToken, initialApiKey, onLoadAuth]);\n\n const value: FrappeContextValue = {\n baseUrl,\n ...(token !== undefined && { token }),\n ...(apiKey !== undefined && { apiKey }),\n };\n\n return (\n <FrappeContext.Provider value={value}>\n {children}\n </FrappeContext.Provider>\n );\n}\n\nexport function useFrappeConfig(): FrappeContextValue {\n const context = useContext(FrappeContext);\n\n if (!context) {\n throw new Error('useFrappeConfig must be used within FrappeProvider');\n }\n\n return context;\n}\n","'use client';\n\nimport { useFrappeConfig } from './context';\nimport {\n frappeCall as frappeCallCore,\n frappeCallGet as frappeCallGetCore,\n getDoc as getDocCore,\n getList as getListCore,\n createDoc as createDocCore,\n updateDoc as updateDocCore,\n deleteDoc as deleteDocCore,\n} from './core';\nimport type { AuthOptions } from './types';\n\nexport function useFrappe() {\n const { baseUrl, token, apiKey } = useFrappeConfig();\n\n const auth: AuthOptions = {\n ...(token && { token }),\n ...(apiKey && { apiKey }),\n };\n\n return {\n call: <T = any>(method: string, args?: Record<string, any>) =>\n frappeCallCore<T>(baseUrl, method, args, auth),\n\n callGet: <T = any>(method: string, args?: Record<string, any>) =>\n frappeCallGetCore<T>(baseUrl, method, args, auth),\n\n getList: <T = any>(params: {\n doctype: string;\n fields?: string[];\n filters?: Record<string, any>;\n orderBy?: string;\n limitStart?: number;\n limitPageLength?: number;\n }) => getListCore<T>(baseUrl, params, auth),\n\n getDoc: <T = any>(doctype: string, name: string) =>\n getDocCore<T>(baseUrl, doctype, name, auth),\n\n createDoc: <T = any>(doctype: string, doc: Record<string, any>) =>\n createDocCore<T>(baseUrl, doctype, doc, auth),\n\n updateDoc: <T = any>(\n doctype: string,\n name: string,\n doc: Record<string, any>\n ) => updateDocCore<T>(baseUrl, doctype, name, doc, auth),\n\n deleteDoc: (doctype: string, name: string) =>\n deleteDocCore(baseUrl, doctype, name, auth),\n\n baseUrl,\n auth,\n };\n}\n","export interface StorageAdapter {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport const webStorageAdapter: StorageAdapter = {\n getItem: (key: string) => {\n if (typeof window === 'undefined') return null;\n return localStorage.getItem(key);\n },\n setItem: (key: string, value: string) => {\n if (typeof window === 'undefined') return;\n localStorage.setItem(key, value);\n },\n removeItem: (key: string) => {\n if (typeof window === 'undefined') return;\n localStorage.removeItem(key);\n },\n};\n\nlet currentAdapter: StorageAdapter = webStorageAdapter;\n\nexport function setStorageAdapter(adapter: StorageAdapter) {\n currentAdapter = adapter;\n}\n\nexport function getStorageAdapter(): StorageAdapter {\n return currentAdapter;\n}\n\nconst TOKEN_KEY = 'frappe_token';\nconst API_KEY_KEY = 'frappe_api_key';\nconst API_SECRET_KEY = 'frappe_api_secret';\n\nexport function getToken(): string | null | Promise<string | null> {\n return currentAdapter.getItem(TOKEN_KEY);\n}\n\nexport function setToken(token: string): void | Promise<void> {\n return currentAdapter.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken(): void | Promise<void> {\n return currentAdapter.removeItem(TOKEN_KEY);\n}\n\nexport async function getApiKey(): Promise<{ key: string; secret: string } | null> {\n const key = await currentAdapter.getItem(API_KEY_KEY);\n const secret = await currentAdapter.getItem(API_SECRET_KEY);\n\n if (!key || !secret) return null;\n\n return { key, secret };\n}\n\nexport async function setApiKey(key: string, secret: string): Promise<void> {\n await currentAdapter.setItem(API_KEY_KEY, key);\n await currentAdapter.setItem(API_SECRET_KEY, secret);\n}\n\nexport async function clearApiKey(): Promise<void> {\n await currentAdapter.removeItem(API_KEY_KEY);\n await currentAdapter.removeItem(API_SECRET_KEY);\n}\n\nexport async function clearAuth(): Promise<void> {\n await clearToken();\n await clearApiKey();\n}\n\nexport async function isAuthenticated(): Promise<boolean> {\n const token = await getToken();\n const apiKey = await getApiKey();\n return !!token || !!apiKey;\n}\n","import { getDoc } from '../../client'\nimport type { AuthOptions } from '../../client'\nimport type { Page } from './types'\n\nexport async function getPage(\n baseUrl: string,\n slug: string,\n auth?: AuthOptions\n): Promise<Page> {\n return getDoc<Page>(baseUrl, 'Design Page', slug, auth)\n}\n","import type {ModelNumber} from \"../lasterp\";\n\nexport function toDescription(modelNumber: ModelNumber) {\n if (!modelNumber) {\n return null;\n }\n return modelNumber.simCardType;\n}\n","export function equalsIgnoreCase(str1: string, str2: string): boolean {\n return str1.localeCompare(str2, undefined, { sensitivity: 'accent' }) === 0;\n};\n","import { frappeCall } from '../../client';\nimport type { AuthOptions } from '../../client';\nimport type { ShopContext, ProductContext } from './types';\n\nexport async function getShopContext(\n baseUrl: string,\n params?: {\n categoryName?: string;\n gradeName?: string;\n },\n auth?: AuthOptions\n): Promise<ShopContext> {\n return frappeCall<ShopContext>(\n baseUrl,\n 'lasterp.shop.controllers.shop_controller.get_context',\n params,\n auth\n );\n}\n\nexport async function getProductContext(\n baseUrl: string,\n productName: string,\n auth?: AuthOptions\n): Promise<ProductContext> {\n return frappeCall<ProductContext>(\n baseUrl,\n 'lasterp.shop.controllers.product_controller.get_context',\n { productName },\n auth\n );\n}\n","'use client';\n\nimport { useQuery, type UseQueryOptions } from '@tanstack/react-query';\nimport { useFrappe } from '../../client';\nimport { getShopContext, getProductContext } from './api';\nimport type { ShopContext, ProductContext } from './types';\n\nexport function useShopContext(\n params?: {\n categoryName?: string;\n gradeName?: string;\n },\n options?: Omit<\n UseQueryOptions<ShopContext, Error>,\n 'queryKey' | 'queryFn'\n >\n) {\n const { baseUrl, auth } = useFrappe();\n\n return useQuery<ShopContext, Error>({\n queryKey: ['shop-context', params],\n queryFn: () => getShopContext(baseUrl, params, auth),\n ...options,\n });\n}\n\nexport function useProductContext(\n productName: string,\n options?: Omit<\n UseQueryOptions<ProductContext, Error>,\n 'queryKey' | 'queryFn'\n >\n) {\n const { baseUrl, auth } = useFrappe();\n\n return useQuery<ProductContext, Error>({\n queryKey: ['product-context', productName],\n queryFn: () => getProductContext(baseUrl, productName, auth),\n enabled: !!productName,\n ...options,\n });\n}\n"]}
|
package/src/client/context.tsx
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
export interface FrappeContextValue {
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
apiKey?: {
|
|
9
|
-
key: string;
|
|
10
|
-
secret: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const FrappeContext = createContext<FrappeContextValue | null>(null);
|
|
15
|
-
|
|
16
|
-
export interface FrappeProviderProps {
|
|
17
|
-
baseUrl: string;
|
|
18
|
-
token?: string;
|
|
19
|
-
apiKey?: {
|
|
20
|
-
key: string;
|
|
21
|
-
secret: string;
|
|
22
|
-
};
|
|
23
|
-
autoLoadAuth?: boolean;
|
|
24
|
-
onLoadAuth?: () => Promise<{ token?: string; apiKey?: { key: string; secret: string } }> | { token?: string; apiKey?: { key: string; secret: string } };
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function FrappeProvider({
|
|
29
|
-
baseUrl,
|
|
30
|
-
token: initialToken,
|
|
31
|
-
apiKey: initialApiKey,
|
|
32
|
-
autoLoadAuth = true,
|
|
33
|
-
onLoadAuth,
|
|
34
|
-
children,
|
|
35
|
-
}: FrappeProviderProps) {
|
|
36
|
-
const [token, setToken] = useState<string | undefined>(initialToken);
|
|
37
|
-
const [apiKey, setApiKey] = useState<{ key: string; secret: string } | undefined>(
|
|
38
|
-
initialApiKey
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (autoLoadAuth && !initialToken && !initialApiKey && onLoadAuth) {
|
|
43
|
-
Promise.resolve(onLoadAuth()).then((auth) => {
|
|
44
|
-
if (auth.token) {
|
|
45
|
-
setToken(auth.token);
|
|
46
|
-
} else if (auth.apiKey) {
|
|
47
|
-
setApiKey(auth.apiKey);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}, [autoLoadAuth, initialToken, initialApiKey, onLoadAuth]);
|
|
52
|
-
|
|
53
|
-
const value: FrappeContextValue = {
|
|
54
|
-
baseUrl,
|
|
55
|
-
...(token !== undefined && { token }),
|
|
56
|
-
...(apiKey !== undefined && { apiKey }),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<FrappeContext.Provider value={value}>
|
|
61
|
-
{children}
|
|
62
|
-
</FrappeContext.Provider>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function useFrappeConfig(): FrappeContextValue {
|
|
67
|
-
const context = useContext(FrappeContext);
|
|
68
|
-
|
|
69
|
-
if (!context) {
|
|
70
|
-
throw new Error('useFrappeConfig must be used within FrappeProvider');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return context;
|
|
74
|
-
}
|