@questpie/admin 3.2.7 → 3.3.0

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.
Files changed (79) hide show
  1. package/dist/client/components/blocks/block-editor-provider.mjs +13 -0
  2. package/dist/client/components/fields/array-field.mjs +105 -122
  3. package/dist/client/components/fields/asset-preview-field.mjs +1 -1
  4. package/dist/client/components/fields/blocks-field/blocks-field.mjs +1 -1
  5. package/dist/client/components/fields/boolean-field.mjs +1 -1
  6. package/dist/client/components/fields/date-field.mjs +1 -1
  7. package/dist/client/components/fields/datetime-field.mjs +1 -1
  8. package/dist/client/components/fields/email-field.mjs +1 -1
  9. package/dist/client/components/fields/field-wrapper.mjs +44 -15
  10. package/dist/client/components/fields/number-field.mjs +1 -1
  11. package/dist/client/components/fields/object-array-field.mjs +179 -149
  12. package/dist/client/components/fields/object-field.mjs +96 -87
  13. package/dist/client/components/fields/relation-picker.mjs +1 -1
  14. package/dist/client/components/fields/relation-select.mjs +1 -1
  15. package/dist/client/components/fields/rich-text-editor/index.mjs +1 -1
  16. package/dist/client/components/fields/select-field.mjs +1 -1
  17. package/dist/client/components/fields/text-field.mjs +1 -1
  18. package/dist/client/components/fields/textarea-field.mjs +1 -1
  19. package/dist/client/components/fields/time-field.mjs +1 -1
  20. package/dist/client/components/fields/upload-field.mjs +1 -1
  21. package/dist/client/components/history-sidebar.mjs +10 -4
  22. package/dist/client/components/structured-diff.mjs +367 -0
  23. package/dist/client/components/ui/sidebar.mjs +1 -1
  24. package/dist/client/hooks/use-field-options.mjs +34 -15
  25. package/dist/client/hooks/use-transition-stage.mjs +2 -2
  26. package/dist/client/utils/auto-expand-fields.mjs +1 -1
  27. package/dist/client/views/collection/auto-form-fields.mjs +23 -19
  28. package/dist/client/views/collection/cells/complex-cells.mjs +1 -1
  29. package/dist/client/views/collection/columns/build-columns.mjs +1 -1
  30. package/dist/client/views/collection/columns/column-defaults.mjs +17 -4
  31. package/dist/client/views/collection/field-renderer.mjs +19 -7
  32. package/dist/client/views/collection/form-view.mjs +10 -6
  33. package/dist/client/views/collection/table-view.mjs +19 -13
  34. package/dist/client/views/globals/global-form-view.mjs +47 -27
  35. package/dist/client/views/layout/admin-sidebar.mjs +2 -2
  36. package/dist/client.mjs +1 -1
  37. package/dist/index.mjs +1 -1
  38. package/dist/server/i18n/messages/cs.mjs +8 -0
  39. package/dist/server/i18n/messages/de.mjs +8 -0
  40. package/dist/server/i18n/messages/en.mjs +8 -0
  41. package/dist/server/i18n/messages/es.mjs +8 -0
  42. package/dist/server/i18n/messages/fr.mjs +8 -0
  43. package/dist/server/i18n/messages/pl.mjs +8 -0
  44. package/dist/server/i18n/messages/pt.mjs +8 -0
  45. package/dist/server/i18n/messages/sk.mjs +8 -0
  46. package/dist/server/modules/admin/collections/account.d.mts +50 -50
  47. package/dist/server/modules/admin/collections/admin-locks.d.mts +54 -54
  48. package/dist/server/modules/admin/collections/admin-preferences.d.mts +39 -39
  49. package/dist/server/modules/admin/collections/admin-saved-views.d.mts +47 -47
  50. package/dist/server/modules/admin/collections/apikey.d.mts +68 -68
  51. package/dist/server/modules/admin/collections/assets.d.mts +39 -39
  52. package/dist/server/modules/admin/collections/session.d.mts +42 -42
  53. package/dist/server/modules/admin/collections/user.d.mts +63 -63
  54. package/dist/server/modules/admin/collections/verification.d.mts +36 -36
  55. package/dist/server/modules/admin/routes/admin-config.d.mts +2 -2
  56. package/dist/server/modules/admin/routes/execute-action.d.mts +9 -9
  57. package/dist/server/modules/admin/routes/locales.d.mts +2 -2
  58. package/dist/server/modules/admin/routes/preview.d.mts +24 -19
  59. package/dist/server/modules/admin/routes/preview.mjs +83 -62
  60. package/dist/server/modules/admin/routes/reactive.d.mts +9 -9
  61. package/dist/server/modules/admin/routes/setup.d.mts +7 -7
  62. package/dist/server/modules/admin/routes/translations.d.mts +4 -4
  63. package/dist/server/modules/admin/routes/widget-data.d.mts +5 -5
  64. package/dist/server/modules/admin-preferences/collections/saved-views.d.mts +41 -41
  65. package/dist/server/modules/audit/.generated/module.d.mts +6 -6
  66. package/dist/server/modules/audit/collections/audit-log.d.mts +80 -78
  67. package/dist/server/modules/audit/collections/audit-log.mjs +7 -2
  68. package/dist/server/modules/audit/config/localize-title.mjs +67 -0
  69. package/dist/server/modules/audit/index.d.mts +2 -1
  70. package/dist/server/modules/audit/jobs/audit-cleanup.d.mts +2 -2
  71. package/dist/server/modules/audit/log-audit-entry.d.mts +85 -0
  72. package/dist/server/modules/audit/log-audit-entry.mjs +125 -0
  73. package/dist/server/plugin.mjs +4 -4
  74. package/dist/server.d.mts +2 -1
  75. package/dist/server.mjs +2 -1
  76. package/dist/shared/preview-utils.d.mts +4 -4
  77. package/dist/shared/preview-utils.mjs +5 -7
  78. package/package.json +3 -3
  79. package/dist/client/hooks/use-audit-history.mjs +0 -38
