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.
- package/README.md +646 -91
- package/dist/auth/constants.d.mts +4 -0
- package/dist/auth/constants.d.ts +4 -0
- package/dist/auth/email/client.d.mts +149 -0
- package/dist/auth/email/client.d.ts +149 -0
- package/dist/auth/email/index.cjs.js +2 -20
- package/dist/auth/email/index.d.mts +41 -1
- package/dist/auth/email/index.d.ts +41 -1
- package/dist/auth/email/index.esm.js +1 -17
- package/dist/auth/email/routes/delete.cjs.js +0 -1
- package/dist/auth/email/routes/delete.d.mts +5 -0
- package/dist/auth/email/routes/delete.d.ts +5 -0
- package/dist/auth/email/routes/delete.esm.js +0 -1
- package/dist/auth/email/routes/get.d.mts +5 -0
- package/dist/auth/email/routes/get.d.ts +5 -0
- package/dist/auth/email/routes/post.cjs.js +0 -1
- package/dist/auth/email/routes/post.d.mts +5 -0
- package/dist/auth/email/routes/post.d.ts +5 -0
- package/dist/auth/email/routes/post.esm.js +0 -1
- package/dist/auth/email/routes/put.cjs.js +0 -1
- package/dist/auth/email/routes/put.d.mts +5 -0
- package/dist/auth/email/routes/put.d.ts +5 -0
- package/dist/auth/email/routes/put.esm.js +0 -1
- package/dist/auth/email/token.d.mts +62 -0
- package/dist/auth/email/token.d.ts +62 -0
- package/dist/auth/email/types.d.mts +22 -0
- package/dist/auth/email/types.d.ts +22 -0
- package/dist/auth/email/utils.cjs.js +0 -18
- package/dist/auth/email/utils.d.mts +41 -3
- package/dist/auth/email/utils.d.ts +41 -3
- package/dist/auth/email/utils.esm.js +0 -16
- package/dist/auth/google/get.d.mts +5 -0
- package/dist/auth/google/get.d.ts +5 -0
- package/dist/auth/google/index.d.mts +39 -0
- package/dist/auth/google/index.d.ts +39 -0
- package/dist/auth/index.cjs.js +4 -22
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.esm.js +3 -19
- package/dist/auth/instagram/client.d.mts +19 -0
- package/dist/auth/instagram/client.d.ts +19 -0
- package/dist/auth/instagram/index.d.mts +37 -0
- package/dist/auth/instagram/index.d.ts +37 -0
- package/dist/auth/instagram/route.d.mts +5 -0
- package/dist/auth/instagram/route.d.ts +5 -0
- package/dist/auth/instagram/utils.d.mts +13 -0
- package/dist/auth/instagram/utils.d.ts +13 -0
- package/dist/auth/types.d.mts +24 -0
- package/dist/auth/types.d.ts +24 -0
- package/dist/auth/utils/errors.d.mts +10 -0
- package/dist/auth/utils/errors.d.ts +10 -0
- package/dist/auth/utils/token.d.mts +20 -0
- package/dist/auth/utils/token.d.ts +20 -0
- package/dist/client/hooks.d.mts +59 -0
- package/dist/client/hooks.d.ts +59 -0
- package/dist/client/seo.d.mts +46 -0
- package/dist/client/seo.d.ts +46 -0
- package/dist/env.d.mts +61 -0
- package/dist/env.d.ts +61 -0
- package/dist/file/client.d.mts +53 -1
- package/dist/file/client.d.ts +53 -1
- package/dist/file/index.cjs.js +0 -1
- package/dist/file/index.esm.js +0 -1
- package/dist/file/put.cjs.js +0 -1
- package/dist/file/put.d.mts +11 -0
- package/dist/file/put.d.ts +11 -0
- package/dist/file/put.esm.js +0 -1
- package/dist/file/setup.cjs.js +0 -1
- package/dist/file/setup.d.mts +48 -0
- package/dist/file/setup.d.ts +48 -0
- package/dist/file/setup.esm.js +0 -1
- package/dist/file/utils.d.mts +41 -0
- package/dist/file/utils.d.ts +41 -0
- package/dist/graphql/client.d.mts +113 -0
- package/dist/graphql/client.d.ts +113 -0
- package/dist/graphql/errors.d.mts +26 -0
- package/dist/graphql/errors.d.ts +26 -0
- package/dist/graphql/index.cjs.js +2 -3
- package/dist/graphql/index.esm.js +2 -3
- package/dist/graphql/init.cjs.js +0 -1
- package/dist/graphql/init.d.mts +33 -0
- package/dist/graphql/init.d.ts +33 -0
- package/dist/graphql/init.esm.js +0 -1
- package/dist/graphql/server.d.mts +88 -0
- package/dist/graphql/server.d.ts +88 -0
- package/dist/graphql/types.d.mts +21 -0
- package/dist/graphql/types.d.ts +21 -0
- package/dist/graphql/utils.d.mts +217 -0
- package/dist/graphql/utils.d.ts +217 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/socials/instagram/getters.d.mts +115 -0
- package/dist/socials/instagram/getters.d.ts +115 -0
- package/dist/socials/instagram/setters.d.mts +18 -0
- package/dist/socials/instagram/setters.d.ts +18 -0
- package/dist/socials/instagram/types.d.mts +46 -0
- package/dist/socials/instagram/types.d.ts +46 -0
- package/dist/socials/instagram/utils.d.mts +19 -0
- package/dist/socials/instagram/utils.d.ts +19 -0
- package/dist/socials/instagram/webhook.d.mts +31 -0
- package/dist/socials/instagram/webhook.d.ts +31 -0
- package/dist/socials/meta-webhook.d.mts +11 -0
- package/dist/socials/meta-webhook.d.ts +11 -0
- package/dist/socials/threads/getters.d.mts +57 -0
- package/dist/socials/threads/getters.d.ts +57 -0
- package/dist/socials/threads/setters.d.mts +59 -0
- package/dist/socials/threads/setters.d.ts +59 -0
- package/dist/socials/threads/types.d.mts +9 -0
- package/dist/socials/threads/types.d.ts +9 -0
- package/dist/socials/threads/utils.d.mts +19 -0
- package/dist/socials/threads/utils.d.ts +19 -0
- package/dist/socials/threads/webhook.d.mts +30 -0
- package/dist/socials/threads/webhook.d.ts +30 -0
- 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 };
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -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 };
|
package/dist/graphql/errors.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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
|
|
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
|
|
727
|
+
const Cookie = await cookies2();
|
|
729
728
|
const refresh = Cookie.get(REFRESH_COOKIE_NAME)?.value;
|
|
730
729
|
return refresh ? getUserIdFromRefreshToken(refresh) : null;
|
|
731
730
|
};
|
package/dist/graphql/init.cjs.js
CHANGED
package/dist/graphql/init.d.mts
CHANGED
|
@@ -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>;
|
package/dist/graphql/init.d.ts
CHANGED
|
@@ -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>;
|
package/dist/graphql/init.esm.js
CHANGED
|
@@ -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;
|