storyblok 4.6.12 → 4.6.14

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/dist/index.mjs CHANGED
@@ -4376,19 +4376,36 @@ typesCommand.command("generate").description("Generate types d.ts for your compo
4376
4376
  const program$4 = getProgram();
4377
4377
  const datasourcesCommand = program$4.command(commands.DATASOURCES).alias("ds").description(`Manage your space's datasources`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/datasources");
4378
4378
 
4379
+ async function fetchAllPages(fetchFunction, extractDataFunction, page = 1, collectedItems = []) {
4380
+ const { data, response } = await fetchFunction(page);
4381
+ const totalHeader = response.headers.get("total");
4382
+ const total = Number(totalHeader);
4383
+ const fetchedItems = extractDataFunction(data);
4384
+ const allItems = [...collectedItems, ...fetchedItems];
4385
+ if (!totalHeader || Number.isNaN(total)) {
4386
+ return allItems;
4387
+ }
4388
+ if (allItems.length < total && fetchedItems.length > 0) {
4389
+ return fetchAllPages(fetchFunction, extractDataFunction, page + 1, allItems);
4390
+ }
4391
+ return allItems;
4392
+ }
4379
4393
  const fetchDatasourceEntries = async (spaceId, datasourceId) => {
4380
4394
  try {
4381
4395
  const client = mapiClient();
4382
- const { data } = await client.datasourceEntries.list({
4383
- path: {
4384
- space_id: spaceId
4385
- },
4386
- query: {
4387
- datasource_id: datasourceId
4388
- },
4389
- throwOnError: true
4390
- });
4391
- return data?.datasource_entries;
4396
+ return await fetchAllPages(
4397
+ (page) => client.datasourceEntries.list({
4398
+ path: {
4399
+ space_id: spaceId
4400
+ },
4401
+ query: {
4402
+ datasource_id: datasourceId,
4403
+ page
4404
+ },
4405
+ throwOnError: true
4406
+ }),
4407
+ (data) => data?.datasource_entries || []
4408
+ );
4392
4409
  } catch (error) {
4393
4410
  handleAPIError("pull_datasources", error);
4394
4411
  }
@@ -4396,21 +4413,26 @@ const fetchDatasourceEntries = async (spaceId, datasourceId) => {
4396
4413
  const fetchDatasources = async (spaceId) => {
4397
4414
  try {
4398
4415
  const client = mapiClient();
4399
- const { data } = await client.datasources.list({
4400
- path: {
4401
- space_id: spaceId
4402
- },
4403
- throwOnError: true
4404
- });
4405
- const datasources = data?.datasources;
4416
+ const datasources = await fetchAllPages(
4417
+ (page) => client.datasources.list({
4418
+ path: {
4419
+ space_id: spaceId
4420
+ },
4421
+ query: {
4422
+ page
4423
+ },
4424
+ throwOnError: true
4425
+ }),
4426
+ (data) => data?.datasources || []
4427
+ );
4406
4428
  const datasourcesWithEntries = await Promise.all(
4407
- datasources?.map(async (ds) => {
4429
+ datasources.map(async (ds) => {
4408
4430
  if (!ds.id) {
4409
4431
  return { ...ds, entries: [] };
4410
4432
  }
4411
4433
  const entries = await fetchDatasourceEntries(spaceId, ds.id);
4412
4434
  return { ...ds, entries };
4413
- }) || []
4435
+ })
4414
4436
  );
4415
4437
  return datasourcesWithEntries;
4416
4438
  } catch (error) {
@@ -5195,7 +5217,7 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
5195
5217
  konsola.br();
5196
5218
  });
5197
5219
 
5198
- const version = "4.6.12";
5220
+ const version = "4.6.14";
5199
5221
  const pkg = {
5200
5222
  version: version};
5201
5223