@powerformer/prism-client 0.5.1 → 0.7.0
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/build-info.json +4 -4
- package/dist/{chunk-PZLXS7XK.js → chunk-2G5GDKYE.js} +1 -1
- package/dist/{chunk-546JYWIC.js → chunk-3B2PZHLA.js} +23 -5
- package/dist/{chunk-5F3SG6QX.js → chunk-MYDJI2NW.js} +74 -10
- package/dist/chunk-NSC3MYAU.js +483 -0
- package/dist/contracts/resource-manifest.d.ts +31 -5
- package/dist/contracts/types.d.ts +13 -0
- package/dist/sdk/astro.d.ts +29 -0
- package/dist/sdk/astro.js +105 -4
- package/dist/sdk/client.d.ts +8 -1
- package/dist/sdk/contract.js +1 -1
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +8 -4
- package/dist/sdk/runtime.js +3 -3
- package/dist/sdk/types.d.ts +12 -0
- package/dist/sdk/visual-map.d.ts +173 -0
- package/dist/sdk/visual-map.js +42 -0
- package/dist/sdk/visual-middleware.d.ts +3 -0
- package/dist/sdk/visual-middleware.js +22 -0
- package/package.json +9 -1
package/dist/sdk/astro.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildVisualConfigFromTraces,
|
|
3
|
+
enableAutomaticReadTracing,
|
|
4
|
+
finalizeVisualArtifacts,
|
|
5
|
+
getLivePageReads,
|
|
6
|
+
readOverridesFile,
|
|
7
|
+
resolveBuildRef
|
|
8
|
+
} from "../chunk-NSC3MYAU.js";
|
|
1
9
|
import {
|
|
2
10
|
getRuntime,
|
|
3
11
|
releaseRuntime,
|
|
4
12
|
runtimeSeeds
|
|
5
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-2G5GDKYE.js";
|
|
6
14
|
import {
|
|
7
15
|
PrismError
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
16
|
+
} from "../chunk-MYDJI2NW.js";
|
|
17
|
+
import "../chunk-3B2PZHLA.js";
|
|
10
18
|
|
|
11
19
|
// app/sdk/astro.ts
|
|
12
20
|
import { randomUUID } from "node:crypto";
|
|
21
|
+
import { join, resolve } from "node:path";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
13
23
|
var virtualId = "virtual:prism", resolvedId = "\0virtual:prism";
|
|
14
24
|
function prismContent(options) {
|
|
15
25
|
if (!options.resources?.length) throw new PrismError("INVALID_CONFIG", "prismContent resources must not be empty");
|
|
@@ -23,6 +33,7 @@ function prismContent(options) {
|
|
|
23
33
|
if (!(command === "preview" || command === "sync")) {
|
|
24
34
|
clientOptions = {
|
|
25
35
|
environment: command === "dev" ? "dev" : "prod",
|
|
36
|
+
...options.visibility !== void 0 ? { visibility: options.visibility } : {},
|
|
26
37
|
channel: options.channel,
|
|
27
38
|
version: options.version,
|
|
28
39
|
locale: options.locale,
|
|
@@ -75,6 +86,96 @@ export const prismClient = getRuntime(${JSON.stringify(runtimeId)}, ${JSON.strin
|
|
|
75
86
|
}
|
|
76
87
|
};
|
|
77
88
|
}
|
|
89
|
+
function prismVisualMap(options = {}) {
|
|
90
|
+
let rootDir = process.cwd(), outDir = resolve(rootDir, "out"), activeEnv = options.environment ?? (process.env.PRISM_CONTENT_ENV === "dev" ? "dev" : "prod"), isDev = !1;
|
|
91
|
+
return {
|
|
92
|
+
name: "@powerformer/prism-client/visual-map",
|
|
93
|
+
hooks: {
|
|
94
|
+
"astro:config:setup": ({ command, config, addMiddleware }) => {
|
|
95
|
+
command === "preview" || command === "sync" || (isDev = command === "dev", rootDir = fileURLToPath(config.root), outDir = fileURLToPath(config.outDir), activeEnv = options.environment ?? (process.env.PRISM_CONTENT_ENV === "dev" || process.env.PRISM_CONTENT_ENV === "prod" ? process.env.PRISM_CONTENT_ENV : isDev ? "dev" : "prod"), enableAutomaticReadTracing(), isDev || (process.env.PRISM_VISUAL_TRACE_DIR = join(rootDir, ".prism", "trace")), addMiddleware({
|
|
96
|
+
entrypoint: "@powerformer/prism-client/visual-middleware",
|
|
97
|
+
order: "pre"
|
|
98
|
+
}));
|
|
99
|
+
},
|
|
100
|
+
"astro:server:setup": ({ server }) => {
|
|
101
|
+
server.middlewares.use((req, res, next) => {
|
|
102
|
+
let url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
103
|
+
if (url.pathname === "/prism-visual.json") {
|
|
104
|
+
let overrides = readOverridesFile(resolve(rootDir, options.overridesFile ?? "prism.visual.json")), pageReads = new Map(getLivePageReads()), seeded = options.devResourcesProvider?.() ?? [], { publicConfig } = buildVisualConfigFromTraces({
|
|
105
|
+
pageReads,
|
|
106
|
+
environment: activeEnv,
|
|
107
|
+
buildRef: resolveBuildRef(rootDir),
|
|
108
|
+
overrides
|
|
109
|
+
});
|
|
110
|
+
for (let item of seeded)
|
|
111
|
+
publicConfig.resources[item.resourceId] || (publicConfig.resources[item.resourceId] = {
|
|
112
|
+
...item.module ? { module: item.module } : {},
|
|
113
|
+
publicationId: item.publicationId,
|
|
114
|
+
versionId: item.versionId,
|
|
115
|
+
generation: item.generation
|
|
116
|
+
});
|
|
117
|
+
if (overrides.routes?.length) {
|
|
118
|
+
let modToId = /* @__PURE__ */ new Map();
|
|
119
|
+
for (let [rid, meta] of Object.entries(publicConfig.resources))
|
|
120
|
+
meta.module && modToId.set(meta.module, rid);
|
|
121
|
+
for (let declared of overrides.routes) {
|
|
122
|
+
if (publicConfig.routes.some((r) => r.pattern === declared.pattern)) continue;
|
|
123
|
+
let rid = declared.resourceId ?? (declared.module ? modToId.get(declared.module) : void 0), bindings = declared.bindings?.length ? declared.bindings : rid ? [{
|
|
124
|
+
resourceId: rid,
|
|
125
|
+
...declared.module ? { module: declared.module } : {},
|
|
126
|
+
...declared.selector ? { selector: declared.selector } : {}
|
|
127
|
+
}] : [];
|
|
128
|
+
bindings.length && publicConfig.routes.push({
|
|
129
|
+
pattern: declared.pattern,
|
|
130
|
+
bindings,
|
|
131
|
+
...declared.overrides?.length ? { overrides: declared.overrides } : {},
|
|
132
|
+
...declared.listPolicies && Object.keys(declared.listPolicies).length ? { listPolicies: declared.listPolicies } : {}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
res.statusCode = 200, res.setHeader("Content-Type", "application/json; charset=utf-8"), res.setHeader("Cache-Control", "no-store"), res.setHeader("X-Robots-Tag", "noindex, nofollow"), res.end(JSON.stringify(publicConfig, null, 2));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (url.pathname === "/__prism-dev/slice" && options.devSliceResolver) {
|
|
140
|
+
try {
|
|
141
|
+
let data = options.devSliceResolver({
|
|
142
|
+
resourceId: url.searchParams.get("resourceId") ?? "",
|
|
143
|
+
module: url.searchParams.get("module") ?? void 0,
|
|
144
|
+
collection: url.searchParams.get("collection") ?? void 0,
|
|
145
|
+
keyField: url.searchParams.get("keyField") ?? void 0,
|
|
146
|
+
keyValue: url.searchParams.get("keyValue") ?? void 0
|
|
147
|
+
});
|
|
148
|
+
res.statusCode = data ? 200 : 404, res.setHeader("Content-Type", "application/json; charset=utf-8"), res.setHeader("Cache-Control", "no-store"), res.end(JSON.stringify(data ?? { error: "Slice not found" }));
|
|
149
|
+
} catch (error) {
|
|
150
|
+
res.statusCode = 500, res.setHeader("Content-Type", "application/json; charset=utf-8"), res.end(JSON.stringify({ error: error instanceof Error ? error.message : "Slice resolution failed" }));
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
next();
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
"astro:build:done": ({ logger }) => {
|
|
158
|
+
if (isDev) return;
|
|
159
|
+
let verifyEnabled = process.env.PRISM_VISUAL_VERIFY === "1" && !!(process.env.PRISM_VERSION_OVERRIDE || process.env.PRISM_VERSION), publicKeyPem = options.encryptPublicKeyPem ?? process.env.PRISM_VISUAL_PUBLIC_KEY_PEM, result = finalizeVisualArtifacts({
|
|
160
|
+
rootDir,
|
|
161
|
+
outDir,
|
|
162
|
+
environment: activeEnv,
|
|
163
|
+
overridesFile: options.overridesFile ?? "prism.visual.json",
|
|
164
|
+
encryptPublicKeyPem: publicKeyPem,
|
|
165
|
+
encryptKeyId: options.encryptKeyId ?? process.env.PRISM_VISUAL_KEY_ID ?? "prism-visual-v1",
|
|
166
|
+
verify: verifyEnabled
|
|
167
|
+
});
|
|
168
|
+
if (logger.info(`Wrote ${result.visualMapPath} and ${result.publicConfigPath} (${result.publicConfig.routes.length} routes).`), result.verifyReport && (logger.info(`Visual XPath verification: ${result.verifyReport.passed}/${result.verifyReport.total} passed.`), !result.verifyReport.ok)) {
|
|
169
|
+
let summary = result.verifyReport.items.filter((item) => item.status !== "passed").map((item) => ` - [${item.status}] ${item.pagePath} ${item.xpath}: ${item.detail}`).join(`
|
|
170
|
+
`);
|
|
171
|
+
throw new Error(`Prism visual XPath verification failed (${result.verifyReport.failed}/${result.verifyReport.total}):
|
|
172
|
+
${summary}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
78
178
|
export {
|
|
79
|
-
prismContent
|
|
179
|
+
prismContent,
|
|
180
|
+
prismVisualMap
|
|
80
181
|
};
|
package/dist/sdk/client.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type { DevServerHandle, DevServerOptions, PrismOptions, ResourceOptions, ResourceQuery } from './types.js';
|
|
1
|
+
import type { DevServerHandle, DevServerOptions, PrismOptions, PrismReadObserver, ResourceOptions, ResourceQuery } from './types.js';
|
|
2
|
+
/** Register a zero-overhead read observer (used by Node build-time visual-map tracing). */
|
|
3
|
+
export declare function registerReadObserver(observer: PrismReadObserver): () => void;
|
|
4
|
+
/** Parse PRISM_VERSION_OVERRIDE (`uuid=ver,uuid2=ver2` or JSON map) and PRISM_VERSION. */
|
|
5
|
+
export declare function resolveEnvVersionOverrides(environment: 'dev' | 'prod'): {
|
|
6
|
+
byResource: ReadonlyMap<string, string>;
|
|
7
|
+
fallbackVersion?: string;
|
|
8
|
+
};
|
|
2
9
|
export declare class Prism {
|
|
3
10
|
private readonly locale?;
|
|
4
11
|
constructor(options: PrismOptions);
|
package/dist/sdk/contract.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
resourceVersionLocalePath,
|
|
17
17
|
resourceVersionMainPath,
|
|
18
18
|
resourceVersionManifestPath
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-3B2PZHLA.js";
|
|
20
20
|
|
|
21
21
|
// app/sdk/contract.ts
|
|
22
22
|
var parseResourceMain2 = parseResourceMain, parseResourceManifest2 = parseResourceManifest, parseResourceManifestV22 = parseResourceManifestV2, resourceMainPath2 = resourceMainPath, resourceEnvironmentManifestPath2 = resourceEnvironmentManifestPath, parseResourceMainV22 = parseResourceMainV2, parseResourceManifestV32 = parseResourceManifestV3, resourcePublicMainPath2 = resourcePublicMainPath, resourcePublicManifestPath2 = resourcePublicManifestPath, resourcePublicContentPath2 = resourcePublicContentPath, resourceDeliveryOrigin2 = resourceDeliveryOrigin, parseResourceManifestV42 = parseResourceManifestV4, parseDeliveryManifest2 = parseDeliveryManifest, resourceVersionMainPath2 = resourceVersionMainPath, resourceVersionManifestPath2 = resourceVersionManifestPath, resourceVersionLocalePath2 = resourceVersionLocalePath, resourcePublicLocalePath2 = resourcePublicLocalePath;
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Prism } from './client.js';
|
|
1
|
+
export { Prism, registerReadObserver, resolveEnvVersionOverrides } from './client.js';
|
|
2
2
|
export { PrismError } from './errors.js';
|
|
3
3
|
export type { PrismErrorCode } from './errors.js';
|
|
4
|
-
export type { PrismOptions, Environment, ResourceOptions, ResourceQuery, PublicationMeta, ResourceResult, ResourceBundleResult, DevServerOptions, DevServerHandle, DevUpdate, } from './types.js';
|
|
4
|
+
export type { PrismOptions, Environment, Visibility, ResourceOptions, ResourceQuery, PublicationMeta, ResourceResult, ResourceBundleResult, DevServerOptions, DevServerHandle, DevUpdate, PrismReadEvent, PrismReadObserver, VisualExpectation, } from './types.js';
|
|
5
5
|
export type { ScopeRole, ResourceMembership } from '../contracts/access.js';
|
package/dist/sdk/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Prism,
|
|
3
|
-
PrismError
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
PrismError,
|
|
4
|
+
registerReadObserver,
|
|
5
|
+
resolveEnvVersionOverrides
|
|
6
|
+
} from "../chunk-MYDJI2NW.js";
|
|
7
|
+
import "../chunk-3B2PZHLA.js";
|
|
6
8
|
export {
|
|
7
9
|
Prism,
|
|
8
|
-
PrismError
|
|
10
|
+
PrismError,
|
|
11
|
+
registerReadObserver,
|
|
12
|
+
resolveEnvVersionOverrides
|
|
9
13
|
};
|
package/dist/sdk/runtime.js
CHANGED
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
getRuntime,
|
|
3
3
|
releaseRuntime,
|
|
4
4
|
runtimeSeeds
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-2G5GDKYE.js";
|
|
6
|
+
import "../chunk-MYDJI2NW.js";
|
|
7
|
+
import "../chunk-3B2PZHLA.js";
|
|
8
8
|
export {
|
|
9
9
|
getRuntime,
|
|
10
10
|
releaseRuntime,
|
package/dist/sdk/types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { VisualExpectation } from '../contracts/types.js';
|
|
2
|
+
export type { VisualExpectation } from '../contracts/types.js';
|
|
1
3
|
export type Environment = 'dev' | 'prod';
|
|
4
|
+
export type Visibility = 'public' | 'internal';
|
|
2
5
|
export interface PrismOptions {
|
|
3
6
|
environment: Environment;
|
|
7
|
+
visibility?: Visibility;
|
|
4
8
|
channel?: string;
|
|
5
9
|
/** Frozen URL address shown by Prism: SemVer for new Versions, saved alias for legacy Versions. */
|
|
6
10
|
version?: string;
|
|
@@ -23,7 +27,15 @@ export interface PublicationMeta {
|
|
|
23
27
|
version: string | null;
|
|
24
28
|
schemaId: string;
|
|
25
29
|
schemaVersion: number;
|
|
30
|
+
visualExpectations?: VisualExpectation[];
|
|
26
31
|
}
|
|
32
|
+
export interface PrismReadEvent {
|
|
33
|
+
resourceId: string;
|
|
34
|
+
locale: string;
|
|
35
|
+
all: boolean;
|
|
36
|
+
meta: PublicationMeta;
|
|
37
|
+
}
|
|
38
|
+
export type PrismReadObserver = (event: PrismReadEvent) => void;
|
|
27
39
|
export interface ResourceResult<T = unknown> {
|
|
28
40
|
data: T;
|
|
29
41
|
meta: PublicationMeta & {
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { JsonValue, VisualExpectation } from '../contracts/types.js';
|
|
2
|
+
export interface PrismReadSelector {
|
|
3
|
+
collection: string;
|
|
4
|
+
keyField: string;
|
|
5
|
+
keyValue: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PrismReadTraceRecord {
|
|
8
|
+
module?: string;
|
|
9
|
+
resourceId: string;
|
|
10
|
+
locale: string;
|
|
11
|
+
publicationId: string;
|
|
12
|
+
versionId: string;
|
|
13
|
+
generation: number;
|
|
14
|
+
pageId?: string;
|
|
15
|
+
/** Optional canonical page path owned by this item; filters out site-wide manifest/sitemap preloads during another page's render. */
|
|
16
|
+
canonicalPath?: string;
|
|
17
|
+
selector?: PrismReadSelector;
|
|
18
|
+
visualExpectations?: VisualExpectation[];
|
|
19
|
+
}
|
|
20
|
+
export interface VisualOverrideRule {
|
|
21
|
+
scope?: string;
|
|
22
|
+
match: string;
|
|
23
|
+
pointer: string;
|
|
24
|
+
localeScope?: 'current-locale' | 'all-locales' | 'default-locale';
|
|
25
|
+
control?: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface VisualRouteBinding {
|
|
29
|
+
resourceId: string;
|
|
30
|
+
module?: string;
|
|
31
|
+
selector?: {
|
|
32
|
+
collection: string;
|
|
33
|
+
keyField: string;
|
|
34
|
+
keyValue?: string;
|
|
35
|
+
fromParam?: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface VisualListPolicy {
|
|
39
|
+
allowReorder?: boolean;
|
|
40
|
+
allowAdd?: boolean;
|
|
41
|
+
allowRemove?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface VisualRouteConfig {
|
|
44
|
+
pattern: string;
|
|
45
|
+
bindings: VisualRouteBinding[];
|
|
46
|
+
overrides?: VisualOverrideRule[];
|
|
47
|
+
listPolicies?: Record<string, VisualListPolicy>;
|
|
48
|
+
}
|
|
49
|
+
export interface VisualResourceSummary {
|
|
50
|
+
module?: string;
|
|
51
|
+
publicationId: string;
|
|
52
|
+
versionId: string;
|
|
53
|
+
generation: number;
|
|
54
|
+
visualExpectations?: VisualExpectation[];
|
|
55
|
+
}
|
|
56
|
+
export interface VisualPublicConfig {
|
|
57
|
+
schemaVersion: 1;
|
|
58
|
+
environment: 'dev' | 'prod';
|
|
59
|
+
buildRef: string | null;
|
|
60
|
+
locales: string[];
|
|
61
|
+
ignoreSelectors: string[];
|
|
62
|
+
resources: Record<string, Omit<VisualResourceSummary, 'visualExpectations'>>;
|
|
63
|
+
routes: VisualRouteConfig[];
|
|
64
|
+
}
|
|
65
|
+
export interface VisualOverridesFile {
|
|
66
|
+
schemaVersion?: 1;
|
|
67
|
+
locales?: string[];
|
|
68
|
+
ignoreSelectors?: string[];
|
|
69
|
+
routes?: Array<{
|
|
70
|
+
pattern: string;
|
|
71
|
+
module?: string;
|
|
72
|
+
resourceId?: string;
|
|
73
|
+
selector?: VisualRouteBinding['selector'];
|
|
74
|
+
bindings?: VisualRouteBinding[];
|
|
75
|
+
overrides?: VisualOverrideRule[];
|
|
76
|
+
listPolicies?: Record<string, VisualListPolicy>;
|
|
77
|
+
}>;
|
|
78
|
+
modules?: Record<string, {
|
|
79
|
+
routes?: string[];
|
|
80
|
+
overrides?: VisualOverrideRule[];
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
export interface VisualEnvelope {
|
|
84
|
+
v: 1;
|
|
85
|
+
alg: 'RSA-OAEP-256+A256GCM';
|
|
86
|
+
kid: string;
|
|
87
|
+
ek: string;
|
|
88
|
+
iv: string;
|
|
89
|
+
ct: string;
|
|
90
|
+
}
|
|
91
|
+
interface TraceStore {
|
|
92
|
+
pathname: string;
|
|
93
|
+
reads: Map<string, PrismReadTraceRecord>;
|
|
94
|
+
}
|
|
95
|
+
export declare function enableAutomaticReadTracing(): void;
|
|
96
|
+
export declare function runWithPageTrace<T>(pathname: string, fn: () => Promise<T> | T): Promise<T>;
|
|
97
|
+
export declare function currentPageTrace(): TraceStore | undefined;
|
|
98
|
+
export declare function recordPrismRead(record: PrismReadTraceRecord): void;
|
|
99
|
+
export declare function recordLivePageReads(pathname: string, reads: PrismReadTraceRecord[]): void;
|
|
100
|
+
export declare function getLivePageReads(): Map<string, PrismReadTraceRecord[]>;
|
|
101
|
+
export declare function appendWorkerTrace(traceDir: string, pathname: string, reads: PrismReadTraceRecord[]): void;
|
|
102
|
+
export declare function normalizePathname(pathname: string): string;
|
|
103
|
+
export declare function stripLocalePrefix(pathname: string, locales: readonly string[]): {
|
|
104
|
+
locale: string;
|
|
105
|
+
canonicalPath: string;
|
|
106
|
+
};
|
|
107
|
+
export declare function resolveBuildRef(rootDir: string): string | null;
|
|
108
|
+
export declare function isVisualEnvelope(value: unknown): value is VisualEnvelope;
|
|
109
|
+
export declare function encryptVisualEnvelope(payload: VisualPublicConfig, publicKeyPem: string, kid?: string): VisualEnvelope;
|
|
110
|
+
export declare function decryptVisualEnvelope(envelope: VisualEnvelope, privateKeyPem: string): VisualPublicConfig;
|
|
111
|
+
export declare function readOverridesFile(filePath: string | undefined): VisualOverridesFile;
|
|
112
|
+
/** Compact per-page reads across locales and collection detail routes into compact route patterns. */
|
|
113
|
+
export declare function buildVisualConfigFromTraces(input: {
|
|
114
|
+
pageReads: Map<string, PrismReadTraceRecord[]>;
|
|
115
|
+
environment: 'dev' | 'prod';
|
|
116
|
+
buildRef: string | null;
|
|
117
|
+
overrides?: VisualOverridesFile;
|
|
118
|
+
}): {
|
|
119
|
+
publicConfig: VisualPublicConfig;
|
|
120
|
+
expectations: Array<{
|
|
121
|
+
resourceId: string;
|
|
122
|
+
versionId: string;
|
|
123
|
+
expectations: VisualExpectation[];
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
/** Evaluate semantic relative/absolute XPath against MiniNode HTML5 tree. */
|
|
127
|
+
export declare function evaluateHtmlXPath(html: string, xpath: string): Array<{
|
|
128
|
+
text: string;
|
|
129
|
+
attr?: string;
|
|
130
|
+
}>;
|
|
131
|
+
export interface VisualVerifyItemResult {
|
|
132
|
+
resourceId: string;
|
|
133
|
+
versionId: string;
|
|
134
|
+
pagePath: string;
|
|
135
|
+
xpath: string;
|
|
136
|
+
pointer: string;
|
|
137
|
+
locale: string;
|
|
138
|
+
status: 'passed' | 'xpath_not_found' | 'value_mismatch' | 'page_not_found';
|
|
139
|
+
expected: JsonValue;
|
|
140
|
+
actual: string | null;
|
|
141
|
+
detail: string;
|
|
142
|
+
}
|
|
143
|
+
export interface VisualVerifyReport {
|
|
144
|
+
ok: boolean;
|
|
145
|
+
checkedAt: string;
|
|
146
|
+
total: number;
|
|
147
|
+
passed: number;
|
|
148
|
+
failed: number;
|
|
149
|
+
items: VisualVerifyItemResult[];
|
|
150
|
+
}
|
|
151
|
+
export declare function verifyVisualExpectations(input: {
|
|
152
|
+
outDir: string;
|
|
153
|
+
bundles: Array<{
|
|
154
|
+
resourceId: string;
|
|
155
|
+
versionId: string;
|
|
156
|
+
expectations: VisualExpectation[];
|
|
157
|
+
}>;
|
|
158
|
+
}): VisualVerifyReport;
|
|
159
|
+
export declare function finalizeVisualArtifacts(options: {
|
|
160
|
+
rootDir: string;
|
|
161
|
+
outDir: string;
|
|
162
|
+
environment: 'dev' | 'prod';
|
|
163
|
+
overridesFile?: string;
|
|
164
|
+
encryptPublicKeyPem?: string;
|
|
165
|
+
encryptKeyId?: string;
|
|
166
|
+
verify?: boolean;
|
|
167
|
+
}): {
|
|
168
|
+
visualMapPath: string;
|
|
169
|
+
publicConfigPath: string;
|
|
170
|
+
publicConfig: VisualPublicConfig;
|
|
171
|
+
verifyReport?: VisualVerifyReport;
|
|
172
|
+
};
|
|
173
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendWorkerTrace,
|
|
3
|
+
buildVisualConfigFromTraces,
|
|
4
|
+
currentPageTrace,
|
|
5
|
+
decryptVisualEnvelope,
|
|
6
|
+
enableAutomaticReadTracing,
|
|
7
|
+
encryptVisualEnvelope,
|
|
8
|
+
evaluateHtmlXPath,
|
|
9
|
+
finalizeVisualArtifacts,
|
|
10
|
+
getLivePageReads,
|
|
11
|
+
isVisualEnvelope,
|
|
12
|
+
normalizePathname,
|
|
13
|
+
readOverridesFile,
|
|
14
|
+
recordLivePageReads,
|
|
15
|
+
recordPrismRead,
|
|
16
|
+
resolveBuildRef,
|
|
17
|
+
runWithPageTrace,
|
|
18
|
+
stripLocalePrefix,
|
|
19
|
+
verifyVisualExpectations
|
|
20
|
+
} from "../chunk-NSC3MYAU.js";
|
|
21
|
+
import "../chunk-MYDJI2NW.js";
|
|
22
|
+
import "../chunk-3B2PZHLA.js";
|
|
23
|
+
export {
|
|
24
|
+
appendWorkerTrace,
|
|
25
|
+
buildVisualConfigFromTraces,
|
|
26
|
+
currentPageTrace,
|
|
27
|
+
decryptVisualEnvelope,
|
|
28
|
+
enableAutomaticReadTracing,
|
|
29
|
+
encryptVisualEnvelope,
|
|
30
|
+
evaluateHtmlXPath,
|
|
31
|
+
finalizeVisualArtifacts,
|
|
32
|
+
getLivePageReads,
|
|
33
|
+
isVisualEnvelope,
|
|
34
|
+
normalizePathname,
|
|
35
|
+
readOverridesFile,
|
|
36
|
+
recordLivePageReads,
|
|
37
|
+
recordPrismRead,
|
|
38
|
+
resolveBuildRef,
|
|
39
|
+
runWithPageTrace,
|
|
40
|
+
stripLocalePrefix,
|
|
41
|
+
verifyVisualExpectations
|
|
42
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendWorkerTrace,
|
|
3
|
+
currentPageTrace,
|
|
4
|
+
enableAutomaticReadTracing,
|
|
5
|
+
recordLivePageReads,
|
|
6
|
+
runWithPageTrace
|
|
7
|
+
} from "../chunk-NSC3MYAU.js";
|
|
8
|
+
import "../chunk-MYDJI2NW.js";
|
|
9
|
+
import "../chunk-3B2PZHLA.js";
|
|
10
|
+
|
|
11
|
+
// app/sdk/visual-middleware.ts
|
|
12
|
+
async function onRequest(context, next) {
|
|
13
|
+
enableAutomaticReadTracing();
|
|
14
|
+
let traceDir = process.env.PRISM_VISUAL_TRACE_DIR, capturedReads = [], response = await runWithPageTrace(context.url.pathname, async () => {
|
|
15
|
+
let res = await next(), store = currentPageTrace();
|
|
16
|
+
return store && store.reads.size > 0 && (capturedReads = [...store.reads.values()]), res;
|
|
17
|
+
}), contentType = response.headers.get("content-type") ?? "";
|
|
18
|
+
return capturedReads.length > 0 && (contentType.includes("text/html") || !contentType) && (recordLivePageReads(context.url.pathname, capturedReads), traceDir && appendWorkerTrace(traceDir, context.url.pathname, capturedReads)), response;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
onRequest
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerformer/prism-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Read published Prism multilingual content with shared caching and Astro development updates.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"types": "./dist/sdk/astro.d.ts",
|
|
19
19
|
"import": "./dist/sdk/astro.js"
|
|
20
20
|
},
|
|
21
|
+
"./visual-map": {
|
|
22
|
+
"types": "./dist/sdk/visual-map.d.ts",
|
|
23
|
+
"import": "./dist/sdk/visual-map.js"
|
|
24
|
+
},
|
|
25
|
+
"./visual-middleware": {
|
|
26
|
+
"types": "./dist/sdk/visual-middleware.d.ts",
|
|
27
|
+
"import": "./dist/sdk/visual-middleware.js"
|
|
28
|
+
},
|
|
21
29
|
"./runtime": {
|
|
22
30
|
"types": "./dist/sdk/runtime.d.ts",
|
|
23
31
|
"import": "./dist/sdk/runtime.js"
|