@kasuvia/sdk 0.0.1 → 0.0.2
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/README.md +1 -1
- package/dist/index.d.mts +40 -2
- package/dist/index.d.ts +40 -2
- package/dist/index.js +79 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config/index.ts +1 -1
- package/src/index.ts +3 -0
- package/src/types/auth/index.ts +21 -0
- package/src/types/store/index.ts +6 -2
- package/src/utils/customer.ts +14 -0
- package/src/utils/storage.ts +71 -0
package/package.json
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -37,7 +37,7 @@ const BACKEND_URLS = {
|
|
|
37
37
|
store: 'https://127.0.0.1:8001/api/v1',
|
|
38
38
|
payment: 'https://127.0.0.1:8002/api/v1',
|
|
39
39
|
notifications: 'https://127.0.0.1:8007/api/v1',
|
|
40
|
-
cms: 'https://127.0.0.1:
|
|
40
|
+
cms: 'https://127.0.0.1:8009/api/v1',
|
|
41
41
|
} as const
|
|
42
42
|
|
|
43
43
|
/**
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,9 @@ export * from './utils/sanitize-url'
|
|
|
60
60
|
export * from './utils/customer'
|
|
61
61
|
export * from './utils/checkout'
|
|
62
62
|
export * from './utils/error-handler'
|
|
63
|
+
export { sessionStore, localStore } from './utils/storage'
|
|
64
|
+
|
|
65
|
+
|
|
63
66
|
|
|
64
67
|
// App service functions
|
|
65
68
|
export { googleTranslate } from './services/app.service'
|
package/src/types/auth/index.ts
CHANGED
|
@@ -53,6 +53,27 @@ export interface UpdateProfilePayload {
|
|
|
53
53
|
phone?: string;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
export interface NotificationPreferences {
|
|
57
|
+
email_enabled: boolean;
|
|
58
|
+
sms_enabled: boolean;
|
|
59
|
+
whatsapp_enabled: boolean;
|
|
60
|
+
push_enabled: boolean;
|
|
61
|
+
email_order_confirmations: boolean;
|
|
62
|
+
email_delivery_updates: boolean;
|
|
63
|
+
email_low_stock_alerts: boolean;
|
|
64
|
+
email_payment_received: boolean;
|
|
65
|
+
push_order_confirmations: boolean;
|
|
66
|
+
push_delivery_updates: boolean;
|
|
67
|
+
push_low_stock_alerts: boolean;
|
|
68
|
+
push_payment_received: boolean;
|
|
69
|
+
whatsapp_order_confirmations: boolean;
|
|
70
|
+
whatsapp_delivery_updates: boolean;
|
|
71
|
+
whatsapp_payment_received: boolean;
|
|
72
|
+
sms_order_confirmations: boolean;
|
|
73
|
+
sms_delivery_updates: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
56
77
|
// ── Business Context (storefront is scoped to one business) ──────────────────
|
|
57
78
|
|
|
58
79
|
export interface BusinessContext {
|
package/src/types/store/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { DeliveryAddress } from "./shipping";
|
|
1
|
+
import type { DeliveryAddress } from "./shipping";
|
|
2
|
+
|
|
3
|
+
export * from "./shipping";
|
|
4
|
+
export type { DeliveryAddress };
|
|
2
5
|
|
|
3
6
|
export type ProductType = "physical" | "digital" | "service" | "bespoke";
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
|
|
9
|
+
|
|
6
10
|
|
|
7
11
|
export interface Address {
|
|
8
12
|
street: string
|
package/src/utils/customer.ts
CHANGED
|
@@ -18,3 +18,17 @@ export function getCustomerDisplayName(user: CustomerUser): string {
|
|
|
18
18
|
const fromParts = buildFullName(user.firstname, user.lastname)
|
|
19
19
|
return fromParts || user.full_name || user.email.split('@')[0]
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Constructs live storefront URL for a business.
|
|
24
|
+
* If custom domain is not yet connected/verified, defaults to `https://<business_id>.kasuvia.com`.
|
|
25
|
+
*/
|
|
26
|
+
export function getStorefrontUrl(businessId: string, customDomain?: string | null): string {
|
|
27
|
+
if (customDomain && customDomain.trim()) {
|
|
28
|
+
const cleanDomain = customDomain.trim().replace(/^https?:\/\//, '');
|
|
29
|
+
return `https://${cleanDomain}`;
|
|
30
|
+
}
|
|
31
|
+
const cleanBid = (businessId || 'store').toLowerCase().trim();
|
|
32
|
+
return `https://${cleanBid}.kasuvia.com`;
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file storage.ts
|
|
3
|
+
* @description Centralized tenant-isolated storage utility for sessionStorage and localStorage.
|
|
4
|
+
* Automatically prefixes all keys with the storefront Business ID to guarantee multi-tenant segregation.
|
|
5
|
+
*/
|
|
6
|
+
import { getRuntimeConfig } from '../config'
|
|
7
|
+
|
|
8
|
+
function getPrefixedKey(key: string): string {
|
|
9
|
+
const config = getRuntimeConfig()
|
|
10
|
+
const bid = config.businessId
|
|
11
|
+
const cleanKey = key.startsWith('luxe_') ? key.substring(5) : key
|
|
12
|
+
return bid ? `luxe-sf-${bid}-${cleanKey}` : `luxe-sf-anon-${cleanKey}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const sessionStore = {
|
|
16
|
+
get: (key: string): string | null => {
|
|
17
|
+
if (typeof window === 'undefined') return null
|
|
18
|
+
return sessionStorage.getItem(getPrefixedKey(key))
|
|
19
|
+
},
|
|
20
|
+
set: (key: string, value: string): void => {
|
|
21
|
+
if (typeof window === 'undefined') return
|
|
22
|
+
sessionStorage.setItem(getPrefixedKey(key), value)
|
|
23
|
+
},
|
|
24
|
+
remove: (key: string): void => {
|
|
25
|
+
if (typeof window === 'undefined') return
|
|
26
|
+
sessionStorage.removeItem(getPrefixedKey(key))
|
|
27
|
+
},
|
|
28
|
+
getJSON: <T = unknown>(key: string): T | null => {
|
|
29
|
+
if (typeof window === 'undefined') return null
|
|
30
|
+
const value = sessionStorage.getItem(getPrefixedKey(key))
|
|
31
|
+
if (!value) return null
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(value) as T
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
setJSON: (key: string, value: unknown): void => {
|
|
39
|
+
if (typeof window === 'undefined') return
|
|
40
|
+
sessionStorage.setItem(getPrefixedKey(key), JSON.stringify(value))
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const localStore = {
|
|
45
|
+
get: (key: string): string | null => {
|
|
46
|
+
if (typeof window === 'undefined') return null
|
|
47
|
+
return localStorage.getItem(getPrefixedKey(key))
|
|
48
|
+
},
|
|
49
|
+
set: (key: string, value: string): void => {
|
|
50
|
+
if (typeof window === 'undefined') return
|
|
51
|
+
localStorage.setItem(getPrefixedKey(key), value)
|
|
52
|
+
},
|
|
53
|
+
remove: (key: string): void => {
|
|
54
|
+
if (typeof window === 'undefined') return
|
|
55
|
+
localStorage.removeItem(getPrefixedKey(key))
|
|
56
|
+
},
|
|
57
|
+
getJSON: <T = unknown>(key: string): T | null => {
|
|
58
|
+
if (typeof window === 'undefined') return null
|
|
59
|
+
const value = localStorage.getItem(getPrefixedKey(key))
|
|
60
|
+
if (!value) return null
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(value) as T
|
|
63
|
+
} catch {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
setJSON: (key: string, value: unknown): void => {
|
|
68
|
+
if (typeof window === 'undefined') return
|
|
69
|
+
localStorage.setItem(getPrefixedKey(key), JSON.stringify(value))
|
|
70
|
+
},
|
|
71
|
+
}
|