admin-lib-cms 1.2.16 → 1.2.18

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/dist/storage.js CHANGED
@@ -174,7 +174,15 @@ function createWriteClient(config) {
174
174
  });
175
175
  }
176
176
  async function apiRequest(apiBase, path, init) {
177
- const res = await fetch(`${apiBase}${path}`, init);
177
+ const res = await fetch(`${apiBase}${path}`, {
178
+ cache: "no-store",
179
+ ...init,
180
+ headers: {
181
+ "Cache-Control": "no-cache",
182
+ Pragma: "no-cache",
183
+ ...init?.headers
184
+ }
185
+ });
178
186
  if (!res.ok) {
179
187
  const text = await res.text();
180
188
  throw new Error(text || `API error ${res.status}`);
@@ -240,23 +248,45 @@ function createSanityAdapter(config) {
240
248
  }
241
249
  await writeClient.delete(`cms_entry_${collectionId}_${entryId}`);
242
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;
243
256
  return {
244
257
  name: "sanity",
245
258
  async getOverrides() {
246
- try {
247
- if (canUseApi()) {
248
- return await apiRequest(apiBase, "/overrides");
249
- }
250
- const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
251
- if (doc && typeof doc.data === "string") {
252
- return JSON.parse(doc.data);
253
- }
254
- } catch (err) {
255
- 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;
256
262
  }
257
- return {};
263
+ if (inFlightOverrides) {
264
+ return inFlightOverrides;
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;
258
287
  },
259
288
  async setOverrides(map) {
289
+ overridesCache = null;
260
290
  try {
261
291
  await writeOverrides(map);
262
292
  } catch (err) {
@@ -264,25 +294,45 @@ function createSanityAdapter(config) {
264
294
  }
265
295
  },
266
296
  async listEntries(collectionId) {
267
- try {
268
- if (canUseApi()) {
269
- return await apiRequest(
270
- apiBase,
271
- `/entries?collectionId=${encodeURIComponent(collectionId)}`
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
272
324
  );
325
+ return [];
326
+ } finally {
327
+ inFlightListEntries.delete(collectionId);
273
328
  }
274
- const query = `*[_type == "cms_entry" && collectionId == $collectionId]`;
275
- const docs = await readClient.fetch(query, { collectionId });
276
- return docs.map((doc) => JSON.parse(doc.data));
277
- } catch (err) {
278
- console.error(
279
- `Sanity Adapter: failed to list entries for ${collectionId}`,
280
- err
281
- );
282
- return [];
283
- }
329
+ })();
330
+ inFlightListEntries.set(collectionId, p);
331
+ return p;
284
332
  },
285
333
  async putEntry(collectionId, entry) {
334
+ listEntriesCache.delete(collectionId);
335
+ inFlightListEntries.delete(collectionId);
286
336
  try {
287
337
  await writeEntry(collectionId, entry);
288
338
  } catch (err) {
@@ -290,6 +340,8 @@ function createSanityAdapter(config) {
290
340
  }
291
341
  },
292
342
  async deleteEntry(collectionId, entryId) {
343
+ listEntriesCache.delete(collectionId);
344
+ inFlightListEntries.delete(collectionId);
293
345
  try {
294
346
  await removeEntry(collectionId, entryId);
295
347
  } catch (err) {
package/dist/storage.mjs CHANGED
@@ -146,7 +146,15 @@ function createWriteClient(config) {
146
146
  });
147
147
  }
148
148
  async function apiRequest(apiBase, path, init) {
149
- const res = await fetch(`${apiBase}${path}`, init);
149
+ const res = await fetch(`${apiBase}${path}`, {
150
+ cache: "no-store",
151
+ ...init,
152
+ headers: {
153
+ "Cache-Control": "no-cache",
154
+ Pragma: "no-cache",
155
+ ...init?.headers
156
+ }
157
+ });
150
158
  if (!res.ok) {
151
159
  const text = await res.text();
152
160
  throw new Error(text || `API error ${res.status}`);
@@ -212,23 +220,45 @@ function createSanityAdapter(config) {
212
220
  }
213
221
  await writeClient.delete(`cms_entry_${collectionId}_${entryId}`);
214
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;
215
228
  return {
216
229
  name: "sanity",
217
230
  async getOverrides() {
218
- try {
219
- if (canUseApi()) {
220
- return await apiRequest(apiBase, "/overrides");
221
- }
222
- const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
223
- if (doc && typeof doc.data === "string") {
224
- return JSON.parse(doc.data);
225
- }
226
- } catch (err) {
227
- 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;
228
234
  }
229
- return {};
235
+ if (inFlightOverrides) {
236
+ return inFlightOverrides;
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;
230
259
  },
231
260
  async setOverrides(map) {
261
+ overridesCache = null;
232
262
  try {
233
263
  await writeOverrides(map);
234
264
  } catch (err) {
@@ -236,25 +266,45 @@ function createSanityAdapter(config) {
236
266
  }
237
267
  },
238
268
  async listEntries(collectionId) {
239
- try {
240
- if (canUseApi()) {
241
- return await apiRequest(
242
- apiBase,
243
- `/entries?collectionId=${encodeURIComponent(collectionId)}`
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
244
296
  );
297
+ return [];
298
+ } finally {
299
+ inFlightListEntries.delete(collectionId);
245
300
  }
246
- const query = `*[_type == "cms_entry" && collectionId == $collectionId]`;
247
- const docs = await readClient.fetch(query, { collectionId });
248
- return docs.map((doc) => JSON.parse(doc.data));
249
- } catch (err) {
250
- console.error(
251
- `Sanity Adapter: failed to list entries for ${collectionId}`,
252
- err
253
- );
254
- return [];
255
- }
301
+ })();
302
+ inFlightListEntries.set(collectionId, p);
303
+ return p;
256
304
  },
257
305
  async putEntry(collectionId, entry) {
306
+ listEntriesCache.delete(collectionId);
307
+ inFlightListEntries.delete(collectionId);
258
308
  try {
259
309
  await writeEntry(collectionId, entry);
260
310
  } catch (err) {
@@ -262,6 +312,8 @@ function createSanityAdapter(config) {
262
312
  }
263
313
  },
264
314
  async deleteEntry(collectionId, entryId) {
315
+ listEntriesCache.delete(collectionId);
316
+ inFlightListEntries.delete(collectionId);
265
317
  try {
266
318
  await removeEntry(collectionId, entryId);
267
319
  } catch (err) {
package/dist/types.d.mts CHANGED
@@ -61,13 +61,19 @@ interface CollectionField {
61
61
  })[]>;
62
62
  colSpan?: 1 | 2 | 6 | 12;
63
63
  readOnly?: boolean;
64
+ required?: boolean;
64
65
  unique?: boolean;
65
66
  customRender?: (props: {
66
67
  value: any;
67
68
  record: any;
68
69
  onChange?: (val: any) => void;
69
70
  isCreatingEntry?: boolean;
71
+ isViewingDetail?: boolean;
72
+ readOnly?: boolean;
70
73
  }) => React.ReactNode;
74
+ onCellClick?: (value: any, record: any) => void;
75
+ renderCell?: (value: any, record: any) => React.ReactNode;
76
+ onSelectRecord?: (record: any, currentValues: any) => Record<string, any>;
71
77
  }
72
78
  interface CollectionDef {
73
79
  id: string;
@@ -83,14 +89,52 @@ interface CollectionDef {
83
89
  saveLabel?: string;
84
90
  isSeparator?: boolean;
85
91
  enableDetailView?: boolean;
92
+ enableQuickCreate?: boolean;
93
+ onViewRecord?: (record: any) => void;
94
+ customDetailView?: (props: {
95
+ record: any;
96
+ isEditing?: boolean;
97
+ onBack: () => void;
98
+ reload: () => Promise<void> | void;
99
+ }) => React.ReactNode;
100
+ renderCustomDetail?: (props: {
101
+ record: any;
102
+ isEditing?: boolean;
103
+ onBack: () => void;
104
+ reload: () => Promise<void> | void;
105
+ }) => React.ReactNode;
106
+ customEditView?: (props: {
107
+ record: any;
108
+ isEditing?: boolean;
109
+ onBack: () => void;
110
+ reload: () => Promise<void> | void;
111
+ }) => React.ReactNode;
112
+ customCreateView?: (props: {
113
+ onBack: () => void;
114
+ reload: () => Promise<void> | void;
115
+ }) => React.ReactNode;
116
+ viewRecordTitle?: string;
86
117
  disableEdit?: boolean;
87
118
  disableDelete?: boolean;
119
+ hideDelete?: boolean;
120
+ canDelete?: (record: any) => boolean;
121
+ disableExport?: boolean;
122
+ disableImport?: boolean;
88
123
  onDownloadPdf?: (record: any) => void;
89
124
  canDownloadPdf?: (record: any) => boolean;
125
+ defaultSort?: {
126
+ field: string;
127
+ direction: "asc" | "desc";
128
+ } | ((a: any, b: any) => number);
90
129
  customRowActions?: (props: {
91
130
  record: any;
92
131
  openDetail: () => void;
93
132
  openEdit: () => void;
133
+ openCustomView?: (renderFn: (props: {
134
+ onBack: () => void;
135
+ reload: () => Promise<void> | void;
136
+ }) => React.ReactNode) => void;
137
+ reload: () => Promise<void> | void;
94
138
  }) => React.ReactNode;
95
139
  }
96
140
  interface GlobalGroup {
package/dist/types.d.ts CHANGED
@@ -61,13 +61,19 @@ interface CollectionField {
61
61
  })[]>;
62
62
  colSpan?: 1 | 2 | 6 | 12;
63
63
  readOnly?: boolean;
64
+ required?: boolean;
64
65
  unique?: boolean;
65
66
  customRender?: (props: {
66
67
  value: any;
67
68
  record: any;
68
69
  onChange?: (val: any) => void;
69
70
  isCreatingEntry?: boolean;
71
+ isViewingDetail?: boolean;
72
+ readOnly?: boolean;
70
73
  }) => React.ReactNode;
74
+ onCellClick?: (value: any, record: any) => void;
75
+ renderCell?: (value: any, record: any) => React.ReactNode;
76
+ onSelectRecord?: (record: any, currentValues: any) => Record<string, any>;
71
77
  }
72
78
  interface CollectionDef {
73
79
  id: string;
@@ -83,14 +89,52 @@ interface CollectionDef {
83
89
  saveLabel?: string;
84
90
  isSeparator?: boolean;
85
91
  enableDetailView?: boolean;
92
+ enableQuickCreate?: boolean;
93
+ onViewRecord?: (record: any) => void;
94
+ customDetailView?: (props: {
95
+ record: any;
96
+ isEditing?: boolean;
97
+ onBack: () => void;
98
+ reload: () => Promise<void> | void;
99
+ }) => React.ReactNode;
100
+ renderCustomDetail?: (props: {
101
+ record: any;
102
+ isEditing?: boolean;
103
+ onBack: () => void;
104
+ reload: () => Promise<void> | void;
105
+ }) => React.ReactNode;
106
+ customEditView?: (props: {
107
+ record: any;
108
+ isEditing?: boolean;
109
+ onBack: () => void;
110
+ reload: () => Promise<void> | void;
111
+ }) => React.ReactNode;
112
+ customCreateView?: (props: {
113
+ onBack: () => void;
114
+ reload: () => Promise<void> | void;
115
+ }) => React.ReactNode;
116
+ viewRecordTitle?: string;
86
117
  disableEdit?: boolean;
87
118
  disableDelete?: boolean;
119
+ hideDelete?: boolean;
120
+ canDelete?: (record: any) => boolean;
121
+ disableExport?: boolean;
122
+ disableImport?: boolean;
88
123
  onDownloadPdf?: (record: any) => void;
89
124
  canDownloadPdf?: (record: any) => boolean;
125
+ defaultSort?: {
126
+ field: string;
127
+ direction: "asc" | "desc";
128
+ } | ((a: any, b: any) => number);
90
129
  customRowActions?: (props: {
91
130
  record: any;
92
131
  openDetail: () => void;
93
132
  openEdit: () => void;
133
+ openCustomView?: (renderFn: (props: {
134
+ onBack: () => void;
135
+ reload: () => Promise<void> | void;
136
+ }) => React.ReactNode) => void;
137
+ reload: () => Promise<void> | void;
94
138
  }) => React.ReactNode;
95
139
  }
96
140
  interface GlobalGroup {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.2.16",
3
+ "version": "1.2.18",
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",