@omerlo/omerlo-webkit 0.0.36 → 0.0.38
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/dist/omerlo/reader/endpoints/distributions.d.ts +15 -2
- package/dist/omerlo/reader/endpoints/distributions.js +28 -5
- package/dist/omerlo/reader/endpoints/magazines.js +36 -16
- package/dist/omerlo/reader/endpoints/media.d.ts +4 -1
- package/dist/omerlo/reader/endpoints/media.js +6 -1
- package/dist/omerlo/reader/stores/user_session.js +5 -7
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ApiAssocs, type ApiData, type PagingParams } from '../utils/api';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LocalesMetadata } from '../utils/response';
|
|
3
|
+
import { type IssueSummary } from './magazines';
|
|
4
|
+
import { type Visual } from './visuals';
|
|
3
5
|
export declare const distributionFetchers: (f: typeof fetch) => {
|
|
4
6
|
listReleases: (distributionId: string, params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<Release[]>>;
|
|
5
7
|
};
|
|
@@ -9,6 +11,17 @@ export interface Release {
|
|
|
9
11
|
issue: IssueSummary;
|
|
10
12
|
startsAt: Date;
|
|
11
13
|
endsAt: Date | null;
|
|
12
|
-
updatedAt: Date;
|
|
13
14
|
}
|
|
14
15
|
export declare function parseRelease(data: ApiData, assocs: ApiAssocs): Release;
|
|
16
|
+
export interface Distribution {
|
|
17
|
+
id: string;
|
|
18
|
+
meta: {
|
|
19
|
+
locales: LocalesMetadata;
|
|
20
|
+
};
|
|
21
|
+
name: string;
|
|
22
|
+
visual: Visual | null;
|
|
23
|
+
metadata: {
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function parseDistribution(data: ApiData, assocs: ApiAssocs): Distribution;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { parseMany } from '../utils/api';
|
|
2
2
|
import { getAssoc } from '../utils/assocs';
|
|
3
|
-
import { parseDate } from '../utils/parseHelpers';
|
|
3
|
+
import { buildMeta, parseDate } from '../utils/parseHelpers';
|
|
4
4
|
import { request } from '../utils/request';
|
|
5
|
+
import { parseIssueSummary } from './magazines';
|
|
6
|
+
import { parseVisual } from './visuals';
|
|
5
7
|
export const distributionFetchers = (f) => {
|
|
6
8
|
return {
|
|
7
9
|
listReleases: releasesFetcher(f)
|
|
@@ -14,12 +16,33 @@ export function releasesFetcher(f) {
|
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
export function parseRelease(data, assocs) {
|
|
19
|
+
let issue;
|
|
20
|
+
// NOTE for retro compatibility
|
|
21
|
+
if (data.issue) {
|
|
22
|
+
issue = parseIssueSummary(data.issue, assocs);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
issue = getAssoc(assocs, 'issues', data.issue_id);
|
|
26
|
+
}
|
|
17
27
|
return {
|
|
18
28
|
id: data.id,
|
|
19
|
-
issue:
|
|
20
|
-
// isPublished: data.is_published,
|
|
29
|
+
issue: issue,
|
|
21
30
|
startsAt: new Date(data.starts_at),
|
|
22
|
-
endsAt: parseDate(data.ends_at)
|
|
23
|
-
updatedAt: new Date(data.updated_at)
|
|
31
|
+
endsAt: parseDate(data.ends_at)
|
|
24
32
|
};
|
|
25
33
|
}
|
|
34
|
+
export function parseDistribution(data, assocs) {
|
|
35
|
+
// NOTE for retro compatibility
|
|
36
|
+
if (data.localized) {
|
|
37
|
+
return {
|
|
38
|
+
id: data.id,
|
|
39
|
+
meta: buildMeta(data.localized.locale),
|
|
40
|
+
metadata: data.metadata,
|
|
41
|
+
name: data.localized.name,
|
|
42
|
+
visual: parseVisual(data.visual, assocs)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw "missing parser for distribution for reader's api";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -4,6 +4,7 @@ import { parseMany } from '../utils/api';
|
|
|
4
4
|
import { getAssoc } from '../utils/assocs';
|
|
5
5
|
import { request } from '../utils/request';
|
|
6
6
|
import { parseContentSummary } from './contents';
|
|
7
|
+
import { buildMeta } from '../utils/parseHelpers';
|
|
7
8
|
export const magazineFetchers = (f) => {
|
|
8
9
|
return {
|
|
9
10
|
getIssue: issueFetcher(f),
|
|
@@ -40,22 +41,41 @@ export function sectionContentsFetcher(f) {
|
|
|
40
41
|
* Parsers
|
|
41
42
|
******************************************************************************/
|
|
42
43
|
export function parseIssueSummary(data, assocs) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
// NOTE retrocompability
|
|
45
|
+
if (data.localized) {
|
|
46
|
+
return {
|
|
47
|
+
id: data.id,
|
|
48
|
+
issueType: getAssoc(assocs, 'issue_types', data.issue_type_id),
|
|
49
|
+
kind: data.issue_type,
|
|
50
|
+
name: data.localized.name,
|
|
51
|
+
descriptionText: data.localized.description_text,
|
|
52
|
+
descriptionHtml: data.localized.description_html,
|
|
53
|
+
color: data.color,
|
|
54
|
+
pdfUrl: data.pdf_url,
|
|
55
|
+
visual: parseVisual(data.localized.visual, assocs),
|
|
56
|
+
metadata: data.metadata,
|
|
57
|
+
meta: buildMeta(data.localized.locale),
|
|
58
|
+
updatedAt: new Date(data.updated_at)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return {
|
|
63
|
+
id: data.id,
|
|
64
|
+
issueType: getAssoc(assocs, 'issue_types', data.issue_type_id),
|
|
65
|
+
kind: data.kind,
|
|
66
|
+
name: data.name,
|
|
67
|
+
descriptionText: data.description_text,
|
|
68
|
+
descriptionHtml: data.description_html,
|
|
69
|
+
color: data.color,
|
|
70
|
+
pdfUrl: data.pdf_url,
|
|
71
|
+
visual: parseVisual(data.visual, assocs),
|
|
72
|
+
metadata: data.metadata,
|
|
73
|
+
meta: {
|
|
74
|
+
locales: parseLocalesMetadata(data.meta)
|
|
75
|
+
},
|
|
76
|
+
updatedAt: new Date(data.updated_at)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
59
79
|
}
|
|
60
80
|
export function parseIssue(data, assocs) {
|
|
61
81
|
return {
|
|
@@ -3,6 +3,7 @@ import type { ApiData } from '../utils/api';
|
|
|
3
3
|
import type { LocalesMetadata } from '../utils/response';
|
|
4
4
|
import { type Visual } from './visuals';
|
|
5
5
|
import { type ContentSummary } from './contents';
|
|
6
|
+
import { type Distribution, type Release } from './distributions';
|
|
6
7
|
export declare const mediaFetchers: (f: typeof fetch) => {
|
|
7
8
|
getMedia: () => Promise<import("../utils/api").ApiResponse<Media>>;
|
|
8
9
|
getMediaSection: (id: string) => Promise<import("../utils/api").ApiResponse<MediaSection>>;
|
|
@@ -51,7 +52,7 @@ export interface MediaSectionSummary {
|
|
|
51
52
|
updatedAt: Date;
|
|
52
53
|
}
|
|
53
54
|
export interface MediaSectionHierarchy extends MediaSectionSummary {
|
|
54
|
-
sections:
|
|
55
|
+
sections: MediaSectionHierarchy[];
|
|
55
56
|
}
|
|
56
57
|
export interface MediaSection extends MediaSectionSummary {
|
|
57
58
|
description: string | null;
|
|
@@ -87,6 +88,8 @@ export interface MediaBlock extends MediaBlockSummary {
|
|
|
87
88
|
export interface MediaBlockEntry {
|
|
88
89
|
contents: ContentSummary[];
|
|
89
90
|
section: MediaSectionSummary | null;
|
|
91
|
+
distribution: Distribution | null;
|
|
92
|
+
releases: Release[] | null;
|
|
90
93
|
}
|
|
91
94
|
export declare function parseMedia(data: ApiData, assocs: ApiAssocs): Media;
|
|
92
95
|
export declare function parseMediaBlockConfiguration(data: ApiData): MediaBlockConfigurationSummary;
|
|
@@ -4,6 +4,7 @@ import { parseVisual } from './visuals';
|
|
|
4
4
|
import { buildMeta } from '../utils/parseHelpers';
|
|
5
5
|
import { parseContentSummary } from './contents';
|
|
6
6
|
import { getAssocs } from '../utils/assocs';
|
|
7
|
+
import { parseDistribution, parseRelease } from './distributions';
|
|
7
8
|
export const mediaFetchers = (f) => {
|
|
8
9
|
return {
|
|
9
10
|
getMedia: getMedia(f),
|
|
@@ -130,6 +131,10 @@ function parseBlock(data, assocs) {
|
|
|
130
131
|
function parseBlockEntry(data, assocs) {
|
|
131
132
|
return {
|
|
132
133
|
contents: getAssocs(assocs, 'contents', data.content_ids),
|
|
133
|
-
section: data.section ? parseSectionSummary(data.section, assocs) : null
|
|
134
|
+
section: data.section ? parseSectionSummary(data.section, assocs) : null,
|
|
135
|
+
releases: data.releases
|
|
136
|
+
? data.releases.map((release) => parseRelease(release, assocs))
|
|
137
|
+
: [],
|
|
138
|
+
distribution: data.distribution ? parseDistribution(data.distribution, assocs) : null
|
|
134
139
|
};
|
|
135
140
|
}
|
|
@@ -31,25 +31,23 @@ export function initUserSession(session) {
|
|
|
31
31
|
throw new Error('MUST NOT call refresh on user session from server side.');
|
|
32
32
|
}
|
|
33
33
|
invalidate('omerlo:user_session');
|
|
34
|
-
update(updateUserInfo(null, false));
|
|
34
|
+
update(updateUserInfo(null, false, false));
|
|
35
35
|
},
|
|
36
36
|
refresh: async () => {
|
|
37
37
|
if (!browser) {
|
|
38
38
|
throw new Error('MUST NOT call refresh on user session from server side.');
|
|
39
39
|
}
|
|
40
|
-
const userInfo = await useReader(fetch)
|
|
41
|
-
|
|
42
|
-
.then((resp) => resp.data);
|
|
43
|
-
update(updateUserInfo(userInfo, true));
|
|
40
|
+
const userInfo = await useReader(fetch).userInfo();
|
|
41
|
+
update(updateUserInfo(userInfo.data, true, userInfo.ok));
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
44
|
setContext('user_session', ctx);
|
|
47
45
|
return ctx;
|
|
48
46
|
}
|
|
49
|
-
const updateUserInfo = (userInfo, authenticated) => {
|
|
47
|
+
const updateUserInfo = (userInfo, authenticated, verified) => {
|
|
50
48
|
return (session) => {
|
|
51
49
|
session.user = userInfo;
|
|
52
|
-
session.verified =
|
|
50
|
+
session.verified = verified;
|
|
53
51
|
session.authenticated = authenticated;
|
|
54
52
|
localStorage.setItem('user_session', JSON.stringify(session));
|
|
55
53
|
return session;
|