admin-lib-cms 1.1.6 → 1.1.7
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 +46 -4
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +358 -317
- package/dist/index.mjs +502 -461
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
|
@@ -112,6 +116,7 @@ interface SubscriptionContextValue {
|
|
|
112
116
|
error: string | null;
|
|
113
117
|
refetch: (silent?: boolean) => Promise<void>;
|
|
114
118
|
isSubscriptionActive: boolean;
|
|
119
|
+
daysOverdue: number;
|
|
115
120
|
config: {
|
|
116
121
|
apiUrl?: string;
|
|
117
122
|
projectId?: string;
|
|
@@ -119,11 +124,12 @@ interface SubscriptionContextValue {
|
|
|
119
124
|
}
|
|
120
125
|
declare function useSubscriptionContext(): SubscriptionContextValue;
|
|
121
126
|
declare function useSubscription(): SubscriptionContextValue;
|
|
122
|
-
declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
|
|
127
|
+
declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
|
|
123
128
|
children: ReactNode;
|
|
124
129
|
apiUrl?: string;
|
|
125
130
|
projectId?: string;
|
|
126
131
|
email?: string;
|
|
132
|
+
validateSubscriptionUrl?: string;
|
|
127
133
|
}): react.JSX.Element;
|
|
128
134
|
|
|
129
135
|
declare function SubscriptionPage(): react.JSX.Element;
|
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(
|
|
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
|
|
|
@@ -112,6 +116,7 @@ interface SubscriptionContextValue {
|
|
|
112
116
|
error: string | null;
|
|
113
117
|
refetch: (silent?: boolean) => Promise<void>;
|
|
114
118
|
isSubscriptionActive: boolean;
|
|
119
|
+
daysOverdue: number;
|
|
115
120
|
config: {
|
|
116
121
|
apiUrl?: string;
|
|
117
122
|
projectId?: string;
|
|
@@ -119,11 +124,12 @@ interface SubscriptionContextValue {
|
|
|
119
124
|
}
|
|
120
125
|
declare function useSubscriptionContext(): SubscriptionContextValue;
|
|
121
126
|
declare function useSubscription(): SubscriptionContextValue;
|
|
122
|
-
declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
|
|
127
|
+
declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
|
|
123
128
|
children: ReactNode;
|
|
124
129
|
apiUrl?: string;
|
|
125
130
|
projectId?: string;
|
|
126
131
|
email?: string;
|
|
132
|
+
validateSubscriptionUrl?: string;
|
|
127
133
|
}): react.JSX.Element;
|
|
128
134
|
|
|
129
135
|
declare function SubscriptionPage(): react.JSX.Element;
|