@andrzejchm/notion-cli 0.9.1 → 0.10.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/README.md CHANGED
@@ -107,6 +107,8 @@ notion ls
107
107
  | `notion create-page --parent <id\|url> --title <title>` | Create a new page, prints URL |
108
108
  | `notion update <id\|url> --prop "Name=Value"` | Update properties on a page |
109
109
  | `notion archive <id\|url>` | Archive (trash) a page |
110
+ | `notion move <ids\|urls...> --to <id\|url>` | Move pages to a new parent page |
111
+ | `notion move <ids\|urls...> --to-db <id\|url>` | Move pages to a database parent |
110
112
  | `notion completion bash\|zsh\|fish` | Install shell tab completion |
111
113
 
112
114
  ### `notion search` / `notion ls` flags
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { readFileSync } from "fs";
5
5
  import { dirname, join as join3 } from "path";
6
6
  import { fileURLToPath } from "url";
7
- import { Command as Command24 } from "commander";
7
+ import { Command as Command25 } from "commander";
8
8
 
9
9
  // src/commands/append.ts
10
10
  import { Command } from "commander";
@@ -2479,13 +2479,71 @@ function lsCommand() {
2479
2479
  return cmd;
2480
2480
  }
2481
2481
 
2482
+ // src/commands/move.ts
2483
+ import { Command as Command16 } from "commander";
2484
+ function moveCommand() {
2485
+ const cmd = new Command16("move");
2486
+ cmd.description("move pages to a new parent").argument("<ids/urls...>", "Notion page IDs or URLs to move").option("--to <id/url>", "target page parent ID or URL").option(
2487
+ "--to-db <id/url>",
2488
+ "target database parent ID or URL (resolves to data source)"
2489
+ ).action(
2490
+ withErrorHandling(async (idsOrUrls, opts) => {
2491
+ if (!opts.to && !opts.toDb) {
2492
+ throw new CliError(
2493
+ ErrorCodes.INVALID_ARG,
2494
+ "No target parent specified.",
2495
+ "Provide --to <page-id> or --to-db <database-id>"
2496
+ );
2497
+ }
2498
+ if (opts.to && opts.toDb) {
2499
+ throw new CliError(
2500
+ ErrorCodes.INVALID_ARG,
2501
+ "Cannot specify both --to and --to-db.",
2502
+ "Provide only one: --to <page-id> or --to-db <database-id>"
2503
+ );
2504
+ }
2505
+ const { token, source } = await resolveToken();
2506
+ reportTokenSource(source);
2507
+ const client = createNotionClient(token);
2508
+ let parent;
2509
+ if (opts.toDb) {
2510
+ const dsId = await resolveDataSourceId(client, opts.toDb);
2511
+ parent = { type: "data_source_id", data_source_id: dsId };
2512
+ } else if (opts.to) {
2513
+ const targetId = toUuid(parseNotionId(opts.to));
2514
+ parent = { type: "page_id", page_id: targetId };
2515
+ } else {
2516
+ throw new CliError(
2517
+ ErrorCodes.INVALID_ARG,
2518
+ "No target parent specified."
2519
+ );
2520
+ }
2521
+ const results = [];
2522
+ for (const idOrUrl of idsOrUrls) {
2523
+ const uuid = toUuid(parseNotionId(idOrUrl));
2524
+ const result = await client.pages.move({ page_id: uuid, parent });
2525
+ results.push(result);
2526
+ }
2527
+ const mode = getOutputMode();
2528
+ if (mode === "json") {
2529
+ process.stdout.write(`${formatJSON(results)}
2530
+ `);
2531
+ } else {
2532
+ process.stdout.write(`Moved ${results.length} page(s).
2533
+ `);
2534
+ }
2535
+ })
2536
+ );
2537
+ return cmd;
2538
+ }
2539
+
2482
2540
  // src/commands/open.ts
2483
2541
  import { exec } from "child_process";
2484
2542
  import { promisify } from "util";
2485
- import { Command as Command16 } from "commander";
2543
+ import { Command as Command17 } from "commander";
2486
2544
  var execAsync = promisify(exec);
