@jini-ai/devops 0.4.0 → 0.5.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/CHANGELOG.md +125 -0
- package/README.md +62 -2
- package/dist/agent-jobs/entry.d.ts +4 -0
- package/dist/agent-jobs/entry.js +4 -0
- package/dist/agent-jobs/jobs.d.ts +25 -0
- package/dist/agent-jobs/jobs.js +115 -0
- package/dist/agent-jobs/node.d.ts +12 -0
- package/dist/agent-jobs/node.js +53 -0
- package/dist/agent-jobs/ports.d.ts +69 -0
- package/dist/agent-jobs/ports.js +2 -0
- package/dist/checks/coverage/diff.d.ts +57 -0
- package/dist/checks/coverage/diff.js +48 -0
- package/dist/checks/coverage/disk.d.ts +65 -0
- package/dist/checks/coverage/disk.js +136 -0
- package/dist/checks/coverage/floors.d.ts +31 -0
- package/dist/checks/coverage/floors.js +24 -0
- package/dist/checks/coverage/index.d.ts +7 -0
- package/dist/checks/coverage/index.js +6 -0
- package/dist/checks/coverage/integrity.d.ts +79 -0
- package/dist/checks/coverage/integrity.js +140 -0
- package/dist/checks/coverage/lcov.d.ts +65 -0
- package/dist/checks/coverage/lcov.js +64 -0
- package/dist/checks/node.d.ts +19 -0
- package/dist/checks/node.js +40 -0
- package/dist/checks/ports.d.ts +67 -0
- package/dist/checks/ports.js +2 -0
- package/dist/checks/published-types/index.d.ts +77 -0
- package/dist/checks/published-types/index.js +186 -0
- package/dist/deploy/host-kit.d.ts +27 -10
- package/dist/deploy/naming.d.ts +8 -4
- package/dist/deploy/naming.js +4 -5
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +42 -12
- package/dist/deploy/reachability.js +75 -69
- package/dist/deploy/redirect-guard.d.ts +7 -2
- package/dist/deploy/redirect-guard.js +3 -3
- package/dist/deploy/tokens.d.ts +14 -11
- package/dist/deploy/tokens.js +13 -13
- package/dist/deploy/tool.d.ts +9 -5
- package/dist/deploy/tool.js +5 -6
- package/dist/deploy/types.d.ts +22 -10
- package/dist/deploy/types.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-dev/index.d.ts +55 -0
- package/dist/local-dev/index.js +68 -0
- package/dist/packaging/electron/archive.d.ts +41 -0
- package/dist/packaging/electron/archive.js +77 -0
- package/dist/packaging/electron/asar-adapter.d.ts +13 -0
- package/dist/packaging/electron/asar-adapter.js +5 -0
- package/dist/packaging/electron/entry.d.ts +9 -0
- package/dist/packaging/electron/entry.js +9 -0
- package/dist/packaging/electron/imports.d.ts +13 -0
- package/dist/packaging/electron/imports.js +44 -0
- package/dist/packaging/electron/node.d.ts +8 -0
- package/dist/packaging/electron/node.js +51 -0
- package/dist/packaging/electron/policies.d.ts +64 -0
- package/dist/packaging/electron/policies.js +63 -0
- package/dist/packaging/electron/ports.d.ts +113 -0
- package/dist/packaging/electron/ports.js +2 -0
- package/dist/packaging/electron/stability.d.ts +9 -0
- package/dist/packaging/electron/stability.js +12 -0
- package/dist/packaging/electron/staging.d.ts +108 -0
- package/dist/packaging/electron/staging.js +249 -0
- package/dist/packaging/electron/typescript.d.ts +7 -0
- package/dist/packaging/electron/typescript.js +18 -0
- package/dist/source-control/commit.d.ts +11 -0
- package/dist/source-control/commit.js +71 -0
- package/dist/source-control/contracts.d.ts +327 -0
- package/dist/source-control/contracts.js +2 -0
- package/dist/source-control/entry.d.ts +6 -0
- package/dist/source-control/entry.js +6 -0
- package/dist/source-control/kit.d.ts +15 -0
- package/dist/source-control/kit.js +17 -0
- package/dist/source-control/registry.d.ts +100 -0
- package/dist/source-control/registry.js +174 -0
- package/dist/source-control/repository-target.d.ts +13 -0
- package/dist/source-control/repository-target.js +28 -0
- package/dist/static-export/contracts.d.ts +138 -0
- package/dist/static-export/contracts.js +5 -0
- package/dist/static-export/entry.d.ts +6 -0
- package/dist/static-export/entry.js +6 -0
- package/dist/static-export/failure-summary.d.ts +12 -0
- package/dist/static-export/failure-summary.js +12 -0
- package/dist/static-export/fetch-adapter.d.ts +6 -0
- package/dist/static-export/fetch-adapter.js +5 -0
- package/dist/static-export/node-adapters.d.ts +11 -0
- package/dist/static-export/node-adapters.js +111 -0
- package/dist/static-export/runner.d.ts +6 -0
- package/dist/static-export/runner.js +135 -0
- package/dist/static-export/transforms.d.ts +53 -0
- package/dist/static-export/transforms.js +154 -0
- package/package.json +82 -5
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
2
|
+
import type { ExportReport } from '../static-export/contracts.js';
|
|
3
|
+
/** Repository-relative bytes, passed unchanged to the provider. */
|
|
4
|
+
export interface CommitFile {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly data: string | Buffer;
|
|
7
|
+
}
|
|
8
|
+
export type SourceControlCommitResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
branch: string;
|
|
11
|
+
branchCreated: boolean;
|
|
12
|
+
commitSha: string;
|
|
13
|
+
commitUrl: string;
|
|
14
|
+
filesChanged: number;
|
|
15
|
+
filesDeleted: number;
|
|
16
|
+
divergedPaths?: readonly string[];
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
code: 'repository-not-found' | 'no-changes' | 'diverged' | 'network-unreachable' | 'provider-error';
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
export interface CommitSiteInput {
|
|
23
|
+
readonly token: string;
|
|
24
|
+
readonly owner: string;
|
|
25
|
+
readonly repo: string;
|
|
26
|
+
readonly commitMessage: string;
|
|
27
|
+
readonly files: readonly CommitFile[];
|
|
28
|
+
}
|
|
29
|
+
export type ProviderCallFailure = {
|
|
30
|
+
ok: false;
|
|
31
|
+
code: 'provider-error';
|
|
32
|
+
message: string;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
code: 'network-unreachable';
|
|
36
|
+
message: string;
|
|
37
|
+
logDetail: string;
|
|
38
|
+
};
|
|
39
|
+
export interface CredentialedRepositoryTarget {
|
|
40
|
+
readonly baseUrl: string;
|
|
41
|
+
readonly authorization: string;
|
|
42
|
+
readonly owner: string;
|
|
43
|
+
readonly repo: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WriteFile {
|
|
46
|
+
readonly path: string;
|
|
47
|
+
readonly content: string;
|
|
48
|
+
}
|
|
49
|
+
export interface FileWriteState {
|
|
50
|
+
readonly path: string;
|
|
51
|
+
readonly exists: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface FileWritePlan {
|
|
54
|
+
readonly parentCommitSha: string;
|
|
55
|
+
readonly baseTreeSha: string;
|
|
56
|
+
readonly fileStates: readonly FileWriteState[];
|
|
57
|
+
}
|
|
58
|
+
export type FileWritePlanResult = {
|
|
59
|
+
ok: true;
|
|
60
|
+
plan: FileWritePlan;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
code: 'branch-not-found';
|
|
64
|
+
message: string;
|
|
65
|
+
} | ProviderCallFailure;
|
|
66
|
+
export type CommitFilesResult = {
|
|
67
|
+
ok: true;
|
|
68
|
+
commitSha: string;
|
|
69
|
+
commitUrl: string;
|
|
70
|
+
} | {
|
|
71
|
+
ok: false;
|
|
72
|
+
code: 'diverged';
|
|
73
|
+
message: string;
|
|
74
|
+
} | ProviderCallFailure;
|
|
75
|
+
export interface BackupRepositoryState {
|
|
76
|
+
readonly branch: string;
|
|
77
|
+
readonly parentCommitSha: string;
|
|
78
|
+
readonly baseTreeSha: string;
|
|
79
|
+
readonly htmlUrl: string;
|
|
80
|
+
readonly folderExists: boolean;
|
|
81
|
+
}
|
|
82
|
+
export type InspectBackupRepositoryFailureCode = 'repo-not-found' | 'repo-not-private' | 'no-push-permission' | 'repo-empty' | 'branch-not-found' | 'folder-is-file';
|
|
83
|
+
export type InspectBackupRepositoryResult = {
|
|
84
|
+
ok: true;
|
|
85
|
+
state: BackupRepositoryState;
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
code: InspectBackupRepositoryFailureCode;
|
|
89
|
+
message: string;
|
|
90
|
+
} | ProviderCallFailure;
|
|
91
|
+
export interface UploadedBackupBlob {
|
|
92
|
+
readonly path: string;
|
|
93
|
+
readonly blobSha: string;
|
|
94
|
+
readonly bytes: number;
|
|
95
|
+
readonly sha256: string;
|
|
96
|
+
}
|
|
97
|
+
export interface CommitBackupTreeInput extends CredentialedRepositoryTarget {
|
|
98
|
+
readonly branch: string;
|
|
99
|
+
readonly folder: string;
|
|
100
|
+
readonly commitMessage: string;
|
|
101
|
+
readonly parentCommitSha: string;
|
|
102
|
+
readonly baseTreeSha: string;
|
|
103
|
+
readonly htmlUrl: string;
|
|
104
|
+
readonly blobs: readonly UploadedBackupBlob[];
|
|
105
|
+
}
|
|
106
|
+
export interface SourceControlHostFacts {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly label: string;
|
|
109
|
+
readonly apiOrigin: string;
|
|
110
|
+
readonly maxFileBytes?: number;
|
|
111
|
+
readonly reservedPaths?: readonly string[];
|
|
112
|
+
readonly workflowPaths?: readonly string[];
|
|
113
|
+
}
|
|
114
|
+
/** New module ABI: all required inputs, including an approved write plan, are one object. */
|
|
115
|
+
export interface SourceControlProviderOperations {
|
|
116
|
+
commitSite(required: CommitSiteInput, optional?: {
|
|
117
|
+
branch?: string;
|
|
118
|
+
}): Promise<SourceControlCommitResult>;
|
|
119
|
+
readAccountLabel(required: {
|
|
120
|
+
token: string;
|
|
121
|
+
}): Promise<string | null>;
|
|
122
|
+
planFileWrite(required: CredentialedRepositoryTarget & {
|
|
123
|
+
branch: string;
|
|
124
|
+
files: readonly WriteFile[];
|
|
125
|
+
}): Promise<FileWritePlanResult>;
|
|
126
|
+
commitFiles(required: CredentialedRepositoryTarget & {
|
|
127
|
+
branch: string;
|
|
128
|
+
commitMessage: string;
|
|
129
|
+
files: readonly WriteFile[];
|
|
130
|
+
plan: FileWritePlan;
|
|
131
|
+
}): Promise<CommitFilesResult>;
|
|
132
|
+
inspectBackupRepository(required: CredentialedRepositoryTarget & {
|
|
133
|
+
folder: string;
|
|
134
|
+
}, optional?: {
|
|
135
|
+
branch?: string;
|
|
136
|
+
}): Promise<InspectBackupRepositoryResult>;
|
|
137
|
+
uploadBackupBlob(required: {
|
|
138
|
+
target: CredentialedRepositoryTarget;
|
|
139
|
+
file: {
|
|
140
|
+
path: string;
|
|
141
|
+
content: Uint8Array;
|
|
142
|
+
};
|
|
143
|
+
}): Promise<{
|
|
144
|
+
ok: true;
|
|
145
|
+
blob: UploadedBackupBlob;
|
|
146
|
+
} | ProviderCallFailure>;
|
|
147
|
+
commitBackupTree(required: CommitBackupTreeInput): Promise<CommitFilesResult>;
|
|
148
|
+
}
|
|
149
|
+
export interface RepositoryTarget {
|
|
150
|
+
readonly owner: string;
|
|
151
|
+
readonly repo: string;
|
|
152
|
+
}
|
|
153
|
+
export type RepositoryTargetValidator = (required: RepositoryTarget) => string | null;
|
|
154
|
+
export type SourceControlProvider = SourceControlProviderOperations & SourceControlHostFacts & {
|
|
155
|
+
readonly validateTarget?: RepositoryTargetValidator;
|
|
156
|
+
};
|
|
157
|
+
export interface DescribedTransportError {
|
|
158
|
+
readonly refusal: string | undefined;
|
|
159
|
+
readonly logDetail: string;
|
|
160
|
+
}
|
|
161
|
+
/** Structural guarded HTTP port: the host owns origin/DNS/redirect policy and secret redaction. */
|
|
162
|
+
export type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
163
|
+
/** The host binds guarded/native HTTP through object arguments. */
|
|
164
|
+
export type SourceControlFetchPort = (required: {
|
|
165
|
+
url: string;
|
|
166
|
+
}, optional?: {
|
|
167
|
+
init?: RequestInit;
|
|
168
|
+
}) => Promise<Response>;
|
|
169
|
+
export interface SourceControlProviderKit {
|
|
170
|
+
fetch(required: {
|
|
171
|
+
url: string;
|
|
172
|
+
init: RequestInit;
|
|
173
|
+
}): Promise<Response>;
|
|
174
|
+
redirectGuardInit(required: {
|
|
175
|
+
init: RequestInit;
|
|
176
|
+
}): RequestInit;
|
|
177
|
+
assertNotRedirected(required: {
|
|
178
|
+
response: Response;
|
|
179
|
+
hostName: string;
|
|
180
|
+
}): void;
|
|
181
|
+
isRedirectRefusal(required: {
|
|
182
|
+
error: unknown;
|
|
183
|
+
}): boolean;
|
|
184
|
+
readonly httpClient: HttpClientPort;
|
|
185
|
+
describeTransportError(required: {
|
|
186
|
+
error: unknown;
|
|
187
|
+
}): DescribedTransportError;
|
|
188
|
+
}
|
|
189
|
+
export interface SourceControlProviderModule {
|
|
190
|
+
create(required: {
|
|
191
|
+
kit: SourceControlProviderKit;
|
|
192
|
+
}): SourceControlProviderOperations;
|
|
193
|
+
validateTarget?: RepositoryTargetValidator;
|
|
194
|
+
}
|
|
195
|
+
export interface SourceControlProviderDescriptor extends SourceControlHostFacts {
|
|
196
|
+
readonly module: string;
|
|
197
|
+
readonly credential?: unknown;
|
|
198
|
+
readonly i18n?: unknown;
|
|
199
|
+
}
|
|
200
|
+
export interface LoadedSourceControlProvider {
|
|
201
|
+
readonly descriptor: SourceControlProviderDescriptor;
|
|
202
|
+
readonly pluginId: string;
|
|
203
|
+
readonly module: SourceControlProviderModule;
|
|
204
|
+
}
|
|
205
|
+
export interface SourceControlProviderRegistry {
|
|
206
|
+
list(required: Record<string, never>): readonly LoadedSourceControlProvider[];
|
|
207
|
+
get(required: {
|
|
208
|
+
providerId: string;
|
|
209
|
+
}): LoadedSourceControlProvider | undefined;
|
|
210
|
+
readonly refusals: readonly string[];
|
|
211
|
+
readonly switchedOff: ReadonlyMap<string, string>;
|
|
212
|
+
}
|
|
213
|
+
export type CatalogPackage = {
|
|
214
|
+
pluginId: string;
|
|
215
|
+
state: 'refused';
|
|
216
|
+
reason: string;
|
|
217
|
+
} | {
|
|
218
|
+
pluginId: string;
|
|
219
|
+
state: 'inactive';
|
|
220
|
+
descriptorText: string;
|
|
221
|
+
} | {
|
|
222
|
+
pluginId: string;
|
|
223
|
+
state: 'trusted';
|
|
224
|
+
descriptorText: string;
|
|
225
|
+
importModule(required: {
|
|
226
|
+
relativePath: string;
|
|
227
|
+
}): Promise<unknown>;
|
|
228
|
+
};
|
|
229
|
+
/** Only trusted entries may expose importModule. The adapter must verify activation, digest and realpath containment before import. */
|
|
230
|
+
export interface ProviderCatalogPort {
|
|
231
|
+
list(required: {
|
|
232
|
+
workspaceId: string;
|
|
233
|
+
descriptorFileName: string;
|
|
234
|
+
}): Promise<readonly CatalogPackage[]>;
|
|
235
|
+
}
|
|
236
|
+
export type DescriptorExtensions = {
|
|
237
|
+
credential?: unknown;
|
|
238
|
+
i18n?: unknown;
|
|
239
|
+
};
|
|
240
|
+
export type DescriptorExtensionReader = (required: {
|
|
241
|
+
entry: Readonly<Record<string, unknown>>;
|
|
242
|
+
at: string;
|
|
243
|
+
}) => {
|
|
244
|
+
ok: true;
|
|
245
|
+
extensions: DescriptorExtensions;
|
|
246
|
+
} | {
|
|
247
|
+
ok: false;
|
|
248
|
+
reason: string;
|
|
249
|
+
};
|
|
250
|
+
export interface CredentialResolverPort {
|
|
251
|
+
resolve(required: {
|
|
252
|
+
workspaceId: string;
|
|
253
|
+
providerId: string;
|
|
254
|
+
}): Promise<{
|
|
255
|
+
providerId: string;
|
|
256
|
+
token: string;
|
|
257
|
+
} | null>;
|
|
258
|
+
}
|
|
259
|
+
export interface FileSourcePort {
|
|
260
|
+
export(required: {
|
|
261
|
+
outputDir: string;
|
|
262
|
+
}, optional?: {
|
|
263
|
+
clean?: boolean;
|
|
264
|
+
}): Promise<ExportReport>;
|
|
265
|
+
}
|
|
266
|
+
export interface CommitLayoutPort {
|
|
267
|
+
outputDirectory(required: {
|
|
268
|
+
workspaceId: string;
|
|
269
|
+
providerId: string;
|
|
270
|
+
runId: string;
|
|
271
|
+
}): string;
|
|
272
|
+
cleanup(required: {
|
|
273
|
+
outputDir: string;
|
|
274
|
+
}): Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
export interface CommitExportArgs {
|
|
277
|
+
workspaceId: string;
|
|
278
|
+
owner: string;
|
|
279
|
+
repo: string;
|
|
280
|
+
commitMessage: string;
|
|
281
|
+
providerId: string;
|
|
282
|
+
files: FileSourcePort;
|
|
283
|
+
layout: CommitLayoutPort;
|
|
284
|
+
ids: {
|
|
285
|
+
next(required: Record<string, never>): string;
|
|
286
|
+
};
|
|
287
|
+
/** Must return caller-safe text without credentials. */
|
|
288
|
+
describeError(required: {
|
|
289
|
+
error: unknown;
|
|
290
|
+
}): string;
|
|
291
|
+
}
|
|
292
|
+
export interface CommitOrchestrationArgs extends CommitExportArgs {
|
|
293
|
+
credentials: CredentialResolverPort;
|
|
294
|
+
adapter: Pick<SourceControlProviderOperations, 'commitSite'>;
|
|
295
|
+
}
|
|
296
|
+
export interface CommitOptions {
|
|
297
|
+
branch?: string;
|
|
298
|
+
validateTarget?: RepositoryTargetValidator;
|
|
299
|
+
}
|
|
300
|
+
export type CommitFailureCode = 'INVALID_CONFIG' | 'NO_CREDENTIALS_CONFIGURED' | 'EXPORT_FAILED' | 'REPOSITORY_NOT_FOUND' | 'NO_CHANGES' | 'DIVERGED_BRANCH' | 'NETWORK_UNREACHABLE' | 'PROVIDER_ERROR';
|
|
301
|
+
export type SourceControlCommitOutcome = {
|
|
302
|
+
ok: false;
|
|
303
|
+
code: CommitFailureCode;
|
|
304
|
+
message: string;
|
|
305
|
+
} | {
|
|
306
|
+
ok: true;
|
|
307
|
+
owner: string;
|
|
308
|
+
repo: string;
|
|
309
|
+
branch: string;
|
|
310
|
+
branchCreated: boolean;
|
|
311
|
+
commitSha: string;
|
|
312
|
+
commitUrl: string;
|
|
313
|
+
filesChanged: number;
|
|
314
|
+
filesDeleted: number;
|
|
315
|
+
divergedPaths: readonly string[];
|
|
316
|
+
};
|
|
317
|
+
export type PreviewCommitExportResult = {
|
|
318
|
+
ok: true;
|
|
319
|
+
fileCount: number;
|
|
320
|
+
totalBytes: number;
|
|
321
|
+
paths: string[];
|
|
322
|
+
} | {
|
|
323
|
+
ok: false;
|
|
324
|
+
code: 'INVALID_CONFIG' | 'EXPORT_FAILED';
|
|
325
|
+
message: string;
|
|
326
|
+
};
|
|
327
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
2
|
+
import type { DescribedTransportError, SourceControlFetchPort, SourceControlProviderKit } from './contracts.js';
|
|
3
|
+
/** Build a kit without globals or a silently missing guarded HTTP client. */
|
|
4
|
+
export declare function createSourceControlProviderKit(required: {
|
|
5
|
+
httpClient: HttpClientPort;
|
|
6
|
+
fetch: SourceControlFetchPort;
|
|
7
|
+
describeTransportError(required: {
|
|
8
|
+
error: unknown;
|
|
9
|
+
}): DescribedTransportError;
|
|
10
|
+
}): SourceControlProviderKit;
|
|
11
|
+
/** Adapt a host-selected native/guarded fetch without choosing a global transport. */
|
|
12
|
+
export declare function createSourceControlFetchAdapter(required: {
|
|
13
|
+
fetch: typeof fetch;
|
|
14
|
+
}): SourceControlFetchPort;
|
|
15
|
+
//# sourceMappingURL=kit.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assertNotRedirected, DeployError, redirectGuardInit } from '../deploy/index.js';
|
|
2
|
+
/** Build a kit without globals or a silently missing guarded HTTP client. */
|
|
3
|
+
export function createSourceControlProviderKit(required) {
|
|
4
|
+
return {
|
|
5
|
+
fetch: ({ url, init }) => required.fetch({ url }, { init: redirectGuardInit({ init }) }),
|
|
6
|
+
redirectGuardInit: ({ init }) => redirectGuardInit({ init }),
|
|
7
|
+
assertNotRedirected: ({ response, hostName }) => assertNotRedirected({ resp: response, providerLabel: hostName }),
|
|
8
|
+
isRedirectRefusal: ({ error }) => error instanceof DeployError,
|
|
9
|
+
httpClient: required.httpClient,
|
|
10
|
+
describeTransportError: input => required.describeTransportError(input),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Adapt a host-selected native/guarded fetch without choosing a global transport. */
|
|
14
|
+
export function createSourceControlFetchAdapter(required) {
|
|
15
|
+
return ({ url }, optional = {}) => required.fetch(url, optional.init);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=kit.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { DescriptorExtensionReader, LoadedSourceControlProvider, ProviderCatalogPort, SourceControlProvider, SourceControlProviderDescriptor, SourceControlProviderKit, SourceControlProviderRegistry } from './contracts.js';
|
|
2
|
+
type ParseResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
descriptors: SourceControlProviderDescriptor[];
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
reason: string;
|
|
8
|
+
};
|
|
9
|
+
/** Parse generic host facts; the caller validates credential/i18n extensions. Unknown keys are ignored. */
|
|
10
|
+
export declare function parseSourceControlProvidersFile(required: {
|
|
11
|
+
raw: string;
|
|
12
|
+
readExtensions: DescriptorExtensionReader;
|
|
13
|
+
}): ParseResult;
|
|
14
|
+
/** Fresh instance-local registry; only the catalog can grant the ability to import trusted modules. */
|
|
15
|
+
export declare function loadSourceControlProviderRegistry(required: {
|
|
16
|
+
workspaceId: string;
|
|
17
|
+
descriptorFileName: string;
|
|
18
|
+
catalog: ProviderCatalogPort;
|
|
19
|
+
readExtensions: DescriptorExtensionReader;
|
|
20
|
+
describeError(required: {
|
|
21
|
+
error: unknown;
|
|
22
|
+
}): string;
|
|
23
|
+
}): Promise<SourceControlProviderRegistry>;
|
|
24
|
+
/** Build operations and host facts without allowing module operations to overwrite declared facts. */
|
|
25
|
+
export declare function buildLoadedSourceControlProvider(required: {
|
|
26
|
+
loaded: LoadedSourceControlProvider;
|
|
27
|
+
kit: SourceControlProviderKit;
|
|
28
|
+
}): SourceControlProvider;
|
|
29
|
+
export type BuildSourceControlProviderResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
provider: SourceControlProvider;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
message: string;
|
|
35
|
+
refusals: readonly string[];
|
|
36
|
+
};
|
|
37
|
+
export interface BuildProviderArgs {
|
|
38
|
+
workspaceId: string;
|
|
39
|
+
providerId: string;
|
|
40
|
+
kit: SourceControlProviderKit;
|
|
41
|
+
load(required: {
|
|
42
|
+
workspaceId: string;
|
|
43
|
+
}): Promise<SourceControlProviderRegistry>;
|
|
44
|
+
noProviderMessage(required: {
|
|
45
|
+
registry: SourceControlProviderRegistry;
|
|
46
|
+
providerId: string;
|
|
47
|
+
}): string;
|
|
48
|
+
}
|
|
49
|
+
/** Operator navigation/copy is supplied by the host, with no descriptor or product defaults. */
|
|
50
|
+
export declare function buildSourceControlProvider(required: BuildProviderArgs): Promise<BuildSourceControlProviderResult>;
|
|
51
|
+
export interface BuildProvidersArgs {
|
|
52
|
+
workspaceId: string;
|
|
53
|
+
kit: SourceControlProviderKit;
|
|
54
|
+
load(required: {
|
|
55
|
+
workspaceId: string;
|
|
56
|
+
}): Promise<SourceControlProviderRegistry>;
|
|
57
|
+
noProviderMessage(required: {
|
|
58
|
+
registry: SourceControlProviderRegistry;
|
|
59
|
+
}): string;
|
|
60
|
+
}
|
|
61
|
+
/** Build every enabled provider over the same guarded kit, in catalog order. */
|
|
62
|
+
export declare function buildSourceControlProviders(required: BuildProvidersArgs): Promise<{
|
|
63
|
+
providers: readonly SourceControlProvider[];
|
|
64
|
+
refusals: readonly string[];
|
|
65
|
+
noProviderMessage: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** Build and select a provider for one custom credential's API origin. */
|
|
68
|
+
export declare function buildSourceControlProviderForApi(required: BuildProvidersArgs & {
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
}): Promise<BuildSourceControlProviderResult>;
|
|
71
|
+
/** Find the folder or ancestor that has provider-defined reserved semantics, ignoring case. */
|
|
72
|
+
export declare function findReservedPath(required: {
|
|
73
|
+
folder: string;
|
|
74
|
+
}, optional?: {
|
|
75
|
+
reservedPaths?: readonly string[];
|
|
76
|
+
}): string | undefined;
|
|
77
|
+
/** Workflow recognition is case-sensitive and relative to repository root. */
|
|
78
|
+
export declare function isUnderWorkflowPath(required: {
|
|
79
|
+
filePath: string;
|
|
80
|
+
}, optional?: {
|
|
81
|
+
workflowPaths?: readonly string[];
|
|
82
|
+
}): boolean;
|
|
83
|
+
/** URL origin or undefined for malformed URLs. */
|
|
84
|
+
export declare function originOf(required: {
|
|
85
|
+
url: string;
|
|
86
|
+
}): string | undefined;
|
|
87
|
+
/** Exact API-origin match first; a sole provider may serve a self-hosted origin. */
|
|
88
|
+
export declare function pickSourceControlProviderForApi(required: {
|
|
89
|
+
providers: readonly SourceControlProvider[];
|
|
90
|
+
baseUrl: string;
|
|
91
|
+
noProviderMessage: string;
|
|
92
|
+
}): {
|
|
93
|
+
ok: true;
|
|
94
|
+
provider: SourceControlProvider;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
message: string;
|
|
98
|
+
};
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
function object(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
|
2
|
+
function relativeModule(value) {
|
|
3
|
+
return typeof value === 'string' && value.endsWith('.mjs') && !/[\\\x00-\x1f\x7f:]/.test(value) && value.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..');
|
|
4
|
+
}
|
|
5
|
+
function httpsOrigin(value) {
|
|
6
|
+
if (typeof value !== 'string')
|
|
7
|
+
return false;
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(value);
|
|
10
|
+
return url.protocol === 'https:' && url.origin === value;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function pathList(value) {
|
|
17
|
+
return Array.isArray(value) && value.length <= 20 && value.every(entry => typeof entry === 'string' && entry.length <= 200 && !/[\\\x00-\x1f\x7f:]/.test(entry) && entry.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..'));
|
|
18
|
+
}
|
|
19
|
+
function parseDescriptor(entry, at, readExtensions) {
|
|
20
|
+
if (!object(entry))
|
|
21
|
+
return `${at} must be an object`;
|
|
22
|
+
const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths, module } = entry;
|
|
23
|
+
if (typeof id !== 'string' || id.length > 64 || /\s/.test(id) || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id))
|
|
24
|
+
return `${at}.id must be a lowercase hyphenated id`;
|
|
25
|
+
if (typeof label !== 'string' || label.trim() === '' || label.length > 100)
|
|
26
|
+
return `${at}.label must be a non-empty string`;
|
|
27
|
+
if (!httpsOrigin(apiOrigin))
|
|
28
|
+
return `${at}.apiOrigin must be an https origin with no path`;
|
|
29
|
+
if (maxFileBytes !== undefined && (typeof maxFileBytes !== 'number' || !Number.isSafeInteger(maxFileBytes) || maxFileBytes <= 0))
|
|
30
|
+
return `${at}.maxFileBytes must be a positive integer`;
|
|
31
|
+
if (reservedPaths !== undefined && !pathList(reservedPaths))
|
|
32
|
+
return `${at}.reservedPaths must be a list of at most 20 relative folder paths`;
|
|
33
|
+
if (workflowPaths !== undefined && !pathList(workflowPaths))
|
|
34
|
+
return `${at}.workflowPaths must be a list of at most 20 relative folder paths`;
|
|
35
|
+
if (!relativeModule(module))
|
|
36
|
+
return `${at}.module must be a relative path ending in .mjs`;
|
|
37
|
+
const extras = readExtensions({ entry, at });
|
|
38
|
+
if (!extras.ok)
|
|
39
|
+
return extras.reason;
|
|
40
|
+
return { ...extras.extensions, id, label, apiOrigin, module, ...(typeof maxFileBytes === 'number' ? { maxFileBytes } : {}), ...(pathList(reservedPaths) ? { reservedPaths } : {}), ...(pathList(workflowPaths) ? { workflowPaths } : {}) };
|
|
41
|
+
}
|
|
42
|
+
/** Parse generic host facts; the caller validates credential/i18n extensions. Unknown keys are ignored. */
|
|
43
|
+
export function parseSourceControlProvidersFile(required) {
|
|
44
|
+
let value;
|
|
45
|
+
try {
|
|
46
|
+
value = JSON.parse(required.raw);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return { ok: false, reason: 'not valid JSON' };
|
|
50
|
+
}
|
|
51
|
+
if (!object(value) || value.schemaVersion !== 1)
|
|
52
|
+
return { ok: false, reason: 'schemaVersion must be 1' };
|
|
53
|
+
if (!Array.isArray(value.providers))
|
|
54
|
+
return { ok: false, reason: 'providers must be an array' };
|
|
55
|
+
const descriptors = [];
|
|
56
|
+
for (const [index, entry] of value.providers.entries()) {
|
|
57
|
+
const descriptor = parseDescriptor(entry, `providers[${index}]`, required.readExtensions);
|
|
58
|
+
if (typeof descriptor === 'string')
|
|
59
|
+
return { ok: false, reason: descriptor };
|
|
60
|
+
if (descriptors.some(prior => prior.id === descriptor.id))
|
|
61
|
+
return { ok: false, reason: `providers[${index}].id '${descriptor.id}' is declared twice` };
|
|
62
|
+
descriptors.push(descriptor);
|
|
63
|
+
}
|
|
64
|
+
return { ok: true, descriptors };
|
|
65
|
+
}
|
|
66
|
+
function moduleError(value) {
|
|
67
|
+
if (!object(value) || typeof value.create !== 'function')
|
|
68
|
+
return 'its module has no create() function';
|
|
69
|
+
if (value.validateTarget !== undefined && typeof value.validateTarget !== 'function')
|
|
70
|
+
return "its module's validateTarget is not a function";
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
/** Fresh instance-local registry; only the catalog can grant the ability to import trusted modules. */
|
|
74
|
+
export async function loadSourceControlProviderRegistry(required) {
|
|
75
|
+
const packages = [...await required.catalog.list({ workspaceId: required.workspaceId, descriptorFileName: required.descriptorFileName })].sort((a, b) => a.pluginId < b.pluginId ? -1 : a.pluginId > b.pluginId ? 1 : 0);
|
|
76
|
+
const providers = [];
|
|
77
|
+
const refusals = [];
|
|
78
|
+
const switchedOff = new Map();
|
|
79
|
+
for (const item of packages) {
|
|
80
|
+
if (item.state === 'refused') {
|
|
81
|
+
refusals.push(`${item.pluginId}: ${item.reason}`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = parseSourceControlProvidersFile({ raw: item.descriptorText, readExtensions: required.readExtensions });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
refusals.push(`${item.pluginId}: ${required.describeError({ error })}`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!parsed.ok) {
|
|
93
|
+
refusals.push(`${item.pluginId}: ${parsed.reason}`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (item.state === 'inactive') {
|
|
97
|
+
for (const descriptor of parsed.descriptors)
|
|
98
|
+
if (!switchedOff.has(descriptor.id))
|
|
99
|
+
switchedOff.set(descriptor.id, item.pluginId);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
for (const descriptor of parsed.descriptors) {
|
|
103
|
+
try {
|
|
104
|
+
const candidate = await item.importModule({ relativePath: descriptor.module });
|
|
105
|
+
const reason = moduleError(candidate);
|
|
106
|
+
if (reason) {
|
|
107
|
+
refusals.push(`${item.pluginId}/${descriptor.id}: ${reason}`);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
providers.push({ descriptor, pluginId: item.pluginId, module: candidate });
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
refusals.push(`${item.pluginId}/${descriptor.id}: ${required.describeError({ error })}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const frozen = Object.freeze(providers.slice());
|
|
118
|
+
return { list: () => frozen, get: ({ providerId }) => frozen.find(provider => provider.descriptor.id === providerId), refusals: Object.freeze(refusals.slice()), switchedOff };
|
|
119
|
+
}
|
|
120
|
+
/** Build operations and host facts without allowing module operations to overwrite declared facts. */
|
|
121
|
+
export function buildLoadedSourceControlProvider(required) {
|
|
122
|
+
const { loaded, kit } = required;
|
|
123
|
+
const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths } = loaded.descriptor;
|
|
124
|
+
return { ...loaded.module.create({ kit }), ...(loaded.module.validateTarget ? { validateTarget: loaded.module.validateTarget } : {}), id, label, apiOrigin,
|
|
125
|
+
...(maxFileBytes !== undefined ? { maxFileBytes } : {}), ...(reservedPaths !== undefined ? { reservedPaths } : {}), ...(workflowPaths !== undefined ? { workflowPaths } : {}) };
|
|
126
|
+
}
|
|
127
|
+
/** Operator navigation/copy is supplied by the host, with no descriptor or product defaults. */
|
|
128
|
+
export async function buildSourceControlProvider(required) {
|
|
129
|
+
const registry = await required.load({ workspaceId: required.workspaceId });
|
|
130
|
+
const loaded = registry.get({ providerId: required.providerId });
|
|
131
|
+
if (!loaded)
|
|
132
|
+
return { ok: false, message: required.noProviderMessage({ registry, providerId: required.providerId }), refusals: registry.refusals };
|
|
133
|
+
return { ok: true, provider: buildLoadedSourceControlProvider({ loaded, kit: required.kit }) };
|
|
134
|
+
}
|
|
135
|
+
/** Build every enabled provider over the same guarded kit, in catalog order. */
|
|
136
|
+
export async function buildSourceControlProviders(required) {
|
|
137
|
+
const registry = await required.load({ workspaceId: required.workspaceId });
|
|
138
|
+
return { providers: registry.list({}).map(loaded => buildLoadedSourceControlProvider({ loaded, kit: required.kit })), refusals: registry.refusals, noProviderMessage: required.noProviderMessage({ registry }) };
|
|
139
|
+
}
|
|
140
|
+
/** Build and select a provider for one custom credential's API origin. */
|
|
141
|
+
export async function buildSourceControlProviderForApi(required) {
|
|
142
|
+
const built = await buildSourceControlProviders(required);
|
|
143
|
+
const picked = pickSourceControlProviderForApi({ providers: built.providers, baseUrl: required.baseUrl, noProviderMessage: built.noProviderMessage });
|
|
144
|
+
if (picked.ok)
|
|
145
|
+
return picked;
|
|
146
|
+
return { ...picked, refusals: built.refusals };
|
|
147
|
+
}
|
|
148
|
+
/** Find the folder or ancestor that has provider-defined reserved semantics, ignoring case. */
|
|
149
|
+
export function findReservedPath(required, optional = {}) {
|
|
150
|
+
const lower = required.folder.toLowerCase();
|
|
151
|
+
return optional.reservedPaths?.find(reserved => lower === reserved.toLowerCase() || lower.startsWith(`${reserved.toLowerCase()}/`));
|
|
152
|
+
}
|
|
153
|
+
/** Workflow recognition is case-sensitive and relative to repository root. */
|
|
154
|
+
export function isUnderWorkflowPath(required, optional = {}) {
|
|
155
|
+
return optional.workflowPaths?.some(folder => required.filePath.startsWith(`${folder}/`)) ?? false;
|
|
156
|
+
}
|
|
157
|
+
/** URL origin or undefined for malformed URLs. */
|
|
158
|
+
export function originOf(required) {
|
|
159
|
+
try {
|
|
160
|
+
return new URL(required.url).origin;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Exact API-origin match first; a sole provider may serve a self-hosted origin. */
|
|
167
|
+
export function pickSourceControlProviderForApi(required) {
|
|
168
|
+
const origin = originOf({ url: required.baseUrl });
|
|
169
|
+
const match = required.providers.find(provider => originOf({ url: provider.apiOrigin }) === origin) ?? (required.providers.length === 1 ? required.providers[0] : undefined);
|
|
170
|
+
if (match)
|
|
171
|
+
return { ok: true, provider: match };
|
|
172
|
+
return { ok: false, message: required.providers.length === 0 ? required.noProviderMessage : `No enabled provider supplies source control for ${origin ?? required.baseUrl}.` };
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RepositoryTarget, RepositoryTargetValidator } from './contracts.js';
|
|
2
|
+
/** Host rules precede the common one-URL-segment rule. Returns caller-safe refusal text. */
|
|
3
|
+
export declare function repositoryTargetError(required: RepositoryTarget, optional?: {
|
|
4
|
+
validateTarget?: RepositoryTargetValidator;
|
|
5
|
+
}): string | null;
|
|
6
|
+
/** Validate before resolving credentials or exporting bytes. */
|
|
7
|
+
export declare function validateCommitTarget(required: RepositoryTarget & {
|
|
8
|
+
commitMessage: string;
|
|
9
|
+
}, optional?: {
|
|
10
|
+
validateTarget?: RepositoryTargetValidator;
|
|
11
|
+
branch?: string;
|
|
12
|
+
}): string | null;
|
|
13
|
+
//# sourceMappingURL=repository-target.d.ts.map
|