@putkoff/abstract-utilities 0.1.118 → 0.1.122

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 (259) hide show
  1. package/dist/cjs/functions/auth_utils/imports.d.ts +0 -0
  2. package/dist/cjs/functions/auth_utils/index.d.ts +0 -0
  3. package/dist/cjs/functions/auth_utils/src/index.d.ts +0 -0
  4. package/dist/cjs/functions/auth_utils/src/token_utils.d.ts +0 -0
  5. package/dist/cjs/functions/config_utils/imports.d.ts +0 -0
  6. package/dist/cjs/functions/config_utils/index.d.ts +0 -0
  7. package/dist/cjs/functions/config_utils/src/config_utils.d.ts +0 -0
  8. package/dist/cjs/functions/config_utils/src/index.d.ts +0 -0
  9. package/dist/cjs/functions/constants_utils/index.d.ts +0 -0
  10. package/dist/cjs/functions/constants_utils/src/constants.d.ts +0 -0
  11. package/dist/cjs/functions/constants_utils/src/index.d.ts +0 -0
  12. package/dist/cjs/functions/env_utils/imports.d.ts +0 -0
  13. package/dist/cjs/functions/env_utils/index.d.ts +0 -0
  14. package/dist/cjs/functions/env_utils/src/index.d.ts +0 -0
  15. package/dist/cjs/functions/env_utils/src/window_utils.d.ts +0 -0
  16. package/dist/cjs/functions/fetch_utils/imports.d.ts +1 -1
  17. package/dist/cjs/functions/fetch_utils/index.d.ts +0 -0
  18. package/dist/cjs/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
  19. package/dist/cjs/functions/fetch_utils/src/index.d.ts +0 -0
  20. package/dist/cjs/functions/fetch_utils/src/utils.d.ts +0 -0
  21. package/dist/cjs/functions/index.d.ts +0 -0
  22. package/dist/cjs/functions/path_utils/imports.d.ts +3 -2
  23. package/dist/cjs/functions/path_utils/index.d.ts +0 -0
  24. package/dist/cjs/functions/path_utils/src/base_dirs.d.ts +0 -0
  25. package/dist/cjs/functions/path_utils/src/function_dirs.d.ts +0 -0
  26. package/dist/cjs/functions/path_utils/src/index.d.ts +0 -0
  27. package/dist/cjs/functions/path_utils/src/misc_dirs.d.ts +0 -0
  28. package/dist/cjs/functions/path_utils/src/path_utils.d.ts +0 -0
  29. package/dist/cjs/functions/path_utils/src/paths.d.ts +0 -0
  30. package/dist/cjs/functions/path_utils/src/src_dirs.d.ts +0 -0
  31. package/dist/cjs/functions/read_utils/index.d.ts +0 -0
  32. package/dist/cjs/functions/read_utils/src/index.d.ts +0 -0
  33. package/dist/cjs/functions/read_utils/src/read_utils.d.ts +0 -0
  34. package/dist/cjs/functions/rndm_utils/index.d.ts +0 -0
  35. package/dist/cjs/functions/rndm_utils/src/index.d.ts +0 -0
  36. package/dist/cjs/functions/rndm_utils/src/utils.d.ts +0 -0
  37. package/dist/cjs/functions/string_utils/index.d.ts +0 -0
  38. package/dist/cjs/functions/string_utils/src/index.d.ts +0 -0
  39. package/dist/cjs/functions/string_utils/src/string_utils.d.ts +0 -0
  40. package/dist/cjs/functions/type_utils/index.d.ts +0 -0
  41. package/dist/cjs/functions/type_utils/src/index.d.ts +0 -0
  42. package/dist/cjs/functions/type_utils/src/type_utils.d.ts +0 -0
  43. package/dist/cjs/functions/ui_utils/imports.d.ts +0 -0
  44. package/dist/cjs/functions/ui_utils/index.d.ts +0 -0
  45. package/dist/cjs/functions/ui_utils/src/button.d.ts +0 -0
  46. package/dist/cjs/functions/ui_utils/src/checkbox.d.ts +0 -0
  47. package/dist/cjs/functions/ui_utils/src/index.d.ts +0 -0
  48. package/dist/cjs/functions/ui_utils/src/input.d.ts +0 -0
  49. package/dist/cjs/functions/ui_utils/src/spinner.d.ts +0 -0
  50. package/dist/cjs/index.d.ts +0 -0
  51. package/dist/cjs/index.js +62 -52
  52. package/dist/cjs/index.js.map +1 -1
  53. package/dist/cjs/types/index.d.ts +0 -0
  54. package/dist/cjs/types/src/ChangePassword.d.ts +0 -0
  55. package/dist/cjs/types/src/Files.d.ts +0 -0
  56. package/dist/cjs/types/src/index.d.ts +0 -0
  57. package/dist/cjs/types/src/login.d.ts +0 -0
  58. package/dist/cjs/types/src/logout.d.ts +0 -0
  59. package/dist/cjs/types/src/utils.d.ts +0 -0
  60. package/dist/cjs/utils/imports.d.ts +0 -0
  61. package/dist/cjs/utils/index.d.ts +0 -0
  62. package/dist/cjs/utils/src/Input.d.ts +0 -0
  63. package/dist/cjs/utils/src/config.d.ts +0 -0
  64. package/dist/cjs/utils/src/index.d.ts +0 -0
  65. package/dist/esm/functions/auth_utils/imports.d.ts +0 -0
  66. package/dist/esm/functions/auth_utils/index.d.ts +0 -0
  67. package/dist/esm/functions/auth_utils/src/index.d.ts +0 -0
  68. package/dist/esm/functions/auth_utils/src/token_utils.d.ts +0 -0
  69. package/dist/esm/functions/config_utils/imports.d.ts +0 -0
  70. package/dist/esm/functions/config_utils/index.d.ts +0 -0
  71. package/dist/esm/functions/config_utils/src/config_utils.d.ts +0 -0
  72. package/dist/esm/functions/config_utils/src/index.d.ts +0 -0
  73. package/dist/esm/functions/constants_utils/index.d.ts +0 -0
  74. package/dist/esm/functions/constants_utils/src/constants.d.ts +0 -0
  75. package/dist/esm/functions/constants_utils/src/index.d.ts +0 -0
  76. package/dist/esm/functions/env_utils/imports.d.ts +0 -0
  77. package/dist/esm/functions/env_utils/index.d.ts +0 -0
  78. package/dist/esm/functions/env_utils/src/index.d.ts +0 -0
  79. package/dist/esm/functions/env_utils/src/window_utils.d.ts +0 -0
  80. package/dist/esm/functions/fetch_utils/imports.d.ts +1 -1
  81. package/dist/esm/functions/fetch_utils/index.d.ts +0 -0
  82. package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
  83. package/dist/esm/functions/fetch_utils/src/index.d.ts +0 -0
  84. package/dist/esm/functions/fetch_utils/src/utils.d.ts +0 -0
  85. package/dist/esm/functions/index.d.ts +0 -0
  86. package/dist/esm/functions/path_utils/imports.d.ts +3 -2
  87. package/dist/esm/functions/path_utils/index.d.ts +0 -0
  88. package/dist/esm/functions/path_utils/src/base_dirs.d.ts +0 -0
  89. package/dist/esm/functions/path_utils/src/function_dirs.d.ts +0 -0
  90. package/dist/esm/functions/path_utils/src/index.d.ts +0 -0
  91. package/dist/esm/functions/path_utils/src/misc_dirs.d.ts +0 -0
  92. package/dist/esm/functions/path_utils/src/path_utils.d.ts +0 -0
  93. package/dist/esm/functions/path_utils/src/paths.d.ts +0 -0
  94. package/dist/esm/functions/path_utils/src/src_dirs.d.ts +0 -0
  95. package/dist/esm/functions/read_utils/index.d.ts +0 -0
  96. package/dist/esm/functions/read_utils/src/index.d.ts +0 -0
  97. package/dist/esm/functions/read_utils/src/read_utils.d.ts +0 -0
  98. package/dist/esm/functions/rndm_utils/index.d.ts +0 -0
  99. package/dist/esm/functions/rndm_utils/src/index.d.ts +0 -0
  100. package/dist/esm/functions/rndm_utils/src/utils.d.ts +0 -0
  101. package/dist/esm/functions/string_utils/index.d.ts +0 -0
  102. package/dist/esm/functions/string_utils/src/index.d.ts +0 -0
  103. package/dist/esm/functions/string_utils/src/string_utils.d.ts +0 -0
  104. package/dist/esm/functions/type_utils/index.d.ts +0 -0
  105. package/dist/esm/functions/type_utils/src/index.d.ts +0 -0
  106. package/dist/esm/functions/type_utils/src/type_utils.d.ts +0 -0
  107. package/dist/esm/functions/ui_utils/imports.d.ts +0 -0
  108. package/dist/esm/functions/ui_utils/index.d.ts +0 -0
  109. package/dist/esm/functions/ui_utils/src/button.d.ts +0 -0
  110. package/dist/esm/functions/ui_utils/src/checkbox.d.ts +0 -0
  111. package/dist/esm/functions/ui_utils/src/index.d.ts +0 -0
  112. package/dist/esm/functions/ui_utils/src/input.d.ts +0 -0
  113. package/dist/esm/functions/ui_utils/src/spinner.d.ts +0 -0
  114. package/dist/esm/index.d.ts +0 -0
  115. package/dist/esm/index.js +62 -52
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/types/index.d.ts +0 -0
  118. package/dist/esm/types/src/ChangePassword.d.ts +0 -0
  119. package/dist/esm/types/src/Files.d.ts +0 -0
  120. package/dist/esm/types/src/index.d.ts +0 -0
  121. package/dist/esm/types/src/login.d.ts +0 -0
  122. package/dist/esm/types/src/logout.d.ts +0 -0
  123. package/dist/esm/types/src/utils.d.ts +0 -0
  124. package/dist/esm/utils/imports.d.ts +0 -0
  125. package/dist/esm/utils/index.d.ts +0 -0
  126. package/dist/esm/utils/src/Input.d.ts +0 -0
  127. package/dist/esm/utils/src/config.d.ts +0 -0
  128. package/dist/esm/utils/src/index.d.ts +0 -0
  129. package/dist/functions/auth_utils/imports.d.ts +0 -0
  130. package/dist/functions/auth_utils/imports.js +1 -0
  131. package/dist/functions/auth_utils/index.d.ts +0 -0
  132. package/dist/functions/auth_utils/index.js +1 -0
  133. package/dist/functions/auth_utils/src/index.d.ts +0 -0
  134. package/dist/functions/auth_utils/src/index.js +1 -0
  135. package/dist/functions/auth_utils/src/token_utils.d.ts +0 -0
  136. package/dist/functions/auth_utils/src/token_utils.js +95 -0
  137. package/dist/functions/config_utils/imports.d.ts +0 -0
  138. package/dist/functions/config_utils/imports.js +1 -0
  139. package/dist/functions/config_utils/index.d.ts +0 -0
  140. package/dist/functions/config_utils/index.js +1 -0
  141. package/dist/functions/config_utils/src/config_utils.d.ts +0 -0
  142. package/dist/functions/config_utils/src/config_utils.js +33 -0
  143. package/dist/functions/config_utils/src/index.d.ts +0 -0
  144. package/dist/functions/config_utils/src/index.js +1 -0
  145. package/dist/functions/constants_utils/index.d.ts +0 -0
  146. package/dist/functions/constants_utils/index.js +1 -0
  147. package/dist/functions/constants_utils/src/constants.d.ts +0 -0
  148. package/dist/functions/constants_utils/src/constants.js +7 -0
  149. package/dist/functions/constants_utils/src/index.d.ts +0 -0
  150. package/dist/functions/constants_utils/src/index.js +1 -0
  151. package/dist/functions/env_utils/imports.d.ts +0 -0
  152. package/dist/functions/env_utils/imports.js +1 -0
  153. package/dist/functions/env_utils/index.d.ts +0 -0
  154. package/dist/functions/env_utils/index.js +1 -0
  155. package/dist/functions/env_utils/src/index.d.ts +0 -0
  156. package/dist/functions/env_utils/src/index.js +1 -0
  157. package/dist/functions/env_utils/src/window_utils.d.ts +0 -0
  158. package/dist/functions/env_utils/src/window_utils.js +47 -0
  159. package/dist/functions/fetch_utils/imports.d.ts +1 -1
  160. package/dist/functions/fetch_utils/imports.js +7 -0
  161. package/dist/functions/fetch_utils/index.d.ts +0 -0
  162. package/dist/functions/fetch_utils/index.js +1 -0
  163. package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
  164. package/dist/functions/fetch_utils/src/fetchIt_utils.js +116 -0
  165. package/dist/functions/fetch_utils/src/index.d.ts +0 -0
  166. package/dist/functions/fetch_utils/src/index.js +1 -0
  167. package/dist/functions/fetch_utils/src/utils.d.ts +0 -0
  168. package/dist/functions/fetch_utils/src/utils.js +171 -0
  169. package/dist/functions/index.d.ts +0 -0
  170. package/dist/functions/index.js +12 -0
  171. package/dist/functions/path_utils/imports.d.ts +3 -2
  172. package/dist/functions/path_utils/imports.js +26 -0
  173. package/dist/functions/path_utils/index.d.ts +0 -0
  174. package/dist/functions/path_utils/index.js +1 -0
  175. package/dist/functions/path_utils/src/base_dirs.d.ts +0 -0
  176. package/dist/functions/path_utils/src/base_dirs.js +17 -0
  177. package/dist/functions/path_utils/src/function_dirs.d.ts +0 -0
  178. package/dist/functions/path_utils/src/function_dirs.js +42 -0
  179. package/dist/functions/path_utils/src/index.d.ts +0 -0
  180. package/dist/functions/path_utils/src/index.js +6 -0
  181. package/dist/functions/path_utils/src/misc_dirs.d.ts +0 -0
  182. package/dist/functions/path_utils/src/misc_dirs.js +15 -0
  183. package/dist/functions/path_utils/src/path_utils.d.ts +0 -0
  184. package/dist/functions/path_utils/src/path_utils.js +75 -0
  185. package/dist/functions/path_utils/src/paths.d.ts +0 -0
  186. package/dist/functions/path_utils/src/paths.js +12 -0
  187. package/dist/functions/path_utils/src/src_dirs.d.ts +0 -0
  188. package/dist/functions/path_utils/src/src_dirs.js +25 -0
  189. package/dist/functions/read_utils/imports.d.ts +0 -0
  190. package/dist/functions/read_utils/imports.js +1 -0
  191. package/dist/functions/read_utils/index.d.ts +0 -0
  192. package/dist/functions/read_utils/index.js +1 -0
  193. package/dist/functions/read_utils/src/index.d.ts +0 -0
  194. package/dist/functions/read_utils/src/index.js +1 -0
  195. package/dist/functions/read_utils/src/read_utils.d.ts +0 -0
  196. package/dist/functions/read_utils/src/read_utils.js +55 -0
  197. package/dist/functions/rndm_utils/imports.d.ts +0 -0
  198. package/dist/functions/rndm_utils/imports.js +1 -0
  199. package/dist/functions/rndm_utils/index.d.ts +0 -0
  200. package/dist/functions/rndm_utils/index.js +1 -0
  201. package/dist/functions/rndm_utils/src/index.d.ts +0 -0
  202. package/dist/functions/rndm_utils/src/index.js +1 -0
  203. package/dist/functions/rndm_utils/src/utils.d.ts +0 -0
  204. package/dist/functions/rndm_utils/src/utils.js +12 -0
  205. package/dist/functions/string_utils/index.d.ts +0 -0
  206. package/dist/functions/string_utils/index.js +1 -0
  207. package/dist/functions/string_utils/src/index.d.ts +0 -0
  208. package/dist/functions/string_utils/src/index.js +1 -0
  209. package/dist/functions/string_utils/src/string_utils.d.ts +0 -0
  210. package/dist/functions/string_utils/src/string_utils.js +113 -0
  211. package/dist/functions/type_utils/imports.d.ts +0 -0
  212. package/dist/functions/type_utils/imports.js +1 -0
  213. package/dist/functions/type_utils/index.d.ts +0 -0
  214. package/dist/functions/type_utils/index.js +1 -0
  215. package/dist/functions/type_utils/src/index.d.ts +0 -0
  216. package/dist/functions/type_utils/src/index.js +1 -0
  217. package/dist/functions/type_utils/src/type_utils.d.ts +0 -0
  218. package/dist/functions/type_utils/src/type_utils.js +4 -0
  219. package/dist/functions/ui_utils/imports.d.ts +0 -0
  220. package/dist/functions/ui_utils/imports.js +5 -0
  221. package/dist/functions/ui_utils/index.d.ts +0 -0
  222. package/dist/functions/ui_utils/index.js +1 -0
  223. package/dist/functions/ui_utils/src/button.d.ts +0 -0
  224. package/dist/functions/ui_utils/src/button.js +32 -0
  225. package/dist/functions/ui_utils/src/checkbox.d.ts +0 -0
  226. package/dist/functions/ui_utils/src/checkbox.js +16 -0
  227. package/dist/functions/ui_utils/src/index.d.ts +0 -0
  228. package/dist/functions/ui_utils/src/index.js +4 -0
  229. package/dist/functions/ui_utils/src/input.d.ts +0 -0
  230. package/dist/functions/ui_utils/src/input.js +16 -0
  231. package/dist/functions/ui_utils/src/spinner.d.ts +0 -0
  232. package/dist/functions/ui_utils/src/spinner.js +4 -0
  233. package/dist/index.d.ts +1 -1
  234. package/dist/index.js +5 -0
  235. package/dist/types/index.d.ts +0 -0
  236. package/dist/types/index.js +1 -0
  237. package/dist/types/src/ChangePassword.d.ts +0 -0
  238. package/dist/types/src/ChangePassword.js +1 -0
  239. package/dist/types/src/Files.d.ts +0 -0
  240. package/dist/types/src/Files.js +1 -0
  241. package/dist/types/src/index.d.ts +0 -0
  242. package/dist/types/src/index.js +5 -0
  243. package/dist/types/src/login.d.ts +0 -0
  244. package/dist/types/src/login.js +1 -0
  245. package/dist/types/src/logout.d.ts +0 -0
  246. package/dist/types/src/logout.js +1 -0
  247. package/dist/types/src/utils.d.ts +0 -0
  248. package/dist/types/src/utils.js +1 -0
  249. package/dist/utils/imports.d.ts +0 -0
  250. package/dist/utils/imports.js +1 -0
  251. package/dist/utils/index.d.ts +0 -0
  252. package/dist/utils/index.js +1 -0
  253. package/dist/utils/src/Input.d.ts +0 -0
  254. package/dist/utils/src/Input.js +2 -0
  255. package/dist/utils/src/config.d.ts +0 -0
  256. package/dist/utils/src/config.js +20 -0
  257. package/dist/utils/src/index.d.ts +0 -0
  258. package/dist/utils/src/index.js +2 -0
  259. package/package.json +8 -1
