naystack 1.1.17 → 1.2.0

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.
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/auth/email/client.ts
31
+ var client_exports = {};
32
+ __export(client_exports, {
33
+ getEmailAuthUtils: () => getEmailAuthUtils,
34
+ useLoginWithEmail: () => useLoginWithEmail,
35
+ useLogout: () => useLogout,
36
+ useSignUpWithEmail: () => useSignUpWithEmail
37
+ });
38
+ module.exports = __toCommonJS(client_exports);
39
+ var import_react2 = require("react");
40
+
41
+ // src/graphql/client.tsx
42
+ var import_client = require("@apollo/client");
43
+ var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
44
+ var import_react = __toESM(require("react"));
45
+ var TokenContext = (0, import_react.createContext)({
46
+ token: null,
47
+ setToken: () => null
48
+ });
49
+
50
+ // src/auth/email/client.ts
51
+ function useSignUpWithEmail(endpoint) {
52
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
53
+ return (0, import_react2.useCallback)(
54
+ async (data) => {
55
+ const res = await fetch(endpoint, {
56
+ method: "POST",
57
+ body: JSON.stringify(data),
58
+ credentials: "include"
59
+ });
60
+ if (res.ok) {
61
+ const data2 = await res.json();
62
+ setToken(data2.accessToken);
63
+ return null;
64
+ }
65
+ return res.text();
66
+ },
67
+ [setToken]
68
+ );
69
+ }
70
+ function useLoginWithEmail(endpoint) {
71
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
72
+ return (0, import_react2.useCallback)(
73
+ async (data) => {
74
+ const res = await fetch(endpoint, {
75
+ method: "PUT",
76
+ body: JSON.stringify(data),
77
+ credentials: "include"
78
+ });
79
+ if (res.ok) {
80
+ const data2 = await res.json();
81
+ setToken(data2.accessToken);
82
+ return null;
83
+ }
84
+ return res.text();
85
+ },
86
+ [setToken]
87
+ );
88
+ }
89
+ function useLogout(endpoint) {
90
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
91
+ return (0, import_react2.useCallback)(
92
+ async (data) => {
93
+ setToken(null);
94
+ await fetch(endpoint, {
95
+ method: "DELETE",
96
+ credentials: "include",
97
+ body: JSON.stringify(data)
98
+ });
99
+ },
100
+ [setToken]
101
+ );
102
+ }
103
+ function getEmailAuthUtils(endpoint) {
104
+ return {
105
+ useSignUp: () => useSignUpWithEmail(endpoint),
106
+ useLogin: () => useLoginWithEmail(endpoint),
107
+ useLogout: () => useLogout(endpoint)
108
+ };
109
+ }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ getEmailAuthUtils,
113
+ useLoginWithEmail,
114
+ useLogout,
115
+ useSignUpWithEmail
116
+ });
@@ -0,0 +1,10 @@
1
+ declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
2
+ declare function useLoginWithEmail(endpoint: string): (data: object) => Promise<string | null>;
3
+ declare function useLogout(endpoint: string): (data?: object) => Promise<void>;
4
+ declare function getEmailAuthUtils(endpoint: string): {
5
+ useSignUp: () => (data: object) => Promise<string | null>;
6
+ useLogin: () => (data: object) => Promise<string | null>;
7
+ useLogout: () => (data?: object) => Promise<void>;
8
+ };
9
+
10
+ export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail };
@@ -0,0 +1,10 @@
1
+ declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
2
+ declare function useLoginWithEmail(endpoint: string): (data: object) => Promise<string | null>;
3
+ declare function useLogout(endpoint: string): (data?: object) => Promise<void>;
4
+ declare function getEmailAuthUtils(endpoint: string): {
5
+ useSignUp: () => (data: object) => Promise<string | null>;
6
+ useLogin: () => (data: object) => Promise<string | null>;
7
+ useLogout: () => (data?: object) => Promise<void>;
8
+ };
9
+
10
+ export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail };
@@ -0,0 +1,92 @@
1
+ // src/auth/email/client.ts
2
+ import { useCallback as useCallback2, useContext as useContext2 } from "react";
3
+
4
+ // src/graphql/client.tsx
5
+ import {
6
+ HttpLink,
7
+ useLazyQuery,
8
+ useMutation
9
+ } from "@apollo/client";
10
+ import {
11
+ ApolloClient,
12
+ ApolloNextAppProvider,
13
+ InMemoryCache
14
+ } from "@apollo/client-integration-nextjs";
15
+ import React, {
16
+ createContext,
17
+ useCallback,
18
+ useContext,
19
+ useEffect,
20
+ useState
21
+ } from "react";
22
+ var TokenContext = createContext({
23
+ token: null,
24
+ setToken: () => null
25
+ });
26
+
27
+ // src/auth/email/client.ts
28
+ function useSignUpWithEmail(endpoint) {
29
+ const { setToken } = useContext2(TokenContext);
30
+ return useCallback2(
31
+ async (data) => {
32
+ const res = await fetch(endpoint, {
33
+ method: "POST",
34
+ body: JSON.stringify(data),
35
+ credentials: "include"
36
+ });
37
+ if (res.ok) {
38
+ const data2 = await res.json();
39
+ setToken(data2.accessToken);
40
+ return null;
41
+ }
42
+ return res.text();
43
+ },
44
+ [setToken]
45
+ );
46
+ }
47
+ function useLoginWithEmail(endpoint) {
48
+ const { setToken } = useContext2(TokenContext);
49
+ return useCallback2(
50
+ async (data) => {
51
+ const res = await fetch(endpoint, {
52
+ method: "PUT",
53
+ body: JSON.stringify(data),
54
+ credentials: "include"
55
+ });
56
+ if (res.ok) {
57
+ const data2 = await res.json();
58
+ setToken(data2.accessToken);
59
+ return null;
60
+ }
61
+ return res.text();
62
+ },
63
+ [setToken]
64
+ );
65
+ }
66
+ function useLogout(endpoint) {
67
+ const { setToken } = useContext2(TokenContext);
68
+ return useCallback2(
69
+ async (data) => {
70
+ setToken(null);
71
+ await fetch(endpoint, {
72
+ method: "DELETE",
73
+ credentials: "include",
74
+ body: JSON.stringify(data)
75
+ });
76
+ },
77
+ [setToken]
78
+ );
79
+ }
80
+ function getEmailAuthUtils(endpoint) {
81
+ return {
82
+ useSignUp: () => useSignUpWithEmail(endpoint),
83
+ useLogin: () => useLoginWithEmail(endpoint),
84
+ useLogout: () => useLogout(endpoint)
85
+ };
86
+ }
87
+ export {
88
+ getEmailAuthUtils,
89
+ useLoginWithEmail,
90
+ useLogout,
91
+ useSignUpWithEmail
92
+ };
@@ -152,7 +152,7 @@ var getUserContext = (refreshKey, signingKey, req) => {
152
152
 
153
153
  // src/auth/email/routes/delete.ts
154
154
  var getDeleteRoute = (options) => async (req) => {
155
- if (options.onLogout) await options.onLogout?.(await req.text());
155
+ if (options.onLogout) await options.onLogout?.(await req.json());
156
156
  return getTokenizedResponse(void 0, "");
157
157
  };
158
158
 
@@ -126,7 +126,7 @@ var getUserContext = (refreshKey, signingKey, req) => {
126
126
 
127
127
  // src/auth/email/routes/delete.ts
128
128
  var getDeleteRoute = (options) => async (req) => {
129
- if (options.onLogout) await options.onLogout?.(await req.text());
129
+ if (options.onLogout) await options.onLogout?.(await req.json());
130
130
  return getTokenizedResponse(void 0, "");
131
131
  };
132
132
 
@@ -52,7 +52,7 @@ function getTokenizedResponse(accessToken, refreshToken) {
52
52
 
53
53
  // src/auth/email/routes/delete.ts
54
54
  var getDeleteRoute = (options) => async (req) => {
55
- if (options.onLogout) await options.onLogout?.(await req.text());
55
+ if (options.onLogout) await options.onLogout?.(await req.json());
56
56
  return getTokenizedResponse(void 0, "");
57
57
  };
58
58
  // Annotate the CommonJS export names for ESM import in node:
@@ -26,7 +26,7 @@ function getTokenizedResponse(accessToken, refreshToken) {
26
26
 
27
27
  // src/auth/email/routes/delete.ts
28
28
  var getDeleteRoute = (options) => async (req) => {
29
- if (options.onLogout) await options.onLogout?.(await req.text());
29
+ if (options.onLogout) await options.onLogout?.(await req.json());
30
30
  return getTokenizedResponse(void 0, "");
31
31
  };
32
32
  export {
@@ -166,7 +166,7 @@ var getUserContext = (refreshKey, signingKey, req) => {
166
166
 
167
167
  // src/auth/email/routes/delete.ts
168
168
  var getDeleteRoute = (options) => async (req) => {
169
- if (options.onLogout) await options.onLogout?.(await req.text());
169
+ if (options.onLogout) await options.onLogout?.(await req.json());
170
170
  return getTokenizedResponse(void 0, "");
171
171
  };
172
172
 
@@ -138,7 +138,7 @@ var getUserContext = (refreshKey, signingKey, req) => {
138
138
 
139
139
  // src/auth/email/routes/delete.ts
140
140
  var getDeleteRoute = (options) => async (req) => {
141
- if (options.onLogout) await options.onLogout?.(await req.text());
141
+ if (options.onLogout) await options.onLogout?.(await req.json());
142
142
  return getTokenizedResponse(void 0, "");
143
143
  };
144
144
 
@@ -1,6 +1,6 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
 
3
- declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
3
+ declare function useVisibility(onVisible?: () => void): React.RefObject<null>;
4
4
  declare function useBreakpoint(query: string): boolean | null;
5
5
 
6
6
  export { useBreakpoint, useVisibility };
@@ -1,6 +1,6 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
 
3
- declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
3
+ declare function useVisibility(onVisible?: () => void): React.RefObject<null>;
4
4
  declare function useBreakpoint(query: string): boolean | null;
5
5
 
6
6
  export { useBreakpoint, useVisibility };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,19 +17,182 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/client/index.ts
21
31
  var client_exports = {};
22
32
  __export(client_exports, {
33
+ TokenContext: () => TokenContext,
34
+ getApolloWrapper: () => getApolloWrapper,
35
+ getEmailAuthUtils: () => getEmailAuthUtils,
23
36
  getHandleImageUpload: () => getHandleImageUpload,
24
37
  getInstagramAuthorizationURLSetup: () => getInstagramAuthorizationURLSetup,
25
38
  setupSEO: () => setupSEO,
39
+ tokenContext: () => tokenContext,
40
+ useAuthMutation: () => useAuthMutation,
41
+ useAuthQuery: () => useAuthQuery,
26
42
  useBreakpoint: () => useBreakpoint,
43
+ useLoginWithEmail: () => useLoginWithEmail,
44
+ useLogout: () => useLogout,
45
+ useSignUpWithEmail: () => useSignUpWithEmail,
46
+ useToken: () => useToken,
27
47
  useVisibility: () => useVisibility
28
48
  });
29
49
  module.exports = __toCommonJS(client_exports);
30
50
 
51
+ // src/auth/email/client.ts
52
+ var import_react2 = require("react");
53
+
54
+ // src/graphql/client.tsx
55
+ var import_client = require("@apollo/client");
56
+ var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
57
+ var import_react = __toESM(require("react"));
58
+ var TokenContext = (0, import_react.createContext)({
59
+ token: null,
60
+ setToken: () => null
61
+ });
62
+ var getApolloWrapper = ({
63
+ graphqlUri,
64
+ cacheConfig,
65
+ authEndpoint
66
+ }) => {
67
+ function makeClient() {
68
+ return new import_client_integration_nextjs.ApolloClient({
69
+ cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
70
+ link: new import_client.HttpLink({
71
+ uri: graphqlUri
72
+ })
73
+ });
74
+ }
75
+ return ({ children }) => {
76
+ const [token, setToken] = (0, import_react.useState)(null);
77
+ (0, import_react.useEffect)(() => {
78
+ fetch(authEndpoint, {
79
+ credentials: "include"
80
+ }).then((res) => res.json()).then((data) => setToken(data.accessToken));
81
+ }, []);
82
+ return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, /* @__PURE__ */ import_react.default.createElement(TokenContext, { value: { token, setToken } }, children));
83
+ };
84
+ };
85
+ function useToken() {
86
+ const { token } = (0, import_react.useContext)(TokenContext);
87
+ return token;
88
+ }
89
+ var tokenContext = (token) => {
90
+ if (!token) return void 0;
91
+ return {
92
+ headers: {
93
+ authorization: `Bearer ${token}`
94
+ },
95
+ credentials: `omit`
96
+ };
97
+ };
98
+ function useAuthQuery(query, variables) {
99
+ const token = useToken();
100
+ const [fetch2, result] = (0, import_client.useLazyQuery)(query);
101
+ const [calledVars, setCalledVars] = (0, import_react.useState)();
102
+ (0, import_react.useEffect)(() => {
103
+ if (token && variables && calledVars !== JSON.stringify(variables)) {
104
+ setCalledVars(JSON.stringify(variables));
105
+ void fetch2({
106
+ variables,
107
+ context: tokenContext(token),
108
+ fetchPolicy: "no-cache"
109
+ });
110
+ }
111
+ }, [fetch2, token, variables, calledVars]);
112
+ const reFetch = (0, import_react.useCallback)(
113
+ (v) => fetch2({
114
+ variables: v,
115
+ context: tokenContext(token),
116
+ fetchPolicy: "no-cache"
117
+ }),
118
+ [fetch2, token]
119
+ );
120
+ return [reFetch, result];
121
+ }
122
+ function useAuthMutation(mutation, options) {
123
+ const token = useToken();
124
+ const [mutate, result] = (0, import_client.useMutation)(mutation, options);
125
+ const method = (0, import_react.useCallback)(
126
+ (variables) => mutate({
127
+ variables,
128
+ context: tokenContext(token)
129
+ }),
130
+ [token]
131
+ );
132
+ return [method, result];
133
+ }
134
+
135
+ // src/auth/email/client.ts
136
+ function useSignUpWithEmail(endpoint) {
137
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
138
+ return (0, import_react2.useCallback)(
139
+ async (data) => {
140
+ const res = await fetch(endpoint, {
141
+ method: "POST",
142
+ body: JSON.stringify(data),
143
+ credentials: "include"
144
+ });
145
+ if (res.ok) {
146
+ const data2 = await res.json();
147
+ setToken(data2.accessToken);
148
+ return null;
149
+ }
150
+ return res.text();
151
+ },
152
+ [setToken]
153
+ );
154
+ }
155
+ function useLoginWithEmail(endpoint) {
156
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
157
+ return (0, import_react2.useCallback)(
158
+ async (data) => {
159
+ const res = await fetch(endpoint, {
160
+ method: "PUT",
161
+ body: JSON.stringify(data),
162
+ credentials: "include"
163
+ });
164
+ if (res.ok) {
165
+ const data2 = await res.json();
166
+ setToken(data2.accessToken);
167
+ return null;
168
+ }
169
+ return res.text();
170
+ },
171
+ [setToken]
172
+ );
173
+ }
174
+ function useLogout(endpoint) {
175
+ const { setToken } = (0, import_react2.useContext)(TokenContext);
176
+ return (0, import_react2.useCallback)(
177
+ async (data) => {
178
+ setToken(null);
179
+ await fetch(endpoint, {
180
+ method: "DELETE",
181
+ credentials: "include",
182
+ body: JSON.stringify(data)
183
+ });
184
+ },
185
+ [setToken]
186
+ );
187
+ }
188
+ function getEmailAuthUtils(endpoint) {
189
+ return {
190
+ useSignUp: () => useSignUpWithEmail(endpoint),
191
+ useLogin: () => useLoginWithEmail(endpoint),
192
+ useLogout: () => useLogout(endpoint)
193
+ };
194
+ }
195
+
31
196
  // src/auth/instagram/client.ts
32
197
  var getInstagramAuthorizationURLSetup = (clientId, redirectURL) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${redirectURL}`;
33
198
 
@@ -56,10 +221,10 @@ var getHandleImageUpload = (route) => ({
56
221
  };
57
222
 
58
223
  // src/client/hooks.ts
59
- var import_react = require("react");
224
+ var import_react3 = require("react");
60
225
  function useVisibility(onVisible) {
61
- const visibilityRef = (0, import_react.useRef)(null);
62
- (0, import_react.useEffect)(() => {
226
+ const visibilityRef = (0, import_react3.useRef)(null);
227
+ (0, import_react3.useEffect)(() => {
63
228
  if (!onVisible) return;
64
229
  const observer = new IntersectionObserver(
65
230
  (entries) => {
@@ -88,8 +253,8 @@ function useVisibility(onVisible) {
88
253
  return visibilityRef;
89
254
  }
90
255
  function useBreakpoint(query) {
91
- const [matches, setMatches] = (0, import_react.useState)(null);
92
- (0, import_react.useEffect)(() => {
256
+ const [matches, setMatches] = (0, import_react3.useState)(null);
257
+ (0, import_react3.useEffect)(() => {
93
258
  if (typeof window === "undefined") return;
94
259
  const media = window.matchMedia(query);
95
260
  setMatches(media.matches);
@@ -125,9 +290,19 @@ var setupSEO = (SEO) => (title, description, image) => ({
125
290
  });
126
291
  // Annotate the CommonJS export names for ESM import in node:
127
292
  0 && (module.exports = {
293
+ TokenContext,
294
+ getApolloWrapper,
295
+ getEmailAuthUtils,
128
296
  getHandleImageUpload,
129
297
  getInstagramAuthorizationURLSetup,
130
298
  setupSEO,
299
+ tokenContext,
300
+ useAuthMutation,
301
+ useAuthQuery,
131
302
  useBreakpoint,
303
+ useLoginWithEmail,
304
+ useLogout,
305
+ useSignUpWithEmail,
306
+ useToken,
132
307
  useVisibility
133
308
  });
@@ -1,6 +1,11 @@
1
+ export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail } from '../auth/email/client.mjs';
1
2
  export { getInstagramAuthorizationURLSetup } from '../auth/instagram/client.mjs';
2
3
  export { ImageUploadResponseType, getHandleImageUpload } from '../file/client.mjs';
4
+ export { TokenContext, getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery, useToken } from '../graphql/client.mjs';
3
5
  export { useBreakpoint, useVisibility } from './hooks.mjs';
4
6
  export { setupSEO } from './seo.mjs';
7
+ import '@apollo/client';
8
+ import '@apollo/client/cache';
9
+ import '@graphql-typed-document-node/core';
5
10
  import 'react';
6
11
  import 'next';
@@ -1,6 +1,11 @@
1
+ export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail } from '../auth/email/client.js';
1
2
  export { getInstagramAuthorizationURLSetup } from '../auth/instagram/client.js';
2
3
  export { ImageUploadResponseType, getHandleImageUpload } from '../file/client.js';
4
+ export { TokenContext, getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery, useToken } from '../graphql/client.js';
3
5
  export { useBreakpoint, useVisibility } from './hooks.js';
4
6
  export { setupSEO } from './seo.js';
7
+ import '@apollo/client';
8
+ import '@apollo/client/cache';
9
+ import '@graphql-typed-document-node/core';
5
10
  import 'react';
6
11
  import 'next';