Git Product home page Git Product logo

storyblok-js's Introduction

Storyblok Logo

@storyblok/js

The JavaScript SDK you need to interact with Storyblok API and enable the Real-time Visual Editing Experience.


Storyblok JS npm

Follow @Storyblok Follow @Storyblok

πŸš€ Usage

If you are first-time user of the Storyblok, read the Getting Started guide to get a project ready in less than 5 minutes.

Installation

Install @storyblok/js:

npm install @storyblok/js
// yarn add @storyblok/js

⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like isomorphic-fetch. More info on storyblok-js-client docs.

From a CDN

Install the file from the CDN:

<script src="https://unpkg.com/@storyblok/js"></script>

Initialization

Register the plugin on your application and add the access token of your Storyblok space. You can also add the apiPlugin in case that you want to use the Storyblok API Client:

import { storyblokInit, apiPlugin } from "@storyblok/js";

const { storyblokApi } = storyblokInit({
  accessToken: "YOUR_ACCESS_TOKEN",
  use: [apiPlugin],
});

That's it! All the features are enabled for you: the Api Client for interacting with Storyblok CDN API, and Storyblok Bridge for real-time visual editing experience.

You can enable/disable some of these features if you don't need them, so you save some KB. Please read the "Features and API" section

Region parameter

Possible values:

  • eu (default): For spaces created in the EU
  • us: For spaces created in the US
  • ap: For spaces created in Australia
  • ca: For spaces created in Canada
  • cn: For spaces created in China

Full example for a space created in the US:

import { storyblokInit, apiPlugin } from "@storyblok/js";

const { storyblokApi } = storyblokInit({
  accessToken: "YOUR_ACCESS_TOKEN",
  use: [apiPlugin],
  apiOptions: {
    region: "us",
  },
});

Note: For spaces created in the United States or China, the region parameter must be specified.

Getting Started

@storyblok/js does three actions when you initialize it:

  • Provides a storyblokApi object in your app, which is an instance of storyblok-js-client.
  • Loads Storyblok Bridge for real-time visual updates.
  • Provides a storyblokEditable function to link editable components to the Storyblok Visual Editor.

1. Fetching Content

Inject storyblokApi:

import { storyblokInit, apiPlugin } from "@storyblok/js";

const { storyblokApi } = storyblokInit({
  accessToken: "YOUR_ACCESS_TOKEN",
  use: [apiPlugin],
});

const { data } = await storyblokApi.get("cdn/stories", { version: "draft" });

Note: if you don't use apiPlugin, you can use your prefered method or function to fetch your data.

2. Listen to Storyblok Visual Editor events

Use useStoryblokBridge or registerStoryblokBridge to get the new story every time is triggered a change event from the Visual Editor. You need to pass the story id as first param, and a callback function as second param to update the new story:

import { storyblokInit, apiPlugin, useStoryblokBridge } from "@storyblok/js";

const { storyblokApi } = storyblokInit({
  accessToken: "YOUR_ACCESS_TOKEN",
  use: [apiPlugin],
});

const { data } = await storyblokApi.get("cdn/stories", { version: "draft" });

const story = data ? data.story : null;

useStoryblokBridge(story.id, (story) => (state.story = story));

You can pass Bridge options as a third parameter as well:

useStoryblokBridge(story.id, (story) => (state.story = story), {
  resolveRelations: ["Article.author"],
  resolveLinks: "url"
});

3. Link your components to Storyblok Visual Editor

To link your app and Storyblok components together will depend on the framework you are using. But, in the end, you must add the data-blok-c and data-blok-uid attributes, and the storyblok__outline class.

We provide you a storyblokEditable function to make that easier. As an example, you can check in @storyblok/vue how we use a v-editable directive for that:

import { storyblokEditable } from "@storyblok/js";

const vEditableDirective = {
  bind(el, binding) {
    if (binding.value) {
      const options = storyblokEditable(binding.value);
      el.setAttribute("data-blok-c", options["data-blok-c"]);
      el.setAttribute("data-blok-uid", options["data-blok-uid"]);
      el.classList.add("storyblok__outline");
    }
  },
};

At this point, you'll have your app connected to Storyblok with the real-time editing experience fully enabled.

Features and API

You can choose the features to use when you initialize the plugin. In that way, you can improve Web Performance by optimizing your page load and save some bytes.

Storyblok API

