@econneq/gql-auth 1.0.17 → 1.0.18
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 +2 -3
- package/dist/client.d.ts +0 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +20 -8
- package/dist/query-server.d.ts +0 -2
- package/dist/query-server.d.ts.map +1 -1
- package/dist/query-server.js +0 -6
- package/dist/upload-gql.d.ts +0 -2
- package/dist/upload-gql.d.ts.map +1 -1
- package/dist/upload-gql.js +18 -5
- 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,iBA0DtD,CAAC"}
|
package/dist/api-factory.js
CHANGED
|
@@ -8,14 +8,13 @@ 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
19
|
console.log("response e-conneq/auth-gql ......");
|
|
21
20
|
const result = response?.data?.[mutationName]?.[modelName];
|
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,
|
|
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,CA4D9B"}
|
package/dist/client.js
CHANGED
|
@@ -5,17 +5,29 @@ 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 protocol = process.env.PROTOCOL;
|
|
11
|
+
const production = process.env.NODE_ENV === "production";
|
|
12
|
+
const host = production ? process.env.INTERNAL_API_URL : process.env.EXTERNAL_API_URL;
|
|
13
|
+
if (!host)
|
|
14
|
+
throw new Error("Env (INTERNAL_API_URL or EXTERNAL_API_URL) is required");
|
|
15
|
+
if (!protocol)
|
|
16
|
+
throw new Error("Env (PROTOCOL) is required");
|
|
17
|
+
let uri;
|
|
18
|
+
console.log("client - isServer =====>", isServer);
|
|
19
|
+
if (isServer) {
|
|
20
|
+
uri = `${protocol}${host}/graphql/`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
uri = "/api/graphql";
|
|
24
|
+
}
|
|
10
25
|
const tenant = domain
|
|
11
26
|
? Subdomains.find((s) => s.subdomain.toLowerCase() === domain.toLowerCase())
|
|
12
27
|
: null;
|
|
13
|
-
const baseUrl = `${protocol +
|
|
14
|
-
const uri = `${baseUrl}/graphql/`;
|
|
28
|
+
const baseUrl = `${protocol + host}`;
|
|
15
29
|
const csrfToken = options?.csrfToken || (!isServer ? Cookies.get("csrftoken") : "");
|
|
16
|
-
const dynamicHost = domain
|
|
17
|
-
? `${domain}.${RootApi}`
|
|
18
|
-
: RootApi;
|
|
30
|
+
const dynamicHost = domain ? `${domain}.${host}` : host;
|
|
19
31
|
const headers = {
|
|
20
32
|
'Content-Type': 'application/json',
|
|
21
33
|
'X-API-KEY': apiKey,
|
|
@@ -32,7 +44,7 @@ export default async function getApolloClient(options, domain, config) {
|
|
|
32
44
|
return new ApolloClient({
|
|
33
45
|
link: new HttpLink({
|
|
34
46
|
uri,
|
|
35
|
-
fetch,
|
|
47
|
+
fetch,
|
|
36
48
|
headers,
|
|
37
49
|
}),
|
|
38
50
|
cache: new InMemoryCache(),
|
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":"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,
|
|
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;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,CAyBrC"}
|
package/dist/query-server.js
CHANGED
|
@@ -4,13 +4,8 @@ import { cookies } from 'next/headers';
|
|
|
4
4
|
import getApolloClient from './client';
|
|
5
5
|
export async function queryServerGraphQL({ query, variables = {}, domain, config, }) {
|
|
6
6
|
try {
|
|
7
|
-
// 1. Get server-side cookies
|
|
8
7
|
const cookieStore = await cookies();
|
|
9
8
|
const cookieString = cookieStore.toString();
|
|
10
|
-
// 2. Call getApolloClient with the correct 3 arguments:
|
|
11
|
-
// Arg 1: options (cookies)
|
|
12
|
-
// Arg 2: domain (subdomain string)
|
|
13
|
-
// Arg 3: config (URLs and Subdomain array)
|
|
14
9
|
const client = await getApolloClient({ cookie: cookieString }, domain, config);
|
|
15
10
|
if (!client)
|
|
16
11
|
return null;
|
|
@@ -23,7 +18,6 @@ export async function queryServerGraphQL({ query, variables = {}, domain, config
|
|
|
23
18
|
return result?.data;
|
|
24
19
|
}
|
|
25
20
|
catch (err) {
|
|
26
|
-
// On the server, we console.error instead of using Swal
|
|
27
21
|
console.error("GraphQL Server Error:", err);
|
|
28
22
|
return null;
|
|
29
23
|
}
|
package/dist/upload-gql.d.ts
CHANGED
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;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,gBAwEnB"}
|
package/dist/upload-gql.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
export async function uploadGraphQLMutation({ query, variables, fileMap, token, params, config }) {
|
|
2
|
-
const
|
|
2
|
+
const isServer = typeof window === "undefined";
|
|
3
|
+
const { Subdomains, apiKey } = config;
|
|
4
|
+
const protocol = process.env.PROTOCOL;
|
|
5
|
+
const production = process.env.NODE_ENV === "production";
|
|
6
|
+
const host = production ? process.env.INTERNAL_API_URL : process.env.EXTERNAL_API_URL;
|
|
7
|
+
let API_LINK;
|
|
8
|
+
if (isServer) {
|
|
9
|
+
API_LINK = `${protocol}${host}/graphql/`;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
API_LINK = `/api/graphql`;
|
|
13
|
+
}
|
|
3
14
|
const formData = new FormData();
|
|
4
15
|
const updatedVariables = { ...variables };
|
|
5
16
|
// 1. Prepare GraphQL Multipart Request (Spec compliant)
|
|
@@ -20,25 +31,27 @@ export async function uploadGraphQLMutation({ query, variables, fileMap, token,
|
|
|
20
31
|
// 2. Multi-tenant URL and Data Logic
|
|
21
32
|
const requestedDomain = params?.domain || "";
|
|
22
33
|
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
34
|
// 3. Construct Headers
|
|
26
35
|
const headers = {
|
|
27
36
|
...(token ? { "Authorization": `Bearer ${token}` } : {}),
|
|
28
37
|
...(apiKey ? { "X-API-KEY": apiKey } : {}),
|
|
29
38
|
};
|
|
39
|
+
if (isServer) {
|
|
40
|
+
// headers["Host"] = requestedDomain ? `${requestedDomain}.${host}` : host;
|
|
41
|
+
headers["Host"] = host || "";
|
|
42
|
+
}
|
|
30
43
|
// Inject specific tenant metadata into headers for Django to read
|
|
31
44
|
if (tenantData) {
|
|
32
45
|
headers["X-Tenant-ID"] = String(tenantData.subdomain);
|
|
33
46
|
headers["X-Process-ID"] = tenantData.processId || "";
|
|
34
47
|
headers["X-Widget-ID"] = tenantData.widgetID || "";
|
|
35
48
|
}
|
|
36
|
-
|
|
49
|
+
console.log(`Host (upload.js) ==========: ${host}`);
|
|
50
|
+
console.log(`Mutation connecting to (upload.js) ==========: ${API_LINK}`);
|
|
37
51
|
const res = await fetch(API_LINK, {
|
|
38
52
|
method: "POST",
|
|
39
53
|
headers,
|
|
40
54
|
body: formData,
|
|
41
|
-
// credentials: "include" is important if you use cookies alongside headers
|
|
42
55
|
credentials: "include",
|
|
43
56
|
});
|
|
44
57
|
return await res.json();
|