adaptic-backend 1.0.231 → 1.0.232
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/client.cjs +29 -39
- package/client.d.ts +3 -3
- package/package.json +1 -1
- package/prismaClient.cjs +4 -2
- package/prismaClient.d.ts +1 -1
- package/server/client.d.ts +3 -3
- package/server/client.d.ts.map +1 -1
- package/server/client.js.map +1 -1
- package/server/client.mjs +28 -38
- package/server/prismaClient.d.ts +1 -1
- package/server/prismaClient.d.ts.map +1 -1
- package/server/prismaClient.js.map +1 -1
- package/server/prismaClient.mjs +5 -3
package/client.cjs
CHANGED
@@ -1,58 +1,38 @@
|
|
1
1
|
"use strict";
|
2
|
+
// client.ts
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
5
|
};
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
7
|
exports.client = void 0;
|
7
|
-
exports.
|
8
|
+
exports.getApolloClient = getApolloClient;
|
8
9
|
const client_1 = require("@apollo/client");
|
9
|
-
const
|
10
|
-
const
|
11
|
-
const error_cjs_1 = require("@apollo/client/link/error/error.cjs");
|
10
|
+
const context_1 = require("@apollo/client/link/context");
|
11
|
+
const error_1 = require("@apollo/client/link/error");
|
12
12
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
13
|
-
|
13
|
+
let apolloClient = null;
|
14
14
|
/**
|
15
|
-
*
|
15
|
+
* Initializes a new Apollo Client instance.
|
16
|
+
* @returns ApolloClient instance.
|
16
17
|
*/
|
17
|
-
|
18
|
-
const
|
19
|
-
const
|
20
|
-
|
21
|
-
|
22
|
-
try {
|
23
|
-
const token = await (0, getToken_1.getToken)({
|
24
|
-
req,
|
25
|
-
secureCookie,
|
26
|
-
secret,
|
27
|
-
salt,
|
28
|
-
raw: true,
|
29
|
-
});
|
30
|
-
return token;
|
31
|
-
}
|
32
|
-
catch (error) {
|
33
|
-
console.error("Error retrieving token:", error);
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
return null;
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Function to create a new Apollo Client instance
|
41
|
-
*/
|
42
|
-
function createApolloClient(req) {
|
18
|
+
function initializeApollo() {
|
19
|
+
const isProduction = process.env.NODE_ENV === "production";
|
20
|
+
const httpUrl = isProduction
|
21
|
+
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
22
|
+
: "http://localhost:4000/graphql";
|
43
23
|
const httpLink = new client_1.HttpLink({ uri: httpUrl, fetch: cross_fetch_1.default });
|
44
|
-
const authLink = (0,
|
45
|
-
|
24
|
+
const authLink = (0, context_1.setContext)((_, { headers }) => {
|
25
|
+
// Retrieve the token from environment variables or other secure storage
|
26
|
+
const token = process.env.SERVER_AUTH_TOKEN || "";
|
46
27
|
return {
|
47
28
|
headers: {
|
48
29
|
...headers,
|
49
30
|
authorization: token ? `Bearer ${token}` : "",
|
50
|
-
connection:
|
31
|
+
connection: "close",
|
51
32
|
},
|
52
33
|
};
|
53
34
|
});
|
54
|
-
|
55
|
-
const errorLink = (0, error_cjs_1.onError)(({ graphQLErrors, networkError }) => {
|
35
|
+
const errorLink = (0, error_1.onError)(({ graphQLErrors, networkError }) => {
|
56
36
|
if (graphQLErrors) {
|
57
37
|
graphQLErrors.forEach(({ message, locations, path }) => console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
|
58
38
|
}
|
@@ -65,6 +45,16 @@ function createApolloClient(req) {
|
|
65
45
|
cache: new client_1.InMemoryCache(),
|
66
46
|
});
|
67
47
|
}
|
68
|
-
|
69
|
-
|
48
|
+
/**
|
49
|
+
* Retrieves the singleton Apollo Client instance.
|
50
|
+
* @returns ApolloClient instance.
|
51
|
+
*/
|
52
|
+
function getApolloClient() {
|
53
|
+
if (!apolloClient) {
|
54
|
+
apolloClient = initializeApollo();
|
55
|
+
}
|
56
|
+
return apolloClient;
|
57
|
+
}
|
58
|
+
// Export the singleton instance
|
59
|
+
exports.client = getApolloClient();
|
70
60
|
//# sourceMappingURL=client.js.map
|
package/client.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
export type { NormalizedCacheObject, ApolloClient };
|
3
2
|
/**
|
4
|
-
*
|
3
|
+
* Retrieves the singleton Apollo Client instance.
|
4
|
+
* @returns ApolloClient instance.
|
5
5
|
*/
|
6
|
-
export declare function
|
6
|
+
export declare function getApolloClient(): ApolloClient<NormalizedCacheObject>;
|
7
7
|
export declare const client: ApolloClient<NormalizedCacheObject>;
|
8
8
|
//# sourceMappingURL=client.d.ts.map
|
package/package.json
CHANGED
package/prismaClient.cjs
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
// client with accelerate
|
4
3
|
const edge_1 = require("@prisma/client/edge");
|
5
4
|
const extension_accelerate_1 = require("@prisma/extension-accelerate");
|
5
|
+
const isProduction = process.env.NODE_ENV === "production";
|
6
6
|
let prisma;
|
7
|
-
if (
|
7
|
+
if (isProduction) {
|
8
|
+
// In production, use Prisma Data Proxy by connecting via DATABASE_URL
|
8
9
|
prisma = new edge_1.PrismaClient().$extends((0, extension_accelerate_1.withAccelerate)());
|
9
10
|
}
|
10
11
|
else {
|
12
|
+
// In development, prevent multiple instances due to hot-reloading
|
11
13
|
const globalWithPrisma = global;
|
12
14
|
if (!globalWithPrisma.prisma) {
|
13
15
|
globalWithPrisma.prisma = new edge_1.PrismaClient().$extends((0, extension_accelerate_1.withAccelerate)());
|
package/prismaClient.d.ts
CHANGED
package/server/client.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
export type { NormalizedCacheObject, ApolloClient };
|
3
2
|
/**
|
4
|
-
*
|
3
|
+
* Retrieves the singleton Apollo Client instance.
|
4
|
+
* @returns ApolloClient instance.
|
5
5
|
*/
|
6
|
-
export declare function
|
6
|
+
export declare function getApolloClient(): ApolloClient<NormalizedCacheObject>;
|
7
7
|
export declare const client: ApolloClient<NormalizedCacheObject>;
|
8
8
|
//# sourceMappingURL=client.d.ts.map
|
package/server/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAGZ,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAmDxB;;;GAGG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAAC,qBAAqB,CAAC,CAKrE;AAGD,eAAO,MAAM,MAAM,qCAAoB,CAAC"}
|
package/server/client.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,GAET,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,GAET,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,IAAI,YAAY,GAA+C,IAAI,CAAC;AAEpE;;;GAGG;AACH,SAAS,gBAAgB;IACvB,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAC3D,MAAM,OAAO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AU,eAAe;IAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,gBAAgB,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC"}
|
package/server/client.mjs
CHANGED
@@ -1,51 +1,31 @@
|
|
1
|
+
// client.ts
|
1
2
|
import pkg from '@apollo/client';
|
2
3
|
const { ApolloClient, InMemoryCache, HttpLink, } = pkg;
|
3
|
-
import { setContext } from "@apollo/client/link/context
|
4
|
-
import {
|
5
|
-
import
|
6
|
-
|
7
|
-
const httpUrl = process.env.BACKEND_HTTPS_URL || process.env.NODE_ENV === "production" ? "https://api.adaptic.ai/graphql" : "http://localhost:4000/graphql";
|
4
|
+
import { setContext } from "@apollo/client/link/context";
|
5
|
+
import { onError } from "@apollo/client/link/error";
|
6
|
+
import fetch from "cross-fetch";
|
7
|
+
let apolloClient = null;
|
8
8
|
/**
|
9
|
-
*
|
9
|
+
* Initializes a new Apollo Client instance.
|
10
|
+
* @returns ApolloClient instance.
|
10
11
|
*/
|
11
|
-
|
12
|
-
const
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
try {
|
17
|
-
const token = await getToken({
|
18
|
-
req,
|
19
|
-
secureCookie,
|
20
|
-
secret,
|
21
|
-
salt,
|
22
|
-
raw: true,
|
23
|
-
});
|
24
|
-
return token;
|
25
|
-
}
|
26
|
-
catch (error) {
|
27
|
-
console.error("Error retrieving token:", error);
|
28
|
-
return null;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* Function to create a new Apollo Client instance
|
35
|
-
*/
|
36
|
-
export function createApolloClient(req) {
|
12
|
+
function initializeApollo() {
|
13
|
+
const isProduction = process.env.NODE_ENV === "production";
|
14
|
+
const httpUrl = isProduction
|
15
|
+
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
16
|
+
: "http://localhost:4000/graphql";
|
37
17
|
const httpLink = new HttpLink({ uri: httpUrl, fetch });
|
38
|
-
const authLink = setContext(
|
39
|
-
|
18
|
+
const authLink = setContext((_, { headers }) => {
|
19
|
+
// Retrieve the token from environment variables or other secure storage
|
20
|
+
const token = process.env.SERVER_AUTH_TOKEN || "";
|
40
21
|
return {
|
41
22
|
headers: {
|
42
23
|
...headers,
|
43
24
|
authorization: token ? `Bearer ${token}` : "",
|
44
|
-
connection:
|
25
|
+
connection: "close",
|
45
26
|
},
|
46
27
|
};
|
47
28
|
});
|
48
|
-
// Error handling link
|
49
29
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
50
30
|
if (graphQLErrors) {
|
51
31
|
graphQLErrors.forEach(({ message, locations, path }) => console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
|
@@ -59,6 +39,16 @@ export function createApolloClient(req) {
|
|
59
39
|
cache: new InMemoryCache(),
|
60
40
|
});
|
61
41
|
}
|
62
|
-
|
63
|
-
|
42
|
+
/**
|
43
|
+
* Retrieves the singleton Apollo Client instance.
|
44
|
+
* @returns ApolloClient instance.
|
45
|
+
*/
|
46
|
+
export function getApolloClient() {
|
47
|
+
if (!apolloClient) {
|
48
|
+
apolloClient = initializeApollo();
|
49
|
+
}
|
50
|
+
return apolloClient;
|
51
|
+
}
|
52
|
+
// Export the singleton instance
|
53
|
+
export const client = getApolloClient();
|
64
54
|
//# sourceMappingURL=client.js.map
|
package/server/prismaClient.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prismaClient.d.ts","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"prismaClient.d.ts","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM,CAAC;QACf,UAAU,MAAM;YACd,MAAM,CAAC,EAAE,YAAY,CAAC;SACvB;KACF;CACF;AAID,QAAA,IAAI,MAAM,EAAE,YAAY,CAAC;AAgBzB,eAAe,MAAM,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prismaClient.js","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"prismaClient.js","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAU9D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AAE3D,IAAI,MAAoB,CAAC;AAEzB,IAAI,YAAY,EAAE,CAAC;IACjB,sEAAsE;IACtE,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAA4B,CAAC;AACpF,CAAC;KAAM,CAAC;IACN,kEAAkE;IAClE,MAAM,gBAAgB,GAAG,MAAuD,CAAC;IAEjF,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QAC7B,gBAAgB,CAAC,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAA4B,CAAC;IACrG,CAAC;IAED,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;AACnC,CAAC;AAED,eAAe,MAAM,CAAC"}
|
package/server/prismaClient.mjs
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
// client with accelerate
|
2
1
|
import { PrismaClient } from "@prisma/client/edge";
|
3
|
-
import { withAccelerate } from
|
2
|
+
import { withAccelerate } from "@prisma/extension-accelerate";
|
3
|
+
const isProduction = process.env.NODE_ENV === "production";
|
4
4
|
let prisma;
|
5
|
-
if (
|
5
|
+
if (isProduction) {
|
6
|
+
// In production, use Prisma Data Proxy by connecting via DATABASE_URL
|
6
7
|
prisma = new PrismaClient().$extends(withAccelerate());
|
7
8
|
}
|
8
9
|
else {
|
10
|
+
// In development, prevent multiple instances due to hot-reloading
|
9
11
|
const globalWithPrisma = global;
|
10
12
|
if (!globalWithPrisma.prisma) {
|
11
13
|
globalWithPrisma.prisma = new PrismaClient().$extends(withAccelerate());
|