sb-mig 5.6.0-beta.1 → 5.6.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.
Files changed (172) hide show
  1. package/README.md +20 -19
  2. package/dist/api/assets/assets.js +1 -14
  3. package/dist/api/components/components.js +2 -1
  4. package/dist/api/components/components.sync.d.ts +8 -0
  5. package/dist/api/components/components.sync.js +193 -0
  6. package/dist/api/data-migration/component-data-migration.js +2 -2
  7. package/dist/api/datasources/datasource-entries.js +4 -5
  8. package/dist/api/datasources/datasources.d.ts +5 -2
  9. package/dist/api/datasources/datasources.js +42 -35
  10. package/dist/api/datasources/datasources.sync.d.ts +2 -0
  11. package/dist/api/datasources/datasources.sync.js +11 -0
  12. package/dist/api/datasources/datasources.types.d.ts +1 -1
  13. package/dist/api/datasources/index.d.ts +2 -1
  14. package/dist/api/datasources/index.js +2 -1
  15. package/dist/api/managementApi.d.ts +2 -2
  16. package/dist/api/migrate.d.ts +1 -1
  17. package/dist/api/migrate.js +3 -48
  18. package/dist/api/plugins/index.d.ts +2 -1
  19. package/dist/api/plugins/index.js +2 -1
  20. package/dist/api/plugins/plugins.d.ts +7 -2
  21. package/dist/api/plugins/plugins.js +28 -15
  22. package/dist/api/plugins/plugins.sync.d.ts +2 -0
  23. package/dist/api/plugins/plugins.sync.js +11 -0
  24. package/dist/api/roles/index.d.ts +2 -1
  25. package/dist/api/roles/index.js +2 -1
  26. package/dist/api/roles/roles.d.ts +5 -2
  27. package/dist/api/roles/roles.js +34 -11
  28. package/dist/api/roles/roles.sync.d.ts +2 -0
  29. package/dist/api/roles/roles.sync.js +6 -0
  30. package/dist/api/roles/roles.types.d.ts +1 -1
  31. package/dist/api/stories/stories.js +3 -11
  32. package/dist/api/sync/sync.types.d.ts +30 -0
  33. package/dist/api/sync/sync.types.js +1 -0
  34. package/dist/api/testApi.d.ts +2 -2
  35. package/dist/api/utils/helper-functions.d.ts +5 -1
  36. package/dist/api/utils/helper-functions.js +6 -1
  37. package/dist/api/utils/request.d.ts +1 -1
  38. package/dist/api/utils/request.js +11 -2
  39. package/dist/api/utils/resolverTransformations.js +2 -57
  40. package/dist/api-v2/assets/index.d.ts +13 -0
  41. package/dist/api-v2/assets/index.js +25 -0
  42. package/dist/api-v2/auth/index.d.ts +3 -0
  43. package/dist/api-v2/auth/index.js +8 -0
  44. package/dist/api-v2/client.d.ts +13 -0
  45. package/dist/api-v2/client.js +17 -0
  46. package/dist/api-v2/components/index.d.ts +10 -0
  47. package/dist/api-v2/components/index.js +29 -0
  48. package/dist/api-v2/datasources/index.d.ts +8 -0
  49. package/dist/api-v2/datasources/index.js +58 -0
  50. package/dist/api-v2/discover/discover.d.ts +36 -0
  51. package/dist/api-v2/discover/discover.js +281 -0
  52. package/dist/api-v2/discover/index.d.ts +2 -0
  53. package/dist/api-v2/discover/index.js +1 -0
  54. package/dist/api-v2/index.d.ts +19 -0
  55. package/dist/api-v2/index.js +21 -0
  56. package/dist/api-v2/plugins/index.d.ts +9 -0
  57. package/dist/api-v2/plugins/index.js +42 -0
  58. package/dist/api-v2/precompile/index.d.ts +2 -0
  59. package/dist/api-v2/precompile/index.js +1 -0
  60. package/dist/api-v2/precompile/precompile.d.ts +65 -0
  61. package/dist/api-v2/precompile/precompile.js +127 -0
  62. package/dist/api-v2/presets/index.d.ts +13 -0
  63. package/dist/api-v2/presets/index.js +25 -0
  64. package/dist/api-v2/requestConfig.d.ts +5 -0
  65. package/dist/api-v2/requestConfig.js +34 -0
  66. package/dist/api-v2/roles/index.d.ts +5 -0
  67. package/dist/api-v2/roles/index.js +35 -0
  68. package/dist/api-v2/spaces/index.d.ts +7 -0
  69. package/dist/api-v2/spaces/index.js +11 -0
  70. package/dist/api-v2/stories/index.d.ts +34 -0
  71. package/dist/api-v2/stories/index.js +172 -0
  72. package/dist/api-v2/stories/types.d.ts +28 -0
  73. package/dist/api-v2/stories/types.js +1 -0
  74. package/dist/api-v2/sync/index.d.ts +24 -0
  75. package/dist/api-v2/sync/index.js +109 -0
  76. package/dist/api-v2/sync/types.d.ts +1 -0
  77. package/dist/api-v2/sync/types.js +1 -0
  78. package/dist/api-v2/test.d.ts +15 -0
  79. package/dist/api-v2/test.js +21 -0
  80. package/dist/cli/commands/backup.js +7 -3
  81. package/dist/cli/commands/copy.js +2 -2
  82. package/dist/cli/commands/migrate.js +1 -2
  83. package/dist/cli/commands/migrations.js +2 -2
  84. package/dist/cli/commands/remove.js +1 -1
  85. package/dist/cli/commands/revert.js +2 -2
  86. package/dist/cli/commands/sync.js +1 -2
  87. package/dist/cli/index.js +1 -1
  88. package/dist/cli/utils/cli-utils.d.ts +69 -0
  89. package/dist/cli/utils/cli-utils.js +100 -0
  90. package/dist/cli/utils/discover.d.ts +3 -22
  91. package/dist/cli/utils/discover.js +4 -51
  92. package/dist/config/config.d.ts +2 -39
  93. package/dist/config/config.types.d.ts +40 -0
  94. package/dist/config/config.types.js +1 -0
  95. package/dist/config/defaultConfig.d.ts +1 -1
  96. package/dist/config/defaultConfig.js +2 -2
  97. package/dist/utils/array-utils.d.ts +20 -0
  98. package/dist/utils/array-utils.js +20 -0
  99. package/dist/utils/async-utils.d.ts +13 -0
  100. package/dist/utils/async-utils.js +13 -0
  101. package/dist/utils/date-utils.d.ts +14 -0
  102. package/dist/utils/date-utils.js +21 -0
  103. package/dist/utils/files.d.ts +35 -0
  104. package/dist/utils/files.js +57 -2
  105. package/dist/utils/main.d.ts +8 -18
  106. package/dist/utils/main.js +12 -104
  107. package/dist/utils/migrations.d.ts +9 -3
  108. package/dist/utils/object-utils.d.ts +46 -0
  109. package/dist/utils/object-utils.js +71 -0
  110. package/dist/utils/others.d.ts +6 -9
  111. package/dist/utils/others.js +8 -15
  112. package/dist/utils/path-utils.d.ts +89 -0
  113. package/dist/utils/path-utils.js +106 -0
  114. package/dist/utils/pkg.d.ts +16 -2
  115. package/dist/utils/pkg.js +16 -3
  116. package/dist/utils/string-utils.d.ts +33 -0
  117. package/dist/utils/string-utils.js +45 -0
  118. package/dist/utils/transform-utils.d.ts +62 -0
  119. package/dist/utils/transform-utils.js +113 -0
  120. package/dist-cjs/api/auth/auth.js +28 -0
  121. package/dist-cjs/api/auth/auth.types.js +2 -0
  122. package/dist-cjs/api/components/components.js +202 -0
  123. package/dist-cjs/api/components/components.sync.js +199 -0
  124. package/dist-cjs/api/components/components.types.js +2 -0
  125. package/dist-cjs/api/datasources/datasource-entries.js +166 -0
  126. package/dist-cjs/api/datasources/datasources.js +166 -0
  127. package/dist-cjs/api/datasources/datasources.types.js +2 -0
  128. package/dist-cjs/api/plugins/plugins.js +132 -0
  129. package/dist-cjs/api/plugins/plugins.types.js +2 -0
  130. package/dist-cjs/api/presets/componentPresets.js +25 -0
  131. package/dist-cjs/api/presets/presets.js +92 -0
  132. package/dist-cjs/api/presets/presets.types.js +2 -0
  133. package/dist-cjs/api/presets/resolvePresets.js +49 -0
  134. package/dist-cjs/api/roles/roles.js +131 -0
  135. package/dist-cjs/api/roles/roles.types.js +2 -0
  136. package/dist-cjs/api/spaces/spaces.js +34 -0
  137. package/dist-cjs/api/spaces/spaces.types.js +2 -0
  138. package/dist-cjs/api/stories/stories.js +214 -0
  139. package/dist-cjs/api/stories/stories.types.js +2 -0
  140. package/dist-cjs/api/sync/sync.types.js +2 -0
  141. package/dist-cjs/api/utils/request.js +48 -0
  142. package/dist-cjs/api/utils/resolvers.types.js +2 -0
  143. package/dist-cjs/api-v2/assets/index.js +30 -0
  144. package/dist-cjs/api-v2/auth/index.js +12 -0
  145. package/dist-cjs/api-v2/client.js +23 -0
  146. package/dist-cjs/api-v2/components/index.js +40 -0
  147. package/dist-cjs/api-v2/datasources/index.js +64 -0
  148. package/dist-cjs/api-v2/discover/discover.js +321 -0
  149. package/dist-cjs/api-v2/discover/index.js +9 -0
  150. package/dist-cjs/api-v2/index.js +60 -0
  151. package/dist-cjs/api-v2/plugins/index.js +49 -0
  152. package/dist-cjs/api-v2/precompile/index.js +7 -0
  153. package/dist-cjs/api-v2/precompile/precompile.js +136 -0
  154. package/dist-cjs/api-v2/presets/index.js +33 -0
  155. package/dist-cjs/api-v2/requestConfig.js +37 -0
  156. package/dist-cjs/api-v2/roles/index.js +41 -0
  157. package/dist-cjs/api-v2/spaces/index.js +16 -0
  158. package/dist-cjs/api-v2/stories/index.js +180 -0
  159. package/dist-cjs/api-v2/stories/types.js +2 -0
  160. package/dist-cjs/api-v2/sync/index.js +115 -0
  161. package/dist-cjs/api-v2/sync/types.js +2 -0
  162. package/dist-cjs/api-v2/test.js +25 -0
  163. package/dist-cjs/config/config.types.js +2 -0
  164. package/dist-cjs/config/constants.js +29 -0
  165. package/dist-cjs/package.json +3 -0
  166. package/dist-cjs/utils/array-utils.js +24 -0
  167. package/dist-cjs/utils/logger.js +32 -0
  168. package/dist-cjs/utils/object-utils.js +77 -0
  169. package/dist-cjs/utils/path-utils.js +115 -0
  170. package/package.json +37 -20
  171. package/dist/utils/pkg-require.d.ts +0 -2
  172. package/dist/utils/pkg-require.js +0 -4
