@dishantlangayan/sc-cli-core 0.5.1 → 0.5.3

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.
@@ -45,17 +45,21 @@ export class OrgManager {
45
45
  this.ensureInitialized();
46
46
  // Validate organization
47
47
  this.validateOrg(org);
48
- // Check if organization already exists (by orgId or alias)
49
- const existingByOrgId = this.storage.orgs.find((o) => o.orgId === org.orgId);
50
- if (existingByOrgId) {
51
- throw new OrgError(`Organization '${org.orgId}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
52
- }
48
+ // Check if alias already exists (aliases must be globally unique)
53
49
  if (org.alias) {
54
50
  const existingByAlias = this.storage.orgs.find((o) => o.alias === org.alias);
55
51
  if (existingByAlias) {
56
52
  throw new OrgError(`Organization with alias '${org.alias}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
57
53
  }
58
54
  }
55
+ // If no alias provided, check if orgId already exists (maintain current behavior)
56
+ // If alias is provided, allow multiple tokens for the same orgId with different aliases
57
+ if (!org.alias) {
58
+ const existingByOrgId = this.storage.orgs.find((o) => o.orgId === org.orgId);
59
+ if (existingByOrgId) {
60
+ throw new OrgError(`Organization '${org.orgId}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
61
+ }
62
+ }
59
63
  // If this org is being set as default, unset any existing default
60
64
  if (org.isDefault) {
61
65
  this.unsetAllDefaults();
@@ -295,6 +299,19 @@ export class OrgManager {
295
299
  if (!this.masterKey || !this.machineId) {
296
300
  throw new OrgError('Org manager not initialized', OrgErrorCode.NOT_INITIALIZED);
297
301
  }
302
+ // If storage is empty, delete the file instead of saving
303
+ if (this.storage.orgs.length === 0) {
304
+ try {
305
+ await unlink(this.configFile);
306
+ }
307
+ catch (error) {
308
+ // Ignore if file doesn't exist (ENOENT)
309
+ if (error.code !== 'ENOENT') {
310
+ throw error;
311
+ }
312
+ }
313
+ return;
314
+ }
298
315
  // Ensure directory exists
299
316
  await mkdir(this.configDir, { mode: 0o700, recursive: true });
300
317
  // Generate new salt and derive key for THIS save
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dishantlangayan/sc-cli-core",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Base library for the Solace Cloud CLI and plugins",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Dishant Langayan",