@yimingliao/cms 0.0.78 → 0.0.80

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.
@@ -1,8 +1,21 @@
1
- import { R as Result, S as SuccessResult, a as ErrorResult } from '../types-DHlRoJwv.js';
1
+ import { R as Result, S as SuccessResult, d as ErrorResult, g as AdminFull } from '../types-BGsFazJr.js';
2
2
  import { Logger } from 'logry';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { QueryClient, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
5
5
  import * as _tanstack_query_core from '@tanstack/query-core';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
+ import { c as createVerifyAction } from '../create-verify-action-DBwWOXPO.js';
8
+ import '../types-J25u1G6t.js';
9
+ import '../types-0oS1A2K5.js';
10
+ import 'jsonwebtoken';
11
+ import 'node:crypto';
12
+ import 'next/headers';
13
+ import '@prisma/client';
14
+ import 'zod';
15
+ import 'nodemailer';
16
+ import 'intor';
17
+ import 'keyv';
18
+ import 'zod/v4/core';
6
19
 
7
20
  interface FetchContext {
8
21
  input: string;
@@ -294,4 +307,21 @@ declare function createUseQuery(): <P = void, R = unknown, TData = R>(fn: (param
294
307
  promise: Promise<_tanstack_query_core.NoInfer<TData>>;
295
308
  };
296
309
 
297
- export { type ShowToastOption, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast };
310
+ interface AdminContextValue {
311
+ admin: AdminFull | null;
312
+ setAdmin: (admin: AdminFull | null) => void;
313
+ isLoading: boolean;
314
+ setIsLoading: (loading: boolean) => void;
315
+ }
316
+ declare function AdminProvider({ children }: {
317
+ children: React.ReactNode;
318
+ }): react_jsx_runtime.JSX.Element;
319
+ declare function useAdmin(): AdminContextValue;
320
+
321
+ declare function createAdminInitializer({ useAdmin, useQuery, verifyAction, }: {
322
+ useAdmin: () => AdminContextValue;
323
+ useQuery: ReturnType<typeof createUseQuery>;
324
+ verifyAction: ReturnType<typeof createVerifyAction>;
325
+ }): () => null;
326
+
327
+ export { AdminProvider, type ShowToastOption, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin };
@@ -2,7 +2,7 @@ import { ensureArray } from '../chunk-OAENV763.js';
2
2
  import { toast } from 'sonner';
3
3
  import { jsx, jsxs } from 'react/jsx-runtime';
4
4
  import { useMutation, useQuery } from '@tanstack/react-query';
5
- import { useState } from 'react';
5
+ import { createContext, useState, useContext, useEffect } from 'react';
6
6
 
7
7
  // src/client/infrastructure/fetch/smart-fetch.ts
8
8
  function createSmartFetch({
@@ -124,6 +124,11 @@ var handleToast = (result, showToast) => {
124
124
  }
125
125
  }
126
126
  };
127
+
128
+ // src/client/constants.ts
129
+ var VERIFY_CACHE_KEY = "auth|verify";
130
+
131
+ // src/client/infrastructure/react-query/create-use-command.ts
127
132
  function createUseCommand(queryClient) {
128
133
  return function useCommand(fn, mutationOptions) {
129
134
  const [isRedirecting, setIsRedirecting] = useState(false);
@@ -138,7 +143,7 @@ function createUseCommand(queryClient) {
138
143
  setErrors([]);
139
144
  if (clearAll) {
140
145
  await queryClient.invalidateQueries({
141
- predicate: (query) => !query.queryKey[0].startsWith("auth")
146
+ predicate: ({ queryKey }) => !(queryKey[0] === VERIFY_CACHE_KEY)
142
147
  });
143
148
  }
144
149
  return response.data;
@@ -184,5 +189,50 @@ function createUseQuery() {
184
189
  return { ...query, isNotFound };
185
190
  };
186
191
  }
192
+ var AdminContext = createContext(null);
193
+ function AdminProvider({ children }) {
194
+ const [admin, setAdmin] = useState(null);
195
+ const [isLoading, setIsLoading] = useState(true);
196
+ return /* @__PURE__ */ jsx(
197
+ AdminContext.Provider,
198
+ {
199
+ value: {
200
+ admin,
201
+ setAdmin,
202
+ isLoading,
203
+ setIsLoading
204
+ },
205
+ children
206
+ }
207
+ );
208
+ }
209
+ function useAdmin() {
210
+ const ctx = useContext(AdminContext);
211
+ if (!ctx) throw new Error("useAdmin must be used within AdminProvider");
212
+ return ctx;
213
+ }
214
+ function createAdminInitializer({
215
+ useAdmin: useAdmin2,
216
+ useQuery,
217
+ verifyAction
218
+ }) {
219
+ return function AdminInitializer() {
220
+ const { admin: globalAdmin, setAdmin, setIsLoading } = useAdmin2();
221
+ const { data: admin, isFetching } = useQuery(
222
+ verifyAction,
223
+ [VERIFY_CACHE_KEY],
224
+ {
225
+ select: (data) => data?.admin,
226
+ enabled: !globalAdmin
227
+ }
228
+ );
229
+ useEffect(() => {
230
+ if (isFetching) return;
231
+ if (admin) setAdmin(admin);
232
+ setIsLoading(false);
233
+ }, [isFetching, admin, setAdmin, setIsLoading]);
234
+ return null;
235
+ };
236
+ }
187
237
 
188
- export { createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast };
238
+ export { AdminProvider, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin };