@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/cjs/index.js CHANGED
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
3
  var path$1 = require('path');
5
4
  var fs$1 = require('node:fs');
6
5
  var fsp = require('node:fs/promises');
7
6
  var path$2 = require('node:path');
8
- var jsxRuntime = require('react/jsx-runtime');
9
7
 
10
8
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
9
  function _interopNamespaceDefault(e) {
@@ -29,167 +27,6 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
29
27
  var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
30
28
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$2);
31
29
 
32
- function getSafeDocument() {
33
- return typeof document !== 'undefined' ? document : undefined;
34
- }
35
- function getDocumentProp(...keys) {
36
- let obj = getSafeDocument();
37
- for (const k of keys) {
38
- if (obj == null || typeof obj !== 'object')
39
- return undefined;
40
- obj = obj[k];
41
- }
42
- return obj;
43
- }
44
-
45
- /**
46
- * Safely walk `globalThis` (or window/document) by a chain of property names.
47
- * Returns `undefined` if any step is missing.
48
- */
49
- function safeGlobalProp(...path) {
50
- let obj = globalThis;
51
- for (const key of path) {
52
- if (obj == null || typeof obj !== "object" || !(key in obj)) {
53
- return undefined;
54
- }
55
- obj = obj[key];
56
- }
57
- return obj;
58
- }
59
-
60
- /**
61
- * Returns `window` if running in a browser, otherwise `undefined`.
62
- */
63
- function getSafeLocalStorage() {
64
- if (typeof window === 'undefined')
65
- return undefined;
66
- try {
67
- return window.localStorage;
68
- }
69
- catch (_a) {
70
- return undefined; // e.g. Safari private-mode block
71
- }
72
- }
73
- /**
74
- * Call a Storage method by name, silencing any errors or missing storage.
75
- *
76
- * @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
77
- * @param args The arguments you’d normally pass to that method.
78
- * @returns The method’s return value, or undefined if storage/method isn’t available.
79
- */
80
- function callStorage(method, ...args) {
81
- const storage = getSafeLocalStorage();
82
- if (!storage)
83
- return undefined;
84
- const fn = storage[method];
85
- if (typeof fn !== 'function')
86
- return undefined;
87
- try {
88
- // @ts-ignore – TS can’t infer that this is callable
89
- return fn.apply(storage, args);
90
- }
91
- catch (_a) {
92
- return undefined;
93
- }
94
- }
95
- /**
96
- * Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
97
- * Returns `undefined` on any error.
98
- */
99
- function safeStorage(storageName, method, ...args) {
100
- try {
101
- const store = safeGlobalProp(storageName);
102
- if (!store || typeof store[method] !== "function")
103
- return undefined;
104
- // @ts-ignore
105
- return store[method](...args);
106
- }
107
- catch (_a) {
108
- return undefined;
109
- }
110
- }
111
-
112
- /**
113
- * Returns the global window object if it exists, otherwise undefined.
114
- */
115
- function getSafeWindow() {
116
- return typeof window !== 'undefined' ? window : undefined;
117
- }
118
- /**
119
- * Safely call a method on window by name.
120
- *
121
- * @param method The Window method to call (e.g. "alert", "open", etc.).
122
- * @param args Arguments to pass to that method.
123
- * @returns The method’s return value, or undefined if
124
- * window/method isn’t available or throws.
125
- */
126
- function callWindowMethod(method, ...args) {
127
- const w = getSafeWindow();
128
- if (!w)
129
- return undefined;
130
- const fn = w[method];
131
- if (typeof fn !== 'function')
132
- return undefined;
133
- try {
134
- // cast to any so TS doesn’t complain about apply/invoke
135
- return fn(...args);
136
- }
137
- catch (_a) {
138
- return undefined;
139
- }
140
- }
141
- /** implementation */
142
- function getWindowProp(...keys) {
143
- let obj = getSafeWindow();
144
- for (const k of keys) {
145
- if (obj == null || typeof obj !== 'object')
146
- return undefined;
147
- obj = obj[k];
148
- }
149
- return obj;
150
- }
151
- function getWindowHost() {
152
- return getWindowProp('location', 'host');
153
- }
154
-
155
- /**
156
- ***Changes**:
157
- *- Updated import path for `InputProps` to `../../types/interfaces`.
158
- *
159
- *3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
160
- * Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
161
- *
162
- */
163
- /** Read raw JWT from LocalStorage (or null if absent) */
164
- function getToken() {
165
- return callStorage('getItem', 'token');
166
- }
167
- function isLoggedIn() {
168
- const tok = getToken();
169
- return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
170
- }
171
- /**
172
- * Add a Bearer Authorization header.
173
- * A shallow copy of headers is returned so callers can keep chaining.
174
- */
175
- function getAuthorizationHeader(headers = {}, token = null) {
176
- token = token !== null && token !== void 0 ? token : getToken();
177
- headers = headers || {};
178
- if (token)
179
- headers["Authorization"] = `Bearer ${token}`;
180
- return Object.assign({}, headers);
181
- }
182
- /** Throw + redirect if there’s no valid token; otherwise return it. */
183
- function requireToken() {
184
- const tok = getToken();
185
- if (!tok || isTokenExpired(tok)) {
186
- console.warn("→ No token or expired token, redirecting to login…");
187
- localStorage.removeItem("token");
188
- window.location.href = '/';
189
- throw new Error("Redirecting to login…");
190
- }
191
- return tok;
192
- }
193
30
  /** True if token is structurally bad or its exp ≤ now. */
