@putkoff/abstract-utilities 1.0.113 → 1.0.124

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 (207) hide show
  1. package/dist/cjs/client.js +1 -11
  2. package/dist/cjs/client.js.map +1 -1
  3. package/dist/cjs/functions.js +4 -14
  4. package/dist/cjs/functions.js.map +1 -1
  5. package/dist/cjs/index.js +4 -14
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/{print_utils-DzyRoj6m.js → print_utils-DhPs0s0W.js} +6 -16
  8. package/dist/cjs/print_utils-DhPs0s0W.js.map +1 -0
  9. package/dist/cjs/safe_storage-B6MYZDKg.js +941 -0
  10. package/dist/cjs/safe_storage-B6MYZDKg.js.map +1 -0
  11. package/dist/esm/client.js +1 -11
  12. package/dist/esm/client.js.map +1 -1
  13. package/dist/esm/functions.js +2 -12
  14. package/dist/esm/functions.js.map +1 -1
  15. package/dist/esm/index.js +2 -12
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/{print_utils-qqcMhSul.js → print_utils-gTxtZBM7.js} +2 -12
  18. package/dist/esm/print_utils-gTxtZBM7.js.map +1 -0
  19. package/dist/esm/safe_storage-D4QfcTw0.js +897 -0
  20. package/dist/esm/safe_storage-D4QfcTw0.js.map +1 -0
  21. package/dist/types/client/auth/index.d.ts +1 -1
  22. package/dist/types/client/auth/src/index.d.ts +1 -1
  23. package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
  24. package/dist/types/client/fetch/src/index.d.ts +1 -1
  25. package/dist/types/client/index.d.ts +2 -2
  26. package/dist/types/client/ui_utils/index.d.ts +1 -1
  27. package/dist/types/client/ui_utils/src/index.d.ts +4 -4
  28. package/dist/types/functions/auth_utils/imports.d.ts +2 -2
  29. package/dist/types/functions/auth_utils/index.d.ts +1 -1
  30. package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
  31. package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
  32. package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
  33. package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
  34. package/dist/types/functions/config_utils/imports.d.ts +3 -3
  35. package/dist/types/functions/config_utils/index.d.ts +1 -1
  36. package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
  37. package/dist/types/functions/config_utils/src/index.d.ts +1 -1
  38. package/dist/types/functions/constants_utils/index.d.ts +1 -1
  39. package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
  40. package/dist/types/functions/env_utils/imports.d.ts +1 -1
  41. package/dist/types/functions/env_utils/index.d.ts +1 -1
  42. package/dist/types/functions/env_utils/src/index.d.ts +1 -1
  43. package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
  44. package/dist/types/functions/fetch_utils/index.d.ts +1 -1
  45. package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
  46. package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
  47. package/dist/types/functions/inspect_utils/index.d.ts +2 -2
  48. package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
  49. package/dist/types/functions/math_utils/conversions.d.ts +1 -1
  50. package/dist/types/functions/math_utils/index.d.ts +6 -6
  51. package/dist/types/functions/path_utils/imports.d.ts +2 -2
  52. package/dist/types/functions/path_utils/index.d.ts +1 -1
  53. package/dist/types/functions/path_utils/src/index.d.ts +6 -6
  54. package/dist/types/functions/print_utils/imports.d.ts +1 -1
  55. package/dist/types/functions/print_utils/index.d.ts +1 -1
  56. package/dist/types/functions/print_utils/src/index.d.ts +1 -1
  57. package/dist/types/functions/read_utils/imports.d.ts +1 -1
  58. package/dist/types/functions/read_utils/index.d.ts +1 -1
  59. package/dist/types/functions/read_utils/src/index.d.ts +3 -3
  60. package/dist/types/functions/rndm_utils/imports.d.ts +0 -1
  61. package/dist/types/functions/rndm_utils/index.d.ts +1 -1
  62. package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
  63. package/dist/types/functions/safe_utils/imports.d.ts +1 -1
  64. package/dist/types/functions/safe_utils/index.d.ts +1 -1
  65. package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
  66. package/dist/types/functions/size_utils/index.d.ts +1 -1
  67. package/dist/types/functions/size_utils/src/index.d.ts +1 -1
  68. package/dist/types/functions/string_utils/index.d.ts +1 -1
  69. package/dist/types/functions/string_utils/src/index.d.ts +2 -2
  70. package/dist/types/functions/type_utils/imports.d.ts +0 -1
  71. package/dist/types/functions/type_utils/index.d.ts +1 -1
  72. package/dist/types/functions/type_utils/src/imports.d.ts +0 -1
  73. package/dist/types/functions/type_utils/src/index.d.ts +6 -6
  74. package/dist/types/functions/variable_utils/imports.d.ts +1 -1
  75. package/dist/types/functions/variable_utils/index.d.ts +1 -1
  76. package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
  77. package/dist/types/index.d.ts +2 -2
  78. package/dist/types/server/index.d.ts +1 -1
  79. package/dist/types/server/src/index.d.ts +1 -1
  80. package/dist/types/types/index.d.ts +1 -1
  81. package/dist/types/types/path-browserify.d.ts +2 -3
  82. package/dist/types/types/src/index.d.ts +4 -4
  83. package/dist/types/utils/imports.d.ts +1 -1
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/src/index.d.ts +2 -2
  86. package/package.json +2 -2
  87. package/dist/cjs/print_utils-DzyRoj6m.js.map +0 -1
  88. package/dist/cjs/safe_storage-CJgWghnh.js +0 -15986
  89. package/dist/cjs/safe_storage-CJgWghnh.js.map +0 -1
  90. package/dist/esm/print_utils-qqcMhSul.js.map +0 -1
  91. package/dist/esm/safe_storage-CMuv35Vo.js +0 -15941
  92. package/dist/esm/safe_storage-CMuv35Vo.js.map +0 -1
  93. package/dist/types/client/auth/index.js +0 -3
  94. package/dist/types/client/auth/src/index.js +0 -3
  95. package/dist/types/client/auth/src/token_client.js +0 -73
  96. package/dist/types/client/fetch/src/fetch_auth.js +0 -26
  97. package/dist/types/client/fetch/src/index.js +0 -2
  98. package/dist/types/client/index.js +0 -4
  99. package/dist/types/client/ui_utils/index.js +0 -2
  100. package/dist/types/client/ui_utils/src/button.js +0 -34
  101. package/dist/types/client/ui_utils/src/checkbox.js +0 -18
  102. package/dist/types/client/ui_utils/src/index.js +0 -4
  103. package/dist/types/client/ui_utils/src/input.js +0 -18
  104. package/dist/types/client/ui_utils/src/spinner.js +0 -5
  105. package/dist/types/functions/auth_utils/imports.js +0 -1
  106. package/dist/types/functions/auth_utils/index.js +0 -1
  107. package/dist/types/functions/auth_utils/src/index.js +0 -1
  108. package/dist/types/functions/auth_utils/src/jwt_core.js +0 -25
  109. package/dist/types/functions/auth_utils/src/token_utils (Copy).js +0 -25
  110. package/dist/types/functions/auth_utils/src/token_utils.js +0 -105
  111. package/dist/types/functions/config_utils/imports.js +0 -2
  112. package/dist/types/functions/config_utils/index.js +0 -1
  113. package/dist/types/functions/config_utils/src/config_utils.js +0 -83
  114. package/dist/types/functions/config_utils/src/index.js +0 -1
  115. package/dist/types/functions/constants_utils/index.js +0 -1
  116. package/dist/types/functions/constants_utils/src/constants.js +0 -7
  117. package/dist/types/functions/constants_utils/src/index.js +0 -1
  118. package/dist/types/functions/env_utils/imports.js +0 -1
  119. package/dist/types/functions/env_utils/index.js +0 -1
  120. package/dist/types/functions/env_utils/src/index.js +0 -1
  121. package/dist/types/functions/env_utils/src/window_utils.js +0 -47
  122. package/dist/types/functions/fetch_utils/imports.js +0 -1
  123. package/dist/types/functions/fetch_utils/index.js +0 -1
  124. package/dist/types/functions/fetch_utils/src/fetch_utils.js +0 -70
  125. package/dist/types/functions/fetch_utils/src/index.js +0 -3
  126. package/dist/types/functions/fetch_utils/src/url_utils.js +0 -86
  127. package/dist/types/functions/fetch_utils/src/utils.js +0 -102
  128. package/dist/types/functions/index.js +0 -17
  129. package/dist/types/functions/inspect_utils/imports.js +0 -1
  130. package/dist/types/functions/inspect_utils/index.js +0 -2
  131. package/dist/types/functions/inspect_utils/src/caller_utils.js +0 -28
  132. package/dist/types/functions/inspect_utils/src/index.js +0 -1
  133. package/dist/types/functions/math_utils/bigint_utils.js +0 -36
  134. package/dist/types/functions/math_utils/constants.js +0 -37
  135. package/dist/types/functions/math_utils/conversions.js +0 -129
  136. package/dist/types/functions/math_utils/index.js +0 -6
  137. package/dist/types/functions/math_utils/safe_math.js +0 -35
  138. package/dist/types/functions/math_utils/scaleInterfaces.js +0 -3
  139. package/dist/types/functions/math_utils/time_utils.js +0 -4
  140. package/dist/types/functions/path_utils/imports.js +0 -27
  141. package/dist/types/functions/path_utils/index.js +0 -1
  142. package/dist/types/functions/path_utils/src/base_dirs.js +0 -17
  143. package/dist/types/functions/path_utils/src/function_dirs.js +0 -42
  144. package/dist/types/functions/path_utils/src/index.js +0 -6
  145. package/dist/types/functions/path_utils/src/misc_dirs.js +0 -15
  146. package/dist/types/functions/path_utils/src/path_utils.js +0 -160
  147. package/dist/types/functions/path_utils/src/paths.js +0 -12
  148. package/dist/types/functions/path_utils/src/src_dirs.js +0 -25
  149. package/dist/types/functions/print_utils/imports.js +0 -1
  150. package/dist/types/functions/print_utils/index.js +0 -1
  151. package/dist/types/functions/print_utils/src/index.js +0 -1
  152. package/dist/types/functions/print_utils/src/print_utils.js +0 -14
  153. package/dist/types/functions/read_utils/imports.js +0 -1
  154. package/dist/types/functions/read_utils/index.js +0 -1
  155. package/dist/types/functions/read_utils/src/index.js +0 -3
  156. package/dist/types/functions/read_utils/src/readJsonFile.browser.js +0 -26
  157. package/dist/types/functions/read_utils/src/readJsonFile.js +0 -35
  158. package/dist/types/functions/read_utils/src/readJsonFile.node.js +0 -13
  159. package/dist/types/functions/rndm_utils/imports.js +0 -1
  160. package/dist/types/functions/rndm_utils/index.js +0 -1
  161. package/dist/types/functions/rndm_utils/src/index.js +0 -1
  162. package/dist/types/functions/rndm_utils/src/utils.js +0 -12
  163. package/dist/types/functions/safe_utils/imports.js +0 -1
  164. package/dist/types/functions/safe_utils/index.js +0 -1
  165. package/dist/types/functions/safe_utils/src/index.js +0 -4
  166. package/dist/types/functions/safe_utils/src/safe_document.js +0 -12
  167. package/dist/types/functions/safe_utils/src/safe_globals.js +0 -14
  168. package/dist/types/functions/safe_utils/src/safe_storage.js +0 -50
  169. package/dist/types/functions/safe_utils/src/safe_window.js +0 -42
  170. package/dist/types/functions/size_utils/index.js +0 -1
  171. package/dist/types/functions/size_utils/src/index.js +0 -1
  172. package/dist/types/functions/size_utils/src/sizeUtils.js +0 -44
  173. package/dist/types/functions/string_utils/index.js +0 -1
  174. package/dist/types/functions/string_utils/src/index.js +0 -2
  175. package/dist/types/functions/string_utils/src/quote_utils.js +0 -17
  176. package/dist/types/functions/string_utils/src/string_utils.js +0 -186
  177. package/dist/types/functions/type_utils/imports.js +0 -1
  178. package/dist/types/functions/type_utils/index.js +0 -1
  179. package/dist/types/functions/type_utils/src/clean_utils.js +0 -38
  180. package/dist/types/functions/type_utils/src/ensure_utils.js +0 -84
  181. package/dist/types/functions/type_utils/src/imports.js +0 -1
  182. package/dist/types/functions/type_utils/src/index.js +0 -6
  183. package/dist/types/functions/type_utils/src/json_utils.js +0 -93
  184. package/dist/types/functions/type_utils/src/list_utils.js +0 -83
  185. package/dist/types/functions/type_utils/src/mime_utils.js +0 -314
  186. package/dist/types/functions/type_utils/src/null_utils.js +0 -21
  187. package/dist/types/functions/type_utils/src/type_utils.js +0 -39
  188. package/dist/types/functions/variable_utils/imports.js +0 -1
  189. package/dist/types/functions/variable_utils/index.js +0 -1
  190. package/dist/types/functions/variable_utils/src/index.js +0 -1
  191. package/dist/types/functions/variable_utils/src/variable_utils.js +0 -34
  192. package/dist/types/index.js +0 -2
  193. package/dist/types/server/index.js +0 -2
  194. package/dist/types/server/src/index.js +0 -2
  195. package/dist/types/server/src/mime_utils.js +0 -314
  196. package/dist/types/types/index.js +0 -1
  197. package/dist/types/types/path-browserify.js +0 -1
  198. package/dist/types/types/src/Files.js +0 -1
  199. package/dist/types/types/src/index.js +0 -4
  200. package/dist/types/types/src/login.js +0 -1
  201. package/dist/types/types/src/logout.js +0 -1
  202. package/dist/types/types/src/utils.js +0 -1
  203. package/dist/types/utils/imports.js +0 -1
  204. package/dist/types/utils/index.js +0 -1
  205. package/dist/types/utils/src/Input.js +0 -2
  206. package/dist/types/utils/src/config.js +0 -27
  207. package/dist/types/utils/src/index.js +0 -2
