@putkoff/abstract-utilities 1.0.52 → 1.0.63

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.
Files changed (114) hide show
  1. package/dist/cjs/index.js +214 -374
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +222 -356
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.ts +1 -45
  6. package/dist/types/client/auth/index.d.ts +1 -0
  7. package/dist/types/client/auth/src/index.d.ts +1 -0
  8. package/dist/types/client/auth/src/token_client.d.ts +15 -0
  9. package/dist/types/client/fetch/src/fetch_auth.d.ts +3 -0
  10. package/dist/types/client/fetch/src/index.d.ts +1 -0
  11. package/dist/types/client/index.d.ts +2 -0
  12. package/dist/types/client/ui_utils/index.d.ts +1 -0
  13. package/dist/types/client/ui_utils/src/button.d.ts +6 -0
  14. package/dist/types/client/ui_utils/src/checkbox.d.ts +4 -0
  15. package/dist/types/client/ui_utils/src/index.d.ts +4 -0
  16. package/dist/types/client/ui_utils/src/input.d.ts +5 -0
  17. package/dist/types/client/ui_utils/src/spinner.d.ts +1 -0
  18. package/dist/types/functions/auth_utils/imports.d.ts +0 -0
  19. package/dist/types/functions/auth_utils/index.d.ts +0 -0
  20. package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
  21. package/dist/types/functions/auth_utils/src/jwt_core.d.ts +7 -0
  22. package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +7 -0
  23. package/dist/types/functions/auth_utils/src/token_utils.d.ts +0 -0
  24. package/dist/types/functions/config_utils/imports.d.ts +0 -0
  25. package/dist/types/functions/config_utils/index.d.ts +0 -0
  26. package/dist/types/functions/config_utils/src/config_utils.d.ts +0 -0
  27. package/dist/types/functions/config_utils/src/index.d.ts +0 -0
  28. package/dist/types/functions/constants_utils/index.d.ts +0 -0
  29. package/dist/types/functions/constants_utils/src/constants.d.ts +0 -0
  30. package/dist/types/functions/constants_utils/src/index.d.ts +0 -0
  31. package/dist/types/functions/env_utils/imports.d.ts +0 -0
  32. package/dist/types/functions/env_utils/index.d.ts +0 -0
  33. package/dist/types/functions/env_utils/src/index.d.ts +0 -0
  34. package/dist/types/functions/env_utils/src/window_utils.d.ts +0 -0
  35. package/dist/types/functions/fetch_utils/imports.d.ts +0 -1
  36. package/dist/types/functions/fetch_utils/index.d.ts +0 -0
  37. package/dist/types/functions/fetch_utils/src/fetch_utils.d.ts +0 -0
  38. package/dist/types/functions/fetch_utils/src/index.d.ts +0 -0
  39. package/dist/types/functions/fetch_utils/src/url_utils.d.ts +0 -0
  40. package/dist/types/functions/fetch_utils/src/utils.d.ts +0 -0
  41. package/dist/types/functions/index.d.ts +0 -2
  42. package/dist/types/functions/math_utils/constants.d.ts +0 -0
  43. package/dist/types/functions/math_utils/conversions.d.ts +0 -0
  44. package/dist/types/functions/math_utils/index.d.ts +0 -0
  45. package/dist/types/functions/math_utils/safe_math.d.ts +0 -0
  46. package/dist/types/functions/math_utils/scaleInterfaces.d.ts +0 -0
  47. package/dist/types/functions/path_utils/imports.d.ts +0 -0
  48. package/dist/types/functions/path_utils/index.d.ts +0 -0
  49. package/dist/types/functions/path_utils/src/base_dirs.d.ts +0 -0
  50. package/dist/types/functions/path_utils/src/function_dirs.d.ts +0 -0
  51. package/dist/types/functions/path_utils/src/index.d.ts +0 -0
  52. package/dist/types/functions/path_utils/src/misc_dirs.d.ts +0 -0
  53. package/dist/types/functions/path_utils/src/path_utils.d.ts +0 -0
  54. package/dist/types/functions/path_utils/src/paths.d.ts +0 -0
  55. package/dist/types/functions/path_utils/src/src_dirs.d.ts +0 -0
  56. package/dist/types/functions/read_utils/imports.d.ts +0 -0
  57. package/dist/types/functions/read_utils/index.d.ts +0 -0
  58. package/dist/types/functions/read_utils/src/index.d.ts +0 -0
  59. package/dist/types/functions/read_utils/src/utils.d.ts +0 -0
  60. package/dist/types/functions/rndm_utils/imports.d.ts +0 -0
  61. package/dist/types/functions/rndm_utils/index.d.ts +0 -0
  62. package/dist/types/functions/rndm_utils/src/index.d.ts +0 -0
  63. package/dist/types/functions/rndm_utils/src/utils.d.ts +0 -0
  64. package/dist/types/functions/safe_utils/imports.d.ts +0 -0
  65. package/dist/types/functions/safe_utils/index.d.ts +0 -0
  66. package/dist/types/functions/safe_utils/src/index.d.ts +0 -0
  67. package/dist/types/functions/safe_utils/src/safe_document.d.ts +0 -0
  68. package/dist/types/functions/safe_utils/src/safe_globals.d.ts +0 -0
  69. package/dist/types/functions/safe_utils/src/safe_storage.d.ts +0 -0
  70. package/dist/types/functions/safe_utils/src/safe_window.d.ts +0 -0
  71. package/dist/types/functions/string_utils/index.d.ts +0 -0
  72. package/dist/types/functions/string_utils/src/index.d.ts +0 -0
  73. package/dist/types/functions/string_utils/src/string_utils.d.ts +0 -0
  74. package/dist/types/functions/type_utils/imports.d.ts +0 -0
  75. package/dist/types/functions/type_utils/index.d.ts +0 -0
  76. package/dist/types/functions/type_utils/src/clean_utils.d.ts +0 -0
  77. package/dist/types/functions/type_utils/src/ensure_utils.d.ts +0 -0
  78. package/dist/types/functions/type_utils/src/imports.d.ts +0 -0
  79. package/dist/types/functions/type_utils/src/index.d.ts +0 -0
  80. package/dist/types/functions/type_utils/src/json_utils.d.ts +0 -0
  81. package/dist/types/functions/type_utils/src/list_utils.d.ts +0 -0
  82. package/dist/types/functions/type_utils/src/mime_utils.d.ts +0 -0
  83. package/dist/types/functions/type_utils/src/type_utils.d.ts +0 -0
  84. package/dist/types/functions/ui_utils/imports.d.ts +0 -0
  85. package/dist/types/functions/ui_utils/index.d.ts +0 -0
  86. package/dist/types/functions/ui_utils/src/button.d.ts +0 -0
  87. package/dist/types/functions/ui_utils/src/checkbox.d.ts +0 -0
  88. package/dist/types/functions/ui_utils/src/index.d.ts +0 -0
  89. package/dist/types/functions/ui_utils/src/input.d.ts +0 -0
  90. package/dist/types/functions/ui_utils/src/spinner.d.ts +0 -0
  91. package/dist/types/functions/variable_utils/imports.d.ts +0 -0
  92. package/dist/types/functions/variable_utils/index.d.ts +0 -0
  93. package/dist/types/functions/variable_utils/src/index.d.ts +0 -0
  94. package/dist/types/functions/variable_utils/src/variable_utils.d.ts +0 -0
  95. package/dist/types/index.d.ts +0 -0
  96. package/dist/types/types/index.d.ts +0 -0
  97. package/dist/types/types/src/ChangePassword.d.ts +0 -0
  98. package/dist/types/types/src/Files.d.ts +0 -0
  99. package/dist/types/types/src/index.d.ts +0 -0
  100. package/dist/types/types/src/login.d.ts +0 -0
  101. package/dist/types/types/src/logout.d.ts +0 -0
  102. package/dist/types/types/src/utils.d.ts +0 -0
  103. package/dist/types/ui/Navbar/DropDowns/DropDownElements.d.ts +8 -0
  104. package/dist/types/ui/Navbar/DropDowns/ForumsDropdown.d.ts +2 -0
  105. package/dist/types/ui/Navbar/DropDowns/index.d.ts +3 -0
  106. package/dist/types/ui/Navbar/NavBar.d.ts +8 -0
  107. package/dist/types/ui/Navbar/index.d.ts +3 -0
  108. package/dist/types/ui/index.d.ts +1 -0
  109. package/dist/types/utils/imports.d.ts +0 -0
  110. package/dist/types/utils/index.d.ts +0 -0
  111. package/dist/types/utils/src/Input.d.ts +0 -0
  112. package/dist/types/utils/src/config.d.ts +0 -0
  113. package/dist/types/utils/src/index.d.ts +0 -0
  114. package/package.json +11 -1
