@boboddy/sdk 0.1.14-alpha → 0.1.16-alpha

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.
Files changed (31) hide show
  1. package/dist/boboddy-config-parser.js +4 -325
  2. package/dist/client.js +2 -1
  3. package/dist/defaults/auth-file.d.ts +14 -0
  4. package/dist/defaults/base-url.d.ts +1 -0
  5. package/dist/defaults/index.d.ts +7 -0
  6. package/dist/defaults/index.js +312 -0
  7. package/dist/defaults/load-push-defaults.d.ts +21 -0
  8. package/dist/defaults/project-config.d.ts +5 -0
  9. package/dist/definitions/advancement-policies/define-advancement-policy.d.ts +4 -0
  10. package/dist/definitions/advancement-policies/fluent-rules.d.ts +82 -0
  11. package/dist/definitions/advancement-policies/index.d.ts +1 -0
  12. package/dist/definitions/advancement-policies/index.js +87 -0
  13. package/dist/definitions/pipelines/builder.d.ts +111 -0
  14. package/dist/definitions/pipelines/define-pipeline.d.ts +24 -52
  15. package/dist/definitions/pipelines/index.d.ts +2 -0
  16. package/dist/definitions/pipelines/index.js +14672 -75
  17. package/dist/definitions/pipelines/input-accessor.d.ts +25 -0
  18. package/dist/definitions/pipelines/pipeline-definitions-client.d.ts +17 -21
  19. package/dist/definitions/steps/define-step.d.ts +17 -4
  20. package/dist/definitions/steps/index.d.ts +1 -0
  21. package/dist/definitions/steps/index.js +1605 -1578
  22. package/dist/definitions/steps/prompt-template.d.ts +16 -0
  23. package/dist/definitions/steps/step-features.d.ts +1 -1
  24. package/dist/generated/types.gen.d.ts +90 -108
  25. package/dist/index.js +1981 -1956
  26. package/dist/jsonc.js +1 -0
  27. package/dist/opencode-mcp.js +1573 -1572
  28. package/dist/push/index.d.ts +2 -0
  29. package/dist/push/index.js +16480 -0
  30. package/dist/push/push-from-directory.d.ts +21 -0
  31. package/package.json +9 -1
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  var __defProp = Object.defineProperty;
2
3
  var __returnValue = (v) => v;