@@ -1 +1,2 @@
1
- export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, syncProvidedPlugins, } from "./plugins.js";
1
+ export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
2
+ export { syncProvidedPlugins } from "./plugins.sync.js";
@@ -1 +1,2 @@
1
- export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, syncProvidedPlugins, } from "./plugins.js";
1
+ export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
2
+ export { syncProvidedPlugins } from "./plugins.sync.js";
@@ -1,8 +1,13 @@
1
1
  import type { CreatePlugin, GetAllPlugins, GetPlugin, GetPluginDetails, UpdatePlugin } from "./plugins.types.js";
2
- import type { SyncProvidedPlugins } from "./plugins.types.js";
2
+ import type { SyncResult } from "../sync/sync.types.js";
3
3
  export declare const getAllPlugins: GetAllPlugins;
4
4
  export declare const getPlugin: GetPlugin;
5
5
  export declare const getPluginDetails: GetPluginDetails;
6
6
  export declare const updatePlugin: UpdatePlugin;
7
7
  export declare const createPlugin: CreatePlugin;
8
- export declare const syncProvidedPlugins: SyncProvidedPlugins;
8
+ export declare const syncPluginsData: ({ plugins }: {
9
+ plugins: {
10
+ name: string;
11
+ body: string;
12
+ }[];
13
+ }, config: any) => Promise<SyncResult>;
@@ -1,4 +1,3 @@
1
- import { readFile } from "../../utils/files.js";
2
1
  import Logger from "../../utils/logger.js";
