@omerlo/omerlo-webkit 0.0.16 → 0.0.19

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  # Omerlo WebKit
2
2
 
3
- This webkit is a wapper arround Omerlo's API to create quickly a website using Omerlo.
3
+ This webkit is a wrapper around Omerlo's API to create quickly a website using Omerlo solutions.
4
4
 
5
- The user's session and tokens will be managed by Omerlo Webkit. The connection state is dispatched
5
+ User's session and tokens will be managed by Omerlo Webkit. The connection state is dispatched
6
6
  over all window's tab, no need to refresh other tabs.
7
7
 
8
8
  ## Using the omerlo webkit
9
9
 
10
- Install the package `omerlo-webkit`
10
+ Install `omerlo-webkit` package
11
11
 
12
12
  ```sh
13
13
  npm i @omerlo/omerlo-webkit
@@ -38,6 +38,4 @@ export declare const useReader: (f: typeof fetch) => {
38
38
  registerDevice: (params: import("./reader").DeviceParams) => Promise<import("./reader/utils/api").ApiResponse<unknown>>;
39
39
  userInfo: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").UserInfo>>;
40
40
  userEntitlements: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").UserEntitlement[]>>;
41
- verifyAccount: (params: import("./reader").VerifyAccountParams) => void;
42
- validateAccount: (params: import("./reader").ValidateAccountParams) => void;
43
41
  };
@@ -1,18 +1,7 @@
1
1
  export declare const accountsFetchers: (f: typeof fetch) => {
2
2
  userInfo: () => Promise<import("../utils/api").ApiResponse<UserInfo>>;
3
3
  userEntitlements: () => Promise<import("../utils/api").ApiResponse<UserEntitlement[]>>;
4
- verifyAccount: (params: VerifyAccountParams) => void;
5
- validateAccount: (params: ValidateAccountParams) => void;
6
4
  };
7
- export interface ValidateAccountParams {
8
- email: string;
9
- callbackUrl: string;
10
- }
11
- export declare function validateAccount(f: typeof fetch): (params: ValidateAccountParams) => void;
12
- export interface VerifyAccountParams {
13
- verification_token: string;
14
- }
15
- export declare function verifyAccount(f: typeof fetch): (params: VerifyAccountParams) => void;
16
5
  export declare function getUserInfo(f: typeof fetch): () => Promise<import("../utils/api").ApiResponse<UserInfo>>;
17
6
  export interface UserInfo {
18
7
  name: string;
@@ -3,31 +3,10 @@ import { request } from '../utils/request';
3
3
  export const accountsFetchers = (f) => {
4
4
  return {
5
5
  userInfo: getUserInfo(f),
6
- userEntitlements: getUserEntitlements(f),
7
- verifyAccount: verifyAccount(f),
8
- validateAccount: validateAccount(f)
6
+ userEntitlements: getUserEntitlements(f)
9
7
  };
10
8
  };
11
9
  //
12
- // Validate an account using the bearer token.
13
- //
14
- export function validateAccount(f) {
15
- return (params) => {
16
- const queryParams = { email: params.email, callback_url: params.callbackUrl };
17
- const opts = { queryParams, method: 'post' };
18
- request(f, '/account/validate', opts);
19
- };
20
- }
21
- //
22
- // Verify an account using the signed JWT token generate on account validation.
23
- //
24
- export function verifyAccount(f) {
25
- return (params) => {
26
- const opts = { queryParams: params };
27
- request(f, '/account/verify', opts);
28
- };
29
- }
30
- //
31
10
  // Get user's informations associated to the bearer token.
32
11
  //
33
12
  export function getUserInfo(f) {
@@ -5,6 +5,7 @@ import { type ApiAssocs, type ApiData, type PagingParams } from '../utils/api';
5
5
  import { type LocalesMetadata } from '../utils/response';
6
6
  import type { PersonSummary } from './person';
7
7
  import type { OrganizationSummary } from './organizations';
8
+ export type AuthorSummary = PersonSummary | OrganizationSummary;
8
9
  export declare const contentsFetchers: (f: typeof fetch) => {
9
10
  getContent: (id: string) => Promise<import("../utils/api").ApiResponse<Content>>;
10
11
  listContents: (params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<ContentSummary[]>>;
@@ -34,7 +35,7 @@ export interface ContentSummary {
34
35
  meta: {
35
36
  locales: LocalesMetadata;
36
37
  };
37
- authors: (PersonSummary | OrganizationSummary)[];
38
+ authors: AuthorSummary[];
38
39
  }
39
40
  export interface Content extends ContentSummary {
40
41
  seo: ContentSeo;
@@ -22,6 +22,8 @@ export function getContent(f) {
22
22
  return async (id) => {
23
23
  const opts = { parser: parseContent };
24
24
  return requestPublisher(f, `media/contents/${id}`, opts);
25
+ // TODO: switch to Reader API (this API is already completed and documented)
26
+ // return request(f, `/contents/${id}`, opts)
25
27
  };
26
28
  }
27
29
  export function listContents(f) {
@@ -33,6 +35,10 @@ export function listContents(f) {
33
35
  export function parseContentSummary(data, assocs) {
34
36
  if (data.localized) {
35
37
  // NOTE: This is to support publisher public api v2
38
+ const metadata = (data.metadata ?? []).reduce((acc, { key, value }) => {
39
+ acc[key] = value;
40
+ return acc;
41
+ }, {});
36
42
  return {
37
43
  id: data.id,
38
44
  template: getAssoc(assocs, 'templates', data.template_id),
@@ -51,7 +57,7 @@ export function parseContentSummary(data, assocs) {
51
57
  subtitleText: data.localized.subtitle_text,
52
58
  visual: parseVisual(data.localized.visual, assocs),
53
59
  meta: buildMeta(data.localized.locale),
54
- metadata: {},
60
+ metadata: metadata,
55
61
  authors: getAssocs(assocs, 'profiles', data.localized.author_ids)
56
62
  };
57
63
  }
@@ -74,7 +80,7 @@ export function parseContentSummary(data, assocs) {
74
80
  subtitleText: data.subtitle_text,
75
81
  visual: parseVisual(data.visual, assocs),
76
82
  meta: { locales: parseLocalesMetadata(data.meta) },
77
- metadata: {},
83
+ metadata: data.metadata,
78
84
  authors: getAssocs(assocs, 'profiles', data.author_ids)
79
85
  };
80
86
  }
@@ -1,12 +1,12 @@
1
1
  import { type ApiAssocs, type ApiData, type PagingParams } from '../utils/api';
2
- import type { Issue } from './magazines';
2
+ import type { IssueSummary } from './magazines';
3
3
  export declare const distributionFetchers: (f: typeof fetch) => {
4
4
  listReleases: (distributionId: string, params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<Release[]>>;
5
5
  };
6
6
  export declare function releasesFetcher(f: typeof fetch): (distributionId: string, params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<Release[]>>;
7
7
  export interface Release {
8
8
  id: string;
9
- issue: Issue;
9
+ issue: IssueSummary;
10
10
  startsAt: Date;
11
11
  endsAt: Date | null;
12
12
  updatedAt: Date;
@@ -13,7 +13,8 @@ export function parseEventSummary(data, assocs) {
13
13
  kind: 'event',
14
14
  type: data.type,
15
15
  isAllDay: data.is_all_day,
16
- profileImageURL: data.logo_image_url,
16
+ // NOTE remove logo_image_url once using reader api
17
+ profileImageURL: data.logo_image_url || data.profile_image_url,
17
18
  coverImageURL: data.cover_image_url,
18
19
  subscriptionURL: data.subscription_url,
19
20
  name,
@@ -35,6 +35,9 @@ export interface IssueSummary {
35
35
  color: string | null;
36
36
  pdfUrl: string | null;
37
37
  visual: Visual | null;
38
+ metadata: {
39
+ [key: string]: string;
40
+ };
38
41
  meta: {
39
42
  locales: LocalesMetadata;
40
43
  };
@@ -44,9 +47,6 @@ export interface Issue extends IssueSummary {
44
47
  advertisingKey: string | null;
45
48
  descriptionHtml: string | null;
46
49
  descriptionText: string | null;
47
- metadata: {
48
- [key: string]: string;
49
- };
50
50
  sections: IssueSectionSummary[];
51
51
  }
52
52
  export interface IssueType {
@@ -48,6 +48,7 @@ export function parseIssueSummary(data, assocs) {
48
48
  color: data.color,
49
49
  pdfUrl: data.pdf_url,
50
50
  visual: parseVisual(data.visual, assocs),
51
+ metadata: data.metadata,
51
52
  meta: {
52
53
  locales: parseLocalesMetadata(data.meta)
53
54
  },
@@ -60,7 +61,6 @@ export function parseIssue(data, assocs) {
60
61
  advertisingKey: data.advertising_key,
61
62
  descriptionText: data.description_text,
62
63
  descriptionHtml: data.description_html,
63
- metadata: data.metadata,
64
64
  sections: data.sections.map((section) => parseIssueSectionSummary(section, assocs))
65
65
  };
66
66
  }
@@ -20,7 +20,8 @@ export function parseOrganizationSummary(data, assocs) {
20
20
  profileType: getAssoc(assocs, 'profile_types', data.profile_type_id),
21
21
  kind: 'organization',
22
22
  name: data.name,
23
- profileImageURL: data.logo_image_url,
23
+ // NOTE remove logo_image_url once using reader api
24
+ profileImageURL: data.logo_image_url || data.profile_image_url,
24
25
  meta: buildMeta(data.localized?.locale),
25
26
  summaryHtml: data.localized?.summary_html,
26
27
  summaryText: data.localized?.summary_text,
@@ -11,7 +11,8 @@ export function parsePersonSummary(data, assocs) {
11
11
  lastName: data.last_name,
12
12
  otherName: data.other_name,
13
13
  pronoun: data.pronoun,
14
- profileImageURL: data.avatar_image_url,
14
+ // NOTE remove logo_image_url once using reader api
15
+ profileImageURL: data.avatar_image_url || data.profile_image_url,
15
16
  coverImageURL: data.cover_image_url,
16
17
  meta: buildMeta(data.localized?.locale),
17
18
  summaryHtml: data.localized?.summary_html,
@@ -7,7 +7,8 @@ export function parseProjectSummary(data, assocs) {
7
7
  id: data.id,
8
8
  profileType: getAssoc(assocs, 'profile_types', data.profile_type_id),
9
9
  kind: 'project',
10
- profileImageURL: data.logo_image_url,
10
+ // NOTE remove logo_image_url once using reader api
11
+ profileImageURL: data.logo_image_url || data.profile_image_url,
11
12
  coverImageURL: data.cover_image_url,
12
13
  meta: buildMeta(data.localized?.locale),
13
14
  name: data.localized?.name,
@@ -38,6 +38,4 @@ export declare const fetchers: (f: typeof fetch) => {
38
38
  registerDevice: (params: import("./endpoints/device").DeviceParams) => Promise<import("./utils/api").ApiResponse<unknown>>;
39
39
  userInfo: () => Promise<import("./utils/api").ApiResponse<import("./endpoints/accounts").UserInfo>>;
40
40
  userEntitlements: () => Promise<import("./utils/api").ApiResponse<import("./endpoints/accounts").UserEntitlement[]>>;
41
- verifyAccount: (params: import("./endpoints/accounts").VerifyAccountParams) => void;
42
- validateAccount: (params: import("./endpoints/accounts").ValidateAccountParams) => void;
43
41
  };
@@ -4,7 +4,7 @@ import { parseContentBlockTemplate, parseContentTemplate } from './endpoints/con
4
4
  import { parseProfileTypeSummary } from './endpoints/profileType';
5
5
  import { registerAssocParser } from './utils/assocs';
6
6
  import { parseContentSummary } from './endpoints/contents';
7
- import { parseIssueBlockConfiguration, parseIssueType } from './endpoints/magazines';
7
+ import { parseIssueBlockConfiguration, parseIssueSummary, parseIssueType } from './endpoints/magazines';
8
8
  export * from './stores/user_session';
9
9
  export function initReader() {
10
10
  registerAssocParser('categories', parseCategory);
@@ -14,8 +14,12 @@ export function initReader() {
14
14
  registerAssocParser('profile_block_types', parseProfileBlock);
15
15
  registerAssocParser('content_block_templates', parseContentBlockTemplate);
16
16
  registerAssocParser('contents', parseContentSummary);
17
+ registerAssocParser('issues', parseIssueSummary);
17
18
  registerAssocParser('issue_types', parseIssueType);
18
19
  registerAssocParser('issue_block_configurations', parseIssueBlockConfiguration);
19
- // NOTE: This one is for retro compatibility with publisher public api v2
20
+ // NOTE: Those ones are for retro compatibility with publisher public api v2
21
+ // Reason is we renamed some assocs keys in Reader API that are different
22
+ // from Publisher public API V2
20
23
  registerAssocParser('templates', parseContentTemplate);
24
+ registerAssocParser('block_templates', parseContentBlockTemplate);
21
25
  }
@@ -3,3 +3,4 @@ export declare const handleUserToken: import("@sveltejs/kit").Handle;
3
3
  export * from './token';
4
4
  export * from './utils';
5
5
  export * from './email';
6
+ export * from './oauth';
@@ -4,3 +4,4 @@ export const handleUserToken = Hooks.handleUserToken;
4
4
  export * from './token';
5
5
  export * from './utils';
6
6
  export * from './email';
7
+ export * from './oauth';
@@ -0,0 +1 @@
1
+ export declare function verifyOauth(email: string, oauthUserId: string): Promise<void>;
@@ -0,0 +1,23 @@
1
+ import { env } from '$env/dynamic/private';
2
+ import { ApiError } from '../utils/api';
3
+ import { getApplicationToken } from './utils';
4
+ export async function verifyOauth(email, oauthUserId) {
5
+ const url = getOmerloEndpoint();
6
+ const accessToken = await getApplicationToken();
7
+ const headers = new Headers({
8
+ 'x-omerlo-media-id': env.PRIVATE_OMERLO_MEDIA_ID,
9
+ Authorization: `Bearer ${accessToken}`
10
+ });
11
+ url.pathname = '/api/media/v1/oauth/verify';
12
+ url.searchParams.append('oauth_user_id', oauthUserId);
13
+ url.searchParams.append('email', email);
14
+ const resp = await fetch(url, { method: 'POST', headers });
15
+ if (resp.ok) {
16
+ return;
17
+ }
18
+ const payload = await resp.json();
19
+ throw new ApiError(resp.status, payload.error, resp.statusText);
20
+ }
21
+ function getOmerloEndpoint() {
22
+ return new URL(`${env.PRIVATE_OMERLO_PROTOCOL}://${env.PRIVATE_OMERLO_HOST}`);
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omerlo/omerlo-webkit",
3
- "version": "0.0.16",
3
+ "version": "0.0.19",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",
@@ -64,7 +64,7 @@
64
64
  "typescript-eslint": "^8.0.0",
65
65
  "vite": "^5.0.11"
66
66
  },
67
- "description": "This webkit is a wapper arround Omerlo's API to create quickly a website using Omerlo.",
67
+ "description": "Omerlo's API wrapper to help developing blazing fast website.",
68
68
  "main": "eslint.config.js",
69
69
  "directories": {},
70
70
  "repository": {