@kaena1/ecomm-contained-utils 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  import { mapMintLayoutResponseToProps as i } from "../../../mappers/mapMintLayoutResponseToProps.js";
3
3
  async function c(o, n, s) {
4
4
  const [e, r] = s.split("|"), t = await fetch(
5
- `${n}mint/components/mintLayout/v1`,
5
+ `${n}/mint/components/mintLayout/v1`,
6
6
  {
7
7
  method: "POST",
8
8
  headers: {
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
 
3
- export declare interface ComponentManifest {
3
+ declare interface ComponentManifest {
4
4
  bundleUrl: string;
5
5
  styleUrl?: string;
6
6
  }
@@ -26,13 +26,15 @@ export declare const generateImportMapJson: (config?: ImportMapConfig) => string
26
26
 
27
27
  export declare function getMintLayoutProps(NEXT_PUBLIC_SITE_URL: string, ECOMM_API_URL: string, ECOMM_API_STANDALONE_DEVICE_CREDS: string): Promise<MintLayoutProps>;
28
28
 
29
- export declare interface ImportMapConfig {
29
+ declare interface ImportMapConfig {
30
30
  reactVersion?: string;
31
31
  reactDomVersion?: string;
32
32
  }
33
33
 
34
34
  export declare const ImportMapScripts: () => JSX.Element;
35
35
 
36
+ export declare const mapMintLayoutResponseToProps: (NEXT_PUBLIC_SITE_URL: string, data: MintLayoutPropsAPIResponse) => MintLayoutProps;
37
+
36
38
  declare interface MintFooterProps {
37
39
  footerNav: WP_REST_API_Nav_Menu_Items;
38
40
  subfooterNav: WP_REST_API_Nav_Menu_Items;
@@ -46,7 +48,7 @@ declare interface MintHeaderProps {
46
48
  className?: string;
47
49
  }
48
50
 
49
- export declare interface MintLayoutProps {
51
+ declare interface MintLayoutProps {
50
52
  config: {
51
53
  NEXT_PUBLIC_SITE_URL: string;
52
54
  };
@@ -56,28 +58,24 @@ export declare interface MintLayoutProps {
56
58
  slimBannerProps?: Partial<SlimbannerProps>;
57
59
  }
58
60
 
59
- export declare interface ModuleLoadOptions {
60
- bundleUrl: string;
61
- componentName: string;
62
- }
63
-
64
- export declare interface RemoteComponentState {
65
- component: RemoteComponentType | null;
66
- manifest: ComponentManifest | null;
67
- loading: boolean;
68
- error: string | null;
69
- loaded: boolean;
61
+ declare interface MintLayoutPropsAPIResponse {
62
+ theme: WP_REST_API_Theme;
63
+ widgets: WP_REST_API_Widget[];
64
+ menuItems: {
65
+ 'primary-navigation-left': WP_REST_API_Nav_Menu_Items;
66
+ 'primary-navigation-right': WP_REST_API_Nav_Menu_Items;
67
+ 'footer-menu': WP_REST_API_Nav_Menu_Items;
68
+ 'footer-legal-pages': WP_REST_API_Nav_Menu_Items;
69
+ };
70
70
  }
71
71
 
72
- export declare type RemoteComponentType = React.ComponentType<any>;
73
-
74
72
  export declare const RemoteLinks: ({ manifest }: RemoteLinksProps) => JSX.Element;
75
73
 
76
74
  declare interface RemoteLinksProps {
77
75
  manifest: ComponentManifest;
78
76
  }
79
77
 
80
- export declare interface RemoteManifest {
78
+ declare interface RemoteManifest {
81
79
  components: Record<string, ComponentManifest>;
82
80
  version: string;
83
81
  generatedAt: string;
@@ -88,18 +86,6 @@ declare interface SlimbannerProps {
88
86
  isEnabled: boolean;
89
87
  }
90
88
 
91
- export declare interface UseRemoteComponentOptions {
92
- manifest: ComponentManifest;
93
- componentName: string;
94
- autoLoad?: boolean;
95
- }
96
-
97
- export declare interface UseRemoteComponentReturn extends RemoteComponentState {
98
- loadComponent: () => Promise<void>;
99
- reload: () => Promise<void>;
100
- clearError: () => void;
101
- }
102
-
103
89
  declare interface WP_REST_API_Content {
104
90
  rendered: string;
105
91
  raw: string;
@@ -129,4 +115,22 @@ declare interface WP_REST_API_Nav_Menu_Item {
129
115
 
130
116
  declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
131
117
 
118
+ declare interface WP_REST_API_Theme {
119
+ countdown: {
120
+ is_enabled: boolean;
121
+ start_datetime: string;
122
+ start_timezone: string;
123
+ end_datetime: string;
124
+ end_timezone: string;
125
+ start_datetime_utc: string;
126
+ end_datetime_utc: string;
127
+ is_server_now_between: boolean;
128
+ };
129
+ }
130
+
131
+ declare interface WP_REST_API_Widget {
132
+ name: string;
133
+ data: WP_REST_API_Content;
134
+ }
135
+
132
136
  export { }
package/dist/server.js CHANGED
@@ -3,11 +3,13 @@ import { generateImportMap as p, generateImportMapJson as m } from "./services/I
3
3
  import { ImportMapScripts as f } from "./components/ImportMapScripts.js";
4
4
  import { RemoteLinks as s } from "./components/RemoteLinks.js";
5
5
  import { getMintLayoutProps as M } from "./lib/api/server/getMintLayoutProps/getMintLayoutProps.js";
6
+ import { mapMintLayoutResponseToProps as g } from "./lib/mappers/mapMintLayoutResponseToProps.js";
6
7
  export {
7
8
  f as ImportMapScripts,
8
9
  s as RemoteLinks,
9
10
  t as fetchManifest,
10
11
  p as generateImportMap,
11
12
  m as generateImportMapJson,
12
- M as getMintLayoutProps
13
+ M as getMintLayoutProps,
14
+ g as mapMintLayoutResponseToProps
13
15
  };
@@ -0,0 +1,137 @@
1
+ export declare interface ComponentManifest {
2
+ bundleUrl: string;
3
+ styleUrl?: string;
4
+ }
5
+
6
+ declare interface CountdownbannerProps {
7
+ isEnabled: boolean;
8
+ startDatetime: Date;
9
+ endDatetime: Date;
10
+ message: string;
11
+ }
12
+
13
+ export declare interface ImportMapConfig {
14
+ reactVersion?: string;
15
+ reactDomVersion?: string;
16
+ }
17
+
18
+ declare interface MintFooterProps {
19
+ footerNav: WP_REST_API_Nav_Menu_Items;
20
+ subfooterNav: WP_REST_API_Nav_Menu_Items;
21
+ }
22
+
23
+ declare interface MintHeaderProps {
24
+ primaryNav: {
25
+ left: WP_REST_API_Nav_Menu_Items;
26
+ right: WP_REST_API_Nav_Menu_Items;
27
+ };
28
+ className?: string;
29
+ }
30
+
31
+ export declare interface MintLayoutProps {
32
+ config: {
33
+ NEXT_PUBLIC_SITE_URL: string;
34
+ };
35
+ headerProps?: MintHeaderProps;
36
+ footerProps?: MintFooterProps;
37
+ countdownbannerProps?: Partial<CountdownbannerProps>;
38
+ slimBannerProps?: Partial<SlimbannerProps>;
39
+ }
40
+
41
+ export declare interface MintLayoutPropsAPIResponse {
42
+ theme: WP_REST_API_Theme;
43
+ widgets: WP_REST_API_Widget[];
44
+ menuItems: {
45
+ 'primary-navigation-left': WP_REST_API_Nav_Menu_Items;
46
+ 'primary-navigation-right': WP_REST_API_Nav_Menu_Items;
47
+ 'footer-menu': WP_REST_API_Nav_Menu_Items;
48
+ 'footer-legal-pages': WP_REST_API_Nav_Menu_Items;
49
+ };
50
+ }
51
+
52
+ export declare interface ModuleLoadOptions {
53
+ bundleUrl: string;
54
+ componentName: string;
55
+ }
56
+
57
+ export declare interface RemoteComponentState {
58
+ component: RemoteComponentType | null;
59
+ manifest: ComponentManifest | null;
60
+ loading: boolean;
61
+ error: string | null;
62
+ loaded: boolean;
63
+ }
64
+
65
+ export declare type RemoteComponentType = React.ComponentType<any>;
66
+
67
+ export declare interface RemoteManifest {
68
+ components: Record<string, ComponentManifest>;
69
+ version: string;
70
+ generatedAt: string;
71
+ }
72
+
73
+ declare interface SlimbannerProps {
74
+ bannerMessage: string;
75
+ isEnabled: boolean;
76
+ }
77
+
78
+ export declare interface UseRemoteComponentOptions {
79
+ manifest: ComponentManifest;
80
+ componentName: string;
81
+ autoLoad?: boolean;
82
+ }
83
+
84
+ export declare interface UseRemoteComponentReturn extends RemoteComponentState {
85
+ loadComponent: () => Promise<void>;
86
+ reload: () => Promise<void>;
87
+ clearError: () => void;
88
+ }
89
+
90
+ export declare interface WP_REST_API_Content {
91
+ rendered: string;
92
+ raw: string;
93
+ }
94
+
95
+ export declare interface WP_REST_API_Nav_Menu_Item {
96
+ id: number;
97
+ title: WP_REST_API_Content;
98
+ status: string;
99
+ url: string;
100
+ attr_title: string;
101
+ description: string;
102
+ type: string;
103
+ type_label: string;
104
+ object: string;
105
+ object_id: number;
106
+ parent: number;
107
+ menu_order: number;
108
+ target: string;
109
+ classes: string[];
110
+ xfn: string[];
111
+ invalid: boolean;
112
+ meta: Record<string, string>;
113
+ menus: number;
114
+ _links: Record<string, []>;
115
+ }
116
+
117
+ export declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
118
+
119
+ export declare interface WP_REST_API_Theme {
120
+ countdown: {
121
+ is_enabled: boolean;
122
+ start_datetime: string;
123
+ start_timezone: string;
124
+ end_datetime: string;
125
+ end_timezone: string;
126
+ start_datetime_utc: string;
127
+ end_datetime_utc: string;
128
+ is_server_now_between: boolean;
129
+ };
130
+ }
131
+
132
+ export declare interface WP_REST_API_Widget {
133
+ name: string;
134
+ data: WP_REST_API_Content;
135
+ }
136
+
137
+ export { }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "@kaena1/ecomm-contained-utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Shared utilities for loading remote React components in Mint Mobile microfrontends",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
6
  "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
13
- },
14
7
  "./server": {
15
8
  "types": "./dist/server.d.ts",
16
9
  "import": "./dist/server.js"
@@ -18,6 +11,10 @@
18
11
  "./client": {
19
12
  "types": "./dist/client.d.ts",
20
13
  "import": "./dist/client.js"
14
+ },
15
+ "./types": {
16
+ "types": "./dist/types.d.ts",
17
+ "import": "./dist/types.js"
21
18
  }
22
19
  },
23
20
  "files": [
package/dist/index.d.ts DELETED
@@ -1,191 +0,0 @@
1
- /// <reference types="react" />
2
-
3
- import { default as default_2 } from 'react';
4
-
5
- export declare interface ComponentManifest {
6
- bundleUrl: string;
7
- styleUrl?: string;
8
- }
9
-
10
- declare interface CountdownbannerProps {
11
- isEnabled: boolean;
12
- startDatetime: Date;
13
- endDatetime: Date;
14
- message: string;
15
- }
16
-
17
- export declare function fetchManifest(manifestUrl: string): Promise<RemoteManifest>;
18
-
19
- /**
20
- * Generate complete import map object for remote components
21
- *
22
- * @param config - Optional configuration to override default settings
23
- * @returns Import map object ready for browser consumption
24
- */
25
- export declare const generateImportMap: (config?: ImportMapConfig) => object;
26
-
27
- export declare const generateImportMapJson: (config?: ImportMapConfig) => string;
28
-
29
- export declare interface ImportMapConfig {
30
- reactVersion?: string;
31
- reactDomVersion?: string;
32
- }
33
-
34
- export declare const ImportMapScripts: () => JSX.Element;
35
-
36
- declare interface MintFooterProps {
37
- footerNav: WP_REST_API_Nav_Menu_Items;
38
- subfooterNav: WP_REST_API_Nav_Menu_Items;
39
- }
40
-
41
- declare interface MintHeaderProps {
42
- primaryNav: {
43
- left: WP_REST_API_Nav_Menu_Items;
44
- right: WP_REST_API_Nav_Menu_Items;
45
- };
46
- className?: string;
47
- }
48
-
49
- export declare interface MintLayoutProps {
50
- config: {
51
- NEXT_PUBLIC_SITE_URL: string;
52
- };
53
- headerProps?: MintHeaderProps;
54
- footerProps?: MintFooterProps;
55
- countdownbannerProps?: Partial<CountdownbannerProps>;
56
- slimBannerProps?: Partial<SlimbannerProps>;
57
- }
58
-
59
- export declare class ModuleLoader {
60
- private loadedModules;
61
- private importMapInjected;
62
- private prepareGlobalDependencies;
63
- /**
64
- * Ensure import map is injected before loading any modules
65
- * Import maps MUST be added before any module scripts
66
- */
67
- private ensureImportMap;
68
- /**
69
- * Load remote React component from ES module URL
70
- *
71
- * @param options - Configuration object with bundleUrl and componentName
72
- * @returns Promise that resolves to the loaded React component
73
- * @throws Error if component loading fails or times out (10s)
74
- */
75
- loadComponent(options: ModuleLoadOptions): Promise<RemoteComponentType>;
76
- /**
77
- * Load ES module from external URL using dynamic script injection
78
- * This bypasses Webpack's module resolution and works with import maps
79
- */
80
- private loadModuleViaScript;
81
- /**
82
- * Preload a module without extracting components
83
- * Useful for warming up cache
84
- *
85
- * @param bundleUrl - URL of the module to preload
86
- */
87
- preloadModule(bundleUrl: string): Promise<void>;
88
- /**
89
- * Check if a module has already been loaded
90
- *
91
- * @param bundleUrl - URL of the module to check
92
- * @returns true if module is already loaded, false otherwise
93
- */
94
- isLoaded(bundleUrl: string): boolean;
95
- /**
96
- * Clear all loaded modules from cache
97
- * Useful for development/testing
98
- */
99
- clearCache(): void;
100
- }
101
-
102
- export declare const moduleLoader: ModuleLoader;
103
-
104
- export declare interface ModuleLoadOptions {
105
- bundleUrl: string;
106
- componentName: string;
107
- }
108
-
109
- export declare interface RemoteComponentState {
110
- component: RemoteComponentType | null;
111
- manifest: ComponentManifest | null;
112
- loading: boolean;
113
- error: string | null;
114
- loaded: boolean;
115
- }
116
-
117
- export declare type RemoteComponentType = React.ComponentType<any>;
118
-
119
- export declare const RemoteLinks: ({ manifest }: RemoteLinksProps) => JSX.Element;
120
-
121
- declare interface RemoteLinksProps {
122
- manifest: ComponentManifest;
123
- }
124
-
125
- export declare interface RemoteManifest {
126
- components: Record<string, ComponentManifest>;
127
- version: string;
128
- generatedAt: string;
129
- }
130
-
131
- export declare const RemoteRenderer: default_2.FC<RemoteRendererProps>;
132
-
133
- declare interface RemoteRendererProps {
134
- manifest: ComponentManifest;
135
- componentName: string;
136
- componentProps?: any;
137
- autoLoad?: boolean;
138
- placeholder?: default_2.ReactNode;
139
- children?: default_2.ReactNode;
140
- errorFallback?: (error: string) => default_2.ReactNode;
141
- }
142
-
143
- declare interface SlimbannerProps {
144
- bannerMessage: string;
145
- isEnabled: boolean;
146
- }
147
-
148
- export declare function useRemoteComponent(options: UseRemoteComponentOptions): UseRemoteComponentReturn;
149
-
150
- export declare interface UseRemoteComponentOptions {
151
- manifest: ComponentManifest;
152
- componentName: string;
153
- autoLoad?: boolean;
154
- }
155
-
156
- export declare interface UseRemoteComponentReturn extends RemoteComponentState {
157
- loadComponent: () => Promise<void>;
158
- reload: () => Promise<void>;
159
- clearError: () => void;
160
- }
161
-
162
- declare interface WP_REST_API_Content {
163
- rendered: string;
164
- raw: string;
165
- }
166
-
167
- declare interface WP_REST_API_Nav_Menu_Item {
168
- id: number;
169
- title: WP_REST_API_Content;
170
- status: string;
171
- url: string;
172
- attr_title: string;
173
- description: string;
174
- type: string;
175
- type_label: string;
176
- object: string;
177
- object_id: number;
178
- parent: number;
179
- menu_order: number;
180
- target: string;
181
- classes: string[];
182
- xfn: string[];
183
- invalid: boolean;
184
- meta: Record<string, string>;
185
- menus: number;
186
- _links: Record<string, []>;
187
- }
188
-
189
- declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
190
-
191
- export { }
package/dist/index.js DELETED
@@ -1,18 +0,0 @@
1
- import { fetchManifest as r } from "./services/fetchManifest.js";
2
- import { ModuleLoader as m, moduleLoader as p } from "./services/moduleLoader.js";
3
- import { generateImportMap as a, generateImportMapJson as n } from "./services/ImportMapService.js";
4
- import { useRemoteComponent as d } from "./hooks/useRemoteComponent.js";
5
- import { RemoteRenderer as M } from "./components/RemoteRenderer.js";
6
- import { RemoteLinks as i } from "./components/RemoteLinks.js";
7
- import { ImportMapScripts as I } from "./components/ImportMapScripts.js";
8
- export {
9
- I as ImportMapScripts,
10
- m as ModuleLoader,
11
- i as RemoteLinks,
12
- M as RemoteRenderer,
13
- r as fetchManifest,
14
- a as generateImportMap,
15
- n as generateImportMapJson,
16
- p as moduleLoader,
17
- d as useRemoteComponent
18
- };