@lasterp/shared 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
@@ -1,57 +0,0 @@
1
- 'use client';
2
-
3
- import { useFrappeConfig } from './context';
4
- import {
5
- frappeCall as frappeCallCore,
6
- frappeCallGet as frappeCallGetCore,
7
- getDoc as getDocCore,
8
- getList as getListCore,
9
- createDoc as createDocCore,
10
- updateDoc as updateDocCore,
11
- deleteDoc as deleteDocCore,
12
- } from './core';
13
- import type { AuthOptions } from './types';
14
-
15
- export function useFrappe() {
16
- const { baseUrl, token, apiKey } = useFrappeConfig();
17
-
18
- const auth: AuthOptions = {
19
- ...(token && { token }),
20
- ...(apiKey && { apiKey }),
21
- };
22
-
23
- return {
24
- call: <T = any>(method: string, args?: Record<string, any>) =>
25
- frappeCallCore<T>(baseUrl, method, args, auth),
26
-
27
- callGet: <T = any>(method: string, args?: Record<string, any>) =>
28
- frappeCallGetCore<T>(baseUrl, method, args, auth),
29
-
30
- getList: <T = any>(params: {
31
- doctype: string;
32
- fields?: string[];
33
- filters?: Record<string, any>;
34
- orderBy?: string;
35
- limitStart?: number;
36
- limitPageLength?: number;
37
- }) => getListCore<T>(baseUrl, params, auth),
38
-
39
- getDoc: <T = any>(doctype: string, name: string) =>
40
- getDocCore<T>(baseUrl, doctype, name, auth),
41
-
42
- createDoc: <T = any>(doctype: string, doc: Record<string, any>) =>
43
- createDocCore<T>(baseUrl, doctype, doc, auth),
44
-
45
- updateDoc: <T = any>(
46
- doctype: string,
47
- name: string,
48
- doc: Record<string, any>
49
- ) => updateDocCore<T>(baseUrl, doctype, name, doc, auth),
50
-
51
- deleteDoc: (doctype: string, name: string) =>
52
- deleteDocCore(baseUrl, doctype, name, auth),
53
-
54
- baseUrl,
55
- auth,
56
- };
57
- }
@@ -1,20 +0,0 @@
1
- export {
2
- frappeCall,
3
- frappeCallGet,
4
- getList,
5
- getDoc,
6
- createDoc,
7
- updateDoc,
8
- deleteDoc,
9
- getValue,
10
- setValue,
11
- getCount,
12
- getCurrentUser,
13
- } from './core';
14
-
15
- export type { FrappeResponse, FrappeError, AuthOptions } from './types';
16
- export { FrappeProvider, useFrappeConfig } from './context';
17
- export type { FrappeContextValue, FrappeProviderProps } from './context';
18
- export { useFrappe } from './hooks';
19
-
20
- export * from './storage';
@@ -1,76 +0,0 @@
1
- export interface StorageAdapter {
2
- getItem(key: string): string | null | Promise<string | null>;
3
- setItem(key: string, value: string): void | Promise<void>;
4
- removeItem(key: string): void | Promise<void>;
5
- }
6
-
7
- export const webStorageAdapter: StorageAdapter = {
8
- getItem: (key: string) => {
9
- if (typeof window === 'undefined') return null;
10
- return localStorage.getItem(key);
11
- },
12
- setItem: (key: string, value: string) => {
13
- if (typeof window === 'undefined') return;
14
- localStorage.setItem(key, value);
15
- },
16
- removeItem: (key: string) => {
17
- if (typeof window === 'undefined') return;
18
- localStorage.removeItem(key);
19
- },
20
- };
21
-
22
- let currentAdapter: StorageAdapter = webStorageAdapter;
23
-
24
- export function setStorageAdapter(adapter: StorageAdapter) {
25
- currentAdapter = adapter;
26
- }
27
-
28
- export function getStorageAdapter(): StorageAdapter {
29
- return currentAdapter;
30
- }
31
-
32
- const TOKEN_KEY = 'frappe_token';
33
- const API_KEY_KEY = 'frappe_api_key';
34
- const API_SECRET_KEY = 'frappe_api_secret';
35
-
36
- export function getToken(): string | null | Promise<string | null> {
37
- return currentAdapter.getItem(TOKEN_KEY);
38
- }
39
-
40
- export function setToken(token: string): void | Promise<void> {
41
- return currentAdapter.setItem(TOKEN_KEY, token);
42
- }
43
-
44
- export function clearToken(): void | Promise<void> {
45
- return currentAdapter.removeItem(TOKEN_KEY);
46
- }
47
-
48
- export async function getApiKey(): Promise<{ key: string; secret: string } | null> {
49
- const key = await currentAdapter.getItem(API_KEY_KEY);
50
- const secret = await currentAdapter.getItem(API_SECRET_KEY);
51
-
52
- if (!key || !secret) return null;
53
-
54
- return { key, secret };
55
- }
56
-
57
- export async function setApiKey(key: string, secret: string): Promise<void> {
58
- await currentAdapter.setItem(API_KEY_KEY, key);
59
- await currentAdapter.setItem(API_SECRET_KEY, secret);
60
- }
61
-
62
- export async function clearApiKey(): Promise<void> {
63
- await currentAdapter.removeItem(API_KEY_KEY);
64
- await currentAdapter.removeItem(API_SECRET_KEY);
65
- }
66
-
67
- export async function clearAuth(): Promise<void> {
68
- await clearToken();
69
- await clearApiKey();
70
- }
71
-
72
- export async function isAuthenticated(): Promise<boolean> {
73
- const token = await getToken();
74
- const apiKey = await getApiKey();
75
- return !!token || !!apiKey;
76
- }
@@ -1,24 +0,0 @@
1
- export interface FrappeResponse<T = any> {
2
- message?: T;
3
- docs?: T[];
4
- exc?: string;
5
- exc_type?: string;
6
- _server_messages?: string;
7
- _error_message?: string;
8
- }
9
-
10
- export interface FrappeError {
11
- message: string;
12
- statusCode?: number;
13
- exc?: string;
14
- excType?: string;
15
- serverMessages?: string;
16
- }
17
-
18
- export interface AuthOptions {
19
- token?: string;
20
- apiKey?: {
21
- key: string;
22
- secret: string;
23
- };
24
- }
@@ -1 +0,0 @@
1
- export type { FrappeDoc, FrappeChildDoc } from './types';
@@ -1,15 +0,0 @@
1
- export interface FrappeDoc {
2
- name: string;
3
- creation?: string;
4
- modified?: string;
5
- modifiedBy?: string;
6
- owner?: string;
7
- docStatus?: number;
8
- idx?: number;
9
- }
10
-
11
- export interface FrappeChildDoc extends FrappeDoc {
12
- parent: string;
13
- parentType: string;
14
- parentField: string;
15
- }
@@ -1,8 +0,0 @@
1
- export interface AaveFeatureSlidesData {
2
- feature1Title: string
3
- feature1Description: string
4
- feature1Cta?: string
5
- feature2Title: string
6
- feature2Description: string
7
- feature2Cta?: string
8
- }
@@ -1,20 +0,0 @@
1
-
2
- export interface FooterItemGroup {
3
- title: string;
4
- items: FooterItem[];
5
- }
6
-
7
- export interface FooterItem {
8
- label: string;
9
- link?: string;
10
- }
11
-
12
- export interface Footer {
13
- footerType?: string;
14
- groups: FooterItemGroup[];
15
- copyright?: string;
16
- address?: string;
17
- country?: string;
18
- phone?: string;
19
- email?: string;
20
- }
@@ -1,43 +0,0 @@
1
- export interface Brand {
2
- brandImage?: string;
3
- }
4
-
5
- export interface NavbarItem {
6
- label: string;
7
- enableDropdown: boolean;
8
- enableLink: boolean;
9
- link?: string;
10
- dropdownDescription?: string;
11
- dropdownCta?: string;
12
- groups?: NavbarSubItemGroup[]
13
- }
14
-
15
- export interface NavbarSubItemGroup {
16
- title?: string;
17
- items: NavbarSubItem[];
18
- }
19
-
20
- export interface NavbarSubItem {
21
- label: string;
22
- description?: string;
23
- image?: string;
24
- link?: string;
25
- }
26
-
27
- export interface Topbar {
28
- topbarEnabled?: boolean;
29
- items: TopbarItem[];
30
- }
31
-
32
- export interface TopbarItem {
33
- icon?: string;
34
- label: string;
35
- link?: string;
36
- }
37
-
38
- export interface Header {
39
- brand: Brand;
40
- headerType?: string;
41
- tabs: NavbarItem[];
42
- topbar: Topbar;
43
- }
@@ -1,7 +0,0 @@
1
- import type {Header} from "./header";
2
- import type {Footer} from "./footer";
3
-
4
- export interface Globals {
5
- header: Header
6
- footer: Footer
7
- }
@@ -1,8 +0,0 @@
1
- export * from './globals/types';
2
- export * from './globals/header';
3
- export * from './globals/footer';
4
-
5
- export * from './page/types';
6
- export * from './page/api';
7
-
8
- export * from './block/types';
@@ -1,11 +0,0 @@
1
- import { getDoc } from '../../client'
2
- import type { AuthOptions } from '../../client'
3
- import type { Page } from './types'
4
-
5
- export async function getPage(
6
- baseUrl: string,
7
- slug: string,
8
- auth?: AuthOptions
9
- ): Promise<Page> {
10
- return getDoc<Page>(baseUrl, 'Design Page', slug, auth)
11
- }
@@ -1,15 +0,0 @@
1
- export interface Hero {
2
- type: string;
3
- data: Record<string, unknown>;
4
- }
5
-
6
- export interface Block {
7
- type: string;
8
- data?: Record<string, unknown>;
9
- }
10
-
11
- export interface Page {
12
- slug: string;
13
- hero?: Hero;
14
- blocks: Block[];
15
- }
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './common'
2
- export * from './client'
3
- export * from './design'
4
- export * from './utils'
5
- export * from './lasterp'
@@ -1,24 +0,0 @@
1
- export interface Item {
2
- itemCode: string
3
- region: string
4
- grade: string
5
- gradeIssuer: string
6
- color: string
7
- storage: string
8
- memory: string
9
- network: string
10
- }
11
-
12
- export interface ItemVariant extends Item {
13
- itemVariant: string
14
- }
15
-
16
- export interface ModelNumber {
17
- modelNumber: string
18
- simCardType: string
19
- }
20
-
21
- export interface Colour {
22
- name: string
23
- color: string
24
- }
@@ -1,5 +0,0 @@
1
- export * from './catalog/types';
2
-
3
- export * from './shop/types';
4
- export * from './shop/api';
5
- export * from './shop/hooks';
@@ -1,32 +0,0 @@
1
- import { frappeCall } from '../../client';
2
- import type { AuthOptions } from '../../client';
3
- import type { ShopContext, ProductContext } from './types';
4
-
5
- export async function getShopContext(
6
- baseUrl: string,
7
- params?: {
8
- categoryName?: string;
9
- gradeName?: string;
10
- },
11
- auth?: AuthOptions
12
- ): Promise<ShopContext> {
13
- return frappeCall<ShopContext>(
14
- baseUrl,
15
- 'lasterp.shop.controllers.shop_controller.get_context',
16
- params,
17
- auth
18
- );
19
- }
20
-
21
- export async function getProductContext(
22
- baseUrl: string,
23
- productName: string,
24
- auth?: AuthOptions
25
- ): Promise<ProductContext> {
26
- return frappeCall<ProductContext>(
27
- baseUrl,
28
- 'lasterp.shop.controllers.product_controller.get_context',
29
- { productName },
30
- auth
31
- );
32
- }
@@ -1,42 +0,0 @@
1
- 'use client';
2
-
3
- import { useQuery, type UseQueryOptions } from '@tanstack/react-query';
4
- import { useFrappe } from '../../client';
5
- import { getShopContext, getProductContext } from './api';
6
- import type { ShopContext, ProductContext } from './types';
7
-
8
- export function useShopContext(
9
- params?: {
10
- categoryName?: string;
11
- gradeName?: string;
12
- },
13
- options?: Omit<
14
- UseQueryOptions<ShopContext, Error>,
15
- 'queryKey' | 'queryFn'
16
- >
17
- ) {
18
- const { baseUrl, auth } = useFrappe();
19
-
20
- return useQuery<ShopContext, Error>({
21
- queryKey: ['shop-context', params],
22
- queryFn: () => getShopContext(baseUrl, params, auth),
23
- ...options,
24
- });
25
- }
26
-
27
- export function useProductContext(
28
- productName: string,
29
- options?: Omit<
30
- UseQueryOptions<ProductContext, Error>,
31
- 'queryKey' | 'queryFn'
32
- >
33
- ) {
34
- const { baseUrl, auth } = useFrappe();
35
-
36
- return useQuery<ProductContext, Error>({
37
- queryKey: ['product-context', productName],
38
- queryFn: () => getProductContext(baseUrl, productName, auth),
39
- enabled: !!productName,
40
- ...options,
41
- });
42
- }
@@ -1,42 +0,0 @@
1
- import type {Colour, Item, ItemVariant, ModelNumber} from '../catalog/types'
2
-
3
- export interface Category {
4
- name: string
5
- categoryName: string
6
- sequenceId: number
7
- itemCode: string[]
8
- itemGroup: string[]
9
- brand: string[]
10
- os: string[]
11
- }
12
-
13
- export interface Product extends Item {
14
- name: string
15
- image: string
16
- }
17
-
18
- export interface ProductVariant extends ItemVariant {
19
- id: string
20
- specs: Record<string, string>
21
- price: number
22
- stock: number
23
- }
24
-
25
- export interface ShopContext {
26
- title?: string
27
- categories?: Category[]
28
- selectedCategory?: Category
29
- grades?: string[]
30
- selectedGrade?: string
31
- products: Product[]
32
- }
33
-
34
- export interface ProductContext {
35
- currency: string
36
- product: Product
37
- specs: Record<string, string[]>
38
- variants: ProductVariant[]
39
- modelNumbers: Record<string, ModelNumber>
40
- colours: Record<string, Colour>
41
- variantImages: Record<string, string[]>
42
- }
@@ -1,8 +0,0 @@
1
- import type {ModelNumber} from "../lasterp";
2
-
3
- export function toDescription(modelNumber: ModelNumber) {
4
- if (!modelNumber) {
5
- return null;
6
- }
7
- return modelNumber.simCardType;
8
- }
@@ -1,10 +0,0 @@
1
- // Re-export humps utilities with backward-compatible names
2
- export {
3
- camelize as snakeToCamel,
4
- decamelize as camelToSnake,
5
- camelizeKeys as objectSnakeToCamel,
6
- decamelizeKeys as objectCamelToSnake,
7
- } from 'humps';
8
-
9
- export * from './catalog'
10
- export * from './types'
@@ -1,3 +0,0 @@
1
- export function equalsIgnoreCase(str1: string, str2: string): boolean {
2
- return str1.localeCompare(str2, undefined, { sensitivity: 'accent' }) === 0;
3
- };