194
31
  function isTokenExpired(token) {
195
32
  try {
@@ -200,47 +37,6 @@ function isTokenExpired(token) {
200
37
  return true; // treat malformed token as expired
201
38
  }
202
39
  }
203
- /** Convenience wrapper: return username from the JWT (or null). */
204
- function currentUsername() {
205
- const tok = getToken();
206
- if (!tok)
207
- return null;
208
- try {
209
- const { username } = decodeJwt(tok);
210
- return username !== null && username !== void 0 ? username : null;
211
- }
212
- catch (_a) {
213
- return null;
214
- }
215
- }
216
- function currentUsernames() {
217
- var _a;
218
- const tok = getToken();
219
- if (!tok)
220
- return null;
221
- try {
222
- const parts = tok.split(".");
223
- if (parts.length !== 3)
224
- return null;
225
- let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
226
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
227
- const jsonText = atob(b64);
228
- const payload = JSON.parse(jsonText);
229
- return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
230
- }
231
- catch (_b) {
232
- return null;
233
- }
234
- }
235
- /** Remove the JWT from LocalStorage */
236
- function removeToken() {
237
- try {
238
- callStorage('removeItem', 'token');
239
- }
240
- catch (err) {
241
- console.warn("Failed to remove token:", err);
242
- }
243
- }
244
40
  /* ------------------------------------------------------------------ */
245
41
  /* internals */
246
42
  /* ------------------------------------------------------------------ */
@@ -329,18 +125,6 @@ PERFORMANCE OF THIS SOFTWARE.
329
125
  /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
330
126
 
331
127
 
332
- function __rest(s, e) {
333
- var t = {};
334
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
335
- t[p] = s[p];
336
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
337
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
338
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
339
- t[p[i]] = s[p[i]];
340
- }
341
- return t;
342
- }
343
-
344
128
  function __awaiter(thisArg, _arguments, P, generator) {
345
129
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
346
130
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -356,100 +140,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
356
140
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
357
141
  };
358
142
 
