@tenonhq/sincronia-core 0.0.25 → 0.0.26
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/snClient.js +11 -3
- package/dist/updateSetCommands.js +30 -16
- package/package.json +2 -1
package/dist/snClient.js
CHANGED
|
@@ -131,11 +131,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
131
131
|
const endpoint = "api/x_nuvo_sinc/sinc/getCurrentScope";
|
|
132
132
|
return client.get(endpoint);
|
|
133
133
|
};
|
|
134
|
-
const createUpdateSet = (updateSetName) => {
|
|
134
|
+
const createUpdateSet = (updateSetName, scopeSysId, description) => {
|
|
135
135
|
const endpoint = `api/now/table/sys_update_set`;
|
|
136
|
-
|
|
136
|
+
const data = {
|
|
137
137
|
name: updateSetName,
|
|
138
|
-
|
|
138
|
+
state: "in progress"
|
|
139
|
+
};
|
|
140
|
+
if (scopeSysId) {
|
|
141
|
+
data.application = scopeSysId;
|
|
142
|
+
}
|
|
143
|
+
if (description) {
|
|
144
|
+
data.description = description;
|
|
145
|
+
}
|
|
146
|
+
return client.post(endpoint, data);
|
|
139
147
|
};
|
|
140
148
|
const getCurrentUpdateSetUserPref = (userSysId) => {
|
|
141
149
|
const endpoint = `api/now/table/sys_user_preference`;
|
|
@@ -29,15 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
const client = (0, snClient_1.defaultClient)();
|
|
30
30
|
// Get update set details from user
|
|
31
31
|
const { name, description, scope } = await promptForUpdateSetDetails(args);
|
|
32
|
-
|
|
33
|
-
Logger_1.logger.info(`Creating update set: ${name}`);
|
|
34
|
-
const updateSetData = {
|
|
35
|
-
name,
|
|
36
|
-
state: "in progress"
|
|
37
|
-
};
|
|
38
|
-
if (description) {
|
|
39
|
-
updateSetData.description = description;
|
|
40
|
-
}
|
|
32
|
+
let scopeSysId;
|
|
41
33
|
if (scope) {
|
|
42
34
|
// Get scope sys_id if scope name provided
|
|
43
35
|
const scopeResult = await (0, snClient_1.unwrapSNResponse)(client.getScopeId(scope));
|
|
@@ -45,20 +37,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
37
|
Logger_1.logger.error(`Scope "${scope}" not found`);
|
|
46
38
|
process.exit(1);
|
|
47
39
|
}
|
|
48
|
-
|
|
40
|
+
scopeSysId = scopeResult[0].sys_id;
|
|
41
|
+
// Switch to the target scope first
|
|
42
|
+
Logger_1.logger.info(`Switching to scope: ${scope}`);
|
|
43
|
+
await switchToScope(scopeSysId, scope);
|
|
49
44
|
}
|
|
50
|
-
// Create the update set
|
|
51
|
-
|
|
45
|
+
// Create the update set in the correct scope
|
|
46
|
+
Logger_1.logger.info(`Creating update set: ${name}`);
|
|
47
|
+
const createResponse = client.createUpdateSet(name, scopeSysId, description);
|
|
52
48
|
const createResult = await (0, snClient_1.unwrapSNResponse)(createResponse);
|
|
53
49
|
const updateSetSysId = createResult.sys_id;
|
|
54
|
-
// Update the description if provided (ServiceNow API might not accept it during creation)
|
|
55
|
-
if (description) {
|
|
56
|
-
await client.updateRecord("sys_update_set", updateSetSysId, { description });
|
|
57
|
-
}
|
|
58
50
|
// Switch to the new update set
|
|
59
51
|
await switchToUpdateSet(updateSetSysId, name);
|
|
60
52
|
Logger_1.logger.info(chalk_1.default.green(`✓ Update set "${name}" created and activated`));
|
|
61
53
|
Logger_1.logger.info(`Update Set ID: ${updateSetSysId}`);
|
|
54
|
+
if (scope) {
|
|
55
|
+
Logger_1.logger.info(`Scope: ${scope}`);
|
|
56
|
+
}
|
|
62
57
|
}
|
|
63
58
|
catch (e) {
|
|
64
59
|
Logger_1.logger.error("Failed to create update set");
|
|
@@ -219,6 +214,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
219
214
|
await client.createCurrentUpdateSetUserPref(updateSetSysId, userSysId);
|
|
220
215
|
}
|
|
221
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Helper function to switch to a scope
|
|
219
|
+
*/
|
|
220
|
+
async function switchToScope(scopeSysId, scopeName) {
|
|
221
|
+
const client = (0, snClient_1.defaultClient)();
|
|
222
|
+
// Get current user sys_id
|
|
223
|
+
const userSysId = await (0, snClient_1.unwrapTableAPIFirstItem)(client.getUserSysId(), "sys_id");
|
|
224
|
+
// Get or create user preference for current app
|
|
225
|
+
try {
|
|
226
|
+
const curAppUserPrefId = await (0, snClient_1.unwrapTableAPIFirstItem)(client.getCurrentAppUserPrefSysId(userSysId), "sys_id");
|
|
227
|
+
// Update existing preference
|
|
228
|
+
await client.updateCurrentAppUserPref(scopeSysId, curAppUserPrefId);
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
// Create new preference if it doesn't exist
|
|
232
|
+
await client.createCurrentAppUserPref(scopeSysId, userSysId);
|
|
233
|
+
}
|
|
234
|
+
Logger_1.logger.info(`Switched to scope: ${scopeName}`);
|
|
235
|
+
}
|
|
222
236
|
/**
|
|
223
237
|
* Helper function to get update sets based on query
|
|
224
238
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenonhq/sincronia-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "Next-gen file syncer",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.2.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@tenonhq/sincronia-core": "^0.0.24",
|
|
40
41
|
"axios": "^1.5.1",
|
|
41
42
|
"axios-rate-limit": "^1.3.0",
|
|
42
43
|
"chalk": "^5.3.0",
|