@makeswift/runtime 0.28.8-canary.9 → 0.28.8
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/cjs/api/api-resources-client.js +3 -0
- package/dist/cjs/api/api-resources-client.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +1 -1
- package/dist/cjs/api/rest-api-client.js +85 -43
- package/dist/cjs/api/rest-api-client.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/builder/host-to-builder-actions.js +5 -5
- package/dist/cjs/builder/host-to-builder-actions.js.map +1 -1
- package/dist/cjs/client/index.js +40 -44
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/controls/rich-text/control.js +16 -3
- package/dist/cjs/controls/rich-text/control.js.map +1 -1
- package/dist/cjs/controls/rich-text/rich-text.js +2 -2
- package/dist/cjs/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/controls/rich-text-v2/control.js +15 -2
- package/dist/cjs/controls/rich-text-v2/control.js.map +1 -1
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +2 -2
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/controls/slot.js.map +1 -1
- package/dist/cjs/next/testing/breakpoints.js +3 -15
- package/dist/cjs/next/testing/breakpoints.js.map +1 -1
- package/dist/cjs/next/testing/element-data.js +3 -82
- package/dist/cjs/next/testing/element-data.js.map +1 -1
- package/dist/cjs/next/testing/react-runtime.js.map +1 -1
- package/dist/cjs/prop-controllers/instances.js +20 -4
- package/dist/cjs/prop-controllers/instances.js.map +1 -1
- package/dist/cjs/runtimes/react/components/Element.js +53 -24
- package/dist/cjs/runtimes/react/components/Element.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementRegistration.js +32 -11
- package/dist/cjs/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/cjs/runtimes/react/components/control-instances-context.js +38 -0
- package/dist/cjs/runtimes/react/components/control-instances-context.js.map +1 -0
- package/dist/cjs/runtimes/react/components/framework-context.js +1 -0
- package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
- package/dist/cjs/runtimes/react/components/resolve-props.js +5 -1
- package/dist/cjs/runtimes/react/components/resolve-props.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/node-value/editable-node-value.js +42 -0
- package/dist/cjs/runtimes/react/controls/node-value/editable-node-value.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/node-value/index.js +51 -0
- package/dist/cjs/runtimes/react/controls/node-value/index.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +2 -2
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/slot/index.js +29 -0
- package/dist/cjs/runtimes/react/controls/slot/index.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/slot/render-slot.js +37 -0
- package/dist/cjs/runtimes/react/controls/slot/render-slot.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/{slot.js → slot/slot-value.js} +31 -26
- package/dist/cjs/runtimes/react/controls/slot/slot-value.js.map +1 -0
- package/dist/cjs/runtimes/react/element-imperative-handle.js +2 -2
- package/dist/cjs/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-control-instance.js +88 -0
- package/dist/cjs/runtimes/react/hooks/use-control-instance.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-control-instances.js +2 -12
- package/dist/cjs/runtimes/react/hooks/use-control-instances.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-disable-register-element.js +3 -3
- package/dist/cjs/runtimes/react/hooks/use-disable-register-element.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +10 -9
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolved-value-override.js +58 -0
- package/dist/cjs/runtimes/react/hooks/use-resolved-value-override.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-selector.js +8 -2
- package/dist/cjs/runtimes/react/hooks/use-selector.js.map +1 -1
- package/dist/cjs/runtimes/react/testing/index.js +25 -0
- package/dist/cjs/runtimes/react/testing/index.js.map +1 -0
- package/dist/cjs/runtimes/react/testing/react-provider.js +38 -0
- package/dist/cjs/runtimes/react/testing/react-provider.js.map +1 -0
- package/dist/cjs/state/actions/index.js +4 -4
- package/dist/cjs/state/actions/index.js.map +1 -1
- package/dist/cjs/state/actions/internal/action-types.js +34 -0
- package/dist/cjs/state/actions/internal/action-types.js.map +1 -0
- package/dist/cjs/state/actions/internal/index.js +0 -17
- package/dist/cjs/state/actions/internal/index.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-only-action-types.js +44 -0
- package/dist/cjs/state/actions/internal/read-only-action-types.js.map +1 -0
- package/dist/cjs/state/actions/internal/read-only-actions.js +13 -92
- package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-write-action-types.js +44 -0
- package/dist/cjs/state/actions/internal/read-write-action-types.js.map +1 -0
- package/dist/cjs/state/actions/internal/read-write-actions.js +135 -14
- package/dist/cjs/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/cjs/state/api-client/state.js +8 -0
- package/dist/cjs/state/api-client/state.js.map +1 -1
- package/dist/cjs/state/builder-api/action-types.js +49 -0
- package/dist/cjs/state/builder-api/action-types.js.map +1 -0
- package/dist/cjs/state/builder-api/actions.js +14 -36
- package/dist/cjs/state/builder-api/actions.js.map +1 -1
- package/dist/cjs/state/builder-api/proxy.js +2 -1
- package/dist/cjs/state/builder-api/proxy.js.map +1 -1
- package/dist/cjs/state/host-api/action-types.js +43 -0
- package/dist/cjs/state/host-api/action-types.js.map +1 -0
- package/dist/cjs/state/{host-api.js → host-api/actions.js} +17 -33
- package/dist/cjs/state/host-api/actions.js.map +1 -0
- package/dist/cjs/state/host-api/index.js +25 -0
- package/dist/cjs/state/host-api/index.js.map +1 -0
- package/dist/cjs/state/middleware/read-write/builder-api/index.js +2 -58
- package/dist/cjs/state/middleware/read-write/builder-api/index.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/builder-api/middleware.js +89 -0
- package/dist/cjs/state/middleware/read-write/builder-api/middleware.js.map +1 -0
- package/dist/cjs/state/middleware/read-write/builder-api/mount-change-action-buffer.js +72 -0
- package/dist/cjs/state/middleware/read-write/builder-api/mount-change-action-buffer.js.map +1 -0
- package/dist/cjs/state/middleware/read-write/measure-box-models.js +3 -3
- package/dist/cjs/state/middleware/read-write/measure-box-models.js.map +1 -1
- package/dist/cjs/state/middleware/read-write/prop-controller-handles.js +10 -47
- package/dist/cjs/state/middleware/read-write/prop-controller-handles.js.map +1 -1
- package/dist/cjs/state/modules/api-resources.js +5 -5
- package/dist/cjs/state/modules/api-resources.js.map +1 -1
- package/dist/cjs/state/modules/breakpoints.js +4 -4
- package/dist/cjs/state/modules/breakpoints.js.map +1 -1
- package/dist/cjs/state/modules/components-meta.js +3 -3
- package/dist/cjs/state/modules/components-meta.js.map +1 -1
- package/dist/cjs/state/modules/element-trees.js +5 -5
- package/dist/cjs/state/modules/element-trees.js.map +1 -1
- package/dist/cjs/state/modules/is-in-builder.js +2 -2
- package/dist/cjs/state/modules/is-in-builder.js.map +1 -1
- package/dist/cjs/state/modules/is-read-only.js +2 -2
- package/dist/cjs/state/modules/is-read-only.js.map +1 -1
- package/dist/cjs/state/modules/locale.js +2 -2
- package/dist/cjs/state/modules/locale.js.map +1 -1
- package/dist/cjs/state/modules/localized-resources-map.js +3 -3
- package/dist/cjs/state/modules/localized-resources-map.js.map +1 -1
- package/dist/cjs/state/modules/{prop-controllers.js → prop-controller-descriptors.js} +7 -7
- package/dist/cjs/state/modules/prop-controller-descriptors.js.map +1 -0
- package/dist/cjs/state/modules/react-components.js +3 -3
- package/dist/cjs/state/modules/react-components.js.map +1 -1
- package/dist/cjs/state/modules/read-write/box-models.js +5 -5
- package/dist/cjs/state/modules/read-write/box-models.js.map +1 -1
- package/dist/cjs/state/modules/read-write/element-imperative-handles.js +3 -3
- package/dist/cjs/state/modules/read-write/element-imperative-handles.js.map +1 -1
- package/dist/cjs/state/modules/{prop-controller-handles.js → read-write/prop-controllers.js} +5 -5
- package/dist/cjs/state/modules/read-write/prop-controllers.js.map +1 -0
- package/dist/cjs/state/modules/read-write/resolved-value-overrides.js +70 -0
- package/dist/cjs/state/modules/read-write/resolved-value-overrides.js.map +1 -0
- package/dist/cjs/state/read-only-state.js +9 -44
- package/dist/cjs/state/read-only-state.js.map +1 -1
- package/dist/cjs/state/read-write-state.js +61 -1
- package/dist/cjs/state/read-write-state.js.map +1 -1
- package/dist/cjs/state/shared-api/action-types.js +33 -0
- package/dist/cjs/state/shared-api/action-types.js.map +1 -0
- package/dist/cjs/state/{shared-api.js → shared-api/actions.js} +8 -14
- package/dist/cjs/state/shared-api/actions.js.map +1 -0
- package/dist/cjs/state/shared-api/index.js +25 -0
- package/dist/cjs/state/shared-api/index.js.map +1 -0
- package/dist/cjs/state/store.js +5 -3
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/cjs/state/translations/get.js.map +1 -1
- package/dist/cjs/state/translations/merge.js.map +1 -1
- package/dist/cjs/state/unified-state.js +12 -0
- package/dist/cjs/state/unified-state.js.map +1 -1
- package/dist/cjs/testing/breakpoints.js +35 -0
- package/dist/cjs/testing/breakpoints.js.map +1 -0
- package/dist/cjs/testing/element-data.js +102 -0
- package/dist/cjs/testing/element-data.js.map +1 -0
- package/dist/cjs/testing/read-write-state.js +32 -0
- package/dist/cjs/testing/read-write-state.js.map +1 -0
- package/dist/cjs/translations/index.js.map +1 -1
- package/dist/esm/api/api-resources-client.js +3 -0
- package/dist/esm/api/api-resources-client.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +1 -1
- package/dist/esm/api/rest-api-client.js +84 -43
- package/dist/esm/api/rest-api-client.js.map +1 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/builder/host-to-builder-actions.js +2 -4
- package/dist/esm/builder/host-to-builder-actions.js.map +1 -1
- package/dist/esm/client/index.js +45 -45
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/controls/rich-text/control.js +16 -3
- package/dist/esm/controls/rich-text/control.js.map +1 -1
- package/dist/esm/controls/rich-text/rich-text.js +2 -2
- package/dist/esm/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/controls/rich-text-v2/control.js +15 -2
- package/dist/esm/controls/rich-text-v2/control.js.map +1 -1
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js +2 -2
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/controls/slot.js.map +1 -1
- package/dist/esm/next/testing/breakpoints.js +1 -8
- package/dist/esm/next/testing/breakpoints.js.map +1 -1
- package/dist/esm/next/testing/element-data.js +1 -75
- package/dist/esm/next/testing/element-data.js.map +1 -1
- package/dist/esm/next/testing/react-runtime.js.map +1 -1
- package/dist/esm/prop-controllers/instances.js +20 -4
- package/dist/esm/prop-controllers/instances.js.map +1 -1
- package/dist/esm/runtimes/react/components/Element.js +51 -25
- package/dist/esm/runtimes/react/components/Element.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementRegistration.js +37 -12
- package/dist/esm/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/esm/runtimes/react/components/control-instances-context.js +13 -0
- package/dist/esm/runtimes/react/components/control-instances-context.js.map +1 -0
- package/dist/esm/runtimes/react/components/framework-context.js +1 -0
- package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
- package/dist/esm/runtimes/react/components/resolve-props.js +5 -1
- package/dist/esm/runtimes/react/components/resolve-props.js.map +1 -1
- package/dist/esm/runtimes/react/controls/node-value/editable-node-value.js +21 -0
- package/dist/esm/runtimes/react/controls/node-value/editable-node-value.js.map +1 -0
- package/dist/esm/runtimes/react/controls/node-value/index.js +17 -0
- package/dist/esm/runtimes/react/controls/node-value/index.js.map +1 -0
- package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/slot/index.js +5 -0
- package/dist/esm/runtimes/react/controls/slot/index.js.map +1 -0
- package/dist/esm/runtimes/react/controls/slot/render-slot.js +13 -0
- package/dist/esm/runtimes/react/controls/slot/render-slot.js.map +1 -0
- package/dist/esm/runtimes/react/controls/{slot.js → slot/slot-value.js} +34 -23
- package/dist/esm/runtimes/react/controls/slot/slot-value.js.map +1 -0
- package/dist/esm/runtimes/react/element-imperative-handle.js +1 -1
- package/dist/esm/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-control-instance.js +62 -0
- package/dist/esm/runtimes/react/hooks/use-control-instance.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-control-instances.js +1 -11
- package/dist/esm/runtimes/react/hooks/use-control-instances.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-disable-register-element.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-disable-register-element.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js +10 -9
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolved-value-override.js +35 -0
- package/dist/esm/runtimes/react/hooks/use-resolved-value-override.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-selector.js +8 -2
- package/dist/esm/runtimes/react/hooks/use-selector.js.map +1 -1
- package/dist/esm/runtimes/react/testing/index.js +3 -0
- package/dist/esm/runtimes/react/testing/index.js.map +1 -0
- package/dist/esm/runtimes/react/testing/react-provider.js +14 -0
- package/dist/esm/runtimes/react/testing/react-provider.js.map +1 -0
- package/dist/esm/state/actions/index.js +2 -2
- package/dist/esm/state/actions/index.js.map +1 -1
- package/dist/esm/state/actions/internal/action-types.js +10 -0
- package/dist/esm/state/actions/internal/action-types.js.map +1 -0
- package/dist/esm/state/actions/internal/index.js +0 -9
- package/dist/esm/state/actions/internal/index.js.map +1 -1
- package/dist/esm/state/actions/internal/read-only-action-types.js +20 -0
- package/dist/esm/state/actions/internal/read-only-action-types.js.map +1 -0
- package/dist/esm/state/actions/internal/read-only-actions.js +1 -73
- package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
- package/dist/esm/state/actions/internal/read-write-action-types.js +20 -0
- package/dist/esm/state/actions/internal/read-write-action-types.js.map +1 -0
- package/dist/esm/state/actions/internal/read-write-actions.js +108 -8
- package/dist/esm/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/esm/state/api-client/state.js +7 -0
- package/dist/esm/state/api-client/state.js.map +1 -1
- package/dist/esm/state/builder-api/action-types.js +25 -0
- package/dist/esm/state/builder-api/action-types.js.map +1 -0
- package/dist/esm/state/builder-api/actions.js +1 -24
- package/dist/esm/state/builder-api/actions.js.map +1 -1
- package/dist/esm/state/builder-api/proxy.js +2 -1
- package/dist/esm/state/builder-api/proxy.js.map +1 -1
- package/dist/esm/state/host-api/action-types.js +19 -0
- package/dist/esm/state/host-api/action-types.js.map +1 -0
- package/dist/esm/state/{host-api.js → host-api/actions.js} +2 -17
- package/dist/esm/state/host-api/actions.js.map +1 -0
- package/dist/esm/state/host-api/index.js +3 -0
- package/dist/esm/state/host-api/index.js.map +1 -0
- package/dist/esm/state/middleware/read-write/builder-api/index.js +1 -57
- package/dist/esm/state/middleware/read-write/builder-api/index.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +3 -0
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
- package/dist/esm/state/middleware/read-write/builder-api/middleware.js +65 -0
- package/dist/esm/state/middleware/read-write/builder-api/middleware.js.map +1 -0
- package/dist/esm/state/middleware/read-write/builder-api/mount-change-action-buffer.js +48 -0
- package/dist/esm/state/middleware/read-write/builder-api/mount-change-action-buffer.js.map +1 -0
- package/dist/esm/state/middleware/read-write/measure-box-models.js +3 -3
- package/dist/esm/state/middleware/read-write/measure-box-models.js.map +1 -1
- package/dist/esm/state/middleware/read-write/prop-controller-handles.js +13 -47
- package/dist/esm/state/middleware/read-write/prop-controller-handles.js.map +1 -1
- package/dist/esm/state/modules/api-resources.js +2 -2
- package/dist/esm/state/modules/api-resources.js.map +1 -1
- package/dist/esm/state/modules/breakpoints.js +2 -2
- package/dist/esm/state/modules/breakpoints.js.map +1 -1
- package/dist/esm/state/modules/components-meta.js +1 -1
- package/dist/esm/state/modules/components-meta.js.map +1 -1
- package/dist/esm/state/modules/element-trees.js +2 -2
- package/dist/esm/state/modules/element-trees.js.map +1 -1
- package/dist/esm/state/modules/is-in-builder.js +1 -1
- package/dist/esm/state/modules/is-in-builder.js.map +1 -1
- package/dist/esm/state/modules/is-read-only.js +1 -1
- package/dist/esm/state/modules/is-read-only.js.map +1 -1
- package/dist/esm/state/modules/locale.js +1 -1
- package/dist/esm/state/modules/locale.js.map +1 -1
- package/dist/esm/state/modules/localized-resources-map.js +1 -1
- package/dist/esm/state/modules/localized-resources-map.js.map +1 -1
- package/dist/esm/state/modules/{prop-controllers.js → prop-controller-descriptors.js} +2 -2
- package/dist/esm/state/modules/prop-controller-descriptors.js.map +1 -0
- package/dist/esm/state/modules/react-components.js +1 -1
- package/dist/esm/state/modules/react-components.js.map +1 -1
- package/dist/esm/state/modules/read-write/box-models.js +2 -2
- package/dist/esm/state/modules/read-write/box-models.js.map +1 -1
- package/dist/esm/state/modules/read-write/element-imperative-handles.js +3 -3
- package/dist/esm/state/modules/read-write/element-imperative-handles.js.map +1 -1
- package/dist/esm/state/modules/{prop-controller-handles.js → read-write/prop-controllers.js} +2 -2
- package/dist/esm/state/modules/read-write/prop-controllers.js.map +1 -0
- package/dist/esm/state/modules/read-write/resolved-value-overrides.js +43 -0
- package/dist/esm/state/modules/read-write/resolved-value-overrides.js.map +1 -0
- package/dist/esm/state/read-only-state.js +9 -41
- package/dist/esm/state/read-only-state.js.map +1 -1
- package/dist/esm/state/read-write-state.js +56 -1
- package/dist/esm/state/read-write-state.js.map +1 -1
- package/dist/esm/state/shared-api/action-types.js +9 -0
- package/dist/esm/state/shared-api/action-types.js.map +1 -0
- package/dist/esm/state/{shared-api.js → shared-api/actions.js} +2 -7
- package/dist/esm/state/shared-api/actions.js.map +1 -0
- package/dist/esm/state/shared-api/index.js +3 -0
- package/dist/esm/state/shared-api/index.js.map +1 -0
- package/dist/esm/state/store.js +3 -1
- package/dist/esm/state/store.js.map +1 -1
- package/dist/esm/state/translations/get.js.map +1 -1
- package/dist/esm/state/translations/merge.js +3 -1
- package/dist/esm/state/translations/merge.js.map +1 -1
- package/dist/esm/state/unified-state.js +4 -0
- package/dist/esm/state/unified-state.js.map +1 -1
- package/dist/esm/testing/breakpoints.js +9 -0
- package/dist/esm/testing/breakpoints.js.map +1 -0
- package/dist/esm/testing/element-data.js +76 -0
- package/dist/esm/testing/element-data.js.map +1 -0
- package/dist/esm/testing/read-write-state.js +8 -0
- package/dist/esm/testing/read-write-state.js.map +1 -0
- package/dist/esm/translations/index.js.map +1 -1
- package/dist/types/api/__tests__/rest-api-client.retries.test.d.ts +2 -0
- package/dist/types/api/__tests__/rest-api-client.retries.test.d.ts.map +1 -0
- package/dist/types/api/api-resources-client.d.ts +1 -0
- package/dist/types/api/api-resources-client.d.ts.map +1 -1
- package/dist/types/api/rest-api-client.d.ts +4 -0
- package/dist/types/api/rest-api-client.d.ts.map +1 -1
- package/dist/types/api/schema/page-pathname-slice.d.ts +2 -2
- package/dist/types/api/types.d.ts +1 -1
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
- package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
- package/dist/types/builder/host-to-builder-actions.d.ts.map +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/components/builtin/Form/Form.d.ts +1 -1
- package/dist/types/components/builtin/Form/Form.d.ts.map +1 -1
- package/dist/types/components/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
- package/dist/types/components/hooks/useIsomorphicLayoutEffect.d.ts.map +1 -1
- package/dist/types/controls/__tests__/slot.test.d.ts +3 -0
- package/dist/types/controls/__tests__/slot.test.d.ts.map +1 -0
- package/dist/types/controls/rich-text/control.d.ts +5 -1
- package/dist/types/controls/rich-text/control.d.ts.map +1 -1
- package/dist/types/controls/rich-text/rich-text.d.ts +2 -2
- package/dist/types/controls/rich-text/rich-text.d.ts.map +1 -1
- package/dist/types/controls/rich-text-v2/control.d.ts +6 -2
- package/dist/types/controls/rich-text-v2/control.d.ts.map +1 -1
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +2 -2
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/controls/slot.d.ts +1 -1
- package/dist/types/controls/slot.d.ts.map +1 -1
- package/dist/types/locale.d.ts +1 -1
- package/dist/types/next/testing/breakpoints.d.ts +1 -3
- package/dist/types/next/testing/breakpoints.d.ts.map +1 -1
- package/dist/types/next/testing/element-data.d.ts +1 -54
- package/dist/types/next/testing/element-data.d.ts.map +1 -1
- package/dist/types/next/testing/react-runtime.d.ts.map +1 -1
- package/dist/types/prop-controllers/instances.d.ts +9 -3
- package/dist/types/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/Element.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/ElementRegistration.d.ts +4 -4
- package/dist/types/runtimes/react/components/ElementRegistration.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/__tests__/element-registration.test.d.ts +3 -0
- package/dist/types/runtimes/react/components/__tests__/element-registration.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/control-instances-context.d.ts +9 -0
- package/dist/types/runtimes/react/components/control-instances-context.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/resolve-props.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/node-value/editable-node-value.d.ts +7 -0
- package/dist/types/runtimes/react/controls/node-value/editable-node-value.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/node-value/index.d.ts +6 -0
- package/dist/types/runtimes/react/controls/node-value/index.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts +1 -1
- package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/slot/index.d.ts +2 -0
- package/dist/types/runtimes/react/controls/slot/index.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/slot/render-slot.d.ts +9 -0
- package/dist/types/runtimes/react/controls/slot/render-slot.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/{slot.d.ts → slot/slot-value.d.ts} +7 -7
- package/dist/types/runtimes/react/controls/slot/slot-value.d.ts.map +1 -0
- package/dist/types/runtimes/react/element-imperative-handle.d.ts +1 -1
- package/dist/types/runtimes/react/element-imperative-handle.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/__tests__/use-control-instance.test.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/__tests__/use-control-instance.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-control-instance.d.ts +7 -0
- package/dist/types/runtimes/react/hooks/use-control-instance.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-control-instances.d.ts +1 -2
- package/dist/types/runtimes/react/hooks/use-control-instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts +4 -3
- package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resolved-value-override.d.ts +5 -0
- package/dist/types/runtimes/react/hooks/use-resolved-value-override.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-selector.d.ts +2 -5
- package/dist/types/runtimes/react/hooks/use-selector.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts +2 -4
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/testing/index.d.ts +3 -0
- package/dist/types/runtimes/react/testing/index.d.ts.map +1 -0
- package/dist/types/runtimes/react/testing/react-provider.d.ts +8 -0
- package/dist/types/runtimes/react/testing/react-provider.d.ts.map +1 -0
- package/dist/types/slate/InlineModePlugin/index.d.ts +1 -1
- package/dist/types/slate/LinkPlugin/getValue.d.ts.map +1 -1
- package/dist/types/slate/LinkPlugin/index.d.ts.map +1 -1
- package/dist/types/slate/TypographyPlugin/getValue.d.ts.map +1 -1
- package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/state/__tests__/test-store.d.ts +2 -4
- package/dist/types/state/__tests__/test-store.d.ts.map +1 -1
- package/dist/types/state/actions/index.d.ts +9 -6
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/action-types.d.ts +29 -0
- package/dist/types/state/actions/internal/action-types.d.ts.map +1 -0
- package/dist/types/state/actions/internal/index.d.ts +0 -25
- package/dist/types/state/actions/internal/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-only-action-types.d.ts +15 -0
- package/dist/types/state/actions/internal/read-only-action-types.d.ts.map +1 -0
- package/dist/types/state/actions/internal/read-only-actions.d.ts +3 -76
- package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-write-action-types.d.ts +17 -0
- package/dist/types/state/actions/internal/read-write-action-types.d.ts.map +1 -0
- package/dist/types/state/actions/internal/read-write-actions.d.ts +89 -8
- package/dist/types/state/actions/internal/read-write-actions.d.ts.map +1 -1
- package/dist/types/state/api-client/state.d.ts +1 -0
- package/dist/types/state/api-client/state.d.ts.map +1 -1
- package/dist/types/state/builder-api/action-types.d.ts +22 -0
- package/dist/types/state/builder-api/action-types.d.ts.map +1 -0
- package/dist/types/state/builder-api/actions.d.ts +3 -23
- package/dist/types/state/builder-api/actions.d.ts.map +1 -1
- package/dist/types/state/builder-api/proxy.d.ts.map +1 -1
- package/dist/types/state/host-api/action-types.d.ts +17 -0
- package/dist/types/state/host-api/action-types.d.ts.map +1 -0
- package/dist/types/state/{host-api.d.ts → host-api/actions.d.ts} +7 -22
- package/dist/types/state/host-api/actions.d.ts.map +1 -0
- package/dist/types/state/host-api/index.d.ts +3 -0
- package/dist/types/state/host-api/index.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/__tests__/fixtures/operations.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/__tests__/fixtures/root-elements.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/__tests__/prop-controller-handles.test.d.ts +2 -0
- package/dist/types/state/middleware/read-write/__tests__/prop-controller-handles.test.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/__tests__/update-element-tree.test.d.ts +2 -0
- package/dist/types/state/middleware/read-write/__tests__/update-element-tree.test.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/builder-api/__tests__/middleware.test.d.ts +2 -0
- package/dist/types/state/middleware/read-write/builder-api/__tests__/middleware.test.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/builder-api/__tests__/mount-change-action-buffer.test.d.ts +2 -0
- package/dist/types/state/middleware/read-write/builder-api/__tests__/mount-change-action-buffer.test.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/builder-api/index.d.ts +1 -4
- package/dist/types/state/middleware/read-write/builder-api/index.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +1 -1
- package/dist/types/state/middleware/read-write/builder-api/middleware.d.ts +5 -0
- package/dist/types/state/middleware/read-write/builder-api/middleware.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/builder-api/mount-change-action-buffer.d.ts +28 -0
- package/dist/types/state/middleware/read-write/builder-api/mount-change-action-buffer.d.ts.map +1 -0
- package/dist/types/state/middleware/read-write/prop-controller-handles.d.ts.map +1 -1
- package/dist/types/state/modules/element-trees.d.ts +1 -1
- package/dist/types/state/modules/element-trees.d.ts.map +1 -1
- package/dist/types/state/modules/{prop-controllers.d.ts → prop-controller-descriptors.d.ts} +1 -1
- package/dist/types/state/modules/prop-controller-descriptors.d.ts.map +1 -0
- package/dist/types/state/modules/{prop-controller-handles.d.ts → read-write/prop-controllers.d.ts} +4 -4
- package/dist/types/state/modules/{prop-controller-handles.d.ts.map → read-write/prop-controllers.d.ts.map} +1 -1
- package/dist/types/state/modules/read-write/resolved-value-overrides.d.ts +15 -0
- package/dist/types/state/modules/read-write/resolved-value-overrides.d.ts.map +1 -0
- package/dist/types/state/read-only-state.d.ts +6 -70
- package/dist/types/state/read-only-state.d.ts.map +1 -1
- package/dist/types/state/read-write-state.d.ts +74 -4
- package/dist/types/state/read-write-state.d.ts.map +1 -1
- package/dist/types/state/shared-api/action-types.d.ts +6 -0
- package/dist/types/state/shared-api/action-types.d.ts.map +1 -0
- package/dist/types/state/{shared-api.d.ts → shared-api/actions.d.ts} +3 -7
- package/dist/types/state/shared-api/actions.d.ts.map +1 -0
- package/dist/types/state/shared-api/index.d.ts +3 -0
- package/dist/types/state/shared-api/index.d.ts.map +1 -0
- package/dist/types/state/store.d.ts +4 -8
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/state/translations/get.d.ts +1 -1
- package/dist/types/state/translations/get.d.ts.map +1 -1
- package/dist/types/state/translations/merge.d.ts +1 -1
- package/dist/types/state/translations/merge.d.ts.map +1 -1
- package/dist/types/state/unified-state.d.ts +2 -0
- package/dist/types/state/unified-state.d.ts.map +1 -1
- package/dist/types/testing/breakpoints.d.ts +4 -0
- package/dist/types/testing/breakpoints.d.ts.map +1 -0
- package/dist/types/testing/element-data.d.ts +59 -0
- package/dist/types/testing/element-data.d.ts.map +1 -0
- package/dist/types/testing/read-write-state.d.ts +3 -0
- package/dist/types/testing/read-write-state.d.ts.map +1 -0
- package/dist/types/translations/index.d.ts +1 -1
- package/dist/types/translations/index.d.ts.map +1 -1
- package/package.json +7 -5
- package/dist/cjs/runtimes/react/controls/slot.js.map +0 -1
- package/dist/cjs/state/host-api.js.map +0 -1
- package/dist/cjs/state/modules/prop-controller-handles.js.map +0 -1
- package/dist/cjs/state/modules/prop-controllers.js.map +0 -1
- package/dist/cjs/state/shared-api.js.map +0 -1
- package/dist/esm/runtimes/react/controls/slot.js.map +0 -1
- package/dist/esm/state/host-api.js.map +0 -1
- package/dist/esm/state/modules/prop-controller-handles.js.map +0 -1
- package/dist/esm/state/modules/prop-controllers.js.map +0 -1
- package/dist/esm/state/shared-api.js.map +0 -1
- package/dist/types/runtimes/react/controls/slot.d.ts.map +0 -1
- package/dist/types/state/__tests__/fixtures/operations.d.ts.map +0 -1
- package/dist/types/state/__tests__/fixtures/root-elements.d.ts.map +0 -1
- package/dist/types/state/__tests__/react-builder-preview.test.d.ts +0 -2
- package/dist/types/state/__tests__/react-builder-preview.test.d.ts.map +0 -1
- package/dist/types/state/host-api.d.ts.map +0 -1
- package/dist/types/state/modules/prop-controllers.d.ts.map +0 -1
- package/dist/types/state/shared-api.d.ts.map +0 -1
- /package/dist/types/state/{__tests__ → middleware/read-write/__tests__}/fixtures/operations.d.ts +0 -0
- /package/dist/types/state/{__tests__ → middleware/read-write/__tests__}/fixtures/root-elements.d.ts +0 -0
|
@@ -50,6 +50,9 @@ class ApiResourcesClient {
|
|
|
50
50
|
this.store = store;
|
|
51
51
|
this.subscribe = this.store.subscribe;
|
|
52
52
|
}
|
|
53
|
+
get cacheData() {
|
|
54
|
+
return ApiClientState.getSerializedState(this.store.getState());
|
|
55
|
+
}
|
|
53
56
|
async fetchSwatch(swatchId) {
|
|
54
57
|
const fetch = (id, version) => this.fetchSwatchImpl(id, version);
|
|
55
58
|
return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Swatch, swatchId, fetch));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\nimport { fetchAPIResource } from '../state/api-client/fetch-api-resource'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchSwatchImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, fetch))\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchFileImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, fetch))\n }\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTypographyImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, fetch),\n )\n }\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null) =>\n this.fetchGlobalElementImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, fetch),\n )\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) => {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n return this.fetchLocalizedGlobalElementImpl(id, version, locale)\n }\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, fetch, locale),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) =>\n this.fetchPagePathnameSliceImpl(id, version, locale)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, fetch, locale),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTableImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, fetch))\n }\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n\n protected abstract fetchSwatchImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Swatch | null>\n\n protected abstract fetchFileImpl(id: string, version: SiteVersion | null): Promise<File | null>\n protected abstract fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null>\n\n protected abstract fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null>\n\n protected abstract fetchLocalizedGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n locale: string,\n ): Promise<LocalizedGlobalElement | null>\n\n protected abstract fetchPagePathnameSliceImpl(\n id: string,\n version: SiteVersion | null,\n locale: string | null | undefined,\n ): Promise<PagePathnameSlice | null>\n\n protected abstract fetchTableImpl(id: string, version: SiteVersion | null): Promise<Table | null>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAChC,gCAAiC;AAEjC,mBAYO;AAMA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,MAAM;AAAA,EAC9B;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,UAAM,QAAQ,CAAC,IAAY,YAAgC,KAAK,gBAAgB,IAAI,OAAO;AAE3F,WAAO,MAAM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EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,SAAS,SAAS;AAAA,EAChG;AA+BF;","names":["locale"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\nimport { fetchAPIResource } from '../state/api-client/fetch-api-resource'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n get cacheData(): CacheData {\n return ApiClientState.getSerializedState(this.store.getState())\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchSwatchImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, fetch))\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchFileImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, fetch))\n }\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTypographyImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, fetch),\n )\n }\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null) =>\n this.fetchGlobalElementImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, fetch),\n )\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) => {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n return this.fetchLocalizedGlobalElementImpl(id, version, locale)\n }\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, fetch, locale),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) =>\n this.fetchPagePathnameSliceImpl(id, version, locale)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, fetch, locale),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTableImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, fetch))\n }\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n\n protected abstract fetchSwatchImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Swatch | null>\n\n protected abstract fetchFileImpl(id: string, version: SiteVersion | null): Promise<File | null>\n protected abstract fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null>\n\n protected abstract fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null>\n\n protected abstract fetchLocalizedGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n locale: string,\n ): Promise<LocalizedGlobalElement | null>\n\n protected abstract fetchPagePathnameSliceImpl(\n id: string,\n version: SiteVersion | null,\n locale: string | null | undefined,\n ): Promise<PagePathnameSlice | null>\n\n protected abstract fetchTableImpl(id: string, version: SiteVersion | null): Promise<Table | null>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAChC,gCAAiC;AAEjC,mBAYO;AAMA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;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AC,IAAY,YAAgC,KAAK,eAAe,IAAI,OAAO;AAE1F,WAAO,MAAM,KAAK,MAAM,aAAS,4CAAiB,6BAAgB,OAAO,SAAS,KAAK,CAAC;AAAA,EAC1F;AAAA,EAEA,UAAU,SAA+B;AACvC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,OAAO,OAAO;AAAA,EAC5F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,SAAS,SAAS;AAAA,EAChG;AA+BF;","names":["locale"]}
|
|
@@ -27,7 +27,7 @@ class MakeswiftGraphQLApiClient {
|
|
|
27
27
|
graphqlClient;
|
|
28
28
|
constructor({ endpoint }) {
|
|
29
29
|
this.graphqlClient = new import_client.GraphQLClient(endpoint, {
|
|
30
|
-
"makeswift-runtime-version": "0.28.8
|
|
30
|
+
"makeswift-runtime-version": "0.28.8"
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
async createTableRecord(tableId, columns) {
|
|
@@ -29,10 +29,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var rest_api_client_exports = {};
|
|
30
30
|
__export(rest_api_client_exports, {
|
|
31
31
|
MakeswiftRestAPIClient: () => MakeswiftRestAPIClient,
|
|
32
|
+
RestApiClientError: () => RestApiClientError,
|
|
32
33
|
failedResponseBody: () => failedResponseBody
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(rest_api_client_exports);
|
|
36
|
+
var import_ky = __toESM(require("ky"));
|
|
35
37
|
var Schema = __toESM(require("./schema"));
|
|
38
|
+
const RetryBackoffConfig = {
|
|
39
|
+
MaxAttempts: 3,
|
|
40
|
+
MaxDelayMs: 5e3
|
|
41
|
+
};
|
|
36
42
|
class MakeswiftRestAPIClient {
|
|
37
43
|
_fetch;
|
|
38
44
|
apiKey;
|
|
@@ -42,7 +48,28 @@ class MakeswiftRestAPIClient {
|
|
|
42
48
|
apiKey,
|
|
43
49
|
apiOrigin
|
|
44
50
|
}) {
|
|
45
|
-
this._fetch =
|
|
51
|
+
this._fetch = import_ky.default.create({
|
|
52
|
+
fetch,
|
|
53
|
+
timeout: false,
|
|
54
|
+
retry: {
|
|
55
|
+
statusCodes: [429],
|
|
56
|
+
limit: RetryBackoffConfig.MaxAttempts,
|
|
57
|
+
backoffLimit: RetryBackoffConfig.MaxDelayMs,
|
|
58
|
+
delay: (attemptCount) => 2 ** (attemptCount - 1) * 1e3,
|
|
59
|
+
jitter: true
|
|
60
|
+
},
|
|
61
|
+
hooks: {
|
|
62
|
+
beforeRetry: [
|
|
63
|
+
async ({ request, error, retryCount }) => {
|
|
64
|
+
console.warn(
|
|
65
|
+
`Request to ${request.url} failed with ${error}. Retrying (${retryCount}/${RetryBackoffConfig.MaxAttempts})`
|
|
66
|
+
);
|
|
67
|
+
if ((0, import_ky.isHTTPError)(error))
|
|
68
|
+
await failedResponseBody(error.response);
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
});
|
|
46
73
|
this.apiKey = apiKey;
|
|
47
74
|
this.apiOrigin = apiOrigin;
|
|
48
75
|
}
|
|
@@ -50,13 +77,12 @@ class MakeswiftRestAPIClient {
|
|
|
50
77
|
const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion);
|
|
51
78
|
if (!response.ok) {
|
|
52
79
|
const failedBody = await failedResponseBody(response);
|
|
53
|
-
if (response.status
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
80
|
+
if (response.status === 404)
|
|
81
|
+
return null;
|
|
82
|
+
throw new RestApiClientError(`Failed to get swatch '${swatchId}'`, response, {
|
|
83
|
+
body: failedBody,
|
|
84
|
+
siteVersion
|
|
85
|
+
});
|
|
60
86
|
}
|
|
61
87
|
const swatch = await response.json();
|
|
62
88
|
return swatch;
|
|
@@ -65,13 +91,12 @@ class MakeswiftRestAPIClient {
|
|
|
65
91
|
const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion);
|
|
66
92
|
if (!response.ok) {
|
|
67
93
|
const failedBody = await failedResponseBody(response);
|
|
68
|
-
if (response.status
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
94
|
+
if (response.status === 404)
|
|
95
|
+
return null;
|
|
96
|
+
throw new RestApiClientError(`Failed to get typography '${typographyId}'`, response, {
|
|
97
|
+
body: failedBody,
|
|
98
|
+
siteVersion
|
|
99
|
+
});
|
|
75
100
|
}
|
|
76
101
|
const typography = await response.json();
|
|
77
102
|
return typography;
|
|
@@ -80,13 +105,12 @@ class MakeswiftRestAPIClient {
|
|
|
80
105
|
const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion);
|
|
81
106
|
if (!response.ok) {
|
|
82
107
|
const failedBody = await failedResponseBody(response);
|
|
83
|
-
if (response.status
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
108
|
+
if (response.status === 404)
|
|
109
|
+
return null;
|
|
110
|
+
throw new RestApiClientError(`Failed to get global element '${globalElementId}'`, response, {
|
|
111
|
+
body: failedBody,
|
|
112
|
+
siteVersion
|
|
113
|
+
});
|
|
90
114
|
}
|
|
91
115
|
const globalElement = await response.json();
|
|
92
116
|
return globalElement;
|
|
@@ -98,14 +122,13 @@ class MakeswiftRestAPIClient {
|
|
|
98
122
|
);
|
|
99
123
|
if (!response.ok) {
|
|
100
124
|
const failedBody = await failedResponseBody(response);
|
|
101
|
-
if (response.status
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return null;
|
|
125
|
+
if (response.status === 404)
|
|
126
|
+
return null;
|
|
127
|
+
throw new RestApiClientError(
|
|
128
|
+
`Failed to get localized global element '${globalElementId}'`,
|
|
129
|
+
response,
|
|
130
|
+
{ body: failedBody, siteVersion, locale }
|
|
131
|
+
);
|
|
109
132
|
}
|
|
110
133
|
const localizedGlobalElement = await response.json();
|
|
111
134
|
return localizedGlobalElement;
|
|
@@ -119,12 +142,14 @@ class MakeswiftRestAPIClient {
|
|
|
119
142
|
url.searchParams.set("locale", locale);
|
|
120
143
|
const response = await this.fetch(url.pathname + url.search, siteVersion);
|
|
121
144
|
if (!response.ok) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
const failedBody = await failedResponseBody(response);
|
|
146
|
+
if (response.status === 404)
|
|
147
|
+
return [];
|
|
148
|
+
throw new RestApiClientError(
|
|
149
|
+
`Failed to get page pathname slice(s) for ${pageIds.join(", ")}`,
|
|
150
|
+
response,
|
|
151
|
+
{ body: failedBody, siteVersion, locale }
|
|
152
|
+
);
|
|
128
153
|
}
|
|
129
154
|
const json = await response.json();
|
|
130
155
|
const pagePathnameSlices = Schema.pagePathnameSlices.parse(json);
|
|
@@ -147,7 +172,7 @@ class MakeswiftRestAPIClient {
|
|
|
147
172
|
const requestHeaders = new Headers({
|
|
148
173
|
"x-api-key": this.apiKey,
|
|
149
174
|
"makeswift-site-api-key": this.apiKey,
|
|
150
|
-
"makeswift-runtime-version": "0.28.8
|
|
175
|
+
"makeswift-runtime-version": "0.28.8"
|
|
151
176
|
});
|
|
152
177
|
if (siteVersion?.token) {
|
|
153
178
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -158,12 +183,17 @@ class MakeswiftRestAPIClient {
|
|
|
158
183
|
requestHeaders.set(key, value);
|
|
159
184
|
});
|
|
160
185
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
186
|
+
try {
|
|
187
|
+
return await this._fetch(requestUrl.toString(), {
|
|
188
|
+
...init,
|
|
189
|
+
headers: requestHeaders,
|
|
190
|
+
...siteVersion != null ? { cache: "no-store" } : {}
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (error instanceof import_ky.HTTPError)
|
|
194
|
+
return error.response;
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
167
197
|
}
|
|
168
198
|
}
|
|
169
199
|
async function failedResponseBody(response) {
|
|
@@ -178,9 +208,21 @@ async function failedResponseBody(response) {
|
|
|
178
208
|
return `Failed to extract response body: ${e}`;
|
|
179
209
|
}
|
|
180
210
|
}
|
|
211
|
+
function responseError(response) {
|
|
212
|
+
return `${response.status} ${response.statusText}`;
|
|
213
|
+
}
|
|
214
|
+
class RestApiClientError extends Error {
|
|
215
|
+
status;
|
|
216
|
+
constructor(message, response, cause) {
|
|
217
|
+
super(`${message}: ${responseError(response)}`, { cause });
|
|
218
|
+
this.name = "RestApiClientError";
|
|
219
|
+
this.status = response.status;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
181
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
223
|
0 && (module.exports = {
|
|
183
224
|
MakeswiftRestAPIClient,
|
|
225
|
+
RestApiClientError,
|
|
184
226
|
failedResponseBody
|
|
185
227
|
});
|
|
186
228
|
//# sourceMappingURL=rest-api-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/rest-api-client.ts"],"sourcesContent":["import {\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\nimport * as Schema from './schema'\n\nexport class MakeswiftRestAPIClient {\n private _fetch: HttpFetch\n\n readonly apiKey: string\n readonly apiOrigin: string\n\n constructor({\n fetch,\n apiKey,\n apiOrigin,\n }: {\n fetch: HttpFetch\n apiKey: string\n apiOrigin: string\n }) {\n this._fetch = fetch\n this.apiKey = apiKey\n this.apiOrigin = apiOrigin\n }\n\n async getSwatch(swatchId: string, siteVersion: SiteVersion | null): Promise<Swatch | null> {\n const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get swatch '${swatchId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const swatch = await response.json()\n\n return swatch\n }\n\n async getTypography(\n typographyId: string,\n siteVersion: SiteVersion | null,\n ): Promise<Typography | null> {\n const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get typography '${typographyId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const typography = await response.json()\n\n return typography\n }\n\n async getGlobalElement(\n globalElementId: string,\n siteVersion: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const globalElement = await response.json()\n\n return globalElement\n }\n\n async getLocalizedGlobalElement(\n globalElementId: string,\n locale: string,\n siteVersion: SiteVersion | null,\n ): Promise<LocalizedGlobalElement | null> {\n const response = await this.fetch(\n `v3/localized-global-elements/${globalElementId}?locale=${locale}`,\n siteVersion,\n )\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get localized global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n locale,\n })\n }\n\n return null\n }\n\n const localizedGlobalElement = await response.json()\n\n return localizedGlobalElement\n }\n\n async getPagePathnameSlices(\n pageIds: string[],\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null },\n ): Promise<(PagePathnameSlice | null)[]> {\n if (pageIds.length === 0) return []\n\n const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin)\n\n pageIds.forEach(id => url.searchParams.append('ids', id))\n if (locale != null) url.searchParams.set('locale', locale)\n\n const response = await this.fetch(url.pathname + url.search, siteVersion)\n\n if (!response.ok) {\n console.error(`Failed to get page pathname slice(s) for ${pageIds.join(', ')}`, {\n response: await failedResponseBody(response),\n siteVersion,\n locale,\n })\n\n return []\n }\n\n const json = await response.json()\n\n const pagePathnameSlices = Schema.pagePathnameSlices.parse(json)\n\n // We're mapping the basePageId to be the id, because we're still using the GraphQL\n // fragment as our APIResource. The id on the APIResource needs to match the pageId\n // so that we can find the corresponding page pathname slice when we call getPagePathnameSlice(pageId).\n // TODO: Update this once we move away from the GraphQL fragments.\n return pagePathnameSlices.map(pagePathnameSlice => {\n if (pagePathnameSlice == null) return null\n\n return {\n ...pagePathnameSlice,\n id: pagePathnameSlice.basePageId,\n localizedPathname: pagePathnameSlice.localizedPathname ?? null,\n }\n })\n }\n\n async getPagePathnameSlice(\n pageId: string,\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null } = {},\n ): Promise<PagePathnameSlice | null> {\n const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale })\n\n return pagePathnameSlices.at(0) ?? null\n }\n\n protected async fetch(\n path: string,\n siteVersion: SiteVersion | null,\n init?: RequestInit,\n ): Promise<Response> {\n const requestUrl = new URL(path, this.apiOrigin)\n\n const requestHeaders = new Headers({\n 'x-api-key': this.apiKey,\n 'makeswift-site-api-key': this.apiKey,\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n\n if (siteVersion?.token) {\n requestUrl.searchParams.set('version', siteVersion.version)\n requestHeaders.set('makeswift-preview-token', siteVersion.token)\n }\n\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => {\n requestHeaders.set(key, value)\n })\n }\n\n const response = await this._fetch(requestUrl.toString(), {\n ...init,\n headers: requestHeaders,\n ...(siteVersion != null ? { cache: 'no-store' } : {}),\n })\n\n return response\n }\n}\n\n// This function attempts to consume the response body of a failed response, and\n// returns either the parsed JSON or raw text. This is useful for logging more\n// detailed error information when an API request fails.\n//\n// Cloudflare Worker Note: The Cloudflare Worker runtime has automatic deadlock\n// prevention (in the form of auto-cancelling responses) that triggers when too\n// many response bodies are unconsumed. This applies for error responses as\n// well. As such, in this client we use this function to consume the response\n// body whenever the request fails, even if we don't end up logging the body\n// itself, to avoid hitting the deadlock prevention.\nexport async function failedResponseBody(response: Response): Promise<unknown> {\n try {\n const text = await response.text()\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n } catch (e) {\n return `Failed to extract response body: ${e}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,aAAwB;AAEjB,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EAEC;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,UAAU,UAAkB,aAAyD;AACzF,UAAM,WAAW,MAAM,KAAK,MAAM,eAAe,QAAQ,IAAI,WAAW;AAExE,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,aAAa,MAAM,mBAAmB,QAAQ;AACpD,UAAI,SAAS,WAAW,KAAK;AAC3B,gBAAQ,MAAM,yBAAyB,QAAQ,KAAK;AAAA,UAClD,UAAU;AAAA,UACV;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,MAAM,SAAS,KAAK;AAEnC,WAAO;AAAA,EACT;AAAA,EA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Aa,IAAI,WAAW,YAAY,OAAO;AAC1D,qBAAe,IAAI,2BAA2B,YAAY,KAAK;AAAA,IACjE;AAEA,QAAI,MAAM,SAAS;AACjB,UAAI,QAAQ,KAAK,OAAO,EAAE,QAAQ,CAAC,OAAO,QAAQ;AAChD,uBAAe,IAAI,KAAK,KAAK;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,WAAW,SAAS,GAAG;AAAA,MACxD,GAAG;AAAA,MACH,SAAS;AAAA,MACT,GAAI,eAAe,OAAO,EAAE,OAAO,WAAW,IAAI,CAAC;AAAA,IACrD,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAYA,eAAsB,mBAAmB,UAAsC;AAC7E,MAAI;AACF,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AACV,WAAO,oCAAoC,CAAC;AAAA,EAC9C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/rest-api-client.ts"],"sourcesContent":["import ky, { HTTPError, isHTTPError, type KyInstance } from 'ky'\n\nimport {\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\nimport * as Schema from './schema'\n\nconst RetryBackoffConfig = {\n MaxAttempts: 3,\n MaxDelayMs: 5_000,\n}\n\nexport class MakeswiftRestAPIClient {\n private _fetch: KyInstance\n\n readonly apiKey: string\n readonly apiOrigin: string\n\n constructor({\n fetch,\n apiKey,\n apiOrigin,\n }: {\n fetch: HttpFetch\n apiKey: string\n apiOrigin: string\n }) {\n this._fetch = ky.create({\n fetch,\n timeout: false,\n retry: {\n statusCodes: [429],\n limit: RetryBackoffConfig.MaxAttempts,\n backoffLimit: RetryBackoffConfig.MaxDelayMs,\n delay: attemptCount => 2 ** (attemptCount - 1) * 1000,\n jitter: true,\n },\n hooks: {\n beforeRetry: [\n async ({ request, error, retryCount }) => {\n console.warn(\n `Request to ${request.url} failed with ${error}. Retrying (${retryCount}/${RetryBackoffConfig.MaxAttempts})`,\n )\n // Drain the response body before retrying so we don't leak unconsumed\n // response bodies (see the comment on `failedResponseBody` below).\n if (isHTTPError(error)) await failedResponseBody(error.response)\n },\n ],\n },\n })\n\n this.apiKey = apiKey\n this.apiOrigin = apiOrigin\n }\n\n async getSwatch(swatchId: string, siteVersion: SiteVersion | null): Promise<Swatch | null> {\n const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status === 404) return null\n\n throw new RestApiClientError(`Failed to get swatch '${swatchId}'`, response, {\n body: failedBody,\n siteVersion,\n })\n }\n\n const swatch = await response.json()\n\n return swatch\n }\n\n async getTypography(\n typographyId: string,\n siteVersion: SiteVersion | null,\n ): Promise<Typography | null> {\n const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status === 404) return null\n\n throw new RestApiClientError(`Failed to get typography '${typographyId}'`, response, {\n body: failedBody,\n siteVersion,\n })\n }\n\n const typography = await response.json()\n\n return typography\n }\n\n async getGlobalElement(\n globalElementId: string,\n siteVersion: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status === 404) return null\n\n throw new RestApiClientError(`Failed to get global element '${globalElementId}'`, response, {\n body: failedBody,\n siteVersion,\n })\n }\n\n const globalElement = await response.json()\n\n return globalElement\n }\n\n async getLocalizedGlobalElement(\n globalElementId: string,\n locale: string,\n siteVersion: SiteVersion | null,\n ): Promise<LocalizedGlobalElement | null> {\n const response = await this.fetch(\n `v3/localized-global-elements/${globalElementId}?locale=${locale}`,\n siteVersion,\n )\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status === 404) return null\n\n throw new RestApiClientError(\n `Failed to get localized global element '${globalElementId}'`,\n response,\n { body: failedBody, siteVersion, locale },\n )\n }\n\n const localizedGlobalElement = await response.json()\n\n return localizedGlobalElement\n }\n\n async getPagePathnameSlices(\n pageIds: string[],\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null },\n ): Promise<(PagePathnameSlice | null)[]> {\n if (pageIds.length === 0) return []\n\n const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin)\n\n pageIds.forEach(id => url.searchParams.append('ids', id))\n if (locale != null) url.searchParams.set('locale', locale)\n\n const response = await this.fetch(url.pathname + url.search, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status === 404) return []\n\n throw new RestApiClientError(\n `Failed to get page pathname slice(s) for ${pageIds.join(', ')}`,\n response,\n { body: failedBody, siteVersion, locale },\n )\n }\n\n const json = await response.json()\n\n const pagePathnameSlices = Schema.pagePathnameSlices.parse(json)\n\n // We're mapping the basePageId to be the id, because we're still using the GraphQL\n // fragment as our APIResource. The id on the APIResource needs to match the pageId\n // so that we can find the corresponding page pathname slice when we call getPagePathnameSlice(pageId).\n // TODO: Update this once we move away from the GraphQL fragments.\n return pagePathnameSlices.map(pagePathnameSlice => {\n if (pagePathnameSlice == null) return null\n\n return {\n ...pagePathnameSlice,\n id: pagePathnameSlice.basePageId,\n localizedPathname: pagePathnameSlice.localizedPathname ?? null,\n }\n })\n }\n\n async getPagePathnameSlice(\n pageId: string,\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null } = {},\n ): Promise<PagePathnameSlice | null> {\n const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale })\n\n return pagePathnameSlices.at(0) ?? null\n }\n\n protected async fetch(\n path: string,\n siteVersion: SiteVersion | null,\n init?: RequestInit,\n ): Promise<Response> {\n const requestUrl = new URL(path, this.apiOrigin)\n\n const requestHeaders = new Headers({\n 'x-api-key': this.apiKey,\n 'makeswift-site-api-key': this.apiKey,\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n\n if (siteVersion?.token) {\n requestUrl.searchParams.set('version', siteVersion.version)\n requestHeaders.set('makeswift-preview-token', siteVersion.token)\n }\n\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => {\n requestHeaders.set(key, value)\n })\n }\n\n try {\n return await this._fetch(requestUrl.toString(), {\n ...init,\n headers: requestHeaders,\n ...(siteVersion != null ? { cache: 'no-store' } : {}),\n })\n } catch (error) {\n if (error instanceof HTTPError) return error.response\n throw error\n }\n }\n}\n\n// This function attempts to consume the response body of a failed response, and\n// returns either the parsed JSON or raw text. This is useful for logging more\n// detailed error information when an API request fails.\n//\n// Cloudflare Worker Note: The Cloudflare Worker runtime has automatic deadlock\n// prevention (in the form of auto-cancelling responses) that triggers when too\n// many response bodies are unconsumed. This applies for error responses as\n// well. As such, in this client we use this function to consume the response\n// body whenever the request fails, even if we don't end up logging the body\n// itself, to avoid hitting the deadlock prevention.\nexport async function failedResponseBody(response: Response): Promise<unknown> {\n try {\n const text = await response.text()\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n } catch (e) {\n return `Failed to extract response body: ${e}`\n }\n}\n\nfunction responseError(response: Response): string {\n return `${response.status} ${response.statusText}`\n}\n\nexport class RestApiClientError extends Error {\n readonly status: number\n\n constructor(message: string, response: Response, cause: Record<string, unknown>) {\n super(`${message}: ${responseError(response)}`, { cause })\n\n this.name = 'RestApiClientError'\n this.status = response.status\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4D;AAY5D,aAAwB;AAExB,MAAM,qBAAqB;AAAA,EACzB,aAAa;AAAA,EACb,YAAY;AACd;AAEO,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EAEC;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV;AAAA,I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K,KAAK;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,QAAI;AACF,aAAO,MAAM,KAAK,OAAO,WAAW,SAAS,GAAG;AAAA,QAC9C,GAAG;AAAA,QACH,SAAS;AAAA,QACT,GAAI,eAAe,OAAO,EAAE,OAAO,WAAW,IAAI,CAAC;AAAA,MACrD,CAAC;AAAA,IACH,SAAS,OAAO;AACd,UAAI,iBAAiB;AAAW,eAAO,MAAM;AAC7C,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAYA,eAAsB,mBAAmB,UAAsC;AAC7E,MAAI;AACF,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AACV,WAAO,oCAAoC,CAAC;AAAA,EAC9C;AACF;AAEA,SAAS,cAAc,UAA4B;AACjD,SAAO,GAAG,SAAS,MAAM,IAAI,SAAS,UAAU;AAClD;AAEO,MAAM,2BAA2B,MAAM;AAAA,EACnC;AAAA,EAET,YAAY,SAAiB,UAAoB,OAAgC;AAC/E,UAAM,GAAG,OAAO,KAAK,cAAc,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;AAEzD,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;","names":["ky"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/types.ts"],"sourcesContent":["import {\n SwatchFragment as Swatch,\n FileFragment as File,\n TypographyFragment as Typography,\n PagePathnameSliceFragment,\n GlobalElementFragment as GlobalElement,\n LocalizedGlobalElementFragment as LocalizedGlobalElement,\n TableFragment as Table,\n SnippetFragment as Snippet,\n PageFragment as Page,\n SiteFragment as Site,\n} from './graphql/generated/types'\n\ntype PagePathnameSlice = PagePathnameSliceFragment & {\n basePageId?: string\n localizedPathname?: string | null\n}\n\nexport type {\n Swatch,\n File,\n Typography,\n PagePathnameSlice,\n GlobalElement,\n LocalizedGlobalElement,\n Table,\n Snippet,\n Page,\n Site,\n}\n\nexport type LocalizableAPIResource = PagePathnameSlice | LocalizedGlobalElement\n\nexport const LocalizableAPIResourceType: {\n [R in LocalizableAPIResource as R['__typename']]: R['__typename']\n} = {\n PagePathnameSlice: 'PagePathnameSlice',\n LocalizedGlobalElement: 'LocalizedGlobalElement',\n}\n\nexport type LocalizableAPIResourceType =\n (typeof LocalizableAPIResourceType)[keyof typeof LocalizableAPIResourceType]\n\nexport type APIResource =\n | LocalizableAPIResource\n | Swatch\n | File\n | Typography\n | GlobalElement\n | Table\n | Snippet\n | Page\n | Site\n\nexport const APIResourceType: { [R in APIResource as R['__typename']]: R['__typename'] } = {\n ...LocalizableAPIResourceType,\n Swatch: 'Swatch',\n File: 'File',\n Typography: 'Typography',\n GlobalElement: 'GlobalElement',\n Table: 'Table',\n Snippet: 'Snippet',\n Page: 'Page',\n Site: 'Site',\n}\n\nexport type APIResourceType = (typeof APIResourceType)[keyof typeof APIResourceType]\n\nexport type APIResourceByType<T extends APIResourceType> = Extract<APIResource, { __typename: T }>\n\nexport type APIResourceLocale<R extends APIResource | APIResourceType> = R extends\n | LocalizableAPIResource\n | LocalizableAPIResourceType\n ? string | null\n : never\n\nexport type HttpFetch = (
|
|
1
|
+
{"version":3,"sources":["../../../src/api/types.ts"],"sourcesContent":["import {\n SwatchFragment as Swatch,\n FileFragment as File,\n TypographyFragment as Typography,\n PagePathnameSliceFragment,\n GlobalElementFragment as GlobalElement,\n LocalizedGlobalElementFragment as LocalizedGlobalElement,\n TableFragment as Table,\n SnippetFragment as Snippet,\n PageFragment as Page,\n SiteFragment as Site,\n} from './graphql/generated/types'\n\ntype PagePathnameSlice = PagePathnameSliceFragment & {\n basePageId?: string\n localizedPathname?: string | null\n}\n\nexport type {\n Swatch,\n File,\n Typography,\n PagePathnameSlice,\n GlobalElement,\n LocalizedGlobalElement,\n Table,\n Snippet,\n Page,\n Site,\n}\n\nexport type LocalizableAPIResource = PagePathnameSlice | LocalizedGlobalElement\n\nexport const LocalizableAPIResourceType: {\n [R in LocalizableAPIResource as R['__typename']]: R['__typename']\n} = {\n PagePathnameSlice: 'PagePathnameSlice',\n LocalizedGlobalElement: 'LocalizedGlobalElement',\n}\n\nexport type LocalizableAPIResourceType =\n (typeof LocalizableAPIResourceType)[keyof typeof LocalizableAPIResourceType]\n\nexport type APIResource =\n | LocalizableAPIResource\n | Swatch\n | File\n | Typography\n | GlobalElement\n | Table\n | Snippet\n | Page\n | Site\n\nexport const APIResourceType: { [R in APIResource as R['__typename']]: R['__typename'] } = {\n ...LocalizableAPIResourceType,\n Swatch: 'Swatch',\n File: 'File',\n Typography: 'Typography',\n GlobalElement: 'GlobalElement',\n Table: 'Table',\n Snippet: 'Snippet',\n Page: 'Page',\n Site: 'Site',\n}\n\nexport type APIResourceType = (typeof APIResourceType)[keyof typeof APIResourceType]\n\nexport type APIResourceByType<T extends APIResourceType> = Extract<APIResource, { __typename: T }>\n\nexport type APIResourceLocale<R extends APIResource | APIResourceType> = R extends\n | LocalizableAPIResource\n | LocalizableAPIResourceType\n ? string | null\n : never\n\nexport type HttpFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCO,MAAM,6BAET;AAAA,EACF,mBAAmB;AAAA,EACnB,wBAAwB;AAC1B;AAgBO,MAAM,kBAA8E;AAAA,EACzF,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
|
|
@@ -28,7 +28,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
28
28
|
return import_request_response.ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
29
29
|
}
|
|
30
30
|
return import_request_response.ApiResponse.json({
|
|
31
|
-
version: "0.28.8
|
|
31
|
+
version: "0.28.8",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
|
@@ -23,12 +23,12 @@ __export(host_to_builder_actions_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(host_to_builder_actions_exports);
|
|
25
25
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
26
|
-
var
|
|
27
|
-
var
|
|
26
|
+
var import_read_only_action_types = require("../state/actions/internal/read-only-action-types");
|
|
27
|
+
var import_action_types = require("../state/builder-api/action-types");
|
|
28
28
|
const HostToBuilderActionTypes = {
|
|
29
|
-
...
|
|
30
|
-
REGISTER_COMPONENT:
|
|
31
|
-
UNREGISTER_COMPONENT:
|
|
29
|
+
...import_action_types.BuilderActionTypes,
|
|
30
|
+
REGISTER_COMPONENT: import_read_only_action_types.ReadOnlyActionTypes.REGISTER_COMPONENT,
|
|
31
|
+
UNREGISTER_COMPONENT: import_read_only_action_types.ReadOnlyActionTypes.UNREGISTER_COMPONENT
|
|
32
32
|
};
|
|
33
33
|
function isHostToBuilderAction(action) {
|
|
34
34
|
return (0, import_toolkit.isAction)(action) && Object.hasOwn(HostToBuilderActionTypes, action.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/builder/host-to-builder-actions.ts"],"sourcesContent":["import { isAction } from '@reduxjs/toolkit'\n\n// in the past, we reused the same action type for registering components both internally\n// and in the builder; they have been since split into two separate action types,\n// REGISTER_COMPONENT and REGISTER_BUILDER_COMPONENT, but we still have to expose what\n// are now internal actions to the builder for backward compatibility with the older runtimes\nimport {\n type RegisterComponentAction,\n type UnregisterComponentAction,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/builder/host-to-builder-actions.ts"],"sourcesContent":["import { isAction } from '@reduxjs/toolkit'\n\n// in the past, we reused the same action type for registering components both internally\n// and in the builder; they have been since split into two separate action types,\n// REGISTER_COMPONENT and REGISTER_BUILDER_COMPONENT, but we still have to expose what\n// are now internal actions to the builder for backward compatibility with the older runtimes\nimport { ReadOnlyActionTypes } from '../state/actions/internal/read-only-action-types'\nimport {\n type RegisterComponentAction,\n type UnregisterComponentAction,\n} from '../state/actions/internal/read-only-actions'\n\nimport { BuilderActionTypes } from '../state/builder-api/action-types'\nimport { type BuilderAction } from '../state/builder-api/actions'\n\nexport const HostToBuilderActionTypes = {\n ...BuilderActionTypes,\n REGISTER_COMPONENT: ReadOnlyActionTypes.REGISTER_COMPONENT,\n UNREGISTER_COMPONENT: ReadOnlyActionTypes.UNREGISTER_COMPONENT,\n} as const\n\nexport type HostToBuilderAction =\n | BuilderAction\n | RegisterComponentAction\n | UnregisterComponentAction\n\nexport function isHostToBuilderAction(action: unknown): action is HostToBuilderAction {\n return isAction(action) && Object.hasOwn(HostToBuilderActionTypes, action.type)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyB;AAMzB,oCAAoC;AAMpC,0BAAmC;AAG5B,MAAM,2BAA2B;AAAA,EACtC,GAAG;AAAA,EACH,oBAAoB,kDAAoB;AAAA,EACxC,sBAAsB,kDAAoB;AAC5C;AAOO,SAAS,sBAAsB,QAAgD;AACpF,aAAO,yBAAS,MAAM,KAAK,OAAO,OAAO,0BAA0B,OAAO,IAAI;AAChF;","names":[]}
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -78,12 +78,12 @@ Received "${apiKey}" instead.`
|
|
|
78
78
|
const queryParams = getPagesQueryParams(params);
|
|
79
79
|
const response = await this.fetch(`v5/pages?${queryParams.toString()}`, siteVersion);
|
|
80
80
|
if (!response.ok) {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const body = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
82
|
+
throw new import_rest_api_client.RestApiClientError("Failed to get pages", response, {
|
|
83
|
+
body,
|
|
83
84
|
siteVersion,
|
|
84
85
|
params
|
|
85
86
|
});
|
|
86
|
-
throw new Error(`Failed to get pages: ${responseError(response)}`);
|
|
87
87
|
}
|
|
88
88
|
const result = await response.json();
|
|
89
89
|
const parsedResponse = Schema.getPagesResult.safeParse(result);
|
|
@@ -104,12 +104,11 @@ Received "${apiKey}" instead.`
|
|
|
104
104
|
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
105
105
|
if (response.status === 404)
|
|
106
106
|
return null;
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
throw new import_rest_api_client.RestApiClientError(`Failed to get page snapshot for '${pathname}'`, response, {
|
|
108
|
+
body: failedBody,
|
|
109
109
|
siteVersion,
|
|
110
110
|
locale
|
|
111
111
|
});
|
|
112
|
-
throw new Error(`Failed to get page snapshot for '${pathname}': ${responseError(response)}`);
|
|
113
112
|
}
|
|
114
113
|
const json = await response.json();
|
|
115
114
|
return Schema.getPageResult.parse(json);
|
|
@@ -123,11 +122,14 @@ Received "${apiKey}" instead.`
|
|
|
123
122
|
});
|
|
124
123
|
const response = await this.fetch(url.pathname + url.search, siteVersion);
|
|
125
124
|
if (!response.ok) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
126
|
+
if (response.status === 404)
|
|
127
|
+
return [];
|
|
128
|
+
throw new import_rest_api_client.RestApiClientError(
|
|
129
|
+
`Failed to get typographies for [${typographyIds.join(", ")}]`,
|
|
130
|
+
response,
|
|
131
|
+
{ body: failedBody, siteVersion }
|
|
132
|
+
);
|
|
131
133
|
}
|
|
132
134
|
const body = await response.json();
|
|
133
135
|
return body;
|
|
@@ -141,11 +143,13 @@ Received "${apiKey}" instead.`
|
|
|
141
143
|
});
|
|
142
144
|
const response = await this.fetch(url.pathname + url.search, siteVersion);
|
|
143
145
|
if (!response.ok) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
147
|
+
if (response.status === 404)
|
|
148
|
+
return [];
|
|
149
|
+
throw new import_rest_api_client.RestApiClientError(`Failed to get swatches for ${ids.join(", ")}`, response, {
|
|
150
|
+
body: failedBody,
|
|
146
151
|
siteVersion
|
|
147
152
|
});
|
|
148
|
-
return [];
|
|
149
153
|
}
|
|
150
154
|
return await response.json();
|
|
151
155
|
}
|
|
@@ -164,12 +168,11 @@ Received "${apiKey}" instead.`
|
|
|
164
168
|
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
165
169
|
if (response.status === 404)
|
|
166
170
|
return ids.map(() => null);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
locale
|
|
171
|
-
|
|
172
|
-
throw new Error(`Failed to get element trees: ${responseError(response)}`);
|
|
171
|
+
throw new import_rest_api_client.RestApiClientError(
|
|
172
|
+
`Failed to get element trees for [${ids.join(", ")}]`,
|
|
173
|
+
response,
|
|
174
|
+
{ body: failedBody, siteVersion, locale }
|
|
175
|
+
);
|
|
173
176
|
}
|
|
174
177
|
const responseBody = await response.json();
|
|
175
178
|
return responseBody.map(
|
|
@@ -517,12 +520,11 @@ Received "${apiKey}" instead.`
|
|
|
517
520
|
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
518
521
|
if (response.status === 404)
|
|
519
522
|
return null;
|
|
520
|
-
|
|
521
|
-
|
|
523
|
+
throw new import_rest_api_client.RestApiClientError(`Failed to get page snapshot for '${pathname}'`, response, {
|
|
524
|
+
body: failedBody,
|
|
522
525
|
siteVersion,
|
|
523
526
|
locale
|
|
524
527
|
});
|
|
525
|
-
throw new Error(`Failed to get page snapshot for '${pathname}': ${responseError(response)}`);
|
|
526
528
|
}
|
|
527
529
|
const document = await response.json();
|
|
528
530
|
const baseLocalizedPage = document.localizedPages.find(({ parentId }) => parentId == null);
|
|
@@ -556,12 +558,11 @@ Received "${apiKey}" instead.`
|
|
|
556
558
|
if (response.status === 404) {
|
|
557
559
|
return null;
|
|
558
560
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
+
throw new import_rest_api_client.RestApiClientError(`Failed to get component snapshot for '${id}'`, response, {
|
|
562
|
+
body: failedBody,
|
|
561
563
|
siteVersion,
|
|
562
564
|
locale
|
|
563
565
|
});
|
|
564
|
-
throw new Error(`Failed to get component snapshot for '${id}': ${responseError(response)}`);
|
|
565
566
|
}
|
|
566
567
|
const responseBody = await response.json();
|
|
567
568
|
const parsed = Schema.componentDocumentResponse.parse(responseBody);
|
|
@@ -684,14 +685,9 @@ Received "${apiKey}" instead.`
|
|
|
684
685
|
return (0, import_merge.mergeTranslatedContent)(this.getElementDescriptors(), elementTree, translatedData);
|
|
685
686
|
}
|
|
686
687
|
async readPreviewToken(token) {
|
|
687
|
-
const response = await fetch(
|
|
688
|
+
const response = await this.fetch("v1/preview-tokens/reads", null, {
|
|
688
689
|
method: "POST",
|
|
689
|
-
headers: {
|
|
690
|
-
"x-api-key": this.apiKey,
|
|
691
|
-
"makeswift-site-api-key": this.apiKey,
|
|
692
|
-
"makeswift-runtime-version": "0.28.8-canary.9",
|
|
693
|
-
"content-type": "application/json"
|
|
694
|
-
},
|
|
690
|
+
headers: { "content-type": "application/json" },
|
|
695
691
|
body: JSON.stringify({ token }),
|
|
696
692
|
cache: "no-store"
|
|
697
693
|
});
|
|
@@ -701,12 +697,13 @@ Received "${apiKey}" instead.`
|
|
|
701
697
|
console.error(`Preview token is invalid or expired`, {
|
|
702
698
|
response: failedBody
|
|
703
699
|
});
|
|
704
|
-
|
|
705
|
-
console.error(`Failed to verify preview token`, {
|
|
706
|
-
response: failedBody
|
|
707
|
-
});
|
|
700
|
+
return null;
|
|
708
701
|
}
|
|
709
|
-
|
|
702
|
+
if (response.status === 404)
|
|
703
|
+
return null;
|
|
704
|
+
throw new import_rest_api_client.RestApiClientError(`Failed to verify preview token`, response, {
|
|
705
|
+
body: failedBody
|
|
706
|
+
});
|
|
710
707
|
}
|
|
711
708
|
const json = await response.json();
|
|
712
709
|
const parsed = Schema.previewTokenPayload.safeParse(json);
|
|
@@ -720,11 +717,13 @@ Received "${apiKey}" instead.`
|
|
|
720
717
|
async unstable_getFonts(siteVersion = null) {
|
|
721
718
|
const response = await this.fetch("v1_unstable/fonts", siteVersion);
|
|
722
719
|
if (!response.ok) {
|
|
723
|
-
|
|
724
|
-
|
|
720
|
+
const failedBody = await (0, import_rest_api_client.failedResponseBody)(response);
|
|
721
|
+
if (response.status === 404)
|
|
722
|
+
return null;
|
|
723
|
+
throw new import_rest_api_client.RestApiClientError("Failed to fetch fonts", response, {
|
|
724
|
+
body: failedBody,
|
|
725
725
|
siteVersion
|
|
726
726
|
});
|
|
727
|
-
return null;
|
|
728
727
|
}
|
|
729
728
|
const json = await response.json();
|
|
730
729
|
const parsed = Schema.fonts.safeParse(json);
|
|
@@ -767,9 +766,6 @@ function getPagesQueryParams({
|
|
|
767
766
|
params.set("locale", locale);
|
|
768
767
|
return params;
|
|
769
768
|
}
|
|
770
|
-
function responseError(response) {
|
|
771
|
-
return `${response.status} ${response.statusText}`;
|
|
772
|
-
}
|
|
773
769
|
// Annotate the CommonJS export names for ESM import in node:
|
|
774
770
|
0 && (module.exports = {
|
|
775
771
|
MakeswiftClient,
|