@tenonhq/sincronia-core 0.0.79 → 0.0.80

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.
@@ -55,7 +55,6 @@ class MultiScopeWatcherManager {
55
55
  updateSetCheckInterval = null;
56
56
  scopeLock = Promise.resolve();
57
57
  cachedScope = null;
58
- cachedUserSysId = null;
59
58
  pendingScopes = new Map(); // scope -> first change timestamp
60
59
  globalProcessQueue = null;
61
60
  async startWatchingAllScopes(options) {
@@ -206,7 +205,41 @@ class MultiScopeWatcherManager {
206
205
  }
207
206
  var activeTask = this.readActiveTask();
208
207
  if (!activeTask) {
209
- Logger_1.logger.warn(`[${scopeName}] No update set configured for scope ${scopeName}. Changes will go to Default. Use sinc createUpdateSet or activate a task in the dashboard.`);
208
+ // No active task try to resolve the current update set from the ServiceNow
209
+ // session so pushWithUpdateSet can be used instead of the fallback updateRecord.
210
+ try {
211
+ var { defaultClient } = await Promise.resolve().then(() => __importStar(require("./snClient")));
212
+ var sessionClient = defaultClient();
213
+ var curResp = await sessionClient.getCurrentUpdateSet(scopeName);
214
+ var curData = curResp.data;
215
+ if (curData && curData.result) {
216
+ curData = curData.result;
217
+ }
218
+ var curSysId = curData && curData.sysId ? curData.sysId : null;
219
+ var curName = curData && curData.name ? curData.name : null;
220
+ if (curSysId && curName) {
221
+ var isDefault = curName === "Default" || curName.toLowerCase().indexOf("default") !== -1;
222
+ if (isDefault) {
223
+ Logger_1.logger.warn(`[${scopeName}] No update set configured and current update set is Default. ` +
224
+ `Use sinc createUpdateSet or activate a task in the dashboard.`);
225
+ }
226
+ else {
227
+ // Use the session's current non-Default update set
228
+ config = this.getUpdateSetConfig();
229
+ config[scopeName] = { sys_id: curSysId, name: curName };
230
+ this.saveUpdateSetConfig(config);
231
+ Logger_1.logger.info(`[${scopeName}] Using session update set: ${curName}`);
232
+ }
233
+ }
234
+ else {
235
+ Logger_1.logger.warn(`[${scopeName}] No update set configured for scope ${scopeName}. ` +
236
+ `Use sinc createUpdateSet or activate a task in the dashboard.`);
237
+ }
238
+ }
239
+ catch (queryErr) {
240
+ Logger_1.logger.warn(`[${scopeName}] No update set configured and could not query current update set. ` +
241
+ `Changes will use direct Table API. Use sinc createUpdateSet or activate a task in the dashboard.`);
242
+ }
210
243
  return;
211
244
  }
212
245
  var taskId = activeTask.taskId;
@@ -450,31 +483,14 @@ class MultiScopeWatcherManager {
450
483
  return;
451
484
  }
452
485
  try {
453
- const { defaultClient, unwrapSNResponse } = await Promise.resolve().then(() => __importStar(require("./snClient")));
454
- const client = defaultClient();
455
- // Get the scope ID
456
- const scopeResponse = await unwrapSNResponse(client.getScopeId(scopeName));
457
- if (!scopeResponse || !Array.isArray(scopeResponse) || scopeResponse.length === 0 || !scopeResponse[0].sys_id) {
458
- throw new Error(`Scope ${scopeName} not found`);
459
- }
460
- // Get user sys_id (cached for the session — never changes)
461
- if (!this.cachedUserSysId) {
462
- const userResponse = await unwrapSNResponse(client.getUserSysId());
463
- if (!userResponse || !Array.isArray(userResponse) || userResponse.length === 0 || !userResponse[0].sys_id) {
464
- throw new Error("Could not get user sys_id");
465
- }
466
- this.cachedUserSysId = userResponse[0].sys_id;
467
- }
468
- // Get current app preference
469
- const prefResponse = await unwrapSNResponse(client.getCurrentAppUserPrefSysId(this.cachedUserSysId));
470
- if (prefResponse && Array.isArray(prefResponse) && prefResponse.length > 0 && prefResponse[0].sys_id) {
471
- // Update existing preference
472
- await client.updateCurrentAppUserPref(scopeResponse[0].sys_id, prefResponse[0].sys_id);
473
- }
474
- else {
475
- // Create new preference
476
- await client.createCurrentAppUserPref(scopeResponse[0].sys_id, this.cachedUserSysId);
477
- }
486
+ var { defaultClient } = await Promise.resolve().then(() => __importStar(require("./snClient")));
487
+ var client = defaultClient();
488
+ // Use the Claude REST API changeScope endpoint to switch the session scope.
489
+ // This uses gs.setCurrentApplicationId() server-side, which correctly changes
490
+ // the REST API session scope. The previous approach used user preference updates
491
+ // (apps.current_app) which only writes a DB record and does NOT affect the
492
+ // active REST session — causing updateRecord() to operate in the wrong scope.
493
+ await client.changeScope(scopeName);
478
494
  this.cachedScope = scopeName;
479
495
  Logger_1.logger.debug(`Switched to scope: ${scopeName}`);
480
496
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",