You can use an apiOptions object. This is passed down to the (storyblok-js-client config object](https://github.com/storyblok/storyblok-js-client#class-storyblok):

const { storyblokApi } = storyblokInit({
  accessToken: "YOUR_ACCESS_TOKEN",
  apiOptions: {
    // storyblok-js-client config object
    cache: { type: "memory" },
  },
  use: [apiPlugin],
});

If you prefer to use your own fetch method, just remove the apiPlugin and storyblok-js-client won't be added to your application.

storyblokInit({});

Storyblok Bridge

You can conditionally load it by using the bridge option. Very useful if you want to disable it in production:

const { storyblokApi } = storyblokInit({
  bridge: process.env.NODE_ENV !== "production",
});

If you don't use useStoryblokBridge or registerStoryblokBridge, you have still access to the raw window.StoryblokBridge:

const sbBridge = new window.StoryblokBridge(options);

sbBridge.on(["input", "published", "change"], (event) => {
  // ...
});

Rendering Rich Text

You can easily render rich text by using the renderRichText function that comes with @storyblok/js:

import { renderRichText } from "@storyblok/js";

const renderedRichText = renderRichText(blok.richtext);

You can set a custom Schema and component resolver globally at init time by using the richText init option:

import { RichTextSchema, storyblokInit } from "@storyblok/js";
import cloneDeep from "clone-deep";

const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
// ... and edit the nodes and marks, or add your own.
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js

storyblokInit({
  accessToken: "<your-token>",
  richText: {
    schema: mySchema,
    resolver: (component, blok) => {
      switch (component) {
        case "my-custom-component":
          return `<div class="my-component-class">${blok.text}</div>`;
        default:
          return "Resolver not defined";
      }
    },
  },
});

You can also set a custom Schema and component resolver only once by passing the options as the second parameter to renderRichText function:

import { renderRichText } from "@storyblok/js";

renderRichText(blok.richTextField, {
  schema: mySchema,
  resolver: (component, blok) => {
    switch (component) {
      case "my-custom-component":
        return `<div class="my-component-class">${blok.text}</div>`;
        break;
      default:
        return `Component ${component} not found`;
    }
  },
});

The Storyblok JavaScript SDK Ecosystem

A visual representation of the Storyblok JavaScript SDK Ecosystem

πŸ”— Related Links

  • Storyblok Technology Hub: Storyblok integrates with every framework so that you are free to choose the best fit for your project. We prepared the technology hub so that you can find selected beginner tutorials, videos, boilerplates, and even cheatsheets all in one place.
  • Getting Started: Get a project ready in less than 5 minutes.
  • Storyblok CLI: A simple CLI for scaffolding Storyblok projects and fieldtypes.

ℹ️ More Resources

Support

Contributing

Please see our contributing guidelines and our code of conduct. This project use semantic-release for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check this question about it in semantic-release FAQ

storyblok-js's People

Contributors

alexjoverm avatar baheya avatar breningham avatar christianzoppi avatar dawntraoz avatar dependabot[bot] avatar edwardz8 avatar fgiuliani avatar github-actions[bot] avatar imabp avatar jdawber avatar jpkha avatar manuelschroederdev avatar plumber-dhaval avatar schabibi1 avatar tricki avatar ts-storyblok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storyblok-js's Issues

'Header is not defined error' when using Storyblok API client from version 2.1.0 in AWS lambda


I observe an error when I create a AWS Lambda function which fetches stories data from a storyblok space using Storyblok API Client. This lambda is triggered using an API on AWS API Gateway. I receive the error "ReferenceError: Headers is not defined" (shown in the screenshot below).
This error is observed only when i use "@storyblok/js" version 2.1.0. When i downgrade the library version to 1.8.5, i don't see this error.

Expected Behavior

Should be able to fetch the stories from the API in the lambda function.

Current Behavior

I receive the below error
image

The lambda Handler code is as below

image

image

Error in SbBlokData definition

I tried to update @storyblok/vue from 6.0.0 to 6.1.0 and the project could not build.
Upgrading from TypeScript 4.6.2 to latest 4.7.4 did not affect the output.
Unfortunately TypeScript errors are not my thing. I will leave it for you to understand.

node_modules/@storyblok/js/dist/types/types.d.ts:15:5 - error TS2411: Property '_editable' of type 'string | undefined' is not assignable to 'string' index type 'SbBlokKeyDataTypes'.

15     [index: string]: SbBlokKeyDataTypes;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@storyblok/vue/dist/StoryblokComponent.vue.d.ts:48:27 - error TS2307: Cannot find module './StoryblokComponent.vue.__VLS_template' or its corresponding type declarations.

48     $slots: typeof import('./StoryblokComponent.vue.__VLS_template').default;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Process is not defined

Describe the issue you're facing

After updating to 2.2.3 process.env is not defined. Why do we need this in our project.
Sure thing you'll need it in cypress, but that should be a different config for your e2e

We had to inject this Polyfill:

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).process = {
	env: { DEBUG: undefined },
};

