@datlv-trustshop/shopify-inapp-components 0.2.9 โ†’ 0.2.10

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.
Files changed (46) hide show
  1. package/dist/core/SDKManager.d.ts +36 -4
  2. package/dist/core/SDKManager.d.ts.map +1 -1
  3. package/dist/core/SDKManager.js +210 -63
  4. package/dist/core/SDKManager.js.map +1 -1
  5. package/dist/hooks/index.d.ts +1 -3
  6. package/dist/hooks/index.d.ts.map +1 -1
  7. package/dist/hooks/index.js +1 -3
  8. package/dist/hooks/index.js.map +1 -1
  9. package/dist/hooks/useApps.d.ts +1 -1
  10. package/dist/hooks/useApps.d.ts.map +1 -1
  11. package/dist/hooks/useApps.js +15 -7
  12. package/dist/hooks/useApps.js.map +1 -1
  13. package/dist/hooks/useArticles.d.ts.map +1 -1
  14. package/dist/hooks/useArticles.js +12 -12
  15. package/dist/hooks/useArticles.js.map +1 -1
  16. package/dist/hooks/useBanner.d.ts +1 -1
  17. package/dist/hooks/useBanner.d.ts.map +1 -1
  18. package/dist/hooks/useBanner.js +15 -13
  19. package/dist/hooks/useBanner.js.map +1 -1
  20. package/dist/hooks/useDashboard.d.ts.map +1 -1
  21. package/dist/hooks/useDashboard.js +13 -7
  22. package/dist/hooks/useDashboard.js.map +1 -1
  23. package/dist/hooks/useFloatingCards.d.ts +1 -0
  24. package/dist/hooks/useFloatingCards.d.ts.map +1 -1
  25. package/dist/hooks/useFloatingCards.js +45 -94
  26. package/dist/hooks/useFloatingCards.js.map +1 -1
  27. package/dist/hooks/usePartnerIntegration.d.ts +7 -3
  28. package/dist/hooks/usePartnerIntegration.d.ts.map +1 -1
  29. package/dist/hooks/usePartnerIntegration.js +24 -7
  30. package/dist/hooks/usePartnerIntegration.js.map +1 -1
  31. package/dist/hooks/useWhatsNew.d.ts.map +1 -1
  32. package/dist/hooks/useWhatsNew.js +10 -10
  33. package/dist/hooks/useWhatsNew.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/hooks/useFloatingCardActions.d.ts +0 -18
  36. package/dist/hooks/useFloatingCardActions.d.ts.map +0 -1
  37. package/dist/hooks/useFloatingCardActions.js +0 -55
  38. package/dist/hooks/useFloatingCardActions.js.map +0 -1
  39. package/dist/hooks/useFloatingCardEngine.d.ts +0 -22
  40. package/dist/hooks/useFloatingCardEngine.d.ts.map +0 -1
  41. package/dist/hooks/useFloatingCardEngine.js +0 -40
  42. package/dist/hooks/useFloatingCardEngine.js.map +0 -1
  43. package/dist/hooks/useGrowApps.d.ts +0 -11
  44. package/dist/hooks/useGrowApps.d.ts.map +0 -1
  45. package/dist/hooks/useGrowApps.js +0 -15
  46. package/dist/hooks/useGrowApps.js.map +0 -1
@@ -2,8 +2,10 @@
2
2
  * SDK Manager - Internal singleton for managing global state
3
3
  * Components automatically connect to this without manual provider setup
4
4
  */
