admin-lib-cms 1.1.5 → 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/chunk-WBQAMGXK.mjs +0 -0
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +363 -320
- package/dist/index.mjs +508 -464
- package/dist/types.mjs +1 -0
- 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
|
|
|
File without changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.mjs';
|
|
4
|
+
export { CollectionDef, CollectionEntry, CollectionField, FieldType, GlobalGroup, PageDef, Submission } from './types.mjs';
|
|
4
5
|
export { generateDefaultTemplate, sendEmailNotification } from './emails/index.mjs';
|
|
5
6
|
|
|
6
7
|
interface CmsContextValue {
|
|
@@ -35,8 +36,12 @@ interface CmsProviderProps {
|
|
|
35
36
|
className?: string;
|
|
36
37
|
}>>;
|
|
37
38
|
initialOverrides?: OverridesMap;
|
|
39
|
+
apiUrl?: string;
|
|
40
|
+
projectId?: string;
|
|
41
|
+
email?: string;
|
|
42
|
+
validateSubscriptionUrl?: string;
|
|
38
43
|
}
|
|
39
|
-
declare function CmsProvider(
|
|
44
|
+
declare function CmsProvider(props: CmsProviderProps): react.JSX.Element;
|
|
40
45
|
/** Hook to submit form data to the CMS inbox. */
|
|
41
46
|
declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
|
|
42
47
|
|
|
@@ -62,11 +67,12 @@ interface EditableImageProps extends BaseProps {
|
|
|
62
67
|
declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
|
|
63
68
|
interface EditableLinkProps extends BaseProps {
|
|
64
69
|
href: string;
|
|
65
|
-
children
|
|
70
|
+
children?: React.ReactNode;
|
|
71
|
+
text?: string;
|
|
66
72
|
className?: string;
|
|
67
73
|
target?: string;
|
|
68
74
|
}
|
|
69
|
-
declare function EditableLink({ id, label, section, pageId, href, children, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
75
|
+
declare function EditableLink({ id, label, section, pageId, href, children, text, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
70
76
|
interface EditableListProps<T = any> extends BaseProps {
|
|
71
77
|
initialItems: T[];
|
|
72
78
|
renderItem?: (item: T, index: number) => React.ReactNode;
|
|
@@ -110,6 +116,7 @@ interface SubscriptionContextValue {
|
|
|
110
116
|
error: string | null;
|
|
111
117
|
refetch: (silent?: boolean) => Promise<void>;
|
|
112
118
|
isSubscriptionActive: boolean;
|
|
119
|
+
daysOverdue: number;
|
|
113
120
|
config: {
|
|
114
121
|
apiUrl?: string;
|
|
115
122
|
projectId?: string;
|
|
@@ -117,13 +124,14 @@ interface SubscriptionContextValue {
|
|
|
117
124
|
}
|
|
118
125
|
declare function useSubscriptionContext(): SubscriptionContextValue;
|
|
119
126
|
declare function useSubscription(): SubscriptionContextValue;
|
|
120
|
-
declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
|
|
127
|
+
declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
|
|
121
128
|
children: ReactNode;
|
|
122
129
|
apiUrl?: string;
|
|
123
130
|
projectId?: string;
|
|
124
131
|
email?: string;
|
|
132
|
+
validateSubscriptionUrl?: string;
|
|
125
133
|
}): react.JSX.Element;
|
|
126
134
|
|
|
127
135
|
declare function SubscriptionPage(): react.JSX.Element;
|
|
128
136
|
|
|
129
|
-
export { AdminApp, AdminLogin, type AdminLoginProps, CmsProvider, EditableImage, EditableLink, EditableList, EditableText, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
|
|
137
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.js';
|
|
4
|
+
export { CollectionDef, CollectionEntry, CollectionField, FieldType, GlobalGroup, PageDef, Submission } from './types.js';
|
|
4
5
|
export { generateDefaultTemplate, sendEmailNotification } from './emails/index.js';
|
|
5
6
|
|
|
6
7
|
interface CmsContextValue {
|
|
@@ -35,8 +36,12 @@ interface CmsProviderProps {
|
|
|
35
36
|
className?: string;
|
|
36
37
|
}>>;
|
|
37
38
|
initialOverrides?: OverridesMap;
|
|
39
|
+
apiUrl?: string;
|
|
40
|
+
projectId?: string;
|
|
41
|
+
email?: string;
|
|
42
|
+
validateSubscriptionUrl?: string;
|
|
38
43
|
}
|
|
39
|
-
declare function CmsProvider(
|
|
44
|
+
declare function CmsProvider(props: CmsProviderProps): react.JSX.Element;
|
|
40
45
|
/** Hook to submit form data to the CMS inbox. */
|
|
41
46
|
declare function useSubmit(formId: string): (data: Record<string, unknown>) => Promise<void>;
|
|
42
47
|
|
|
@@ -62,11 +67,12 @@ interface EditableImageProps extends BaseProps {
|
|
|
62
67
|
declare function EditableImage({ id, label, section, pageId, src, alt, className, width, height, }: EditableImageProps): react.JSX.Element;
|
|
63
68
|
interface EditableLinkProps extends BaseProps {
|
|
64
69
|
href: string;
|
|
65
|
-
children
|
|
70
|
+
children?: React.ReactNode;
|
|
71
|
+
text?: string;
|
|
66
72
|
className?: string;
|
|
67
73
|
target?: string;
|
|
68
74
|
}
|
|
69
|
-
declare function EditableLink({ id, label, section, pageId, href, children, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
75
|
+
declare function EditableLink({ id, label, section, pageId, href, children, text, className, target, }: EditableLinkProps): react.JSX.Element;
|
|
70
76
|
interface EditableListProps<T = any> extends BaseProps {
|
|
71
77
|
initialItems: T[];
|
|
72
78
|
renderItem?: (item: T, index: number) => React.ReactNode;
|
|
@@ -110,6 +116,7 @@ interface SubscriptionContextValue {
|
|
|
110
116
|
error: string | null;
|
|
111
117
|
refetch: (silent?: boolean) => Promise<void>;
|
|
112
118
|
isSubscriptionActive: boolean;
|
|
119
|
+
daysOverdue: number;
|
|
113
120
|
config: {
|
|
114
121
|
apiUrl?: string;
|
|
115
122
|
projectId?: string;
|
|
@@ -117,13 +124,14 @@ interface SubscriptionContextValue {
|
|
|
117
124
|
}
|
|
118
125
|
declare function useSubscriptionContext(): SubscriptionContextValue;
|
|
119
126
|
declare function useSubscription(): SubscriptionContextValue;
|
|
120
|
-
declare function SubscriptionProvider({ children, apiUrl, projectId, email, }: {
|
|
127
|
+
declare function SubscriptionProvider({ children, apiUrl, projectId, email, validateSubscriptionUrl, }: {
|
|
121
128
|
children: ReactNode;
|
|
122
129
|
apiUrl?: string;
|
|
123
130
|
projectId?: string;
|
|
124
131
|
email?: string;
|
|
132
|
+
validateSubscriptionUrl?: string;
|
|
125
133
|
}): react.JSX.Element;
|
|
126
134
|
|
|
127
135
|
declare function SubscriptionPage(): react.JSX.Element;
|
|
128
136
|
|
|
129
|
-
export { AdminApp, AdminLogin, type AdminLoginProps, CmsProvider, EditableImage, EditableLink, EditableList, EditableText, type SubscriptionContextValue, type SubscriptionData, SubscriptionPage, SubscriptionProvider, useCmsContext, useCmsOptional, useSubmit, useSubscription, useSubscriptionContext };
|
|
137
|
+
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 };
|