Skip to content

Commit

Permalink
feat: add better typings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjoverm committed Jun 8, 2022
1 parent 1970450 commit 6bcfc5a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
StoryblokBridgeConfigV2,
StoryblokBridgeV2,
StoryData,
SbInitResult,
} from "./types";

const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
Expand Down Expand Up @@ -52,7 +53,7 @@ export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => {

// Initialize plugins
const options = { bridge, apiOptions };
let result = {};
let result: SbInitResult = {};

use.forEach((pluginFactory: Function) => {
result = { ...result, ...pluginFactory(options) };
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import StoryblokClient, { StoryblokConfig } from "storyblok-js-client";
import { SbSDKOptions } from "../types";
import { SbSDKOptions, SbPluginFactory } from "../types";

export default (options: SbSDKOptions = {}) => {
const apiFactory: SbPluginFactory = (options = {}) => {
const { apiOptions } = options;

if (!apiOptions.accessToken) {
Expand All @@ -14,3 +14,5 @@ export default (options: SbSDKOptions = {}) => {
const storyblokApi = new StoryblokClient(apiOptions);
return { storyblokApi };
};

export default apiFactory;
12 changes: 10 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { StoryblokConfig, StoryblokComponent } from "storyblok-js-client";
import StoryblokClient, {
StoryblokConfig,
StoryblokComponent,
} from "storyblok-js-client";

declare global {
interface Window {
Expand All @@ -7,6 +10,11 @@ declare global {
}
}

export interface SbInitResult {
storyblokApi?: StoryblokClient;
}

export type SbPluginFactory = (options: SbSDKOptions) => any;
export type SbBlokKeyDataTypes = string | number | object;

export interface SbBlokData extends StoryblokComponent<string> {
Expand All @@ -16,7 +24,7 @@ export interface SbBlokData extends StoryblokComponent<string> {
export interface SbSDKOptions {
bridge?: boolean;
accessToken?: string;
use?: [];
use?: [any];
apiOptions?: StoryblokConfig;
}

Expand Down

0 comments on commit 6bcfc5a

Please sign in to comment.