@bluestep-systems/b6p-core 0.3.1 → 0.5.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 +29 -13
- package/dist/B6PCore.d.ts +38 -80
- package/dist/B6PCore.js +52 -360
- package/dist/B6PCore.js.map +1 -1
- package/dist/B6PUri.d.ts +147 -7
- package/dist/B6PUri.js +190 -12
- package/dist/B6PUri.js.map +1 -1
- package/dist/Err.js.map +1 -1
- package/dist/PlatformContext.d.ts +33 -0
- package/dist/PlatformContext.js +3 -0
- package/dist/PlatformContext.js.map +1 -0
- package/dist/auth/BearerAuthProvider.d.ts +64 -0
- package/dist/auth/BearerAuthProvider.js +148 -0
- package/dist/auth/BearerAuthProvider.js.map +1 -0
- package/dist/cache/OrgCache.d.ts +64 -7
- package/dist/cache/OrgCache.js +142 -23
- package/dist/cache/OrgCache.js.map +1 -1
- package/dist/cache/ScriptMetaDataStore.d.ts +52 -2
- package/dist/cache/ScriptMetaDataStore.js +80 -2
- package/dist/cache/ScriptMetaDataStore.js.map +1 -1
- package/dist/constants/ApiEndpoints.js.map +1 -1
- package/dist/constants/AuthTypes.d.ts +0 -1
- package/dist/constants/AuthTypes.js +0 -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/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.js.map +1 -1
- package/dist/constants/SpecialFiles.js.map +1 -1
- package/dist/constants/WebDAVElements.js.map +1 -1
- package/dist/data/DownstairsPathParser.js.map +1 -1
- package/dist/data/GlobMatcher.js.map +1 -1
- package/dist/data/IdUtility.d.ts +2 -2
- package/dist/data/IdUtility.js.map +1 -1
- package/dist/data/OrgWorker.js.map +1 -1
- package/dist/data/ScriptKey.js.map +1 -1
- package/dist/data/ScriptUrlParser.d.ts +4 -3
- package/dist/data/ScriptUrlParser.js +2 -1
- package/dist/data/ScriptUrlParser.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +7 -4
- 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.d.ts +12 -7
- package/dist/persistence/PersistablePseudoMap.js +12 -5
- package/dist/persistence/PersistablePseudoMap.js.map +1 -1
- package/dist/persistence/PersistenceKeys.d.ts +0 -4
- package/dist/persistence/PersistenceKeys.js +0 -4
- package/dist/persistence/PersistenceKeys.js.map +1 -1
- package/dist/persistence/PrivatePersistanceMap.d.ts +4 -3
- package/dist/persistence/PrivatePersistanceMap.js +2 -1
- package/dist/persistence/PrivatePersistanceMap.js.map +1 -1
- package/dist/persistence/PseudoMap.js.map +1 -1
- package/dist/persistence/PublicPersistanceMap.d.ts +3 -3
- package/dist/persistence/PublicPersistanceMap.js +1 -1
- package/dist/persistence/PublicPersistanceMap.js.map +1 -1
- package/dist/persistence/Serializable.js.map +1 -1
- package/dist/persistence/SharedFilePersistence.d.ts +4 -3
- package/dist/persistence/SharedFilePersistence.js +129 -7
- package/dist/persistence/SharedFilePersistence.js.map +1 -1
- package/dist/persistence/TypedMap.js.map +1 -1
- package/dist/persistence/TypedPersistable.d.ts +5 -5
- package/dist/persistence/TypedPersistable.js +2 -2
- package/dist/persistence/TypedPersistable.js.map +1 -1
- package/dist/persistence/TypedPrivatePersistable.d.ts +3 -3
- package/dist/persistence/TypedPrivatePersistable.js +1 -1
- package/dist/persistence/TypedPrivatePersistable.js.map +1 -1
- package/dist/persistence/dirLockdown.js.map +1 -1
- package/dist/providers.d.ts +70 -13
- package/dist/script/ScriptContext.d.ts +17 -16
- package/dist/script/ScriptFactory.d.ts +23 -16
- package/dist/script/ScriptFactory.js +23 -44
- package/dist/script/ScriptFactory.js.map +1 -1
- package/dist/script/ScriptFile.d.ts +12 -0
- package/dist/script/ScriptFile.js +14 -1
- package/dist/script/ScriptFile.js.map +1 -1
- package/dist/script/ScriptFolder.d.ts +21 -0
- package/dist/script/ScriptFolder.js +28 -4
- package/dist/script/ScriptFolder.js.map +1 -1
- package/dist/script/ScriptNode.js.map +1 -1
- package/dist/script/ScriptRoot.js +10 -6
- package/dist/script/ScriptRoot.js.map +1 -1
- package/dist/script/ScriptService.d.ts +112 -0
- package/dist/script/ScriptService.js +411 -0
- package/dist/script/ScriptService.js.map +1 -0
- package/dist/script/ScriptTranspiler.js.map +1 -1
- package/dist/script/SnapshotHistoryRecorder.d.ts +14 -1
- package/dist/script/SnapshotHistoryRecorder.js +15 -10
- package/dist/script/SnapshotHistoryRecorder.js.map +1 -1
- package/dist/script/TsConfig.js.map +1 -1
- package/dist/script/TsLibResolver.js.map +1 -1
- package/dist/{push.d.ts → script/push.d.ts} +1 -3
- package/dist/{push.js → script/push.js} +10 -10
- package/dist/script/push.js.map +1 -0
- package/dist/session/SessionManager.d.ts +3 -2
- package/dist/session/SessionManager.js.map +1 -1
- package/dist/testing/MockFileSystem.d.ts +16 -3
- package/dist/testing/MockFileSystem.js +65 -42
- package/dist/testing/MockFileSystem.js.map +1 -1
- package/dist/testing/TestableFactory.d.ts +10 -6
- package/dist/types.d.ts +21 -5
- package/dist/update/UpdateService.d.ts +2 -2
- package/dist/update/UpdateService.js.map +1 -1
- package/package.json +12 -14
- package/dist/auth/BasicAuthProvider.d.ts +0 -39
- package/dist/auth/BasicAuthProvider.js +0 -106
- package/dist/auth/BasicAuthProvider.js.map +0 -1
- package/dist/push.js.map +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BearerAuthProvider = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const PERSISTENCE_KEY = "bearerAuth";
|
|
6
|
+
/**
|
|
7
|
+
* Secret-storage key written by the removed `BasicAuthProvider`. Purged by
|
|
8
|
+
* {@link BearerAuthProvider.clear} so an upgraded install does not leave a
|
|
9
|
+
* stored username/password pair behind indefinitely.
|
|
10
|
+
*/
|
|
11
|
+
const LEGACY_BASIC_PERSISTENCE_KEY = "basicAuth";
|
|
12
|
+
/** The {@link AuthParams.scheme} discriminant for this provider's credentials. */
|
|
13
|
+
const BEARER_SCHEME = "bearer";
|
|
14
|
+
/**
|
|
15
|
+
* Core-layer bearer auth provider.
|
|
16
|
+
*
|
|
17
|
+
* Holds a single opaque token, prompted from the user and kept in secret
|
|
18
|
+
* storage. Credential prompting and storage are delegated to the provider
|
|
19
|
+
* interfaces, so this class stays platform-free.
|
|
20
|
+
*/
|
|
21
|
+
class BearerAuthProvider {
|
|
22
|
+
persistence;
|
|
23
|
+
prompt;
|
|
24
|
+
logger;
|
|
25
|
+
constructor(persistence, prompt, logger) {
|
|
26
|
+
this.persistence = persistence;
|
|
27
|
+
this.prompt = prompt;
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the bearer auth header value (`"Bearer <token>"`).
|
|
32
|
+
* Prompts for a token if none is stored.
|
|
33
|
+
*/
|
|
34
|
+
async authHeaderValue() {
|
|
35
|
+
const { token } = await this.getOrCreate();
|
|
36
|
+
return `${constants_1.AuthTypes.BEARER_PREFIX}${token}`;
|
|
37
|
+
}
|
|
38
|
+
async getOrCreate() {
|
|
39
|
+
const stored = await this.readStored();
|
|
40
|
+
if (stored) {
|
|
41
|
+
return stored;
|
|
42
|
+
}
|
|
43
|
+
this.prompt.info("No existing token found, please enter a new token.");
|
|
44
|
+
return this.createNew();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The stored credentials, or `undefined` if absent or unusable.
|
|
48
|
+
*
|
|
49
|
+
* Secret storage is shared with every other key the consumer keeps, and its
|
|
50
|
+
* contents outlive any single version of this class, so what comes back is
|
|
51
|
+
* parsed and checked rather than asserted. Anything that is not well-formed
|
|
52
|
+
* `"bearer"` params is treated as absent, which routes the caller to a fresh
|
|
53
|
+
* prompt instead of letting a malformed value reach the `Authorization`
|
|
54
|
+
* header as `"Bearer undefined"`.
|
|
55
|
+
*/
|
|
56
|
+
async readStored() {
|
|
57
|
+
const raw = await this.persistence.getSecret(PERSISTENCE_KEY);
|
|
58
|
+
if (!raw) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = JSON.parse(raw);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
this.logger.warn("Stored bearer credentials are not valid JSON; discarding them.");
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
if (!this.isBearerAuthParams(parsed)) {
|
|
70
|
+
this.logger.warn("Stored bearer credentials are malformed; discarding them.");
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
isBearerAuthParams(value) {
|
|
76
|
+
if (typeof value !== "object" || value === null) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const candidate = value;
|
|
80
|
+
return candidate.scheme === BEARER_SCHEME && typeof candidate.token === "string" && candidate.token.length > 0;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Prompt for a new token and store it.
|
|
84
|
+
*
|
|
85
|
+
* An **empty** entry is treated as cancellation, not as a token. It has to be:
|
|
86
|
+
* {@link isBearerAuthParams} rejects a zero-length token, so storing one produced a
|
|
87
|
+
* credential this class would immediately discard — `hasCredentials()` returned
|
|
88
|
+
* false right after a "Token stored" log line, and the next `authHeaderValue()`
|
|
89
|
+
* re-prompted, giving a user who keeps pressing Enter an unbounded prompt loop.
|
|
90
|
+
*
|
|
91
|
+
* Note {@link update} deliberately reads empty as "keep the current token"; there
|
|
92
|
+
* is no current token to keep here.
|
|
93
|
+
* @lastreviewed null
|
|
94
|
+
*/
|
|
95
|
+
async createNew() {
|
|
96
|
+
const token = await this.prompt.inputBox({ prompt: "Enter your access token", password: true });
|
|
97
|
+
if (token === undefined || token.length === 0) {
|
|
98
|
+
throw new Error("Token entry cancelled");
|
|
99
|
+
}
|
|
100
|
+
const creds = { scheme: BEARER_SCHEME, token };
|
|
101
|
+
await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
|
|
102
|
+
this.logger.info("Token stored");
|
|
103
|
+
return creds;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Update the stored token (prompts, keeps the old value on empty input).
|
|
107
|
+
*/
|
|
108
|
+
async update() {
|
|
109
|
+
const existing = await this.getOrCreate();
|
|
110
|
+
const newToken = await this.prompt.inputBox({
|
|
111
|
+
prompt: "Enter new access token (empty to keep current)",
|
|
112
|
+
password: true,
|
|
113
|
+
});
|
|
114
|
+
if (newToken === undefined) {
|
|
115
|
+
this.prompt.info("Cancelled");
|
|
116
|
+
return existing;
|
|
117
|
+
}
|
|
118
|
+
const creds = { scheme: BEARER_SCHEME, token: newToken || existing.token };
|
|
119
|
+
await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
|
|
120
|
+
if (creds.token === existing.token) {
|
|
121
|
+
this.prompt.info("No changes made to the token.");
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.prompt.info("Token updated!");
|
|
125
|
+
}
|
|
126
|
+
return creds;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Clear the stored token, along with any credentials left behind by the
|
|
130
|
+
* removed basic-auth provider.
|
|
131
|
+
*/
|
|
132
|
+
async clear() {
|
|
133
|
+
await this.persistence.deleteSecret(PERSISTENCE_KEY);
|
|
134
|
+
await this.persistence.deleteSecret(LEGACY_BASIC_PERSISTENCE_KEY);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Whether a usable token is currently stored.
|
|
138
|
+
*
|
|
139
|
+
* Agrees with {@link getOrCreate}: a stored value that would be discarded as
|
|
140
|
+
* malformed reports `false`, so this never claims credentials that the next
|
|
141
|
+
* `getOrCreate()` would throw away and re-prompt for.
|
|
142
|
+
*/
|
|
143
|
+
async hasCredentials() {
|
|
144
|
+
return (await this.readStored()) !== undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.BearerAuthProvider = BearerAuthProvider;
|
|
148
|
+
//# sourceMappingURL=BearerAuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BearerAuthProvider.js","sourceRoot":"","sources":["../../src/auth/BearerAuthProvider.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AAGzC,MAAM,eAAe,GAAG,YAAY,CAAC;AAErC;;;;GAIG;AACH,MAAM,4BAA4B,GAAG,WAAW,CAAC;AAEjD,kFAAkF;AAClF,MAAM,aAAa,GAAG,QAAQ,CAAC;AAE/B;;;;;;GAMG;AACH;IAEqB,WAAW;IACX,MAAM;IACN,MAAM;IAHzB,YACmB,WAAwB,EACxB,MAAc,EACd,MAAc;2BAFd,WAAW;sBACX,MAAM;sBACN,MAAM;IACtB,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,GAAG,qBAAS,CAAC,aAAa,GAAG,KAAK,EAAE,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACvC,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACv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AED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACrD,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,4BAA4B,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc;QAClB,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,SAAS,CAAC;IACjD,CAAC;CACF"}
|
package/dist/cache/OrgCache.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { OrgCacheElement } from "../types";
|
|
2
2
|
import { PublicPersistanceMap } from "../persistence";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Persistence, Logger, Prompt } from "../providers";
|
|
4
4
|
/**
|
|
5
5
|
* Minimal settings shape required by {@link OrgCache}.
|
|
6
6
|
*
|
|
7
7
|
* Implementations may pull values from any backing store (VS Code config, env, file).
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface OrgCacheSettings {
|
|
10
10
|
/**
|
|
11
11
|
* Returns an override URL for the given U if one is configured (e.g. via debug-mode
|
|
12
12
|
* settings); returns `null` if no override applies.
|
|
@@ -30,17 +30,66 @@ export declare class OrgCache implements OrgCacheDisposable {
|
|
|
30
30
|
private readonly prompt?;
|
|
31
31
|
private readonly orgCacheMap;
|
|
32
32
|
private _cleanupTimer;
|
|
33
|
+
private _disposed;
|
|
33
34
|
/**
|
|
34
35
|
* Optional callback invoked when the cache changes (e.g. for MCP server updates).
|
|
35
36
|
*/
|
|
36
37
|
onChanged: (() => void) | null;
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Resolves once the backing map has loaded and the first cleanup pass has run.
|
|
40
|
+
* Every public method that *reads or mutates the cache* awaits this first. The two
|
|
41
|
+
* exceptions are deliberate: {@link map} hands out the backing map itself (its
|
|
42
|
+
* caller owns the timing) and {@link dispose} must stay synchronous. Resolves —
|
|
43
|
+
* never rejects — so a failed load leaves the cache empty rather than hanging
|
|
44
|
+
* awaiters.
|
|
45
|
+
* @lastreviewed null
|
|
46
|
+
*/
|
|
47
|
+
private readonly ready;
|
|
48
|
+
constructor(persistence: Persistence, logger: Logger, settings: OrgCacheSettings, isDebugMode: () => boolean, prompt?: Prompt | undefined);
|
|
49
|
+
/**
|
|
50
|
+
* Awaits the initial load. Public methods do this for you; call it directly only
|
|
51
|
+
* before {@link findUCacheOnly}, which is synchronous and cannot await.
|
|
52
|
+
* @lastreviewed null
|
|
53
|
+
*/
|
|
54
|
+
whenReady(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the underlying persistence map. **Not gated on the initial load** — await
|
|
57
|
+
* {@link whenReady} (or the map's own `whenReady()`) before reading from it.
|
|
58
|
+
* @lastreviewed null
|
|
59
|
+
*/
|
|
39
60
|
map(): PublicPersistanceMap<OrgCacheElement[]>;
|
|
40
61
|
delete(u: string): Promise<void>;
|
|
41
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Cleans up entries that have not been accessed in the last 3 days, persists the
|
|
64
|
+
* result if anything expired, then re-arms itself for a day later.
|
|
65
|
+
*
|
|
66
|
+
* **Async on purpose.** The `store()` used to be issued and dropped on the floor.
|
|
67
|
+
* A rejected write was then an unhandled rejection — the `catch` on {@link ready}
|
|
68
|
+
* did not cover it, because that only ever saw a *synchronous* throw, and the
|
|
69
|
+
* timer-driven pass sat in no promise chain at all. Awaiting it also means
|
|
70
|
+
* {@link whenReady} genuinely waits for the first write rather than resolving
|
|
71
|
+
* while it is still in flight.
|
|
72
|
+
*
|
|
73
|
+
* The re-arm is in a `finally` so a transient write failure ends this pass, not
|
|
74
|
+
* every future one.
|
|
75
|
+
* @lastreviewed null
|
|
76
|
+
*/
|
|
42
77
|
private cleanupOldEntries;
|
|
43
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Timer entry point for {@link cleanupOldEntries}. Nothing awaits the timer
|
|
80
|
+
* callback, so this is where a failed scheduled sweep is absorbed — otherwise it
|
|
81
|
+
* would surface as an unhandled rejection a day into a long-running host.
|
|
82
|
+
* @lastreviewed null
|
|
83
|
+
*/
|
|
84
|
+
private runScheduledCleanup;
|
|
85
|
+
/**
|
|
86
|
+
* Validates the cache to ensure no duplicate hosts exist.
|
|
87
|
+
*
|
|
88
|
+
* Async for the same reason {@link cleanupOldEntries} is: its `store()` was issued
|
|
89
|
+
* and dropped, so a rejected write became an unhandled rejection. All three callers
|
|
90
|
+
* are already async and now await it.
|
|
91
|
+
* @lastreviewed null
|
|
92
|
+
*/
|
|
44
93
|
private cleanDuplicates;
|
|
45
94
|
/** Hard-validates all entries in the cache by calling the orgs to verify the U-host association. */
|
|
46
95
|
hardValidateAll(): Promise<void>;
|
|
@@ -60,7 +109,15 @@ export declare class OrgCache implements OrgCacheDisposable {
|
|
|
60
109
|
* If not cached, will attempt to call the org to get the U.
|
|
61
110
|
*/
|
|
62
111
|
findU(url: string | URL, cacheOnly?: boolean): Promise<string>;
|
|
63
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Finds the U associated with the provided URL from cache only.
|
|
114
|
+
*
|
|
115
|
+
* Synchronous, so it cannot await the initial load itself. External callers must
|
|
116
|
+
* `await orgCache.whenReady()` first; without that it reports a miss on a cache
|
|
117
|
+
* that is merely not loaded yet, which an unlucky caller turns into a needless
|
|
118
|
+
* BlueHQ round trip. Internal callers all run after {@link ready} has settled.
|
|
119
|
+
* @lastreviewed null
|
|
120
|
+
*/
|
|
64
121
|
findUCacheOnly(url: URL): string | null;
|
|
65
122
|
dispose(): void;
|
|
66
123
|
}
|
package/dist/cache/OrgCache.js
CHANGED
|
@@ -17,47 +17,147 @@ class OrgCache {
|
|
|
17
17
|
prompt;
|
|
18
18
|
orgCacheMap;
|
|
19
19
|
_cleanupTimer = null;
|
|
20
|
+
_disposed = false;
|
|
20
21
|
/**
|
|
21
22
|
* Optional callback invoked when the cache changes (e.g. for MCP server updates).
|
|
22
23
|
*/
|
|
23
24
|
onChanged = null;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves once the backing map has loaded and the first cleanup pass has run.
|
|
27
|
+
* Every public method that *reads or mutates the cache* awaits this first. The two
|
|
28
|
+
* exceptions are deliberate: {@link map} hands out the backing map itself (its
|
|
29
|
+
* caller owns the timing) and {@link dispose} must stay synchronous. Resolves —
|
|
30
|
+
* never rejects — so a failed load leaves the cache empty rather than hanging
|
|
31
|
+
* awaiters.
|
|
32
|
+
* @lastreviewed null
|
|
33
|
+
*/
|
|
34
|
+
ready;
|
|
24
35
|
constructor(persistence, logger, settings, isDebugMode, prompt) {
|
|
25
36
|
this.logger = logger;
|
|
26
37
|
this.settings = settings;
|
|
27
38
|
this.isDebugMode = isDebugMode;
|
|
28
39
|
this.prompt = prompt;
|
|
29
40
|
this.orgCacheMap = new persistence_1.PublicPersistanceMap(persistence_1.PublicKeys.U_CACHE, persistence);
|
|
30
|
-
|
|
41
|
+
// MUST await the load before the first cleanup. `PublicPersistanceMap` loads
|
|
42
|
+
// asynchronously and *reassigns* its backing object when the load lands, so a
|
|
43
|
+
// cleanup that ran synchronously here would iterate an empty map and then
|
|
44
|
+
// `store()` that emptiness over the real file — silently wiping the persisted
|
|
45
|
+
// cache on every construction, invisibly, because the in-memory copy arrives
|
|
46
|
+
// immediately afterwards and looks correct for the rest of the session.
|
|
47
|
+
this.ready = this.orgCacheMap
|
|
48
|
+
.whenReady()
|
|
49
|
+
.then(() => this.cleanupOldEntries())
|
|
50
|
+
.catch((e) => {
|
|
51
|
+
// Must not reject. `whenReady()` never does, but `cleanupOldEntries` reaches
|
|
52
|
+
// `Persistence.set`, and a consumer implementation may throw synchronously.
|
|
53
|
+
// Nothing awaits `ready` at construction time, so a rejection here would be
|
|
54
|
+
// an unhandled rejection that takes the process down — and would then make
|
|
55
|
+
// every gated method reject for the rest of the process's life.
|
|
56
|
+
this.logger.warn(`OrgCache initial cleanup failed; continuing with the loaded cache: ${String(e)}`);
|
|
57
|
+
});
|
|
31
58
|
}
|
|
32
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Awaits the initial load. Public methods do this for you; call it directly only
|
|
61
|
+
* before {@link findUCacheOnly}, which is synchronous and cannot await.
|
|
62
|
+
* @lastreviewed null
|
|
63
|
+
*/
|
|
64
|
+
whenReady() {
|
|
65
|
+
return this.ready;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the underlying persistence map. **Not gated on the initial load** — await
|
|
69
|
+
* {@link whenReady} (or the map's own `whenReady()`) before reading from it.
|
|
70
|
+
* @lastreviewed null
|
|
71
|
+
*/
|
|
33
72
|
map() {
|
|
34
73
|
return this.orgCacheMap;
|
|
35
74
|
}
|
|
36
75
|
async delete(u) {
|
|
76
|
+
await this.ready;
|
|
37
77
|
this.orgCacheMap.delete(u);
|
|
38
78
|
await this.orgCacheMap.store();
|
|
39
79
|
this.onChanged?.();
|
|
40
80
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Cleans up entries that have not been accessed in the last 3 days, persists the
|
|
83
|
+
* result if anything expired, then re-arms itself for a day later.
|
|
84
|
+
*
|
|
85
|
+
* **Async on purpose.** The `store()` used to be issued and dropped on the floor.
|
|
86
|
+
* A rejected write was then an unhandled rejection — the `catch` on {@link ready}
|
|
87
|
+
* did not cover it, because that only ever saw a *synchronous* throw, and the
|
|
88
|
+
* timer-driven pass sat in no promise chain at all. Awaiting it also means
|
|
89
|
+
* {@link whenReady} genuinely waits for the first write rather than resolving
|
|
90
|
+
* while it is still in flight.
|
|
91
|
+
*
|
|
92
|
+
* The re-arm is in a `finally` so a transient write failure ends this pass, not
|
|
93
|
+
* every future one.
|
|
94
|
+
* @lastreviewed null
|
|
95
|
+
*/
|
|
96
|
+
async cleanupOldEntries() {
|
|
97
|
+
// The first sweep is deferred onto `ready`, so `dispose()` can land before this
|
|
98
|
+
// ever runs — at which point `_cleanupTimer` was still null and dispose() found
|
|
99
|
+
// nothing to clear. Without this guard the deferred sweep would then arm a timer
|
|
100
|
+
// that re-arms itself forever, on an object its owner already disposed.
|
|
101
|
+
if (this._disposed) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
const cutoff = now - constants_1.Numerical.millisecondsInXDays(3);
|
|
107
|
+
let changed = false;
|
|
108
|
+
for (const [u, elementArray] of this.orgCacheMap) {
|
|
109
|
+
const filteredArray = elementArray.filter((element) => element.lastAccess >= cutoff);
|
|
110
|
+
if (filteredArray.length === 0) {
|
|
111
|
+
this.orgCacheMap.delete(u);
|
|
112
|
+
changed = true;
|
|
113
|
+
}
|
|
114
|
+
else if (filteredArray.length < elementArray.length) {
|
|
115
|
+
// `update: false` — this set() would otherwise store() on the spot, and the
|
|
116
|
+
// single write below would then be a second, redundant one.
|
|
117
|
+
this.orgCacheMap.set(u, filteredArray, false);
|
|
118
|
+
changed = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Only write when something actually expired. The old unconditional store()
|
|
122
|
+
// rewrote the whole cache file on every construction, which on Windows is a
|
|
123
|
+
// rapid-fire write that AV / ransomware heuristics penalise (see the retry
|
|
124
|
+
// logic in SharedFilePersistence).
|
|
125
|
+
if (changed) {
|
|
126
|
+
await this.orgCacheMap.store();
|
|
127
|
+
this.onChanged?.();
|
|
49
128
|
}
|
|
50
|
-
|
|
51
|
-
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
if (!this._disposed) {
|
|
132
|
+
this._cleanupTimer = setTimeout(() => void this.runScheduledCleanup(), constants_1.Numerical.millisecondsInXDays(1));
|
|
133
|
+
// Don't keep the process alive just for cleanup (critical for the CLI).
|
|
134
|
+
this._cleanupTimer.unref?.();
|
|
52
135
|
}
|
|
53
136
|
}
|
|
54
|
-
this.orgCacheMap.store();
|
|
55
|
-
this._cleanupTimer = setTimeout(() => this.cleanupOldEntries(), constants_1.Numerical.millisecondsInXDays(1));
|
|
56
|
-
// Don't keep the process alive just for cleanup (critical for the CLI).
|
|
57
|
-
this._cleanupTimer.unref?.();
|
|
58
137
|
}
|
|
59
|
-
/**
|
|
60
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Timer entry point for {@link cleanupOldEntries}. Nothing awaits the timer
|
|
140
|
+
* callback, so this is where a failed scheduled sweep is absorbed — otherwise it
|
|
141
|
+
* would surface as an unhandled rejection a day into a long-running host.
|
|
142
|
+
* @lastreviewed null
|
|
143
|
+
*/
|
|
144
|
+
async runScheduledCleanup() {
|
|
145
|
+
try {
|
|
146
|
+
await this.cleanupOldEntries();
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
this.logger.warn(`OrgCache scheduled cleanup failed; the cache is unchanged: ${String(e)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validates the cache to ensure no duplicate hosts exist.
|
|
154
|
+
*
|
|
155
|
+
* Async for the same reason {@link cleanupOldEntries} is: its `store()` was issued
|
|
156
|
+
* and dropped, so a rejected write became an unhandled rejection. All three callers
|
|
157
|
+
* are already async and now await it.
|
|
158
|
+
* @lastreviewed null
|
|
159
|
+
*/
|
|
160
|
+
async cleanDuplicates(throwIfDuplicateExists = false) {
|
|
61
161
|
const uniqueHosts = new Set();
|
|
62
162
|
for (const [u, elementArray] of this.orgCacheMap) {
|
|
63
163
|
for (const element of elementArray) {
|
|
@@ -75,7 +175,7 @@ class OrgCache {
|
|
|
75
175
|
this.logger.info(`OrgCache contained duplicate host ${element.host}. Cleared U ${foundU}`);
|
|
76
176
|
this.orgCacheMap.delete(foundU);
|
|
77
177
|
}
|
|
78
|
-
this.orgCacheMap.store();
|
|
178
|
+
await this.orgCacheMap.store();
|
|
79
179
|
console.warn(`OrgCache contained duplicate host ${element.host}. Cleared all Us`);
|
|
80
180
|
}
|
|
81
181
|
}
|
|
@@ -85,13 +185,15 @@ class OrgCache {
|
|
|
85
185
|
}
|
|
86
186
|
/** Hard-validates all entries in the cache by calling the orgs to verify the U-host association. */
|
|
87
187
|
async hardValidateAll() {
|
|
88
|
-
this.
|
|
188
|
+
await this.ready;
|
|
189
|
+
await this.cleanDuplicates(true);
|
|
89
190
|
for (const u of this.orgCacheMap.keys()) {
|
|
90
191
|
await this.hardValidateU(u);
|
|
91
192
|
}
|
|
92
193
|
}
|
|
93
194
|
/** Hard-validates an individual U by ensuring each known host connects to the same U. */
|
|
94
195
|
async hardValidateU(u) {
|
|
196
|
+
await this.ready;
|
|
95
197
|
const elementArr = this.orgCacheMap.get(u);
|
|
96
198
|
if (!elementArr) {
|
|
97
199
|
return;
|
|
@@ -124,7 +226,8 @@ class OrgCache {
|
|
|
124
226
|
if (!/^U\d{6}$/.test(u)) {
|
|
125
227
|
throw new Err_1.Err.OrgCacheError("Invalid U format: " + u);
|
|
126
228
|
}
|
|
127
|
-
this.
|
|
229
|
+
await this.ready;
|
|
230
|
+
await this.cleanDuplicates();
|
|
128
231
|
// check cache first
|
|
129
232
|
if (this.orgCacheMap.has(u)) {
|
|
130
233
|
const cacheElement = this.orgCacheMap.get(u);
|
|
@@ -150,7 +253,8 @@ class OrgCache {
|
|
|
150
253
|
}
|
|
151
254
|
/** Associates a host with a U value in the cache. */
|
|
152
255
|
async addHost(u, url) {
|
|
153
|
-
this.
|
|
256
|
+
await this.ready;
|
|
257
|
+
await this.cleanDuplicates(false);
|
|
154
258
|
const host = url.hostname;
|
|
155
259
|
if (this.orgCacheMap.has(u)) {
|
|
156
260
|
const elementArray = this.orgCacheMap.get(u);
|
|
@@ -173,6 +277,7 @@ class OrgCache {
|
|
|
173
277
|
}
|
|
174
278
|
/** Clears the entire cache. */
|
|
175
279
|
async clearCache() {
|
|
280
|
+
await this.ready;
|
|
176
281
|
await this.orgCacheMap.clear();
|
|
177
282
|
this.onChanged?.();
|
|
178
283
|
}
|
|
@@ -181,6 +286,7 @@ class OrgCache {
|
|
|
181
286
|
* If not cached, will attempt to call the org to get the U.
|
|
182
287
|
*/
|
|
183
288
|
async findU(url, cacheOnly = false) {
|
|
289
|
+
await this.ready;
|
|
184
290
|
url = new URL(url);
|
|
185
291
|
const existingU = this.findUCacheOnly(url);
|
|
186
292
|
if (existingU) {
|
|
@@ -194,8 +300,20 @@ class OrgCache {
|
|
|
194
300
|
await this.addHost(U, url);
|
|
195
301
|
return U;
|
|
196
302
|
}
|
|
197
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* Finds the U associated with the provided URL from cache only.
|
|
305
|
+
*
|
|
306
|
+
* Synchronous, so it cannot await the initial load itself. External callers must
|
|
307
|
+
* `await orgCache.whenReady()` first; without that it reports a miss on a cache
|
|
308
|
+
* that is merely not loaded yet, which an unlucky caller turns into a needless
|
|
309
|
+
* BlueHQ round trip. Internal callers all run after {@link ready} has settled.
|
|
310
|
+
* @lastreviewed null
|
|
311
|
+
*/
|
|
198
312
|
findUCacheOnly(url) {
|
|
313
|
+
if (!this.orgCacheMap.isInitialized()) {
|
|
314
|
+
this.logger.warn("OrgCache.findUCacheOnly called before the cache finished loading; reporting a miss.");
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
199
317
|
url = new URL(url);
|
|
200
318
|
const newHostName = url.hostname;
|
|
201
319
|
for (const [u, elementArray] of this.orgCacheMap) {
|
|
@@ -210,6 +328,7 @@ class OrgCache {
|
|
|
210
328
|
return null;
|
|
211
329
|
}
|
|
212
330
|
dispose() {
|
|
331
|
+
this._disposed = true;
|
|
213
332
|
if (this._cleanupTimer) {
|
|
214
333
|
clearTimeout(this._cleanupTimer);
|
|
215
334
|
this._cleanupTimer = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrgCache.js","sourceRoot":"","sources":["../../src/cache/OrgCache.ts"],"names":[],"mappings":";;;AACA,4CAAuD;AACvD,iDAA8C;AAC9C,sDAAmD;AACnD,gCAA6B;AAC7B,gDAAkE;A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QAC3B,OAAO,CAAC,CAAC;IACX,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,GAAQ;QAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAC;YACxG,OAAO,IAAI,CAAC;QACd,CAAC;QACD,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,MAAM,WAAW,GAAG,GAAG,CAAC,QAAQ,CAAC;QACjC,KAAK,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjD,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,IAAI,WAAW,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC;oBACjC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;oBAChC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;oBACtC,OAAO,CAAC,CAAC;gBACX,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ScriptMetaData } from "../types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Persistence } from "../providers";
|
|
3
3
|
/**
|
|
4
4
|
* Persistent store for script metadata.
|
|
5
5
|
*
|
|
@@ -11,7 +11,57 @@ import type { IPersistence } from "../providers";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class ScriptMetaDataStore {
|
|
13
13
|
private readonly metadataMap;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Nesting depth of active {@link beginBatch} calls. While > 0, upserts/removes
|
|
16
|
+
* mutate memory only and defer the disk write. A depth counter (rather than a
|
|
17
|
+
* boolean) keeps two overlapping batches from stranding each other's pending
|
|
18
|
+
* writes — the coalesced write happens only when the outermost batch ends.
|
|
19
|
+
* @lastreviewed null
|
|
20
|
+
*/
|
|
21
|
+
private batchDepth;
|
|
22
|
+
/**
|
|
23
|
+
* Count of deferred writes not yet persisted within the current batch.
|
|
24
|
+
* @lastreviewed null
|
|
25
|
+
*/
|
|
26
|
+
private pendingWrites;
|
|
27
|
+
/**
|
|
28
|
+
* Upper bound on deferred writes before we flush mid-batch. Bounds how much
|
|
29
|
+
* metadata a hard interrupt (SIGINT / crash, which bypasses {@link flush}) can
|
|
30
|
+
* lose, while still collapsing the bulk of a pull's per-script write burst.
|
|
31
|
+
* @lastreviewed null
|
|
32
|
+
*/
|
|
33
|
+
private static readonly BATCH_FLUSH_THRESHOLD;
|
|
34
|
+
constructor(persistence: Persistence);
|
|
35
|
+
private get batching();
|
|
36
|
+
/**
|
|
37
|
+
* Begins a write-coalescing batch: subsequent {@link upsert} / {@link remove}
|
|
38
|
+
* calls mutate the in-memory store but defer the disk write until the matching
|
|
39
|
+
* {@link flush}. Used to collapse the burst of per-script writes during a pull
|
|
40
|
+
* into a single atomic write. Awaits the initial load first so the coalesced
|
|
41
|
+
* write includes pre-existing entries instead of overwriting them. Nestable:
|
|
42
|
+
* each `beginBatch` must be paired with a `flush`.
|
|
43
|
+
* @lastreviewed null
|
|
44
|
+
*/
|
|
45
|
+
beginBatch(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Ends a batch started by {@link beginBatch}. The deferred changes are written
|
|
48
|
+
* in a single store when the outermost batch ends. Safe to call when nothing
|
|
49
|
+
* changed — it writes only when there is a pending change. The batch depth is
|
|
50
|
+
* decremented up front so a failed store never leaves the store stuck in batch
|
|
51
|
+
* mode; but `pendingWrites` is cleared only *after* a successful store. If the
|
|
52
|
+
* store throws, the changes stay marked pending so a later write still
|
|
53
|
+
* persists them (rather than being silently dropped).
|
|
54
|
+
* @lastreviewed null
|
|
55
|
+
*/
|
|
56
|
+
flush(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Persists the in-memory store mid-batch once enough writes have accumulated,
|
|
59
|
+
* so a hard interrupt can't discard an unbounded amount of pulled metadata.
|
|
60
|
+
* `pendingWrites` is cleared only on a successful store; if it throws, the
|
|
61
|
+
* changes remain pending so a later flush retries them.
|
|
62
|
+
* @lastreviewed null
|
|
63
|
+
*/
|
|
64
|
+
private maybeAutoFlush;
|
|
15
65
|
/**
|
|
16
66
|
* Awaits the initial load from persistence. The synchronous read methods
|
|
17
67
|
* ({@link all}, {@link findByScriptName}, …) observe an empty store until this
|