@cntrl-site/sdk 1.27.0 → 1.27.2

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.
@@ -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);
package/lib/cli.js CHANGED
@@ -69,14 +69,14 @@ commander_1.program
69
69
  return;
70
70
  }
71
71
  const indexable = project.pages.filter(isIndexablePage);
72
- const lastmod = new Date().toISOString();
72
+ const fallbackLastmod = formatLastmod(new Date().toISOString());
73
73
  const outputDir = path_1.default.resolve(process.cwd(), options.output);
74
74
  if (!fs_1.default.existsSync(outputDir)) {
75
75
  fs_1.default.mkdirSync(outputDir, { recursive: true });
76
76
  }
77
77
  const sitemapPath = path_1.default.resolve(outputDir, 'sitemap.xml');
78
78
  const robotsPath = path_1.default.resolve(outputDir, 'robots.txt');
79
- fs_1.default.writeFileSync(sitemapPath, renderSitemap(indexable, siteUrl, lastmod));
79
+ fs_1.default.writeFileSync(sitemapPath, renderSitemap(indexable, siteUrl, fallbackLastmod));
80
80
  fs_1.default.writeFileSync(robotsPath, renderRobots(siteUrl));
81
81
  console.log(`Generated sitemap.xml at ${sitemapPath} (${indexable.length} of ${project.pages.length} pages)`);
82
82
  console.log(`Generated robots.txt at ${robotsPath}`);
@@ -101,9 +101,10 @@ function isIndexablePage(page) {
101
101
  return false;
102
102
  return true;
103
103
  }
104
- function renderSitemap(pages, siteUrl, lastmod) {
104
+ function renderSitemap(pages, siteUrl, fallbackLastmod) {
105
105
  const entries = pages.map(page => {
106
106
  const loc = escapeXml(buildPageUrl(siteUrl, page.slug));
107
+ const lastmod = page.lastModified ? formatLastmod(page.lastModified) : fallbackLastmod;
107
108
  const priority = page.slug === '' ? '1.00' : '0.80';
108
109
  return [
109
110
  ' <url>',
@@ -121,6 +122,10 @@ function renderSitemap(pages, siteUrl, lastmod) {
121
122
  ''
122
123
  ].join('\n');
123
124
  }
125
+ function formatLastmod(iso) {
126
+ // YYYY-MM-DD is sitemap-spec valid and avoids hour-of-rebuild noise.
127
+ return iso.slice(0, 10);
128
+ }
124
129
  function renderRobots(siteUrl) {
125
130
  const sitemapUrl = new URL('/sitemap.xml', siteUrl.origin).toString();
126
131
  return [
@@ -76,6 +76,7 @@ export declare const ProjectSchema: z.ZodObject<{
76
76
  id: z.ZodString;
77
77
  isPublished: z.ZodOptional<z.ZodBoolean>;
78
78
  isAuthProtected: z.ZodOptional<z.ZodBoolean>;
79
+ lastModified: z.ZodOptional<z.ZodString>;
79
80
  }, "strip", z.ZodTypeAny, {
80
81
  id: string;
81
82
  title: string;
@@ -90,6 +91,7 @@ export declare const ProjectSchema: z.ZodObject<{
90
91
  } | undefined;
91
92
  isPublished?: boolean | undefined;
92
93
  isAuthProtected?: boolean | undefined;
94
+ lastModified?: string | undefined;
93
95
  }, {
94
96
  id: string;
95
97
  title: string;
@@ -104,6 +106,7 @@ export declare const ProjectSchema: z.ZodObject<{
104
106
  } | undefined;
105
107
  isPublished?: boolean | undefined;
106
108
  isAuthProtected?: boolean | undefined;
109
+ lastModified?: string | undefined;
107
110
  }>, "many">;
108
111
  fonts: z.ZodObject<{
109
112
  google: z.ZodString;
@@ -199,6 +202,7 @@ export declare const ProjectSchema: z.ZodObject<{
199
202
  } | undefined;
200
203
  isPublished?: boolean | undefined;
201
204
  isAuthProtected?: boolean | undefined;
205
+ lastModified?: string | undefined;
202
206
  }[];
203
207
  fonts: {
204
208
  custom: {
@@ -248,6 +252,7 @@ export declare const ProjectSchema: z.ZodObject<{
248
252
  } | undefined;
249
253
  isPublished?: boolean | undefined;
250
254
  isAuthProtected?: boolean | undefined;
255
+ lastModified?: string | undefined;
251
256
  }[];
252
257
  fonts: {
253
258
  custom: {
@@ -32,7 +32,8 @@ exports.ProjectSchema = zod_1.z.object({
32
32
  }).optional(),
33
33
  id: zod_1.z.string().min(1),
34
34
  isPublished: zod_1.z.boolean().optional(),
35
- isAuthProtected: zod_1.z.boolean().optional()
35
+ isAuthProtected: zod_1.z.boolean().optional(),
36
+ lastModified: zod_1.z.string().optional()
36
37
  })),
37
38
  fonts: zod_1.z.object({
38
39
  google: zod_1.z.string(),
@@ -10,4 +10,5 @@ export interface Page {
10
10
  meta?: PageMeta;
11
11
  isPublished?: boolean;
12
12
  isAuthProtected?: boolean;
13
+ lastModified?: string;
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk",
3
- "version": "1.27.0",
3
+ "version": "1.27.2",
4
4
  "description": "Generic SDK for use in public websites.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",