@putkoff/abstract-utilities 1.0.103 → 1.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/print_utils-DzyRoj6m.js.map +1 -1
- package/dist/cjs/safe_storage-CJgWghnh.js.map +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/print_utils-qqcMhSul.js.map +1 -1
- package/dist/esm/safe_storage-CMuv35Vo.js.map +1 -1
- package/dist/types/client/auth/index.d.ts +1 -1
- package/dist/types/client/auth/index.js +3 -0
- package/dist/types/client/auth/src/index.d.ts +1 -1
- package/dist/types/client/auth/src/index.js +3 -0
- package/dist/types/client/auth/src/token_client.js +73 -0
- package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
- package/dist/types/client/fetch/src/fetch_auth.js +26 -0
- package/dist/types/client/fetch/src/index.d.ts +1 -1
- package/dist/types/client/fetch/src/index.js +2 -0
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/index.js +4 -0
- package/dist/types/client/ui_utils/index.d.ts +1 -1
- package/dist/types/client/ui_utils/index.js +2 -0
- package/dist/types/client/ui_utils/src/button.js +34 -0
- package/dist/types/client/ui_utils/src/checkbox.js +18 -0
- package/dist/types/client/ui_utils/src/index.d.ts +4 -4
- package/dist/types/client/ui_utils/src/index.js +4 -0
- package/dist/types/client/ui_utils/src/input.js +18 -0
- package/dist/types/client/ui_utils/src/spinner.js +5 -0
- package/dist/types/functions/auth_utils/imports.d.ts +2 -2
- package/dist/types/functions/auth_utils/imports.js +1 -0
- package/dist/types/functions/auth_utils/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/index.js +1 -0
- package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/index.js +1 -0
- package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/jwt_core.js +25 -0
- package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils (Copy).js +25 -0
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils.js +105 -0
- package/dist/types/functions/config_utils/imports.d.ts +3 -3
- package/dist/types/functions/config_utils/imports.js +2 -0
- package/dist/types/functions/config_utils/index.d.ts +1 -1
- package/dist/types/functions/config_utils/index.js +1 -0
- package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/src/config_utils.js +83 -0
- package/dist/types/functions/config_utils/src/index.d.ts +1 -1
- package/dist/types/functions/config_utils/src/index.js +1 -0
- package/dist/types/functions/constants_utils/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/index.js +1 -0
- package/dist/types/functions/constants_utils/src/constants.js +7 -0
- package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/src/index.js +1 -0
- package/dist/types/functions/env_utils/imports.d.ts +1 -1
- package/dist/types/functions/env_utils/imports.js +1 -0
- package/dist/types/functions/env_utils/index.d.ts +1 -1
- package/dist/types/functions/env_utils/index.js +1 -0
- package/dist/types/functions/env_utils/src/index.d.ts +1 -1
- package/dist/types/functions/env_utils/src/index.js +1 -0
- package/dist/types/functions/env_utils/src/window_utils.js +47 -0
- package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
- package/dist/types/functions/fetch_utils/imports.js +1 -0
- package/dist/types/functions/fetch_utils/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/index.js +1 -0
- package/dist/types/functions/fetch_utils/src/fetch_utils.js +70 -0
- package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
- package/dist/types/functions/fetch_utils/src/index.js +3 -0
- package/dist/types/functions/fetch_utils/src/url_utils.js +86 -0
- package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
- package/dist/types/functions/fetch_utils/src/utils.js +102 -0
- package/dist/types/functions/index.d.ts +17 -17
- package/dist/types/functions/index.js +17 -0
- package/dist/types/functions/inspect_utils/imports.js +1 -0
- package/dist/types/functions/inspect_utils/index.d.ts +2 -2
- package/dist/types/functions/inspect_utils/index.js +2 -0
- package/dist/types/functions/inspect_utils/src/caller_utils.js +28 -0
- package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
- package/dist/types/functions/inspect_utils/src/index.js +1 -0
- package/dist/types/functions/math_utils/bigint_utils.js +36 -0
- package/dist/types/functions/math_utils/constants.js +37 -0
- package/dist/types/functions/math_utils/conversions.d.ts +1 -1
- package/dist/types/functions/math_utils/conversions.js +129 -0
- package/dist/types/functions/math_utils/index.d.ts +6 -6
- package/dist/types/functions/math_utils/index.js +6 -0
- package/dist/types/functions/math_utils/safe_math.js +35 -0
- package/dist/types/functions/math_utils/scaleInterfaces.js +3 -0
- package/dist/types/functions/math_utils/time_utils.js +4 -0
- package/dist/types/functions/path_utils/imports.d.ts +2 -2
- package/dist/types/functions/path_utils/imports.js +27 -0
- package/dist/types/functions/path_utils/index.d.ts +1 -1
- package/dist/types/functions/path_utils/index.js +1 -0
- package/dist/types/functions/path_utils/src/base_dirs.js +17 -0
- package/dist/types/functions/path_utils/src/function_dirs.js +42 -0
- package/dist/types/functions/path_utils/src/index.d.ts +6 -6
- package/dist/types/functions/path_utils/src/index.js +6 -0
- package/dist/types/functions/path_utils/src/misc_dirs.js +15 -0
- package/dist/types/functions/path_utils/src/path_utils.js +160 -0
- package/dist/types/functions/path_utils/src/paths.js +12 -0
- package/dist/types/functions/path_utils/src/src_dirs.js +25 -0
- package/dist/types/functions/print_utils/imports.d.ts +1 -1
- package/dist/types/functions/print_utils/imports.js +1 -0
- package/dist/types/functions/print_utils/index.d.ts +1 -1
- package/dist/types/functions/print_utils/index.js +1 -0
- package/dist/types/functions/print_utils/src/index.d.ts +1 -1
- package/dist/types/functions/print_utils/src/index.js +1 -0
- package/dist/types/functions/print_utils/src/print_utils.js +14 -0
- package/dist/types/functions/read_utils/imports.d.ts +1 -1
- package/dist/types/functions/read_utils/imports.js +1 -0
- package/dist/types/functions/read_utils/index.d.ts +1 -1
- package/dist/types/functions/read_utils/index.js +1 -0
- package/dist/types/functions/read_utils/src/index.d.ts +3 -3
- package/dist/types/functions/read_utils/src/index.js +3 -0
- package/dist/types/functions/read_utils/src/readJsonFile.browser.js +26 -0
- package/dist/types/functions/read_utils/src/readJsonFile.js +35 -0
- package/dist/types/functions/read_utils/src/readJsonFile.node.js +13 -0
- package/dist/types/functions/rndm_utils/imports.d.ts +1 -0
- package/dist/types/functions/rndm_utils/imports.js +1 -0
- package/dist/types/functions/rndm_utils/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/index.js +1 -0
- package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/src/index.js +1 -0
- package/dist/types/functions/rndm_utils/src/utils.js +12 -0
- package/dist/types/functions/safe_utils/imports.d.ts +1 -1
- package/dist/types/functions/safe_utils/imports.js +1 -0
- package/dist/types/functions/safe_utils/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/index.js +1 -0
- package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
- package/dist/types/functions/safe_utils/src/index.js +4 -0
- package/dist/types/functions/safe_utils/src/safe_document.js +12 -0
- package/dist/types/functions/safe_utils/src/safe_globals.js +14 -0
- package/dist/types/functions/safe_utils/src/safe_storage.js +50 -0
- package/dist/types/functions/safe_utils/src/safe_window.js +42 -0
- package/dist/types/functions/size_utils/index.d.ts +1 -1
- package/dist/types/functions/size_utils/index.js +1 -0
- package/dist/types/functions/size_utils/src/index.d.ts +1 -1
- package/dist/types/functions/size_utils/src/index.js +1 -0
- package/dist/types/functions/size_utils/src/sizeUtils.js +44 -0
- package/dist/types/functions/string_utils/index.d.ts +1 -1
- package/dist/types/functions/string_utils/index.js +1 -0
- package/dist/types/functions/string_utils/src/index.d.ts +2 -2
- package/dist/types/functions/string_utils/src/index.js +2 -0
- package/dist/types/functions/string_utils/src/quote_utils.js +17 -0
- package/dist/types/functions/string_utils/src/string_utils.js +186 -0
- package/dist/types/functions/type_utils/imports.d.ts +1 -0
- package/dist/types/functions/type_utils/imports.js +1 -0
- package/dist/types/functions/type_utils/index.d.ts +1 -1
- package/dist/types/functions/type_utils/index.js +1 -0
- package/dist/types/functions/type_utils/src/clean_utils.js +38 -0
- package/dist/types/functions/type_utils/src/ensure_utils.js +84 -0
- package/dist/types/functions/type_utils/src/imports.d.ts +1 -0
- package/dist/types/functions/type_utils/src/imports.js +1 -0
- package/dist/types/functions/type_utils/src/index.d.ts +6 -6
- package/dist/types/functions/type_utils/src/index.js +6 -0
- package/dist/types/functions/type_utils/src/json_utils.js +93 -0
- package/dist/types/functions/type_utils/src/list_utils.js +83 -0
- package/dist/types/functions/type_utils/src/mime_utils.js +314 -0
- package/dist/types/functions/type_utils/src/null_utils.js +21 -0
- package/dist/types/functions/type_utils/src/type_utils.js +39 -0
- package/dist/types/functions/variable_utils/imports.d.ts +1 -1
- package/dist/types/functions/variable_utils/imports.js +1 -0
- package/dist/types/functions/variable_utils/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/index.js +1 -0
- package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/src/index.js +1 -0
- package/dist/types/functions/variable_utils/src/variable_utils.js +34 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -0
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/index.js +2 -0
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/server/src/index.js +2 -0
- package/dist/types/server/src/mime_utils.js +314 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.js +1 -0
- package/dist/types/types/path-browserify.d.ts +3 -2
- package/dist/types/types/path-browserify.js +1 -0
- package/dist/types/types/src/Files.js +1 -0
- package/dist/types/types/src/index.d.ts +4 -4
- package/dist/types/types/src/index.js +4 -0
- package/dist/types/types/src/login.js +1 -0
- package/dist/types/types/src/logout.js +1 -0
- package/dist/types/types/src/utils.js +1 -0
- package/dist/types/utils/imports.d.ts +1 -1
- package/dist/types/utils/imports.js +1 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.js +1 -0
- package/dist/types/utils/src/Input.js +2 -0
- package/dist/types/utils/src/config.js +27 -0
- package/dist/types/utils/src/index.d.ts +2 -2
- package/dist/types/utils/src/index.js +2 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './token_client';
|
|
1
|
+
export * from './token_client.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
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,3 +1,3 @@
|
|
|
1
|
-
import { fetchIt as fetchCore } from './../../../functions';
|
|
1
|
+
import { fetchIt as fetchCore } from './../../../functions/index.js';
|
|
2
2
|
export declare function fetchIt<T = any>(endpoint: string, options?: Parameters<typeof fetchCore>[1]): Promise<T>;
|
|
3
3
|
export declare function getHeaders(headers?: Record<string, string>, method?: string | null, body?: unknown): Record<string, string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
export * from './fetch_auth';
|
|
1
|
+
export * from './fetch_auth.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './auth';
|
|
2
|
-
export * from './ui_utils';
|
|
1
|
+
export * from './auth/index.js';
|
|
2
|
+
export * from './ui_utils/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 +1,4 @@
|
|
|
1
|
-
export * from './button';
|
|
2
|
-
export * from './checkbox';
|
|
3
|
-
export * from './input';
|
|
4
|
-
export * from './spinner';
|
|
1
|
+
export * from './button.js';
|
|
2
|
+
export * from './checkbox.js';
|
|
3
|
+
export * from './input.js';
|
|
4
|
+
export * from './spinner.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
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,2 +1,2 @@
|
|
|
1
|
-
export type { JwtPayload } from './../../types';
|
|
2
|
-
export { callStorage } from './../safe_utils';
|
|
1
|
+
export type { JwtPayload } from './../../types/index.js';
|
|
2
|
+
export { callStorage } from './../safe_utils/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { callStorage } from './../safe_utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./jwt_core";
|
|
1
|
+
export * from "./jwt_core.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jwt_core";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helpers for dealing with the JWT stored in localStorage.
|
|
3
3
|
*/
|
|
4
|
-
import type { JwtPayload } from './../imports';
|
|
4
|
+
import type { JwtPayload } from './../imports.js';
|
|
5
5
|
/** True if token is structurally bad or its exp ≤ now. */
|
|
6
6
|
export declare function isTokenExpired(token: string): boolean;
|
|
7
7
|
export declare function decodeJwt(token: string): JwtPayload;
|
|
@@ -0,0 +1,25 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helpers for dealing with the JWT stored in localStorage.
|
|
3
3
|
*/
|
|
4
|
-
import type { JwtPayload } from './../imports';
|
|
4
|
+
import type { JwtPayload } from './../imports.js';
|
|
5
5
|
/** True if token is structurally bad or its exp ≤ now. */
|
|
6
6
|
export declare function isTokenExpired(token: string): boolean;
|
|
7
7
|
export declare function decodeJwt(token: string): JwtPayload;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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,3 +1,3 @@
|
|
|
1
|
-
export type { AppConfig } from './../../types';
|
|
2
|
-
export { getDocumentProp, safeGlobalProp } from './../safe_utils';
|
|
3
|
-
export { readJsonFile } from './../read_utils';
|
|
1
|
+
export type { AppConfig } from './../../types/index.js';
|
|
2
|
+
export { getDocumentProp, safeGlobalProp } from './../safe_utils/index.js';
|
|
3
|
+
export { readJsonFile } from './../read_utils/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1,83 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
export * from './config_utils';
|
|
1
|
+
export * from './config_utils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './config_utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -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/`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './constants';
|
|
1
|
+
export * from './constants.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constants';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { BASE_URL, DEV_PREFIX } from './../constants_utils/index';
|
|
1
|
+
export { BASE_URL, DEV_PREFIX } from './../constants_utils/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BASE_URL, DEV_PREFIX } from './../constants_utils/index';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './window_utils';
|
|
1
|
+
export * from './window_utils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './window_utils';
|