2487
2545
  function openCommand() {
2488
- const cmd = new Command16("open");
2546
+ const cmd = new Command17("open");
2489
2547
  cmd.description("open a Notion page in the default browser").argument("<id/url>", "Notion page ID or URL").action(
2490
2548
  withErrorHandling(async (idOrUrl) => {
2491
2549
  const id = parseNotionId(idOrUrl);
@@ -2501,9 +2559,9 @@ function openCommand() {
2501
2559
  }
2502
2560
 
2503
2561
  // src/commands/profile/list.ts
2504
- import { Command as Command17 } from "commander";
2562
+ import { Command as Command18 } from "commander";
2505
2563
  function profileListCommand() {
2506
- const cmd = new Command17("list");
2564
+ const cmd = new Command18("list");
2507
2565
  cmd.description("list all authentication profiles").action(
2508
2566
  withErrorHandling(async () => {
2509
2567
  const config = await readGlobalConfig();
@@ -2532,9 +2590,9 @@ function profileListCommand() {
2532
2590
  }
2533
2591
 
2534
2592
  // src/commands/profile/remove.ts
2535
- import { Command as Command18 } from "commander";
2593
+ import { Command as Command19 } from "commander";
2536
2594
  function profileRemoveCommand() {
2537
- const cmd = new Command18("remove");
2595
+ const cmd = new Command19("remove");
2538
2596
  cmd.description("remove an authentication profile").argument("<name>", "profile name to remove").action(
2539
2597
  withErrorHandling(async (name) => {
2540
2598
  const config = await readGlobalConfig();
@@ -2560,9 +2618,9 @@ function profileRemoveCommand() {
2560
2618
  }
2561
2619
 
2562
2620
  // src/commands/profile/use.ts
2563
- import { Command as Command19 } from "commander";
2621
+ import { Command as Command20 } from "commander";
2564
2622
  function profileUseCommand() {
2565
- const cmd = new Command19("use");
2623
+ const cmd = new Command20("use");
2566
2624
  cmd.description("switch the active profile").argument("<name>", "profile name to activate").action(
2567
2625
  withErrorHandling(async (name) => {
2568
2626
  const config = await readGlobalConfig();
@@ -2585,7 +2643,7 @@ function profileUseCommand() {
2585
2643
  }
2586
2644
 
2587
2645
  // src/commands/read.ts
2588
- import { Command as Command20 } from "commander";
2646
+ import { Command as Command21 } from "commander";
2589
2647
 
2590
2648
  // src/output/markdown.ts
2591
2649
  import { Chalk as Chalk2 } from "chalk";
@@ -2725,7 +2783,7 @@ async function fetchPageMarkdown(client, pageId) {
2725
2783
 
2726
2784
  // src/commands/read.ts
2727
2785
  function readCommand() {
2728
- return new Command20("read").description("Read a Notion page as markdown").argument("<id>", "Notion page ID or URL").action(
2786
+ return new Command21("read").description("Read a Notion page as markdown").argument("<id>", "Notion page ID or URL").action(
2729
2787
  withErrorHandling(async (id) => {
2730
2788
  const { token } = await resolveToken();
2731
2789
  const client = createNotionClient(token);
@@ -2751,7 +2809,7 @@ function readCommand() {
2751
2809
 
2752
2810
  // src/commands/search.ts
2753
2811
  import { isFullPageOrDataSource as isFullPageOrDataSource2 } from "@notionhq/client";
2754
- import { Command as Command21 } from "commander";
2812
+ import { Command as Command22 } from "commander";
2755
2813
  function getTitle2(item) {
2756
2814
  if (item.object === "data_source") {
2757
2815
  return item.title.map((t) => t.plain_text).join("") || "(untitled)";
@@ -2771,7 +2829,7 @@ function displayType2(item) {
2771
2829
  return item.object === "data_source" ? "database" : item.object;
2772
2830
  }
2773
2831
  function searchCommand() {
2774
- const cmd = new Command21("search");
2832
+ const cmd = new Command22("search");
2775
2833
  cmd.description("search Notion workspace by keyword").argument("<query>", "search keyword").option(
2776
2834
  "--type <type>",
2777
2835
  "filter by object type (page or database)",
@@ -2842,13 +2900,13 @@ function searchCommand() {
2842
2900
  }
2843
2901
 
2844
2902
  // src/commands/update.ts
2845
- import { Command as Command22 } from "commander";
2903
+ import { Command as Command23 } from "commander";
2846
2904
  function collectProps3(val, acc) {
2847
2905
  acc.push(val);
2848
2906
  return acc;
2849
2907
  }
2850
2908
  function updateCommand() {
2851
- const cmd = new Command22("update");
2909
+ const cmd = new Command23("update");
2852
2910
  cmd.description("update properties on a Notion page").argument("<id/url>", "Notion page ID or URL").option(
2853
2911
  "--prop <property=value>",
2854
2912
  "set a property value (repeatable)",
@@ -2906,7 +2964,7 @@ function updateCommand() {
2906
2964
  }
2907
2965
 
2908
2966
  // src/commands/users.ts
2909
- import { Command as Command23 } from "commander";
2967
+ import { Command as Command24 } from "commander";
2910
2968
  function getEmailOrWorkspace(user) {
2911
2969
  if (user.type === "person") {
2912
2970
  return user.person.email ?? "\u2014";
@@ -2918,7 +2976,7 @@ function getEmailOrWorkspace(user) {
2918
2976
  return "\u2014";
2919
2977
  }
2920
2978
  function usersCommand() {
2921
- const cmd = new Command23("users");
2979
+ const cmd = new Command24("users");
2922
2980
  cmd.description("list all users in the workspace").option("--json", "output as JSON").action(
2923
2981
  withErrorHandling(async (opts) => {
2924
2982
  if (opts.json) setOutputMode("json");
@@ -2949,7 +3007,7 @@ var __dirname = dirname(__filename);
2949
3007
  var pkg = JSON.parse(
2950
3008
  readFileSync(join3(__dirname, "../package.json"), "utf-8")
2951
3009
  );
2952
- var program = new Command24();
3010
+ var program = new Command25();
2953
3011
  program.name("notion").description("Notion CLI \u2014 read Notion pages and databases from the terminal").version(pkg.version);
2954
3012
  program.option("--verbose", "show API requests/responses").option("--color", "force color output").option("--json", "force JSON output (overrides TTY detection)").option("--md", "force markdown output for page content");
2955
3013
  program.configureOutput({
@@ -2970,7 +3028,7 @@ program.hook("preAction", (thisCommand) => {
2970
3028
  setOutputMode("md");
2971
3029
  }
2972
3030
  });
2973
- var authCmd = new Command24("auth").description("manage Notion authentication");
3031
+ var authCmd = new Command25("auth").description("manage Notion authentication");
2974
3032
  authCmd.action(authDefaultAction(authCmd));
2975
3033
  authCmd.addCommand(loginCommand());
2976
3034
  authCmd.addCommand(logoutCommand());
@@ -2980,7 +3038,7 @@ authCmd.addCommand(profileUseCommand());
2980
3038
  authCmd.addCommand(profileRemoveCommand());
2981
3039
  program.addCommand(authCmd);
2982
3040
  program.addCommand(initCommand(), { hidden: true });
2983
- var profileCmd = new Command24("profile").description(
3041
+ var profileCmd = new Command25("profile").description(
2984
3042
  "manage authentication profiles"
2985
3043
  );
2986
3044
  profileCmd.addCommand(profileListCommand());
@@ -2999,7 +3057,8 @@ program.addCommand(createPageCommand());
2999
3057
  program.addCommand(editPageCommand());
3000
3058
  program.addCommand(updateCommand());
3001
3059
  program.addCommand(archiveCommand());
3002
- var dbCmd = new Command24("db").description("Database operations");
3060
+ program.addCommand(moveCommand());
3061
+ var dbCmd = new Command25("db").description("Database operations");
3003
3062
  dbCmd.addCommand(dbCreateCommand());
3004
3063
  dbCmd.addCommand(dbSchemaCommand());
3005
3064
  dbCmd.addCommand(dbQueryCommand());