359
- // src/functions/read_utils/src/read_utils.ts
360
- let fs = null;
361
- let path = null;
362
- function getFsModules() {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- var _a;
365
- if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
366
- try {
367
- // prevent bundlers from resolving these at build time
368
- fs = (new Function("return require('fs')"))();
369
- path = (new Function("return require('path')"))();
370
- }
371
- catch (_b) {
372
- fs = null;
373
- path = null;
374
- }
375
- }
376
- return { fs, path };
377
- });
378
- }
379
- /**
380
- * Reads a JSON file, either via Node’s fs (if available)
381
- * or via window.fetch in the browser. Never throws — returns
382
- * the parsed object or null on any error.
383
- */
384
- function readJsonFile(relativeOrAbsolutePath) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- var _a;
387
- // 1) Try Node.js fs (only at runtime, not bundled)
388
- if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
389
- try {
390
- const { fs, path } = yield getFsModules();
391
- if (fs && path) {
392
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
393
- ? relativeOrAbsolutePath
394
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
395
- const text = fs.readFileSync(filePath, "utf8");
396
- return JSON.parse(text);
397
- }
398
- }
399
- catch (_b) {
400
- // swallow and fall back
401
- }
402
- }
403
- // 2) Try browser fetch
404
- const fetchFn = safeGlobalProp("fetch");
405
- if (typeof fetchFn !== "function") {
406
- return null;
407
- }
408
- let url = relativeOrAbsolutePath;
409
- const baseURI = safeGlobalProp("document", "baseURI");
410
- if (baseURI) {
411
- try {
412
- url = new URL(relativeOrAbsolutePath, baseURI).href;
413
- }
414
- catch (_c) {
415
- /* keep url as-is */
416
- }
417
- }
418
- try {
419
- const res = yield fetchFn(url);
420
- if (!res.ok)
421
- return null;
422
- return (yield res.json());
423
- }
424
- catch (_d) {
425
- return null;
426
- }
427
- });
428
- }
429
- function getConfigContent() {
430
- return __awaiter(this, void 0, void 0, function* () {
431
- try {
432
- // `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
433
- const cfg = yield readJsonFile('./config.json');
434
- return cfg;
435
- }
436
- catch (_a) {
437
- // swallow errors & return null so callers can detect “no config”
438
- return null;
439
- }
440
- });
441
- }
442
- // 2) Pull a single key out of that object
443
- function getConfigVar() {
444
- return __awaiter(this, arguments, void 0, function* (key = null) {
445
- const cfg = yield getConfigContent();
446
- if (cfg && typeof cfg === 'object' && key in cfg) {
447
- return cfg[key];
448
- }
449
- return undefined;
450
- });
451
- }
452
-
453
143
  /**
454
144
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
455
145
  */