Reproduction

none

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 26.89 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.1/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v18.12.1/bin/npm
    pnpm: 8.3.1 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 115.0.5790.114
    Safari: 16.4

Used Package Manager

npm

Error logs (Optional)

No response

Validations

preventClicks: true is not working

Doing { preventClicks: true, } in bridge options is not working. It is still following clicks.

Expected Behavior

I expect preventClicks to result in me not going to any of the links i click on a page when in the editor.

Current Behavior

Links to other pages (both internal and external) behaves the same as without the option.

Steps to Reproduce

  1. Use the storyblok bridge in a project
  2. Add options to do { preventClicks: true, }
  3. Open the page in the editor.
  4. Press a link.
  5. Profit.

I have tested this both with a vue project and a nuxt project.

Bridge doesn't work properly for components in Shadow DOM

Building web components with Storyblok isn't fully workable, because the Bridge can't access the shadow DOM.


Expected Behavior

If I call the Storyblok-API with the bridge from inside a Web Component, it should be possible to use the full Bridge-functionality.

Current Behavior

U can take the events and response to that, but u can't click on components inside / access the "Component Menus".

Steps to Reproduce

if u like i can create an example project with the problem shwon, but it's simple:

  1. create web component with storyblok-sdk inside
  2. load web component in shadow dom
  3. try to edit something in the visual editor

In my opinion is the problem, that the script ist loaded into the head, interacts with the body-tag only and it queries through the document, but these are all things, that havent's access to components in shadow DOM (and no, I can't just drop the shadow DOM ^^).
Or do I make any mistakes?! πŸ˜…

Trying to load a slug that doesn't exist causes a UnhandledPromiseRejection

With @storyblok/js 2.0.10-2.0.12, trying to load a story with a slug that doesn't exist, storyblok client causes a UnhandledPromiseRejection.


Expected Behavior

A error with statusCode 404 should be thrown.

Current Behavior

NodeJS crashes with a UnhandledPromiseRejection:

(node:76604) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v18.12.1
error Command failed with exit code 1.

Steps to Reproduce

Minimal reproduction (call with node main.mjs):

import {storyblokInit, apiPlugin} from "@storyblok/js";

const {storyblokApi} = storyblokInit({
    accessToken: "token",
    use: [apiPlugin],
});

storyblokApi.get("non-existing-slug")
    .catch((e) => {
        console.log("Caught error with status: ", e.response.status);
    })

Tried this with node 18.12.1 and 19.5.0.

Workaround

Installing @storyblok/js v2.0.9 fixes this

`adapter` is not a function

I'm attempting to use the js client to access my stories, and I'm running into an issue with how y'all are using axios I think

Stacktrace (Paths partially removed for privacy reasons, ~ is the project root)

TypeError: adapter is not a function
    at dispatchRequest (~/node_modules/axios/lib/core/dispatchRequest.js:58:10)
    at Axios.request (~/node_modules/axios/lib/core/Axios.js:109:15)
    at Axios. [as get] (~/node_modules/axios/lib/core/Axios.js:131:17)
    at Function.wrap2 [as get] (~/node_modules/axios/lib/helpers/bind.js:9:15)
    at h.throttledRequest (~/node_modules/@storyblok/js/dist/storyblok-js.mjs:641:24)
    at a2 (~/node_modules/@storyblok/js/dist/storyblok-js.mjs:340:19)
    at ~/node_modules/@storyblok/js/dist/storyblok-js.mjs:344:76
    at new Promise ()
    at h.l2 [as throttle] (~/node_modules/@storyblok/js/dist/storyblok-js.mjs:343:12)
    at ~/node_modules/@storyblok/js/dist/storyblok-js.mjs:628:29

Code causing this issue (Qwik city application):

export const onGet: RequestHandler<BlogPost> = async ({
	params,
	response,
	platform,
}) => {
	if (params.slug == '') return;

	if (storyblokApi == undefined) {
		storyblokApi = storyblokInit({
			accessToken: platform.STORYBLOK_KEY,
			use: [apiPlugin],
		}).storyblokApi;
	}

	if (!storyblokApi) {
		const re = response.error(500);
		re.message = 'STORYBLOK API UNINITIALISED';
		throw re;
	}
	
	const { data } = await storyblokApi.get(`cdn/stories/${params.slug}`, {
		version: 'published',
	});

	return data.story;
};

