kintone-migrator 0.24.8 → 0.25.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/dist/index.mjs CHANGED
@@ -5548,6 +5548,42 @@ function createCliCaptureContainers(input) {
5548
5548
  };
5549
5549
  }
5550
5550
  //#endregion
5551
+ //#region src/core/adapters/kintone/appLister.ts
5552
+ const PAGE_LIMIT = 100;
5553
+ const MAX_PAGES = 1e3;
5554
+ var KintoneAppLister = class {
5555
+ constructor(client) {
5556
+ this.client = client;
5557
+ }
5558
+ async getAllApps() {
5559
+ const result = [];
5560
+ try {
5561
+ let offset = 0;
5562
+ let completed = false;
5563
+ for (let page = 0; page < MAX_PAGES; page++) {
5564
+ const { apps } = await this.client.app.getApps({
5565
+ limit: PAGE_LIMIT,
5566
+ offset
5567
+ });
5568
+ for (const app of apps) result.push({
5569
+ appId: app.appId,
5570
+ code: app.code,
5571
+ name: app.name
5572
+ });
5573
+ if (apps.length < PAGE_LIMIT) {
5574
+ completed = true;
5575
+ break;
5576
+ }
5577
+ offset += PAGE_LIMIT;
5578
+ }
5579
+ if (!completed) throw new SystemError(SystemErrorCode.ExternalApiError, `Pagination did not complete within ${MAX_PAGES} pages (fetched ${result.length} apps). This may indicate an API issue.`);
5580
+ return result;
5581
+ } catch (error) {
5582
+ throw wrapKintoneError(error, `Failed to get apps (fetched ${result.length} so far)`);
5583
+ }
5584
+ }
5585
+ };
5586
+ //#endregion
5551
5587
  //#region src/core/adapters/kintone/spaceReader.ts