@@ -474,18 +164,13 @@ function getMethod(method = null, body = null) {
474
164
  // Gets headers, skips JSON headers when body is FormData
475
165
  function getHeaders(headers = {}, method = null, body = null) {
476
166
  const result = Object.assign({}, headers);
477
- // inject auth if missing
478
- if (!result.Authorization) {
479
- const token = getToken();
480
- Object.assign(result, getAuthorizationHeader(result, token));
481
- }
482
- method = getMethod(method, body);
483
- // if it’s a multipart FormData, let the browser set the boundary header
167
+ // let browser set boundary
484
168
  if (body instanceof FormData) {
485
169
  return result;
486
170
  }
487
- // otherwise for POST/PUT/PATCH default to JSON
488
- if (['POST', 'PUT', 'PATCH'].includes(method) && !result['Content-Type']) {
171
+ const upper = method === null || method === void 0 ? void 0 : method.toUpperCase();
172
+ if (['POST', 'PUT', 'PATCH'].includes(upper !== null && upper !== void 0 ? upper : '') &&
173
+ !result['Content-Type']) {
489
174
  result['Content-Type'] = 'application/json';
490
175
  }
491
176
  return result;
@@ -555,7 +240,7 @@ function fetchIt(endpoint_1) {
555
240
  // 2) choose the URL
556
241
  let url = endpoint;
557
242
  // 3) prepare headers & body
558
- headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
243
+ headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
559
244
  const opts = {
560
245
  method,
561
246
  credentials: withCredentials ? "include" : "same-origin",
@@ -2364,39 +2049,221 @@ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit)
2364
2049
  const isFiniteNum = (x) => Number.isFinite(x);
2365
2050
  const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2366
2051
 
2367
- function Button(_a) {
2368
- var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
2369
- 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';
2370
- const variantStyles = {
2371
- default: '',
2372
- icon: 'p-1 bg-transparent hover:bg-gray-100',
2373
- primary: 'text-white',
2374
- secondary: '',
2375
- };
2376
- const palette = {
2377
- gray: variant === 'primary'
2378
- ? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
2379
- : 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
2380
- green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
2381
- blue: variant === 'primary'
2382
- ? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
2383
- : 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
2384
- };
2385
- return (jsxRuntime.jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
2052
+ function getSafeDocument() {
2053
+ return typeof document !== 'undefined' ? document : undefined;
2054
+ }
2055
+ function getDocumentProp(...keys) {
2056
+ let obj = getSafeDocument();
2057
+ for (const k of keys) {
2058
+ if (obj == null || typeof obj !== 'object')
2059
+ return undefined;
2060
+ obj = obj[k];
2061
+ }
2062
+ return obj;
2386
2063
  }
2387
2064
 
2388
- function Checkbox(_a) {
2389
- var { label } = _a, rest = __rest(_a, ["label"]);
2390
- return (jsxRuntime.jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [jsxRuntime.jsx("input", Object.assign({ type: 'checkbox' }, rest)), jsxRuntime.jsx("span", { children: label })] }));
2065
+ /**
2066
+ * Safely walk `globalThis` (or window/document) by a chain of property names.
2067
+ * Returns `undefined` if any step is missing.
2068
+ */
2069
+ function safeGlobalProp(...path) {
2070
+ let obj = globalThis;
2071
+ for (const key of path) {
2072
+ if (obj == null || typeof obj !== "object" || !(key in obj)) {
2073
+ return undefined;
2074
+ }
2075
+ obj = obj[key];
2076
+ }
2077
+ return obj;
2078
+ }
2079
+
2080
+ /**
2081
+ * Returns `window` if running in a browser, otherwise `undefined`.
2082
+ */
2083
+ function getSafeLocalStorage() {
2084
+ if (typeof window === 'undefined')
2085
+ return undefined;
2086
+ try {
2087
+ return window.localStorage;
2088
+ }
2089
+ catch (_a) {
2090
+ return undefined; // e.g. Safari private-mode block
2091
+ }
2092
+ }
2093
+ /**
2094
+ * Call a Storage method by name, silencing any errors or missing storage.
2095
+ *
2096
+ * @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
2097
+ * @param args The arguments you’d normally pass to that method.
2098
+ * @returns The method’s return value, or undefined if storage/method isn’t available.
2099
+ */
2100
+ function callStorage(method, ...args) {
2101
+ const storage = getSafeLocalStorage();
2102
+ if (!storage)
2103
+ return undefined;
2104
+ const fn = storage[method];
2105
+ if (typeof fn !== 'function')
2106
+ return undefined;
2107
+ try {
2108
+ // @ts-ignore – TS can’t infer that this is callable
2109
+ return fn.apply(storage, args);
2110
+ }
2111
+ catch (_a) {
2112
+ return undefined;
2113
+ }
2114
+ }
2115
+ /**
2116
+ * Safely call storage methods (`localStorage` or `sessionStorage`) without blowing up.
2117
+ * Returns `undefined` on any error.
2118
+ */
2119
+ function safeStorage(storageName, method, ...args) {
2120
+ try {
2121
+ const store = safeGlobalProp(storageName);
2122
+ if (!store || typeof store[method] !== "function")
2123
+ return undefined;
2124
+ // @ts-ignore
2125
+ return store[method](...args);
2126
+ }
2127
+ catch (_a) {
2128
+ return undefined;
2129
+ }
2391
2130
  }
2392
2131
 
2393
- function Input(_a) {
2394
- var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
2395
- return (jsxRuntime.jsxs("label", { className: 'mb-4 block', children: [jsxRuntime.jsx("span", { className: 'block text-sm font-medium mb-1', children: label }), jsxRuntime.jsxs("div", { className: 'flex gap-2', children: [jsxRuntime.jsx("input", Object.assign({ className: 'flex-1 rounded border px-2 py-1 disabled:bg-gray-100' }, rest)), trailing] })] }));
2132
+ /**
2133
+ * Returns the global window object if it exists, otherwise undefined.
2134
+ */
2135
+ function getSafeWindow() {
2136
+ return typeof window !== 'undefined' ? window : undefined;
2137
+ }
2138
+ /**
2139
+ * Safely call a method on window by name.
2140
+ *
2141
+ * @param method The Window method to call (e.g. "alert", "open", etc.).
2142
+ * @param args Arguments to pass to that method.
2143
+ * @returns The method’s return value, or undefined if
2144
+ * window/method isn’t available or throws.
2145
+ */
2146
+ function callWindowMethod(method, ...args) {
2147
+ const w = getSafeWindow();
2148
+ if (!w)
2149
+ return undefined;
2150
+ const fn = w[method];
2151
+ if (typeof fn !== 'function')
2152
+ return undefined;
2153
+ try {
2154
+ // cast to any so TS doesn’t complain about apply/invoke
2155
+ return fn(...args);
2156
+ }
2157
+ catch (_a) {
2158
+ return undefined;
2159
+ }
2160
+ }
2161
+ /** implementation */
2162
+ function getWindowProp(...keys) {
2163
+ let obj = getSafeWindow();
2164
+ for (const k of keys) {
2165
+ if (obj == null || typeof obj !== 'object')
2166
+ return undefined;
2167
+ obj = obj[k];
2168
+ }
2169
+ return obj;
2170
+ }
2171
+ function getWindowHost() {
2172
+ return getWindowProp('location', 'host');
2396
2173
  }
2397
2174
 
2398
- function Spinner() {
2399
- return (jsxRuntime.jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
2175
+ // src/functions/read_utils/src/read_utils.ts
2176
+ let fs = null;
2177
+ let path = null;
2178
+ function getFsModules() {
2179
+ return __awaiter(this, void 0, void 0, function* () {
2180
+ var _a;
2181
+ if (!fs && !path && typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
2182
+ try {
2183
+ // prevent bundlers from resolving these at build time
2184
+ fs = (new Function("return require('fs')"))();
2185
+ path = (new Function("return require('path')"))();
2186
+ }
2187
+ catch (_b) {
2188
+ fs = null;
2189
+ path = null;
2190
+ }
2191
+ }
2192
+ return { fs, path };
2193
+ });
2194
+ }
2195
+ /**
2196
+ * Reads a JSON file, either via Node’s fs (if available)
2197
+ * or via window.fetch in the browser. Never throws — returns
2198
+ * the parsed object or null on any error.
2199
+ */
2200
+ function readJsonFile(relativeOrAbsolutePath) {
2201
+ return __awaiter(this, void 0, void 0, function* () {
2202
+ var _a;
2203
+ // 1) Try Node.js fs (only at runtime, not bundled)
2204
+ if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
2205
+ try {
2206
+ const { fs, path } = yield getFsModules();
2207
+ if (fs && path) {
2208
+ const filePath = path.isAbsolute(relativeOrAbsolutePath)
2209
+ ? relativeOrAbsolutePath
2210
+ : path.resolve(process.cwd(), relativeOrAbsolutePath);
2211
+ const text = fs.readFileSync(filePath, "utf8");
2212
+ return JSON.parse(text);
2213
+ }
2214
+ }
2215
+ catch (_b) {
2216
+ // swallow and fall back
2217
+ }
2218
+ }
2219
+ // 2) Try browser fetch
2220
+ const fetchFn = safeGlobalProp("fetch");
2221
+ if (typeof fetchFn !== "function") {
2222
+ return null;
2223
+ }
2224
+ let url = relativeOrAbsolutePath;
2225
+ const baseURI = safeGlobalProp("document", "baseURI");
2226
+ if (baseURI) {
2227
+ try {
2228
+ url = new URL(relativeOrAbsolutePath, baseURI).href;
2229
+ }
2230
+ catch (_c) {
2231
+ /* keep url as-is */
2232
+ }
2233
+ }
2234
+ try {
2235
+ const res = yield fetchFn(url);
2236
+ if (!res.ok)
2237
+ return null;
2238
+ return (yield res.json());
2239
+ }
2240
+ catch (_d) {
2241
+ return null;
2242
+ }
2243
+ });
2244
+ }
2245
+ function getConfigContent() {
2246
+ return __awaiter(this, void 0, void 0, function* () {
2247
+ try {
2248
+ // `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
2249
+ const cfg = yield readJsonFile('./config.json');
2250
+ return cfg;
2251
+ }
2252
+ catch (_a) {
2253
+ // swallow errors & return null so callers can detect “no config”
2254
+ return null;
2255
+ }
2256
+ });
2257
+ }
2258
+ // 2) Pull a single key out of that object
2259
+ function getConfigVar() {
2260
+ return __awaiter(this, arguments, void 0, function* (key = null) {
2261
+ const cfg = yield getConfigContent();
2262
+ if (cfg && typeof cfg === 'object' && key in cfg) {
2263
+ return cfg[key];
2264
+ }
2265
+ return undefined;
2266
+ });
2400
2267
  }
2401
2268
 
2402
2269
  // src/functions/config_utils/src/config_utils.ts
@@ -2507,28 +2374,10 @@ function get_keyword_string(keywords) {
2507
2374
  return allString;
2508
2375
  }
2509
2376
 
2510
- Object.defineProperty(exports, "useCallback", {
2511
- enumerable: true,
2512
- get: function () { return react.useCallback; }
2513
- });
2514
- Object.defineProperty(exports, "useEffect", {
2515
- enumerable: true,
2516
- get: function () { return react.useEffect; }
2517
- });
2518
- Object.defineProperty(exports, "useRef", {
2519
- enumerable: true,
2520
- get: function () { return react.useRef; }
2521
- });
2522
- Object.defineProperty(exports, "useState", {
2523
- enumerable: true,
2524
- get: function () { return react.useState; }
2525
- });
2526
2377
  exports.API_PREFIX = API_PREFIX;
2527
2378
  exports.ATTOSECOND = ATTOSECOND;
2528
2379
  exports.BASE_URL = BASE_URL;
2529
- exports.Button = Button;
2530
2380
  exports.CENTISECOND = CENTISECOND;
2531
- exports.Checkbox = Checkbox;
2532
2381
  exports.DAY = DAY;
2533
2382
  exports.DAY_IN_S = DAY_IN_S;
2534
2383
  exports.DECISECOND = DECISECOND;
@@ -2541,7 +2390,6 @@ exports.FEET_PER_METER = FEET_PER_METER;
2541
2390
  exports.FEMTOSECOND = FEMTOSECOND;
2542
2391
  exports.HOUR = HOUR;
2543
2392
  exports.HOUR_IN_S = HOUR_IN_S;
2544
- exports.Input = Input;
2545
2393
  exports.KMS_PER_METER = KMS_PER_METER;
2546
2394
  exports.MEDIA_TYPES = MEDIA_TYPES;
2547
2395
  exports.METERS_PER_FOOT = METERS_PER_FOOT;
@@ -2569,7 +2417,6 @@ exports.SECONDS_PER_HOUR = SECONDS_PER_HOUR;
2569
2417
  exports.SECONDS_PER_MINUTE = SECONDS_PER_MINUTE;
2570
2418
  exports.SUB_DIR = SUB_DIR;
2571
2419
  exports.SpeedConverter = SpeedConverter;
2572
- exports.Spinner = Spinner;
2573
2420
  exports.TIME_ALIASES = TIME_ALIASES;
2574
2421
  exports.TIME_FACTORS = TIME_FACTORS;
2575
2422
  exports.TimeConverter = TimeConverter;
@@ -2604,8 +2451,6 @@ exports.convertDistance = convertDistance;
2604
2451
  exports.convertSpeed = convertSpeed;
2605
2452
  exports.convertTime = convertTime;
2606
2453
  exports.create_list_string = create_list_string;
2607
- exports.currentUsername = currentUsername;
2608
- exports.currentUsernames = currentUsernames;
2609
2454
  exports.decodeJwt = decodeJwt;
2610
2455
  exports.distanceToMeters = distanceToMeters;
2611
2456
  exports.eatAll = eatAll;
@@ -2653,7 +2498,6 @@ exports.getAllFileTypes = getAllFileTypes;
2653
2498
  exports.getAllFileTypesSync = getAllFileTypesSync;
2654
2499
  exports.getAlphaNum = getAlphaNum;
2655
2500
  exports.getAlphas = getAlphas;
2656
- exports.getAuthorizationHeader = getAuthorizationHeader;
2657
2501
  exports.getBaseDir = getBaseDir;
2658
2502
  exports.getBasename = getBasename;
2659
2503
  exports.getBody = getBody;
@@ -2693,7 +2537,6 @@ exports.getSchemasPath = getSchemasPath;
2693
2537
  exports.getSplitext = getSplitext;
2694
2538
  exports.getSrcDir = getSrcDir;
2695
2539
  exports.getSubstring = getSubstring;
2696
- exports.getToken = getToken;
2697
2540
  exports.getWindowHost = getWindowHost;
2698
2541
  exports.getWindowProp = getWindowProp;
2699
2542
  exports.get_all_file_types = get_all_file_types;
@@ -2720,7 +2563,6 @@ exports.getextname = getextname;
2720
2563
  exports.getfilename = getfilename;
2721
2564
  exports.getsplitext = getsplitext;
2722
2565
  exports.isFiniteNum = isFiniteNum;
2723
- exports.isLoggedIn = isLoggedIn;
2724
2566
  exports.isMediaType = isMediaType;
2725
2567
  exports.isNum = isNum;
2726
2568
  exports.isStrInString = isStrInString;
@@ -2742,8 +2584,6 @@ exports.path_to_url = path_to_url;
2742
2584
  exports.pathjoin = pathjoin;
2743
2585
  exports.processKeywords = processKeywords;
2744
2586
  exports.readJsonFile = readJsonFile;
2745
- exports.removeToken = removeToken;
2746
- exports.requireToken = requireToken;
2747
2587
  exports.roundPercentage = roundPercentage;
2748
2588
  exports.safeDivide = safeDivide;
2749
2589
  exports.safeGlobalProp = safeGlobalProp;