Migration to Typescript

Migrating to Typescript will help storyblok-js to support for both the languages, Typescript as well as JavaScript.
This also makes sure, storyblok is easily integrate with most common NextJS projects

We got this idea from PR: #3 and adding @alexjoverm points here:

  • We prefer having the source code in Typescript. In that way, types are autogenerated, better typed, and easier to maintain
  • Types can be more sophisticated/elaborated
  • More steps are needed to integrate Typescript (like a few changes in package.json) and we'd rather keep it in 1 PR since is not much work

Would like to work on this issue.

Error in SbSDKOptions type definition

There is an error in SbSDKOptions type definition that specifies the type of 'use'.

use?: []; means this may be an empty array.

When you pass anything in use TS reports an error:
Type '{}' is not assignable to type 'undefined'.

Here is an example:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAglC8UDeBYAUFKBXAzhA-AFxQDaAuugL4Dc66AxgPYB2OwUYAhgE6cC2CZDTpomrdp0JxESbHmIkuvPmWFogA

If you don't specify any types for plugins you could probably change that to: use?: any[]

SbBlokKeyDataTypes should support optional properties (undefined values)

When adding new fields to existing custom blocks/components I want to be able to define optional properties (may be undefined) for my component types in TS (which are extending from SbBlokData) for backwards compatibility with component instances that are part of stories that have not been modified since editing the block definition since those old versions of the component don't yet contain the new property until they have been edited and saved.

Here's an example of what I want to do:

interface MyComponentBlok extends SbBlokData {
  some_field: string;
  new_field?: string; // <- currently TS doesn't allow this to be optional due to SbBlokKeyDataTypes
}

