@kosdev-code/kos-test-utils 2.0.2
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/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +11 -0
- package/index.js.map +1 -0
- package/index.mjs +223 -0
- package/index.mjs.map +1 -0
- package/lib/kos-test-utils.d.ts +2 -0
- package/lib/kos-test-utils.d.ts.map +1 -0
- package/mockWs.d.ts +27 -0
- package/mockWs.d.ts.map +1 -0
- package/package.json +13 -0
- package/types/global.d.ts +30 -0
- package/types/index.d.ts +1 -0
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/sdk/kos-test-utils/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var P=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function N(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var C={exports:{}};(function(o){(function(r,n){o.exports?o.exports=n():r.log=n()})(P,function(){var r=function(){},n="undefined",i=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),u=["trace","debug","info","warn","error"],f={},s=null;function g(t,c){var e=t[c];if(typeof e.bind=="function")return e.bind(t);try{return Function.prototype.bind.call(e,t)}catch{return function(){return Function.prototype.apply.apply(e,[t,arguments])}}}function w(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function T(t){return t==="debug"&&(t="log"),typeof console===n?!1:t==="trace"&&i?w:console[t]!==void 0?g(console,t):console.log!==void 0?g(console,"log"):r}function p(){for(var t=this.getLevel(),c=0;c<u.length;c++){var e=u[c];this[e]=c<t?r:this.methodFactory(e,t,this.name)}if(this.log=this.debug,typeof console===n&&t<this.levels.SILENT)return"No console available for logging"}function m(t){return function(){typeof console!==n&&(p.call(this),this[t].apply(this,arguments))}}function x(t,c,e){return T(t)||m.apply(this,arguments)}function A(t,c){var e=this,L,R,h,d="loglevel";typeof t=="string"?d+=":"+t:typeof t=="symbol"&&(d=void 0);function _(l){var a=(u[l]||"silent").toUpperCase();if(!(typeof window===n||!d)){try{window.localStorage[d]=a;return}catch{}try{window.document.cookie=encodeURIComponent(d)+"="+a+";"}catch{}}}function M(){var l;if(!(typeof window===n||!d)){try{l=window.localStorage[d]}catch{}if(typeof l===n)try{var a=window.document.cookie,E=encodeURIComponent(d),O=a.indexOf(E+"=");O!==-1&&(l=/^([^;]+)/.exec(a.slice(O+E.length+1))[1])}catch{}return e.levels[l]===void 0&&(l=void 0),l}}function $(){if(!(typeof window===n||!d)){try{window.localStorage.removeItem(d)}catch{}try{window.document.cookie=encodeURIComponent(d)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function b(l){var a=l;if(typeof a=="string"&&e.levels[a.toUpperCase()]!==void 0&&(a=e.levels[a.toUpperCase()]),typeof a=="number"&&a>=0&&a<=e.levels.SILENT)return a;throw new TypeError("log.setLevel() called with invalid level: "+l)}e.name=t,e.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},e.methodFactory=c||x,e.getLevel=function(){return h??R??L},e.setLevel=function(l,a){return h=b(l),a!==!1&&_(h),p.call(e)},e.setDefaultLevel=function(l){R=b(l),M()||e.setLevel(l,!1)},e.resetLevel=function(){h=null,$(),p.call(e)},e.enableAll=function(l){e.setLevel(e.levels.TRACE,l)},e.disableAll=function(l){e.setLevel(e.levels.SILENT,l)},e.rebuild=function(){if(s!==e&&(L=b(s.getLevel())),p.call(e),s===e)for(var l in f)f[l].rebuild()},L=b(s?s.getLevel():"WARN");var I=M();I!=null&&(h=b(I)),p.call(e)}s=new A,s.getLogger=function(c){if(typeof c!="symbol"&&typeof c!="string"||c==="")throw new TypeError("You must supply a name when creating a logger.");var e=f[c];return e||(e=f[c]=new A(c,s.methodFactory)),e};var U=typeof window!==n?window.log:void 0;return s.noConflict=function(){return typeof window!==n&&window.log===s&&(window.log=U),s},s.getLoggers=function(){return f},s.default=s,s})})(C);var j=C.exports;const v=N(j),q=globalThis.kosUtils.EventBus,W="url";let y={};const B=(o,r)=>{globalThis.kosMockWs=r,globalThis.kosTopicIntercept=n=>{v.debug("confirming intercept data",n);const{headers:i}=S(String(n));v.debug("headers",i);const u=y[i[W]];return v.debug(`handlers found for request: ${!!u}`),{handler:u,requestId:i["request-id"]}},r&&(globalThis.kosWindowWebsocketOpen=()=>{v.warn("Initiated Mock Websocket")},globalThis.kosWindowWebsocketSend=n=>{v.info("Sending",n);const{headers:i}=S(n);v.debug("headers",i);const u=y[i[W]];v.debug("handler",u),u&&globalThis.kosWindowWebsocketRecv(u(i["request-id"]))}),y={...y,...o},v.debug(y)},G=()=>{y={}},J=({body:o={},status:r="200",version:n={major:1,minor:0},headers:i={}})=>(i.type="kos.http.response",i.status=r,D({body:o,status:r,version:n,headers:i})),D=({body:o={},status:r,version:n,headers:i={}})=>`${Object.entries(i).map(([g,w])=>`${g}:${w}
|
|
2
|
+
`).join("")}
|
|
3
|
+
|
|
4
|
+
${JSON.stringify({version:n,status:r,data:o})}`,F=({body:o={},headers:r={}})=>`${Object.entries(r).map(([f,s])=>`${f}:${s}
|
|
5
|
+
`).join("")}
|
|
6
|
+
|
|
7
|
+
${JSON.stringify(o)}`;function S(o){const r=`
|
|
8
|
+
|
|
9
|
+
`,n=`
|
|
10
|
+
`,i=/:(.*)/s,[u,f]=o.split(r).map(g=>g.trim());return{headers:u.split(n).reduce((g,w)=>{const[T,p]=w.split(i).map(m=>m.trim());return T&&p&&(g[T]=p),g},{}),body:f}}const z=o=>{o.headers=o.headers||{},o.headers.type="kos.future",k(o)},K=(o,r)=>{r.headers=r.headers||{},r.headers.topic=o,r.headers.type="kos.broker.topic",k(r)},k=({headers:o={},body:r})=>{q.publish("/mock/msg/receive",F({body:r,headers:o}))};exports.clearHandlers=G;exports.createHttpResponse=J;exports.createTopicMsg=F;exports.initHandlers=B;exports.processMessage=S;exports.sendFuture=z;exports.sendMockWs=k;exports.sendToTopic=K;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../node_modules/loglevel/lib/loglevel.js","../../../../packages/sdk/kos-test-utils/src/mockWs.ts"],"sourcesContent":["/*\n* loglevel - https://github.com/pimterry/loglevel\n*\n* Copyright (c) 2013 Tim Perry\n* Licensed under the MIT license.\n*/\n(function (root, definition) {\n \"use strict\";\n if (typeof define === 'function' && define.amd) {\n define(definition);\n } else if (typeof module === 'object' && module.exports) {\n module.exports = definition();\n } else {\n root.log = definition();\n }\n}(this, function () {\n \"use strict\";\n\n // Slightly dubious tricks to cut down minimized file size\n var noop = function() {};\n var undefinedType = \"undefined\";\n var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (\n /Trident\\/|MSIE /.test(window.navigator.userAgent)\n );\n\n var logMethods = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warn\",\n \"error\"\n ];\n\n var _loggersByName = {};\n var defaultLogger = null;\n\n // Cross-browser bind equivalent that works at least back to IE6\n function bindMethod(obj, methodName) {\n var method = obj[methodName];\n if (typeof method.bind === 'function') {\n return method.bind(obj);\n } else {\n try {\n return Function.prototype.bind.call(method, obj);\n } catch (e) {\n // Missing bind shim or IE8 + Modernizr, fallback to wrapping\n return function() {\n return Function.prototype.apply.apply(method, [obj, arguments]);\n };\n }\n }\n }\n\n // Trace() doesn't print the message in IE, so for that case we need to wrap it\n function traceForIE() {\n if (console.log) {\n if (console.log.apply) {\n console.log.apply(console, arguments);\n } else {\n // In old IE, native console methods themselves don't have apply().\n Function.prototype.apply.apply(console.log, [console, arguments]);\n }\n }\n if (console.trace) console.trace();\n }\n\n // Build the best logging method possible for this env\n // Wherever possible we want to bind, not wrap, to preserve stack traces\n function realMethod(methodName) {\n if (methodName === 'debug') {\n methodName = 'log';\n }\n\n if (typeof console === undefinedType) {\n return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives\n } else if (methodName === 'trace' && isIE) {\n return traceForIE;\n } else if (console[methodName] !== undefined) {\n return bindMethod(console, methodName);\n } else if (console.log !== undefined) {\n return bindMethod(console, 'log');\n } else {\n return noop;\n }\n }\n\n // These private functions always need `this` to be set properly\n\n function replaceLoggingMethods() {\n /*jshint validthis:true */\n var level = this.getLevel();\n\n // Replace the actual methods.\n for (var i = 0; i < logMethods.length; i++) {\n var methodName = logMethods[i];\n this[methodName] = (i < level) ?\n noop :\n this.methodFactory(methodName, level, this.name);\n }\n\n // Define log.log as an alias for log.debug\n this.log = this.debug;\n\n // Return any important warnings.\n if (typeof console === undefinedType && level < this.levels.SILENT) {\n return \"No console available for logging\";\n }\n }\n\n // In old IE versions, the console isn't present until you first open it.\n // We build realMethod() replacements here that regenerate logging methods\n function enableLoggingWhenConsoleArrives(methodName) {\n return function () {\n if (typeof console !== undefinedType) {\n replaceLoggingMethods.call(this);\n this[methodName].apply(this, arguments);\n }\n };\n }\n\n // By default, we use closely bound real methods wherever possible, and\n // otherwise we wait for a console to appear, and then try again.\n function defaultMethodFactory(methodName, _level, _loggerName) {\n /*jshint validthis:true */\n return realMethod(methodName) ||\n enableLoggingWhenConsoleArrives.apply(this, arguments);\n }\n\n function Logger(name, factory) {\n // Private instance variables.\n var self = this;\n /**\n * The level inherited from a parent logger (or a global default). We\n * cache this here rather than delegating to the parent so that it stays\n * in sync with the actual logging methods that we have installed (the\n * parent could change levels but we might not have rebuilt the loggers\n * in this child yet).\n * @type {number}\n */\n var inheritedLevel;\n /**\n * The default level for this logger, if any. If set, this overrides\n * `inheritedLevel`.\n * @type {number|null}\n */\n var defaultLevel;\n /**\n * A user-specific level for this logger. If set, this overrides\n * `defaultLevel`.\n * @type {number|null}\n */\n var userLevel;\n\n var storageKey = \"loglevel\";\n if (typeof name === \"string\") {\n storageKey += \":\" + name;\n } else if (typeof name === \"symbol\") {\n storageKey = undefined;\n }\n\n function persistLevelIfPossible(levelNum) {\n var levelName = (logMethods[levelNum] || 'silent').toUpperCase();\n\n if (typeof window === undefinedType || !storageKey) return;\n\n // Use localStorage if available\n try {\n window.localStorage[storageKey] = levelName;\n return;\n } catch (ignore) {}\n\n // Use session cookie as fallback\n try {\n window.document.cookie =\n encodeURIComponent(storageKey) + \"=\" + levelName + \";\";\n } catch (ignore) {}\n }\n\n function getPersistedLevel() {\n var storedLevel;\n\n if (typeof window === undefinedType || !storageKey) return;\n\n try {\n storedLevel = window.localStorage[storageKey];\n } catch (ignore) {}\n\n // Fallback to cookies if local storage gives us nothing\n if (typeof storedLevel === undefinedType) {\n try {\n var cookie = window.document.cookie;\n var cookieName = encodeURIComponent(storageKey);\n var location = cookie.indexOf(cookieName + \"=\");\n if (location !== -1) {\n storedLevel = /^([^;]+)/.exec(\n cookie.slice(location + cookieName.length + 1)\n )[1];\n }\n } catch (ignore) {}\n }\n\n // If the stored level is not valid, treat it as if nothing was stored.\n if (self.levels[storedLevel] === undefined) {\n storedLevel = undefined;\n }\n\n return storedLevel;\n }\n\n function clearPersistedLevel() {\n if (typeof window === undefinedType || !storageKey) return;\n\n // Use localStorage if available\n try {\n window.localStorage.removeItem(storageKey);\n } catch (ignore) {}\n\n // Use session cookie as fallback\n try {\n window.document.cookie =\n encodeURIComponent(storageKey) + \"=; expires=Thu, 01 Jan 1970 00:00:00 UTC\";\n } catch (ignore) {}\n }\n\n function normalizeLevel(input) {\n var level = input;\n if (typeof level === \"string\" && self.levels[level.toUpperCase()] !== undefined) {\n level = self.levels[level.toUpperCase()];\n }\n if (typeof level === \"number\" && level >= 0 && level <= self.levels.SILENT) {\n return level;\n } else {\n throw new TypeError(\"log.setLevel() called with invalid level: \" + input);\n }\n }\n\n /*\n *\n * Public logger API - see https://github.com/pimterry/loglevel for details\n *\n */\n\n self.name = name;\n\n self.levels = { \"TRACE\": 0, \"DEBUG\": 1, \"INFO\": 2, \"WARN\": 3,\n \"ERROR\": 4, \"SILENT\": 5};\n\n self.methodFactory = factory || defaultMethodFactory;\n\n self.getLevel = function () {\n if (userLevel != null) {\n return userLevel;\n } else if (defaultLevel != null) {\n return defaultLevel;\n } else {\n return inheritedLevel;\n }\n };\n\n self.setLevel = function (level, persist) {\n userLevel = normalizeLevel(level);\n if (persist !== false) { // defaults to true\n persistLevelIfPossible(userLevel);\n }\n\n // NOTE: in v2, this should call rebuild(), which updates children.\n return replaceLoggingMethods.call(self);\n };\n\n self.setDefaultLevel = function (level) {\n defaultLevel = normalizeLevel(level);\n if (!getPersistedLevel()) {\n self.setLevel(level, false);\n }\n };\n\n self.resetLevel = function () {\n userLevel = null;\n clearPersistedLevel();\n replaceLoggingMethods.call(self);\n };\n\n self.enableAll = function(persist) {\n self.setLevel(self.levels.TRACE, persist);\n };\n\n self.disableAll = function(persist) {\n self.setLevel(self.levels.SILENT, persist);\n };\n\n self.rebuild = function () {\n if (defaultLogger !== self) {\n inheritedLevel = normalizeLevel(defaultLogger.getLevel());\n }\n replaceLoggingMethods.call(self);\n\n if (defaultLogger === self) {\n for (var childName in _loggersByName) {\n _loggersByName[childName].rebuild();\n }\n }\n };\n\n // Initialize all the internal levels.\n inheritedLevel = normalizeLevel(\n defaultLogger ? defaultLogger.getLevel() : \"WARN\"\n );\n var initialLevel = getPersistedLevel();\n if (initialLevel != null) {\n userLevel = normalizeLevel(initialLevel);\n }\n replaceLoggingMethods.call(self);\n }\n\n /*\n *\n * Top-level API\n *\n */\n\n defaultLogger = new Logger();\n\n defaultLogger.getLogger = function getLogger(name) {\n if ((typeof name !== \"symbol\" && typeof name !== \"string\") || name === \"\") {\n throw new TypeError(\"You must supply a name when creating a logger.\");\n }\n\n var logger = _loggersByName[name];\n if (!logger) {\n logger = _loggersByName[name] = new Logger(\n name,\n defaultLogger.methodFactory\n );\n }\n return logger;\n };\n\n // Grab the current global log variable in case of overwrite\n var _log = (typeof window !== undefinedType) ? window.log : undefined;\n defaultLogger.noConflict = function() {\n if (typeof window !== undefinedType &&\n window.log === defaultLogger) {\n window.log = _log;\n }\n\n return defaultLogger;\n };\n\n defaultLogger.getLoggers = function getLoggers() {\n return _loggersByName;\n };\n\n // ES6 default export, for compatibility\n defaultLogger['default'] = defaultLogger;\n\n return defaultLogger;\n}));\n","import log from \"loglevel\";\nexport interface KosInternalEvent {\n headers: Record<string | `topic` | `http-request-id`, string>;\n body: string;\n}\n\nconst EventBus = globalThis.kosUtils.EventBus;\nconst HEADER_URL = `url`;\ninterface MessageData {\n body: any;\n status?: string;\n version?: { major: number; minor: number };\n headers: Record<string, string>;\n}\n\nlet handlers: Record<string, (requestId: string) => string> = {};\nexport const initHandlers = (\n _handlers: Record<string, (requestId: string) => string>,\n forceMock: boolean\n) => {\n globalThis.kosMockWs = forceMock;\n\n globalThis.kosTopicIntercept = (data) => {\n log.debug(\"confirming intercept data\", data);\n const { headers } = processMessage(String(data));\n log.debug(\"headers\", headers);\n\n const handler = handlers[headers[HEADER_URL]];\n log.debug(`handlers found for request: ${!!handler}`);\n return { handler, requestId: headers[\"request-id\"] };\n };\n\n if (forceMock) {\n globalThis.kosWindowWebsocketOpen = () => {\n log.warn(\"Initiated Mock Websocket\");\n };\n\n globalThis.kosWindowWebsocketSend = (data: any) => {\n log.info(\"Sending\", data);\n const { headers } = processMessage(data);\n log.debug(\"headers\", headers);\n\n const handler = handlers[headers[HEADER_URL]];\n log.debug(\"handler\", handler);\n if (handler) {\n globalThis.kosWindowWebsocketRecv(handler(headers[\"request-id\"]));\n }\n };\n }\n\n handlers = { ...handlers, ..._handlers };\n log.debug(handlers);\n};\n\nexport const clearHandlers = () => {\n handlers = {};\n};\n\nexport const createHttpResponse = ({\n body = {},\n status = \"200\",\n version = { major: 1, minor: 0 },\n headers = {},\n}: MessageData) => {\n headers[\"type\"] = \"kos.http.response\";\n headers[\"status\"] = status;\n return createMsg({ body, status, version, headers });\n};\nconst createMsg = ({\n body = {},\n status,\n version,\n headers = {},\n}: MessageData) => {\n const headerTxt = Object.entries(headers)\n .map(([key, value]) => `${key}:${value}\\n`)\n .join(\"\");\n const msgData = {\n version,\n status,\n data: body,\n };\n const msg = `${headerTxt}\n\n${JSON.stringify(msgData)}`;\n\n return msg;\n};\n\nexport const createTopicMsg = ({ body = {}, headers = {} }: MessageData) => {\n const headerTxt = Object.entries(headers)\n .map(([key, value]) => `${key}:${value}\\n`)\n .join(\"\");\n const msgData = body;\n const msg = `${headerTxt}\n\n${JSON.stringify(msgData)}`;\n return msg;\n};\nexport function processMessage(data: string): KosInternalEvent {\n const MESSAGE_SEPARATOR = `\\n\\n`;\n const SEPARATOR = `\\n`;\n const HEADER_SEPARATOR = /:(.*)/s;\n\n const [headerText, body] = data\n .split(MESSAGE_SEPARATOR)\n .map((line: string) => line.trim());\n const headers = headerText\n .split(SEPARATOR)\n .reduce((acc: any, curr: string) => {\n const [header, value] = curr\n .split(HEADER_SEPARATOR)\n .map((raw: string) => raw.trim());\n if (header && value) {\n acc[header] = value;\n }\n return acc;\n }, {});\n\n return {\n headers,\n body: body,\n };\n}\n\ninterface MockSendWs {\n headers?: Record<string, string>;\n body: any;\n}\n\nexport const sendFuture = (messageData: MockSendWs) => {\n messageData.headers = messageData.headers || {};\n messageData.headers[\"type\"] = \"kos.future\";\n sendMockWs(messageData);\n};\nexport const sendToTopic = (topic: string, messageData: MockSendWs) => {\n messageData.headers = messageData.headers || {};\n messageData.headers[\"topic\"] = topic;\n messageData.headers[\"type\"] = \"kos.broker.topic\";\n\n sendMockWs(messageData);\n};\nexport const sendMockWs = ({ headers = {}, body }: MockSendWs) => {\n EventBus.publish(\"/mock/msg/receive\", createTopicMsg({ body, headers }));\n};\n\nexport {};\n"],"names":["root","definition","module","this","noop","undefinedType","isIE","logMethods","_loggersByName","defaultLogger","bindMethod","obj","methodName","method","traceForIE","realMethod","replaceLoggingMethods","level","i","enableLoggingWhenConsoleArrives","defaultMethodFactory","_level","_loggerName","Logger","name","factory","self","inheritedLevel","defaultLevel","userLevel","storageKey","persistLevelIfPossible","levelNum","levelName","getPersistedLevel","storedLevel","cookie","cookieName","location","clearPersistedLevel","normalizeLevel","input","persist","childName","initialLevel","logger","_log","EventBus","HEADER_URL","handlers","initHandlers","_handlers","forceMock","data","log","headers","processMessage","handler","clearHandlers","createHttpResponse","body","status","version","createMsg","key","value","createTopicMsg","MESSAGE_SEPARATOR","SEPARATOR","HEADER_SEPARATOR","headerText","line","acc","curr","header","raw","sendFuture","messageData","sendMockWs","sendToTopic","topic"],"mappings":"sUAMC,SAAUA,EAAMC,EAAY,CAIgBC,EAAO,QAC5CA,EAAA,QAAiBD,IAEjBD,EAAK,IAAMC,GAElB,GAACE,EAAM,UAAY,CAIhB,IAAIC,EAAO,UAAW,GAClBC,EAAgB,YAChBC,EAAQ,OAAO,SAAWD,GAAmB,OAAO,OAAO,YAAcA,GACzE,kBAAkB,KAAK,OAAO,UAAU,SAAS,EAGjDE,EAAa,CACb,QACA,QACA,OACA,OACA,OACR,EAEQC,EAAiB,CAAA,EACjBC,EAAgB,KAGpB,SAASC,EAAWC,EAAKC,EAAY,CACjC,IAAIC,EAASF,EAAIC,CAAU,EAC3B,GAAI,OAAOC,EAAO,MAAS,WACvB,OAAOA,EAAO,KAAKF,CAAG,EAEtB,GAAI,CACA,OAAO,SAAS,UAAU,KAAK,KAAKE,EAAQF,CAAG,CAClD,MAAW,CAER,OAAO,UAAW,CACd,OAAO,SAAS,UAAU,MAAM,MAAME,EAAQ,CAACF,EAAK,SAAS,CAAC,CAClF,CACa,CAER,CAGD,SAASG,GAAa,CACd,QAAQ,MACJ,QAAQ,IAAI,MACZ,QAAQ,IAAI,MAAM,QAAS,SAAS,EAGpC,SAAS,UAAU,MAAM,MAAM,QAAQ,IAAK,CAAC,QAAS,SAAS,CAAC,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EAAWD,CAAW,CACxB,EACaE,EAAc,CAACC,EAAeH,IAA4B,CACzDA,EAAA,QAAUA,EAAY,SAAW,CAAA,EACjCA,EAAA,QAAQ,MAAWG,EACnBH,EAAA,QAAQ,KAAU,mBAE9BC,EAAWD,CAAW,CACxB,EACaC,EAAa,CAAC,CAAE,QAAAvB,EAAU,CAAC,EAAG,KAAAK,KAAuB,CAChEb,EAAS,QAAQ,oBAAqBmB,EAAe,CAAE,KAAAN,EAAM,QAAAL,CAAS,CAAA,CAAC,CACzE","x_google_ignoreList":[0]}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var N = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
+
function P(o) {
|
|
3
|
+
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
4
|
+
}
|
|
5
|
+
var C = { exports: {} };
|
|
6
|
+
(function(o) {
|
|
7
|
+
(function(r, n) {
|
|
8
|
+
o.exports ? o.exports = n() : r.log = n();
|
|
9
|
+
})(N, function() {
|
|
10
|
+
var r = function() {
|
|
11
|
+
}, n = "undefined", i = typeof window !== n && typeof window.navigator !== n && /Trident\/|MSIE /.test(window.navigator.userAgent), u = [
|
|
12
|
+
"trace",
|
|
13
|
+
"debug",
|
|
14
|
+
"info",
|
|
15
|
+
"warn",
|
|
16
|
+
"error"
|
|
17
|
+
], d = {}, s = null;
|
|
18
|
+
function g(t, c) {
|
|
19
|
+
var e = t[c];
|
|
20
|
+
if (typeof e.bind == "function")
|
|
21
|
+
return e.bind(t);
|
|
22
|
+
try {
|
|
23
|
+
return Function.prototype.bind.call(e, t);
|
|
24
|
+
} catch {
|
|
25
|
+
return function() {
|
|
26
|
+
return Function.prototype.apply.apply(e, [t, arguments]);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function w() {
|
|
31
|
+
console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
|
|
32
|
+
}
|
|
33
|
+
function L(t) {
|
|
34
|
+
return t === "debug" && (t = "log"), typeof console === n ? !1 : t === "trace" && i ? w : console[t] !== void 0 ? g(console, t) : console.log !== void 0 ? g(console, "log") : r;
|
|
35
|
+
}
|
|
36
|
+
function p() {
|
|
37
|
+
for (var t = this.getLevel(), c = 0; c < u.length; c++) {
|
|
38
|
+
var e = u[c];
|
|
39
|
+
this[e] = c < t ? r : this.methodFactory(e, t, this.name);
|
|
40
|
+
}
|
|
41
|
+
if (this.log = this.debug, typeof console === n && t < this.levels.SILENT)
|
|
42
|
+
return "No console available for logging";
|
|
43
|
+
}
|
|
44
|
+
function m(t) {
|
|
45
|
+
return function() {
|
|
46
|
+
typeof console !== n && (p.call(this), this[t].apply(this, arguments));
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function x(t, c, e) {
|
|
50
|
+
return L(t) || m.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
function k(t, c) {
|
|
53
|
+
var e = this, T, R, h, f = "loglevel";
|
|
54
|
+
typeof t == "string" ? f += ":" + t : typeof t == "symbol" && (f = void 0);
|
|
55
|
+
function U(l) {
|
|
56
|
+
var a = (u[l] || "silent").toUpperCase();
|
|
57
|
+
if (!(typeof window === n || !f)) {
|
|
58
|
+
try {
|
|
59
|
+
window.localStorage[f] = a;
|
|
60
|
+
return;
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
window.document.cookie = encodeURIComponent(f) + "=" + a + ";";
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function S() {
|
|
70
|
+
var l;
|
|
71
|
+
if (!(typeof window === n || !f)) {
|
|
72
|
+
try {
|
|
73
|
+
l = window.localStorage[f];
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
if (typeof l === n)
|
|
77
|
+
try {
|
|
78
|
+
var a = window.document.cookie, E = encodeURIComponent(f), I = a.indexOf(E + "=");
|
|
79
|
+
I !== -1 && (l = /^([^;]+)/.exec(
|
|
80
|
+
a.slice(I + E.length + 1)
|
|
81
|
+
)[1]);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
return e.levels[l] === void 0 && (l = void 0), l;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function _() {
|
|
88
|
+
if (!(typeof window === n || !f)) {
|
|
89
|
+
try {
|
|
90
|
+
window.localStorage.removeItem(f);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
window.document.cookie = encodeURIComponent(f) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function b(l) {
|
|
100
|
+
var a = l;
|
|
101
|
+
if (typeof a == "string" && e.levels[a.toUpperCase()] !== void 0 && (a = e.levels[a.toUpperCase()]), typeof a == "number" && a >= 0 && a <= e.levels.SILENT)
|
|
102
|
+
return a;
|
|
103
|
+
throw new TypeError("log.setLevel() called with invalid level: " + l);
|
|
104
|
+
}
|
|
105
|
+
e.name = t, e.levels = {
|
|
106
|
+
TRACE: 0,
|
|
107
|
+
DEBUG: 1,
|
|
108
|
+
INFO: 2,
|
|
109
|
+
WARN: 3,
|
|
110
|
+
ERROR: 4,
|
|
111
|
+
SILENT: 5
|
|
112
|
+
}, e.methodFactory = c || x, e.getLevel = function() {
|
|
113
|
+
return h ?? R ?? T;
|
|
114
|
+
}, e.setLevel = function(l, a) {
|
|
115
|
+
return h = b(l), a !== !1 && U(h), p.call(e);
|
|
116
|
+
}, e.setDefaultLevel = function(l) {
|
|
117
|
+
R = b(l), S() || e.setLevel(l, !1);
|
|
118
|
+
}, e.resetLevel = function() {
|
|
119
|
+
h = null, _(), p.call(e);
|
|
120
|
+
}, e.enableAll = function(l) {
|
|
121
|
+
e.setLevel(e.levels.TRACE, l);
|
|
122
|
+
}, e.disableAll = function(l) {
|
|
123
|
+
e.setLevel(e.levels.SILENT, l);
|
|
124
|
+
}, e.rebuild = function() {
|
|
125
|
+
if (s !== e && (T = b(s.getLevel())), p.call(e), s === e)
|
|
126
|
+
for (var l in d)
|
|
127
|
+
d[l].rebuild();
|
|
128
|
+
}, T = b(
|
|
129
|
+
s ? s.getLevel() : "WARN"
|
|
130
|
+
);
|
|
131
|
+
var A = S();
|
|
132
|
+
A != null && (h = b(A)), p.call(e);
|
|
133
|
+
}
|
|
134
|
+
s = new k(), s.getLogger = function(c) {
|
|
135
|
+
if (typeof c != "symbol" && typeof c != "string" || c === "")
|
|
136
|
+
throw new TypeError("You must supply a name when creating a logger.");
|
|
137
|
+
var e = d[c];
|
|
138
|
+
return e || (e = d[c] = new k(
|
|
139
|
+
c,
|
|
140
|
+
s.methodFactory
|
|
141
|
+
)), e;
|
|
142
|
+
};
|
|
143
|
+
var F = typeof window !== n ? window.log : void 0;
|
|
144
|
+
return s.noConflict = function() {
|
|
145
|
+
return typeof window !== n && window.log === s && (window.log = F), s;
|
|
146
|
+
}, s.getLoggers = function() {
|
|
147
|
+
return d;
|
|
148
|
+
}, s.default = s, s;
|
|
149
|
+
});
|
|
150
|
+
})(C);
|
|
151
|
+
var j = C.exports;
|
|
152
|
+
const v = /* @__PURE__ */ P(j), H = globalThis.kosUtils.EventBus, M = "url";
|
|
153
|
+
let y = {};
|
|
154
|
+
const G = (o, r) => {
|
|
155
|
+
globalThis.kosMockWs = r, globalThis.kosTopicIntercept = (n) => {
|
|
156
|
+
v.debug("confirming intercept data", n);
|
|
157
|
+
const { headers: i } = O(String(n));
|
|
158
|
+
v.debug("headers", i);
|
|
159
|
+
const u = y[i[M]];
|
|
160
|
+
return v.debug(`handlers found for request: ${!!u}`), { handler: u, requestId: i["request-id"] };
|
|
161
|
+
}, r && (globalThis.kosWindowWebsocketOpen = () => {
|
|
162
|
+
v.warn("Initiated Mock Websocket");
|
|
163
|
+
}, globalThis.kosWindowWebsocketSend = (n) => {
|
|
164
|
+
v.info("Sending", n);
|
|
165
|
+
const { headers: i } = O(n);
|
|
166
|
+
v.debug("headers", i);
|
|
167
|
+
const u = y[i[M]];
|
|
168
|
+
v.debug("handler", u), u && globalThis.kosWindowWebsocketRecv(u(i["request-id"]));
|
|
169
|
+
}), y = { ...y, ...o }, v.debug(y);
|
|
170
|
+
}, J = () => {
|
|
171
|
+
y = {};
|
|
172
|
+
}, D = ({
|
|
173
|
+
body: o = {},
|
|
174
|
+
status: r = "200",
|
|
175
|
+
version: n = { major: 1, minor: 0 },
|
|
176
|
+
headers: i = {}
|
|
177
|
+
}) => (i.type = "kos.http.response", i.status = r, q({ body: o, status: r, version: n, headers: i })), q = ({
|
|
178
|
+
body: o = {},
|
|
179
|
+
status: r,
|
|
180
|
+
version: n,
|
|
181
|
+
headers: i = {}
|
|
182
|
+
}) => `${Object.entries(i).map(([g, w]) => `${g}:${w}
|
|
183
|
+
`).join("")}
|
|
184
|
+
|
|
185
|
+
${JSON.stringify({
|
|
186
|
+
version: n,
|
|
187
|
+
status: r,
|
|
188
|
+
data: o
|
|
189
|
+
})}`, B = ({ body: o = {}, headers: r = {} }) => `${Object.entries(r).map(([d, s]) => `${d}:${s}
|
|
190
|
+
`).join("")}
|
|
191
|
+
|
|
192
|
+
${JSON.stringify(o)}`;
|
|
193
|
+
function O(o) {
|
|
194
|
+
const r = `
|
|
195
|
+
|
|
196
|
+
`, n = `
|
|
197
|
+
`, i = /:(.*)/s, [u, d] = o.split(r).map((g) => g.trim());
|
|
198
|
+
return {
|
|
199
|
+
headers: u.split(n).reduce((g, w) => {
|
|
200
|
+
const [L, p] = w.split(i).map((m) => m.trim());
|
|
201
|
+
return L && p && (g[L] = p), g;
|
|
202
|
+
}, {}),
|
|
203
|
+
body: d
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const z = (o) => {
|
|
207
|
+
o.headers = o.headers || {}, o.headers.type = "kos.future", W(o);
|
|
208
|
+
}, K = (o, r) => {
|
|
209
|
+
r.headers = r.headers || {}, r.headers.topic = o, r.headers.type = "kos.broker.topic", W(r);
|
|
210
|
+
}, W = ({ headers: o = {}, body: r }) => {
|
|
211
|
+
H.publish("/mock/msg/receive", B({ body: r, headers: o }));
|
|
212
|
+
};
|
|
213
|
+
export {
|
|
214
|
+
J as clearHandlers,
|
|
215
|
+
D as createHttpResponse,
|
|
216
|
+
B as createTopicMsg,
|
|
217
|
+
G as initHandlers,
|
|
218
|
+
O as processMessage,
|
|
219
|
+
z as sendFuture,
|
|
220
|
+
W as sendMockWs,
|
|
221
|
+
K as sendToTopic
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../node_modules/loglevel/lib/loglevel.js","../../../../packages/sdk/kos-test-utils/src/mockWs.ts"],"sourcesContent":["/*\n* loglevel - https://github.com/pimterry/loglevel\n*\n* Copyright (c) 2013 Tim Perry\n* Licensed under the MIT license.\n*/\n(function (root, definition) {\n \"use strict\";\n if (typeof define === 'function' && define.amd) {\n define(definition);\n } else if (typeof module === 'object' && module.exports) {\n module.exports = definition();\n } else {\n root.log = definition();\n }\n}(this, function () {\n \"use strict\";\n\n // Slightly dubious tricks to cut down minimized file size\n var noop = function() {};\n var undefinedType = \"undefined\";\n var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (\n /Trident\\/|MSIE /.test(window.navigator.userAgent)\n );\n\n var logMethods = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warn\",\n \"error\"\n ];\n\n var _loggersByName = {};\n var defaultLogger = null;\n\n // Cross-browser bind equivalent that works at least back to IE6\n function bindMethod(obj, methodName) {\n var method = obj[methodName];\n if (typeof method.bind === 'function') {\n return method.bind(obj);\n } else {\n try {\n return Function.prototype.bind.call(method, obj);\n } catch (e) {\n // Missing bind shim or IE8 + Modernizr, fallback to wrapping\n return function() {\n return Function.prototype.apply.apply(method, [obj, arguments]);\n };\n }\n }\n }\n\n // Trace() doesn't print the message in IE, so for that case we need to wrap it\n function traceForIE() {\n if (console.log) {\n if (console.log.apply) {\n console.log.apply(console, arguments);\n } else {\n // In old IE, native console methods themselves don't have apply().\n Function.prototype.apply.apply(console.log, [console, arguments]);\n }\n }\n if (console.trace) console.trace();\n }\n\n // Build the best logging method possible for this env\n // Wherever possible we want to bind, not wrap, to preserve stack traces\n function realMethod(methodName) {\n if (methodName === 'debug') {\n methodName = 'log';\n }\n\n if (typeof console === undefinedType) {\n return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives\n } else if (methodName === 'trace' && isIE) {\n return traceForIE;\n } else if (console[methodName] !== undefined) {\n return bindMethod(console, methodName);\n } else if (console.log !== undefined) {\n return bindMethod(console, 'log');\n } else {\n return noop;\n }\n }\n\n // These private functions always need `this` to be set properly\n\n function replaceLoggingMethods() {\n /*jshint validthis:true */\n var level = this.getLevel();\n\n // Replace the actual methods.\n for (var i = 0; i < logMethods.length; i++) {\n var methodName = logMethods[i];\n this[methodName] = (i < level) ?\n noop :\n this.methodFactory(methodName, level, this.name);\n }\n\n // Define log.log as an alias for log.debug\n this.log = this.debug;\n\n // Return any important warnings.\n if (typeof console === undefinedType && level < this.levels.SILENT) {\n return \"No console available for logging\";\n }\n }\n\n // In old IE versions, the console isn't present until you first open it.\n // We build realMethod() replacements here that regenerate logging methods\n function enableLoggingWhenConsoleArrives(methodName) {\n return function () {\n if (typeof console !== undefinedType) {\n replaceLoggingMethods.call(this);\n this[methodName].apply(this, arguments);\n }\n };\n }\n\n // By default, we use closely bound real methods wherever possible, and\n // otherwise we wait for a console to appear, and then try again.\n function defaultMethodFactory(methodName, _level, _loggerName) {\n /*jshint validthis:true */\n return realMethod(methodName) ||\n enableLoggingWhenConsoleArrives.apply(this, arguments);\n }\n\n function Logger(name, factory) {\n // Private instance variables.\n var self = this;\n /**\n * The level inherited from a parent logger (or a global default). We\n * cache this here rather than delegating to the parent so that it stays\n * in sync with the actual logging methods that we have installed (the\n * parent could change levels but we might not have rebuilt the loggers\n * in this child yet).\n * @type {number}\n */\n var inheritedLevel;\n /**\n * The default level for this logger, if any. If set, this overrides\n * `inheritedLevel`.\n * @type {number|null}\n */\n var defaultLevel;\n /**\n * A user-specific level for this logger. If set, this overrides\n * `defaultLevel`.\n * @type {number|null}\n */\n var userLevel;\n\n var storageKey = \"loglevel\";\n if (typeof name === \"string\") {\n storageKey += \":\" + name;\n } else if (typeof name === \"symbol\") {\n storageKey = undefined;\n }\n\n function persistLevelIfPossible(levelNum) {\n var levelName = (logMethods[levelNum] || 'silent').toUpperCase();\n\n if (typeof window === undefinedType || !storageKey) return;\n\n // Use localStorage if available\n try {\n window.localStorage[storageKey] = levelName;\n return;\n } catch (ignore) {}\n\n // Use session cookie as fallback\n try {\n window.document.cookie =\n encodeURIComponent(storageKey) + \"=\" + levelName + \";\";\n } catch (ignore) {}\n }\n\n function getPersistedLevel() {\n var storedLevel;\n\n if (typeof window === undefinedType || !storageKey) return;\n\n try {\n storedLevel = window.localStorage[storageKey];\n } catch (ignore) {}\n\n // Fallback to cookies if local storage gives us nothing\n if (typeof storedLevel === undefinedType) {\n try {\n var cookie = window.document.cookie;\n var cookieName = encodeURIComponent(storageKey);\n var location = cookie.indexOf(cookieName + \"=\");\n if (location !== -1) {\n storedLevel = /^([^;]+)/.exec(\n cookie.slice(location + cookieName.length + 1)\n )[1];\n }\n } catch (ignore) {}\n }\n\n // If the stored level is not valid, treat it as if nothing was stored.\n if (self.levels[storedLevel] === undefined) {\n storedLevel = undefined;\n }\n\n return storedLevel;\n }\n\n function clearPersistedLevel() {\n if (typeof window === undefinedType || !storageKey) return;\n\n // Use localStorage if available\n try {\n window.localStorage.removeItem(storageKey);\n } catch (ignore) {}\n\n // Use session cookie as fallback\n try {\n window.document.cookie =\n encodeURIComponent(storageKey) + \"=; expires=Thu, 01 Jan 1970 00:00:00 UTC\";\n } catch (ignore) {}\n }\n\n function normalizeLevel(input) {\n var level = input;\n if (typeof level === \"string\" && self.levels[level.toUpperCase()] !== undefined) {\n level = self.levels[level.toUpperCase()];\n }\n if (typeof level === \"number\" && level >= 0 && level <= self.levels.SILENT) {\n return level;\n } else {\n throw new TypeError(\"log.setLevel() called with invalid level: \" + input);\n }\n }\n\n /*\n *\n * Public logger API - see https://github.com/pimterry/loglevel for details\n *\n */\n\n self.name = name;\n\n self.levels = { \"TRACE\": 0, \"DEBUG\": 1, \"INFO\": 2, \"WARN\": 3,\n \"ERROR\": 4, \"SILENT\": 5};\n\n self.methodFactory = factory || defaultMethodFactory;\n\n self.getLevel = function () {\n if (userLevel != null) {\n return userLevel;\n } else if (defaultLevel != null) {\n return defaultLevel;\n } else {\n return inheritedLevel;\n }\n };\n\n self.setLevel = function (level, persist) {\n userLevel = normalizeLevel(level);\n if (persist !== false) { // defaults to true\n persistLevelIfPossible(userLevel);\n }\n\n // NOTE: in v2, this should call rebuild(), which updates children.\n return replaceLoggingMethods.call(self);\n };\n\n self.setDefaultLevel = function (level) {\n defaultLevel = normalizeLevel(level);\n if (!getPersistedLevel()) {\n self.setLevel(level, false);\n }\n };\n\n self.resetLevel = function () {\n userLevel = null;\n clearPersistedLevel();\n replaceLoggingMethods.call(self);\n };\n\n self.enableAll = function(persist) {\n self.setLevel(self.levels.TRACE, persist);\n };\n\n self.disableAll = function(persist) {\n self.setLevel(self.levels.SILENT, persist);\n };\n\n self.rebuild = function () {\n if (defaultLogger !== self) {\n inheritedLevel = normalizeLevel(defaultLogger.getLevel());\n }\n replaceLoggingMethods.call(self);\n\n if (defaultLogger === self) {\n for (var childName in _loggersByName) {\n _loggersByName[childName].rebuild();\n }\n }\n };\n\n // Initialize all the internal levels.\n inheritedLevel = normalizeLevel(\n defaultLogger ? defaultLogger.getLevel() : \"WARN\"\n );\n var initialLevel = getPersistedLevel();\n if (initialLevel != null) {\n userLevel = normalizeLevel(initialLevel);\n }\n replaceLoggingMethods.call(self);\n }\n\n /*\n *\n * Top-level API\n *\n */\n\n defaultLogger = new Logger();\n\n defaultLogger.getLogger = function getLogger(name) {\n if ((typeof name !== \"symbol\" && typeof name !== \"string\") || name === \"\") {\n throw new TypeError(\"You must supply a name when creating a logger.\");\n }\n\n var logger = _loggersByName[name];\n if (!logger) {\n logger = _loggersByName[name] = new Logger(\n name,\n defaultLogger.methodFactory\n );\n }\n return logger;\n };\n\n // Grab the current global log variable in case of overwrite\n var _log = (typeof window !== undefinedType) ? window.log : undefined;\n defaultLogger.noConflict = function() {\n if (typeof window !== undefinedType &&\n window.log === defaultLogger) {\n window.log = _log;\n }\n\n return defaultLogger;\n };\n\n defaultLogger.getLoggers = function getLoggers() {\n return _loggersByName;\n };\n\n // ES6 default export, for compatibility\n defaultLogger['default'] = defaultLogger;\n\n return defaultLogger;\n}));\n","import log from \"loglevel\";\nexport interface KosInternalEvent {\n headers: Record<string | `topic` | `http-request-id`, string>;\n body: string;\n}\n\nconst EventBus = globalThis.kosUtils.EventBus;\nconst HEADER_URL = `url`;\ninterface MessageData {\n body: any;\n status?: string;\n version?: { major: number; minor: number };\n headers: Record<string, string>;\n}\n\nlet handlers: Record<string, (requestId: string) => string> = {};\nexport const initHandlers = (\n _handlers: Record<string, (requestId: string) => string>,\n forceMock: boolean\n) => {\n globalThis.kosMockWs = forceMock;\n\n globalThis.kosTopicIntercept = (data) => {\n log.debug(\"confirming intercept data\", data);\n const { headers } = processMessage(String(data));\n log.debug(\"headers\", headers);\n\n const handler = handlers[headers[HEADER_URL]];\n log.debug(`handlers found for request: ${!!handler}`);\n return { handler, requestId: headers[\"request-id\"] };\n };\n\n if (forceMock) {\n globalThis.kosWindowWebsocketOpen = () => {\n log.warn(\"Initiated Mock Websocket\");\n };\n\n globalThis.kosWindowWebsocketSend = (data: any) => {\n log.info(\"Sending\", data);\n const { headers } = processMessage(data);\n log.debug(\"headers\", headers);\n\n const handler = handlers[headers[HEADER_URL]];\n log.debug(\"handler\", handler);\n if (handler) {\n globalThis.kosWindowWebsocketRecv(handler(headers[\"request-id\"]));\n }\n };\n }\n\n handlers = { ...handlers, ..._handlers };\n log.debug(handlers);\n};\n\nexport const clearHandlers = () => {\n handlers = {};\n};\n\nexport const createHttpResponse = ({\n body = {},\n status = \"200\",\n version = { major: 1, minor: 0 },\n headers = {},\n}: MessageData) => {\n headers[\"type\"] = \"kos.http.response\";\n headers[\"status\"] = status;\n return createMsg({ body, status, version, headers });\n};\nconst createMsg = ({\n body = {},\n status,\n version,\n headers = {},\n}: MessageData) => {\n const headerTxt = Object.entries(headers)\n .map(([key, value]) => `${key}:${value}\\n`)\n .join(\"\");\n const msgData = {\n version,\n status,\n data: body,\n };\n const msg = `${headerTxt}\n\n${JSON.stringify(msgData)}`;\n\n return msg;\n};\n\nexport const createTopicMsg = ({ body = {}, headers = {} }: MessageData) => {\n const headerTxt = Object.entries(headers)\n .map(([key, value]) => `${key}:${value}\\n`)\n .join(\"\");\n const msgData = body;\n const msg = `${headerTxt}\n\n${JSON.stringify(msgData)}`;\n return msg;\n};\nexport function processMessage(data: string): KosInternalEvent {\n const MESSAGE_SEPARATOR = `\\n\\n`;\n const SEPARATOR = `\\n`;\n const HEADER_SEPARATOR = /:(.*)/s;\n\n const [headerText, body] = data\n .split(MESSAGE_SEPARATOR)\n .map((line: string) => line.trim());\n const headers = headerText\n .split(SEPARATOR)\n .reduce((acc: any, curr: string) => {\n const [header, value] = curr\n .split(HEADER_SEPARATOR)\n .map((raw: string) => raw.trim());\n if (header && value) {\n acc[header] = value;\n }\n return acc;\n }, {});\n\n return {\n headers,\n body: body,\n };\n}\n\ninterface MockSendWs {\n headers?: Record<string, string>;\n body: any;\n}\n\nexport const sendFuture = (messageData: MockSendWs) => {\n messageData.headers = messageData.headers || {};\n messageData.headers[\"type\"] = \"kos.future\";\n sendMockWs(messageData);\n};\nexport const sendToTopic = (topic: string, messageData: MockSendWs) => {\n messageData.headers = messageData.headers || {};\n messageData.headers[\"topic\"] = topic;\n messageData.headers[\"type\"] = \"kos.broker.topic\";\n\n sendMockWs(messageData);\n};\nexport const sendMockWs = ({ headers = {}, body }: MockSendWs) => {\n EventBus.publish(\"/mock/msg/receive\", createTopicMsg({ body, headers }));\n};\n\nexport {};\n"],"names":["root","definition","module","this","noop","undefinedType","isIE","logMethods","_loggersByName","defaultLogger","bindMethod","obj","methodName","method","traceForIE","realMethod","replaceLoggingMethods","level","i","enableLoggingWhenConsoleArrives","defaultMethodFactory","_level","_loggerName","Logger","name","factory","self","inheritedLevel","defaultLevel","userLevel","storageKey","persistLevelIfPossible","levelNum","levelName","getPersistedLevel","storedLevel","cookie","cookieName","location","clearPersistedLevel","normalizeLevel","input","persist","childName","initialLevel","logger","_log","EventBus","HEADER_URL","handlers","initHandlers","_handlers","forceMock","data","log","headers","processMessage","handler","clearHandlers","createHttpResponse","body","status","version","createMsg","key","value","createTopicMsg","MESSAGE_SEPARATOR","SEPARATOR","HEADER_SEPARATOR","headerText","line","acc","curr","header","raw","sendFuture","messageData","sendMockWs","sendToTopic","topic"],"mappings":";;;;;;AAMA,GAAC,SAAUA,GAAMC,GAAY;AAIlB,IAAkCC,EAAO,UAC5CA,EAAA,UAAiBD,MAEjBD,EAAK,MAAMC;EAElB,GAACE,GAAM,WAAY;AAIhB,QAAIC,IAAO,WAAW;AAAA,OAClBC,IAAgB,aAChBC,IAAQ,OAAO,WAAWD,KAAmB,OAAO,OAAO,cAAcA,KACzE,kBAAkB,KAAK,OAAO,UAAU,SAAS,GAGjDE,IAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACR,GAEQC,IAAiB,CAAA,GACjBC,IAAgB;AAGpB,aAASC,EAAWC,GAAKC,GAAY;AACjC,UAAIC,IAASF,EAAIC,CAAU;AAC3B,UAAI,OAAOC,EAAO,QAAS;AACvB,eAAOA,EAAO,KAAKF,CAAG;AAEtB,UAAI;AACA,eAAO,SAAS,UAAU,KAAK,KAAKE,G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AAC;AACzE;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kos-test-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/sdk/kos-test-utils/src/lib/kos-test-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
|
package/mockWs.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface KosInternalEvent {
|
|
2
|
+
headers: Record<string | `topic` | `http-request-id`, string>;
|
|
3
|
+
body: string;
|
|
4
|
+
}
|
|
5
|
+
interface MessageData {
|
|
6
|
+
body: any;
|
|
7
|
+
status?: string;
|
|
8
|
+
version?: {
|
|
9
|
+
major: number;
|
|
10
|
+
minor: number;
|
|
11
|
+
};
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare const initHandlers: (_handlers: Record<string, (requestId: string) => string>, forceMock: boolean) => void;
|
|
15
|
+
export declare const clearHandlers: () => void;
|
|
16
|
+
export declare const createHttpResponse: ({ body, status, version, headers, }: MessageData) => string;
|
|
17
|
+
export declare const createTopicMsg: ({ body, headers }: MessageData) => string;
|
|
18
|
+
export declare function processMessage(data: string): KosInternalEvent;
|
|
19
|
+
interface MockSendWs {
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
body: any;
|
|
22
|
+
}
|
|
23
|
+
export declare const sendFuture: (messageData: MockSendWs) => void;
|
|
24
|
+
export declare const sendToTopic: (topic: string, messageData: MockSendWs) => void;
|
|
25
|
+
export declare const sendMockWs: ({ headers, body }: MockSendWs) => void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=mockWs.d.ts.map
|
package/mockWs.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockWs.d.ts","sourceRoot":"","sources":["../../../../packages/sdk/kos-test-utils/src/mockWs.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,gBAAgB;IAC/B,O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_PORT: string;
|
|
8
|
+
KOS_PORT: string;
|
|
9
|
+
KOS_STUDIO_PORT: string;
|
|
10
|
+
KOS_CONNECTION_ALIAS: string;
|
|
11
|
+
KOS_MOCK_WS: string;
|
|
12
|
+
KOS_LOG_WS: string;
|
|
13
|
+
KOS_FOS_PORT: string;
|
|
14
|
+
KOS_USE_FOS: string;
|
|
15
|
+
KOS_WS_TIMEOUT: string;
|
|
16
|
+
KOS_LOG_LEVEL: string;
|
|
17
|
+
KOS_MOCK_FETCH: string;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare global {
|
|
22
|
+
interface Window {
|
|
23
|
+
kosWindowWebsocketOpen: () => void;
|
|
24
|
+
kosWindowWebsocketSend: (
|
|
25
|
+
data: string | ArrayBufferLike | Blob | ArrayBufferView
|
|
26
|
+
) => void;
|
|
27
|
+
kosWindowWebsocketRecv: (msg: string) => void;
|
|
28
|
+
kosLog: (msg: string) => void;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|