@cntrl-site/sdk 0.2.7 → 0.2.9

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Client = void 0;
7
7
  const core_1 = require("@cntrl-site/core");
8
8
  const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
9
+ const url_1 = require("url");
9
10
  class Client {
10
11
  constructor(projectId, APIUrl, fetchImpl = isomorphic_fetch_1.default) {
11
12
  this.projectId = projectId;
@@ -19,7 +20,8 @@ class Client {
19
20
  }
20
21
  }
21
22
  async getProject() {
22
- const response = await this.fetchImpl(`${this.APIUrl}/projects/${this.projectId}`);
23
+ const projectUrl = new url_1.URL(`/projects/${this.projectId}`, this.APIUrl);
24
+ const response = await this.fetchImpl(projectUrl.href);
23
25
  if (!response.ok) {
24
26
  throw new Error(`Failed to fetch project with id #${this.projectId}: ${response.statusText}`);
25
27
  }
@@ -28,7 +30,8 @@ class Client {
28
30
  return project;
29
31
  }
30
32
  async getPageArticle(pageSlug) {
31
- const projectResponse = await this.fetchImpl(`${this.APIUrl}/projects/${this.projectId}`);
33
+ const projectUrl = new url_1.URL(`/projects/${this.projectId}`, this.APIUrl);
34
+ const projectResponse = await this.fetchImpl(projectUrl.href);
32
35
  if (!projectResponse.ok) {
33
36
  throw new Error(`Failed to fetch project with id #${this.projectId}: ${projectResponse.statusText}`);
34
37
  }
@@ -38,7 +41,8 @@ class Client {
38
41
  if (!page) {
39
42
  throw new Error(`Page with a slug ${pageSlug} was not found in project with id #${this.projectId}`);
40
43
  }
41
- const articleResponse = await this.fetchImpl(`${this.APIUrl}/articles/${page.articleId}`);
44
+ const url = new url_1.URL(`/articles/${page.articleId}`, this.APIUrl);
45
+ const articleResponse = await this.fetchImpl(url.href);
42
46
  if (!articleResponse.ok) {
43
47
  throw new Error(`Failed to fetch article with id #${page.articleId}: ${articleResponse.statusText}`);
44
48
  }
package/lib/utils.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLayoutStyles = void 0;
4
- const core_1 = require("@cntrl-site/core");
5
4
  function getLayoutStyles(layouts, layoutValues, mapToStyles) {
6
5
  const mediaQueries = layouts
7
6
  .sort((a, b) => a.startsWith - b.startsWith)
8
7
  .reduce((acc, layout) => {
9
- const values = layoutValues.map(lv => lv[layout.id] ?? (0, core_1.getClosestLayoutValue)(lv, layouts, layout.id));
8
+ const values = layoutValues.map(lv => lv[layout.id]);
10
9
  return `
11
10
  ${acc}
12
11
  ${layout.startsWith !== 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Generic SDK for use in public websites.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -24,14 +24,16 @@
24
24
  "lib": "lib"
25
25
  },
26
26
  "dependencies": {
27
- "@cntrl-site/core": "^1.7.1",
27
+ "@cntrl-site/core": "^1.7.5",
28
28
  "@types/isomorphic-fetch": "^0.0.36",
29
- "isomorphic-fetch": "^3.0.0"
29
+ "isomorphic-fetch": "^3.0.0",
30
+ "url": "^0.11.0"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@tsconfig/node16": "^1.0.3",
33
34
  "@tsconfig/recommended": "^1.0.1",
34
35
  "@types/jest": "^29.0.0",
36
+ "@types/node": "^18.11.7",
35
37
  "jest": "^28.1.3",
36
38
  "ts-jest": "^28.0.8",
37
39
  "typescript": "^4.7.4"
@@ -1,5 +1,6 @@
1
1
  import { TProject, ProjectSchema, TArticle, ArticleSchema, TMeta, TPageMeta } from '@cntrl-site/core';
2
2
  import fetch from 'isomorphic-fetch';
3
+ import { URL } from 'url';
3
4
 
4
5
  export class Client {
5
6
  constructor(
@@ -16,7 +17,8 @@ export class Client {
16
17
  }
17
18
 
18
19
  async getProject(): Promise<TProject> {
19
- const response = await this.fetchImpl(`${this.APIUrl}/projects/${this.projectId}`);
20
+ const projectUrl = new URL(`/projects/${this.projectId}`, this.APIUrl);
21
+ const response = await this.fetchImpl(projectUrl.href);
20
22
  if (!response.ok) {
21
23
  throw new Error(`Failed to fetch project with id #${this.projectId}: ${response.statusText}`);
22
24
  }
@@ -26,7 +28,8 @@ export class Client {
26
28
  }
27
29
 
28
30
  async getPageArticle(pageSlug: string): Promise<TArticle> {
29
- const projectResponse = await this.fetchImpl(`${this.APIUrl}/projects/${this.projectId}`);
31
+ const projectUrl = new URL(`/projects/${this.projectId}`, this.APIUrl);
32
+ const projectResponse = await this.fetchImpl(projectUrl.href);
30
33
  if (!projectResponse.ok) {
31
34
  throw new Error(`Failed to fetch project with id #${this.projectId}: ${projectResponse.statusText}`);
32
35
  }
@@ -36,8 +39,8 @@ export class Client {
36
39
  if (!page) {
37
40
  throw new Error(`Page with a slug ${pageSlug} was not found in project with id #${this.projectId}`);
38
41
  }
39
-
40
- const articleResponse = await this.fetchImpl(`${this.APIUrl}/articles/${page.articleId}`);
42
+ const url = new URL(`/articles/${page.articleId}`, this.APIUrl);
43
+ const articleResponse = await this.fetchImpl(url.href);
41
44
  if (!articleResponse.ok) {
42
45
  throw new Error(`Failed to fetch article with id #${page.articleId}: ${articleResponse.statusText}`);
43
46
  }
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TLayout, getClosestLayoutValue } from '@cntrl-site/core';
1
+ import { TLayout } from '@cntrl-site/core';
2
2
 
3
3
  export function getLayoutStyles<V, M> (
4
4
  layouts: TLayout[],
@@ -8,7 +8,7 @@ export function getLayoutStyles<V, M> (
8
8
  const mediaQueries = layouts
9
9
  .sort((a, b) => a.startsWith - b.startsWith)
10
10
  .reduce((acc, layout) => {
11
- const values = layoutValues.map(lv => lv[layout.id] ?? getClosestLayoutValue(lv, layouts, layout.id));
11
+ const values = layoutValues.map(lv => lv[layout.id]);
12
12
  return `
13
13
  ${acc}
14
14
  ${layout.startsWith !== 0