admin-lib-cms 1.1.6 → 1.1.8

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 CHANGED
@@ -148,7 +148,46 @@ Typically in your `layout.tsx` or `_app.tsx`, pass your adapter and configuratio
148
148
  }
149
149
  ```
150
150
 
151
- 5. Setup Authentication Routes:
151
+ ### 5. Subscription & Billing Integration (Optional)
152
+ `admin-lib-cms` includes an integrated subscription portal to manage your users' active states. To enable it, you need to provide the `apiUrl` and `projectId` props to your `CmsProvider` and `AdminApp` components.
153
+
154
+ **In your CmsProvider Wrapper:**
155
+ ```tsx
156
+ <CmsProvider
157
+ config={cmsConfig}
158
+ adapter={adapter}
159
+ apiUrl={process.env.NEXT_PUBLIC_API_URL}
160
+ projectId={process.env.NEXT_PUBLIC_STRIPE_PROJECT_ID}
161
+ // Optional: If you use a custom backend, specify the exact endpoint to validate the subscription
162
+ validateSubscriptionUrl="https://your-custom-backend.com/api/validate"
163
+ >
164
+ {children}
165
+ </CmsProvider>
166
+ ```
167
+
168
+ If `validateSubscriptionUrl` is omitted, the library will automatically use `${apiUrl}/api/validate-subscription`.
169
+
170
+ **Expected API Request & Response:**
171
+ When validating the subscription, `admin-lib-cms` will make a `POST` request to your endpoint with the following body:
172
+ ```json
173
+ { "projectId": "your-project-id" }
174
+ ```
175
+
176
+ Your API route must return a JSON object with the following structure to properly update the CMS state:
177
+ ```json
178
+ {
179
+ "valid": true,
180
+ "status": "active",
181
+ "expiryDate": "2024-12-31T23:59:59.000Z",
182
+ "_id": "sub_12345",
183
+ "stripeCustomerId": "cus_67890",
184
+ "stripePaymentLink": "https://buy.stripe.com/test_..."
185
+ }
186
+ ```
187
+ *(Note: `_id`, `stripeCustomerId`, and `stripePaymentLink` are optional but required if you want to use the "Manage Billing" and "Pay Now" buttons).*
188
+
189
+
190
+ 6. Setup Authentication Routes:
152
191
  `admin-lib-cms` provides a fully featured authentication system (registration, login, and JWT cookies) that works directly with your Storage Adapter. Create an API route at `app/api/admin/auth/route.ts`:
153
192
 
154
193
  ```tsx
@@ -164,7 +203,7 @@ Typically in your `layout.tsx` or `_app.tsx`, pass your adapter and configuratio
164
203
  export const POST = handler;
165
204
  ```
166
205
 
167
- 6. Setup the Admin Pages (Dashboard & Login):
206
+ 7. Setup the Admin Pages (Dashboard & Login):
168
207
  In your app's routing, create the following pages to render the CMS interface.
169
208
 
170
209
  **Dashboard (`app/admin/page.tsx`):**
@@ -172,7 +211,10 @@ Typically in your `layout.tsx` or `_app.tsx`, pass your adapter and configuratio
172
211
  import { AdminApp } from "admin-lib-cms";
173
212
 
174
213
  export default function AdminPage() {
175
- return <AdminApp />;
214
+ return <AdminApp
215
+ apiUrl={process.env.NEXT_PUBLIC_API_URL}
216
+ projectId={process.env.NEXT_PUBLIC_STRIPE_PROJECT_ID}
217
+ />;
176
218
  }
177
219
  ```
178
220
 
@@ -186,7 +228,7 @@ Typically in your `layout.tsx` or `_app.tsx`, pass your adapter and configuratio
186
228
  }
