@granular-software/sdk 0.4.52 → 0.4.53

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.
@@ -16330,6 +16330,55 @@ var Granular = class _Granular {
16330
16330
  throw error;
16331
16331
  }
16332
16332
  }
16333
+ /**
16334
+ * Resolve one exact environment only when Granular confirms that it belongs
16335
+ * to the given external user in the requested sandbox (and, optionally,
16336
+ * tag). This is deliberately read-only: callers use it to keep an already
16337
+ * opened delegated workspace stable while a newer active environment is
16338
+ * being prepared in the background.
16339
+ */
16340
+ async getEnvironmentForUser(options) {
16341
+ const sandboxId = options.sandboxId.trim();
16342
+ const userId = options.userId.trim();
16343
+ const environmentId = options.environmentId.trim();
16344
+ const tagName = options.tag?.trim();
16345
+ if (!sandboxId || !userId || !environmentId) {
16346
+ throw new Error(
16347
+ "getEnvironmentForUser() requires sandboxId, userId, and environmentId."
16348
+ );
16349
+ }
16350
+ const subjects = await this.request(
16351
+ `/control/subjects?identityId=${encodeURIComponent(userId)}`
16352
+ );
16353
+ const subject = (subjects.items || []).find(
16354
+ (item) => item.identityId === userId || item.userId === userId
16355
+ );
16356
+ const subjectId = subject?.subjectId || subject?.granularId;
16357
+ if (!subjectId) return null;
16358
+ let environment;
16359
+ try {
16360
+ environment = await this.environments.get(environmentId);
16361
+ } catch (error) {
16362
+ const message = error instanceof Error ? error.message : String(error);
16363
+ if (message.includes("404") || message.includes("not found")) {
16364
+ return null;
16365
+ }
16366
+ throw error;
16367
+ }
16368
+ if (environment.sandboxId !== sandboxId || environment.subjectId !== subjectId) {
16369
+ return null;
16370
+ }
16371
+ if (tagName) {
16372
+ const tags = await this.request(`/control/sandboxes/${encodeURIComponent(sandboxId)}/tags`);
16373
+ const tag = (tags.items || []).find(
16374
+ (candidate) => candidate?.name === tagName
16375
+ );
16376
+ if (!tag || environment.tagId !== tag.tagId) {
16377
+ return null;
16378
+ }
16379
+ }
16380
+ return this.bindEnvironmentHandle(environment);
16381
+ }
16333
16382
  /**
16334
16383
  * Register one reviewed, pre-existing environment as the active workspace
16335
16384
  * for an external user. This is for a controlled migration only: it does