@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.
- package/README.md +310 -32
- package/dist/B6PCore.d.ts +7 -0
- package/dist/B6PCore.js +96 -1
- package/dist/B6PCore.js.map +1 -1
- package/dist/B6PUri.d.ts +6 -8
- package/dist/B6PUri.js +6 -8
- package/dist/B6PUri.js.map +1 -1
- package/dist/Err.d.ts +421 -0
- package/dist/Err.js +558 -0
- package/dist/Err.js.map +1 -1
- package/dist/auth/BearerAuthProvider.d.ts +32 -0
- package/dist/auth/BearerAuthProvider.js +49 -0
- package/dist/auth/BearerAuthProvider.js.map +1 -1
- package/dist/cache/OrgCache.js.map +1 -1
- package/dist/cache/ScriptMetaDataStore.js.map +1 -1
- package/dist/constants/ApiEndpoints.d.ts +1 -0
- package/dist/constants/ApiEndpoints.js +1 -0
- package/dist/constants/ApiEndpoints.js.map +1 -1
- package/dist/constants/AuthTypes.js.map +1 -1
- package/dist/constants/BlueHQ.js.map +1 -1
- package/dist/constants/CryptoAlgorithms.js.map +1 -1
- package/dist/constants/ExtensionConfig.js.map +1 -1
- package/dist/constants/FileExtensions.js.map +1 -1
- package/dist/constants/FolderNames.js.map +1 -1
- package/dist/constants/Gateway.d.ts +71 -0
- package/dist/constants/Gateway.js +79 -0
- package/dist/constants/Gateway.js.map +1 -0
- package/dist/constants/GitHubUrls.js.map +1 -1
- package/dist/constants/Http.js.map +1 -1
- package/dist/constants/MimeTypes.js.map +1 -1
- package/dist/constants/Numerical.js.map +1 -1
- package/dist/constants/OutputChannels.js.map +1 -1
- package/dist/constants/SettingsKeys.d.ts +5 -0
- package/dist/constants/SettingsKeys.js +5 -0
- package/dist/constants/SettingsKeys.js.map +1 -1
- package/dist/constants/SpecialFiles.js.map +1 -1
- package/dist/constants/WebDAVElements.js.map +1 -1
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +3 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/data/DownstairsPathParser.js.map +1 -1
- package/dist/data/GlobMatcher.js.map +1 -1
- package/dist/data/IdUtility.js.map +1 -1
- package/dist/data/OrgWorker.js.map +1 -1
- package/dist/data/ScriptKey.d.ts +3 -27
- package/dist/data/ScriptKey.js +12 -24
- package/dist/data/ScriptKey.js.map +1 -1
- package/dist/data/ScriptUrlParser.js +3 -1
- package/dist/data/ScriptUrlParser.js.map +1 -1
- package/dist/data/ServerVersion.d.ts +76 -0
- package/dist/data/ServerVersion.js +111 -0
- package/dist/data/ServerVersion.js.map +1 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.js +7 -1
- package/dist/data/index.js.map +1 -1
- package/dist/gateway/GatewayClient.d.ts +147 -0
- package/dist/gateway/GatewayClient.js +395 -0
- package/dist/gateway/GatewayClient.js.map +1 -0
- package/dist/gateway/GatewayContext.d.ts +43 -0
- package/dist/gateway/GatewayContext.js +3 -0
- package/dist/gateway/GatewayContext.js.map +1 -0
- package/dist/gateway/GatewayGit.d.ts +291 -0
- package/dist/gateway/GatewayGit.js +731 -0
- package/dist/gateway/GatewayGit.js.map +1 -0
- package/dist/gateway/GatewayKb.d.ts +173 -0
- package/dist/gateway/GatewayKb.js +354 -0
- package/dist/gateway/GatewayKb.js.map +1 -0
- package/dist/gateway/GatewayMarketplace.d.ts +116 -0
- package/dist/gateway/GatewayMarketplace.js +278 -0
- package/dist/gateway/GatewayMarketplace.js.map +1 -0
- package/dist/gateway/GatewayService.d.ts +47 -0
- package/dist/gateway/GatewayService.js +54 -0
- package/dist/gateway/GatewayService.js.map +1 -0
- package/dist/gateway/GatewayToken.d.ts +18 -0
- package/dist/gateway/GatewayToken.js +43 -0
- package/dist/gateway/GatewayToken.js.map +1 -0
- package/dist/gateway/GatewayTokenService.d.ts +101 -0
- package/dist/gateway/GatewayTokenService.js +465 -0
- package/dist/gateway/GatewayTokenService.js.map +1 -0
- package/dist/index.d.ts +29 -8
- package/dist/index.js +81 -9
- package/dist/index.js.map +1 -1
- package/dist/network/HttpClient.js.map +1 -1
- package/dist/network/HttpClientProvider.js.map +1 -1
- package/dist/network/StatusCodes.js.map +1 -1
- package/dist/persistence/PersistablePseudoMap.js.map +1 -1
- package/dist/persistence/PersistenceKeys.js.map +1 -1
- package/dist/persistence/PrivatePersistanceMap.js.map +1 -1
- package/dist/persistence/PseudoMap.js.map +1 -1
- package/dist/persistence/PublicPersistanceMap.js.map +1 -1
- package/dist/persistence/Serializable.js.map +1 -1
- package/dist/persistence/SharedFilePersistence.d.ts +22 -0
- package/dist/persistence/SharedFilePersistence.js +65 -14
- package/dist/persistence/SharedFilePersistence.js.map +1 -1
- package/dist/persistence/TypedMap.js.map +1 -1
- package/dist/persistence/TypedPersistable.js.map +1 -1
- package/dist/persistence/TypedPrivatePersistable.js.map +1 -1
- package/dist/persistence/dirLockdown.js.map +1 -1
- package/dist/providers.d.ts +46 -16
- package/dist/script/GitIdentity.d.ts +48 -0
- package/dist/script/GitIdentity.js +52 -0
- package/dist/script/GitIdentity.js.map +1 -0
- package/dist/script/GitSync.d.ts +388 -0
- package/dist/script/GitSync.js +1068 -0
- package/dist/script/GitSync.js.map +1 -0
- package/dist/script/ScriptContext.d.ts +20 -5
- package/dist/script/ScriptFactory.d.ts +1 -2
- package/dist/script/ScriptFactory.js +1 -2
- package/dist/script/ScriptFactory.js.map +1 -1
- package/dist/script/ScriptFile.d.ts +0 -94
- package/dist/script/ScriptFile.js +0 -245
- package/dist/script/ScriptFile.js.map +1 -1
- package/dist/script/ScriptFolder.d.ts +0 -9
- package/dist/script/ScriptFolder.js +4 -7
- package/dist/script/ScriptFolder.js.map +1 -1
- package/dist/script/ScriptNode.d.ts +0 -9
- package/dist/script/ScriptNode.js.map +1 -1
- package/dist/script/ScriptRoot.d.ts +0 -65
- package/dist/script/ScriptRoot.js +0 -199
- package/dist/script/ScriptRoot.js.map +1 -1
- package/dist/script/ScriptService.d.ts +113 -9
- package/dist/script/ScriptService.js +164 -52
- package/dist/script/ScriptService.js.map +1 -1
- package/dist/script/ServerCompile.d.ts +35 -0
- package/dist/script/ServerCompile.js +40 -0
- package/dist/script/ServerCompile.js.map +1 -0
- package/dist/script/TsConfig.d.ts +2 -2
- package/dist/script/TsConfig.js +3 -3
- package/dist/script/TsConfig.js.map +1 -1
- package/dist/script/push.d.ts +162 -188
- package/dist/script/push.js +216 -474
- package/dist/script/push.js.map +1 -1
- package/dist/session/SessionManager.js.map +1 -1
- package/dist/testing/FakeGateway.d.ts +280 -0
- package/dist/testing/FakeGateway.js +627 -0
- package/dist/testing/FakeGateway.js.map +1 -0
- package/dist/testing/MockFileSystem.js.map +1 -1
- package/dist/types.d.ts +332 -0
- package/dist/update/UpdateService.js.map +1 -1
- package/package.json +17 -12
- package/dist/script/ScriptTranspiler.d.ts +0 -121
- package/dist/script/ScriptTranspiler.js +0 -333
- package/dist/script/ScriptTranspiler.js.map +0 -1
- package/dist/script/SnapshotHistoryRecorder.d.ts +0 -47
- package/dist/script/SnapshotHistoryRecorder.js +0 -231
- package/dist/script/SnapshotHistoryRecorder.js.map +0 -1
- package/dist/script/TsLibResolver.d.ts +0 -60
- package/dist/script/TsLibResolver.js +0 -134
- package/dist/script/TsLibResolver.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { GatewayMarketplaceRepo } from "../types";
|
|
2
|
+
import type { GatewayClient } from "./GatewayClient";
|
|
3
|
+
import type { GatewayGit } from "./GatewayGit";
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link GatewayMarketplace.pull}.
|
|
6
|
+
* @lastreviewed null
|
|
7
|
+
*/
|
|
8
|
+
export interface GatewayMarketplacePullOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The folder `dir` is relative to. The consumer passes its own working directory; core never reads
|
|
11
|
+
* `process.cwd()`.
|
|
12
|
+
* @lastreviewed null
|
|
13
|
+
*/
|
|
14
|
+
cwd: string;
|
|
15
|
+
/**
|
|
16
|
+
* Where the clone lives, relative to `cwd` (or absolute). Defaults to the repo's name.
|
|
17
|
+
* @lastreviewed null
|
|
18
|
+
*/
|
|
19
|
+
dir?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The branch or tag to check out. Defaults to the repo's default branch.
|
|
22
|
+
* @lastreviewed null
|
|
23
|
+
*/
|
|
24
|
+
ref?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What {@link GatewayMarketplace.pull} did.
|
|
28
|
+
* @lastreviewed null
|
|
29
|
+
*/
|
|
30
|
+
export interface GatewayMarketplacePullResult {
|
|
31
|
+
/**
|
|
32
|
+
* `cloned` (a new working clone), `fast-forwarded`, `up-to-date` (nothing new upstream; for a tag, the
|
|
33
|
+
* gateway's tag still points at the checked-out commit), or `ahead` (the clone has commits upstream lacks; nothing to pull).
|
|
34
|
+
* @lastreviewed null
|
|
35
|
+
*/
|
|
36
|
+
action: "cloned" | "fast-forwarded" | "up-to-date" | "ahead";
|
|
37
|
+
/**
|
|
38
|
+
* The marketplace repo's name.
|
|
39
|
+
* @lastreviewed null
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* The absolute local folder.
|
|
44
|
+
* @lastreviewed null
|
|
45
|
+
*/
|
|
46
|
+
dir: string;
|
|
47
|
+
/**
|
|
48
|
+
* The ref that was cloned or kept: the branch or tag asked for, else the default branch.
|
|
49
|
+
* @lastreviewed null
|
|
50
|
+
*/
|
|
51
|
+
ref: string;
|
|
52
|
+
/**
|
|
53
|
+
* The checked-out branch, or `null` on a tag (a detached head).
|
|
54
|
+
* @lastreviewed null
|
|
55
|
+
*/
|
|
56
|
+
branch: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* The commit now checked out.
|
|
59
|
+
* @lastreviewed null
|
|
60
|
+
*/
|
|
61
|
+
head: string;
|
|
62
|
+
/**
|
|
63
|
+
* The commit before a fast-forward; the same as `head` when nothing changed or the repo was just cloned.
|
|
64
|
+
* @lastreviewed null
|
|
65
|
+
*/
|
|
66
|
+
from: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Marketplace repositories on web-global's gateway: browse them and pull a plain working clone.
|
|
70
|
+
* There is no push (the gateway refuses it for the marketplace), and a pull never reads or
|
|
71
|
+
* changes any script's sources or pins.
|
|
72
|
+
* @lastreviewed null
|
|
73
|
+
*/
|
|
74
|
+
export declare class GatewayMarketplace {
|
|
75
|
+
private readonly client;
|
|
76
|
+
private readonly gitLayer;
|
|
77
|
+
constructor(client: GatewayClient, gitLayer: GatewayGit);
|
|
78
|
+
/**
|
|
79
|
+
* Every well-formed marketplace repo the caller may read, with its tags. An entry of the wrong
|
|
80
|
+
* shape is left out, so one bad entry never hides the others.
|
|
81
|
+
* @throws {Err.GatewayUnexpectedResponseError} the body is not a listing at all
|
|
82
|
+
* @throws {Err.GatewayError} a subclass for any gateway failure
|
|
83
|
+
* @lastreviewed null
|
|
84
|
+
*/
|
|
85
|
+
list(): Promise<GatewayMarketplaceRepo[]>;
|
|
86
|
+
/**
|
|
87
|
+
* One marketplace repo by name.
|
|
88
|
+
* @throws {Err.GatewayNotFoundError} no repo has that name (or it is not visible to this user)
|
|
89
|
+
* @throws {Err.GatewayUnexpectedResponseError} the entry for that name is malformed
|
|
90
|
+
* @lastreviewed null
|
|
91
|
+
*/
|
|
92
|
+
get(name: string): Promise<GatewayMarketplaceRepo>;
|
|
93
|
+
private entries;
|
|
94
|
+
/**
|
|
95
|
+
* Make `options.dir` (default: `<cwd>/<name>`, relative paths resolved against `options.cwd`) a
|
|
96
|
+
* working clone of the repo at `options.ref` (default: the repo's default branch; `refs/heads/x`
|
|
97
|
+
* and `refs/tags/x` are accepted and mean `x`). A missing or empty folder is cloned. A folder that
|
|
98
|
+
* already holds a clone of the same `gitUrl` is fast-forwarded when it is on that branch and
|
|
99
|
+
* tracks it; a clone on a tag is `up-to-date` only while the gateway's tag still points at the
|
|
100
|
+
* checked-out commit. Nothing is merged, rebased or overwritten, and nothing is pushed.
|
|
101
|
+
*
|
|
102
|
+
* @param name the repo's name from {@link list}
|
|
103
|
+
* @throws {Err.GatewayNotFoundError} no such repo
|
|
104
|
+
* @throws {Err.GatewayConfigError} the folder is relative and `cwd` is missing or not absolute
|
|
105
|
+
* @throws {Err.GatewayUnexpectedResponseError} the name cannot be a folder name (with no `dir`)
|
|
106
|
+
* @throws {Err.GatewayCloneMismatchError} `different-repo`, `different-ref`, `tag-moved` (the tag now
|
|
107
|
+
* names another commit on the gateway) or `tag-gone` (the gateway no longer has it)
|
|
108
|
+
* @throws {Err.GatewayDirtyWorkingTreeError} the incoming commits change files with local changes
|
|
109
|
+
* @throws {Err.GatewayWorkingCopyError} `not-empty` (files, but no clone), `not-a-clone` (a `.git` that is
|
|
110
|
+
* not a usable repository), `ref-not-found`, `diverged`, ...
|
|
111
|
+
* @lastreviewed null
|
|
112
|
+
*/
|
|
113
|
+
pull(name: string, options: GatewayMarketplacePullOptions): Promise<GatewayMarketplacePullResult>;
|
|
114
|
+
private targetFolder;
|
|
115
|
+
private differentRef;
|
|
116
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GatewayMarketplace = void 0;
|
|
37
|
+
const nodeFs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const Gateway_1 = require("../constants/Gateway");
|
|
40
|
+
const Err_1 = require("../Err");
|
|
41
|
+
function isRecord(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Control characters, Unicode format characters and invisible or bidi-ignorable code points
|
|
46
|
+
* (zero-width, directional marks and overrides, BOM, soft hyphen). They can hide inside a name
|
|
47
|
+
* (a zero-width joiner before `.git` is `.git` on HFS+) or garble a terminal, so a listing
|
|
48
|
+
* carrying one is malformed.
|
|
49
|
+
* @lastreviewed null
|
|
50
|
+
*/
|
|
51
|
+
const INVISIBLE = /[\p{Cc}\p{Cf}\u200b-\u200f\u202a-\u202e\u2060-\u206f\ufeff]/u;
|
|
52
|
+
/**
|
|
53
|
+
* A folder name taken from the listing must be one plain path segment on every platform: no
|
|
54
|
+
* separators, drive or reserved characters, control characters, surrounding whitespace, leading
|
|
55
|
+
* dot (so never `.git` in any case, nor another dotfile), trailing dot, Windows 8.3 alias of
|
|
56
|
+
* `.git` (`git~1`), or Windows device name (`CON`, `NUL`, `COM1`, `COM\u00b9`, `LPT1`, ...), so a
|
|
57
|
+
* hostile or odd name cannot place a clone outside the folder the consumer chose or turn the
|
|
58
|
+
* consumer's cwd into a repository.
|
|
59
|
+
* @lastreviewed null
|
|
60
|
+
*/
|
|
61
|
+
function isPlainSegment(segment) {
|
|
62
|
+
return (segment !== "" &&
|
|
63
|
+
!segment.startsWith(".") &&
|
|
64
|
+
!/[\\/:*?"<>|]/.test(segment) &&
|
|
65
|
+
!INVISIBLE.test(segment) &&
|
|
66
|
+
segment === segment.trim() &&
|
|
67
|
+
!segment.endsWith(".") &&
|
|
68
|
+
!/^git~[0-9]+$/i.test(segment) &&
|
|
69
|
+
!/^(con|prn|aux|nul|conin\$|conout\$|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3])$/i.test(segment.split(".")[0].trimEnd()));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check one listing entry's shape. Throws `GatewayUnexpectedResponseError` naming the entry's
|
|
73
|
+
* position and field, never echoing a value. The name is NOT checked as a folder name here.
|
|
74
|
+
* @lastreviewed null
|
|
75
|
+
*/
|
|
76
|
+
function parseRepo(value, index) {
|
|
77
|
+
const bad = (what) => new Err_1.Err.GatewayUnexpectedResponseError(`The marketplace listing's entry ${index} has ${what}.`, 200, null);
|
|
78
|
+
if (!isRecord(value)) {
|
|
79
|
+
throw bad("the wrong shape");
|
|
80
|
+
}
|
|
81
|
+
const { name, description, defaultBranch, tags, gitUrl } = value;
|
|
82
|
+
if (typeof name !== "string" || INVISIBLE.test(name)) {
|
|
83
|
+
throw bad("no usable name");
|
|
84
|
+
}
|
|
85
|
+
if (typeof description !== "string" || INVISIBLE.test(description)) {
|
|
86
|
+
throw bad("no usable description");
|
|
87
|
+
}
|
|
88
|
+
if (typeof defaultBranch !== "string" || defaultBranch === "" || INVISIBLE.test(defaultBranch)) {
|
|
89
|
+
throw bad("no usable defaultBranch");
|
|
90
|
+
}
|
|
91
|
+
if (!Array.isArray(tags) || !tags.every((t) => typeof t === "string" && !INVISIBLE.test(t))) {
|
|
92
|
+
throw bad("tags that are not a list of plain strings");
|
|
93
|
+
}
|
|
94
|
+
if (typeof gitUrl !== "string" || gitUrl === "") {
|
|
95
|
+
throw bad("no gitUrl");
|
|
96
|
+
}
|
|
97
|
+
return { name, description, defaultBranch, tags, gitUrl };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* `refs/heads/x` and `refs/tags/x` are accepted and mean `x`, so the same options work on a second
|
|
101
|
+
* pull (the clone's own branch is the short name).
|
|
102
|
+
* @lastreviewed null
|
|
103
|
+
*/
|
|
104
|
+
function shortRef(ref) {
|
|
105
|
+
return ref.replace(/^refs\/(heads|tags)\//, "");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Compare two git URLs by what they address, ignoring a trailing slash. The one place a clone's
|
|
109
|
+
* `origin` is matched to a listing's `gitUrl`.
|
|
110
|
+
* @lastreviewed null
|
|
111
|
+
*/
|
|
112
|
+
function sameUrl(a, b) {
|
|
113
|
+
const norm = (value) => {
|
|
114
|
+
try {
|
|
115
|
+
const url = new URL(value);
|
|
116
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
return norm(a) === norm(b);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Marketplace repositories on web-global's gateway: browse them and pull a plain working clone.
|
|
126
|
+
* There is no push (the gateway refuses it for the marketplace), and a pull never reads or
|
|
127
|
+
* changes any script's sources or pins.
|
|
128
|
+
* @lastreviewed null
|
|
129
|
+
*/
|
|
130
|
+
class GatewayMarketplace {
|
|
131
|
+
client;
|
|
132
|
+
gitLayer;
|
|
133
|
+
constructor(client, gitLayer) {
|
|
134
|
+
this.client = client;
|
|
135
|
+
this.gitLayer = gitLayer;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Every well-formed marketplace repo the caller may read, with its tags. An entry of the wrong
|
|
139
|
+
* shape is left out, so one bad entry never hides the others.
|
|
140
|
+
* @throws {Err.GatewayUnexpectedResponseError} the body is not a listing at all
|
|
141
|
+
* @throws {Err.GatewayError} a subclass for any gateway failure
|
|
142
|
+
* @lastreviewed null
|
|
143
|
+
*/
|
|
144
|
+
async list() {
|
|
145
|
+
return (await this.entries()).repos;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* One marketplace repo by name.
|
|
149
|
+
* @throws {Err.GatewayNotFoundError} no repo has that name (or it is not visible to this user)
|
|
150
|
+
* @throws {Err.GatewayUnexpectedResponseError} the entry for that name is malformed
|
|
151
|
+
* @lastreviewed null
|
|
152
|
+
*/
|
|
153
|
+
async get(name) {
|
|
154
|
+
const { repos, malformed } = await this.entries();
|
|
155
|
+
const found = repos.find((repo) => repo.name === name);
|
|
156
|
+
if (found) {
|
|
157
|
+
return found;
|
|
158
|
+
}
|
|
159
|
+
const broken = malformed.get(name);
|
|
160
|
+
if (broken) {
|
|
161
|
+
throw broken;
|
|
162
|
+
}
|
|
163
|
+
throw new Err_1.Err.GatewayNotFoundError(`No marketplace repo is named ${name}.`, "not-found");
|
|
164
|
+
}
|
|
165
|
+
async entries() {
|
|
166
|
+
const body = await this.client.getJson(Gateway_1.Gateway.Paths.REGISTRY_REPOS);
|
|
167
|
+
if (!isRecord(body) || !Array.isArray(body.repos)) {
|
|
168
|
+
throw new Err_1.Err.GatewayUnexpectedResponseError("The marketplace listing is not the expected shape.", 200, null);
|
|
169
|
+
}
|
|
170
|
+
const repos = [];
|
|
171
|
+
const malformed = new Map();
|
|
172
|
+
body.repos.forEach((entry, index) => {
|
|
173
|
+
try {
|
|
174
|
+
repos.push(parseRepo(entry, index));
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (error instanceof Err_1.Err.GatewayUnexpectedResponseError) {
|
|
178
|
+
if (isRecord(entry) && typeof entry.name === "string") {
|
|
179
|
+
malformed.set(entry.name, error);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return { repos, malformed };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Make `options.dir` (default: `<cwd>/<name>`, relative paths resolved against `options.cwd`) a
|
|
190
|
+
* working clone of the repo at `options.ref` (default: the repo's default branch; `refs/heads/x`
|
|
191
|
+
* and `refs/tags/x` are accepted and mean `x`). A missing or empty folder is cloned. A folder that
|
|
192
|
+
* already holds a clone of the same `gitUrl` is fast-forwarded when it is on that branch and
|
|
193
|
+
* tracks it; a clone on a tag is `up-to-date` only while the gateway's tag still points at the
|
|
194
|
+
* checked-out commit. Nothing is merged, rebased or overwritten, and nothing is pushed.
|
|
195
|
+
*
|
|
196
|
+
* @param name the repo's name from {@link list}
|
|
197
|
+
* @throws {Err.GatewayNotFoundError} no such repo
|
|
198
|
+
* @throws {Err.GatewayConfigError} the folder is relative and `cwd` is missing or not absolute
|
|
199
|
+
* @throws {Err.GatewayUnexpectedResponseError} the name cannot be a folder name (with no `dir`)
|
|
200
|
+
* @throws {Err.GatewayCloneMismatchError} `different-repo`, `different-ref`, `tag-moved` (the tag now
|
|
201
|
+
* names another commit on the gateway) or `tag-gone` (the gateway no longer has it)
|
|
202
|
+
* @throws {Err.GatewayDirtyWorkingTreeError} the incoming commits change files with local changes
|
|
203
|
+
* @throws {Err.GatewayWorkingCopyError} `not-empty` (files, but no clone), `not-a-clone` (a `.git` that is
|
|
204
|
+
* not a usable repository), `ref-not-found`, `diverged`, ...
|
|
205
|
+
* @lastreviewed null
|
|
206
|
+
*/
|
|
207
|
+
async pull(name, options) {
|
|
208
|
+
const repo = await this.get(name);
|
|
209
|
+
if (options.dir === undefined && !isPlainSegment(repo.name)) {
|
|
210
|
+
throw new Err_1.Err.GatewayUnexpectedResponseError(`The marketplace repo name "${repo.name}" cannot be used as a folder name.`, 200, null);
|
|
211
|
+
}
|
|
212
|
+
const target = this.targetFolder(repo.name, options);
|
|
213
|
+
const ref = shortRef(options.ref ?? repo.defaultBranch);
|
|
214
|
+
if (!nodeFs.existsSync(path.join(target, ".git"))) {
|
|
215
|
+
const cloned = await this.gitLayer.clone(repo.gitUrl, target, { ref });
|
|
216
|
+
return {
|
|
217
|
+
action: "cloned",
|
|
218
|
+
name: repo.name,
|
|
219
|
+
dir: target,
|
|
220
|
+
ref,
|
|
221
|
+
branch: cloned.branch,
|
|
222
|
+
head: cloned.head,
|
|
223
|
+
from: cloned.head,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const found = await this.gitLayer.inspect(target, ref);
|
|
227
|
+
if (found.origin === null || !sameUrl(found.origin, repo.gitUrl)) {
|
|
228
|
+
throw new Err_1.Err.GatewayCloneMismatchError(`${target} is a clone of a different repository than marketplace repo ${repo.name}, so it was left as it is.`, "different-repo", target, repo.name);
|
|
229
|
+
}
|
|
230
|
+
const { branch, head } = found;
|
|
231
|
+
if (branch === null) {
|
|
232
|
+
// A detached head is a tag checkout. Keep it only if it is the tag that was asked for.
|
|
233
|
+
if (options.ref === undefined || found.tagCommit !== head) {
|
|
234
|
+
throw this.differentRef(target, repo.name, ref, "a tag or commit");
|
|
235
|
+
}
|
|
236
|
+
// Tags can move: ask the gateway, rather than trusting the local copy of the tag.
|
|
237
|
+
const upstream = await this.gitLayer.remoteTagCommit(repo.gitUrl, ref);
|
|
238
|
+
if (upstream !== head) {
|
|
239
|
+
throw new Err_1.Err.GatewayCloneMismatchError(upstream === null
|
|
240
|
+
? `Tag ${ref} no longer exists on the gateway; ${target} still has the commit it was cloned at.`
|
|
241
|
+
: `Tag ${ref} now points at a different commit on the gateway than the one checked out in ${target}.`, upstream === null ? "tag-gone" : "tag-moved", target, repo.name);
|
|
242
|
+
}
|
|
243
|
+
return { action: "up-to-date", name: repo.name, dir: target, ref, branch: null, head, from: head };
|
|
244
|
+
}
|
|
245
|
+
if (branch !== ref) {
|
|
246
|
+
throw this.differentRef(target, repo.name, ref, `branch ${branch}`);
|
|
247
|
+
}
|
|
248
|
+
if (found.upstream !== ref) {
|
|
249
|
+
throw this.differentRef(target, repo.name, ref, `branch ${branch} tracking ${found.upstream ?? "nothing"}`);
|
|
250
|
+
}
|
|
251
|
+
const pulled = await this.gitLayer.pull(target);
|
|
252
|
+
return {
|
|
253
|
+
action: pulled.outcome,
|
|
254
|
+
name: repo.name,
|
|
255
|
+
dir: target,
|
|
256
|
+
ref,
|
|
257
|
+
branch,
|
|
258
|
+
head: pulled.to,
|
|
259
|
+
from: pulled.from,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
// Core never reads process.cwd(): a relative folder needs an absolute cwd from the consumer.
|
|
263
|
+
targetFolder(name, options) {
|
|
264
|
+
const folder = options.dir ?? name;
|
|
265
|
+
if (options.dir !== undefined && path.isAbsolute(folder)) {
|
|
266
|
+
return path.resolve(folder);
|
|
267
|
+
}
|
|
268
|
+
if (typeof options.cwd !== "string" || !path.isAbsolute(options.cwd)) {
|
|
269
|
+
throw new Err_1.Err.GatewayConfigError("A pull into a relative folder needs the consumer's absolute working directory (cwd).");
|
|
270
|
+
}
|
|
271
|
+
return path.resolve(options.cwd, folder);
|
|
272
|
+
}
|
|
273
|
+
differentRef(dir, repo, ref, current) {
|
|
274
|
+
return new Err_1.Err.GatewayCloneMismatchError(`${dir} is a clone of marketplace repo ${repo} on ${current}, not on ${ref}, so it was left as it is.`, "different-ref", dir, repo);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.GatewayMarketplace = GatewayMarketplace;
|
|
278
|
+
//# sourceMappingURL=GatewayMarketplace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayMarketplace.js","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@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GatewayClient } from "./GatewayClient";
|
|
2
|
+
import { GatewayGit } from "./GatewayGit";
|
|
3
|
+
import { GatewayKb } from "./GatewayKb";
|
|
4
|
+
import type { GatewayGitOptions } from "./GatewayGit";
|
|
5
|
+
import { GatewayMarketplace } from "./GatewayMarketplace";
|
|
6
|
+
import type { GatewayContext } from "./GatewayContext";
|
|
7
|
+
import { GatewayTokenService } from "./GatewayTokenService";
|
|
8
|
+
/**
|
|
9
|
+
* The gateway subsystem: web-global's gateway (`gateway.bluestep.net`), reached for knowledge bases
|
|
10
|
+
* and marketplace repos. It sits beside `core.script` as `core.gateway`.
|
|
11
|
+
*
|
|
12
|
+
* It holds the HTTP {@link client}, the {@link git} layer and the caller's own token management
|
|
13
|
+
* ({@link tokens}); the knowledge-base and marketplace operations are added beside them as their
|
|
14
|
+
* own members. Each is built over that one client, so every REST request made through it, every
|
|
15
|
+
* git operation and every token rotation shares its one-at-a-time queue.
|
|
16
|
+
* @lastreviewed null
|
|
17
|
+
*/
|
|
18
|
+
export declare class GatewayService {
|
|
19
|
+
/**
|
|
20
|
+
* The authenticated, sequential HTTP client for the gateway.
|
|
21
|
+
* @lastreviewed null
|
|
22
|
+
*/
|
|
23
|
+
readonly client: GatewayClient;
|
|
24
|
+
/**
|
|
25
|
+
* Pure-JS git over the gateway's smart HTTP endpoints (clone, fast-forward pull, status, push).
|
|
26
|
+
* @lastreviewed null
|
|
27
|
+
*/
|
|
28
|
+
readonly git: GatewayGit;
|
|
29
|
+
/**
|
|
30
|
+
* Self-service management of the caller's own tokens: list, create, revoke, rotate.
|
|
31
|
+
* @lastreviewed null
|
|
32
|
+
*/
|
|
33
|
+
readonly tokens: GatewayTokenService;
|
|
34
|
+
/**
|
|
35
|
+
* Marketplace repos: list and pull a plain working clone (no push).
|
|
36
|
+
* @lastreviewed null
|
|
37
|
+
*/
|
|
38
|
+
readonly marketplace: GatewayMarketplace;
|
|
39
|
+
/**
|
|
40
|
+
* Knowledge bases: list, pull into a local folder, push back.
|
|
41
|
+
* @lastreviewed null
|
|
42
|
+
*/
|
|
43
|
+
readonly kb: GatewayKb;
|
|
44
|
+
constructor(ctx: GatewayContext, options?: {
|
|
45
|
+
git?: GatewayGitOptions;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayService = void 0;
|
|
4
|
+
const GatewayClient_1 = require("./GatewayClient");
|
|
5
|
+
const GatewayGit_1 = require("./GatewayGit");
|
|
6
|
+
const GatewayKb_1 = require("./GatewayKb");
|
|
7
|
+
const GatewayMarketplace_1 = require("./GatewayMarketplace");
|
|
8
|
+
const GatewayTokenService_1 = require("./GatewayTokenService");
|
|
9
|
+
/**
|
|
10
|
+
* The gateway subsystem: web-global's gateway (`gateway.bluestep.net`), reached for knowledge bases
|
|
11
|
+
* and marketplace repos. It sits beside `core.script` as `core.gateway`.
|
|
12
|
+
*
|
|
13
|
+
* It holds the HTTP {@link client}, the {@link git} layer and the caller's own token management
|
|
14
|
+
* ({@link tokens}); the knowledge-base and marketplace operations are added beside them as their
|
|
15
|
+
* own members. Each is built over that one client, so every REST request made through it, every
|
|
16
|
+
* git operation and every token rotation shares its one-at-a-time queue.
|
|
17
|
+
* @lastreviewed null
|
|
18
|
+
*/
|
|
19
|
+
class GatewayService {
|
|
20
|
+
/**
|
|
21
|
+
* The authenticated, sequential HTTP client for the gateway.
|
|
22
|
+
* @lastreviewed null
|
|
23
|
+
*/
|
|
24
|
+
client;
|
|
25
|
+
/**
|
|
26
|
+
* Pure-JS git over the gateway's smart HTTP endpoints (clone, fast-forward pull, status, push).
|
|
27
|
+
* @lastreviewed null
|
|
28
|
+
*/
|
|
29
|
+
git;
|
|
30
|
+
/**
|
|
31
|
+
* Self-service management of the caller's own tokens: list, create, revoke, rotate.
|
|
32
|
+
* @lastreviewed null
|
|
33
|
+
*/
|
|
34
|
+
tokens;
|
|
35
|
+
/**
|
|
36
|
+
* Marketplace repos: list and pull a plain working clone (no push).
|
|
37
|
+
* @lastreviewed null
|
|
38
|
+
*/
|
|
39
|
+
marketplace;
|
|
40
|
+
/**
|
|
41
|
+
* Knowledge bases: list, pull into a local folder, push back.
|
|
42
|
+
* @lastreviewed null
|
|
43
|
+
*/
|
|
44
|
+
kb;
|
|
45
|
+
constructor(ctx, options = {}) {
|
|
46
|
+
this.client = new GatewayClient_1.GatewayClient(ctx);
|
|
47
|
+
this.git = new GatewayGit_1.GatewayGit(ctx, this.client, options.git);
|
|
48
|
+
this.tokens = new GatewayTokenService_1.GatewayTokenService(this.client, ctx);
|
|
49
|
+
this.marketplace = new GatewayMarketplace_1.GatewayMarketplace(this.client, this.git);
|
|
50
|
+
this.kb = new GatewayKb_1.GatewayKb(this.client, this.git);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.GatewayService = GatewayService;
|
|
54
|
+
//# sourceMappingURL=GatewayService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayService.js","sourceRoot":"","sources":["../../src/gateway/GatewayService.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,6CAA0C;AAC1C,2CAAwC;AAExC,6DAA0D;AAE1D,+DAA4D;AAE5D;;;;;;;;;GASG;AACH;IACE;;;OAGG;IACM,MAAM,CAAgB;IAE/B;;;OAGG;IACM,GAAG,CAAa;IAEzB;;;OAGG;IACM,MAAM,CAAsB;IAErC;;;OAGG;IACM,WAAW,CAAqB;IAEzC;;;OAGG;IACM,EAAE,CAAY;IAEvB,YAAY,GAAmB,EAAE,OAAO,GAAgC,EAAE;QACxE,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,GAAG,GAAG,IAAI,uBAAU,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,uCAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,EAAE,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a candidate value is not a gateway access token, or `null` when it is one. The reason never
|
|
3
|
+
* quotes the value: a token pasted into the wrong place must not reach a log or an error message.
|
|
4
|
+
*
|
|
5
|
+
* Checked: the `b6pt_` prefix, something after it, and only printable ASCII (`0x21`–`0x7E`).
|
|
6
|
+
* Whitespace and control characters would corrupt the `Authorization` header, and a character
|
|
7
|
+
* outside ASCII (a smart quote or `…` from a paste) makes fetch refuse the header, which would
|
|
8
|
+
* otherwise surface as the gateway being unreachable. Within printable ASCII the alphabet is the
|
|
9
|
+
* gateway's business and is not checked.
|
|
10
|
+
* @lastreviewed null
|
|
11
|
+
*/
|
|
12
|
+
export declare function gatewayTokenProblem(candidate: string): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Replace every occurrence of `token` in `text` with a fixed placeholder. Applied to anything the
|
|
15
|
+
* gateway sends back before it reaches a message, so a server that echoes the token cannot leak it.
|
|
16
|
+
* @lastreviewed null
|
|
17
|
+
*/
|
|
18
|
+
export declare function redactToken(text: string, token: string | undefined): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gatewayTokenProblem = gatewayTokenProblem;
|
|
4
|
+
exports.redactToken = redactToken;
|
|
5
|
+
const Gateway_1 = require("../constants/Gateway");
|
|
6
|
+
/**
|
|
7
|
+
* Why a candidate value is not a gateway access token, or `null` when it is one. The reason never
|
|
8
|
+
* quotes the value: a token pasted into the wrong place must not reach a log or an error message.
|
|
9
|
+
*
|
|
10
|
+
* Checked: the `b6pt_` prefix, something after it, and only printable ASCII (`0x21`–`0x7E`).
|
|
11
|
+
* Whitespace and control characters would corrupt the `Authorization` header, and a character
|
|
12
|
+
* outside ASCII (a smart quote or `…` from a paste) makes fetch refuse the header, which would
|
|
13
|
+
* otherwise surface as the gateway being unreachable. Within printable ASCII the alphabet is the
|
|
14
|
+
* gateway's business and is not checked.
|
|
15
|
+
* @lastreviewed null
|
|
16
|
+
*/
|
|
17
|
+
function gatewayTokenProblem(candidate) {
|
|
18
|
+
if (candidate.length === 0) {
|
|
19
|
+
return "it is empty";
|
|
20
|
+
}
|
|
21
|
+
if (!candidate.startsWith(Gateway_1.Gateway.TOKEN_PREFIX)) {
|
|
22
|
+
return `it does not start with ${Gateway_1.Gateway.TOKEN_PREFIX}`;
|
|
23
|
+
}
|
|
24
|
+
if (candidate.length === Gateway_1.Gateway.TOKEN_PREFIX.length) {
|
|
25
|
+
return `it has nothing after ${Gateway_1.Gateway.TOKEN_PREFIX}`;
|
|
26
|
+
}
|
|
27
|
+
if (/[^\x21-\x7e]/.test(candidate)) {
|
|
28
|
+
return "it contains a character that is not printable ASCII (whitespace, a control character or a non-ASCII character)";
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Replace every occurrence of `token` in `text` with a fixed placeholder. Applied to anything the
|
|
34
|
+
* gateway sends back before it reaches a message, so a server that echoes the token cannot leak it.
|
|
35
|
+
* @lastreviewed null
|
|
36
|
+
*/
|
|
37
|
+
function redactToken(text, token) {
|
|
38
|
+
if (!token) {
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
return text.split(token).join(`${Gateway_1.Gateway.TOKEN_PREFIX}…`);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=GatewayToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayToken.js","sourceRoot":"","sources":["../../src/gateway/GatewayToken.ts"],"names":[],"mappings":";;;;AAAA,kDAA+C;AAE/C;;;;;;;;;;GAUG;AACH,6BAAoC,SAAiB;IACnD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,iBAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAChD,OAAO,0BAA0B,iBAAO,CAAC,YAAY,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,iBAAO,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACrD,OAAO,wBAAwB,iBAAO,CAAC,YAAY,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACnC,OAAO,gHAAgH,CAAC;IAC1H,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,qBAA4B,IAAY,EAAE,KAAyB;IACjE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,iBAAO,CAAC,YAAY,GAAG,CAAC,CAAC;AAC5D,CAAC"}
|