@datlv-trustshop/shopify-inapp-components 0.2.8 โ 0.2.9
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/components/AppList.d.ts +1 -0
- package/dist/components/AppList.d.ts.map +1 -0
- package/dist/components/AppList.js +1 -0
- package/dist/components/AppList.js.map +1 -0
- package/dist/components/ArticleList.d.ts +1 -0
- package/dist/components/ArticleList.d.ts.map +1 -0
- package/dist/components/ArticleList.js +1 -0
- package/dist/components/ArticleList.js.map +1 -0
- package/dist/components/ArticleSlide.d.ts +1 -0
- package/dist/components/ArticleSlide.d.ts.map +1 -0
- package/dist/components/ArticleSlide.js +1 -0
- package/dist/components/ArticleSlide.js.map +1 -0
- package/dist/components/FloatingCard.d.ts +1 -0
- package/dist/components/FloatingCard.d.ts.map +1 -0
- package/dist/components/FloatingCard.js +5 -4
- package/dist/components/FloatingCard.js.map +1 -0
- package/dist/components/FooterBanner.d.ts +1 -0
- package/dist/components/FooterBanner.d.ts.map +1 -0
- package/dist/components/FooterBanner.js +1 -0
- package/dist/components/FooterBanner.js.map +1 -0
- package/dist/components/GrowApps.d.ts +6 -6
- package/dist/components/GrowApps.d.ts.map +1 -0
- package/dist/components/GrowApps.js +11 -3
- package/dist/components/GrowApps.js.map +1 -0
- package/dist/components/ImageLoading.d.ts +1 -0
- package/dist/components/ImageLoading.d.ts.map +1 -0
- package/dist/components/ImageLoading.js +1 -0
- package/dist/components/ImageLoading.js.map +1 -0
- package/dist/components/PartnerIntegration.d.ts +8 -8
- package/dist/components/PartnerIntegration.d.ts.map +1 -0
- package/dist/components/PartnerIntegration.js +15 -76
- package/dist/components/PartnerIntegration.js.map +1 -0
- package/dist/components/PartnerList.d.ts +1 -0
- package/dist/components/PartnerList.d.ts.map +1 -0
- package/dist/components/PartnerList.js +1 -0
- package/dist/components/PartnerList.js.map +1 -0
- package/dist/components/PopupBanner.d.ts +4 -4
- package/dist/components/PopupBanner.d.ts.map +1 -0
- package/dist/components/PopupBanner.js +5 -1
- package/dist/components/PopupBanner.js.map +1 -0
- package/dist/components/TopBanner.d.ts +7 -7
- package/dist/components/TopBanner.d.ts.map +1 -0
- package/dist/components/TopBanner.js +15 -30
- package/dist/components/TopBanner.js.map +1 -0
- package/dist/components/WhatsNew.d.ts +6 -7
- package/dist/components/WhatsNew.d.ts.map +1 -0
- package/dist/components/WhatsNew.js +23 -25
- package/dist/components/WhatsNew.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/inlineStyles.d.ts +1 -0
- package/dist/components/inlineStyles.d.ts.map +1 -0
- package/dist/components/inlineStyles.js +1 -0
- package/dist/components/inlineStyles.js.map +1 -0
- package/dist/components/styles.d.ts +1 -0
- package/dist/components/styles.d.ts.map +1 -0
- package/dist/components/styles.js +1 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/config/component-defaults.d.ts +71 -0
- package/dist/config/component-defaults.d.ts.map +1 -0
- package/dist/config/component-defaults.js +106 -0
- package/dist/config/component-defaults.js.map +1 -0
- package/dist/config/internal-config.d.ts +28 -0
- package/dist/config/internal-config.d.ts.map +1 -0
- package/dist/config/internal-config.js +100 -0
- package/dist/config/internal-config.js.map +1 -0
- package/dist/core/SDKManager.d.ts +230 -0
- package/dist/core/SDKManager.d.ts.map +1 -0
- package/dist/core/SDKManager.js +380 -0
- package/dist/core/SDKManager.js.map +1 -0
- package/dist/core/adapter.d.ts +1 -0
- package/dist/core/adapter.d.ts.map +1 -0
- package/dist/core/adapter.js +1 -0
- package/dist/core/adapter.js.map +1 -0
- package/dist/core/engine.d.ts +1 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +1 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/fetcher.d.ts +1 -0
- package/dist/core/fetcher.d.ts.map +1 -0
- package/dist/core/fetcher.js +1 -0
- package/dist/core/fetcher.js.map +1 -0
- package/dist/core/global-manager.d.ts +1 -0
- package/dist/core/global-manager.d.ts.map +1 -0
- package/dist/core/global-manager.js +1 -0
- package/dist/core/global-manager.js.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useApps.d.ts +2 -1
- package/dist/hooks/useApps.d.ts.map +1 -0
- package/dist/hooks/useApps.js +8 -15
- package/dist/hooks/useApps.js.map +1 -0
- package/dist/hooks/useArticles.d.ts +1 -0
- package/dist/hooks/useArticles.d.ts.map +1 -0
- package/dist/hooks/useArticles.js +14 -18
- package/dist/hooks/useArticles.js.map +1 -0
- package/dist/hooks/useBanner.d.ts +2 -1
- package/dist/hooks/useBanner.d.ts.map +1 -0
- package/dist/hooks/useBanner.js +14 -15
- package/dist/hooks/useBanner.js.map +1 -0
- package/dist/hooks/useCampaignTracking.d.ts +1 -0
- package/dist/hooks/useCampaignTracking.d.ts.map +1 -0
- package/dist/hooks/useCampaignTracking.js +1 -0
- package/dist/hooks/useCampaignTracking.js.map +1 -0
- package/dist/hooks/useDashboard.d.ts +1 -0
- package/dist/hooks/useDashboard.d.ts.map +1 -0
- package/dist/hooks/useDashboard.js +12 -9
- package/dist/hooks/useDashboard.js.map +1 -0
- package/dist/hooks/useFloatingCardActions.d.ts +1 -0
- package/dist/hooks/useFloatingCardActions.d.ts.map +1 -0
- package/dist/hooks/useFloatingCardActions.js +1 -0
- package/dist/hooks/useFloatingCardActions.js.map +1 -0
- package/dist/hooks/useFloatingCardEngine.d.ts +1 -0
- package/dist/hooks/useFloatingCardEngine.d.ts.map +1 -0
- package/dist/hooks/useFloatingCardEngine.js +1 -0
- package/dist/hooks/useFloatingCardEngine.js.map +1 -0
- package/dist/hooks/useFloatingCards.d.ts +3 -2
- package/dist/hooks/useFloatingCards.d.ts.map +1 -0
- package/dist/hooks/useFloatingCards.js +37 -12
- package/dist/hooks/useFloatingCards.js.map +1 -0
- package/dist/hooks/useGrowApps.d.ts +1 -0
- package/dist/hooks/useGrowApps.d.ts.map +1 -0
- package/dist/hooks/useGrowApps.js +1 -0
- package/dist/hooks/useGrowApps.js.map +1 -0
- package/dist/hooks/usePartnerIntegration.d.ts +5 -4
- package/dist/hooks/usePartnerIntegration.d.ts.map +1 -0
- package/dist/hooks/usePartnerIntegration.js +10 -38
- package/dist/hooks/usePartnerIntegration.js.map +1 -0
- package/dist/hooks/useTranslations.d.ts +1 -0
- package/dist/hooks/useTranslations.d.ts.map +1 -0
- package/dist/hooks/useTranslations.js +5 -3
- package/dist/hooks/useTranslations.js.map +1 -0
- package/dist/hooks/useWhatsNew.d.ts +1 -0
- package/dist/hooks/useWhatsNew.d.ts.map +1 -0
- package/dist/hooks/useWhatsNew.js +12 -11
- package/dist/hooks/useWhatsNew.js.map +1 -0
- package/dist/index.d.ts +38 -22
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -22
- package/dist/index.js.map +1 -0
- package/dist/translations/default.d.ts +1 -0
- package/dist/translations/default.d.ts.map +1 -0
- package/dist/translations/default.js +1 -0
- package/dist/translations/default.js.map +1 -0
- package/dist/translations/locales/cn.json +39 -0
- package/dist/translations/locales/de.json +39 -0
- package/dist/translations/locales/dk.json +39 -0
- package/dist/translations/locales/en.json +39 -0
- package/dist/translations/locales/es.json +39 -0
- package/dist/translations/locales/fr.json +39 -0
- package/dist/translations/locales/ie.json +39 -0
- package/dist/translations/locales/in.json +39 -0
- package/dist/translations/locales/it.json +39 -0
- package/dist/translations/locales/jp.json +39 -0
- package/dist/translations/locales/nl.json +39 -0
- package/dist/translations/locales/nz.json +39 -0
- package/dist/translations/locales/pt.json +39 -0
- package/dist/translations/locales/se.json +39 -0
- package/dist/translations/locales/vi.json +39 -0
- package/dist/translations/translation-manager.d.ts +89 -0
- package/dist/translations/translation-manager.d.ts.map +1 -0
- package/dist/translations/translation-manager.js +239 -0
- package/dist/translations/translation-manager.js.map +1 -0
- package/dist/types/app.d.ts +1 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +1 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/article.d.ts +1 -0
- package/dist/types/article.d.ts.map +1 -0
- package/dist/types/article.js +1 -0
- package/dist/types/article.js.map +1 -0
- package/dist/types/banner.d.ts +1 -0
- package/dist/types/banner.d.ts.map +1 -0
- package/dist/types/banner.js +1 -0
- package/dist/types/banner.js.map +1 -0
- package/dist/types/component-props.d.ts +140 -0
- package/dist/types/component-props.d.ts.map +1 -0
- package/dist/types/component-props.js +6 -0
- package/dist/types/component-props.js.map +1 -0
- package/dist/types/dashboard.d.ts +1 -0
- package/dist/types/dashboard.d.ts.map +1 -0
- package/dist/types/dashboard.js +1 -0
- package/dist/types/dashboard.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/integration.d.ts +1 -0
- package/dist/types/integration.d.ts.map +1 -0
- package/dist/types/integration.js +1 -0
- package/dist/types/integration.js.map +1 -0
- package/dist/types/partner.d.ts +1 -0
- package/dist/types/partner.d.ts.map +1 -0
- package/dist/types/partner.js +1 -0
- package/dist/types/partner.js.map +1 -0
- package/dist/types/product-update.d.ts +1 -0
- package/dist/types/product-update.d.ts.map +1 -0
- package/dist/types/product-update.js +1 -0
- package/dist/types/product-update.js.map +1 -0
- package/dist/types/translations.d.ts +1 -0
- package/dist/types/translations.d.ts.map +1 -0
- package/dist/types/translations.js +1 -0
- package/dist/types/translations.js.map +1 -0
- package/dist/utils/campaignTracking.d.ts +1 -0
- package/dist/utils/campaignTracking.d.ts.map +1 -0
- package/dist/utils/campaignTracking.js +1 -0
- package/dist/utils/campaignTracking.js.map +1 -0
- package/dist/utils/cls-monitor.d.ts +1 -0
- package/dist/utils/cls-monitor.d.ts.map +1 -0
- package/dist/utils/cls-monitor.js +1 -0
- package/dist/utils/cls-monitor.js.map +1 -0
- package/dist/utils/injectStyles.d.ts +1 -0
- package/dist/utils/injectStyles.d.ts.map +1 -0
- package/dist/utils/injectStyles.js +1 -0
- package/dist/utils/injectStyles.js.map +1 -0
- package/dist/utils/sessionManager.d.ts +1 -0
- package/dist/utils/sessionManager.d.ts.map +1 -0
- package/dist/utils/sessionManager.js +1 -0
- package/dist/utils/sessionManager.js.map +1 -0
- package/package.json +4 -3
- package/dist/provider/DashboardProvider.d.ts +0 -36
- package/dist/provider/DashboardProvider.js +0 -200
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Manager - Internal singleton for managing global state
|
|
3
|
+
* Components automatically connect to this without manual provider setup
|
|
4
|
+
*/
|
|
5
|
+
import { type SupportedLocale, type SDKTranslations } from '../translations/translation-manager';
|
|
6
|
+
import { type ShopInfo, type SDKInternalConfig } from '../config/internal-config';
|
|
7
|
+
interface SDKState {
|
|
8
|
+
initialized: boolean;
|
|
9
|
+
shopInfo?: ShopInfo;
|
|
10
|
+
locale: SupportedLocale;
|
|
11
|
+
translations: SDKTranslations;
|
|
12
|
+
config: SDKInternalConfig;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error?: Error;
|
|
15
|
+
}
|
|
16
|
+
interface SDKOptions {
|
|
17
|
+
shopInfo?: ShopInfo;
|
|
18
|
+
locale?: SupportedLocale;
|
|
19
|
+
translations?: Partial<SDKTranslations>;
|
|
20
|
+
config?: Partial<SDKInternalConfig>;
|
|
21
|
+
}
|
|
22
|
+
declare class SDKManagerClass {
|
|
23
|
+
private state;
|
|
24
|
+
private listeners;
|
|
25
|
+
private initPromise?;
|
|
26
|
+
private localeObserver?;
|
|
27
|
+
private currentDetectedLocale?;
|
|
28
|
+
constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Auto-detect current locale from browser/Shopify context
|
|
31
|
+
*/
|
|
32
|
+
private autoDetectLocale;
|
|
33
|
+
/**
|
|
34
|
+
* Get locale from Shopify Admin context
|
|
35
|
+
*/
|
|
36
|
+
private getShopifyAdminLocale;
|
|
37
|
+
/**
|
|
38
|
+
* Setup watcher for locale changes in the DOM
|
|
39
|
+
*/
|
|
40
|
+
private setupLocaleWatcher;
|
|
41
|
+
/**
|
|
42
|
+
* Handle custom locale change events
|
|
43
|
+
*/
|
|
44
|
+
private handleCustomLocaleChange;
|
|
45
|
+
/**
|
|
46
|
+
* Handle locale changes (re-fetch data and translations)
|
|
47
|
+
*/
|
|
48
|
+
private handleLocaleChange;
|
|
49
|
+
/**
|
|
50
|
+
* Refresh API data with new locale
|
|
51
|
+
*/
|
|
52
|
+
private refreshDataWithNewLocale;
|
|
53
|
+
/**
|
|
54
|
+
* Normalize locale string to supported format
|
|
55
|
+
*/
|
|
56
|
+
private normalizeLocale;
|
|
57
|
+
/**
|
|
58
|
+
* Manually update locale (for programmatic changes)
|
|
59
|
+
*/
|
|
60
|
+
updateLocale(newLocale: string | SupportedLocale): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Auto-detect shop info from Shopify App Bridge or URL
|
|
63
|
+
*/
|
|
64
|
+
private autoDetectShopInfo;
|
|
65
|
+
/**
|
|
66
|
+
* Initialize SDK with options (called automatically by components)
|
|
67
|
+
*/
|
|
68
|
+
initialize(options?: SDKOptions): Promise<void>;
|
|
69
|
+
private performInitialization;
|
|
70
|
+
/**
|
|
71
|
+
* Update SDK state and notify listeners
|
|
72
|
+
*/
|
|
73
|
+
private updateState;
|
|
74
|
+
/**
|
|
75
|
+
* Update configuration (called when components pass new props)
|
|
76
|
+
*/
|
|
77
|
+
updateConfig(options: SDKOptions): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Get current state
|
|
80
|
+
*/
|
|
81
|
+
getState(): SDKState;
|
|
82
|
+
/**
|
|
83
|
+
* Subscribe to state changes
|
|
84
|
+
*/
|
|
85
|
+
subscribe(listener: () => void): () => void;
|
|
86
|
+
private notifyListeners;
|
|
87
|
+
/**
|
|
88
|
+
* Get component defaults
|
|
89
|
+
*/
|
|
90
|
+
getDefaults(): {
|
|
91
|
+
readonly topBanner: {
|
|
92
|
+
readonly open: true;
|
|
93
|
+
readonly closable: true;
|
|
94
|
+
readonly sticky: false;
|
|
95
|
+
};
|
|
96
|
+
readonly whatsNew: {
|
|
97
|
+
readonly maxUpdates: 5;
|
|
98
|
+
readonly maxArticles: 10;
|
|
99
|
+
readonly showNavigation: true;
|
|
100
|
+
readonly showViewAllButton: true;
|
|
101
|
+
readonly enableSwipe: true;
|
|
102
|
+
};
|
|
103
|
+
readonly growApps: {
|
|
104
|
+
readonly maxItems: 6;
|
|
105
|
+
readonly showDismiss: true;
|
|
106
|
+
readonly showNavigation: true;
|
|
107
|
+
readonly dismissKey: "ts-dashboard-growapps-dismissed";
|
|
108
|
+
readonly dismissDuration: number;
|
|
109
|
+
};
|
|
110
|
+
readonly popupBanner: {
|
|
111
|
+
readonly autoShow: true;
|
|
112
|
+
readonly showDelay: 0;
|
|
113
|
+
readonly persistClose: true;
|
|
114
|
+
readonly storageKey: "ts-dashboard-popup-closed";
|
|
115
|
+
};
|
|
116
|
+
readonly partnerIntegration: {
|
|
117
|
+
readonly showEmptyState: true;
|
|
118
|
+
readonly maxItems: 12;
|
|
119
|
+
};
|
|
120
|
+
readonly ui: {
|
|
121
|
+
readonly animationDuration: 300;
|
|
122
|
+
readonly debounceDelay: 100;
|
|
123
|
+
readonly skeletonCount: 3;
|
|
124
|
+
readonly enableHapticFeedback: false;
|
|
125
|
+
};
|
|
126
|
+
readonly cls: {
|
|
127
|
+
readonly reserveSpace: true;
|
|
128
|
+
readonly useSkeletons: true;
|
|
129
|
+
readonly lazyLoadImages: true;
|
|
130
|
+
readonly preventLayoutShift: true;
|
|
131
|
+
};
|
|
132
|
+
readonly loading: {
|
|
133
|
+
readonly retryAttempts: 3;
|
|
134
|
+
readonly retryDelay: 1000;
|
|
135
|
+
readonly loadingDelay: 200;
|
|
136
|
+
readonly showSpinner: false;
|
|
137
|
+
};
|
|
138
|
+
readonly storage: {
|
|
139
|
+
readonly keyPrefix: "ts-sdk-";
|
|
140
|
+
readonly persistenceEnabled: true;
|
|
141
|
+
readonly encryptStorage: false;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Check if SDK is ready for use
|
|
146
|
+
*/
|
|
147
|
+
isReady(): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Cleanup observers and listeners
|
|
150
|
+
*/
|
|
151
|
+
destroy(): void;
|
|
152
|
+
}
|
|
153
|
+
export declare const SDKManager: SDKManagerClass;
|
|
154
|
+
export interface UseSDKOptions {
|
|
155
|
+
shopInfo?: ShopInfo;
|
|
156
|
+
locale?: SupportedLocale;
|
|
157
|
+
translations?: Partial<SDKTranslations>;
|
|
158
|
+
config?: Partial<SDKInternalConfig>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Hook for components to connect to SDK Manager
|
|
162
|
+
* Automatically initializes SDK on first use
|
|
163
|
+
*/
|
|
164
|
+
export declare function useSDK(options?: UseSDKOptions): {
|
|
165
|
+
isInitializing: boolean;
|
|
166
|
+
defaults: {
|
|
167
|
+
readonly topBanner: {
|
|
168
|
+
readonly open: true;
|
|
169
|
+
readonly closable: true;
|
|
170
|
+
readonly sticky: false;
|
|
171
|
+
};
|
|
172
|
+
readonly whatsNew: {
|
|
173
|
+
readonly maxUpdates: 5;
|
|
174
|
+
readonly maxArticles: 10;
|
|
175
|
+
readonly showNavigation: true;
|
|
176
|
+
readonly showViewAllButton: true;
|
|
177
|
+
readonly enableSwipe: true;
|
|
178
|
+
};
|
|
179
|
+
readonly growApps: {
|
|
180
|
+
readonly maxItems: 6;
|
|
181
|
+
readonly showDismiss: true;
|
|
182
|
+
readonly showNavigation: true;
|
|
183
|
+
readonly dismissKey: "ts-dashboard-growapps-dismissed";
|
|
184
|
+
readonly dismissDuration: number;
|
|
185
|
+
};
|
|
186
|
+
readonly popupBanner: {
|
|
187
|
+
readonly autoShow: true;
|
|
188
|
+
readonly showDelay: 0;
|
|
189
|
+
readonly persistClose: true;
|
|
190
|
+
readonly storageKey: "ts-dashboard-popup-closed";
|
|
191
|
+
};
|
|
192
|
+
readonly partnerIntegration: {
|
|
193
|
+
readonly showEmptyState: true;
|
|
194
|
+
readonly maxItems: 12;
|
|
195
|
+
};
|
|
196
|
+
readonly ui: {
|
|
197
|
+
readonly animationDuration: 300;
|
|
198
|
+
readonly debounceDelay: 100;
|
|
199
|
+
readonly skeletonCount: 3;
|
|
200
|
+
readonly enableHapticFeedback: false;
|
|
201
|
+
};
|
|
202
|
+
readonly cls: {
|
|
203
|
+
readonly reserveSpace: true;
|
|
204
|
+
readonly useSkeletons: true;
|
|
205
|
+
readonly lazyLoadImages: true;
|
|
206
|
+
readonly preventLayoutShift: true;
|
|
207
|
+
};
|
|
208
|
+
readonly loading: {
|
|
209
|
+
readonly retryAttempts: 3;
|
|
210
|
+
readonly retryDelay: 1000;
|
|
211
|
+
readonly loadingDelay: 200;
|
|
212
|
+
readonly showSpinner: false;
|
|
213
|
+
};
|
|
214
|
+
readonly storage: {
|
|
215
|
+
readonly keyPrefix: "ts-sdk-";
|
|
216
|
+
readonly persistenceEnabled: true;
|
|
217
|
+
readonly encryptStorage: false;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
isReady: boolean;
|
|
221
|
+
initialized: boolean;
|
|
222
|
+
shopInfo?: ShopInfo;
|
|
223
|
+
locale: SupportedLocale;
|
|
224
|
+
translations: SDKTranslations;
|
|
225
|
+
config: SDKInternalConfig;
|
|
226
|
+
loading: boolean;
|
|
227
|
+
error?: Error;
|
|
228
|
+
};
|
|
229
|
+
export default SDKManager;
|
|
230
|
+
//# sourceMappingURL=SDKManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SDKManager.d.ts","sourceRoot":"","sources":["../../src/core/SDKManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAA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C,IAAI,CAAC;YAS3C,qBAAqB;IAmCnC;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAWtD;;OAEG;IACH,QAAQ,IAAI,QAAQ;IAIpB;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAK3C,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIX;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,OAAO,IAAI,IAAI;CAahB;AAMD,eAAO,MAAM,UAAU,iBAAwB,CAAC;AAQhD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBApanC,OAAO;eACT,QAAQ;YACX,eAAe;kBACT,eAAe;YACrB,iBAAiB;aAChB,OAAO;YACR,KAAK;EAicd;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Manager - Internal singleton for managing global state
|
|
3
|
+
* Components automatically connect to this without manual provider setup
|
|
4
|
+
*/
|
|
5
|
+
import { loadTranslations, getTranslations, mergeTranslations } from '../translations/translation-manager';
|
|
6
|
+
import { generateDashboardConfig } from '../config/internal-config';
|
|
7
|
+
import { COMPONENT_DEFAULTS } from '../config/component-defaults';
|
|
8
|
+
// ============================================
|
|
9
|
+
// SDK Manager Singleton
|
|
10
|
+
// ============================================
|
|
11
|
+
class SDKManagerClass {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.listeners = new Set();
|
|
14
|
+
/**
|
|
15
|
+
* Handle custom locale change events
|
|
16
|
+
*/
|
|
17
|
+
this.handleCustomLocaleChange = (event) => {
|
|
18
|
+
const newLocale = event.detail?.locale || event.detail;
|
|
19
|
+
if (newLocale && typeof newLocale === 'string') {
|
|
20
|
+
const normalizedLocale = this.normalizeLocale(newLocale);
|
|
21
|
+
console.log('๐ก Received locale change event:', normalizedLocale);
|
|
22
|
+
this.handleLocaleChange(normalizedLocale);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.state = {
|
|
26
|
+
initialized: false,
|
|
27
|
+
locale: 'en',
|
|
28
|
+
translations: getTranslations('en'),
|
|
29
|
+
config: generateDashboardConfig(),
|
|
30
|
+
loading: false,
|
|
31
|
+
};
|
|
32
|
+
// Try to auto-detect Shopify context and locale
|
|
33
|
+
this.autoDetectShopInfo();
|
|
34
|
+
this.autoDetectLocale();
|
|
35
|
+
this.setupLocaleWatcher();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Auto-detect current locale from browser/Shopify context
|
|
39
|
+
*/
|
|
40
|
+
autoDetectLocale() {
|
|
41
|
+
if (typeof window === 'undefined')
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
// Method 1: Check Shopify Admin locale (if available)
|
|
45
|
+
const shopifyLocale = this.getShopifyAdminLocale();
|
|
46
|
+
if (shopifyLocale) {
|
|
47
|
+
this.currentDetectedLocale = shopifyLocale;
|
|
48
|
+
this.updateLocale(shopifyLocale);
|
|
49
|
+
console.log('๐ Auto-detected Shopify locale:', shopifyLocale);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Method 2: Browser language
|
|
53
|
+
const browserLocale = navigator.language || navigator.languages?.[0];
|
|
54
|
+
if (browserLocale) {
|
|
55
|
+
const normalizedLocale = this.normalizeLocale(browserLocale);
|
|
56
|
+
this.currentDetectedLocale = normalizedLocale;
|
|
57
|
+
this.updateLocale(normalizedLocale);
|
|
58
|
+
console.log('๐ Auto-detected browser locale:', normalizedLocale);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.warn('Failed to auto-detect locale:', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get locale from Shopify Admin context
|
|
67
|
+
*/
|
|
68
|
+
getShopifyAdminLocale() {
|
|
69
|
+
try {
|
|
70
|
+
// Check if we can detect locale from Shopify admin
|
|
71
|
+
const html = document.documentElement;
|
|
72
|
+
const lang = html.getAttribute('lang') || html.getAttribute('xml:lang');
|
|
73
|
+
if (lang) {
|
|
74
|
+
return this.normalizeLocale(lang);
|
|
75
|
+
}
|
|
76
|
+
// Check meta tags
|
|
77
|
+
const metaLang = document.querySelector('meta[http-equiv="content-language"]');
|
|
78
|
+
if (metaLang) {
|
|
79
|
+
const content = metaLang.getAttribute('content');
|
|
80
|
+
if (content) {
|
|
81
|
+
return this.normalizeLocale(content);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Setup watcher for locale changes in the DOM
|
|
92
|
+
*/
|
|
93
|
+
setupLocaleWatcher() {
|
|
94
|
+
if (typeof window === 'undefined')
|
|
95
|
+
return;
|
|
96
|
+
try {
|
|
97
|
+
this.localeObserver = new MutationObserver((mutations) => {
|
|
98
|
+
mutations.forEach((mutation) => {
|
|
99
|
+
if (mutation.type === 'attributes' &&
|
|
100
|
+
(mutation.attributeName === 'lang' || mutation.attributeName === 'xml:lang')) {
|
|
101
|
+
const newLocale = this.getShopifyAdminLocale();
|
|
102
|
+
if (newLocale && newLocale !== this.currentDetectedLocale) {
|
|
103
|
+
console.log('๐ Detected locale change:', this.currentDetectedLocale, 'โ', newLocale);
|
|
104
|
+
this.currentDetectedLocale = newLocale;
|
|
105
|
+
this.handleLocaleChange(newLocale);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
// Watch for changes to document element attributes
|
|
111
|
+
this.localeObserver.observe(document.documentElement, {
|
|
112
|
+
attributes: true,
|
|
113
|
+
attributeFilter: ['lang', 'xml:lang']
|
|
114
|
+
});
|
|
115
|
+
// Also listen for custom locale change events
|
|
116
|
+
window.addEventListener('trustshop-locale-change', this.handleCustomLocaleChange.bind(this));
|
|
117
|
+
window.addEventListener('shopify-locale-change', this.handleCustomLocaleChange.bind(this));
|
|
118
|
+
console.log('๐ Locale watcher initialized');
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn('Failed to setup locale watcher:', error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Handle locale changes (re-fetch data and translations)
|
|
126
|
+
*/
|
|
127
|
+
async handleLocaleChange(newLocale) {
|
|
128
|
+
if (newLocale === this.state.locale)
|
|
129
|
+
return;
|
|
130
|
+
try {
|
|
131
|
+
console.log('๐ Updating SDK locale:', this.state.locale, 'โ', newLocale);
|
|
132
|
+
this.updateState({ loading: true });
|
|
133
|
+
// Load new translations
|
|
134
|
+
const baseTranslations = await loadTranslations(newLocale);
|
|
135
|
+
const translations = mergeTranslations(baseTranslations);
|
|
136
|
+
// Update state
|
|
137
|
+
this.updateState({
|
|
138
|
+
locale: newLocale,
|
|
139
|
+
translations,
|
|
140
|
+
loading: false,
|
|
141
|
+
});
|
|
142
|
+
// Trigger re-fetch of API data with new locale
|
|
143
|
+
this.refreshDataWithNewLocale(newLocale);
|
|
144
|
+
console.log('โ
SDK locale updated successfully');
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('โ Failed to update SDK locale:', error);
|
|
148
|
+
this.updateState({ loading: false, error: error });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Refresh API data with new locale
|
|
153
|
+
*/
|
|
154
|
+
refreshDataWithNewLocale(locale) {
|
|
155
|
+
// Clear any cached data and trigger re-fetch
|
|
156
|
+
// This will cause all components to re-fetch their data
|
|
157
|
+
// Emit event for hooks to re-fetch data
|
|
158
|
+
window.dispatchEvent(new CustomEvent('trustshop-data-refresh', {
|
|
159
|
+
detail: { locale, reason: 'locale-change' }
|
|
160
|
+
}));
|
|
161
|
+
console.log('๐ก Triggered data refresh for locale:', locale);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Normalize locale string to supported format
|
|
165
|
+
*/
|
|
166
|
+
normalizeLocale(locale) {
|
|
167
|
+
if (!locale)
|
|
168
|
+
return 'en';
|
|
169
|
+
// Use the same normalization as translation manager
|
|
170
|
+
const SUPPORTED_LOCALES = [
|
|
171
|
+
'cn', 'de', 'dk', 'en', 'es', 'fr', 'ie', 'in',
|
|
172
|
+
'it', 'jp', 'nl', 'nz', 'pt', 'se', 'vi'
|
|
173
|
+
];
|
|
174
|
+
// Direct match
|
|
175
|
+
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
176
|
+
return locale;
|
|
177
|
+
}
|
|
178
|
+
// Extract base locale (en-US โ en)
|
|
179
|
+
const base = locale.split(/[-_]/)[0].toLowerCase();
|
|
180
|
+
// Special mappings
|
|
181
|
+
const mappings = {
|
|
182
|
+
'zh': 'cn',
|
|
183
|
+
'da': 'dk',
|
|
184
|
+
'ga': 'ie',
|
|
185
|
+
'hi': 'in',
|
|
186
|
+
'ja': 'jp',
|
|
187
|
+
'mi': 'nz',
|
|
188
|
+
'sv': 'se',
|
|
189
|
+
};
|
|
190
|
+
const mapped = mappings[base] || base;
|
|
191
|
+
if (SUPPORTED_LOCALES.includes(mapped)) {
|
|
192
|
+
return mapped;
|
|
193
|
+
}
|
|
194
|
+
return 'en';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Manually update locale (for programmatic changes)
|
|
198
|
+
*/
|
|
199
|
+
async updateLocale(newLocale) {
|
|
200
|
+
const normalizedLocale = this.normalizeLocale(newLocale);
|
|
201
|
+
await this.handleLocaleChange(normalizedLocale);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Auto-detect shop info from Shopify App Bridge or URL
|
|
205
|
+
*/
|
|
206
|
+
autoDetectShopInfo() {
|
|
207
|
+
if (typeof window === 'undefined')
|
|
208
|
+
return;
|
|
209
|
+
try {
|
|
210
|
+
// Method 1: Check if Shopify App Bridge is available
|
|
211
|
+
const shopifyApp = window.ShopifyApp;
|
|
212
|
+
if (shopifyApp) {
|
|
213
|
+
// Extract from App Bridge context if available
|
|
214
|
+
console.log('๐ Detected Shopify App Bridge context');
|
|
215
|
+
}
|
|
216
|
+
// Method 2: Parse from URL (admin.shopify.com)
|
|
217
|
+
const currentUrl = window.location.href;
|
|
218
|
+
const shopifyAdminMatch = currentUrl.match(/https:\/\/admin\.shopify\.com\/store\/([^\/]+)/);
|
|
219
|
+
if (shopifyAdminMatch) {
|
|
220
|
+
const [, storeName] = shopifyAdminMatch;
|
|
221
|
+
this.updateState({
|
|
222
|
+
shopInfo: {
|
|
223
|
+
domain: `${storeName}.myshopify.com`,
|
|
224
|
+
id: storeName,
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
console.log('๐ Auto-detected shop from URL:', storeName);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.warn('Failed to auto-detect shop info:', error);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Initialize SDK with options (called automatically by components)
|
|
236
|
+
*/
|
|
237
|
+
async initialize(options = {}) {
|
|
238
|
+
if (this.initPromise) {
|
|
239
|
+
return this.initPromise;
|
|
240
|
+
}
|
|
241
|
+
this.initPromise = this.performInitialization(options);
|
|
242
|
+
return this.initPromise;
|
|
243
|
+
}
|
|
244
|
+
async performInitialization(options) {
|
|
245
|
+
try {
|
|
246
|
+
this.updateState({ loading: true });
|
|
247
|
+
const locale = options.locale || this.state.locale;
|
|
248
|
+
const shopInfo = options.shopInfo || this.state.shopInfo;
|
|
249
|
+
// Load translations
|
|
250
|
+
const baseTranslations = await loadTranslations(locale);
|
|
251
|
+
const translations = mergeTranslations(baseTranslations, options.translations);
|
|
252
|
+
// Generate config
|
|
253
|
+
const config = generateDashboardConfig(shopInfo, options.config);
|
|
254
|
+
this.updateState({
|
|
255
|
+
initialized: true,
|
|
256
|
+
locale,
|
|
257
|
+
shopInfo,
|
|
258
|
+
translations,
|
|
259
|
+
config,
|
|
260
|
+
loading: false,
|
|
261
|
+
error: undefined,
|
|
262
|
+
});
|
|
263
|
+
console.log('โ
SDK initialized successfully', { locale, shopInfo });
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
this.updateState({
|
|
267
|
+
loading: false,
|
|
268
|
+
error: error,
|
|
269
|
+
});
|
|
270
|
+
console.error('โ SDK initialization failed:', error);
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Update SDK state and notify listeners
|
|
276
|
+
*/
|
|
277
|
+
updateState(updates) {
|
|
278
|
+
this.state = { ...this.state, ...updates };
|
|
279
|
+
this.notifyListeners();
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Update configuration (called when components pass new props)
|
|
283
|
+
*/
|
|
284
|
+
async updateConfig(options) {
|
|
285
|
+
const hasChanges = options.locale !== this.state.locale ||
|
|
286
|
+
JSON.stringify(options.shopInfo) !== JSON.stringify(this.state.shopInfo);
|
|
287
|
+
if (hasChanges) {
|
|
288
|
+
this.initPromise = undefined; // Reset init promise to allow re-initialization
|
|
289
|
+
await this.initialize(options);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get current state
|
|
294
|
+
*/
|
|
295
|
+
getState() {
|
|
296
|
+
return this.state;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Subscribe to state changes
|
|
300
|
+
*/
|
|
301
|
+
subscribe(listener) {
|
|
302
|
+
this.listeners.add(listener);
|
|
303
|
+
return () => this.listeners.delete(listener);
|
|
304
|
+
}
|
|
305
|
+
notifyListeners() {
|
|
306
|
+
this.listeners.forEach(listener => listener());
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get component defaults
|
|
310
|
+
*/
|
|
311
|
+
getDefaults() {
|
|
312
|
+
return COMPONENT_DEFAULTS;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Check if SDK is ready for use
|
|
316
|
+
*/
|
|
317
|
+
isReady() {
|
|
318
|
+
return this.state.initialized && !this.state.loading && !this.state.error;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Cleanup observers and listeners
|
|
322
|
+
*/
|
|
323
|
+
destroy() {
|
|
324
|
+
if (this.localeObserver) {
|
|
325
|
+
this.localeObserver.disconnect();
|
|
326
|
+
}
|
|
327
|
+
if (typeof window !== 'undefined') {
|
|
328
|
+
window.removeEventListener('trustshop-locale-change', this.handleCustomLocaleChange);
|
|
329
|
+
window.removeEventListener('shopify-locale-change', this.handleCustomLocaleChange);
|
|
330
|
+
}
|
|
331
|
+
this.listeners.clear();
|
|
332
|
+
console.log('๐งน SDK Manager cleaned up');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// ============================================
|
|
336
|
+
// Export Singleton Instance
|
|
337
|
+
// ============================================
|
|
338
|
+
export const SDKManager = new SDKManagerClass();
|
|
339
|
+
// ============================================
|
|
340
|
+
// React Hook for Components
|
|
341
|
+
// ============================================
|
|
342
|
+
import { useState, useEffect } from 'react';
|
|
343
|
+
/**
|
|
344
|
+
* Hook for components to connect to SDK Manager
|
|
345
|
+
* Automatically initializes SDK on first use
|
|
346
|
+
*/
|
|
347
|
+
export function useSDK(options = {}) {
|
|
348
|
+
const [state, setState] = useState(() => SDKManager.getState());
|
|
349
|
+
const [isInitializing, setIsInitializing] = useState(false);
|
|
350
|
+
// Subscribe to state changes
|
|
351
|
+
useEffect(() => {
|
|
352
|
+
const unsubscribe = SDKManager.subscribe(() => {
|
|
353
|
+
setState(SDKManager.getState());
|
|
354
|
+
});
|
|
355
|
+
return unsubscribe;
|
|
356
|
+
}, []);
|
|
357
|
+
// Auto-initialize SDK when component mounts
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
if (!state.initialized && !isInitializing) {
|
|
360
|
+
setIsInitializing(true);
|
|
361
|
+
SDKManager.initialize(options).finally(() => {
|
|
362
|
+
setIsInitializing(false);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}, [state.initialized, isInitializing]);
|
|
366
|
+
// Update config if options change
|
|
367
|
+
useEffect(() => {
|
|
368
|
+
if (state.initialized) {
|
|
369
|
+
SDKManager.updateConfig(options);
|
|
370
|
+
}
|
|
371
|
+
}, [state.initialized, JSON.stringify(options)]);
|
|
372
|
+
return {
|
|
373
|
+
...state,
|
|
374
|
+
isInitializing,
|
|
375
|
+
defaults: SDKManager.getDefaults(),
|
|
376
|
+
isReady: SDKManager.isReady(),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
export default SDKManager;
|
|
380
|
+
//# sourceMappingURL=SDKManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SDKManager.js","sourceRoot":"","sources":["../../src/core/SDKManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAGlB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAyC,MAAM,2BAA2B,CAAC;AAC3G,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAuBlE,+CAA+C;AAC/C,wBAAwB;AACxB,+CAA+C;AAE/C,MAAM,eAAe;IAOnB;QALQ,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kCAAkC;IAClC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjD,OAAO;QACL,GAAG,KAAK;QACR,cAAc;QACd,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE;QAClC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE;KAC9B,CAAC;AACJ,CAAC;AAED,eAAe,UAAU,CAAC","sourcesContent":["/**\n * SDK Manager - Internal singleton for managing global state\n * Components automatically connect to this without manual provider setup\n */\n\nimport { \n loadTranslations, \n getTranslations, \n mergeTranslations,\n type SupportedLocale,\n type SDKTranslations \n} from '../translations/translation-manager';\nimport { generateDashboardConfig, type ShopInfo, type SDKInternalConfig } from '../config/internal-config';\nimport { COMPONENT_DEFAULTS } from '../config/component-defaults';\n\n// ============================================\n// SDK Global State\n// ============================================\n\ninterface SDKState {\n initialized: boolean;\n shopInfo?: ShopInfo;\n locale: SupportedLocale;\n translations: SDKTranslations;\n config: SDKInternalConfig;\n loading: boolean;\n error?: Error;\n}\n\ninterface SDKOptions {\n shopInfo?: ShopInfo;\n locale?: SupportedLocale;\n translations?: Partial<SDKTranslations>;\n config?: Partial<SDKInternalConfig>;\n}\n\n// ============================================\n// SDK Manager Singleton\n// ============================================\n\nclass SDKManagerClass {\n private state: SDKState;\n private listeners: Set<() => void> = new Set();\n private initPromise?: Promise<void>;\n private localeObserver?: MutationObserver;\n private currentDetectedLocale?: SupportedLocale;\n\n constructor() {\n this.state = {\n initialized: false,\n locale: 'en',\n translations: getTranslations('en'),\n config: generateDashboardConfig(),\n loading: false,\n };\n\n // Try to auto-detect Shopify context and locale\n this.autoDetectShopInfo();\n this.autoDetectLocale();\n this.setupLocaleWatcher();\n }\n\n /**\n * Auto-detect current locale from browser/Shopify context\n */\n private autoDetectLocale(): void {\n if (typeof window === 'undefined') return;\n\n try {\n // Method 1: Check Shopify Admin locale (if available)\n const shopifyLocale = this.getShopifyAdminLocale();\n if (shopifyLocale) {\n this.currentDetectedLocale = shopifyLocale;\n this.updateLocale(shopifyLocale);\n console.log('๐ Auto-detected Shopify locale:', shopifyLocale);\n return;\n }\n\n // Method 2: Browser language\n const browserLocale = navigator.language || navigator.languages?.[0];\n if (browserLocale) {\n const normalizedLocale = this.normalizeLocale(browserLocale);\n this.currentDetectedLocale = normalizedLocale;\n this.updateLocale(normalizedLocale);\n console.log('๐ Auto-detected browser locale:', normalizedLocale);\n }\n } catch (error) {\n console.warn('Failed to auto-detect locale:', error);\n }\n }\n\n /**\n * Get locale from Shopify Admin context\n */\n private getShopifyAdminLocale(): SupportedLocale | null {\n try {\n // Check if we can detect locale from Shopify admin\n const html = document.documentElement;\n const lang = html.getAttribute('lang') || html.getAttribute('xml:lang');\n \n if (lang) {\n return this.normalizeLocale(lang);\n }\n\n // Check meta tags\n const metaLang = document.querySelector('meta[http-equiv=\"content-language\"]');\n if (metaLang) {\n const content = metaLang.getAttribute('content');\n if (content) {\n return this.normalizeLocale(content);\n }\n }\n\n return null;\n } catch {\n return null;\n }\n }\n\n /**\n * Setup watcher for locale changes in the DOM\n */\n private setupLocaleWatcher(): void {\n if (typeof window === 'undefined') return;\n\n try {\n this.localeObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (mutation.type === 'attributes' && \n (mutation.attributeName === 'lang' || mutation.attributeName === 'xml:lang')) {\n const newLocale = this.getShopifyAdminLocale();\n if (newLocale && newLocale !== this.currentDetectedLocale) {\n console.log('๐ Detected locale change:', this.currentDetectedLocale, 'โ', newLocale);\n this.currentDetectedLocale = newLocale;\n this.handleLocaleChange(newLocale);\n }\n }\n });\n });\n\n // Watch for changes to document element attributes\n this.localeObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['lang', 'xml:lang']\n });\n\n // Also listen for custom locale change events\n window.addEventListener('trustshop-locale-change', this.handleCustomLocaleChange.bind(this));\n window.addEventListener('shopify-locale-change', this.handleCustomLocaleChange.bind(this));\n \n console.log('๐ Locale watcher initialized');\n } catch (error) {\n console.warn('Failed to setup locale watcher:', error);\n }\n }\n\n /**\n * Handle custom locale change events\n */\n private handleCustomLocaleChange = (event: any) => {\n const newLocale = event.detail?.locale || event.detail;\n if (newLocale && typeof newLocale === 'string') {\n const normalizedLocale = this.normalizeLocale(newLocale);\n console.log('๐ก Received locale change event:', normalizedLocale);\n this.handleLocaleChange(normalizedLocale);\n }\n };\n\n /**\n * Handle locale changes (re-fetch data and translations)\n */\n private async handleLocaleChange(newLocale: SupportedLocale): Promise<void> {\n if (newLocale === this.state.locale) return;\n\n try {\n console.log('๐ Updating SDK locale:', this.state.locale, 'โ', newLocale);\n this.updateState({ loading: true });\n\n // Load new translations\n const baseTranslations = await loadTranslations(newLocale);\n const translations = mergeTranslations(baseTranslations);\n\n // Update state\n this.updateState({\n locale: newLocale,\n translations,\n loading: false,\n });\n\n // Trigger re-fetch of API data with new locale\n this.refreshDataWithNewLocale(newLocale);\n\n console.log('โ
SDK locale updated successfully');\n } catch (error) {\n console.error('โ Failed to update SDK locale:', error);\n this.updateState({ loading: false, error: error as Error });\n }\n }\n\n /**\n * Refresh API data with new locale\n */\n private refreshDataWithNewLocale(locale: SupportedLocale): void {\n // Clear any cached data and trigger re-fetch\n // This will cause all components to re-fetch their data\n \n // Emit event for hooks to re-fetch data\n window.dispatchEvent(new CustomEvent('trustshop-data-refresh', {\n detail: { locale, reason: 'locale-change' }\n }));\n\n console.log('๐ก Triggered data refresh for locale:', locale);\n }\n\n /**\n * Normalize locale string to supported format\n */\n private normalizeLocale(locale: string): SupportedLocale {\n if (!locale) return 'en';\n \n // Use the same normalization as translation manager\n const SUPPORTED_LOCALES: SupportedLocale[] = [\n 'cn', 'de', 'dk', 'en', 'es', 'fr', 'ie', 'in',\n 'it', 'jp', 'nl', 'nz', 'pt', 'se', 'vi'\n ];\n \n // Direct match\n if (SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return locale as SupportedLocale;\n }\n \n // Extract base locale (en-US โ en)\n const base = locale.split(/[-_]/)[0].toLowerCase();\n \n // Special mappings\n const mappings: Record<string, SupportedLocale> = {\n 'zh': 'cn',\n 'da': 'dk',\n 'ga': 'ie',\n 'hi': 'in',\n 'ja': 'jp',\n 'mi': 'nz',\n 'sv': 'se',\n };\n \n const mapped = mappings[base] || base;\n \n if (SUPPORTED_LOCALES.includes(mapped as SupportedLocale)) {\n return mapped as SupportedLocale;\n }\n \n return 'en';\n }\n\n /**\n * Manually update locale (for programmatic changes)\n */\n async updateLocale(newLocale: string | SupportedLocale): Promise<void> {\n const normalizedLocale = this.normalizeLocale(newLocale);\n await this.handleLocaleChange(normalizedLocale);\n }\n\n /**\n * Auto-detect shop info from Shopify App Bridge or URL\n */\n private autoDetectShopInfo(): void {\n if (typeof window === 'undefined') return;\n\n try {\n // Method 1: Check if Shopify App Bridge is available\n const shopifyApp = (window as any).ShopifyApp;\n if (shopifyApp) {\n // Extract from App Bridge context if available\n console.log('๐ Detected Shopify App Bridge context');\n }\n\n // Method 2: Parse from URL (admin.shopify.com)\n const currentUrl = window.location.href;\n const shopifyAdminMatch = currentUrl.match(\n /https:\\/\\/admin\\.shopify\\.com\\/store\\/([^\\/]+)/\n );\n \n if (shopifyAdminMatch) {\n const [, storeName] = shopifyAdminMatch;\n this.updateState({\n shopInfo: {\n domain: `${storeName}.myshopify.com`,\n id: storeName,\n }\n });\n console.log('๐ Auto-detected shop from URL:', storeName);\n }\n } catch (error) {\n console.warn('Failed to auto-detect shop info:', error);\n }\n }\n\n /**\n * Initialize SDK with options (called automatically by components)\n */\n async initialize(options: SDKOptions = {}): Promise<void> {\n if (this.initPromise) {\n return this.initPromise;\n }\n\n this.initPromise = this.performInitialization(options);\n return this.initPromise;\n }\n\n private async performInitialization(options: SDKOptions): Promise<void> {\n try {\n this.updateState({ loading: true });\n\n const locale = options.locale || this.state.locale;\n const shopInfo = options.shopInfo || this.state.shopInfo;\n\n // Load translations\n const baseTranslations = await loadTranslations(locale);\n const translations = mergeTranslations(baseTranslations, options.translations);\n\n // Generate config\n const config = generateDashboardConfig(shopInfo, options.config);\n\n this.updateState({\n initialized: true,\n locale,\n shopInfo,\n translations,\n config,\n loading: false,\n error: undefined,\n });\n\n console.log('โ
SDK initialized successfully', { locale, shopInfo });\n } catch (error) {\n this.updateState({\n loading: false,\n error: error as Error,\n });\n console.error('โ SDK initialization failed:', error);\n throw error;\n }\n }\n\n /**\n * Update SDK state and notify listeners\n */\n private updateState(updates: Partial<SDKState>): void {\n this.state = { ...this.state, ...updates };\n this.notifyListeners();\n }\n\n /**\n * Update configuration (called when components pass new props)\n */\n async updateConfig(options: SDKOptions): Promise<void> {\n const hasChanges = \n options.locale !== this.state.locale ||\n JSON.stringify(options.shopInfo) !== JSON.stringify(this.state.shopInfo);\n\n if (hasChanges) {\n this.initPromise = undefined; // Reset init promise to allow re-initialization\n await this.initialize(options);\n }\n }\n\n /**\n * Get current state\n */\n getState(): SDKState {\n return this.state;\n }\n\n /**\n * Subscribe to state changes\n */\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n private notifyListeners(): void {\n this.listeners.forEach(listener => listener());\n }\n\n /**\n * Get component defaults\n */\n getDefaults() {\n return COMPONENT_DEFAULTS;\n }\n\n /**\n * Check if SDK is ready for use\n */\n isReady(): boolean {\n return this.state.initialized && !this.state.loading && !this.state.error;\n }\n\n /**\n * Cleanup observers and listeners\n */\n destroy(): void {\n if (this.localeObserver) {\n this.localeObserver.disconnect();\n }\n \n if (typeof window !== 'undefined') {\n window.removeEventListener('trustshop-locale-change', this.handleCustomLocaleChange);\n window.removeEventListener('shopify-locale-change', this.handleCustomLocaleChange);\n }\n \n this.listeners.clear();\n console.log('๐งน SDK Manager cleaned up');\n }\n}\n\n// ============================================\n// Export Singleton Instance\n// ============================================\n\nexport const SDKManager = new SDKManagerClass();\n\n// ============================================\n// React Hook for Components\n// ============================================\n\nimport { useState, useEffect } from 'react';\n\nexport interface UseSDKOptions {\n shopInfo?: ShopInfo;\n locale?: SupportedLocale;\n translations?: Partial<SDKTranslations>;\n config?: Partial<SDKInternalConfig>;\n}\n\n/**\n * Hook for components to connect to SDK Manager\n * Automatically initializes SDK on first use\n */\nexport function useSDK(options: UseSDKOptions = {}) {\n const [state, setState] = useState(() => SDKManager.getState());\n const [isInitializing, setIsInitializing] = useState(false);\n\n // Subscribe to state changes\n useEffect(() => {\n const unsubscribe = SDKManager.subscribe(() => {\n setState(SDKManager.getState());\n });\n return unsubscribe;\n }, []);\n\n // Auto-initialize SDK when component mounts\n useEffect(() => {\n if (!state.initialized && !isInitializing) {\n setIsInitializing(true);\n SDKManager.initialize(options).finally(() => {\n setIsInitializing(false);\n });\n }\n }, [state.initialized, isInitializing]);\n\n // Update config if options change\n useEffect(() => {\n if (state.initialized) {\n SDKManager.updateConfig(options);\n }\n }, [state.initialized, JSON.stringify(options)]);\n\n return {\n ...state,\n isInitializing,\n defaults: SDKManager.getDefaults(),\n isReady: SDKManager.isReady(),\n };\n}\n\nexport default SDKManager;"]}
|
package/dist/core/adapter.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export declare function adaptBanner(apiData: any): BannerItem;
|
|
|
4
4
|
export declare function adaptApp(apiData: any, defaultGroup?: AppGroup): AppItem;
|
|
5
5
|
export declare function adaptArticle(apiData: any): ArticleItem;
|
|
6
6
|
export declare function adaptProductUpdate(apiData: any): ProductUpdateItem;
|
|
7
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/core/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,EACP,WAAW,EACX,iBAAiB,EAEjB,QAAQ,EACT,MAAM,UAAU,CAAC;AAElB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,aAAa,CAoC9D;AAQD,wBAAgB,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,UAAU,CAwCpD;AAoFD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,QAAQ,GAAG,OAAO,CAyBvE;AAQD,wBAAgB,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,CAkCtD;AAgBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,iBAAiB,CAiElE"}
|