@koed-labs/server 0.0.0-stage → 0.10.3
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/LICENSE +201 -0
- package/README.md +64 -2
- package/bin/koed.js +7 -0
- package/package.json +26 -4
- package/third-party-notices.json +92 -0
- package/vendor/chunk-2BWTLF7A.js +13883 -0
- package/vendor/chunk-2DA7EFZV.js +924 -0
- package/vendor/chunk-2S3OGPUC.js +58 -0
- package/vendor/chunk-473OA62O.js +26827 -0
- package/vendor/chunk-6JRWGOQG.js +236 -0
- package/vendor/chunk-7NOQSX4T.js +14 -0
- package/vendor/chunk-7NXKPDF3.js +1586 -0
- package/vendor/chunk-A4NKL2PK.js +153 -0
- package/vendor/chunk-A6WMU2GG.js +48 -0
- package/vendor/chunk-AFLKCQHF.js +73 -0
- package/vendor/chunk-BTS4ZTF3.js +43 -0
- package/vendor/chunk-C3N4N5HR.js +108 -0
- package/vendor/chunk-DXTAWHY3.js +25 -0
- package/vendor/chunk-G4IIVVJO.js +56 -0
- package/vendor/chunk-GELDEJJ2.js +4337 -0
- package/vendor/chunk-HFM6ROJL.js +188 -0
- package/vendor/chunk-HK2H3MVE.js +328 -0
- package/vendor/chunk-HZJK5RWC.js +5088 -0
- package/vendor/chunk-J2L726BC.js +2497 -0
- package/vendor/chunk-JBGD4JLR.js +3779 -0
- package/vendor/chunk-JJNLH5GA.js +2470 -0
- package/vendor/chunk-JKOG52PE.js +128 -0
- package/vendor/chunk-K2EIFEQF.js +89 -0
- package/vendor/chunk-KUIWH33N.js +16 -0
- package/vendor/chunk-NEWIOOM6.js +34 -0
- package/vendor/chunk-NM5NXCVM.js +2404 -0
- package/vendor/chunk-PT3AUPGE.js +459 -0
- package/vendor/chunk-PY5LYLV7.js +143 -0
- package/vendor/chunk-QIIKMG3M.js +103 -0
- package/vendor/chunk-QT24SAW6.js +110 -0
- package/vendor/chunk-RVYJKKWA.js +22 -0
- package/vendor/chunk-SKVYP7NY.js +1647 -0
- package/vendor/chunk-TSRPHKAC.js +780 -0
- package/vendor/chunk-UI5RLBKQ.js +30 -0
- package/vendor/chunk-VPC5NLZG.js +259 -0
- package/vendor/chunk-W2HNI6AA.js +75 -0
- package/vendor/chunk-X6M525ZJ.js +20 -0
- package/vendor/chunk-XIZVLPHZ.js +18 -0
- package/vendor/chunk-XNFVSVBS.js +242 -0
- package/vendor/chunk-YCDEMYY6.js +2076 -0
- package/vendor/chunk-YJ6XUZT6.js +292 -0
- package/vendor/chunk-YJWREXN6.js +26020 -0
- package/vendor/chunk-YK4F4VY2.js +173 -0
- package/vendor/chunk-YOFI4PCH.js +36 -0
- package/vendor/chunk-ZUGNCQZE.js +247 -0
- package/vendor/chunk-ZXX4ZNJY.js +21 -0
- package/vendor/cli.js +7 -0
- package/vendor/component-manifest-catalog.js +8 -0
- package/vendor/control-plane.js +23 -0
- package/vendor/package.json +1 -0
- package/vendor/privacy-service-bootstrap.js +6 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/koed-server/dist/project-team-workspace-links.js
|
|
4
|
+
import { existsSync, readFileSync, renameSync, writeFileSync, mkdirSync } from "node:fs";
|
|
5
|
+
import { dirname, resolve } from "node:path";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
var depsWithDefaults = (deps = {}) => ({
|
|
8
|
+
existsSync: deps.existsSync ?? existsSync,
|
|
9
|
+
readFileSync: deps.readFileSync ?? readFileSync,
|
|
10
|
+
writeFileSync: deps.writeFileSync ?? writeFileSync,
|
|
11
|
+
renameSync: deps.renameSync ?? renameSync,
|
|
12
|
+
mkdirSync: deps.mkdirSync ?? mkdirSync,
|
|
13
|
+
now: deps.now ?? (() => /* @__PURE__ */ new Date())
|
|
14
|
+
});
|
|
15
|
+
var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
16
|
+
var normalizeProjectRoot = (projectRoot) => {
|
|
17
|
+
const trimmed = projectRoot.trim();
|
|
18
|
+
if (!trimmed) {
|
|
19
|
+
throw new Error("Project root is required.");
|
|
20
|
+
}
|
|
21
|
+
return resolve(trimmed);
|
|
22
|
+
};
|
|
23
|
+
var validateTeamWorkspaceId = (teamWorkspaceId) => {
|
|
24
|
+
const trimmed = teamWorkspaceId.trim();
|
|
25
|
+
if (!uuidPattern.test(trimmed)) {
|
|
26
|
+
throw new Error("Team Workspace id must be a UUID.");
|
|
27
|
+
}
|
|
28
|
+
return trimmed;
|
|
29
|
+
};
|
|
30
|
+
var validateBackendId = (backendId) => {
|
|
31
|
+
const trimmed = backendId?.trim();
|
|
32
|
+
if (!trimmed) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{1,63}$/.test(trimmed)) {
|
|
36
|
+
throw new Error("Backend id must be 2-64 characters of letters, numbers, hyphen, or underscore.");
|
|
37
|
+
}
|
|
38
|
+
return trimmed;
|
|
39
|
+
};
|
|
40
|
+
var linkIdForProjectRoot = (projectRoot) => `ptw_${createHash("sha256").update(projectRoot).digest("hex").slice(0, 16)}`;
|
|
41
|
+
var validateLocalProjectId = (value) => {
|
|
42
|
+
if (typeof value !== "string")
|
|
43
|
+
return null;
|
|
44
|
+
const trimmed = value.trim();
|
|
45
|
+
return /^lp_[a-f0-9]{16,64}$/i.test(trimmed) ? trimmed : null;
|
|
46
|
+
};
|
|
47
|
+
var validateIdentityId = (value) => typeof value === "string" && uuidPattern.test(value.trim()) ? value.trim().toLowerCase() : null;
|
|
48
|
+
var normalizeLink = (value) => {
|
|
49
|
+
if (typeof value.projectRoot !== "string" || typeof value.teamWorkspaceId !== "string") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const projectRoot = normalizeProjectRoot(value.projectRoot);
|
|
53
|
+
const teamWorkspaceId = validateTeamWorkspaceId(value.teamWorkspaceId);
|
|
54
|
+
const backendId = typeof value.backendId === "string" ? validateBackendId(value.backendId) : null;
|
|
55
|
+
const remotePrincipalId = validateIdentityId(value.remotePrincipalId);
|
|
56
|
+
const deviceCredentialId = validateIdentityId(value.deviceCredentialId);
|
|
57
|
+
if (backendId && (!remotePrincipalId || !deviceCredentialId))
|
|
58
|
+
return null;
|
|
59
|
+
return {
|
|
60
|
+
id: typeof value.id === "string" ? value.id : linkIdForProjectRoot(projectRoot),
|
|
61
|
+
projectRoot,
|
|
62
|
+
teamWorkspaceId,
|
|
63
|
+
backendId,
|
|
64
|
+
remotePrincipalId: backendId ? remotePrincipalId : null,
|
|
65
|
+
deviceCredentialId: backendId ? deviceCredentialId : null,
|
|
66
|
+
localProjectId: validateLocalProjectId(value.localProjectId),
|
|
67
|
+
projectDisplayName: typeof value.projectDisplayName === "string" && value.projectDisplayName.trim() ? value.projectDisplayName.trim().slice(0, 120) : null,
|
|
68
|
+
createdAt: typeof value.createdAt === "string" ? value.createdAt : (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
69
|
+
updatedAt: typeof value.updatedAt === "string" ? value.updatedAt : (/* @__PURE__ */ new Date(0)).toISOString()
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var readStore = (paths, deps) => {
|
|
73
|
+
const now = deps.now().toISOString();
|
|
74
|
+
if (!deps.existsSync(paths.projectTeamWorkspaceLinksPath)) {
|
|
75
|
+
return { schemaVersion: 1, updatedAt: now, links: [] };
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(deps.readFileSync(paths.projectTeamWorkspaceLinksPath, "utf8"));
|
|
79
|
+
return {
|
|
80
|
+
schemaVersion: parsed.schemaVersion === 2 ? 2 : 1,
|
|
81
|
+
updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : now,
|
|
82
|
+
links: Array.isArray(parsed.links) ? parsed.links.map((link) => normalizeLink(link)).filter((link) => Boolean(link)) : []
|
|
83
|
+
};
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error("Project Team Workspace link config is malformed.", {
|
|
86
|
+
cause: error
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var writeStore = (paths, store, deps) => {
|
|
91
|
+
deps.mkdirSync(dirname(paths.projectTeamWorkspaceLinksPath), {
|
|
92
|
+
recursive: true,
|
|
93
|
+
mode: 448
|
|
94
|
+
});
|
|
95
|
+
const tmpPath = `${paths.projectTeamWorkspaceLinksPath}.tmp`;
|
|
96
|
+
deps.writeFileSync(tmpPath, `${JSON.stringify(store, null, 2)}
|
|
97
|
+
`, {
|
|
98
|
+
mode: 384
|
|
99
|
+
});
|
|
100
|
+
deps.renameSync(tmpPath, paths.projectTeamWorkspaceLinksPath);
|
|
101
|
+
};
|
|
102
|
+
var linkProjectTeamWorkspace = (paths, input, depsInput = {}) => {
|
|
103
|
+
const deps = depsWithDefaults(depsInput);
|
|
104
|
+
const now = deps.now().toISOString();
|
|
105
|
+
const projectRoot = normalizeProjectRoot(input.projectRoot);
|
|
106
|
+
const teamWorkspaceId = validateTeamWorkspaceId(input.teamWorkspaceId);
|
|
107
|
+
const backendId = validateBackendId(input.backendId);
|
|
108
|
+
const remotePrincipalId = validateIdentityId(input.remotePrincipalId);
|
|
109
|
+
const deviceCredentialId = validateIdentityId(input.deviceCredentialId);
|
|
110
|
+
if (backendId && (!remotePrincipalId || !deviceCredentialId)) {
|
|
111
|
+
throw new Error("Backend Project links require the remote principal and device credential identity.");
|
|
112
|
+
}
|
|
113
|
+
const store = readStore(paths, deps);
|
|
114
|
+
const existing = store.links.find((link2) => link2.projectRoot === projectRoot);
|
|
115
|
+
const link = {
|
|
116
|
+
id: existing?.id ?? linkIdForProjectRoot(projectRoot),
|
|
117
|
+
projectRoot,
|
|
118
|
+
teamWorkspaceId,
|
|
119
|
+
backendId,
|
|
120
|
+
remotePrincipalId: backendId ? remotePrincipalId : null,
|
|
121
|
+
deviceCredentialId: backendId ? deviceCredentialId : null,
|
|
122
|
+
localProjectId: validateLocalProjectId(input.localProjectId) ?? existing?.localProjectId ?? null,
|
|
123
|
+
projectDisplayName: input.projectDisplayName?.trim() ? input.projectDisplayName.trim().slice(0, 120) : existing?.projectDisplayName ?? null,
|
|
124
|
+
createdAt: existing?.createdAt ?? now,
|
|
125
|
+
updatedAt: now
|
|
126
|
+
};
|
|
127
|
+
const nextLinks = [
|
|
128
|
+
...store.links.filter((candidate) => candidate.projectRoot !== projectRoot),
|
|
129
|
+
link
|
|
130
|
+
].sort((left, right) => left.projectRoot.localeCompare(right.projectRoot));
|
|
131
|
+
writeStore(paths, { schemaVersion: 2, updatedAt: now, links: nextLinks }, deps);
|
|
132
|
+
return {
|
|
133
|
+
ok: true,
|
|
134
|
+
state: "linked",
|
|
135
|
+
message: "Project linked to Team Workspace.",
|
|
136
|
+
link
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
var listProjectTeamWorkspaceLinks = (paths, depsInput = {}) => {
|
|
140
|
+
const store = readStore(paths, depsWithDefaults(depsInput));
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
state: "listed",
|
|
144
|
+
message: `Found ${store.links.length} Project Team Workspace link(s).`,
|
|
145
|
+
links: store.links
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
var getProjectTeamWorkspaceLink = (paths, projectRoot, depsInput = {}) => {
|
|
149
|
+
const normalizedProjectRoot = normalizeProjectRoot(projectRoot);
|
|
150
|
+
const store = readStore(paths, depsWithDefaults(depsInput));
|
|
151
|
+
const link = store.links.find((candidate) => candidate.projectRoot === normalizedProjectRoot) ?? null;
|
|
152
|
+
if (!link) {
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
state: "missing",
|
|
156
|
+
message: "Project is not linked to a Team Workspace."
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
state: "found",
|
|
162
|
+
message: "Project Team Workspace link found.",
|
|
163
|
+
link
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
var removeProjectTeamWorkspaceLink = (paths, projectRoot, depsInput = {}) => {
|
|
167
|
+
const deps = depsWithDefaults(depsInput);
|
|
168
|
+
const normalizedProjectRoot = normalizeProjectRoot(projectRoot);
|
|
169
|
+
const store = readStore(paths, deps);
|
|
170
|
+
const existing = store.links.find((candidate) => candidate.projectRoot === normalizedProjectRoot);
|
|
171
|
+
if (!existing) {
|
|
172
|
+
return {
|
|
173
|
+
ok: false,
|
|
174
|
+
state: "missing",
|
|
175
|
+
message: "Project is not linked to a Team Workspace."
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const now = deps.now().toISOString();
|
|
179
|
+
writeStore(paths, {
|
|
180
|
+
schemaVersion: 2,
|
|
181
|
+
updatedAt: now,
|
|
182
|
+
links: store.links.filter((candidate) => candidate.projectRoot !== normalizedProjectRoot)
|
|
183
|
+
}, deps);
|
|
184
|
+
return {
|
|
185
|
+
ok: true,
|
|
186
|
+
state: "removed",
|
|
187
|
+
message: "Project Team Workspace link removed.",
|
|
188
|
+
link: existing
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
var removeProjectTeamWorkspaceLinksForBackend = (paths, backendId, depsInput = {}) => {
|
|
192
|
+
const deps = depsWithDefaults(depsInput);
|
|
193
|
+
const normalizedBackendId = validateBackendId(backendId);
|
|
194
|
+
if (!normalizedBackendId)
|
|
195
|
+
return 0;
|
|
196
|
+
const store = readStore(paths, deps);
|
|
197
|
+
const links = store.links.filter((link) => link.backendId !== normalizedBackendId);
|
|
198
|
+
const removed = store.links.length - links.length;
|
|
199
|
+
if (removed === 0)
|
|
200
|
+
return 0;
|
|
201
|
+
writeStore(paths, {
|
|
202
|
+
schemaVersion: 2,
|
|
203
|
+
updatedAt: deps.now().toISOString(),
|
|
204
|
+
links
|
|
205
|
+
}, deps);
|
|
206
|
+
return removed;
|
|
207
|
+
};
|
|
208
|
+
var removeProjectTeamWorkspaceLinksForMismatchedBinding = (paths, input, depsInput = {}) => {
|
|
209
|
+
const deps = depsWithDefaults(depsInput);
|
|
210
|
+
const backendId = validateBackendId(input.backendId);
|
|
211
|
+
const remotePrincipalId = validateIdentityId(input.remotePrincipalId);
|
|
212
|
+
const deviceCredentialId = validateIdentityId(input.deviceCredentialId);
|
|
213
|
+
if (!backendId || !remotePrincipalId || !deviceCredentialId) {
|
|
214
|
+
throw new Error("Project link binding is invalid.");
|
|
215
|
+
}
|
|
216
|
+
const store = readStore(paths, deps);
|
|
217
|
+
const nextLinks = store.links.filter((link) => link.backendId !== backendId || link.remotePrincipalId === remotePrincipalId && link.deviceCredentialId === deviceCredentialId);
|
|
218
|
+
const removed = store.links.length - nextLinks.length;
|
|
219
|
+
if (removed === 0)
|
|
220
|
+
return 0;
|
|
221
|
+
writeStore(paths, {
|
|
222
|
+
schemaVersion: 2,
|
|
223
|
+
updatedAt: deps.now().toISOString(),
|
|
224
|
+
links: nextLinks
|
|
225
|
+
}, deps);
|
|
226
|
+
return removed;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export {
|
|
230
|
+
linkProjectTeamWorkspace,
|
|
231
|
+
listProjectTeamWorkspaceLinks,
|
|
232
|
+
getProjectTeamWorkspaceLink,
|
|
233
|
+
removeProjectTeamWorkspaceLink,
|
|
234
|
+
removeProjectTeamWorkspaceLinksForBackend,
|
|
235
|
+
removeProjectTeamWorkspaceLinksForMismatchedBinding
|
|
236
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
environmentWithRepoEnv,
|
|
4
|
+
loadRepoEnv,
|
|
5
|
+
parseEnvFile,
|
|
6
|
+
resolveApiUrl
|
|
7
|
+
} from "./chunk-W2HNI6AA.js";
|
|
8
|
+
import "./chunk-BTS4ZTF3.js";
|
|
9
|
+
export {
|
|
10
|
+
environmentWithRepoEnv,
|
|
11
|
+
loadRepoEnv,
|
|
12
|
+
parseEnvFile,
|
|
13
|
+
resolveApiUrl
|
|
14
|
+
};
|