@cntrl-site/sdk 1.28.0-6 → 1.28.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 CNTRL
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 CNTRL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # CNTRL SDK
2
- This is a root SDK module for CNTRL. Should be used along with other framework-specific modules like `@cntrl-site/sdk-react`
1
+ # CNTRL SDK
2
+ This is a root SDK module for CNTRL. Should be used along with other framework-specific modules like `@cntrl-site/sdk-react`
@@ -18,6 +18,7 @@ export declare class Client {
18
18
  getHostname(): string;
19
19
  private fetchProject;
20
20
  private fetchArticle;
21
+ private request;
21
22
  private findArticleIdByPageSlug;
22
23
  }
23
24
  interface FetchImplResponse {
@@ -90,11 +90,7 @@ class Client {
90
90
  return __awaiter(this, arguments, void 0, function* (buildMode = 'default') {
91
91
  const { username: projectId, password: apiKey, origin } = this.url;
92
92
  const url = new url_1.URL(`/projects/${projectId}/custom-components?buildMode=${buildMode}`, origin);
93
- const response = yield this.fetchImpl(url.href, {
94
- headers: {
95
- Authorization: `Bearer ${apiKey}`
96
- }
97
- });
93
+ const response = yield this.request(url.href, apiKey);
98
94
  if (!response.ok) {
99
95
  throw new Error(`Failed to fetch custom components for project #${projectId}: ${response.statusText}`);
100
96
  }
@@ -105,11 +101,7 @@ class Client {
105
101
  return __awaiter(this, arguments, void 0, function* (componentId, buildMode = 'default') {
106
102
  const { username: projectId, password: apiKey, origin } = this.url;
107
103
  const url = new url_1.URL(`/projects/${projectId}/custom-components/${componentId}/bundle.js?buildMode=${buildMode}`, origin);
108
- const response = yield this.fetchImpl(url.href, {
109
- headers: {
110
- Authorization: `Bearer ${apiKey}`
111
- }
112
- });
104
+ const response = yield this.request(url.href, apiKey);
113
105
  if (!response.ok) {
114
106
  throw new Error(`Failed to fetch bundle for custom component #${componentId}: ${response.statusText}`);
115
107
  }
@@ -123,11 +115,7 @@ class Client {
123
115
  return __awaiter(this, arguments, void 0, function* (buildMode = 'default') {
124
116
  const { username: projectId, password: apiKey, origin } = this.url;
125
117
  const url = new url_1.URL(`/projects/${projectId}?buildMode=${buildMode}`, origin);
126
- const response = yield this.fetchImpl(url.href, {
127
- headers: {
128
- Authorization: `Bearer ${apiKey}`
129
- }
130
- });
118
+ const response = yield this.request(url.href, apiKey);
131
119
  if (!response.ok) {
132
120
  throw new Error(`Failed to fetch project with id #${projectId}: ${response.statusText}`);
133
121
  }
@@ -140,11 +128,7 @@ class Client {
140
128
  return __awaiter(this, arguments, void 0, function* (articleId, buildMode = 'default') {
141
129
  const { username: projectId, password: apiKey, origin } = this.url;
142
130
  const url = new url_1.URL(`/projects/${projectId}/articles/${articleId}?buildMode=${buildMode}`, origin);
143
- const response = yield this.fetchImpl(url.href, {
144
- headers: {
145
- Authorization: `Bearer ${apiKey}`
146
- }
147
- });
131
+ const response = yield this.request(url.href, apiKey);
148
132
  if (!response.ok) {
149
133
  throw new Error(`Failed to fetch article with id #${articleId}: ${response.statusText}`);
150
134
  }
@@ -154,6 +138,16 @@ class Client {
154
138
  return { article, keyframes };
155
139
  });
156
140
  }
141
+ request(url, apiKey) {
142
+ const init = {
143
+ compress: false,
144
+ headers: {
145
+ Authorization: `Bearer ${apiKey}`,
146
+ 'Accept-Encoding': 'identity'
147
+ }
148
+ };
149
+ return this.fetchImpl(url, init);
150
+ }
157
151
  findArticleIdByPageSlug(slug, pages) {
158
152
  const { username: projectId } = this.url;
159
153
  const page = pages.find((page) => page.slug === slug);
@@ -15,12 +15,12 @@ class FontFaceGenerator {
15
15
  const otherFiles = font.files
16
16
  .filter(file => file.type !== 'eot')
17
17
  .map(file => `url('${file.url}') format('${FILE_TYPES_MAP[file.type] || file.type}')`);
18
- return `
19
- @font-face {
20
- font-family: "${font.name}";
21
- font-weight: ${font.weight};
22
- font-style: ${font.style};
23
- ${eotFile ? `src: url('${eotFile.url}');\n ` : ''}src: ${otherFiles.join(', ')};
18
+ return `
19
+ @font-face {
20
+ font-family: "${font.name}";
21
+ font-weight: ${font.weight};
22
+ font-style: ${font.style};
23
+ ${eotFile ? `src: url('${eotFile.url}');\n ` : ''}src: ${otherFiles.join(', ')};
24
24
  }`;
25
25
  }).join('\n');
26
26
  }
@@ -6,16 +6,22 @@ export declare const StructuredBlockAreaSchema: z.ZodObject<{
6
6
  height: z.ZodOptional<z.ZodNumber>;
7
7
  paddingTop: z.ZodOptional<z.ZodNumber>;
8
8
  zIndex: z.ZodNumber;
9
+ alignment: z.ZodOptional<z.ZodEnum<["left", "center", "right"]>>;
10
+ horizontalOffset: z.ZodOptional<z.ZodNumber>;
9
11
  }, "strip", z.ZodTypeAny, {
10
12
  zIndex: number;
11
13
  width?: number | undefined;
12
14
  height?: number | undefined;
13
15
  paddingTop?: number | undefined;
16
+ alignment?: "center" | "left" | "right" | undefined;
17
+ horizontalOffset?: number | undefined;
14
18
  }, {
15
19
  zIndex: number;
16
20
  width?: number | undefined;
17
21
  height?: number | undefined;
18
22
  paddingTop?: number | undefined;
23
+ alignment?: "center" | "left" | "right" | undefined;
24
+ horizontalOffset?: number | undefined;
19
25
  }>;
20
26
  export declare const StructuredBlockComponentCommonParamsSchema: z.ZodObject<{
21
27
  componentId: z.ZodString;
@@ -12,7 +12,9 @@ exports.StructuredBlockAreaSchema = zod_1.z.object({
12
12
  width: zod_1.z.number().nonnegative().optional(),
13
13
  height: zod_1.z.number().nonnegative().optional(),
14
14
  paddingTop: zod_1.z.number().optional(),
15
- zIndex: zod_1.z.number()
15
+ zIndex: zod_1.z.number(),
16
+ alignment: zod_1.z.enum(['left', 'center', 'right']).optional(),
17
+ horizontalOffset: zod_1.z.number().optional()
16
18
  });
17
19
  exports.StructuredBlockComponentCommonParamsSchema = zod_1.z.object({
18
20
  componentId: zod_1.z.string(),
@@ -8,6 +8,8 @@ export interface StructuredBlockArea {
8
8
  height?: number;
9
9
  paddingTop?: number;
10
10
  zIndex: number;
11
+ alignment?: 'left' | 'center' | 'right';
12
+ horizontalOffset?: number;
11
13
  }
12
14
  export interface StructuredBlockComponentCommonParams {
13
15
  componentId: string;
package/lib/utils.js CHANGED
@@ -8,8 +8,8 @@ function getLayoutStyles(layouts, layoutValues, mapToStyles) {
8
8
  .sort((a, b) => a.startsWith - b.startsWith)
9
9
  .reduce((acc, layout) => {
10
10
  const values = layoutValues.map(lv => lv[layout.id]);
11
- return `
12
- ${acc}
11
+ return `
12
+ ${acc}
13
13
  ${layout.startsWith !== 0
14
14
  ? `@media (min-width: ${layout.startsWith}px) {${mapToStyles(values, layout.exemplary)}}`
15
15
  : `${mapToStyles(values, layout.exemplary)}`}`;
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@cntrl-site/sdk",
3
- "version": "1.28.0-6",
4
- "description": "Generic SDK for use in public websites.",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "scripts": {
8
- "test": "jest",
9
- "prebuild": "rimraf ./lib",
10
- "build": "tsc --project tsconfig.build.json",
11
- "build:watch": "tsc --watch --project tsconfig.build.json",
12
- "prepublishOnly": "cross-env NODE_ENV=production npm run build"
13
- },
14
- "bin": {
15
- "cntrl-sdk": "lib/cli.js"
16
- },
17
- "files": [
18
- "lib",
19
- "resources"
20
- ],
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/cntrl-site/sdk.git"
24
- },
25
- "author": "arsen@momdesign.nyc",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/cntrl-site/sdk/issues"
29
- },
30
- "homepage": "https://github.com/cntrl-site/sdk#readme",
31
- "directories": {
32
- "lib": "lib"
33
- },
34
- "dependencies": {
35
- "@splidejs/react-splide": "^0.7.12",
36
- "@types/ejs": "^3.1.2",
37
- "@types/isomorphic-fetch": "^0.0.36",
38
- "@types/ua-parser-js": "^0.7.39",
39
- "commander": "^10.0.1",
40
- "dotenv": "^16.1.3",
41
- "ejs": "^3.1.9",
42
- "isomorphic-fetch": "^3.0.0",
43
- "mp4box": "^0.5.2",
44
- "styled-jsx": "^5.1.6",
45
- "ts-node": "^10.9.1",
46
- "ua-parser-js": "^1.0.37",
47
- "url": "^0.11.0",
48
- "zod": "^3.22.4"
49
- },
50
- "devDependencies": {
51
- "@tsconfig/node16": "^1.0.3",
52
- "@tsconfig/recommended": "^1.0.1",
53
- "@types/jest": "^29.0.0",
54
- "@types/node": "^18.11.7",
55
- "@types/react": "^18.2.0",
56
- "@types/react-dom": "^18.2.0",
57
- "@vitejs/plugin-react": "^4.3.4",
58
- "cross-env": "^10.1.0",
59
- "jest": "^28.1.3",
60
- "ts-jest": "^28.0.8",
61
- "typescript": "^5.2.2"
62
- }
63
- }
1
+ {
2
+ "name": "@cntrl-site/sdk",
3
+ "version": "1.28.0",
4
+ "description": "Generic SDK for use in public websites.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "test": "jest",
9
+ "prebuild": "rimraf ./lib",
10
+ "build": "tsc --project tsconfig.build.json",
11
+ "build:watch": "tsc --watch --project tsconfig.build.json",
12
+ "prepublishOnly": "cross-env NODE_ENV=production npm run build"
13
+ },
14
+ "bin": {
15
+ "cntrl-sdk": "lib/cli.js"
16
+ },
17
+ "files": [
18
+ "lib",
19
+ "resources"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/cntrl-site/sdk.git"
24
+ },
25
+ "author": "arsen@momdesign.nyc",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/cntrl-site/sdk/issues"
29
+ },
30
+ "homepage": "https://github.com/cntrl-site/sdk#readme",
31
+ "directories": {
32
+ "lib": "lib"
33
+ },
34
+ "dependencies": {
35
+ "@splidejs/react-splide": "^0.7.12",
36
+ "@types/ejs": "^3.1.2",
37
+ "@types/isomorphic-fetch": "^0.0.36",
38
+ "@types/ua-parser-js": "^0.7.39",
39
+ "commander": "^10.0.1",
40
+ "dotenv": "^16.1.3",
41
+ "ejs": "^3.1.9",
42
+ "isomorphic-fetch": "^3.0.0",
43
+ "mp4box": "^0.5.2",
44
+ "styled-jsx": "^5.1.6",
45
+ "ts-node": "^10.9.1",
46
+ "ua-parser-js": "^1.0.37",
47
+ "url": "^0.11.0",
48
+ "zod": "^3.22.4"
49
+ },
50
+ "devDependencies": {
51
+ "@tsconfig/node16": "^1.0.3",
52
+ "@tsconfig/recommended": "^1.0.1",
53
+ "@types/jest": "^29.0.0",
54
+ "@types/node": "^18.11.7",
55
+ "@types/react": "^18.2.0",
56
+ "@types/react-dom": "^18.2.0",
57
+ "@vitejs/plugin-react": "^4.3.4",
58
+ "cross-env": "^10.1.0",
59
+ "jest": "^28.1.3",
60
+ "ts-jest": "^28.0.8",
61
+ "typescript": "^5.2.2"
62
+ }
63
+ }
@@ -1,50 +1,50 @@
1
- // CAUTION: THIS FILE IS AUTO-GENERATED BASED ON
2
- // LAYOUT CONFIGURATION IN YOUR CNTRL PROJECT
3
- // WE HIGHLY ADVICE YOU TO NOT CHANGE IT MANUALLY
4
- @use "sass:map";
5
-
6
- $__CNTRL_LAYOUT_WIDTH__: <%= ranges[0].exemplary %>;
7
-
8
- $layout: (
9
- <% ranges.forEach(function(range) { %>
10
- <%= range.name %>: (
11
- start: <%= range.start %>,
12
- end: <%= range.end %>,
13
- exemplary: <%= range.exemplary %>,
14
- isFirst: <%= range.isFirst %>,
15
- isLast: <%= range.isLast %>
16
- ),
17
- <% }); %>
18
- );
19
-
20
- @function size($value) {
21
- @return #{$value/$__CNTRL_LAYOUT_WIDTH__*100}vw;
22
- }
23
-
24
- @mixin for($name) {
25
- $start: map.get(map.get($layout, $name), "start");
26
- $end: map.get(map.get($layout, $name), "end");
27
- $isFirst: map.get(map.get($layout, $name), "isFirst");
28
- $isLast: map.get(map.get($layout, $name), "isLast");
29
- $exemplary: map.get(map.get($layout, $name), "exemplary");
30
- $__CNTRL_LAYOUT_WIDTH__: $exemplary !global;
31
-
32
- @if $isFirst == true and $isLast == true {
33
- @content;
34
- } @else if $isFirst == true {
35
- @media (max-width: #{$end}px) {
36
- @content;
37
- }
38
- } @else if $isLast == true {
39
- @media (min-width: #{$start}px) {
40
- @content;
41
- }
42
- } @else {
43
- @media (min-width: #{$start}px) and (max-width: #{$end}px) {
44
- @content;
45
- }
46
- }
47
-
48
- // reset global variable back to first layout's exemplary (mobile-first)
49
- $__CNTRL_LAYOUT_WIDTH__: <%= ranges[0].exemplary %> !global;
50
- }
1
+ // CAUTION: THIS FILE IS AUTO-GENERATED BASED ON
2
+ // LAYOUT CONFIGURATION IN YOUR CNTRL PROJECT
3
+ // WE HIGHLY ADVICE YOU TO NOT CHANGE IT MANUALLY
4
+ @use "sass:map";
5
+
6
+ $__CNTRL_LAYOUT_WIDTH__: <%= ranges[0].exemplary %>;
7
+
8
+ $layout: (
9
+ <% ranges.forEach(function(range) { %>
10
+ <%= range.name %>: (
11
+ start: <%= range.start %>,
12
+ end: <%= range.end %>,
13
+ exemplary: <%= range.exemplary %>,
14
+ isFirst: <%= range.isFirst %>,
15
+ isLast: <%= range.isLast %>
16
+ ),
17
+ <% }); %>
18
+ );
19
+
20
+ @function size($value) {
21
+ @return #{$value/$__CNTRL_LAYOUT_WIDTH__*100}vw;
22
+ }
23
+
24
+ @mixin for($name) {
25
+ $start: map.get(map.get($layout, $name), "start");
26
+ $end: map.get(map.get($layout, $name), "end");
27
+ $isFirst: map.get(map.get($layout, $name), "isFirst");
28
+ $isLast: map.get(map.get($layout, $name), "isLast");
29
+ $exemplary: map.get(map.get($layout, $name), "exemplary");
30
+ $__CNTRL_LAYOUT_WIDTH__: $exemplary !global;
31
+
32
+ @if $isFirst == true and $isLast == true {
33
+ @content;
34
+ } @else if $isFirst == true {
35
+ @media (max-width: #{$end}px) {
36
+ @content;
37
+ }
38
+ } @else if $isLast == true {
39
+ @media (min-width: #{$start}px) {
40
+ @content;
41
+ }
42
+ } @else {
43
+ @media (min-width: #{$start}px) and (max-width: #{$end}px) {
44
+ @content;
45
+ }
46
+ }
47
+
48
+ // reset global variable back to first layout's exemplary (mobile-first)
49
+ $__CNTRL_LAYOUT_WIDTH__: <%= ranges[0].exemplary %> !global;
50
+ }