@boristype/ws-client 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +278 -13
- package/build/client.d.ts +3 -1
- package/build/client.d.ts.map +1 -1
- package/build/client.js +3 -1
- package/build/client.js.map +1 -1
- package/build/evaluator.d.ts +8 -0
- package/build/evaluator.d.ts.map +1 -1
- package/build/evaluator.js +10 -0
- package/build/evaluator.js.map +1 -1
- package/build/hcm/api.d.ts +11 -2
- package/build/hcm/api.d.ts.map +1 -1
- package/build/hcm/api.js +14 -1
- package/build/hcm/api.js.map +1 -1
- package/build/hcm/execute.d.ts +35 -0
- package/build/hcm/execute.d.ts.map +1 -0
- package/build/hcm/execute.js +76 -0
- package/build/hcm/execute.js.map +1 -0
- package/build/hcm/packages/archive-types.d.ts +23 -0
- package/build/hcm/packages/archive-types.d.ts.map +1 -0
- package/build/hcm/packages/archive-types.js +2 -0
- package/build/hcm/packages/archive-types.js.map +1 -0
- package/build/hcm/packages/archive.d.ts +5 -0
- package/build/hcm/packages/archive.d.ts.map +1 -0
- package/build/hcm/packages/archive.js +410 -0
- package/build/hcm/packages/archive.js.map +1 -0
- package/build/hcm/packages/artifacts.d.ts +16 -0
- package/build/hcm/packages/artifacts.d.ts.map +1 -0
- package/build/hcm/packages/artifacts.js +140 -0
- package/build/hcm/packages/artifacts.js.map +1 -0
- package/build/hcm/packages/contracts.d.ts +89 -0
- package/build/hcm/packages/contracts.d.ts.map +1 -0
- package/build/hcm/packages/contracts.js +41 -0
- package/build/hcm/packages/contracts.js.map +1 -0
- package/build/hcm/packages/native.d.ts +5 -0
- package/build/hcm/packages/native.d.ts.map +1 -0
- package/build/hcm/packages/native.js +47 -0
- package/build/hcm/packages/native.js.map +1 -0
- package/build/hcm/packages/schemas.d.ts +121 -0
- package/build/hcm/packages/schemas.d.ts.map +1 -0
- package/build/hcm/packages/schemas.js +94 -0
- package/build/hcm/packages/schemas.js.map +1 -0
- package/build/hcm/packages/service.d.ts +215 -0
- package/build/hcm/packages/service.d.ts.map +1 -0
- package/build/hcm/packages/service.js +420 -0
- package/build/hcm/packages/service.js.map +1 -0
- package/build/hcm/packages/transfer.d.ts +6 -0
- package/build/hcm/packages/transfer.d.ts.map +1 -0
- package/build/hcm/packages/transfer.js +81 -0
- package/build/hcm/packages/transfer.js.map +1 -0
- package/build/hcm/schemas.d.ts +98 -0
- package/build/hcm/schemas.d.ts.map +1 -1
- package/build/hcm/schemas.js +18 -0
- package/build/hcm/schemas.js.map +1 -1
- package/build/hcm/system-info.d.ts +24 -0
- package/build/hcm/system-info.d.ts.map +1 -0
- package/build/hcm/system-info.js +57 -0
- package/build/hcm/system-info.js.map +1 -0
- package/build/hcm/xquery.d.ts +4 -3
- package/build/hcm/xquery.d.ts.map +1 -1
- package/build/hcm/xquery.js +3 -28
- package/build/hcm/xquery.js.map +1 -1
- package/build/index.d.ts +12 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -0
- package/build/index.js.map +1 -1
- package/build/soap-utils.d.ts +8 -14
- package/build/soap-utils.d.ts.map +1 -1
- package/build/soap-utils.js +205 -169
- package/build/soap-utils.js.map +1 -1
- package/build/types.d.ts +9 -0
- package/build/types.d.ts.map +1 -1
- package/build/value-projection.d.ts +8 -0
- package/build/value-projection.d.ts.map +1 -0
- package/build/value-projection.js +101 -0
- package/build/value-projection.js.map +1 -0
- package/build/xquery.d.ts +28 -0
- package/build/xquery.d.ts.map +1 -0
- package/build/xquery.js +63 -0
- package/build/xquery.js.map +1 -0
- package/package.json +7 -2
- package/resources/execute.bs +40 -0
- package/resources/package-operation.bs +318 -0
- package/resources/value-projection.bs +79 -0
- package/resources/xquery.bs +16 -24
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { PackageArtifact } from "./artifacts.js";
|
|
3
|
+
import type { WshcmEvaluator } from "../types.js";
|
|
4
|
+
import { packageSchemas } from "./schemas.js";
|
|
5
|
+
import { type PackagePage, type PackageSchema, type PackageSchemaSummary } from "./contracts.js";
|
|
6
|
+
import { PackageArtifactStore } from "./artifacts.js";
|
|
7
|
+
type Input<K extends keyof typeof packageSchemas> = z.input<(typeof packageSchemas)[K]>;
|
|
8
|
+
export interface PackageInspectionItem {
|
|
9
|
+
kind: "package" | "object";
|
|
10
|
+
packageId: string;
|
|
11
|
+
type: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
nameTruncated?: boolean;
|
|
15
|
+
conflict?: boolean;
|
|
16
|
+
versionMismatch?: boolean;
|
|
17
|
+
alreadyImported?: boolean;
|
|
18
|
+
serverVersion?: string;
|
|
19
|
+
hasCustomTemplates?: boolean;
|
|
20
|
+
hasAccessRoles?: boolean;
|
|
21
|
+
hasLists?: boolean;
|
|
22
|
+
deletionCount?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class WshcmPackages {
|
|
25
|
+
private readonly evaluator;
|
|
26
|
+
private tail;
|
|
27
|
+
private readonly snapshots;
|
|
28
|
+
private readonly inspections;
|
|
29
|
+
private readonly operationArtifacts;
|
|
30
|
+
readonly artifacts: PackageArtifactStore;
|
|
31
|
+
constructor(evaluator: WshcmEvaluator, options?: {
|
|
32
|
+
artifactDirectory?: string;
|
|
33
|
+
});
|
|
34
|
+
private run;
|
|
35
|
+
private record;
|
|
36
|
+
private expected;
|
|
37
|
+
listSchemas(input?: Input<"listSchemas">): Promise<PackagePage<PackageSchemaSummary>>;
|
|
38
|
+
getSchema(input: Input<"getSchema">): Promise<PackageSchema>;
|
|
39
|
+
private read;
|
|
40
|
+
private change;
|
|
41
|
+
saveSchema(input: Input<"saveSchema">): Promise<{
|
|
42
|
+
revision: string;
|
|
43
|
+
schemaId: string;
|
|
44
|
+
operation: {
|
|
45
|
+
operationId: string;
|
|
46
|
+
accountId: string;
|
|
47
|
+
targetId: string;
|
|
48
|
+
operation: string;
|
|
49
|
+
phase: string;
|
|
50
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
51
|
+
verification: "platform_report_only" | "archive_membership";
|
|
52
|
+
error: string;
|
|
53
|
+
reportIds: string[];
|
|
54
|
+
downloadIds: string[];
|
|
55
|
+
};
|
|
56
|
+
errors: string[];
|
|
57
|
+
}>;
|
|
58
|
+
deleteSchema(input: Input<"deleteSchema">): Promise<{
|
|
59
|
+
schemaId: string;
|
|
60
|
+
operation: {
|
|
61
|
+
operationId: string;
|
|
62
|
+
accountId: string;
|
|
63
|
+
targetId: string;
|
|
64
|
+
operation: string;
|
|
65
|
+
phase: string;
|
|
66
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
67
|
+
verification: "platform_report_only" | "archive_membership";
|
|
68
|
+
error: string;
|
|
69
|
+
reportIds: string[];
|
|
70
|
+
downloadIds: string[];
|
|
71
|
+
};
|
|
72
|
+
errors: string[];
|
|
73
|
+
}>;
|
|
74
|
+
addObjects(input: Input<"addObjects">): Promise<{
|
|
75
|
+
revision: string;
|
|
76
|
+
schemaId: string;
|
|
77
|
+
operation: {
|
|
78
|
+
operationId: string;
|
|
79
|
+
accountId: string;
|
|
80
|
+
targetId: string;
|
|
81
|
+
operation: string;
|
|
82
|
+
phase: string;
|
|
83
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
84
|
+
verification: "platform_report_only" | "archive_membership";
|
|
85
|
+
error: string;
|
|
86
|
+
reportIds: string[];
|
|
87
|
+
downloadIds: string[];
|
|
88
|
+
};
|
|
89
|
+
errors: string[];
|
|
90
|
+
}>;
|
|
91
|
+
removeObjects(input: Input<"removeObjects">): Promise<{
|
|
92
|
+
revision: string;
|
|
93
|
+
schemaId: string;
|
|
94
|
+
operation: {
|
|
95
|
+
operationId: string;
|
|
96
|
+
accountId: string;
|
|
97
|
+
targetId: string;
|
|
98
|
+
operation: string;
|
|
99
|
+
phase: string;
|
|
100
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
101
|
+
verification: "platform_report_only" | "archive_membership";
|
|
102
|
+
error: string;
|
|
103
|
+
reportIds: string[];
|
|
104
|
+
downloadIds: string[];
|
|
105
|
+
};
|
|
106
|
+
errors: string[];
|
|
107
|
+
}>;
|
|
108
|
+
exportPackage(input: Input<"exportPackage">): Promise<{
|
|
109
|
+
status: "completed" | "partial";
|
|
110
|
+
verification: "archive_membership";
|
|
111
|
+
objects: {
|
|
112
|
+
items: {
|
|
113
|
+
name: string;
|
|
114
|
+
nameTruncated: boolean;
|
|
115
|
+
id: string;
|
|
116
|
+
type: string;
|
|
117
|
+
}[];
|
|
118
|
+
offset: number;
|
|
119
|
+
limit: number;
|
|
120
|
+
total: number;
|
|
121
|
+
};
|
|
122
|
+
missingIds: string[];
|
|
123
|
+
missingCount: number;
|
|
124
|
+
errors: string[];
|
|
125
|
+
operation: {
|
|
126
|
+
operationId: string;
|
|
127
|
+
accountId: string;
|
|
128
|
+
targetId: string;
|
|
129
|
+
operation: string;
|
|
130
|
+
phase: string;
|
|
131
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
132
|
+
verification: "platform_report_only" | "archive_membership";
|
|
133
|
+
error: string;
|
|
134
|
+
reportIds: string[];
|
|
135
|
+
downloadIds: string[];
|
|
136
|
+
};
|
|
137
|
+
cleanupError?: string | undefined;
|
|
138
|
+
operationId: string;
|
|
139
|
+
artifact: PackageArtifact;
|
|
140
|
+
}>;
|
|
141
|
+
private manifest;
|
|
142
|
+
private selection;
|
|
143
|
+
private previewRequest;
|
|
144
|
+
inspectPackage(input: Input<"inspectPackage">): Promise<{
|
|
145
|
+
inspectionId: string;
|
|
146
|
+
artifact: {
|
|
147
|
+
artifactId: string;
|
|
148
|
+
localPath: string;
|
|
149
|
+
mimeType: "application/zip";
|
|
150
|
+
sizeBytes: number;
|
|
151
|
+
sha256: string;
|
|
152
|
+
expiresAt: string;
|
|
153
|
+
};
|
|
154
|
+
operation: {
|
|
155
|
+
operationId: string;
|
|
156
|
+
accountId: string;
|
|
157
|
+
targetId: string;
|
|
158
|
+
operation: string;
|
|
159
|
+
phase: string;
|
|
160
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
161
|
+
verification: "platform_report_only" | "archive_membership";
|
|
162
|
+
error: string;
|
|
163
|
+
reportIds: string[];
|
|
164
|
+
downloadIds: string[];
|
|
165
|
+
};
|
|
166
|
+
items: PackageInspectionItem[];
|
|
167
|
+
offset: number;
|
|
168
|
+
limit: number;
|
|
169
|
+
total: number;
|
|
170
|
+
}>;
|
|
171
|
+
importPackage(input: Input<"importPackage">): Promise<{
|
|
172
|
+
operationId: string;
|
|
173
|
+
accountId: string;
|
|
174
|
+
targetId: string;
|
|
175
|
+
operation: string;
|
|
176
|
+
phase: string;
|
|
177
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
178
|
+
verification: "platform_report_only" | "archive_membership";
|
|
179
|
+
error: string;
|
|
180
|
+
reportIds: string[];
|
|
181
|
+
downloadIds: string[];
|
|
182
|
+
}>;
|
|
183
|
+
getOperation(input: Input<"getOperation">): Promise<{
|
|
184
|
+
artifact?: {
|
|
185
|
+
artifactId: string;
|
|
186
|
+
localPath: string;
|
|
187
|
+
mimeType: "application/zip";
|
|
188
|
+
sizeBytes: number;
|
|
189
|
+
sha256: string;
|
|
190
|
+
expiresAt: string;
|
|
191
|
+
} | undefined;
|
|
192
|
+
operationId: string;
|
|
193
|
+
accountId: string;
|
|
194
|
+
targetId: string;
|
|
195
|
+
operation: string;
|
|
196
|
+
phase: string;
|
|
197
|
+
status: "failed" | "unknown" | "completed" | "running" | "partial";
|
|
198
|
+
verification: "platform_report_only" | "archive_membership";
|
|
199
|
+
error: string;
|
|
200
|
+
reportIds: string[];
|
|
201
|
+
downloadIds: string[];
|
|
202
|
+
}>;
|
|
203
|
+
}
|
|
204
|
+
export type ListPackageSchemasResult = Awaited<ReturnType<WshcmPackages["listSchemas"]>>;
|
|
205
|
+
export type GetPackageSchemaResult = Awaited<ReturnType<WshcmPackages["getSchema"]>>;
|
|
206
|
+
export type SavePackageSchemaResult = Awaited<ReturnType<WshcmPackages["saveSchema"]>>;
|
|
207
|
+
export type DeletePackageSchemaResult = Awaited<ReturnType<WshcmPackages["deleteSchema"]>>;
|
|
208
|
+
export type AddPackageObjectsResult = Awaited<ReturnType<WshcmPackages["addObjects"]>>;
|
|
209
|
+
export type RemovePackageObjectsResult = Awaited<ReturnType<WshcmPackages["removeObjects"]>>;
|
|
210
|
+
export type ExportPackageResult = Awaited<ReturnType<WshcmPackages["exportPackage"]>>;
|
|
211
|
+
export type InspectPackageResult = Awaited<ReturnType<WshcmPackages["inspectPackage"]>>;
|
|
212
|
+
export type ImportPackageResult = Awaited<ReturnType<WshcmPackages["importPackage"]>>;
|
|
213
|
+
export type GetPackageOperationResult = Awaited<ReturnType<WshcmPackages["getOperation"]>>;
|
|
214
|
+
export {};
|
|
215
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/hcm/packages/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,KAAK,KAAK,CAAC,CAAC,SAAS,MAAM,OAAO,cAAc,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAkCxF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAA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B,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;AACtF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACxF,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;AACtF,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { inspectPackageArchive } from "./archive.js";
|
|
7
|
+
import { uploadPackage, downloadPackage, hashRemotePackage } from "./transfer.js";
|
|
8
|
+
import { packageSchemas } from "./schemas.js";
|
|
9
|
+
import { operationResult, schemaResult, schemaSummary, WshcmPackageError, } from "./contracts.js";
|
|
10
|
+
import { packageNative } from "./native.js";
|
|
11
|
+
import { PackageArtifactStore } from "./artifacts.js";
|
|
12
|
+
// Keep public schemas JSON Schema serializable; normalize only public UUID handles
|
|
13
|
+
// after validation and before native dispatch, local map lookup or artifact access.
|
|
14
|
+
function canonicalHandles(args) {
|
|
15
|
+
for (const key of ["operationId", "artifactId", "inspectionId"]) {
|
|
16
|
+
if (key in args) {
|
|
17
|
+
const value = args[key];
|
|
18
|
+
if (typeof value === "string")
|
|
19
|
+
Object.assign(args, { [key]: value.toLowerCase() });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return args;
|
|
23
|
+
}
|
|
24
|
+
const snapshot = z
|
|
25
|
+
.string()
|
|
26
|
+
.max(33554432)
|
|
27
|
+
.refine((v) => Buffer.byteLength(v) <= 33554432);
|
|
28
|
+
const readSchema = z.strictObject({ snapshot, result: schemaResult.omit({ revision: true }) });
|
|
29
|
+
const mutation = z.strictObject({ schemaId: z.string(), operation: operationResult, errors: z.array(z.string()).max(10000) });
|
|
30
|
+
const nativePreview = z.strictObject({
|
|
31
|
+
serverVersion: z.string().max(128),
|
|
32
|
+
parts: z
|
|
33
|
+
.array(z.strictObject({
|
|
34
|
+
id: z.string().max(256),
|
|
35
|
+
type: z.enum(["objects", "courses", "web", "custom_file"]),
|
|
36
|
+
versionMismatch: z.boolean(),
|
|
37
|
+
alreadyImported: z.boolean(),
|
|
38
|
+
objects: z.array(z.strictObject({ id: z.string(), conflict: z.boolean() })).max(10000),
|
|
39
|
+
}))
|
|
40
|
+
.max(10000),
|
|
41
|
+
operation: operationResult,
|
|
42
|
+
});
|
|
43
|
+
export class WshcmPackages {
|
|
44
|
+
evaluator;
|
|
45
|
+
tail = Promise.resolve();
|
|
46
|
+
snapshots = new Map();
|
|
47
|
+
inspections = new Map();
|
|
48
|
+
operationArtifacts = new Map();
|
|
49
|
+
artifacts;
|
|
50
|
+
constructor(evaluator, options = {}) {
|
|
51
|
+
this.evaluator = evaluator;
|
|
52
|
+
this.artifacts = new PackageArtifactStore(options.artifactDirectory);
|
|
53
|
+
}
|
|
54
|
+
run(fn) {
|
|
55
|
+
const next = this.tail.then(fn, fn);
|
|
56
|
+
this.tail = next.catch(() => { });
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
59
|
+
record(xml) {
|
|
60
|
+
const revision = createHash("sha256").update(xml).digest("hex");
|
|
61
|
+
this.snapshots.set(revision, xml);
|
|
62
|
+
if (this.snapshots.size > 32)
|
|
63
|
+
this.snapshots.delete(this.snapshots.keys().next().value);
|
|
64
|
+
return revision;
|
|
65
|
+
}
|
|
66
|
+
expected(revision) {
|
|
67
|
+
const xml = this.snapshots.get(revision);
|
|
68
|
+
if (xml === undefined)
|
|
69
|
+
throw new WshcmPackageError({
|
|
70
|
+
code: "ReadRequired",
|
|
71
|
+
message: "Read the common schema document in this SDK instance",
|
|
72
|
+
phase: "input",
|
|
73
|
+
status: "not_attempted",
|
|
74
|
+
});
|
|
75
|
+
return xml;
|
|
76
|
+
}
|
|
77
|
+
async listSchemas(input = {}) {
|
|
78
|
+
const args = canonicalHandles(packageSchemas.listSchemas.parse(input));
|
|
79
|
+
return this.run(async () => {
|
|
80
|
+
const body = await packageNative(this.evaluator, { operation: "list", operationId: randomUUID(), ...args }, z.strictObject({
|
|
81
|
+
snapshot,
|
|
82
|
+
result: z.strictObject({
|
|
83
|
+
items: z.array(schemaSummary).max(1000),
|
|
84
|
+
total: z.number().int().nonnegative(),
|
|
85
|
+
offset: z.number().int(),
|
|
86
|
+
limit: z.number().int(),
|
|
87
|
+
}),
|
|
88
|
+
}));
|
|
89
|
+
const revision = this.record(body.snapshot);
|
|
90
|
+
return { ...body.result, items: body.result.items.map((v) => ({ ...v, revision })) };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async getSchema(input) {
|
|
94
|
+
const args = canonicalHandles(packageSchemas.getSchema.parse(input));
|
|
95
|
+
return this.run(() => this.read(args));
|
|
96
|
+
}
|
|
97
|
+
async read(args) {
|
|
98
|
+
const body = await packageNative(this.evaluator, { operation: "get", operationId: randomUUID(), ...args }, readSchema);
|
|
99
|
+
return { ...body.result, revision: this.record(body.snapshot) };
|
|
100
|
+
}
|
|
101
|
+
async change(operation, args) {
|
|
102
|
+
const body = await packageNative(this.evaluator, {
|
|
103
|
+
...args,
|
|
104
|
+
operation,
|
|
105
|
+
operationId: args.operationId ?? randomUUID(),
|
|
106
|
+
...(args.revision ? { expected: this.expected(args.revision) } : {}),
|
|
107
|
+
}, mutation);
|
|
108
|
+
try {
|
|
109
|
+
const fresh = await this.read({ schemaId: body.schemaId, offset: 0, limit: 100 });
|
|
110
|
+
return { ...body, revision: fresh.revision };
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw new WshcmPackageError({
|
|
114
|
+
code: "ReadbackError",
|
|
115
|
+
message: String(error).slice(0, 2000),
|
|
116
|
+
operationId: body.operation.operationId,
|
|
117
|
+
phase: "readback",
|
|
118
|
+
status: "unknown",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
saveSchema(input) {
|
|
123
|
+
const args = canonicalHandles(packageSchemas.saveSchema.parse(input));
|
|
124
|
+
return this.run(() => this.change("save", args));
|
|
125
|
+
}
|
|
126
|
+
deleteSchema(input) {
|
|
127
|
+
const args = canonicalHandles(packageSchemas.deleteSchema.parse(input));
|
|
128
|
+
return this.run(() => packageNative(this.evaluator, { ...args, operation: "delete", operationId: args.operationId ?? randomUUID(), expected: this.expected(args.revision) }, mutation));
|
|
129
|
+
}
|
|
130
|
+
addObjects(input) {
|
|
131
|
+
const args = canonicalHandles(packageSchemas.addObjects.parse(input));
|
|
132
|
+
args.objectIds = [...new Set(args.objectIds)];
|
|
133
|
+
return this.run(() => this.change("add", args));
|
|
134
|
+
}
|
|
135
|
+
removeObjects(input) {
|
|
136
|
+
const args = canonicalHandles(packageSchemas.removeObjects.parse(input));
|
|
137
|
+
args.objectIds = [...new Set(args.objectIds)];
|
|
138
|
+
return this.run(() => this.change("remove", args));
|
|
139
|
+
}
|
|
140
|
+
async exportPackage(input) {
|
|
141
|
+
const args = canonicalHandles(packageSchemas.exportPackage.parse(input));
|
|
142
|
+
if (args.objectIds)
|
|
143
|
+
args.objectIds = [...new Set(args.objectIds)];
|
|
144
|
+
return this.run(async () => {
|
|
145
|
+
const operationId = args.operationId ?? randomUUID();
|
|
146
|
+
const result = await packageNative(this.evaluator, { ...args, operation: "export", operationId, ...(args.revision ? { expected: this.expected(args.revision) } : {}) }, z.strictObject({
|
|
147
|
+
sizeBytes: z.number().int().min(0).max(134217728),
|
|
148
|
+
requestedIds: z.array(z.string()).max(10000),
|
|
149
|
+
errors: z.array(z.string()).max(10000),
|
|
150
|
+
operation: operationResult,
|
|
151
|
+
}));
|
|
152
|
+
let directory;
|
|
153
|
+
async function cleanup() {
|
|
154
|
+
if (directory === undefined)
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
await rm(directory, { recursive: true, force: true });
|
|
158
|
+
directory = undefined;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return String(error).slice(0, 2000);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
directory = await mkdtemp(join(tmpdir(), "boristype-package-"));
|
|
166
|
+
const downloaded = await downloadPackage(this.evaluator, operationId, result.sizeBytes, directory);
|
|
167
|
+
const artifact = await this.artifacts.capture(downloaded);
|
|
168
|
+
this.operationArtifacts.set(operationId, artifact);
|
|
169
|
+
const archive = await inspectPackageArchive(artifact.localPath);
|
|
170
|
+
const objects = archive.packages.flatMap((p) => p.objects.map((o) => ({ ...o, name: o.name.slice(0, 4096), nameTruncated: o.name.length > 4096 })));
|
|
171
|
+
const actual = new Set(objects.map((o) => o.id));
|
|
172
|
+
const missing = [...new Set([...(args.objectIds ?? []), ...result.requestedIds])].filter((id) => !actual.has(id));
|
|
173
|
+
result.operation = await packageNative(this.evaluator, { operation: "finish_export", operationId, partial: missing.length > 0 || result.errors.length > 0 }, operationResult);
|
|
174
|
+
const cleanupError = await cleanup();
|
|
175
|
+
return {
|
|
176
|
+
operationId,
|
|
177
|
+
artifact,
|
|
178
|
+
...(cleanupError ? { cleanupError } : {}),
|
|
179
|
+
status: missing.length || result.errors.length || result.operation.status === "partial" ? "partial" : "completed",
|
|
180
|
+
verification: "archive_membership",
|
|
181
|
+
objects: { items: objects.slice(0, 100), offset: 0, limit: 100, total: objects.length },
|
|
182
|
+
missingIds: missing.slice(0, 1000),
|
|
183
|
+
missingCount: missing.length,
|
|
184
|
+
errors: result.errors.slice(0, 100),
|
|
185
|
+
operation: result.operation,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const failure = error instanceof WshcmPackageError
|
|
190
|
+
? error
|
|
191
|
+
: new WshcmPackageError({
|
|
192
|
+
operationId,
|
|
193
|
+
code: "ArchiveError",
|
|
194
|
+
message: String(error).slice(0, 2000),
|
|
195
|
+
phase: "archive",
|
|
196
|
+
status: "unknown",
|
|
197
|
+
});
|
|
198
|
+
failure.details.lastKnownOperation ??= structuredClone(result.operation);
|
|
199
|
+
const cleanupError = await cleanup();
|
|
200
|
+
if (cleanupError)
|
|
201
|
+
failure.details.cleanupError = cleanupError;
|
|
202
|
+
throw failure;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
manifest(archive) {
|
|
207
|
+
if (archive.packages.length > 10000 || archive.packages.reduce((n, p) => n + p.objects.length, 0) > 10000)
|
|
208
|
+
throw new WshcmPackageError({
|
|
209
|
+
code: "InputLimit",
|
|
210
|
+
message: "Preview exceeds 10000 objects/packages",
|
|
211
|
+
phase: "input",
|
|
212
|
+
status: "not_attempted",
|
|
213
|
+
});
|
|
214
|
+
for (const p of archive.packages)
|
|
215
|
+
if (p.url.length > 2048 ||
|
|
216
|
+
(p.baseUrl?.length ?? 0) > 2048 ||
|
|
217
|
+
(p.serverVersion?.length ?? 0) > 128 ||
|
|
218
|
+
p.objects.some((o) => o.type.length > 256))
|
|
219
|
+
throw new WshcmPackageError({
|
|
220
|
+
code: "InputLimit",
|
|
221
|
+
message: "Package metadata exceeds limits",
|
|
222
|
+
phase: "input",
|
|
223
|
+
status: "not_attempted",
|
|
224
|
+
});
|
|
225
|
+
return archive.packages.map((p) => ({
|
|
226
|
+
id: p.id,
|
|
227
|
+
type: p.type,
|
|
228
|
+
url: p.url,
|
|
229
|
+
objectCount: p.objects.length,
|
|
230
|
+
objectTypes: Object.fromEntries(p.objects.map((o) => [o.id, o.type])),
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
selection(inspection, args) {
|
|
234
|
+
const packageIds = args?.packageIds ?? inspection.archive.packages.map((p) => p.id);
|
|
235
|
+
const parts = inspection.archive.packages.filter((p) => packageIds.includes(p.id));
|
|
236
|
+
if (parts.length !== new Set(packageIds).size)
|
|
237
|
+
throw new WshcmPackageError({
|
|
238
|
+
code: "InvalidSelection",
|
|
239
|
+
message: "Package outside inspection",
|
|
240
|
+
phase: "input",
|
|
241
|
+
status: "not_attempted",
|
|
242
|
+
});
|
|
243
|
+
const allowed = new Set(parts.flatMap((p) => p.objects.map((o) => o.id)));
|
|
244
|
+
const objectIds = args?.objectIds ?? [...allowed];
|
|
245
|
+
if (objectIds.some((id) => !allowed.has(id)))
|
|
246
|
+
throw new WshcmPackageError({
|
|
247
|
+
code: "InvalidSelection",
|
|
248
|
+
message: "Object outside selected inspected packages",
|
|
249
|
+
phase: "input",
|
|
250
|
+
status: "not_attempted",
|
|
251
|
+
});
|
|
252
|
+
if (args?.includeFiles)
|
|
253
|
+
for (const p of parts)
|
|
254
|
+
if (p.type === "custom_file" && !/^x-local:\/\/custom\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_.-]+)*\/?$/.test(p.baseUrl ?? ""))
|
|
255
|
+
throw new WshcmPackageError({
|
|
256
|
+
code: "UnsafeDestination",
|
|
257
|
+
message: "custom_file requires a safe destination below x-local://custom/",
|
|
258
|
+
phase: "input",
|
|
259
|
+
status: "not_attempted",
|
|
260
|
+
});
|
|
261
|
+
if (args &&
|
|
262
|
+
objectIds.length === 0 &&
|
|
263
|
+
!args.includeFiles &&
|
|
264
|
+
!args.includeCustomTemplates &&
|
|
265
|
+
!args.includeAccessRoles &&
|
|
266
|
+
!args.includeDeletions &&
|
|
267
|
+
!args.includeLists)
|
|
268
|
+
throw new WshcmPackageError({
|
|
269
|
+
code: "InvalidSelection",
|
|
270
|
+
message: "No inspected objects or explicit extras selected",
|
|
271
|
+
phase: "input",
|
|
272
|
+
status: "not_attempted",
|
|
273
|
+
});
|
|
274
|
+
return {
|
|
275
|
+
selectedPackages: Object.fromEntries(packageIds.map((id) => [id, true])),
|
|
276
|
+
selectedObjects: Object.fromEntries(objectIds.map((id) => [id, true])),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
previewRequest(inspection, args) {
|
|
280
|
+
return {
|
|
281
|
+
sourceId: inspection.sourceId,
|
|
282
|
+
sha256: inspection.artifact.sha256,
|
|
283
|
+
manifest: this.manifest(inspection.archive),
|
|
284
|
+
...this.selection(inspection, args),
|
|
285
|
+
includeFiles: args?.includeFiles ?? false,
|
|
286
|
+
includeCustomTemplates: args?.includeCustomTemplates ?? false,
|
|
287
|
+
includeAccessRoles: args?.includeAccessRoles ?? false,
|
|
288
|
+
includeDeletions: args?.includeDeletions ?? false,
|
|
289
|
+
includeLists: args?.includeLists ?? false,
|
|
290
|
+
allowVersionMismatch: args?.allowVersionMismatch ?? false,
|
|
291
|
+
allowReimport: args?.allowReimport ?? false,
|
|
292
|
+
skipConflictingIds: args?.skipConflictingIds ?? false,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
async inspectPackage(input) {
|
|
296
|
+
const args = canonicalHandles(packageSchemas.inspectPackage.parse(input));
|
|
297
|
+
return this.run(async () => {
|
|
298
|
+
let inspectionId = args.inspectionId;
|
|
299
|
+
let state;
|
|
300
|
+
if (inspectionId) {
|
|
301
|
+
state = this.inspections.get(inspectionId);
|
|
302
|
+
if (!state)
|
|
303
|
+
throw new WshcmPackageError({
|
|
304
|
+
code: "InspectionRequired",
|
|
305
|
+
message: "Unknown inspection in this SDK instance",
|
|
306
|
+
phase: "input",
|
|
307
|
+
status: "not_attempted",
|
|
308
|
+
});
|
|
309
|
+
await this.artifacts.get(state.artifact.artifactId);
|
|
310
|
+
const receipt = await this.getOperation({ operationId: inspectionId });
|
|
311
|
+
if (receipt.accountId !== state.operation.accountId || receipt.targetId !== state.operation.targetId)
|
|
312
|
+
throw new Error("Inspection context changed");
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const artifact = await this.artifacts.capture(args.localPath ?? (await this.artifacts.get(args.artifactId)).localPath);
|
|
316
|
+
const archive = await inspectPackageArchive(artifact.localPath);
|
|
317
|
+
this.manifest(archive);
|
|
318
|
+
inspectionId = args.operationId ?? randomUUID();
|
|
319
|
+
const sourceId = inspectionId;
|
|
320
|
+
const draft = {
|
|
321
|
+
artifact,
|
|
322
|
+
archive,
|
|
323
|
+
sourceId,
|
|
324
|
+
};
|
|
325
|
+
await uploadPackage(this.evaluator, sourceId, artifact);
|
|
326
|
+
const preview = await packageNative(this.evaluator, { operation: "preview", operationId: inspectionId, ...this.previewRequest(draft) }, nativePreview);
|
|
327
|
+
state = { ...draft, operation: preview.operation, items: [], attempted: false };
|
|
328
|
+
for (const part of archive.packages) {
|
|
329
|
+
const native = preview.parts.find((p) => p.id === part.id);
|
|
330
|
+
if (!native)
|
|
331
|
+
throw new Error("Native inspection identity mismatch");
|
|
332
|
+
state.items.push({
|
|
333
|
+
kind: "package",
|
|
334
|
+
packageId: part.id,
|
|
335
|
+
type: part.type,
|
|
336
|
+
versionMismatch: native.versionMismatch,
|
|
337
|
+
alreadyImported: native.alreadyImported,
|
|
338
|
+
...(part.serverVersion ? { serverVersion: part.serverVersion } : {}),
|
|
339
|
+
hasCustomTemplates: part.hasCustomTemplates,
|
|
340
|
+
hasAccessRoles: part.hasAccessRoles,
|
|
341
|
+
hasLists: part.hasLists,
|
|
342
|
+
deletionCount: part.deletedObjectIds.length,
|
|
343
|
+
});
|
|
344
|
+
for (const obj of part.objects) {
|
|
345
|
+
const checked = native.objects.find((o) => o.id === obj.id);
|
|
346
|
+
if (!checked)
|
|
347
|
+
throw new Error("Native inspection object mismatch");
|
|
348
|
+
state.items.push({
|
|
349
|
+
kind: "object",
|
|
350
|
+
packageId: part.id,
|
|
351
|
+
...obj,
|
|
352
|
+
name: obj.name.slice(0, 4096),
|
|
353
|
+
nameTruncated: obj.name.length > 4096,
|
|
354
|
+
conflict: checked.conflict,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
this.inspections.set(inspectionId, state);
|
|
359
|
+
this.operationArtifacts.set(inspectionId, artifact);
|
|
360
|
+
}
|
|
361
|
+
const items = state.items.slice(args.offset, args.offset + args.limit);
|
|
362
|
+
return {
|
|
363
|
+
inspectionId,
|
|
364
|
+
artifact: { ...state.artifact },
|
|
365
|
+
operation: structuredClone(state.operation),
|
|
366
|
+
items: structuredClone(items),
|
|
367
|
+
offset: args.offset,
|
|
368
|
+
limit: args.limit,
|
|
369
|
+
total: state.items.length,
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async importPackage(input) {
|
|
374
|
+
const args = canonicalHandles(packageSchemas.importPackage.parse(input));
|
|
375
|
+
return this.run(async () => {
|
|
376
|
+
const state = this.inspections.get(args.inspectionId);
|
|
377
|
+
if (!state)
|
|
378
|
+
throw new WshcmPackageError({
|
|
379
|
+
code: "InspectionRequired",
|
|
380
|
+
message: "Inspect the archive in this SDK instance first",
|
|
381
|
+
phase: "input",
|
|
382
|
+
status: "not_attempted",
|
|
383
|
+
});
|
|
384
|
+
if (state.attempted && !args.allowReimport)
|
|
385
|
+
throw new WshcmPackageError({
|
|
386
|
+
code: "Reimport",
|
|
387
|
+
message: "An import was already dispatched; query its receipt before another explicit attempt",
|
|
388
|
+
phase: "input",
|
|
389
|
+
status: "not_attempted",
|
|
390
|
+
});
|
|
391
|
+
const request = this.previewRequest(state, args);
|
|
392
|
+
await this.artifacts.get(state.artifact.artifactId);
|
|
393
|
+
if ((await hashRemotePackage(this.evaluator, state.sourceId, state.artifact.sizeBytes)) !== state.artifact.sha256)
|
|
394
|
+
throw new WshcmPackageError({
|
|
395
|
+
code: "IntegrityChanged",
|
|
396
|
+
message: "Remote archive bytes changed",
|
|
397
|
+
phase: "input",
|
|
398
|
+
status: "not_attempted",
|
|
399
|
+
});
|
|
400
|
+
const operationId = args.operationId ?? randomUUID();
|
|
401
|
+
try {
|
|
402
|
+
const result = await packageNative(this.evaluator, { ...request, operation: "import", operationId }, operationResult);
|
|
403
|
+
state.attempted = true;
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
if (!(error instanceof WshcmPackageError) || error.details.status === "unknown")
|
|
408
|
+
state.attempted = true;
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
async getOperation(input) {
|
|
414
|
+
const args = canonicalHandles(packageSchemas.getOperation.parse(input));
|
|
415
|
+
const result = await packageNative(this.evaluator, { operation: "status", ...args }, operationResult);
|
|
416
|
+
const artifact = this.operationArtifacts.get(args.operationId);
|
|
417
|
+
return { ...result, ...(artifact ? { artifact: { ...artifact } } : {}) };
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=service.js.map
|