@prezly/theme-kit-core 10.12.0 → 10.13.0

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.
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+
3
+ var _sdk = require("@prezly/sdk");
4
+ var _ContentDelivery = require("./ContentDelivery.cjs");
5
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
6
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
7
+ function setup(body) {
8
+ var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
9
+ var fetch = jest.fn(/*#__PURE__*/function () {
10
+ var _ref = _asyncToGenerator(function* (_url, _init) {
11
+ return new Response(JSON.stringify(body), {
12
+ status,
13
+ headers: {
14
+ 'content-type': 'application/json'
15
+ }
16
+ });
17
+ });
18
+ return function (_x, _x2) {
19
+ return _ref.apply(this, arguments);
20
+ };
21
+ }());
22
+ var sdk = (0, _sdk.createPrezlyClient)({
23
+ accessToken: 'test-token',
24
+ fetch
25
+ });
26
+ return {
27
+ client: (0, _ContentDelivery.createClient)(sdk, 'test-newsroom', undefined),
28
+ request: () => new URL(String(fetch.mock.calls[0][0])),
29
+ init: () => fetch.mock.calls[0][1]
30
+ };
31
+ }
32
+ describe('ContentDelivery with the installed SDK', () => {
33
+ it('unwraps newsroom, theme, language, category and gallery responses', /*#__PURE__*/_asyncToGenerator(function* () {
34
+ var newsroom = {
35
+ uuid: 'test-newsroom'
36
+ };
37
+ var theme = {
38
+ id: 'test-theme',
39
+ settings: {
40
+ title: 'Theme'
41
+ }
42
+ };
43
+ var language = {
44
+ code: 'en',
45
+ is_default: true
46
+ };
47
+ var category = {
48
+ id: 7
49
+ };
50
+ var gallery = {
51
+ uuid: 'test-gallery'
52
+ };
53
+ var fetch = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
54
+ return new Response(JSON.stringify({
55
+ newsroom,
56
+ theme,
57
+ languages: [language],
58
+ categories: [category],
59
+ galleries: [gallery],
60
+ gallery
61
+ }), {
62
+ headers: {
63
+ 'content-type': 'application/json'
64
+ }
65
+ });
66
+ }));
67
+ var sdk = (0, _sdk.createPrezlyClient)({
68
+ accessToken: 'test-token',
69
+ fetch
70
+ });
71
+ var client = (0, _ContentDelivery.createClient)(sdk, 'test-newsroom', 'test-theme');
72
+ yield expect(client.newsroom()).resolves.toEqual(newsroom);
73
+ yield expect(client.themeSettings()).resolves.toEqual(theme.settings);
74
+ yield expect(client.languages()).resolves.toEqual([language]);
75
+ yield expect(client.categories()).resolves.toEqual([category]);
76
+ yield expect(client.galleries()).resolves.toMatchObject({
77
+ galleries: [gallery]
78
+ });
79
+ yield expect(client.gallery(gallery.uuid)).resolves.toEqual(gallery);
80
+ }));
81
+ it('preserves featured contact social profiles and filters by is_featured', /*#__PURE__*/_asyncToGenerator(function* () {
82
+ var contact = {
83
+ uuid: '824b29da-97a1-44f2-ab45-f708ab268afc',
84
+ facebook: 'https://facebook.com/prezly',
85
+ twitter: 'https://twitter.com/prezly',
86
+ linkedin: 'https://linkedin.com/in/test-contact',
87
+ instagram: 'https://instagram.com/prezly'
88
+ };
89
+ var _setup = setup({
90
+ contacts: [contact]
91
+ }),
92
+ client = _setup.client,
93
+ request = _setup.request;
94
+ yield expect(client.featuredContacts()).resolves.toEqual([contact]);
95
+ expect(request().pathname).toBe('/v2/newsrooms/test-newsroom/contacts');
96
+ expect(JSON.parse(request().searchParams.get('query'))).toEqual({
97
+ is_featured: true
98
+ });
99
+ }));
100
+ it('serializes story filters, pagination, sort order, formats and extra fields', /*#__PURE__*/_asyncToGenerator(function* () {
101
+ var result = {
102
+ stories: [],
103
+ pagination: {
104
+ total: 0
105
+ }
106
+ };
107
+ var _setup2 = setup(result),
108
+ client = _setup2.client,
109
+ request = _setup2.request,
110
+ init = _setup2.init;
111
+ yield expect(client.stories({
112
+ limit: 10,
113
+ offset: 10,
114
+ highlighted: 2,
115
+ locale: 'en',
116
+ categories: [{
117
+ id: 7
118
+ }]
119
+ }, {
120
+ include: ['content']
121
+ })).resolves.toEqual(result);
122
+ expect(request().pathname).toBe('/v2/stories/search');
123
+ expect(init().method).toBe('POST');
124
+ var payload = JSON.parse(String(init().body));
125
+ expect(payload).toMatchObject({
126
+ limit: 10,
127
+ offset: 12,
128
+ sort: '-is_pinned,-published_at',
129
+ include: 'content'
130
+ });
131
+ expect(new Headers(init().headers).get('accept')).toContain('content-format=v4');
132
+ expect(payload.query).toEqual({
133
+ 'category.id': {
134
+ $all: [7]
135
+ },
136
+ 'newsroom.uuid': {
137
+ $in: ['test-newsroom']
138
+ },
139
+ locale: {
140
+ $in: ['en']
141
+ },
142
+ status: {
143
+ $in: [_sdk.Story.Status.PUBLISHED]
144
+ },
145
+ visibility: {
146
+ $in: [_sdk.Story.Visibility.PUBLIC]
147
+ }
148
+ });
149
+ }));
150
+ it.each([{
151
+ uuid: 'test-story'
152
+ }, {
153
+ slug: 'test-story'
154
+ }])('retrieves story content and extended fields using %j', /*#__PURE__*/function () {
155
+ var _ref6 = _asyncToGenerator(function* (lookup) {
156
+ var story = {
157
+ uuid: 'test-story',
158
+ content: 'story content',
159
+ subtitle: 'Subtitle'
160
+ };
161
+ var _setup3 = setup({
162
+ story
163
+ }),
164
+ client = _setup3.client,
165
+ request = _setup3.request;
166
+ yield expect(client.story(lookup, {
167
+ include: ['content']
168
+ })).resolves.toEqual(story);
169
+ expect(request().searchParams.getAll('include[]')).toEqual(expect.arrayContaining(['content', 'header_image']));
170
+ });
171
+ return function (_x3) {
172
+ return _ref6.apply(this, arguments);
173
+ };
174
+ }());
175
+ it.each([403, 404, 410])('maps SDK HTTP %s errors to missing content', /*#__PURE__*/function () {
176
+ var _ref7 = _asyncToGenerator(function* (status) {
177
+ var _setup4 = setup({
178
+ message: 'Unavailable'
179
+ }, status),
180
+ client = _setup4.client;
181
+ yield expect(client.story({
182
+ uuid: 'test-story'
183
+ })).resolves.toBeNull();
184
+ yield expect(client.story({
185
+ slug: 'test-story'
186
+ })).resolves.toBeNull();
187
+ yield expect(client.gallery('test-gallery')).resolves.toBeNull();
188
+ });
189
+ return function (_x4) {
190
+ return _ref7.apply(this, arguments);
191
+ };
192
+ }());
193
+ it.each([401, 429, 500])('propagates SDK HTTP %s errors', /*#__PURE__*/function () {
194
+ var _ref8 = _asyncToGenerator(function* (status) {
195
+ var _setup5 = setup({
196
+ message: 'Failure'
197
+ }, status),
198
+ client = _setup5.client;
199
+ yield expect(client.story({
200
+ uuid: 'test-story'
201
+ })).rejects.toBeInstanceOf(_sdk.ApiError);
202
+ yield expect(client.story({
203
+ slug: 'test-story'
204
+ })).rejects.toMatchObject({
205
+ status
206
+ });
207
+ yield expect(client.gallery('test-gallery')).rejects.toMatchObject({
208
+ status
209
+ });
210
+ });
211
+ return function (_x5) {
212
+ return _ref8.apply(this, arguments);
213
+ };
214
+ }());
215
+ });
@@ -0,0 +1,213 @@
1
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
2
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
3
+ import { ApiError, createPrezlyClient, Story } from '@prezly/sdk';
4
+ import { createClient } from "./ContentDelivery.mjs";
5
+ function setup(body) {
6
+ var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
7
+ var fetch = jest.fn(/*#__PURE__*/function () {
8
+ var _ref = _asyncToGenerator(function* (_url, _init) {
9
+ return new Response(JSON.stringify(body), {
10
+ status,
11
+ headers: {
12
+ 'content-type': 'application/json'
13
+ }
14
+ });
15
+ });
16
+ return function (_x, _x2) {
17
+ return _ref.apply(this, arguments);
18
+ };
19
+ }());
20
+ var sdk = createPrezlyClient({
21
+ accessToken: 'test-token',
22
+ fetch
23
+ });
24
+ return {
25
+ client: createClient(sdk, 'test-newsroom', undefined),
26
+ request: () => new URL(String(fetch.mock.calls[0][0])),
27
+ init: () => fetch.mock.calls[0][1]
28
+ };
29
+ }
30
+ describe('ContentDelivery with the installed SDK', () => {
31
+ it('unwraps newsroom, theme, language, category and gallery responses', /*#__PURE__*/_asyncToGenerator(function* () {
32
+ var newsroom = {
33
+ uuid: 'test-newsroom'
34
+ };
35
+ var theme = {
36
+ id: 'test-theme',
37
+ settings: {
38
+ title: 'Theme'
39
+ }
40
+ };
41
+ var language = {
42
+ code: 'en',
43
+ is_default: true
44
+ };
45
+ var category = {
46
+ id: 7
47
+ };
48
+ var gallery = {
49
+ uuid: 'test-gallery'
50
+ };
51
+ var fetch = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
52
+ return new Response(JSON.stringify({
53
+ newsroom,
54
+ theme,
55
+ languages: [language],
56
+ categories: [category],
57
+ galleries: [gallery],
58
+ gallery
59
+ }), {
60
+ headers: {
61
+ 'content-type': 'application/json'
62
+ }
63
+ });
64
+ }));
65
+ var sdk = createPrezlyClient({
66
+ accessToken: 'test-token',
67
+ fetch
68
+ });
69
+ var client = createClient(sdk, 'test-newsroom', 'test-theme');
70
+ yield expect(client.newsroom()).resolves.toEqual(newsroom);
71
+ yield expect(client.themeSettings()).resolves.toEqual(theme.settings);
72
+ yield expect(client.languages()).resolves.toEqual([language]);
73
+ yield expect(client.categories()).resolves.toEqual([category]);
74
+ yield expect(client.galleries()).resolves.toMatchObject({
75
+ galleries: [gallery]
76
+ });
77
+ yield expect(client.gallery(gallery.uuid)).resolves.toEqual(gallery);
78
+ }));
79
+ it('preserves featured contact social profiles and filters by is_featured', /*#__PURE__*/_asyncToGenerator(function* () {
80
+ var contact = {
81
+ uuid: '824b29da-97a1-44f2-ab45-f708ab268afc',
82
+ facebook: 'https://facebook.com/prezly',
83
+ twitter: 'https://twitter.com/prezly',
84
+ linkedin: 'https://linkedin.com/in/test-contact',
85
+ instagram: 'https://instagram.com/prezly'
86
+ };
87
+ var _setup = setup({
88
+ contacts: [contact]
89
+ }),
90
+ client = _setup.client,
91
+ request = _setup.request;
92
+ yield expect(client.featuredContacts()).resolves.toEqual([contact]);
93
+ expect(request().pathname).toBe('/v2/newsrooms/test-newsroom/contacts');
94
+ expect(JSON.parse(request().searchParams.get('query'))).toEqual({
95
+ is_featured: true
96
+ });
97
+ }));
98
+ it('serializes story filters, pagination, sort order, formats and extra fields', /*#__PURE__*/_asyncToGenerator(function* () {
99
+ var result = {
100
+ stories: [],
101
+ pagination: {
102
+ total: 0
103
+ }
104
+ };
105
+ var _setup2 = setup(result),
106
+ client = _setup2.client,
107
+ request = _setup2.request,
108
+ init = _setup2.init;
109
+ yield expect(client.stories({
110
+ limit: 10,
111
+ offset: 10,
112
+ highlighted: 2,
113
+ locale: 'en',
114
+ categories: [{
115
+ id: 7
116
+ }]
117
+ }, {
118
+ include: ['content']
119
+ })).resolves.toEqual(result);
120
+ expect(request().pathname).toBe('/v2/stories/search');
121
+ expect(init().method).toBe('POST');
122
+ var payload = JSON.parse(String(init().body));
123
+ expect(payload).toMatchObject({
124
+ limit: 10,
125
+ offset: 12,
126
+ sort: '-is_pinned,-published_at',
127
+ include: 'content'
128
+ });
129
+ expect(new Headers(init().headers).get('accept')).toContain('content-format=v4');
130
+ expect(payload.query).toEqual({
131
+ 'category.id': {
132
+ $all: [7]
133
+ },
134
+ 'newsroom.uuid': {
135
+ $in: ['test-newsroom']
136
+ },
137
+ locale: {
138
+ $in: ['en']
139
+ },
140
+ status: {
141
+ $in: [Story.Status.PUBLISHED]
142
+ },
143
+ visibility: {
144
+ $in: [Story.Visibility.PUBLIC]
145
+ }
146
+ });
147
+ }));
148
+ it.each([{
149
+ uuid: 'test-story'
150
+ }, {
151
+ slug: 'test-story'
152
+ }])('retrieves story content and extended fields using %j', /*#__PURE__*/function () {
153
+ var _ref6 = _asyncToGenerator(function* (lookup) {
154
+ var story = {
155
+ uuid: 'test-story',
156
+ content: 'story content',
157
+ subtitle: 'Subtitle'
158
+ };
159
+ var _setup3 = setup({
160
+ story
161
+ }),
162
+ client = _setup3.client,
163
+ request = _setup3.request;
164
+ yield expect(client.story(lookup, {
165
+ include: ['content']
166
+ })).resolves.toEqual(story);
167
+ expect(request().searchParams.getAll('include[]')).toEqual(expect.arrayContaining(['content', 'header_image']));
168
+ });
169
+ return function (_x3) {
170
+ return _ref6.apply(this, arguments);
171
+ };
172
+ }());
173
+ it.each([403, 404, 410])('maps SDK HTTP %s errors to missing content', /*#__PURE__*/function () {
174
+ var _ref7 = _asyncToGenerator(function* (status) {
175
+ var _setup4 = setup({
176
+ message: 'Unavailable'
177
+ }, status),
178
+ client = _setup4.client;
179
+ yield expect(client.story({
180
+ uuid: 'test-story'
181
+ })).resolves.toBeNull();
182
+ yield expect(client.story({
183
+ slug: 'test-story'
184
+ })).resolves.toBeNull();
185
+ yield expect(client.gallery('test-gallery')).resolves.toBeNull();
186
+ });
187
+ return function (_x4) {
188
+ return _ref7.apply(this, arguments);
189
+ };
190
+ }());
191
+ it.each([401, 429, 500])('propagates SDK HTTP %s errors', /*#__PURE__*/function () {
192
+ var _ref8 = _asyncToGenerator(function* (status) {
193
+ var _setup5 = setup({
194
+ message: 'Failure'
195
+ }, status),
196
+ client = _setup5.client;
197
+ yield expect(client.story({
198
+ uuid: 'test-story'
199
+ })).rejects.toBeInstanceOf(ApiError);
200
+ yield expect(client.story({
201
+ slug: 'test-story'
202
+ })).rejects.toMatchObject({
203
+ status
204
+ });
205
+ yield expect(client.gallery('test-gallery')).rejects.toMatchObject({
206
+ status
207
+ });
208
+ });
209
+ return function (_x5) {
210
+ return _ref8.apply(this, arguments);
211
+ };
212
+ }());
213
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-core",
3
- "version": "10.12.0",
3
+ "version": "10.13.0",
4
4
  "description": "Data layer and utility library for developing Prezly themes with JavaScript",
5
5
  "main": "build/index.mjs",
6
6
  "type": "module",
@@ -37,10 +37,10 @@
37
37
  "test:build:cjs": "node tests/test-build.cjs"
38
38
  },
39
39
  "peerDependencies": {
40
- "@prezly/sdk": "21.12.0 || ^23.x"
40
+ "@prezly/sdk": "21.12.0 || ^23.0.1 || ^26.16.0"
41
41
  },
42
42
  "dependencies": {
43
- "@prezly/theme-kit-intl": "^10.12.0",
43
+ "@prezly/theme-kit-intl": "^10.13.0",
44
44
  "@prezly/uploadcare": "2.4.4",
45
45
  "@technically/is-not-undefined": "^1.0.0",
46
46
  "@technically/omit-undefined": "^1.0.4",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "aa8fe2c8311ddf0c5aa2329da15e086b12a81d96"
74
+ "gitHead": "455f8c5db29b21db0791ee7f6e9fd60a08bd840e"
75
75
  }