@10x-media/form-builder 0.1.0-beta.3 → 0.1.0-beta.5
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 +125 -0
- package/README.md +4 -4
- package/dist/actions/body/serializeBody.d.ts +22 -4
- package/dist/actions/body/serializeBody.js +3 -1
- package/dist/actions/body/serializeBody.js.map +1 -1
- package/dist/actions/body/textOfBody.d.ts +13 -0
- package/dist/actions/body/textOfBody.js +35 -0
- package/dist/actions/body/textOfBody.js.map +1 -0
- package/dist/actions/builtin/confirmation.js +51 -12
- package/dist/actions/builtin/confirmation.js.map +1 -1
- package/dist/actions/builtin/emailTeam.js +82 -34
- package/dist/actions/builtin/emailTeam.js.map +1 -1
- package/dist/actions/builtin/index.d.ts +18 -1
- package/dist/actions/builtin/index.js +21 -7
- package/dist/actions/builtin/index.js.map +1 -1
- package/dist/actions/builtin/signedWebhook.js +2 -16
- package/dist/actions/builtin/signedWebhook.js.map +1 -1
- package/dist/actions/defineAction.d.ts +1 -1
- package/dist/actions/fromAddresses.d.ts +21 -0
- package/dist/actions/fromAddresses.js +74 -0
- package/dist/actions/fromAddresses.js.map +1 -0
- package/dist/actions/runActions.js +2 -0
- package/dist/actions/runActions.js.map +1 -1
- package/dist/actions/task.js +9 -8
- package/dist/actions/task.js.map +1 -1
- package/dist/aggregation/aggregateResponses.d.ts +9 -0
- package/dist/aggregation/aggregateResponses.js +8 -14
- package/dist/aggregation/aggregateResponses.js.map +1 -1
- package/dist/aggregation/resolveResultsRequest.d.ts +35 -6
- package/dist/aggregation/resolveResultsRequest.js +68 -11
- package/dist/aggregation/resolveResultsRequest.js.map +1 -1
- package/dist/calc/computeCalcFields.js +2 -1
- package/dist/calc/computeCalcFields.js.map +1 -1
- package/dist/client/ByteSizeField.d.ts +8 -0
- package/dist/client/ByteSizeField.js +3 -1
- package/dist/client/ByteSizeField.js.map +1 -1
- package/dist/client/ClosePollButton.d.ts +15 -0
- package/dist/client/ClosePollButton.js +80 -0
- package/dist/client/ClosePollButton.js.map +1 -0
- package/dist/client/CondensedArray.d.ts +15 -0
- package/dist/client/CondensedArray.js +97 -0
- package/dist/client/CondensedArray.js.map +1 -0
- package/dist/client/EndpointOptionsSelect.d.ts +45 -0
- package/dist/client/EndpointOptionsSelect.js +103 -0
- package/dist/client/EndpointOptionsSelect.js.map +1 -0
- package/dist/client/FieldBlockLabel.d.ts +18 -0
- package/dist/client/FieldBlockLabel.js +34 -0
- package/dist/client/FieldBlockLabel.js.map +1 -0
- package/dist/client/FieldNameSelect.d.ts +20 -4
- package/dist/client/FieldNameSelect.js +25 -14
- package/dist/client/FieldNameSelect.js.map +1 -1
- package/dist/client/FlowBuilder.d.ts +2 -1
- package/dist/client/FlowBuilder.js +134 -83
- package/dist/client/FlowBuilder.js.map +1 -1
- package/dist/client/RuleDescription.d.ts +21 -0
- package/dist/client/RuleDescription.js +19 -0
- package/dist/client/RuleDescription.js.map +1 -0
- package/dist/client/admin.css +83 -5
- package/dist/client/endpointOptions.js +29 -0
- package/dist/client/endpointOptions.js.map +1 -0
- package/dist/client/flowAuthoring.js +142 -0
- package/dist/client/flowAuthoring.js.map +1 -0
- package/dist/client/synthesizeClientField.js +21 -10
- package/dist/client/synthesizeClientField.js.map +1 -1
- package/dist/collections/buttonFields.d.ts +34 -0
- package/dist/collections/buttonFields.js +35 -0
- package/dist/collections/buttonFields.js.map +1 -0
- package/dist/collections/cells/FieldCountCell.d.ts +15 -0
- package/dist/collections/cells/FieldCountCell.js +18 -0
- package/dist/collections/cells/FieldCountCell.js.map +1 -0
- package/dist/collections/cells/FlowStepsCell.d.ts +14 -0
- package/dist/collections/cells/FlowStepsCell.js +17 -0
- package/dist/collections/cells/FlowStepsCell.js.map +1 -0
- package/dist/collections/formSubmissions.js +55 -12
- package/dist/collections/formSubmissions.js.map +1 -1
- package/dist/collections/forms.js +376 -57
- package/dist/collections/forms.js.map +1 -1
- package/dist/collections/redirectFields.d.ts +29 -0
- package/dist/conditions/conditionType.js +9 -2
- package/dist/conditions/conditionType.js.map +1 -1
- package/dist/conditions/normalizeConditions.js +2 -1
- package/dist/conditions/normalizeConditions.js.map +1 -1
- package/dist/consent/applyConsentStatements.d.ts +14 -0
- package/dist/consent/applyConsentStatements.js +17 -0
- package/dist/consent/applyConsentStatements.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +19 -8
- package/dist/consent/captureConsent.js +34 -11
- package/dist/consent/captureConsent.js.map +1 -1
- package/dist/consent/consentSourcesField.d.ts +58 -0
- package/dist/consent/consentSourcesField.js +79 -0
- package/dist/consent/consentSourcesField.js.map +1 -0
- package/dist/consent/resolveConsentEntries.d.ts +24 -0
- package/dist/consent/resolveConsentEntries.js +43 -0
- package/dist/consent/resolveConsentEntries.js.map +1 -0
- package/dist/consent/resolveConsentSourcesRequest.d.ts +37 -0
- package/dist/consent/resolveConsentSourcesRequest.js +55 -0
- package/dist/consent/resolveConsentSourcesRequest.js.map +1 -0
- package/dist/consent/resolveConsentStatements.d.ts +45 -0
- package/dist/consent/resolveConsentStatements.js +44 -0
- package/dist/consent/resolveConsentStatements.js.map +1 -0
- package/dist/consent/resolvePublishedVersionRef.d.ts +17 -11
- package/dist/consent/resolvePublishedVersionRef.js +13 -10
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
- package/dist/consent/types.d.ts +49 -0
- package/dist/email/departments.d.ts +55 -0
- package/dist/email/departments.js +130 -0
- package/dist/email/departments.js.map +1 -0
- package/dist/email/departmentsField.d.ts +49 -0
- package/dist/email/departmentsField.js +69 -0
- package/dist/email/departmentsField.js.map +1 -0
- package/dist/exports/client.d.ts +8 -1
- package/dist/exports/client.js +8 -1
- package/dist/exports/react.d.ts +15 -6
- package/dist/exports/react.js +11 -3
- package/dist/exports/rsc.d.ts +8 -1
- package/dist/exports/rsc.js +8 -1
- package/dist/exports/types.d.ts +18 -10
- package/dist/fields/buildFieldBlocks.js +43 -19
- package/dist/fields/buildFieldBlocks.js.map +1 -1
- package/dist/fields/builtin/calculation.js +7 -0
- package/dist/fields/builtin/calculation.js.map +1 -1
- package/dist/fields/builtin/checkbox.js +8 -0
- package/dist/fields/builtin/checkbox.js.map +1 -1
- package/dist/fields/builtin/consent.js +25 -15
- package/dist/fields/builtin/consent.js.map +1 -1
- package/dist/fields/builtin/country.d.ts +13 -0
- package/dist/fields/builtin/country.js +30 -0
- package/dist/fields/builtin/country.js.map +1 -0
- package/dist/fields/builtin/date.js +2 -0
- package/dist/fields/builtin/date.js.map +1 -1
- package/dist/fields/builtin/file.js +13 -8
- package/dist/fields/builtin/file.js.map +1 -1
- package/dist/fields/builtin/index.d.ts +13 -1
- package/dist/fields/builtin/index.js +20 -7
- package/dist/fields/builtin/index.js.map +1 -1
- package/dist/fields/builtin/message.js +30 -0
- package/dist/fields/builtin/message.js.map +1 -0
- package/dist/fields/builtin/repeater.js +8 -3
- package/dist/fields/builtin/repeater.js.map +1 -1
- package/dist/fields/builtin/select.js +8 -3
- package/dist/fields/builtin/select.js.map +1 -1
- package/dist/fields/builtin/state.d.ts +13 -0
- package/dist/fields/builtin/state.js +30 -0
- package/dist/fields/builtin/state.js.map +1 -0
- package/dist/fields/data/regions.d.ts +21 -0
- package/dist/fields/data/regions.js +1238 -0
- package/dist/fields/data/regions.js.map +1 -0
- package/dist/fields/fieldKey.d.ts +15 -0
- package/dist/fields/fieldKey.js +16 -0
- package/dist/fields/fieldKey.js.map +1 -0
- package/dist/fields/fieldNamesOfType.js +13 -8
- package/dist/fields/fieldNamesOfType.js.map +1 -1
- package/dist/fields/instanceOptions.js +20 -0
- package/dist/fields/instanceOptions.js.map +1 -0
- package/dist/fields/localizedIf.d.ts +13 -0
- package/dist/fields/localizedIf.js +12 -0
- package/dist/fields/localizedIf.js.map +1 -0
- package/dist/fields/registry.d.ts +1 -0
- package/dist/fields/registry.js +21 -2
- package/dist/fields/registry.js.map +1 -1
- package/dist/fields/sharedConfig.js +101 -51
- package/dist/fields/sharedConfig.js.map +1 -1
- package/dist/fields/types.d.ts +61 -5
- package/dist/flow/engine.d.ts +6 -4
- package/dist/flow/engine.js +11 -6
- package/dist/flow/engine.js.map +1 -1
- package/dist/flow/normalizeFlow.js +22 -7
- package/dist/flow/normalizeFlow.js.map +1 -1
- package/dist/flow/stepLabel.js +15 -0
- package/dist/flow/stepLabel.js.map +1 -0
- package/dist/flow/types.d.ts +12 -3
- package/dist/flow/types.js +11 -0
- package/dist/flow/types.js.map +1 -0
- package/dist/form/pollState.d.ts +22 -0
- package/dist/form/pollState.js +17 -0
- package/dist/form/pollState.js.map +1 -0
- package/dist/form/toFormDocument.d.ts +85 -0
- package/dist/form/toFormDocument.js +75 -0
- package/dist/form/toFormDocument.js.map +1 -0
- package/dist/form/types.d.ts +65 -0
- package/dist/index.d.ts +193 -27
- package/dist/index.js +59 -19
- package/dist/index.js.map +1 -1
- package/dist/plugin/customState.js +26 -0
- package/dist/plugin/customState.js.map +1 -0
- package/dist/plugin/registerCollections.js +33 -44
- package/dist/plugin/registerCollections.js.map +1 -1
- package/dist/plugin/uploadsCollection.d.ts +13 -0
- package/dist/plugin/uploadsCollection.js +44 -0
- package/dist/plugin/uploadsCollection.js.map +1 -0
- package/dist/poll/applyPollOptions.js +18 -0
- package/dist/poll/applyPollOptions.js.map +1 -0
- package/dist/poll/buildPollOptionSourceFields.js +50 -0
- package/dist/poll/buildPollOptionSourceFields.js.map +1 -0
- package/dist/poll/closeJob.d.ts +52 -0
- package/dist/poll/closeJob.js +119 -0
- package/dist/poll/closeJob.js.map +1 -0
- package/dist/poll/definePollOptionSource.d.ts +44 -0
- package/dist/poll/definePollOptionSource.js +6 -0
- package/dist/poll/definePollOptionSource.js.map +1 -0
- package/dist/poll/definePollType.d.ts +34 -0
- package/dist/poll/definePollType.js +6 -0
- package/dist/poll/definePollType.js.map +1 -0
- package/dist/poll/effectivePollOptions.d.ts +38 -0
- package/dist/poll/effectivePollOptions.js +64 -0
- package/dist/poll/effectivePollOptions.js.map +1 -0
- package/dist/poll/mostVoted.d.ts +21 -0
- package/dist/poll/mostVoted.js +32 -0
- package/dist/poll/mostVoted.js.map +1 -0
- package/dist/poll/outcomeBeforeChange.js +91 -0
- package/dist/poll/outcomeBeforeChange.js.map +1 -0
- package/dist/poll/outcomeFields.d.ts +38 -0
- package/dist/poll/outcomeFields.js +52 -0
- package/dist/poll/outcomeFields.js.map +1 -0
- package/dist/poll/pollTypeRegistry.d.ts +34 -0
- package/dist/poll/pollTypeRegistry.js +71 -0
- package/dist/poll/pollTypeRegistry.js.map +1 -0
- package/dist/poll/registry.d.ts +16 -0
- package/dist/poll/registry.js +16 -0
- package/dist/poll/registry.js.map +1 -0
- package/dist/poll/resolvePollCloseRequest.js +105 -0
- package/dist/poll/resolvePollCloseRequest.js.map +1 -0
- package/dist/poll/resolvePollOptions.d.ts +29 -0
- package/dist/poll/resolvePollOptions.js +52 -0
- package/dist/poll/resolvePollOptions.js.map +1 -0
- package/dist/poll/resolvePollOptionsRequest.js +51 -0
- package/dist/poll/resolvePollOptionsRequest.js.map +1 -0
- package/dist/poll/resolvePollOutcome.d.ts +34 -0
- package/dist/poll/resolvePollOutcome.js +76 -0
- package/dist/poll/resolvePollOutcome.js.map +1 -0
- package/dist/poll/resultsField.js +21 -0
- package/dist/poll/resultsField.js.map +1 -0
- package/dist/prefill/valuesFromSearchParams.js +3 -2
- package/dist/prefill/valuesFromSearchParams.js.map +1 -1
- package/dist/presentations/types.d.ts +3 -2
- package/dist/react/Form.d.ts +15 -33
- package/dist/react/Form.js +144 -119
- package/dist/react/Form.js.map +1 -1
- package/dist/react/FormContext.d.ts +37 -1
- package/dist/react/FormContext.js.map +1 -1
- package/dist/react/FormControls.d.ts +55 -0
- package/dist/react/FormControls.js +56 -0
- package/dist/react/FormControls.js.map +1 -0
- package/dist/react/FormResults.d.ts +6 -3
- package/dist/react/FormResults.js +37 -29
- package/dist/react/FormResults.js.map +1 -1
- package/dist/react/FormSteps.d.ts +17 -0
- package/dist/react/FormSteps.js +35 -0
- package/dist/react/FormSteps.js.map +1 -0
- package/dist/react/Poll.d.ts +17 -6
- package/dist/react/Poll.js +66 -18
- package/dist/react/Poll.js.map +1 -1
- package/dist/react/contract.d.ts +2 -3
- package/dist/react/contract.js.map +1 -1
- package/dist/react/fetchResults.d.ts +1 -1
- package/dist/react/fetchResults.js +1 -1
- package/dist/react/fetchResults.js.map +1 -1
- package/dist/react/primitives/Checkbox.d.ts +4 -2
- package/dist/react/primitives/Checkbox.js +2 -1
- package/dist/react/primitives/Checkbox.js.map +1 -1
- package/dist/react/primitives/FieldShell.d.ts +2 -4
- package/dist/react/primitives/FieldShell.js +12 -19
- package/dist/react/primitives/FieldShell.js.map +1 -1
- package/dist/react/renderers/calculation.js +1 -2
- package/dist/react/renderers/calculation.js.map +1 -1
- package/dist/react/renderers/checkbox.js +1 -2
- package/dist/react/renderers/checkbox.js.map +1 -1
- package/dist/react/renderers/consent.js +78 -34
- package/dist/react/renderers/consent.js.map +1 -1
- package/dist/react/renderers/date.js +1 -3
- package/dist/react/renderers/date.js.map +1 -1
- package/dist/react/renderers/email.js +1 -2
- package/dist/react/renderers/email.js.map +1 -1
- package/dist/react/renderers/file.js +6 -3
- package/dist/react/renderers/file.js.map +1 -1
- package/dist/react/renderers/index.js +5 -0
- package/dist/react/renderers/index.js.map +1 -1
- package/dist/react/renderers/message.js +35 -0
- package/dist/react/renderers/message.js.map +1 -0
- package/dist/react/renderers/number.js +1 -2
- package/dist/react/renderers/number.js.map +1 -1
- package/dist/react/renderers/region.js +45 -0
- package/dist/react/renderers/region.js.map +1 -0
- package/dist/react/renderers/repeater.js +7 -10
- package/dist/react/renderers/repeater.js.map +1 -1
- package/dist/react/renderers/select.js +1 -2
- package/dist/react/renderers/select.js.map +1 -1
- package/dist/react/renderers/text.js +1 -2
- package/dist/react/renderers/text.js.map +1 -1
- package/dist/react/renderers/textarea.js +1 -2
- package/dist/react/renderers/textarea.js.map +1 -1
- package/dist/react/state.d.ts +23 -2
- package/dist/react/state.js +16 -7
- package/dist/react/state.js.map +1 -1
- package/dist/react/uploadFile.d.ts +2 -2
- package/dist/react/uploadFile.js +1 -1
- package/dist/react/uploadFile.js.map +1 -1
- package/dist/react/useField.d.ts +0 -1
- package/dist/react/useField.js +0 -1
- package/dist/react/useField.js.map +1 -1
- package/dist/react/useFormState.d.ts +1 -1
- package/dist/react/useFormState.js +1 -1
- package/dist/react/useFormState.js.map +1 -1
- package/dist/react/validateField.js +3 -6
- package/dist/react/validateField.js.map +1 -1
- package/dist/recall/interpolate.d.ts +4 -3
- package/dist/recall/interpolate.js +5 -4
- package/dist/recall/interpolate.js.map +1 -1
- package/dist/recall/resolver.d.ts +1 -1
- package/dist/recall/resolver.js +14 -2
- package/dist/recall/resolver.js.map +1 -1
- package/dist/spam/captcha.d.ts +1 -1
- package/dist/spam/captcha.js +1 -1
- package/dist/spam/captcha.js.map +1 -1
- package/dist/submissions/SubmissionAnswers.js +6 -2
- package/dist/submissions/SubmissionAnswers.js.map +1 -1
- package/dist/submissions/SubmissionAnswersClient.js +91 -62
- package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
- package/dist/submissions/createSubmission.d.ts +36 -0
- package/dist/submissions/createSubmission.js +26 -0
- package/dist/submissions/createSubmission.js.map +1 -0
- package/dist/submissions/runSubmission.d.ts +10 -0
- package/dist/submissions/runSubmission.js +92 -44
- package/dist/submissions/runSubmission.js.map +1 -1
- package/dist/submissions/types.d.ts +11 -4
- package/dist/submissions/validateSubmission.js +59 -10
- package/dist/submissions/validateSubmission.js.map +1 -1
- package/dist/submissions/votedCookie.d.ts +13 -0
- package/dist/submissions/votedCookie.js +27 -0
- package/dist/submissions/votedCookie.js.map +1 -0
- package/dist/translations/de.js +295 -0
- package/dist/translations/de.js.map +1 -0
- package/dist/translations/en.js +138 -23
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/index.d.ts +2 -1
- package/dist/translations/index.js +6 -2
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +134 -19
- package/dist/translations/keys.js +135 -20
- package/dist/translations/keys.js.map +1 -1
- package/dist/uploads/types.d.ts +1 -2
- package/dist/validation/buildRuleBlocks.js +18 -17
- package/dist/validation/buildRuleBlocks.js.map +1 -1
- package/dist/validation/builtin/email.js +1 -0
- package/dist/validation/builtin/email.js.map +1 -1
- package/dist/validation/builtin/matchesField.js +3 -7
- package/dist/validation/builtin/matchesField.js.map +1 -1
- package/dist/validation/builtin/max.js +1 -0
- package/dist/validation/builtin/max.js.map +1 -1
- package/dist/validation/builtin/maxDate.js +1 -0
- package/dist/validation/builtin/maxDate.js.map +1 -1
- package/dist/validation/builtin/maxLength.js +1 -0
- package/dist/validation/builtin/maxLength.js.map +1 -1
- package/dist/validation/builtin/min.js +1 -0
- package/dist/validation/builtin/min.js.map +1 -1
- package/dist/validation/builtin/minDate.js +1 -0
- package/dist/validation/builtin/minDate.js.map +1 -1
- package/dist/validation/builtin/minLength.js +1 -0
- package/dist/validation/builtin/minLength.js.map +1 -1
- package/dist/validation/builtin/notAlreadySubmitted.js +1 -0
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
- package/dist/validation/builtin/oneOf.js +1 -0
- package/dist/validation/builtin/oneOf.js.map +1 -1
- package/dist/validation/builtin/pattern.js +11 -2
- package/dist/validation/builtin/pattern.js.map +1 -1
- package/dist/validation/builtin/url.js +1 -0
- package/dist/validation/builtin/url.js.map +1 -1
- package/dist/validation/builtin/validateRegexParams.js +44 -0
- package/dist/validation/builtin/validateRegexParams.js.map +1 -0
- package/dist/validation/fieldTargetParam.d.ts +22 -0
- package/dist/validation/fieldTargetParam.js +38 -0
- package/dist/validation/fieldTargetParam.js.map +1 -0
- package/dist/validation/runValidation.js +8 -29
- package/dist/validation/runValidation.js.map +1 -1
- package/dist/validation/types.d.ts +5 -11
- package/dist/validation/validateUrl.js +22 -0
- package/dist/validation/validateUrl.js.map +1 -0
- package/package.json +7 -6
- package/styles/form-builder.css +10 -0
- package/dist/collections/uploads.d.ts +0 -30
- package/dist/collections/uploads.js +0 -55
- package/dist/collections/uploads.js.map +0 -1
- package/dist/consent/buildConsentSourceConfig.js +0 -49
- package/dist/consent/buildConsentSourceConfig.js.map +0 -1
- package/dist/consent/builtin/index.d.ts +0 -7
- package/dist/consent/builtin/index.js +0 -11
- package/dist/consent/builtin/index.js.map +0 -1
- package/dist/consent/builtin/pageReference.js +0 -75
- package/dist/consent/builtin/pageReference.js.map +0 -1
- package/dist/consent/builtin/static.js +0 -44
- package/dist/consent/builtin/static.js.map +0 -1
- package/dist/consent/defineConsentSource.d.ts +0 -35
- package/dist/consent/defineConsentSource.js +0 -6
- package/dist/consent/defineConsentSource.js.map +0 -1
- package/dist/consent/registry.d.ts +0 -16
- package/dist/consent/registry.js +0 -16
- package/dist/consent/registry.js.map +0 -1
- package/dist/consent/resolveConsentLinks.d.ts +0 -19
- package/dist/consent/resolveConsentLinks.js +0 -26
- package/dist/consent/resolveConsentLinks.js.map +0 -1
- package/dist/presentations/registry.d.ts +0 -15
- package/dist/presentations/registry.js +0 -15
- package/dist/presentations/registry.js.map +0 -1
- package/dist/react/toFormDocument.d.ts +0 -24
- package/dist/react/toFormDocument.js +0 -22
- package/dist/react/toFormDocument.js.map +0 -1
|
@@ -5,39 +5,25 @@ const RULE_TIMEOUT_MS = 5e3;
|
|
|
5
5
|
const isEmpty = (value) => value == null || value === "" || Array.isArray(value) && value.length === 0;
|
|
6
6
|
/** Build the per-instance message resolver: custom override (a literal template) or the localized default. */
|
|
7
7
|
const makeMessage = (instance, defaultMessageKey, t) => {
|
|
8
|
-
const { blockType: _blockType, message: _message,
|
|
8
|
+
const { blockType: _blockType, message: _message, ...params } = instance;
|
|
9
9
|
const template = typeof instance.message === "string" && instance.message.length > 0 ? instance.message : t(defaultMessageKey);
|
|
10
10
|
return (vars = {}) => resolveMessage(template, {
|
|
11
11
|
...params,
|
|
12
12
|
...vars
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
const toIssue = (result, fallbackSeverity) => {
|
|
16
|
-
if (result === true) return null;
|
|
17
|
-
if (typeof result === "string") return {
|
|
18
|
-
message: result,
|
|
19
|
-
severity: fallbackSeverity
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
message: result.message,
|
|
23
|
-
severity: result.severity ?? fallbackSeverity
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
15
|
/**
|
|
27
16
|
* The one validation engine, run per field on client and server. Order: required, the field type's
|
|
28
17
|
* intrinsic validator, then each declarative rule instance. Server-only rules are skipped in client
|
|
29
18
|
* mode; every rule is wrapped in try/catch + a timeout so a bad rule cannot crash or stall the submit
|
|
30
|
-
* path (a thrown or timed-out rule fails open, logged on the server).
|
|
31
|
-
*
|
|
19
|
+
* path (a thrown or timed-out rule fails open, logged on the server). Every returned message is a
|
|
20
|
+
* blocking error.
|
|
32
21
|
*/
|
|
33
22
|
const runValidation = async (input) => {
|
|
34
23
|
const { field, fieldDefinition, value, fieldType, ruleRegistry, answers, locale, t, operation, event, mode, req, payload, formId, timeoutMs } = input;
|
|
35
24
|
const timeout = timeoutMs ?? RULE_TIMEOUT_MS;
|
|
36
25
|
const errors = [];
|
|
37
|
-
if (field.required && isEmpty(value)) return { errors: [
|
|
38
|
-
message: t(keys.validationRequired),
|
|
39
|
-
severity: "error"
|
|
40
|
-
}] };
|
|
26
|
+
if (field.required && isEmpty(value)) return { errors: [t(keys.validationRequired)] };
|
|
41
27
|
if (isEmpty(value) && field.blockType !== "repeater") return { errors: [] };
|
|
42
28
|
if (fieldDefinition?.validate) try {
|
|
43
29
|
const ran = fieldDefinition.validate({
|
|
@@ -49,10 +35,7 @@ const runValidation = async (input) => {
|
|
|
49
35
|
t
|
|
50
36
|
});
|
|
51
37
|
const result = ran instanceof Promise ? await withTimeout(ran, timeout, true) : ran;
|
|
52
|
-
if (result !== true) errors.push(
|
|
53
|
-
message: result,
|
|
54
|
-
severity: "error"
|
|
55
|
-
});
|
|
38
|
+
if (result !== true) errors.push(result);
|
|
56
39
|
} catch (error) {
|
|
57
40
|
req?.payload?.logger?.error?.({
|
|
58
41
|
err: error,
|
|
@@ -61,10 +44,7 @@ const runValidation = async (input) => {
|
|
|
61
44
|
}
|
|
62
45
|
if (fieldDefinition?.schema) try {
|
|
63
46
|
const outcome = await fieldDefinition.schema["~standard"].validate(value);
|
|
64
|
-
if (outcome.issues) for (const issue of outcome.issues) errors.push(
|
|
65
|
-
message: issue.message,
|
|
66
|
-
severity: "error"
|
|
67
|
-
});
|
|
47
|
+
if (outcome.issues) for (const issue of outcome.issues) errors.push(issue.message);
|
|
68
48
|
} catch (error) {
|
|
69
49
|
req?.payload?.logger?.error?.({
|
|
70
50
|
err: error,
|
|
@@ -77,7 +57,6 @@ const runValidation = async (input) => {
|
|
|
77
57
|
if (!rule) continue;
|
|
78
58
|
if (mode === "client" && rule.client === false) continue;
|
|
79
59
|
const message = makeMessage(instance, rule.defaultMessage, t);
|
|
80
|
-
const fallbackSeverity = instance.severity ?? rule.severity ?? "error";
|
|
81
60
|
try {
|
|
82
61
|
const ran = rule.validate({
|
|
83
62
|
value,
|
|
@@ -94,8 +73,8 @@ const runValidation = async (input) => {
|
|
|
94
73
|
payload: mode === "server" ? payload : void 0,
|
|
95
74
|
formId: mode === "server" ? formId : void 0
|
|
96
75
|
});
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
76
|
+
const result = ran instanceof Promise ? await withTimeout(ran, timeout, true) : ran;
|
|
77
|
+
if (result !== true) errors.push(result);
|
|
99
78
|
} catch (error) {
|
|
100
79
|
req?.payload?.logger?.error?.({
|
|
101
80
|
err: error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runValidation.js","names":[],"sources":["../../src/validation/runValidation.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { AnyFormFieldDefinition, Translate } from '../fields/types'\nimport type { FormFieldInstance } from '../submissions/types'\nimport { keys } from '../translations/keys'\nimport { resolveMessage, withTimeout } from './message'\nimport type { ValidationRuleRegistry } from './registry'\nimport type { MessageFn
|
|
1
|
+
{"version":3,"file":"runValidation.js","names":[],"sources":["../../src/validation/runValidation.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { AnyFormFieldDefinition, Translate } from '../fields/types'\nimport type { FormFieldInstance } from '../submissions/types'\nimport { keys } from '../translations/keys'\nimport { resolveMessage, withTimeout } from './message'\nimport type { ValidationRuleRegistry } from './registry'\nimport type { MessageFn } from './types'\n\nconst RULE_TIMEOUT_MS = 5000\n\nexport type RunValidationInput = {\n\tfield: FormFieldInstance\n\tfieldDefinition?: AnyFormFieldDefinition\n\tvalue: unknown\n\tfieldType: string\n\truleRegistry: ValidationRuleRegistry\n\tanswers: Record<string, unknown>\n\tlocale: string\n\tt: Translate\n\toperation: 'create' | 'update'\n\tevent: 'onChange' | 'submit'\n\tmode: 'client' | 'server'\n\treq?: PayloadRequest\n\tpayload?: Payload\n\tformId?: number | string\n\t/** Override the per-rule timeout in ms. Defaults to RULE_TIMEOUT_MS; primarily for tests. */\n\ttimeoutMs?: number\n}\n\nexport type RunValidationResult = { errors: string[] }\n\nconst isEmpty = (value: unknown): boolean =>\n\tvalue == null || value === '' || (Array.isArray(value) && value.length === 0)\n\ntype RuleInstance = { blockType: string; message?: string } & Record<string, unknown>\n\n/** Build the per-instance message resolver: custom override (a literal template) or the localized default. */\nconst makeMessage = (\n\tinstance: RuleInstance,\n\tdefaultMessageKey: string,\n\tt: Translate\n): MessageFn => {\n\tconst { blockType: _blockType, message: _message, ...params } = instance\n\tconst template =\n\t\ttypeof instance.message === 'string' && instance.message.length > 0\n\t\t\t? instance.message\n\t\t\t: t(defaultMessageKey)\n\treturn (vars = {}) => resolveMessage(template, { ...params, ...vars })\n}\n\n/**\n * The one validation engine, run per field on client and server. Order: required, the field type's\n * intrinsic validator, then each declarative rule instance. Server-only rules are skipped in client\n * mode; every rule is wrapped in try/catch + a timeout so a bad rule cannot crash or stall the submit\n * path (a thrown or timed-out rule fails open, logged on the server). Every returned message is a\n * blocking error.\n */\nexport const runValidation = async (input: RunValidationInput): Promise<RunValidationResult> => {\n\tconst {\n\t\tfield,\n\t\tfieldDefinition,\n\t\tvalue,\n\t\tfieldType,\n\t\truleRegistry,\n\t\tanswers,\n\t\tlocale,\n\t\tt,\n\t\toperation,\n\t\tevent,\n\t\tmode,\n\t\treq,\n\t\tpayload,\n\t\tformId,\n\t\ttimeoutMs,\n\t} = input\n\tconst timeout = timeoutMs ?? RULE_TIMEOUT_MS\n\tconst errors: string[] = []\n\n\tif (field.required && isEmpty(value)) {\n\t\treturn { errors: [t(keys.validationRequired)] }\n\t}\n\t// Repeaters coerced to [] must reach fieldDefinition.validate so minRows is enforced;\n\t// all other empty fields have no intrinsic rules to run.\n\tif (isEmpty(value) && field.blockType !== 'repeater') {\n\t\treturn { errors: [] }\n\t}\n\n\tif (fieldDefinition?.validate) {\n\t\ttry {\n\t\t\tconst ran = fieldDefinition.validate({\n\t\t\t\tvalue,\n\t\t\t\tconfig: field,\n\t\t\t\tsiblingData: answers,\n\t\t\t\tdata: answers,\n\t\t\t\tlocale,\n\t\t\t\tt,\n\t\t\t})\n\t\t\tconst result = ran instanceof Promise ? await withTimeout(ran, timeout, true) : ran\n\t\t\tif (result !== true) {\n\t\t\t\terrors.push(result)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treq?.payload?.logger?.error?.(\n\t\t\t\t{ err: error, field: field.name },\n\t\t\t\t'form-builder intrinsic field validator threw'\n\t\t\t)\n\t\t}\n\t}\n\n\tif (fieldDefinition?.schema) {\n\t\ttry {\n\t\t\tconst outcome = await fieldDefinition.schema['~standard'].validate(value)\n\t\t\tif (outcome.issues) {\n\t\t\t\tfor (const issue of outcome.issues) {\n\t\t\t\t\terrors.push(issue.message)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treq?.payload?.logger?.error?.(\n\t\t\t\t{ err: error, field: field.name },\n\t\t\t\t'form-builder field schema threw'\n\t\t\t)\n\t\t}\n\t}\n\n\tconst instances = (Array.isArray(field.validations) ? field.validations : []) as RuleInstance[]\n\tfor (const instance of instances) {\n\t\tconst rule = ruleRegistry.get(instance.blockType)\n\t\tif (!rule) {\n\t\t\tcontinue\n\t\t}\n\t\tif (mode === 'client' && rule.client === false) {\n\t\t\tcontinue\n\t\t}\n\t\tconst message = makeMessage(instance, rule.defaultMessage, t)\n\t\ttry {\n\t\t\tconst ran = rule.validate({\n\t\t\t\tvalue,\n\t\t\t\tparams: instance,\n\t\t\t\tsiblingData: answers,\n\t\t\t\tdata: answers,\n\t\t\t\tfield,\n\t\t\t\tfieldType,\n\t\t\t\toperation,\n\t\t\t\tevent,\n\t\t\t\tlocale,\n\t\t\t\tmessage,\n\t\t\t\treq: mode === 'server' ? req : undefined,\n\t\t\t\tpayload: mode === 'server' ? payload : undefined,\n\t\t\t\tformId: mode === 'server' ? formId : undefined,\n\t\t\t})\n\t\t\tconst result = ran instanceof Promise ? await withTimeout(ran, timeout, true) : ran\n\t\t\tif (result !== true) {\n\t\t\t\terrors.push(result)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treq?.payload?.logger?.error?.(\n\t\t\t\t{ err: error, rule: rule.type },\n\t\t\t\t'form-builder validation rule threw'\n\t\t\t)\n\t\t}\n\t}\n\n\treturn { errors }\n}\n"],"mappings":";;;AAQA,MAAM,kBAAkB;AAuBxB,MAAM,WAAW,UAChB,SAAS,QAAQ,UAAU,MAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW;;AAK5E,MAAM,eACL,UACA,mBACA,MACe;CACf,MAAM,EAAE,WAAW,YAAY,SAAS,UAAU,GAAG,WAAW;CAChE,MAAM,WACL,OAAO,SAAS,YAAY,YAAY,SAAS,QAAQ,SAAS,IAC/D,SAAS,UACT,EAAE,iBAAiB;CACvB,QAAQ,OAAO,CAAC,MAAM,eAAe,UAAU;EAAE,GAAG;EAAQ,GAAG;CAAK,CAAC;AACtE;;;;;;;;AASA,MAAa,gBAAgB,OAAO,UAA4D;CAC/F,MAAM,EACL,OACA,iBACA,OACA,WACA,cACA,SACA,QACA,GACA,WACA,OACA,MACA,KACA,SACA,QACA,cACG;CACJ,MAAM,UAAU,aAAa;CAC7B,MAAM,SAAmB,CAAC;CAE1B,IAAI,MAAM,YAAY,QAAQ,KAAK,GAClC,OAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,kBAAkB,CAAC,EAAE;CAI/C,IAAI,QAAQ,KAAK,KAAK,MAAM,cAAc,YACzC,OAAO,EAAE,QAAQ,CAAC,EAAE;CAGrB,IAAI,iBAAiB,UACpB,IAAI;EACH,MAAM,MAAM,gBAAgB,SAAS;GACpC;GACA,QAAQ;GACR,aAAa;GACb,MAAM;GACN;GACA;EACD,CAAC;EACD,MAAM,SAAS,eAAe,UAAU,MAAM,YAAY,KAAK,SAAS,IAAI,IAAI;EAChF,IAAI,WAAW,MACd,OAAO,KAAK,MAAM;CAEpB,SAAS,OAAO;EACf,KAAK,SAAS,QAAQ,QACrB;GAAE,KAAK;GAAO,OAAO,MAAM;EAAK,GAChC,8CACD;CACD;CAGD,IAAI,iBAAiB,QACpB,IAAI;EACH,MAAM,UAAU,MAAM,gBAAgB,OAAO,aAAa,SAAS,KAAK;EACxE,IAAI,QAAQ,QACX,KAAK,MAAM,SAAS,QAAQ,QAC3B,OAAO,KAAK,MAAM,OAAO;CAG5B,SAAS,OAAO;EACf,KAAK,SAAS,QAAQ,QACrB;GAAE,KAAK;GAAO,OAAO,MAAM;EAAK,GAChC,iCACD;CACD;CAGD,MAAM,YAAa,MAAM,QAAQ,MAAM,WAAW,IAAI,MAAM,cAAc,CAAC;CAC3E,KAAK,MAAM,YAAY,WAAW;EACjC,MAAM,OAAO,aAAa,IAAI,SAAS,SAAS;EAChD,IAAI,CAAC,MACJ;EAED,IAAI,SAAS,YAAY,KAAK,WAAW,OACxC;EAED,MAAM,UAAU,YAAY,UAAU,KAAK,gBAAgB,CAAC;EAC5D,IAAI;GACH,MAAM,MAAM,KAAK,SAAS;IACzB;IACA,QAAQ;IACR,aAAa;IACb,MAAM;IACN;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,SAAS,WAAW,MAAM,KAAA;IAC/B,SAAS,SAAS,WAAW,UAAU,KAAA;IACvC,QAAQ,SAAS,WAAW,SAAS,KAAA;GACtC,CAAC;GACD,MAAM,SAAS,eAAe,UAAU,MAAM,YAAY,KAAK,SAAS,IAAI,IAAI;GAChF,IAAI,WAAW,MACd,OAAO,KAAK,MAAM;EAEpB,SAAS,OAAO;GACf,KAAK,SAAS,QAAQ,QACrB;IAAE,KAAK;IAAO,MAAM,KAAK;GAAK,GAC9B,oCACD;EACD;CACD;CAEA,OAAO,EAAE,OAAO;AACjB"}
|
|
@@ -2,12 +2,8 @@ import { FormFieldInstance } from "../submissions/types.js";
|
|
|
2
2
|
import { Field, Payload, PayloadRequest } from "payload";
|
|
3
3
|
|
|
4
4
|
//#region src/validation/types.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type ValidationRuleResult = true | string | {
|
|
8
|
-
message: string;
|
|
9
|
-
severity?: ValidationSeverity;
|
|
10
|
-
};
|
|
5
|
+
/** A rule outcome: pass (`true`) or a blocking error message. */
|
|
6
|
+
type ValidationRuleResult = true | string;
|
|
11
7
|
/** Resolves this rule instance's message (custom override or localized default) with `{var}` interpolation. */
|
|
12
8
|
type MessageFn = (vars?: Record<string, unknown>) => string;
|
|
13
9
|
/** Resolved per-instance rule params (loose at the DB boundary, narrowed by the author's generic). */
|
|
@@ -30,7 +26,7 @@ type ValidationRuleValidateArgs<TParams extends ValidationParams, TValue, TData
|
|
|
30
26
|
type ValidationRuleValidate<TParams extends ValidationParams, TValue, TData extends Record<string, unknown> = Record<string, unknown>> = (args: ValidationRuleValidateArgs<TParams, TValue, TData>) => Promise<ValidationRuleResult> | ValidationRuleResult;
|
|
31
27
|
/**
|
|
32
28
|
* A validation rule type, authored once. `params` is a Payload `Field[]` rendered in the per-field
|
|
33
|
-
* constraint list; `validate` returns `true | string
|
|
29
|
+
* constraint list; `validate` returns `true | string`. `client` defaults from
|
|
34
30
|
* whether the rule is pure (a rule that is async or uses `req`/`payload` must set `client: false`).
|
|
35
31
|
*/
|
|
36
32
|
type ValidationRuleDefinition<TParams extends ValidationParams = ValidationParams, TValue = unknown, TData extends Record<string, unknown> = Record<string, unknown>> = {
|
|
@@ -40,8 +36,7 @@ type ValidationRuleDefinition<TParams extends ValidationParams = ValidationParam
|
|
|
40
36
|
appliesTo?: string[];
|
|
41
37
|
params?: Field[];
|
|
42
38
|
defaultMessage: string; /** Runs client-side too. Defaults to `true`; set `false` for async or `req`/`payload`-using rules. */
|
|
43
|
-
client?: boolean;
|
|
44
|
-
severity?: ValidationSeverity;
|
|
39
|
+
client?: boolean;
|
|
45
40
|
validate: ValidationRuleValidate<TParams, TValue, TData>;
|
|
46
41
|
};
|
|
47
42
|
/** Erased shape stored in the heterogeneous registry; params re-narrow per matched rule at execution. */
|
|
@@ -68,9 +63,8 @@ type AnyValidationRuleDefinition = {
|
|
|
68
63
|
params?: Field[];
|
|
69
64
|
defaultMessage: string;
|
|
70
65
|
client?: boolean;
|
|
71
|
-
severity?: ValidationSeverity;
|
|
72
66
|
validate: AnyValidationRuleValidate;
|
|
73
67
|
};
|
|
74
68
|
//#endregion
|
|
75
|
-
export { AnyValidationRuleDefinition, ValidationParams, ValidationRuleDefinition, ValidationRuleResult
|
|
69
|
+
export { AnyValidationRuleDefinition, ValidationParams, ValidationRuleDefinition, ValidationRuleResult };
|
|
76
70
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
import { asTranslate } from "../translations/server.js";
|
|
3
|
+
//#region src/validation/validateUrl.ts
|
|
4
|
+
/**
|
|
5
|
+
* Payload field validator for URL config fields (signed-webhook `url`, response redirect `url`):
|
|
6
|
+
* unset is fine (the consumer enforces presence where it matters), otherwise the value must parse
|
|
7
|
+
* as an absolute http(s) URL.
|
|
8
|
+
*/
|
|
9
|
+
const validateUrl = (value, { req }) => {
|
|
10
|
+
if (typeof value !== "string" || value.length === 0) return true;
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = new URL(value);
|
|
14
|
+
} catch {
|
|
15
|
+
return asTranslate(req.t)(keys.validationUrlInvalid);
|
|
16
|
+
}
|
|
17
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:" ? true : asTranslate(req.t)(keys.validationUrlInvalid);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { validateUrl };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=validateUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateUrl.js","names":[],"sources":["../../src/validation/validateUrl.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { keys } from '../translations/keys'\nimport { asTranslate } from '../translations/server'\n\n/**\n * Payload field validator for URL config fields (signed-webhook `url`, response redirect `url`):\n * unset is fine (the consumer enforces presence where it matters), otherwise the value must parse\n * as an absolute http(s) URL.\n */\nexport const validateUrl = (\n\tvalue: unknown,\n\t{ req }: { data?: unknown; req: PayloadRequest }\n): string | true => {\n\tif (typeof value !== 'string' || value.length === 0) {\n\t\treturn true\n\t}\n\tlet parsed: URL\n\ttry {\n\t\tparsed = new URL(value)\n\t} catch {\n\t\treturn asTranslate(req.t)(keys.validationUrlInvalid)\n\t}\n\treturn parsed.protocol === 'http:' || parsed.protocol === 'https:'\n\t\t? true\n\t\t: asTranslate(req.t)(keys.validationUrlInvalid)\n}\n"],"mappings":";;;;;;;;AASA,MAAa,eACZ,OACA,EAAE,UACiB;CACnB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GACjD,OAAO;CAER,IAAI;CACJ,IAAI;EACH,SAAS,IAAI,IAAI,KAAK;CACvB,QAAQ;EACP,OAAO,YAAY,IAAI,CAAC,EAAE,KAAK,oBAAoB;CACpD;CACA,OAAO,OAAO,aAAa,WAAW,OAAO,aAAa,WACvD,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,oBAAoB;AAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@10x-media/form-builder",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"description": "End-to-end forms platform for Payload: author, validate, render, collect, aggregate, and act.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"LICENSE"
|
|
63
63
|
],
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@payloadcms/ui": "^3.
|
|
66
|
-
"payload": "^3.
|
|
65
|
+
"@payloadcms/ui": "^3.83.0",
|
|
66
|
+
"payload": "^3.83.0",
|
|
67
67
|
"react": "^19.0.0",
|
|
68
68
|
"react-dom": "^19.0.0"
|
|
69
69
|
},
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@axe-core/playwright": "^4.11.3",
|
|
75
75
|
"@payloadcms/db-mongodb": "3.85.0",
|
|
76
76
|
"@payloadcms/db-postgres": "3.85.0",
|
|
77
|
+
"@payloadcms/richtext-lexical": "3.85.0",
|
|
77
78
|
"@payloadcms/ui": "3.85.0",
|
|
78
79
|
"@playwright/test": "1.60.0",
|
|
79
80
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -93,9 +94,9 @@
|
|
|
93
94
|
"typescript": "5.9.3",
|
|
94
95
|
"vitest": "4.1.7",
|
|
95
96
|
"@10x-media/payload-test-harness": "0.0.0",
|
|
96
|
-
"@10x-media/
|
|
97
|
+
"@10x-media/tsconfig": "0.0.0",
|
|
97
98
|
"@10x-media/tsdown-config": "0.0.0",
|
|
98
|
-
"@10x-media/
|
|
99
|
+
"@10x-media/vitest-config": "0.0.0"
|
|
99
100
|
},
|
|
100
101
|
"publishConfig": {
|
|
101
102
|
"access": "public"
|
|
@@ -109,7 +110,7 @@
|
|
|
109
110
|
"test": "vitest run",
|
|
110
111
|
"test:unit": "vitest run src",
|
|
111
112
|
"test:int": "vitest run tests/int",
|
|
112
|
-
"test:matrix": "DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts && DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts",
|
|
113
|
+
"test:matrix": "DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts tests/int/messageResponse.int.spec.ts tests/int/pollAutoClose.int.spec.ts && DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts tests/int/messageResponse.int.spec.ts tests/int/pollAutoClose.int.spec.ts",
|
|
113
114
|
"test:container": "TEST_DB=container DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts && TEST_DB=container DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts",
|
|
114
115
|
"test:e2e": "bash scripts/e2e.sh",
|
|
115
116
|
"dev": "pnpm --filter @10x-media/form-builder-dev dev",
|
package/styles/form-builder.css
CHANGED
|
@@ -101,6 +101,16 @@
|
|
|
101
101
|
height: 100%;
|
|
102
102
|
background: var(--fb-results-fill, currentColor);
|
|
103
103
|
}
|
|
104
|
+
.fb-results__bucket--winner {
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
}
|
|
107
|
+
.fb-results__winner-badge {
|
|
108
|
+
margin-inline-start: 0.375rem;
|
|
109
|
+
font-size: 0.75em;
|
|
110
|
+
text-transform: uppercase;
|
|
111
|
+
letter-spacing: 0.05em;
|
|
112
|
+
opacity: 0.7;
|
|
113
|
+
}
|
|
104
114
|
.fb-results__total {
|
|
105
115
|
margin-block-start: 0.5rem;
|
|
106
116
|
opacity: 0.7;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CollectionOverrides } from "../plugin/collectionOverrides.js";
|
|
2
|
-
import { CollectionConfig } from "payload";
|
|
3
|
-
|
|
4
|
-
//#region src/collections/uploads.d.ts
|
|
5
|
-
declare const FORM_UPLOADS_SLUG = "form-uploads";
|
|
6
|
-
/** Override surface for the built-in upload collection. */
|
|
7
|
-
type UploadsCollectionConfig = {
|
|
8
|
-
slug?: string; /** Merged onto the collection's `upload` config (e.g. `staticDir`, `mimeTypes`). `true` uses Payload defaults. */
|
|
9
|
-
upload?: NonNullable<CollectionConfig['upload']> | true; /** Replace access (defaults: anonymous create, authed read/update/delete). */
|
|
10
|
-
access?: CollectionConfig['access']; /** Append extra fields. */
|
|
11
|
-
fields?: CollectionConfig['fields'];
|
|
12
|
-
};
|
|
13
|
-
type UploadsOption = boolean | UploadsCollectionConfig;
|
|
14
|
-
/**
|
|
15
|
-
* The built-in upload collection backing the `file` field. Anonymous create (public forms upload here),
|
|
16
|
-
* authed read/update/delete (only admins read stored files; submitters cannot enumerate others' uploads).
|
|
17
|
-
* Per-field MIME/size is re-enforced at submit, so the collection stays permissive by default. No
|
|
18
|
-
* `imageSizes`, so it needs no `sharp`. Projects with their own upload collection set `uploads: false` and
|
|
19
|
-
* point the file field's `relationTo` at theirs.
|
|
20
|
-
*/
|
|
21
|
-
declare const buildUploadsCollection: (config?: UploadsCollectionConfig, overrides?: CollectionOverrides) => CollectionConfig;
|
|
22
|
-
/** Resolve the `uploads` plugin option: `false` disables, `true`/object enables the built-in collection. */
|
|
23
|
-
declare const resolveUploads: (option: UploadsOption | undefined) => {
|
|
24
|
-
enabled: boolean;
|
|
25
|
-
slug: string;
|
|
26
|
-
collection?: CollectionConfig;
|
|
27
|
-
};
|
|
28
|
-
//#endregion
|
|
29
|
-
export { FORM_UPLOADS_SLUG, UploadsCollectionConfig, UploadsOption, buildUploadsCollection, resolveUploads };
|
|
30
|
-
//# sourceMappingURL=uploads.d.ts.map
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { isLoggedIn } from "../plugin/access.js";
|
|
2
|
-
//#region src/collections/uploads.ts
|
|
3
|
-
const FORM_UPLOADS_SLUG = "form-uploads";
|
|
4
|
-
/**
|
|
5
|
-
* The built-in upload collection backing the `file` field. Anonymous create (public forms upload here),
|
|
6
|
-
* authed read/update/delete (only admins read stored files; submitters cannot enumerate others' uploads).
|
|
7
|
-
* Per-field MIME/size is re-enforced at submit, so the collection stays permissive by default. No
|
|
8
|
-
* `imageSizes`, so it needs no `sharp`. Projects with their own upload collection set `uploads: false` and
|
|
9
|
-
* point the file field's `relationTo` at theirs.
|
|
10
|
-
*/
|
|
11
|
-
const buildUploadsCollection = (config = {}, overrides) => {
|
|
12
|
-
const defaultFields = [{
|
|
13
|
-
name: "owner",
|
|
14
|
-
type: "text",
|
|
15
|
-
admin: {
|
|
16
|
-
readOnly: true,
|
|
17
|
-
hidden: true
|
|
18
|
-
}
|
|
19
|
-
}, ...config.fields ?? []];
|
|
20
|
-
return {
|
|
21
|
-
...overrides ?? {},
|
|
22
|
-
slug: config.slug ?? "form-uploads",
|
|
23
|
-
access: {
|
|
24
|
-
create: () => true,
|
|
25
|
-
read: isLoggedIn,
|
|
26
|
-
update: isLoggedIn,
|
|
27
|
-
delete: isLoggedIn,
|
|
28
|
-
...config.access ?? {},
|
|
29
|
-
...overrides?.access ?? {}
|
|
30
|
-
},
|
|
31
|
-
admin: {
|
|
32
|
-
group: "Forms",
|
|
33
|
-
...overrides?.admin ?? {}
|
|
34
|
-
},
|
|
35
|
-
upload: config.upload && config.upload !== true ? config.upload : true,
|
|
36
|
-
fields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
/** Resolve the `uploads` plugin option: `false` disables, `true`/object enables the built-in collection. */
|
|
40
|
-
const resolveUploads = (option) => {
|
|
41
|
-
if (option === false) return {
|
|
42
|
-
enabled: false,
|
|
43
|
-
slug: FORM_UPLOADS_SLUG
|
|
44
|
-
};
|
|
45
|
-
const collection = buildUploadsCollection(option && option !== true ? option : {});
|
|
46
|
-
return {
|
|
47
|
-
enabled: true,
|
|
48
|
-
slug: collection.slug,
|
|
49
|
-
collection
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
//#endregion
|
|
53
|
-
export { FORM_UPLOADS_SLUG, buildUploadsCollection, resolveUploads };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=uploads.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uploads.js","names":[],"sources":["../../src/collections/uploads.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\nimport { isLoggedIn } from '../plugin/access'\nimport type { CollectionOverrides } from '../plugin/collectionOverrides'\n\nexport const FORM_UPLOADS_SLUG = 'form-uploads'\n\n/** Override surface for the built-in upload collection. */\nexport type UploadsCollectionConfig = {\n\tslug?: string\n\t/** Merged onto the collection's `upload` config (e.g. `staticDir`, `mimeTypes`). `true` uses Payload defaults. */\n\tupload?: NonNullable<CollectionConfig['upload']> | true\n\t/** Replace access (defaults: anonymous create, authed read/update/delete). */\n\taccess?: CollectionConfig['access']\n\t/** Append extra fields. */\n\tfields?: CollectionConfig['fields']\n}\n\nexport type UploadsOption = boolean | UploadsCollectionConfig\n\n/**\n * The built-in upload collection backing the `file` field. Anonymous create (public forms upload here),\n * authed read/update/delete (only admins read stored files; submitters cannot enumerate others' uploads).\n * Per-field MIME/size is re-enforced at submit, so the collection stays permissive by default. No\n * `imageSizes`, so it needs no `sharp`. Projects with their own upload collection set `uploads: false` and\n * point the file field's `relationTo` at theirs.\n */\nexport const buildUploadsCollection = (\n\tconfig: UploadsCollectionConfig = {},\n\toverrides?: CollectionOverrides\n): CollectionConfig => {\n\tconst defaultFields: Field[] = [\n\t\t{ name: 'owner', type: 'text', admin: { readOnly: true, hidden: true } },\n\t\t...(config.fields ?? []),\n\t]\n\n\treturn {\n\t\t...(overrides ?? {}),\n\t\tslug: config.slug ?? FORM_UPLOADS_SLUG,\n\t\taccess: {\n\t\t\tcreate: () => true,\n\t\t\tread: isLoggedIn,\n\t\t\tupdate: isLoggedIn,\n\t\t\tdelete: isLoggedIn,\n\t\t\t...(config.access ?? {}),\n\t\t\t...(overrides?.access ?? {}),\n\t\t},\n\t\tadmin: { group: 'Forms', ...(overrides?.admin ?? {}) },\n\t\tupload: config.upload && config.upload !== true ? config.upload : true,\n\t\tfields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields,\n\t}\n}\n\n/** Resolve the `uploads` plugin option: `false` disables, `true`/object enables the built-in collection. */\nexport const resolveUploads = (\n\toption: UploadsOption | undefined\n): { enabled: boolean; slug: string; collection?: CollectionConfig } => {\n\tif (option === false) {\n\t\treturn { enabled: false, slug: FORM_UPLOADS_SLUG }\n\t}\n\tconst config = option && option !== true ? option : {}\n\tconst collection = buildUploadsCollection(config)\n\treturn { enabled: true, slug: collection.slug as string, collection }\n}\n"],"mappings":";;AAIA,MAAa,oBAAoB;;;;;;;;AAsBjC,MAAa,0BACZ,SAAkC,CAAC,GACnC,cACsB;CACtB,MAAM,gBAAyB,CAC9B;EAAE,MAAM;EAAS,MAAM;EAAQ,OAAO;GAAE,UAAU;GAAM,QAAQ;EAAK;CAAE,GACvE,GAAI,OAAO,UAAU,CAAC,CACvB;CAEA,OAAO;EACN,GAAI,aAAa,CAAC;EAClB,MAAM,OAAO,QAAA;EACb,QAAQ;GACP,cAAc;GACd,MAAM;GACN,QAAQ;GACR,QAAQ;GACR,GAAI,OAAO,UAAU,CAAC;GACtB,GAAI,WAAW,UAAU,CAAC;EAC3B;EACA,OAAO;GAAE,OAAO;GAAS,GAAI,WAAW,SAAS,CAAC;EAAG;EACrD,QAAQ,OAAO,UAAU,OAAO,WAAW,OAAO,OAAO,SAAS;EAClE,QAAQ,WAAW,SAAS,UAAU,OAAO,EAAE,cAAc,CAAC,IAAI;CACnE;AACD;;AAGA,MAAa,kBACZ,WACuE;CACvE,IAAI,WAAW,OACd,OAAO;EAAE,SAAS;EAAO,MAAM;CAAkB;CAGlD,MAAM,aAAa,uBADJ,UAAU,WAAW,OAAO,SAAS,CAAC,CACL;CAChD,OAAO;EAAE,SAAS;EAAM,MAAM,WAAW;EAAgB;CAAW;AACrE"}
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|