@@ -0,0 +1,125 @@
1
+ import { AUDIT_LOG_COLLECTION } from "./collections/audit-log.mjs";
2
+ import { tryGetContext } from "questpie";
3
+
4
+ //#region src/server/modules/audit/log-audit-entry.ts
5
+ function resolveCollections(ctx) {
6
+ return ctx.collections ?? ctx.app?.collections ?? null;
7
+ }
8
+ function resolveActor(ctx) {
9
+ const user = ctx.session?.user;
10
+ const userId = user?.id != null ? String(user.id) : null;
11
+ for (const candidate of [
12
+ user?.name,
13
+ user?.email,
14
+ userId
15
+ ]) if (typeof candidate === "string" && candidate.trim().length > 0) return {
16
+ actorType: "user",
17
+ userId,
18
+ userName: candidate.trim()
19
+ };
20
+ if (ctx.accessMode === "system") return {
21
+ actorType: "system",
22
+ userId: "system",
23
+ userName: "System"
24
+ };
25
+ return {
26
+ actorType: "anonymous",
27
+ userId: null,
28
+ userName: "Anonymous"
29
+ };
30
+ }
31
+ function getResourceTypeLabel(ctx, resourceType, resource) {
32
+ const stored = tryGetContext();
33
+ const app = ctx.app ?? stored?.app;
34
+ if (!app) return resource;
35
+ if (resourceType === "collection") {
36
+ const config = app.getCollectionConfig?.(resource);
37
+ const label = config?.state?.admin?.label ?? config?.state?.label;
38
+ if (typeof label === "string") return label;
39
+ return resource;
40
+ }
41
+ if (resourceType === "global") {
42
+ const config = app.getGlobals?.()?.[resource];
43
+ const label = config?.state?.admin?.label ?? config?.state?.label;
44
+ if (typeof label === "string") return label;
45
+ return resource;
46
+ }
47
+ return resource;
48
+ }
49
+ function resolveActorType(actor, options, userId) {
50
+ if (options.actorType) return options.actorType;
51
+ if (options.userId !== void 0 || options.userName !== void 0) return userId && userId !== "system" ? "user" : "system";
52
+ return actor.actorType;
53
+ }
54
+ /**
55
+ * Write a custom audit log entry.
56
+ *
57
+ * Use this in jobs, custom actions, webhooks, or anywhere you want
58
+ * to record a meaningful event in the audit trail.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { logAuditEntry } from "@questpie/admin/server";
63
+ *
64
+ * // Inside a job handler:
65
+ * await logAuditEntry(ctx, {
66
+ * action: "bulk-email",
67
+ * resourceType: "system",
68
+ * resource: "newsletter",
69
+ * resourceLabel: "Q1 Campaign",
70
+ * metadata: { sentCount: 1234, jobId: ctx.id },
71
+ * });
72
+ *
73
+ * // Inside a collection hook with session:
74
+ * await logAuditEntry(ctx, {
75
+ * action: "export",
76
+ * resourceType: "collection",
77
+ * resource: "orders",
78
+ * resourceLabel: "Monthly export",
79
+ * changes: { format: { from: null, to: "csv" } },
80
+ * });
81
+ * ```
82
+ */
83
+ async function logAuditEntry(ctx, options) {
84
+ const collections = resolveCollections(ctx);
85
+ if (!collections?.[AUDIT_LOG_COLLECTION]) {
86
+ ctx.logger?.error?.("[Audit] Cannot write audit entry — audit log collection not available");
87
+ return;
88
+ }
89
+ const actor = resolveActor(ctx);
90
+ const userName = options.userName ?? actor.userName;
91
+ const userId = options.userId !== void 0 ? options.userId : actor.userId;
92
+ const actorType = resolveActorType(actor, options, userId);
93
+ const resourceTypeLabel = getResourceTypeLabel(ctx, options.resourceType, options.resource);
94
+ const resourceLabel = options.resourceLabel ?? null;
95
+ const label = resourceLabel || "(unnamed)";
96
+ const title = `${userName} ${{
97
+ create: "created",
98
+ update: "updated",
99
+ delete: "deleted",
100
+ transition: "changed status of"
101
+ }[options.action] || options.action} ${resourceTypeLabel} '${label}'`;
102
+ await collections[AUDIT_LOG_COLLECTION].create({
103
+ action: options.action,
104
+ resourceType: options.resourceType,
105
+ resource: options.resource,
106
+ resourceId: options.resourceId ?? null,
107
+ resourceLabel,
108
+ userId,
109
+ userName,
110
+ locale: options.locale ?? null,
111
+ changes: options.changes ?? null,
112
+ metadata: {
113
+ actorType,
114
+ accessMode: ctx.accessMode ?? "system",
115
+ ...options.metadata ?? {}
116
+ },
117
+ title
118
+ }, {
119
+ accessMode: "system",
120
+ db: ctx.db
121
+ });
122
+ }
123
+
124
+ //#endregion
125
+ export { logAuditEntry };
@@ -267,7 +267,7 @@ function adminPlugin() {
267
267
  view: {
268
268
  dir: "views",
269
269
  description: "Server-side view definition",
270
- template: ({ kebab, camel }) => `import { view } from "@questpie/admin/server";\n\nexport const ${camel}View = view("${kebab}", "list", {\n\t// TODO: configure view\n});\n`
270
+ template: ({ kebab, camel }) => `import { view } from "@questpie/admin/server";\n\nexport const ${camel}View = view("${kebab}", {\n\tkind: "list",\n});\n`
271
271
  },
272
272
  component: {
273
273
  dir: "components",
@@ -362,19 +362,19 @@ function adminPlugin() {
362
362
  dir: "views",
363
363
  extension: ".tsx",
364
364
  description: "Client-side view component",
365
- template: ({ kebab, pascal }) => `import { defineView } from "@questpie/admin";\n\nexport default defineView("${kebab}", (props) => {\n\treturn (\n\t\t<div>\n\t\t\t<h2>${pascal} View</h2>\n\t\t\t{/* TODO: implement view */}\n\t\t</div>\n\t);\n});\n`
365
+ template: ({ kebab, pascal }) => `import { type CollectionListViewProps, view } from "@questpie/admin/client";\n\nfunction ${pascal}View(_props: CollectionListViewProps) {\n\treturn (\n\t\t<div>\n\t\t\t<h2>${pascal} View</h2>\n\t\t\t{/* TODO: implement view */}\n\t\t</div>\n\t);\n}\n\nexport default view("${kebab}", {\n\tkind: "list",\n\tcomponent: ${pascal}View,\n});\n`
366
366
  },
367
367
  field: {
368
368
  dir: "fields",
369
369
  extension: ".tsx",
370
370
  description: "Client-side field component",
371
- template: ({ kebab, pascal }) => `import { field } from "@questpie/admin";\n\nexport default field({\n\tname: "${kebab}",\n\tcomponent: (props) => {\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t<label>${pascal}</label>\n\t\t\t\t{/* TODO: implement field */}\n\t\t\t</div>\n\t\t);\n\t},\n});\n`
371
+ template: ({ kebab, pascal }) => `import { type BaseFieldProps, field } from "@questpie/admin/client";\n\nfunction ${pascal}Field({ label, value, onChange, onBlur }: BaseFieldProps) {\n\treturn (\n\t\t<label>\n\t\t\t<span>{label ?? "${pascal}"}</span>\n\t\t\t<input\n\t\t\t\tvalue={typeof value === "string" ? value : ""}\n\t\t\t\tonChange={(event) => onChange?.(event.target.value)}\n\t\t\t\tonBlur={onBlur}\n\t\t\t/>\n\t\t</label>\n\t);\n}\n\nexport default field("${kebab}", {\n\tcomponent: ${pascal}Field,\n});\n`
372
372
  },
373
373
  widget: {
374
374
  dir: "widgets",
375
375
  extension: ".tsx",
376
376
  description: "Client-side dashboard widget",
377
- template: ({ kebab, pascal }) => `import { defineWidget } from "@questpie/admin";\n\nexport default defineWidget("${kebab}", (props) => {\n\treturn (\n\t\t<div>\n\t\t\t<h3>${pascal} Widget</h3>\n\t\t\t{/* TODO: implement widget */}\n\t\t</div>\n\t);\n});\n`
377
+ template: ({ kebab, pascal }) => `import { type WidgetComponentProps, widget } from "@questpie/admin/client";\n\nfunction ${pascal}Widget(_props: WidgetComponentProps) {\n\treturn (\n\t\t<div>\n\t\t\t<h3>${pascal} Widget</h3>\n\t\t\t{/* TODO: implement widget */}\n\t\t</div>\n\t);\n}\n\nexport default widget("${kebab}", {\n\tcomponent: ${pascal}Widget,\n});\n`
378
378
  }
379
379
  },
380
380
  generate: (ctx) => generateAdminClientTemplate(ctx)
package/dist/server.d.mts CHANGED
@@ -27,7 +27,8 @@ import { savedViewsCollection } from "./server/modules/admin-preferences/collect
27
27
  import { AdminModule, adminModule, adminRoutes } from "./server/modules/admin/index.mjs";
28
28
  import { auditLogCollection } from "./server/modules/audit/collections/audit-log.mjs";
29
29
  import { AuditModule, _module } from "./server/modules/audit/.generated/module.mjs";
30
+ import { AuditActorType, AuditContext, LogAuditEntryOptions, logAuditEntry } from "./server/modules/audit/log-audit-entry.mjs";
30
31
  import "./server/modules/audit/index.mjs";
31
32
  import { createActionCallbackProxy, createActionProxy, createComponentCallbackProxy, createComponentProxy, createDashboardCallbackContext, createDashboardContributionProxy, createFieldProxy, createSidebarCallbackContext, createSidebarContributionProxy, createViewCallbackProxy, createViewProxy, resolveDashboardCallback, resolveSidebarCallback } from "./server/proxy-factories.mjs";
32
33
  import { component, editView, filterViewsByKind, listView, view } from "./server/registry-helpers.mjs";
33
- export { type ActionReference, type ActionsConfigContext, type AdminBlockConfig, type AdminCollectionConfig, type AdminConfigContext, type AdminConfigInput, type AdminGlobalConfig, type AdminLocaleConfig, type AdminModule, type AnyBlockBuilder, type AnyBlockDefinition, type AuditModule, type AuthSession, BeforeLoadContext, BlockBuilder, type BlockBuilderState, type BlockCategoryConfig, type BlockDefinition, type BlockNode, type BlockPrefetchContext, type BlockPrefetchFn, type BlockPrefetchWith, type BlockPrefetchWithOptions, type BlockSchema, type BlockValues, type BlocksDocument, type BlocksFieldMeta, type BlocksPrefetchContext, type BuiltinActionType, type ComponentDefinition, type ComponentFactory, type ComponentReference, type ComponentType, type ComponentTypeRegistry, type DashboardActionFactory, type DashboardActionProxy, type DashboardCallback, type DashboardCallbackContext, type DashboardConfigContext, type DashboardContribution, type DashboardItemDef, type DashboardProxy, type DashboardSectionDef, type EditViewDefinition, type EditViewFactory, type ExecuteActionRequest, type ExecuteActionResponse, type ExpandWithResult, type ExpandedRecord, type FieldLayoutItem, type FilterOperator, type FilterRule, type FilterViewsByKind, type FormFieldLayoutItem, type FormReactiveConfig, type FormReactiveContext, type FormSectionLayout, type FormSidebarConfig, type FormTabConfig, type FormTabsLayout, type FormViewConfig, type FormViewConfigContext, type GetAdminSessionOptions, type InferBlockData, type InferBlockValues, type ListViewConfig, type ListViewConfigContext, type ListViewDefinition, type ListViewFactory, NextAuthMiddlewareOptions, type PreviewConfig, type PreviewTokenPayload, type RequireAdminAuthOptions, type RichTextFeature, type RichTextFieldMeta, type ServerActionContext, type ServerActionDefinition, type ServerActionDownload, type ServerActionEffects, type ServerActionError, type ServerActionForm, type ServerActionFormField, type ServerActionHandler, type ServerActionRedirect, type ServerActionResult, type ServerActionSuccess, type ServerActionsConfig, type ServerBrandingConfig, type ServerChartWidget, type ServerCustomWidget, type ServerDashboardAction, type ServerDashboardConfig, type ServerDashboardItem, type ServerDashboardSection, type ServerDashboardTab, type ServerDashboardTabs, type ServerDashboardWidget, type ServerProgressWidget, type ServerQuickAction, type ServerQuickActionsWidget, type ServerRecentItemsWidget, type ServerSidebarCollectionItem, type ServerSidebarConfig, type ServerSidebarDividerItem, type ServerSidebarGlobalItem, type ServerSidebarItem, type ServerSidebarLinkItem, type ServerSidebarPageItem, type ServerSidebarSection, type ServerStatsWidget, type ServerTableWidget, type ServerTimelineWidget, type ServerValueWidget, type SidebarCallback, type SidebarCallbackContext, type SidebarConfigContext, type SidebarContribution, type SidebarItemDef, type SidebarProxy, type SidebarSectionDef, type SortConfig, TanStackAuthGuardOptions, type TipTapDocument, type TipTapNode, type ViewConfiguration, type ViewDefinition, type ViewKind, type ViewKindRegistry, type WidgetAccessRule, type WidgetFetchContext, actionFunctions, adminConfig, adminFields, adminModule, adminPlugin, adminRoutes, auditLogCollection, _module as auditModule, batchReactive, block, component, createActionCallbackProxy, createActionProxy, createBlocksPrefetchHook, createComponentCallbackProxy, createComponentProxy, createDashboardCallbackContext, createDashboardContributionProxy, createFieldProxy, createFirstAdmin, createNextAuthMiddleware, createPreviewFunctions, createPreviewTokenVerifier, createSidebarCallbackContext, createSidebarContributionProxy, createTanStackAuthGuard, createTanStackSessionLoader, createViewCallbackProxy, createViewProxy, editView, executeAction, executeActionFn, fetchWidgetData, fieldOptions, filterViewsByKind, getActionsConfig, getActionsConfigFn, getAdminSession, getBlocksByCategory, getNextAdminSession, introspectBlock, introspectBlocks, isAdminUser, isSetupRequired, listView, processBlocksDocument, processDocumentBlocksPrefetch, reactiveFunctions, requireAdminAuth, resolveDashboardCallback, resolveSidebarCallback, savedViewsCollection, setupFunctions, verifyPreviewTokenDirect, view, widgetDataFunctions };
34
+ export { type ActionReference, type ActionsConfigContext, type AdminBlockConfig, type AdminCollectionConfig, type AdminConfigContext, type AdminConfigInput, type AdminGlobalConfig, type AdminLocaleConfig, type AdminModule, type AnyBlockBuilder, type AnyBlockDefinition, type AuditActorType, type AuditContext, type AuditModule, type AuthSession, BeforeLoadContext, BlockBuilder, type BlockBuilderState, type BlockCategoryConfig, type BlockDefinition, type BlockNode, type BlockPrefetchContext, type BlockPrefetchFn, type BlockPrefetchWith, type BlockPrefetchWithOptions, type BlockSchema, type BlockValues, type BlocksDocument, type BlocksFieldMeta, type BlocksPrefetchContext, type BuiltinActionType, type ComponentDefinition, type ComponentFactory, type ComponentReference, type ComponentType, type ComponentTypeRegistry, type DashboardActionFactory, type DashboardActionProxy, type DashboardCallback, type DashboardCallbackContext, type DashboardConfigContext, type DashboardContribution, type DashboardItemDef, type DashboardProxy, type DashboardSectionDef, type EditViewDefinition, type EditViewFactory, type ExecuteActionRequest, type ExecuteActionResponse, type ExpandWithResult, type ExpandedRecord, type FieldLayoutItem, type FilterOperator, type FilterRule, type FilterViewsByKind, type FormFieldLayoutItem, type FormReactiveConfig, type FormReactiveContext, type FormSectionLayout, type FormSidebarConfig, type FormTabConfig, type FormTabsLayout, type FormViewConfig, type FormViewConfigContext, type GetAdminSessionOptions, type InferBlockData, type InferBlockValues, type ListViewConfig, type ListViewConfigContext, type ListViewDefinition, type ListViewFactory, type LogAuditEntryOptions, NextAuthMiddlewareOptions, type PreviewConfig, type PreviewTokenPayload, type RequireAdminAuthOptions, type RichTextFeature, type RichTextFieldMeta, type ServerActionContext, type ServerActionDefinition, type ServerActionDownload, type ServerActionEffects, type ServerActionError, type ServerActionForm, type ServerActionFormField, type ServerActionHandler, type ServerActionRedirect, type ServerActionResult, type ServerActionSuccess, type ServerActionsConfig, type ServerBrandingConfig, type ServerChartWidget, type ServerCustomWidget, type ServerDashboardAction, type ServerDashboardConfig, type ServerDashboardItem, type ServerDashboardSection, type ServerDashboardTab, type ServerDashboardTabs, type ServerDashboardWidget, type ServerProgressWidget, type ServerQuickAction, type ServerQuickActionsWidget, type ServerRecentItemsWidget, type ServerSidebarCollectionItem, type ServerSidebarConfig, type ServerSidebarDividerItem, type ServerSidebarGlobalItem, type ServerSidebarItem, type ServerSidebarLinkItem, type ServerSidebarPageItem, type ServerSidebarSection, type ServerStatsWidget, type ServerTableWidget, type ServerTimelineWidget, type ServerValueWidget, type SidebarCallback, type SidebarCallbackContext, type SidebarConfigContext, type SidebarContribution, type SidebarItemDef, type SidebarProxy, type SidebarSectionDef, type SortConfig, TanStackAuthGuardOptions, type TipTapDocument, type TipTapNode, type ViewConfiguration, type ViewDefinition, type ViewKind, type ViewKindRegistry, type WidgetAccessRule, type WidgetFetchContext, actionFunctions, adminConfig, adminFields, adminModule, adminPlugin, adminRoutes, auditLogCollection, _module as auditModule, batchReactive, block, component, createActionCallbackProxy, createActionProxy, createBlocksPrefetchHook, createComponentCallbackProxy, createComponentProxy, createDashboardCallbackContext, createDashboardContributionProxy, createFieldProxy, createFirstAdmin, createNextAuthMiddleware, createPreviewFunctions, createPreviewTokenVerifier, createSidebarCallbackContext, createSidebarContributionProxy, createTanStackAuthGuard, createTanStackSessionLoader, createViewCallbackProxy, createViewProxy, editView, executeAction, executeActionFn, fetchWidgetData, fieldOptions, filterViewsByKind, getActionsConfig, getActionsConfigFn, getAdminSession, getBlocksByCategory, getNextAdminSession, introspectBlock, introspectBlocks, isAdminUser, isSetupRequired, listView, logAuditEntry, processBlocksDocument, processDocumentBlocksPrefetch, reactiveFunctions, requireAdminAuth, resolveDashboardCallback, resolveSidebarCallback, savedViewsCollection, setupFunctions, verifyPreviewTokenDirect, view, widgetDataFunctions };
package/dist/server.mjs CHANGED
@@ -18,5 +18,6 @@ import { adminConfig } from "./server/augmentation/index.mjs";
18
18
  import { adminModule, adminRoutes } from "./server/modules/admin/index.mjs";
19
19
  import { auditLogCollection } from "./server/modules/audit/collections/audit-log.mjs";
20
20
  import module_default from "./server/modules/audit/.generated/module.mjs";
21
+ import { logAuditEntry } from "./server/modules/audit/log-audit-entry.mjs";
21
22
 
22
- export { BlockBuilder, actionFunctions, adminConfig, adminFields, adminModule, adminPlugin, adminRoutes, auditLogCollection, module_default as auditModule, batchReactive, block, component, createActionCallbackProxy, createActionProxy, createBlocksPrefetchHook, createComponentCallbackProxy, createComponentProxy, createDashboardCallbackContext, createDashboardContributionProxy, createFieldProxy, createFirstAdmin, createNextAuthMiddleware, createPreviewFunctions, createPreviewTokenVerifier, createSidebarCallbackContext, createSidebarContributionProxy, createTanStackAuthGuard, createTanStackSessionLoader, createViewCallbackProxy, createViewProxy, editView, executeAction, executeActionFn, fetchWidgetData, fieldOptions, filterViewsByKind, getActionsConfig, getActionsConfigFn, getAdminSession, getBlocksByCategory, getNextAdminSession, introspectBlock, introspectBlocks, isAdminUser, isSetupRequired, listView, processBlocksDocument, processDocumentBlocksPrefetch, reactiveFunctions, requireAdminAuth, resolveDashboardCallback, resolveSidebarCallback, savedViewsCollection, setupFunctions, verifyPreviewTokenDirect, view, widgetDataFunctions };
23
+ export { BlockBuilder, actionFunctions, adminConfig, adminFields, adminModule, adminPlugin, adminRoutes, auditLogCollection, module_default as auditModule, batchReactive, block, component, createActionCallbackProxy, createActionProxy, createBlocksPrefetchHook, createComponentCallbackProxy, createComponentProxy, createDashboardCallbackContext, createDashboardContributionProxy, createFieldProxy, createFirstAdmin, createNextAuthMiddleware, createPreviewFunctions, createPreviewTokenVerifier, createSidebarCallbackContext, createSidebarContributionProxy, createTanStackAuthGuard, createTanStackSessionLoader, createViewCallbackProxy, createViewProxy, editView, executeAction, executeActionFn, fetchWidgetData, fieldOptions, filterViewsByKind, getActionsConfig, getActionsConfigFn, getAdminSession, getBlocksByCategory, getNextAdminSession, introspectBlock, introspectBlocks, isAdminUser, isSetupRequired, listView, logAuditEntry, processBlocksDocument, processDocumentBlocksPrefetch, reactiveFunctions, requireAdminAuth, resolveDashboardCallback, resolveSidebarCallback, savedViewsCollection, setupFunctions, verifyPreviewTokenDirect, view, widgetDataFunctions };
@@ -76,11 +76,11 @@ declare function isDraftMode(cookieHeader: string | null | undefined): boolean;
76
76
  */
77
77
  declare function createDraftModeCookie(enabled: boolean, maxAge?: number): string;
78
78
  /**
79
- * Get preview secret from environment variables.
80
- * Falls back to SECRET if PREVIEW_SECRET is not set.
79
+ * Resolve a preview secret from an explicit value.
81
80
  *
82
- * @returns The preview secret
81
+ * @deprecated Preview token signing now reads `app.config.secret` in server
82
+ * route handlers. Pass a secret explicitly when using standalone helpers.
83
83
  */
84
- declare function getPreviewSecret(): string;
84
+ declare function getPreviewSecret(secret?: string): string;
85
85
  //#endregion
86
86
  export { ADMIN_API_PREFIX, DRAFT_MODE_COOKIE, createDraftModeCookie, getPreviewSecret, isAdminRequest, isDraftMode };
@@ -127,15 +127,13 @@ function createDraftModeCookie(enabled, maxAge = 3600) {
127
127
  return `${DRAFT_MODE_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax; HttpOnly`;
128
128
  }
129
129
  /**
130
- * Get preview secret from environment variables.
131
- * Falls back to SECRET if PREVIEW_SECRET is not set.
130
+ * Resolve a preview secret from an explicit value.
132
131
  *
133
- * @returns The preview secret
132
+ * @deprecated Preview token signing now reads `app.config.secret` in server
133
+ * route handlers. Pass a secret explicitly when using standalone helpers.
134
134
  */
135
- function getPreviewSecret() {
136
- const secret = process.env.PREVIEW_SECRET || process.env.SECRET || "dev-preview-secret";
137
- if (process.env.NODE_ENV === "production" && secret === "dev-preview-secret") console.warn("[preview] Using default secret in production. Set PREVIEW_SECRET or SECRET env var.");
138
- return secret;
135
+ function getPreviewSecret(secret) {
136
+ return secret ?? "dev-preview-secret";
139
137
  }
140
138
 
141
139
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@questpie/admin",
3
- "version": "3.2.7",
3
+ "version": "3.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/questpie/questpie.git",
@@ -62,7 +62,7 @@
62
62
  "@fontsource-variable/jetbrains-mono": "^5.2.8",
63
63
  "@hookform/resolvers": "^5.1.0",
64
64
  "@iconify/react": "^6.0.2",
65
- "@questpie/tanstack-query": "^3.2.7",
65
+ "@questpie/tanstack-query": "^3.3.0",
66
66
  "@tailwindcss/vite": "^4.0.6",
67
67
  "@tiptap/core": "^2.x",
68
68
  "@tiptap/extension-character-count": "^2.x",
@@ -88,7 +88,7 @@
88
88
  "date-fns": "^4.1.0",
89
89
  "lowlight": "^3.x",
90
90
  "next-themes": "^0.4.6",
91
- "questpie": "^3.2.7",
91
+ "questpie": "^3.3.0",
92
92
  "react-day-picker": "^9.12.0",
93
93
  "react-hook-form": "^7.54.0",
94
94
  "react-resizable-panels": "^4.4.2",
@@ -1,38 +0,0 @@
1
- import { selectBasePath, useAdminStore } from "../runtime/provider.mjs";
2
- import * as React from "react";
3
- import { useQuery } from "@tanstack/react-query";
4
-
5
- //#region src/client/hooks/use-audit-history.ts
6
- function useAuditFetcher(path) {
7
- const basePath = useAdminStore(selectBasePath);
8
- return React.useCallback(async (signal) => {
9
- const response = await fetch(`${basePath}${path}`, {
10
- credentials: "include",
11
- headers: { Accept: "application/json" },
12
- signal
13
- });
14
- if (!response.ok) throw new Error(`Failed to fetch audit history: ${response.status}`);
15
- const data = await response.json();
16
- return Array.isArray(data) ? data : data?.docs ?? data ?? [];
17
- }, [basePath, path]);
18
- }
19
- function useGlobalAuditHistory(globalName, options, queryOptions) {
20
- const params = new URLSearchParams();
21
- if (options?.limit) params.set("limit", String(options.limit));
22
- const fetchAudit = useAuditFetcher(`/globals/${globalName}/audit${params.toString() ? `?${params}` : ""}`);
23
- return useQuery({
24
- queryKey: [
25
- "questpie",
26
- "audit",
27
- "global",
28
- globalName,
29
- options
30
- ],
31
- queryFn: ({ signal }) => fetchAudit(signal),
32
- enabled: !!globalName && (queryOptions?.enabled ?? true),
33
- ...queryOptions
34
- });
35
- }
36
-
37
- //#endregion
38
- export { useGlobalAuditHistory };