@jordancoin/notioncli 1.2.0 → 1.2.1

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 (2) hide show
  1. package/bin/notion.js +63 -17
  2. package/package.json +1 -1
package/bin/notion.js CHANGED
@@ -1308,18 +1308,48 @@ program
1308
1308
  properties['Name'] = { title: {} };
1309
1309
  }
1310
1310
 
1311
+ // 2025 API: databases.create() only handles title property reliably.
1312
+ // Non-title properties must be added via dataSources.update() after creation.
1313
+ const titleProps = {};
1314
+ const extraProps = {};
1315
+ for (const [name, prop] of Object.entries(properties)) {
1316
+ if (prop.title) {
1317
+ titleProps[name] = prop;
1318
+ } else {
1319
+ extraProps[name] = prop;
1320
+ }
1321
+ }
1322
+ // Ensure title property exists in create call
1323
+ if (Object.keys(titleProps).length === 0) {
1324
+ titleProps['Name'] = { title: {} };
1325
+ }
1326
+
1311
1327
  const res = await notion.databases.create({
1312
1328
  parent: { type: 'page_id', page_id: parentPageId },
1313
1329
  title: [{ text: { content: title } }],
1314
- properties,
1330
+ properties: titleProps,
1315
1331
  });
1316
1332
 
1333
+ // Extract correct dual IDs from response
1334
+ const databaseId = res.id;
1335
+ const dataSourceId = (res.data_sources && res.data_sources[0])
1336
+ ? res.data_sources[0].id
1337
+ : res.id;
1338
+
1339
+ // Add non-title properties via dataSources.update()
1340
+ if (Object.keys(extraProps).length > 0) {
1341
+ await notion.dataSources.update({
1342
+ data_source_id: dataSourceId,
1343
+ properties: extraProps,
1344
+ });
1345
+ }
1346
+
1317
1347
  if (getGlobalJson(cmd)) {
1318
1348
  console.log(JSON.stringify(res, null, 2));
1319
1349
  return;
1320
1350
  }
1321
1351
 
1322
- console.log(`✅ Created database: ${res.id.slice(0, 8)}…`);
1352
+ console.log(`✅ Created database: ${databaseId.slice(0, 8)}…`);
1323
1353
  console.log(` Title: ${title}`);
1324
1354
  console.log(` Properties: ${Object.keys(properties).join(', ')}`);
1325
1355
 
@@ -1330,8 +1360,8 @@ program
1330
1360
  if (!config.workspaces[wsName]) config.workspaces[wsName] = { aliases: {} };
1331
1361
  if (!config.workspaces[wsName].aliases) config.workspaces[wsName].aliases = {};
1332
1362
  config.workspaces[wsName].aliases[opts.alias] = {
1333
- database_id: res.database_id || res.id,
1334
- data_source_id: res.id,
1363
+ database_id: databaseId,
1364
+ data_source_id: dataSourceId,
1335
1365
  };
1336
1366
  saveConfig(config);
1337
1367
  console.log(` Alias: ${opts.alias}`);
@@ -1354,10 +1384,14 @@ program
1354
1384
  const notion = getNotion();
1355
1385
  const dbIds = resolveDb(db);
1356
1386
 
1357
- // databases.update() requires the canonical database_id, which may differ
1358
- // from data_source_id. Resolve via dataSources.retrieve().parent.database_id.
1387
+ // 2025 API: property changes go through dataSources.update(), NOT databases.update().
1388
+ // databases.update() silently ignores property modifications.
1389
+ // Title changes still go through databases.update().
1359
1390
  let canonicalId = dbIds.database_id;
1360
- if (canonicalId === dbIds.data_source_id) {
1391
+ const dataSourceId = dbIds.data_source_id;
1392
+
1393
+ // Resolve canonical database_id if both IDs are the same
1394
+ if (canonicalId === dataSourceId) {
1361
1395
  try {
1362
1396
  const ds = await notion.dataSources.retrieve({ data_source_id: canonicalId });
1363
1397
  if (ds.parent && ds.parent.type === 'database_id') {
@@ -1366,14 +1400,10 @@ program
1366
1400
  } catch (_) { /* fall through with what we have */ }
1367
1401
  }
1368
1402
 
1369
- const params = { database_id: canonicalId };
1370
-
1371
- if (opts.title) {
1372
- params.title = [{ text: { content: opts.title } }];
1373
- }
1374
-
1403
+ // Build property changes for dataSources.update()
1404
+ let propChanges = null;
1375
1405
  if (opts.addProp.length > 0 || opts.removeProp.length > 0) {
1376
- params.properties = {};
1406
+ propChanges = {};
1377
1407
 
1378
1408
  for (const kv of opts.addProp) {
1379
1409
  const colonIdx = kv.indexOf(':');
@@ -1383,15 +1413,31 @@ program
1383
1413
  }
1384
1414
  const name = kv.slice(0, colonIdx);
1385
1415
  const type = kv.slice(colonIdx + 1).toLowerCase();
1386
- params.properties[name] = { [type]: {} };
1416
+ propChanges[name] = { [type]: {} };
1387
1417
  }
1388
1418
 
1389
1419
  for (const name of opts.removeProp) {
1390
- params.properties[name] = null;
1420
+ propChanges[name] = null;
1391
1421
  }
1392
1422
  }
1393
1423
 
1394
- const res = await notion.databases.update(params);
1424
+ let res;
1425
+
1426
+ // Title changes go through databases.update()
1427
+ if (opts.title) {
1428
+ res = await notion.databases.update({
1429
+ database_id: canonicalId,
1430
+ title: [{ text: { content: opts.title } }],
1431
+ });
1432
+ }
1433
+
1434
+ // Property changes go through dataSources.update()
1435
+ if (propChanges) {
1436
+ res = await notion.dataSources.update({
1437
+ data_source_id: dataSourceId,
1438
+ properties: propChanges,
1439
+ });
1440
+ }
1395
1441
 
1396
1442
  if (getGlobalJson(cmd)) {
1397
1443
  console.log(JSON.stringify(res, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jordancoin/notioncli",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A powerful CLI for the Notion API — query databases, manage pages, and automate your workspace from the terminal.",
5
5
  "main": "bin/notion.js",
6
6
  "bin": {