admin-lib-cms 1.2.17 → 1.2.19
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 +29 -0
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +2206 -1091
- package/dist/index.mjs +2224 -1099
- package/dist/storage.js +70 -26
- package/dist/storage.mjs +70 -26
- package/dist/types.d.mts +36 -1
- package/dist/types.d.ts +36 -1
- package/package.json +3 -2
package/dist/storage.js
CHANGED
|
@@ -248,23 +248,45 @@ function createSanityAdapter(config) {
|
|
|
248
248
|
}
|
|
249
249
|
await writeClient.delete(`cms_entry_${collectionId}_${entryId}`);
|
|
250
250
|
}
|
|
251
|
+
const listEntriesCache = /* @__PURE__ */ new Map();
|
|
252
|
+
const inFlightListEntries = /* @__PURE__ */ new Map();
|
|
253
|
+
let inFlightOverrides = null;
|
|
254
|
+
let overridesCache = null;
|
|
255
|
+
const CACHE_TTL_MS = 3e3;
|
|
251
256
|
return {
|
|
252
257
|
name: "sanity",
|
|
253
258
|
async getOverrides() {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return JSON.parse(doc.data);
|
|
261
|
-
}
|
|
262
|
-
} catch (err) {
|
|
263
|
-
console.error("Sanity Adapter: failed to fetch overrides", err);
|
|
259
|
+
const now = Date.now();
|
|
260
|
+
if (overridesCache && now - overridesCache.timestamp < CACHE_TTL_MS) {
|
|
261
|
+
return overridesCache.data;
|
|
262
|
+
}
|
|
263
|
+
if (inFlightOverrides) {
|
|
264
|
+
return inFlightOverrides;
|
|
264
265
|
}
|
|
265
|
-
|
|
266
|
+
inFlightOverrides = (async () => {
|
|
267
|
+
try {
|
|
268
|
+
let res = {};
|
|
269
|
+
if (canUseApi()) {
|
|
270
|
+
res = await apiRequest(apiBase, "/overrides");
|
|
271
|
+
} else {
|
|
272
|
+
const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
|
|
273
|
+
if (doc && typeof doc.data === "string") {
|
|
274
|
+
res = JSON.parse(doc.data);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
overridesCache = { timestamp: Date.now(), data: res };
|
|
278
|
+
return res;
|
|
279
|
+
} catch (err) {
|
|
280
|
+
console.error("Sanity Adapter: failed to fetch overrides", err);
|
|
281
|
+
return {};
|
|
282
|
+
} finally {
|
|
283
|
+
inFlightOverrides = null;
|
|
284
|
+
}
|
|
285
|
+
})();
|
|
286
|
+
return inFlightOverrides;
|
|
266
287
|
},
|
|
267
288
|
async setOverrides(map) {
|
|
289
|
+
overridesCache = null;
|
|
268
290
|
try {
|
|
269
291
|
await writeOverrides(map);
|
|
270
292
|
} catch (err) {
|
|
@@ -272,25 +294,45 @@ function createSanityAdapter(config) {
|
|
|
272
294
|
}
|
|
273
295
|
},
|
|
274
296
|
async listEntries(collectionId) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
297
|
+
const now = Date.now();
|
|
298
|
+
const cached = listEntriesCache.get(collectionId);
|
|
299
|
+
if (cached && now - cached.timestamp < CACHE_TTL_MS) {
|
|
300
|
+
return cached.data;
|
|
301
|
+
}
|
|
302
|
+
if (inFlightListEntries.has(collectionId)) {
|
|
303
|
+
return inFlightListEntries.get(collectionId);
|
|
304
|
+
}
|
|
305
|
+
const p = (async () => {
|
|
306
|
+
try {
|
|
307
|
+
let entries = [];
|
|
308
|
+
if (canUseApi()) {
|
|
309
|
+
entries = await apiRequest(
|
|
310
|
+
apiBase,
|
|
311
|
+
`/entries?collectionId=${encodeURIComponent(collectionId)}`
|
|
312
|
+
);
|
|
313
|
+
} else {
|
|
314
|
+
const query = `*[_type == "cms_entry" && collectionId == $collectionId]`;
|
|
315
|
+
const docs = await readClient.fetch(query, { collectionId });
|
|
316
|
+
entries = docs.map((doc) => JSON.parse(doc.data));
|
|
317
|
+
}
|
|
318
|
+
listEntriesCache.set(collectionId, { timestamp: Date.now(), data: entries });
|
|
319
|
+
return entries;
|
|
320
|
+
} catch (err) {
|
|
321
|
+
console.error(
|
|
322
|
+
`Sanity Adapter: failed to list entries for ${collectionId}`,
|
|
323
|
+
err
|
|
280
324
|
);
|
|
325
|
+
return [];
|
|
326
|
+
} finally {
|
|
327
|
+
inFlightListEntries.delete(collectionId);
|
|
281
328
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
} catch (err) {
|
|
286
|
-
console.error(
|
|
287
|
-
`Sanity Adapter: failed to list entries for ${collectionId}`,
|
|
288
|
-
err
|
|
289
|
-
);
|
|
290
|
-
return [];
|
|
291
|
-
}
|
|
329
|
+
})();
|
|
330
|
+
inFlightListEntries.set(collectionId, p);
|
|
331
|
+
return p;
|
|
292
332
|
},
|
|
293
333
|
async putEntry(collectionId, entry) {
|
|
334
|
+
listEntriesCache.delete(collectionId);
|
|
335
|
+
inFlightListEntries.delete(collectionId);
|
|
294
336
|
try {
|
|
295
337
|
await writeEntry(collectionId, entry);
|
|
296
338
|
} catch (err) {
|
|
@@ -298,6 +340,8 @@ function createSanityAdapter(config) {
|
|
|
298
340
|
}
|
|
299
341
|
},
|
|
300
342
|
async deleteEntry(collectionId, entryId) {
|
|
343
|
+
listEntriesCache.delete(collectionId);
|
|
344
|
+
inFlightListEntries.delete(collectionId);
|
|
301
345
|
try {
|
|
302
346
|
await removeEntry(collectionId, entryId);
|
|
303
347
|
} catch (err) {
|
package/dist/storage.mjs
CHANGED
|
@@ -220,23 +220,45 @@ function createSanityAdapter(config) {
|
|
|
220
220
|
}
|
|
221
221
|
await writeClient.delete(`cms_entry_${collectionId}_${entryId}`);
|
|
222
222
|
}
|
|
223
|
+
const listEntriesCache = /* @__PURE__ */ new Map();
|
|
224
|
+
const inFlightListEntries = /* @__PURE__ */ new Map();
|
|
225
|
+
let inFlightOverrides = null;
|
|
226
|
+
let overridesCache = null;
|
|
227
|
+
const CACHE_TTL_MS = 3e3;
|
|
223
228
|
return {
|
|
224
229
|
name: "sanity",
|
|
225
230
|
async getOverrides() {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return JSON.parse(doc.data);
|
|
233
|
-
}
|
|
234
|
-
} catch (err) {
|
|
235
|
-
console.error("Sanity Adapter: failed to fetch overrides", err);
|
|
231
|
+
const now = Date.now();
|
|
232
|
+
if (overridesCache && now - overridesCache.timestamp < CACHE_TTL_MS) {
|
|
233
|
+
return overridesCache.data;
|
|
234
|
+
}
|
|
235
|
+
if (inFlightOverrides) {
|
|
236
|
+
return inFlightOverrides;
|
|
236
237
|
}
|
|
237
|
-
|
|
238
|
+
inFlightOverrides = (async () => {
|
|
239
|
+
try {
|
|
240
|
+
let res = {};
|
|
241
|
+
if (canUseApi()) {
|
|
242
|
+
res = await apiRequest(apiBase, "/overrides");
|
|
243
|
+
} else {
|
|
244
|
+
const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
|
|
245
|
+
if (doc && typeof doc.data === "string") {
|
|
246
|
+
res = JSON.parse(doc.data);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
overridesCache = { timestamp: Date.now(), data: res };
|
|
250
|
+
return res;
|
|
251
|
+
} catch (err) {
|
|
252
|
+
console.error("Sanity Adapter: failed to fetch overrides", err);
|
|
253
|
+
return {};
|
|
254
|
+
} finally {
|
|
255
|
+
inFlightOverrides = null;
|
|
256
|
+
}
|
|
257
|
+
})();
|
|
258
|
+
return inFlightOverrides;
|
|
238
259
|
},
|
|
239
260
|
async setOverrides(map) {
|
|
261
|
+
overridesCache = null;
|
|
240
262
|
try {
|
|
241
263
|
await writeOverrides(map);
|
|
242
264
|
} catch (err) {
|
|
@@ -244,25 +266,45 @@ function createSanityAdapter(config) {
|
|
|
244
266
|
}
|
|
245
267
|
},
|
|
246
268
|
async listEntries(collectionId) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
269
|
+
const now = Date.now();
|
|
270
|
+
const cached = listEntriesCache.get(collectionId);
|
|
271
|
+
if (cached && now - cached.timestamp < CACHE_TTL_MS) {
|
|
272
|
+
return cached.data;
|
|
273
|
+
}
|
|
274
|
+
if (inFlightListEntries.has(collectionId)) {
|
|
275
|
+
return inFlightListEntries.get(collectionId);
|
|
276
|
+
}
|
|
277
|
+
const p = (async () => {
|
|
278
|
+
try {
|
|
279
|
+
let entries = [];
|
|
280
|
+
if (canUseApi()) {
|
|
281
|
+
entries = await apiRequest(
|
|
282
|
+
apiBase,
|
|
283
|
+
`/entries?collectionId=${encodeURIComponent(collectionId)}`
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
const query = `*[_type == "cms_entry" && collectionId == $collectionId]`;
|
|
287
|
+
const docs = await readClient.fetch(query, { collectionId });
|
|
288
|
+
entries = docs.map((doc) => JSON.parse(doc.data));
|
|
289
|
+
}
|
|
290
|
+
listEntriesCache.set(collectionId, { timestamp: Date.now(), data: entries });
|
|
291
|
+
return entries;
|
|
292
|
+
} catch (err) {
|
|
293
|
+
console.error(
|
|
294
|
+
`Sanity Adapter: failed to list entries for ${collectionId}`,
|
|
295
|
+
err
|
|
252
296
|
);
|
|
297
|
+
return [];
|
|
298
|
+
} finally {
|
|
299
|
+
inFlightListEntries.delete(collectionId);
|
|
253
300
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
} catch (err) {
|
|
258
|
-
console.error(
|
|
259
|
-
`Sanity Adapter: failed to list entries for ${collectionId}`,
|
|
260
|
-
err
|
|
261
|
-
);
|
|
262
|
-
return [];
|
|
263
|
-
}
|
|
301
|
+
})();
|
|
302
|
+
inFlightListEntries.set(collectionId, p);
|
|
303
|
+
return p;
|
|
264
304
|
},
|
|
265
305
|
async putEntry(collectionId, entry) {
|
|
306
|
+
listEntriesCache.delete(collectionId);
|
|
307
|
+
inFlightListEntries.delete(collectionId);
|
|
266
308
|
try {
|
|
267
309
|
await writeEntry(collectionId, entry);
|
|
268
310
|
} catch (err) {
|
|
@@ -270,6 +312,8 @@ function createSanityAdapter(config) {
|
|
|
270
312
|
}
|
|
271
313
|
},
|
|
272
314
|
async deleteEntry(collectionId, entryId) {
|
|
315
|
+
listEntriesCache.delete(collectionId);
|
|
316
|
+
inFlightListEntries.delete(collectionId);
|
|
273
317
|
try {
|
|
274
318
|
await removeEntry(collectionId, entryId);
|
|
275
319
|
} catch (err) {
|
package/dist/types.d.mts
CHANGED
|
@@ -32,7 +32,7 @@ interface PageDef {
|
|
|
32
32
|
interface CollectionField {
|
|
33
33
|
id: string;
|
|
34
34
|
label: string;
|
|
35
|
-
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug" | "
|
|
35
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug" | "time" | "time-range" | "date" | "datetime" | "signature";
|
|
36
36
|
startField?: string;
|
|
37
37
|
endField?: string;
|
|
38
38
|
options?: string[] | {
|
|
@@ -61,6 +61,7 @@ interface CollectionField {
|
|
|
61
61
|
})[]>;
|
|
62
62
|
colSpan?: 1 | 2 | 6 | 12;
|
|
63
63
|
readOnly?: boolean;
|
|
64
|
+
formatter?: boolean;
|
|
64
65
|
required?: boolean;
|
|
65
66
|
unique?: boolean;
|
|
66
67
|
customRender?: (props: {
|
|
@@ -73,6 +74,7 @@ interface CollectionField {
|
|
|
73
74
|
}) => React.ReactNode;
|
|
74
75
|
onCellClick?: (value: any, record: any) => void;
|
|
75
76
|
renderCell?: (value: any, record: any) => React.ReactNode;
|
|
77
|
+
formatExport?: (value: any, record: any) => string | number | boolean;
|
|
76
78
|
onSelectRecord?: (record: any, currentValues: any) => Record<string, any>;
|
|
77
79
|
}
|
|
78
80
|
interface CollectionDef {
|
|
@@ -91,9 +93,35 @@ interface CollectionDef {
|
|
|
91
93
|
enableDetailView?: boolean;
|
|
92
94
|
enableQuickCreate?: boolean;
|
|
93
95
|
onViewRecord?: (record: any) => void;
|
|
96
|
+
customDetailView?: (props: {
|
|
97
|
+
record: any;
|
|
98
|
+
isEditing?: boolean;
|
|
99
|
+
onBack: () => void;
|
|
100
|
+
reload: () => Promise<void> | void;
|
|
101
|
+
}) => React.ReactNode;
|
|
102
|
+
renderCustomDetail?: (props: {
|
|
103
|
+
record: any;
|
|
104
|
+
isEditing?: boolean;
|
|
105
|
+
onBack: () => void;
|
|
106
|
+
reload: () => Promise<void> | void;
|
|
107
|
+
}) => React.ReactNode;
|
|
108
|
+
customEditView?: (props: {
|
|
109
|
+
record: any;
|
|
110
|
+
isEditing?: boolean;
|
|
111
|
+
onBack: () => void;
|
|
112
|
+
reload: () => Promise<void> | void;
|
|
113
|
+
}) => React.ReactNode;
|
|
114
|
+
customCreateView?: (props: {
|
|
115
|
+
onBack: () => void;
|
|
116
|
+
reload: () => Promise<void> | void;
|
|
117
|
+
}) => React.ReactNode;
|
|
94
118
|
viewRecordTitle?: string;
|
|
95
119
|
disableEdit?: boolean;
|
|
96
120
|
disableDelete?: boolean;
|
|
121
|
+
hideDelete?: boolean;
|
|
122
|
+
canDelete?: (record: any) => boolean;
|
|
123
|
+
disableExport?: boolean;
|
|
124
|
+
disableImport?: boolean;
|
|
97
125
|
onDownloadPdf?: (record: any) => void;
|
|
98
126
|
canDownloadPdf?: (record: any) => boolean;
|
|
99
127
|
defaultSort?: {
|
|
@@ -104,6 +132,11 @@ interface CollectionDef {
|
|
|
104
132
|
record: any;
|
|
105
133
|
openDetail: () => void;
|
|
106
134
|
openEdit: () => void;
|
|
135
|
+
openCustomView?: (renderFn: (props: {
|
|
136
|
+
onBack: () => void;
|
|
137
|
+
reload: () => Promise<void> | void;
|
|
138
|
+
}) => React.ReactNode) => void;
|
|
139
|
+
reload: () => Promise<void> | void;
|
|
107
140
|
}) => React.ReactNode;
|
|
108
141
|
}
|
|
109
142
|
interface GlobalGroup {
|
|
@@ -124,6 +157,8 @@ interface CmsConfig {
|
|
|
124
157
|
siteName?: string;
|
|
125
158
|
locale?: "es" | "en" | string;
|
|
126
159
|
lang?: "es" | "en" | string;
|
|
160
|
+
currency?: string;
|
|
161
|
+
currencyLocale?: string;
|
|
127
162
|
pages: PageDef[];
|
|
128
163
|
collections?: CollectionDef[];
|
|
129
164
|
globals?: GlobalGroup[];
|
package/dist/types.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface PageDef {
|
|
|
32
32
|
interface CollectionField {
|
|
33
33
|
id: string;
|
|
34
34
|
label: string;
|
|
35
|
-
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug" | "
|
|
35
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug" | "time" | "time-range" | "date" | "datetime" | "signature";
|
|
36
36
|
startField?: string;
|
|
37
37
|
endField?: string;
|
|
38
38
|
options?: string[] | {
|
|
@@ -61,6 +61,7 @@ interface CollectionField {
|
|
|
61
61
|
})[]>;
|
|
62
62
|
colSpan?: 1 | 2 | 6 | 12;
|
|
63
63
|
readOnly?: boolean;
|
|
64
|
+
formatter?: boolean;
|
|
64
65
|
required?: boolean;
|
|
65
66
|
unique?: boolean;
|
|
66
67
|
customRender?: (props: {
|
|
@@ -73,6 +74,7 @@ interface CollectionField {
|
|
|
73
74
|
}) => React.ReactNode;
|
|
74
75
|
onCellClick?: (value: any, record: any) => void;
|
|
75
76
|
renderCell?: (value: any, record: any) => React.ReactNode;
|
|
77
|
+
formatExport?: (value: any, record: any) => string | number | boolean;
|
|
76
78
|
onSelectRecord?: (record: any, currentValues: any) => Record<string, any>;
|
|
77
79
|
}
|
|
78
80
|
interface CollectionDef {
|
|
@@ -91,9 +93,35 @@ interface CollectionDef {
|
|
|
91
93
|
enableDetailView?: boolean;
|
|
92
94
|
enableQuickCreate?: boolean;
|
|
93
95
|
onViewRecord?: (record: any) => void;
|
|
96
|
+
customDetailView?: (props: {
|
|
97
|
+
record: any;
|
|
98
|
+
isEditing?: boolean;
|
|
99
|
+
onBack: () => void;
|
|
100
|
+
reload: () => Promise<void> | void;
|
|
101
|
+
}) => React.ReactNode;
|
|
102
|
+
renderCustomDetail?: (props: {
|
|
103
|
+
record: any;
|
|
104
|
+
isEditing?: boolean;
|
|
105
|
+
onBack: () => void;
|
|
106
|
+
reload: () => Promise<void> | void;
|
|
107
|
+
}) => React.ReactNode;
|
|
108
|
+
customEditView?: (props: {
|
|
109
|
+
record: any;
|
|
110
|
+
isEditing?: boolean;
|
|
111
|
+
onBack: () => void;
|
|
112
|
+
reload: () => Promise<void> | void;
|
|
113
|
+
}) => React.ReactNode;
|
|
114
|
+
customCreateView?: (props: {
|
|
115
|
+
onBack: () => void;
|
|
116
|
+
reload: () => Promise<void> | void;
|
|
117
|
+
}) => React.ReactNode;
|
|
94
118
|
viewRecordTitle?: string;
|
|
95
119
|
disableEdit?: boolean;
|
|
96
120
|
disableDelete?: boolean;
|
|
121
|
+
hideDelete?: boolean;
|
|
122
|
+
canDelete?: (record: any) => boolean;
|
|
123
|
+
disableExport?: boolean;
|
|
124
|
+
disableImport?: boolean;
|
|
97
125
|
onDownloadPdf?: (record: any) => void;
|
|
98
126
|
canDownloadPdf?: (record: any) => boolean;
|
|
99
127
|
defaultSort?: {
|
|
@@ -104,6 +132,11 @@ interface CollectionDef {
|
|
|
104
132
|
record: any;
|
|
105
133
|
openDetail: () => void;
|
|
106
134
|
openEdit: () => void;
|
|
135
|
+
openCustomView?: (renderFn: (props: {
|
|
136
|
+
onBack: () => void;
|
|
137
|
+
reload: () => Promise<void> | void;
|
|
138
|
+
}) => React.ReactNode) => void;
|
|
139
|
+
reload: () => Promise<void> | void;
|
|
107
140
|
}) => React.ReactNode;
|
|
108
141
|
}
|
|
109
142
|
interface GlobalGroup {
|
|
@@ -124,6 +157,8 @@ interface CmsConfig {
|
|
|
124
157
|
siteName?: string;
|
|
125
158
|
locale?: "es" | "en" | string;
|
|
126
159
|
lang?: "es" | "en" | string;
|
|
160
|
+
currency?: string;
|
|
161
|
+
currencyLocale?: string;
|
|
127
162
|
pages: PageDef[];
|
|
128
163
|
collections?: CollectionDef[];
|
|
129
164
|
globals?: GlobalGroup[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "admin-lib-cms",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.19",
|
|
4
4
|
"description": "Agnostic Admin CMS Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -78,7 +78,8 @@
|
|
|
78
78
|
"bcryptjs": "^3.0.3",
|
|
79
79
|
"dayjs": "^1.11.23",
|
|
80
80
|
"jose": "^6.2.3",
|
|
81
|
-
"lucide-react": "^0.300.0"
|
|
81
|
+
"lucide-react": "^0.300.0",
|
|
82
|
+
"xlsx": "^0.18.5"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
85
|
"@sanity/client": "^8.6.2",
|