naystack 1.5.9 → 1.5.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.
Files changed (114) hide show
  1. package/README.md +646 -91
  2. package/dist/auth/constants.d.mts +4 -0
  3. package/dist/auth/constants.d.ts +4 -0
  4. package/dist/auth/email/client.d.mts +149 -0
  5. package/dist/auth/email/client.d.ts +149 -0
  6. package/dist/auth/email/index.cjs.js +2 -20
  7. package/dist/auth/email/index.d.mts +41 -1
  8. package/dist/auth/email/index.d.ts +41 -1
  9. package/dist/auth/email/index.esm.js +1 -17
  10. package/dist/auth/email/routes/delete.cjs.js +0 -1
  11. package/dist/auth/email/routes/delete.d.mts +5 -0
  12. package/dist/auth/email/routes/delete.d.ts +5 -0
  13. package/dist/auth/email/routes/delete.esm.js +0 -1
  14. package/dist/auth/email/routes/get.d.mts +5 -0
  15. package/dist/auth/email/routes/get.d.ts +5 -0
  16. package/dist/auth/email/routes/post.cjs.js +0 -1
  17. package/dist/auth/email/routes/post.d.mts +5 -0
  18. package/dist/auth/email/routes/post.d.ts +5 -0
  19. package/dist/auth/email/routes/post.esm.js +0 -1
  20. package/dist/auth/email/routes/put.cjs.js +0 -1
  21. package/dist/auth/email/routes/put.d.mts +5 -0
  22. package/dist/auth/email/routes/put.d.ts +5 -0
  23. package/dist/auth/email/routes/put.esm.js +0 -1
  24. package/dist/auth/email/token.d.mts +62 -0
  25. package/dist/auth/email/token.d.ts +62 -0
  26. package/dist/auth/email/types.d.mts +22 -0
  27. package/dist/auth/email/types.d.ts +22 -0
  28. package/dist/auth/email/utils.cjs.js +0 -18
  29. package/dist/auth/email/utils.d.mts +41 -3
  30. package/dist/auth/email/utils.d.ts +41 -3
  31. package/dist/auth/email/utils.esm.js +0 -16
  32. package/dist/auth/google/get.d.mts +5 -0
  33. package/dist/auth/google/get.d.ts +5 -0
  34. package/dist/auth/google/index.d.mts +39 -0
  35. package/dist/auth/google/index.d.ts +39 -0
  36. package/dist/auth/index.cjs.js +4 -22
  37. package/dist/auth/index.d.mts +1 -1
  38. package/dist/auth/index.d.ts +1 -1
  39. package/dist/auth/index.esm.js +3 -19
  40. package/dist/auth/instagram/client.d.mts +19 -0
  41. package/dist/auth/instagram/client.d.ts +19 -0
  42. package/dist/auth/instagram/index.d.mts +37 -0
  43. package/dist/auth/instagram/index.d.ts +37 -0
  44. package/dist/auth/instagram/route.d.mts +5 -0
  45. package/dist/auth/instagram/route.d.ts +5 -0
  46. package/dist/auth/instagram/utils.d.mts +13 -0
  47. package/dist/auth/instagram/utils.d.ts +13 -0
  48. package/dist/auth/types.d.mts +24 -0
  49. package/dist/auth/types.d.ts +24 -0
  50. package/dist/auth/utils/errors.d.mts +10 -0
  51. package/dist/auth/utils/errors.d.ts +10 -0
  52. package/dist/auth/utils/token.d.mts +20 -0
  53. package/dist/auth/utils/token.d.ts +20 -0
  54. package/dist/client/hooks.d.mts +59 -0
  55. package/dist/client/hooks.d.ts +59 -0
  56. package/dist/client/seo.d.mts +46 -0
  57. package/dist/client/seo.d.ts +46 -0
  58. package/dist/env.d.mts +61 -0
  59. package/dist/env.d.ts +61 -0
  60. package/dist/file/client.d.mts +53 -1
  61. package/dist/file/client.d.ts +53 -1
  62. package/dist/file/index.cjs.js +0 -1
  63. package/dist/file/index.esm.js +0 -1
  64. package/dist/file/put.cjs.js +0 -1
  65. package/dist/file/put.d.mts +11 -0
  66. package/dist/file/put.d.ts +11 -0
  67. package/dist/file/put.esm.js +0 -1
  68. package/dist/file/setup.cjs.js +0 -1
  69. package/dist/file/setup.d.mts +48 -0
  70. package/dist/file/setup.d.ts +48 -0
  71. package/dist/file/setup.esm.js +0 -1
  72. package/dist/file/utils.d.mts +41 -0
  73. package/dist/file/utils.d.ts +41 -0
  74. package/dist/graphql/client.d.mts +113 -0
  75. package/dist/graphql/client.d.ts +113 -0
  76. package/dist/graphql/errors.d.mts +26 -0
  77. package/dist/graphql/errors.d.ts +26 -0
  78. package/dist/graphql/index.cjs.js +2 -3
  79. package/dist/graphql/index.esm.js +2 -3
  80. package/dist/graphql/init.cjs.js +0 -1
  81. package/dist/graphql/init.d.mts +33 -0
  82. package/dist/graphql/init.d.ts +33 -0
  83. package/dist/graphql/init.esm.js +0 -1
  84. package/dist/graphql/server.d.mts +88 -0
  85. package/dist/graphql/server.d.ts +88 -0
  86. package/dist/graphql/types.d.mts +21 -0
  87. package/dist/graphql/types.d.ts +21 -0
  88. package/dist/graphql/utils.d.mts +217 -0
  89. package/dist/graphql/utils.d.ts +217 -0
  90. package/dist/index.d.mts +16 -0
  91. package/dist/index.d.ts +16 -0
  92. package/dist/socials/instagram/getters.d.mts +115 -0
  93. package/dist/socials/instagram/getters.d.ts +115 -0
  94. package/dist/socials/instagram/setters.d.mts +18 -0
  95. package/dist/socials/instagram/setters.d.ts +18 -0
  96. package/dist/socials/instagram/types.d.mts +46 -0
  97. package/dist/socials/instagram/types.d.ts +46 -0
  98. package/dist/socials/instagram/utils.d.mts +19 -0
  99. package/dist/socials/instagram/utils.d.ts +19 -0
  100. package/dist/socials/instagram/webhook.d.mts +31 -0
  101. package/dist/socials/instagram/webhook.d.ts +31 -0
  102. package/dist/socials/meta-webhook.d.mts +11 -0
  103. package/dist/socials/meta-webhook.d.ts +11 -0
  104. package/dist/socials/threads/getters.d.mts +57 -0
  105. package/dist/socials/threads/getters.d.ts +57 -0
  106. package/dist/socials/threads/setters.d.mts +59 -0
  107. package/dist/socials/threads/setters.d.ts +59 -0
  108. package/dist/socials/threads/types.d.mts +9 -0
  109. package/dist/socials/threads/types.d.ts +9 -0
  110. package/dist/socials/threads/utils.d.mts +19 -0
  111. package/dist/socials/threads/utils.d.ts +19 -0
  112. package/dist/socials/threads/webhook.d.mts +30 -0
  113. package/dist/socials/threads/webhook.d.ts +30 -0
  114. package/package.json +4 -2
