@kaena1/ecomm-contained-utils 1.0.3 → 1.0.4
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
|
-
│
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
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`,
|
|
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-
|
|
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-
|
|
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.
|
|
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-
|
|
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
|
-
|
|
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
|
|
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
|
-
>
|
|
204
|
-
> -
|
|
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
|
-
|
|
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;
|
|
@@ -433,6 +426,65 @@ const manifest = await fetchManifest(
|
|
|
433
426
|
|
|
434
427
|
---
|
|
435
428
|
|
|
429
|
+
#### `getRemoteManifest(manifestUrl): Promise<RemoteManifest>`
|
|
430
|
+
|
|
431
|
+
Server-side function that fetches the remote component manifest. Encapsulates URL construction (cache-busting timestamp) and the fetch call.
|
|
432
|
+
|
|
433
|
+
**Parameters:**
|
|
434
|
+
|
|
435
|
+
- `manifestUrl`: `string` - Base URL to the manifest JSON file (without query params)
|
|
436
|
+
|
|
437
|
+
**Returns:** `Promise<RemoteManifest>`
|
|
438
|
+
|
|
439
|
+
**Usage:**
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
import { getRemoteManifest } from '@kaena1/ecomm-contained-utils/server';
|
|
443
|
+
|
|
444
|
+
const remoteManifest = await getRemoteManifest(process.env.MANIFEST_URL);
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
#### `getMintLayoutProps(NEXT_PUBLIC_SITE_URL, ECOMM_API_URL, ECOMM_API_STANDALONE_DEVICE_CREDS): Promise<MintLayoutProps>`
|
|
450
|
+
|
|
451
|
+
Server-side function that fetches MintLayout props from the ecomm API and maps them to the expected format.
|
|
452
|
+
|
|
453
|
+
**Parameters:**
|
|
454
|
+
|
|
455
|
+
- `NEXT_PUBLIC_SITE_URL`: `string` - The public site URL
|
|
456
|
+
- `ECOMM_API_URL`: `string` - The ecomm API base URL
|
|
457
|
+
- `ECOMM_API_STANDALONE_DEVICE_CREDS`: `string` - Credentials in `username|password` format
|
|
458
|
+
|
|
459
|
+
**Returns:** `Promise<MintLayoutProps>`
|
|
460
|
+
|
|
461
|
+
**Usage:**
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
import { getMintLayoutProps } from '@kaena1/ecomm-contained-utils/server';
|
|
465
|
+
|
|
466
|
+
const mintLayoutProps = await getMintLayoutProps(
|
|
467
|
+
process.env.NEXT_PUBLIC_SITE_URL,
|
|
468
|
+
process.env.ECOMM_API_URL,
|
|
469
|
+
process.env.ECOMM_API_STANDALONE_DEVICE_CREDS,
|
|
470
|
+
);
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
#### `mapMintLayoutResponseToProps(NEXT_PUBLIC_SITE_URL, data): MintLayoutProps`
|
|
476
|
+
|
|
477
|
+
Maps the raw API response to `MintLayoutProps` format. Used internally by `getMintLayoutProps`, but exported for custom usage.
|
|
478
|
+
|
|
479
|
+
**Parameters:**
|
|
480
|
+
|
|
481
|
+
- `NEXT_PUBLIC_SITE_URL`: `string` - The public site URL
|
|
482
|
+
- `data`: `MintLayoutPropsAPIResponse` - Raw API response
|
|
483
|
+
|
|
484
|
+
**Returns:** `MintLayoutProps`
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
436
488
|
## Build & Development
|
|
437
489
|
|
|
438
490
|
### Build the Package
|
|
@@ -470,7 +522,7 @@ npm run lint
|
|
|
470
522
|
|
|
471
523
|
```json
|
|
472
524
|
{
|
|
473
|
-
"version": "1.
|
|
525
|
+
"version": "1.0.3"
|
|
474
526
|
}
|
|
475
527
|
```
|
|
476
528
|
|
|
@@ -483,17 +535,17 @@ npm run lint
|
|
|
483
535
|
3. **Publish to npm:**
|
|
484
536
|
|
|
485
537
|
```bash
|
|
486
|
-
npm publish --tag f-poc-
|
|
538
|
+
npm publish --tag f-poc-EC-3570 --access public
|
|
487
539
|
```
|
|
488
540
|
|
|
489
541
|
4. **Install in consumer apps:**
|
|
490
542
|
|
|
491
543
|
```bash
|
|
492
544
|
# Specific version
|
|
493
|
-
npm install ecomm-contained-utils@1.
|
|
545
|
+
npm install @kaena1/ecomm-contained-utils@1.0.3
|
|
494
546
|
|
|
495
547
|
# Or use the tag for latest POC version
|
|
496
|
-
npm install ecomm-contained-utils@f-poc-
|
|
548
|
+
npm install @kaena1/ecomm-contained-utils@f-poc-EC-3570
|
|
497
549
|
```
|
|
498
550
|
|
|
499
551
|
### Enabling Automatic Publishing (Future)
|
|
@@ -546,12 +598,12 @@ docs: update README with usage examples
|
|
|
546
598
|
|
|
547
599
|
#### Release Rules
|
|
548
600
|
|
|
549
|
-
| Commit Type | Scope
|
|
550
|
-
| ----------- |
|
|
601
|
+
| Commit Type | Scope | Release Type |
|
|
602
|
+
| ----------- | ----------------------- | ------------- |
|
|
551
603
|
| `feat` | `ecomm-contained-utils` | Minor (1.x.0) |
|
|
552
604
|
| `fix` | `ecomm-contained-utils` | Patch (1.0.x) |
|
|
553
|
-
| `feat` | Any
|
|
554
|
-
| `fix` | Any
|
|
605
|
+
| `feat` | Any | Minor |
|
|
606
|
+
| `fix` | Any | Patch |
|
|
555
607
|
|
|
556
608
|
### POC Branch Strategy
|
|
557
609
|
|
|
@@ -568,8 +620,8 @@ For the POC, we use the branch pattern `f-poc-*` with a specific prerelease iden
|
|
|
568
620
|
|
|
569
621
|
This means:
|
|
570
622
|
|
|
571
|
-
- Branch `f-poc-EC-
|
|
572
|
-
- Branch `f-poc-live-update` → publishes as `1.
|
|
623
|
+
- Branch `f-poc-EC-3570` → publishes as `1.0.3-f-poc-EC-3570.1`
|
|
624
|
+
- Branch `f-poc-live-update` → publishes as `1.0.3-f-poc-live-update.1`
|
|
573
625
|
|
|
574
626
|
## How It Works
|
|
575
627
|
|
package/dist/server.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ 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 function getRemoteManifest(manifestUrl: string): Promise<RemoteManifest>;
|
|
30
|
+
|
|
29
31
|
declare interface ImportMapConfig {
|
|
30
32
|
reactVersion?: string;
|
|
31
33
|
reactDomVersion?: string;
|
package/dist/server.js
CHANGED
|
@@ -3,7 +3,8 @@ 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 {
|
|
6
|
+
import { getRemoteManifest as g } from "./lib/api/server/getRemoteManifest/getRemoteManifest.js";
|
|
7
|
+
import { mapMintLayoutResponseToProps as L } from "./lib/mappers/mapMintLayoutResponseToProps.js";
|
|
7
8
|
export {
|
|
8
9
|
f as ImportMapScripts,
|
|
9
10
|
s as RemoteLinks,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
p as generateImportMap,
|
|
12
13
|
m as generateImportMapJson,
|
|
13
14
|
M as getMintLayoutProps,
|
|
14
|
-
g as
|
|
15
|
+
g as getRemoteManifest,
|
|
16
|
+
L as mapMintLayoutResponseToProps
|
|
15
17
|
};
|