187
229
  ```
188
230
 
189
- 7. Make elements editable on your pages:
231
+ 8. Make elements editable on your pages:
190
232
 
191
233
  You can use specific `Editable` components depending on the type of content you want to manage.
192
234
 
package/dist/index.d.mts CHANGED
@@ -36,8 +36,12 @@ interface CmsProviderProps {
36
36
  className?: string;
37
37
  }>>;
38
38
  initialOverrides?: OverridesMap;
39
+ apiUrl?: string;
40
+ projectId?: string;
41
+ email?: string;
42
+ validateSubscriptionUrl?: string;
39
43
  }
40
- declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
44
+ declare function CmsProvider(props: CmsProviderProps): react.JSX.Element;
41
45
  /** Hook to submit form data to the CMS inbox. */
42
46
  declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
43
47
 
@@ -61,6 +65,13 @@ interface EditableImageProps extends BaseProps {
61
65
  height?: number;
62
66
  }
63
67
  declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
68
+ interface EditableFileProps extends BaseProps {
69
+ src?: string;
70
+ defaultUrl?: string;
71
+ className?: string;
72
+ children?: (url: string) => React.ReactNode;
73
+ }
74
+ declare function EditableFile({ id, label, section, pageId, src, defaultUrl, className, children, }: EditableFileProps): react.JSX.Element;
64
75
  interface EditableLinkProps extends BaseProps {
65
76
  href: string;
66
77
  children?: React.ReactNode;
@@ -112,6 +123,7 @@ interface SubscriptionContextValue {
112
123
  error: string | null;
113
124
  refetch: (silent?: boolean) => Promise<void>;
114
125
  isSubscriptionActive: boolean;
126
+ daysOverdue: number;
115
127
  config: {
116
128
  apiUrl?: string;
117
129
  projectId?: string;
@@ -119,13 +131,14 @@ interface SubscriptionContextValue {
119
131
  }
120
132
  declare function useSubscriptionContext(): SubscriptionContextValue;
121
133
  declare function useSubscription(): SubscriptionContextValue;
122
- declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
134
+ declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
123
135
  children: ReactNode;
124
136
  apiUrl?: string;
125
137
  projectId?: string;
126
138
  email?: string;
139
+ validateSubscriptionUrl?: string;
127
140
  }): react.JSX.Element;
128
141
 
129
142
  declare function SubscriptionPage(): react.JSX.Element;
130
143
 
131
- export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
144
+ export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableFile, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
package/dist/index.d.ts CHANGED
@@ -36,8 +36,12 @@ interface CmsProviderProps {
36
36
  className?: string;
37
37
  }>>;
38
38
  initialOverrides?: OverridesMap;
39
+ apiUrl?: string;
40
+ projectId?: string;
41
+ email?: string;
42
+ validateSubscriptionUrl?: string;
39
43
  }
40
- declare function CmsProvider({ config, adapter, children, iconMap, initialOverrides }: CmsProviderProps): react.JSX.Element;
44
+ declare function CmsProvider(props: CmsProviderProps): react.JSX.Element;
41
45
  /** Hook to submit form data to the CMS inbox. */
42
46
  declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
43
47
 
@@ -61,6 +65,13 @@ interface EditableImageProps extends BaseProps {
61
65
  height?: number;
62
66
  }
63
67
  declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
68
+ interface EditableFileProps extends BaseProps {
69
+ src?: string;
70
+ defaultUrl?: string;
71
+ className?: string;
72
+ children?: (url: string) => React.ReactNode;
73
+ }
74
+ declare function EditableFile({ id, label, section, pageId, src, defaultUrl, className, children, }: EditableFileProps): react.JSX.Element;
64
75
  interface EditableLinkProps extends BaseProps {
65
76
  href: string;
66
77
  children?: React.ReactNode;
@@ -112,6 +123,7 @@ interface SubscriptionContextValue {
112
123
  error: string | null;
113
124
  refetch: (silent?: boolean) => Promise<void>;
114
125
  isSubscriptionActive: boolean;
126
+ daysOverdue: number;
115
127
  config: {
116
128
  apiUrl?: string;
117
129
  projectId?: string;
@@ -119,13 +131,14 @@ interface SubscriptionContextValue {
119
131
  }
120
132
  declare function useSubscriptionContext(): SubscriptionContextValue;
121
133
  declare function useSubscription(): SubscriptionContextValue;
122
- declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
134
+ declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
123
135
  children: ReactNode;
124
136
  apiUrl?: string;
125
137
  projectId?: string;
126
138
  email?: string;
139
+ validateSubscriptionUrl?: string;
127
140
  }): react.JSX.Element;
128
141
 
129
142
  declare function SubscriptionPage(): react.JSX.Element;
130
143
 
131
- export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
144
+ export { AdminApp, AdminLogin, type AdminLoginProps, CmsConfig, CmsProvider, EditableFile, EditableImage, EditableLink, EditableList, EditableMeta, EditableText, OverridesMap, StorageAdapter, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };