adaptic-backend 1.0.230 → 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 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.createApolloClient = createApolloClient;
8
+ exports.getApolloClient = getApolloClient;
8
9
  const client_1 = require("@apollo/client");
9
- const context_cjs_1 = require("@apollo/client/link/context/context.cjs");
10
- const getToken_1 = require("./getToken.cjs");
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
- const httpUrl = process.env.BACKEND_HTTPS_URL || process.env.NODE_ENV === "production" ? "https://api.adaptic.ai/graphql" : "http://localhost:4000/graphql";
13
+ let apolloClient = null;
14
14
  /**
15
- * Function to get the authentication token using the custom getToken implementation
15
+ * Initializes a new Apollo Client instance.
16
+ * @returns ApolloClient instance.
16
17
  */
17
- async function getAuthToken(req) {
18
- const secret = process.env.JWT_SECRET;
19
- const salt = process.env.JWT_SALT;
20
- const secureCookie = process.env.NODE_ENV === "production";
21
- if (secret && salt && req) {
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, context_cjs_1.setContext)(async (_, { headers }) => {
45
- const token = await getAuthToken(req);
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: 'close',
31
+ connection: "close",
51
32
  },
52
33
  };
53
34
  });
54
- // Error handling link
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
- // initialise apollo client
69
- exports.client = createApolloClient();
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
- * Function to create a new Apollo Client instance
3
+ * Retrieves the singleton Apollo Client instance.
4
+ * @returns ApolloClient instance.
5
5
  */
6
- export declare function createApolloClient(req?: any): ApolloClient<NormalizedCacheObject>;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adaptic-backend",
3
- "version": "1.0.230",
3
+ "version": "1.0.232",
4
4
  "description": "Backend executable CRUD functions with dynamic variables construction, and type definitions for the Adaptic AI platform.",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",
package/prismaClient.cjs CHANGED
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // client with accelerate
4
- const client_1 = require("@prisma/client");
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 (process.env.NODE_ENV === "production") {
8
- prisma = new client_1.PrismaClient().$extends((0, extension_accelerate_1.withAccelerate)());
7
+ if (isProduction) {
8
+ // In production, use Prisma Data Proxy by connecting via DATABASE_URL
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
- globalWithPrisma.prisma = new client_1.PrismaClient().$extends((0, extension_accelerate_1.withAccelerate)());
15
+ globalWithPrisma.prisma = new edge_1.PrismaClient().$extends((0, extension_accelerate_1.withAccelerate)());
14
16
  }
15
17
  prisma = globalWithPrisma.prisma;
16
18
  }
package/prismaClient.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { PrismaClient } from "@prisma/client";
1
+ import { PrismaClient } from "@prisma/client/edge";
2
2
  declare global {
3
3
  namespace NodeJS {
4
4
  interface Global {
5
- prisma: PrismaClient;
5
+ prisma?: PrismaClient;
6
6
  }
7
7
  }
8
8
  }
@@ -1,8 +1,8 @@
1
1
  import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
2
- export type { NormalizedCacheObject, ApolloClient };
3
2
  /**
4
- * Function to create a new Apollo Client instance
3
+ * Retrieves the singleton Apollo Client instance.
4
+ * @returns ApolloClient instance.
5
5
  */
6
- export declare function createApolloClient(req?: any): ApolloClient<NormalizedCacheObject>;
6
+ export declare function getApolloClient(): ApolloClient<NormalizedCacheObject>;
7
7
  export declare const client: ApolloClient<NormalizedCacheObject>;
8
8
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGZ,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAMxB,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC;AA8BpD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,YAAY,CAAC,qBAAqB,CAAC,CAiCjF;AAID,eAAO,MAAM,MAAM,qCAAuB,CAAC"}
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"}
@@ -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,yCAAyC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,KAAK,MAAM,aAAa,CAAC;AAIhC,MAAM,OAAO,GAAG,OAAO,CAAC,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B,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/context.cjs";
4
- import { getToken } from "./getToken.mjs";
5
- import { onError } from "@apollo/client/link/error/error.cjs";
6
- import fetch from 'cross-fetch';
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
- * Function to get the authentication token using the custom getToken implementation
9
+ * Initializes a new Apollo Client instance.
10
+ * @returns ApolloClient instance.
10
11
  */
11
- async function getAuthToken(req) {
12
- const secret = process.env.JWT_SECRET;
13
- const salt = process.env.JWT_SALT;
14
- const secureCookie = process.env.NODE_ENV === "production";
15
- if (secret && salt && req) {
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(async (_, { headers }) => {
39
- const token = await getAuthToken(req);
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: 'close',
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
- // initialise apollo client
63
- export const client = createApolloClient();
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
@@ -1,8 +1,8 @@
1
- import { PrismaClient } from "@prisma/client";
1
+ import { PrismaClient } from "@prisma/client/edge";
2
2
  declare global {
3
3
  namespace NodeJS {
4
4
  interface Global {
5
- prisma: PrismaClient;
5
+ prisma?: PrismaClient;
6
6
  }
7
7
  }
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prismaClient.d.ts","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM,CAAC;QACf,UAAU,MAAM;YACd,MAAM,EAAE,YAAY,CAAC;SACtB;KACF;CACF;AAED,QAAA,IAAI,MAAM,EAAE,YAAY,CAAC;AAczB,eAAe,MAAM,CAAC"}
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,yBAAyB;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAU7D,IAAI,MAAoB,CAAC;AAEzB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAA4B,CAAC;AACpF,CAAC;KAAM,CAAC;IACN,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"}
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"}
@@ -1,11 +1,13 @@
1
- // client with accelerate
2
- import { PrismaClient } from "@prisma/client";
3
- import { withAccelerate } from '@prisma/extension-accelerate';
1
+ import { PrismaClient } from "@prisma/client/edge";
2
+ import { withAccelerate } from "@prisma/extension-accelerate";
3
+ const isProduction = process.env.NODE_ENV === "production";
4
4
  let prisma;
5
- if (process.env.NODE_ENV === "production") {
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());