In the above case if I have just added the new_field to my block definition in Storyblok, the old instances of that block still don't have the property so I know I can't rely on it always being there yet (and I might have a lot of stories that don't contain the new field yet even if they use the block already) and I know I need to check for the existence of it in my code by TS will work against me if I can't declare it as optional.

In practice the API doesn't return those new properties for all cases but only for those cases that have been edited after introducing the new field so I want my TS types to reflect the reality that in some cases the property might not be there but in other cases it will so I would need to declare my new property as optional (e.g. new_field?: string;)

As a fix I suggest to update this line:

export type SbBlokKeyDataTypes = string | number | object | boolean;

to:

export type SbBlokKeyDataTypes = string | number | object | boolean | undefined;

I can do a PR for this if you agree with this change.

storyblok-js-client is not a runtime dependency


Expected Behavior

End users should be able to update storyblok-js-client as per the semver in its package.json (currently ^5.2.5).

Current Behavior

storyblok-js-client is bundled by vite's lib mode by default, so the actual version used by @storyblok/js is the one from the last time storyblok-js-client was updated and @storyblok/js was built. End users need to wait for this to happen and would get unexpected results (for example, thinking an issue would be fixed by upgrading storyblok-js-client)

Solutions to fix it

Either:

  • Mark storyblok-js-client as external in vite's config
  • Make storyblok-js-client part of devDependencies and keep upgrading @storyblok/js every time storyblok-js-client is upgraded

AxiosError: options must be an object, using latest version of axios

Using @storyblok/js with axios v1 does not work.

Expected Behavior

It is expected that @storyblok/js must be compatible with axios v1.

Current Behavior

Steps to Reproduce

  1. Install axios, "yarn add axios".
  2. Execute the project (for example, using NextJS and @storyblok/react), and then yarn dev.
  3. The following error is shown: AxiosError: options must be an object.

The inferred type of 'storyblokApi' cannot be named without a reference to '@storyblok/js/node_modules/storyblok-js-client'.

Describe the issue you're facing

We are using the @storyblok/js library in our NX monorepo and upgrading to the latest NX version v17.0.1 from v15.8.7 has resulted in the following error when trying to build the project:

βœ–  nx run storyblok:build
     Bundling storyblok...
     Error during bundle: Error: libs/storyblok/src/lib/storyblok.ts:3:16 - error TS2742: The inferred type of 'storyblokApi' cannot be named without a reference to '@storyblok/js/node_modules/storyblok-js-client'. This is likely not portable. A type annotation is necessary.
       
       export const { storyblokApi } = storyblokInit({
                        ~~~~~~~~~~~~
       
       Bundle failed: storyblok

We are currently using storyblok/js v1.8.5 and storyblok-js-client v3.3.1, however we have also tried using the latest storyblok/js version v2.3.0

Reproduction

n/a

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.5 Manjaro Linux
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 9.27 GB / 15.29 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.volta/tools/image/node/18.18.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 7.24.2 - ~/Projects/EF/martech-toolkit/node_modules/.bin/npm
    Watchman: 20231013.222836.0 - /usr/bin/watchman
  Browsers:
    Brave Browser: 118.1.59.120

Used Package Manager

npm

Error logs (Optional)

βœ–  nx run storyblok:build
     Bundling storyblok...
     Error during bundle: Error: libs/storyblok/src/lib/storyblok.ts:3:16 - error TS2742: The inferred type of 'storyblokApi' cannot be named without a reference to '@storyblok/js/node_modules/storyblok-js-client'. This is likely not portable. A type annotation is necessary.
       
       export const { storyblokApi } = storyblokInit({
                        ~~~~~~~~~~~~
       
       Bundle failed: storyblok

Validations

Bridge has no way to unbind events

StoryblokBridgeV2 has bridge.on(...) but no bridge.off(...).

This can be a major issue for obvious reasons.
If you're implementing an Event Emitter-like pattern, please allow us to also unsubscribe from events!

I also cannot find the repository for the bridge.js, is it closed source?

Retrieve Multiple Links API returns all links even if version filter is used

Describe the issue you're facing

I got a space with many published and draft stories. Some of the were unpublished and published again.

When I query for the links with the API: https://www.storyblok.com/docs/api/content-delivery/v2#core-resources/links/retrieve-multiple-links I get strange results.

I assumed that if I query for published links then I will get only published links. After running following code I get following results:

Fetched no param: 448
Filtered draft: 322
Filtered published: 126

Fetched published: 448
Filtered draft: 322
Filtered published: 126

Fetched draft: 810
Filtered draft: 684
Filtered publish: 126
const { data: dataNoParam } = await storyblokApi.get('cdn/links/'); 
console.log("Fetched no param:", Object.values(dataNoParam.links).length);
console.log("Filtered draft:", Object.values(dataNoParam.links).filter((link) => !link.published).length);
console.log("Filtered published:", Object.values(dataNoParam.links).filter((link) => link.published).length);

const { data: dataPublished } = await storyblokApi.get('cdn/links/', { version: "published" });
console.log("\nFetched published:", Object.values(dataPublished.links).length);
console.log("Filtered draft:", Object.values(dataPublished.links).filter((link) => !link.published).length);
console.log("Filtered published:", Object.values(dataPublished.links).filter((link) => link.published).length);

const { data: dataDraft } = await storyblokApi.get('cdn/links/', { version: "draft" });
console.log("\nFetched draft:", Object.values(dataDraft.links).length);
console.log("Filtered draft:", Object.values(dataDraft.links).filter((link) => !link.published).length);
console.log("Filtered publish:", Object.values(dataDraft.links).filter((link) => link.published).length);

Why the version without filter gets less than the one with draft filter?
How can I get only published links?

Reproduction

check the description

Steps to reproduce

No response

System Info

Tested on latest: "@storyblok/js": "^2.3.0"

Used Package Manager

npm

Error logs (Optional)

No response

Validations

[Storyblok bridge V2] When listening to "input" events, event payload doesn't return `_editable` key for bloks nested within Rich Text

Expected Behavior

When attaching a handler to the "input" event like this:

const setEntryData = () => {
    // ... set data
}

sbBridgeInstance?.on(
        "input",
        (event: StoryblokEventPayload | undefined) => {
          if (event?.story) {
            setEntryData({
              data: {
                story: event.story,
              },
            });
          }
        }
      );

The content of event.story should include the _editable key for nested bloks within Rich Text Fields.

Current Behavior

  • Bloks within rich text fields do not include the _editable key
  • Bloks that are not nested within rich text fields do include the _editable key

Steps to Reproduce

  • Nest a blok within rich text fields
  • Listen to the StoryblokEventPayload passed to callback for sbBridgeInstance.on("input", (event: StoryblokEventPayload | undefined) => {})
  • You should observe that nested bloks inside Rich text fields are missing the _editable key

Custom properties are not being properly handled for Rich Text Field links

Custom properties provided by Rich Text Field links in Storyblok editor are currently not being added to the rendered tag. After some investigation, I saw that the issue is solved on [email protected] on which this package depends on (check src/schema.ts file). So my idea was to generate a new version of this package with storyblok-js-client bumped to the new version and then update it on @storyblok/react.

Expected Behavior

I'd like to get custom attributes defined in Storyblok editor added to rendered tags.

image

Current Behavior

Screenshot 2023-03-14 at 13 30 58

storyblokInit return is typed as an empty object

Hey guys,
I have an issue with typings :)

The return of the function storyblokInit is typed as an empty object {}

export declare const storyblokInit: (pluginOptions?: SbSDKOptions) => {};

but it should be typed as

export declare const storyblokInit: (pluginOptions?: SbSDKOptions) => { storyblokApi: Storyblok };

Probably type generation from Storyblok class does not go as it should :) Can you please fix it?

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Storyblok Bridge resolveLinks option

Description

Internally, we have created a nuxt server api that re-fetches story data whenever storyblok bridge gives the input, changed or published events. This provides us with fresh data without reloading the page. (We are currently using a custom made setup that leverages storyblok graphql api, hence the need to customly handle bridge updates).
Long story short, our graphql apis are set with resolveLinks: "story", while bridge resolve links as urls.

Suggested solution or improvement

Add a resolveLinks parameter to the storyblokBridge class

Additional context

No response

Validations

Multiple Stories per window, window.reload()

I use this library by way of @storyblok/react and gatsby-source-storyblok. I'm very excited to have low-config support for the Storyblok bridge with the useStoryblokState hook. However, I'm running into an issue with my use case.

I use different stories for different parts of a website layout: one for the site header, one for the site footer, one for each page. This way I can have my fixed layout elements managed in Storyblok. It works great and it's a killer feature or Storyblok in general. Previously I was initializing my own bridge and dispatching story changes to redux. While upgrading gatsby-source-storyblok and finding the useStoryblokState hook, I started to implement it throughout my project so I could ditch my custom bridge implementation and my reliance on Redux for preview state.

However, when I useStoryblokState on more than one story rendered on a page, each Bridge instance thinks it's not on the right page and reloads the page. This doesn't seem to be configurable from gatsby-source-storyblok down.

Are there any considerations for supporting multiple stories per window, or at least a way to configure the bridge event handlers from a higher-level library? I know I can disable the bridge from gatsby-source-storyblok and implement my own, but I'd love to use the internal per-story state implemented by the library. Currently my page just reloads every time I make a change in the editor.

Thanks for this plugin and any insight you can provide!

Cannot add property `accessToken`, object is not extensible

As mentioned in storyblok/storyblok-nuxt#149 , there is an issue with the pluginOptions object in storyblokInit. More specifically, this piece of code:

export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => {
const { bridge, accessToken, use = [], apiOptions = {} } = pluginOptions;
apiOptions.accessToken = apiOptions.accessToken || accessToken;

When trying to use storyblok-nuxt with Nuxt 3 and passing in the apiOptions to the module we get the error: Cannot add property accessToken, object is not extensible. I think somewhere in the plugin pipeline for Nuxt we hit a Object.preventExtensions().

Project is forcing eslint, but is not properly set up for typescript

During commit, an error from eslint is thrown. Causing any commits using a proper git client to be impossible.
image


Expected Behavior

I expect to be able to do proper commits using a git client.

Current Behavior

It errors because of typescript:
image

Steps to Reproduce

  1. Make a commit.
  2. Try to push it via git.
  3. It errors.

Resources:
https://www.reddit.com/r/typescript/comments/q378h9/component_props_error_parsing_error_unexpected/
https://www.appsloveworld.com/reactjs/100/5/eslint-parsing-error-unexpected-token-on-typescript-cast-operator-as
https://frontendfolks.com/posts/parsing-error-unexpected-token-eslint-typescript/53
https://stackoverflow.com/questions/60547153/eslint-parsing-error-unexpected-token-on-typescript-cast-operator-as

[renderRichText] A new line at the beginning without content causes problems

Describe the issue you're facing

A new line at the beginning without content causes renderRichText to return an empty string for all rendered content.
Sometimes it is also desired to insert a blank line at the beginning of the text to increase the spacing. This is no longer possible after the last changes to the lib.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ngu3pb?file=src%2FApp.vue

Steps to reproduce

Add a line at the beginning of your document, just like in the stackblitz reproduction

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm

Used Package Manager

npm

Error logs (Optional)

No response

Validations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.