5552
5588
  /**
5553
5589
  * Reads space information from the kintone REST API.
@@ -5597,8 +5633,10 @@ function createLocalFileProjectConfigStorage(filePath) {
5597
5633
  //#endregion
5598
5634
  //#region src/core/application/container/initCli.ts
5599
5635
  function createInitCliContainer(config) {
5636
+ const client = config.client ?? createKintoneClient(config);
5600
5637
  return {
5601
- spaceReader: new KintoneSpaceReader(config.client ?? createKintoneClient(config)),
5638
+ spaceReader: new KintoneSpaceReader(client),
5639
+ appLister: new KintoneAppLister(client),
5602
5640
  projectConfigStorage: createLocalFileProjectConfigStorage(config.configFilePath)
5603
5641
  };
5604
5642
  }
@@ -6171,7 +6209,7 @@ function buildCaptureTasks(args) {
6171
6209
  container: c.customization,
6172
6210
  input: {
6173
6211
  basePath: input.customizeBasePath,
6174
- filePrefix: input.appName
6212
+ filePrefix: ""
6175
6213
  }
6176
6214
  });
6177
6215
  await saveCustomization({
@@ -6300,6 +6338,13 @@ async function captureAllForApp(args) {
6300
6338
  return results;
6301
6339
  }
6302
6340
  //#endregion
6341
+ //#region src/core/application/init/fetchAllApps.ts
6342
+ async function fetchAllApps(args) {
6343
+ const apps = await args.container.appLister.getAllApps();
6344
+ if (apps.length === 0) throw new NotFoundError(NotFoundErrorCode.NotFound, "No apps found. Please check your API token permissions.");
6345
+ return apps;
6346
+ }
6347
+ //#endregion
6303
6348
  //#region src/core/application/init/fetchSpaceApps.ts
6304
6349
  async function fetchSpaceApps(args) {
6305
6350
  const apps = await args.container.spaceReader.getSpaceApps(args.input.spaceId);
@@ -6347,8 +6392,7 @@ const initArgs = {
6347
6392
  "space-id": {
6348
6393
  type: "string",
6349
6394
  short: "s",
6350
- description: "kintone space ID",
6351
- required: true
6395
+ description: "kintone space ID"
6352
6396
  },
6353
6397
  domain: kintoneArgs.domain,
6354
6398
  username: kintoneArgs.username,
@@ -6378,15 +6422,52 @@ function printCaptureResults(results) {
6378
6422
  logError(result.error);
6379
6423
  }
6380
6424
  }
6425
+ function printDryRunPreview(apps, configPath, configText, output) {
6426
+ p.log.info(pc.dim("(dry-run mode - no files will be written)"));
6427
+ p.log.step(`\nConfig file: ${pc.cyan(configPath)}`);
6428
+ p.log.message(configText);
6429
+ for (const app of apps) {
6430
+ const appName = resolveAppName(app);
6431
+ const paths = buildAppFilePaths(appName, output);
6432
+ p.log.step(`\n=== [${pc.bold(appName)}] (appId: ${app.appId}) ===`);
6433
+ p.log.message(" Files that would be created:");
6434
+ for (const [domain, filePath] of Object.entries(paths)) p.log.message(` ${domain}: ${pc.dim(filePath)}`);
6435
+ }
6436
+ p.log.success("\nDry run complete. No files were written.");
6437
+ }
6438
+ async function captureApps(apps, config) {
6439
+ for (const app of apps) {
6440
+ const appName = resolveAppName(app);
6441
+ p.log.step(`\n=== [${pc.bold(appName)}] (appId: ${app.appId}) ===`);
6442
+ const { containers, paths } = createCliCaptureContainers({
6443
+ baseUrl: config.baseUrl,
6444
+ auth: config.auth,
6445
+ appId: app.appId,
6446
+ guestSpaceId: config.guestSpaceId,
6447
+ appName,
6448
+ baseDir: config.output
6449
+ });
6450
+ const cs = p.spinner();
6451
+ cs.start(`Capturing all domains for ${appName}...`);
6452
+ const results = await captureAllForApp({
6453
+ container: containers,
6454
+ input: { customizeBasePath: dirname(resolve(paths.customize)) }
6455
+ });
6456
+ const successCount = results.filter((r) => r.success).length;
6457
+ const failCount = results.length - successCount;
6458
+ cs.stop(`Captured ${successCount}/${results.length} domains.` + (failCount > 0 ? pc.red(` (${failCount} failed)`) : ""));
6459
+ printCaptureResults(results);
6460
+ }
6461
+ }
6381
6462
  var init_default = define({
6382
6463
  name: "init",
6383
- description: "Initialize project from a kintone space",
6464
+ description: "Initialize project from kintone",
6384
6465
  args: initArgs,
6385
6466
  run: async (ctx) => {
6386
6467
  try {
6387
6468
  const values = ctx.values;
6388
6469
  const spaceId = values["space-id"];
6389
- if (!/^[1-9]\d*$/.test(spaceId)) throw new ValidationError(ValidationErrorCode.InvalidInput, `Invalid space ID: "${spaceId}" (must be a positive integer, e.g. 1, 42, 100)`);
6470
+ if (spaceId && !/^[1-9]\d*$/.test(spaceId)) throw new ValidationError(ValidationErrorCode.InvalidInput, `Invalid space ID: "${spaceId}" (must be a positive integer, e.g. 1, 42, 100)`);
6390
6471
  const kintoneDomain = values.domain ?? process.env.KINTONE_DOMAIN;
6391
6472
  if (!kintoneDomain) throw new ValidationError(ValidationErrorCode.InvalidInput, "Missing required configuration:\n KINTONE_DOMAIN is required");
6392
6473
  const apiToken = values["api-token"] ?? process.env.KINTONE_API_TOKEN;
@@ -6399,19 +6480,26 @@ var init_default = define({
6399
6480
  const configPath = DEFAULT_CONFIG_PATH;
6400
6481
  const skipConfirm = values.yes ?? false;
6401
6482
  const dryRun = values["dry-run"] ?? false;
6402
- const { spaceReader, projectConfigStorage } = createInitCliContainer({
6483
+ const { spaceReader, appLister, projectConfigStorage } = createInitCliContainer({
6403
6484
  baseUrl,
6404
6485
  auth,
6405
6486
  guestSpaceId,
6406
6487
  configFilePath: configPath
6407
6488
  });
6408
6489
  const s = p.spinner();
6409
- s.start("Fetching space info...");
6410
- const apps = await fetchSpaceApps({
6411
- container: { spaceReader },
6412
- input: { spaceId }
6413
- });
6414
- s.stop(`Found ${apps.length} app(s) in the space.`);
6490
+ let apps;
6491
+ if (spaceId) {
6492
+ s.start("Fetching space info...");
6493
+ apps = await fetchSpaceApps({
6494
+ container: { spaceReader },
6495
+ input: { spaceId }
6496
+ });
6497
+ s.stop(`Found ${apps.length} app(s) in the space.`);
6498
+ } else {
6499
+ s.start("Fetching all apps...");
6500
+ apps = await fetchAllApps({ container: { appLister } });
6501
+ s.stop(`Found ${apps.length} app(s).`);
6502
+ }
6415
6503
  p.log.info("Apps:");
6416
6504
  for (const app of apps) {
6417
6505
  const name = resolveAppName(app);
@@ -6424,17 +6512,7 @@ var init_default = define({
6424
6512
  baseDir: output
6425
6513
  }, configCodec);
6426
6514
  if (dryRun) {
6427
- p.log.info(pc.dim("(dry-run mode - no files will be written)"));
6428
- p.log.step(`\nConfig file: ${pc.cyan(configPath)}`);
6429
- p.log.message(configText);
6430
- for (const app of apps) {
6431
- const appName = resolveAppName(app);
6432
- const paths = buildAppFilePaths(appName, output);
6433
- p.log.step(`\n=== [${pc.bold(appName)}] (appId: ${app.appId}) ===`);
6434
- p.log.message(" Files that would be created:");
6435
- for (const [domain, filePath] of Object.entries(paths)) p.log.message(` ${domain}: ${pc.dim(filePath)}`);
6436
- }
6437
- p.log.success("\nDry run complete. No files were written.");
6515
+ printDryRunPreview(apps, configPath, configText, output);
6438
6516
  return;
6439
6517
  }
6440
6518
  if ((await projectConfigStorage.get()).exists && !skipConfirm) {
@@ -6446,31 +6524,12 @@ var init_default = define({
6446
6524
  }
6447
6525
  await projectConfigStorage.update(configText);
6448
6526
  p.log.success(`Config written to: ${pc.cyan(configPath)}`);
6449
- for (const app of apps) {
6450
- const appName = resolveAppName(app);
6451
- p.log.step(`\n=== [${pc.bold(appName)}] (appId: ${app.appId}) ===`);
6452
- const { containers, paths } = createCliCaptureContainers({
6453
- baseUrl,
6454
- auth,
6455
- appId: app.appId,
6456
- guestSpaceId,
6457
- appName,
6458
- baseDir: output
6459
- });
6460
- const cs = p.spinner();
6461
- cs.start(`Capturing all domains for ${appName}...`);
6462
- const results = await captureAllForApp({
6463
- container: containers,
6464
- input: {
6465
- appName,
6466
- customizeBasePath: dirname(resolve(paths.customize))
6467
- }
6468
- });
6469
- const successCount = results.filter((r) => r.success).length;
6470
- const failCount = results.length - successCount;
6471
- cs.stop(`Captured ${successCount}/${results.length} domains.` + (failCount > 0 ? pc.red(` (${failCount} failed)`) : ""));
6472
- printCaptureResults(results);
6473
- }
6527
+ await captureApps(apps, {
6528
+ baseUrl,
6529
+ auth,
6530
+ guestSpaceId,
6531
+ output
6532
+ });
6474
6533
  p.log.info(`Add authentication settings (auth) to ${pc.cyan(configPath)} or set KINTONE_API_TOKEN / KINTONE_USERNAME + KINTONE_PASSWORD environment variables.`);
6475
6534
  p.log.success("\nProject initialization complete.");
6476
6535
  } catch (error) {