package/dist/esm/index.js CHANGED
@@ -1,6 +1,3 @@
1
- export { useCallback, useEffect, useRef, useState } from 'react';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
-
4
1
  function _mergeNamespaces(n, m) {
5
2
  m.forEach(function (e) {
6
3
  e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
@@ -16,167 +13,6 @@ function _mergeNamespaces(n, m) {
16
13
  return Object.freeze(n);
17
14
  }
18
15
 
19
- function getSafeDocument() {
20
- return typeof document !== 'undefined' ? document : undefined;
21
- }
22
- function getDocumentProp(...keys) {
23
- let obj = getSafeDocument();
24
- for (const k of keys) {
25
- if (obj == null || typeof obj !== 'object')
26
- return undefined;
27
- obj = obj[k];
28
- }
29
- return obj;
30
- }
31
-
32
- /**
33
- * Safely walk `globalThis` (or window/document) by a chain of property names.
34
- * Returns `undefined` if any step is missing.
35
- */
36
- function safeGlobalProp(...path) {
37
- let obj = globalThis;
38
- for (const key of path) {
39
- if (obj == null || typeof obj !== "object" || !(key in obj)) {
40
- return undefined;
41
- }
42
- obj = obj[key];
43
- }
44
- return obj;
45
- }
46
-
47
- /**
48
- * Returns `window` if running in a browser, otherwise `undefined`.
49
- */
50
- function getSafeLocalStorage() {
51
- if (typeof window === 'undefined')
52
- return undefined;
53
- try {
54
- return window.localStorage;
55
- }
56
- catch (_a) {
57
- return undefined; // e.g. Safari private-mode block
58
- }
59
- }
60
- /**
61
- * Call a Storage method by name, silencing any errors or missing storage.
62
- *
63
- * @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
64
- * @param args The arguments you’d normally pass to that method.
65
- * @returns The method’s return value, or undefined if storage/method isn’t available.
66
- */
67
- function callStorage(method, ...args) {
68
- const storage = getSafeLocalStorage();
69
- if (!storage)
70
- return undefined;
71
- const fn = storage[method];
72
- if (typeof fn !== 'function')
73
- return undefined;
74
- try {
75
- // @ts-ignore – TS can’t infer that this is callable
76
- return fn.apply(storage, args);
77
- }
78
- catch (_a) {
79
- return undefined;
80
- }
81
- }
82
- /**
83
- * Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
84
- * Returns `undefined` on any error.
85
- */
86
- function safeStorage(storageName, method, ...args) {
87
- try {
88
- const store = safeGlobalProp(storageName);
89
- if (!store || typeof store[method] !== "function")
90
- return undefined;
91
- // @ts-ignore
92
- return store[method](...args);
93
- }
94
- catch (_a) {
95
- return undefined;
96
- }
97
- }
98
-
99
- /**
100
- * Returns the global window object if it exists, otherwise undefined.
101
- */
102
- function getSafeWindow() {
103
- return typeof window !== 'undefined' ? window : undefined;
104
- }
105
- /**
106
- * Safely call a method on window by name.
107
- *
108
- * @param method The Window method to call (e.g. "alert", "open", etc.).
109
- * @param args Arguments to pass to that method.
110
- * @returns The method’s return value, or undefined if
111
- * window/method isn’t available or throws.
112
- */
113
- function callWindowMethod(method, ...args) {
114
- const w = getSafeWindow();
115
- if (!w)
116
- return undefined;
117
- const fn = w[method];
118
- if (typeof fn !== 'function')
119
- return undefined;
120
- try {
121
- // cast to any so TS doesn’t complain about apply/invoke
122
- return fn(...args);
123
- }
124
- catch (_a) {
125
- return undefined;
126
- }
127
- }
128
- /** implementation */
129
- function getWindowProp(...keys) {
130
- let obj = getSafeWindow();
131
- for (const k of keys) {
132
- if (obj == null || typeof obj !== 'object')
133
- return undefined;
134
- obj = obj[k];
135
- }
136
- return obj;
137
- }
138
- function getWindowHost() {
139
- return getWindowProp('location', 'host');
140
- }
141
-
142
- /**
143
- ***Changes**:
144
- *- Updated import path for `InputProps` to `../../types/interfaces`.
145
- *
146
- *3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
147
- * Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
148
- *
149
- */
150
- /** Read raw JWT from LocalStorage (or null if absent) */
151
- function getToken() {
152
- return callStorage('getItem', 'token');
153
- }
154
- function isLoggedIn() {
155
- const tok = getToken();
156
- return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
157
- }
158
- /**
159
- * Add a Bearer Authorization header.
160
- * A shallow copy of headers is returned so callers can keep chaining.
161
- */
162
- function getAuthorizationHeader(headers = {}, token = null) {
163
- token = token !== null && token !== void 0 ? token : getToken();
164
- headers = headers || {};
165
- if (token)
166
- headers["Authorization"] = `Bearer ${token}`;
167
- return Object.assign({}, headers);
168
- }
169
- /** Throw + redirect if there’s no valid token; otherwise return it. */
170
- function requireToken() {
171
- const tok = getToken();
172
- if (!tok || isTokenExpired(tok)) {
173
- console.warn("→ No token or expired token, redirecting to login…");
174
- localStorage.removeItem("token");
175
- window.location.href = '/';
176
- throw new Error("Redirecting to login…");
177
- }
178
- return tok;
179
- }
180
16
  /** True if token is structurally bad or its exp ≤ now. */
181
17
  function isTokenExpired(token) {
182
18
  try {
@@ -187,47 +23,6 @@ function isTokenExpired(token) {
187
23
  return true; // treat malformed token as expired
188
24
  }
189
25
  }
190
- /** Convenience wrapper: return username from the JWT (or null). */
191
- function currentUsername() {
192
- const tok = getToken();
193
- if (!tok)
194
- return null;
195
- try {
196
- const { username } = decodeJwt(tok);
197
- return username !== null && username !== void 0 ? username : null;
198
- }
199
- catch (_a) {
200
- return null;
201
- }
202
- }
203
- function currentUsernames() {
204
- var _a;
205
- const tok = getToken();
206
- if (!tok)
207
- return null;
208
- try {
209
- const parts = tok.split(".");
210
- if (parts.length !== 3)
211
- return null;
212
- let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
213
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
214
- const jsonText = atob(b64);
215
- const payload = JSON.parse(jsonText);
216
- return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
217
- }
218
- catch (_b) {
219
- return null;
220
- }
221
- }
222
- /** Remove the JWT from LocalStorage */
223
- function removeToken() {
224
- try {
225
- callStorage('removeItem', 'token');
226
- }
227
- catch (err) {
228
- console.warn("Failed to remove token:", err);
229
- }
230
- }
231
26
  /* ------------------------------------------------------------------ */
232
27
  /* internals */
233
28
  /* ------------------------------------------------------------------ */
@@ -316,18 +111,6 @@ PERFORMANCE OF THIS SOFTWARE.
316
111
  /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
317
112
 
318
113
 
319
- function __rest(s, e) {
320
- var t = {};
321
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
322
- t[p] = s[p];
323
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
324
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
325
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
326
- t[p[i]] = s[p[i]];
327
- }
328
- return t;
329
- }
330
-
331
114
  function __awaiter(thisArg, _arguments, P, generator) {
332
115
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
333
116
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -343,100 +126,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
343
126
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
344
127
  };
345
128
 
346
- // src/functions/read_utils/src/read_utils.ts
347
- let fs = null;
348
- let path$2 = null;
349
- function getFsModules() {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- var _a;
352
- if (!fs && !path$2 && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
353
- try {
354
- // prevent bundlers from resolving these at build time
355
- fs = (new Function("return require('fs')"))();
356
- path$2 = (new Function("return require('path')"))();
357
- }
358
- catch (_b) {
359
- fs = null;
360
- path$2 = null;
361
- }
362
- }
363
- return { fs, path: path$2 };
364
- });
365
- }
366
- /**
367
- * Reads a JSON file, either via Node’s fs (if available)
368
- * or via window.fetch in the browser. Never throws — returns
369
- * the parsed object or null on any error.
370
- */
371
- function readJsonFile(relativeOrAbsolutePath) {
372
- return __awaiter(this, void 0, void 0, function* () {
373
- var _a;
374
- // 1) Try Node.js fs (only at runtime, not bundled)
375
- if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
376
- try {
377
- const { fs, path } = yield getFsModules();
378
- if (fs && path) {
379
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
380
- ? relativeOrAbsolutePath
381
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
382
- const text = fs.readFileSync(filePath, "utf8");
383
- return JSON.parse(text);
384
- }
385
- }
386
- catch (_b) {
387
- // swallow and fall back
388
- }
389
- }
390
- // 2) Try browser fetch
391
- const fetchFn = safeGlobalProp("fetch");
392
- if (typeof fetchFn !== "function") {
393
- return null;
394
- }
395
- let url = relativeOrAbsolutePath;
396
- const baseURI = safeGlobalProp("document", "baseURI");
397
- if (baseURI) {
398
- try {
399
- url = new URL(relativeOrAbsolutePath, baseURI).href;
400
- }
401
- catch (_c) {
402
- /* keep url as-is */
403
- }
404
- }
405
- try {
406
- const res = yield fetchFn(url);
407
- if (!res.ok)
408
- return null;
409
- return (yield res.json());
410
- }
411
- catch (_d) {
412
- return null;
413
- }
414
- });
415
- }
416
- function getConfigContent() {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- try {
419
- // `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
420
- const cfg = yield readJsonFile('./config.json');
421
- return cfg;
422
- }
423
- catch (_a) {
424
- // swallow errors & return null so callers can detect “no config”
425
- return null;
426
- }
427
- });
428
- }
429
- // 2) Pull a single key out of that object
430
- function getConfigVar() {
431
- return __awaiter(this, arguments, void 0, function* (key = null) {
432
- const cfg = yield getConfigContent();
433
- if (cfg && typeof cfg === 'object' && key in cfg) {
434
- return cfg[key];
435
- }
436
- return undefined;
437
- });
438
- }
439
-
440
129
  /**
441
130
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
442
131
  */