@@ -3,16 +3,129 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
4
  import React__default, { PropsWithChildren } from 'react';
5
5
 
6
+ /**
7
+ * Apollo Client provider for Next.js. Wrap your app (or a subtree) so client components can run GraphQL queries and mutations.
8
+ * The GraphQL endpoint is read from `NEXT_PUBLIC_GRAPHQL_ENDPOINT` env var.
9
+ *
10
+ * Must be placed **inside** `AuthWrapper` (since `useAuthQuery` / `useAuthMutation` depend on the auth token).
11
+ *
12
+ * @param props - Component props.
13
+ * @param props.children - React children (your app or page content).
14
+ * @param props.cacheConfig - Optional `InMemoryCache` config (e.g. `typePolicies`, `addTypename`). Passed to Apollo's `InMemoryCache`.
15
+ * @returns Provider component that supplies Apollo Client to the tree.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * // app/layout.tsx
20
+ * import { AuthWrapper } from "naystack/auth/email/client";
21
+ * import { ApolloWrapper } from "naystack/graphql/client";
22
+ *
23
+ * export default function RootLayout({ children }: { children: React.ReactNode }) {
24
+ * return (
25
+ * <html lang="en">
26
+ * <body>
27
+ * <AuthWrapper>
28
+ * <ApolloWrapper>{children}</ApolloWrapper>
29
+ * </AuthWrapper>
30
+ * </body>
31
+ * </html>
32
+ * );
33
+ * }
34
+ * ```
35
+ *
36
+ * @category GraphQL
37
+ */
6
38
  declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
