@dp-bohrium/widget-sdk 0.7.0 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { n as MemoryTransport, t as ProtocolEndpoint } from "../protocol-endpoint-CDz-YDGT.js";
1
+ import { n as MemoryTransport, t as ProtocolEndpoint } from "../protocol-endpoint-DbT0OJNu.js";
2
2
  //#region src/runtime/mock-host.ts
3
3
  const widgetMessageTypes = /* @__PURE__ */ new Set([
4
4
  "ready",
package/dist/contracts.js CHANGED
@@ -1,2 +1,3 @@
1
- import { i as isWidgetActivationEvent, n as isWidgetEventName, r as WIDGET_ACTIVATION_EVENTS, t as WIDGET_EVENT_NAMES } from "./widget-events-BT0QxR-H.js";
2
- export { WIDGET_ACTIVATION_EVENTS, WIDGET_EVENT_NAMES, isWidgetActivationEvent, isWidgetEventName };
1
+ import { a as projectWidgetRuntimeDiagnostic, c as WIDGET_EVENT_NAMES, d as isWidgetActivationEvent, i as projectWidgetCapabilityDiagnostic, l as isWidgetEventName, n as createWidgetRecoveryPlan, o as projectWidgetToolchainDiagnostic, r as findWidgetRecoveryRule, s as selectWidgetDevelopmentExtensions, t as WIDGET_RECOVERY_RULES, u as WIDGET_ACTIVATION_EVENTS } from "./widget-recovery-BF_sSUZX.js";
2
+ import { n as isWidgetGuestDiagnostic, r as isWidgetRenderResult, t as isWidgetDevelopmentOffer } from "./development-guards-COvBR0G1.js";
3
+ export { WIDGET_ACTIVATION_EVENTS, WIDGET_EVENT_NAMES, WIDGET_RECOVERY_RULES, createWidgetRecoveryPlan, findWidgetRecoveryRule, isWidgetActivationEvent, isWidgetDevelopmentOffer, isWidgetEventName, isWidgetGuestDiagnostic, isWidgetRenderResult, projectWidgetCapabilityDiagnostic, projectWidgetRuntimeDiagnostic, projectWidgetToolchainDiagnostic, selectWidgetDevelopmentExtensions };
@@ -0,0 +1,136 @@
1
+ //#region src/protocol/generated-development-policy.ts
2
+ /** GENERATED FILE. Do not edit directly. */
3
+ const widgetDevelopmentPolicy = {
4
+ "required": [
5
+ "schemaVersion",
6
+ "source",
7
+ "code",
8
+ "phase",
9
+ "operation",
10
+ "severity",
11
+ "message"
12
+ ],
13
+ "keys": [
14
+ "schemaVersion",
15
+ "source",
16
+ "code",
17
+ "sourceCode",
18
+ "phase",
19
+ "sourcePhase",
20
+ "operation",
21
+ "severity",
22
+ "message",
23
+ "retryable",
24
+ "correlationId",
25
+ "diagnostics",
26
+ "io"
27
+ ],
28
+ "textMax": {
29
+ "code": 96,
30
+ "sourceCode": 96,
31
+ "sourcePhase": 96,
32
+ "operation": 96,
33
+ "message": 1024,
34
+ "field": 128,
35
+ "expected": 256,
36
+ "observed": 256,
37
+ "file": 256,
38
+ "excerpt": 1024
39
+ },
40
+ "maxDetails": 8,
41
+ "phases": [
42
+ "discovery",
43
+ "build",
44
+ "config",
45
+ "load",
46
+ "handshake",
47
+ "render",
48
+ "update",
49
+ "capability",
50
+ "dispose"
51
+ ],
52
+ "severities": [
53
+ "warning",
54
+ "request-error",
55
+ "instance-failure"
56
+ ],
57
+ "identifierPattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
58
+ "filePattern": "^(?!/)(?!.*\\\\)(?!.*:)(?!.*(?:^|/)\\.{1,2}(?:/|$))[^\\u0000-\\u001f]+$"
59
+ };
60
+ //#endregion
61
+ //#region src/protocol/development-guards.ts
62
+ function record(value) {
63
+ return value !== null && typeof value === "object" && !Array.isArray(value);
64
+ }
65
+ function keys(value, required, allowed = required) {
66
+ return required.every((key) => Object.hasOwn(value, key)) && Object.keys(value).every((key) => allowed.includes(key));
67
+ }
68
+ const identifier = new RegExp(widgetDevelopmentPolicy.identifierPattern, "u");
69
+ const sourceFile = new RegExp(widgetDevelopmentPolicy.filePattern, "u");
70
+ function text(value, max, empty = false) {
71
+ return typeof value === "string" && (empty || value.length > 0) && [...value].length <= max;
72
+ }
73
+ function correlation(value) {
74
+ return typeof value === "string" && value.length > 0;
75
+ }
76
+ function id(value) {
77
+ return text(value, widgetDevelopmentPolicy.textMax.code) && identifier.test(value);
78
+ }
79
+ function detail(value) {
80
+ if (!record(value)) return false;
81
+ if ("file" in value) return keys(value, [
82
+ "file",
83
+ "line",
84
+ "column"
85
+ ], [
86
+ "file",
87
+ "line",
88
+ "column",
89
+ "excerpt"
90
+ ]) && text(value["file"], widgetDevelopmentPolicy.textMax.file) && sourceFile.test(value["file"]) && Number.isSafeInteger(value["line"]) && Number(value["line"]) > 0 && Number.isSafeInteger(value["column"]) && Number(value["column"]) > 0 && (value["excerpt"] === void 0 || text(value["excerpt"], widgetDevelopmentPolicy.textMax.excerpt));
91
+ return keys(value, ["field"], [
92
+ "field",
93
+ "expected",
94
+ "observed"
95
+ ]) && text(value["field"], widgetDevelopmentPolicy.textMax.field) && (value["expected"] === void 0 || text(value["expected"], widgetDevelopmentPolicy.textMax.expected, true)) && (value["observed"] === void 0 || text(value["observed"], widgetDevelopmentPolicy.textMax.observed, true));
96
+ }
97
+ function io(value) {
98
+ if (!record(value) || !keys(value, ["kind"], [
99
+ "kind",
100
+ "status",
101
+ "sourceCode"
102
+ ]) || value["sourceCode"] !== void 0 && !id(value["sourceCode"])) return false;
103
+ if (value["kind"] === "http") return Number.isInteger(value["status"]) && Number(value["status"]) >= 100 && Number(value["status"]) <= 599 && !(Number(value["status"]) >= 200 && Number(value["status"]) < 300);
104
+ return (value["kind"] === "transport" || value["kind"] === "invalid-response") && value["status"] === void 0;
105
+ }
106
+ /** 与源头 Schema 同源限额的轻量边界判定,不加载 AJV 或 Runtime。 */
107
+ function isWidgetGuestDiagnostic(value) {
108
+ if (!record(value) || !keys(value, widgetDevelopmentPolicy.required, widgetDevelopmentPolicy.keys) || value["schemaVersion"] !== 1 || value["source"] !== "sdk" || !id(value["code"]) || !id(value["operation"]) || !widgetDevelopmentPolicy.phases.some((phase) => phase === value["phase"]) || !widgetDevelopmentPolicy.severities.some((severity) => severity === value["severity"]) || !text(value["message"], widgetDevelopmentPolicy.textMax.message)) return false;
109
+ if (value["retryable"] !== void 0 && typeof value["retryable"] !== "boolean" || value["correlationId"] !== void 0 && !correlation(value["correlationId"]) || value["sourceCode"] !== void 0 && !id(value["sourceCode"]) || value["sourcePhase"] !== void 0 && !id(value["sourcePhase"])) return false;
110
+ return (value["diagnostics"] === void 0 || Array.isArray(value["diagnostics"]) && value["diagnostics"].length <= widgetDevelopmentPolicy.maxDetails && value["diagnostics"].every(detail)) && (value["io"] === void 0 || io(value["io"]));
111
+ }
112
+ /** offer 只声明解析能力;实际 iframe 来源与 attempt 由 Host 校验。 */
113
+ function isWidgetDevelopmentOffer(value) {
114
+ return record(value) && keys(value, [
115
+ "type",
116
+ "protocolVersion",
117
+ "extensions"
118
+ ]) && value["type"] === "widget-bootstrap-offer" && value["protocolVersion"] === 1 && Array.isArray(value["extensions"]) && value["extensions"].length === 1 && value["extensions"][0] === "development-diagnostics-v1";
119
+ }
120
+ /** 失败回执仍需 Host 再匹配实际已发送的 request/revision。 */
121
+ function isWidgetRenderResult(value) {
122
+ if (!record(value) || !correlation(value["requestId"]) || !Number.isSafeInteger(value["revision"]) || Number(value["revision"]) < 1) return false;
123
+ if (value["outcome"] === "handled" || value["outcome"] === "superseded") return keys(value, [
124
+ "requestId",
125
+ "revision",
126
+ "outcome"
127
+ ]);
128
+ return value["outcome"] === "failed" && keys(value, [
129
+ "requestId",
130
+ "revision",
131
+ "outcome",
132
+ "diagnostic"
133
+ ]) && isWidgetGuestDiagnostic(value["diagnostic"]) && value["diagnostic"].correlationId === value["requestId"] && (value["diagnostic"].phase === "render" || value["diagnostic"].phase === "update");
134
+ }
135
+ //#endregion
136
+ export { isWidgetGuestDiagnostic as n, isWidgetRenderResult as r, isWidgetDevelopmentOffer as t };