3
4
  function __exportSetter(name, newValue) {
@@ -14,330 +15,8 @@ var __export = (target, all) => {
14
15
  };
15
16
 
16
17
  // src/boboddy-config-parser.ts
17
- var {access, readFile} = (() => ({}));
18
-
19
- // node:path
20
- function assertPath(path) {
21
- if (typeof path !== "string")
22
- throw TypeError("Path must be a string. Received " + JSON.stringify(path));
23
- }
24
- function normalizeStringPosix(path, allowAboveRoot) {
25
- var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
26
- for (var i = 0;i <= path.length; ++i) {
27
- if (i < path.length)
28
- code = path.charCodeAt(i);
29
- else if (code === 47)
30
- break;
31
- else
32
- code = 47;
33
- if (code === 47) {
34
- if (lastSlash === i - 1 || dots === 1)
35
- ;
36
- else if (lastSlash !== i - 1 && dots === 2) {
37
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
38
- if (res.length > 2) {
39
- var lastSlashIndex = res.lastIndexOf("/");
40
- if (lastSlashIndex !== res.length - 1) {
41
- if (lastSlashIndex === -1)
42
- res = "", lastSegmentLength = 0;
43
- else
44
- res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
45
- lastSlash = i, dots = 0;
46
- continue;
47
- }
48
- } else if (res.length === 2 || res.length === 1) {
49
- res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
50
- continue;
51
- }
52
- }
53
- if (allowAboveRoot) {
54
- if (res.length > 0)
55
- res += "/..";
56
- else
57
- res = "..";
58
- lastSegmentLength = 2;
59
- }
60
- } else {
61
- if (res.length > 0)
62
- res += "/" + path.slice(lastSlash + 1, i);
63
- else
64
- res = path.slice(lastSlash + 1, i);
65
- lastSegmentLength = i - lastSlash - 1;
66
- }
67
- lastSlash = i, dots = 0;
68
- } else if (code === 46 && dots !== -1)
69
- ++dots;
70
- else
71
- dots = -1;
72
- }
73
- return res;
74
- }
75
- function _format(sep, pathObject) {
76
- var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
77
- if (!dir)
78
- return base;
79
- if (dir === pathObject.root)
80
- return dir + base;
81
- return dir + sep + base;
82
- }
83
- function resolve() {
84
- var resolvedPath = "", resolvedAbsolute = false, cwd;
85
- for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
86
- var path;
87
- if (i >= 0)
88
- path = arguments[i];
89
- else {
90
- if (cwd === undefined)
91
- cwd = process.cwd();
92
- path = cwd;
93
- }
94
- if (assertPath(path), path.length === 0)
95
- continue;
96
- resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
97
- }
98
- if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
99
- if (resolvedPath.length > 0)
100
- return "/" + resolvedPath;
101
- else
102
- return "/";
103
- else if (resolvedPath.length > 0)
104
- return resolvedPath;
105
- else
106
- return ".";
107
- }
108
- function normalize(path) {
109
- if (assertPath(path), path.length === 0)
110
- return ".";
111
- var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
112
- if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
113
- path = ".";
114
- if (path.length > 0 && trailingSeparator)
115
- path += "/";
116
- if (isAbsolute)
117
- return "/" + path;
118
- return path;
119
- }
120
- function isAbsolute(path) {
121
- return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
122
- }
123
- function join() {
124
- if (arguments.length === 0)
125
- return ".";
126
- var joined;
127
- for (var i = 0;i < arguments.length; ++i) {
128
- var arg = arguments[i];
129
- if (assertPath(arg), arg.length > 0)
130
- if (joined === undefined)
131
- joined = arg;
132
- else
133
- joined += "/" + arg;
134
- }
135
- if (joined === undefined)
136
- return ".";
137
- return normalize(joined);
138
- }
139
- function relative(from, to) {
140
- if (assertPath(from), assertPath(to), from === to)
141
- return "";
142
- if (from = resolve(from), to = resolve(to), from === to)
143
- return "";
144
- var fromStart = 1;
145
- for (;fromStart < from.length; ++fromStart)
146
- if (from.charCodeAt(fromStart) !== 47)
147
- break;
148
- var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
149
- for (;toStart < to.length; ++toStart)
150
- if (to.charCodeAt(toStart) !== 47)
151
- break;
152
- var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
153
- for (;i <= length; ++i) {
154
- if (i === length) {
155
- if (toLen > length) {
156
- if (to.charCodeAt(toStart + i) === 47)
157
- return to.slice(toStart + i + 1);
158
- else if (i === 0)
159
- return to.slice(toStart + i);
160
- } else if (fromLen > length) {
161
- if (from.charCodeAt(fromStart + i) === 47)
162
- lastCommonSep = i;
163
- else if (i === 0)
164
- lastCommonSep = 0;
165
- }
166
- break;
167
- }
168
- var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
169
- if (fromCode !== toCode)
170
- break;
171
- else if (fromCode === 47)
172
- lastCommonSep = i;
173
- }
174
- var out = "";
175
- for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
176
- if (i === fromEnd || from.charCodeAt(i) === 47)
177
- if (out.length === 0)
178
- out += "..";
179
- else
180
- out += "/..";
181
- if (out.length > 0)
182
- return out + to.slice(toStart + lastCommonSep);
183
- else {
184
- if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
185
- ++toStart;
186
- return to.slice(toStart);
187
- }
188
- }
189
- function _makeLong(path) {
190
- return path;
191
- }
192
- function dirname(path) {
193
- if (assertPath(path), path.length === 0)
194
- return ".";
195
- var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
196
- for (var i = path.length - 1;i >= 1; --i)
197
- if (code = path.charCodeAt(i), code === 47) {
198
- if (!matchedSlash) {
199
- end = i;
200
- break;
201
- }
202
- } else
203
- matchedSlash = false;
204
- if (end === -1)
205
- return hasRoot ? "/" : ".";
206
- if (hasRoot && end === 1)
207
- return "//";
208
- return path.slice(0, end);
209
- }
210
- function basename(path, ext) {
211
- if (ext !== undefined && typeof ext !== "string")
212
- throw TypeError('"ext" argument must be a string');
213
- assertPath(path);
214
- var start = 0, end = -1, matchedSlash = true, i;
215
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
216
- if (ext.length === path.length && ext === path)
217
- return "";
218
- var extIdx = ext.length - 1, firstNonSlashEnd = -1;
219
- for (i = path.length - 1;i >= 0; --i) {
220
- var code = path.charCodeAt(i);
221
- if (code === 47) {
222
- if (!matchedSlash) {
223
- start = i + 1;
224
- break;
225
- }
226
- } else {
227
- if (firstNonSlashEnd === -1)
228
- matchedSlash = false, firstNonSlashEnd = i + 1;
229
- if (extIdx >= 0)
230
- if (code === ext.charCodeAt(extIdx)) {
231
- if (--extIdx === -1)
232
- end = i;
233
- } else
234
- extIdx = -1, end = firstNonSlashEnd;
235
- }
236
- }
237
- if (start === end)
238
- end = firstNonSlashEnd;
239
- else if (end === -1)
240
- end = path.length;
241
- return path.slice(start, end);
242
- } else {
243
- for (i = path.length - 1;i >= 0; --i)
244
- if (path.charCodeAt(i) === 47) {
245
- if (!matchedSlash) {
246
- start = i + 1;
247
- break;
248
- }
249
- } else if (end === -1)
250
- matchedSlash = false, end = i + 1;
251
- if (end === -1)
252
- return "";
253
- return path.slice(start, end);
254
- }
255
- }
256
- function extname(path) {
257
- assertPath(path);
258
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
259
- for (var i = path.length - 1;i >= 0; --i) {
260
- var code = path.charCodeAt(i);
261
- if (code === 47) {
262
- if (!matchedSlash) {
263
- startPart = i + 1;
264
- break;
265
- }
266
- continue;
267
- }
268
- if (end === -1)
269
- matchedSlash = false, end = i + 1;
270
- if (code === 46) {
271
- if (startDot === -1)
272
- startDot = i;
273
- else if (preDotState !== 1)
274
- preDotState = 1;
275
- } else if (startDot !== -1)
276
- preDotState = -1;
277
- }
278
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
279
- return "";
280
- return path.slice(startDot, end);
281
- }
282
- function format(pathObject) {
283
- if (pathObject === null || typeof pathObject !== "object")
284
- throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
285
- return _format("/", pathObject);
286
- }
287
- function parse(path) {
288
- assertPath(path);
289
- var ret = { root: "", dir: "", base: "", ext: "", name: "" };
290
- if (path.length === 0)
291
- return ret;
292
- var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
293
- if (isAbsolute2)
294
- ret.root = "/", start = 1;
295
- else
296
- start = 0;
297
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
298
- for (;i >= start; --i) {
299
- if (code = path.charCodeAt(i), code === 47) {
300
- if (!matchedSlash) {
301
- startPart = i + 1;
302
- break;
303
- }
304
- continue;
305
- }
306
- if (end === -1)
307
- matchedSlash = false, end = i + 1;
308
- if (code === 46) {
309
- if (startDot === -1)
310
- startDot = i;
311
- else if (preDotState !== 1)
312
- preDotState = 1;
313
- } else if (startDot !== -1)
314
- preDotState = -1;
315
- }
316
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
317
- if (end !== -1)
318
- if (startPart === 0 && isAbsolute2)
319
- ret.base = ret.name = path.slice(1, end);
320
- else
321
- ret.base = ret.name = path.slice(startPart, end);
322
- } else {
323
- if (startPart === 0 && isAbsolute2)
324
- ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
325
- else
326
- ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
327
- ret.ext = path.slice(startDot, end);
328
- }
329
- if (startPart > 0)
330
- ret.dir = path.slice(0, startPart - 1);
331
- else if (isAbsolute2)
332
- ret.dir = "/";
333
- return ret;
334
- }
335
- var sep = "/";
336
- var delimiter = ":";
337
- var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
338
- var path_default = posix;
339
-
340
- // src/boboddy-config-parser.ts
18
+ import { access, readFile } from "fs/promises";
19
+ import path from "path";
341
20
  var BOBODDY_CONFIG_RELATIVE_PATH = ".boboddy/boboddy.jsonc";
