@storyblok/nuxt 5.0.2 → 5.1.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.
@@ -1,2 +1,2 @@
1
- export default useAsyncStoryblok;
2
- declare function useAsyncStoryblok(url: any, apiOptions?: {}, bridgeOptions?: {}): Promise<any>;
1
+ import type { ISbStoriesParams, StoryblokBridgeConfigV2 } from '@storyblok/vue';
2
+ export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<any>;
@@ -1,28 +1,18 @@
1
1
  import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
2
- import { useAsyncData, useState, onMounted } from "#imports";
3
-
4
- const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
2
+ import { useAsyncData, useState, onMounted, createError } from "#imports";
3
+ export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
5
4
  const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
6
- const story = useState(`${uniqueKey}-state`, () => null);
5
+ const story = useState(`${uniqueKey}-state`, () => ({}));
7
6
  const storyblokApiInstance = useStoryblokApi();
8
-
9
7
  onMounted(() => {
10
8
  if (story.value && story.value.id) {
11
- useStoryblokBridge(
12
- story.value.id,
13
- (evStory) => (story.value = evStory),
14
- bridgeOptions
15
- );
9
+ useStoryblokBridge(story.value.id, (evStory) => story.value = evStory, bridgeOptions);
16
10
  }
17
11
  });
18
-
19
- const { data } = await useAsyncData(
20
- `${uniqueKey}-asyncdata`,
21
- async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
22
- );
23
- story.value = data.value.data.story;
24
-
12
+ const { data, error } = await useAsyncData(`${uniqueKey}-asyncdata`, () => storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions));
13
+ if (error.value?.response.status >= 400 && error.value?.response.status < 600) {
14
+ throw createError({ statusCode: error.value?.response.status, statusMessage: error.value?.message.message });
15
+ }
16
+ story.value = data.value?.data.story;
25
17
  return story;
26
18
  };
27
-
28
- export default useAsyncStoryblok;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "Storyblok Nuxt module",
5
5
  "type": "module",
6
6
  "exports": {