@omerlo/omerlo-webkit 0.0.11 → 0.0.13

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
@@ -60,7 +60,7 @@ Then you need to use the component `OmerloWebkit` and give him the `userSession`
60
60
  ```ts
61
61
  // +layout.svelte
62
62
  <script lang="ts">
63
- import { OmerloWebkit } from 'omerlo-webkit'
63
+ import { OmerloWebkit } from '$omerlo'
64
64
  let { data, children } = $props();
65
65
  </script>
66
66
 
@@ -76,7 +76,7 @@ To use reader API, you can use the function `useReader` passing the sveltekit `f
76
76
  ```ts
77
77
  // +page.ts
78
78
  import type { PageLoad } from './$types';
79
- import { useReader } from 'omerlo-webkit';
79
+ import { useReader } from '$omerlo';
80
80
 
81
81
  export const load: PageLoad = async ({ fetch }) => {
82
82
  const oauthProviders = await useReader(fetch).listOauthProviders();
@@ -36,6 +36,7 @@ export declare const useReader: (f: typeof fetch) => {
36
36
  getOauthUser: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").OauthUser>>;
37
37
  registerDevice: (params: import("./reader").DeviceParams) => Promise<import("./reader/utils/api").ApiResponse<unknown>>;
38
38
  userInfo: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").UserInfo>>;
39
+ userEntitlements: () => Promise<import("./reader/utils/api").ApiResponse<import("./reader").UserEntitlement[]>>;
39
40
  verifyAccount: (params: import("./reader").VerifyAccountParams) => void;
40
41
  validateAccount: (params: import("./reader").ValidateAccountParams) => void;
41
42
  };
@@ -1,5 +1,6 @@
1
1
  export declare const accountsFetchers: (f: typeof fetch) => {
2
2
  userInfo: () => Promise<import("../utils/api").ApiResponse<UserInfo>>;
3
+ userEntitlements: () => Promise<import("../utils/api").ApiResponse<UserEntitlement[]>>;
3
4
  verifyAccount: (params: VerifyAccountParams) => void;
4
5
  validateAccount: (params: ValidateAccountParams) => void;
5
6
  };
@@ -17,3 +18,8 @@ export interface UserInfo {
17
18
  name: string;
18
19
  email: string;
19
20
  }
21
+ export declare function getUserEntitlements(f: typeof fetch): () => Promise<import("../utils/api").ApiResponse<UserEntitlement[]>>;
22
+ export interface UserEntitlement {
23
+ id: string;
24
+ feature_key: string;
25
+ }
@@ -1,7 +1,9 @@
1
+ import { parseMany } from '../utils/api';
1
2
  import { request } from '../utils/request';
2
3
  export const accountsFetchers = (f) => {
3
4
  return {
4
5
  userInfo: getUserInfo(f),
6
+ userEntitlements: getUserEntitlements(f),
5
7
  verifyAccount: verifyAccount(f),
6
8
  validateAccount: validateAccount(f)
7
9
  };
@@ -40,3 +42,18 @@ function parseUserInfo(data, _assoc) {
40
42
  email: data.email
41
43
  };
42
44
  }
45
+ //
46
+ // Get user's entitlements associated to the bearer token (Platform).
47
+ //
48
+ export function getUserEntitlements(f) {
49
+ return async () => {
50
+ const opts = { parser: parseMany(parseUserEntitlement) };
51
+ return request(f, '/account/me/entitlements', opts);
52
+ };
53
+ }
54
+ function parseUserEntitlement(data, _assoc) {
55
+ return {
56
+ id: data.id,
57
+ feature_key: data.feature_key
58
+ };
59
+ }
@@ -10,8 +10,8 @@ export declare const contentsFetchers: (f: typeof fetch) => {
10
10
  listContents: (params?: Partial<PagingParams>) => Promise<import("../utils/api").ApiResponse<ContentSummary[]>>;
11
11
  };
12
12
  export interface ContentSeo {
13
- title: string;
14
- description: string;
13
+ title: string | null;
14
+ description: string | null;
15
15
  }
16
16
  export interface ContentSummary {
17
17
  id: string;
@@ -37,6 +37,7 @@ export interface ContentSummary {
37
37
  authors: (PersonSummary | OrganizationSummary)[];
38
38
  }
39
39
  export interface Content extends ContentSummary {
40
+ seo: ContentSeo;
40
41
  blocks: ContentBlock[];
41
42
  }
42
43
  export type ContentBlockRichtext = {
@@ -73,7 +74,7 @@ export type ContentBlockQuote = {
73
74
  export type ContentBlockRelatedContents = {
74
75
  id: string;
75
76
  kind: 'related-contents';
76
- contents: Content[];
77
+ contents: ContentSummary[];
77
78
  visual: Visual | null;
78
79
  template: ContentBlockTemplate | null;
79
80
  };
@@ -51,6 +51,7 @@ export function parseContentSummary(data, assocs) {
51
51
  subtitleText: data.localized.subtitle_text,
52
52
  visual: parseVisual(data.visual, assocs),
53
53
  meta: buildMeta(data.localized.locale),
54
+ metadata: {},
54
55
  authors: getAssocs(assocs, 'profiles', data.localized.author_ids)
55
56
  };
56
57
  }
@@ -73,6 +74,7 @@ export function parseContentSummary(data, assocs) {
73
74
  subtitleText: data.subtitle_text,
74
75
  visual: parseVisual(data.visual, assocs),
75
76
  meta: { locales: parseLocalesMetadata(data.meta) },
77
+ metadata: {},
76
78
  authors: getAssocs(assocs, 'profiles', data.author_ids)
77
79
  };
78
80
  }
@@ -114,7 +116,7 @@ function getBlockTemplate(data, assocs) {
114
116
  ? getAssoc(assocs, 'block_templates', data.template_id)
115
117
  : null;
116
118
  }
117
- function getBlockContent(data, assocs) {
119
+ function getBlockContents(data, assocs) {
118
120
  return data.related_contents ? getAssocs(assocs, 'contents', data.related_contents) : [];
119
121
  }
120
122
  function parseContentBlockRichtext(data, assocs) {
@@ -145,7 +147,7 @@ function parseContentBlockQuote(data, assocs) {
145
147
  };
146
148
  }
147
149
  function parseContentBlockRelatedContents(data, assocs) {
148
- const contents = getBlockContent(data, assocs);
150
+ const contents = getBlockContents(data, assocs);
149
151
  return {
150
152
  ...baseBlock(data, assocs),
151
153
  contents
@@ -1,17 +1,17 @@
1
1
  import { type LocalesMetadata } from '../utils/response';
2
2
  import { type Visual } from './visuals';
3
3
  import { type ApiAssocs, type ApiData } from '../utils/api';
4
- import { type Content, type ContentSummary } from './contents';
4
+ import { type ContentSummary } from './contents';
5
5
  export declare const magazineFetchers: (f: typeof fetch) => {
6
6
  getIssue: (id: string) => Promise<import("../utils/api").ApiResponse<Issue>>;
7
7
  getBlocks: (sectionId: string) => Promise<import("../utils/api").ApiResponse<IssueBlock[]>>;
8
8
  searchContents: (issueId: string, q: string) => Promise<import("../utils/api").ApiResponse<SectionContent[]>>;
9
- getSectionContents: (sectionId: string) => Promise<import("../utils/api").ApiResponse<Content[]>>;
9
+ getSectionContents: (sectionId: string) => Promise<import("../utils/api").ApiResponse<import("./contents").Content[]>>;
10
10
  };
11
11
  export declare function issueFetcher(f: typeof fetch): (id: string) => Promise<import("../utils/api").ApiResponse<Issue>>;
12
12
  export declare function issueBlocksFetcher(f: typeof fetch): (sectionId: string) => Promise<import("../utils/api").ApiResponse<IssueBlock[]>>;
13
13
  export declare function contentsSearch(f: typeof fetch): (issueId: string, q: string) => Promise<import("../utils/api").ApiResponse<SectionContent[]>>;
14
- export declare function sectionContentsFetcher(f: typeof fetch): (sectionId: string) => Promise<import("../utils/api").ApiResponse<Content[]>>;
14
+ export declare function sectionContentsFetcher(f: typeof fetch): (sectionId: string) => Promise<import("../utils/api").ApiResponse<import("./contents").Content[]>>;
15
15
  /******************************************************************************
16
16
  * Parsers
17
17
  ******************************************************************************/
@@ -23,7 +23,7 @@ export declare function parseIssueBlock(data: ApiData, assocs: ApiAssocs): Issue
23
23
  export declare function parseIssueBlockSlot(data: ApiData, assocs: ApiAssocs): IssueBlockSlot;
24
24
  export declare function parseIssueSectionContent(data: ApiData, assocs: ApiAssocs): SectionContent;
25
25
  export declare function parseIssueType(data: ApiData, _assocs: ApiAssocs): IssueType;
26
- export declare function parseIssueBlockConfiguration(data: ApiData, assocs: ApiAssocs): IssueBlockConfiguration;
26
+ export declare function parseIssueBlockConfiguration(data: ApiData): IssueBlockConfiguration;
27
27
  /******************************************************************************
28
28
  * Interfaces
29
29
  ******************************************************************************/
@@ -88,7 +88,7 @@ export interface IssueBlock {
88
88
  };
89
89
  updatedAt: Date;
90
90
  }
91
- export interface SectionContent extends Content {
91
+ export interface SectionContent extends ContentSummary {
92
92
  section: IssueSectionSummary;
93
93
  }
94
94
  export interface IssueBlockConfiguration {
@@ -3,7 +3,7 @@ import { parseVisual } from './visuals';
3
3
  import { parseMany } from '../utils/api';
4
4
  import { getAssoc } from '../utils/assocs';
5
5
  import { request } from '../utils/request';
6
- import { parseContent } from './contents';
6
+ import { parseContent, parseContentSummary } from './contents';
7
7
  export const magazineFetchers = (f) => {
8
8
  return {
9
9
  getIssue: issueFetcher(f),
@@ -108,7 +108,7 @@ export function parseIssueBlockSlot(data, assocs) {
108
108
  }
109
109
  export function parseIssueSectionContent(data, assocs) {
110
110
  return {
111
- ...parseContent(data, assocs),
111
+ ...parseContentSummary(data, assocs),
112
112
  section: getAssoc(assocs, 'issue_sections', data.section_id)
113
113
  };
114
114
  }
@@ -124,7 +124,7 @@ export function parseIssueType(data, _assocs) {
124
124
  updatedAt: new Date(data.updated_at)
125
125
  };
126
126
  }
127
- export function parseIssueBlockConfiguration(data, assocs) {
127
+ export function parseIssueBlockConfiguration(data) {
128
128
  return {
129
129
  id: data.id,
130
130
  key: data.key,
@@ -1,5 +1,5 @@
1
1
  import { type ApiAssocs, type ApiData } from '../utils/api';
2
- import type { LocalesMetadata } from '../utils/response';
2
+ import { type LocalesMetadata } from '../utils/response';
3
3
  export interface ProfileTypeSummary {
4
4
  id: string;
5
5
  kind: 'person' | 'project' | 'organization' | 'event';
@@ -1,12 +1,20 @@
1
1
  import {} from '../utils/api';
2
+ import { parseLocalesMetadata } from '../utils/response';
2
3
  import { buildMeta } from '../utils/parseHelpers';
3
4
  export function parseProfileTypeSummary(data, _assocs) {
5
+ let localizedField;
6
+ // NOTE: This is to support publisher public api v2
7
+ if (data.localized) {
8
+ localizedField = { name: data.localized.name, meta: buildMeta(data.localized.locale) };
9
+ }
10
+ else {
11
+ localizedField = { name: data.name, meta: { locales: parseLocalesMetadata(data.meta) } };
12
+ }
4
13
  return {
14
+ ...localizedField,
5
15
  id: data.id,
6
16
  kind: data.kind,
7
17
  key: data.key,
8
- name: data.localized.name,
9
- meta: buildMeta(data.localized.locale),
10
18
  updatedAt: new Date(data.updated_at)
11
19
  };
12
20
  }
@@ -4,7 +4,7 @@ import { type EventSummary } from './events';
4
4
  import { type Organization, type OrganizationSummary } from './organizations';
5
5
  import type { ApiAssocs, ApiData } from '../utils/api';
6
6
  import type { LocalesMetadata } from '../utils/response';
7
- import type { Content } from './contents';
7
+ import type { ContentSummary } from './contents';
8
8
  import { type Image, type Slideshow, type Video } from './visuals';
9
9
  export type Profile = Person | Project | Event | Organization;
10
10
  export type ProfileSummary = PersonSummary | ProjectSummary | EventSummary | OrganizationSummary;
@@ -58,7 +58,7 @@ export type ProfileBlock = {
58
58
  updatedAt: Date;
59
59
  };
60
60
  export interface ProfileBlockContents extends ProfileBlock {
61
- contents: Content[];
61
+ contents: ContentSummary[];
62
62
  }
63
63
  export interface ProfileBlockRelations extends ProfileBlock {
64
64
  profiles: ProfileSummary[];
@@ -36,6 +36,7 @@ export declare const fetchers: (f: typeof fetch) => {
36
36
  getOauthUser: () => Promise<import("./utils/api").ApiResponse<import("./endpoints/oauth").OauthUser>>;
37
37
  registerDevice: (params: import("./endpoints/device").DeviceParams) => Promise<import("./utils/api").ApiResponse<unknown>>;
38
38
  userInfo: () => Promise<import("./utils/api").ApiResponse<import("./endpoints/accounts").UserInfo>>;
39
+ userEntitlements: () => Promise<import("./utils/api").ApiResponse<import("./endpoints/accounts").UserEntitlement[]>>;
39
40
  verifyAccount: (params: import("./endpoints/accounts").VerifyAccountParams) => void;
40
41
  validateAccount: (params: import("./endpoints/accounts").ValidateAccountParams) => void;
41
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omerlo/omerlo-webkit",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",