@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/build-info.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerformer/prism-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"gitCommit": "
|
|
5
|
-
"sourceSha256": "
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"gitCommit": "c8330b2269f97bbe95a5944e6d58bc95e5b2ab86",
|
|
5
|
+
"sourceSha256": "bf41b5215e1bd81b7a06ce5f24c426bc189b8c061d86f7ba04b041e8d646724d",
|
|
6
6
|
"contentContract": "app/contracts",
|
|
7
|
-
"contentContractSha256": "
|
|
7
|
+
"contentContractSha256": "443ac891fd70f4ff6c59193de4668cb7bd0136d879eead0b0e100e4f480ddd32"
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Prism,
|
|
3
3
|
PrismError,
|
|
4
4
|
storeFor
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MYDJI2NW.js";
|
|
6
6
|
|
|
7
7
|
// app/sdk/runtime.ts
|
|
8
8
|
var key = /* @__PURE__ */ Symbol.for("@powerformer/prism-client/runtime/v1"), globalRegistry = globalThis, registry = globalRegistry[key] ??= /* @__PURE__ */ new Map();
|
|
@@ -15187,7 +15187,8 @@ function date4(params) {
|
|
|
15187
15187
|
}
|
|
15188
15188
|
|
|
15189
15189
|
// app/contracts/resource-manifest.ts
|
|
15190
|
-
var RESOURCE_CDN_ORIGIN = "https://r.open-design.ai", MANIFEST_PROTOCOL = "v1";
|
|
15190
|
+
var RESOURCE_CDN_ORIGIN = "https://r.open-design.ai", RESOURCE_DEV_CDN_ORIGIN = "https://r.powerformer.net", RESOURCE_INTERNAL_CDN_ORIGIN = "https://r-internal.powerformer.net", MANIFEST_PROTOCOL = "v1";
|
|
15191
|
+
var resourceVisibilitySchema = external_exports.enum(["public", "internal"]);
|
|
15191
15192
|
var resourceIdSchema = external_exports.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/), channelNameSchema = external_exports.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/), versionIdSchema = external_exports.string().regex(/^ver_[0-9a-f]{32}$/), semanticLabelSchema = external_exports.string().min(1).max(64), semanticVersionSchema = external_exports.string().max(64).regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?![\s\S])/, "Use SemVer, for example 1.2.3 or 1.2.3-rc.1"), versionAddressSchema = external_exports.string().min(1).max(512).regex(/^[A-Za-z0-9][A-Za-z0-9._+-]*(?![\s\S])/), sha256Schema = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
15192
15193
|
function encodeResourcePathSegment(segment) {
|
|
15193
15194
|
return encodeURIComponent(segment);
|
|
@@ -15283,8 +15284,9 @@ function parseResourceMain(value) {
|
|
|
15283
15284
|
return resourceMainSchema.parse(value);
|
|
15284
15285
|
}
|
|
15285
15286
|
var resourceUuidSchema = external_exports.uuid().refine((value) => value === value.toLowerCase(), "Use a lowercase UUID");
|
|
15286
|
-
function resourceDeliveryOrigin(environment) {
|
|
15287
|
-
|
|
15287
|
+
function resourceDeliveryOrigin(environment, visibility = "public") {
|
|
15288
|
+
let env = resourceEnvironmentSchema.parse(environment), vis = resourceVisibilitySchema.parse(visibility);
|
|
15289
|
+
return env === "dev" ? RESOURCE_DEV_CDN_ORIGIN : vis === "internal" ? RESOURCE_INTERNAL_CDN_ORIGIN : RESOURCE_CDN_ORIGIN;
|
|
15288
15290
|
}
|
|
15289
15291
|
function resourcePublicMainPath(id, channel) {
|
|
15290
15292
|
return `/resources/${resourceUuidSchema.parse(id)}/channels/${channelNameSchema.parse(channel)}/main.json`;
|
|
@@ -15331,9 +15333,24 @@ function parseResourceManifestV3(value) {
|
|
|
15331
15333
|
contents: input2.contents.map((item) => ({ ...item, contentUrl: resourceLocaleContentPath(input2.resourceId, input2.environment, input2.contentPublicationId, item.locale, item.sha256) }))
|
|
15332
15334
|
}), manifestVersion: "v3", mainUrl: input2.mainUrl, contents: input2.contents };
|
|
15333
15335
|
}
|
|
15336
|
+
var visualExpectationSchema = external_exports.object({
|
|
15337
|
+
pagePath: external_exports.string().min(1).regex(/^\//),
|
|
15338
|
+
xpath: external_exports.string().min(1).max(1e3),
|
|
15339
|
+
pointer: external_exports.string().max(500),
|
|
15340
|
+
locale: resourceLocaleSchema,
|
|
15341
|
+
matchType: external_exports.enum(["exact-text", "template-segments", "richtext-html", "media-src", "override-number"]),
|
|
15342
|
+
beforeValue: mainJsonValueSchema.optional(),
|
|
15343
|
+
expectedValue: mainJsonValueSchema,
|
|
15344
|
+
capturedBuildRef: external_exports.string().max(120).optional(),
|
|
15345
|
+
createdAt: external_exports.string().max(64).optional()
|
|
15346
|
+
});
|
|
15334
15347
|
function parseResourceMainV2(value) {
|
|
15335
|
-
let input2 = external_exports.object({
|
|
15336
|
-
|
|
15348
|
+
let input2 = external_exports.object({
|
|
15349
|
+
mainVersion: external_exports.literal("v2"),
|
|
15350
|
+
resourceId: resourceUuidSchema,
|
|
15351
|
+
visualExpectations: external_exports.array(visualExpectationSchema).max(500).optional()
|
|
15352
|
+
}).passthrough().parse(value), parsed = { ...parseResourceMain({ ...input2, mainVersion: "v1" }), mainVersion: "v2" };
|
|
15353
|
+
return input2.visualExpectations ? { ...parsed, visualExpectations: input2.visualExpectations } : parsed;
|
|
15337
15354
|
}
|
|
15338
15355
|
function parseResourceManifestV4(value) {
|
|
15339
15356
|
let input2 = external_exports.object({
|
|
@@ -15363,6 +15380,7 @@ function parseDeliveryManifest(value) {
|
|
|
15363
15380
|
}
|
|
15364
15381
|
|
|
15365
15382
|
export {
|
|
15383
|
+
resourceVisibilitySchema,
|
|
15366
15384
|
channelNameSchema,
|
|
15367
15385
|
versionAddressSchema,
|
|
15368
15386
|
parseResourceManifest,
|
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
resourceUuidSchema,
|
|
11
11
|
resourceVersionMainPath,
|
|
12
12
|
resourceVersionManifestPath,
|
|
13
|
+
resourceVisibilitySchema,
|
|
13
14
|
versionAddressSchema
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3B2PZHLA.js";
|
|
15
16
|
|
|
16
17
|
// app/sdk/errors.ts
|
|
17
18
|
var PrismError = class extends Error {
|
|
@@ -82,6 +83,59 @@ function startDevServer(store, options) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
// app/sdk/client.ts
|
|
86
|
+
var OBSERVER_KEY = /* @__PURE__ */ Symbol.for("@powerformer/prism-client/read-observers/v1");
|
|
87
|
+
function observerSet() {
|
|
88
|
+
let host = globalThis;
|
|
89
|
+
return host[OBSERVER_KEY] ??= /* @__PURE__ */ new Set();
|
|
90
|
+
}
|
|
91
|
+
function registerReadObserver(observer) {
|
|
92
|
+
let set = observerSet();
|
|
93
|
+
return set.add(observer), () => {
|
|
94
|
+
set.delete(observer);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function notifyRead(event) {
|
|
98
|
+
let set = globalThis[OBSERVER_KEY];
|
|
99
|
+
if (!(!set || set.size === 0))
|
|
100
|
+
for (let fn of set)
|
|
101
|
+
try {
|
|
102
|
+
fn(event);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function readProcessEnv() {
|
|
107
|
+
return globalThis.process?.env;
|
|
108
|
+
}
|
|
109
|
+
function resolveEnvVersionOverrides(environment) {
|
|
110
|
+
let env = readProcessEnv(), rawMap = env?.PRISM_VERSION_OVERRIDE?.trim() ?? "", rawSingle = env?.PRISM_VERSION?.trim() ?? "";
|
|
111
|
+
if (environment === "prod" && (rawMap || rawSingle))
|
|
112
|
+
throw new PrismError("INVALID_CONFIG", "PRISM_VERSION_OVERRIDE and PRISM_VERSION are forbidden in prod environment");
|
|
113
|
+
let byResource = /* @__PURE__ */ new Map();
|
|
114
|
+
if (rawMap)
|
|
115
|
+
if (rawMap.startsWith("{")) {
|
|
116
|
+
let parsed;
|
|
117
|
+
try {
|
|
118
|
+
parsed = JSON.parse(rawMap);
|
|
119
|
+
} catch {
|
|
120
|
+
throw new PrismError("INVALID_CONFIG", "PRISM_VERSION_OVERRIDE JSON is invalid");
|
|
121
|
+
}
|
|
122
|
+
if (!parsed || typeof parsed != "object" || Array.isArray(parsed))
|
|
123
|
+
throw new PrismError("INVALID_CONFIG", "PRISM_VERSION_OVERRIDE JSON must be an object");
|
|
124
|
+
for (let [k, v] of Object.entries(parsed))
|
|
125
|
+
byResource.set(
|
|
126
|
+
checked(resourceUuidSchema.parse, k, "PRISM_VERSION_OVERRIDE resourceId"),
|
|
127
|
+
checked(versionAddressSchema.parse, v, "PRISM_VERSION_OVERRIDE version")
|
|
128
|
+
);
|
|
129
|
+
} else
|
|
130
|
+
for (let pair of rawMap.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
131
|
+
let eq = pair.indexOf("=");
|
|
132
|
+
if (eq < 1) throw new PrismError("INVALID_CONFIG", `Invalid PRISM_VERSION_OVERRIDE entry: ${pair}`);
|
|
133
|
+
let id = checked(resourceUuidSchema.parse, pair.slice(0, eq).trim(), "PRISM_VERSION_OVERRIDE resourceId"), ver = checked(versionAddressSchema.parse, pair.slice(eq + 1).trim(), "PRISM_VERSION_OVERRIDE version");
|
|
134
|
+
byResource.set(id, ver);
|
|
135
|
+
}
|
|
136
|
+
let fallbackVersion = rawSingle ? checked(versionAddressSchema.parse, rawSingle, "PRISM_VERSION") : void 0;
|
|
137
|
+
return { byResource, fallbackVersion };
|
|
138
|
+
}
|
|
85
139
|
function checked(parse, value, field) {
|
|
86
140
|
try {
|
|
87
141
|
return parse(value);
|
|
@@ -132,6 +186,8 @@ function select(main, requirement) {
|
|
|
132
186
|
}
|
|
133
187
|
var ClientStore = class {
|
|
134
188
|
options;
|
|
189
|
+
envOverrides;
|
|
190
|
+
envFallbackVersion;
|
|
135
191
|
cache = /* @__PURE__ */ new Map();
|
|
136
192
|
pending = /* @__PURE__ */ new Map();
|
|
137
193
|
requirements = /* @__PURE__ */ new Map();
|
|
@@ -139,13 +195,18 @@ var ClientStore = class {
|
|
|
139
195
|
watcher;
|
|
140
196
|
constructor(options) {
|
|
141
197
|
if (!options || typeof options != "object") throw new PrismError("INVALID_CONFIG", "Prism options are required");
|
|
142
|
-
|
|
143
|
-
|
|
198
|
+
let environment = checked(resourceEnvironmentSchema.parse, options.environment, "environment"), overrides = resolveEnvVersionOverrides(environment);
|
|
199
|
+
this.envOverrides = overrides.byResource, this.envFallbackVersion = overrides.fallbackVersion, this.options = {
|
|
200
|
+
environment,
|
|
201
|
+
visibility: checked(resourceVisibilitySchema.parse, options.visibility ?? "public", "visibility"),
|
|
144
202
|
channel: checked(channelNameSchema.parse, options.channel ?? DEFAULT_EDITORIAL_CHANNEL, "channel"),
|
|
145
203
|
timeoutMs: positive(options.timeoutMs ?? 8e3, "timeoutMs"),
|
|
146
204
|
...options.version === void 0 ? {} : { version: checked(versionAddressSchema.parse, options.version, "version") }
|
|
147
205
|
};
|
|
148
206
|
}
|
|
207
|
+
versionFor(id) {
|
|
208
|
+
return this.envOverrides.get(id) ?? this.options.version ?? this.envFallbackVersion;
|
|
209
|
+
}
|
|
149
210
|
parse(value, id) {
|
|
150
211
|
let main;
|
|
151
212
|
try {
|
|
@@ -168,10 +229,11 @@ var ClientStore = class {
|
|
|
168
229
|
if (this.allowedResources && !this.allowedResources.has(id))
|
|
169
230
|
throw new PrismError("INVALID_CONFIG", `Resource ${id} must be listed in prismContent resources`, { resourceId: id });
|
|
170
231
|
let cached = this.cache.get(id), cachedData = cached ? select(cached.main, requirement) : void 0, requirements = this.requirements.get(id) ?? [], added = !requirements.some((r) => r.locale === requirement.locale && r.all === requirement.all && r.parse === requirement.parse);
|
|
171
|
-
if (added && (requirements.push(requirement), this.requirements.set(id, requirements)), cached)
|
|
232
|
+
if (added && (requirements.push(requirement), this.requirements.set(id, requirements)), cached)
|
|
233
|
+
return notifyRead({ resourceId: id, locale: requirement.locale ?? cached.main.defaultLocale, all: requirement.all, meta: metadata(cached.main) }), { entry: cached, data: cachedData };
|
|
172
234
|
try {
|
|
173
|
-
let entry = await this.fetch(id);
|
|
174
|
-
return {
|
|
235
|
+
let entry = await this.fetch(id), data = select(entry.main, requirement);
|
|
236
|
+
return notifyRead({ resourceId: id, locale: requirement.locale ?? entry.main.defaultLocale, all: requirement.all, meta: metadata(entry.main) }), { entry, data };
|
|
175
237
|
} catch (error) {
|
|
176
238
|
throw added && requirements.splice(requirements.indexOf(requirement), 1), error;
|
|
177
239
|
}
|
|
@@ -189,9 +251,9 @@ var ClientStore = class {
|
|
|
189
251
|
timedOut = !0, controller.abort();
|
|
190
252
|
}, this.options.timeoutMs);
|
|
191
253
|
try {
|
|
192
|
-
let
|
|
193
|
-
if (
|
|
194
|
-
let response2 = await fetch(new URL(resourceVersionManifestPath(id, this.options.channel,
|
|
254
|
+
let selectedVersion = this.versionFor(id), path = selectedVersion === void 0 ? resourcePublicMainPath(id, this.options.channel) : resourceVersionMainPath(id, this.options.channel, selectedVersion), expectedVersionId = selectedVersion === void 0 ? void 0 : previous?.main.versionId, origin = resourceDeliveryOrigin(this.options.environment, this.options.visibility);
|
|
255
|
+
if (selectedVersion !== void 0 && !expectedVersionId) {
|
|
256
|
+
let response2 = await fetch(new URL(resourceVersionManifestPath(id, this.options.channel, selectedVersion), origin), {
|
|
195
257
|
method: "GET",
|
|
196
258
|
cache: "no-store",
|
|
197
259
|
credentials: "omit",
|
|
@@ -207,7 +269,7 @@ var ClientStore = class {
|
|
|
207
269
|
throw new PrismError("IDENTITY_MISMATCH", `Version manifest identity does not match ${id}`, { resourceId: id });
|
|
208
270
|
expectedVersionId = manifest.versionId;
|
|
209
271
|
}
|
|
210
|
-
let response = await fetch(new URL(path,
|
|
272
|
+
let response = await fetch(new URL(path, origin), {
|
|
211
273
|
method: "GET",
|
|
212
274
|
cache: "no-store",
|
|
213
275
|
credentials: "omit",
|
|
@@ -280,6 +342,8 @@ var Prism = class _Prism {
|
|
|
280
342
|
|
|
281
343
|
export {
|
|
282
344
|
PrismError,
|
|
345
|
+
registerReadObserver,
|
|
346
|
+
resolveEnvVersionOverrides,
|
|
283
347
|
storeFor,
|
|
284
348
|
Prism
|
|
285
349
|
};
|