@raketa-cloud/next 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/next",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "check-types": "tsc --noEmit",
@@ -1,16 +1,12 @@
1
1
  import DxpClient from "./DxpClient";
2
- import Pages from "./Pages";
3
- import Articles from "./Articles";
4
- import Events from "./Events";
2
+ import Resources from "./Resources";
5
3
  import Settings from "./Settings";
6
4
  import Tags from "./Tags";
7
5
 
8
6
  export default class Dxp {
9
7
  constructor(getConfig, getToken) {
10
8
  this.client = new DxpClient(getConfig, getToken);
11
- this.pages = new Pages(this.client);
12
- this.articles = new Articles(this.client);
13
- this.events = new Events(this.client);
9
+ this.resources = new Resources(this.client);
14
10
  this.settings = new Settings(this.client);
15
11
  this.tags = new Tags(this.client);
16
12
  }
@@ -0,0 +1,31 @@
1
+ import DxpModel from "./DxpModel";
2
+ import {
3
+ ResourceChangePreviewDocument,
4
+ MiniResourcesDocument,
5
+ } from "./documents/resourcesDocuments";
6
+
7
+ export default class Resources extends DxpModel {
8
+ async changePreview(locale, id, version, resourceType) {
9
+ const response = await this.client.query(ResourceChangePreviewDocument, {
10
+ input: {
11
+ locale,
12
+ resourceId: id,
13
+ version,
14
+ resourceType,
15
+ },
16
+ });
17
+
18
+ return response?.resourceChangePreview;
19
+ }
20
+
21
+ async miniResources(locale, input = {}) {
22
+ const response = await this.client.query(MiniResourcesDocument, {
23
+ input: {
24
+ locale,
25
+ ...input,
26
+ },
27
+ });
28
+
29
+ return response?.miniResources;
30
+ }
31
+ }
@@ -22,16 +22,6 @@ export function categoryFragment() {
22
22
  `;
23
23
  }
24
24
 
25
- export function resourceTypeFragment() {
26
- return gql`
27
- {
28
- id
29
- slug
30
- title
31
- }
32
- `;
33
- }
34
-
35
25
  export function paginationFragment() {
36
26
  return gql`
37
27
  {
@@ -1,12 +1,13 @@
1
1
  import { gql } from "../../graphql";
2
- import { tagFragment, categoryFragment, resourceTypeFragment } from "./common";
2
+ import { tagFragment, categoryFragment } from "./common";
3
3
 
4
- const PageByIdDocument = gql`
5
- query PageByID($input: IdInput!) {
6
- page(input: $input) {
4
+ const ResourceByIdDocument = gql`
5
+ query ResourceByID($input: IdInput!) {
6
+ resource(input: $input) {
7
7
  id
8
8
  slug
9
9
  title
10
+ resourceType
10
11
  widgets
11
12
  settings
12
13
  visibility
@@ -14,18 +15,18 @@ const PageByIdDocument = gql`
14
15
  revisionsCount
15
16
  tags ${tagFragment()}
16
17
  categories ${categoryFragment()}
17
- pageType ${resourceTypeFragment()}
18
18
  }
19
19
  }
20
20
  `;
21
21
 
22
- const PageChangePreviewDocument = gql`
23
- query ($input: PageChangePreviewInput!) {
24
- pageChangePreview(input: $input) {
25
- page {
22
+ const ResourceChangePreviewDocument = gql`
23
+ query ($input: ResourceChangePreviewInput!) {
24
+ resourceChangePreview(input: $input) {
25
+ resource {
26
26
  id
27
27
  slug
28
28
  title
29
+ resourceType
29
30
  widgets
30
31
  settings
31
32
  visibility
@@ -33,9 +34,8 @@ const PageChangePreviewDocument = gql`
33
34
  websiteSettings
34
35
  tags ${tagFragment()}
35
36
  categories ${categoryFragment()}
36
- pageType ${resourceTypeFragment()}
37
37
  }
38
- pageChange {
38
+ resourceChange {
39
39
  version
40
40
  title
41
41
  description
@@ -48,9 +48,9 @@ const PageChangePreviewDocument = gql`
48
48
  }
49
49
  `;
50
50
 
51
- const MiniPagesDocument = gql`
52
- query ($input: PagesInput!) {
53
- miniPages(input: $input) {
51
+ const MiniResourcesDocument = gql`
52
+ query ($input: ResourcesInput!) {
53
+ miniResources(input: $input) {
54
54
  list {
55
55
  id
56
56
  slug
@@ -61,4 +61,4 @@ const MiniPagesDocument = gql`
61
61
  }
62
62
  `;
63
63
 
64
- export { PageByIdDocument, PageChangePreviewDocument, MiniPagesDocument };
64
+ export { ResourceByIdDocument, ResourceChangePreviewDocument, MiniResourcesDocument };
@@ -1,7 +1,5 @@
1
1
  import DxpClient from "./DxpClient";
2
- import Pages from "./Pages";
3
- import Articles from "./Articles";
4
- import Events from "./Events";
2
+ import Resources from "./Resources";
5
3
  import Settings from "./Settings";
6
4
  import Tags from "./Tags";
7
5
  import Redirects from "./Redirects";
@@ -9,9 +7,7 @@ import Redirects from "./Redirects";
9
7
  export default class Dxp {
10
8
  constructor(getConfig, cache) {
11
9
  this.client = new DxpClient(getConfig);
12
- this.pages = new Pages(this.client, cache);
13
- this.articles = new Articles(this.client, cache);
14
- this.events = new Events(this.client, cache);
10
+ this.resources = new Resources(this.client, cache);
15
11
  this.setttings = new Settings(this.client, cache);
16
12
  this.tags = new Tags(this.client, cache);
17
13
  this.redirects = new Redirects(this.client, cache);
@@ -1,18 +1,18 @@
1
1
  import DxpModel from "./DxpModel";
2
- import { PageBySlugDocument, PagesDocument } from "./documents";
2
+ import { ResourceBySlugDocument, ResourcesDocument } from "./documents";
3
3
 
4
- export default class Pages extends DxpModel {
4
+ export default class Resources extends DxpModel {
5
5
  async find(locale, slug, resourceType, opts = {}) {
6
6
  const response = await this.fetch(
7
- `page-${locale}-${slug}`,
7
+ `${resourceType}-${locale}-${slug}`,
8
8
  async () =>
9
9
  await this.client.query(
10
- PageBySlugDocument,
10
+ ResourceBySlugDocument,
11
11
  {
12
12
  input: {
13
13
  locale,
14
14
  slug,
15
- resourceType
15
+ resourceType,
16
16
  },
17
17
  },
18
18
  opts
@@ -20,20 +20,23 @@ export default class Pages extends DxpModel {
20
20
  opts
21
21
  );
22
22
 
23
- return response?.page;
23
+ return response?.resource;
24
24
  }
25
25
 
26
26
  async list(locale, input = {}, opts = {}) {
27
+ const resourceType = input?.filters?.resourceType;
28
+ const cacheKey = `${resourceType}s-${locale}-${JSON.stringify(input)}`;
29
+
27
30
  const response = await this.fetch(
28
- `pages-${locale}-${JSON.stringify(input)}`,
31
+ cacheKey,
29
32
  async () =>
30
33
  await this.client.query(
31
- PagesDocument,
34
+ ResourcesDocument,
32
35
  this.formatPaginationInInput(locale, input),
33
36
  opts
34
37
  )
35
38
  );
36
39
 
37
- return response?.pages;
40
+ return response?.resources;
38
41
  }
39
42
  }
@@ -10,19 +10,6 @@ function tagFragment() {
10
10
  `;
11
11
  }
12
12
 
13
- function revisionFragment() {
14
- return gql`
15
- {
16
- id
17
- title
18
- slug
19
- settings
20
- widgets
21
- visibility
22
- }
23
- `;
24
- }
25
-
26
13
  function paginationFragment() {
27
14
  return gql`
28
15
  {
@@ -34,12 +21,15 @@ function paginationFragment() {
34
21
  `;
35
22
  }
36
23
 
37
- function resourceTypeFragment() {
24
+ function revisionFragment() {
38
25
  return gql`
39
26
  {
40
27
  id
41
- slug
42
28
  title
29
+ slug
30
+ settings
31
+ widgets
32
+ visibility
43
33
  }
44
34
  `;
45
35
  }
@@ -64,125 +54,62 @@ const CategoriesDocument = gql`
64
54
  }
65
55
  `;
66
56
 
67
- const ArticlesDocument = gql`
68
- query Articles($input: ArticlesInput!) {
69
- articles(input: $input) {
70
- list {
71
- id
72
- slug
73
- title
74
- widgets
75
- settings
76
- publishAt
77
- visibility
78
- tags ${tagFragment()}
79
- categories ${categoryFragment()}
80
- articleType ${resourceTypeFragment()}
81
- }
82
-
83
- pagination ${paginationFragment()}
84
- }
85
- }
86
- `;
87
-
88
- const PageBySlugDocument = gql`
89
- query PageBySlug($input: SlugInput!) {
90
- page(input: $input) {
57
+ const ResourceBySlugDocument = gql`
58
+ query ResourceBySlug($input: SlugTypeInput!) {
59
+ resource(input: $input) {
91
60
  id
92
61
  title
93
62
  slug
94
- settings
63
+ resourceType
95
64
  widgets
96
- websiteSettings
97
- createdAt
98
- updatedAt
65
+ settings
99
66
  visibility
67
+ tags ${tagFragment()}
100
68
  translations
101
- pageType ${resourceTypeFragment()}
69
+ websiteSettings
102
70
  categories ${categoryFragment()}
103
- tags ${tagFragment()}
104
- }
105
- }
106
- `;
107
-
108
- const PageRevisionPreviewDocument = gql`
109
- query ($input: RevisionPreviewInput!) {
110
- pageRevisionPreview(input: $input) {
111
- page {
112
- id
113
- title
114
- slug
115
- settings
116
- widgets
117
- websiteSettings
118
- createdAt
119
- updatedAt
120
- visibility
121
- translations
122
- pageType ${resourceTypeFragment()}
123
- categories ${categoryFragment()}
124
- tags ${tagFragment()}
125
- }
126
- revision ${revisionFragment()}
71
+ createdAt
72
+ updatedAt
127
73
  }
128
74
  }
129
75
  `;
130
76
 
131
- const PagesDocument = gql`
132
- query Pages($input: PagesInput!) {
133
- pages(input: $input) {
77
+ const ResourcesDocument = gql`
78
+ query Resources($input: ResourcesInput!) {
79
+ resources(input: $input) {
134
80
  list {
135
81
  id
136
82
  slug
137
83
  title
84
+ resourceType
138
85
  widgets
139
86
  settings
140
87
  visibility
141
- pageType ${resourceTypeFragment()}
142
- categories ${categoryFragment()}
143
88
  tags ${tagFragment()}
89
+ categories ${categoryFragment()}
144
90
  }
145
91
  pagination ${paginationFragment()}
146
92
  }
147
93
  }
148
94
  `;
149
95
 
150
- const ArticleBySlugDocument = gql`
151
- query ArticleBySlug($input: SlugInput!) {
152
- article(input: $input) {
153
- id
154
- title
155
- slug
156
- settings
157
- widgets
158
- publishAt
159
- updatedAt
160
- websiteSettings
161
- visibility
162
- translations
163
- articleType ${resourceTypeFragment()}
164
- categories ${categoryFragment()}
165
- tags ${tagFragment()}
166
- }
167
- }
168
- `;
169
-
170
- const ArticleRevisionPreviewDocument = gql`
96
+ const ResourceRevisionPreviewDocument = gql`
171
97
  query ($input: RevisionPreviewInput!) {
172
- articleRevisionPreview(input: $input) {
173
- article {
98
+ resourceRevisionPreview(input: $input) {
99
+ resource {
174
100
  id
175
101
  title
176
102
  slug
103
+ resourceType
177
104
  settings
178
105
  widgets
179
- publishAt
180
106
  websiteSettings
107
+ createdAt
108
+ updatedAt
181
109
  visibility
182
110
  translations
183
- articleType ${resourceTypeFragment()}
184
- categories ${categoryFragment()}
185
111
  tags ${tagFragment()}
112
+ categories ${categoryFragment()}
186
113
  }
187
114
  revision ${revisionFragment()}
188
115
  }
@@ -206,71 +133,6 @@ const TagBySlugDocument = gql`
206
133
  }
207
134
  `;
208
135
 
209
- const EventsDocument = gql`
210
- query Events($input: EventsInput!) {
211
- events(input: $input) {
212
- list {
213
- id
214
- slug
215
- title
216
- widgets
217
- settings
218
- publishAt
219
- startsAt
220
- endsAt
221
- visibility
222
- eventType ${resourceTypeFragment()}
223
- categories ${categoryFragment()}
224
- tags ${tagFragment()}
225
- }
226
- pagination ${paginationFragment()}
227
- }
228
- }
229
- `;
230
-
231
- const EventBySlugDocument = gql`
232
- query EventBySlug($input: SlugInput!) {
233
- event(input: $input) {
234
- id
235
- title
236
- slug
237
- settings
238
- widgets
239
- publishAt
240
- startsAt
241
- endsAt
242
- websiteSettings
243
- visibility
244
- translations
245
- eventType ${resourceTypeFragment()}
246
- categories ${categoryFragment()}
247
- tags ${tagFragment()}
248
- }
249
- }
250
- `;
251
-
252
- const EventRevisionPreviewDocument = gql`
253
- query ($input: RevisionPreviewInput!) {
254
- eventRevisionPreview(input: $input) {
255
- event {
256
- id
257
- title
258
- slug
259
- settings
260
- widgets
261
- publishAt
262
- websiteSettings
263
- visibility
264
- translations
265
- eventType ${resourceTypeFragment()}
266
- categories ${categoryFragment()}
267
- tags ${tagFragment()}
268
- }
269
- revision ${revisionFragment()}
270
- }
271
- }
272
- `;
273
-
274
136
  const RedirectDocument = gql`
275
137
  query ($input: UrlInput!) {
276
138
  redirect(input: $input) {
@@ -283,15 +145,9 @@ const RedirectDocument = gql`
283
145
  `;
284
146
 
285
147
  export {
286
- ArticlesDocument,
287
- ArticleBySlugDocument,
288
- ArticleRevisionPreviewDocument,
289
- PagesDocument,
290
- PageBySlugDocument,
291
- PageRevisionPreviewDocument,
292
- EventsDocument,
293
- EventBySlugDocument,
294
- EventRevisionPreviewDocument,
148
+ ResourceBySlugDocument,
149
+ ResourcesDocument,
150
+ ResourceRevisionPreviewDocument,
295
151
  SettingDocument,
296
152
  CategoriesDocument,
297
153
  TagBySlugDocument,
@@ -1,30 +0,0 @@
1
- import DxpModel from "./DxpModel";
2
- import {
3
- ArticleChangePreviewDocument,
4
- MiniArticlesDocument,
5
- } from "./documents/articlesDocuments";
6
-
7
- export default class Pages extends DxpModel {
8
- async articleChangePreview(locale, id, version) {
9
- const response = await this.client.query(ArticleChangePreviewDocument, {
10
- input: {
11
- locale,
12
- articleId: id,
13
- version,
14
- },
15
- });
16
-
17
- return response?.articleChangePreview;
18
- }
19
-
20
- async miniArticles(locale, input = {}) {
21
- const response = await this.client.query(MiniArticlesDocument, {
22
- input: {
23
- locale,
24
- ...input,
25
- },
26
- });
27
-
28
- return response?.miniArticles;
29
- }
30
- }
@@ -1,30 +0,0 @@
1
- import DxpModel from "./DxpModel";
2
- import {
3
- EventChangePreviewDocument,
4
- MiniEventsDocument,
5
- } from "./documents/eventsDocuments";
6
-
7
- export default class Pages extends DxpModel {
8
- async eventChangePreview(locale, id, version) {
9
- const response = await this.client.query(EventChangePreviewDocument, {
10
- input: {
11
- locale,
12
- eventId: id,
13
- version,
14
- },
15
- });
16
-
17
- return response?.eventChangePreview;
18
- }
19
-
20
- async miniEvents(locale, input = {}) {
21
- const response = await this.client.query(MiniEventsDocument, {
22
- input: {
23
- locale,
24
- ...input,
25
- },
26
- });
27
-
28
- return response?.miniEvents;
29
- }
30
- }
@@ -1,30 +0,0 @@
1
- import DxpModel from "./DxpModel";
2
- import {
3
- PageChangePreviewDocument,
4
- MiniPagesDocument,
5
- } from "./documents/pagesDocuments";
6
-
7
- export default class Pages extends DxpModel {
8
- async pageChangePreview(locale, id, version) {
9
- const response = await this.client.query(PageChangePreviewDocument, {
10
- input: {
11
- locale,
12
- pageId: id,
13
- version,
14
- },
15
- });
16
-
17
- return response?.pageChangePreview;
18
- }
19
-
20
- async miniPages(locale, input = {}) {
21
- const response = await this.client.query(MiniPagesDocument, {
22
- input: {
23
- locale,
24
- ...input,
25
- },
26
- });
27
-
28
- return response?.miniPages;
29
- }
30
- }
@@ -1,69 +0,0 @@
1
- import { gql } from "../../graphql";
2
- import { tagFragment, categoryFragment, resourceTypeFragment } from "./common";
3
-
4
- const ArticleByIdDocument = gql`
5
- query ArticleByID($input: IdInput!) {
6
- article(input: $input) {
7
- id
8
- slug
9
- title
10
- widgets
11
- settings
12
- visibility
13
- publishAt
14
- translations
15
- tags ${tagFragment()}
16
- categories ${categoryFragment()}
17
- articleType ${resourceTypeFragment()}
18
- }
19
- }
20
- `;
21
-
22
- const ArticleChangePreviewDocument = gql`
23
- query ($input: ArticleChangePreviewInput!) {
24
- articleChangePreview(input: $input) {
25
- article {
26
- id
27
- slug
28
- title
29
- widgets
30
- settings
31
- visibility
32
- publishAt
33
- translations
34
- websiteSettings
35
- tags ${tagFragment()}
36
- categories ${categoryFragment()}
37
- articleType ${resourceTypeFragment()}
38
- }
39
- articleChange {
40
- version
41
- title
42
- description
43
- operator
44
- operatorMeta
45
- source
46
- insertedAt
47
- }
48
- }
49
- }
50
- `;
51
-
52
- const MiniArticlesDocument = gql`
53
- query ($input: ArticlesInput!) {
54
- miniArticles(input: $input) {
55
- list {
56
- id
57
- slug
58
- title
59
- visibility
60
- }
61
- }
62
- }
63
- `;
64
-
65
- export {
66
- ArticleByIdDocument,
67
- ArticleChangePreviewDocument,
68
- MiniArticlesDocument,
69
- };
@@ -1,69 +0,0 @@
1
- import { gql } from "../../graphql";
2
- import { tagFragment, categoryFragment, resourceTypeFragment } from "./common";
3
-
4
- const EventByIdDocument = gql`
5
- query EventByID($input: IdInput!) {
6
- event(input: $input) {
7
- id
8
- slug
9
- title
10
- widgets
11
- settings
12
- visibility
13
- publishAt
14
- startsAt
15
- endsAt
16
- translations
17
- tags ${tagFragment()}
18
- categories ${categoryFragment()}
19
- eventType ${resourceTypeFragment()}
20
- }
21
- }
22
- `;
23
-
24
- const EventChangePreviewDocument = gql`
25
- query ($input: EventChangePreviewInput!) {
26
- eventChangePreview(input: $input) {
27
- event {
28
- id
29
- slug
30
- title
31
- widgets
32
- settings
33
- visibility
34
- publishAt
35
- startsAt
36
- endsAt
37
- translations
38
- websiteSettings
39
- tags ${tagFragment()}
40
- categories ${categoryFragment()}
41
- eventType ${resourceTypeFragment()}
42
- }
43
- eventChange {
44
- version
45
- title
46
- description
47
- operator
48
- operatorMeta
49
- source
50
- insertedAt
51
- }
52
- }
53
- }
54
- `;
55
-
56
- const MiniEventsDocument = gql`
57
- query ($input: EventsInput!) {
58
- miniEvents(input: $input) {
59
- list {
60
- id
61
- slug
62
- title
63
- visibility
64
- }
65
- }
66
- }
67
- `;
68
-
69
- export { EventByIdDocument, EventChangePreviewDocument, MiniEventsDocument };
@@ -1,39 +0,0 @@
1
- import DxpModel from "./DxpModel";
2
- import { ArticleBySlugDocument, ArticlesDocument } from "./documents";
3
-
4
- export default class Articles extends DxpModel {
5
- async find(locale, slug, resourceType = null, opts = {}) {
6
- const response = await this.fetch(
7
- `article-${locale}-${slug}`,
8
- async () =>
9
- await this.client.query(
10
- ArticleBySlugDocument,
11
- {
12
- input: {
13
- locale,
14
- slug,
15
- resourceType
16
- },
17
- },
18
- opts
19
- ),
20
- opts
21
- );
22
-
23
- return response?.article;
24
- }
25
-
26
- async list(locale, input = {}, opts = {}) {
27
- const response = await this.fetch(
28
- `articles-${locale}-${JSON.stringify(input)}`,
29
- async () =>
30
- await this.client.query(
31
- ArticlesDocument,
32
- this.formatPaginationInInput(locale, input),
33
- opts
34
- )
35
- );
36
-
37
- return response?.articles;
38
- }
39
- }
@@ -1,39 +0,0 @@
1
- import DxpModel from "./DxpModel";
2
- import { EventBySlugDocument, EventsDocument } from "./documents";
3
-
4
- export default class Events extends DxpModel {
5
- async find(locale, slug, resourceType = null, opts = {}) {
6
- const response = await this.fetch(
7
- `event-${locale}-${slug}`,
8
- async () =>
9
- await this.client.query(
10
- EventBySlugDocument,
11
- {
12
- input: {
13
- locale,
14
- slug,
15
- resourceType
16
- },
17
- },
18
- opts
19
- ),
20
- opts
21
- );
22
-
23
- return response?.event;
24
- }
25
-
26
- async list(locale, input = {}, opts = {}) {
27
- const response = await this.fetch(
28
- `events-${locale}-${JSON.stringify(input)}`,
29
- async () =>
30
- await this.client.query(
31
- EventsDocument,
32
- this.formatPaginationInInput(locale, input),
33
- opts
34
- )
35
- );
36
-
37
- return response?.events;
38
- }
39
- }