7
39
  cacheConfig?: InMemoryCacheConfig;
8
40
  }>) => React__default.JSX.Element;
41
+ /**
42
+ * Builds the Apollo link context so requests include the user's Bearer token.
43
+ * Used internally by `useAuthQuery` / `useAuthMutation`; you typically don't call this directly.
44
+ *
45
+ * @param token - The JWT access token. If `null`/`undefined`, returns `undefined` (no auth header).
46
+ * @returns Context object with `headers.authorization` and `credentials: 'omit'`, or `undefined` if no token.
47
+ *
48
+ * @category GraphQL
49
+ */
9
50
  declare const tokenContext: (token?: string | null) => {
10
51
  headers: {
11
52
  authorization: string;
12
53
  };
13
54
  credentials: string;
14
55
  } | undefined;
56
+ /**
57
+ * Hook to run a GraphQL query with the current user's token. The query auto-fires when both the token
58
+ * and variables are available. Returns a refetch function and the Apollo query result.
59
+ *
60
+ * Uses `fetchPolicy: "no-cache"` by default to always get fresh data.
61
+ *
62
+ * @param query - A `TypedDocumentNode` for the query (e.g. from codegen or a `gql` template).
63
+ * @param variables - Optional initial variables. Query fires automatically when this and token are set; change to refetch.
64
+ * @returns Tuple: `[refetch, result]`.
65
+ * - `refetch(input)` — runs the query again with the given input (passed as `variables.input`).
66
+ * - `result` — `{ data, loading, error }` from Apollo.
67
+ *
68
+ * @example Lazy query (no initial variables, manually triggered):
69
+ * ```tsx
70
+ * import { useAuthQuery } from "naystack/graphql/client";
71
+ * import { GET_SUMMARY } from "@/constants/graphql/queries";
72
+ *
73
+ * function SummaryCard({ type }: { type: string }) {
74
+ * const [getSummary, { loading, data }] = useAuthQuery(GET_SUMMARY);
75
+ *
76
+ * const handleFetch = async () => {
77
+ * const result = await getSummary({ type });
78
+ * if (result.data?.getSummary) setSummary(result.data.getSummary);
79
+ * };
80
+ *
81
+ * return <button onClick={handleFetch} disabled={loading}>Get Summary</button>;
82
+ * }
83
+ * ```
84
+ *
85
+ * @example Auto-firing query with variables:
86
+ * ```tsx
87
+ * const [refetch, { data, loading }] = useAuthQuery(GET_ORGANIZATION_DETAILS, { id: orgId });
88
+ * // Query fires automatically when orgId and token are available
89
+ * ```
90
+ *
91
+ * @category GraphQL
92
+ */
15
93
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(input: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
94
+ /**
95
+ * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
96
+ *
97
+ * The input is sent as `variables.input` to the GraphQL endpoint.
98
+ *
99
+ * @param mutation - A `TypedDocumentNode` for the mutation (e.g. from codegen or a `gql` template).
100
+ * @param options - Optional Apollo `MutationHookOptions` (e.g. `onCompleted`, `onError`, `refetchQueries`).
101
+ * @returns Tuple: `[mutate, result]`.
102
+ * - `mutate(input)` — runs the mutation with the given input. Returns a Promise with `{ data }`.
103
+ * - `result` — `{ data, loading, error }` from Apollo.
104
+ *
105
+ * @example
106
+ * ```tsx
107
+ * import { useAuthMutation } from "naystack/graphql/client";
108
+ * import { CREATE_DEAL } from "@/lib/gql/mutations";
109
+ *
110
+ * function CreateDealModal({ propertyId }: { propertyId: number }) {
111
+ * const [createDeal, { loading }] = useAuthMutation(CREATE_DEAL);
112
+ *
113
+ * const onSubmit = async (values: FormFields) => {
114
+ * const response = await createDeal({
115
+ * propertyId,
116
+ * share: Number(values.share),
117
+ * targetProfit: Number(values.targetProfit),
118
+ * });
119
+ * const dealId = response.data?.createDeal;
120
+ * if (dealId) router.push(`/deals/${dealId}`);
121
+ * };
122
+ *
123
+ * return <form onSubmit={handleSubmit(onSubmit)}>...</form>;
124
+ * }
125
+ * ```
126
+ *
127
+ * @category GraphQL
128
+ */
16
129
  declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
130
 
18
131
  export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -3,16 +3,129 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
4
  import React__default, { PropsWithChildren } from 'react';
5
5
 
6
+ /**
7
+ * Apollo Client provider for Next.js. Wrap your app (or a subtree) so client components can run GraphQL queries and mutations.
8
+ * The GraphQL endpoint is read from `NEXT_PUBLIC_GRAPHQL_ENDPOINT` env var.
9
+ *
10
+ * Must be placed **inside** `AuthWrapper` (since `useAuthQuery` / `useAuthMutation` depend on the auth token).
11
+ *
12
+ * @param props - Component props.
13
+ * @param props.children - React children (your app or page content).
14
+ * @param props.cacheConfig - Optional `InMemoryCache` config (e.g. `typePolicies`, `addTypename`). Passed to Apollo's `InMemoryCache`.
15
+ * @returns Provider component that supplies Apollo Client to the tree.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * // app/layout.tsx
20
+ * import { AuthWrapper } from "naystack/auth/email/client";
21
+ * import { ApolloWrapper } from "naystack/graphql/client";
22
+ *
23
+ * export default function RootLayout({ children }: { children: React.ReactNode }) {
24
+ * return (
25
+ * <html lang="en">
26
+ * <body>
27
+ * <AuthWrapper>
28
+ * <ApolloWrapper>{children}</ApolloWrapper>
29
+ * </AuthWrapper>
30
+ * </body>
31
+ * </html>
32
+ * );
33
+ * }
34
+ * ```
35
+ *
36
+ * @category GraphQL
37
+ */
6
38
  declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
7
39
  cacheConfig?: InMemoryCacheConfig;
8
40
  }>) => React__default.JSX.Element;
