@kaena1/ecomm-contained-utils 1.0.3 → 1.0.5

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 CHANGED
@@ -25,14 +25,19 @@ packages/ecomm-contained-utils/
25
25
  │ │ └── RemoteRenderer.tsx # Renders remote components ('use client')
26
26
  │ ├── hooks/ # React hooks
27
27
  │ │ └── useRemoteComponent.ts # Hook for loading remote components ('use client')
28
+ │ ├── lib/ # Business logic
29
+ │ │ ├── api/server/ # Server-side API functions
30
+ │ │ │ └── getMintLayoutProps/ # Fetches MintLayout props from ecomm API
31
+ │ │ └── mappers/ # Data mappers
32
+ │ │ └── mapMintLayoutResponseToProps.ts
28
33
  │ ├── services/ # Core services
29
34
  │ │ ├── fetchManifest.ts # Fetches component manifests
30
35
  │ │ ├── ImportMapService.ts # Generates import map JSON
31
36
  │ │ └── moduleLoader.ts # ES module loader service
32
37
  │ ├── types/ # TypeScript definitions
33
- │ ├── index.ts # Main entry point (exports everything)
34
38
  │ ├── server.ts # Server-safe exports for App Router
35
- └── client.ts # Client-only exports for App Router
39
+ ├── client.ts # Client-only exports for App Router
40
+ │ └── types.ts # Type-only exports entry point
36
41
  ├── dist/ # Built files (generated)
37
42
  ├── vite.config.ts # Build configuration
38
43
  ├── package.json
@@ -44,16 +49,18 @@ packages/ecomm-contained-utils/
44
49
 
45
50
  The package provides three entry points for different use cases:
46
51
 
47
- | Entry Point | Import Path | Use Case |
48
- |-------------|-------------|----------|
49
- | Main | `ecomm-contained-utils` | Everything (Pages Router, or when you need all exports) |
50
- | Server | `ecomm-contained-utils/server` | Server Components (App Router RSC) |
51
- | Client | `ecomm-contained-utils/client` | Client Components (App Router) |
52
+ | Entry Point | Import Path | Use Case |
53
+ | ----------- | -------------------------------------- | ---------------------------------------------------- |
54
+ | Server | `@kaena1/ecomm-contained-utils/server` | Server Components (App Router RSC, Pages Router SSR) |
55
+ | Client | `@kaena1/ecomm-contained-utils/client` | Client Components (App Router, Pages Router CSR) |
56
+ | Types | `@kaena1/ecomm-contained-utils/types` | Type-only imports |
52
57
 
53
- **Server exports:** `fetchManifest`, `ImportMapScripts`, `RemoteLinks`, `generateImportMap`, `generateImportMapJson`, all types
58
+ **Server exports:** `fetchManifest`, `getRemoteManifest`, `ImportMapScripts`, `RemoteLinks`, `generateImportMap`, `generateImportMapJson`, `getMintLayoutProps`, `mapMintLayoutResponseToProps`
54
59
 
55
60
  **Client exports:** `RemoteRenderer`, `useRemoteComponent`, `moduleLoader`, `ModuleLoader`
56
61
 
62
+ **Types exports:** `ComponentManifest`, `RemoteManifest`, `MintLayoutProps`, `MintLayoutPropsAPIResponse`, WP REST API types
63
+
57
64
  ## Installation
58
65
 
59
66
  ### In Consumer Applications (e.g., mm-mf-features)
@@ -63,17 +70,17 @@ The package provides three entry points for different use cases:
63
70
  Always get the latest version from the POC branch:
64
71
 
65
72
  ```bash
66
- npm install ecomm-contained-utils@f-poc-EC-3301
73
+ npm install @kaena1/ecomm-contained-utils@f-poc-EC-3570
67
74
  ```
68
75
 
69
- This installs the latest version tagged with `f-poc-EC-3301`. You don't need to track specific version numbers.
76
+ This installs the latest version tagged with `f-poc-EC-3570`. You don't need to track specific version numbers.
70
77
 
71
78
  #### Option 2: Install Specific Version
72
79
 
73
80
  If you need a specific version:
74
81
 
75
82
  ```bash
76
- npm install ecomm-contained-utils@1.25.0-f-poc-EC-3301.5
83
+ npm install @kaena1/ecomm-contained-utils@1.0.3
77
84
  ```
78
85
 
79
86
  #### Updating to Latest
@@ -82,10 +89,10 @@ To update to the latest POC version:
82
89
 
