@bluestep-systems/b6p-core 0.1.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 +75 -0
- package/dist/B6PCore.d.ts +109 -0
- package/dist/B6PCore.js +470 -0
- package/dist/B6PCore.js.map +1 -0
- package/dist/B6PUri.d.ts +31 -0
- package/dist/B6PUri.js +110 -0
- package/dist/B6PUri.js.map +1 -0
- package/dist/Err.d.ts +470 -0
- package/dist/Err.js +800 -0
- package/dist/Err.js.map +1 -0
- package/dist/auth/BasicAuthProvider.d.ts +39 -0
- package/dist/auth/BasicAuthProvider.js +106 -0
- package/dist/auth/BasicAuthProvider.js.map +1 -0
- package/dist/cache/OrgCache.d.ts +66 -0
- package/dist/cache/OrgCache.js +220 -0
- package/dist/cache/OrgCache.js.map +1 -0
- package/dist/cache/ScriptMetaDataStore.d.ts +39 -0
- package/dist/cache/ScriptMetaDataStore.js +83 -0
- package/dist/cache/ScriptMetaDataStore.js.map +1 -0
- package/dist/constants/ApiEndpoints.d.ts +13 -0
- package/dist/constants/ApiEndpoints.js +18 -0
- package/dist/constants/ApiEndpoints.js.map +1 -0
- package/dist/constants/AuthTypes.d.ts +9 -0
- package/dist/constants/AuthTypes.js +14 -0
- package/dist/constants/AuthTypes.js.map +1 -0
- package/dist/constants/BlueHQ.d.ts +20 -0
- package/dist/constants/BlueHQ.js +36 -0
- package/dist/constants/BlueHQ.js.map +1 -0
- package/dist/constants/CryptoAlgorithms.d.ts +8 -0
- package/dist/constants/CryptoAlgorithms.js +13 -0
- package/dist/constants/CryptoAlgorithms.js.map +1 -0
- package/dist/constants/ExtensionConfig.d.ts +11 -0
- package/dist/constants/ExtensionConfig.js +16 -0
- package/dist/constants/ExtensionConfig.js.map +1 -0
- package/dist/constants/FileExtensions.d.ts +13 -0
- package/dist/constants/FileExtensions.js +18 -0
- package/dist/constants/FileExtensions.js.map +1 -0
- package/dist/constants/FolderNames.d.ts +12 -0
- package/dist/constants/FolderNames.js +17 -0
- package/dist/constants/FolderNames.js.map +1 -0
- package/dist/constants/GitHubUrls.d.ts +12 -0
- package/dist/constants/GitHubUrls.js +17 -0
- package/dist/constants/GitHubUrls.js.map +1 -0
- package/dist/constants/Http.d.ts +57 -0
- package/dist/constants/Http.js +67 -0
- package/dist/constants/Http.js.map +1 -0
- package/dist/constants/MimeTypes.d.ts +9 -0
- package/dist/constants/MimeTypes.js +14 -0
- package/dist/constants/MimeTypes.js.map +1 -0
- package/dist/constants/Numerical.d.ts +14 -0
- package/dist/constants/Numerical.js +32 -0
- package/dist/constants/Numerical.js.map +1 -0
- package/dist/constants/OutputChannels.d.ts +8 -0
- package/dist/constants/OutputChannels.js +13 -0
- package/dist/constants/OutputChannels.js.map +1 -0
- package/dist/constants/SettingsKeys.d.ts +11 -0
- package/dist/constants/SettingsKeys.js +16 -0
- package/dist/constants/SettingsKeys.js.map +1 -0
- package/dist/constants/SpecialFiles.d.ts +10 -0
- package/dist/constants/SpecialFiles.js +15 -0
- package/dist/constants/SpecialFiles.js.map +1 -0
- package/dist/constants/WebDAVElements.d.ts +10 -0
- package/dist/constants/WebDAVElements.js +15 -0
- package/dist/constants/WebDAVElements.js.map +1 -0
- package/dist/constants/index.d.ts +22 -0
- package/dist/constants/index.js +41 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/data/DownstairsPathParser.d.ts +20 -0
- package/dist/data/DownstairsPathParser.js +132 -0
- package/dist/data/DownstairsPathParser.js.map +1 -0
- package/dist/data/GlobMatcher.d.ts +23 -0
- package/dist/data/GlobMatcher.js +135 -0
- package/dist/data/GlobMatcher.js.map +1 -0
- package/dist/data/IdUtility.d.ts +22 -0
- package/dist/data/IdUtility.js +119 -0
- package/dist/data/IdUtility.js.map +1 -0
- package/dist/data/OrgWorker.d.ts +14 -0
- package/dist/data/OrgWorker.js +54 -0
- package/dist/data/OrgWorker.js.map +1 -0
- package/dist/data/ScriptKey.d.ts +93 -0
- package/dist/data/ScriptKey.js +123 -0
- package/dist/data/ScriptKey.js.map +1 -0
- package/dist/data/ScriptUrlParser.d.ts +42 -0
- package/dist/data/ScriptUrlParser.js +258 -0
- package/dist/data/ScriptUrlParser.js.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.js +14 -0
- package/dist/data/index.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/dist/network/HttpClient.d.ts +32 -0
- package/dist/network/HttpClient.js +65 -0
- package/dist/network/HttpClient.js.map +1 -0
- package/dist/network/HttpClientProvider.d.ts +216 -0
- package/dist/network/HttpClientProvider.js +256 -0
- package/dist/network/HttpClientProvider.js.map +1 -0
- package/dist/network/StatusCodes.d.ts +101 -0
- package/dist/network/StatusCodes.js +121 -0
- package/dist/network/StatusCodes.js.map +1 -0
- package/dist/persistence/Persistable.d.ts +9 -0
- package/dist/persistence/Persistable.js +3 -0
- package/dist/persistence/Persistable.js.map +1 -0
- package/dist/persistence/PersistablePseudoMap.d.ts +50 -0
- package/dist/persistence/PersistablePseudoMap.js +62 -0
- package/dist/persistence/PersistablePseudoMap.js.map +1 -0
- package/dist/persistence/PersistenceKeys.d.ts +38 -0
- package/dist/persistence/PersistenceKeys.js +44 -0
- package/dist/persistence/PersistenceKeys.js.map +1 -0
- package/dist/persistence/PrivatePersistanceMap.d.ts +30 -0
- package/dist/persistence/PrivatePersistanceMap.js +67 -0
- package/dist/persistence/PrivatePersistanceMap.js.map +1 -0
- package/dist/persistence/PseudoMap.d.ts +65 -0
- package/dist/persistence/PseudoMap.js +96 -0
- package/dist/persistence/PseudoMap.js.map +1 -0
- package/dist/persistence/PublicPersistanceMap.d.ts +25 -0
- package/dist/persistence/PublicPersistanceMap.js +38 -0
- package/dist/persistence/PublicPersistanceMap.js.map +1 -0
- package/dist/persistence/Serializable.d.ts +40 -0
- package/dist/persistence/Serializable.js +54 -0
- package/dist/persistence/Serializable.js.map +1 -0
- package/dist/persistence/SharedFilePersistence.d.ts +70 -0
- package/dist/persistence/SharedFilePersistence.js +277 -0
- package/dist/persistence/SharedFilePersistence.js.map +1 -0
- package/dist/persistence/TypedMap.d.ts +73 -0
- package/dist/persistence/TypedMap.js +104 -0
- package/dist/persistence/TypedMap.js.map +1 -0
- package/dist/persistence/TypedPersistable.d.ts +36 -0
- package/dist/persistence/TypedPersistable.js +42 -0
- package/dist/persistence/TypedPersistable.js.map +1 -0
- package/dist/persistence/TypedPrivatePersistable.d.ts +124 -0
- package/dist/persistence/TypedPrivatePersistable.js +164 -0
- package/dist/persistence/TypedPrivatePersistable.js.map +1 -0
- package/dist/persistence/dirLockdown.d.ts +12 -0
- package/dist/persistence/dirLockdown.js +73 -0
- package/dist/persistence/dirLockdown.js.map +1 -0
- package/dist/persistence/index.d.ts +11 -0
- package/dist/persistence/index.js +27 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/providers.d.ts +133 -0
- package/dist/providers.js +3 -0
- package/dist/providers.js.map +1 -0
- package/dist/push.d.ts +20 -0
- package/dist/push.js +245 -0
- package/dist/push.js.map +1 -0
- package/dist/script/ScriptContext.d.ts +24 -0
- package/dist/script/ScriptContext.js +3 -0
- package/dist/script/ScriptContext.js.map +1 -0
- package/dist/script/ScriptFactory.d.ts +44 -0
- package/dist/script/ScriptFactory.js +130 -0
- package/dist/script/ScriptFactory.js.map +1 -0
- package/dist/script/ScriptFile.d.ts +62 -0
- package/dist/script/ScriptFile.js +373 -0
- package/dist/script/ScriptFile.js.map +1 -0
- package/dist/script/ScriptFolder.d.ts +43 -0
- package/dist/script/ScriptFolder.js +109 -0
- package/dist/script/ScriptFolder.js.map +1 -0
- package/dist/script/ScriptNode.d.ts +87 -0
- package/dist/script/ScriptNode.js +273 -0
- package/dist/script/ScriptNode.js.map +1 -0
- package/dist/script/ScriptPathElement.d.ts +30 -0
- package/dist/script/ScriptPathElement.js +3 -0
- package/dist/script/ScriptPathElement.js.map +1 -0
- package/dist/script/ScriptRoot.d.ts +61 -0
- package/dist/script/ScriptRoot.js +331 -0
- package/dist/script/ScriptRoot.js.map +1 -0
- package/dist/script/ScriptTranspiler.d.ts +18 -0
- package/dist/script/ScriptTranspiler.js +122 -0
- package/dist/script/ScriptTranspiler.js.map +1 -0
- package/dist/script/SnapshotHistoryRecorder.d.ts +12 -0
- package/dist/script/SnapshotHistoryRecorder.js +175 -0
- package/dist/script/SnapshotHistoryRecorder.js.map +1 -0
- package/dist/script/TsConfig.d.ts +26 -0
- package/dist/script/TsConfig.js +110 -0
- package/dist/script/TsConfig.js.map +1 -0
- package/dist/session/SessionManager.d.ts +77 -0
- package/dist/session/SessionManager.js +290 -0
- package/dist/session/SessionManager.js.map +1 -0
- package/dist/testing/MockFileSystem.d.ts +37 -0
- package/dist/testing/MockFileSystem.js +249 -0
- package/dist/testing/MockFileSystem.js.map +1 -0
- package/dist/testing/TestableFactory.d.ts +61 -0
- package/dist/testing/TestableFactory.js +3 -0
- package/dist/testing/TestableFactory.js.map +1 -0
- package/dist/types.d.ts +577 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/update/UpdateService.d.ts +126 -0
- package/dist/update/UpdateService.js +351 -0
- package/dist/update/UpdateService.js.map +1 -0
- package/dist/update/index.d.ts +2 -0
- package/dist/update/index.js +6 -0
- package/dist/update/index.js.map +1 -0
- package/dist/update/types.d.ts +96 -0
- package/dist/update/types.js +3 -0
- package/dist/update/types.js.map +1 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockFileSystem = exports.UpdateService = exports.ScriptMetaDataStore = exports.OrgCache = exports.SharedFilePersistence = exports.PrivateTypedPersistable = exports.TypedPersistable = exports.PrivateGenericMap = exports.PublicPersistanceMap = exports.PersistablePseudoMap = exports.PublicKeys = exports.PrivateKeys = exports.revive = exports.registerSerializable = exports.TypedMap = exports.PseudoMap = exports.WebDAVElements = exports.SpecialFiles = exports.SettingsKeys = exports.OutputChannels = exports.Numerical = exports.MimeTypes = exports.Http = exports.GitHubUrls = exports.FolderNames = exports.FileExtensions = exports.ExtensionConfig = exports.CryptoAlgorithms = exports.BlueHQ = exports.AuthTypes = exports.ApiEndpoints = exports.ScriptFile = exports.ScriptRoot = exports.ScriptNode = exports.ScriptFactory = exports.ResponseCodes = exports.HttpClient = exports.SessionManager = exports.BasicAuthProvider = exports.ScriptUrlParser = exports.ScriptKey = exports.OrgWorker = exports.IdUtility = exports.GlobMatcher = exports.DownstairsPathParser = exports.executePush = exports.Err = exports.B6PUri = exports.B6PCore = void 0;
|
|
4
|
+
// ─── Top-level entry points ──────────────────────────────────────────
|
|
5
|
+
var B6PCore_1 = require("./B6PCore");
|
|
6
|
+
Object.defineProperty(exports, "B6PCore", { enumerable: true, get: function () { return B6PCore_1.B6PCore; } });
|
|
7
|
+
var B6PUri_1 = require("./B6PUri");
|
|
8
|
+
Object.defineProperty(exports, "B6PUri", { enumerable: true, get: function () { return B6PUri_1.B6PUri; } });
|
|
9
|
+
var Err_1 = require("./Err");
|
|
10
|
+
Object.defineProperty(exports, "Err", { enumerable: true, get: function () { return Err_1.Err; } });
|
|
11
|
+
var push_1 = require("./push");
|
|
12
|
+
Object.defineProperty(exports, "executePush", { enumerable: true, get: function () { return push_1.executePush; } });
|
|
13
|
+
// ─── Pure data classes ───────────────────────────────────────────────
|
|
14
|
+
var DownstairsPathParser_1 = require("./data/DownstairsPathParser");
|
|
15
|
+
Object.defineProperty(exports, "DownstairsPathParser", { enumerable: true, get: function () { return DownstairsPathParser_1.DownstairsPathParser; } });
|
|
16
|
+
var GlobMatcher_1 = require("./data/GlobMatcher");
|
|
17
|
+
Object.defineProperty(exports, "GlobMatcher", { enumerable: true, get: function () { return GlobMatcher_1.GlobMatcher; } });
|
|
18
|
+
var IdUtility_1 = require("./data/IdUtility");
|
|
19
|
+
Object.defineProperty(exports, "IdUtility", { enumerable: true, get: function () { return IdUtility_1.IdUtility; } });
|
|
20
|
+
var OrgWorker_1 = require("./data/OrgWorker");
|
|
21
|
+
Object.defineProperty(exports, "OrgWorker", { enumerable: true, get: function () { return OrgWorker_1.OrgWorker; } });
|
|
22
|
+
var ScriptKey_1 = require("./data/ScriptKey");
|
|
23
|
+
Object.defineProperty(exports, "ScriptKey", { enumerable: true, get: function () { return ScriptKey_1.ScriptKey; } });
|
|
24
|
+
var ScriptUrlParser_1 = require("./data/ScriptUrlParser");
|
|
25
|
+
Object.defineProperty(exports, "ScriptUrlParser", { enumerable: true, get: function () { return ScriptUrlParser_1.ScriptUrlParser; } });
|
|
26
|
+
// ─── Auth + sessions ─────────────────────────────────────────────────
|
|
27
|
+
var BasicAuthProvider_1 = require("./auth/BasicAuthProvider");
|
|
28
|
+
Object.defineProperty(exports, "BasicAuthProvider", { enumerable: true, get: function () { return BasicAuthProvider_1.BasicAuthProvider; } });
|
|
29
|
+
var SessionManager_1 = require("./session/SessionManager");
|
|
30
|
+
Object.defineProperty(exports, "SessionManager", { enumerable: true, get: function () { return SessionManager_1.SessionManager; } });
|
|
31
|
+
// ─── Network ─────────────────────────────────────────────────────────
|
|
32
|
+
var HttpClient_1 = require("./network/HttpClient");
|
|
33
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_1.HttpClient; } });
|
|
34
|
+
var StatusCodes_1 = require("./network/StatusCodes");
|
|
35
|
+
Object.defineProperty(exports, "ResponseCodes", { enumerable: true, get: function () { return StatusCodes_1.ResponseCodes; } });
|
|
36
|
+
// ─── Script tree ─────────────────────────────────────────────────────
|
|
37
|
+
var ScriptFactory_1 = require("./script/ScriptFactory");
|
|
38
|
+
Object.defineProperty(exports, "ScriptFactory", { enumerable: true, get: function () { return ScriptFactory_1.ScriptFactory; } });
|
|
39
|
+
var ScriptNode_1 = require("./script/ScriptNode");
|
|
40
|
+
Object.defineProperty(exports, "ScriptNode", { enumerable: true, get: function () { return ScriptNode_1.ScriptNode; } });
|
|
41
|
+
var ScriptRoot_1 = require("./script/ScriptRoot");
|
|
42
|
+
Object.defineProperty(exports, "ScriptRoot", { enumerable: true, get: function () { return ScriptRoot_1.ScriptRoot; } });
|
|
43
|
+
var ScriptFile_1 = require("./script/ScriptFile");
|
|
44
|
+
Object.defineProperty(exports, "ScriptFile", { enumerable: true, get: function () { return ScriptFile_1.ScriptFile; } });
|
|
45
|
+
// ─── Constants ───────────────────────────────────────────────────────
|
|
46
|
+
var constants_1 = require("./constants");
|
|
47
|
+
Object.defineProperty(exports, "ApiEndpoints", { enumerable: true, get: function () { return constants_1.ApiEndpoints; } });
|
|
48
|
+
Object.defineProperty(exports, "AuthTypes", { enumerable: true, get: function () { return constants_1.AuthTypes; } });
|
|
49
|
+
Object.defineProperty(exports, "BlueHQ", { enumerable: true, get: function () { return constants_1.BlueHQ; } });
|
|
50
|
+
Object.defineProperty(exports, "CryptoAlgorithms", { enumerable: true, get: function () { return constants_1.CryptoAlgorithms; } });
|
|
51
|
+
Object.defineProperty(exports, "ExtensionConfig", { enumerable: true, get: function () { return constants_1.ExtensionConfig; } });
|
|
52
|
+
Object.defineProperty(exports, "FileExtensions", { enumerable: true, get: function () { return constants_1.FileExtensions; } });
|
|
53
|
+
Object.defineProperty(exports, "FolderNames", { enumerable: true, get: function () { return constants_1.FolderNames; } });
|
|
54
|
+
Object.defineProperty(exports, "GitHubUrls", { enumerable: true, get: function () { return constants_1.GitHubUrls; } });
|
|
55
|
+
Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return constants_1.Http; } });
|
|
56
|
+
Object.defineProperty(exports, "MimeTypes", { enumerable: true, get: function () { return constants_1.MimeTypes; } });
|
|
57
|
+
Object.defineProperty(exports, "Numerical", { enumerable: true, get: function () { return constants_1.Numerical; } });
|
|
58
|
+
Object.defineProperty(exports, "OutputChannels", { enumerable: true, get: function () { return constants_1.OutputChannels; } });
|
|
59
|
+
Object.defineProperty(exports, "SettingsKeys", { enumerable: true, get: function () { return constants_1.SettingsKeys; } });
|
|
60
|
+
Object.defineProperty(exports, "SpecialFiles", { enumerable: true, get: function () { return constants_1.SpecialFiles; } });
|
|
61
|
+
Object.defineProperty(exports, "WebDAVElements", { enumerable: true, get: function () { return constants_1.WebDAVElements; } });
|
|
62
|
+
// ─── Persistence ─────────────────────────────────────────────────────
|
|
63
|
+
var persistence_1 = require("./persistence");
|
|
64
|
+
Object.defineProperty(exports, "PseudoMap", { enumerable: true, get: function () { return persistence_1.PseudoMap; } });
|
|
65
|
+
Object.defineProperty(exports, "TypedMap", { enumerable: true, get: function () { return persistence_1.TypedMap; } });
|
|
66
|
+
Object.defineProperty(exports, "registerSerializable", { enumerable: true, get: function () { return persistence_1.registerSerializable; } });
|
|
67
|
+
Object.defineProperty(exports, "revive", { enumerable: true, get: function () { return persistence_1.revive; } });
|
|
68
|
+
Object.defineProperty(exports, "PrivateKeys", { enumerable: true, get: function () { return persistence_1.PrivateKeys; } });
|
|
69
|
+
Object.defineProperty(exports, "PublicKeys", { enumerable: true, get: function () { return persistence_1.PublicKeys; } });
|
|
70
|
+
Object.defineProperty(exports, "PersistablePseudoMap", { enumerable: true, get: function () { return persistence_1.PersistablePseudoMap; } });
|
|
71
|
+
Object.defineProperty(exports, "PublicPersistanceMap", { enumerable: true, get: function () { return persistence_1.PublicPersistanceMap; } });
|
|
72
|
+
Object.defineProperty(exports, "PrivateGenericMap", { enumerable: true, get: function () { return persistence_1.PrivateGenericMap; } });
|
|
73
|
+
Object.defineProperty(exports, "TypedPersistable", { enumerable: true, get: function () { return persistence_1.TypedPersistable; } });
|
|
74
|
+
Object.defineProperty(exports, "PrivateTypedPersistable", { enumerable: true, get: function () { return persistence_1.PrivateTypedPersistable; } });
|
|
75
|
+
var SharedFilePersistence_1 = require("./persistence/SharedFilePersistence");
|
|
76
|
+
Object.defineProperty(exports, "SharedFilePersistence", { enumerable: true, get: function () { return SharedFilePersistence_1.SharedFilePersistence; } });
|
|
77
|
+
// ─── Caches ──────────────────────────────────────────────────────────
|
|
78
|
+
var OrgCache_1 = require("./cache/OrgCache");
|
|
79
|
+
Object.defineProperty(exports, "OrgCache", { enumerable: true, get: function () { return OrgCache_1.OrgCache; } });
|
|
80
|
+
var ScriptMetaDataStore_1 = require("./cache/ScriptMetaDataStore");
|
|
81
|
+
Object.defineProperty(exports, "ScriptMetaDataStore", { enumerable: true, get: function () { return ScriptMetaDataStore_1.ScriptMetaDataStore; } });
|
|
82
|
+
// ─── Update service ──────────────────────────────────────────────────
|
|
83
|
+
var UpdateService_1 = require("./update/UpdateService");
|
|
84
|
+
Object.defineProperty(exports, "UpdateService", { enumerable: true, get: function () { return UpdateService_1.UpdateService; } });
|
|
85
|
+
// ─── Test utilities (still in core because they're vscode-free) ──────
|
|
86
|
+
var MockFileSystem_1 = require("./testing/MockFileSystem");
|
|
87
|
+
Object.defineProperty(exports, "MockFileSystem", { enumerable: true, get: function () { return MockFileSystem_1.MockFileSystem; } });
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAAwE;AACxE,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,+BAAqC;AAA5B,mGAAA,WAAW,OAAA;AAcpB,wEAAwE;AACxE,oEAAmE;AAA1D,4HAAA,oBAAoB,OAAA;AAC7B,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,0DAAyD;AAAhD,kHAAA,eAAe,OAAA;AAExB,wEAAwE;AACxE,8DAA6D;AAApD,sHAAA,iBAAiB,OAAA;AAC1B,2DAA0D;AAAjD,gHAAA,cAAc,OAAA;AAEvB,wEAAwE;AACxE,mDAAkD;AAAzC,wGAAA,UAAU,OAAA;AACnB,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAEtB,wEAAwE;AACxE,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AACtB,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AACnB,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AACnB,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AAInB,wEAAwE;AACxE,yCAgBqB;AAfnB,yGAAA,YAAY,OAAA;AACZ,sGAAA,SAAS,OAAA;AACT,mGAAA,MAAM,OAAA;AACN,6GAAA,gBAAgB,OAAA;AAChB,4GAAA,eAAe,OAAA;AACf,2GAAA,cAAc,OAAA;AACd,wGAAA,WAAW,OAAA;AACX,uGAAA,UAAU,OAAA;AACV,iGAAA,IAAI,OAAA;AACJ,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,2GAAA,cAAc,OAAA;AACd,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,2GAAA,cAAc,OAAA;AAGhB,wEAAwE;AACxE,6CAauB;AAZrB,wGAAA,SAAS,OAAA;AACT,uGAAA,QAAQ,OAAA;AAER,mHAAA,oBAAoB,OAAA;AACpB,qGAAA,MAAM,OAAA;AACN,0GAAA,WAAW,OAAA;AACX,yGAAA,UAAU,OAAA;AACV,mHAAA,oBAAoB,OAAA;AACpB,mHAAA,oBAAoB,OAAA;AACpB,gHAAA,iBAAiB,OAAA;AACjB,+GAAA,gBAAgB,OAAA;AAChB,sHAAA,uBAAuB,OAAA;AAGzB,6EAA4E;AAAnE,8HAAA,qBAAqB,OAAA;AAE9B,wEAAwE;AACxE,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,mEAAkE;AAAzD,0HAAA,mBAAmB,OAAA;AAE5B,wEAAwE;AACxE,wDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAGtB,wEAAwE;AACxE,2DAA0D;AAAjD,gHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HttpClientProvider, MockHttpClient } from "./HttpClientProvider";
|
|
2
|
+
/**
|
|
3
|
+
* Namespace for managing the HTTP client provider.
|
|
4
|
+
* This allows us to switch between real and mock implementations for testing.
|
|
5
|
+
* Conforms to the TestableFactory pattern.
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace HttpClient {
|
|
8
|
+
/**
|
|
9
|
+
* Get the current HTTP client provider instance.
|
|
10
|
+
*/
|
|
11
|
+
function getInstance(): HttpClientProvider;
|
|
12
|
+
/**
|
|
13
|
+
* Set a custom HTTP client provider (mainly for testing).
|
|
14
|
+
*/
|
|
15
|
+
function setProvider(provider: HttpClientProvider): void;
|
|
16
|
+
/**
|
|
17
|
+
* Switch to mock mode for testing.
|
|
18
|
+
*/
|
|
19
|
+
function enableTestMode(): MockHttpClient;
|
|
20
|
+
/**
|
|
21
|
+
* Switch back to real global fetch.
|
|
22
|
+
*/
|
|
23
|
+
function enableProductionMode(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Check if we're currently in test mode.
|
|
26
|
+
*/
|
|
27
|
+
function getIsTestMode(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Reset to default state (production mode).
|
|
30
|
+
*/
|
|
31
|
+
function reset(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const HttpClientProvider_1 = require("./HttpClientProvider");
|
|
5
|
+
/**
|
|
6
|
+
* Namespace for managing the HTTP client provider.
|
|
7
|
+
* This allows us to switch between real and mock implementations for testing.
|
|
8
|
+
* Conforms to the TestableFactory pattern.
|
|
9
|
+
*/
|
|
10
|
+
var HttpClient;
|
|
11
|
+
(function (HttpClient) {
|
|
12
|
+
let instance = new HttpClientProvider_1.GlobalHttpClient();
|
|
13
|
+
let isTestMode = false;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current HTTP client provider instance.
|
|
16
|
+
*/
|
|
17
|
+
function getInstance() {
|
|
18
|
+
return instance;
|
|
19
|
+
}
|
|
20
|
+
HttpClient.getInstance = getInstance;
|
|
21
|
+
/**
|
|
22
|
+
* Set a custom HTTP client provider (mainly for testing).
|
|
23
|
+
*/
|
|
24
|
+
function setProvider(provider) {
|
|
25
|
+
instance = provider;
|
|
26
|
+
}
|
|
27
|
+
HttpClient.setProvider = setProvider;
|
|
28
|
+
/**
|
|
29
|
+
* Switch to mock mode for testing.
|
|
30
|
+
*/
|
|
31
|
+
function enableTestMode() {
|
|
32
|
+
const mockProvider = new HttpClientProvider_1.MockHttpClient();
|
|
33
|
+
instance = mockProvider;
|
|
34
|
+
isTestMode = true;
|
|
35
|
+
return mockProvider;
|
|
36
|
+
}
|
|
37
|
+
HttpClient.enableTestMode = enableTestMode;
|
|
38
|
+
/**
|
|
39
|
+
* Switch back to real global fetch.
|
|
40
|
+
*/
|
|
41
|
+
function enableProductionMode() {
|
|
42
|
+
instance = new HttpClientProvider_1.GlobalHttpClient();
|
|
43
|
+
isTestMode = false;
|
|
44
|
+
}
|
|
45
|
+
HttpClient.enableProductionMode = enableProductionMode;
|
|
46
|
+
/**
|
|
47
|
+
* Check if we're currently in test mode.
|
|
48
|
+
*/
|
|
49
|
+
function getIsTestMode() {
|
|
50
|
+
return isTestMode;
|
|
51
|
+
}
|
|
52
|
+
HttpClient.getIsTestMode = getIsTestMode;
|
|
53
|
+
/**
|
|
54
|
+
* Reset to default state (production mode).
|
|
55
|
+
*/
|
|
56
|
+
function reset() {
|
|
57
|
+
enableProductionMode();
|
|
58
|
+
}
|
|
59
|
+
HttpClient.reset = reset;
|
|
60
|
+
})(HttpClient || (exports.HttpClient = HttpClient = {}));
|
|
61
|
+
// Type assertion to ensure HttpClient conforms to TestableFactory pattern
|
|
62
|
+
const _typeCheck = HttpClient;
|
|
63
|
+
// Prevent unused variable warning
|
|
64
|
+
void _typeCheck;
|
|
65
|
+
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/network/HttpClient.ts"],"names":[],"mappings":";;;AAAA,6DAA4F;AAG5F;;;;GAIG;AACH,IAAiB,UAAU,CAiD1B;AAjDD,WAAiB,UAAU;IACzB,IAAI,QAAQ,GAAuB,IAAI,qCAAgB,EAAE,CAAC;IAC1D,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB;;OAEG;IACH,SAAgB,WAAW;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAFe,sBAAW,cAE1B,CAAA;IAED;;OAEG;IACH,SAAgB,WAAW,CAAC,QAA4B;QACtD,QAAQ,GAAG,QAAQ,CAAC;IACtB,CAAC;IAFe,sBAAW,cAE1B,CAAA;IAED;;OAEG;IACH,SAAgB,cAAc;QAC5B,MAAM,YAAY,GAAG,IAAI,mCAAc,EAAE,CAAC;QAC1C,QAAQ,GAAG,YAAY,CAAC;QACxB,UAAU,GAAG,IAAI,CAAC;QAClB,OAAO,YAAY,CAAC;IACtB,CAAC;IALe,yBAAc,iBAK7B,CAAA;IAED;;OAEG;IACH,SAAgB,oBAAoB;QAClC,QAAQ,GAAG,IAAI,qCAAgB,EAAE,CAAC;QAClC,UAAU,GAAG,KAAK,CAAC;IACrB,CAAC;IAHe,+BAAoB,uBAGnC,CAAA;IAED;;OAEG;IACH,SAAgB,aAAa;QAC3B,OAAO,UAAU,CAAC;IACpB,CAAC;IAFe,wBAAa,gBAE5B,CAAA;IAED;;OAEG;IACH,SAAgB,KAAK;QACnB,oBAAoB,EAAE,CAAC;IACzB,CAAC;IAFe,gBAAK,QAEpB,CAAA;AACH,CAAC,EAjDgB,UAAU,0BAAV,UAAU,QAiD1B;AAED,0EAA0E;AAC1E,MAAM,UAAU,GAA8D,UAAU,CAAC;AACzF,kCAAkC;AAClC,KAAK,UAAU,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface defining HTTP client operations needed for network requests.
|
|
3
|
+
* This allows us to create both real and mock implementations for testing.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the global fetch API to provide a consistent abstraction layer
|
|
6
|
+
* for HTTP operations that can be easily mocked for testing.
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpClientProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Perform an HTTP request using the Fetch API.
|
|
11
|
+
*
|
|
12
|
+
* @param url The URL to request
|
|
13
|
+
* @param options Optional request configuration
|
|
14
|
+
* @returns A promise that resolves to the HTTP response
|
|
15
|
+
* @throws Error if the request fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const response = await httpClient.fetch('https://example.com/api/data');
|
|
20
|
+
* const data = await response.json();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
fetch(url: string | URL, options?: RequestInit): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Real implementation that delegates to the global fetch API.
|
|
27
|
+
*/
|
|
28
|
+
export declare class GlobalHttpClient implements HttpClientProvider {
|
|
29
|
+
fetch(url: string | URL, options?: RequestInit): Promise<Response>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Mock implementation for testing purposes.
|
|
33
|
+
*
|
|
34
|
+
* Provides a configurable HTTP client that can return predefined responses
|
|
35
|
+
* or throw errors for specific URLs, enabling comprehensive testing of
|
|
36
|
+
* network-dependent code without making actual HTTP requests.
|
|
37
|
+
*/
|
|
38
|
+
export declare class MockHttpClient implements HttpClientProvider {
|
|
39
|
+
private responses;
|
|
40
|
+
private requestLog;
|
|
41
|
+
constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Set up a mock response for a specific URL.
|
|
44
|
+
* This is the primary method for preparing test data.
|
|
45
|
+
*
|
|
46
|
+
* @param url The URL that should return this mock response
|
|
47
|
+
* @param response The mock Response object to return
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* mockHttp.setMockResponse('https://api.example.com/data', new Response(
|
|
52
|
+
* JSON.stringify({ id: 1, name: 'Test' }),
|
|
53
|
+
* { status: 200, headers: { 'Content-Type': 'application/json' } }
|
|
54
|
+
* ));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
setMockResponse(url: string, response: Response): void;
|
|
58
|
+
/**
|
|
59
|
+
* Set up a mock response with JSON data for a specific URL.
|
|
60
|
+
* Convenience method for the common case of returning JSON data.
|
|
61
|
+
*
|
|
62
|
+
* @param url The URL that should return this mock response
|
|
63
|
+
* @param data The data to serialize as JSON
|
|
64
|
+
* @param status Optional HTTP status code (default: 200)
|
|
65
|
+
* @param headers Optional additional headers
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* mockHttp.setMockJsonResponse('https://api.example.com/user',
|
|
70
|
+
* { id: 1, username: 'test' },
|
|
71
|
+
* 200,
|
|
72
|
+
* { 'X-Custom-Header': 'value' }
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
setMockJsonResponse(url: string, data: unknown, status?: number, headers?: Record<string, string>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Set up a mock response with plain text for a specific URL.
|
|
79
|
+
* Convenience method for returning text/plain responses.
|
|
80
|
+
*
|
|
81
|
+
* @param url The URL that should return this mock response
|
|
82
|
+
* @param text The text content to return
|
|
83
|
+
* @param status Optional HTTP status code (default: 200)
|
|
84
|
+
* @param headers Optional additional headers
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* mockHttp.setMockTextResponse('https://api.example.com/csrf-token',
|
|
89
|
+
* 'abc123token',
|
|
90
|
+
* 200
|
|
91
|
+
* );
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
setMockTextResponse(url: string, text: string, status?: number, headers?: Record<string, string>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Configure a URL to throw an error when fetched.
|
|
97
|
+
* Useful for testing error handling scenarios.
|
|
98
|
+
*
|
|
99
|
+
* @param url The URL that should throw an error
|
|
100
|
+
* @param error The error to throw when the URL is fetched
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* mockHttp.setMockError(
|
|
105
|
+
* 'https://api.example.com/failing-endpoint',
|
|
106
|
+
* new Error('Network timeout')
|
|
107
|
+
* );
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
setMockError(url: string, error: Error): void;
|
|
111
|
+
/**
|
|
112
|
+
* Clear all mock responses and request logs.
|
|
113
|
+
* Resets the mock HTTP client to an empty state.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Set up some responses
|
|
118
|
+
* mockHttp.setMockJsonResponse('https://api.example.com/data', { id: 1 });
|
|
119
|
+
*
|
|
120
|
+
* // Clear everything for the next test
|
|
121
|
+
* mockHttp.clearMocks();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
clearMocks(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Get all URLs that have been requested.
|
|
127
|
+
* Useful for verifying that expected requests were made during tests.
|
|
128
|
+
*
|
|
129
|
+
* @returns Array of URLs that were requested
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Make some requests
|
|
134
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
135
|
+
* await httpClient.fetch('https://api.example.com/user');
|
|
136
|
+
*
|
|
137
|
+
* // Verify the requests
|
|
138
|
+
* const requests = mockHttp.getRequestLog();
|
|
139
|
+
* assert.strictEqual(requests.length, 2);
|
|
140
|
+
* assert.strictEqual(requests[0].url, 'https://api.example.com/data');
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
getRequestLog(): Array<{
|
|
144
|
+
url: string;
|
|
145
|
+
options?: RequestInit;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Get the last request that was made.
|
|
149
|
+
* Convenience method for checking the most recent request.
|
|
150
|
+
*
|
|
151
|
+
* @returns The last request, or undefined if no requests have been made
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* await httpClient.fetch('https://api.example.com/data', { method: 'POST' });
|
|
156
|
+
*
|
|
157
|
+
* const lastRequest = mockHttp.getLastRequest();
|
|
158
|
+
* assert.strictEqual(lastRequest?.url, 'https://api.example.com/data');
|
|
159
|
+
* assert.strictEqual(lastRequest?.options?.method, 'POST');
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
getLastRequest(): {
|
|
163
|
+
url: string;
|
|
164
|
+
options?: RequestInit;
|
|
165
|
+
} | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Check if a specific URL has been requested.
|
|
168
|
+
*
|
|
169
|
+
* @param url The URL to check for
|
|
170
|
+
* @returns true if the URL was requested, false otherwise
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
175
|
+
*
|
|
176
|
+
* assert.strictEqual(mockHttp.wasRequested('https://api.example.com/data'), true);
|
|
177
|
+
* assert.strictEqual(mockHttp.wasRequested('https://api.example.com/other'), false);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
wasRequested(url: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Get the number of times a specific URL was requested.
|
|
183
|
+
*
|
|
184
|
+
* @param url The URL to count requests for
|
|
185
|
+
* @returns The number of times the URL was requested
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
190
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
191
|
+
*
|
|
192
|
+
* assert.strictEqual(mockHttp.getRequestCount('https://api.example.com/data'), 2);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
getRequestCount(url: string): number;
|
|
196
|
+
/**
|
|
197
|
+
* Set up multiple mock responses at once for testing.
|
|
198
|
+
*
|
|
199
|
+
* @param responses Map of URLs to Response objects
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* mockHttp.setMockResponses({
|
|
204
|
+
* 'https://api.example.com/user': new Response(JSON.stringify({ id: 1 })),
|
|
205
|
+
* 'https://api.example.com/posts': new Response(JSON.stringify([{ id: 1, title: 'Test' }]))
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
setMockResponses(responses: Record<string, Response>): void;
|
|
210
|
+
/**
|
|
211
|
+
* Normalize URL for consistent lookup.
|
|
212
|
+
* Converts URL objects to strings and handles trailing slashes.
|
|
213
|
+
*/
|
|
214
|
+
private normalizeUrl;
|
|
215
|
+
fetch(url: string | URL, options?: RequestInit): Promise<Response>;
|
|
216
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockHttpClient = exports.GlobalHttpClient = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
/**
|
|
6
|
+
* Real implementation that delegates to the global fetch API.
|
|
7
|
+
*/
|
|
8
|
+
class GlobalHttpClient {
|
|
9
|
+
async fetch(url, options) {
|
|
10
|
+
return globalThis.fetch(url, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.GlobalHttpClient = GlobalHttpClient;
|
|
14
|
+
/**
|
|
15
|
+
* Mock implementation for testing purposes.
|
|
16
|
+
*
|
|
17
|
+
* Provides a configurable HTTP client that can return predefined responses
|
|
18
|
+
* or throw errors for specific URLs, enabling comprehensive testing of
|
|
19
|
+
* network-dependent code without making actual HTTP requests.
|
|
20
|
+
*/
|
|
21
|
+
class MockHttpClient {
|
|
22
|
+
responses = new Map();
|
|
23
|
+
requestLog = [];
|
|
24
|
+
constructor() {
|
|
25
|
+
// Initialize with some default behavior
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set up a mock response for a specific URL.
|
|
29
|
+
* This is the primary method for preparing test data.
|
|
30
|
+
*
|
|
31
|
+
* @param url The URL that should return this mock response
|
|
32
|
+
* @param response The mock Response object to return
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* mockHttp.setMockResponse('https://api.example.com/data', new Response(
|
|
37
|
+
* JSON.stringify({ id: 1, name: 'Test' }),
|
|
38
|
+
* { status: 200, headers: { 'Content-Type': 'application/json' } }
|
|
39
|
+
* ));
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
setMockResponse(url, response) {
|
|
43
|
+
this.responses.set(this.normalizeUrl(url), response);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set up a mock response with JSON data for a specific URL.
|
|
47
|
+
* Convenience method for the common case of returning JSON data.
|
|
48
|
+
*
|
|
49
|
+
* @param url The URL that should return this mock response
|
|
50
|
+
* @param data The data to serialize as JSON
|
|
51
|
+
* @param status Optional HTTP status code (default: 200)
|
|
52
|
+
* @param headers Optional additional headers
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* mockHttp.setMockJsonResponse('https://api.example.com/user',
|
|
57
|
+
* { id: 1, username: 'test' },
|
|
58
|
+
* 200,
|
|
59
|
+
* { 'X-Custom-Header': 'value' }
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
setMockJsonResponse(url, data, status = 200, headers = {}) {
|
|
64
|
+
const response = new Response(JSON.stringify(data), {
|
|
65
|
+
status,
|
|
66
|
+
headers: {
|
|
67
|
+
[constants_1.Http.Headers.CONTENT_TYPE]: constants_1.MimeTypes.APPLICATION_JSON,
|
|
68
|
+
...headers,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
this.setMockResponse(url, response);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set up a mock response with plain text for a specific URL.
|
|
75
|
+
* Convenience method for returning text/plain responses.
|
|
76
|
+
*
|
|
77
|
+
* @param url The URL that should return this mock response
|
|
78
|
+
* @param text The text content to return
|
|
79
|
+
* @param status Optional HTTP status code (default: 200)
|
|
80
|
+
* @param headers Optional additional headers
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* mockHttp.setMockTextResponse('https://api.example.com/csrf-token',
|
|
85
|
+
* 'abc123token',
|
|
86
|
+
* 200
|
|
87
|
+
* );
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
setMockTextResponse(url, text, status = 200, headers = {}) {
|
|
91
|
+
const response = new Response(text, {
|
|
92
|
+
status,
|
|
93
|
+
headers: {
|
|
94
|
+
[constants_1.Http.Headers.CONTENT_TYPE]: constants_1.MimeTypes.TEXT_PLAIN,
|
|
95
|
+
...headers,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
this.setMockResponse(url, response);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Configure a URL to throw an error when fetched.
|
|
102
|
+
* Useful for testing error handling scenarios.
|
|
103
|
+
*
|
|
104
|
+
* @param url The URL that should throw an error
|
|
105
|
+
* @param error The error to throw when the URL is fetched
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* mockHttp.setMockError(
|
|
110
|
+
* 'https://api.example.com/failing-endpoint',
|
|
111
|
+
* new Error('Network timeout')
|
|
112
|
+
* );
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
setMockError(url, error) {
|
|
116
|
+
this.responses.set(this.normalizeUrl(url), error);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Clear all mock responses and request logs.
|
|
120
|
+
* Resets the mock HTTP client to an empty state.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Set up some responses
|
|
125
|
+
* mockHttp.setMockJsonResponse('https://api.example.com/data', { id: 1 });
|
|
126
|
+
*
|
|
127
|
+
* // Clear everything for the next test
|
|
128
|
+
* mockHttp.clearMocks();
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
clearMocks() {
|
|
132
|
+
this.responses.clear();
|
|
133
|
+
this.requestLog = [];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get all URLs that have been requested.
|
|
137
|
+
* Useful for verifying that expected requests were made during tests.
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of URLs that were requested
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Make some requests
|
|
144
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
145
|
+
* await httpClient.fetch('https://api.example.com/user');
|
|
146
|
+
*
|
|
147
|
+
* // Verify the requests
|
|
148
|
+
* const requests = mockHttp.getRequestLog();
|
|
149
|
+
* assert.strictEqual(requests.length, 2);
|
|
150
|
+
* assert.strictEqual(requests[0].url, 'https://api.example.com/data');
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
getRequestLog() {
|
|
154
|
+
return [...this.requestLog];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get the last request that was made.
|
|
158
|
+
* Convenience method for checking the most recent request.
|
|
159
|
+
*
|
|
160
|
+
* @returns The last request, or undefined if no requests have been made
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* await httpClient.fetch('https://api.example.com/data', { method: 'POST' });
|
|
165
|
+
*
|
|
166
|
+
* const lastRequest = mockHttp.getLastRequest();
|
|
167
|
+
* assert.strictEqual(lastRequest?.url, 'https://api.example.com/data');
|
|
168
|
+
* assert.strictEqual(lastRequest?.options?.method, 'POST');
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
getLastRequest() {
|
|
172
|
+
return this.requestLog[this.requestLog.length - 1];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check if a specific URL has been requested.
|
|
176
|
+
*
|
|
177
|
+
* @param url The URL to check for
|
|
178
|
+
* @returns true if the URL was requested, false otherwise
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
183
|
+
*
|
|
184
|
+
* assert.strictEqual(mockHttp.wasRequested('https://api.example.com/data'), true);
|
|
185
|
+
* assert.strictEqual(mockHttp.wasRequested('https://api.example.com/other'), false);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
wasRequested(url) {
|
|
189
|
+
const normalized = this.normalizeUrl(url);
|
|
190
|
+
return this.requestLog.some((req) => this.normalizeUrl(req.url) === normalized);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get the number of times a specific URL was requested.
|
|
194
|
+
*
|
|
195
|
+
* @param url The URL to count requests for
|
|
196
|
+
* @returns The number of times the URL was requested
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
201
|
+
* await httpClient.fetch('https://api.example.com/data');
|
|
202
|
+
*
|
|
203
|
+
* assert.strictEqual(mockHttp.getRequestCount('https://api.example.com/data'), 2);
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
getRequestCount(url) {
|
|
207
|
+
const normalized = this.normalizeUrl(url);
|
|
208
|
+
return this.requestLog.filter((req) => this.normalizeUrl(req.url) === normalized).length;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Set up multiple mock responses at once for testing.
|
|
212
|
+
*
|
|
213
|
+
* @param responses Map of URLs to Response objects
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* mockHttp.setMockResponses({
|
|
218
|
+
* 'https://api.example.com/user': new Response(JSON.stringify({ id: 1 })),
|
|
219
|
+
* 'https://api.example.com/posts': new Response(JSON.stringify([{ id: 1, title: 'Test' }]))
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
setMockResponses(responses) {
|
|
224
|
+
Object.entries(responses).forEach(([url, response]) => {
|
|
225
|
+
this.setMockResponse(url, response);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Normalize URL for consistent lookup.
|
|
230
|
+
* Converts URL objects to strings and handles trailing slashes.
|
|
231
|
+
*/
|
|
232
|
+
normalizeUrl(url) {
|
|
233
|
+
const urlString = url instanceof URL ? url.href : url.toString();
|
|
234
|
+
// Remove trailing slash for consistency
|
|
235
|
+
return urlString.endsWith("/") && urlString.length > 1 ? urlString.slice(0, -1) : urlString;
|
|
236
|
+
}
|
|
237
|
+
async fetch(url, options) {
|
|
238
|
+
const urlString = url instanceof URL ? url.href : url.toString();
|
|
239
|
+
const normalizedUrl = this.normalizeUrl(urlString);
|
|
240
|
+
// Log the request
|
|
241
|
+
this.requestLog.push({ url: urlString, options });
|
|
242
|
+
// Check if we have a mock response for this URL
|
|
243
|
+
const mockResponse = this.responses.get(normalizedUrl);
|
|
244
|
+
if (!mockResponse) {
|
|
245
|
+
// No mock configured - throw an error to catch unhandled requests in tests
|
|
246
|
+
throw new Error(`No mock response configured for URL: ${urlString}`);
|
|
247
|
+
}
|
|
248
|
+
if (mockResponse instanceof Error) {
|
|
249
|
+
throw mockResponse;
|
|
250
|
+
}
|
|
251
|
+
// Clone the response so it can be used multiple times
|
|
252
|
+
return mockResponse.clone();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.MockHttpClient = MockHttpClient;
|
|
256
|
+
//# sourceMappingURL=HttpClientProvider.js.map
|