Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

storyblok-js-client

Package Overview
Dependencies
Maintainers
8
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storyblok-js-client - npm Package Compare versions

Comparing version 6.10.5 to 6.10.6

3

dist/types/index.d.ts
import RichTextResolver from './richTextResolver';
import type { ISbConfig, ISbContentMangmntAPI, ISbCustomFetch, ISbResponseData, ISbResult, ISbStories, ISbStoriesParams, ISbStory, ISbStoryParams } from './interfaces';
import type { ISbConfig, ISbContentMangmntAPI, ISbCustomFetch, ISbLinksParams, ISbLinksResult, ISbResponseData, ISbResult, ISbStories, ISbStoriesParams, ISbStory, ISbStoryParams } from './interfaces';
interface ComponentResolverFn {

@@ -39,2 +39,3 @@ (...args: any): any;

private makeRequest;
get(slug: 'cdn/links', params?: ISbLinksParams, fetchOptions?: ISbCustomFetch): Promise<ISbLinksResult>;
get(slug: string, params?: ISbStoriesParams, fetchOptions?: ISbCustomFetch): Promise<ISbResult>;

@@ -41,0 +42,0 @@ getAll(slug: string, params: ISbStoriesParams, entity?: string, fetchOptions?: ISbCustomFetch): Promise<any[]>;

@@ -221,2 +221,5 @@ import type { ResponseFn } from './sbFetch';

}
export interface ISbLinksResult extends ISbResult {
data: ISbLinks;
}
export interface ISbResponse {

@@ -307,3 +310,18 @@ data: any;

is_startpage?: boolean;
path?: string;
real_path?: string;
published_at?: string;
created_at?: string;
updated_at?: string;
}
export interface ISbLinksParams {
starts_with?: string;
version?: 'published' | 'draft';
paginated?: number;
per_page?: number;
page?: number;
sort_by?: string;
include_dates?: 0 | 1;
with_parent?: number;
}
export interface ISbLinks {

@@ -310,0 +328,0 @@ links?: {

{
"name": "storyblok-js-client",
"version": "6.10.5",
"version": "6.10.6",
"packageManager": "pnpm@9.15.0",

@@ -64,11 +64,11 @@ "description": "Universal JavaScript SDK for Storyblok's API",

"devDependencies": {
"@commitlint/cli": "^19.6.0",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@storyblok/eslint-config": "^0.3.0",
"@tsconfig/recommended": "^1.0.8",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"eslint": "^9.16.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",

@@ -78,6 +78,7 @@ "isomorphic-fetch": "^3.0.0",

"prettier": "^3.4.2",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.7.2",
"vite": "^5.4.11",
"vite-plugin-banner": "^0.8.0",
"vite-plugin-dts": "^4.3.0",
"vite-plugin-dts": "^4.4.0",
"vitest": "^2.1.8"

@@ -105,3 +106,7 @@ },

]
},
"simple-git-hooks": {
"pre-commit": "pnpm lint",
"pre-push": "pnpm commitlint --last --verbose"
}
}

@@ -6,2 +6,3 @@ import StoryblokClient from '.';

import { SbHelpers } from './sbHelpers';
import type { ISbLink } from './interfaces';