83
90
  ```bash
84
91
  # Update and save to package.json
85
- npm install ecomm-contained-utils@f-poc-EC-3301 --save
92
+ npm install @kaena1/ecomm-contained-utils@f-poc-EC-3570 --save
86
93
 
87
94
  # Or use npm update (if version is already in package.json with the tag)
88
- npm update ecomm-contained-utils
95
+ npm update @kaena1/ecomm-contained-utils
89
96
  ```
90
97
 
91
98
  #### For Local Development
@@ -99,10 +106,10 @@ Due to React's requirement of a single instance, `npm link` causes "Invalid hook
99
106
  cd packages/ecomm-contained-utils
100
107
  npm run build
101
108
  npm pack
102
- # This generates: ecomm-contained-utils-X.X.X.tgz
109
+ # This generates: kaena1-ecomm-contained-utils-X.X.X.tgz
103
110
 
104
111
  # In the consumer application (mm-mf-features)
105
- npm install /absolute/path/to/ecomm-contained-utils-X.X.X.tgz
112
+ npm install /absolute/path/to/kaena1-ecomm-contained-utils-X.X.X.tgz
106
113
  ```
107
114
 
108
115
  ## Usage
@@ -117,7 +124,7 @@ The setup differs slightly between Next.js Pages Router and App Router.
117
124
 
118
125
  ```typescript
119
126
  import { Html, Head, Main, NextScript } from 'next/document';
120
- import { ImportMapScripts } from 'ecomm-contained-utils';
127
+ import { ImportMapScripts } from '@kaena1/ecomm-contained-utils/server';
121
128
 