@@ -0,0 +1,95 @@
1
+ /**
2
+ ***Changes**:
3
+ *- Updated import path for `InputProps` to `../../types/interfaces`.
4
+ *
5
+ *3. **Token Utilities** (`src/functions/auth/token_utils.ts`):
6
+ * Copy from `/var/www/abstractendeavors/my-login-app/src/functions/auth_utils/token_utils.ts`.
7
+ *
8
+ */
9
+ export function isLoggedIn() {
10
+ const tok = localStorage.getItem("token");
11
+ return !!tok && !isTokenExpired(tok !== null && tok !== void 0 ? tok : "");
12
+ }
13
+ /** Read raw JWT from LocalStorage (or null if absent) */
14
+ export function getToken() {
15
+ return localStorage.getItem("token");
16
+ }
17
+ /**
18
+ * Add a Bearer Authorization header.
19
+ * A shallow copy of headers is returned so callers can keep chaining.
20
+ */
21
+ export function getAuthorizationHeader(headers = {}, token = null) {
22
+ token = token !== null && token !== void 0 ? token : getToken();
23
+ headers = headers || {};
24
+ if (token)
25
+ headers["Authorization"] = `Bearer ${token}`;
26
+ return Object.assign({}, headers);
27
+ }
28
+ /** Throw + redirect if there’s no valid token; otherwise return it. */
29
+ export function requireToken() {
30
+ const tok = getToken();
31
+ if (!tok || isTokenExpired(tok)) {
32
+ console.warn("→ No token or expired token, redirecting to login…");
33
+ localStorage.removeItem("token");
34
+ window.location.href = '/login';
35
+ throw new Error("Redirecting to login…");
36
+ }
37
+ return tok;
38
+ }
39
+ /** True if token is structurally bad or its exp ≤ now. */
40
+ export function isTokenExpired(token) {
41
+ try {
42
+ const payload = decodeJwt(token);
43
+ return Date.now() / 1000 >= payload.exp;
44
+ }
45
+ catch (_a) {
46
+ return true; // treat malformed token as expired
47
+ }
48
+ }
49
+ /** Convenience wrapper: return username from the JWT (or null). */
50
+ export function currentUsername() {
51
+ const tok = getToken();
52
+ if (!tok)
53
+ return null;
54
+ try {
55
+ const { username } = decodeJwt(tok);
56
+ return username !== null && username !== void 0 ? username : null;
57
+ }
58
+ catch (_a) {
59
+ return null;
60
+ }
61
+ }
62
+ export function currentUsernames() {
63
+ var _a;
64
+ const tok = localStorage.getItem("token");
65
+ if (!tok)
66
+ return null;
67
+ try {
68
+ const parts = tok.split(".");
69
+ if (parts.length !== 3)
70
+ return null;
71
+ let b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
72
+ b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
73
+ const jsonText = atob(b64);
74
+ const payload = JSON.parse(jsonText);
75
+ return (_a = payload.username) !== null && _a !== void 0 ? _a : null;
76
+ }
77
+ catch (_b) {
78
+ return null;
79
+ }
80
+ }
81
+ /* ------------------------------------------------------------------ */
82
+ /* internals */
83
+ /* ------------------------------------------------------------------ */
84
+ export function decodeJwt(token) {
85
+ const [header, payload, signature] = token.split(".");
86
+ if (!header || !payload || !signature) {
87
+ throw new Error("Malformed JWT");
88
+ }
89
+ // Handle URL-safe Base64
90
+ let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
91
+ // Add padding if necessary
92
+ b64 = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
93
+ const jsonText = atob(b64);
94
+ return JSON.parse(jsonText);
95
+ }
File without changes
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export * from './src';
File without changes
@@ -0,0 +1,33 @@
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
+ let _cachedConfig = null;
11
+ function loadConfig() {
12
+ return __awaiter(this, arguments, void 0, function* (filePath = null) {
13
+ // 1. If nobody passed a custom path, we default to "config.json" (relative)
14
+ const relativePath = filePath || 'config.json';
15
+ // 2. Resolve it against the running page’s URL (document.baseURI)
16
+ const configUrl = new URL(relativePath, document.baseURI).href;
17
+ // 3. Fetch + cache
18
+ if (_cachedConfig)
19
+ return _cachedConfig;
20
+ const res = yield fetch(configUrl);
21
+ if (!res.ok) {
22
+ throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
23
+ }
24
+ _cachedConfig = (yield res.json());
25
+ return _cachedConfig;
26
+ });
27
+ }
28
+ export function getConfig(key) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const cfg = yield loadConfig();
31
+ return key ? cfg[key] : cfg;
32
+ });
33
+ }
File without changes
@@ -0,0 +1 @@
1
+ export * from './config_utils';
File without changes
@@ -0,0 +1 @@
1
+ export * from './src';
File without changes
@@ -0,0 +1,7 @@
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/`;
File without changes
@@ -0,0 +1 @@
1
+ export * from './constants';
File without changes
@@ -0,0 +1 @@
1
+ export { BASE_URL, DEV_PREFIX } from './../constants_utils/index';
File without changes
@@ -0,0 +1 @@
1
+ export * from './src';
File without changes
@@ -0,0 +1 @@
1
+ export * from './window_utils';
File without changes
@@ -0,0 +1,47 @@
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
+ }
@@ -4,5 +4,5 @@ export { stripPrefixes } from './../string_utils';
4
4
  export { alertit } from './../rndm_utils';
5
5
  export { ensure_list } from './../type_utils';
6
6
  export { eatInner } from './../string_utils';
7
- export type { LogoutButtonProps, FetchVariables } from './../../types';
7
+ export type { LogoutButtonProps, FetchVariables, AppConfig } from './../../types';
8
8
  export { getConfig } from './../config_utils';
@@ -0,0 +1,7 @@
1
+ export { getAuthorizationHeader } from "./../auth_utils";
2
+ export { make_path } from './../path_utils';
3
+ export { stripPrefixes } from './../string_utils';
4
+ export { alertit } from './../rndm_utils';
5
+ export { ensure_list } from './../type_utils';
6
+ export { eatInner } from './../string_utils';
7
+ export { getConfig } from './../config_utils';
File without changes
@@ -0,0 +1 @@
1
+ export * from './src';
@@ -7,7 +7,7 @@
7
7
  *
8
8
  */
9
9
  /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
10
- export declare function get_app_config_url(endpoint: any, appKey?: any): Promise<string>;
10
+ export declare function get_app_config_url(endpoint: string, appKey?: any): Promise<string>;
11
11
  export declare function fetchIt(endpoint: string, body?: unknown, method?: string | null, headers?: Record<string, string> | null, blob?: boolean | null, no_api?: boolean, requireAuth?: boolean): Promise<unknown>;
12
12
  export declare function secureFetchIt<T>(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<T>;
13
13
  export declare function secureFetchIt(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<Blob>;
@@ -0,0 +1,116 @@
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 { getFetchVars, checkResponse, api, parseResult, ensureAbstractUrl, getResult } from './utils';
11
+ import { getAuthorizationHeader, getConfig } from './../imports';
12
+ /**
13
+
14
+ ***Changes**: None, as it’s self-contained and doesn’t rely on external imports.
15
+ *
16
+ *4. **secureFetchIt** (`src/functions/fetch/secureFetchIt.ts`):
17
+ * Since `secureFetchIt` isn’t provided, we’ll create a minimal implementation based on its usage in `Login` and `uploadFiles`. It’s assumed to be a wrapper around `fetch` that handles authentication and JSON parsing.
18
+ *
19
+ */
20
+ /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
21
+ // src/functions/fetch/secureFetchIt.ts
22
+ // --- fetch_utils/src/fetch_utils.ts ----------------------------
23
+ export function get_app_config_url(endpoint_1) {
24
+ return __awaiter(this, arguments, void 0, function* (endpoint, appKey = 'BASE_API_URL') {
25
+ const cleanEndpoint = endpoint.replace(/^\/+/, '');
26
+ console.log(`cleanEndpoint == ${cleanEndpoint}`);
27
+ const config = yield getConfig();
28
+ console.log(`config == ${config}`);
29
+ const baseUrl = JSON.stringify(config);
30
+ console.log(`baseUrl == ${baseUrl}`);
31
+ appKey = appKey || 'BASE_API_URL';
32
+ console.log(`appKey == ${appKey}`);
33
+ const base = baseUrl[appKey]; // full AppConfig object
34
+ console.log(`base == ${base}`);
35
+ const slices = base.split('/').filter(Boolean);
36
+ console.log(`slices == ${slices}`);
37
+ return ensureAbstractUrl(cleanEndpoint, slices);
38
+ });
39
+ }
40
+ export function fetchIt(endpoint_1) {
41
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
42
+ const vars = getFetchVars(headers, method, body);
43
+ const url = no_api ? endpoint : api(endpoint);
44
+ const res = yield fetch(url, vars);
45
+ return blob ? (checkResponse(res), res.blob()) : yield parseResult(res);
46
+ });
47
+ }
48
+ export function secureFetchIt(endpoint_1) {
49
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true, returnReult = true) {
50
+ // strip leading slashes off the endpoint
51
+ method = method || "GET";
52
+ let url = endpoint;
53
+ if (!noApi) {
54
+ url = yield get_app_config_url(endpoint);
55
+ }
56
+ // headers: JSON by default, plus any auth + overrides
57
+ const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
58
+ const opts = {
59
+ method: method.toUpperCase(),
60
+ credentials: withCredentials ? "include" : "same-origin",
61
+ headers,
62
+ body: body instanceof FormData
63
+ ? body
64
+ : body != null && method.toUpperCase() !== "GET"
65
+ ? JSON.stringify(body)
66
+ : undefined,
67
+ };
68
+ console.debug("➡️ secureFetchIt →", url, opts);
69
+ const res = yield fetch(url, opts);
70
+ if (!res.ok) {
71
+ const err = yield res.text();
72
+ throw new Error(`HTTP ${res.status}: ${err}`);
73
+ }
74
+ if (blob)
75
+ return res.blob();
76
+ if (returnReult)
77
+ return getResult(res.json());
78
+ if (returnJson)
79
+ return res.json();
80
+ return res;
81
+ });
82
+ }
83
+ // Performs PATCH request
84
+ export function requestPatch(url_1) {
85
+ return __awaiter(this, arguments, void 0, function* (url, body = null) {
86
+ const variables = getFetchVars(null, 'PATCH', body);
87
+ return yield fetch(api(url), variables);
88
+ });
89
+ }
90
+ // Performs PATCH request for file sharing
91
+ export function fetchSharePatch(file_1) {
92
+ return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
93
+ const cleanEndpoint = '/files/share';
94
+ // build final URL
95
+ const url = yield get_app_config_url(cleanEndpoint);
96
+ const token = localStorage.getItem('token');
97
+ const body = JSON.stringify(file);
98
+ const method = 'PATCH';
99
+ const headers = {
100
+ 'Content-Type': 'application/json',
101
+ 'Authorization': `Bearer ${token}`,
102
+ };
103
+ const resp = yield fetch(url, {
104
+ method,
105
+ headers,
106
+ body
107
+ });
108
+ if (!resp.ok) {
109
+ console.error('Error from server', yield resp.text());
110
+ }
111
+ else {
112
+ const data = yield resp.json();
113
+ console.log('Success!', data);
114
+ }
115
+ });
116
+ }
File without changes
@@ -0,0 +1 @@
1
+ export * from './fetchIt_utils';
File without changes
@@ -0,0 +1,171 @@
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 { eatInner, stripPrefixes, make_path, getAuthorizationHeader, ensure_list } from './../imports';
11
+ export function ensureAbstractUrl(endpoint, slices = []) {
12
+ slices = ['https//thedailydialectics.com', 'api', 'secure-files'];
13
+ // 1) build a prefix string like "api/v1/"
14
+ const prefix = slices.map((s) => `${s}/`).join("");
15
+ // 2) normalize the list you’ll use for stripping
16
+ const normalized = ["/", ...ensure_list(slices)];
17
+ // 3) remove any inner “/” duplicates from prefix
18
+ const target = eatInner(prefix, ["/"]);
19
+ // 4) drop any of those prefixes off the endpoint
20
+ const strippedEndpoint = stripPrefixes(endpoint, normalized);
21
+ // 5) hand it back to make_path to join “target” + “strippedEndpoint”
22
+ return make_path(target, strippedEndpoint);
23
+ }
24
+ /**
25
+ * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
26
+ */
27
+ export function getResult(obj) {
28
+ let current = obj;
29
+ while (current &&
30
+ typeof current === "object" &&
31
+ Object.prototype.hasOwnProperty.call(current, "result")) {
32
+ current = current.result;
33
+ }
34
+ return current;
35
+ }
36
+ // Constructs API URL from endpoint
37
+ export function api(endpoint) {
38
+ return ensureAbstractUrl(endpoint);
39
+ }
40
+ // Checks if response is OK, handles 401/403 by redirecting to login
41
+ export function checkResponse(res) {
42
+ if (!res.ok) {
43
+ if (res.status === 401 || res.status === 403) {
44
+ alert('Session expired. Please log in again.');
45
+ localStorage.removeItem('token');
46
+ window.location.href = '/secure-files/login';
47
+ }
48
+ }
49
+ return res;
50
+ }
51
+ // Parses JSON response and handles specific response shapes
52
+ export function parseResult(res) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ res = checkResponse(res);
55
+ try {
56
+ const data = yield res.json();
57
+ if ((data === null || data === void 0 ? void 0 : data.success) === true && Array.isArray(data.result)) {
58
+ return data.result;
59
+ }
60
+ if ((data === null || data === void 0 ? void 0 : data.message) && typeof data.message === 'string') {
61
+ alert(`Error: ${data.message}`);
62
+ }
63
+ return data;
64
+ }
65
+ catch (err) {
66
+ throw new Error('Server returned invalid JSON');
67
+ }
68
+ });
69
+ }
70
+ // Determines HTTP method, defaults to GET or POST based on body
71
+ export function getMethod(method = null, body = null) {
72
+ const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'PULL'];
73
+ method = (method || '').toUpperCase();
74
+ if (!validMethods.includes(method)) {
75
+ method = body ? 'POST' : 'GET';
76
+ }
77
+ return method;
78
+ }
79
+ // Gets headers, skips JSON headers when body is FormData
80
+ export function getHeaders(headers = {}, method = null, body = null) {
81
+ const result = Object.assign({}, headers);
82
+ // inject auth if missing
83
+ if (!result.Authorization) {
84
+ const token = localStorage.getItem('token');
85
+ Object.assign(result, getAuthorizationHeader(result, token));
86
+ }
87
+ method = getMethod(method, body);
88
+ // if it’s a multipart FormData, let the browser set the boundary header
89
+ if (body instanceof FormData) {
90
+ return result;
91
+ }
92
+ // otherwise for POST/PUT/PATCH default to JSON
93
+ if (['POST', 'PUT', 'PATCH'].includes(method) && !result['Content-Type']) {
94
+ result['Content-Type'] = 'application/json';
95
+ }
96
+ return result;
97
+ }
98
+ // Prepares request body, serializes to JSON for non-GET requests
99
+ export function getBody(body = null, method = null) {
100
+ method = getMethod(method, body);
101
+ if (method === 'GET') {
102
+ return undefined;
103
+ }
104
+ if (body) {
105
+ try {
106
+ return JSON.stringify(body);
107
+ }
108
+ catch (err) {
109
+ return body;
110
+ }
111
+ }
112
+ return undefined;
113
+ }
114
+ // Prepares fetch variables, passes FormData intact
115
+ export function getFetchVars(headers = null, method = null, body = null) {
116
+ method = getMethod(method, body);
117
+ headers = getHeaders(headers || {}, method, body);
118
+ // only JSON-stringify non-FormData bodies
119
+ if (!(body instanceof FormData)) {
120
+ body = getBody(body, method);
121
+ }
122
+ return { method, headers, body };
123
+ }
124
+ function tryParse(obj) {
125
+ try {
126
+ obj = JSON.stringify(obj);
127
+ }
128
+ catch (err) {
129
+ try {
130
+ obj = JSON.parse(obj);
131
+ }
132
+ catch (err) {
133
+ }
134
+ }
135
+ return obj;
136
+ }
137
+ function create_list_string(array_obj) {
138
+ let string = '';
139
+ for (const obj in array_obj) {
140
+ const array_value = array_obj[obj];
141
+ const parsed_value = tryParse(array_value);
142
+ string += `${obj} == ${parsed_value}\n`;
143
+ }
144
+ return string;
145
+ }
146
+ // Constructs HTML directory path
147
+ export function getHtmlDirectory(directory, filename) {
148
+ return `${directory}/${filename}.html`;
149
+ }
150
+ // Fetches HTML content
151
+ export function fetchIndexHtml(filename_1) {
152
+ return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
153
+ const url = `/${base}/${directory}/${filename}.html`;
154
+ const response = yield fetch(api(url));
155
+ return yield response.text();
156
+ });
157
+ }
158
+ // Fetches and injects HTML content into container
159
+ export function fetchIndexHtmlContainer(filename_1) {
160
+ return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
161
+ const container = `${filename}-container`;
162
+ const html = yield fetchIndexHtml(filename, directory);
163
+ const el = doc.getElementById(container);
164
+ if (el) {
165
+ el.innerHTML = html;
166
+ }
167
+ else {
168
+ console.warn(`⚠️ No container found for: #${container}`);
169
+ }
170
+ });
171
+ }
File without changes
@@ -0,0 +1,12 @@
1
+ export { useCallback, useRef, useState, useEffect } from "react";
2
+ export * from './auth_utils';
3
+ export * from './constants_utils';
4
+ export * from './env_utils';
5
+ export * from './fetch_utils';
6
+ export * from './path_utils';
7
+ export * from './rndm_utils';
8
+ export * from './string_utils';
9
+ export * from './type_utils';
10
+ export * from './ui_utils';
11
+ export * from './config_utils';
12
+ export * from './read_utils';
@@ -2,14 +2,15 @@
2
2
  * In the browser we already have a WHATWG URL constructor on window.