@@ -1,3 +0,0 @@
1
- // src/client/ui_utils/imports.ts
2
- 'use client';
3
- export * from './src';
@@ -1,3 +0,0 @@
1
- // src/client/ui_utils/imports.ts
2
- 'use client';
3
- export * from './token_client';
@@ -1,73 +0,0 @@
1
- 'use client';
2
- import { isTokenExpired, decodeJwt, callStorage, } from '../../../functions';
3
- /** Read raw JWT from LocalStorage (or null if absent) */
4
- export function getToken() {
5
- return callStorage('getItem', 'token');
6
- }
7
- export function isLoggedIn() {
8
- const tok = getToken();
9
- return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
10
- }
11
- /**
12
- * Add a Bearer Authorization header.
13
- * A shallow copy of headers is returned so callers can keep chaining.
14
- */
15
- export function getAuthorizationHeader(headers = {}, token = null) {
16
- token = token !== null && token !== void 0 ? token : getToken();
17
- headers = headers || {};
18
- if (token)
19
- headers["Authorization"] = `Bearer ${token}`;
20
- return Object.assign({}, headers);
21
- }
22
- /** Throw + redirect if there’s no valid token; otherwise return it. */
23
- export function requireToken() {
24
- const tok = getToken();
25
- if (!tok || isTokenExpired(tok)) {
26
- console.warn("→ No token or expired token, redirecting to login…");
27
- localStorage.removeItem("token");
28
- window.location.href = '/';
29
- throw new Error("Redirecting to login…");
30
- }
31
- return tok;
32
- }
33
- /** Convenience wrapper: return username from the JWT (or null). */
34
- export function currentUsername() {
35
- const tok = getToken();
36
- if (!tok)
37
- return null;
38
- try {
39
- const { username } = decodeJwt(tok);
40
- return username !== null && username !== void 0 ? username : null;
41
- }
42
- catch (_a) {
43
- return null;
44
- }
45
- }
46
- export function currentUsernames() {
47
- var _a;
48
- const tok = getToken();
49
- if (!tok)
50
- return null;
51
- try {
52
- const parts = tok.split(".");
53
- if (parts.length !== 3)
54
- return null;
55
- let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
56
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
57
- const jsonText = atob(b64);
58
- const payload = JSON.parse(jsonText);
59
- return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
60
- }
61
- catch (_b) {
62
- return null;
63
- }
64
- }
65
- /** Remove the JWT from LocalStorage */
66
- export function removeToken() {
67
- try {
68
- callStorage('removeItem', 'token');
69
- }
70
- catch (err) {
71
- console.warn("Failed to remove token:", err);
72
- }
73
- }
@@ -1,26 +0,0 @@
1
- 'use client';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import { fetchIt as fetchCore, getHeaders as getHeadersCore } from './../../../functions';
12
- import { getAuthorizationHeader } from './../../auth';
13
- export function fetchIt(endpoint_1) {
14
- return __awaiter(this, arguments, void 0, function* (endpoint, options = {}) {
15
- const authHeaders = getAuthorizationHeader();
16
- return fetchCore(endpoint, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, authHeaders), options.headers) }));
17
- });
18
- }
19
- 'use client';
20
- export function getHeaders(headers = {}, method = null, body = null) {
21
- const base = getHeadersCore(headers, method, body);
22
- if (!base.Authorization) {
23
- Object.assign(base, getAuthorizationHeader(base));
24
- }
25
- return base;
26
- }
@@ -1,2 +0,0 @@
1
- 'use client';
2
- export * from './fetch_auth';
@@ -1,4 +0,0 @@
1
- // src/client/index.ts
2
- 'use client';
3
- export * from './auth';
4
- export * from './ui_utils';
@@ -1,2 +0,0 @@
1
- 'use client';
2
- export * from './src';
@@ -1,34 +0,0 @@
1
- // src/client/ui_utils/src/button.tsx
2
- 'use client';
3
- var __rest = (this && this.__rest) || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
- t[p] = s[p];
7
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
- t[p[i]] = s[p[i]];
11
- }
12
- return t;
13
- };
14
- import { jsx as _jsx } from "react/jsx-runtime";
15
- export function Button(_a) {
16
- var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
17
- 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';
18
- const variantStyles = {
19
- default: '',
20
- icon: 'p-1 bg-transparent hover:bg-gray-100',
21
- primary: 'text-white',
22
- secondary: '',
23
- };
24
- const palette = {
25
- gray: variant === 'primary'
26
- ? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
27
- : 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
28
- green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
29
- blue: variant === 'primary'
30
- ? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
31
- : 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
32
- };
33
- return (_jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
34
- }
@@ -1,18 +0,0 @@
1
- // src/client/ui_utils/src/checkbox.tsx
2
- 'use client';
3
- var __rest = (this && this.__rest) || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
- t[p] = s[p];
7
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
- t[p[i]] = s[p[i]];
11
- }
12
- return t;
13
- };
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
- export function Checkbox(_a) {
16
- var { label } = _a, rest = __rest(_a, ["label"]);
17
- return (_jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [_jsx("input", Object.assign({ type: 'checkbox' }, rest)), _jsx("span", { children: label })] }));
18
- }
@@ -1,4 +0,0 @@
1
- export * from './button';
2
- export * from './checkbox';
3
- export * from './input';
4
- export * from './spinner';
@@ -1,18 +0,0 @@
1
- // src/client/ui_utils/src/input.tsx
2
- 'use client';
3
- var __rest = (this && this.__rest) || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
- t[p] = s[p];
7
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
- t[p[i]] = s[p[i]];
11
- }
12
- return t;
13
- };
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
- export function Input(_a) {
16
- var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
17
- 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] })] }));
18
- }
@@ -1,5 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- export function Spinner() {
4
- return (_jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
5
- }
@@ -1 +0,0 @@
1
- export { callStorage } from './../safe_utils';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from "./jwt_core";
@@ -1,25 +0,0 @@
1
- /** True if token is structurally bad or its exp ≤ now. */
2
- export function isTokenExpired(token) {
3
- try {
4
- const payload = decodeJwt(token);
5
- return Date.now() / 1000 >= payload.exp;
6
- }
7
- catch (_a) {
8
- return true; // treat malformed token as expired
9
- }
10
- }
11
- /* ------------------------------------------------------------------ */
12
- /* internals */
13
- /* ------------------------------------------------------------------ */
14
- export function decodeJwt(token) {
15
- const [header, payload, signature] = token.split(".");
16
- if (!header || !payload || !signature) {
17
- throw new Error("Malformed JWT");
18
- }
19
- // Handle URL-safe Base64
20
- let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
21
- // Add padding if necessary
22
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
23
- const jsonText = atob(b64);
24
- return JSON.parse(jsonText);
25
- }
@@ -1,25 +0,0 @@
1
- /** True if token is structurally bad or its exp ≤ now. */
2
- export function isTokenExpired(token) {
3
- try {
4
- const payload = decodeJwt(token);
5
- return Date.now() / 1000 >= payload.exp;
6
- }
7
- catch (_a) {
8
- return true; // treat malformed token as expired
9
- }
10
- }
11
- /* ------------------------------------------------------------------ */
12
- /* internals */
13
- /* ------------------------------------------------------------------ */
14
- export function decodeJwt(token) {
15
- const [header, payload, signature] = token.split(".");
16
- if (!header || !payload || !signature) {
17
- throw new Error("Malformed JWT");
18
- }
19
- // Handle URL-safe Base64
20
- let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
21
- // Add padding if necessary
22
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
23
- const jsonText = atob(b64);
24
- return JSON.parse(jsonText);
25
- }
@@ -1,105 +0,0 @@
1
- import { callStorage } from './../imports';
2
- /**
3
- ***Changes**:
4
- *- Updated import path for `InputProps` to `../../types/interfaces`.
5
- *
6
- *3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
7
- * Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
8
- *
9
- */
10
- /** Read raw JWT from LocalStorage (or null if absent) */
11
- export function getToken() {
12
- return callStorage('getItem', 'token');
13
- }
14
- export function isLoggedIn() {
15
- const tok = getToken();
16
- return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
17
- }
18
- /**
19
- * Add a Bearer Authorization header.
20
- * A shallow copy of headers is returned so callers can keep chaining.
21
- */
22
- export function getAuthorizationHeader(headers = {}, token = null) {
23
- token = token !== null && token !== void 0 ? token : getToken();
24
- headers = headers || {};
25
- if (token)
26
- headers["Authorization"] = `Bearer ${token}`;
27
- return Object.assign({}, headers);
28
- }
29
- /** Throw + redirect if there’s no valid token; otherwise return it. */
30
- export function requireToken() {
31
- const tok = getToken();
32
- if (!tok || isTokenExpired(tok)) {
33
- console.warn("→ No token or expired token, redirecting to login…");
34
- localStorage.removeItem("token");
35
- window.location.href = '/';
36
- throw new Error("Redirecting to login…");
37
- }
38
- return tok;
39
- }
40
- /** True if token is structurally bad or its exp ≤ now. */
41
- export function isTokenExpired(token) {
42
- try {
43
- const payload = decodeJwt(token);
44
- return Date.now() / 1000 >= payload.exp;
45
- }
46
- catch (_a) {
47
- return true; // treat malformed token as expired
48
- }
49
- }
50
- /** Convenience wrapper: return username from the JWT (or null). */
51
- export function currentUsername() {
52
- const tok = getToken();
53
- if (!tok)
54
- return null;
55
- try {
56
- const { username } = decodeJwt(tok);
57
- return username !== null && username !== void 0 ? username : null;
58
- }
59
- catch (_a) {
60
- return null;
61
- }
62
- }
63
- export function currentUsernames() {
64
- var _a;
65
- const tok = getToken();
66
- if (!tok)
67
- return null;
68
- try {
69
- const parts = tok.split(".");
70
- if (parts.length !== 3)
71
- return null;
72
- let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
73
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
74
- const jsonText = atob(b64);
75
- const payload = JSON.parse(jsonText);
76
- return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
77
- }
78
- catch (_b) {
79
- return null;
80
- }
81
- }
82
- /** Remove the JWT from LocalStorage */
83
- export function removeToken() {
84
- try {
85
- callStorage('removeItem', 'token');
86
- }
87
- catch (err) {
88
- console.warn("Failed to remove token:", err);
89
- }
90
- }
91
- /* ------------------------------------------------------------------ */
92
- /* internals */
93
- /* ------------------------------------------------------------------ */
94
- export function decodeJwt(token) {
95
- const [header, payload, signature] = token.split(".");
96
- if (!header || !payload || !signature) {
97
- throw new Error("Malformed JWT");
98
- }
99
- // Handle URL-safe Base64
100
- let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
101
- // Add padding if necessary
102
- b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
103
- const jsonText = atob(b64);
104
- return JSON.parse(jsonText);
105
- }
@@ -1,2 +0,0 @@
1
- export { getDocumentProp, safeGlobalProp } from './../safe_utils';
2
- export { readJsonFile } from './../read_utils';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,83 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { safeGlobalProp, readJsonFile } from "./../imports";
11
- // src/functions/config_utils/src/config_utils.ts
12
- let _cachedConfig = null;
13
- export function loadConfig() {
14
- return __awaiter(this, arguments, void 0, function* (filePath = null) {
15
- var _a, _b;
16
- if (_cachedConfig) {
17
- return _cachedConfig;
18
- }
19
- // 1) figure out where config.json lives
20
- let configUrl;
21
- if (filePath) {
22
- configUrl = filePath;
23
- }
24
- else if (typeof import.meta !== 'undefined' && typeof import.meta.url === 'string') {
25
- // ES module: resolve relative to this file
26
- try {
27
- const mod = yield (new Function("return import('./config.json').catch(() => ({}))"))();
28
- _cachedConfig = (_a = mod.default) !== null && _a !== void 0 ? _a : {};
29
- return _cachedConfig;
30
- }
31
- catch (_c) {
32
- configUrl = 'config.json';
33
- }
34
- }
35
- else {
36
- // browser fallback
37
- const baseURI = safeGlobalProp('document', 'baseURI');
38
- try {
39
- configUrl =
40
- typeof baseURI === 'string'
41
- ? new URL('config.json', baseURI).href
42
- : 'config.json';
43
- }
44
- catch (_d) {
45
- configUrl = 'config.json';
46
- }
47
- }
48
- // 2) if we have a fetch, try HTTP(S)
49
- const fetchFn = safeGlobalProp('fetch');
50
- if (typeof fetchFn === 'function') {
51
- try {
52
- const res = yield fetchFn(configUrl);
53
- if (res.ok) {
54
- const json = yield res.json();
55
- // cache & return
56
- _cachedConfig = (_b = json) !== null && _b !== void 0 ? _b : {};
57
- return _cachedConfig;
58
- }
59
- }
60
- catch (_e) {
61
- /* swallow */
62
- }
63
- }
64
- // 3) Node fallback: try reading from disk (requires your readJsonFile util)
65
- try {
66
- const disk = yield readJsonFile(configUrl);
67
- _cachedConfig = disk !== null && disk !== void 0 ? disk : {};
68
- return _cachedConfig;
69
- }
70
- catch (_f) {
71
- /* swallow */
72
- }
73
- // 4) if all else fails, return an empty config
74
- _cachedConfig = {};
75
- return _cachedConfig;
76
- });
77
- }
78
- export function getConfig(key) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const cfg = yield loadConfig();
81
- return key != null ? cfg[key] : cfg;
82
- });
83
- }
@@ -1 +0,0 @@
1
- export * from './config_utils';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,7 +0,0 @@
1
- export const PROTOCOL = 'https://';
2
- export const DOMAIN_NAME = 'abstractendeavors';
3
- export const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
4
- export const SUB_DIR = 'secure-files';
5
- export const PROD_PREFIX = `/${SUB_DIR}/`;
6
- export const API_PREFIX = `/${SUB_DIR}/api`;
7
- export const DEV_PREFIX = `/${SUB_DIR}-dev/`;
@@ -1 +0,0 @@
1
- export * from './constants';
@@ -1 +0,0 @@
1
- export { BASE_URL, DEV_PREFIX } from './../constants_utils/index';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from './window_utils';
@@ -1,47 +0,0 @@
1
- import { BASE_URL, DEV_PREFIX } from './../imports';
2
- export function get_window() {
3
- try {
4
- if (typeof window !== 'undefined') {
5
- return window;
6
- }
7
- }
8
- catch (err) {
9
- alert(err);
10
- }
11
- return null;
12
- }
13
- export function get_window_location() {
14
- try {
15
- const Window = get_window();
16
- if (!Window) {
17
- return BASE_URL;
18
- }
19
- return Window.location;
20
- }
21
- catch (err) {
22
- alert(err);
23
- }
24
- return null;
25
- }
26
- export function get_window_pathname() {
27
- try {
28
- const Window = get_window();
29
- if (!Window) {
30
- return DEV_PREFIX;
31
- }
32
- return Window.location.pathname;
33
- }
34
- catch (err) {
35
- alert(err);
36
- }
37
- return null;
38
- }
39
- export function get_window_parts() {
40
- try {
41
- return get_window_location();
42
- }
43
- catch (err) {
44
- alert(err);
45
- }
46
- return null;
47
- }
@@ -1 +0,0 @@
1
- export { readJsonFile, getConfigContent } from './../read_utils';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,70 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { getResult } from './utils';
11
- export function fetchIt(endpoint_1) {
12
- return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
13
- method = (method || "GET").toUpperCase();
14
- // 1) auto-detect absolute URLs
15
- const isAbsolute = typeof endpoint === "string" && /^https?:\/\//i.test(endpoint);
16
- // 2) choose the URL
17
- const url = endpoint;
18
- // 3) prepare headers & body
19
- headers = Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), headers);
20
- const opts = {
21
- method,
22
- credentials: withCredentials ? "include" : "same-origin",
23
- headers,
24
- body: body instanceof FormData
25
- ? body
26
- : body != null && method !== "GET"
27
- ? JSON.stringify(body)
28
- : undefined,
29
- };
30
- console.debug("➡️ secureFetchIt →", url, opts);
31
- const res = yield fetch(url, opts);
32
- if (!res.ok) {
33
- const err = yield res.text();
34
- throw new Error(`HTTP ${res.status}: ${err}`);
35
- }
36
- if (blob)
37
- return res.blob();
38
- if (returnReult)
39
- return getResult(res.json());
40
- if (returnJson)
41
- return res.json();
42
- return res;
43
- });
44
- }
45
- // Constructs HTML directory path
46
- export function getHtmlDirectory(directory, filename) {
47
- return `${directory}/${filename}.html`;
48
- }
49
- // Fetches HTML content
50
- export function fetchIndexHtml(filename_1) {
51
- return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
52
- const url = `/${base}/${directory}/${filename}.html`;
53
- const response = yield fetch(url);
54
- return yield response.text();
55
- });
56
- }
57
- // Fetches and injects HTML content into container
58
- export function fetchIndexHtmlContainer(filename_1) {
59
- return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
60
- const container = `${filename}-container`;
61
- const html = yield fetchIndexHtml(filename, directory);
62
- const el = doc.getElementById(container);
63
- if (el) {
64
- el.innerHTML = html;
65
- }
66
- else {
67
- console.warn(`⚠️ No container found for: #${container}`);
68
- }
69
- });
70
- }
@@ -1,3 +0,0 @@
1
- export * from './fetch_utils';
2
- export * from './utils';
3
- export * from './url_utils';