@cntrl-site/sdk 1.1.9 → 1.1.10
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/cntrl-site-sdk-1.1.10.tgz +0 -0
- package/cntrl-site-sdk-1.1.9.tgz +0 -0
- package/lib/Client/Client.js +106 -82
- package/lib/cli.js +12 -3
- package/package.json +2 -2
|
Binary file
|
|
Binary file
|
package/lib/Client/Client.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -19,103 +28,118 @@ class Client {
|
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
30
|
static getPageMeta(projectMeta, pageMeta) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
22
32
|
return pageMeta.enabled ? {
|
|
23
|
-
title: pageMeta.title ? pageMeta.title : projectMeta.title
|
|
24
|
-
description: pageMeta.description ? pageMeta.description : projectMeta.description
|
|
25
|
-
keywords: pageMeta.keywords ? pageMeta.keywords : projectMeta.keywords
|
|
26
|
-
opengraphThumbnail: pageMeta.opengraphThumbnail ? pageMeta.opengraphThumbnail : projectMeta.opengraphThumbnail
|
|
27
|
-
favicon: projectMeta.favicon
|
|
33
|
+
title: pageMeta.title ? pageMeta.title : (_a = projectMeta.title) !== null && _a !== void 0 ? _a : '',
|
|
34
|
+
description: pageMeta.description ? pageMeta.description : (_b = projectMeta.description) !== null && _b !== void 0 ? _b : '',
|
|
35
|
+
keywords: pageMeta.keywords ? pageMeta.keywords : (_c = projectMeta.keywords) !== null && _c !== void 0 ? _c : '',
|
|
36
|
+
opengraphThumbnail: pageMeta.opengraphThumbnail ? pageMeta.opengraphThumbnail : (_d = projectMeta.opengraphThumbnail) !== null && _d !== void 0 ? _d : '',
|
|
37
|
+
favicon: (_e = projectMeta.favicon) !== null && _e !== void 0 ? _e : ''
|
|
28
38
|
} : projectMeta;
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
getPageData(pageSlug) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const project = yield this.fetchProject();
|
|
44
|
+
const articleId = this.findArticleIdByPageSlug(pageSlug, project.pages);
|
|
45
|
+
const [{ article, keyframes }, typePresets] = yield Promise.all([
|
|
46
|
+
this.fetchArticle(articleId),
|
|
47
|
+
this.fetchTypePresets()
|
|
48
|
+
]);
|
|
49
|
+
const page = project.pages.find(page => page.slug === pageSlug);
|
|
50
|
+
const meta = Client.getPageMeta(project.meta, page === null || page === void 0 ? void 0 : page.meta);
|
|
51
|
+
return {
|
|
52
|
+
project,
|
|
53
|
+
typePresets,
|
|
54
|
+
article,
|
|
55
|
+
keyframes,
|
|
56
|
+
meta
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
51
63
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
getProjectPagesPaths() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
const { pages } = yield this.fetchProject();
|
|
68
|
+
return pages.map(p => p.slug);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
getLayouts() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const { layouts } = yield this.fetchProject();
|
|
79
|
+
return layouts;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
69
85
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
getTypePresets() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const response = yield this.fetchTypePresets();
|
|
89
|
+
return response;
|
|
90
|
+
});
|
|
73
91
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
fetchProject() {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const { username: projectId, password: apiKey, origin } = this.url;
|
|
95
|
+
const url = new url_1.URL(`/projects/${projectId}`, origin);
|
|
96
|
+
const response = yield this.fetchImpl(url.href, {
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${apiKey}`
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw new Error(`Failed to fetch project with id #${projectId}: ${response.statusText}`);
|
|
80
103
|
}
|
|
104
|
+
const data = yield response.json();
|
|
105
|
+
const project = core_1.ProjectSchema.parse(data);
|
|
106
|
+
return project;
|
|
81
107
|
});
|
|
82
|
-
if (!response.ok) {
|
|
83
|
-
throw new Error(`Failed to fetch project with id #${projectId}: ${response.statusText}`);
|
|
84
|
-
}
|
|
85
|
-
const data = await response.json();
|
|
86
|
-
const project = core_1.ProjectSchema.parse(data);
|
|
87
|
-
return project;
|
|
88
108
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
fetchArticle(articleId) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const { username: projectId, password: apiKey, origin } = this.url;
|
|
112
|
+
const url = new url_1.URL(`/projects/${projectId}/articles/${articleId}`, origin);
|
|
113
|
+
const response = yield this.fetchImpl(url.href, {
|
|
114
|
+
headers: {
|
|
115
|
+
Authorization: `Bearer ${apiKey}`
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
throw new Error(`Failed to fetch article with id #${articleId}: ${response.statusText}`);
|
|
95
120
|
}
|
|
121
|
+
const data = yield response.json();
|
|
122
|
+
const article = core_1.ArticleSchema.parse(data.article);
|
|
123
|
+
const keyframes = core_1.KeyframesSchema.parse(data.keyframes);
|
|
124
|
+
return { article, keyframes };
|
|
96
125
|
});
|
|
97
|
-
if (!response.ok) {
|
|
98
|
-
throw new Error(`Failed to fetch article with id #${articleId}: ${response.statusText}`);
|
|
99
|
-
}
|
|
100
|
-
const data = await response.json();
|
|
101
|
-
const article = core_1.ArticleSchema.parse(data.article);
|
|
102
|
-
const keyframes = core_1.KeyframesSchema.parse(data.keyframes);
|
|
103
|
-
return { article, keyframes };
|
|
104
126
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
fetchTypePresets() {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const { username: projectId, password: apiKey, origin } = this.url;
|
|
130
|
+
const url = new url_1.URL(`/projects/${projectId}/type-presets`, origin);
|
|
131
|
+
const response = yield this.fetchImpl(url.href, {
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Bearer ${apiKey}`
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new Error(`Failed to fetch type presets for the project with id #${projectId}: ${response.statusText}`);
|
|
111
138
|
}
|
|
139
|
+
const data = yield response.json();
|
|
140
|
+
const typePresets = core_1.TypePresetsSchema.parse(data);
|
|
141
|
+
return typePresets;
|
|
112
142
|
});
|
|
113
|
-
if (!response.ok) {
|
|
114
|
-
throw new Error(`Failed to fetch type presets for the project with id #${projectId}: ${response.statusText}`);
|
|
115
|
-
}
|
|
116
|
-
const data = await response.json();
|
|
117
|
-
const typePresets = core_1.TypePresetsSchema.parse(data);
|
|
118
|
-
return typePresets;
|
|
119
143
|
}
|
|
120
144
|
findArticleIdByPageSlug(slug, pages) {
|
|
121
145
|
const { username: projectId } = this.url;
|
package/lib/cli.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
3
12
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
14
|
};
|
|
@@ -14,7 +23,7 @@ commander_1.program
|
|
|
14
23
|
.command('generate-layouts')
|
|
15
24
|
.option('-o, --output <outputFilePath>', 'Output file path', 'cntrl.scss')
|
|
16
25
|
.option('-e, --env <envFilename>', 'Name of the .env file', '.env.local')
|
|
17
|
-
.action(
|
|
26
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
27
|
try {
|
|
19
28
|
(0, dotenv_1.config)({ path: options.env });
|
|
20
29
|
const templateFilePath = path_1.default.resolve(__dirname, '../resources/template.scss.ejs');
|
|
@@ -24,7 +33,7 @@ commander_1.program
|
|
|
24
33
|
throw new Error('Environment variable "CNTRL_API_URL" must be set.');
|
|
25
34
|
}
|
|
26
35
|
const client = new Client_1.Client(apiUrl);
|
|
27
|
-
const layouts =
|
|
36
|
+
const layouts = yield client.getLayouts();
|
|
28
37
|
const ranges = convertLayouts(layouts);
|
|
29
38
|
const compiledTemplate = ejs_1.default.compile(scssTemplate);
|
|
30
39
|
const renderedTemplate = compiledTemplate({ ranges });
|
|
@@ -36,7 +45,7 @@ commander_1.program
|
|
|
36
45
|
console.error('An error occurred:', error);
|
|
37
46
|
process.exit(1);
|
|
38
47
|
}
|
|
39
|
-
});
|
|
48
|
+
}));
|
|
40
49
|
function convertLayouts(layouts, maxLayoutWidth = Number.MAX_SAFE_INTEGER) {
|
|
41
50
|
const sorted = layouts.slice().sort((la, lb) => la.startsWith - lb.startsWith);
|
|
42
51
|
const mapped = sorted.map((layout, i, ls) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Generic SDK for use in public websites.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lib": "lib"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cntrl-site/core": "^1.28.
|
|
30
|
+
"@cntrl-site/core": "^1.28.2",
|
|
31
31
|
"@types/ejs": "^3.1.2",
|
|
32
32
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
33
33
|
"commander": "^10.0.1",
|