@prezly/theme-kit-core 10.16.0 → 10.16.1
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.
- package/build/index.cjs +4 -1
- package/build/index.d.ts +1 -0
- package/build/index.mjs +2 -0
- package/build/stories.cjs +27 -0
- package/build/stories.d.ts +16 -0
- package/build/stories.mjs +20 -0
- package/build/stories.test.cjs +47 -0
- package/build/stories.test.mjs +45 -0
- package/package.json +2 -2
package/build/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var _exportNames = {
|
|
|
15
15
|
PrivacyPortal: true,
|
|
16
16
|
Search: true,
|
|
17
17
|
Sitemap: true,
|
|
18
|
+
Stories: true,
|
|
18
19
|
Uploads: true
|
|
19
20
|
};
|
|
20
21
|
exports.Galleries = exports.Environment = exports.ContentDelivery = exports.Boilerplate = void 0;
|
|
@@ -24,7 +25,7 @@ Object.defineProperty(exports, "HttpClient", {
|
|
|
24
25
|
return _index2.HttpClient;
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
|
-
exports.Uploads = exports.Sitemap = exports.Search = exports.PrivacyPortal = exports.Newsrooms = exports.Metadata = exports.Intl = void 0;
|
|
28
|
+
exports.Uploads = exports.Stories = exports.Sitemap = exports.Search = exports.PrivacyPortal = exports.Newsrooms = exports.Metadata = exports.Intl = void 0;
|
|
28
29
|
var _Boilerplate = _interopRequireWildcard(require("./boilerplate.cjs"));
|
|
29
30
|
exports.Boilerplate = _Boilerplate;
|
|
30
31
|
var _constants = require("./constants.cjs");
|
|
@@ -82,6 +83,8 @@ var _Search = _interopRequireWildcard(require("./search.cjs"));
|
|
|
82
83
|
exports.Search = _Search;
|
|
83
84
|
var _Sitemap = _interopRequireWildcard(require("./sitemap/index.cjs"));
|
|
84
85
|
exports.Sitemap = _Sitemap;
|
|
86
|
+
var _Stories = _interopRequireWildcard(require("./stories.cjs"));
|
|
87
|
+
exports.Stories = _Stories;
|
|
85
88
|
var _Uploads = _interopRequireWildcard(require("./uploads.cjs"));
|
|
86
89
|
exports.Uploads = _Uploads;
|
|
87
90
|
var cache;
|
package/build/index.d.ts
CHANGED
package/build/index.mjs
CHANGED
|
@@ -22,5 +22,7 @@ import * as _Search from "./search.mjs";
|
|
|
22
22
|
export { _Search as Search };
|
|
23
23
|
import * as _Sitemap from "./sitemap/index.mjs";
|
|
24
24
|
export { _Sitemap as Sitemap };
|
|
25
|
+
import * as _Stories from "./stories.mjs";
|
|
26
|
+
export { _Stories as Stories };
|
|
25
27
|
import * as _Uploads from "./uploads.mjs";
|
|
26
28
|
export { _Uploads as Uploads };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPublicTranslations = getPublicTranslations;
|
|
7
|
+
exports.isPubliclyPublished = isPubliclyPublished;
|
|
8
|
+
var _sdk = require("@prezly/sdk");
|
|
9
|
+
/**
|
|
10
|
+
* Tells whether anyone can open the story on the site right now.
|
|
11
|
+
*
|
|
12
|
+
* A published story is not necessarily public: private and confidential stories are published too,
|
|
13
|
+
* and only people who were given the link should reach them.
|
|
14
|
+
*/
|
|
15
|
+
function isPubliclyPublished(story) {
|
|
16
|
+
return story.status === _sdk.Story.Status.PUBLISHED && story.visibility === _sdk.Story.Visibility.PUBLIC;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lists the story translations a page can link to.
|
|
21
|
+
*
|
|
22
|
+
* The API returns every translation of a story, whatever its status and visibility. Linking to a
|
|
23
|
+
* draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
|
|
24
|
+
*/
|
|
25
|
+
function getPublicTranslations(story) {
|
|
26
|
+
return story.translations.filter(isPubliclyPublished);
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Story } from '@prezly/sdk';
|
|
2
|
+
import type { StoryRef } from '@prezly/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Tells whether anyone can open the story on the site right now.
|
|
5
|
+
*
|
|
6
|
+
* A published story is not necessarily public: private and confidential stories are published too,
|
|
7
|
+
* and only people who were given the link should reach them.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPubliclyPublished(story: Pick<StoryRef, 'status' | 'visibility'>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Lists the story translations a page can link to.
|
|
12
|
+
*
|
|
13
|
+
* The API returns every translation of a story, whatever its status and visibility. Linking to a
|
|
14
|
+
* draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPublicTranslations(story: Pick<Story, 'translations'>): StoryRef[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Story } from '@prezly/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Tells whether anyone can open the story on the site right now.
|
|
4
|
+
*
|
|
5
|
+
* A published story is not necessarily public: private and confidential stories are published too,
|
|
6
|
+
* and only people who were given the link should reach them.
|
|
7
|
+
*/
|
|
8
|
+
export function isPubliclyPublished(story) {
|
|
9
|
+
return story.status === Story.Status.PUBLISHED && story.visibility === Story.Visibility.PUBLIC;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Lists the story translations a page can link to.
|
|
14
|
+
*
|
|
15
|
+
* The API returns every translation of a story, whatever its status and visibility. Linking to a
|
|
16
|
+
* draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
|
|
17
|
+
*/
|
|
18
|
+
export function getPublicTranslations(story) {
|
|
19
|
+
return story.translations.filter(isPubliclyPublished);
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _sdk = require("@prezly/sdk");
|
|
4
|
+
var _stories = require("./stories.cjs");
|
|
5
|
+
function translation(code, status) {
|
|
6
|
+
var visibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _sdk.Story.Visibility.PUBLIC;
|
|
7
|
+
return {
|
|
8
|
+
culture: {
|
|
9
|
+
code
|
|
10
|
+
},
|
|
11
|
+
status,
|
|
12
|
+
visibility
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
describe('isPubliclyPublished', () => {
|
|
16
|
+
it('accepts a published public story', () => {
|
|
17
|
+
expect((0, _stories.isPubliclyPublished)({
|
|
18
|
+
status: _sdk.Story.Status.PUBLISHED,
|
|
19
|
+
visibility: _sdk.Story.Visibility.PUBLIC
|
|
20
|
+
})).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
it.each([_sdk.Story.Visibility.PRIVATE, _sdk.Story.Visibility.CONFIDENTIAL, _sdk.Story.Visibility.EMBARGO])('rejects a published %s story', visibility => {
|
|
23
|
+
expect((0, _stories.isPubliclyPublished)({
|
|
24
|
+
status: _sdk.Story.Status.PUBLISHED,
|
|
25
|
+
visibility
|
|
26
|
+
})).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
it.each([_sdk.Story.Status.UNINITIALIZED, _sdk.Story.Status.DRAFT, _sdk.Story.Status.SCHEDULED, _sdk.Story.Status.EMBARGO])('rejects a public story with the %s status', status => {
|
|
29
|
+
expect((0, _stories.isPubliclyPublished)({
|
|
30
|
+
status,
|
|
31
|
+
visibility: _sdk.Story.Visibility.PUBLIC
|
|
32
|
+
})).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('getPublicTranslations', () => {
|
|
36
|
+
it('keeps only the published public translations', () => {
|
|
37
|
+
var translations = [translation('en', _sdk.Story.Status.PUBLISHED), translation('fr', _sdk.Story.Status.DRAFT), translation('de', _sdk.Story.Status.SCHEDULED), translation('es', _sdk.Story.Status.EMBARGO, _sdk.Story.Visibility.EMBARGO), translation('nl', _sdk.Story.Status.PUBLISHED, _sdk.Story.Visibility.PRIVATE), translation('it', _sdk.Story.Status.PUBLISHED, _sdk.Story.Visibility.CONFIDENTIAL), translation('pt', _sdk.Story.Status.PUBLISHED)];
|
|
38
|
+
expect((0, _stories.getPublicTranslations)({
|
|
39
|
+
translations
|
|
40
|
+
}).map(story => story.culture.code)).toEqual(['en', 'pt']);
|
|
41
|
+
});
|
|
42
|
+
it('returns an empty list when the story has no translations', () => {
|
|
43
|
+
expect((0, _stories.getPublicTranslations)({
|
|
44
|
+
translations: []
|
|
45
|
+
})).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Story } from '@prezly/sdk';
|
|
2
|
+
import { getPublicTranslations, isPubliclyPublished } from "./stories.mjs";
|
|
3
|
+
function translation(code, status) {
|
|
4
|
+
var visibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Story.Visibility.PUBLIC;
|
|
5
|
+
return {
|
|
6
|
+
culture: {
|
|
7
|
+
code
|
|
8
|
+
},
|
|
9
|
+
status,
|
|
10
|
+
visibility
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
describe('isPubliclyPublished', () => {
|
|
14
|
+
it('accepts a published public story', () => {
|
|
15
|
+
expect(isPubliclyPublished({
|
|
16
|
+
status: Story.Status.PUBLISHED,
|
|
17
|
+
visibility: Story.Visibility.PUBLIC
|
|
18
|
+
})).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
it.each([Story.Visibility.PRIVATE, Story.Visibility.CONFIDENTIAL, Story.Visibility.EMBARGO])('rejects a published %s story', visibility => {
|
|
21
|
+
expect(isPubliclyPublished({
|
|
22
|
+
status: Story.Status.PUBLISHED,
|
|
23
|
+
visibility
|
|
24
|
+
})).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
it.each([Story.Status.UNINITIALIZED, Story.Status.DRAFT, Story.Status.SCHEDULED, Story.Status.EMBARGO])('rejects a public story with the %s status', status => {
|
|
27
|
+
expect(isPubliclyPublished({
|
|
28
|
+
status,
|
|
29
|
+
visibility: Story.Visibility.PUBLIC
|
|
30
|
+
})).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('getPublicTranslations', () => {
|
|
34
|
+
it('keeps only the published public translations', () => {
|
|
35
|
+
var translations = [translation('en', Story.Status.PUBLISHED), translation('fr', Story.Status.DRAFT), translation('de', Story.Status.SCHEDULED), translation('es', Story.Status.EMBARGO, Story.Visibility.EMBARGO), translation('nl', Story.Status.PUBLISHED, Story.Visibility.PRIVATE), translation('it', Story.Status.PUBLISHED, Story.Visibility.CONFIDENTIAL), translation('pt', Story.Status.PUBLISHED)];
|
|
36
|
+
expect(getPublicTranslations({
|
|
37
|
+
translations
|
|
38
|
+
}).map(story => story.culture.code)).toEqual(['en', 'pt']);
|
|
39
|
+
});
|
|
40
|
+
it('returns an empty list when the story has no translations', () => {
|
|
41
|
+
expect(getPublicTranslations({
|
|
42
|
+
translations: []
|
|
43
|
+
})).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/theme-kit-core",
|
|
3
|
-
"version": "10.16.
|
|
3
|
+
"version": "10.16.1",
|
|
4
4
|
"description": "Data layer and utility library for developing Prezly themes with JavaScript",
|
|
5
5
|
"main": "build/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@technically/omit-undefined": "^1.0.4",
|
|
26
26
|
"parse-data-url": "^6.0.0",
|
|
27
27
|
"url-pattern": "^1.0.3",
|
|
28
|
-
"@prezly/theme-kit-intl": "^10.16.
|
|
28
|
+
"@prezly/theme-kit-intl": "^10.16.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/parse-data-url": "3.0.2"
|