@bluestep-systems/b6p-core 0.8.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +310 -32
  2. package/dist/B6PCore.d.ts +7 -0
  3. package/dist/B6PCore.js +96 -1
  4. package/dist/B6PCore.js.map +1 -1
  5. package/dist/B6PUri.d.ts +6 -8
  6. package/dist/B6PUri.js +6 -8
  7. package/dist/B6PUri.js.map +1 -1
  8. package/dist/Err.d.ts +421 -0
  9. package/dist/Err.js +558 -0
  10. package/dist/Err.js.map +1 -1
  11. package/dist/auth/BearerAuthProvider.d.ts +32 -0
  12. package/dist/auth/BearerAuthProvider.js +49 -0
  13. package/dist/auth/BearerAuthProvider.js.map +1 -1
  14. package/dist/cache/OrgCache.js.map +1 -1
  15. package/dist/cache/ScriptMetaDataStore.js.map +1 -1
  16. package/dist/constants/ApiEndpoints.d.ts +1 -0
  17. package/dist/constants/ApiEndpoints.js +1 -0
  18. package/dist/constants/ApiEndpoints.js.map +1 -1
  19. package/dist/constants/AuthTypes.js.map +1 -1
  20. package/dist/constants/BlueHQ.js.map +1 -1
  21. package/dist/constants/CryptoAlgorithms.js.map +1 -1
  22. package/dist/constants/ExtensionConfig.js.map +1 -1
  23. package/dist/constants/FileExtensions.js.map +1 -1
  24. package/dist/constants/FolderNames.js.map +1 -1
  25. package/dist/constants/Gateway.d.ts +71 -0
  26. package/dist/constants/Gateway.js +79 -0
  27. package/dist/constants/Gateway.js.map +1 -0
  28. package/dist/constants/GitHubUrls.js.map +1 -1
  29. package/dist/constants/Http.js.map +1 -1
  30. package/dist/constants/MimeTypes.js.map +1 -1
  31. package/dist/constants/Numerical.js.map +1 -1
  32. package/dist/constants/OutputChannels.js.map +1 -1
  33. package/dist/constants/SettingsKeys.d.ts +5 -0
  34. package/dist/constants/SettingsKeys.js +5 -0
  35. package/dist/constants/SettingsKeys.js.map +1 -1
  36. package/dist/constants/SpecialFiles.js.map +1 -1
  37. package/dist/constants/WebDAVElements.js.map +1 -1
  38. package/dist/constants/index.d.ts +1 -0
  39. package/dist/constants/index.js +3 -1
  40. package/dist/constants/index.js.map +1 -1
  41. package/dist/data/DownstairsPathParser.js.map +1 -1
  42. package/dist/data/GlobMatcher.js.map +1 -1
  43. package/dist/data/IdUtility.js.map +1 -1
  44. package/dist/data/OrgWorker.js.map +1 -1
  45. package/dist/data/ScriptKey.d.ts +3 -27
  46. package/dist/data/ScriptKey.js +12 -24
  47. package/dist/data/ScriptKey.js.map +1 -1
  48. package/dist/data/ScriptUrlParser.js +3 -1
  49. package/dist/data/ScriptUrlParser.js.map +1 -1
  50. package/dist/data/ServerVersion.d.ts +76 -0
  51. package/dist/data/ServerVersion.js +111 -0
  52. package/dist/data/ServerVersion.js.map +1 -0
  53. package/dist/data/index.d.ts +2 -0
  54. package/dist/data/index.js +7 -1
  55. package/dist/data/index.js.map +1 -1
  56. package/dist/gateway/GatewayClient.d.ts +147 -0
  57. package/dist/gateway/GatewayClient.js +395 -0
  58. package/dist/gateway/GatewayClient.js.map +1 -0
  59. package/dist/gateway/GatewayContext.d.ts +43 -0
  60. package/dist/gateway/GatewayContext.js +3 -0
  61. package/dist/gateway/GatewayContext.js.map +1 -0
  62. package/dist/gateway/GatewayGit.d.ts +291 -0
  63. package/dist/gateway/GatewayGit.js +731 -0
  64. package/dist/gateway/GatewayGit.js.map +1 -0
  65. package/dist/gateway/GatewayKb.d.ts +173 -0
  66. package/dist/gateway/GatewayKb.js +354 -0
  67. package/dist/gateway/GatewayKb.js.map +1 -0
  68. package/dist/gateway/GatewayMarketplace.d.ts +116 -0
  69. package/dist/gateway/GatewayMarketplace.js +278 -0
  70. package/dist/gateway/GatewayMarketplace.js.map +1 -0
  71. package/dist/gateway/GatewayService.d.ts +47 -0
  72. package/dist/gateway/GatewayService.js +54 -0
  73. package/dist/gateway/GatewayService.js.map +1 -0
  74. package/dist/gateway/GatewayToken.d.ts +18 -0
  75. package/dist/gateway/GatewayToken.js +43 -0
  76. package/dist/gateway/GatewayToken.js.map +1 -0
  77. package/dist/gateway/GatewayTokenService.d.ts +101 -0
  78. package/dist/gateway/GatewayTokenService.js +465 -0
  79. package/dist/gateway/GatewayTokenService.js.map +1 -0
  80. package/dist/index.d.ts +29 -8
  81. package/dist/index.js +81 -9
  82. package/dist/index.js.map +1 -1
  83. package/dist/network/HttpClient.js.map +1 -1
  84. package/dist/network/HttpClientProvider.js.map +1 -1
  85. package/dist/network/StatusCodes.js.map +1 -1
  86. package/dist/persistence/PersistablePseudoMap.js.map +1 -1
  87. package/dist/persistence/PersistenceKeys.js.map +1 -1
  88. package/dist/persistence/PrivatePersistanceMap.js.map +1 -1
  89. package/dist/persistence/PseudoMap.js.map +1 -1
  90. package/dist/persistence/PublicPersistanceMap.js.map +1 -1
  91. package/dist/persistence/Serializable.js.map +1 -1
  92. package/dist/persistence/SharedFilePersistence.d.ts +22 -0
  93. package/dist/persistence/SharedFilePersistence.js +65 -14
  94. package/dist/persistence/SharedFilePersistence.js.map +1 -1
  95. package/dist/persistence/TypedMap.js.map +1 -1
  96. package/dist/persistence/TypedPersistable.js.map +1 -1
  97. package/dist/persistence/TypedPrivatePersistable.js.map +1 -1
  98. package/dist/persistence/dirLockdown.js.map +1 -1
  99. package/dist/providers.d.ts +46 -16
  100. package/dist/script/GitIdentity.d.ts +48 -0
  101. package/dist/script/GitIdentity.js +52 -0
  102. package/dist/script/GitIdentity.js.map +1 -0
  103. package/dist/script/GitSync.d.ts +388 -0
  104. package/dist/script/GitSync.js +1068 -0
  105. package/dist/script/GitSync.js.map +1 -0
  106. package/dist/script/ScriptContext.d.ts +20 -5
  107. package/dist/script/ScriptFactory.d.ts +1 -2
  108. package/dist/script/ScriptFactory.js +1 -2
  109. package/dist/script/ScriptFactory.js.map +1 -1
  110. package/dist/script/ScriptFile.d.ts +0 -94
  111. package/dist/script/ScriptFile.js +0 -245
  112. package/dist/script/ScriptFile.js.map +1 -1
  113. package/dist/script/ScriptFolder.d.ts +0 -9
  114. package/dist/script/ScriptFolder.js +4 -7
  115. package/dist/script/ScriptFolder.js.map +1 -1
  116. package/dist/script/ScriptNode.d.ts +0 -9
  117. package/dist/script/ScriptNode.js.map +1 -1
  118. package/dist/script/ScriptRoot.d.ts +0 -65
  119. package/dist/script/ScriptRoot.js +0 -199
  120. package/dist/script/ScriptRoot.js.map +1 -1
  121. package/dist/script/ScriptService.d.ts +113 -9
  122. package/dist/script/ScriptService.js +164 -52
  123. package/dist/script/ScriptService.js.map +1 -1
  124. package/dist/script/ServerCompile.d.ts +35 -0
  125. package/dist/script/ServerCompile.js +40 -0
  126. package/dist/script/ServerCompile.js.map +1 -0
  127. package/dist/script/TsConfig.d.ts +2 -2
  128. package/dist/script/TsConfig.js +3 -3
  129. package/dist/script/TsConfig.js.map +1 -1
  130. package/dist/script/push.d.ts +162 -188
  131. package/dist/script/push.js +216 -474
  132. package/dist/script/push.js.map +1 -1
  133. package/dist/session/SessionManager.js.map +1 -1
  134. package/dist/testing/FakeGateway.d.ts +280 -0
  135. package/dist/testing/FakeGateway.js +627 -0
  136. package/dist/testing/FakeGateway.js.map +1 -0
  137. package/dist/testing/MockFileSystem.js.map +1 -1
  138. package/dist/types.d.ts +332 -0
  139. package/dist/update/UpdateService.js.map +1 -1
  140. package/package.json +17 -12
  141. package/dist/script/ScriptTranspiler.d.ts +0 -121
  142. package/dist/script/ScriptTranspiler.js +0 -333
  143. package/dist/script/ScriptTranspiler.js.map +0 -1
  144. package/dist/script/SnapshotHistoryRecorder.d.ts +0 -47
  145. package/dist/script/SnapshotHistoryRecorder.js +0 -231
  146. package/dist/script/SnapshotHistoryRecorder.js.map +0 -1
  147. package/dist/script/TsLibResolver.d.ts +0 -60
  148. package/dist/script/TsLibResolver.js +0 -134
  149. package/dist/script/TsLibResolver.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import type { ScriptRepoOptions } from "@bluestep-systems/b6p-core-bsjs-git";