@@ -461,18 +150,13 @@ function getMethod(method = null, body = null) {
461
150
  // Gets headers, skips JSON headers when body is FormData
462
151
  function getHeaders(headers = {}, method = null, body = null) {
463
152
  const result = Object.assign({}, headers);
464
- // inject auth if missing
465
- if (!result.Authorization) {
466
- const token = getToken();
467
- Object.assign(result, getAuthorizationHeader(result, token));
468
- }
469
- method = getMethod(method, body);
470
- // if it’s a multipart FormData, let the browser set the boundary header
153
+ // let browser set boundary
471
154
  if (body instanceof FormData) {
472
155
  return result;
473
156
  }
474
- // otherwise for POST/PUT/PATCH default to JSON
475
- if (['POST', 'PUT', 'PATCH'].includes(method) && !result['Content-Type']) {
157
+ const upper = method === null || method === void 0 ? void 0 : method.toUpperCase();
158
+ if (['POST', 'PUT', 'PATCH'].includes(upper !== null && upper !== void 0 ? upper : '') &&
159
+ !result['Content-Type']) {
476
160
  result['Content-Type'] = 'application/json';
477
161
  }
478
162
  return result;
@@ -542,7 +226,7 @@ function fetchIt(endpoint_1) {
542
226
  // 2) choose the URL
543
227
  let url = endpoint;
544
228
  // 3) prepare headers & body
545
- headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
229
+ headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
546
230
  const opts = {
547
231
  method,
548
232
  credentials: withCredentials ? "include" : "same-origin",
@@ -1101,11 +785,11 @@ posix.posix = posix;
1101
785
 
1102
786
  var pathBrowserify = posix;
1103
787
 
1104
- var path = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
788
+ var path$1 = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserify);
1105
789
 
1106
- var path$1 = /*#__PURE__*/_mergeNamespaces({
790
+ var path$2 = /*#__PURE__*/_mergeNamespaces({
1107
791
  __proto__: null,
1108
- default: path
792
+ default: path$1
1109
793
  }, [pathBrowserify]);
1110
794
 
1111
795
  function urlJoin(...parts) {
@@ -1150,7 +834,7 @@ function get_full_path(partial_path, parent_dir = null) {
1150
834
  if (typeof partial_path !== 'string') {
1151
835
  throw new Error('partial_path must be a string');
1152
836
  }
1153
- if (path.isAbsolute(partial_path)) {
837
+ if (path$1.isAbsolute(partial_path)) {
1154
838
  return partial_path;
1155
839
  }
1156
840
  return urlJoin(parent_dir, partial_path);
@@ -1165,7 +849,7 @@ function path_to_url(filePath, all_paths) {
1165
849
  }
1166
850
  for (const key in all_paths) {
1167
851
  const mapping = all_paths[key];
1168
- const normalizedBase = path.normalize(mapping.path);
852
+ const normalizedBase = path$1.normalize(mapping.path);
1169
853
  if (filePath.startsWith(normalizedBase)) {
1170
854
  const relativePath = filePath.substring(normalizedBase.length);
1171
855
  return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
@@ -1672,7 +1356,7 @@ function getMimeType(pathOrExt) {
1672
1356
  }
1673
1357
  function getAllFileTypesSync(directory, categories, opts) {
1674
1358
  // 🧩 Skip entirely if fs isn't available
1675
- if (!fsp || !path$1)
1359
+ if (!fsp || !path$2)
1676
1360
  return [];
1677
1361
  try {
1678
1362
  const stat = statSync(directory);
@@ -1705,7 +1389,7 @@ function getAllFileTypesSync(directory, categories, opts) {
1705
1389
  function getAllFileTypes(directory, categories, opts) {
1706
1390
  return __awaiter(this, void 0, void 0, function* () {
1707
1391
  // 🧩 Skip entirely if fsp isn't available
1708
- if (!fsp || !path$1)
1392
+ if (!fsp || !path$2)
1709
1393
  return [];
1710
1394
  try {
1711
1395
  const stat$1 = yield stat(directory);
@@ -2392,39 +2076,221 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
2392
2076
  const isFiniteNum = (x) => Number.isFinite(x);
2393
2077
  const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2394
2078
 
2395
- function Button(_a) {
2396
- var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
2397
- const base = 'rounded px-3 py-1 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors duration-150';
2398
- const variantStyles = {
2399
- default: '',
2400
- icon: 'p-1 bg-transparent hover:bg-gray-100',
2401
- primary: 'text-white',
2402
- secondary: '',
2403
- };
2404
- const palette = {
2405
- gray: variant === 'primary'
2406
- ? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
2407
- : 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
2408
- green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
2409
- blue: variant === 'primary'
2410
- ? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
2411
- : 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
2412
- };
2413
- return (jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
2079
+ function getSafeDocument() {
2080
+ return typeof document !== 'undefined' ? document : undefined;
2081
+ }
2082
+ function getDocumentProp(...keys) {
2083
+ let obj = getSafeDocument();
2084
+ for (const k of keys) {
2085
+ if (obj == null || typeof obj !== 'object')
2086
+ return undefined;
2087
+ obj = obj[k];
2088
+ }
2089
+ return obj;
2414
2090
  }
2415
2091
 
2416
- function Checkbox(_a) {
2417
- var { label } = _a, rest = __rest(_a, ["label"]);
2418
- return (jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [jsx("input", Object.assign({ type: 'checkbox' }, rest)), jsx("span", { children: label })] }));
2092
+ /**
2093
+ * Safely walk `globalThis` (or window/document) by a chain of property names.
2094
+ * Returns `undefined` if any step is missing.
2095
+ */
2096
+ function safeGlobalProp(...path) {
2097
+ let obj = globalThis;
2098
+ for (const key of path) {
2099
+ if (obj == null || typeof obj !== "object" || !(key in obj)) {
2100
+ return undefined;
2101
+ }
2102
+ obj = obj[key];
2103
+ }
2104
+ return obj;
2419
2105
  }
2420
2106
 
2421
- function Input(_a) {
2422
- var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
2423
- return (jsxs("label", { className: 'mb-4 block', children: [jsx("span", { className: 'block text-sm font-medium mb-1', children: label }), jsxs("div", { className: 'flex gap-2', children: [jsx("input", Object.assign({ className: 'flex-1 rounded border px-2 py-1 disabled:bg-gray-100' }, rest)), trailing] })] }));
2107
+ /**
2108
+ * Returns `window` if running in a browser, otherwise `undefined`.
2109
+ */
2110
+ function getSafeLocalStorage() {
2111
+ if (typeof window === 'undefined')
2112
+ return undefined;
2113
+ try {
2114
+ return window.localStorage;
2115
+ }
2116
+ catch (_a) {
2117
+ return undefined; // e.g. Safari private-mode block
2118
+ }
2119
+ }
2120
+ /**
2121
+ * Call a Storage method by name, silencing any errors or missing storage.
2122
+ *
2123
+ * @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
2124
+ * @param args The arguments you’d normally pass to that method.
2125
+ * @returns The method’s return value, or undefined if storage/method isn’t available.
2126
+ */
2127
+ function callStorage(method, ...args) {
2128
+ const storage = getSafeLocalStorage();
2129
+ if (!storage)
2130
+ return undefined;
2131
+ const fn = storage[method];
2132
+ if (typeof fn !== 'function')
2133
+ return undefined;
2134
+ try {
2135
+ // @ts-ignore – TS can’t infer that this is callable
2136
+ return fn.apply(storage, args);
2137
+ }
2138
+ catch (_a) {
2139
+ return undefined;
2140
+ }
2141
+ }
2142
+ /**
2143
+ * Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
2144
+ * Returns `undefined` on any error.
2145
+ */
2146
+ function safeStorage(storageName, method, ...args) {
2147
+ try {
2148
+ const store = safeGlobalProp(storageName);
2149
+ if (!store || typeof store[method] !== "function")
2150
+ return undefined;
2151
+ // @ts-ignore
2152
+ return store[method](...args);
2153
+ }
2154
+ catch (_a) {
2155
+ return undefined;
2156
+ }
2157
+ }
2158
+
2159
+ /**
2160
+ * Returns the global window object if it exists, otherwise undefined.
2161
+ */
2162
+ function getSafeWindow() {
2163
+ return typeof window !== 'undefined' ? window : undefined;
2164
+ }
2165
+ /**
2166
+ * Safely call a method on window by name.
2167
+ *
2168
+ * @param method The Window method to call (e.g. "alert", "open", etc.).
2169
+ * @param args Arguments to pass to that method.
2170
+ * @returns The method’s return value, or undefined if
2171
+ * window/method isn’t available or throws.
2172
+ */
2173
+ function callWindowMethod(method, ...args) {
2174
+ const w = getSafeWindow();
2175
+ if (!w)
2176
+ return undefined;
2177
+ const fn = w[method];
2178
+ if (typeof fn !== 'function')
2179
+ return undefined;
2180
+ try {
2181
+ // cast to any so TS doesn’t complain about apply/invoke
2182
+ return fn(...args);
2183
+ }
2184
+ catch (_a) {
2185
+ return undefined;
2186
+ }
2187
+ }
2188
+ /** implementation */
2189
+ function getWindowProp(...keys) {
2190
+ let obj = getSafeWindow();
2191
+ for (const k of keys) {
2192
+ if (obj == null || typeof obj !== 'object')
2193
+ return undefined;
2194
+ obj = obj[k];
2195
+ }
2196
+ return obj;
2197
+ }
2198
+ function getWindowHost() {
2199
+ return getWindowProp('location', 'host');
2424
2200
  }
2425
2201
 
2426
- function Spinner() {
2427
- return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
2202
+ // src/functions/read_utils/src/read_utils.ts
2203
+ let fs = null;
2204
+ let path = null;
2205
+ function getFsModules() {
2206
+ return __awaiter(this, void 0, void 0, function* () {
2207
+ var _a;
2208
+ if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
2209
+ try {
2210
+ // prevent bundlers from resolving these at build time
2211
+ fs = (new Function("return require('fs')"))();
2212
+ path = (new Function("return require('path')"))();
2213
+ }
2214
+ catch (_b) {
2215
+ fs = null;
2216
+ path = null;
2217
+ }
2218
+ }
2219
+ return { fs, path };
2220
+ });
2221
+ }
2222
+ /**
2223
+ * Reads a JSON file, either via Node’s fs (if available)
2224
+ * or via window.fetch in the browser. Never throws — returns
2225
+ * the parsed object or null on any error.
2226
+ */
2227
+ function readJsonFile(relativeOrAbsolutePath) {
2228
+ return __awaiter(this, void 0, void 0, function* () {
2229
+ var _a;
2230
+ // 1) Try Node.js fs (only at runtime, not bundled)
2231
+ if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
2232
+ try {
2233
+ const { fs, path } = yield getFsModules();
2234
+ if (fs && path) {
2235
+ const filePath = path.isAbsolute(relativeOrAbsolutePath)
2236
+ ? relativeOrAbsolutePath
2237
+ : path.resolve(process.cwd(), relativeOrAbsolutePath);
2238
+ const text = fs.readFileSync(filePath, "utf8");
2239
+ return JSON.parse(text);
2240
+ }
2241
+ }
2242
+ catch (_b) {
2243
+ // swallow and fall back
2244
+ }
2245
+ }
2246
+ // 2) Try browser fetch
2247
+ const fetchFn = safeGlobalProp("fetch");
2248
+ if (typeof fetchFn !== "function") {
2249
+ return null;
2250
+ }
2251
+ let url = relativeOrAbsolutePath;
2252
+ const baseURI = safeGlobalProp("document", "baseURI");
2253
+ if (baseURI) {
2254
+ try {
2255
+ url = new URL(relativeOrAbsolutePath, baseURI).href;
2256
+ }
2257
+ catch (_c) {
2258
+ /* keep url as-is */
2259
+ }
2260
+ }
2261
+ try {
2262
+ const res = yield fetchFn(url);
2263
+ if (!res.ok)
2264
+ return null;
2265
+ return (yield res.json());
2266
+ }
2267
+ catch (_d) {
2268
+ return null;
2269
+ }
2270
+ });
2271
+ }
2272
+ function getConfigContent() {
2273
+ return __awaiter(this, void 0, void 0, function* () {
2274
+ try {
2275
+ // `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
2276
+ const cfg = yield readJsonFile('./config.json');
2277
+ return cfg;
2278
+ }
2279
+ catch (_a) {
2280
+ // swallow errors & return null so callers can detect “no config”
2281
+ return null;
2282
+ }
2283
+ });
2284
+ }
2285
+ // 2) Pull a single key out of that object
2286
+ function getConfigVar() {
2287
+ return __awaiter(this, arguments, void 0, function* (key = null) {
2288
+ const cfg = yield getConfigContent();
2289
+ if (cfg && typeof cfg === 'object' && key in cfg) {
2290
+ return cfg[key];
2291
+ }
2292
+ return undefined;
2293
+ });
2428
2294
  }
2429
2295
 
2430
2296
  // src/functions/config_utils/src/config_utils.ts
@@ -2535,5 +2401,5 @@ function get_keyword_string(keywords) {
2535
2401
  return allString;
2536
2402
  }
2537
2403
 
2538
- export { API_PREFIX, ATTOSECOND, BASE_URL, Button, CENTISECOND, Checkbox, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, Input, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, Spinner, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, assurearray, assurelist, assurenumber, assurestring, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, currentUsername, currentUsernames, decodeJwt, distanceToMeters, eatAll, eatElse, eatInner, eatOuter, eatall, eatinner, eatouter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, ensurearray, ensurelist, ensurenumber, ensurestring, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBasename, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDirname, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getExtname, getFetchVars, getFilename, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSplitext, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, getbasename, getdirname, getextname, getfilename, getsplitext, isFiniteNum, isLoggedIn, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, makePath, make_path, make_sanitized_path, makepath, metersToDistance, mpsToSpeed, normalizeUrl, parseResult, pathJoin, path_join, path_to_url, pathjoin, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, secondsToTime, speedToMps, stripPrefixes, timeToSeconds, toMeters, toSeconds, truncateString, tryEatPrefix, tryParse, urlJoin, url_to_path, urljoin, velocityFromMs, velocityToMs };
2404
+ export { API_PREFIX, ATTOSECOND, BASE_URL, CENTISECOND, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, assurearray, assurelist, assurenumber, assurestring, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, decodeJwt, distanceToMeters, eatAll, eatElse, eatInner, eatOuter, eatall, eatinner, eatouter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, ensurearray, ensurelist, ensurenumber, ensurestring, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getBaseDir, getBasename, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDirname, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getExtname, getFetchVars, getFilename, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSplitext, getSrcDir, getSubstring, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, getbasename, getdirname, getextname, getfilename, getsplitext, isFiniteNum, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, makePath, make_path, make_sanitized_path, makepath, metersToDistance, mpsToSpeed, normalizeUrl, parseResult, pathJoin, path_join, path_to_url, pathjoin, processKeywords, readJsonFile, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, secondsToTime, speedToMps, stripPrefixes, timeToSeconds, toMeters, toSeconds, truncateString, tryEatPrefix, tryParse, urlJoin, url_to_path, urljoin, velocityFromMs, velocityToMs };
2539
2405
  //# sourceMappingURL=index.js.map