@builder.io/sdk-react-native 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/button/button.js +6 -2
- package/dist/blocks/button/component-info.js +4 -8
- package/dist/blocks/columns/columns.js +19 -23
- package/dist/blocks/columns/component-info.js +27 -48
- package/dist/blocks/custom-code/component-info.js +4 -8
- package/dist/blocks/custom-code/custom-code.js +1 -1
- package/dist/blocks/embed/component-info.js +7 -11
- package/dist/blocks/embed/embed.js +1 -1
- package/dist/blocks/embed/helpers.js +2 -6
- package/dist/blocks/form/component-info.js +33 -69
- package/dist/blocks/form/form.js +2 -203
- package/dist/blocks/fragment/fragment.js +1 -1
- package/dist/blocks/helpers.js +33 -0
- package/dist/blocks/image/component-info.js +21 -47
- package/dist/blocks/image/image.helpers.js +2 -2
- package/dist/blocks/img/component-info.js +2 -4
- package/dist/blocks/img/img.js +2 -1
- package/dist/blocks/input/component-info.js +8 -34
- package/dist/blocks/input/input.js +2 -1
- package/dist/blocks/raw-text/component-info.js +2 -4
- package/dist/blocks/raw-text/raw-text.js +3 -2
- package/dist/blocks/section/component-info.js +5 -10
- package/dist/blocks/section/section.js +2 -1
- package/dist/blocks/select/component-info.js +12 -24
- package/dist/blocks/select/select.js +2 -1
- package/dist/blocks/submit-button/component-info.js +2 -4
- package/dist/blocks/submit-button/submit-button.js +2 -1
- package/dist/blocks/symbol/component-info.js +7 -12
- package/dist/blocks/symbol/symbol.helpers.js +66 -0
- package/dist/blocks/symbol/symbol.js +23 -50
- package/dist/blocks/text/component-info.js +3 -4
- package/dist/blocks/textarea/component-info.js +6 -12
- package/dist/blocks/textarea/textarea.js +2 -1
- package/dist/blocks/video/component-info.js +21 -41
- package/dist/components/block/block.helpers.js +102 -0
- package/dist/components/block/block.js +141 -0
- package/dist/components/block/components/block-styles.js +95 -0
- package/dist/components/block/components/block-wrapper/block-wrapper.js +41 -0
- package/dist/components/block/components/block-wrapper.js +56 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.js +40 -0
- package/dist/components/block/components/component-ref/component-ref.js +63 -0
- package/dist/components/block/components/component-ref.js +81 -0
- package/dist/components/block/components/component.js +41 -0
- package/dist/components/block/components/interactive-element/interactive-element.helpers.js +35 -0
- package/dist/components/block/components/interactive-element/interactive-element.js +36 -0
- package/dist/components/block/components/interactive-element.js +46 -0
- package/dist/components/block/components/repeated-block.js +40 -0
- package/dist/components/block/types.js +1 -0
- package/dist/components/blocks/blocks-wrapper.js +69 -0
- package/dist/components/blocks/blocks.js +41 -0
- package/dist/components/content/builder-editing.js +32 -0
- package/dist/components/content/components/content-styles.helpers.js +55 -0
- package/dist/components/content/components/content-styles.js +61 -0
- package/dist/components/content/components/enable-editor.js +310 -0
- package/dist/components/content/components/styles.helpers.js +55 -0
- package/dist/components/content/components/styles.js +61 -0
- package/dist/components/content/content.helpers.js +49 -0
- package/dist/components/content/content.js +110 -0
- package/dist/components/content/content.types.js +1 -0
- package/dist/components/content/index.js +8 -0
- package/dist/components/content/wrap-component-ref.js +5 -0
- package/dist/components/content-variants/content-variants.js +77 -0
- package/dist/components/content-variants/content-variants.types.js +1 -0
- package/dist/components/content-variants/helpers.js +175 -0
- package/dist/components/inlined-script.js +32 -0
- package/dist/components/{render-inlined-styles.js → inlined-styles.js} +3 -3
- package/dist/components/render-block/block-styles.js +2 -2
- package/dist/components/render-content/components/render-styles.js +2 -2
- package/dist/components/render-content/render-content.js +10 -8
- package/dist/components/render-content-variants/helpers.js +49 -20
- package/dist/components/render-content-variants/render-content-variants.js +29 -24
- package/dist/components/render-content-variants/render-content-variants.types.js +1 -0
- package/dist/constants/device-sizes.js +2 -2
- package/dist/constants/sdk-version.js +1 -1
- package/dist/context/builder.context.js +1 -1
- package/dist/functions/apply-patch-with-mutation.js +75 -0
- package/dist/functions/apply-patch-with-mutation.test.js +55 -0
- package/dist/functions/camel-to-kebab-case.js +1 -1
- package/dist/functions/evaluate/acorn.js +1691 -0
- package/dist/functions/evaluate/evaluate.js +72 -0
- package/dist/functions/evaluate/index.js +5 -0
- package/dist/functions/evaluate/interpreter.js +2903 -0
- package/dist/functions/evaluate/non-node-runtime.js +97 -0
- package/dist/functions/evaluate/types.js +1 -0
- package/dist/functions/evaluate.test.js +12 -6
- package/dist/functions/event-handler-name.js +1 -1
- package/dist/functions/extract-text-styles.js +3 -9
- package/dist/functions/fast-clone.js +1 -1
- package/dist/functions/get-block-actions-handler.js +2 -2
- package/dist/functions/get-block-actions.js +14 -1
- package/dist/functions/get-block-component-options.js +6 -1
- package/dist/functions/get-block-properties.js +21 -8
- package/dist/functions/get-builder-search-params/fn.test.js +3 -3
- package/dist/functions/get-builder-search-params/index.js +4 -4
- package/dist/functions/get-content/generate-content-url.js +12 -5
- package/dist/functions/get-content/generate-content-url.test.js +31 -17
- package/dist/functions/get-content/index.js +36 -12
- package/dist/functions/get-content/processCookies.js +7 -0
- package/dist/functions/get-processed-block.js +8 -3
- package/dist/functions/get-processed-block.test.js +3 -1
- package/dist/functions/get-react-native-block-styles.js +6 -1
- package/dist/functions/is-non-node-server.js +12 -0
- package/dist/functions/on-change.test.js +13 -3
- package/dist/functions/register-component.js +24 -19
- package/dist/functions/sanitize-react-native-block-styles.js +17 -6
- package/dist/functions/set.test.js +9 -3
- package/dist/functions/track/helpers.js +5 -5
- package/dist/functions/track/index.js +29 -18
- package/dist/functions/track/interaction.js +10 -4
- package/dist/functions/transform-block-properties.js +2 -0
- package/dist/helpers/ab-tests.js +38 -14
- package/dist/helpers/canTrack.js +2 -2
- package/dist/helpers/css.js +2 -2
- package/dist/helpers/flatten.js +10 -7
- package/dist/helpers/nullable.js +1 -1
- package/dist/helpers/preview-lru-cache/get.js +11 -0
- package/dist/helpers/preview-lru-cache/helpers.js +13 -0
- package/dist/helpers/preview-lru-cache/init.js +13 -0
- package/dist/helpers/preview-lru-cache/set.js +37 -0
- package/dist/helpers/preview-lru-cache/types.js +1 -0
- package/dist/helpers/sessionId.js +13 -6
- package/dist/helpers/url.js +1 -1
- package/dist/helpers/visitorId.js +4 -1
- package/dist/index-helpers/blocks-exports.js +2 -2
- package/dist/scripts/init-editing.js +61 -46
- package/dist/types/builder-props.js +1 -0
- package/dist/types/enforced-partials.js +1 -0
- package/package.json +2 -2
- package/src/blocks/button/button.jsx +11 -2
- package/src/blocks/button/component-info.js +16 -22
- package/src/blocks/columns/columns.jsx +29 -28
- package/src/blocks/columns/component-info.js +203 -226
- package/src/blocks/custom-code/component-info.js +19 -25
- package/src/blocks/custom-code/custom-code.jsx +1 -1
- package/src/blocks/embed/component-info.js +31 -37
- package/src/blocks/embed/embed.jsx +1 -1
- package/src/blocks/embed/helpers.js +3 -9
- package/src/blocks/form/component-info.js +174 -212
- package/src/blocks/form/form.jsx +3 -247
- package/src/blocks/fragment/component-info.js +1 -3
- package/src/blocks/fragment/fragment.jsx +1 -1
- package/src/blocks/helpers.js +27 -0
- package/src/blocks/image/component-info.js +105 -133
- package/src/blocks/image/image.helpers.js +3 -5
- package/src/blocks/img/component-info.js +8 -12
- package/src/blocks/img/img.jsx +3 -1
- package/src/blocks/input/component-info.js +29 -57
- package/src/blocks/input/input.jsx +3 -1
- package/src/blocks/raw-text/component-info.js +7 -11
- package/src/blocks/raw-text/raw-text.jsx +4 -2
- package/src/blocks/section/component-info.js +24 -31
- package/src/blocks/section/section.jsx +3 -1
- package/src/blocks/select/component-info.js +34 -48
- package/src/blocks/select/select.jsx +3 -1
- package/src/blocks/submit-button/component-info.js +6 -10
- package/src/blocks/submit-button/submit-button.jsx +3 -2
- package/src/blocks/symbol/component-info.js +30 -37
- package/src/blocks/symbol/symbol.helpers.js +60 -0
- package/src/blocks/symbol/symbol.jsx +34 -59
- package/src/blocks/text/component-info.js +10 -13
- package/src/blocks/textarea/component-info.js +22 -30
- package/src/blocks/textarea/textarea.jsx +3 -1
- package/src/blocks/video/component-info.js +74 -96
- package/src/components/{render-block/render-block.helpers.js → block/block.helpers.js} +26 -44
- package/src/components/{render-block/render-block.jsx → block/block.jsx} +68 -81
- package/src/components/{render-block → block/components}/block-styles.jsx +19 -18
- package/src/components/block/components/block-wrapper.jsx +58 -0
- package/src/components/block/components/component-ref/component-ref.helpers.js +41 -0
- package/src/components/block/components/component-ref/component-ref.jsx +72 -0
- package/src/components/block/components/interactive-element.jsx +37 -0
- package/src/components/{render-block/render-repeated-block.jsx → block/components/repeated-block.jsx} +10 -6
- package/src/components/blocks/blocks-wrapper.jsx +74 -0
- package/src/components/blocks/blocks.jsx +51 -0
- package/src/components/{render-content/render-content.jsx → content/components/enable-editor.jsx} +81 -165
- package/src/components/{render-content/components/render-styles.helpers.js → content/components/styles.helpers.js} +6 -7
- package/src/components/{render-content/components/render-styles.jsx → content/components/styles.jsx} +7 -7
- package/src/components/{render-content/render-content.helpers.js → content/content.helpers.js} +15 -15
- package/src/components/content/content.jsx +141 -0
- package/src/components/content/content.types.js +0 -0
- package/src/components/content/index.js +2 -0
- package/src/components/content/wrap-component-ref.js +2 -0
- package/src/components/content-variants/content-variants.jsx +120 -0
- package/src/components/{render-content-variants → content-variants}/helpers.js +58 -41
- package/src/components/inlined-script.jsx +18 -0
- package/src/components/{render-inlined-styles.jsx → inlined-styles.jsx} +3 -3
- package/src/constants/device-sizes.js +6 -6
- package/src/constants/sdk-version.js +1 -1
- package/src/context/builder.context.js +1 -1
- package/src/functions/apply-patch-with-mutation.js +66 -0
- package/src/functions/camel-to-kebab-case.js +2 -4
- package/src/functions/evaluate/acorn.js +1595 -0
- package/src/functions/{evaluate.js → evaluate/evaluate.js} +36 -10
- package/src/functions/evaluate/index.js +2 -0
- package/src/functions/evaluate/interpreter.js +2801 -0
- package/src/functions/evaluate/non-node-runtime.js +92 -0
- package/src/functions/evaluate/types.js +0 -0
- package/src/functions/event-handler-name.js +2 -4
- package/src/functions/extract-text-styles.js +4 -12
- package/src/functions/fast-clone.js +2 -4
- package/src/functions/get-block-actions-handler.js +3 -5
- package/src/functions/get-block-actions.js +15 -4
- package/src/functions/get-block-component-options.js +11 -12
- package/src/functions/get-block-properties.js +29 -19
- package/src/functions/get-builder-search-params/index.js +5 -10
- package/src/functions/get-content/generate-content-url.js +17 -19
- package/src/functions/get-content/index.js +43 -29
- package/src/functions/get-fetch.js +1 -3
- package/src/functions/get-global-this.js +1 -3
- package/src/functions/get-processed-block.js +12 -13
- package/src/functions/get-react-native-block-styles.js +11 -12
- package/src/functions/if-target.js +1 -3
- package/src/functions/is-browser.js +1 -3
- package/src/functions/is-editing.js +1 -3
- package/src/functions/is-iframe.js +1 -3
- package/src/functions/is-non-node-server.js +9 -0
- package/src/functions/is-previewing.js +1 -3
- package/src/functions/on-change.js +1 -4
- package/src/functions/register-component.js +34 -42
- package/src/functions/register.js +1 -3
- package/src/functions/sanitize-react-native-block-styles.js +22 -17
- package/src/functions/set-editor-settings.js +1 -3
- package/src/functions/set.js +1 -3
- package/src/functions/track/helpers.js +3 -5
- package/src/functions/track/index.js +45 -43
- package/src/functions/track/interaction.js +11 -7
- package/src/functions/transform-block-properties.js +2 -0
- package/src/helpers/ab-tests.js +46 -26
- package/src/helpers/canTrack.js +3 -5
- package/src/helpers/css.js +3 -7
- package/src/helpers/flatten.js +15 -18
- package/src/helpers/localStorage.js +1 -4
- package/src/helpers/logger.js +1 -3
- package/src/helpers/nullable.js +2 -4
- package/src/helpers/preview-lru-cache/get.js +8 -0
- package/src/helpers/preview-lru-cache/helpers.js +10 -0
- package/src/helpers/preview-lru-cache/init.js +10 -0
- package/src/helpers/preview-lru-cache/set.js +35 -0
- package/src/helpers/preview-lru-cache/types.js +0 -0
- package/src/helpers/sessionId.js +14 -11
- package/src/helpers/time.js +1 -3
- package/src/helpers/url.js +2 -4
- package/src/helpers/uuid.js +4 -6
- package/src/helpers/visitorId.js +8 -7
- package/src/index-helpers/blocks-exports.js +1 -1
- package/src/index.js +2 -17
- package/src/scripts/init-editing.js +62 -48
- package/src/types/api-version.js +1 -3
- package/src/types/builder-props.js +0 -0
- package/src/types/enforced-partials.js +0 -0
- package/dist/blocks/BaseText.d.ts +0 -6
- package/dist/blocks/button/button.d.ts +0 -9
- package/dist/blocks/button/component-info.d.ts +0 -2
- package/dist/blocks/columns/columns.d.ts +0 -16
- package/dist/blocks/columns/component-info.d.ts +0 -2
- package/dist/blocks/custom-code/component-info.d.ts +0 -2
- package/dist/blocks/custom-code/custom-code.d.ts +0 -5
- package/dist/blocks/embed/component-info.d.ts +0 -2
- package/dist/blocks/embed/embed.d.ts +0 -5
- package/dist/blocks/embed/helpers.d.ts +0 -1
- package/dist/blocks/form/component-info.d.ts +0 -2
- package/dist/blocks/form/form.d.ts +0 -28
- package/dist/blocks/fragment/component-info.d.ts +0 -2
- package/dist/blocks/fragment/fragment.d.ts +0 -8
- package/dist/blocks/image/component-info.d.ts +0 -2
- package/dist/blocks/image/image.d.ts +0 -17
- package/dist/blocks/image/image.helpers.d.ts +0 -1
- package/dist/blocks/img/component-info.d.ts +0 -2
- package/dist/blocks/img/img.d.ts +0 -11
- package/dist/blocks/input/component-info.d.ts +0 -2
- package/dist/blocks/input/input.d.ts +0 -12
- package/dist/blocks/raw-text/component-info.d.ts +0 -2
- package/dist/blocks/raw-text/raw-text.d.ts +0 -5
- package/dist/blocks/section/component-info.d.ts +0 -2
- package/dist/blocks/section/section.d.ts +0 -9
- package/dist/blocks/select/component-info.d.ts +0 -2
- package/dist/blocks/select/select.d.ts +0 -13
- package/dist/blocks/submit-button/component-info.d.ts +0 -2
- package/dist/blocks/submit-button/submit-button.d.ts +0 -7
- package/dist/blocks/symbol/component-info.d.ts +0 -2
- package/dist/blocks/symbol/symbol.d.ts +0 -21
- package/dist/blocks/text/component-info.d.ts +0 -2
- package/dist/blocks/text/text.d.ts +0 -7
- package/dist/blocks/textarea/component-info.d.ts +0 -2
- package/dist/blocks/textarea/textarea.d.ts +0 -10
- package/dist/blocks/util.d.ts +0 -4
- package/dist/blocks/video/component-info.d.ts +0 -2
- package/dist/blocks/video/video.d.ts +0 -31
- package/dist/components/render-block/block-styles.d.ts +0 -9
- package/dist/components/render-block/render-block.d.ts +0 -9
- package/dist/components/render-block/render-block.helpers.d.ts +0 -12
- package/dist/components/render-block/render-component.d.ts +0 -17
- package/dist/components/render-block/render-repeated-block.d.ts +0 -9
- package/dist/components/render-block/types.d.ts +0 -6
- package/dist/components/render-blocks.d.ts +0 -10
- package/dist/components/render-content/builder-editing.d.ts +0 -3
- package/dist/components/render-content/components/render-styles.d.ts +0 -9
- package/dist/components/render-content/components/render-styles.helpers.d.ts +0 -15
- package/dist/components/render-content/index.d.ts +0 -1
- package/dist/components/render-content/render-content.d.ts +0 -4
- package/dist/components/render-content/render-content.helpers.d.ts +0 -7
- package/dist/components/render-content/render-content.types.d.ts +0 -38
- package/dist/components/render-content/wrap-component-ref.d.ts +0 -6
- package/dist/components/render-content-variants/helpers.d.ts +0 -17
- package/dist/components/render-content-variants/render-content-variants.d.ts +0 -5
- package/dist/components/render-inlined-styles.d.ts +0 -7
- package/dist/constants/builder-registered-components.d.ts +0 -6
- package/dist/constants/device-sizes.d.ts +0 -13
- package/dist/constants/sdk-version.d.ts +0 -1
- package/dist/constants/target.d.ts +0 -3
- package/dist/context/builder.context.d.ts +0 -3
- package/dist/context/types.d.ts +0 -35
- package/dist/functions/camel-to-kebab-case.d.ts +0 -1
- package/dist/functions/evaluate.d.ts +0 -7
- package/dist/functions/evaluate.test.d.ts +0 -1
- package/dist/functions/event-handler-name.d.ts +0 -1
- package/dist/functions/extract-text-styles.d.ts +0 -4
- package/dist/functions/fast-clone.d.ts +0 -4
- package/dist/functions/get-block-actions-handler.d.ts +0 -8
- package/dist/functions/get-block-actions.d.ts +0 -9
- package/dist/functions/get-block-component-options.d.ts +0 -2
- package/dist/functions/get-block-properties.d.ts +0 -2
- package/dist/functions/get-builder-search-params/fn.test.d.ts +0 -1
- package/dist/functions/get-builder-search-params/index.d.ts +0 -12
- package/dist/functions/get-content/generate-content-url.d.ts +0 -2
- package/dist/functions/get-content/generate-content-url.test.d.ts +0 -1
- package/dist/functions/get-content/index.d.ts +0 -16
- package/dist/functions/get-content/types.d.ts +0 -51
- package/dist/functions/get-fetch.d.ts +0 -1
- package/dist/functions/get-processed-block.d.ts +0 -10
- package/dist/functions/get-processed-block.test.d.ts +0 -1
- package/dist/functions/get-react-native-block-styles.d.ts +0 -7
- package/dist/functions/if-target.d.ts +0 -7
- package/dist/functions/is-browser.d.ts +0 -1
- package/dist/functions/is-editing.d.ts +0 -1
- package/dist/functions/is-iframe.d.ts +0 -1
- package/dist/functions/is-previewing.d.ts +0 -1
- package/dist/functions/on-change.d.ts +0 -7
- package/dist/functions/on-change.test.d.ts +0 -1
- package/dist/functions/register-component.d.ts +0 -14
- package/dist/functions/register.d.ts +0 -16
- package/dist/functions/sanitize-react-native-block-styles.d.ts +0 -3
- package/dist/functions/set-editor-settings.d.ts +0 -4
- package/dist/functions/set.d.ts +0 -7
- package/dist/functions/set.test.d.ts +0 -1
- package/dist/functions/track/helpers.d.ts +0 -5
- package/dist/functions/track/index.d.ts +0 -51
- package/dist/functions/track/interaction.d.ts +0 -13
- package/dist/functions/transform-block-properties.d.ts +0 -3
- package/dist/functions/transform-block.d.ts +0 -2
- package/dist/helpers/ab-tests.d.ts +0 -9
- package/dist/helpers/canTrack.d.ts +0 -1
- package/dist/helpers/cookie.d.ts +0 -9
- package/dist/helpers/css.d.ts +0 -7
- package/dist/helpers/flatten.d.ts +0 -6
- package/dist/helpers/localStorage.d.ts +0 -9
- package/dist/helpers/logger.d.ts +0 -6
- package/dist/helpers/nullable.d.ts +0 -2
- package/dist/helpers/sessionId.d.ts +0 -6
- package/dist/helpers/time.d.ts +0 -1
- package/dist/helpers/url.d.ts +0 -6
- package/dist/helpers/url.test.d.ts +0 -1
- package/dist/helpers/uuid.d.ts +0 -8
- package/dist/helpers/visitorId.d.ts +0 -6
- package/dist/index-helpers/blocks-exports.d.ts +0 -8
- package/dist/index-helpers/top-of-file.d.ts +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/scripts/init-editing.d.ts +0 -6
- package/dist/types/api-version.d.ts +0 -2
- package/dist/types/builder-block.d.ts +0 -66
- package/dist/types/builder-content.d.ts +0 -44
- package/dist/types/can-track.d.ts +0 -3
- package/dist/types/components.d.ts +0 -105
- package/dist/types/deep-partial.d.ts +0 -3
- package/dist/types/element.d.ts +0 -59
- package/dist/types/input.d.ts +0 -121
- package/dist/types/targets.d.ts +0 -3
- package/dist/types/typescript.d.ts +0 -5
- package/src/blocks/util.js +0 -8
- package/src/components/render-block/render-component.jsx +0 -55
- package/src/components/render-blocks.jsx +0 -101
- package/src/components/render-content/builder-editing.jsx +0 -16
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/wrap-component-ref.js +0 -4
- package/src/components/render-content-variants/render-content-variants.jsx +0 -101
- package/src/functions/evaluate.test.js +0 -17
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-content/generate-content-url.test.js +0 -97
- package/src/functions/get-processed-block.test.js +0 -34
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/set.test.js +0 -16
- package/src/helpers/url.test.js +0 -21
- /package/src/components/{render-block → block}/types.js +0 -0
- /package/src/components/{render-content/render-content.types.js → content-variants/content-variants.types.js} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runInNonNode = void 0;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value
|
|
16
|
+
}) : obj[key] = value;
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
if (__getOwnPropSymbols)
|
|
22
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
23
|
+
if (__propIsEnum.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
}
|
|
26
|
+
return a;
|
|
27
|
+
};
|
|
28
|
+
const logger_1 = require("../../helpers/logger");
|
|
29
|
+
const set_1 = require("../set");
|
|
30
|
+
const interpreter_js_1 = __importDefault(require("./interpreter.js"));
|
|
31
|
+
const processCode = code => {
|
|
32
|
+
return code.split("\n").map(line => {
|
|
33
|
+
const trimmed = line.trim();
|
|
34
|
+
if (line.includes("__awaiter"))
|
|
35
|
+
return void 0;
|
|
36
|
+
const isStateSetter = trimmed.startsWith("state.");
|
|
37
|
+
if (!isStateSetter)
|
|
38
|
+
return line;
|
|
39
|
+
const [lhs, rhs] = trimmed.split("=");
|
|
40
|
+
const setStr = lhs.replace("state.", "").trim();
|
|
41
|
+
const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
|
|
42
|
+
return `
|
|
43
|
+
${line}
|
|
44
|
+
${setExpr}
|
|
45
|
+
`;
|
|
46
|
+
}).filter(Boolean).join("\n");
|
|
47
|
+
};
|
|
48
|
+
const getJSONValName = val => val + "JSON";
|
|
49
|
+
const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
|
|
50
|
+
const state = __spreadValues(__spreadValues({}, rootState), localState);
|
|
51
|
+
const properties = {
|
|
52
|
+
state,
|
|
53
|
+
Builder: builder,
|
|
54
|
+
builder,
|
|
55
|
+
context,
|
|
56
|
+
event
|
|
57
|
+
};
|
|
58
|
+
const prependedCode = Object.keys(properties).map(key => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
|
|
59
|
+
const cleanedCode = processCode(useCode);
|
|
60
|
+
if (cleanedCode === "") {
|
|
61
|
+
logger_1.logger.warn("Skipping evaluation of empty code block.");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const transformed = `
|
|
65
|
+
function theFunction() {
|
|
66
|
+
${prependedCode}
|
|
67
|
+
|
|
68
|
+
${cleanedCode}
|
|
69
|
+
}
|
|
70
|
+
theFunction();
|
|
71
|
+
`;
|
|
72
|
+
const setRootState = (prop, value) => {
|
|
73
|
+
const newState = (0, set_1.set)(state, prop, value);
|
|
74
|
+
rootSetState == null ? void 0 : rootSetState(newState);
|
|
75
|
+
};
|
|
76
|
+
const initFunc = function (interpreter, globalObject) {
|
|
77
|
+
Object.keys(properties).forEach(key => {
|
|
78
|
+
const val = properties[key] || {};
|
|
79
|
+
const jsonVal = JSON.stringify(val);
|
|
80
|
+
interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
|
|
81
|
+
});
|
|
82
|
+
interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const myInterpreter = new interpreter_js_1.default(transformed, initFunc);
|
|
86
|
+
myInterpreter.run();
|
|
87
|
+
const output = myInterpreter.pseudoToNative(myInterpreter.value);
|
|
88
|
+
return output;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
logger_1.logger.warn("Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.", {
|
|
92
|
+
e
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.runInNonNode = runInNonNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const evaluate_js_1 = require("./evaluate.js");
|
|
4
4
|
describe("flatten state", () => {
|
|
5
5
|
it("should behave normally when no PROTO_STATE", () => {
|
|
6
6
|
const localState = {};
|
|
7
|
-
const rootState = {
|
|
8
|
-
|
|
7
|
+
const rootState = {
|
|
8
|
+
foo: "bar"
|
|
9
|
+
};
|
|
10
|
+
const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
|
|
9
11
|
expect(flattened.foo).toEqual("bar");
|
|
10
12
|
flattened.foo = "baz";
|
|
11
13
|
expect(rootState.foo).toEqual("baz");
|
|
12
14
|
});
|
|
13
15
|
it("should shadow write ", () => {
|
|
14
|
-
const rootState = {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const rootState = {
|
|
17
|
+
foo: "foo"
|
|
18
|
+
};
|
|
19
|
+
const localState = {
|
|
20
|
+
foo: "baz"
|
|
21
|
+
};
|
|
22
|
+
const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
|
|
17
23
|
expect(() => flattened.foo = "bar").toThrow("Writing to local state is not allowed as it is read-only.");
|
|
18
24
|
});
|
|
19
25
|
});
|
|
@@ -4,5 +4,5 @@ exports.getEventHandlerName = void 0;
|
|
|
4
4
|
function capitalizeFirstLetter(string) {
|
|
5
5
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
6
6
|
}
|
|
7
|
-
const getEventHandlerName =
|
|
7
|
+
const getEventHandlerName = key => `on${capitalizeFirstLetter(key)}`;
|
|
8
8
|
exports.getEventHandlerName = getEventHandlerName;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractTextStyles = void 0;
|
|
4
|
-
const TEXT_STYLE_KEYS = [
|
|
5
|
-
|
|
6
|
-
"whiteSpace",
|
|
7
|
-
"direction",
|
|
8
|
-
"hyphens",
|
|
9
|
-
"overflowWrap"
|
|
10
|
-
];
|
|
11
|
-
const isTextStyle = (key) => {
|
|
4
|
+
const TEXT_STYLE_KEYS = ["color", "whiteSpace", "direction", "hyphens", "overflowWrap"];
|
|
5
|
+
const isTextStyle = key => {
|
|
12
6
|
return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
|
|
13
7
|
};
|
|
14
|
-
const extractTextStyles =
|
|
8
|
+
const extractTextStyles = styles => {
|
|
15
9
|
const textStyles = {};
|
|
16
10
|
Object.entries(styles).forEach(([key, value]) => {
|
|
17
11
|
if (isTextStyle(key)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createEventHandler = void 0;
|
|
4
|
-
const
|
|
5
|
-
const createEventHandler = (value, options) =>
|
|
4
|
+
const evaluate_1 = require("./evaluate");
|
|
5
|
+
const createEventHandler = (value, options) => event => (0, evaluate_1.evaluate)({
|
|
6
6
|
code: value,
|
|
7
7
|
context: options.context,
|
|
8
8
|
localState: options.localState,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBlockActions = void 0;
|
|
4
|
+
const target_js_1 = require("../constants/target.js");
|
|
4
5
|
const event_handler_name_js_1 = require("./event-handler-name.js");
|
|
5
6
|
const get_block_actions_handler_js_1 = require("./get-block-actions-handler.js");
|
|
6
7
|
function getBlockActions(options) {
|
|
@@ -12,7 +13,19 @@ function getBlockActions(options) {
|
|
|
12
13
|
continue;
|
|
13
14
|
}
|
|
14
15
|
const value = optionActions[key];
|
|
15
|
-
|
|
16
|
+
let eventHandlerName = (0, event_handler_name_js_1.getEventHandlerName)(key);
|
|
17
|
+
if (options.stripPrefix) {
|
|
18
|
+
switch (target_js_1.TARGET) {
|
|
19
|
+
case "vue2":
|
|
20
|
+
case "vue3":
|
|
21
|
+
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
22
|
+
break;
|
|
23
|
+
case "svelte":
|
|
24
|
+
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
obj[eventHandlerName] = (0, get_block_actions_handler_js_1.createEventHandler)(value, options);
|
|
16
29
|
}
|
|
17
30
|
return obj;
|
|
18
31
|
}
|
|
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
7
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value
|
|
15
|
+
}) : obj[key] = value;
|
|
11
16
|
var __spreadValues = (a, b) => {
|
|
12
17
|
for (var prop in b || (b = {}))
|
|
13
18
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
7
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value
|
|
15
|
+
}) : obj[key] = value;
|
|
11
16
|
var __spreadValues = (a, b) => {
|
|
12
17
|
for (var prop in b || (b = {}))
|
|
13
18
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -22,24 +27,31 @@ var __spreadValues = (a, b) => {
|
|
|
22
27
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
28
|
const target_js_1 = require("../constants/target.js");
|
|
24
29
|
const css_js_1 = require("../helpers/css.js");
|
|
30
|
+
const get_react_native_block_styles_js_1 = require("./get-react-native-block-styles.js");
|
|
25
31
|
const transform_block_properties_js_1 = require("./transform-block-properties.js");
|
|
26
|
-
const extractRelevantRootBlockProperties =
|
|
27
|
-
return {
|
|
32
|
+
const extractRelevantRootBlockProperties = block => {
|
|
33
|
+
return {
|
|
34
|
+
href: block.href
|
|
35
|
+
};
|
|
28
36
|
};
|
|
29
|
-
function getBlockProperties(block) {
|
|
37
|
+
function getBlockProperties({ block, context }) {
|
|
30
38
|
var _a;
|
|
31
39
|
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
32
40
|
"builder-id": block.id,
|
|
33
|
-
style: getStyleAttribute(block.style),
|
|
41
|
+
style: block.style ? getStyleAttribute(block.style) : void 0,
|
|
34
42
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
35
43
|
});
|
|
44
|
+
if (target_js_1.TARGET === "reactNative") {
|
|
45
|
+
properties.style = (0, get_react_native_block_styles_js_1.getReactNativeBlockStyles)({
|
|
46
|
+
block,
|
|
47
|
+
context,
|
|
48
|
+
blockStyles: properties.style
|
|
49
|
+
});
|
|
50
|
+
}
|
|
36
51
|
return (0, transform_block_properties_js_1.transformBlockProperties)(properties);
|
|
37
52
|
}
|
|
38
53
|
exports.getBlockProperties = getBlockProperties;
|
|
39
54
|
function getStyleAttribute(style) {
|
|
40
|
-
if (!style) {
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
55
|
switch (target_js_1.TARGET) {
|
|
44
56
|
case "svelte":
|
|
45
57
|
case "vue2":
|
|
@@ -49,6 +61,7 @@ function getStyleAttribute(style) {
|
|
|
49
61
|
case "qwik":
|
|
50
62
|
case "reactNative":
|
|
51
63
|
case "react":
|
|
64
|
+
case "rsc":
|
|
52
65
|
return style;
|
|
53
66
|
}
|
|
54
67
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const index_js_1 = require("./index.js");
|
|
4
4
|
const querystring = "someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017";
|
|
5
5
|
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
6
6
|
describe("Get Builder SearchParams", () => {
|
|
7
7
|
test("correctly converts URLSearchParams to object", () => {
|
|
8
|
-
const output = (0,
|
|
8
|
+
const output = (0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams);
|
|
9
9
|
expect(output).toMatchSnapshot();
|
|
10
10
|
});
|
|
11
11
|
test("correctly extracts all builder params from a query object", () => {
|
|
12
|
-
const output = (0,
|
|
12
|
+
const output = (0, index_js_1.getBuilderSearchParams)((0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams));
|
|
13
13
|
expect(output).toMatchSnapshot();
|
|
14
14
|
});
|
|
15
15
|
});
|
|
@@ -4,7 +4,7 @@ exports.normalizeSearchParams = exports.getBuilderSearchParamsFromWindow = expor
|
|
|
4
4
|
const is_browser_js_1 = require("../is-browser.js");
|
|
5
5
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
6
6
|
const BUILDER_OPTIONS_PREFIX = "options.";
|
|
7
|
-
const convertSearchParamsToQueryObject =
|
|
7
|
+
const convertSearchParamsToQueryObject = searchParams => {
|
|
8
8
|
const options = {};
|
|
9
9
|
searchParams.forEach((value, key) => {
|
|
10
10
|
options[key] = value;
|
|
@@ -12,13 +12,13 @@ const convertSearchParamsToQueryObject = (searchParams) => {
|
|
|
12
12
|
return options;
|
|
13
13
|
};
|
|
14
14
|
exports.convertSearchParamsToQueryObject = convertSearchParamsToQueryObject;
|
|
15
|
-
const getBuilderSearchParams =
|
|
15
|
+
const getBuilderSearchParams = _options => {
|
|
16
16
|
if (!_options) {
|
|
17
17
|
return {};
|
|
18
18
|
}
|
|
19
19
|
const options = normalizeSearchParams(_options);
|
|
20
20
|
const newOptions = {};
|
|
21
|
-
Object.keys(options).forEach(
|
|
21
|
+
Object.keys(options).forEach(key => {
|
|
22
22
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
23
23
|
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
24
24
|
newOptions[trimmedKey] = options[key];
|
|
@@ -35,5 +35,5 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
35
35
|
return getBuilderSearchParams(searchParams);
|
|
36
36
|
};
|
|
37
37
|
exports.getBuilderSearchParamsFromWindow = getBuilderSearchParamsFromWindow;
|
|
38
|
-
const normalizeSearchParams =
|
|
38
|
+
const normalizeSearchParams = searchParams => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
39
39
|
exports.normalizeSearchParams = normalizeSearchParams;
|
|
@@ -5,7 +5,12 @@ var __defProp = Object.defineProperty;
|
|
|
5
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value
|
|
13
|
+
}) : obj[key] = value;
|
|
9
14
|
var __spreadValues = (a, b) => {
|
|
10
15
|
for (var prop in b || (b = {}))
|
|
11
16
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -19,9 +24,9 @@ var __spreadValues = (a, b) => {
|
|
|
19
24
|
};
|
|
20
25
|
const flatten_js_1 = require("../../helpers/flatten.js");
|
|
21
26
|
const index_js_1 = require("../get-builder-search-params/index.js");
|
|
22
|
-
const
|
|
23
|
-
const generateContentUrl =
|
|
24
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion =
|
|
27
|
+
const api_version_js_1 = require("../../types/api-version.js");
|
|
28
|
+
const generateContentUrl = options => {
|
|
29
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = api_version_js_1.DEFAULT_API_VERSION } = options;
|
|
25
30
|
if (!apiKey) {
|
|
26
31
|
throw new Error("Missing API key");
|
|
27
32
|
}
|
|
@@ -38,7 +43,9 @@ const generateContentUrl = (options) => {
|
|
|
38
43
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
39
44
|
}
|
|
40
45
|
if (query) {
|
|
41
|
-
const flattened2 = (0, flatten_js_1.flatten)({
|
|
46
|
+
const flattened2 = (0, flatten_js_1.flatten)({
|
|
47
|
+
query
|
|
48
|
+
});
|
|
42
49
|
for (const key in flattened2) {
|
|
43
50
|
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
44
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const generate_content_url_js_1 = require("./generate-content-url.js");
|
|
4
4
|
const testKey = "YJIGb4i01jvw0SRdL5Bt";
|
|
5
5
|
const testModel = "page";
|
|
6
6
|
const testId = "c1b81bab59704599b997574eb0736def";
|
|
@@ -14,46 +14,56 @@ const options = {
|
|
|
14
14
|
};
|
|
15
15
|
describe("Generate Content URL", () => {
|
|
16
16
|
test("generates the proper value for a simple query", () => {
|
|
17
|
-
const output = (0,
|
|
17
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
18
18
|
apiKey: testKey,
|
|
19
19
|
model: testModel,
|
|
20
|
-
query: {
|
|
20
|
+
query: {
|
|
21
|
+
id: testId
|
|
22
|
+
}
|
|
21
23
|
});
|
|
22
24
|
expect(output).toMatchSnapshot();
|
|
23
25
|
});
|
|
24
26
|
test("Handles overrides correctly", () => {
|
|
25
|
-
const output = (0,
|
|
27
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
26
28
|
apiKey: testKey,
|
|
27
29
|
model: testModel,
|
|
28
|
-
query: {
|
|
30
|
+
query: {
|
|
31
|
+
id: testId
|
|
32
|
+
},
|
|
29
33
|
options
|
|
30
34
|
});
|
|
31
35
|
expect(output).toMatchSnapshot();
|
|
32
36
|
});
|
|
33
37
|
test("generate content url with apiVersion as default", () => {
|
|
34
|
-
const output = (0,
|
|
38
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
35
39
|
apiKey: testKey,
|
|
36
40
|
model: testModel,
|
|
37
|
-
query: {
|
|
41
|
+
query: {
|
|
42
|
+
id: testId
|
|
43
|
+
},
|
|
38
44
|
options
|
|
39
45
|
});
|
|
40
46
|
expect(output).toMatchSnapshot();
|
|
41
47
|
});
|
|
42
48
|
test("generate content url with apiVersion as v2", () => {
|
|
43
|
-
const output = (0,
|
|
49
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
44
50
|
apiKey: testKey,
|
|
45
51
|
model: testModel,
|
|
46
|
-
query: {
|
|
52
|
+
query: {
|
|
53
|
+
id: testId
|
|
54
|
+
},
|
|
47
55
|
options,
|
|
48
56
|
apiVersion: "v2"
|
|
49
57
|
});
|
|
50
58
|
expect(output).toMatchSnapshot();
|
|
51
59
|
});
|
|
52
60
|
test("generate content url with apiVersion as v3", () => {
|
|
53
|
-
const output = (0,
|
|
61
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
54
62
|
apiKey: testKey,
|
|
55
63
|
model: testModel,
|
|
56
|
-
query: {
|
|
64
|
+
query: {
|
|
65
|
+
id: testId
|
|
66
|
+
},
|
|
57
67
|
options,
|
|
58
68
|
apiVersion: "v3"
|
|
59
69
|
});
|
|
@@ -61,10 +71,12 @@ describe("Generate Content URL", () => {
|
|
|
61
71
|
});
|
|
62
72
|
test("throw error when trying to generate content url with apiVersion as v1", () => {
|
|
63
73
|
expect(() => {
|
|
64
|
-
(0,
|
|
74
|
+
(0, generate_content_url_js_1.generateContentUrl)({
|
|
65
75
|
apiKey: testKey,
|
|
66
76
|
model: testModel,
|
|
67
|
-
query: {
|
|
77
|
+
query: {
|
|
78
|
+
id: testId
|
|
79
|
+
},
|
|
68
80
|
options,
|
|
69
81
|
apiVersion: "v1"
|
|
70
82
|
});
|
|
@@ -72,17 +84,19 @@ describe("Generate Content URL", () => {
|
|
|
72
84
|
});
|
|
73
85
|
test("throw error when trying to generate content url with an invalid apiVersion value", () => {
|
|
74
86
|
expect(() => {
|
|
75
|
-
(0,
|
|
87
|
+
(0, generate_content_url_js_1.generateContentUrl)({
|
|
76
88
|
apiKey: testKey,
|
|
77
89
|
model: testModel,
|
|
78
|
-
query: {
|
|
90
|
+
query: {
|
|
91
|
+
id: testId
|
|
92
|
+
},
|
|
79
93
|
options,
|
|
80
94
|
apiVersion: "INVALID_API_VERSION"
|
|
81
95
|
});
|
|
82
96
|
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
|
|
83
97
|
});
|
|
84
98
|
test("generate content url with enrich option true", () => {
|
|
85
|
-
const output = (0,
|
|
99
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
86
100
|
apiKey: testKey,
|
|
87
101
|
model: testModel,
|
|
88
102
|
enrich: true
|
|
@@ -90,7 +104,7 @@ describe("Generate Content URL", () => {
|
|
|
90
104
|
expect(output).toMatchSnapshot();
|
|
91
105
|
});
|
|
92
106
|
test("generate content url with enrich option not present", () => {
|
|
93
|
-
const output = (0,
|
|
107
|
+
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
94
108
|
apiKey: testKey,
|
|
95
109
|
model: testModel
|
|
96
110
|
});
|
|
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
7
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value
|
|
15
|
+
}) : obj[key] = value;
|
|
11
16
|
var __spreadValues = (a, b) => {
|
|
12
17
|
for (var prop in b || (b = {}))
|
|
13
18
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -22,7 +27,7 @@ var __spreadValues = (a, b) => {
|
|
|
22
27
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
28
|
var __async = (__this, __arguments, generator) => {
|
|
24
29
|
return new Promise((resolve, reject) => {
|
|
25
|
-
var fulfilled =
|
|
30
|
+
var fulfilled = value => {
|
|
26
31
|
try {
|
|
27
32
|
step(generator.next(value));
|
|
28
33
|
}
|
|
@@ -30,7 +35,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
30
35
|
reject(e);
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
|
-
var rejected =
|
|
38
|
+
var rejected = value => {
|
|
34
39
|
try {
|
|
35
40
|
step(generator.throw(value));
|
|
36
41
|
}
|
|
@@ -38,7 +43,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
43
|
reject(e);
|
|
39
44
|
}
|
|
40
45
|
};
|
|
41
|
-
var step =
|
|
46
|
+
var step = x => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
42
47
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
48
|
});
|
|
44
49
|
};
|
|
@@ -46,28 +51,40 @@ const target_js_1 = require("../../constants/target.js");
|
|
|
46
51
|
const ab_tests_js_1 = require("../../helpers/ab-tests.js");
|
|
47
52
|
const canTrack_js_1 = require("../../helpers/canTrack.js");
|
|
48
53
|
const logger_js_1 = require("../../helpers/logger.js");
|
|
54
|
+
const get_js_1 = require("../../helpers/preview-lru-cache/get.js");
|
|
49
55
|
const get_fetch_js_1 = require("../get-fetch.js");
|
|
50
56
|
const is_browser_js_1 = require("../is-browser.js");
|
|
51
57
|
const generate_content_url_js_1 = require("./generate-content-url.js");
|
|
52
|
-
const checkContentHasResults =
|
|
58
|
+
const checkContentHasResults = content => "results" in content;
|
|
53
59
|
function getContent(options) {
|
|
54
60
|
return __async(this, null, function* () {
|
|
55
|
-
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), {
|
|
56
|
-
|
|
61
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), {
|
|
62
|
+
limit: 1
|
|
63
|
+
}));
|
|
64
|
+
if (allContent) {
|
|
57
65
|
return allContent.results[0] || null;
|
|
58
66
|
}
|
|
59
67
|
return null;
|
|
60
68
|
});
|
|
61
69
|
}
|
|
62
70
|
exports.getContent = getContent;
|
|
63
|
-
const fetchContent =
|
|
71
|
+
const fetchContent = options => __async(void 0, null, function* () {
|
|
64
72
|
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
65
73
|
const res = yield (0, get_fetch_js_1.fetch)(url.href);
|
|
66
74
|
const content = yield res.json();
|
|
67
75
|
return content;
|
|
68
76
|
});
|
|
69
|
-
const processContentResult = (
|
|
77
|
+
const processContentResult = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (options, content, url = (0, generate_content_url_js_1.generateContentUrl)(options)) {
|
|
70
78
|
const canTrack = (0, canTrack_js_1.getDefaultCanTrack)(options.canTrack);
|
|
79
|
+
const isPreviewing = url.search.includes(`preview=`);
|
|
80
|
+
if (target_js_1.TARGET === "rsc" && isPreviewing) {
|
|
81
|
+
const newResults = [];
|
|
82
|
+
for (const item of content.results) {
|
|
83
|
+
const previewContent = (0, get_js_1.getPreviewContent)(url.searchParams);
|
|
84
|
+
newResults.push(previewContent || item);
|
|
85
|
+
}
|
|
86
|
+
content.results = newResults;
|
|
87
|
+
}
|
|
71
88
|
if (!canTrack)
|
|
72
89
|
return content;
|
|
73
90
|
if (!((0, is_browser_js_1.isBrowser)() || target_js_1.TARGET === "reactNative"))
|
|
@@ -75,7 +92,10 @@ const processContentResult = (options, content) => __async(void 0, null, functio
|
|
|
75
92
|
try {
|
|
76
93
|
const newResults = [];
|
|
77
94
|
for (const item of content.results) {
|
|
78
|
-
newResults.push(yield (0, ab_tests_js_1.handleABTesting)({
|
|
95
|
+
newResults.push(yield (0, ab_tests_js_1.handleABTesting)({
|
|
96
|
+
item,
|
|
97
|
+
canTrack
|
|
98
|
+
}));
|
|
79
99
|
}
|
|
80
100
|
content.results = newResults;
|
|
81
101
|
}
|
|
@@ -91,8 +111,12 @@ function getAllContent(options) {
|
|
|
91
111
|
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
92
112
|
const content = yield fetchContent(options);
|
|
93
113
|
if (!checkContentHasResults(content)) {
|
|
94
|
-
logger_js_1.logger.error("Error fetching data. ", {
|
|
95
|
-
|
|
114
|
+
logger_js_1.logger.error("Error fetching data. ", {
|
|
115
|
+
url,
|
|
116
|
+
content,
|
|
117
|
+
options
|
|
118
|
+
});
|
|
119
|
+
return null;
|
|
96
120
|
}
|
|
97
121
|
return processContentResult(options, content);
|
|
98
122
|
}
|
|
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
7
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value
|
|
15
|
+
}) : obj[key] = value;
|
|
11
16
|
var __spreadValues = (a, b) => {
|
|
12
17
|
for (var prop in b || (b = {}))
|
|
13
18
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -20,7 +25,7 @@ var __spreadValues = (a, b) => {
|
|
|
20
25
|
return a;
|
|
21
26
|
};
|
|
22
27
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
const
|
|
28
|
+
const evaluate_1 = require("./evaluate");
|
|
24
29
|
const fast_clone_js_1 = require("./fast-clone.js");
|
|
25
30
|
const set_js_1 = require("./set.js");
|
|
26
31
|
const transform_block_js_1 = require("./transform-block.js");
|
|
@@ -35,7 +40,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
35
40
|
});
|
|
36
41
|
for (const binding in block.bindings) {
|
|
37
42
|
const expression = block.bindings[binding];
|
|
38
|
-
const value = (0,
|
|
43
|
+
const value = (0, evaluate_1.evaluate)({
|
|
39
44
|
code: expression,
|
|
40
45
|
localState,
|
|
41
46
|
rootState,
|