@putkoff/abstract-utilities 1.0.139 → 1.0.142
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/dist/cjs/browser.js +34 -0
- package/dist/cjs/browser.js.map +1 -0
- package/dist/cjs/client.js +0 -2
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/functions.js +1 -5
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.js +1 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/print_utils-DA-vFdOl.js +1907 -0
- package/dist/cjs/print_utils-DA-vFdOl.js.map +1 -0
- package/dist/cjs/readJsonFile.browser-BsrKPMhm.js +34 -0
- package/dist/cjs/readJsonFile.browser-BsrKPMhm.js.map +1 -0
- package/dist/cjs/readJsonFile.node-DqCxMX38.js +19 -0
- package/dist/cjs/readJsonFile.node-DqCxMX38.js.map +1 -0
- package/dist/cjs/server.js +11 -222
- package/dist/cjs/server.js.map +1 -1
- package/dist/esm/browser.js +31 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/client.js +0 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/functions.js +1 -3
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/print_utils-DHCwLBDO.js +1667 -0
- package/dist/esm/print_utils-DHCwLBDO.js.map +1 -0
- package/dist/esm/readJsonFile.browser-C9FwYiRq.js +31 -0
- package/dist/esm/readJsonFile.browser-C9FwYiRq.js.map +1 -0
- package/dist/esm/readJsonFile.node-Dg_ttFdy.js +17 -0
- package/dist/esm/readJsonFile.node-Dg_ttFdy.js.map +1 -0
- package/dist/esm/server.js +11 -211
- package/dist/esm/server.js.map +1 -1
- package/dist/types/browser/index.d.ts +1 -0
- package/dist/types/browser/src/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/imports.d.ts +0 -0
- package/dist/types/browser/src/read_utils/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/src/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/src/readJsonFile.browser.d.ts +6 -0
- package/dist/types/functions/read_utils/src/index.d.ts +0 -2
- package/dist/types/functions/read_utils/src/readJsonFile.browser.d.ts +5 -0
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/server/src/read_utils/imports.d.ts +0 -0
- package/dist/types/server/src/read_utils/index.d.ts +1 -0
- package/dist/types/server/src/read_utils/src/index.d.ts +1 -0
- package/dist/types/server/src/read_utils/src/readJsonFile.node.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
5
|
+
* Returns `undefined` if any step is missing.
|
|
6
|
+
*/
|
|
7
|
+
function safeGlobalProp(...path) {
|
|
8
|
+
let obj = globalThis;
|
|
9
|
+
for (const key of path) {
|
|
10
|
+
if (obj == null || typeof obj !== "object" || !(key in obj)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
obj = obj[key];
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
async function readJsonFileBrowser(url) {
|
|
18
|
+
const fetchFn = safeGlobalProp("fetch");
|
|
19
|
+
if (typeof fetchFn !== "function")
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetchFn(url);
|
|
23
|
+
if (!res.ok)
|
|
24
|
+
return null;
|
|
25
|
+
return (await res.json());
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.readJsonFileBrowser = readJsonFileBrowser;
|
|
33
|
+
exports.safeGlobalProp = safeGlobalProp;
|
|
34
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sources":["../../src/browser/src/read_utils/src/readJsonFile.browser.ts"],"sourcesContent":["/** \n * Safely walk `globalThis` (or window/document) by a chain of property names.\n * Returns `undefined` if any step is missing.\n */\nexport function safeGlobalProp<T = any>(...path: string[]): T | undefined {\n let obj: any = globalThis;\n for (const key of path) {\n if (obj == null || typeof obj !== \"object\" || !(key in obj)) {\n return undefined;\n }\n obj = obj[key];\n }\n return obj as T;\n}\n\nexport async function readJsonFileBrowser<T = any>(\n url: string\n): Promise<T | null> {\n const fetchFn = safeGlobalProp<typeof fetch>(\"fetch\");\n if (typeof fetchFn !== \"function\") return null;\n\n try {\n const res = await fetchFn(url);\n if (!res.ok) return null;\n return (await res.json()) as T;\n } catch {\n return null;\n }\n}\n"],"names":[],"mappings":";;AAAA;;;AAGG;AACG,SAAU,cAAc,CAAU,GAAG,IAAc,EAAA;IACvD,IAAI,GAAG,GAAQ,UAAU;AACzB,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,IAAI,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE;AAC3D,YAAA,OAAO,SAAS;QAClB;AACA,QAAA,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAChB;AACA,IAAA,OAAO,GAAQ;AACjB;AAEO,eAAe,mBAAmB,CACvC,GAAW,EAAA;AAEX,IAAA,MAAM,OAAO,GAAG,cAAc,CAAe,OAAO,CAAC;IACrD,IAAI,OAAO,OAAO,KAAK,UAAU;AAAE,QAAA,OAAO,IAAI;AAE9C,IAAA,IAAI;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,EAAE;AAAE,YAAA,OAAO,IAAI;AACxB,QAAA,QAAQ,MAAM,GAAG,CAAC,IAAI,EAAE;IAC1B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,IAAI;IACb;AACF;;;;;"}
|
package/dist/cjs/client.js
CHANGED
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/client/auth/src/token_client.ts"],"sourcesContent":["\nimport {\n isTokenExpired,\n decodeJwt,\n callStorage,\n} from '../../../functions';\n\n\n/** Read raw JWT from LocalStorage (or null if absent) */\nexport function getToken(): string | null | any {\n return callStorage('getItem', 'token');\n}\n\n\nexport function isLoggedIn() {\n const tok = getToken();\n return !!tok && !isTokenExpired(tok ?? \"\");\n}\n\n\n/**\n * Add a Bearer Authorization header.\n * A shallow copy of headers is returned so callers can keep chaining.\n */\nexport function getAuthorizationHeader(\n headers: Record<string, string> | null = {},\n token: string | null = null\n): Record<string, string> {\n token = token ?? getToken();\n headers = headers || {}\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n return { ...headers };\n}\n\n\n/** Throw + redirect if there’s no valid token; otherwise return it. */\nexport function requireToken(): string {\n const tok = getToken();\n if (!tok || isTokenExpired(tok)) {\n console.warn(\"→ No token or expired token, redirecting to login…\");\n localStorage.removeItem(\"token\");\n window.location.href = '/';\n throw new Error(\"Redirecting to login…\");\n }\n return tok;\n}\n\n\n\n\n/** Convenience wrapper: return username from the JWT (or null). */\nexport function currentUsername() {\n const tok = getToken();\n if (!tok) return null;\n try {\n const { username } = decodeJwt(tok);\n return username ?? null;\n } catch {\n return null;\n }\n}\nexport function currentUsernames() {\n const tok = getToken();\n if (!tok) return null;\n try {\n const parts = tok.split(\".\");\n if (parts.length !== 3) return null;\n let b64 = parts[1].replace(/-/g, \"+\").replace(/_/g, \"/\");\n b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, \"=\");\n const jsonText = atob(b64);\n const payload = JSON.parse(jsonText);\n return payload.username ?? null;\n } catch {\n return null;\n }\n}\n\n/** Remove the JWT from LocalStorage */\nexport function removeToken(): void {\n try {\n callStorage('removeItem', 'token');\n } catch (err) {\n console.warn(\"Failed to remove token:\", err);\n }\n}"],"names":["callStorage","isTokenExpired","decodeJwt"],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/client/auth/src/token_client.ts"],"sourcesContent":["\nimport {\n isTokenExpired,\n decodeJwt,\n callStorage,\n} from '../../../functions';\n\n\n/** Read raw JWT from LocalStorage (or null if absent) */\nexport function getToken(): string | null | any {\n return callStorage('getItem', 'token');\n}\n\n\nexport function isLoggedIn() {\n const tok = getToken();\n return !!tok && !isTokenExpired(tok ?? \"\");\n}\n\n\n/**\n * Add a Bearer Authorization header.\n * A shallow copy of headers is returned so callers can keep chaining.\n */\nexport function getAuthorizationHeader(\n headers: Record<string, string> | null = {},\n token: string | null = null\n): Record<string, string> {\n token = token ?? getToken();\n headers = headers || {}\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n return { ...headers };\n}\n\n\n/** Throw + redirect if there’s no valid token; otherwise return it. */\nexport function requireToken(): string {\n const tok = getToken();\n if (!tok || isTokenExpired(tok)) {\n console.warn(\"→ No token or expired token, redirecting to login…\");\n localStorage.removeItem(\"token\");\n window.location.href = '/';\n throw new Error(\"Redirecting to login…\");\n }\n return tok;\n}\n\n\n\n\n/** Convenience wrapper: return username from the JWT (or null). */\nexport function currentUsername() {\n const tok = getToken();\n if (!tok) return null;\n try {\n const { username } = decodeJwt(tok);\n return username ?? null;\n } catch {\n return null;\n }\n}\nexport function currentUsernames() {\n const tok = getToken();\n if (!tok) return null;\n try {\n const parts = tok.split(\".\");\n if (parts.length !== 3) return null;\n let b64 = parts[1].replace(/-/g, \"+\").replace(/_/g, \"/\");\n b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, \"=\");\n const jsonText = atob(b64);\n const payload = JSON.parse(jsonText);\n return payload.username ?? null;\n } catch {\n return null;\n }\n}\n\n/** Remove the JWT from LocalStorage */\nexport function removeToken(): void {\n try {\n callStorage('removeItem', 'token');\n } catch (err) {\n console.warn(\"Failed to remove token:\", err);\n }\n}"],"names":["callStorage","isTokenExpired","decodeJwt"],"mappings":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gB,GAAA;AAC9B,IAAA,MAAM,GAAG,GAAG,QAAQ,EAAE;AACtB,IAAA,IAAI,CAAC,GAAG;AAAE,QAAA,OAAO,IAAI;AACrB,IAAA,IAAI;QACF,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5B,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;AAAE,YAAA,OAAO,IAAI;QACnC,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;QACxD,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;AACpD,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;AACpC,QAAA,OAAO,OAAO,CAAC,QAAQ,IAAI,IAAI;IACjC;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,IAAI;IACb;AACF;AAEA;SACgB,WAAW,GAAA;AACzB,IAAA,IAAI;AACF,QAAAF,sBAAW,CAAC,YAAY,EAAE,OAAO,CAAC;IACpC;IAAE,OAAO,GAAG,EAAE;AACZ,QAAA,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC;IAC9C;AACF;;;;;;;;;;"}
|
package/dist/cjs/functions.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var mime_utils = require('./mime_utils-C53pEVr1.js');
|
|
4
|
-
var print_utils = require('./print_utils-
|
|
4
|
+
var print_utils = require('./print_utils-DA-vFdOl.js');
|
|
5
5
|
var util = require('util');
|
|
6
6
|
require('path');
|
|
7
|
-
require('node:fs');
|
|
8
|
-
require('node:path');
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
|
|
@@ -239,8 +237,6 @@ exports.path_to_url = print_utils.path_to_url;
|
|
|
239
237
|
exports.pathjoin = print_utils.pathjoin;
|
|
240
238
|
exports.processKeywords = print_utils.processKeywords;
|
|
241
239
|
exports.readJsonFile = print_utils.readJsonFile;
|
|
242
|
-
exports.readJsonFileBrowser = print_utils.readJsonFileBrowser;
|
|
243
|
-
exports.readJsonFileNode = print_utils.readJsonFileNode;
|
|
244
240
|
exports.removeToken = print_utils.removeToken;
|
|
245
241
|
exports.requireToken = print_utils.requireToken;
|
|
246
242
|
exports.roundPercentage = print_utils.roundPercentage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var mime_utils = require('./mime_utils-C53pEVr1.js');
|
|
4
|
-
var print_utils = require('./print_utils-
|
|
4
|
+
var print_utils = require('./print_utils-DA-vFdOl.js');
|
|
5
5
|
var util = require('util');
|
|
6
6
|
require('path');
|
|
7
|
-
require('node:fs');
|
|
8
|
-
require('node:path');
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
|
|
@@ -239,8 +237,6 @@ exports.path_to_url = print_utils.path_to_url;
|
|
|
239
237
|
exports.pathjoin = print_utils.pathjoin;
|
|
240
238
|
exports.processKeywords = print_utils.processKeywords;
|
|
241
239
|
exports.readJsonFile = print_utils.readJsonFile;
|
|
242
|
-
exports.readJsonFileBrowser = print_utils.readJsonFileBrowser;
|
|
243
|
-
exports.readJsonFileNode = print_utils.readJsonFileNode;
|
|
244
240
|
exports.removeToken = print_utils.removeToken;
|
|
245
241
|
exports.requireToken = print_utils.requireToken;
|
|
246
242
|
exports.roundPercentage = print_utils.roundPercentage;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|