@omerlo/omerlo-webkit 0.0.5 → 0.0.7
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/README.md +0 -2
- package/dist/omerlo/index.d.ts +32 -6
- package/dist/omerlo/reader/endpoints/categories.d.ts +1 -1
- package/dist/omerlo/reader/endpoints/categories.js +16 -13
- package/dist/omerlo/reader/endpoints/content-templates.d.ts +9 -2
- package/dist/omerlo/reader/endpoints/content-templates.js +34 -1
- package/dist/omerlo/reader/endpoints/contents.d.ts +98 -27
- package/dist/omerlo/reader/endpoints/contents.js +187 -2
- package/dist/omerlo/reader/endpoints/events.d.ts +32 -0
- package/dist/omerlo/reader/endpoints/events.js +45 -0
- package/dist/omerlo/reader/endpoints/magazines.d.ts +104 -0
- package/dist/omerlo/reader/endpoints/magazines.js +135 -0
- package/dist/omerlo/reader/endpoints/media.d.ts +65 -0
- package/dist/omerlo/reader/endpoints/media.js +133 -0
- package/dist/omerlo/reader/endpoints/menu.d.ts +31 -0
- package/dist/omerlo/reader/endpoints/menu.js +49 -0
- package/dist/omerlo/reader/endpoints/notification.js +1 -1
- package/dist/omerlo/reader/endpoints/organizations.d.ts +40 -0
- package/dist/omerlo/reader/endpoints/organizations.js +72 -0
- package/dist/omerlo/reader/endpoints/person.d.ts +30 -0
- package/dist/omerlo/reader/endpoints/person.js +39 -0
- package/dist/omerlo/reader/endpoints/profileType.d.ts +27 -0
- package/dist/omerlo/reader/endpoints/profileType.js +28 -0
- package/dist/omerlo/reader/endpoints/profiles.d.ts +70 -0
- package/dist/omerlo/reader/endpoints/profiles.js +97 -0
- package/dist/omerlo/reader/endpoints/projects.d.ts +28 -0
- package/dist/omerlo/reader/endpoints/projects.js +37 -0
- package/dist/omerlo/reader/endpoints/visuals.d.ts +28 -10
- package/dist/omerlo/reader/endpoints/visuals.js +44 -1
- package/dist/omerlo/reader/endpoints/webpage.d.ts +20 -0
- package/dist/omerlo/reader/endpoints/webpage.js +21 -0
- package/dist/omerlo/reader/fetchers.d.ts +26 -0
- package/dist/omerlo/reader/fetchers.js +11 -1
- package/dist/omerlo/reader/index.d.ts +18 -1
- package/dist/omerlo/reader/index.js +18 -0
- package/dist/omerlo/reader/server/email.d.ts +4 -4
- package/dist/omerlo/reader/server/email.js +5 -5
- package/dist/omerlo/reader/server/hooks.js +17 -3
- package/dist/omerlo/reader/utils/api.d.ts +1 -1
- package/dist/omerlo/reader/utils/api.js +4 -3
- package/dist/omerlo/reader/utils/assocs.d.ts +5 -4
- package/dist/omerlo/reader/utils/assocs.js +23 -0
- package/dist/omerlo/reader/utils/parseHelpers.d.ts +7 -0
- package/dist/omerlo/reader/utils/parseHelpers.js +22 -0
- package/eslint.config.js +10 -1
- package/package.json +2 -1
package/README.md
CHANGED
package/dist/omerlo/index.d.ts
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
export declare const useReader: (f: typeof fetch) => {
|
|
2
2
|
notifications: {
|
|
3
|
-
listTopics: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader
|
|
4
|
-
subscribeToTopic: (params: import("./reader
|
|
5
|
-
unsubscribeFromTopic: (params: import("./reader
|
|
3
|
+
listTopics: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").TopicSummary[]>>;
|
|
4
|
+
subscribeToTopic: (params: import("./reader").SubscriptionParams) => Promise<import("./reader/utils/api").ApiResponse<unknown>>;
|
|
5
|
+
unsubscribeFromTopic: (params: import("./reader").SubscriptionParams) => Promise<import("./reader/utils/api").ApiResponse<unknown>>;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
magazines: {
|
|
8
|
+
getIssue: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Issue>>;
|
|
9
|
+
getBlocks: (sectionId: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").IssueBlock[]>>;
|
|
10
|
+
searchContents: (issueId: string, q: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").SectionContent[]>>;
|
|
11
|
+
getSectionContents: (sectionId: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Content[]>>;
|
|
12
|
+
};
|
|
13
|
+
getMenu: (key: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Menu>>;
|
|
14
|
+
listMenus: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").MenuSummary[]>>;
|
|
15
|
+
listOrganizations: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OrganizationSummary[]>>;
|
|
16
|
+
getOrganization: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Organization>>;
|
|
17
|
+
getOrgWebpage: (slug: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OrgWebpage>>;
|
|
18
|
+
listOrgWebpages: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").WebpageSummary[]>>;
|
|
19
|
+
getMedia: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Media>>;
|
|
20
|
+
getMediaOrganization: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Organization>>;
|
|
21
|
+
listMediaOrganizations: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OrganizationSummary[]>>;
|
|
22
|
+
getMediaEvent: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Event>>;
|
|
23
|
+
listMediaEvents: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").EventSummary[]>>;
|
|
24
|
+
listMediaEventBlocks: (id: string, params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").ProfileBlockKind[]>>;
|
|
25
|
+
getMediaPerson: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Person>>;
|
|
26
|
+
listMediaPersons: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").PersonSummary[]>>;
|
|
27
|
+
getMediaProject: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Project>>;
|
|
28
|
+
listMediaProjects: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").ProjectSummary[]>>;
|
|
29
|
+
getMediaProfileType: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").ProfileType>>;
|
|
30
|
+
listMediaProfileTypes: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").ProfileTypeSummary[]>>;
|
|
31
|
+
getContent: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Content>>;
|
|
32
|
+
listContents: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").ContentSummary[]>>;
|
|
33
|
+
listCategories: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Category[]>>;
|
|
34
|
+
getCategory: (id: string) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").Category>>;
|
|
9
35
|
listOauthProviders: (params?: Partial<import("./reader/utils/api").PagingParams>) => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OauthProviderSummary[]>>;
|
|
10
36
|
getOauthUser: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OauthUser>>;
|
|
11
|
-
registerDevice: (params: import("./reader
|
|
37
|
+
registerDevice: (params: import("./reader").DeviceParams) => Promise<import("./reader/utils/api").ApiResponse<unknown>>;
|
|
12
38
|
userInfo: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").UserInfo>>;
|
|
13
39
|
verifyAccount: (params: import("./reader").VerifyAccountParams) => void;
|
|
14
40
|
validateAccount: (params: import("./reader").ValidateAccountParams) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {} from '../utils/response';
|
|
1
|
+
import { parseLocalesMetadata } from '../utils/response';
|
|
2
2
|
import { parseMany } from '../utils/api';
|
|
3
3
|
import { requestPublisher } from '../utils/request';
|
|
4
|
+
import { buildMeta } from '../utils/parseHelpers';
|
|
4
5
|
export const categoriesFetchers = (f) => {
|
|
5
6
|
return {
|
|
6
7
|
listCategories: listCategories(f),
|
|
@@ -10,27 +11,29 @@ export const categoriesFetchers = (f) => {
|
|
|
10
11
|
export function getCategory(f) {
|
|
11
12
|
return async (id) => {
|
|
12
13
|
const opts = { parser: parseCategory };
|
|
13
|
-
return requestPublisher(f,
|
|
14
|
+
return requestPublisher(f, `media/categories/${id}`, opts);
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
export function listCategories(f) {
|
|
17
18
|
return async (params) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
return requestPublisher(f, `/categories`, opts);
|
|
19
|
+
const opts = { parser: parseMany(parseCategory), queryParams: params };
|
|
20
|
+
return requestPublisher(f, `media/categories`, opts);
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
export function parseCategory(data, _assoc) {
|
|
24
|
+
let meta;
|
|
25
|
+
// NOTE: this is to support publisher public api v2 but also reader api v1
|
|
26
|
+
if (data.meta) {
|
|
27
|
+
meta = { locales: parseLocalesMetadata(data.meta) };
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
meta = buildMeta(data.localized.locale);
|
|
31
|
+
}
|
|
24
32
|
return {
|
|
25
33
|
id: data.id,
|
|
34
|
+
name: data.name,
|
|
26
35
|
svg: data.svg_icon,
|
|
27
|
-
|
|
28
|
-
updatedAt: data.updated_at
|
|
29
|
-
meta: {
|
|
30
|
-
locale: {
|
|
31
|
-
available: [data.localized.locale],
|
|
32
|
-
current: data.localized.locale
|
|
33
|
-
}
|
|
34
|
-
}
|
|
36
|
+
meta,
|
|
37
|
+
updatedAt: data.updated_at
|
|
35
38
|
};
|
|
36
39
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalesMetadata } from '../utils/response';
|
|
2
|
+
import type { ApiAssocs, ApiData } from '../utils/api';
|
|
2
3
|
export interface ContentTemplate {
|
|
3
4
|
id: string;
|
|
4
5
|
key: string;
|
|
@@ -7,10 +8,16 @@ export interface ContentTemplate {
|
|
|
7
8
|
locales: LocalesMetadata;
|
|
8
9
|
};
|
|
9
10
|
metadata: Record<string, string>;
|
|
10
|
-
|
|
11
|
+
enabledFields: string[];
|
|
11
12
|
updatedAt: Date;
|
|
12
13
|
}
|
|
13
14
|
export interface ContentBlockTemplate {
|
|
14
15
|
id: string;
|
|
15
16
|
key: string;
|
|
17
|
+
visual: {
|
|
18
|
+
allowedTypes: string[];
|
|
19
|
+
isEnabled: boolean;
|
|
20
|
+
};
|
|
16
21
|
}
|
|
22
|
+
export declare function parseContentBlockTemplate(data: ApiData, _assocs: ApiAssocs): ContentBlockTemplate;
|
|
23
|
+
export declare function parseContentTemplate(data: ApiData, _assocs: ApiAssocs): ContentTemplate;
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import { parseLocalesMetadata } from '../utils/response';
|
|
2
|
+
import { buildMeta } from '../utils/parseHelpers';
|
|
3
|
+
export function parseContentBlockTemplate(data, _assocs) {
|
|
4
|
+
return {
|
|
5
|
+
id: data.id,
|
|
6
|
+
key: data.key,
|
|
7
|
+
visual: {
|
|
8
|
+
allowedTypes: data.visual.allowed_types,
|
|
9
|
+
isEnabled: data.visual.is_enabled
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function parseContentTemplate(data, _assocs) {
|
|
14
|
+
let name;
|
|
15
|
+
let meta;
|
|
16
|
+
if (data.localized) {
|
|
17
|
+
// NOTE: this is for retrocompatibility with public publisher api v2
|
|
18
|
+
name = data.localized.name;
|
|
19
|
+
meta = buildMeta(data.localized.locale);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
name = data.name;
|
|
23
|
+
meta = { locales: parseLocalesMetadata(data.meta) };
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
id: data.id,
|
|
27
|
+
key: data.key,
|
|
28
|
+
name,
|
|
29
|
+
meta,
|
|
30
|
+
metadata: data.metadata,
|
|
31
|
+
enabledFields: data.enabled_fields,
|
|
32
|
+
updatedAt: data.updated_at
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,51 +1,122 @@
|
|
|
1
|
-
import type { LocalesMetadata } from '../utils/response';
|
|
2
1
|
import type { Category } from './categories';
|
|
3
2
|
import type { ContentBlockTemplate, ContentTemplate } from './content-templates';
|
|
4
|
-
import type
|
|
3
|
+
import { type Visual, type Slideshow, type Image, type Video } from './visuals';
|
|
4
|
+
import { type ApiAssocs, type ApiData, type PagingParams } from '../utils/api';
|
|
5
|
+
import { type LocalesMetadata } from '../utils/response';
|
|
6
|
+
import type { PersonSummary } from './person';
|
|
7
|
+
import type { OrganizationSummary } from './organizations';
|
|
8
|
+
export declare const contentsFetchers: (f: typeof fetch) => {
|
|
9
|
+
getContent: (id: string) => Promise<import("../utils/api").ApiResponse<Content>>;
|
|
10
|
+
listContents: (params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<ContentSummary[]>>;
|
|
11
|
+
};
|
|
12
|
+
export interface ContentSeo {
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
5
16
|
export interface ContentSummary {
|
|
6
17
|
id: string;
|
|
7
18
|
template: ContentTemplate;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
publishedAt?: Date;
|
|
13
|
-
visibility?: string;
|
|
19
|
+
canonicalDomain: string | null;
|
|
20
|
+
canonicalUrl: string | null;
|
|
21
|
+
publishedAt: Date | null;
|
|
22
|
+
visibility: string | null;
|
|
14
23
|
categories: Category[];
|
|
15
|
-
|
|
24
|
+
showPublishedAt: boolean;
|
|
16
25
|
updatedAt: Date;
|
|
26
|
+
titleHtml: string;
|
|
27
|
+
titleText: string;
|
|
28
|
+
leadHtml: string | null;
|
|
29
|
+
leadText: string | null;
|
|
30
|
+
subtitleHtml: string | null;
|
|
31
|
+
subtitleText: string | null;
|
|
32
|
+
visual: Visual | null;
|
|
17
33
|
meta: {
|
|
18
34
|
locales: LocalesMetadata;
|
|
19
35
|
};
|
|
20
|
-
|
|
21
|
-
titleText: string;
|
|
22
|
-
leadHtml: string;
|
|
23
|
-
leadText: string;
|
|
24
|
-
subtitleHtml: string;
|
|
25
|
-
subtitleText: string;
|
|
26
|
-
visual: Visual;
|
|
27
|
-
seo: ContentSeo;
|
|
28
|
-
}
|
|
29
|
-
export interface ContentSeo {
|
|
30
|
-
title: string;
|
|
31
|
-
description: string;
|
|
36
|
+
authors: (PersonSummary | OrganizationSummary)[];
|
|
32
37
|
}
|
|
33
38
|
export interface Content extends ContentSummary {
|
|
39
|
+
metadata: Record<string, string>;
|
|
34
40
|
blocks: ContentBlock[];
|
|
35
41
|
}
|
|
36
|
-
export type ContentBlock = ContentBlockRichtext | ContentBlockData;
|
|
37
42
|
export type ContentBlockRichtext = {
|
|
38
43
|
id: string;
|
|
39
|
-
template: ContentBlockTemplate;
|
|
40
|
-
visual?: Visual;
|
|
41
44
|
kind: 'richtext';
|
|
42
45
|
contentHtml: string;
|
|
46
|
+
visual: Visual | null;
|
|
47
|
+
template: ContentBlockTemplate | null;
|
|
43
48
|
};
|
|
44
49
|
export type ContentBlockData = {
|
|
45
50
|
id: string;
|
|
46
|
-
template: ContentBlockTemplate;
|
|
47
|
-
visual?: Visual;
|
|
48
51
|
kind: 'data';
|
|
49
52
|
contentType: string;
|
|
50
|
-
data:
|
|
53
|
+
data: string;
|
|
54
|
+
visual: Visual | null;
|
|
55
|
+
template: ContentBlockTemplate | null;
|
|
56
|
+
};
|
|
57
|
+
export type ContentBlockHTML = {
|
|
58
|
+
id: string;
|
|
59
|
+
kind: 'html';
|
|
60
|
+
contentHtml: string;
|
|
61
|
+
visual: Visual | null;
|
|
62
|
+
template: ContentBlockTemplate | null;
|
|
63
|
+
};
|
|
64
|
+
export type ContentBlockQuote = {
|
|
65
|
+
id: string;
|
|
66
|
+
kind: 'quote';
|
|
67
|
+
quoteHtml: string;
|
|
68
|
+
quoteText: string;
|
|
69
|
+
author: string;
|
|
70
|
+
visual: Visual | null;
|
|
71
|
+
template: ContentBlockTemplate | null;
|
|
72
|
+
};
|
|
73
|
+
export type ContentBlockRelatedContents = {
|
|
74
|
+
id: string;
|
|
75
|
+
kind: 'related-contents';
|
|
76
|
+
contents: Content[];
|
|
77
|
+
visual: Visual | null;
|
|
78
|
+
template: ContentBlockTemplate | null;
|
|
79
|
+
};
|
|
80
|
+
export type Answer = {
|
|
81
|
+
id: string;
|
|
82
|
+
contentHtml: string;
|
|
83
|
+
contentText: string;
|
|
84
|
+
};
|
|
85
|
+
export type ContentBlockQuestion = {
|
|
86
|
+
id: string;
|
|
87
|
+
kind: 'question';
|
|
88
|
+
questionHtml: string;
|
|
89
|
+
questionText: string;
|
|
90
|
+
acceptVoteUntil: Date;
|
|
91
|
+
answers: Answer[];
|
|
92
|
+
visual: Visual | null;
|
|
93
|
+
template: ContentBlockTemplate | null;
|
|
94
|
+
};
|
|
95
|
+
export type ContentBlockImage = {
|
|
96
|
+
id: string;
|
|
97
|
+
kind: 'image';
|
|
98
|
+
image: Image;
|
|
99
|
+
visual: Visual | null;
|
|
100
|
+
template: ContentBlockTemplate | null;
|
|
101
|
+
};
|
|
102
|
+
export type ContentBlockSlideshow = {
|
|
103
|
+
id: string;
|
|
104
|
+
kind: 'slideshow';
|
|
105
|
+
slideshow: Slideshow;
|
|
106
|
+
visual: Visual | null;
|
|
107
|
+
template: ContentBlockTemplate | null;
|
|
108
|
+
};
|
|
109
|
+
export type ContentBlockVideo = {
|
|
110
|
+
id: string;
|
|
111
|
+
kind: 'video';
|
|
112
|
+
video: Video;
|
|
113
|
+
visual: Visual | null;
|
|
114
|
+
template: ContentBlockTemplate | null;
|
|
51
115
|
};
|
|
116
|
+
export type ContentBlock = ContentBlockRichtext | ContentBlockData | ContentBlockHTML | ContentBlockQuote | ContentBlockRelatedContents | ContentBlockQuestion | ContentBlockImage | ContentBlockSlideshow | ContentBlockVideo;
|
|
117
|
+
export type ContentBlockType = 'richtext' | 'data' | 'html' | 'quote' | 'related-contents' | 'question' | 'image' | 'slideshow' | 'video';
|
|
118
|
+
export declare function getContent(f: typeof fetch): (id: string) => Promise<import("../utils/api").ApiResponse<Content>>;
|
|
119
|
+
export declare function listContents(f: typeof fetch): (params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<ContentSummary[]>>;
|
|
120
|
+
export declare function parseContentSummary(data: ApiData, assocs: ApiAssocs): ContentSummary;
|
|
121
|
+
export declare function parseContent(data: ApiData, assocs: ApiAssocs): Content;
|
|
122
|
+
export declare function parseContentBlock(block: ApiData, assocs: ApiAssocs): ContentBlock | null;
|
|
@@ -1,2 +1,187 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { parseVideo, parseImage, parseSlideshow, parseVisual } from './visuals';
|
|
2
|
+
import { requestPublisher } from '../utils/request';
|
|
3
|
+
import { parseMany } from '../utils/api';
|
|
4
|
+
import { getAssoc, getAssocs } from '../utils/assocs';
|
|
5
|
+
import { parseLocalesMetadata } from '../utils/response';
|
|
6
|
+
import { buildMeta, parseDate } from '../utils/parseHelpers';
|
|
7
|
+
export const contentsFetchers = (f) => {
|
|
8
|
+
return {
|
|
9
|
+
getContent: getContent(f),
|
|
10
|
+
listContents: listContents(f)
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
function baseBlock(data, assocs) {
|
|
14
|
+
return {
|
|
15
|
+
id: data.id,
|
|
16
|
+
kind: data.kind,
|
|
17
|
+
template: getBlockTemplate(data, assocs),
|
|
18
|
+
visual: parseVisual(data.visual, assocs)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function getContent(f) {
|
|
22
|
+
return async (id) => {
|
|
23
|
+
const opts = { parser: parseContent };
|
|
24
|
+
return requestPublisher(f, `media/contents/${id}`, opts);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function listContents(f) {
|
|
28
|
+
return async (params) => {
|
|
29
|
+
const opts = { parser: parseMany(parseContentSummary), queryParams: params };
|
|
30
|
+
return requestPublisher(f, `media/contents`, opts);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function parseContentSummary(data, assocs) {
|
|
34
|
+
if (data.localized) {
|
|
35
|
+
// NOTE: This is to support publisher public api v2
|
|
36
|
+
return {
|
|
37
|
+
id: data.id,
|
|
38
|
+
template: getAssoc(assocs, 'templates', data.template_id),
|
|
39
|
+
canonicalDomain: data.canonical_domain,
|
|
40
|
+
canonicalUrl: data.canonical_url,
|
|
41
|
+
publishedAt: parseDate(data.published_at),
|
|
42
|
+
visibility: data.visibility,
|
|
43
|
+
categories: getAssocs(assocs, 'categories', data.category_ids),
|
|
44
|
+
showPublishedAt: data.show_published_at,
|
|
45
|
+
updatedAt: new Date(data.updated_at),
|
|
46
|
+
titleHtml: data.localized.title_html,
|
|
47
|
+
titleText: data.localized.title_text,
|
|
48
|
+
leadHtml: data.localized.lead_html,
|
|
49
|
+
leadText: data.localized.lead_text,
|
|
50
|
+
subtitleHtml: data.localized.subtitle_html,
|
|
51
|
+
subtitleText: data.localized.subtitle_text,
|
|
52
|
+
visual: parseVisual(data.visual, assocs),
|
|
53
|
+
meta: buildMeta(data.localized.locale),
|
|
54
|
+
authors: getAssocs(assocs, 'profiles', data.localized.author_ids)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return {
|
|
59
|
+
id: data.id,
|
|
60
|
+
template: getAssoc(assocs, 'content_templates', data.template_id),
|
|
61
|
+
canonicalDomain: data.canonical_domain,
|
|
62
|
+
canonicalUrl: data.canonical_url,
|
|
63
|
+
publishedAt: parseDate(data.published_at),
|
|
64
|
+
visibility: data.visibility,
|
|
65
|
+
categories: getAssocs(assocs, 'categories', data.category_ids),
|
|
66
|
+
showPublishedAt: data.show_published_at,
|
|
67
|
+
updatedAt: new Date(data.updated_at),
|
|
68
|
+
titleHtml: data.title_html,
|
|
69
|
+
titleText: data.title_text,
|
|
70
|
+
leadHtml: data.lead_html,
|
|
71
|
+
leadText: data.lead_text,
|
|
72
|
+
subtitleHtml: data.subtitle_html,
|
|
73
|
+
subtitleText: data.subtitle_text,
|
|
74
|
+
visual: parseVisual(data.visual, assocs),
|
|
75
|
+
meta: { locales: parseLocalesMetadata(data.meta) },
|
|
76
|
+
authors: getAssocs(assocs, 'profiles', data.author_ids)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function parseContent(data, assocs) {
|
|
81
|
+
let seo;
|
|
82
|
+
if (data.localized) {
|
|
83
|
+
seo = { title: data.localized.seo.title, description: data.localized.seo.description };
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
seo = { title: data.seo.title, description: data.seo.description };
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
...parseContentSummary(data, assocs),
|
|
90
|
+
metadata: data.metadata,
|
|
91
|
+
seo,
|
|
92
|
+
blocks: data.localized.blocks
|
|
93
|
+
.map((block) => parseContentBlock(block, assocs))
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const ContentBlockParser = {
|
|
98
|
+
richtext: parseContentBlockRichtext,
|
|
99
|
+
data: parseContentBlockData,
|
|
100
|
+
html: parseContentBlockHTML,
|
|
101
|
+
quote: parseContentBlockQuote,
|
|
102
|
+
'related-contents': parseContentBlockRelatedContents,
|
|
103
|
+
question: parseContentBlockQuestion,
|
|
104
|
+
image: parseContentBlockImage,
|
|
105
|
+
slideshow: parseContentBlockSlideshow,
|
|
106
|
+
video: parseContentBlockVideo
|
|
107
|
+
};
|
|
108
|
+
export function parseContentBlock(block, assocs) {
|
|
109
|
+
const parser = ContentBlockParser[block.kind];
|
|
110
|
+
return parser ? parser(block, assocs) : null;
|
|
111
|
+
}
|
|
112
|
+
function getBlockTemplate(data, assocs) {
|
|
113
|
+
return data.template_id
|
|
114
|
+
? getAssoc(assocs, 'block_templates', data.template_id)
|
|
115
|
+
: null;
|
|
116
|
+
}
|
|
117
|
+
function getBlockContent(data, assocs) {
|
|
118
|
+
return data.related_contents ? getAssocs(assocs, 'contents', data.related_contents) : [];
|
|
119
|
+
}
|
|
120
|
+
function parseContentBlockRichtext(data, assocs) {
|
|
121
|
+
return {
|
|
122
|
+
...baseBlock(data, assocs),
|
|
123
|
+
contentHtml: data.content_html
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function parseContentBlockData(data, assocs) {
|
|
127
|
+
return {
|
|
128
|
+
...baseBlock(data, assocs),
|
|
129
|
+
contentType: data.content_type,
|
|
130
|
+
data: data.data
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function parseContentBlockHTML(data, assocs) {
|
|
134
|
+
return {
|
|
135
|
+
...baseBlock(data, assocs),
|
|
136
|
+
contentHtml: data.content_html
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function parseContentBlockQuote(data, assocs) {
|
|
140
|
+
return {
|
|
141
|
+
...baseBlock(data, assocs),
|
|
142
|
+
quoteHtml: data.quote_html,
|
|
143
|
+
quoteText: data.quote_text,
|
|
144
|
+
author: data.author
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function parseContentBlockRelatedContents(data, assocs) {
|
|
148
|
+
const contents = getBlockContent(data, assocs);
|
|
149
|
+
return {
|
|
150
|
+
...baseBlock(data, assocs),
|
|
151
|
+
contents
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function parseContentBlockQuestion(data, assocs) {
|
|
155
|
+
return {
|
|
156
|
+
...baseBlock(data, assocs),
|
|
157
|
+
questionHtml: data.question_html,
|
|
158
|
+
questionText: data.question_text,
|
|
159
|
+
acceptVoteUntil: new Date(data.accept_vote_until),
|
|
160
|
+
answers: data.answers?.map((answer) => parseAnswer(answer)) || []
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function parseAnswer(data) {
|
|
164
|
+
return {
|
|
165
|
+
id: data.id,
|
|
166
|
+
contentHtml: data.content_html,
|
|
167
|
+
contentText: data.content_text
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function parseContentBlockImage(data, assocs) {
|
|
171
|
+
return {
|
|
172
|
+
...baseBlock(data, assocs),
|
|
173
|
+
image: parseImage(data.image, assocs)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function parseContentBlockSlideshow(data, assocs) {
|
|
177
|
+
return {
|
|
178
|
+
...baseBlock(data, assocs),
|
|
179
|
+
slideshow: parseSlideshow(data.slideshow, assocs)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function parseContentBlockVideo(data, assocs) {
|
|
183
|
+
return {
|
|
184
|
+
...baseBlock(data, assocs),
|
|
185
|
+
video: parseVideo(data.video, assocs)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Category } from './categories';
|
|
2
|
+
import { type ApiAssocs, type ApiData } from '../utils/api';
|
|
3
|
+
import type { LocalesMetadata } from '../utils/response';
|
|
4
|
+
import type { ProfileType } from './profileType';
|
|
5
|
+
import type { ProfileAddress, ProfileContact, ProfileDescription } from './profiles';
|
|
6
|
+
export interface EventSummary {
|
|
7
|
+
id: string;
|
|
8
|
+
profileType: ProfileType;
|
|
9
|
+
kind: string;
|
|
10
|
+
type: string;
|
|
11
|
+
isAllDay: boolean;
|
|
12
|
+
profileImageURL: string | null;
|
|
13
|
+
coverImageURL: string | null;
|
|
14
|
+
subscriptionURL: string | null;
|
|
15
|
+
meta: {
|
|
16
|
+
locales: LocalesMetadata;
|
|
17
|
+
};
|
|
18
|
+
name: string | null;
|
|
19
|
+
summaryHtml: string | null;
|
|
20
|
+
summaryText: string | null;
|
|
21
|
+
startsAt: Date | null;
|
|
22
|
+
endsAt: Date | null;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface Event extends EventSummary {
|
|
26
|
+
categories: Category[];
|
|
27
|
+
address: ProfileAddress | null;
|
|
28
|
+
contact: ProfileContact | null;
|
|
29
|
+
description: ProfileDescription | null;
|
|
30
|
+
}
|
|
31
|
+
export declare function parseEventSummary(data: ApiData, assocs: ApiAssocs): EventSummary;
|
|
32
|
+
export declare function parseEvent(data: ApiData, assocs: ApiAssocs): Event;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {} from '../utils/api';
|
|
2
|
+
import { getAssoc, getAssocs } from '../utils/assocs';
|
|
3
|
+
import { parseDate } from '../utils/parseHelpers';
|
|
4
|
+
import { parseProfileAddress, parseProfileContact, parseProfileDescription } from './profiles';
|
|
5
|
+
import { buildMeta } from '../utils/parseHelpers';
|
|
6
|
+
export function parseEventSummary(data, assocs) {
|
|
7
|
+
const name = data.localized?.name || null;
|
|
8
|
+
const summaryHtml = data.localized?.summary_html || null;
|
|
9
|
+
const summaryText = data.localized?.summary_text || null;
|
|
10
|
+
return {
|
|
11
|
+
id: data.id,
|
|
12
|
+
profileType: getAssoc(assocs, 'profile_types', data.profile_type_id),
|
|
13
|
+
kind: 'event',
|
|
14
|
+
type: data.type,
|
|
15
|
+
isAllDay: data.is_all_day,
|
|
16
|
+
profileImageURL: data.logo_image_url,
|
|
17
|
+
coverImageURL: data.cover_image_url,
|
|
18
|
+
subscriptionURL: data.subscription_url,
|
|
19
|
+
name,
|
|
20
|
+
summaryHtml,
|
|
21
|
+
summaryText,
|
|
22
|
+
meta: buildMeta(data.localized?.locale),
|
|
23
|
+
startsAt: parseDate(data.starts_at),
|
|
24
|
+
endsAt: parseDate(data.ends_at),
|
|
25
|
+
updatedAt: new Date(data.updated_at)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function parseEvent(data, assocs) {
|
|
29
|
+
const address = data.localized_address
|
|
30
|
+
? parseProfileAddress(data.localized_address, assocs)
|
|
31
|
+
: null;
|
|
32
|
+
const contact = data.localized_contact
|
|
33
|
+
? parseProfileContact(data.localized_contact, assocs)
|
|
34
|
+
: null;
|
|
35
|
+
const description = data.localized_description
|
|
36
|
+
? parseProfileDescription(data.localized_description, assocs)
|
|
37
|
+
: null;
|
|
38
|
+
return {
|
|
39
|
+
...parseEventSummary(data, assocs),
|
|
40
|
+
categories: getAssocs(assocs, 'categories', data.category_ids),
|
|
41
|
+
address,
|
|
42
|
+
contact,
|
|
43
|
+
description
|
|
44
|
+
};
|
|
45
|
+
}
|