3
2
  import { getAllItemsWithPagination } from "../utils/request.js";
4
3
  export const getAllPlugins = (config) => {
@@ -87,21 +86,35 @@ export const createPlugin = (pluginName, config) => {
87
86
  console.error("Error happened :()");
88
87
  });
89
88
  };
90
- export const syncProvidedPlugins = async ({ plugins }, config) => {
91
- const body = await readFile("dist/export.js");
92
- if (plugins.length === 1) {
93
- const pluginName = plugins[0];
94
- const plugin = await getPlugin(pluginName, config);
95
- if (plugin) {
96
- Logger.log("Plugin exist.");
97
- Logger.log("Start updating plugin....");
98
- return await updatePlugin({ plugin: plugin.field_type, body }, config);
89
+ // File-based sync wrapper lives in `plugins.sync.ts` to keep this module CJS-safe.
90
+ export const syncPluginsData = async ({ plugins }, config) => {
91
+ const result = {
92
+ created: [],
93
+ updated: [],
94
+ skipped: [],
95
+ errors: [],
96
+ };
97
+ for (const p of plugins) {
98
+ const name = String(p?.name ?? "unknown");
99
+ if (!p?.name) {
100
+ result.skipped.push(name);
101
+ continue;
99
102
  }
100
- else {
101
- Logger.log("Start creating plugin...");
102
- const { field_type } = await createPlugin(pluginName, config);
103
- Logger.log("Start updating plugin...");
104
- return await updatePlugin({ plugin: field_type, body }, config);
103
+ try {
104
+ const plugin = await getPlugin(name, config);
105
+ if (plugin) {
106
+ await updatePlugin({ plugin: plugin.field_type, body: p.body }, config);
107
+ result.updated.push(name);
108
+ }
109
+ else {
110
+ const created = await createPlugin(name, config);
111
+ await updatePlugin({ plugin: created.field_type, body: p.body }, config);
112
+ result.created.push(name);
113
+ }
114
+ }
115
+ catch (e) {
116
+ result.errors.push({ name, message: String(e) });
105
117
  }
106
118
  }
119
+ return result;
107
120
  };
@@ -0,0 +1,2 @@
1
+ import type { SyncProvidedPlugins } from "./plugins.types.js";
2
+ export declare const syncProvidedPlugins: SyncProvidedPlugins;
@@ -0,0 +1,11 @@
1
+ import { readFile } from "../../utils/files.js";
2
+ import { syncPluginsData } from "./plugins.js";
3
+ export const syncProvidedPlugins = async ({ plugins }, config) => {
4
+ const body = await readFile("dist/export.js");
5
+ if (!body) {
6
+ throw new Error("Unable to read plugin bundle from dist/export.js");
7
+ }
8
+ await syncPluginsData({
9
+ plugins: plugins.map((name) => ({ name: String(name), body })),
10
+ }, config);
11
+ };
@@ -1 +1,2 @@
1
- export { createRole, getRole, getAllRoles, syncRoles, updateRole, } from "./roles.js";
1
+ export { createRole, getRole, getAllRoles, updateRole } from "./roles.js";
2
+ export { syncRoles } from "./roles.sync.js";
@@ -1 +1,2 @@
1
- export { createRole, getRole, getAllRoles, syncRoles, updateRole, } from "./roles.js";
1
+ export { createRole, getRole, getAllRoles, updateRole } from "./roles.js";
2
+ export { syncRoles } from "./roles.sync.js";
@@ -1,6 +1,9 @@
1
- import type { CreateRole, GetAllRoles, GetRole, SyncRoles, UpdateRole } from "./roles.types.js";
1
+ import type { CreateRole, GetAllRoles, GetRole, UpdateRole } from "./roles.types.js";
2
+ import type { SyncResult } from "../sync/sync.types.js";
2
3
  export declare const createRole: CreateRole;
3
4
  export declare const updateRole: UpdateRole;
4
5
  export declare const getAllRoles: GetAllRoles;
5
6
  export declare const getRole: GetRole;
6
- export declare const syncRoles: SyncRoles;
7
+ export declare const syncRolesData: ({ roles }: {
8
+ roles: any[];
9
+ }, config: any) => Promise<SyncResult>;
@@ -1,10 +1,9 @@
1
1
  import Logger from "../../utils/logger.js";
2
- import { getFileContentWithRequire } from "../../utils/main.js";
3
2
  import { getAllItemsWithPagination } from "../utils/request.js";
4
3
  // POST
5
4
  export const createRole = (role, config) => {
6
5
  const { sbApi, spaceId } = config;
7
- sbApi
6
+ return sbApi
8
7
  .post(`spaces/${spaceId}/space_roles/`, {
9
8
  space_role: role,
10
9
  })
@@ -14,12 +13,13 @@ export const createRole = (role, config) => {
14
13
  .catch((err) => {
15
14
  Logger.error("error happened... :(");
16
15
  console.log(`${err.message} in migration of ${role.role} in createRole function`);
16
+ throw err;
17
17
  });
18
18
  };
19
19
  // PUT
20
20
  export const updateRole = (role, config) => {
21
21
  const { sbApi, spaceId } = config;
22
- sbApi
22
+ return sbApi
23
23
  .put(`spaces/${spaceId}/space_roles/${role.id}`, {
24
24
  space_role: role,
25
25
  })
@@ -29,6 +29,7 @@ export const updateRole = (role, config) => {
29
29
  .catch((err) => {
30
30
  Logger.error("error happened... :(");
31
31
  console.log(`${err.message} in migration of ${role.role} in updateRole function`);
32
+ throw err;
32
33
  });
33
34
  };
34
35
  // GET
@@ -74,12 +75,22 @@ export const getRole = async (roleName, config) => {
74
75
  })
75
76
  .catch((err) => Logger.error(err));
76
77
  };
77
- export const syncRoles = async ({ specifiedRoles }, config) => {
78
- const specifiedRolesContent = await Promise.all(specifiedRoles.map((roles) => getFileContentWithRequire({ file: roles.p })));
79
- const space_roles = await getAllRoles(config);
78
+ export const syncRolesData = async ({ roles }, config) => {
79
+ const result = {
80
+ created: [],
81
+ updated: [],
82
+ skipped: [],
83
+ errors: [],
84
+ };
85
+ const space_roles_raw = await getAllRoles(config);
86
+ const space_roles = Array.isArray(space_roles_raw) ? space_roles_raw : [];
80
87
  const rolesToUpdate = [];
81
88
  const rolesToCreate = [];
82
- for (const role of specifiedRolesContent) {
89
+ for (const role of roles) {
90
+ if (!role || typeof role !== "object" || !("role" in role)) {
91
+ result.skipped.push(String(role?.role ?? "unknown"));
92
+ continue;
93
+ }
83
94
  const shouldBeUpdated = space_roles.find((remoteRole) => role.role === remoteRole.role);
84
95
  if (shouldBeUpdated) {
85
96
  rolesToUpdate.push({ id: shouldBeUpdated.id, ...role });
@@ -88,10 +99,22 @@ export const syncRoles = async ({ specifiedRoles }, config) => {
88
99
  rolesToCreate.push(role);
89
100
  }
90
101
  }
91
- rolesToUpdate.map(async (role) => {
92
- await updateRole(role, config);
102
+ const updateResults = await Promise.allSettled(rolesToUpdate.map((role) => updateRole(role, config)));
103
+ updateResults.forEach((r, idx) => {
104
+ const name = String(rolesToUpdate[idx]?.role ?? "unknown");
105
+ if (r.status === "fulfilled")
106
+ result.updated.push(name);
107
+ else
108
+ result.errors.push({ name, message: String(r.reason) });
93
109
  });
94
- rolesToCreate.map(async (role) => {
95
- await createRole(role, config);
110
+ const createResults = await Promise.allSettled(rolesToCreate.map((role) => createRole(role, config)));
111
+ createResults.forEach((r, idx) => {
112
+ const name = String(rolesToCreate[idx]?.role ?? "unknown");
113
+ if (r.status === "fulfilled")
114
+ result.created.push(name);
115
+ else
116
+ result.errors.push({ name, message: String(r.reason) });
96
117
  });
118
+ return result;
97
119
  };
120
+ // File-based sync wrapper lives in `roles.sync.ts` to keep this module CJS-safe.
@@ -0,0 +1,2 @@
1
+ import type { SyncRoles } from "./roles.types.js";
2
+ export declare const syncRoles: SyncRoles;
@@ -0,0 +1,6 @@
1
+ import { getFileContentWithRequire } from "../../utils/files.js";
2
+ import { syncRolesData } from "./roles.js";
3
+ export const syncRoles = async ({ specifiedRoles }, config) => {
4
+ const specifiedRolesContent = await Promise.all(specifiedRoles.map((roles) => getFileContentWithRequire({ file: roles.p })));
5
+ await syncRolesData({ roles: specifiedRolesContent }, config);
6
+ };
@@ -1,4 +1,4 @@
1
- import type { OneFileElement } from "../../cli/utils/discover.js";
1
+ import type { OneFileElement } from "../../utils/path-utils.js";
2
2
  import type { RequestBaseConfig } from "../utils/request.js";
3
3
  export type GetRole = (roleName: string | undefined, config: RequestBaseConfig) => Promise<void>;
4
4
  export type GetAllRoles = (config: RequestBaseConfig) => Promise<any>;
@@ -1,15 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import Logger from "../../utils/logger.js";
3
- import { managementApi } from "../managementApi.js";
3
+ import { notNullish } from "../../utils/object-utils.js";
4
4
  import { getAllItemsWithPagination } from "../utils/request.js";
5
- const notNullish = (params) => {
6
- return Object.keys(params).reduce((acc, key) => {
7
- if (params[key] !== null && params[key] !== undefined) {
8
- acc[key] = params[key];
9
- }
10
- return acc;
11
- }, {});
12
- };
13
5
  export const removeStory = (args, config) => {
14
6
  const { storyId } = args;
15
7
  const { spaceId, sbApi } = config;
@@ -151,7 +143,7 @@ export const upsertStory = async (args, config) => {
151
143
  else if (storySlug) {
152
144
  // if this exist than we update story with this slug (probably when we try to add story from one space to another,
153
145
  console.log("You've selected slug!");
154
- const foundStory = await managementApi.stories.getStoryBySlug(storySlug, config);
146
+ const foundStory = await getStoryBySlug(storySlug, config);
155
147
  console.log("This is story");
156
148
  console.log(foundStory);
157
149
  if (foundStory) {
@@ -160,7 +152,7 @@ export const upsertStory = async (args, config) => {
160
152
  else {
161
153
  const { story: { parent_id, id, parent, ...rest }, } = content;
162
154
  console.log("We are going to create story");
163
- const response = await managementApi.stories.createStory(rest, config);
155
+ const response = await createStory(rest, config);
164
156
  console.log("This is response");
165
157
  console.log(response);
166
158
  }
@@ -0,0 +1,30 @@
1
+ export type SyncError = {
2
+ name: string;
3
+ message: string;
4
+ };
5
+ export interface SyncResult {
6
+ created: string[];
7
+ updated: string[];
8
+ skipped: string[];
9
+ errors: SyncError[];
10
+ }
11
+ /**
12
+ * Progress event emitted during sync operations
13
+ */
14
+ export interface SyncProgressEvent {
15
+ type: "start" | "progress" | "complete";
16
+ /** Current item index (1-based) */
17
+ current?: number;
18
+ /** Total number of items */
19
+ total?: number;
20
+ /** Name of the component/resource being synced */
21
+ name?: string;
22
+ /** Action performed */
23
+ action?: "creating" | "updating" | "created" | "updated" | "skipped" | "error";
24
+ /** Optional message */
25
+ message?: string;
26
+ }
27
+ /**
28
+ * Callback function for reporting sync progress
29
+ */
30
+ export type SyncProgressCallback = (event: SyncProgressEvent) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -25,8 +25,8 @@ export declare const testApi: {
25
25
  createDatasource: import("./datasources/datasources.types.js").CreateDatasource;
26
26
  getDatasource: import("./datasources/datasources.types.js").GetDatasource;
27
27
  getAllDatasources: import("./datasources/datasources.types.js").GetAllDatasources;
28
- syncDatasources: import("./datasources/datasources.types.js").SyncDatasources;
29
28
  updateDatasource: import("./datasources/datasources.types.js").UpdateDatasource;
29
+ syncDatasources: import("./datasources/datasources.types.js").SyncDatasources;
30
30
  };
31
31
  plugins: {
32
32
  getAllPlugins: import("./plugins/plugins.types.js").GetAllPlugins;
@@ -48,8 +48,8 @@ export declare const testApi: {
48
48
  createRole: import("./roles/roles.types.js").CreateRole;
49
49
  getRole: import("./roles/roles.types.js").GetRole;
50
50
  getAllRoles: import("./roles/roles.types.js").GetAllRoles;
51
- syncRoles: import("./roles/roles.types.js").SyncRoles;
52
51
  updateRole: import("./roles/roles.types.js").UpdateRole;
52
+ syncRoles: import("./roles/roles.types.js").SyncRoles;
53
53
  };
54
54
  stories: {
55
55
  createStory: import("./stories/stories.types.js").CreateStory;
@@ -1 +1,5 @@
1
- export declare const _uniqueValuesFrom: (array: any[]) => any[];
1
+ /**
2
+ * Re-exports for backwards compatibility
3
+ * Functions have been moved to their proper modules
4
+ */
5
+ export { _uniqueValuesFrom, uniqueValuesFrom, } from "../../utils/array-utils.js";
@@ -1 +1,6 @@
1
- export const _uniqueValuesFrom = (array) => [...new Set(array)];
1
+ /**
2
+ * Re-exports for backwards compatibility
3
+ * Functions have been moved to their proper modules
4
+ */
5
+ // Array utilities - now in utils/array-utils.ts
6
+ export { _uniqueValuesFrom, uniqueValuesFrom, } from "../../utils/array-utils.js";
@@ -1,4 +1,4 @@
1
- import type { IStoryblokConfig } from "../../config/config.js";
1
+ import type { IStoryblokConfig } from "../../config/config.types.js";
2
2
  import type StoryblokClient from "storyblok-js-client";
3
3
  export interface RequestBaseConfig extends Partial<Omit<IStoryblokConfig, "sbApi">> {
4
4
  spaceId: string;
@@ -7,8 +7,14 @@ export const getAllItemsWithPagination = async ({ apiFn, params, itemsKey, }) =>
7
7
  let amountOfFetchedItems = 0;
8
8
  do {
9
9
  const response = await apiFn({ per_page, page, ...params });
10
+ // Handle case where API call failed and returned undefined
11
+ if (!response || !response.data) {
12
+ Logger.warning(`API returned no data for ${itemsKey}`);
13
+ return allItems;
14
+ }
10
15
  if (!totalPages) {
11
- totalPages = Math.ceil(response.total / response.perPage);
16
+ totalPages =
17
+ Math.ceil((response.total ?? 0) / (response.perPage ?? per_page)) || 1;
12
18
  }
13
19
  /**
14
20
  *
@@ -25,7 +31,10 @@ export const getAllItemsWithPagination = async ({ apiFn, params, itemsKey, }) =>
25
31
  Logger.success(`${amountOfFetchedItems} of ${response.total} items fetched.`);
26
32
  }
27
33
  }
28
- allItems.push(...response.data[itemsKey]);
34
+ const items = response.data?.[itemsKey];
35
+ if (Array.isArray(items)) {
36
+ allItems.push(...items);
37
+ }
29
38
  page++;
30
39
  } while (page <= totalPages);
31
40
  return allItems;
@@ -1,6 +1,7 @@
1
1
  import { discoverResolvers, LOOKUP_TYPE, SCOPE, } from "../../cli/utils/discover.js";
2
2
  import config from "../../config/config.js";
3
- import { getFileContentWithRequire } from "../../utils/main.js";
3
+ import { getFileContentWithRequire } from "../../utils/files.js";
4
+ import { deepTransform, extendField, isContentAvailableAsBloks, isItemsAvailableAsBloks, } from "../../utils/transform-utils.js";
4
5
  export const transformWithResolverFiles = async (componentsContent) => {
5
6
  componentsContent = structuredClone(componentsContent);
6
7
  const resolversFilenames = await discoverResolvers({
@@ -20,12 +21,6 @@ export const transformWithResolverFiles = async (componentsContent) => {
20
21
  }
21
22
  return componentsContent;
22
23
  };
23
- const isContentAvailableAsBloks = (component) => "content" in component.schema &&
24
- component.schema.content.component_whitelist &&
25
- component.schema.content.type === "bloks";
26
- const isItemsAvailableAsBloks = (component) => "items" in component.schema &&
27
- component.schema.items.component_whitelist &&
28
- component.schema.items.type === "bloks";
29
24
  const updateComponentWhitelist = ({ component, update, }) => {
30
25
  if (isContentAvailableAsBloks(component)) {
31
26
  component.schema.content.component_whitelist = [
@@ -73,31 +68,6 @@ export const resolveGlobalTransformations = async (componentsContent) => {
73
68
  componentsContent = await transformWithMainConfigFile(componentsContent);
74
69
  return componentsContent;
75
70
  };
76
- const extendField = (obj, targetField, newValue) => {
77
- if (typeof obj !== "object" || obj === null) {
78
- return false;
79
- }
80
- if (obj.hasOwnProperty(targetField)) {
81
- if (Array.isArray(obj[targetField])) {
82
- for (const element of newValue) {
83
- if (!obj[targetField].includes(element)) {
84
- obj[targetField] = [...obj[targetField], element];
85
- }
86
- }
87
- }
88
- else if (typeof obj[targetField] === "object") {
89
- // this is something i have to fix, comparing to object is stupid
90
- obj[targetField] = { ...obj[targetField], ...newValue };
91
- }
92
- return true;
93
- }
94
- for (const key in obj) {
95
- if (extendField(obj[key], targetField, newValue)) {
96
- return true;
97
- }
98
- }
99
- return false;
100
- };
101
71
  const resolveAll = (resolver, componentsContent) => {
102
72
  if (!resolver.all)
103
73
  return componentsContent;
@@ -109,31 +79,6 @@ export const extendFields = (componentNamesResolver, component) => {
109
79
  console.log(targetField);
110
80
  extendField(component, targetField, componentNamesResolver.methods.extend[targetField]);
111
81
  };
112
- function deepTransform(obj, transformers) {
113
- if (typeof obj !== "object" || obj === null) {
114
- return obj;
115
- }
116
- const result = Array.isArray(obj) ? [...obj] : { ...obj };
117
- for (const key in transformers) {
118
- if (typeof transformers[key] === "function") {
119
- result[key] = transformers[key](obj[key]);
120
- }
121
- else if (typeof transformers[key] === "object" &&
122
- transformers[key] !== null) {
123
- result[key] = deepTransform(obj[key] || {}, transformers[key]);
124
- }
125
- else {
126
- result[key] = transformers[key];
127
- }
128
- }
129
- // Preserve untransformed properties
130
- for (const key in obj) {
131
- if (!(key in transformers)) {
132
- result[key] = obj[key];
133
- }
134
- }
135
- return result;
136
- }
137
82
  export const resolverTransformations = (componentsContent, resolverFilesContent) => {
138
83
  let resolvedComponents = [];
139
84
  resolvedComponents = resolveComponentNames(resolverFilesContent, componentsContent);
@@ -0,0 +1,13 @@
1
+ import type { ApiClient } from "../client.js";
2
+ export declare function getAllAssets(client: ApiClient, args: {
3
+ spaceId: string;
4
+ search?: string;
5
+ }): Promise<any>;
6
+ export declare function getAssetById(client: ApiClient, args: {
7
+ spaceId: string;
8
+ assetId: number;
9
+ }): Promise<any>;
10
+ export declare function getAssetByName(client: ApiClient, args: {
11
+ spaceId: string;
12
+ fileName: string;
13
+ }): Promise<any>;
@@ -0,0 +1,25 @@
1
+ export async function getAllAssets(client, args) {
2
+ const { spaceId, search } = args;
3
+ return client.sbApi
4
+ .get(`spaces/${spaceId}/assets/`, {
5
+ // @ts-ignore storyblok-js-client mismatch: documentation uses `search`
6
+ search: search ?? "",
7
+ per_page: 100,
8
+ })
9
+ .then(({ data }) => data);
10
+ }
11
+ export async function getAssetById(client, args) {
12
+ const { spaceId, assetId } = args;
13
+ return client.sbApi
14
+ .get(`spaces/${spaceId}/assets/${assetId}`)
15
+ .then(({ data }) => data);
16
+ }
17
+ export async function getAssetByName(client, args) {
18
+ const result = await getAllAssets(client, {
19
+ spaceId: args.spaceId,
20
+ search: args.fileName,
21
+ });
22
+ if (result?.assets?.length === 1)
23
+ return result.assets[0];
24
+ return undefined;
25
+ }
@@ -0,0 +1,3 @@
1
+ import type { ApiClient } from "../client.js";
2
+ export declare function getCurrentUser(client: ApiClient): Promise<any>;
3
+ export declare function hasAccessToSpace(client: ApiClient, spaceId: string): Promise<boolean>;
@@ -0,0 +1,8 @@
1
+ import { getCurrentUser as apiGetCurrentUser, hasAccessToSpace as apiHasAccessToSpace, } from "../../api/auth/auth.js";
2
+ import { toRequestConfig } from "../requestConfig.js";
3
+ export async function getCurrentUser(client) {
4
+ return await apiGetCurrentUser(toRequestConfig(client));
5
+ }
6
+ export async function hasAccessToSpace(client, spaceId) {
7
+ return await apiHasAccessToSpace({ spaceId }, toRequestConfig(client));
8
+ }
@@ -0,0 +1,13 @@
1
+ import StoryblokClient from "storyblok-js-client";
2
+ export interface ClientConfig {
3
+ oauthToken: string;
4
+ spaceId: string;
5
+ accessToken?: string;
6
+ rateLimit?: number;
7
+ }
8
+ export interface ApiClient {
9
+ config: ClientConfig;
10
+ sbApi: StoryblokClient;
11
+ spaceId: string;
12
+ }
13
+ export declare function createClient(options: ClientConfig): ApiClient;
@@ -0,0 +1,17 @@
1
+ import StoryblokClient from "storyblok-js-client";
2
+ export function createClient(options) {
3
+ const sbApi = new StoryblokClient({
4
+ oauthToken: options.oauthToken,
5
+ accessToken: options.accessToken,
6
+ rateLimit: options.rateLimit ?? 3,
7
+ cache: {
8
+ clear: "auto",
9
+ type: "none",
10
+ },
11
+ }, "https://mapi.storyblok.com/v1");
12
+ return {
13
+ config: options,
14
+ sbApi,
15
+ spaceId: options.spaceId,
16
+ };
17
+ }
@@ -0,0 +1,10 @@
1
+ import type { ApiClient } from "../client.js";
2
+ export declare function getAllComponents(client: ApiClient): Promise<any[]>;
3
+ export declare function getComponent(client: ApiClient, componentName: string): Promise<any>;
4
+ export declare function getAllComponentsGroups(client: ApiClient): Promise<any[]>;
5
+ export declare function getComponentsGroup(client: ApiClient, groupName: string): Promise<any>;
6
+ export declare function createComponentsGroup(client: ApiClient, groupName: string): Promise<any>;
7
+ export declare function removeComponentGroup(client: ApiClient, componentGroup: any): Promise<any>;
8
+ export declare function removeComponent(client: ApiClient, component: any): Promise<any>;
9
+ export declare function createComponent(client: ApiClient, component: any, presets?: boolean): Promise<any>;
10
+ export declare function updateComponent(client: ApiClient, component: any, presets?: boolean): Promise<any>;
@@ -0,0 +1,29 @@
1
+ import { createComponent as apiCreateComponent, getAllComponents as apiGetAllComponents, getComponent as apiGetComponent, getAllComponentsGroups as apiGetAllComponentsGroups, createComponentsGroup as apiCreateComponentsGroup, getComponentsGroup as apiGetComponentsGroup, removeComponent as apiRemoveComponent, removeComponentGroup as apiRemoveComponentGroup, updateComponent as apiUpdateComponent, } from "../../api/components/components.js";
2
+ import { toRequestConfig } from "../requestConfig.js";
3
+ export async function getAllComponents(client) {
4
+ return await apiGetAllComponents(toRequestConfig(client));
5
+ }
6
+ export async function getComponent(client, componentName) {
7
+ return await apiGetComponent(componentName, toRequestConfig(client));
8
+ }
9
+ export async function getAllComponentsGroups(client) {
10
+ return await apiGetAllComponentsGroups(toRequestConfig(client));
11
+ }
12
+ export async function getComponentsGroup(client, groupName) {
13
+ return await apiGetComponentsGroup(groupName, toRequestConfig(client));
14
+ }
15
+ export async function createComponentsGroup(client, groupName) {
16
+ return await apiCreateComponentsGroup(groupName, toRequestConfig(client));
17
+ }
18
+ export async function removeComponentGroup(client, componentGroup) {
19
+ return await apiRemoveComponentGroup(componentGroup, toRequestConfig(client));
20
+ }
21
+ export async function removeComponent(client, component) {
22
+ return await apiRemoveComponent(component, toRequestConfig(client));
23
+ }
24
+ export async function createComponent(client, component, presets = false) {
25
+ return await apiCreateComponent(component, presets, toRequestConfig(client));
26
+ }
27
+ export async function updateComponent(client, component, presets = false) {
28
+ return await apiUpdateComponent(component, presets, toRequestConfig(client));
29
+ }
@@ -0,0 +1,8 @@
1
+ import type { ApiClient } from "../client.js";
2
+ export declare function getAllDatasources(client: ApiClient): Promise<any>;
3
+ export declare function getDatasource(client: ApiClient, datasourceName: string): Promise<any>;
4
+ export declare function createDatasource(client: ApiClient, datasource: any): Promise<any>;
5
+ export declare function updateDatasource(client: ApiClient, args: {
6
+ datasource: any;
7
+ datasourceToBeUpdated: any;
8
+ }): Promise<any>;