41
+ /**
42
+ * Builds the Apollo link context so requests include the user's Bearer token.
43
+ * Used internally by `useAuthQuery` / `useAuthMutation`; you typically don't call this directly.
44
+ *
45
+ * @param token - The JWT access token. If `null`/`undefined`, returns `undefined` (no auth header).
46
+ * @returns Context object with `headers.authorization` and `credentials: 'omit'`, or `undefined` if no token.
47
+ *
48
+ * @category GraphQL
49
+ */
9
50
  declare const tokenContext: (token?: string | null) => {
10
51
  headers: {
11
52
  authorization: string;
12
53
  };
13
54
  credentials: string;
14
55
  } | undefined;
56
+ /**
57
+ * Hook to run a GraphQL query with the current user's token. The query auto-fires when both the token
58
+ * and variables are available. Returns a refetch function and the Apollo query result.
59
+ *
60
+ * Uses `fetchPolicy: "no-cache"` by default to always get fresh data.
61
+ *
62
+ * @param query - A `TypedDocumentNode` for the query (e.g. from codegen or a `gql` template).
63
+ * @param variables - Optional initial variables. Query fires automatically when this and token are set; change to refetch.
64
+ * @returns Tuple: `[refetch, result]`.
65
+ * - `refetch(input)` — runs the query again with the given input (passed as `variables.input`).
66
+ * - `result` — `{ data, loading, error }` from Apollo.
67
+ *
68
+ * @example Lazy query (no initial variables, manually triggered):
69
+ * ```tsx
70
+ * import { useAuthQuery } from "naystack/graphql/client";
71
+ * import { GET_SUMMARY } from "@/constants/graphql/queries";
72
+ *
73
+ * function SummaryCard({ type }: { type: string }) {
74
+ * const [getSummary, { loading, data }] = useAuthQuery(GET_SUMMARY);
75
+ *
76
+ * const handleFetch = async () => {
77
+ * const result = await getSummary({ type });
78
+ * if (result.data?.getSummary) setSummary(result.data.getSummary);
79
+ * };
80
+ *
81
+ * return <button onClick={handleFetch} disabled={loading}>Get Summary</button>;
82
+ * }
83
+ * ```
84
+ *
85
+ * @example Auto-firing query with variables:
86
+ * ```tsx
87
+ * const [refetch, { data, loading }] = useAuthQuery(GET_ORGANIZATION_DETAILS, { id: orgId });
88
+ * // Query fires automatically when orgId and token are available
89
+ * ```
90
+ *
91
+ * @category GraphQL
92
+ */
15
93
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(input: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
94
+ /**
95
+ * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
96
+ *
97
+ * The input is sent as `variables.input` to the GraphQL endpoint.
98
+ *
99
+ * @param mutation - A `TypedDocumentNode` for the mutation (e.g. from codegen or a `gql` template).
100
+ * @param options - Optional Apollo `MutationHookOptions` (e.g. `onCompleted`, `onError`, `refetchQueries`).
101
+ * @returns Tuple: `[mutate, result]`.
102
+ * - `mutate(input)` — runs the mutation with the given input. Returns a Promise with `{ data }`.
103
+ * - `result` — `{ data, loading, error }` from Apollo.
104
+ *
105
+ * @example
106
+ * ```tsx
107
+ * import { useAuthMutation } from "naystack/graphql/client";
108
+ * import { CREATE_DEAL } from "@/lib/gql/mutations";
109
+ *
110
+ * function CreateDealModal({ propertyId }: { propertyId: number }) {
111
+ * const [createDeal, { loading }] = useAuthMutation(CREATE_DEAL);
112
+ *
113
+ * const onSubmit = async (values: FormFields) => {
114
+ * const response = await createDeal({
115
+ * propertyId,
116
+ * share: Number(values.share),
117
+ * targetProfit: Number(values.targetProfit),
118
+ * });
119
+ * const dealId = response.data?.createDeal;
120
+ * if (dealId) router.push(`/deals/${dealId}`);
121
+ * };
122
+ *
123
+ * return <form onSubmit={handleSubmit(onSubmit)}>...</form>;
124
+ * }
125
+ * ```
126
+ *
127
+ * @category GraphQL
128
+ */
16
129
  declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
130
 
18
131
  export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -1,5 +1,31 @@
1
1
  import { GraphQLError } from 'graphql/error';
2
2
 
3
+ /**
4
+ * Creates a GraphQL error with an HTTP status code in `extensions.statusCode`.
5
+ * Use in resolvers when validation, authorization, or lookup fails.
6
+ *
7
+ * Default messages by status:
8
+ * - **400** → "Please provide all required inputs"
9
+ * - **403** → "You are not allowed to perform this action"
10
+ * - **404** → "Entity not found"
11
+ * - **other** → "Server Error"
12
+ *
13
+ * @param status - HTTP-like status code (e.g. 400, 403, 404). Defaults to 500.
14
+ * @param message - Override the default message for the status. If omitted, the default above is used.
15
+ * @returns GraphQLError with `extensions.statusCode` set.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { GQLError } from "naystack/graphql";
20
+ *
21
+ * // In a resolver:
22
+ * if (!input.email) throw GQLError(400);
23
+ * if (!ctx.userId) throw GQLError(403);
24
+ * if (!deal) throw GQLError(404, "Deal not found");
25
+ * ```
26
+ *
27
+ * @category GraphQL
28
+ */
3
29
  declare function GQLError(status?: number, message?: string): GraphQLError;
4
30
 
5
31
  export { GQLError };
@@ -1,5 +1,31 @@
1
1
  import { GraphQLError } from 'graphql/error';
2
2
 
3
+ /**
4
+ * Creates a GraphQL error with an HTTP status code in `extensions.statusCode`.
5
+ * Use in resolvers when validation, authorization, or lookup fails.
6
+ *
7
+ * Default messages by status:
8
+ * - **400** → "Please provide all required inputs"
9
+ * - **403** → "You are not allowed to perform this action"
10
+ * - **404** → "Entity not found"
11
+ * - **other** → "Server Error"
12
+ *
13
+ * @param status - HTTP-like status code (e.g. 400, 403, 404). Defaults to 500.
14
+ * @param message - Override the default message for the status. If omitted, the default above is used.
15
+ * @returns GraphQLError with `extensions.statusCode` set.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { GQLError } from "naystack/graphql";
20
+ *
21
+ * // In a resolver:
22
+ * if (!input.email) throw GQLError(400);
23
+ * if (!ctx.userId) throw GQLError(403);
24
+ * if (!deal) throw GQLError(404, "Deal not found");
25
+ * ```
26
+ *
27
+ * @category GraphQL
28
+ */
3
29
  declare function GQLError(status?: number, message?: string): GraphQLError;
4
30
 
5
31
  export { GQLError };
@@ -627,7 +627,6 @@ function getEnv(key, skipCheck) {
627
627
 
628
628
  // src/auth/email/utils.ts
629
629
  var import_jsonwebtoken2 = require("jsonwebtoken");
630
- var import_headers2 = require("next/headers");
631
630
 
632
631
  // src/auth/email/token.ts
633
632
  var import_bcryptjs = require("bcryptjs");
@@ -717,7 +716,7 @@ async function initGraphQLServer({
717
716
  }
718
717
 
719
718
  // src/graphql/utils.ts
720
- var import_headers3 = require("next/headers");
719
+ var import_headers2 = require("next/headers");
721
720
  var import_react = require("react");
722
721
  var import_type_graphql2 = require("type-graphql");
723
722
  function query(fn, options) {
@@ -729,7 +728,7 @@ function query(fn, options) {
729
728
  };
730
729
  }
731
730
  var getUserId = async () => {
732
- const Cookie = await (0, import_headers3.cookies)();
731
+ const Cookie = await (0, import_headers2.cookies)();
733
732
  const refresh = Cookie.get(REFRESH_COOKIE_NAME)?.value;
734
733
  return refresh ? getUserIdFromRefreshToken(refresh) : null;
735
734
  };
@@ -614,7 +614,6 @@ function getEnv(key, skipCheck) {
614
614
 
615
615
  // src/auth/email/utils.ts
616
616
  import { verify as verify2 } from "jsonwebtoken";
617
- import { cookies as cookies2 } from "next/headers";
618
617
 
619
618
  // src/auth/email/token.ts
620
619
  import { compare } from "bcryptjs";
@@ -704,7 +703,7 @@ async function initGraphQLServer({
704
703
  }
705
704
 
706
705
  // src/graphql/utils.ts
707
- import { cookies as cookies3 } from "next/headers";
706
+ import { cookies as cookies2 } from "next/headers";
708
707
  import { cache } from "react";
709
708
  import {
710
709
  Arg,
@@ -725,7 +724,7 @@ function query(fn, options) {
725
724
  };
726
725
  }
727
726
  var getUserId = async () => {
728
- const Cookie = await cookies3();
727
+ const Cookie = await cookies2();
729
728
  const refresh = Cookie.get(REFRESH_COOKIE_NAME)?.value;
730
729
  return refresh ? getUserIdFromRefreshToken(refresh) : null;
731
730
  };
@@ -80,7 +80,6 @@ function getEnv(key, skipCheck) {
80
80
 
81
81
  // src/auth/email/utils.ts
82
82
  var import_jsonwebtoken2 = require("jsonwebtoken");
83
- var import_headers2 = require("next/headers");
84
83
 
85
84
  // src/auth/email/token.ts
86
85
  var import_bcryptjs = require("bcryptjs");
@@ -2,6 +2,39 @@ import { ApolloServerPlugin } from '@apollo/server';
2
2
  import { NextRequest } from 'next/server';
3
3
  import { AuthChecker, NonEmptyArray } from 'type-graphql';
4
4
 
5
+ /**
6
+ * Builds the Apollo GraphQL server and Next.js GET/POST route handlers.
7
+ * Call this at the top level of your GraphQL route file (e.g. `app/api/(graphql)/route.ts`) and export the returned `GET` and `POST`.
8
+ *
9
+ * Uses `type-graphql` to build the schema from the resolver classes you provide (created with `QueryLibrary` and `FieldLibrary`).
10
+ * The default `authChecker` authorizes requests where `context.userId` is truthy.
11
+ * The default `getContext` reads the `Authorization: Bearer` header or the refresh cookie — pass a custom one to override.
12
+ *
13
+ * In production (`NODE_ENV=production`), introspection is disabled and the Apollo production landing page is shown.
14
+ * In development, the Apollo Sandbox is available.
15
+ *
16
+ * @param options - Configuration object.
17
+ * @param options.authChecker - Optional custom type-graphql `AuthChecker`. Default: authorized if `context.userId` is truthy.
18
+ * @param options.resolvers - Array of type-graphql resolver classes (from `QueryLibrary` / `FieldLibrary`). **Required.**
19
+ * @param options.plugins - Optional Apollo Server plugins (e.g. logging, tracing, caching).
20
+ * @param options.getContext - Optional function to build context from the request. Default: reads Bearer token or refresh cookie.
21
+ * Signature: `(req: NextRequest) => Promise<Context> | Context`. Must return at least `{ userId: number | null }`.
22
+ * @returns Promise of `{ GET, POST }` — export these as your route's handlers.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // app/api/(graphql)/route.ts
27
+ * import { initGraphQLServer } from "naystack/graphql";
28
+ * import { UserResolvers, UserFieldResolvers } from "./User/graphql";
29
+ * import { ChatResolvers } from "./Chat/graphql";
30
+ *
31
+ * export const { GET, POST } = await initGraphQLServer({
32
+ * resolvers: [UserResolvers, UserFieldResolvers, ChatResolvers],
33
+ * });
34
+ * ```
35
+ *
36
+ * @category GraphQL
37
+ */
5
38
  declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext: overrideGetContext, }: {
6
39
  authChecker?: AuthChecker<any>;
7
40
  resolvers: NonEmptyArray<Function>;
@@ -2,6 +2,39 @@ import { ApolloServerPlugin } from '@apollo/server';
2
2
  import { NextRequest } from 'next/server';
3
3
  import { AuthChecker, NonEmptyArray } from 'type-graphql';
4
4
 
5
+ /**
6
+ * Builds the Apollo GraphQL server and Next.js GET/POST route handlers.
7
+ * Call this at the top level of your GraphQL route file (e.g. `app/api/(graphql)/route.ts`) and export the returned `GET` and `POST`.
8
+ *
9
+ * Uses `type-graphql` to build the schema from the resolver classes you provide (created with `QueryLibrary` and `FieldLibrary`).
10
+ * The default `authChecker` authorizes requests where `context.userId` is truthy.
11
+ * The default `getContext` reads the `Authorization: Bearer` header or the refresh cookie — pass a custom one to override.
12
+ *
13
+ * In production (`NODE_ENV=production`), introspection is disabled and the Apollo production landing page is shown.
14
+ * In development, the Apollo Sandbox is available.
15
+ *
16
+ * @param options - Configuration object.
17
+ * @param options.authChecker - Optional custom type-graphql `AuthChecker`. Default: authorized if `context.userId` is truthy.
18
+ * @param options.resolvers - Array of type-graphql resolver classes (from `QueryLibrary` / `FieldLibrary`). **Required.**
19
+ * @param options.plugins - Optional Apollo Server plugins (e.g. logging, tracing, caching).
20
+ * @param options.getContext - Optional function to build context from the request. Default: reads Bearer token or refresh cookie.
21
+ * Signature: `(req: NextRequest) => Promise<Context> | Context`. Must return at least `{ userId: number | null }`.
22
+ * @returns Promise of `{ GET, POST }` — export these as your route's handlers.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // app/api/(graphql)/route.ts
27
+ * import { initGraphQLServer } from "naystack/graphql";
28
+ * import { UserResolvers, UserFieldResolvers } from "./User/graphql";
29
+ * import { ChatResolvers } from "./Chat/graphql";
30
+ *
31
+ * export const { GET, POST } = await initGraphQLServer({
32
+ * resolvers: [UserResolvers, UserFieldResolvers, ChatResolvers],
33
+ * });
34
+ * ```
35
+ *
36
+ * @category GraphQL
37
+ */
5
38
  declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext: overrideGetContext, }: {
6
39
  authChecker?: AuthChecker<any>;
7
40
  resolvers: NonEmptyArray<Function>;
@@ -61,7 +61,6 @@ function getEnv(key, skipCheck) {
61
61
 
62
62
  // src/auth/email/utils.ts
63
63
  import { verify as verify2 } from "jsonwebtoken";
64
- import { cookies as cookies2 } from "next/headers";
65
64
 
66
65
  // src/auth/email/token.ts
67
66
  import { compare } from "bcryptjs";
@@ -2,12 +2,67 @@ import { OperationVariables } from '@apollo/client';
2
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
3
  import React__default, { FC } from 'react';
4
4
 
5
+ /** Component props type minus loading and data (inferred from Injector Component). */
5
6
  type OmittedProps<Y> = Omit<Omit<Y, "loading">, "data">;
7
+ /** Props for Injector: either optional or required based on remaining Component props. */
6
8
  type ComponentProps<Y> = OmittedProps<Y> extends Record<string, never> ? {
7
9
  props?: object;
8
10
  } : {
9
11
  props: OmittedProps<Y>;
10
12
  };
13
+ /**
14
+ * Server component that wraps a client component with server-fetched data using Suspense.
15
+ *
16
+ * While the `fetch` function is resolving, the `Component` is rendered with `loading={true}` (and no `data`).
17
+ * Once the fetch resolves, the `Component` re-renders with `loading={false}` and `data` set to the result.
18
+ *
19
+ * This is the primary way to inject server-side data into client components in naystack.
20
+ * Use `.authCall()` or `.call()` from your query definitions inside the `fetch` function.
21
+ *
22
+ * @param injectorProps - Configuration object.
23
+ * @param injectorProps.fetch - Async function that returns the data to pass to the component. Runs on the server.
24
+ * @param injectorProps.Component - React component that receives `{ data?: T; loading: boolean }` plus any extra props.
25
+ * @param injectorProps.props - Optional. Any additional props to pass to `Component`. Required if the Component has props other than `data` and `loading`.
26
+ * @returns A React element that suspends until `fetch()` completes, then renders `Component` with the data.
27
+ *
28
+ * @example Simple usage:
29
+ * ```tsx
30
+ * import { Injector } from "naystack/graphql/server";
31
+ * import getCurrentUser from "@/app/api/(graphql)/User/resolvers/get-current-user";
32
+ * import AuthChecker from "./components/auth-checker";
33
+ *
34
+ * export default async function Layout({ children }: { children: React.ReactNode }) {
35
+ * return (
36
+ * <div>
37
+ * {children}
38
+ * <Injector fetch={getCurrentUser.authCall} Component={AuthChecker} />
39
+ * </div>
40
+ * );
41
+ * }
42
+ * ```
43
+ *
44
+ * @example Fetching multiple queries:
45
+ * ```tsx
46
+ * import { Injector } from "naystack/graphql/server";
47
+ * import getCurrentUser from "@/app/api/(graphql)/User/resolvers/get-current-user";
48
+ * import getChats from "@/app/api/(graphql)/Chat/resolvers/get-chats";
49
+ * import { ChatWindow } from "./components/chat-window";
50
+ *
51
+ * export default async function ChatPage() {
52
+ * return (
53
+ * <Injector
54
+ * fetch={async () => ({
55
+ * user: await getCurrentUser.authCall(),
56
+ * chats: await getChats.authCall(),
57
+ * })}
58
+ * Component={ChatWindow}
59
+ * />
60
+ * );
61
+ * }
62
+ * ```
63
+ *
64
+ * @category GraphQL
65
+ */
11
66
  declare function Injector<T, Y>({ fetch, Component, props, }: {
12
67
  fetch: () => Promise<T>;
13
68
  Component: FC<{
@@ -15,6 +70,39 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
15
70
  loading: boolean;
16
71
  } & Y>;
17
72
  } & ComponentProps<Y>): React__default.JSX.Element;
73
+ /**
74
+ * Runs a raw GraphQL query on the server using the registered Apollo client.
75
+ * Cookies are forwarded automatically so the backend can identify the user.
76
+ *
77
+ * Use this in Server Components, Server Actions, or route handlers when you need to
78
+ * run a query against the GraphQL endpoint (rather than calling a resolver directly with `.call()`/`.authCall()`).
79
+ *
80
+ * Supports Next.js ISR via `revalidate` and on-demand revalidation via `tags`.
81
+ *
82
+ * @param _query - A `TypedDocumentNode` (e.g. from codegen) defining the query and its result type.
83
+ * @param options - Optional query options.
84
+ * @param options.variables - Variables object for the query (must match the document's variable types).
85
+ * @param options.revalidate - Next.js revalidate in seconds; when set, enables caching with this TTL.
86
+ * @param options.tags - Next.js cache tags for on-demand revalidation.
87
+ * @param options.noCookie - If `true`, the request is sent without cookies (unauthenticated).
88
+ * @returns Promise resolving to the query result data (typed by the document).
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import { query } from "naystack/graphql/server";
93
+ * import { GetUserDocument } from "@/generated/graphql";
94
+ *
95
+ * // In a Server Component:
96
+ * const data = await query(GetUserDocument, {
97
+ * variables: { id: userId },
98
+ * revalidate: 60, // Cache for 60s (Next.js ISR)
99
+ * tags: ["user"], // For on-demand revalidation
100
+ * });
101
+ * return <Profile user={data.user} />;
102
+ * ```
103
+ *
104
+ * @category GraphQL
105
+ */
18
106
  declare const query: <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
19
107
  variables?: V;
20
108
  revalidate?: number;