122
129
  export default function Document() {
123
130
  return (
@@ -139,18 +146,13 @@ export default function Document() {
139
146
 
140
147
  ```typescript
141
148
  import type { AppProps, AppContext } from 'next/app';
142
- import {
143
- RemoteRenderer,
144
- RemoteLinks,
145
- fetchManifest,
146
- } from 'ecomm-contained-utils';
149
+ import { RemoteLinks, getRemoteManifest } from '@kaena1/ecomm-contained-utils/server';
150
+ import { RemoteRenderer } from '@kaena1/ecomm-contained-utils/client';
147
151
 
148
152
  App.getInitialProps = async (ctx: AppContext) => {
149
- const manifestUrl = `https://assets-qa.mintmobile.com/contained-components/manifest-poc/f-poc-live-update/manifest.json?_ts=${Date.now()}`;
150
-
151
153
  let remoteManifest;
152
154
  try {
153
- remoteManifest = await fetchManifest(manifestUrl);
155
+ remoteManifest = await getRemoteManifest(process.env.MANIFEST_URL);
154
156
  } catch (e) {
155
157
  console.error('Failed to fetch manifest:', e);
156
158
  remoteManifest = null;
@@ -200,8 +202,10 @@ export default function App({ Component, pageProps }: AppProps) {
200
202
  #### App Router Setup
201
203
 
202
204
  > **Note:** App Router is fully supported. The package provides separate entry points for server and client code:
203
- > - `ecomm-contained-utils/server` - Server-safe exports (fetchManifest, ImportMapScripts, RemoteLinks, types)
204
- > - `ecomm-contained-utils/client` - Client-only exports (RemoteRenderer, useRemoteComponent, moduleLoader)
205
+ >
206
+ > - `@kaena1/ecomm-contained-utils/server` - Server-safe exports (fetchManifest, getRemoteManifest, ImportMapScripts, RemoteLinks, getMintLayoutProps, mapMintLayoutResponseToProps)
207
+ > - `@kaena1/ecomm-contained-utils/client` - Client-only exports (RemoteRenderer, useRemoteComponent, moduleLoader)
208
+ > - `@kaena1/ecomm-contained-utils/types` - Type-only exports
205
209
 
206
210
  ##### Add Import Map Scripts to `app/layout.tsx`
207
211
 
@@ -210,29 +214,18 @@ export default function App({ Component, pageProps }: AppProps) {
210
214
  import {
211
215
  ImportMapScripts,
212
216
  RemoteLinks,
213
- fetchManifest
214
- } from 'ecomm-contained-utils/server';
217
+ getRemoteManifest,
218
+ } from '@kaena1/ecomm-contained-utils/server';
215
219
 
216
220
  // Use /client for client components (in separate 'use client' files)
217
- // import { RemoteRenderer } from 'ecomm-contained-utils/client';
218
-
219
- // Fetch manifest at build time
220
- async function getRemoteManifest() {
221
- try {
222
- const manifestUrl = `https://assets-qa.mintmobile.com/contained-components/manifest-poc/f-poc-live-update/manifest.json?_ts=${Date.now()}`;
223
- return await fetchManifest(manifestUrl);
224
- } catch (e) {
225
- console.error('Failed to fetch manifest:', e);
226
- return null;
227
- }
228
- }
221
+ // import { RemoteRenderer } from '@kaena1/ecomm-contained-utils/client';
229
222
 
230
223
  export default async function RootLayout({
231
224
  children,
232
225
  }: {
233
226
  children: React.ReactNode;
234
227
  }) {
235
- const remoteManifest = await getRemoteManifest();
228
+ const remoteManifest = await getRemoteManifest(process.env.MANIFEST_URL);
236
229
  const layoutManifest = remoteManifest?.components?.MintLayout;
237
230
 
238
231
  return (
@@ -268,7 +261,7 @@ export default async function RootLayout({
268
261
  ### 2. Using Remote Components in Pages
269
262
 
270
263
  ```typescript
271
- import { RemoteRenderer } from 'ecomm-contained-utils';
264
+ import { RemoteRenderer } from '@kaena1/ecomm-contained-utils/client';
272
265
 
273
266
  export default function MyPage({ remoteManifest }) {
274
267
  const pocComponentManifest = remoteManifest?.components?.PocComponent;
@@ -411,23 +404,56 @@ return <Component {...props} />;
411
404
 
412
405
  ---
413
406
 
414
- ### Services
407
+ ### Data fetching (server-side)
415
408
 
416
- #### `fetchManifest(manifestUrl: string): Promise<RemoteManifest>`
409
+ #### `getRemoteManifest(environment, cookieStore): Promise<RemoteManifest>`
417
410
 
418
- Fetches and validates a remote component manifest.
411
+ Server-side function that fetches the remote component manifest. Encapsulates URL construction (cache-busting timestamp) and the fetch call.
419
412
 
420
413
  **Parameters:**
421
414
 
422
- - `manifestUrl`: `string` - URL to the manifest JSON file
415
+ - `environment`: `Environment` - Environment variable value set in the consumer app's repository. Can be `production` or `develop`. Defaults to `production`.
416
+ - `cookieBranch`: `string | undefined` - f-branch can be set as a cookie with the name `cont-comp`. If it's not set or none is provided, it will default to `f-poc-live-update` for develop, and `master` for production.
423
417
 
424
418
  **Returns:** `Promise<RemoteManifest>`
425
419
 
420
+ **Usage (NextJS):**
421
+
422
+ ```typescript
423
+ import { getRemoteManifest } from '@kaena1/ecomm-contained-utils/server';
424
+ import { cookies } from 'next/headers';
425
+
426
+ const cookieStore = await cookies();
427
+ const branchCookie = cookieStore.get('cont-comp')?.value;
428
+ const remoteManifest = await getRemoteManifest(
429
+ process.env.NEXT_PUBLIC_ENVIRONMENT,
430
+ branchCookie,
431
+ );
432
+ ```
433
+
434
+ ---
435
+
436
+ #### `getMintLayoutProps(NEXT_PUBLIC_SITE_URL, ECOMM_API_URL, ECOMM_API_STANDALONE_DEVICE_CREDS): Promise<MintLayoutProps>`
437
+
438
+ Server-side function that fetches MintLayout props from the ecomm API and maps them to the expected format.
439
+
440
+ **Parameters:**
441
+
442
+ - `NEXT_PUBLIC_SITE_URL`: `string` - The public site URL
443
+ - `ECOMM_API_URL`: `string` - The ecomm API base URL
444
+ - `ECOMM_API_STANDALONE_DEVICE_CREDS`: `string` - Credentials in `username|password` format
445
+
446
+ **Returns:** `Promise<MintLayoutProps>`
447
+
426
448
  **Usage:**
427
449
 
428
450
  ```typescript
429
- const manifest = await fetchManifest(
430
- 'https://assets-qa.mintmobile.com/.../manifest.json',
451
+ import { getMintLayoutProps } from '@kaena1/ecomm-contained-utils/server';
452
+
453
+ const mintLayoutProps = await getMintLayoutProps(
454
+ process.env.NEXT_PUBLIC_SITE_URL,
455
+ process.env.ECOMM_API_URL,
456
+ process.env.ECOMM_API_STANDALONE_DEVICE_CREDS,
431
457
  );
432
458
  ```
433
459
 
@@ -470,7 +496,7 @@ npm run lint
470
496
 
471
497
  ```json
472
498
  {
473
- "version": "1.25.0-f-poc-EC-3301.5"
499
+ "version": "1.0.3"
474
500
  }
475
501
  ```
476
502
 
@@ -483,17 +509,17 @@ npm run lint
483
509
  3. **Publish to npm:**
484
510
 
485
511
  ```bash
486
- npm publish --tag f-poc-live-update
512
+ npm publish --tag f-poc-EC-3570 --access public
487
513
  ```
488
514
 
489
515
  4. **Install in consumer apps:**
490
516
 
491
517
  ```bash
492
518
  # Specific version
493
- npm install ecomm-contained-utils@1.25.0-f-poc-EC-3301.5
519
+ npm install @kaena1/ecomm-contained-utils@1.0.3
494
520
 
495
521
  # Or use the tag for latest POC version
496
- npm install ecomm-contained-utils@f-poc-live-update
522
+ npm install @kaena1/ecomm-contained-utils@f-poc-EC-3570
497
523
  ```
498
524
 
499
525
  ### Enabling Automatic Publishing (Future)
@@ -546,12 +572,12 @@ docs: update README with usage examples
546
572
 
547
573
  #### Release Rules
548
574
 
549
- | Commit Type | Scope | Release Type |
550
- | ----------- | -------------- | ------------- |
575
+ | Commit Type | Scope | Release Type |
576
+ | ----------- | ----------------------- | ------------- |
551
577
  | `feat` | `ecomm-contained-utils` | Minor (1.x.0) |
552
578
  | `fix` | `ecomm-contained-utils` | Patch (1.0.x) |
553
- | `feat` | Any | Minor |
554
- | `fix` | Any | Patch |
579
+ | `feat` | Any | Minor |
580
+ | `fix` | Any | Patch |
555
581
 
556
582
  ### POC Branch Strategy
557
583
 
@@ -568,8 +594,8 @@ For the POC, we use the branch pattern `f-poc-*` with a specific prerelease iden
568
594
 
569
595
  This means:
570
596
 
571
- - Branch `f-poc-EC-3301` → publishes as `1.25.0-f-poc-EC-3301.1`
572
- - Branch `f-poc-live-update` → publishes as `1.25.0-f-poc-live-update.1`
597
+ - Branch `f-poc-EC-3570` → publishes as `1.0.3-f-poc-EC-3570.1`
598
+ - Branch `f-poc-live-update` → publishes as `1.0.3-f-poc-live-update.1`
573
599
 
574
600
  ## How It Works
575
601
 
@@ -0,0 +1,15 @@
1
+ "use server";
2
+ import { fetchManifest as t } from "../../../../services/fetchManifest.js";
3
+ import "react";
4
+ import "react-dom";
5
+ import { mapManifestUrl as r } from "../../../mappers/mapManifestUrl.js";
6
+ async function f(e, i) {
7
+ try {
8
+ return await t(r(e, i));
9
+ } catch {
10
+ return await t(r("production", void 0));
11
+ }
12
+ }
13
+ export {
14
+ f as getRemoteManifest
15
+ };
@@ -0,0 +1,21 @@
1
+ const n = "manifest.json", c = "https://assets.mintmobile.com", a = "https://assets-qa.mintmobile.com", p = (t, s) => {
2
+ const e = r(t), o = m(t, s);
3
+ return `${e}/contained-components/manifest-poc/${o}/${n}?_ts=${Date.now()}`;
4
+ }, r = (t) => {
5
+ switch (t) {
6
+ case "production":
7
+ return c;
8
+ case "develop":
9
+ return a;
10
+ }
11
+ }, m = (t, s) => {
12
+ switch (t) {
13
+ case "production":
14
+ return s || "master";
15
+ case "develop":
16
+ return s || "f-poc-live-update";
17
+ }
18
+ };
19
+ export {
20
+ p as mapManifestUrl
21
+ };
package/dist/server.d.ts CHANGED
@@ -12,29 +12,14 @@ declare interface CountdownbannerProps {
12
12
  message: string;
13
13
  }
14
14
 
15
- export declare function fetchManifest(manifestUrl: string): Promise<RemoteManifest>;
16
-
17
- /**
18
- * Generate complete import map object for remote components
19
- *
20
- * @param config - Optional configuration to override default settings
21
- * @returns Import map object ready for browser consumption
22
- */
23
- export declare const generateImportMap: (config?: ImportMapConfig) => object;
24
-
25
- export declare const generateImportMapJson: (config?: ImportMapConfig) => string;
15
+ declare type Environment = 'develop' | 'production';
26
16
 
27
17
  export declare function getMintLayoutProps(NEXT_PUBLIC_SITE_URL: string, ECOMM_API_URL: string, ECOMM_API_STANDALONE_DEVICE_CREDS: string): Promise<MintLayoutProps>;
28
18
 
29
- declare interface ImportMapConfig {
30
- reactVersion?: string;
31
- reactDomVersion?: string;
32
- }
19
+ export declare function getRemoteManifest(environment: Environment, cookieBranch: string | undefined): Promise<RemoteManifest>;
33
20
 
34
21
  export declare const ImportMapScripts: () => JSX.Element;
35
22
 
36
- export declare const mapMintLayoutResponseToProps: (NEXT_PUBLIC_SITE_URL: string, data: MintLayoutPropsAPIResponse) => MintLayoutProps;
37
-
38
23
  declare interface MintFooterProps {
39
24
  footerNav: WP_REST_API_Nav_Menu_Items;
40
25
  subfooterNav: WP_REST_API_Nav_Menu_Items;
@@ -58,17 +43,6 @@ declare interface MintLayoutProps {
58
43
  slimBannerProps?: Partial<SlimbannerProps>;
59
44
  }
60
45
 
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
- }
71
-
72
46
  export declare const RemoteLinks: ({ manifest }: RemoteLinksProps) => JSX.Element;
73
47
 
74
48
  declare interface RemoteLinksProps {
@@ -115,22 +89,4 @@ declare interface WP_REST_API_Nav_Menu_Item {
115
89
 
116
90
  declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
117
91
 
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
-
136
92
  export { }
package/dist/server.js CHANGED
@@ -1,15 +1,10 @@
1
- import { fetchManifest as t } from "./services/fetchManifest.js";
2
- import { generateImportMap as p, generateImportMapJson as m } from "./services/ImportMapService.js";
3
- import { ImportMapScripts as f } from "./components/ImportMapScripts.js";
4
- import { RemoteLinks as s } from "./components/RemoteLinks.js";
5
- import { getMintLayoutProps as M } from "./lib/api/server/getMintLayoutProps/getMintLayoutProps.js";
6
- import { mapMintLayoutResponseToProps as g } from "./lib/mappers/mapMintLayoutResponseToProps.js";
1
+ import { ImportMapScripts as e } from "./components/ImportMapScripts.js";
2
+ import { RemoteLinks as p } from "./components/RemoteLinks.js";
3
+ import { getMintLayoutProps as f } from "./lib/api/server/getMintLayoutProps/getMintLayoutProps.js";
4
+ import { getRemoteManifest as s } from "./lib/api/server/getRemoteManifest/getRemoteManifest.js";
7
5
  export {
8
- f as ImportMapScripts,
9
- s as RemoteLinks,
10
- t as fetchManifest,
11
- p as generateImportMap,
12
- m as generateImportMapJson,
13
- M as getMintLayoutProps,
14
- g as mapMintLayoutResponseToProps
6
+ e as ImportMapScripts,
7
+ p as RemoteLinks,
8
+ f as getMintLayoutProps,
9
+ s as getRemoteManifest
15
10
  };
package/dist/types.d.ts CHANGED
@@ -10,6 +10,8 @@ declare interface CountdownbannerProps {
10
10
  message: string;
11
11
  }
12
12
 
13
+ export declare type Environment = 'develop' | 'production';
14
+
13
15
  export declare interface ImportMapConfig {
14
16
  reactVersion?: string;
15
17
  reactDomVersion?: string;
@@ -38,17 +40,6 @@ export declare interface MintLayoutProps {
38
40
  slimBannerProps?: Partial<SlimbannerProps>;
39
41
  }
40
42
 
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
43
  export declare interface ModuleLoadOptions {
53
44
  bundleUrl: string;
54
45
  componentName: string;
@@ -87,12 +78,12 @@ export declare interface UseRemoteComponentReturn extends RemoteComponentState {
87
78
  clearError: () => void;
88
79
  }
89
80
 
90
- export declare interface WP_REST_API_Content {
81
+ declare interface WP_REST_API_Content {
91
82
  rendered: string;
92
83
  raw: string;
93
84
  }
94
85
 
95
- export declare interface WP_REST_API_Nav_Menu_Item {
86
+ declare interface WP_REST_API_Nav_Menu_Item {
96
87
  id: number;
97
88
  title: WP_REST_API_Content;
98
89
  status: string;
@@ -114,24 +105,6 @@ export declare interface WP_REST_API_Nav_Menu_Item {
114
105
  _links: Record<string, []>;
115
106
  }
116
107
 
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
- }
108
+ declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
136
109
 
137
110
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaena1/ecomm-contained-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Shared utilities for loading remote React components in Mint Mobile microfrontends",
5
5
  "type": "module",
6
6
  "exports": {