@kaena1/ecomm-contained-utils 1.0.4 → 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 +12 -38
- package/dist/lib/api/server/getRemoteManifest/getRemoteManifest.js +11 -5
- package/dist/lib/mappers/mapManifestUrl.js +21 -0
- package/dist/server.d.ts +2 -48
- package/dist/server.js +8 -15
- package/dist/types.d.ts +5 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -404,44 +404,31 @@ return <Component {...props} />;
|
|
|
404
404
|
|
|
405
405
|
---
|
|
406
406
|
|
|
407
|
-
###
|
|
407
|
+
### Data fetching (server-side)
|
|
408
408
|
|
|
409
|
-
#### `
|
|
410
|
-
|
|
411
|
-
Fetches and validates a remote component manifest.
|
|
412
|
-
|
|
413
|
-
**Parameters:**
|
|
414
|
-
|
|
415
|
-
- `manifestUrl`: `string` - URL to the manifest JSON file
|
|
416
|
-
|
|
417
|
-
**Returns:** `Promise<RemoteManifest>`
|
|
418
|
-
|
|
419
|
-
**Usage:**
|
|
420
|
-
|
|
421
|
-
```typescript
|
|
422
|
-
const manifest = await fetchManifest(
|
|
423
|
-
'https://assets-qa.mintmobile.com/.../manifest.json',
|
|
424
|
-
);
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
---
|
|
428
|
-
|
|
429
|
-
#### `getRemoteManifest(manifestUrl): Promise<RemoteManifest>`
|
|
409
|
+
#### `getRemoteManifest(environment, cookieStore): Promise<RemoteManifest>`
|
|
430
410
|
|
|
431
411
|
Server-side function that fetches the remote component manifest. Encapsulates URL construction (cache-busting timestamp) and the fetch call.
|
|
432
412
|
|
|
433
413
|
**Parameters:**
|
|
434
414
|
|
|
435
|
-
- `
|
|
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.
|
|
436
417
|
|
|
437
418
|
**Returns:** `Promise<RemoteManifest>`
|
|
438
419
|
|
|
439
|
-
**Usage:**
|
|
420
|
+
**Usage (NextJS):**
|
|
440
421
|
|
|
441
422
|
```typescript
|
|
442
423
|
import { getRemoteManifest } from '@kaena1/ecomm-contained-utils/server';
|
|
424
|
+
import { cookies } from 'next/headers';
|
|
443
425
|
|
|
444
|
-
const
|
|
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
|
+
);
|
|
445
432
|
```
|
|
446
433
|
|
|
447
434
|
---
|
|
@@ -472,19 +459,6 @@ const mintLayoutProps = await getMintLayoutProps(
|
|
|
472
459
|
|
|
473
460
|
---
|
|
474
461
|
|
|
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
|
-
|
|
488
462
|
## Build & Development
|
|
489
463
|
|
|
490
464
|
### Build the Package
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
import { fetchManifest as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
}
|
|
6
12
|
}
|
|
7
13
|
export {
|
|
8
|
-
|
|
14
|
+
f as getRemoteManifest
|
|
9
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,31 +12,14 @@ declare interface CountdownbannerProps {
|
|
|
12
12
|
message: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
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
|
-
export declare function getRemoteManifest(
|
|
30
|
-
|
|
31
|
-
declare interface ImportMapConfig {
|
|
32
|
-
reactVersion?: string;
|
|
33
|
-
reactDomVersion?: string;
|
|
34
|
-
}
|
|
19
|
+
export declare function getRemoteManifest(environment: Environment, cookieBranch: string | undefined): Promise<RemoteManifest>;
|
|
35
20
|
|
|
36
21
|
export declare const ImportMapScripts: () => JSX.Element;
|
|
37
22
|
|
|
38
|
-
export declare const mapMintLayoutResponseToProps: (NEXT_PUBLIC_SITE_URL: string, data: MintLayoutPropsAPIResponse) => MintLayoutProps;
|
|
39
|
-
|
|
40
23
|
declare interface MintFooterProps {
|
|
41
24
|
footerNav: WP_REST_API_Nav_Menu_Items;
|
|
42
25
|
subfooterNav: WP_REST_API_Nav_Menu_Items;
|
|
@@ -60,17 +43,6 @@ declare interface MintLayoutProps {
|
|
|
60
43
|
slimBannerProps?: Partial<SlimbannerProps>;
|
|
61
44
|
}
|
|
62
45
|
|
|
63
|
-
declare interface MintLayoutPropsAPIResponse {
|
|
64
|
-
theme: WP_REST_API_Theme;
|
|
65
|
-
widgets: WP_REST_API_Widget[];
|
|
66
|
-
menuItems: {
|
|
67
|
-
'primary-navigation-left': WP_REST_API_Nav_Menu_Items;
|
|
68
|
-
'primary-navigation-right': WP_REST_API_Nav_Menu_Items;
|
|
69
|
-
'footer-menu': WP_REST_API_Nav_Menu_Items;
|
|
70
|
-
'footer-legal-pages': WP_REST_API_Nav_Menu_Items;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
46
|
export declare const RemoteLinks: ({ manifest }: RemoteLinksProps) => JSX.Element;
|
|
75
47
|
|
|
76
48
|
declare interface RemoteLinksProps {
|
|
@@ -117,22 +89,4 @@ declare interface WP_REST_API_Nav_Menu_Item {
|
|
|
117
89
|
|
|
118
90
|
declare type WP_REST_API_Nav_Menu_Items = WP_REST_API_Nav_Menu_Item[];
|
|
119
91
|
|
|
120
|
-
declare interface WP_REST_API_Theme {
|
|
121
|
-
countdown: {
|
|
122
|
-
is_enabled: boolean;
|
|
123
|
-
start_datetime: string;
|
|
124
|
-
start_timezone: string;
|
|
125
|
-
end_datetime: string;
|
|
126
|
-
end_timezone: string;
|
|
127
|
-
start_datetime_utc: string;
|
|
128
|
-
end_datetime_utc: string;
|
|
129
|
-
is_server_now_between: boolean;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
declare interface WP_REST_API_Widget {
|
|
134
|
-
name: string;
|
|
135
|
-
data: WP_REST_API_Content;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
92
|
export { }
|
package/dist/server.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getMintLayoutProps as M } from "./lib/api/server/getMintLayoutProps/getMintLayoutProps.js";
|
|
6
|
-
import { getRemoteManifest as g } from "./lib/api/server/getRemoteManifest/getRemoteManifest.js";
|
|
7
|
-
import { mapMintLayoutResponseToProps as L } 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";
|
|
8
5
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
m as generateImportMapJson,
|
|
14
|
-
M as getMintLayoutProps,
|
|
15
|
-
g as getRemoteManifest,
|
|
16
|
-
L as mapMintLayoutResponseToProps
|
|
6
|
+
e as ImportMapScripts,
|
|
7
|
+
p as RemoteLinks,
|
|
8
|
+
f as getMintLayoutProps,
|
|
9
|
+
s as getRemoteManifest
|
|
17
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
|
-
|
|
81
|
+
declare interface WP_REST_API_Content {
|
|
91
82
|
rendered: string;
|
|
92
83
|
raw: string;
|
|
93
84
|
}
|
|
94
85
|
|
|
95
|
-
|
|
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
|
-
|
|
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 { }
|