5
- import { type SupportedLocale, type SDKTranslations } from '../translations/translation-manager';
6
- import { type ShopInfo, type SDKInternalConfig } from '../config/internal-config';
5
+ import { type SupportedLocale, type SDKTranslations } from "../translations/translation-manager";
6
+ import { type ShopInfo, type SDKInternalConfig } from "../config/internal-config";
7
+ import { DashboardEngine } from "./engine";
8
+ import { DashboardData } from "../types";
7
9
  interface SDKState {
8
10
  initialized: boolean;
9
11
  shopInfo?: ShopInfo;
@@ -12,6 +14,12 @@ interface SDKState {
12
14
  config: SDKInternalConfig;
13
15
  loading: boolean;
14
16
  error?: Error;
17
+ dashboardData?: DashboardData | null;
18
+ dashboardLoading?: boolean;
19
+ dashboardError?: Error | null;
20
+ campaignsData?: any[] | null;
21
+ campaignsLoading?: boolean;
22
+ campaignsError?: Error | null;
15
23
  }
16
24
  interface SDKOptions {
17
25
  shopInfo?: ShopInfo;
@@ -25,6 +33,7 @@ declare class SDKManagerClass {
25
33
  private initPromise?;
26
34
  private localeObserver?;
27
35
  private currentDetectedLocale?;
36
+ private dashboardEngine?;
28
37
  constructor();
29
38
  /**
30
39
  * Auto-detect current locale from browser/Shopify context
@@ -47,9 +56,13 @@ declare class SDKManagerClass {
47
56
  */
48
57
  private handleLocaleChange;
49
58
  /**
50
- * Refresh API data with new locale
59
+ * Refresh dashboard data with new locale
51
60
  */
52
- private refreshDataWithNewLocale;
61
+ private refreshDashboardData;
62
+ /**
63
+ * Refresh campaigns data with new locale
64
+ */
65
+ private refreshCampaignsData;
53
66
  /**
54
67
  * Normalize locale string to supported format
55
68
  */
@@ -141,6 +154,18 @@ declare class SDKManagerClass {
141
154
  readonly encryptStorage: false;
142
155
  };
143
156
  };
157
+ /**
158
+ * Get dashboard engine instance
159
+ */
160
+ getDashboardEngine(): DashboardEngine | undefined;
161
+ /**
162
+ * Get dashboard data
163
+ */
164
+ getDashboardData(): DashboardData | null | undefined;
165
+ /**
166
+ * Get campaigns data
167
+ */
168
+ getCampaignsData(): any[] | null | undefined;
144
169
  /**
145
170
  * Check if SDK is ready for use
146
171
  */
@@ -218,6 +243,7 @@ export declare function useSDK(options?: UseSDKOptions): {
218
243
  };
219
244
  };
220
245
  isReady: boolean;
246
+ dashboardEngine: DashboardEngine | undefined;
221
247
  initialized: boolean;
222
248
  shopInfo?: ShopInfo;
223
249
  locale: SupportedLocale;
@@ -225,6 +251,12 @@ export declare function useSDK(options?: UseSDKOptions): {
225
251
  config: SDKInternalConfig;
226
252
  loading: boolean;
227
253
  error?: Error;
254
+ dashboardData?: DashboardData | null;
255
+ dashboardLoading?: boolean;
256
+ dashboardError?: Error | null;
257
+ campaignsData?: any[] | null;
258
+ campaignsLoading?: boolean;
259
+ campaignsError?: Error | null;
228
260
  };
229
261
  export default SDKManager;
230
262
  //# sourceMappingURL=SDKManager.d.ts.map
@@ -1 +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,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAA2B,KAAK,QA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAtmBnC,OAAO;eACT,QAAQ;YACX,eAAe;kBACT,eAAe;YACrB,iBAAiB;aAChB,OAAO;YACR,KAAK;oBACG,aAAa,GAAG,IAAI;uBACjB,OAAO;qBACT,KAAK,GAAG,IAAI;oBACb,GAAG,EAAE,GAAG,IAAI;uBACT,OAAO;qBACT,KAAK,GAAG,IAAI;EA8nB9B;AAED,eAAe,UAAU,CAAC"}
@@ -2,9 +2,10 @@
2
2
  * SDK Manager - Internal singleton for managing global state
3
3
  * Components automatically connect to this without manual provider setup
4
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';
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
+ import { DashboardEngine } from "./engine";
8
9
  // ============================================
9
10
  // SDK Manager Singleton
10
11
  // ============================================
@@ -16,16 +17,16 @@ class SDKManagerClass {
16
17
  */
17
18
  this.handleCustomLocaleChange = (event) => {
18
19
  const newLocale = event.detail?.locale || event.detail;
19
- if (newLocale && typeof newLocale === 'string') {
20
+ if (newLocale && typeof newLocale === "string") {
20
21
  const normalizedLocale = this.normalizeLocale(newLocale);
21
- console.log('๐Ÿ“ก Received locale change event:', normalizedLocale);
22
+ // console.log("Received locale change event:", normalizedLocale);
22
23
  this.handleLocaleChange(normalizedLocale);
23
24
  }
24
25
  };
25
26
  this.state = {
26
27
  initialized: false,
27
- locale: 'en',
28
- translations: getTranslations('en'),
28
+ locale: "en",
29
+ translations: getTranslations("en"),
29
30
  config: generateDashboardConfig(),
30
31
  loading: false,
31
32
  };
@@ -38,7 +39,7 @@ class SDKManagerClass {
38
39
  * Auto-detect current locale from browser/Shopify context
39
40
  */
40
41
  autoDetectLocale() {
41
- if (typeof window === 'undefined')
42
+ if (typeof window === "undefined")
42
43
  return;
43
44
  try {
44
45
  // Method 1: Check Shopify Admin locale (if available)
@@ -46,7 +47,7 @@ class SDKManagerClass {
46
47
  if (shopifyLocale) {
47
48
  this.currentDetectedLocale = shopifyLocale;
48
49
  this.updateLocale(shopifyLocale);
49
- console.log('๐ŸŒ Auto-detected Shopify locale:', shopifyLocale);
50
+ // console.log("Auto-detected Shopify locale:", shopifyLocale);
50
51
  return;
51
52
  }
52
53
  // Method 2: Browser language
@@ -55,11 +56,11 @@ class SDKManagerClass {
55
56
  const normalizedLocale = this.normalizeLocale(browserLocale);
56
57
  this.currentDetectedLocale = normalizedLocale;
57
58
  this.updateLocale(normalizedLocale);
58
- console.log('๐ŸŒ Auto-detected browser locale:', normalizedLocale);
59
+ // console.log("Auto-detected browser locale:", normalizedLocale);
59
60
  }
60
61
  }
61
62
  catch (error) {
62
- console.warn('Failed to auto-detect locale:', error);
63
+ console.warn("Failed to auto-detect locale:", error);
63
64
  }
64
65
  }
65
66
  /**
@@ -69,14 +70,14 @@ class SDKManagerClass {
69
70
  try {
70
71
  // Check if we can detect locale from Shopify admin
71
72
  const html = document.documentElement;
72
- const lang = html.getAttribute('lang') || html.getAttribute('xml:lang');
73
+ const lang = html.getAttribute("lang") || html.getAttribute("xml:lang");
73
74
  if (lang) {
74
75
  return this.normalizeLocale(lang);
75
76
  }
76
77
  // Check meta tags
77
78
  const metaLang = document.querySelector('meta[http-equiv="content-language"]');
78
79
  if (metaLang) {
79
- const content = metaLang.getAttribute('content');
80
+ const content = metaLang.getAttribute("content");
80
81
  if (content) {
81
82
  return this.normalizeLocale(content);
82
83
  }
@@ -91,16 +92,22 @@ class SDKManagerClass {
91
92
  * Setup watcher for locale changes in the DOM
92
93
  */
93
94
  setupLocaleWatcher() {
94
- if (typeof window === 'undefined')
95
+ if (typeof window === "undefined")
95
96
  return;
96
97
  try {
97
98
  this.localeObserver = new MutationObserver((mutations) => {
98
99
  mutations.forEach((mutation) => {
99
- if (mutation.type === 'attributes' &&
100
- (mutation.attributeName === 'lang' || mutation.attributeName === 'xml:lang')) {
100
+ if (mutation.type === "attributes" &&
101
+ (mutation.attributeName === "lang" ||
102
+ mutation.attributeName === "xml:lang")) {
101
103
  const newLocale = this.getShopifyAdminLocale();
102
104
  if (newLocale && newLocale !== this.currentDetectedLocale) {
103
- console.log('๐Ÿ”„ Detected locale change:', this.currentDetectedLocale, 'โ†’', newLocale);
105
+ // console.log(
106
+ // "Detected locale change:",
107
+ // this.currentDetectedLocale,
108
+ // "โ†’",
109
+ // newLocale,
110
+ // );
104
111
  this.currentDetectedLocale = newLocale;
105
112
  this.handleLocaleChange(newLocale);
106
113
  }
@@ -110,15 +117,15 @@ class SDKManagerClass {
110
117
  // Watch for changes to document element attributes
111
118
  this.localeObserver.observe(document.documentElement, {
112
119
  attributes: true,
113
- attributeFilter: ['lang', 'xml:lang']
120
+ attributeFilter: ["lang", "xml:lang"],
114
121
  });
115
122
  // 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');
123
+ window.addEventListener("trustshop-locale-change", this.handleCustomLocaleChange.bind(this));
124
+ window.addEventListener("shopify-locale-change", this.handleCustomLocaleChange.bind(this));
125
+ // console.log("Locale watcher initialized");
119
126
  }
120
127
  catch (error) {
121
- console.warn('Failed to setup locale watcher:', error);
128
+ console.warn("Failed to setup locale watcher:", error);
122
129
  }
123
130
  }
124
131
  /**
@@ -128,48 +135,161 @@ class SDKManagerClass {
128
135
  if (newLocale === this.state.locale)
129
136
  return;
130
137
  try {
131
- console.log('๐Ÿ”„ Updating SDK locale:', this.state.locale, 'โ†’', newLocale);
138
+ // console.log(Updating SDK locale:", this.state.locale, "โ†’", newLocale);
132
139
  this.updateState({ loading: true });
133
140
  // Load new translations
134
141
  const baseTranslations = await loadTranslations(newLocale);
135
142
  const translations = mergeTranslations(baseTranslations);
143
+ // Update config with new locale
144
+ const newConfig = { ...this.state.config, locale: newLocale };
136
145
  // Update state
137
146
  this.updateState({
138
147
  locale: newLocale,
139
148
  translations,
149
+ config: newConfig,
140
150
  loading: false,
141
151
  });
142
152
  // Trigger re-fetch of API data with new locale
143
- this.refreshDataWithNewLocale(newLocale);
144
- console.log('โœ… SDK locale updated successfully');
153
+ await this.refreshDashboardData(newLocale);
154
+ // console.log("SDK locale updated successfully");
145
155
  }
146
156
  catch (error) {
147
- console.error('โŒ Failed to update SDK locale:', error);
157
+ console.error(" Failed to update SDK locale:", error);
148
158
  this.updateState({ loading: false, error: error });
149
159
  }
150
160
  }
151
161
  /**
152
- * Refresh API data with new locale
162
+ * Refresh dashboard data with new locale
153
163
  */
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);
164
+ async refreshDashboardData(locale) {
165
+ try {
166
+ this.updateState({ dashboardLoading: true, dashboardError: null });
167
+ const currentLocale = locale || this.state.locale;
168
+ const config = { ...this.state.config, locale: currentLocale };
169
+ // Initialize or update dashboard engine
170
+ if (!this.dashboardEngine) {
171
+ this.dashboardEngine = DashboardEngine.getInstance(config);
172
+ }
173
+ else {
174
+ // Update engine config with new locale
175
+ await this.dashboardEngine.setLocale(currentLocale);
176
+ }
177
+ // Fetch dashboard data
178
+ await this.dashboardEngine.init();
179
+ const dashboardData = this.dashboardEngine.getData();
180
+ this.updateState({
181
+ dashboardData,
182
+ dashboardLoading: false,
183
+ dashboardError: null,
184
+ });
185
+ // Also refresh campaigns data
186
+ await this.refreshCampaignsData(currentLocale);
187
+ // Emit event for components to refresh
188
+ window.dispatchEvent(new CustomEvent("trustshop-data-refresh", {
189
+ detail: {
190
+ locale: currentLocale,
191
+ reason: "locale-change",
192
+ data: dashboardData,
193
+ },
194
+ }));
195
+ // console.log(`Dashboard data refreshed for locale: ${currentLocale}`);
196
+ }
197
+ catch (error) {
198
+ console.error("Failed to refresh dashboard data:", error);
199
+ this.updateState({
200
+ dashboardLoading: false,
201
+ dashboardError: error,
202
+ });
203
+ }
204
+ }
205
+ /**
206
+ * Refresh campaigns data with new locale
207
+ */
208
+ async refreshCampaignsData(locale) {
209
+ try {
210
+ // Only fetch campaigns if we have a shop ID
211
+ if (!this.state.shopInfo?.id) {
212
+ // console.log("Skipping campaigns fetch - no shop ID available");
213
+ return;
214
+ }
215
+ this.updateState({ campaignsLoading: true, campaignsError: null });
216
+ const currentLocale = locale || this.state.locale;
217
+ const shopId = this.state.shopInfo.id;
218
+ // Build campaigns API URL
219
+ let baseUrl;
220
+ if (this.state.config?.apiUrl) {
221
+ const configUrl = this.state.config.apiUrl;
222
+ if (configUrl.includes("/dashboard")) {
223
+ baseUrl = configUrl.replace("/dashboard", "");
224
+ }
225
+ else {
226
+ baseUrl = configUrl;
227
+ }
228
+ }
229
+ else {
230
+ baseUrl =
231
+ typeof window !== "undefined" &&
232
+ window.location.hostname === "localhost"
233
+ ? "/api"
234
+ : "https://ops.trustshop.io/api";
235
+ }
236
+ const apiUrl = `${baseUrl}/campaigns?shop_id=${shopId}&locale=${currentLocale}`;
237
+ const response = await fetch(apiUrl, {
238
+ method: "GET",
239
+ headers: {
240
+ Accept: "application/json",
241
+ "Content-Type": "application/json",
242
+ "Accept-Language": currentLocale,
243
+ ...(this.state.config?.headers || {}),
244
+ },
245
+ credentials: "include",
246
+ });
247
+ if (!response.ok) {
248
+ throw new Error(`Failed to fetch campaigns: ${response.statusText}`);
249
+ }
250
+ const data = await response.json();
251
+ const campaignsData = data.success && Array.isArray(data.data) ? data.data : [];
252
+ this.updateState({
253
+ campaignsData,
254
+ campaignsLoading: false,
255
+ campaignsError: null,
256
+ });
257
+ // Emit event for campaigns refresh
258
+ window.dispatchEvent(new CustomEvent("trustshop-campaigns-refresh", {
259
+ detail: { locale: currentLocale, data: campaignsData, shopId },
260
+ }));
261
+ }
262
+ catch (error) {
263
+ console.error("Failed to refresh campaigns data:", error);
264
+ this.updateState({
265
+ campaignsLoading: false,
266
+ campaignsError: error,
267
+ });
268
+ }
162
269
  }
163
270
  /**
164
271
  * Normalize locale string to supported format
165
272
  */
166
273
  normalizeLocale(locale) {
167
274
  if (!locale)
168
- return 'en';
275
+ return "en";
169
276
  // Use the same normalization as translation manager
170
277
  const SUPPORTED_LOCALES = [
171
- 'cn', 'de', 'dk', 'en', 'es', 'fr', 'ie', 'in',
172
- 'it', 'jp', 'nl', 'nz', 'pt', 'se', 'vi'
278
+ "cn",
279
+ "de",
280
+ "dk",
281
+ "en",
282
+ "es",
283
+ "fr",
284
+ "ie",
285
+ "in",
286
+ "it",
287
+ "jp",
288
+ "nl",
289
+ "nz",
290
+ "pt",
291
+ "se",
292
+ "vi",
173
293
  ];
174
294
  // Direct match
175
295
  if (SUPPORTED_LOCALES.includes(locale)) {
@@ -179,19 +299,19 @@ class SDKManagerClass {
179
299
  const base = locale.split(/[-_]/)[0].toLowerCase();
180
300
  // Special mappings
181
301
  const mappings = {
182
- 'zh': 'cn',
183
- 'da': 'dk',
184
- 'ga': 'ie',
185
- 'hi': 'in',
186
- 'ja': 'jp',
187
- 'mi': 'nz',
188
- 'sv': 'se',
302
+ zh: "cn",
303
+ da: "dk",
304
+ ga: "ie",
305
+ hi: "in",
306
+ ja: "jp",
307
+ mi: "nz",
308
+ sv: "se",
189
309
  };
190
310
  const mapped = mappings[base] || base;
191
311
  if (SUPPORTED_LOCALES.includes(mapped)) {
192
312
  return mapped;
193
313
  }
194
- return 'en';
314
+ return "en";
195
315
  }
196
316
  /**
197
317
  * Manually update locale (for programmatic changes)
@@ -204,14 +324,12 @@ class SDKManagerClass {
204
324
  * Auto-detect shop info from Shopify App Bridge or URL
205
325
  */
206
326
  autoDetectShopInfo() {
207
- if (typeof window === 'undefined')
327
+ if (typeof window === "undefined")
208
328
  return;
209
329
  try {
210
330
  // Method 1: Check if Shopify App Bridge is available
211
331
  const shopifyApp = window.ShopifyApp;
212
332
  if (shopifyApp) {
213
- // Extract from App Bridge context if available
214
- console.log('๐Ÿ” Detected Shopify App Bridge context');
215
333
  }
216
334
  // Method 2: Parse from URL (admin.shopify.com)
217
335
  const currentUrl = window.location.href;
@@ -222,13 +340,12 @@ class SDKManagerClass {
222
340
  shopInfo: {
223
341
  domain: `${storeName}.myshopify.com`,
224
342
  id: storeName,
225
- }
343
+ },
226
344
  });
227
- console.log('๐Ÿ” Auto-detected shop from URL:', storeName);
228
345
  }
229
346
  }
230
347
  catch (error) {
231
- console.warn('Failed to auto-detect shop info:', error);
348
+ console.warn("Failed to auto-detect shop info:", error);
232
349
  }
233
350
  }
234
351
  /**
@@ -249,8 +366,11 @@ class SDKManagerClass {
249
366
  // Load translations
250
367
  const baseTranslations = await loadTranslations(locale);
251
368
  const translations = mergeTranslations(baseTranslations, options.translations);
252
- // Generate config
253
- const config = generateDashboardConfig(shopInfo, options.config);
369
+ // Generate config with locale
370
+ const config = {
371
+ ...generateDashboardConfig(shopInfo, options.config),
372
+ locale,
373
+ };
254
374
  this.updateState({
255
375
  initialized: true,
256
376
  locale,
@@ -260,14 +380,19 @@ class SDKManagerClass {
260
380
  loading: false,
261
381
  error: undefined,
262
382
  });
263
- console.log('โœ… SDK initialized successfully', { locale, shopInfo });
383
+ // Automatically fetch dashboard data after initialization
384
+ await this.refreshDashboardData(locale);
385
+ // console.log("SDK initialized successfully with dashboard data", {
386
+ // locale,
387
+ // shopInfo,
388
+ // });
264
389
  }
265
390
  catch (error) {
266
391
  this.updateState({
267
392
  loading: false,
268
393
  error: error,
269
394
  });
270
- console.error('โŒ SDK initialization failed:', error);
395
+ console.error("SDK initialization failed:", error);
271
396
  throw error;
272
397
  }
273
398
  }
@@ -303,7 +428,7 @@ class SDKManagerClass {
303
428
  return () => this.listeners.delete(listener);
304
429
  }
305
430
  notifyListeners() {
306
- this.listeners.forEach(listener => listener());
431
+ this.listeners.forEach((listener) => listener());
307
432
  }
308
433
  /**
309
434
  * Get component defaults
@@ -311,11 +436,32 @@ class SDKManagerClass {
311
436
  getDefaults() {
312
437
  return COMPONENT_DEFAULTS;
313
438
  }
439
+ /**
440
+ * Get dashboard engine instance
441
+ */
442
+ getDashboardEngine() {
443
+ return this.dashboardEngine;
444
+ }
445
+ /**
446
+ * Get dashboard data
447
+ */
448
+ getDashboardData() {
449
+ return this.state.dashboardData;
450
+ }
451
+ /**
452
+ * Get campaigns data
453
+ */
454
+ getCampaignsData() {
455
+ return this.state.campaignsData;
456
+ }
314
457
  /**
315
458
  * Check if SDK is ready for use
316
459
  */
317
460
  isReady() {
318
- return this.state.initialized && !this.state.loading && !this.state.error;
461
+ return (this.state.initialized &&
462
+ !this.state.loading &&
463
+ !this.state.error &&
464
+ !this.state.dashboardLoading);
319
465
  }
320
466
  /**
321
467
  * Cleanup observers and listeners
@@ -324,12 +470,12 @@ class SDKManagerClass {
324
470
  if (this.localeObserver) {
325
471
  this.localeObserver.disconnect();
326
472
  }
327
- if (typeof window !== 'undefined') {
328
- window.removeEventListener('trustshop-locale-change', this.handleCustomLocaleChange);
329
- window.removeEventListener('shopify-locale-change', this.handleCustomLocaleChange);
473
+ if (typeof window !== "undefined") {
474
+ window.removeEventListener("trustshop-locale-change", this.handleCustomLocaleChange);
475
+ window.removeEventListener("shopify-locale-change", this.handleCustomLocaleChange);
330
476
  }
331
477
  this.listeners.clear();
332
- console.log('๐Ÿงน SDK Manager cleaned up');
478
+ // console.log("SDK Manager cleaned up");
333
479
  }
334
480
  }
335
481
  // ============================================
@@ -339,7 +485,7 @@ export const SDKManager = new SDKManagerClass();
339
485
  // ============================================
340
486
  // React Hook for Components
341
487
  // ============================================
342
- import { useState, useEffect } from 'react';
488
+ import { useState, useEffect } from "react";
343
489
  /**
344
490
  * Hook for components to connect to SDK Manager
345
491
  * Automatically initializes SDK on first use
@@ -374,6 +520,7 @@ export function useSDK(options = {}) {
374
520
  isInitializing,
375
521
  defaults: SDKManager.getDefaults(),
376
522
  isReady: SDKManager.isReady(),
523
+ dashboardEngine: SDKManager.getDashboardEngine(),
377
524
  };
378
525
  }
379
526
  export default SDKManager;