@econneq/gql-auth 1.2.8 → 1.2.10
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/api-factory.d.ts +2 -0
- package/dist/api-factory.d.ts.map +1 -1
- package/dist/api-factory.js +6 -4
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +11 -32
- package/dist/index.d.ts +38 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/query-server.d.ts +2 -0
- package/dist/query-server.d.ts.map +1 -1
- package/dist/query-server.js +10 -1
- package/dist/upload-gql.d.ts +3 -0
- package/dist/upload-gql.d.ts.map +1 -1
- package/dist/upload-gql.js +6 -17
- package/dist/utilsGeneral.d.ts +1 -1
- package/dist/utilsGeneral.d.ts.map +1 -1
- package/package.json +14 -6
- package/dist/authServer.d.ts +0 -5
- package/dist/authServer.d.ts.map +0 -1
- package/dist/authServer.js +0 -40
- package/dist/functions.d.ts +0 -6
- package/dist/functions.d.ts.map +0 -1
- package/dist/functions.js +0 -38
- package/dist/utils.d.ts +0 -24
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -257
package/dist/api-factory.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-factory.d.ts","sourceRoot":"","sources":["../src/api-factory.ts"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,UAAU,EAAE,GAAG,EAAE,CAAC;K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M,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,SAAS,aAAa,iBA0DtD,CAAC"}
|
package/dist/api-factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { uploadGraphQLMutation } from "./upload-gql.js";
|
|
2
|
+
import { removeEmptyFields } from "./utilsGeneral.js";
|
|
3
3
|
export const ApiFactory = async (options) => {
|
|
4
4
|
const { newData, editData, mutationName, modelName, successField = "title", query, router, params, reload = true, redirect, redirectPath, returnResponseField = false, returnResponseObject = false, getFileMap, token, config, onAlert } = options;
|
|
5
5
|
const items = Array.isArray(newData || editData) ? (newData || editData) : [(newData || editData)];
|
|
@@ -8,14 +8,16 @@ export const ApiFactory = async (options) => {
|
|
|
8
8
|
let responseFieldData = null;
|
|
9
9
|
for (const res of items) {
|
|
10
10
|
try {
|
|
11
|
+
console.log("launching e-conneq/auth-gql ......");
|
|
11
12
|
const response = await uploadGraphQLMutation({
|
|
12
13
|
query: query.loc?.source.body || "",
|
|
13
14
|
variables: removeEmptyFields(res),
|
|
14
15
|
fileMap: getFileMap ? getFileMap(res) : {},
|
|
15
|
-
params,
|
|
16
|
+
params, // Pass domain params for multi-tenancy
|
|
16
17
|
token,
|
|
17
|
-
config,
|
|
18
|
+
config, // Pass global URLs and Subdomain list
|
|
18
19
|
});
|
|
20
|
+
console.log("response e-conneq/auth-gql ......");
|
|
19
21
|
const result = response?.data?.[mutationName]?.[modelName];
|
|
20
22
|
if (response?.data?.[mutationName]) {
|
|
21
23
|
successMessages.push(result?.[successField] || "operation successful ✅");
|
package/dist/client.d.ts
CHANGED
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA2B,MAAM,gBAAgB,CAAC;AAGvE,wBAA8B,eAAe,CAC3C,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EACjD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,CAAC,EAAE;IACP,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC3E,MAAM,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA2B,MAAM,gBAAgB,CAAC;AAGvE,wBAA8B,eAAe,CAC3C,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EACjD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,CAAC,EAAE;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC3E,MAAM,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAgD9B"}
|
package/dist/client.js
CHANGED
|
@@ -5,41 +5,20 @@ export default async function getApolloClient(options, domain, config) {
|
|
|
5
5
|
if (!config)
|
|
6
6
|
throw new Error("Configuration is required for getApolloClient");
|
|
7
7
|
const isServer = typeof window === "undefined";
|
|
8
|
-
const { Subdomains } = config;
|
|
9
|
-
//
|
|
10
|
-
const urlDomain = process.env.NEXT_PUBLIC_DOMAIN_URL || process.env.DOMAIN_URL; // e.g e-conneq.com
|
|
11
|
-
const protocol = process.env.NEXT_PUBLIC_PROTOCOL || process.env.PROTOCOL; // e.g https:// or e.g http://
|
|
12
|
-
const urlBackEndInt = process.env.NEXT_PUBLIC_BACKEND_URL_INT || process.env.BACKEND_URL_INT; // e.g api:8000 (docker) or 127.0.0.1:8100 (VPS host) or localhost:8001 (local host)
|
|
13
|
-
const urlBackEndExt = process.env.NEXT_PUBLIC_BACKEND_URL_EXT || process.env.BACKEND_URL_EXT; // e.g https://admin.e-conneq.com
|
|
14
|
-
if (!urlDomain)
|
|
15
|
-
throw new Error("Env (DOMAIN_URL) is required");
|
|
16
|
-
if (!protocol)
|
|
17
|
-
throw new Error("Env (PROTOCOL) is required");
|
|
18
|
-
if (!urlBackEndInt)
|
|
19
|
-
throw new Error("Env (BACKEND_URL_INT) is required");
|
|
20
|
-
if (!urlBackEndExt)
|
|
21
|
-
throw new Error("Env (BACKEND_URL_EXT) is required");
|
|
8
|
+
const { protocol, RootApi, Subdomains, apiKey } = config;
|
|
9
|
+
// 1. Find Tenant Data
|
|
22
10
|
const tenant = domain
|
|
23
11
|
? Subdomains.find((s) => s.subdomain.toLowerCase() === domain.toLowerCase())
|
|
24
12
|
: null;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const sourceHost = `${protocol}${tenant?.subdomain || "public"}.${urlDomain}`;
|
|
28
|
-
if (isServer) {
|
|
29
|
-
destUrl = `http://${urlBackEndInt}`;
|
|
30
|
-
uri = `${destUrl}/graphql/`;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
uri = "/api/graphql";
|
|
34
|
-
destUrl = `${protocol}${urlBackEndExt}`;
|
|
35
|
-
}
|
|
36
|
-
console.log("g-auth uri ==============", uri);
|
|
37
|
-
console.log("g-auth sourceHost =======", sourceHost);
|
|
38
|
-
console.log("g-auth destinationHost ==========", destUrl);
|
|
13
|
+
const baseUrl = `${protocol + RootApi}`;
|
|
14
|
+
const uri = `${baseUrl}/graphql/`;
|
|
39
15
|
const csrfToken = options?.csrfToken || (!isServer ? Cookies.get("csrftoken") : "");
|
|
16
|
+
const dynamicHost = domain
|
|
17
|
+
? `${domain}.${RootApi}`
|
|
18
|
+
: RootApi;
|
|
40
19
|
const headers = {
|
|
41
20
|
'Content-Type': 'application/json',
|
|
42
|
-
|
|
21
|
+
'X-API-KEY': apiKey,
|
|
43
22
|
...(options?.cookie && { 'Cookie': options.cookie }),
|
|
44
23
|
...(csrfToken && { 'X-CSRFToken': csrfToken }),
|
|
45
24
|
...(tenant && {
|
|
@@ -47,13 +26,13 @@ export default async function getApolloClient(options, domain, config) {
|
|
|
47
26
|
'X-Process-ID': tenant?.processId || "",
|
|
48
27
|
'X-Widget-ID': tenant?.widgetID || "",
|
|
49
28
|
}),
|
|
50
|
-
'Referer':
|
|
51
|
-
'Host': isServer ?
|
|
29
|
+
'Referer': baseUrl,
|
|
30
|
+
'Host': isServer ? dynamicHost : window.location.host,
|
|
52
31
|
};
|
|
53
32
|
return new ApolloClient({
|
|
54
33
|
link: new HttpLink({
|
|
55
34
|
uri,
|
|
56
|
-
fetch,
|
|
35
|
+
fetch, // Next.js polyfills fetch on server automatically
|
|
57
36
|
headers,
|
|
58
37
|
}),
|
|
59
38
|
cache: new InMemoryCache(),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
1
2
|
import { queryServerGraphQL } from './query-server.js';
|
|
2
3
|
import { ApiFactory } from './api-factory.js';
|
|
3
4
|
import { uploadGraphQLMutation } from './upload-gql.js';
|
|
4
5
|
export { queryServerGraphQL, ApiFactory, uploadGraphQLMutation };
|
|
5
6
|
export type ConfigType = {
|
|
7
|
+
protocol: string;
|
|
8
|
+
RootApi: string;
|
|
9
|
+
NoDomainRootApi: string;
|
|
6
10
|
Subdomains: SubdomainItem[];
|
|
11
|
+
apiKey: string;
|
|
7
12
|
fonts: string[];
|
|
8
13
|
};
|
|
9
14
|
export type SubdomainItem = {
|
|
@@ -16,6 +21,10 @@ export type ApolloOptions = {
|
|
|
16
21
|
csrfToken?: string;
|
|
17
22
|
cookie?: string;
|
|
18
23
|
};
|
|
24
|
+
export type SelectOptions = string | {
|
|
25
|
+
label: string;
|
|
26
|
+
value: string | number;
|
|
27
|
+
};
|
|
19
28
|
export interface InterLoginData {
|
|
20
29
|
username: string;
|
|
21
30
|
password: string;
|
|
@@ -38,14 +47,39 @@ export interface JwtPayload {
|
|
|
38
47
|
is_active?: boolean;
|
|
39
48
|
is_hod?: boolean;
|
|
40
49
|
role?: string;
|
|
41
|
-
|
|
50
|
+
dept?: string[] | any;
|
|
42
51
|
page?: string[] | any;
|
|
43
52
|
school?: number[] | any;
|
|
44
53
|
domain?: number[] | any;
|
|
45
|
-
permissions?: string[];
|
|
46
54
|
language?: string[];
|
|
47
55
|
last_login?: any;
|
|
48
56
|
}
|
|
49
|
-
export
|
|
50
|
-
|
|
57
|
+
export interface InterField {
|
|
58
|
+
name: string;
|
|
59
|
+
label: string;
|
|
60
|
+
inputType: 'text' | "textarea" | 'number' | 'float' | 'search-select' | 'select' | 'file' | 'date' | 'password';
|
|
61
|
+
type: 'text' | 'textarea' | 'number' | 'float' | 'email' | 'date' | 'file' | 'password';
|
|
62
|
+
required?: boolean;
|
|
63
|
+
min?: number;
|
|
64
|
+
max?: number;
|
|
65
|
+
message?: string;
|
|
66
|
+
options?: {
|
|
67
|
+
value: string | number;
|
|
68
|
+
label: string;
|
|
69
|
+
}[];
|
|
70
|
+
show?: boolean;
|
|
71
|
+
sort?: boolean;
|
|
72
|
+
placeholder?: string;
|
|
73
|
+
acceptedFileType?: string;
|
|
74
|
+
icon?: ReactNode;
|
|
75
|
+
labelIcon?: ReactNode;
|
|
76
|
+
}
|
|
77
|
+
export interface InterFieldList {
|
|
78
|
+
rowId: number | string;
|
|
79
|
+
desktopCols: 1 | 2 | 3 | 4;
|
|
80
|
+
mobileCols: 1 | 2;
|
|
81
|
+
fields: InterField[];
|
|
82
|
+
}
|
|
83
|
+
export { capitalizeEachWord, errorLog, getToken, getUser, logout, getStoredFont, getTimeAgo, getLanguage, getTemplate, decodeUrlID, removeEmptyFields, Alert, validateFormFields, lastYears, formatText, } from './utilsGeneral.js';
|
|
84
|
+
export { getProfile, getClass, getClassName, getLevel, getAcademicYear, getAcademicYearStudent } from './utilsSchool.js';
|
|
51
85
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,qBAAqB,EAAE,CAAC;AAIjE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IAC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,EAAE,OAAO,EAAE,MAAM,EACvD,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EACnD,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,UAAU,GACjD,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,UAAU,EAAE,QAAQ,EAAE,YAAY,EAClC,QAAQ,EAAE,eAAe,EAAE,sBAAsB,EAClD,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
// 1. Export the Core Functions
|
|
1
2
|
import { queryServerGraphQL } from './query-server.js';
|
|
2
3
|
import { ApiFactory } from './api-factory.js';
|
|
3
4
|
import { uploadGraphQLMutation } from './upload-gql.js';
|
|
4
5
|
export { queryServerGraphQL, ApiFactory, uploadGraphQLMutation };
|
|
5
|
-
|
|
6
|
-
export {
|
|
6
|
+
// 3. Export Helper Utilities (Optional)
|
|
7
|
+
export { capitalizeEachWord, errorLog, getToken, getUser, logout, getStoredFont, getTimeAgo, getLanguage, getTemplate, decodeUrlID, removeEmptyFields, Alert, validateFormFields, lastYears, formatText, } from './utilsGeneral.js';
|
|
8
|
+
export { getProfile, getClass, getClassName, getLevel, getAcademicYear, getAcademicYearStudent } from './utilsSchool.js';
|
package/dist/query-server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-server.d.ts","sourceRoot":"","sources":["../src/query-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-server.d.ts","sourceRoot":"","sources":["../src/query-server.ts"],"names":[],"mappings":"AAMA,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,GAAG,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,EAChD,KAAK,EACL,SAAc,EACd,MAAM,EACN,MAAM,GACP,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CA8BrC"}
|
package/dist/query-server.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
// src/server-query.ts
|
|
2
|
+
/// <reference types="next" />
|
|
2
3
|
'use server';
|
|
3
4
|
import { cookies } from 'next/headers';
|
|
4
|
-
import getApolloClient from './client';
|
|
5
|
+
import getApolloClient from './client.js';
|
|
5
6
|
export async function queryServerGraphQL({ query, variables = {}, domain, config, }) {
|
|
6
7
|
try {
|
|
8
|
+
// 1. Get server-side cookies
|
|
7
9
|
const cookieStore = await cookies();
|
|
8
10
|
const cookieString = cookieStore.toString();
|
|
11
|
+
// 2. Call getApolloClient with the correct 3 arguments:
|
|
12
|
+
// Arg 1: options (cookies)
|
|
13
|
+
// Arg 2: domain (subdomain string)
|
|
14
|
+
// Arg 3: config (URLs and Subdomain array)
|
|
9
15
|
const client = await getApolloClient({ cookie: cookieString }, domain, config);
|
|
10
16
|
if (!client)
|
|
11
17
|
return null;
|
|
@@ -14,9 +20,12 @@ export async function queryServerGraphQL({ query, variables = {}, domain, config
|
|
|
14
20
|
variables,
|
|
15
21
|
fetchPolicy: 'no-cache',
|
|
16
22
|
});
|
|
23
|
+
console.log("getting @e-conneq/gql-auth ........");
|
|
17
24
|
return result?.data;
|
|
18
25
|
}
|
|
19
26
|
catch (err) {
|
|
27
|
+
// On the server, we console.error instead of using Swal
|
|
28
|
+
console.error("GraphQL Server Error:", err);
|
|
20
29
|
return null;
|
|
21
30
|
}
|
|
22
31
|
}
|
package/dist/upload-gql.d.ts
CHANGED
|
@@ -5,12 +5,15 @@ type UploadGraphQLArgs = {
|
|
|
5
5
|
token?: string;
|
|
6
6
|
params: any;
|
|
7
7
|
config: {
|
|
8
|
+
protocol: string;
|
|
9
|
+
RootApi: string;
|
|
8
10
|
Subdomains: {
|
|
9
11
|
subdomain: string;
|
|
10
12
|
id: string | number;
|
|
11
13
|
processId: string;
|
|
12
14
|
widgetID: string;
|
|
13
15
|
}[];
|
|
16
|
+
apiKey?: string;
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
export declare function uploadGraphQLMutation({ query, variables, fileMap, token, params, config }: UploadGraphQLArgs): Promise<any>;
|
package/dist/upload-gql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-gql.d.ts","sourceRoot":"","sources":["../src/upload-gql.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE;QACN,UAAU,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"upload-gql.d.ts","sourceRoot":"","sources":["../src/upload-gql.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,EAC1C,KAAK,EACL,SAAS,EACT,OAAO,EACP,KAAK,EACL,MAAM,EACN,MAAM,EACP,EAAE,iBAAiB,gBA0DnB"}
|
package/dist/upload-gql.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
export async function uploadGraphQLMutation({ query, variables, fileMap, token, params, config }) {
|
|
2
|
-
const
|
|
3
|
-
const { Subdomains } = config;
|
|
4
|
-
const BACKEND_URL_INT = process.env.BACKEND_URL_INT;
|
|
5
|
-
const API_KEY = process.env.API_KEY || "";
|
|
6
|
-
let API_LINK;
|
|
7
|
-
if (isServer) {
|
|
8
|
-
API_LINK = `${BACKEND_URL_INT}/graphql/`;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
API_LINK = `/api/graphql`;
|
|
12
|
-
}
|
|
2
|
+
const { protocol, RootApi, Subdomains, apiKey } = config;
|
|
13
3
|
const formData = new FormData();
|
|
14
4
|
const updatedVariables = { ...variables };
|
|
15
5
|
// 1. Prepare GraphQL Multipart Request (Spec compliant)
|
|
@@ -30,26 +20,25 @@ export async function uploadGraphQLMutation({ query, variables, fileMap, token,
|
|
|
30
20
|
// 2. Multi-tenant URL and Data Logic
|
|
31
21
|
const requestedDomain = params?.domain || "";
|
|
32
22
|
const tenantData = Subdomains.find((d) => d.subdomain.toLowerCase() === requestedDomain.toLowerCase());
|
|
23
|
+
// Determine URL: Use subdomain api if tenant exists, otherwise use root API
|
|
24
|
+
const API_LINK = `${protocol + RootApi}/graphql/`;
|
|
33
25
|
// 3. Construct Headers
|
|
34
26
|
const headers = {
|
|
35
27
|
...(token ? { "Authorization": `Bearer ${token}` } : {}),
|
|
28
|
+
...(apiKey ? { "X-API-KEY": apiKey } : {}),
|
|
36
29
|
};
|
|
37
|
-
if (isServer) {
|
|
38
|
-
headers["Host"] = BACKEND_URL_INT || "";
|
|
39
|
-
}
|
|
40
30
|
// Inject specific tenant metadata into headers for Django to read
|
|
41
31
|
if (tenantData) {
|
|
42
32
|
headers["X-Tenant-ID"] = String(tenantData.subdomain);
|
|
43
33
|
headers["X-Process-ID"] = tenantData.processId || "";
|
|
44
34
|
headers["X-Widget-ID"] = tenantData.widgetID || "";
|
|
45
|
-
headers["X-API-KEY"] = API_KEY || "";
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
throw ("No Tenant Found ===================>");
|
|
36
|
+
// 4. Execute Fetch
|
|
49
37
|
const res = await fetch(API_LINK, {
|
|
50
38
|
method: "POST",
|
|
51
39
|
headers,
|
|
52
40
|
body: formData,
|
|
41
|
+
// credentials: "include" is important if you use cookies alongside headers
|
|
53
42
|
credentials: "include",
|
|
54
43
|
});
|
|
55
44
|
return await res.json();
|
package/dist/utilsGeneral.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InterFieldList, JwtPayload } from ".";
|
|
1
|
+
import { InterFieldList, JwtPayload } from "./index.js";
|
|
2
2
|
export declare const capitalizeEachWord: (str: string) => string;
|
|
3
3
|
export declare const errorLog: (err: any, show?: boolean) => string;
|
|
4
4
|
export declare const logout: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsGeneral.d.ts","sourceRoot":"","sources":["../src/utilsGeneral.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utilsGeneral.d.ts","sourceRoot":"","sources":["../src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
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"prepublishOnly": "npm run build"
|
|
11
|
-
},
|
|
12
8
|
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
11
|
},
|
|
15
12
|
"exports": {
|
|
16
13
|
".": {
|
|
@@ -37,5 +34,16 @@
|
|
|
37
34
|
"dependencies": {
|
|
38
35
|
"js-cookie": "^3.0.0",
|
|
39
36
|
"jwt-decode": "^4.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^25.5.0",
|
|
40
|
+
"@types/react": "^19.2.14",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
42
|
+
"next": "^16.2.2",
|
|
43
|
+
"typescript": "^6.0.2"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc",
|
|
47
|
+
"dev": "tsc --watch"
|
|
40
48
|
}
|
|
41
49
|
}
|
package/dist/authServer.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from ".";
|
|
2
|
-
export declare const getServerToken: () => Promise<string | null>;
|
|
3
|
-
export declare const getServerUser: () => Promise<JwtPayload | null>;
|
|
4
|
-
export declare const getPermissions: (list: string[], access: number, action?: string) => boolean;
|
|
5
|
-
//# sourceMappingURL=authServer.d.ts.map
|
package/dist/authServer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authServer.d.ts","sourceRoot":"","sources":["../src/authServer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAE/B,eAAO,MAAM,cAAc,8BAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,kCAUzB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,EAAE,QAAQ,MAAM,EAAE,SAAS,MAAM,YAqB7E,CAAC"}
|
package/dist/authServer.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// utils/authServer.ts
|
|
2
|
-
import { cookies } from 'next/headers';
|
|
3
|
-
import { jwtDecode } from "jwt-decode";
|
|
4
|
-
export const getServerToken = async () => {
|
|
5
|
-
const cookieStore = await cookies();
|
|
6
|
-
return cookieStore.get("token")?.value || null;
|
|
7
|
-
};
|
|
8
|
-
export const getServerUser = async () => {
|
|
9
|
-
const token = await getServerToken();
|
|
10
|
-
if (!token)
|
|
11
|
-
return null;
|
|
12
|
-
try {
|
|
13
|
-
const user = jwtDecode(token);
|
|
14
|
-
return user;
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export const getPermissions = (list, access, action) => {
|
|
21
|
-
if (!list || list.length < 1)
|
|
22
|
-
return false;
|
|
23
|
-
try {
|
|
24
|
-
return list.some(entry => {
|
|
25
|
-
// If only num is provided, check if entry starts with that number followed by non-digits
|
|
26
|
-
if (access && !action) {
|
|
27
|
-
const regex = new RegExp(`^${access}(?!\\d)`);
|
|
28
|
-
return regex.test(entry);
|
|
29
|
-
}
|
|
30
|
-
// If both are provided, check for the exact combination
|
|
31
|
-
if (access && action) {
|
|
32
|
-
return entry === `${access}${action}`;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
};
|
package/dist/functions.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from ".";
|
|
2
|
-
export declare const logout: () => void;
|
|
3
|
-
export declare const getToken: () => string | null;
|
|
4
|
-
export declare const getUser: () => JwtPayload | null;
|
|
5
|
-
export declare const removeEmptyFields: (obj: any) => any;
|
|
6
|
-
//# sourceMappingURL=functions.d.ts.map
|
package/dist/functions.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAG/B,eAAO,MAAM,MAAM,YAclB,CAAC;AAEF,eAAO,MAAM,QAAQ,qBAKpB,CAAC;AAEF,eAAO,MAAM,OAAO,yBAInB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,KAAK,GAAG,QAUzC,CAAC"}
|
package/dist/functions.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Cookies from "js-cookie";
|
|
2
|
-
import { jwtDecode } from "jwt-decode";
|
|
3
|
-
export const logout = () => {
|
|
4
|
-
// 1. Clear Local Storage
|
|
5
|
-
localStorage.removeItem("token");
|
|
6
|
-
const tokenDeleteString = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;";
|
|
7
|
-
document.cookie = tokenDeleteString;
|
|
8
|
-
// 3. Fallback: Clear ALL cookies (your original loop)
|
|
9
|
-
const cookies = document.cookie.split(";");
|
|
10
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
11
|
-
const cookie = cookies[i];
|
|
12
|
-
const eqPos = cookie.indexOf("=");
|
|
13
|
-
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();
|
|
14
|
-
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;`;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export const getToken = () => {
|
|
18
|
-
if (typeof window === "undefined") {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
return Cookies.get("token") || localStorage.getItem("token");
|
|
22
|
-
};
|
|
23
|
-
export const getUser = () => {
|
|
24
|
-
const token = getToken();
|
|
25
|
-
const user = token ? jwtDecode(token) : null;
|
|
26
|
-
return user;
|
|
27
|
-
};
|
|
28
|
-
export const removeEmptyFields = (obj) => {
|
|
29
|
-
const newObj = {};
|
|
30
|
-
for (const key in obj) {
|
|
31
|
-
// Keep File objects and non-empty values
|
|
32
|
-
if (obj[key] instanceof File ||
|
|
33
|
-
(obj[key] !== null && obj[key] !== undefined && obj[key] !== '')) {
|
|
34
|
-
newObj[key] = obj[key];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return newObj;
|
|
38
|
-
};
|
package/dist/utils.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { InterFieldList, JwtPayload } from ".";
|
|
2
|
-
export declare const capitalizeEachWord: (str: string) => string;
|
|
3
|
-
export declare const errorLog: (err: any, show?: boolean) => string;
|
|
4
|
-
export declare const getToken: () => string | null;
|
|
5
|
-
export declare const getUser: () => JwtPayload | null;
|
|
6
|
-
export declare const getStoredFont: (FONTS: string[]) => string;
|
|
7
|
-
export declare const getTimeAgo: (dateStr: string, type: "past" | "future") => string;
|
|
8
|
-
export declare const getLanguage: () => "en" | "fr";
|
|
9
|
-
export declare const getTemplate: () => number;
|
|
10
|
-
export declare const decodeUrlID: (urlID: string) => string;
|
|
11
|
-
export declare function getAcademicYear(): string;
|
|
12
|
-
export declare const removeEmptyFields: (obj: any) => any;
|
|
13
|
-
export declare const Alert: ({ title, duration, status }: {
|
|
14
|
-
title: string;
|
|
15
|
-
duration: 1000 | 1500 | 2000 | 3000 | 4000 | 5000;
|
|
16
|
-
status?: boolean;
|
|
17
|
-
}) => void;
|
|
18
|
-
export declare const validateFormFields: (formData: any, currentStepFields: InterFieldList[]) => Record<string, string>;
|
|
19
|
-
export declare const lastYears: (number: number) => {
|
|
20
|
-
value: string;
|
|
21
|
-
label: string;
|
|
22
|
-
}[];
|
|
23
|
-
export declare const formatText: (text: string) => string;
|
|
24
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELET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etalert2";
|
|
2
|
-
import Cookies from "js-cookie";
|
|
3
|
-
import { jwtDecode } from "jwt-decode";
|
|
4
|
-
export const capitalizeEachWord = (str) => {
|
|
5
|
-
if (!str)
|
|
6
|
-
return ''; // Handle empty or null strings
|
|
7
|
-
return str
|
|
8
|
-
.split(' ')
|
|
9
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
10
|
-
.join(' ');
|
|
11
|
-
};
|
|
12
|
-
export const errorLog = (err, show) => {
|
|
13
|
-
let mes = "An unknown error occurred";
|
|
14
|
-
if (typeof err === "string")
|
|
15
|
-
mes = err;
|
|
16
|
-
else if (err?.graphQLErrors?.length > 0)
|
|
17
|
-
mes = err.graphQLErrors.map((e) => e.message).join('\n');
|
|
18
|
-
else if (err?.networkError) {
|
|
19
|
-
const netErr = err.networkError;
|
|
20
|
-
if ("result" in netErr && netErr.result?.errors?.length > 0)
|
|
21
|
-
mes = netErr.result.errors.map((e) => e.message).join('\n');
|
|
22
|
-
else if (netErr.message)
|
|
23
|
-
mes = netErr.message;
|
|
24
|
-
}
|
|
25
|
-
else if (err?.extraInfo)
|
|
26
|
-
mes = String(err.extraInfo);
|
|
27
|
-
else if (err?.message)
|
|
28
|
-
mes = err.message;
|
|
29
|
-
if (show) {
|
|
30
|
-
Swal.fire({
|
|
31
|
-
title: mes,
|
|
32
|
-
icon: 'error',
|
|
33
|
-
timer: 3000,
|
|
34
|
-
timerProgressBar: true,
|
|
35
|
-
showConfirmButton: false,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return mes;
|
|
39
|
-
};
|
|
40
|
-
const currentYear = new Date().getFullYear();
|
|
41
|
-
export const getToken = () => {
|
|
42
|
-
if (typeof window === "undefined") {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return Cookies.get("token") || localStorage.getItem("token");
|
|
46
|
-
};
|
|
47
|
-
export const getUser = () => {
|
|
48
|
-
// const token = typeof window !== 'undefined' ? localStorage.getItem("token") : null;
|
|
49
|
-
const token = getToken();
|
|
50
|
-
const user = token ? jwtDecode(token) : null;
|
|
51
|
-
return user;
|
|
52
|
-
};
|
|
53
|
-
export const getStoredFont = (FONTS) => {
|
|
54
|
-
if (typeof window === "undefined")
|
|
55
|
-
return FONTS[0]; // Default for SSR
|
|
56
|
-
const up = localStorage.getItem("user-pref");
|
|
57
|
-
if (!up)
|
|
58
|
-
return FONTS[5]; // Default to Ubuntu (6th index)
|
|
59
|
-
const fontIndex = parseInt(up[1]) - 1;
|
|
60
|
-
return FONTS[fontIndex] || FONTS[5];
|
|
61
|
-
};
|
|
62
|
-
export const getTimeAgo = (dateStr, type) => {
|
|
63
|
-
if (!dateStr)
|
|
64
|
-
return "";
|
|
65
|
-
const now = new Date();
|
|
66
|
-
const item = new Date(dateStr);
|
|
67
|
-
let diffMs = 0;
|
|
68
|
-
if (type === "past")
|
|
69
|
-
diffMs = now.getTime() - item.getTime();
|
|
70
|
-
if (type === "future")
|
|
71
|
-
diffMs = item.getTime() - now.getTime();
|
|
72
|
-
// Handle invalid date ranges
|
|
73
|
-
if (diffMs < 0) {
|
|
74
|
-
return type === "past" ? "just now" : "Closed";
|
|
75
|
-
}
|
|
76
|
-
const seconds = Math.floor(diffMs / 1000);
|
|
77
|
-
const minutes = Math.floor(seconds / 60);
|
|
78
|
-
const hours = Math.floor(minutes / 60);
|
|
79
|
-
const days = Math.floor(hours / 24);
|
|
80
|
-
const weeks = Math.floor(days / 7);
|
|
81
|
-
const months = Math.floor(days / 30.44); // Use average month length
|
|
82
|
-
const years = Math.floor(days / 365.25); // Account for leap years
|
|
83
|
-
const suffix = type === "past" ? "ago" : "left";
|
|
84
|
-
// 1. Logic for Past Dates (e.g., Posted 2 days ago)
|
|
85
|
-
if (type === "past") {
|
|
86
|
-
if (days === 0)
|
|
87
|
-
return "Today";
|
|
88
|
-
if (days === 1)
|
|
89
|
-
return "Yesterday";
|
|
90
|
-
if (days < 7)
|
|
91
|
-
return `${days} days ago`;
|
|
92
|
-
if (weeks < 5)
|
|
93
|
-
return `${weeks} week${weeks > 1 ? "s" : ""} ago`;
|
|
94
|
-
if (months < 12)
|
|
95
|
-
return `${months} month${months > 1 ? "s" : ""} ago`;
|
|
96
|
-
return `${years} year${years > 1 ? "s" : ""} ago`;
|
|
97
|
-
}
|
|
98
|
-
// 2. Logic for Future Dates (e.g., 5 days left)
|
|
99
|
-
if (days === 0)
|
|
100
|
-
return "Ends today";
|
|
101
|
-
if (days === 1)
|
|
102
|
-
return "1 day left";
|
|
103
|
-
if (days < 7)
|
|
104
|
-
return `${days} days left`;
|
|
105
|
-
if (weeks < 5)
|
|
106
|
-
return `${weeks} week${weeks > 1 ? "s" : ""} left`;
|
|
107
|
-
if (months < 12)
|
|
108
|
-
return `${months} month${months > 1 ? "s" : ""} left`;
|
|
109
|
-
return `${years} year${years > 1 ? "s" : ""} left`;
|
|
110
|
-
};
|
|
111
|
-
export const getLanguage = () => {
|
|
112
|
-
if (typeof window === "undefined")
|
|
113
|
-
return "en";
|
|
114
|
-
const up = localStorage.getItem("user-pref");
|
|
115
|
-
if (!up)
|
|
116
|
-
return "en";
|
|
117
|
-
const langNumber = parseInt(up[0]);
|
|
118
|
-
return langNumber === 1 ? "en" : "fr";
|
|
119
|
-
};
|
|
120
|
-
export const getTemplate = () => {
|
|
121
|
-
if (typeof window === "undefined")
|
|
122
|
-
return 1;
|
|
123
|
-
const up = localStorage.getItem("user-pref");
|
|
124
|
-
if (!up)
|
|
125
|
-
return 1;
|
|
126
|
-
return parseInt(up[2]);
|
|
127
|
-
};
|
|
128
|
-
export const decodeUrlID = (urlID) => {
|
|
129
|
-
const base64DecodedString = decodeURIComponent(urlID); // Decodes %3D%3D to ==
|
|
130
|
-
const id = Buffer.from(base64DecodedString, 'base64').toString('utf-8'); // Decoding from base64
|
|
131
|
-
return id.split(":")[1];
|
|
132
|
-
};
|
|
133
|
-
export function getAcademicYear() {
|
|
134
|
-
const today = new Date();
|
|
135
|
-
const year = today.getFullYear();
|
|
136
|
-
const month = today.getMonth(); // 0 = January, 7 = August
|
|
137
|
-
if (month < 7) {
|
|
138
|
-
return `${year - 1}/${year}`;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
return `${year}/${year + 1}`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export const removeEmptyFields = (obj) => {
|
|
145
|
-
const newObj = {};
|
|
146
|
-
for (const key in obj) {
|
|
147
|
-
// Keep File objects and non-empty values
|
|
148
|
-
if (obj[key] instanceof File ||
|
|
149
|
-
(obj[key] !== null && obj[key] !== undefined && obj[key] !== '')) {
|
|
150
|
-
newObj[key] = obj[key];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return newObj;
|
|
154
|
-
};
|
|
155
|
-
export const Alert = ({ title, duration, status = true }) => {
|
|
156
|
-
Swal.fire({
|
|
157
|
-
title: capitalizeEachWord(title),
|
|
158
|
-
timer: duration,
|
|
159
|
-
timerProgressBar: true,
|
|
160
|
-
showConfirmButton: false,
|
|
161
|
-
icon: status ? 'success' : 'error',
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
export const validateFormFields = (formData, currentStepFields) => {
|
|
165
|
-
const newErrors = {};
|
|
166
|
-
// 1. Flatten the fields from all rows in the step
|
|
167
|
-
const fieldsToValidate = currentStepFields.flatMap(row => row.fields);
|
|
168
|
-
fieldsToValidate.forEach((field) => {
|
|
169
|
-
// Skip validation if the field is hidden
|
|
170
|
-
if (field.show === false)
|
|
171
|
-
return;
|
|
172
|
-
// 2. Get the value from formData
|
|
173
|
-
const value = formData[field.name];
|
|
174
|
-
// 3. Check Required
|
|
175
|
-
if (field.required && (!value || value.toString().trim() === "")) {
|
|
176
|
-
newErrors[field.name] = `${capitalizeEachWord(field.label)} is required`;
|
|
177
|
-
// return;
|
|
178
|
-
}
|
|
179
|
-
// 4. Check Type (Email)
|
|
180
|
-
if (field.type === 'email' && value) {
|
|
181
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
182
|
-
if (!emailRegex.test(value)) {
|
|
183
|
-
newErrors[field.name] = "Invalid email format";
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// 5. Check Numbers (Min/Max)
|
|
187
|
-
if (field.type === 'number' && value) {
|
|
188
|
-
const numValue = Number(value);
|
|
189
|
-
if (field.min !== undefined && numValue < field.min) {
|
|
190
|
-
newErrors[field.name] = `Minimum value is ${field.min}`;
|
|
191
|
-
}
|
|
192
|
-
if (field.max !== undefined && numValue > field.max) {
|
|
193
|
-
newErrors[field.name] = `Maximum value is ${field.max}`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// 6. Check Length (Strings)
|
|
197
|
-
if (field.type === 'text' && value) {
|
|
198
|
-
if (field.min !== undefined && value.length < field.min) {
|
|
199
|
-
newErrors[field.name] = `Too short (min ${field.min} chars)`;
|
|
200
|
-
}
|
|
201
|
-
if (field.max !== undefined && value.length > field.max) {
|
|
202
|
-
newErrors[field.name] = `Too long (min ${field.max} chars)`;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
return newErrors;
|
|
207
|
-
};
|
|
208
|
-
export const lastYears = (number) => {
|
|
209
|
-
return Array.from({ length: number }, (_, i) => ({
|
|
210
|
-
value: (currentYear - i).toString(),
|
|
211
|
-
label: (currentYear - i).toString()
|
|
212
|
-
})).sort((a, b) => Number(b.value) - Number(a.value));
|
|
213
|
-
};
|
|
214
|
-
export const formatText = (text) => {
|
|
215
|
-
return text;
|
|
216
|
-
if (!text || typeof text !== "string")
|
|
217
|
-
return "";
|
|
218
|
-
return text
|
|
219
|
-
// Ensure space after "." if it's not part of abbreviation/number
|
|
220
|
-
.replace(/\.(?!\s|$|[a-zA-Z0-9])/g, ". ")
|
|
221
|
-
// Split sentences by ". " but preserve delimiter
|
|
222
|
-
.split(/(\. )/g)
|
|
223
|
-
.map((segment) => {
|
|
224
|
-
if (segment === ". ")
|
|
225
|
-
return segment; // keep delimiter
|
|
226
|
-
return segment
|
|
227
|
-
.split(" ")
|
|
228
|
-
.map((word, i) => {
|
|
229
|
-
if (word === "")
|
|
230
|
-
return word;
|
|
231
|
-
// Preserve existing ALL CAPS words
|
|
232
|
-
if (word.length > 1 && /^[A-Z]+$/.test(word)) {
|
|
233
|
-
return word;
|
|
234
|
-
}
|
|
235
|
-
// Abbreviations like g.a, n.l.n
|
|
236
|
-
if (/^([a-zA-Z]\.)+[a-zA-Z]?$/.test(word)) {
|
|
237
|
-
return word.toUpperCase(); // → G.A, N.L.N
|
|
238
|
-
}
|
|
239
|
-
// Version numbers like 3.0.1
|
|
240
|
-
if (/^\d+(\.\d+)+$/.test(word)) {
|
|
241
|
-
return word;
|
|
242
|
-
}
|
|
243
|
-
// Mixed abbrev/numbers (like p.m2.5 or covid-19 v2.0)
|
|
244
|
-
if (/[a-zA-Z]\.\d/.test(word) || /\d+\.\d+[a-zA-Z]?/.test(word)) {
|
|
245
|
-
return word; // leave as-is
|
|
246
|
-
}
|
|
247
|
-
// First word of sentence → capitalize first letter
|
|
248
|
-
if (i === 0) {
|
|
249
|
-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
250
|
-
}
|
|
251
|
-
// Other words → lowercase
|
|
252
|
-
return word.toLowerCase();
|
|
253
|
-
})
|
|
254
|
-
.join(" ");
|
|
255
|
-
})
|
|
256
|
-
.join("");
|
|
257
|
-
};
|