342
21
  var stripJsoncComments = (content) => {
343
22
  let result = "";
@@ -489,7 +168,7 @@ var parseServices = (raw) => {
489
168
  });
490
169
  };
491
170
  async function parseBoboddyConfig(workspacePath) {
492
- const filePath = path_default.join(workspacePath, BOBODDY_CONFIG_RELATIVE_PATH);
171
+ const filePath = path.join(workspacePath, BOBODDY_CONFIG_RELATIVE_PATH);
493
172
  const exists = await access(filePath).then(() => true).catch(() => false);
494
173
  if (!exists) {
495
174
  return { found: false };
package/dist/client.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  var __defProp = Object.defineProperty;
2
3
  var __returnValue = (v) => v;
3
4
  function __exportSetter(name, newValue) {
@@ -240,7 +241,7 @@ var serializePrimitiveParam = ({
240
241
  return "";
241
242
  }
242
243
  if (typeof value === "object") {
243
- throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
244
+ throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");
244
245
  }
245
246
  return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
246
247
  };
@@ -0,0 +1,14 @@
1
+ export interface AuthProfile {
2
+ accessToken: string;
3
+ userId?: string;
4
+ email?: string;
5
+ name?: string;
6
+ }
7
+ export interface AuthFile {
8
+ profiles: Record<string, AuthProfile>;
9
+ }
10
+ export declare const getAuthFilePath: () => string;
11
+ export declare const loadAuthFile: () => AuthFile;
12
+ export declare const loadAuthProfile: (baseUrl: string) => AuthProfile | null;
13
+ export declare const saveAuthProfile: (baseUrl: string, profile: AuthProfile) => void;
14
+ export declare const deleteAuthProfile: (baseUrl: string) => void;
@@ -0,0 +1 @@
1
+ export declare const resolveBoboddyBaseUrl: (value?: string | null) => string;
@@ -0,0 +1,7 @@
1
+ export { deleteAuthProfile, getAuthFilePath, loadAuthFile, loadAuthProfile, saveAuthProfile, } from "./auth-file";
2
+ export type { AuthFile, AuthProfile } from "./auth-file";
3
+ export { resolveBoboddyBaseUrl } from "./base-url";
4
+ export { loadProjectConfig, PROJECT_CONFIG_RELATIVE_PATH, } from "./project-config";
5
+ export type { ProjectConfig } from "./project-config";
6
+ export { loadPushDefaults } from "./load-push-defaults";
7
+ export type { LoadPushDefaultsOptions, PushDefaults, } from "./load-push-defaults";
@@ -0,0 +1,312 @@
1
+ // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+
17
+ // src/jsonc.ts
18
+ var stripJsoncComments = (content) => {
19
+ let result = "";
20
+ let inString = false;
21
+ let escapeNextCharacter = false;
22
+ let lineComment = false;
23
+ let blockComment = false;
24
+ for (let index = 0;index < content.length; index += 1) {
25
+ const character = content.charAt(index);
26
+ const nextCharacter = content.charAt(index + 1);
27
+ if (lineComment) {
28
+ if (character === `
29
+ `) {
30
+ lineComment = false;
31
+ result += character;
32
+ }
33
+ continue;
34
+ }
35
+ if (blockComment) {
36
+ if (character === "*" && nextCharacter === "/") {
37
+ blockComment = false;
38
+ index += 1;
39
+ }
40
+ continue;
41
+ }
42
+ if (inString) {
43
+ result += character;
44
+ if (escapeNextCharacter) {
45
+ escapeNextCharacter = false;
46
+ continue;
47
+ }
48
+ if (character === "\\") {
49
+ escapeNextCharacter = true;
50
+ continue;
51
+ }
52
+ if (character === '"') {
53
+ inString = false;
54
+ }
55
+ continue;
56
+ }
57
+ if (character === '"') {
58
+ inString = true;
59
+ result += character;
60
+ continue;
61
+ }
62
+ if (character === "/" && nextCharacter === "/") {
63
+ lineComment = true;
64
+ index += 1;
65
+ continue;
66
+ }
67
+ if (character === "/" && nextCharacter === "*") {
68
+ blockComment = true;
69
+ index += 1;
70
+ continue;
71
+ }
72
+ result += character;
73
+ }
74
+ return result;
75
+ };
76
+ var stripTrailingCommas = (content) => {
77
+ let result = "";
78
+ let inString = false;
79
+ let escapeNextCharacter = false;
80
+ for (let index = 0;index < content.length; index += 1) {
81
+ const character = content.charAt(index);
82
+ if (inString) {
83
+ result += character;
84
+ if (escapeNextCharacter) {
85
+ escapeNextCharacter = false;
86
+ continue;
87
+ }
88
+ if (character === "\\") {
89
+ escapeNextCharacter = true;
90
+ continue;
91
+ }
92
+ if (character === '"') {
93
+ inString = false;
94
+ }
95
+ continue;
96
+ }
97
+ if (character === '"') {
98
+ inString = true;
99
+ result += character;
100
+ continue;
101
+ }
102
+ if (character === ",") {
103
+ let lookaheadIndex = index + 1;
104
+ while (lookaheadIndex < content.length) {
105
+ const lookaheadCharacter2 = content.charAt(lookaheadIndex);
106
+ if (/\s/u.test(lookaheadCharacter2)) {
107
+ lookaheadIndex += 1;
108
+ continue;
109
+ }
110
+ if (lookaheadCharacter2 === "}" || lookaheadCharacter2 === "]") {
111
+ break;
112
+ }
113
+ result += character;
114
+ break;
115
+ }
116
+ if (lookaheadIndex >= content.length) {
117
+ continue;
118
+ }
119
+ const lookaheadCharacter = content.charAt(lookaheadIndex);
120
+ if (lookaheadCharacter === "}" || lookaheadCharacter === "]") {
121
+ continue;
122
+ }
123
+ continue;
124
+ }
125
+ result += character;
126
+ }
127
+ return result;
128
+ };
129
+ var parseJsonc = (content) => JSON.parse(stripTrailingCommas(stripJsoncComments(content)));
130
+
131
+ // src/defaults/auth-file.ts
132
+ import {
133
+ chmodSync,
134
+ existsSync,
135
+ lstatSync,
136
+ mkdirSync,
137
+ readFileSync,
138
+ renameSync,
139
+ rmSync,
140
+ writeFileSync
141
+ } from "fs";
142
+ import { dirname, join } from "path";
143
+ import { homedir } from "os";
144
+ var LEGACY_AUTH_FILE_PATH = join(homedir(), ".boboddy");
145
+ var AUTH_FILE_PATH = join(homedir(), ".boboddy.json");
146
+ var EMPTY_AUTH_FILE = {
147
+ profiles: {}
148
+ };
149
+ function isAuthProfile(value) {
150
+ if (typeof value !== "object" || value === null)
151
+ return false;
152
+ const obj = value;
153
+ if (typeof obj["accessToken"] !== "string")
154
+ return false;
155
+ for (const key of ["userId", "email", "name"]) {
156
+ const v = obj[key];
157
+ if (v !== undefined && typeof v !== "string")
158
+ return false;
159
+ }
160
+ return true;
161
+ }
162
+ function isAuthFile(value) {
163
+ if (typeof value !== "object" || value === null)
164
+ return false;
165
+ const profiles = value["profiles"];
166
+ if (typeof profiles !== "object" || profiles === null)
167
+ return false;
168
+ for (const profile of Object.values(profiles)) {
169
+ if (!isAuthProfile(profile))
170
+ return false;
171
+ }
172
+ return true;
173
+ }
174
+ var ensureFilePermissions = (filePath) => {
175
+ try {
176
+ chmodSync(filePath, 384);
177
+ } catch {}
178
+ };
179
+ var getAuthFilePath = () => AUTH_FILE_PATH;
180
+ var loadAuthFileFromPath = (filePath) => {
181
+ if (!existsSync(filePath))
182
+ return EMPTY_AUTH_FILE;
183
+ if (!lstatSync(filePath).isFile())
184
+ return EMPTY_AUTH_FILE;
185
+ const content = readFileSync(filePath, "utf8");
186
+ if (content.trim().length === 0)
187
+ return EMPTY_AUTH_FILE;
188
+ let parsed;
189
+ try {
190
+ parsed = JSON.parse(content);
191
+ } catch {
192
+ return EMPTY_AUTH_FILE;
193
+ }
194
+ if (!isAuthFile(parsed))
195
+ return EMPTY_AUTH_FILE;
196
+ return parsed;
197
+ };
198
+ var loadAuthFile = () => {
199
+ if (existsSync(AUTH_FILE_PATH)) {
200
+ return loadAuthFileFromPath(AUTH_FILE_PATH);
201
+ }
202
+ return loadAuthFileFromPath(LEGACY_AUTH_FILE_PATH);
203
+ };
204
+ var writeAuthFile = (data) => {
205
+ const parentDirectory = dirname(AUTH_FILE_PATH);
206
+ if (!existsSync(parentDirectory)) {
207
+ mkdirSync(parentDirectory, { recursive: true });
208
+ }
209
+ const temporaryPath = `${AUTH_FILE_PATH}.${String(process.pid)}.${String(Date.now())}.tmp`;
210
+ writeFileSync(temporaryPath, `${JSON.stringify(data, null, 2)}
211
+ `, { encoding: "utf8", mode: 384 });
212
+ ensureFilePermissions(temporaryPath);
213
+ renameSync(temporaryPath, AUTH_FILE_PATH);
214
+ ensureFilePermissions(AUTH_FILE_PATH);
215
+ };
216
+ var loadAuthProfile = (baseUrl) => {
217
+ const authFile = loadAuthFile();
218
+ return authFile.profiles[baseUrl] ?? null;
219
+ };
220
+ var saveAuthProfile = (baseUrl, profile) => {
221
+ const authFile = loadAuthFile();
222
+ authFile.profiles[baseUrl] = profile;
223
+ writeAuthFile(authFile);
224
+ };
225
+ var deleteAuthProfile = (baseUrl) => {
226
+ const authFile = loadAuthFile();
227
+ if (!(baseUrl in authFile.profiles))
228
+ return;
229
+ const remainingProfiles = Object.fromEntries(Object.entries(authFile.profiles).filter(([profileBaseUrl]) => profileBaseUrl !== baseUrl));
230
+ if (Object.keys(remainingProfiles).length === 0) {
231
+ rmSync(AUTH_FILE_PATH, { force: true });
232
+ if (existsSync(LEGACY_AUTH_FILE_PATH) && lstatSync(LEGACY_AUTH_FILE_PATH).isFile()) {
233
+ rmSync(LEGACY_AUTH_FILE_PATH, { force: true });
234
+ }
235
+ return;
236
+ }
237
+ writeAuthFile({ profiles: remainingProfiles });
238
+ };
239
+ // src/defaults/base-url.ts
240
+ var DEFAULT_BASE_URL = "https://app.boboddy.dev";
241
+ var trimTrailingSlashes = (value) => {
242
+ let endIndex = value.length;
243
+ while (endIndex > 0 && value.charAt(endIndex - 1) === "/") {
244
+ endIndex -= 1;
245
+ }
246
+ return value.slice(0, endIndex);
247
+ };
248
+ var resolveBoboddyBaseUrl = (value) => {
249
+ const trimmedValue = value?.trim();
250
+ if (trimmedValue)
251
+ return trimTrailingSlashes(trimmedValue);
252
+ const envValue = process.env["BOBODDY_BASE_URL"]?.trim();
253
+ if (envValue)
254
+ return trimTrailingSlashes(envValue);
255
+ return DEFAULT_BASE_URL;
256
+ };
257
+ // src/defaults/project-config.ts
258
+ import { readFile } from "fs/promises";
259
+ import path from "path";
260
+ var BOBODDY_DIR = ".boboddy";
261
+ var CONFIG_FILENAME = "boboddy.jsonc";
262
+ var PROJECT_CONFIG_RELATIVE_PATH = path.join(BOBODDY_DIR, CONFIG_FILENAME);
263
+ function getConfigPath(rootDir) {
264
+ return path.join(rootDir, PROJECT_CONFIG_RELATIVE_PATH);
265
+ }
266
+ function isProjectConfig(value) {
267
+ if (typeof value !== "object" || value === null)
268
+ return false;
269
+ return typeof value["projectId"] === "string";
270
+ }
271
+ async function loadProjectConfig(rootDir = process.cwd()) {
272
+ try {
273
+ const content = await readFile(getConfigPath(rootDir), "utf8");
274
+ const parsed = parseJsonc(content);
275
+ return isProjectConfig(parsed) ? parsed : null;
276
+ } catch {
277
+ return null;
278
+ }
279
+ }
280
+ // src/defaults/load-push-defaults.ts
281
+ import path2 from "path";
282
+ async function findProjectConfigUpwards(startDir) {
283
+ let current = path2.resolve(startDir);
284
+ while (true) {
285
+ const found = await loadProjectConfig(current);
286
+ if (found)
287
+ return found;
288
+ const parent = path2.dirname(current);
289
+ if (parent === current)
290
+ return null;
291
+ current = parent;
292
+ }
293
+ }
294
+ async function loadPushDefaults(opts) {
295
+ const baseUrl = resolveBoboddyBaseUrl();
296
+ const envProjectId = process.env["BOBODDY_PROJECT_ID"]?.trim();
297
+ const projectId = envProjectId && envProjectId.length > 0 ? envProjectId : (await findProjectConfigUpwards(opts.dir))?.projectId;
298
+ const envAccessToken = process.env["BOBODDY_ACCESS_TOKEN"]?.trim();
299
+ const accessToken = envAccessToken && envAccessToken.length > 0 ? envAccessToken : loadAuthProfile(baseUrl)?.accessToken;
300
+ return { baseUrl, projectId, accessToken };
301
+ }
302
+ export {
303
+ saveAuthProfile,
304
+ resolveBoboddyBaseUrl,
305
+ loadPushDefaults,
306
+ loadProjectConfig,
307
+ loadAuthProfile,
308
+ loadAuthFile,
309
+ getAuthFilePath,
310
+ deleteAuthProfile,
311
+ PROJECT_CONFIG_RELATIVE_PATH
312
+ };