sb-mig 5.7.0-beta.1 → 5.7.0-beta.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.
@@ -2,6 +2,24 @@ import chalk from "chalk";
2
2
  import Logger from "../../utils/logger.js";
3
3
  import { notNullish } from "../../utils/object-utils.js";
4
4
  import { getAllItemsWithPagination } from "../utils/request.js";
5
+ const resolveStoryLabel = (content, storyId) => content?.full_slug || content?.slug || content?.name || String(storyId);
6
+ const resolveStoryblokErrorResponse = (err) => {
7
+ if (typeof err?.response === "string" && err.response.trim().length > 0) {
8
+ return err.response.trim();
9
+ }
10
+ if (typeof err?.response?.data === "string" &&
11
+ err.response.data.trim().length > 0) {
12
+ return err.response.data.trim();
13
+ }
14
+ if (typeof err?.response?.message === "string" &&
15
+ err.response.message.trim().length > 0) {
16
+ return err.response.message.trim();
17
+ }
18
+ if (typeof err?.message === "string" && err.message.trim().length > 0) {
19
+ return err.message.trim();
20
+ }
21
+ return undefined;
22
+ };
5
23
  export const removeStory = (args, config) => {
6
24
  const { storyId } = args;
7
25
  const { spaceId, sbApi } = config;
@@ -106,6 +124,7 @@ export const createStory = (content, config) => {
106
124
  // UPDATE
107
125
  export const updateStory = (content, storyId, options, config) => {
108
126
  const { spaceId, sbApi } = config;
127
+ const storyLabel = resolveStoryLabel(content, storyId);
109
128
  Logger.warning("Trying to update Story...");
110
129
  Logger.log(`Updating story with name: ${content.name} in space: ${spaceId}`);
111
130
  // console.log("THis is content to update: ");
@@ -127,12 +146,21 @@ export const updateStory = (content, storyId, options, config) => {
127
146
  };
128
147
  })
129
148
  .catch((err) => {
130
- console.error(err);
149
+ const status = err?.status || err?.response?.status;
150
+ const responseMessage = resolveStoryblokErrorResponse(err);
151
+ const statusLabel = status ? `status ${status}` : "unknown status";
152
+ const responseLabel = responseMessage
153
+ ? ` Response: ${responseMessage}`
154
+ : "";
155
+ Logger.error(`Failed to update story '${storyLabel}' in space '${spaceId}' (${statusLabel}).${responseLabel}`);
131
156
  return {
132
157
  ok: false,
133
158
  id: storyId,
134
159
  name: content?.name,
135
160
  slug: content?.full_slug || content?.slug,
161
+ spaceId,
162
+ status,
163
+ response: responseMessage,
136
164
  error: err,
137
165
  };
138
166
  });
@@ -8,6 +8,24 @@ const chalk_1 = __importDefault(require("chalk"));
8
8
  const logger_js_1 = __importDefault(require("../../utils/logger.js"));
9
9
  const object_utils_js_1 = require("../../utils/object-utils.js");
10
10
  const request_js_1 = require("../utils/request.js");
11
+ const resolveStoryLabel = (content, storyId) => content?.full_slug || content?.slug || content?.name || String(storyId);
12
+ const resolveStoryblokErrorResponse = (err) => {
13
+ if (typeof err?.response === "string" && err.response.trim().length > 0) {
14
+ return err.response.trim();
15
+ }
16
+ if (typeof err?.response?.data === "string" &&
17
+ err.response.data.trim().length > 0) {
18
+ return err.response.data.trim();
19
+ }
20
+ if (typeof err?.response?.message === "string" &&
21
+ err.response.message.trim().length > 0) {
22
+ return err.response.message.trim();
23
+ }
24
+ if (typeof err?.message === "string" && err.message.trim().length > 0) {
25
+ return err.message.trim();
26
+ }
27
+ return undefined;
28
+ };
11
29
  const removeStory = (args, config) => {
12
30
  const { storyId } = args;
13
31
  const { spaceId, sbApi } = config;
@@ -118,6 +136,7 @@ exports.createStory = createStory;
118
136
  // UPDATE
119
137
  const updateStory = (content, storyId, options, config) => {
120
138
  const { spaceId, sbApi } = config;
139
+ const storyLabel = resolveStoryLabel(content, storyId);
121
140
  logger_js_1.default.warning("Trying to update Story...");
122
141
  logger_js_1.default.log(`Updating story with name: ${content.name} in space: ${spaceId}`);
123
142
  // console.log("THis is content to update: ");
@@ -139,12 +158,21 @@ const updateStory = (content, storyId, options, config) => {
139
158
  };
140
159
  })
141
160
  .catch((err) => {
142
- console.error(err);
161
+ const status = err?.status || err?.response?.status;
162
+ const responseMessage = resolveStoryblokErrorResponse(err);
163
+ const statusLabel = status ? `status ${status}` : "unknown status";
164
+ const responseLabel = responseMessage
165
+ ? ` Response: ${responseMessage}`
166
+ : "";
167
+ logger_js_1.default.error(`Failed to update story '${storyLabel}' in space '${spaceId}' (${statusLabel}).${responseLabel}`);
143
168
  return {
144
169
  ok: false,
145
170
  id: storyId,
146
171
  name: content?.name,
147
172
  slug: content?.full_slug || content?.slug,
173
+ spaceId,
174
+ status,
175
+ response: responseMessage,
148
176
  error: err,
149
177
  };
150
178
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sb-mig",
3
- "version": "5.7.0-beta.1",
3
+ "version": "5.7.0-beta.2",
4
4
  "description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
5
5
  "author": "Marcin Krawczyk <marckraw@icloud.com>",
6
6
  "license": "MIT",