3
3
  * Here we re-export it as “url” so other modules can import it.
4
4
  */
5
- export declare const url: {
5
+ declare const _url: {
6
6
  new (url: string | URL, base?: string | URL): URL;
7
7
  prototype: URL;
8
8
  canParse(url: string | URL, base?: string | URL): boolean;
9
9
  createObjectURL(obj: Blob | MediaSource): string;
10
10
  parse(url: string | URL, base?: string | URL): URL | null;
11
11
  revokeObjectURL(url: string): void;
12
- };
12
+ } | undefined;
13
+ export { _url as url };
13
14
  /**
14
15
  * Minimal fileURLToPath implementation for browser-side code.
15
16
  * If you only ever need to strip off “file://” in development, this is enough.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * In the browser we already have a WHATWG URL constructor on window.
3
+ * Here we re-export it as “url” so other modules can import it.
4
+ */
5
+ export const url = window.URL;
6
+ /**
7
+ * Minimal fileURLToPath implementation for browser-side code.
8
+ * If you only ever need to strip off “file://” in development, this is enough.
9
+ */
10
+ export function fileURLToPath(fileUrl) {
11
+ // e.g. fileUrl = "file:///Users/foo/bar.txt"
12
+ try {
13
+ const u = new URL(fileUrl);
14
+ return u.pathname;
15
+ }
16
+ catch (_a) {
17
+ // fallback: just strip file://
18
+ return fileUrl.replace(/^file:\/\//, '');
19
+ }
20
+ }
21
+ export { eatOuter, eatInner } from './../string_utils';
22
+ export { ensure_list } from './../type_utils';
23
+ export function getAbsolutePath() {
24
+ return fileURLToPath(import.meta.url);
25
+ }
26
+ ;
File without changes
@@ -0,0 +1 @@
1
+ export * from './src';
File without changes
@@ -0,0 +1,17 @@
1
+ import { make_path, get_dirname } from './path_utils';
2
+ import { getSrcDir } from './src_dirs';
3
+ export function getBaseDir() {
4
+ return get_dirname(getSrcDir());
5
+ }
6
+ export function getPublicDir() {
7
+ return make_path(getBaseDir(), 'public');
8
+ }
9
+ ;
10
+ export function getDistDir() {
11
+ return make_path(getBaseDir(), 'dist');
12
+ }
13
+ ;
14
+ export function getEnvDir() {
15
+ return make_path(getBaseDir(), '.env');
16
+ }
17
+ ;
File without changes