@omerlo/omerlo-webkit 0.0.53 → 0.0.55
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/contents.d.ts +7 -0
- package/dist/omerlo/reader/endpoints/contents.js +5 -2
- package/dist/omerlo/reader/endpoints/organizations.d.ts +1 -0
- package/dist/omerlo/reader/endpoints/organizations.js +1 -0
- package/dist/omerlo/reader/endpoints/person.d.ts +1 -0
- package/dist/omerlo/reader/endpoints/person.js +1 -0
- package/dist/omerlo/reader/utils/api.js +23 -6
- package/package.json +1 -1
|
@@ -45,6 +45,7 @@ export type ContentBlockRichtext = {
|
|
|
45
45
|
id: string;
|
|
46
46
|
kind: 'richtext';
|
|
47
47
|
contentHtml: string;
|
|
48
|
+
contentText: string;
|
|
48
49
|
visual: Visual | null;
|
|
49
50
|
template: ContentBlockTemplate | null;
|
|
50
51
|
};
|
|
@@ -79,10 +80,15 @@ export type ContentBlockRelatedContents = {
|
|
|
79
80
|
visual: Visual | null;
|
|
80
81
|
template: ContentBlockTemplate | null;
|
|
81
82
|
};
|
|
83
|
+
export type AnswerVotes = {
|
|
84
|
+
total: number;
|
|
85
|
+
sources: Record<string, unknown>;
|
|
86
|
+
};
|
|
82
87
|
export type Answer = {
|
|
83
88
|
id: string;
|
|
84
89
|
contentHtml: string;
|
|
85
90
|
contentText: string;
|
|
91
|
+
votes: AnswerVotes | null;
|
|
86
92
|
};
|
|
87
93
|
export type ContentBlockQuestion = {
|
|
88
94
|
id: string;
|
|
@@ -90,6 +96,7 @@ export type ContentBlockQuestion = {
|
|
|
90
96
|
questionHtml: string;
|
|
91
97
|
questionText: string;
|
|
92
98
|
acceptVoteUntil: Date;
|
|
99
|
+
acceptVotesUntilTimezone: string | null;
|
|
93
100
|
answers: Answer[];
|
|
94
101
|
visual: Visual | null;
|
|
95
102
|
template: ContentBlockTemplate | null;
|
|
@@ -130,7 +130,8 @@ function getBlockContents(data, assocs) {
|
|
|
130
130
|
function parseContentBlockRichtext(data, assocs) {
|
|
131
131
|
return {
|
|
132
132
|
...baseBlock(data, assocs),
|
|
133
|
-
contentHtml: data.content_html
|
|
133
|
+
contentHtml: data.content_html,
|
|
134
|
+
contentText: data.content_text
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
function parseContentBlockData(data, assocs) {
|
|
@@ -167,6 +168,7 @@ function parseContentBlockQuestion(data, assocs) {
|
|
|
167
168
|
questionHtml: data.question_html,
|
|
168
169
|
questionText: data.question_text,
|
|
169
170
|
acceptVoteUntil: new Date(data.accept_vote_until),
|
|
171
|
+
acceptVotesUntilTimezone: data.accept_votes_until_timezone ?? null,
|
|
170
172
|
answers: data.answers?.map((answer) => parseAnswer(answer)) || []
|
|
171
173
|
};
|
|
172
174
|
}
|
|
@@ -174,7 +176,8 @@ function parseAnswer(data) {
|
|
|
174
176
|
return {
|
|
175
177
|
id: data.id,
|
|
176
178
|
contentHtml: data.content_html,
|
|
177
|
-
contentText: data.content_text
|
|
179
|
+
contentText: data.content_text,
|
|
180
|
+
votes: data.votes ? { total: data.votes.total ?? 0, sources: data.votes.sources ?? {} } : null
|
|
178
181
|
};
|
|
179
182
|
}
|
|
180
183
|
function parseContentBlockImage(data, assocs) {
|
|
@@ -57,6 +57,7 @@ export function parseOrganizationSummary(data, assocs) {
|
|
|
57
57
|
name: data.name,
|
|
58
58
|
// NOTE remove logo_image_url once using reader api
|
|
59
59
|
profileImageUrl: data.logo_image_url || data.profile_image_url,
|
|
60
|
+
canonicalUrl: data.canonical_url ?? null,
|
|
60
61
|
...localizedField,
|
|
61
62
|
updatedAt: new Date(data.updated_at)
|
|
62
63
|
};
|
|
@@ -61,6 +61,7 @@ export function parsePersonSummary(data, assocs) {
|
|
|
61
61
|
// NOTE remove logo_image_url once using reader api
|
|
62
62
|
profileImageUrl: data.avatar_image_url || data.profile_image_url,
|
|
63
63
|
coverImageUrl: data.cover_image_url,
|
|
64
|
+
canonicalUrl: data.canonical_url ?? null,
|
|
64
65
|
...localizedField,
|
|
65
66
|
updatedAt: new Date(data.updated_at)
|
|
66
67
|
};
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { initAssocs, parseAssocs } from './assocs';
|
|
2
2
|
export async function parseApiResponse(response, parser) {
|
|
3
|
-
const
|
|
4
|
-
let data = null, meta = null;
|
|
3
|
+
const text = await response.text();
|
|
5
4
|
if (response.ok) {
|
|
5
|
+
const payload = JSON.parse(text);
|
|
6
6
|
let assocs = initAssocs(payload.assocs);
|
|
7
7
|
assocs = parseAssocs(assocs);
|
|
8
|
-
meta = payload.meta;
|
|
9
|
-
data = parser(payload.data, assocs);
|
|
8
|
+
const meta = payload.meta;
|
|
9
|
+
const data = parser(payload.data, assocs);
|
|
10
|
+
const errors = payload.errors || [];
|
|
11
|
+
return { ok: true, status: response.status, parser, meta, data, errors };
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
// Response not OK - try to parse JSON for API errors, fallback to generic error
|
|
14
|
+
let errors = [];
|
|
15
|
+
try {
|
|
16
|
+
const payload = JSON.parse(text);
|
|
17
|
+
errors = payload.errors || [];
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
console.error('[OmerloWebkit - parseApiResponse] Non-OK response with non-JSON body', {
|
|
21
|
+
url: response.url,
|
|
22
|
+
status: response.status,
|
|
23
|
+
statusText: response.statusText,
|
|
24
|
+
contentType: response.headers.get('content-type'),
|
|
25
|
+
body: text.slice(0, 1000)
|
|
26
|
+
});
|
|
27
|
+
errors = [{ message: `${response.status} ${response.statusText}`, body: text.slice(0, 500) }];
|
|
28
|
+
}
|
|
29
|
+
return { ok: false, status: response.status, parser, meta: null, data: null, errors };
|
|
13
30
|
}
|
|
14
31
|
export function parseMany(parser) {
|
|
15
32
|
return (response, assocs) => {
|