@econneq/gql-auth 1.2.10 → 1.2.11
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 +0 -2
- package/dist/api-factory.d.ts.map +1 -1
- package/dist/api-factory.js +3 -5
- package/dist/authServer.d.ts +5 -0
- package/dist/authServer.d.ts.map +1 -0
- package/dist/authServer.js +40 -0
- package/dist/client.d.ts +0 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +32 -11
- package/dist/functions.d.ts +6 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +38 -0
- package/dist/index.d.ts +4 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/query-server.d.ts +0 -3
- package/dist/query-server.d.ts.map +1 -1
- package/dist/query-server.js +0 -9
- package/dist/upload-gql.d.ts +0 -3
- package/dist/upload-gql.d.ts.map +1 -1
- package/dist/upload-gql.js +17 -6
- package/package.json +1 -1
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,
|
|
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;KACnB,CAAC;IACF,OAAO,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,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,iBAyDtD,CAAC"}
|
package/dist/api-factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { removeEmptyFields } from "./functions.js";
|
|
1
2
|
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,16 +8,14 @@ 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 ......");
|
|
12
11
|
const response = await uploadGraphQLMutation({
|
|
13
12
|
query: query.loc?.source.body || "",
|
|
14
13
|
variables: removeEmptyFields(res),
|
|
15
14
|
fileMap: getFileMap ? getFileMap(res) : {},
|
|
16
|
-
params,
|
|
15
|
+
params,
|
|
17
16
|
token,
|
|
18
|
-
config,
|
|
17
|
+
config,
|
|
19
18
|
});
|
|
20
|
-
console.log("response e-conneq/auth-gql ......");
|
|
21
19
|
const result = response?.data?.[mutationName]?.[modelName];
|
|
22
20
|
if (response?.data?.[mutationName]) {
|
|
23
21
|
successMessages.push(result?.[successField] || "operation successful ✅");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { JwtPayload } from "./index.js";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authServer.d.ts","sourceRoot":"","sources":["../src/authServer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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/client.d.ts
CHANGED
|
@@ -3,13 +3,10 @@ export default function getApolloClient(options?: {
|
|
|
3
3
|
csrfToken?: string;
|
|
4
4
|
cookie?: string;
|
|
5
5
|
}, domain?: string | null, config?: {
|
|
6
|
-
protocol: string;
|
|
7
|
-
RootApi: string;
|
|
8
6
|
Subdomains: {
|
|
9
7
|
subdomain: string;
|
|
10
8
|
processId?: string;
|
|
11
9
|
widgetID?: string;
|
|
12
10
|
}[];
|
|
13
|
-
apiKey: string;
|
|
14
11
|
}): Promise<ApolloClient | null>;
|
|
15
12
|
//# sourceMappingURL=client.d.ts.map
|
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,
|
|
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;CAC5E,GACA,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAgE9B"}
|
package/dist/client.js
CHANGED
|
@@ -5,20 +5,41 @@ 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 {
|
|
9
|
-
//
|
|
8
|
+
const { Subdomains } = config;
|
|
9
|
+
// const apiKey = process.env.API_KEY || "";
|
|
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");
|
|
10
22
|
const tenant = domain
|
|
11
23
|
? Subdomains.find((s) => s.subdomain.toLowerCase() === domain.toLowerCase())
|
|
12
24
|
: null;
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
let uri;
|
|
26
|
+
let destUrl;
|
|
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);
|
|
15
39
|
const csrfToken = options?.csrfToken || (!isServer ? Cookies.get("csrftoken") : "");
|
|
16
|
-
const dynamicHost = domain
|
|
17
|
-
? `${domain}.${RootApi}`
|
|
18
|
-
: RootApi;
|
|
19
40
|
const headers = {
|
|
20
41
|
'Content-Type': 'application/json',
|
|
21
|
-
'X-API-KEY': apiKey,
|
|
42
|
+
// 'X-API-KEY': apiKey,
|
|
22
43
|
...(options?.cookie && { 'Cookie': options.cookie }),
|
|
23
44
|
...(csrfToken && { 'X-CSRFToken': csrfToken }),
|
|
24
45
|
...(tenant && {
|
|
@@ -26,13 +47,13 @@ export default async function getApolloClient(options, domain, config) {
|
|
|
26
47
|
'X-Process-ID': tenant?.processId || "",
|
|
27
48
|
'X-Widget-ID': tenant?.widgetID || "",
|
|
28
49
|
}),
|
|
29
|
-
'Referer':
|
|
30
|
-
'Host': isServer ?
|
|
50
|
+
'Referer': destUrl,
|
|
51
|
+
'Host': isServer ? sourceHost : window.location.host,
|
|
31
52
|
};
|
|
32
53
|
return new ApolloClient({
|
|
33
54
|
link: new HttpLink({
|
|
34
55
|
uri,
|
|
35
|
-
fetch,
|
|
56
|
+
fetch,
|
|
36
57
|
headers,
|
|
37
58
|
}),
|
|
38
59
|
cache: new InMemoryCache(),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { JwtPayload } from "./index.js";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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/index.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
1
|
import { queryServerGraphQL } from './query-server.js';
|
|
3
2
|
import { ApiFactory } from './api-factory.js';
|
|
4
3
|
import { uploadGraphQLMutation } from './upload-gql.js';
|
|
5
4
|
export { queryServerGraphQL, ApiFactory, uploadGraphQLMutation };
|
|
6
5
|
export type ConfigType = {
|
|
7
|
-
protocol: string;
|
|
8
|
-
RootApi: string;
|
|
9
|
-
NoDomainRootApi: string;
|
|
10
6
|
Subdomains: SubdomainItem[];
|
|
11
|
-
apiKey: string;
|
|
12
7
|
fonts: string[];
|
|
13
8
|
};
|
|
14
9
|
export type SubdomainItem = {
|
|
@@ -21,10 +16,6 @@ export type ApolloOptions = {
|
|
|
21
16
|
csrfToken?: string;
|
|
22
17
|
cookie?: string;
|
|
23
18
|
};
|
|
24
|
-
export type SelectOptions = string | {
|
|
25
|
-
label: string;
|
|
26
|
-
value: string | number;
|
|
27
|
-
};
|
|
28
19
|
export interface InterLoginData {
|
|
29
20
|
username: string;
|
|
30
21
|
password: string;
|
|
@@ -47,39 +38,14 @@ export interface JwtPayload {
|
|
|
47
38
|
is_active?: boolean;
|
|
48
39
|
is_hod?: boolean;
|
|
49
40
|
role?: string;
|
|
50
|
-
|
|
41
|
+
depts?: string[] | any;
|
|
51
42
|
page?: string[] | any;
|
|
52
43
|
school?: number[] | any;
|
|
53
44
|
domain?: number[] | any;
|
|
45
|
+
permissions?: string[];
|
|
54
46
|
language?: string[];
|
|
55
47
|
last_login?: any;
|
|
56
48
|
}
|
|
57
|
-
export
|
|
58
|
-
|
|
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';
|
|
49
|
+
export { getToken, getUser, logout, removeEmptyFields, } from './functions.js';
|
|
50
|
+
export { getServerToken, getServerUser, getPermissions } from './authServer.js';
|
|
85
51
|
//# 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":"AAAA,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,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAGD,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAGD,OAAO,EACL,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAC7C,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EAAE,aAAa,EAAE,cAAc,EAC9C,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
// 1. Export the Core Functions
|
|
2
1
|
import { queryServerGraphQL } from './query-server.js';
|
|
3
2
|
import { ApiFactory } from './api-factory.js';
|
|
4
3
|
import { uploadGraphQLMutation } from './upload-gql.js';
|
|
5
4
|
export { queryServerGraphQL, ApiFactory, uploadGraphQLMutation };
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
export { getProfile, getClass, getClassName, getLevel, getAcademicYear, getAcademicYearStudent } from './utilsSchool.js';
|
|
5
|
+
export { getToken, getUser, logout, removeEmptyFields, } from './functions.js';
|
|
6
|
+
export { getServerToken, getServerUser, getPermissions } from './authServer.js';
|
package/dist/query-server.d.ts
CHANGED
|
@@ -3,10 +3,7 @@ type ServerQueryArgs = {
|
|
|
3
3
|
variables?: Record<string, any>;
|
|
4
4
|
domain?: string | null;
|
|
5
5
|
config: {
|
|
6
|
-
protocol: string;
|
|
7
|
-
RootApi: string;
|
|
8
6
|
Subdomains: any[];
|
|
9
|
-
apiKey: string;
|
|
10
7
|
};
|
|
11
8
|
};
|
|
12
9
|
export declare function queryServerGraphQL<T = any>({ query, variables, domain, config, }: ServerQueryArgs): Promise<T | null>;
|
|
@@ -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":"AAKA,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,UAAU,EAAE,GAAG,EAAE,CAAC;KACnB,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,CAyBrC"}
|
package/dist/query-server.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
// src/server-query.ts
|
|
2
|
-
/// <reference types="next" />
|
|
3
2
|
'use server';
|
|
4
3
|
import { cookies } from 'next/headers';
|
|
5
4
|
import getApolloClient from './client.js';
|
|
6
5
|
export async function queryServerGraphQL({ query, variables = {}, domain, config, }) {
|
|
7
6
|
try {
|
|
8
|
-
// 1. Get server-side cookies
|
|
9
7
|
const cookieStore = await cookies();
|
|
10
8
|
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)
|
|
15
9
|
const client = await getApolloClient({ cookie: cookieString }, domain, config);
|
|
16
10
|
if (!client)
|
|
17
11
|
return null;
|
|
@@ -20,12 +14,9 @@ export async function queryServerGraphQL({ query, variables = {}, domain, config
|
|
|
20
14
|
variables,
|
|
21
15
|
fetchPolicy: 'no-cache',
|
|
22
16
|
});
|
|
23
|
-
console.log("getting @e-conneq/gql-auth ........");
|
|
24
17
|
return result?.data;
|
|
25
18
|
}
|
|
26
19
|
catch (err) {
|
|
27
|
-
// On the server, we console.error instead of using Swal
|
|
28
|
-
console.error("GraphQL Server Error:", err);
|
|
29
20
|
return null;
|
|
30
21
|
}
|
|
31
22
|
}
|
package/dist/upload-gql.d.ts
CHANGED
|
@@ -5,15 +5,12 @@ type UploadGraphQLArgs = {
|
|
|
5
5
|
token?: string;
|
|
6
6
|
params: any;
|
|
7
7
|
config: {
|
|
8
|
-
protocol: string;
|
|
9
|
-
RootApi: string;
|
|
10
8
|
Subdomains: {
|
|
11
9
|
subdomain: string;
|
|
12
10
|
id: string | number;
|
|
13
11
|
processId: string;
|
|
14
12
|
widgetID: string;
|
|
15
13
|
}[];
|
|
16
|
-
apiKey?: string;
|
|
17
14
|
};
|
|
18
15
|
};
|
|
19
16
|
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,
|
|
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;KAC/F,CAAC;CACH,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,EAC1C,KAAK,EACL,SAAS,EACT,OAAO,EACP,KAAK,EACL,MAAM,EACN,MAAM,EACP,EAAE,iBAAiB,gBAuEnB"}
|
package/dist/upload-gql.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export async function uploadGraphQLMutation({ query, variables, fileMap, token, params, config }) {
|
|
2
|
-
const
|
|
2
|
+
const isServer = typeof window === "undefined";
|
|
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
|
+
}
|
|
3
13
|
const formData = new FormData();
|
|
4
14
|
const updatedVariables = { ...variables };
|
|
5
15
|
// 1. Prepare GraphQL Multipart Request (Spec compliant)
|
|
@@ -20,25 +30,26 @@ export async function uploadGraphQLMutation({ query, variables, fileMap, token,
|
|
|
20
30
|
// 2. Multi-tenant URL and Data Logic
|
|
21
31
|
const requestedDomain = params?.domain || "";
|
|
22
32
|
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/`;
|
|
25
33
|
// 3. Construct Headers
|
|
26
34
|
const headers = {
|
|
27
35
|
...(token ? { "Authorization": `Bearer ${token}` } : {}),
|
|
28
|
-
...(apiKey ? { "X-API-KEY": apiKey } : {}),
|
|
29
36
|
};
|
|
37
|
+
if (isServer) {
|
|
38
|
+
headers["Host"] = BACKEND_URL_INT || "";
|
|
39
|
+
}
|
|
30
40
|
// Inject specific tenant metadata into headers for Django to read
|
|
31
41
|
if (tenantData) {
|
|
32
42
|
headers["X-Tenant-ID"] = String(tenantData.subdomain);
|
|
33
43
|
headers["X-Process-ID"] = tenantData.processId || "";
|
|
34
44
|
headers["X-Widget-ID"] = tenantData.widgetID || "";
|
|
45
|
+
headers["X-API-KEY"] = API_KEY || "";
|
|
35
46
|
}
|
|
36
|
-
|
|
47
|
+
if (!tenantData?.subdomain)
|
|
48
|
+
throw ("No Tenant Found ===================>");
|
|
37
49
|
const res = await fetch(API_LINK, {
|
|
38
50
|
method: "POST",
|
|
39
51
|
headers,
|
|
40
52
|
body: formData,
|
|
41
|
-
// credentials: "include" is important if you use cookies alongside headers
|
|
42
53
|
credentials: "include",
|
|
43
54
|
});
|
|
44
55
|
return await res.json();
|