@@ -380,2 +381,128 @@ // Mocking external dependencies

});
describe('cdn/links endpoint', () => {
it('should fetch links with dates when include_dates is set to 1', async () => {
const mockLinksResponse = {
data: {
links: {
'story-1': {
id: 1,
uuid: 'story-1-uuid',
slug: 'story-1',
name: 'Story 1',
is_folder: false,
parent_id: 0,
published: true,
position: 0,
// Date fields included because of include_dates: 1
created_at: '2024-01-01T10:00:00.000Z',
published_at: '2024-01-01T11:00:00.000Z',
updated_at: '2024-01-02T10:00:00.000Z',
},
'story-2': {
id: 2,
uuid: 'story-2-uuid',
slug: 'story-2',
name: 'Story 2',
is_folder: false,
parent_id: 0,
published: true,
position: 1,
created_at: '2024-01-03T10:00:00.000Z',
published_at: '2024-01-03T11:00:00.000Z',
updated_at: '2024-01-04T10:00:00.000Z',
},
},
},
headers: {},
status: 200,
};
const mockGet = vi.fn().mockResolvedValue(mockLinksResponse);
client.client = {
get: mockGet,
post: vi.fn(),
setFetchOptions: vi.fn(),
baseURL: 'https://api.storyblok.com/v2',
};
const response = await client.get('cdn/links', {
version: 'draft',
include_dates: 1,
});
// Verify the structure of the response
expect(response).toHaveProperty('data.links');
// Check if links are present and have the correct structure
expect(response.data.links['story-1']).toBeDefined();
expect(response.data.links['story-2']).toBeDefined();
// Verify date fields are present in the response
const link: ISbLink = response.data.links['story-1'];
expect(link).toHaveProperty('created_at');
expect(link).toHaveProperty('published_at');
expect(link).toHaveProperty('updated_at');
// Verify the date formats
const DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
expect(link.created_at).toMatch(DATETIME_FORMAT);
expect(link.published_at).toMatch(DATETIME_FORMAT);
expect(link.updated_at).toMatch(DATETIME_FORMAT);
// Verify the API was called with correct parameters
expect(mockGet).toHaveBeenCalledWith('/cdn/links', {
cv: 0,
token: 'test-token',
version: 'draft',
include_dates: 1,
});
expect(mockGet).toHaveBeenCalledTimes(1);
});
it('should handle links response without dates when include_dates is not set', async () => {
const mockResponse = {
data: {
links: {
'story-1': {
id: 1,
uuid: 'story-1-uuid',
slug: 'story-1',
name: 'Story 1',
is_folder: false,
parent_id: 0,
published: true,
position: 0,
// No date fields
},
},
},
headers: {},
status: 200,
};
const mockGet = vi.fn().mockResolvedValue(mockResponse);
client.client.get = mockGet;
const response = await client.get('cdn/links', { version: 'draft' });
expect(response.data.links['story-1']).not.toHaveProperty('created_at');
expect(response.data.links['story-1']).not.toHaveProperty('published_at');
expect(response.data.links['story-1']).not.toHaveProperty('updated_at');
});
it('should handle errors gracefully', async () => {
const mockGet = vi.fn().mockRejectedValue({
status: 404,
});
client.client.get = mockGet;
await expect(client.get('cdn/links', {
version: 'draft',
})).rejects.toMatchObject({
status: 404,
});
});
});
});

@@ -382,0 +509,0 @@

@@ -15,2 +15,4 @@ import throttledQueue from './throttlePromise';

ISbCustomFetch,
ISbLinksParams,
ISbLinksResult,
ISbLinkURLObject,

@@ -231,6 +233,18 @@ ISbNode,

public get(
slug: 'cdn/links',
params?: ISbLinksParams,
fetchOptions?: ISbCustomFetch
): Promise<ISbLinksResult>;
public get(
slug: string,
params?: ISbStoriesParams,
fetchOptions?: ISbCustomFetch
): Promise<ISbResult>;
public get(
slug: string,
params?: ISbStoriesParams | ISbLinksParams,
fetchOptions?: ISbCustomFetch,
): Promise<ISbResult> {
): Promise<ISbResult | ISbLinksResult> {
if (!params) {

@@ -456,3 +470,2 @@ params = {} as ISbStoriesParams;

if (Array.isArray(fields) ? fields.includes(fieldPath) : fields === fieldPath) {
//
this._resolveField(jtree, treeItem, resolveId);

@@ -459,0 +472,0 @@ }

@@ -241,2 +241,6 @@ import type { ResponseFn } from './sbFetch';

export interface ISbLinksResult extends ISbResult {
data: ISbLinks;
}
export interface ISbResponse {

@@ -337,4 +341,20 @@ data: any;

is_startpage?: boolean;
path?: string;
real_path?: string;
published_at?: string;
created_at?: string;
updated_at?: string;
}
export interface ISbLinksParams {
starts_with?: string;
version?: 'published' | 'draft';
paginated?: number;
per_page?: number;
page?: number;
sort_by?: string;
include_dates?: 0 | 1;
with_parent?: number;
}
export interface ISbLinks {

@@ -341,0 +361,0 @@ links?: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc