@10x-media/form-builder 0.1.0-beta.0 → 0.1.0-beta.2
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/CHANGELOG.md +68 -0
- package/README.md +45 -1402
- package/dist/actions/buildActionBlocks.js +19 -0
- package/dist/actions/buildActionBlocks.js.map +1 -0
- package/dist/actions/builtin/confirmation.js +49 -0
- package/dist/actions/builtin/confirmation.js.map +1 -0
- package/dist/actions/builtin/emailTeam.js +46 -0
- package/dist/actions/builtin/emailTeam.js.map +1 -0
- package/dist/actions/builtin/index.d.ts +7 -0
- package/dist/actions/builtin/index.js +13 -0
- package/dist/actions/builtin/index.js.map +1 -0
- package/dist/actions/builtin/signedWebhook.js +49 -0
- package/dist/actions/builtin/signedWebhook.js.map +1 -0
- package/dist/actions/defineAction.d.ts +36 -0
- package/dist/actions/defineAction.js +6 -0
- package/dist/actions/defineAction.js.map +1 -0
- package/dist/actions/dispatch.js +48 -0
- package/dist/actions/dispatch.js.map +1 -0
- package/dist/actions/registry.d.ts +16 -0
- package/dist/actions/registry.js +16 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/actions/runActions.d.ts +9 -0
- package/dist/actions/runActions.js +34 -0
- package/dist/actions/runActions.js.map +1 -0
- package/dist/actions/sign.d.ts +7 -0
- package/dist/actions/sign.js +9 -0
- package/dist/actions/sign.js.map +1 -0
- package/dist/actions/task.js +82 -0
- package/dist/actions/task.js.map +1 -0
- package/dist/aggregation/aggregateResponses.d.ts +31 -0
- package/dist/aggregation/aggregateResponses.js +86 -0
- package/dist/aggregation/aggregateResponses.js.map +1 -0
- package/dist/aggregation/aggregateRows.d.ts +10 -0
- package/dist/aggregation/aggregateRows.js +64 -0
- package/dist/aggregation/aggregateRows.js.map +1 -0
- package/dist/aggregation/resolveResultsRequest.d.ts +32 -0
- package/dist/aggregation/resolveResultsRequest.js +56 -0
- package/dist/aggregation/resolveResultsRequest.js.map +1 -0
- package/dist/aggregation/types.d.ts +39 -0
- package/dist/calc/computeCalcFields.d.ts +15 -0
- package/dist/calc/computeCalcFields.js +27 -0
- package/dist/calc/computeCalcFields.js.map +1 -0
- package/dist/calc/evaluate.d.ts +8 -0
- package/dist/calc/evaluate.js +59 -0
- package/dist/calc/evaluate.js.map +1 -0
- package/dist/calc/normalizeCalc.d.ts +8 -0
- package/dist/calc/normalizeCalc.js +100 -0
- package/dist/calc/normalizeCalc.js.map +1 -0
- package/dist/calc/types.d.ts +28 -0
- package/dist/client/ConditionBuilder.js +121 -0
- package/dist/client/ConditionBuilder.js.map +1 -0
- package/dist/client/ConditionRow.js +150 -0
- package/dist/client/ConditionRow.js.map +1 -0
- package/dist/client/FlowBuilder.d.ts +15 -0
- package/dist/client/FlowBuilder.js +408 -0
- package/dist/client/FlowBuilder.js.map +1 -0
- package/dist/client/FormConditionField.d.ts +21 -0
- package/dist/client/FormConditionField.js +33 -0
- package/dist/client/FormConditionField.js.map +1 -0
- package/dist/client/synthesizeClientField.js +46 -0
- package/dist/client/synthesizeClientField.js.map +1 -0
- package/dist/collections/formSubmissions.js +157 -0
- package/dist/collections/formSubmissions.js.map +1 -0
- package/dist/collections/forms.js +198 -0
- package/dist/collections/forms.js.map +1 -0
- package/dist/collections/uploads.d.ts +30 -0
- package/dist/collections/uploads.js +55 -0
- package/dist/collections/uploads.js.map +1 -0
- package/dist/conditions/conditionType.js +14 -0
- package/dist/conditions/conditionType.js.map +1 -0
- package/dist/conditions/evaluate.d.ts +17 -0
- package/dist/conditions/evaluate.js +94 -0
- package/dist/conditions/evaluate.js.map +1 -0
- package/dist/conditions/fieldTypes.d.ts +9 -0
- package/dist/{fieldTypes-CzhhJXjg.js → conditions/fieldTypes.js} +2 -2
- package/dist/conditions/fieldTypes.js.map +1 -0
- package/dist/conditions/normalizeConditions.js +47 -0
- package/dist/conditions/normalizeConditions.js.map +1 -0
- package/dist/conditions/types.d.ts +8 -0
- package/dist/consent/buildConsentSourceConfig.js +49 -0
- package/dist/consent/buildConsentSourceConfig.js.map +1 -0
- package/dist/consent/builtin/index.d.ts +7 -0
- package/dist/consent/builtin/index.js +11 -0
- package/dist/consent/builtin/index.js.map +1 -0
- package/dist/consent/builtin/pageReference.js +75 -0
- package/dist/consent/builtin/pageReference.js.map +1 -0
- package/dist/consent/builtin/static.js +44 -0
- package/dist/consent/builtin/static.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +28 -0
- package/dist/consent/captureConsent.js +26 -0
- package/dist/consent/captureConsent.js.map +1 -0
- package/dist/consent/defineConsentSource.d.ts +35 -0
- package/dist/consent/defineConsentSource.js +6 -0
- package/dist/consent/defineConsentSource.js.map +1 -0
- package/dist/consent/registry.d.ts +16 -0
- package/dist/consent/registry.js +16 -0
- package/dist/consent/registry.js.map +1 -0
- package/dist/consent/resolveConsentLinks.d.ts +19 -0
- package/dist/consent/resolveConsentLinks.js +26 -0
- package/dist/consent/resolveConsentLinks.js.map +1 -0
- package/dist/consent/resolvePublishedVersionRef.d.ts +17 -0
- package/dist/consent/resolvePublishedVersionRef.js +27 -0
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -0
- package/dist/events/noopSink.js +6 -0
- package/dist/events/noopSink.js.map +1 -0
- package/dist/events/resolveEventSink.js +8 -0
- package/dist/events/resolveEventSink.js.map +1 -0
- package/dist/events/types.d.ts +31 -0
- package/dist/exports/client.d.ts +3 -21
- package/dist/exports/client.js +3 -319
- package/dist/exports/i18n.d.ts +3 -138
- package/dist/exports/i18n.js +2 -2
- package/dist/exports/react.d.ts +45 -550
- package/dist/exports/react.js +39 -1563
- package/dist/exports/rsc.d.ts +2 -16
- package/dist/exports/rsc.js +1 -54
- package/dist/exports/types.d.ts +28 -5
- package/dist/fields/buildFieldBlocks.js +60 -0
- package/dist/fields/buildFieldBlocks.js.map +1 -0
- package/dist/fields/builtin/calculation.js +24 -0
- package/dist/fields/builtin/calculation.js.map +1 -0
- package/dist/fields/builtin/checkbox.js +13 -0
- package/dist/fields/builtin/checkbox.js.map +1 -0
- package/dist/fields/builtin/consent.js +32 -0
- package/dist/fields/builtin/consent.js.map +1 -0
- package/dist/fields/builtin/email.js +18 -0
- package/dist/fields/builtin/email.js.map +1 -0
- package/dist/fields/builtin/file.js +40 -0
- package/dist/fields/builtin/file.js.map +1 -0
- package/dist/fields/builtin/index.js +27 -0
- package/dist/fields/builtin/index.js.map +1 -0
- package/dist/fields/builtin/number.js +17 -0
- package/dist/fields/builtin/number.js.map +1 -0
- package/dist/fields/builtin/repeater.js +44 -0
- package/dist/fields/builtin/repeater.js.map +1 -0
- package/dist/fields/builtin/select.js +44 -0
- package/dist/fields/builtin/select.js.map +1 -0
- package/dist/fields/builtin/text.js +13 -0
- package/dist/fields/builtin/text.js.map +1 -0
- package/dist/fields/builtin/textarea.js +13 -0
- package/dist/fields/builtin/textarea.js.map +1 -0
- package/dist/fields/defineFormField.d.ts +13 -0
- package/dist/fields/defineFormField.js +12 -0
- package/dist/fields/defineFormField.js.map +1 -0
- package/dist/fields/registry.d.ts +10 -0
- package/dist/fields/registry.js +24 -0
- package/dist/fields/registry.js.map +1 -0
- package/dist/fields/sharedConfig.js +89 -0
- package/dist/fields/sharedConfig.js.map +1 -0
- package/dist/fields/types.d.ts +89 -0
- package/dist/flow/engine.d.ts +17 -0
- package/dist/flow/engine.js +24 -0
- package/dist/flow/engine.js.map +1 -0
- package/dist/flow/normalizeFlow.js +35 -0
- package/dist/flow/normalizeFlow.js.map +1 -0
- package/dist/{types-DsJ_6kGJ.d.ts → flow/types.d.ts} +2 -2
- package/dist/index.d.ts +93 -4
- package/dist/index.js +43 -1890
- package/dist/index.js.map +1 -1
- package/dist/plugin/access.js +12 -0
- package/dist/plugin/access.js.map +1 -0
- package/dist/plugin/collectionOverrides.d.ts +22 -0
- package/dist/plugin/registerCollections.js +68 -0
- package/dist/plugin/registerCollections.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/prefill/valuesFromSearchParams.d.ts +18 -0
- package/dist/prefill/valuesFromSearchParams.js +45 -0
- package/dist/prefill/valuesFromSearchParams.js.map +1 -0
- package/dist/presentations/defaults.d.ts +33 -0
- package/dist/presentations/defaults.js +35 -0
- package/dist/presentations/defaults.js.map +1 -0
- package/dist/presentations/registry.d.ts +15 -0
- package/dist/presentations/registry.js +15 -0
- package/dist/presentations/registry.js.map +1 -0
- package/dist/presentations/types.d.ts +18 -0
- package/dist/react/Form.d.ts +110 -0
- package/dist/react/Form.js +499 -0
- package/dist/react/Form.js.map +1 -0
- package/dist/react/FormContext.d.ts +16 -0
- package/dist/react/FormContext.js +14 -0
- package/dist/react/FormContext.js.map +1 -0
- package/dist/react/FormLayout.d.ts +20 -0
- package/dist/react/FormLayout.js +14 -0
- package/dist/react/FormLayout.js.map +1 -0
- package/dist/react/FormResults.d.ts +25 -0
- package/dist/react/FormResults.js +85 -0
- package/dist/react/FormResults.js.map +1 -0
- package/dist/react/Honeypot.d.ts +22 -0
- package/dist/react/Honeypot.js +38 -0
- package/dist/react/Honeypot.js.map +1 -0
- package/dist/react/Poll.d.ts +32 -0
- package/dist/react/Poll.js +77 -0
- package/dist/react/Poll.js.map +1 -0
- package/dist/react/cn.d.ts +6 -0
- package/dist/react/cn.js +8 -0
- package/dist/react/cn.js.map +1 -0
- package/dist/react/contract.d.ts +32 -0
- package/dist/react/contract.js +7 -0
- package/dist/react/contract.js.map +1 -0
- package/dist/react/events.js +14 -0
- package/dist/react/events.js.map +1 -0
- package/dist/react/fetchResults.d.ts +25 -0
- package/dist/react/fetchResults.js +31 -0
- package/dist/react/fetchResults.js.map +1 -0
- package/dist/react/presentation/Backdrop.d.ts +18 -0
- package/dist/react/presentation/Backdrop.js +14 -0
- package/dist/react/presentation/Backdrop.js.map +1 -0
- package/dist/react/presentation/DialogSurface.d.ts +35 -0
- package/dist/react/presentation/DialogSurface.js +56 -0
- package/dist/react/presentation/DialogSurface.js.map +1 -0
- package/dist/react/presentation/presentations.d.ts +7 -0
- package/dist/react/presentation/presentations.js +32 -0
- package/dist/react/presentation/presentations.js.map +1 -0
- package/dist/react/presentation/registry.d.ts +11 -0
- package/dist/react/presentation/registry.js +12 -0
- package/dist/react/presentation/registry.js.map +1 -0
- package/dist/react/presentation/types.d.ts +19 -0
- package/dist/react/presentation/useDismiss.d.ts +19 -0
- package/dist/react/presentation/useDismiss.js +33 -0
- package/dist/react/presentation/useDismiss.js.map +1 -0
- package/dist/react/presentation/useFocusTrap.d.ts +8 -0
- package/dist/react/presentation/useFocusTrap.js +35 -0
- package/dist/react/presentation/useFocusTrap.js.map +1 -0
- package/dist/react/presentation/useScrollLock.d.ts +6 -0
- package/dist/react/presentation/useScrollLock.js +18 -0
- package/dist/react/presentation/useScrollLock.js.map +1 -0
- package/dist/react/primitives/Checkbox.d.ts +26 -0
- package/dist/react/primitives/Checkbox.js +20 -0
- package/dist/react/primitives/Checkbox.js.map +1 -0
- package/dist/react/primitives/FieldShell.d.ts +31 -0
- package/dist/react/primitives/FieldShell.js +51 -0
- package/dist/react/primitives/FieldShell.js.map +1 -0
- package/dist/react/primitives/Input.d.ts +30 -0
- package/dist/react/primitives/Input.js +21 -0
- package/dist/react/primitives/Input.js.map +1 -0
- package/dist/react/primitives/Select.d.ts +34 -0
- package/dist/react/primitives/Select.js +26 -0
- package/dist/react/primitives/Select.js.map +1 -0
- package/dist/react/primitives/Textarea.d.ts +28 -0
- package/dist/react/primitives/Textarea.js +20 -0
- package/dist/react/primitives/Textarea.js.map +1 -0
- package/dist/react/recall.js +20 -0
- package/dist/react/recall.js.map +1 -0
- package/dist/react/registry.d.ts +16 -0
- package/dist/react/registry.js +16 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/react/renderers/calculation.js +30 -0
- package/dist/react/renderers/calculation.js.map +1 -0
- package/dist/react/renderers/checkbox.js +35 -0
- package/dist/react/renderers/checkbox.js.map +1 -0
- package/dist/react/renderers/consent.js +54 -0
- package/dist/react/renderers/consent.js.map +1 -0
- package/dist/react/renderers/email.js +37 -0
- package/dist/react/renderers/email.js.map +1 -0
- package/dist/react/renderers/file.js +92 -0
- package/dist/react/renderers/file.js.map +1 -0
- package/dist/react/renderers/index.d.ts +8 -0
- package/dist/react/renderers/index.js +28 -0
- package/dist/react/renderers/index.js.map +1 -0
- package/dist/react/renderers/number.js +40 -0
- package/dist/react/renderers/number.js.map +1 -0
- package/dist/react/renderers/repeater.js +113 -0
- package/dist/react/renderers/repeater.js.map +1 -0
- package/dist/react/renderers/select.js +38 -0
- package/dist/react/renderers/select.js.map +1 -0
- package/dist/react/renderers/text.js +37 -0
- package/dist/react/renderers/text.js.map +1 -0
- package/dist/react/renderers/textarea.js +36 -0
- package/dist/react/renderers/textarea.js.map +1 -0
- package/dist/react/resolveForm.js +16 -0
- package/dist/react/resolveForm.js.map +1 -0
- package/dist/react/state.d.ts +15 -0
- package/dist/react/state.js +70 -0
- package/dist/react/state.js.map +1 -0
- package/dist/react/submitForm.d.ts +31 -0
- package/dist/react/submitForm.js +58 -0
- package/dist/react/submitForm.js.map +1 -0
- package/dist/react/toFormDocument.d.ts +24 -0
- package/dist/react/toFormDocument.js +22 -0
- package/dist/react/toFormDocument.js.map +1 -0
- package/dist/react/uploadFile.d.ts +23 -0
- package/dist/react/uploadFile.js +39 -0
- package/dist/react/uploadFile.js.map +1 -0
- package/dist/react/useField.d.ts +14 -0
- package/dist/react/useField.js +49 -0
- package/dist/react/useField.js.map +1 -0
- package/dist/react/useFormState.d.ts +8 -0
- package/dist/react/useFormState.js +9 -0
- package/dist/react/useFormState.js.map +1 -0
- package/dist/react/useFormStep.d.ts +8 -0
- package/dist/react/useFormStep.js +9 -0
- package/dist/react/useFormStep.js.map +1 -0
- package/dist/react/validateField.js +30 -0
- package/dist/react/validateField.js.map +1 -0
- package/dist/recall/interpolate.d.ts +10 -0
- package/dist/recall/interpolate.js +16 -0
- package/dist/recall/interpolate.js.map +1 -0
- package/dist/recall/resolver.d.ts +22 -0
- package/dist/recall/resolver.js +36 -0
- package/dist/recall/resolver.js.map +1 -0
- package/dist/spam/captcha.d.ts +12 -0
- package/dist/spam/captcha.js +11 -0
- package/dist/spam/captcha.js.map +1 -0
- package/dist/spam/constants.d.ts +12 -0
- package/dist/spam/constants.js +15 -0
- package/dist/spam/constants.js.map +1 -0
- package/dist/spam/identify.d.ts +12 -0
- package/dist/spam/identify.js +20 -0
- package/dist/spam/identify.js.map +1 -0
- package/dist/spam/rateLimiter.d.ts +18 -0
- package/dist/spam/rateLimiter.js +41 -0
- package/dist/spam/rateLimiter.js.map +1 -0
- package/dist/spam/reserved.js +30 -0
- package/dist/spam/reserved.js.map +1 -0
- package/dist/spam/resolveSpam.d.ts +12 -0
- package/dist/spam/resolveSpam.js +42 -0
- package/dist/spam/resolveSpam.js.map +1 -0
- package/dist/spam/spamGuard.js +68 -0
- package/dist/spam/spamGuard.js.map +1 -0
- package/dist/spam/types.d.ts +73 -0
- package/dist/spam/uploadHooks.js +33 -0
- package/dist/spam/uploadHooks.js.map +1 -0
- package/dist/submissions/SubmissionAnswers.d.ts +14 -0
- package/dist/submissions/SubmissionAnswers.js +133 -0
- package/dist/submissions/SubmissionAnswers.js.map +1 -0
- package/dist/submissions/SubmissionAnswersClient.js +142 -0
- package/dist/submissions/SubmissionAnswersClient.js.map +1 -0
- package/dist/submissions/runSubmission.js +257 -0
- package/dist/submissions/runSubmission.js.map +1 -0
- package/dist/submissions/types.d.ts +34 -0
- package/dist/submissions/validateSubmission.js +59 -0
- package/dist/submissions/validateSubmission.js.map +1 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/{translations-edMqq_2e.js → translations/en.js} +29 -23
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +14 -0
- package/dist/translations/index.js +26 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +157 -0
- package/dist/{keys-N5xGiUsh.js → translations/keys.js} +28 -3
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/makeTranslate.d.ts +11 -0
- package/dist/translations/makeTranslate.js +11 -0
- package/dist/translations/makeTranslate.js.map +1 -0
- package/dist/translations/server.js +25 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/uploads/captureFileRef.d.ts +27 -0
- package/dist/uploads/captureFileRef.js +34 -0
- package/dist/uploads/captureFileRef.js.map +1 -0
- package/dist/uploads/resolveFileRef.d.ts +26 -0
- package/dist/uploads/resolveFileRef.js +44 -0
- package/dist/uploads/resolveFileRef.js.map +1 -0
- package/dist/uploads/types.d.ts +20 -0
- package/dist/validation/buildRuleBlocks.js +46 -0
- package/dist/validation/buildRuleBlocks.js.map +1 -0
- package/dist/validation/builtin/email.js +19 -0
- package/dist/validation/builtin/email.js.map +1 -0
- package/dist/validation/builtin/index.js +27 -0
- package/dist/validation/builtin/index.js.map +1 -0
- package/dist/validation/builtin/matchesField.js +20 -0
- package/dist/validation/builtin/matchesField.js.map +1 -0
- package/dist/validation/builtin/max.js +21 -0
- package/dist/validation/builtin/max.js.map +1 -0
- package/dist/validation/builtin/maxLength.js +26 -0
- package/dist/validation/builtin/maxLength.js.map +1 -0
- package/dist/validation/builtin/min.js +21 -0
- package/dist/validation/builtin/min.js.map +1 -0
- package/dist/validation/builtin/minLength.js +26 -0
- package/dist/validation/builtin/minLength.js.map +1 -0
- package/dist/validation/builtin/notAlreadySubmitted.js +32 -0
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -0
- package/dist/validation/builtin/oneOf.js +34 -0
- package/dist/validation/builtin/oneOf.js.map +1 -0
- package/dist/validation/builtin/pattern.js +41 -0
- package/dist/validation/builtin/pattern.js.map +1 -0
- package/dist/validation/builtin/url.js +22 -0
- package/dist/validation/builtin/url.js.map +1 -0
- package/dist/validation/defineValidationRule.d.ts +12 -0
- package/dist/validation/defineValidationRule.js +11 -0
- package/dist/validation/defineValidationRule.js.map +1 -0
- package/dist/validation/message.js +14 -0
- package/dist/validation/message.js.map +1 -0
- package/dist/validation/registry.d.ts +10 -0
- package/dist/validation/registry.js +20 -0
- package/dist/validation/registry.js.map +1 -0
- package/dist/validation/runValidation.js +111 -0
- package/dist/validation/runValidation.js.map +1 -0
- package/dist/validation/types.d.ts +76 -0
- package/package.json +8 -5
- package/styles/form-builder.css +201 -11
- package/dist/constants-B-BUfetP.d.ts +0 -288
- package/dist/exports/client.js.map +0 -1
- package/dist/exports/react.js.map +0 -1
- package/dist/exports/rsc.js.map +0 -1
- package/dist/fieldTypes-B8jkNRob.d.ts +0 -188
- package/dist/fieldTypes-CzhhJXjg.js.map +0 -1
- package/dist/index-DfFYGbVF.d.ts +0 -481
- package/dist/keys-N5xGiUsh.js.map +0 -1
- package/dist/registry-CoCyhtvB.js +0 -282
- package/dist/registry-CoCyhtvB.js.map +0 -1
- package/dist/resolver-OeQyVH2N.js +0 -665
- package/dist/resolver-OeQyVH2N.js.map +0 -1
- package/dist/translations-edMqq_2e.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.js","names":[],"sources":["../../src/conditions/evaluate.ts"],"sourcesContent":["import type { Operator, Where } from 'payload'\nimport { transformWhereQuery } from 'payload/shared'\n\nconst isNil = (value: unknown): boolean => value === null || value === undefined\n\nconst toNumber = (value: unknown): number | undefined => {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : undefined\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst next = Number(value)\n\t\treturn Number.isNaN(next) ? undefined : next\n\t}\n\treturn undefined\n}\n\nconst toTime = (value: unknown): number | undefined => {\n\tif (value instanceof Date) {\n\t\treturn value.getTime()\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst time = Date.parse(value)\n\t\treturn Number.isNaN(time) ? undefined : time\n\t}\n\treturn undefined\n}\n\n/** Strict, then numeric, then string equality, mirroring Payload's coerce-by-type-then-compare. */\nconst valuesEqual = (answer: unknown, value: unknown): boolean => {\n\tif (answer === value) {\n\t\treturn true\n\t}\n\tif (isNil(answer) || isNil(value)) {\n\t\treturn false\n\t}\n\tconst a = toNumber(answer)\n\tconst b = toNumber(value)\n\tif (a !== undefined && b !== undefined) {\n\t\treturn a === b\n\t}\n\treturn String(answer) === String(value)\n}\n\nconst toList = (value: unknown): unknown[] => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t}\n\tif (typeof value === 'string') {\n\t\treturn value.split(',').map((entry) => entry.trim())\n\t}\n\treturn [value]\n}\n\nconst ordered = (\n\tanswer: unknown,\n\tvalue: unknown,\n\tcompare: (a: number, b: number) => boolean\n): boolean => {\n\tconst a = toNumber(answer) ?? toTime(answer)\n\tconst b = toNumber(value) ?? toTime(value)\n\tif (a === undefined || b === undefined) {\n\t\treturn false\n\t}\n\treturn compare(a, b)\n}\n\n/** Case-insensitive: every space-separated word in `value` is a substring of `answer` (Payload `like`). */\nconst everyWord = (answer: unknown, value: unknown): boolean => {\n\tconst haystack = String(answer).toLowerCase()\n\treturn String(value)\n\t\t.toLowerCase()\n\t\t.split(' ')\n\t\t.filter((word) => word.length > 0)\n\t\t.every((word) => haystack.includes(word))\n}\n\nconst evaluateOperator = (operator: Operator, answer: unknown, value: unknown): boolean => {\n\tswitch (operator) {\n\t\tcase 'equals':\n\t\t\treturn isNil(value) ? isNil(answer) : valuesEqual(answer, value)\n\t\tcase 'not_equals':\n\t\t\treturn isNil(value) ? !isNil(answer) : isNil(answer) || !valuesEqual(answer, value)\n\t\tcase 'in':\n\t\t\treturn toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'not_in':\n\t\t\treturn isNil(answer) || !toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'exists': {\n\t\t\tconst present = !isNil(answer) && answer !== ''\n\t\t\treturn value === true || value === 'true' ? present : !present\n\t\t}\n\t\tcase 'greater_than':\n\t\t\treturn ordered(answer, value, (a, b) => a > b)\n\t\tcase 'greater_than_equal':\n\t\t\treturn ordered(answer, value, (a, b) => a >= b)\n\t\tcase 'less_than':\n\t\t\treturn ordered(answer, value, (a, b) => a < b)\n\t\tcase 'less_than_equal':\n\t\t\treturn ordered(answer, value, (a, b) => a <= b)\n\t\tcase 'like':\n\t\t\treturn isNil(answer) ? false : everyWord(answer, value)\n\t\tcase 'not_like':\n\t\t\treturn isNil(answer) ? true : !everyWord(answer, value)\n\t\tcase 'contains':\n\t\t\treturn isNil(answer)\n\t\t\t\t? false\n\t\t\t\t: String(answer).toLowerCase().includes(String(value).toLowerCase())\n\t\tdefault:\n\t\t\treturn false\n\t}\n}\n\n/**\n * Evaluate one `Where` node: every top-level key is ANDed. `or` is a disjunction of sub-conditions\n * (an empty `or` matches), `and` is a conjunction, and any other key is a field path whose\n * `{ operator: value }` constraints are ANDed. Recurses, so nested `or`/`and` groups are supported.\n */\nconst evaluateWhere = (where: Where, answers: Record<string, unknown>): boolean =>\n\tObject.entries(where).every(([key, constraint]) => {\n\t\tif (key === 'or') {\n\t\t\tconst groups = (Array.isArray(constraint) ? constraint : []) as Where[]\n\t\t\treturn groups.length === 0 || groups.some((group) => evaluateWhere(group, answers))\n\t\t}\n\t\tif (key === 'and') {\n\t\t\tconst groups = (Array.isArray(constraint) ? constraint : []) as Where[]\n\t\t\treturn groups.every((group) => evaluateWhere(group, answers))\n\t\t}\n\t\tif (constraint == null || typeof constraint !== 'object' || Array.isArray(constraint)) {\n\t\t\treturn false\n\t\t}\n\t\treturn Object.entries(constraint as Record<string, unknown>).every(([operator, value]) =>\n\t\t\tevaluateOperator(operator as Operator, answers[key], value)\n\t\t)\n\t})\n\n/**\n * Evaluate a serializable `Where`-shaped condition against a flat map of (already coerced) form answers.\n * An absent or empty condition matches (returns true). Operator semantics mirror Payload's query\n * adapters: coerce then compare; `not_equals`/`not_in` are null-inclusive; `exists` treats `''`/absent\n * as not-existing; `like` is case-insensitive and space-splits (every word must be a substring), and\n * `not_like` is its logical negation (at least one word absent); `contains` is a single case-insensitive\n * substring; comma-delimited `in`/`not_in` string values are split and trimmed. Geo (`near`/`within`/\n * `intersects`) and `all` are out of scope and evaluate to false. Isomorphic: no `req`/DB access, so the\n * renderer reuses it client-side.\n */\nexport const evaluateCondition = (\n\twhere: Where | null | undefined,\n\tanswers: Record<string, unknown>\n): boolean => {\n\tif (!where || Object.keys(where).length === 0) {\n\t\treturn true\n\t}\n\treturn evaluateWhere(transformWhereQuery(where), answers)\n}\n"],"mappings":";;AAGA,MAAM,SAAS,UAA4B,UAAU,QAAQ,UAAU,KAAA;AAEvE,MAAM,YAAY,UAAuC;CACxD,IAAI,OAAO,UAAU,UACpB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAA;CAEzC,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;EACrD,MAAM,OAAO,OAAO,KAAK;EACzB,OAAO,OAAO,MAAM,IAAI,IAAI,KAAA,IAAY;CACzC;AAED;AAEA,MAAM,UAAU,UAAuC;CACtD,IAAI,iBAAiB,MACpB,OAAO,MAAM,QAAQ;CAEtB,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;EACrD,MAAM,OAAO,KAAK,MAAM,KAAK;EAC7B,OAAO,OAAO,MAAM,IAAI,IAAI,KAAA,IAAY;CACzC;AAED;;AAGA,MAAM,eAAe,QAAiB,UAA4B;CACjE,IAAI,WAAW,OACd,OAAO;CAER,IAAI,MAAM,MAAM,KAAK,MAAM,KAAK,GAC/B,OAAO;CAER,MAAM,IAAI,SAAS,MAAM;CACzB,MAAM,IAAI,SAAS,KAAK;CACxB,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAC5B,OAAO,MAAM;CAEd,OAAO,OAAO,MAAM,MAAM,OAAO,KAAK;AACvC;AAEA,MAAM,UAAU,UAA8B;CAC7C,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO;CAER,IAAI,OAAO,UAAU,UACpB,OAAO,MAAM,MAAM,GAAG,EAAE,KAAK,UAAU,MAAM,KAAK,CAAC;CAEpD,OAAO,CAAC,KAAK;AACd;AAEA,MAAM,WACL,QACA,OACA,YACa;CACb,MAAM,IAAI,SAAS,MAAM,KAAK,OAAO,MAAM;CAC3C,MAAM,IAAI,SAAS,KAAK,KAAK,OAAO,KAAK;CACzC,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAC5B,OAAO;CAER,OAAO,QAAQ,GAAG,CAAC;AACpB;;AAGA,MAAM,aAAa,QAAiB,UAA4B;CAC/D,MAAM,WAAW,OAAO,MAAM,EAAE,YAAY;CAC5C,OAAO,OAAO,KAAK,EACjB,YAAY,EACZ,MAAM,GAAG,EACT,QAAQ,SAAS,KAAK,SAAS,CAAC,EAChC,OAAO,SAAS,SAAS,SAAS,IAAI,CAAC;AAC1C;AAEA,MAAM,oBAAoB,UAAoB,QAAiB,UAA4B;CAC1F,QAAQ,UAAR;EACC,KAAK,UACJ,OAAO,MAAM,KAAK,IAAI,MAAM,MAAM,IAAI,YAAY,QAAQ,KAAK;EAChE,KAAK,cACJ,OAAO,MAAM,KAAK,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,MAAM,KAAK,CAAC,YAAY,QAAQ,KAAK;EACnF,KAAK,MACJ,OAAO,OAAO,KAAK,EAAE,MAAM,UAAU,YAAY,QAAQ,KAAK,CAAC;EAChE,KAAK,UACJ,OAAO,MAAM,MAAM,KAAK,CAAC,OAAO,KAAK,EAAE,MAAM,UAAU,YAAY,QAAQ,KAAK,CAAC;EAClF,KAAK,UAAU;GACd,MAAM,UAAU,CAAC,MAAM,MAAM,KAAK,WAAW;GAC7C,OAAO,UAAU,QAAQ,UAAU,SAAS,UAAU,CAAC;EACxD;EACA,KAAK,gBACJ,OAAO,QAAQ,QAAQ,QAAQ,GAAG,MAAM,IAAI,CAAC;EAC9C,KAAK,sBACJ,OAAO,QAAQ,QAAQ,QAAQ,GAAG,MAAM,KAAK,CAAC;EAC/C,KAAK,aACJ,OAAO,QAAQ,QAAQ,QAAQ,GAAG,MAAM,IAAI,CAAC;EAC9C,KAAK,mBACJ,OAAO,QAAQ,QAAQ,QAAQ,GAAG,MAAM,KAAK,CAAC;EAC/C,KAAK,QACJ,OAAO,MAAM,MAAM,IAAI,QAAQ,UAAU,QAAQ,KAAK;EACvD,KAAK,YACJ,OAAO,MAAM,MAAM,IAAI,OAAO,CAAC,UAAU,QAAQ,KAAK;EACvD,KAAK,YACJ,OAAO,MAAM,MAAM,IAChB,QACA,OAAO,MAAM,EAAE,YAAY,EAAE,SAAS,OAAO,KAAK,EAAE,YAAY,CAAC;EACrE,SACC,OAAO;CACT;AACD;;;;;;AAOA,MAAM,iBAAiB,OAAc,YACpC,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAC,KAAK,gBAAgB;CAClD,IAAI,QAAQ,MAAM;EACjB,MAAM,SAAU,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC;EAC1D,OAAO,OAAO,WAAW,KAAK,OAAO,MAAM,UAAU,cAAc,OAAO,OAAO,CAAC;CACnF;CACA,IAAI,QAAQ,OAEX,QADgB,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,GAC5C,OAAO,UAAU,cAAc,OAAO,OAAO,CAAC;CAE7D,IAAI,cAAc,QAAQ,OAAO,eAAe,YAAY,MAAM,QAAQ,UAAU,GACnF,OAAO;CAER,OAAO,OAAO,QAAQ,UAAqC,EAAE,OAAO,CAAC,UAAU,WAC9E,iBAAiB,UAAsB,QAAQ,MAAM,KAAK,CAC3D;AACD,CAAC;;;;;;;;;;;AAYF,MAAa,qBACZ,OACA,YACa;CACb,IAAI,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,WAAW,GAC3C,OAAO;CAER,OAAO,cAAc,oBAAoB,KAAK,GAAG,OAAO;AACzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/conditions/fieldTypes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The condition input families the builder supports. A deliberate subset of Payload's field-condition
|
|
4
|
+
* types, restricted to the operators `evaluateCondition` implements (no geo/relationship in v1).
|
|
5
|
+
*/
|
|
6
|
+
type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date';
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ConditionFieldType };
|
|
9
|
+
//# sourceMappingURL=fieldTypes.d.ts.map
|
|
@@ -83,6 +83,6 @@ const operatorValueShape = (operator) => {
|
|
|
83
83
|
return "scalar";
|
|
84
84
|
};
|
|
85
85
|
//#endregion
|
|
86
|
-
export {
|
|
86
|
+
export { conditionOperators, defaultConditionType, firstOperatorFor, operatorLabelKey, operatorValueShape };
|
|
87
87
|
|
|
88
|
-
//# sourceMappingURL=fieldTypes
|
|
88
|
+
//# sourceMappingURL=fieldTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldTypes.js","names":[],"sources":["../../src/conditions/fieldTypes.ts"],"sourcesContent":["import type { Operator } from 'payload'\nimport type { FormFieldValueKind } from '../fields/types'\n\n/**\n * The condition input families the builder supports. A deliberate subset of Payload's field-condition\n * types, restricted to the operators `evaluateCondition` implements (no geo/relationship in v1).\n */\nexport type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date'\n\nconst EQUALITY: Operator[] = ['equals', 'not_equals']\nconst MEMBERSHIP: Operator[] = ['in', 'not_in']\nconst ORDER: Operator[] = ['greater_than', 'greater_than_equal', 'less_than', 'less_than_equal']\nconst TEXT_MATCH: Operator[] = ['like', 'not_like', 'contains']\nconst EXISTS: Operator[] = ['exists']\n\n/** Operators offered per condition type. Each is implemented by `evaluateCondition`. */\nexport const conditionOperators: Record<ConditionFieldType, Operator[]> = {\n\ttext: [...EQUALITY, ...MEMBERSHIP, ...TEXT_MATCH, ...EXISTS],\n\tnumber: [...EQUALITY, ...MEMBERSHIP, ...ORDER, ...EXISTS],\n\tselect: [...EQUALITY, ...MEMBERSHIP, ...EXISTS],\n\tcheckbox: [...EQUALITY, ...EXISTS],\n\tdate: [...EQUALITY, ...ORDER, ...EXISTS],\n}\n\n/** Default condition input for a stored value kind; a field type may override via its `conditionType`. */\nexport const defaultConditionType = (value: FormFieldValueKind): ConditionFieldType => {\n\tswitch (value) {\n\t\tcase 'number':\n\t\t\treturn 'number'\n\t\tcase 'boolean':\n\t\t\treturn 'checkbox'\n\t\tcase 'date':\n\t\t\treturn 'date'\n\t\tcase 'text[]':\n\t\t\treturn 'select'\n\t\tdefault:\n\t\t\treturn 'text'\n\t}\n}\n\n/**\n * The Payload `operators:*` i18n keys the builder uses for operator labels. A local literal union (not\n * imported from `@payloadcms/translations`, which this package never depends on); each member is a real\n * client translation key, so a value of this type is accepted by Payload's `i18n.t`.\n */\nexport type OperatorLabelKey =\n\t| 'operators:contains'\n\t| 'operators:equals'\n\t| 'operators:exists'\n\t| 'operators:isGreaterThan'\n\t| 'operators:isGreaterThanOrEqualTo'\n\t| 'operators:isIn'\n\t| 'operators:isLessThan'\n\t| 'operators:isLessThanOrEqualTo'\n\t| 'operators:isLike'\n\t| 'operators:isNotEqualTo'\n\t| 'operators:isNotIn'\n\t| 'operators:isNotLike'\n\nconst OPERATOR_LABEL_KEYS: Partial<Record<Operator, OperatorLabelKey>> = {\n\tequals: 'operators:equals',\n\tnot_equals: 'operators:isNotEqualTo',\n\tin: 'operators:isIn',\n\tnot_in: 'operators:isNotIn',\n\texists: 'operators:exists',\n\tgreater_than: 'operators:isGreaterThan',\n\tgreater_than_equal: 'operators:isGreaterThanOrEqualTo',\n\tless_than: 'operators:isLessThan',\n\tless_than_equal: 'operators:isLessThanOrEqualTo',\n\tlike: 'operators:isLike',\n\tnot_like: 'operators:isNotLike',\n\tcontains: 'operators:contains',\n}\n\n/**\n * The i18n key for an operator's label, in Payload's own `operators:*` namespace (always present in the\n * admin), so the builder reads native, localized operator labels without duplicating them in our i18n.\n * Keys mirror Payload's `WhereBuilder/field-types.tsx` operator labels. Every operator surfaced by\n * `conditionOperators` is mapped; the `operators:equals` fallback is unreachable for the offered\n * catalogs (no geo/`all` operator is ever presented) and exists only to keep the return type total.\n */\nexport const operatorLabelKey = (operator: Operator): OperatorLabelKey =>\n\tOPERATOR_LABEL_KEYS[operator] ?? 'operators:equals'\n\n/**\n * The first (default) operator a condition type offers. Every catalog leads with `equals`, so the\n * fallback is unreachable; it exists only to keep the return non-optional under `noUncheckedIndexedAccess`.\n */\nexport const firstOperatorFor = (type: ConditionFieldType): Operator =>\n\tconditionOperators[type][0] ?? 'equals'\n\n/** The value control an operator needs: a boolean toggle (`exists`), a list (`in`/`not_in`), or a scalar. */\nexport const operatorValueShape = (operator: Operator): 'boolean' | 'array' | 'scalar' => {\n\tif (operator === 'exists') {\n\t\treturn 'boolean'\n\t}\n\tif (operator === 'in' || operator === 'not_in') {\n\t\treturn 'array'\n\t}\n\treturn 'scalar'\n}\n"],"mappings":";AASA,MAAM,WAAuB,CAAC,UAAU,YAAY;AACpD,MAAM,aAAyB,CAAC,MAAM,QAAQ;AAC9C,MAAM,QAAoB;CAAC;CAAgB;CAAsB;CAAa;AAAiB;AAC/F,MAAM,aAAyB;CAAC;CAAQ;CAAY;AAAU;AAC9D,MAAM,SAAqB,CAAC,QAAQ;;AAGpC,MAAa,qBAA6D;CACzE,MAAM;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;EAAY,GAAG;CAAM;CAC3D,QAAQ;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;EAAO,GAAG;CAAM;CACxD,QAAQ;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;CAAM;CAC9C,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM;CACjC,MAAM;EAAC,GAAG;EAAU,GAAG;EAAO,GAAG;CAAM;AACxC;;AAGA,MAAa,wBAAwB,UAAkD;CACtF,QAAQ,OAAR;EACC,KAAK,UACJ,OAAO;EACR,KAAK,WACJ,OAAO;EACR,KAAK,QACJ,OAAO;EACR,KAAK,UACJ,OAAO;EACR,SACC,OAAO;CACT;AACD;AAqBA,MAAM,sBAAmE;CACxE,QAAQ;CACR,YAAY;CACZ,IAAI;CACJ,QAAQ;CACR,QAAQ;CACR,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,UAAU;AACX;;;;;;;;AASA,MAAa,oBAAoB,aAChC,oBAAoB,aAAa;;;;;AAMlC,MAAa,oBAAoB,SAChC,mBAAmB,MAAM,MAAM;;AAGhC,MAAa,sBAAsB,aAAuD;CACzF,IAAI,aAAa,UAChB,OAAO;CAER,IAAI,aAAa,QAAQ,aAAa,UACrC,OAAO;CAER,OAAO;AACR"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { conditionOperators } from "./fieldTypes.js";
|
|
2
|
+
import { transformWhereQuery } from "payload/shared";
|
|
3
|
+
//#region src/conditions/normalizeConditions.ts
|
|
4
|
+
const isValidConstraint = (constraint, operandTypes) => {
|
|
5
|
+
if (constraint == null || typeof constraint !== "object") return false;
|
|
6
|
+
const field = Object.keys(constraint)[0];
|
|
7
|
+
if (!field) return false;
|
|
8
|
+
const type = operandTypes.get(field);
|
|
9
|
+
if (!type) return false;
|
|
10
|
+
const ops = constraint[field];
|
|
11
|
+
if (ops == null || typeof ops !== "object") return false;
|
|
12
|
+
const operator = Object.keys(ops)[0];
|
|
13
|
+
return Boolean(operator && conditionOperators[type].includes(operator));
|
|
14
|
+
};
|
|
15
|
+
const normalizeOne = (raw, operandTypes) => {
|
|
16
|
+
if (raw == null || typeof raw !== "object" || Object.keys(raw).length === 0) return;
|
|
17
|
+
const canonical = transformWhereQuery(raw);
|
|
18
|
+
const groups = (Array.isArray(canonical.or) ? canonical.or : Array.isArray(canonical.and) ? [{ and: canonical.and }] : []).map((group) => {
|
|
19
|
+
return (Array.isArray(group.and) ? group.and : []).filter((constraint) => isValidConstraint(constraint, operandTypes));
|
|
20
|
+
}).filter((group) => group.length > 0);
|
|
21
|
+
return groups.length > 0 ? { or: groups.map((and) => ({ and })) } : void 0;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Normalize every field's `visibleWhen`/`validateWhen` against the form's own field list. Canonicalizes
|
|
25
|
+
* to OR-of-ANDs and strips constraints whose operand field is missing or whose operator is invalid for
|
|
26
|
+
* that field's condition type, so stored conditions always match what `evaluateCondition` can run.
|
|
27
|
+
*/
|
|
28
|
+
const normalizeFormConditions = (fields, conditionTypes) => {
|
|
29
|
+
const operandTypes = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const row of fields) {
|
|
31
|
+
const name = typeof row.name === "string" ? row.name.trim() : "";
|
|
32
|
+
if (name.length > 0) operandTypes.set(name, conditionTypes[row.blockType] ?? "text");
|
|
33
|
+
}
|
|
34
|
+
return fields.map((row) => {
|
|
35
|
+
const visibleWhen = normalizeOne(row.visibleWhen, operandTypes);
|
|
36
|
+
const validateWhen = normalizeOne(row.validateWhen, operandTypes);
|
|
37
|
+
return {
|
|
38
|
+
...row,
|
|
39
|
+
visibleWhen,
|
|
40
|
+
validateWhen
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { normalizeFormConditions };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=normalizeConditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeConditions.js","names":[],"sources":["../../src/conditions/normalizeConditions.ts"],"sourcesContent":["import type { Where } from 'payload'\nimport { transformWhereQuery } from 'payload/shared'\nimport type { ConditionFieldType } from './fieldTypes'\nimport { conditionOperators } from './fieldTypes'\n\nexport type FieldRow = {\n\tblockType: string\n\tname?: string\n\tvisibleWhen?: unknown\n\tvalidateWhen?: unknown\n\t[key: string]: unknown\n}\n\nconst isValidConstraint = (\n\tconstraint: unknown,\n\toperandTypes: Map<string, ConditionFieldType>\n): boolean => {\n\tif (constraint == null || typeof constraint !== 'object') {\n\t\treturn false\n\t}\n\tconst field = Object.keys(constraint as object)[0]\n\tif (!field) {\n\t\treturn false\n\t}\n\tconst type = operandTypes.get(field)\n\tif (!type) {\n\t\treturn false\n\t}\n\tconst ops = (constraint as Record<string, unknown>)[field]\n\tif (ops == null || typeof ops !== 'object') {\n\t\treturn false\n\t}\n\tconst operator = Object.keys(ops as object)[0]\n\treturn Boolean(operator && (conditionOperators[type] as readonly string[]).includes(operator))\n}\n\nconst normalizeOne = (\n\traw: unknown,\n\toperandTypes: Map<string, ConditionFieldType>\n): Where | undefined => {\n\tif (raw == null || typeof raw !== 'object' || Object.keys(raw as object).length === 0) {\n\t\treturn undefined\n\t}\n\tconst canonical = transformWhereQuery(raw as Where)\n\tconst or = Array.isArray(canonical.or)\n\t\t? canonical.or\n\t\t: Array.isArray(canonical.and)\n\t\t\t? [{ and: canonical.and }]\n\t\t\t: []\n\tconst groups = or\n\t\t.map((group) => {\n\t\t\tconst and = Array.isArray((group as Where).and) ? ((group as Where).and as unknown[]) : []\n\t\t\treturn and.filter((constraint) => isValidConstraint(constraint, operandTypes))\n\t\t})\n\t\t.filter((group) => group.length > 0)\n\treturn groups.length > 0 ? ({ or: groups.map((and) => ({ and })) } as Where) : undefined\n}\n\n/**\n * Normalize every field's `visibleWhen`/`validateWhen` against the form's own field list. Canonicalizes\n * to OR-of-ANDs and strips constraints whose operand field is missing or whose operator is invalid for\n * that field's condition type, so stored conditions always match what `evaluateCondition` can run.\n */\nexport const normalizeFormConditions = (\n\tfields: FieldRow[],\n\tconditionTypes: Record<string, ConditionFieldType>\n): FieldRow[] => {\n\tconst operandTypes = new Map<string, ConditionFieldType>()\n\tfor (const row of fields) {\n\t\tconst name = typeof row.name === 'string' ? row.name.trim() : ''\n\t\tif (name.length > 0) {\n\t\t\toperandTypes.set(name, conditionTypes[row.blockType] ?? 'text')\n\t\t}\n\t}\n\treturn fields.map((row) => {\n\t\tconst visibleWhen = normalizeOne(row.visibleWhen, operandTypes)\n\t\tconst validateWhen = normalizeOne(row.validateWhen, operandTypes)\n\t\treturn { ...row, visibleWhen, validateWhen }\n\t})\n}\n"],"mappings":";;;AAaA,MAAM,qBACL,YACA,iBACa;CACb,IAAI,cAAc,QAAQ,OAAO,eAAe,UAC/C,OAAO;CAER,MAAM,QAAQ,OAAO,KAAK,UAAoB,EAAE;CAChD,IAAI,CAAC,OACJ,OAAO;CAER,MAAM,OAAO,aAAa,IAAI,KAAK;CACnC,IAAI,CAAC,MACJ,OAAO;CAER,MAAM,MAAO,WAAuC;CACpD,IAAI,OAAO,QAAQ,OAAO,QAAQ,UACjC,OAAO;CAER,MAAM,WAAW,OAAO,KAAK,GAAa,EAAE;CAC5C,OAAO,QAAQ,YAAa,mBAAmB,MAA4B,SAAS,QAAQ,CAAC;AAC9F;AAEA,MAAM,gBACL,KACA,iBACuB;CACvB,IAAI,OAAO,QAAQ,OAAO,QAAQ,YAAY,OAAO,KAAK,GAAa,EAAE,WAAW,GACnF;CAED,MAAM,YAAY,oBAAoB,GAAY;CAMlD,MAAM,UALK,MAAM,QAAQ,UAAU,EAAE,IAClC,UAAU,KACV,MAAM,QAAQ,UAAU,GAAG,IAC1B,CAAC,EAAE,KAAK,UAAU,IAAI,CAAC,IACvB,CAAC,GAEH,KAAK,UAAU;EAEf,QADY,MAAM,QAAS,MAAgB,GAAG,IAAM,MAAgB,MAAoB,CAAC,GAC9E,QAAQ,eAAe,kBAAkB,YAAY,YAAY,CAAC;CAC9E,CAAC,EACA,QAAQ,UAAU,MAAM,SAAS,CAAC;CACpC,OAAO,OAAO,SAAS,IAAK,EAAE,IAAI,OAAO,KAAK,SAAS,EAAE,IAAI,EAAE,EAAE,IAAc,KAAA;AAChF;;;;;;AAOA,MAAa,2BACZ,QACA,mBACgB;CAChB,MAAM,+BAAe,IAAI,IAAgC;CACzD,KAAK,MAAM,OAAO,QAAQ;EACzB,MAAM,OAAO,OAAO,IAAI,SAAS,WAAW,IAAI,KAAK,KAAK,IAAI;EAC9D,IAAI,KAAK,SAAS,GACjB,aAAa,IAAI,MAAM,eAAe,IAAI,cAAc,MAAM;CAEhE;CACA,OAAO,OAAO,KAAK,QAAQ;EAC1B,MAAM,cAAc,aAAa,IAAI,aAAa,YAAY;EAC9D,MAAM,eAAe,aAAa,IAAI,cAAc,YAAY;EAChE,OAAO;GAAE,GAAG;GAAK;GAAa;EAAa;CAC5C,CAAC;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Where as Where$1 } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/conditions/types.d.ts
|
|
4
|
+
/** A serializable field-visibility/validation condition, stored in Payload's canonical `Where` shape. */
|
|
5
|
+
type FieldCondition = Where$1;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FieldCondition };
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../translations/server.js";
|
|
3
|
+
//#region src/consent/buildConsentSourceConfig.ts
|
|
4
|
+
/**
|
|
5
|
+
* Builds the `source` select and `sourceConfig` group for the consent field block.
|
|
6
|
+
* Fields inside `sourceConfig` are annotated with `admin.condition` so only the
|
|
7
|
+
* fields that belong to the currently selected source type are visible in the admin UI.
|
|
8
|
+
*
|
|
9
|
+
* `resolveConsentLinks` reads `field.sourceConfig` as a flat object; field names within
|
|
10
|
+
* that group must be unique across all registered sources. Built-in sources (static,
|
|
11
|
+
* pageReference) have no overlapping names. Custom sources should follow the same rule.
|
|
12
|
+
*/
|
|
13
|
+
const buildConsentSourceConfig = (registry) => {
|
|
14
|
+
const sources = [...registry.values()];
|
|
15
|
+
const firstType = sources[0]?.type ?? "static";
|
|
16
|
+
const sourceConfigFields = sources.flatMap((source) => (source.config ?? []).map((field) => {
|
|
17
|
+
const existingAdmin = typeof field.admin === "object" && field.admin !== null ? field.admin : {};
|
|
18
|
+
return {
|
|
19
|
+
...field,
|
|
20
|
+
admin: {
|
|
21
|
+
...existingAdmin,
|
|
22
|
+
condition: (data) => data?.source === source.type
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}));
|
|
26
|
+
return [{
|
|
27
|
+
name: "source",
|
|
28
|
+
type: "select",
|
|
29
|
+
defaultValue: firstType,
|
|
30
|
+
label: labelFor(keys.consentConfigSource),
|
|
31
|
+
options: sources.map((s) => ({
|
|
32
|
+
label: labelFor(s.label),
|
|
33
|
+
value: s.type
|
|
34
|
+
}))
|
|
35
|
+
}, {
|
|
36
|
+
name: "sourceConfig",
|
|
37
|
+
type: "group",
|
|
38
|
+
label: labelFor(keys.consentConfigSourceConfig),
|
|
39
|
+
fields: sourceConfigFields.length > 0 ? sourceConfigFields : [{
|
|
40
|
+
name: "_placeholder",
|
|
41
|
+
type: "text",
|
|
42
|
+
admin: { hidden: true }
|
|
43
|
+
}]
|
|
44
|
+
}];
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { buildConsentSourceConfig };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=buildConsentSourceConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildConsentSourceConfig.js","names":[],"sources":["../../src/consent/buildConsentSourceConfig.ts"],"sourcesContent":["import type { Field } from 'payload'\nimport { keys } from '../translations/keys'\nimport { labelFor } from '../translations/server'\nimport type { ConsentSourceRegistry } from './registry'\n\n/**\n * Builds the `source` select and `sourceConfig` group for the consent field block.\n * Fields inside `sourceConfig` are annotated with `admin.condition` so only the\n * fields that belong to the currently selected source type are visible in the admin UI.\n *\n * `resolveConsentLinks` reads `field.sourceConfig` as a flat object; field names within\n * that group must be unique across all registered sources. Built-in sources (static,\n * pageReference) have no overlapping names. Custom sources should follow the same rule.\n */\nexport const buildConsentSourceConfig = (registry: ConsentSourceRegistry): Field[] => {\n\tconst sources = [...registry.values()]\n\tconst firstType = sources[0]?.type ?? 'static'\n\n\tconst sourceConfigFields: Field[] = sources.flatMap((source) =>\n\t\t(source.config ?? []).map((field) => {\n\t\t\tconst existingAdmin =\n\t\t\t\ttypeof field.admin === 'object' && field.admin !== null ? field.admin : {}\n\t\t\treturn {\n\t\t\t\t...field,\n\t\t\t\tadmin: {\n\t\t\t\t\t...existingAdmin,\n\t\t\t\t\tcondition: (data: unknown) => (data as Record<string, unknown>)?.source === source.type,\n\t\t\t\t},\n\t\t\t} as Field\n\t\t})\n\t)\n\n\treturn [\n\t\t{\n\t\t\tname: 'source',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: firstType,\n\t\t\tlabel: labelFor(keys.consentConfigSource),\n\t\t\toptions: sources.map((s) => ({\n\t\t\t\tlabel: labelFor(s.label),\n\t\t\t\tvalue: s.type,\n\t\t\t})),\n\t\t},\n\t\t{\n\t\t\tname: 'sourceConfig',\n\t\t\ttype: 'group',\n\t\t\tlabel: labelFor(keys.consentConfigSourceConfig),\n\t\t\tfields:\n\t\t\t\tsourceConfigFields.length > 0\n\t\t\t\t\t? sourceConfigFields\n\t\t\t\t\t: [{ name: '_placeholder', type: 'text', admin: { hidden: true } }],\n\t\t},\n\t]\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,4BAA4B,aAA6C;CACrF,MAAM,UAAU,CAAC,GAAG,SAAS,OAAO,CAAC;CACrC,MAAM,YAAY,QAAQ,IAAI,QAAQ;CAEtC,MAAM,qBAA8B,QAAQ,SAAS,YACnD,OAAO,UAAU,CAAC,GAAG,KAAK,UAAU;EACpC,MAAM,gBACL,OAAO,MAAM,UAAU,YAAY,MAAM,UAAU,OAAO,MAAM,QAAQ,CAAC;EAC1E,OAAO;GACN,GAAG;GACH,OAAO;IACN,GAAG;IACH,YAAY,SAAmB,MAAkC,WAAW,OAAO;GACpF;EACD;CACD,CAAC,CACF;CAEA,OAAO,CACN;EACC,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,SAAS,KAAK,mBAAmB;EACxC,SAAS,QAAQ,KAAK,OAAO;GAC5B,OAAO,SAAS,EAAE,KAAK;GACvB,OAAO,EAAE;EACV,EAAE;CACH,GACA;EACC,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,yBAAyB;EAC9C,QACC,mBAAmB,SAAS,IACzB,qBACA,CAAC;GAAE,MAAM;GAAgB,MAAM;GAAQ,OAAO,EAAE,QAAQ,KAAK;EAAE,CAAC;CACrE,CACD;AACD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyConsentSource } from "../defineConsentSource.js";
|
|
2
|
+
|
|
3
|
+
//#region src/consent/builtin/index.d.ts
|
|
4
|
+
declare const defaultConsentSources: Record<string, AnyConsentSource>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { defaultConsentSources };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { pageReferenceSource } from "./pageReference.js";
|
|
2
|
+
import { staticSource } from "./static.js";
|
|
3
|
+
//#region src/consent/builtin/index.ts
|
|
4
|
+
const defaultConsentSources = {
|
|
5
|
+
static: staticSource,
|
|
6
|
+
pageReference: pageReferenceSource
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { defaultConsentSources };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/consent/builtin/index.ts"],"sourcesContent":["import type { AnyConsentSource } from '../defineConsentSource'\nimport { pageReferenceSource } from './pageReference'\nimport { staticSource } from './static'\n\nexport const defaultConsentSources: Record<string, AnyConsentSource> = {\n\tstatic: staticSource as AnyConsentSource,\n\tpageReference: pageReferenceSource as AnyConsentSource,\n}\n"],"mappings":";;;AAIA,MAAa,wBAA0D;CACtE,QAAQ;CACR,eAAe;AAChB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../../translations/server.js";
|
|
3
|
+
import { defineConsentSource } from "../defineConsentSource.js";
|
|
4
|
+
import { resolvePublishedVersionRef } from "../resolvePublishedVersionRef.js";
|
|
5
|
+
//#region src/consent/builtin/pageReference.ts
|
|
6
|
+
const pageReferenceSource = defineConsentSource({
|
|
7
|
+
type: "pageReference",
|
|
8
|
+
label: keys.consentSourcePageReference,
|
|
9
|
+
config: [
|
|
10
|
+
{
|
|
11
|
+
name: "relationTo",
|
|
12
|
+
type: "text",
|
|
13
|
+
label: labelFor(keys.consentConfigRelationTo)
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "docId",
|
|
17
|
+
type: "text",
|
|
18
|
+
label: labelFor(keys.consentConfigDocId)
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "urlField",
|
|
22
|
+
type: "text",
|
|
23
|
+
label: labelFor(keys.consentConfigUrlField),
|
|
24
|
+
defaultValue: "slug"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "captureVersion",
|
|
28
|
+
type: "checkbox",
|
|
29
|
+
label: labelFor(keys.consentConfigCaptureVersion)
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
resolve: async ({ config, payload, req, locale }) => {
|
|
33
|
+
const relationTo = String(config.relationTo ?? "");
|
|
34
|
+
const docId = String(config.docId ?? "");
|
|
35
|
+
const urlField = String(config.urlField ?? "slug");
|
|
36
|
+
const captureVersion = Boolean(config.captureVersion);
|
|
37
|
+
if (!relationTo || !docId) return { links: [] };
|
|
38
|
+
const doc = await payload.findByID({
|
|
39
|
+
collection: relationTo,
|
|
40
|
+
id: docId,
|
|
41
|
+
depth: 0,
|
|
42
|
+
locale,
|
|
43
|
+
req
|
|
44
|
+
}).catch(() => null);
|
|
45
|
+
if (!doc) return { links: [{
|
|
46
|
+
label: relationTo,
|
|
47
|
+
url: ""
|
|
48
|
+
}] };
|
|
49
|
+
const docRecord = doc;
|
|
50
|
+
const label = String(docRecord.title ?? docRecord[urlField] ?? relationTo);
|
|
51
|
+
const url = String(docRecord[urlField] ?? "");
|
|
52
|
+
if (!captureVersion) return { links: [{
|
|
53
|
+
label,
|
|
54
|
+
url
|
|
55
|
+
}] };
|
|
56
|
+
const v = await resolvePublishedVersionRef(payload, {
|
|
57
|
+
collection: relationTo,
|
|
58
|
+
id: docId
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
links: [{
|
|
62
|
+
label,
|
|
63
|
+
url
|
|
64
|
+
}],
|
|
65
|
+
...v ? {
|
|
66
|
+
versionRef: v.versionId,
|
|
67
|
+
versionLabel: v.updatedAt
|
|
68
|
+
} : {}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { pageReferenceSource };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=pageReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageReference.js","names":[],"sources":["../../../src/consent/builtin/pageReference.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineConsentSource } from '../defineConsentSource'\nimport { resolvePublishedVersionRef } from '../resolvePublishedVersionRef'\n\ntype PageReferenceConfig = {\n\trelationTo?: string\n\tdocId?: string\n\turlField?: string\n\tcaptureVersion?: boolean\n}\n\nexport const pageReferenceSource = defineConsentSource<PageReferenceConfig>({\n\ttype: 'pageReference',\n\tlabel: keys.consentSourcePageReference,\n\tconfig: [\n\t\t{ name: 'relationTo', type: 'text', label: labelFor(keys.consentConfigRelationTo) },\n\t\t{ name: 'docId', type: 'text', label: labelFor(keys.consentConfigDocId) },\n\t\t{\n\t\t\tname: 'urlField',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelFor(keys.consentConfigUrlField),\n\t\t\tdefaultValue: 'slug',\n\t\t},\n\t\t{\n\t\t\tname: 'captureVersion',\n\t\t\ttype: 'checkbox',\n\t\t\tlabel: labelFor(keys.consentConfigCaptureVersion),\n\t\t},\n\t],\n\tresolve: async ({ config, payload, req, locale }) => {\n\t\tconst relationTo = String(config.relationTo ?? '')\n\t\tconst docId = String(config.docId ?? '')\n\t\tconst urlField = String(config.urlField ?? 'slug')\n\t\tconst captureVersion = Boolean(config.captureVersion)\n\n\t\tif (!relationTo || !docId) {\n\t\t\treturn { links: [] }\n\t\t}\n\n\t\tconst doc = await payload\n\t\t\t.findByID({\n\t\t\t\tcollection: relationTo as never,\n\t\t\t\tid: docId,\n\t\t\t\tdepth: 0,\n\t\t\t\tlocale: locale as never,\n\t\t\t\treq,\n\t\t\t})\n\t\t\t.catch(() => null)\n\n\t\tif (!doc) {\n\t\t\treturn { links: [{ label: relationTo, url: '' }] }\n\t\t}\n\n\t\tconst docRecord = doc as Record<string, unknown>\n\t\tconst label = String(docRecord.title ?? docRecord[urlField] ?? relationTo)\n\t\tconst url = String(docRecord[urlField] ?? '')\n\n\t\tif (!captureVersion) {\n\t\t\treturn { links: [{ label, url }] }\n\t\t}\n\n\t\tconst v = await resolvePublishedVersionRef(payload, { collection: relationTo, id: docId })\n\t\treturn {\n\t\t\tlinks: [{ label, url }],\n\t\t\t...(v ? { versionRef: v.versionId, versionLabel: v.updatedAt } : {}),\n\t\t}\n\t},\n})\n"],"mappings":";;;;;AAYA,MAAa,sBAAsB,oBAAyC;CAC3E,MAAM;CACN,OAAO,KAAK;CACZ,QAAQ;EACP;GAAE,MAAM;GAAc,MAAM;GAAQ,OAAO,SAAS,KAAK,uBAAuB;EAAE;EAClF;GAAE,MAAM;GAAS,MAAM;GAAQ,OAAO,SAAS,KAAK,kBAAkB;EAAE;EACxE;GACC,MAAM;GACN,MAAM;GACN,OAAO,SAAS,KAAK,qBAAqB;GAC1C,cAAc;EACf;EACA;GACC,MAAM;GACN,MAAM;GACN,OAAO,SAAS,KAAK,2BAA2B;EACjD;CACD;CACA,SAAS,OAAO,EAAE,QAAQ,SAAS,KAAK,aAAa;EACpD,MAAM,aAAa,OAAO,OAAO,cAAc,EAAE;EACjD,MAAM,QAAQ,OAAO,OAAO,SAAS,EAAE;EACvC,MAAM,WAAW,OAAO,OAAO,YAAY,MAAM;EACjD,MAAM,iBAAiB,QAAQ,OAAO,cAAc;EAEpD,IAAI,CAAC,cAAc,CAAC,OACnB,OAAO,EAAE,OAAO,CAAC,EAAE;EAGpB,MAAM,MAAM,MAAM,QAChB,SAAS;GACT,YAAY;GACZ,IAAI;GACJ,OAAO;GACC;GACR;EACD,CAAC,EACA,YAAY,IAAI;EAElB,IAAI,CAAC,KACJ,OAAO,EAAE,OAAO,CAAC;GAAE,OAAO;GAAY,KAAK;EAAG,CAAC,EAAE;EAGlD,MAAM,YAAY;EAClB,MAAM,QAAQ,OAAO,UAAU,SAAS,UAAU,aAAa,UAAU;EACzE,MAAM,MAAM,OAAO,UAAU,aAAa,EAAE;EAE5C,IAAI,CAAC,gBACJ,OAAO,EAAE,OAAO,CAAC;GAAE;GAAO;EAAI,CAAC,EAAE;EAGlC,MAAM,IAAI,MAAM,2BAA2B,SAAS;GAAE,YAAY;GAAY,IAAI;EAAM,CAAC;EACzF,OAAO;GACN,OAAO,CAAC;IAAE;IAAO;GAAI,CAAC;GACtB,GAAI,IAAI;IAAE,YAAY,EAAE;IAAW,cAAc,EAAE;GAAU,IAAI,CAAC;EACnE;CACD;AACD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../../translations/server.js";
|
|
3
|
+
import { defineConsentSource } from "../defineConsentSource.js";
|
|
4
|
+
//#region src/consent/builtin/static.ts
|
|
5
|
+
const staticSource = defineConsentSource({
|
|
6
|
+
type: "static",
|
|
7
|
+
label: keys.consentSourceStatic,
|
|
8
|
+
config: [
|
|
9
|
+
{
|
|
10
|
+
name: "label",
|
|
11
|
+
type: "text",
|
|
12
|
+
label: labelFor(keys.consentConfigLabel)
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "url",
|
|
16
|
+
type: "text",
|
|
17
|
+
label: labelFor(keys.consentConfigUrl)
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "version",
|
|
21
|
+
type: "text",
|
|
22
|
+
label: labelFor(keys.consentConfigVersion)
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
resolve({ config }) {
|
|
26
|
+
const label = String(config.label ?? "");
|
|
27
|
+
const url = String(config.url ?? "");
|
|
28
|
+
const version = config.version ? String(config.version) : void 0;
|
|
29
|
+
return {
|
|
30
|
+
links: [{
|
|
31
|
+
label,
|
|
32
|
+
url
|
|
33
|
+
}],
|
|
34
|
+
...version ? {
|
|
35
|
+
versionRef: version,
|
|
36
|
+
versionLabel: version
|
|
37
|
+
} : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//#endregion
|
|
42
|
+
export { staticSource };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=static.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.js","names":[],"sources":["../../../src/consent/builtin/static.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineConsentSource } from '../defineConsentSource'\n\ntype StaticConfig = { label?: string; url?: string; version?: string }\n\nexport const staticSource = defineConsentSource<StaticConfig>({\n\ttype: 'static',\n\tlabel: keys.consentSourceStatic,\n\tconfig: [\n\t\t{ name: 'label', type: 'text', label: labelFor(keys.consentConfigLabel) },\n\t\t{ name: 'url', type: 'text', label: labelFor(keys.consentConfigUrl) },\n\t\t{ name: 'version', type: 'text', label: labelFor(keys.consentConfigVersion) },\n\t],\n\tresolve({ config }) {\n\t\tconst label = String(config.label ?? '')\n\t\tconst url = String(config.url ?? '')\n\t\tconst version = config.version ? String(config.version) : undefined\n\t\treturn {\n\t\t\tlinks: [{ label, url }],\n\t\t\t...(version ? { versionRef: version, versionLabel: version } : {}),\n\t\t}\n\t},\n})\n"],"mappings":";;;;AAMA,MAAa,eAAe,oBAAkC;CAC7D,MAAM;CACN,OAAO,KAAK;CACZ,QAAQ;EACP;GAAE,MAAM;GAAS,MAAM;GAAQ,OAAO,SAAS,KAAK,kBAAkB;EAAE;EACxE;GAAE,MAAM;GAAO,MAAM;GAAQ,OAAO,SAAS,KAAK,gBAAgB;EAAE;EACpE;GAAE,MAAM;GAAW,MAAM;GAAQ,OAAO,SAAS,KAAK,oBAAoB;EAAE;CAC7E;CACA,QAAQ,EAAE,UAAU;EACnB,MAAM,QAAQ,OAAO,OAAO,SAAS,EAAE;EACvC,MAAM,MAAM,OAAO,OAAO,OAAO,EAAE;EACnC,MAAM,UAAU,OAAO,UAAU,OAAO,OAAO,OAAO,IAAI,KAAA;EAC1D,OAAO;GACN,OAAO,CAAC;IAAE;IAAO;GAAI,CAAC;GACtB,GAAI,UAAU;IAAE,YAAY;IAAS,cAAc;GAAQ,IAAI,CAAC;EACjE;CACD;AACD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FormFieldInstance } from "../submissions/types.js";
|
|
2
|
+
import { ConsentSourceRegistry } from "./registry.js";
|
|
3
|
+
import { Payload, PayloadRequest } from "payload";
|
|
4
|
+
|
|
5
|
+
//#region src/consent/captureConsent.d.ts
|
|
6
|
+
type ConsentProof = {
|
|
7
|
+
agreed: boolean;
|
|
8
|
+
ref?: string;
|
|
9
|
+
versionRef?: string;
|
|
10
|
+
at: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Build the authoritative consent proof at submit time: re-resolve the source server-side
|
|
14
|
+
* (ignores any client ref), capturing a reference url -- never the policy text.
|
|
15
|
+
* `now` is injected by the caller (`new Date().toISOString()`) for testability.
|
|
16
|
+
*/
|
|
17
|
+
declare const captureConsent: (args: {
|
|
18
|
+
field: FormFieldInstance;
|
|
19
|
+
agreed: boolean;
|
|
20
|
+
registry: ConsentSourceRegistry;
|
|
21
|
+
payload: Payload;
|
|
22
|
+
req?: PayloadRequest;
|
|
23
|
+
locale: string;
|
|
24
|
+
now: string;
|
|
25
|
+
}) => Promise<ConsentProof>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ConsentProof, captureConsent };
|
|
28
|
+
//# sourceMappingURL=captureConsent.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { resolveConsentLinks } from "./resolveConsentLinks.js";
|
|
2
|
+
//#region src/consent/captureConsent.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build the authoritative consent proof at submit time: re-resolve the source server-side
|
|
5
|
+
* (ignores any client ref), capturing a reference url -- never the policy text.
|
|
6
|
+
* `now` is injected by the caller (`new Date().toISOString()`) for testability.
|
|
7
|
+
*/
|
|
8
|
+
const captureConsent = async (args) => {
|
|
9
|
+
const resolved = await resolveConsentLinks(args.field, {
|
|
10
|
+
registry: args.registry,
|
|
11
|
+
payload: args.payload,
|
|
12
|
+
req: args.req,
|
|
13
|
+
locale: args.locale
|
|
14
|
+
});
|
|
15
|
+
const ref = resolved.links[0]?.url || void 0;
|
|
16
|
+
return {
|
|
17
|
+
agreed: args.agreed,
|
|
18
|
+
...ref ? { ref } : {},
|
|
19
|
+
...resolved.versionRef ? { versionRef: resolved.versionRef } : {},
|
|
20
|
+
at: args.now
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { captureConsent };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=captureConsent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureConsent.js","names":[],"sources":["../../src/consent/captureConsent.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { FormFieldInstance } from '../submissions/types'\nimport type { ConsentSourceRegistry } from './registry'\nimport { resolveConsentLinks } from './resolveConsentLinks'\n\nexport type ConsentProof = {\n\tagreed: boolean\n\tref?: string\n\tversionRef?: string\n\tat: string\n}\n\n/**\n * Build the authoritative consent proof at submit time: re-resolve the source server-side\n * (ignores any client ref), capturing a reference url -- never the policy text.\n * `now` is injected by the caller (`new Date().toISOString()`) for testability.\n */\nexport const captureConsent = async (args: {\n\tfield: FormFieldInstance\n\tagreed: boolean\n\tregistry: ConsentSourceRegistry\n\tpayload: Payload\n\treq?: PayloadRequest\n\tlocale: string\n\tnow: string\n}): Promise<ConsentProof> => {\n\tconst resolved = await resolveConsentLinks(args.field, {\n\t\tregistry: args.registry,\n\t\tpayload: args.payload,\n\t\treq: args.req,\n\t\tlocale: args.locale,\n\t})\n\tconst ref = resolved.links[0]?.url || undefined\n\treturn {\n\t\tagreed: args.agreed,\n\t\t...(ref ? { ref } : {}),\n\t\t...(resolved.versionRef ? { versionRef: resolved.versionRef } : {}),\n\t\tat: args.now,\n\t}\n}\n"],"mappings":";;;;;;;AAiBA,MAAa,iBAAiB,OAAO,SAQR;CAC5B,MAAM,WAAW,MAAM,oBAAoB,KAAK,OAAO;EACtD,UAAU,KAAK;EACf,SAAS,KAAK;EACd,KAAK,KAAK;EACV,QAAQ,KAAK;CACd,CAAC;CACD,MAAM,MAAM,SAAS,MAAM,IAAI,OAAO,KAAA;CACtC,OAAO;EACN,QAAQ,KAAK;EACb,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;EACrB,GAAI,SAAS,aAAa,EAAE,YAAY,SAAS,WAAW,IAAI,CAAC;EACjE,IAAI,KAAK;CACV;AACD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Field, Payload, PayloadRequest } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/consent/defineConsentSource.d.ts
|
|
4
|
+
type ConsentLink = {
|
|
5
|
+
label: string;
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
type ConsentResolved = {
|
|
9
|
+
links: ConsentLink[];
|
|
10
|
+
versionRef?: string;
|
|
11
|
+
versionLabel?: string;
|
|
12
|
+
};
|
|
13
|
+
type ConsentResolveArgs<TConfig extends Record<string, unknown> = Record<string, unknown>> = {
|
|
14
|
+
config: TConfig;
|
|
15
|
+
payload: Payload;
|
|
16
|
+
req?: PayloadRequest;
|
|
17
|
+
locale: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A consent source type, authored once: `config` is the admin `Field[]` for authoring;
|
|
21
|
+
* `resolve` returns localized policy links and an optional version reference at capture time.
|
|
22
|
+
* Built-ins use this same primitive.
|
|
23
|
+
*/
|
|
24
|
+
type ConsentSource<TConfig extends Record<string, unknown> = Record<string, unknown>> = {
|
|
25
|
+
type: string;
|
|
26
|
+
label: string;
|
|
27
|
+
config?: Field[];
|
|
28
|
+
resolve: (args: ConsentResolveArgs<TConfig>) => Promise<ConsentResolved> | ConsentResolved;
|
|
29
|
+
};
|
|
30
|
+
/** Erased shape stored in the registry; config re-narrows per matched type at resolution. */
|
|
31
|
+
type AnyConsentSource = ConsentSource<Record<string, unknown>>;
|
|
32
|
+
declare const defineConsentSource: <TConfig extends Record<string, unknown> = Record<string, unknown>>(source: ConsentSource<TConfig>) => ConsentSource<TConfig>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { AnyConsentSource, ConsentLink, ConsentResolveArgs, ConsentResolved, ConsentSource, defineConsentSource };
|
|
35
|
+
//# sourceMappingURL=defineConsentSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConsentSource.js","names":[],"sources":["../../src/consent/defineConsentSource.ts"],"sourcesContent":["import type { Field, Payload, PayloadRequest } from 'payload'\n\nexport type ConsentLink = { label: string; url: string }\nexport type ConsentResolved = { links: ConsentLink[]; versionRef?: string; versionLabel?: string }\n\nexport type ConsentResolveArgs<TConfig extends Record<string, unknown> = Record<string, unknown>> =\n\t{\n\t\tconfig: TConfig\n\t\tpayload: Payload\n\t\treq?: PayloadRequest\n\t\tlocale: string\n\t}\n\n/**\n * A consent source type, authored once: `config` is the admin `Field[]` for authoring;\n * `resolve` returns localized policy links and an optional version reference at capture time.\n * Built-ins use this same primitive.\n */\nexport type ConsentSource<TConfig extends Record<string, unknown> = Record<string, unknown>> = {\n\ttype: string\n\tlabel: string\n\tconfig?: Field[]\n\tresolve: (args: ConsentResolveArgs<TConfig>) => Promise<ConsentResolved> | ConsentResolved\n}\n\n/** Erased shape stored in the registry; config re-narrows per matched type at resolution. */\nexport type AnyConsentSource = ConsentSource<Record<string, unknown>>\n\nexport const defineConsentSource = <\n\tTConfig extends Record<string, unknown> = Record<string, unknown>,\n>(\n\tsource: ConsentSource<TConfig>\n): ConsentSource<TConfig> => source\n"],"mappings":";AA4BA,MAAa,uBAGZ,WAC4B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnyConsentSource } from "./defineConsentSource.js";
|
|
2
|
+
|
|
3
|
+
//#region src/consent/registry.d.ts
|
|
4
|
+
type ConsentSourceRegistry = Map<string, AnyConsentSource>;
|
|
5
|
+
/** `false` removes a built-in, `true` keeps it, a definition adds or replaces one. */
|
|
6
|
+
type ConsentSourceOption = boolean | AnyConsentSource;
|
|
7
|
+
type ConsentSourcesConfig = Record<string, ConsentSourceOption>;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the active consent-source registry from built-in defaults and a consumer override map.
|
|
10
|
+
* `false` removes a type, `true` keeps the default (no-op when none exists), a definition adds or
|
|
11
|
+
* replaces. Mirrors the action and field-type registry convention.
|
|
12
|
+
*/
|
|
13
|
+
declare const resolveConsentSources: (defaults: Record<string, AnyConsentSource>, config?: ConsentSourcesConfig) => ConsentSourceRegistry;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ConsentSourceOption, ConsentSourceRegistry, ConsentSourcesConfig, resolveConsentSources };
|
|
16
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/consent/registry.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the active consent-source registry from built-in defaults and a consumer override map.
|
|
4
|
+
* `false` removes a type, `true` keeps the default (no-op when none exists), a definition adds or
|
|
5
|
+
* replaces. Mirrors the action and field-type registry convention.
|
|
6
|
+
*/
|
|
7
|
+
const resolveConsentSources = (defaults, config = {}) => {
|
|
8
|
+
const registry = new Map(Object.entries(defaults));
|
|
9
|
+
for (const [type, option] of Object.entries(config)) if (option === false) registry.delete(type);
|
|
10
|
+
else if (option === true) {} else registry.set(type, option);
|
|
11
|
+
return registry;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { resolveConsentSources };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/consent/registry.ts"],"sourcesContent":["import type { AnyConsentSource } from './defineConsentSource'\n\nexport type ConsentSourceRegistry = Map<string, AnyConsentSource>\n\n/** `false` removes a built-in, `true` keeps it, a definition adds or replaces one. */\nexport type ConsentSourceOption = boolean | AnyConsentSource\n\nexport type ConsentSourcesConfig = Record<string, ConsentSourceOption>\n\n/**\n * Resolve the active consent-source registry from built-in defaults and a consumer override map.\n * `false` removes a type, `true` keeps the default (no-op when none exists), a definition adds or\n * replaces. Mirrors the action and field-type registry convention.\n */\nexport const resolveConsentSources = (\n\tdefaults: Record<string, AnyConsentSource>,\n\tconfig: ConsentSourcesConfig = {}\n): ConsentSourceRegistry => {\n\tconst registry: ConsentSourceRegistry = new Map(Object.entries(defaults))\n\tfor (const [type, option] of Object.entries(config)) {\n\t\tif (option === false) {\n\t\t\tregistry.delete(type)\n\t\t} else if (option === true) {\n\t\t\t// keep the default; no-op when no default exists for this key\n\t\t} else {\n\t\t\tregistry.set(type, option)\n\t\t}\n\t}\n\treturn registry\n}\n"],"mappings":";;;;;;AAcA,MAAa,yBACZ,UACA,SAA+B,CAAC,MACL;CAC3B,MAAM,WAAkC,IAAI,IAAI,OAAO,QAAQ,QAAQ,CAAC;CACxE,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GACjD,IAAI,WAAW,OACd,SAAS,OAAO,IAAI;MACd,IAAI,WAAW,MAAM,CAE5B,OACC,SAAS,IAAI,MAAM,MAAM;CAG3B,OAAO;AACR"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormFieldInstance } from "../submissions/types.js";
|
|
2
|
+
import { ConsentResolved } from "./defineConsentSource.js";
|
|
3
|
+
import { ConsentSourceRegistry } from "./registry.js";
|
|
4
|
+
import { Payload, PayloadRequest } from "payload";
|
|
5
|
+
|
|
6
|
+
//#region src/consent/resolveConsentLinks.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a consent field's policy links via its configured source (for display).
|
|
9
|
+
* Unknown/missing source returns empty links. Never throws.
|
|
10
|
+
*/
|
|
11
|
+
declare const resolveConsentLinks: (field: FormFieldInstance, ctx: {
|
|
12
|
+
registry: ConsentSourceRegistry;
|
|
13
|
+
payload: Payload;
|
|
14
|
+
req?: PayloadRequest;
|
|
15
|
+
locale: string;
|
|
16
|
+
}) => Promise<ConsentResolved>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveConsentLinks };
|
|
19
|
+
//# sourceMappingURL=resolveConsentLinks.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/consent/resolveConsentLinks.ts
|
|
2
|
+
const EMPTY = { links: [] };
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a consent field's policy links via its configured source (for display).
|
|
5
|
+
* Unknown/missing source returns empty links. Never throws.
|
|
6
|
+
*/
|
|
7
|
+
const resolveConsentLinks = async (field, ctx) => {
|
|
8
|
+
const sourceType = typeof field.source === "string" ? field.source : "static";
|
|
9
|
+
const source = ctx.registry.get(sourceType);
|
|
10
|
+
if (!source) return EMPTY;
|
|
11
|
+
const sourceConfig = field.sourceConfig && typeof field.sourceConfig === "object" ? field.sourceConfig : {};
|
|
12
|
+
try {
|
|
13
|
+
return await source.resolve({
|
|
14
|
+
config: sourceConfig,
|
|
15
|
+
payload: ctx.payload,
|
|
16
|
+
req: ctx.req,
|
|
17
|
+
locale: ctx.locale
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
return EMPTY;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { resolveConsentLinks };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=resolveConsentLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveConsentLinks.js","names":[],"sources":["../../src/consent/resolveConsentLinks.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { FormFieldInstance } from '../submissions/types'\nimport type { ConsentResolved } from './defineConsentSource'\nimport type { ConsentSourceRegistry } from './registry'\n\nconst EMPTY: ConsentResolved = { links: [] }\n\n/**\n * Resolve a consent field's policy links via its configured source (for display).\n * Unknown/missing source returns empty links. Never throws.\n */\nexport const resolveConsentLinks = async (\n\tfield: FormFieldInstance,\n\tctx: {\n\t\tregistry: ConsentSourceRegistry\n\t\tpayload: Payload\n\t\treq?: PayloadRequest\n\t\tlocale: string\n\t}\n): Promise<ConsentResolved> => {\n\tconst sourceType = typeof field.source === 'string' ? field.source : 'static'\n\tconst source = ctx.registry.get(sourceType)\n\tif (!source) {\n\t\treturn EMPTY\n\t}\n\t// The source params live in the field's `sourceConfig` group (kept off the top level so they cannot collide with the shared field config).\n\tconst sourceConfig =\n\t\tfield.sourceConfig && typeof field.sourceConfig === 'object'\n\t\t\t? (field.sourceConfig as Record<string, unknown>)\n\t\t\t: {}\n\ttry {\n\t\treturn await source.resolve({\n\t\t\tconfig: sourceConfig,\n\t\t\tpayload: ctx.payload,\n\t\t\treq: ctx.req,\n\t\t\tlocale: ctx.locale,\n\t\t})\n\t} catch {\n\t\treturn EMPTY\n\t}\n}\n"],"mappings":";AAKA,MAAM,QAAyB,EAAE,OAAO,CAAC,EAAE;;;;;AAM3C,MAAa,sBAAsB,OAClC,OACA,QAM8B;CAC9B,MAAM,aAAa,OAAO,MAAM,WAAW,WAAW,MAAM,SAAS;CACrE,MAAM,SAAS,IAAI,SAAS,IAAI,UAAU;CAC1C,IAAI,CAAC,QACJ,OAAO;CAGR,MAAM,eACL,MAAM,gBAAgB,OAAO,MAAM,iBAAiB,WAChD,MAAM,eACP,CAAC;CACL,IAAI;EACH,OAAO,MAAM,OAAO,QAAQ;GAC3B,QAAQ;GACR,SAAS,IAAI;GACb,KAAK,IAAI;GACT,QAAQ,IAAI;EACb,CAAC;CACF,QAAQ;EACP,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Payload } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/consent/resolvePublishedVersionRef.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns the latest published version of a doc, or null when versions/drafts are off or nothing
|
|
6
|
+
* is published. Never throws.
|
|
7
|
+
*/
|
|
8
|
+
declare const resolvePublishedVersionRef: (payload: Payload, args: {
|
|
9
|
+
collection: string;
|
|
10
|
+
id: string | number;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
versionId: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
} | null>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { resolvePublishedVersionRef };
|
|
17
|
+
//# sourceMappingURL=resolvePublishedVersionRef.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/consent/resolvePublishedVersionRef.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns the latest published version of a doc, or null when versions/drafts are off or nothing
|
|
4
|
+
* is published. Never throws.
|
|
5
|
+
*/
|
|
6
|
+
const resolvePublishedVersionRef = async (payload, args) => {
|
|
7
|
+
try {
|
|
8
|
+
const doc = (await payload.findVersions({
|
|
9
|
+
collection: args.collection,
|
|
10
|
+
where: { and: [{ parent: { equals: args.id } }, { "version._status": { equals: "published" } }] },
|
|
11
|
+
sort: "-updatedAt",
|
|
12
|
+
limit: 1,
|
|
13
|
+
depth: 0
|
|
14
|
+
}))?.docs?.[0];
|
|
15
|
+
if (!doc) return null;
|
|
16
|
+
return {
|
|
17
|
+
versionId: String(doc.id),
|
|
18
|
+
updatedAt: String(doc.updatedAt)
|
|
19
|
+
};
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { resolvePublishedVersionRef };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=resolvePublishedVersionRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePublishedVersionRef.js","names":[],"sources":["../../src/consent/resolvePublishedVersionRef.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Returns the latest published version of a doc, or null when versions/drafts are off or nothing\n * is published. Never throws.\n */\nexport const resolvePublishedVersionRef = async (\n\tpayload: Payload,\n\targs: { collection: string; id: string | number }\n): Promise<{ versionId: string; updatedAt: string } | null> => {\n\ttry {\n\t\tconst result = await payload.findVersions({\n\t\t\tcollection: args.collection as never,\n\t\t\twhere: {\n\t\t\t\tand: [{ parent: { equals: args.id } }, { 'version._status': { equals: 'published' } }],\n\t\t\t},\n\t\t\tsort: '-updatedAt',\n\t\t\tlimit: 1,\n\t\t\tdepth: 0,\n\t\t})\n\t\tconst doc = result?.docs?.[0]\n\t\tif (!doc) {\n\t\t\treturn null\n\t\t}\n\t\treturn { versionId: String(doc.id), updatedAt: String(doc.updatedAt) }\n\t} catch {\n\t\treturn null\n\t}\n}\n"],"mappings":";;;;;AAMA,MAAa,6BAA6B,OACzC,SACA,SAC8D;CAC9D,IAAI;EAUH,MAAM,OAAM,MATS,QAAQ,aAAa;GACzC,YAAY,KAAK;GACjB,OAAO,EACN,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,QAAQ,YAAY,EAAE,CAAC,EACtF;GACA,MAAM;GACN,OAAO;GACP,OAAO;EACR,CAAC,IACmB,OAAO;EAC3B,IAAI,CAAC,KACJ,OAAO;EAER,OAAO;GAAE,WAAW,OAAO,IAAI,EAAE;GAAG,WAAW,OAAO,IAAI,SAAS;EAAE;CACtE,QAAQ;EACP,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noopSink.js","names":[],"sources":["../../src/events/noopSink.ts"],"sourcesContent":["import type { FormEventSink } from './types'\n\nexport const noopEventSink: FormEventSink = {\n\temit: () => Promise.resolve(),\n}\n"],"mappings":";AAEA,MAAa,gBAA+B,EAC3C,YAAY,QAAQ,QAAQ,EAC7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { noopEventSink } from "./noopSink.js";
|
|
2
|
+
//#region src/events/resolveEventSink.ts
|
|
3
|
+
/** Resolves the configured event sink, falling back to the no-op sink. Consumed by the submission pipeline in a later phase. */
|
|
4
|
+
const resolveEventSink = (sink) => sink ?? noopEventSink;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { resolveEventSink };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=resolveEventSink.js.map
|