Skip to content

Commit

Permalink
feat: add apiOptions types
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawntraoz committed Feb 3, 2023
1 parent c6f3fd7 commit f5035e6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/src/runtime/composables/useAsyncStoryblok.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
import type { ISbStoryData, ISbError, ISbResult } from '@storyblok/vue';
import type { ISbStoriesParams, StoryblokBridgeConfigV2, ISbStoryData, ISbError, ISbResult } from '@storyblok/vue';
import { useAsyncData, useState, onMounted, createError } from "#imports";

const useAsyncStoryblok = async (
export const useAsyncStoryblok = async (
url: string,
apiOptions = {},
bridgeOptions = {},
apiOptions: ISbStoriesParams = {},
bridgeOptions: StoryblokBridgeConfigV2 = {}
) => {
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
const story = useState<ISbStoryData>(`${uniqueKey}-state`, () => ({} as ISbStoryData));
Expand All @@ -23,10 +23,9 @@ const useAsyncStoryblok = async (

const { data, error } = await useAsyncData<ISbResult, ISbError>(
`${uniqueKey}-asyncdata`,
async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions),
() => storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions),
);

// ToDo: Wait JS sdk 500 to 404 error
if (error.value?.response.status >= 400 && error.value?.response.status < 600) {
throw createError({ statusCode: error.value?.response.status, statusMessage: error.value?.message.message });
}
Expand All @@ -35,6 +34,3 @@ const useAsyncStoryblok = async (

return story;
};

export default useAsyncStoryblok;

0 comments on commit f5035e6

Please sign in to comment.