1
2
  import type { B6PUri } from "./B6PUri";
2
3
  import type { OrgCacheSettings } from "./cache/OrgCache";
3
4
  import type { AuthParams } from "./types";
@@ -131,6 +132,42 @@ export interface AuthProvider<T extends AuthParams> {
131
132
  /** Whether credentials are currently stored. Never prompts. */
132
133
  hasCredentials(): Promise<boolean>;
133
134
  }
135
+ /**
136
+ * Where the gateway client gets the global user's `b6pt_` access token. The client asks on every
137
+ * request and sends what it gets as `Authorization: Bearer <token>`, with no session bootstrap.
138
+ *
139
+ * `B6PCore` backs it with the token the bearer auth provider already stores (the same token that
140
+ * bootstraps the web session). It is an interface so the client and its specs depend only on
141
+ * "something that yields the token", not on where it is kept.
142
+ * @lastreviewed null
143
+ */
144
+ export interface GatewayTokenSource {
145
+ /**
146
+ * The token, or `undefined` when there is none. Never prompts: a missing token surfaces as a
147
+ * typed error from the client, and the consumer decides how to ask for one.
148
+ * @lastreviewed null
149
+ */
150
+ token(): Promise<string | undefined>;
151
+ }
152
+ /**
153
+ * Where a rotated replacement of the stored `b6pt_` token is written. There is still ONE stored
154
+ * token: this replaces it in place and never adds a second.
155
+ *
156
+ * `B6PCore` backs it with {@link BearerAuthProvider.replaceStoredToken}. It is the narrowest write
157
+ * the token-management service needs, and the only one: it cannot clear, prompt, or store a token
158
+ * that is not replacing the one it was rotated from.
159
+ * @lastreviewed null
160
+ */
161
+ export interface GatewayTokenStore {
162
+ /**
163
+ * Store `next` in place of `expected`. Rejects, leaving the stored token as it was, when the
164
+ * stored token is no longer `expected` (something else replaced it meanwhile) or cannot be
165
+ * written. The check is a compare-then-write, not atomic across processes. Neither value is
166
+ * ever logged or put in an error message.
167
+ * @lastreviewed null
168
+ */
169
+ replace(expected: string, next: string): Promise<void>;
170
+ }
134
171
  export interface Logger {
135
172
  info(...args: unknown[]): void;
136
173
  warn(...args: unknown[]): void;
@@ -209,24 +246,17 @@ export interface B6PProviders {
209
246
  */
210
247
  fetchFn?: (url: string | URL, init?: RequestInit) => Promise<Response>;
211
248
  /**
212
- * Optional directories that contain TypeScript's default library declaration
213
- * files (`lib.d.ts`, `lib.es2022.d.ts`, `lib.dom.d.ts`, ...). Used only by the
214
- * local transpile step that snapshot pushes run.
215
- *
216
- * WHY THIS EXISTS: b6p-core is bundled into the consumer (the CLI's single
217
- * `dist/cli.js` and its SEA binary). TypeScript's default host resolves the
218
- * standard library via `getDefaultLibLocation()` = `dirname(__filename)`. Once
219
- * bundled, `__filename` is the bundle path — where no `lib.*.d.ts` live — so
220
- * every compile fails with "File 'lib.esnext.d.ts' not found" cascading into
221
- * "Cannot find global type 'Array'". Because that resolution is unreliable
222
- * when bundled, the consumer should pass the directory it ships or extracts
223
- * these files to:
224
- * - npm bundle: a `lib/` copied next to the bundle (e.g. by esbuild).
225
- * - SEA binary: a temp dir the binary extracts its embedded libs into.
226
- * These are searched before the project-local `node_modules/typescript/lib`.
249
+ * Optional Node-style file system (with `.promises`) the script git working trees live on. Defaults to `node:fs`.
250
+ * Pass one only to run against something other than the real disk the `fs` provider also reads (tests).
251
+ * @lastreviewed null
252
+ */
253
+ gitFs?: ScriptRepoOptions["fs"];
254
+ /**
255
+ * Optional environment commit authors are looked up in as a last resort (after an explicit author and `git config`).
256
+ * Defaults to `process.env`.
227
257
  * @lastreviewed null
228
258
  */
229
- typescriptLibDirs?: readonly string[];
259
+ gitEnv?: Readonly<Record<string, string | undefined>>;
230
260
  /**
231
261
  * Optional update service configuration. If not provided, update checking is disabled.
232
262
  */
@@ -0,0 +1,48 @@
1
+ import { type GitIdentity } from "@bluestep-systems/b6p-core-bsjs-git";
2
+ /**
3
+ * Reads one `git config` value as git itself resolves it (repository, global and system config) for the repository
4
+ * at, or the folder `dir`. Resolves to `undefined` when the key is unset or git is not installed.
5
+ * @lastreviewed null
6
+ */
7
+ export type GitConfigReader = (dir: string, key: string) => Promise<string | undefined>;
8
+ /**
9
+ * Where a commit author may come from, in the order they are tried.
10
+ * @lastreviewed null
11
+ */
12
+ export interface GitIdentitySources {
13
+ /**
14
+ * An author the caller chose outright. Wins over everything else; it must be complete.
15
+ * @lastreviewed null
16
+ */
17
+ readonly explicit?: GitIdentity;
18
+ /**
19
+ * The script folder whose `git config` (and the user's global one) is consulted.
20
+ * @lastreviewed null
21
+ */
22
+ readonly dir: string;
23
+ /**
24
+ * The environment searched last for `GIT_AUTHOR_NAME`/`GIT_AUTHOR_EMAIL`, then `GIT_COMMITTER_NAME`/`_EMAIL`.
25
+ * Defaults to `process.env`.
26
+ * @lastreviewed null
27
+ */
28
+ readonly env?: Readonly<Record<string, string | undefined>>;
29
+ /**
30
+ * Replaces the `git config` lookup (tests); default runs the `git` executable.
31
+ * @lastreviewed null
32
+ */
33
+ readonly readGitConfig?: GitConfigReader;
34
+ }
35
+ /**
36
+ * The default {@link GitConfigReader}: `git config --get <key>` in `dir`.
37
+ * @lastreviewed null
38
+ */
39
+ export declare const runGitConfig: GitConfigReader;
40
+ /**
41
+ * The author a script commit is made by, the first complete (name and email) one of: the explicit identity, `git
42
+ * config user.name`/`user.email` for the script folder, then `GIT_AUTHOR_*`, then `GIT_COMMITTER_*` in the
43
+ * environment. There is no default: a commit made as nobody would reach the script's history as nobody.
44
+ *
45
+ * @throws {GitIdentityError} when the explicit identity is incomplete, or when no source has one.
46
+ * @lastreviewed null
47
+ */
48
+ export declare function resolveGitIdentity(sources: GitIdentitySources): Promise<GitIdentity>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGitConfig = void 0;
4
+ exports.resolveGitIdentity = resolveGitIdentity;
5
+ const node_child_process_1 = require("node:child_process");
6
+ const b6p_core_bsjs_git_1 = require("@bluestep-systems/b6p-core-bsjs-git");
7
+ /**
8
+ * The default {@link GitConfigReader}: `git config --get <key>` in `dir`.
9
+ * @lastreviewed null
10
+ */
11
+ const runGitConfig = (dir, key) => new Promise((resolve) => {
12
+ (0, node_child_process_1.execFile)("git", ["config", "--get", key], { cwd: dir, windowsHide: true }, (error, stdout) => {
13
+ const value = error ? "" : stdout.trim();
14
+ resolve(value === "" ? undefined : value);
15
+ });
16
+ });
17
+ exports.runGitConfig = runGitConfig;
18
+ function complete(name, email) {
19
+ const n = name?.trim();
20
+ const e = email?.trim();
21
+ return n && e ? { name: n, email: e } : undefined;
22
+ }
23
+ /**
24
+ * The author a script commit is made by, the first complete (name and email) one of: the explicit identity, `git
25
+ * config user.name`/`user.email` for the script folder, then `GIT_AUTHOR_*`, then `GIT_COMMITTER_*` in the
26
+ * environment. There is no default: a commit made as nobody would reach the script's history as nobody.
27
+ *
28
+ * @throws {GitIdentityError} when the explicit identity is incomplete, or when no source has one.
29
+ * @lastreviewed null
30
+ */
31
+ async function resolveGitIdentity(sources) {
32
+ if (sources.explicit) {
33
+ const explicit = complete(sources.explicit.name, sources.explicit.email);
34
+ if (!explicit) {
35
+ throw new b6p_core_bsjs_git_1.GitIdentityError("The commit author given has no name or no email");
36
+ }
37
+ return explicit;
38
+ }
39
+ const read = sources.readGitConfig ?? exports.runGitConfig;
40
+ const fromConfig = complete(await read(sources.dir, "user.name"), await read(sources.dir, "user.email"));
41
+ if (fromConfig) {
42
+ return fromConfig;
43
+ }
44
+ const env = sources.env ?? process.env;
45
+ const fromEnv = complete(env.GIT_AUTHOR_NAME, env.GIT_AUTHOR_EMAIL) ?? complete(env.GIT_COMMITTER_NAME, env.GIT_COMMITTER_EMAIL);
46
+ if (fromEnv) {
47
+ return fromEnv;
48
+ }
49
+ throw new b6p_core_bsjs_git_1.GitIdentityError("No commit author found: none was given, the git config for the script folder has no user.name and user.email, " +
50
+ "and the environment has no GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL");
51
+ }
52
+ //# sourceMappingURL=GitIdentity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitIdentity.js","sourceRoot":"","sources":["../../src/script/GitIdentity.ts"],"names":[],"mappings":";;;;AAAA,2DAA8C;AAC9C,2EAAyF;AAqCzF;;;GAGG;AACI,MAAM,YAAY,GAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACxD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,IAAA,6BAAQ,EAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3F,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AANQ,QAAA,YAAY,GAAZ,YAAY,CAMpB;AAEL,SAAS,QAAQ,CAAC,IAAwB,EAAE,KAAyB;IACnE,MAAM,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,6BAA6B,OAA2B;IAClE,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,oCAAgB,CAAC,iDAAiD,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,IAAI,QAAA,YAAY,CAAC;IACnD,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;IACzG,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,OAAO,GACX,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,gBAAgB,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,kBAAkB,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnH,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,oCAAgB,CACxB,gHAAgH;QAC9G,iEAAiE,CACpE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,388 @@
1
+ import { ScriptRepo, type BuildFastForward, type DraftBuildRefusalReason, type DraftCompileOutcome, type GitIdentity } from "@bluestep-systems/b6p-core-bsjs-git";
2
+ import type { ScriptKey } from "../data/ScriptKey";
3
+ import type { ScriptContext } from "./ScriptContext";
4
+ /**
5
+ * Where the files of a script's draft live and which script they belong to: everything the git side needs to open the
6
+ * script's repo.
7
+ * @lastreviewed null
8
+ */
9
+ export interface DraftTarget {
10
+ readonly ctx: ScriptContext;
11
+ readonly script: ScriptKey;
12
+ /**
13
+ * The organization's origin, such as `https://org.bluestep.net/`.
14
+ * @lastreviewed null
15
+ */
16
+ readonly baseUrl: string;
17
+ /**
18
+ * The local `draft/` folder: the git working tree.
19
+ * @lastreviewed null
20
+ */
21
+ readonly draftPath: string;
22
+ }
23
+ /**
24
+ * What a legacy (pre-git) pull or push last synced for a file: the SHA-512 of the content, hex, or `null` when this
25
+ * machine has no record. Lets a draft folder created before git be told apart from edits made since.
26
+ * @lastreviewed null
27
+ */
28
+ export type LastSyncedLookup = (draftRelative: string) => Promise<string | null>;
29
+ /**
30
+ * Thrown when the script still publishes over WebDAV and switching it to git (which cannot be undone) was not confirmed.
31
+ * Nothing was switched and nothing local was changed.
32
+ * @lastreviewed null
33
+ */
34
+ export declare class GitSwitchDeclinedError extends Error {
35
+ constructor();
36
+ }
37
+ /**
38
+ * Thrown by a push when the draft folder's repo has another branch checked out: a commit would advance that branch while
39
+ * the push sends the draft branch, so nothing is committed.
40
+ * @lastreviewed null
41
+ */
42
+ export declare class GitWrongBranchError extends Error {
43
+ readonly branch: string | undefined;
44
+ constructor(branch: string | undefined);
45
+ }
46
+ /**
47
+ * Thrown by a pull when files hold changes that exist only in the git index (staged, then edited again): updating the
48
+ * working tree would discard them. Nothing was changed.
49
+ * @lastreviewed null
50
+ */
51
+ export declare class GitStagedChangesError extends Error {
52
+ readonly paths: string[];
53
+ constructor(paths: string[]);
54
+ }
55
+ /**
56
+ * Thrown by a pull when an incoming file would be written through a symbolic link out of the draft folder. Nothing was
57
+ * changed.
58
+ * @lastreviewed null
59
+ */
60
+ export declare class GitSymlinkError extends Error {
61
+ readonly paths: string[];
62
+ constructor(paths: string[]);
63
+ }
64
+ /**
65
+ * Opens the script's repo on `dir` (the draft folder, or a scratch folder).
66
+ * @lastreviewed null
67
+ */
68
+ export declare function openRepo(target: DraftTarget, dir: string, author?: GitIdentity): Promise<ScriptRepo>;
69
+ /**
70
+ * Whether the draft folder is already a git working tree.
71
+ * @lastreviewed null
72
+ */
73
+ export declare function isGitWorkingTree(ctx: ScriptContext, draftPath: string): Promise<boolean>;
74
+ /**
75
+ * The rules of a script root's old `.gitignore` (which governed what a WebDAV push uploaded) as git rules for the repo
76
+ * rooted at `draft/`. That file's patterns matched paths relative to the script root, so only the ones that reached
77
+ * into `draft/` applied to the draft's files: `draft/<rest>` becomes `/<rest>` (anchored at the draft root) and
78
+ * `**` + `/<rest>` stays as it is. Everything else never matched a draft file and is dropped.
79
+ * @lastreviewed null
80
+ */
81
+ export declare function legacyIgnoreRulesForDraft(rootGitignore: string): string[];
82
+ /**
83
+ * What a pull did to the local draft.
84
+ * @lastreviewed null
85
+ */
86
+ export interface DraftPullOutcome {
87
+ /**
88
+ * Absolute paths of local files kept instead of being replaced by the platform's: edits to files the platform also
89
+ * changed, and local files (ignored or untracked) at paths the platform has started tracking.
90
+ * @lastreviewed null
91
+ */
92
+ readonly keptLocalPaths: string[];
93
+ /**
94
+ * Whether this pull switched the script from WebDAV to git (one-way).
95
+ * @lastreviewed null
96
+ */
97
+ readonly switchedToGit: boolean;
98
+ }
99
+ /**
100
+ * Options of {@link pullDraft}.
101
+ * @lastreviewed null
102
+ */
103
+ export interface DraftPullOptions {
104
+ /**
105
+ * The caller already confirmed switching a WebDAV script to git, so do not ask.
106
+ * @lastreviewed null
107
+ */
108
+ readonly enableGit?: boolean;
109
+ /**
110
+ * Draft-relative, `/`-separated paths whose platform copy wins even over a local edit.
111
+ * @lastreviewed null
112
+ */
113
+ readonly overwrite?: readonly string[];
114
+ /**
115
+ * What a pre-git sync recorded per file; only used when a draft folder with files but no repo is adopted.
116
+ * @lastreviewed null
117
+ */
118
+ readonly lastSynced?: LastSyncedLookup;
119
+ }
120
+ /**
121
+ * Brings the platform's draft into the local draft folder:
122
+ * - no repo: the script's mode is read first. A WebDAV script needs the one-way switch, confirmed before anything is
123
+ * switched or touched. An empty folder then gets a clone; a folder with files is bound to the repo as it stands (a
124
+ * file the platform has that differs from the local one is kept when its last sync record says it was edited here,
125
+ * and replaced otherwise);
126
+ * - a repo: fetches and fast-forwards. A local edit to a file the platform also changed, and a local ignored or
127
+ * untracked file at a path the platform now tracks, are kept and reported. Files the platform has that are missing
128
+ * locally are restored.
129
+ *
130
+ * Nothing is ever written through a symbolic link.
131
+ *
132
+ * @throws {GitSwitchDeclinedError} when a WebDAV script needs the switch and it was declined.
133
+ * @throws {GitNotFastForwardError} when the local draft has commits of its own and the platform moved too.
134
+ * @throws {GitStagedChangesError} when index-only changes would be discarded.
135
+ * @lastreviewed null
136
+ */
137
+ export declare function pullDraft(target: DraftTarget, options?: DraftPullOptions): Promise<DraftPullOutcome>;
138
+ /**
139
+ * Which files of a draft folder differ from the platform's draft.
140
+ * @lastreviewed null
141
+ */
142
+ export interface DraftAudit {
143
+ /**
144
+ * Draft-relative, `/`-separated paths the platform has that this folder lacks.
145
+ * @lastreviewed null
146
+ */
147
+ readonly missingLocally: string[];
148
+ /**
149
+ * Draft-relative paths present on both sides with different content.
150
+ * @lastreviewed null
151
+ */
152
+ readonly changed: string[];
153
+ }
154
+ /**
155
+ * Compares the local draft folder with the platform's draft. Fetches first; reads nothing else from the platform.
156
+ * @returns the differences, or `undefined` when the folder is not a git working tree yet (there is nothing to compare
157
+ * against without pulling it).
158
+ * @lastreviewed null
159
+ */
160
+ export declare function auditDraft(target: DraftTarget): Promise<DraftAudit | undefined>;
161
+ /**
162
+ * Options of {@link pushDraft}.
163
+ * @lastreviewed null
164
+ */
165
+ export interface DraftPushOptions {
166
+ readonly message: string;
167
+ /**
168
+ * Who the commit is by; the caller resolved it (see {@link resolveGitIdentity}).
169
+ * @lastreviewed null
170
+ */
171
+ readonly author: GitIdentity;
172
+ /**
173
+ * Whether to publish the pushed draft.
174
+ * @lastreviewed null
175
+ */
176
+ readonly snapshot: boolean;
177
+ /**
178
+ * A draft folder with no repo becomes the script's working tree (a push). Otherwise (a deploy) the folder is the
179
+ * source of someone else's script and is left alone: its files go through a scratch clone.
180
+ * @lastreviewed null
181
+ */
182
+ readonly adoptUnbound: boolean;
183
+ /**
184
+ * After the push, ask the platform to build the pushed draft ({@link ScriptRepo.compileDraft}) and fast-forward to
185
+ * the build commit it makes; a snapshot then publishes the build, unless the build failed or ended in a status that
186
+ * does not publish. Without it a snapshot publishes the pushed commit as it is (the platform's manifest check still
187
+ * applies); `executePush` never asks for that, it takes no snapshot on a server that does not build.
188
+ * @lastreviewed null
189
+ */
190
+ readonly build?: boolean;
191
+ /**
192
+ * Waits between the build's retries; tests pass a recorder.
193
+ * @lastreviewed null
194
+ */
195
+ readonly sleep?: (ms: number) => Promise<void>;
196
+ /**
197
+ * The caller already confirmed switching a WebDAV script to git, so do not ask.
198
+ * @lastreviewed null
199
+ */
200
+ readonly enableGit?: boolean;
201
+ /**
202
+ * Draft-relative paths whose overwrite the caller confirmed up front.
203
+ * @lastreviewed null
204
+ */
205
+ readonly preConfirmed?: readonly string[];
206
+ /**
207
+ * What a pre-git sync recorded per file; tells a local edit from a platform change in a folder without a repo.
208
+ * @lastreviewed null
209
+ */
210
+ readonly lastSynced?: LastSyncedLookup;
211
+ }
212
+ /**
213
+ * A refusal of the publish by the platform, structured: `reason` is the server's `extensions.reason` (for example
214
+ * `DRAFT_MOVED`, `BUILD_STALE`, `BUILD_MANIFEST_MISSING`, `BUILD_MANIFEST_INVALID`, `ENTRYPOINT_MISSING`) and `withheld`
215
+ * its `extensions.publish.withheld` (the stale paths, or the manifest's path; empty when the server gave none).
216
+ * @lastreviewed null
217
+ */
218
+ export interface PublishRefusal {
219
+ readonly reason: string;
220
+ readonly withheld: string[];
221
+ }
222
+ /**
223
+ * The build half of a {@link DraftPushOutcome}: what the platform's build of the pushed draft came to.
224
+ * @lastreviewed null
225
+ */
226
+ export interface DraftBuildOutcome {
227
+ /**
228
+ * The platform's compile: status, counts and diagnostics. `null` when the build request failed (see `error`).
229
+ * @lastreviewed null
230
+ */
231
+ readonly compile: DraftCompileOutcome | null;
232
+ /**
233
+ * The build commit the platform made, the platform draft's head. `null` when it made none (already built, nothing to
234
+ * build, the compile did not run) or the request failed. The local draft is there too unless `fastForward` says it
235
+ * is not.
236
+ * @lastreviewed null
237
+ */
238
+ readonly buildCommitSha: string | null;
239
+ /**
240
+ * How the local draft folder was moved to `buildCommitSha`: `fast-forwarded`, `unchanged` (no build commit),
241
+ * `blocked` (local files in the way, listed; nothing changed here) or `failed`. `null` when no build answer came.
242
+ * @lastreviewed null
243
+ */
244
+ readonly fastForward: BuildFastForward | null;
245
+ /**
246
+ * Set when the platform could not tell whether its build landed: `buildFound` says whether the draft, read back, was
247
+ * a build of the push (then taken in as `fastForward` says). Nothing is published after it. `null` otherwise.
248
+ * @lastreviewed null
249
+ */
250
+ readonly outcomeUnknown: {
251
+ readonly buildFound: boolean;
252
+ } | null;
253
+ /**
254
+ * Whether the draft passes the platform's build check (a clean build with its manifest committed, or none needed).
255
+ * @lastreviewed null
256
+ */
257
+ readonly vouched: boolean;
258
+ /**
259
+ * Why no build answer came, when none did; the push itself succeeded.
260
+ * @lastreviewed null
261
+ */
262
+ readonly error: string | null;
263
+ /**
264
+ * What `error` is: `not-requested` (no build was asked for: the platform's draft was no longer the pushed commit),
265
+ * `refused` (the platform refused the build, `errorReason`; nothing was built), `request-failed` (any other failure;
266
+ * it may have run). `null` with no error.
267
+ * @lastreviewed null
268
+ */
269
+ readonly errorKind: "not-requested" | "refused" | "request-failed" | null;
270
+ /**
271
+ * The platform's refusal reason when `errorKind` is `refused` (`DRAFT_MOVED`, `DRAFT_TOO_LARGE`, `REPO_MISSING`,
272
+ * `DRAFT_BRANCH_MISSING`); `null` otherwise.
273
+ * @lastreviewed null
274
+ */
275
+ readonly errorReason: DraftBuildRefusalReason | null;
276
+ }
277
+ /**
278
+ * The publish half of a {@link DraftPushOutcome}.
279
+ * @lastreviewed null
280
+ */
281
+ export interface DraftPublishOutcome {
282
+ /**
283
+ * The commit the platform published, or `null` when the publish failed (see `error`).
284
+ * @lastreviewed null
285
+ */
286
+ readonly publishedSha: string | null;
287
+ /**
288
+ * Why the publish failed, when it did.
289
+ * @lastreviewed null
290
+ */
291
+ readonly error: string | null;
292
+ /**
293
+ * The platform's structured refusal, when it refused the publish (`PUBLISH_REFUSED`): its `reason` and the paths in
294
+ * `publish.withheld`. `null` for any other outcome.
295
+ * @lastreviewed null
296
+ */
297
+ readonly refusal: PublishRefusal | null;
298
+ /**
299
+ * Whether the platform's published branch is at `publishedSha` after the publish: `null` when it could not be read.
300
+ * @lastreviewed null
301
+ */
302
+ readonly liveVerified: boolean | null;
303
+ /**
304
+ * Draft-relative paths that differ between the published commit and the published branch, when they differ.
305
+ * @lastreviewed null
306
+ */
307
+ readonly liveMismatches: string[];
308
+ }
309
+ /**
310
+ * What {@link pushDraft} did.
311
+ * @lastreviewed null
312
+ */
313
+ export interface DraftPushOutcome {
314
+ /**
315
+ * The draft branch's head on the platform after the push.
316
+ * @lastreviewed null
317
+ */
318
+ readonly commitSha: string;
319
+ readonly switchedToGit: boolean;
320
+ /**
321
+ * Draft-relative paths that exist only on the platform and were kept because deleting them was not confirmed.
322
+ * @lastreviewed null
323
+ */
324
+ readonly keptPlatformOnly: string[];
325
+ /**
326
+ * Set when the push was asked to build.
327
+ * @lastreviewed null
328
+ */
329
+ readonly build?: DraftBuildOutcome;
330
+ /**
331
+ * Set when the push was asked to publish and, with `build`, the build let it: the build request did not fail and its
332
+ * status is one that publishes ({@link compileAllowsPublish}). Absent otherwise; `build` says why.
333
+ * @lastreviewed null
334
+ */
335
+ readonly publish?: DraftPublishOutcome;
336
+ }
337
+ /**
338
+ * The push's one overwrite confirmation, asked before anything leaves this machine. The safe answer is first so an
339
+ * empty answer and auto-confirm both decline.
340
+ * @param opts.paths Files that differ from a platform version nobody here has seen
341
+ * @param opts.deleted Files the platform deleted since the last sync that this push would bring back
342
+ * @throws an {@link Err.OverwriteDeclinedError} naming the files when the answer is not "Overwrite all".
343
+ * @lastreviewed null
344
+ */
345
+ export declare function confirmOverwrittenFiles(opts: {
346
+ ctx: Pick<ScriptContext, "prompt">;
347
+ paths: readonly string[];
348
+ deleted?: readonly string[];
349
+ isSnapshot: boolean;
350
+ preConfirmed?: readonly string[];
351
+ }): Promise<void>;
352
+ /**
353
+ * Commits the draft folder's changes to the script's draft branch and pushes it; with `build`, asks the platform to
354
+ * build the pushed commit and fast-forwards the folder to the build commit (the platform compiles; nothing compiles
355
+ * here); for a snapshot, then publishes the build commit.
356
+ *
357
+ * Where the repo lives depends on the folder, and the script's publish mode (read first, never assumed from a repo
358
+ * being there) decides whether a switch is needed:
359
+ * - a folder bound to this script's repo whose script is in git mode is pushed in place (and must have the draft
360
+ * branch checked out);
361
+ * - a folder with no repo (a push), or one bound to a read-only mirror of a script that still publishes over WebDAV, is
362
+ * bound to the repo, but only after every consent has been given: the scratch clone is read, the overwrite
363
+ * confirmation asked, and only then is the folder's `.git` installed;
364
+ * - a deploy, or a folder bound to some other script, copies its files through a scratch clone.
365
+ * A script still publishing over WebDAV is switched to git first, which is one-way and confirmed first (`enableGit`
366
+ * pre-confirms). Its platform draft cannot be compared before it is switched, so the overwrite confirmation for it
367
+ * follows the switch, and nothing is installed locally until it is given.
368
+ *
369
+ * Before anything is pushed, one confirmation covers every platform file the push would overwrite or bring back, and
370
+ * another every platform file with no local copy; the safe answers keep the platform's version. The files committed
371
+ * follow git's ignore rules, including the old script-root `.gitignore` rules ({@link legacyIgnoreRulesForDraft}).
372
+ * Nothing is read through a symbolic link.
373
+ *
374
+ * Once the push has succeeded, nothing that follows throws: a failed build comes back as `build.error` and a failed
375
+ * publish as `publish.error`.
376
+ *
377
+ * @throws an {@link Err.OverwriteDeclinedError} when an overwrite is not confirmed.
378
+ * @throws {GitSwitchDeclinedError} when the switch is needed and declined.
379
+ * @throws {GitWrongBranchError} when the folder's repo has another branch checked out.
380
+ * @throws {BsjsGitError} (a typed subclass) when git or the platform refuses the push.
381
+ * @lastreviewed null
382
+ */
383
+ export declare function pushDraft(target: DraftTarget, options: DraftPushOptions): Promise<DraftPushOutcome>;
384
+ /**
385
+ * The draft folder of a script root, `<root>/draft`.
386
+ * @lastreviewed null
387
+ */
388
+ export declare function draftFolderOf(rootPath: string): string;