@financial-times/custom-code-component 2.0.1-alpha.8 → 2.0.1-beta.1
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/dist/{webcomponent/src/index.d.ts → CustomCodeComponent.d.ts} +3 -1
- package/dist/{index.js → CustomCodeComponent.js} +144 -158
- package/dist/CustomCodeComponent.js.map +1 -0
- package/package.json +5 -5
- package/src/custom-code-component.ts +86 -75
- package/src/environment.ts +31 -40
- package/src/errors.ts +1 -1
- package/src/path.ts +19 -23
- package/dist/webcomponent/src/custom-code-component.d.ts +0 -55
- package/dist/webcomponent/src/environment.d.ts +0 -15
- package/dist/webcomponent/src/errors.d.ts +0 -27
- package/dist/webcomponent/src/events.d.ts +0 -10
- package/dist/webcomponent/src/get-trace.d.ts +0 -8
- package/dist/webcomponent/src/logger.d.ts +0 -20
- package/dist/webcomponent/src/path.d.ts +0 -23
- package/dist/webcomponent/src/tracking.d.ts +0 -32
- package/dist/webcomponent/src/util.d.ts +0 -33
- package/dist/webcomponent/test/environment.test.d.ts +0 -1
- package/dist/webcomponent/test/error-handling.test.d.ts +0 -8
- package/dist/webcomponent/test/example.d.ts +0 -11
- package/dist/webcomponent/test/generate-readable-stream.d.ts +0 -8
- package/dist/webcomponent/test/path.test.d.ts +0 -5
- package/dist/webcomponent/test/ssr.test.d.ts +0 -4
- package/dist/webcomponent/test/utils.test.d.ts +0 -1
- package/dist/webcomponent/vite.config.d.ts +0 -2
- package/dist/webcomponent/vitest.config.d.ts +0 -2
package/src/path.ts
CHANGED
|
@@ -3,41 +3,37 @@ import { CCCError } from "./errors";
|
|
|
3
3
|
export type ComponentPathType = {
|
|
4
4
|
org: string;
|
|
5
5
|
repo: string;
|
|
6
|
-
|
|
6
|
+
name: string;
|
|
7
7
|
versionRange: string;
|
|
8
8
|
};
|
|
9
9
|
export class ComponentPath {
|
|
10
|
-
org: string;
|
|
11
|
-
repo: string;
|
|
12
|
-
|
|
10
|
+
org: string = "local";
|
|
11
|
+
repo: string = "dev";
|
|
12
|
+
name: string;
|
|
13
13
|
versionRange: string;
|
|
14
14
|
|
|
15
15
|
constructor(path: ComponentPathType | string) {
|
|
16
|
-
const { org, repo,
|
|
17
|
-
path
|
|
18
|
-
)
|
|
16
|
+
const { org, repo, name, versionRange } = isValidComponentPathObject(path)
|
|
19
17
|
? path
|
|
20
18
|
: ComponentPath.fromString(path);
|
|
21
|
-
this.org = org;
|
|
22
|
-
this.repo = repo;
|
|
23
|
-
this.
|
|
19
|
+
if (org) this.org = org;
|
|
20
|
+
if (repo) this.repo = repo;
|
|
21
|
+
this.name = name;
|
|
24
22
|
this.versionRange = versionRange;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
set path(path: ComponentPathType | string) {
|
|
28
|
-
const { org, repo,
|
|
29
|
-
path
|
|
30
|
-
)
|
|
26
|
+
const { org, repo, name, versionRange } = isValidComponentPathObject(path)
|
|
31
27
|
? path
|
|
32
28
|
: ComponentPath.fromString(path);
|
|
33
29
|
this.org = org;
|
|
34
30
|
this.repo = repo;
|
|
35
|
-
this.
|
|
31
|
+
this.name = name;
|
|
36
32
|
this.versionRange = versionRange;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
get path(): string {
|
|
40
|
-
return `${this.org}/${this.repo}@${this.versionRange}/${this.
|
|
36
|
+
return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
toString(): string {
|
|
@@ -47,6 +43,11 @@ export class ComponentPath {
|
|
|
47
43
|
static fromString(path: string | null, v?: string | null): ComponentPath {
|
|
48
44
|
if (!path) throw new CCCError("No path specified");
|
|
49
45
|
|
|
46
|
+
const [name, repo, org] = path
|
|
47
|
+
.replace(/@[^\/]+/, "")
|
|
48
|
+
.split("/")
|
|
49
|
+
.reverse();
|
|
50
|
+
|
|
50
51
|
const versionRange =
|
|
51
52
|
v ??
|
|
52
53
|
path
|
|
@@ -55,14 +56,9 @@ export class ComponentPath {
|
|
|
55
56
|
.replace("@", "") ??
|
|
56
57
|
"unknown";
|
|
57
58
|
|
|
58
|
-
if (!versionRange) throw new CCCError("No version specified");
|
|
59
|
-
|
|
60
|
-
const [component, repo, org] = path
|
|
61
|
-
.replace(/@[^\/]+/, "")
|
|
62
|
-
.split("/")
|
|
63
|
-
.reverse();
|
|
59
|
+
if (repo && !versionRange) throw new CCCError("No version specified");
|
|
64
60
|
|
|
65
|
-
return new ComponentPath({ org, repo,
|
|
61
|
+
return new ComponentPath({ org, repo, name, versionRange });
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
|
|
@@ -76,7 +72,7 @@ export function isValidComponentPathObject(
|
|
|
76
72
|
value: unknown
|
|
77
73
|
): value is ComponentPathType {
|
|
78
74
|
if (typeof value === "object" && value !== null) {
|
|
79
|
-
return "org" in value && "repo" in value && "
|
|
75
|
+
return "org" in value && "repo" in value && "name" in value;
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
return false;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
* Main component definition for custom-code-component
|
|
4
|
-
*/
|
|
5
|
-
import type { ContentTree } from "@financial-times/content-tree";
|
|
6
|
-
import { BaseRenderer } from "../../ccc-sdk/src/renderers/BaseRenderer";
|
|
7
|
-
import Tracking from "./tracking";
|
|
8
|
-
import { Logger } from "./logger";
|
|
9
|
-
import { ComponentPath } from "./path";
|
|
10
|
-
export declare class FTCustomCodeComponent extends HTMLElement {
|
|
11
|
-
app?: typeof BaseRenderer.prototype.render;
|
|
12
|
-
mode: "closed" | "open";
|
|
13
|
-
RESERVED_ATTRS: Set<string>;
|
|
14
|
-
source?: string;
|
|
15
|
-
tracking?: Tracking;
|
|
16
|
-
lightRoot: ChildNode[];
|
|
17
|
-
component: ComponentPath;
|
|
18
|
-
log: Logger;
|
|
19
|
-
constructor();
|
|
20
|
-
connectedCallback(): Promise<void>;
|
|
21
|
-
emitError(error: Error): void;
|
|
22
|
-
disconnectedCallback(): void;
|
|
23
|
-
channel: MessageChannel;
|
|
24
|
-
onmessage(): void;
|
|
25
|
-
onunmount(root?: any): void;
|
|
26
|
-
onready(app: Promise<void>): Promise<void>;
|
|
27
|
-
postMessage(event: any): void;
|
|
28
|
-
mount(prerendered?: ShadowRoot | null): Promise<void>;
|
|
29
|
-
unmount(e: Error): void;
|
|
30
|
-
load(): Promise<(shadowRoot: ShadowRoot, attrs: any, ssr?: boolean) => {
|
|
31
|
-
unmount: (root: any) => void;
|
|
32
|
-
onmessage: {
|
|
33
|
-
(...data: any[]): void;
|
|
34
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
-
};
|
|
36
|
-
ready: Promise<void>;
|
|
37
|
-
}>;
|
|
38
|
-
initTracking: () => Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
export interface CustomCodeComponent extends ContentTree.Node {
|
|
41
|
-
type: "CustomCodeComponent";
|
|
42
|
-
path: string;
|
|
43
|
-
versionRange: string;
|
|
44
|
-
altText: string;
|
|
45
|
-
lastModified: string;
|
|
46
|
-
fallbackImage?: ContentTree.Image;
|
|
47
|
-
displayFallbackText: boolean;
|
|
48
|
-
layout: "in-line" | "mid-grid" | "full-grid" | "full-bleed";
|
|
49
|
-
attributes: {
|
|
50
|
-
[key: string]: string | boolean | undefined;
|
|
51
|
-
} | {
|
|
52
|
-
children?: CustomCodeComponent | Array<CustomCodeComponent>;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export type { FTCustomCodeComponent as CCCHTMLElement };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assigns a test URL based on the provided testEnv value.
|
|
3
|
-
*
|
|
4
|
-
* @param testEnv - A string indicating test environment setting
|
|
5
|
-
* @returns A `URL` object if valid and safe, or `undefined` if invalid.
|
|
6
|
-
*/
|
|
7
|
-
export declare function assignTestURL(testEnv: string | null): URL | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Checks whether the given test URL can establish a successful WebSocket connection,
|
|
10
|
-
* which indicates a live test environment (e.g., Vite HMR is active).
|
|
11
|
-
*
|
|
12
|
-
* @param testUrl - The test environment URL to check.
|
|
13
|
-
* @returns A promise that resolves to true if WebSocket connection is open, otherwise false.
|
|
14
|
-
*/
|
|
15
|
-
export declare function useComponentTestEnv(testUrl?: URL): Promise<boolean>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is the base CCC component error class. These are raised when the component being loaded errors
|
|
3
|
-
*/
|
|
4
|
-
import { ComponentPath, DetailType } from "./path";
|
|
5
|
-
export declare class CCCError extends Error {
|
|
6
|
-
component: ComponentPath | null;
|
|
7
|
-
source?: string;
|
|
8
|
-
constructor(message: string | null, detail?: DetailType);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* This class is used to raise errors that occur during the import of the CCC component app
|
|
12
|
-
*/
|
|
13
|
-
export declare class CCCImportError extends CCCError {
|
|
14
|
-
constructor(message: string, detail: DetailType);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* This class is used to raise errors that occur during the rendering of the CCC component app
|
|
18
|
-
*/
|
|
19
|
-
export declare class CCCRenderError extends CCCError {
|
|
20
|
-
constructor(message: string, detail: DetailType);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* This class is used to raise errors that occur as a result of the CCC component app timing out
|
|
24
|
-
*/
|
|
25
|
-
export declare class CCCTimeoutError extends CCCError {
|
|
26
|
-
constructor(detail: DetailType);
|
|
27
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ComponentPath } from "./path";
|
|
2
|
-
export declare class CCCConnectedEvent extends Event {
|
|
3
|
-
static eventType: string;
|
|
4
|
-
component: ComponentPath;
|
|
5
|
-
source?: string;
|
|
6
|
-
constructor(detail: {
|
|
7
|
-
component: ComponentPath;
|
|
8
|
-
source?: string;
|
|
9
|
-
}, opts?: EventInit);
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const LogLevel: Readonly<{
|
|
2
|
-
DEBUG: 0;
|
|
3
|
-
INFO: 1;
|
|
4
|
-
WARN: 2;
|
|
5
|
-
ERROR: 3;
|
|
6
|
-
TEST: 4;
|
|
7
|
-
DEFAULT: 2;
|
|
8
|
-
}>;
|
|
9
|
-
export declare function convertStringLogLevel(value: string | null): 0 | 2 | 1 | 3 | 4;
|
|
10
|
-
export declare class Logger {
|
|
11
|
-
level: number;
|
|
12
|
-
constructor({ level }?: {
|
|
13
|
-
level: number;
|
|
14
|
-
});
|
|
15
|
-
debug(...args: any[]): void;
|
|
16
|
-
log: (...args: any[]) => void;
|
|
17
|
-
info(...args: any[]): void;
|
|
18
|
-
warn(...args: any[]): void;
|
|
19
|
-
error(...args: any[]): void;
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type ComponentPathType = {
|
|
2
|
-
org: string;
|
|
3
|
-
repo: string;
|
|
4
|
-
component: string;
|
|
5
|
-
versionRange: string;
|
|
6
|
-
};
|
|
7
|
-
export declare class ComponentPath {
|
|
8
|
-
org: string;
|
|
9
|
-
repo: string;
|
|
10
|
-
component: string;
|
|
11
|
-
versionRange: string;
|
|
12
|
-
constructor(path: ComponentPathType | string);
|
|
13
|
-
set path(path: ComponentPathType | string);
|
|
14
|
-
get path(): string;
|
|
15
|
-
toString(): string;
|
|
16
|
-
static fromString(path: string | null, v?: string | null): ComponentPath;
|
|
17
|
-
}
|
|
18
|
-
export type DetailType = {
|
|
19
|
-
component: ComponentPath;
|
|
20
|
-
source?: string;
|
|
21
|
-
cause?: string;
|
|
22
|
-
};
|
|
23
|
-
export declare function isValidComponentPathObject(value: unknown): value is ComponentPathType;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Logger } from "./logger";
|
|
2
|
-
declare class Tracking {
|
|
3
|
-
cccId: string;
|
|
4
|
-
cccName: string;
|
|
5
|
-
subtype: string;
|
|
6
|
-
teamName: string;
|
|
7
|
-
shadowRoot: ShadowRoot | null;
|
|
8
|
-
category: string;
|
|
9
|
-
elements: string | string[];
|
|
10
|
-
isInitialised: boolean;
|
|
11
|
-
log: Logger;
|
|
12
|
-
constructor({ id, name, subtype, teamName, shadowRoot, category, elements, logger, }: {
|
|
13
|
-
id?: string;
|
|
14
|
-
name: string;
|
|
15
|
-
subtype: string;
|
|
16
|
-
teamName?: string;
|
|
17
|
-
shadowRoot: ShadowRoot | null;
|
|
18
|
-
category?: string;
|
|
19
|
-
elements?: string | string[];
|
|
20
|
-
logger: Logger;
|
|
21
|
-
});
|
|
22
|
-
getEventProperties(event: any): {
|
|
23
|
-
[k: string]: any;
|
|
24
|
-
};
|
|
25
|
-
handleClickEvent(eventData: {
|
|
26
|
-
action: string;
|
|
27
|
-
category: string;
|
|
28
|
-
}, root: Element): (clickEvent: Event, clickElement: HTMLElement) => void;
|
|
29
|
-
sendSpoorEvent(triggerAction: any, extraDetail: any): void;
|
|
30
|
-
init(id: string): void;
|
|
31
|
-
}
|
|
32
|
-
export default Tracking;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used to convert camelCase to kebab-case
|
|
3
|
-
* @param str
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
|
-
export declare const kebabize: (str: string) => string;
|
|
7
|
-
/**
|
|
8
|
-
* Checks if the provided host is part of the allowed test environments.
|
|
9
|
-
*
|
|
10
|
-
* @param host - The hostname to check.
|
|
11
|
-
* @returns True if the hostname is a safe test environment, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isSafeTestEnv(host: string | undefined): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Checks if the current window location hostname is considered a local environment.
|
|
16
|
-
*
|
|
17
|
-
* @returns True if the hostname is local, false otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export declare function isLocalEnv(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Checks if the current window location host is one of the Spark environments.
|
|
22
|
-
*
|
|
23
|
-
* @returns True if the host is spark.ft.com or spark-staging.ft.com, false otherwise.
|
|
24
|
-
*/
|
|
25
|
-
export declare function isSparkEnv(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if the given hostname is in the provided allowlist.
|
|
28
|
-
*
|
|
29
|
-
* @param allowlist - A list of allowed hostnames or RegExp matchers.
|
|
30
|
-
* @param hostname - The hostname to validate.
|
|
31
|
-
* @returns True if the hostname matches any item in the allowlist, false otherwise.
|
|
32
|
-
*/
|
|
33
|
-
export declare function isAllowed(allowlist: (string | RegExp)[], hostname: string | undefined): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactRenderer } from "../../ccc-sdk/src/renderers/react/ReactRenderer";
|
|
2
|
-
export declare const renderer: ReactRenderer;
|
|
3
|
-
declare const _default: (shadowRoot: ShadowRoot, attrs: any, ssr?: boolean) => {
|
|
4
|
-
unmount: (root: any) => void;
|
|
5
|
-
onmessage: {
|
|
6
|
-
(...data: any[]): void;
|
|
7
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
8
|
-
};
|
|
9
|
-
ready: Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
export default _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|