@granular-software/sdk 0.4.13 → 0.4.14
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/README.md +14 -12
- package/dist/cli/index.js +362 -75
- package/dist/index.d.mts +95 -12
- package/dist/index.d.ts +95 -12
- package/dist/index.js +56 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5591,6 +5591,19 @@ function normalizeUser(user) {
|
|
|
5591
5591
|
permissions: Array.isArray(user.permissions) ? user.permissions : []
|
|
5592
5592
|
};
|
|
5593
5593
|
}
|
|
5594
|
+
function normalizeEnvironmentData(environment) {
|
|
5595
|
+
const buildPolicy = environment.buildPolicy || environment.tracking || (environment.tagId ? { mode: "tag", tagId: environment.tagId } : { mode: "pinned", versionId: environment.versionId || environment.buildId });
|
|
5596
|
+
const environmentName = environment.environment || environment.envName || "prod";
|
|
5597
|
+
return {
|
|
5598
|
+
...environment,
|
|
5599
|
+
ontologyId: environment.ontologyId || environment.sandboxId,
|
|
5600
|
+
versionId: environment.versionId || environment.buildId,
|
|
5601
|
+
envName: environmentName,
|
|
5602
|
+
environment: environmentName,
|
|
5603
|
+
buildPolicy,
|
|
5604
|
+
tracking: environment.tracking || buildPolicy
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
5594
5607
|
var Environment = class extends Session {
|
|
5595
5608
|
envData;
|
|
5596
5609
|
_apiKey;
|
|
@@ -5609,10 +5622,26 @@ var Environment = class extends Session {
|
|
|
5609
5622
|
get sandboxId() {
|
|
5610
5623
|
return this.envData.sandboxId;
|
|
5611
5624
|
}
|
|
5625
|
+
/** The ontology ID */
|
|
5626
|
+
get ontologyId() {
|
|
5627
|
+
return this.envData.ontologyId || this.envData.sandboxId;
|
|
5628
|
+
}
|
|
5612
5629
|
/** The subject ID */
|
|
5613
5630
|
get subjectId() {
|
|
5614
5631
|
return this.envData.subjectId;
|
|
5615
5632
|
}
|
|
5633
|
+
/** The named environment slot, such as dev or prod */
|
|
5634
|
+
get envName() {
|
|
5635
|
+
return this.envData.envName;
|
|
5636
|
+
}
|
|
5637
|
+
/** The named environment slot, such as dev or prod */
|
|
5638
|
+
get environment() {
|
|
5639
|
+
return this.envData.environment || this.envData.envName;
|
|
5640
|
+
}
|
|
5641
|
+
/** The resolved ontology version backing this environment */
|
|
5642
|
+
get versionId() {
|
|
5643
|
+
return this.envData.versionId || this.envData.buildId;
|
|
5644
|
+
}
|
|
5616
5645
|
/** Internal Granular user identifier for this environment */
|
|
5617
5646
|
get granularId() {
|
|
5618
5647
|
return this.envData.subjectId;
|
|
@@ -6584,7 +6613,7 @@ var Granular = class {
|
|
|
6584
6613
|
throw new Error("connect() requires either userId, granularId, or a user object returned by recordUser().");
|
|
6585
6614
|
}
|
|
6586
6615
|
/**
|
|
6587
|
-
* Connect to
|
|
6616
|
+
* Connect to an ontology environment and establish a real-time session.
|
|
6588
6617
|
*
|
|
6589
6618
|
* Effects are registered at the sandbox level via `granular.registerEffect()`
|
|
6590
6619
|
* or `granular.registerEffects()`. Sessions pick up live availability from
|
|
@@ -6596,7 +6625,8 @@ var Granular = class {
|
|
|
6596
6625
|
* @example
|
|
6597
6626
|
* ```typescript
|
|
6598
6627
|
* const environment = await granular.connect({
|
|
6599
|
-
*
|
|
6628
|
+
* ontology: 'my-ontology',
|
|
6629
|
+
* environment: 'dev',
|
|
6600
6630
|
* userId: 'user_123',
|
|
6601
6631
|
* permissions: ['agent'],
|
|
6602
6632
|
* });
|
|
@@ -6616,17 +6646,28 @@ var Granular = class {
|
|
|
6616
6646
|
*
|
|
6617
6647
|
* console.log(await job.result); // 'Hello!'
|
|
6618
6648
|
* ```
|
|
6619
|
-
|
|
6649
|
+
*/
|
|
6620
6650
|
async connect(options) {
|
|
6621
6651
|
const clientId = options.clientId || `client_${Date.now()}`;
|
|
6652
|
+
const ontology = options.ontology;
|
|
6653
|
+
if (!ontology) {
|
|
6654
|
+
throw new Error("connect() requires `ontology`.");
|
|
6655
|
+
}
|
|
6656
|
+
const environmentName = options.environment;
|
|
6657
|
+
if (!environmentName) {
|
|
6658
|
+
throw new Error("connect() requires `environment`.");
|
|
6659
|
+
}
|
|
6660
|
+
const tagName = options.tagName?.trim() || void 0;
|
|
6622
6661
|
const user = await this.resolveConnectUser(options);
|
|
6623
|
-
const sandbox = await this.findOrCreateSandbox(
|
|
6662
|
+
const sandbox = await this.findOrCreateSandbox(ontology);
|
|
6624
6663
|
for (const profileName of user.permissions) {
|
|
6625
6664
|
const profileId = await this.ensurePermissionProfile(sandbox.sandboxId, profileName);
|
|
6626
6665
|
await this.ensureAssignment(user.granularId, sandbox.sandboxId, profileId);
|
|
6627
6666
|
}
|
|
6628
6667
|
const envData = await this.environments.create(sandbox.sandboxId, {
|
|
6629
6668
|
subjectId: user.granularId,
|
|
6669
|
+
environment: environmentName,
|
|
6670
|
+
tagName,
|
|
6630
6671
|
permissionProfileId: null
|
|
6631
6672
|
});
|
|
6632
6673
|
await this.activateEnvironment(envData.environmentId);
|
|
@@ -7061,16 +7102,22 @@ var Granular = class {
|
|
|
7061
7102
|
const result = await this.request(
|
|
7062
7103
|
`/control/sandboxes/${sandboxId}/environments`
|
|
7063
7104
|
);
|
|
7064
|
-
return result.items;
|
|
7105
|
+
return result.items.map(normalizeEnvironmentData);
|
|
7065
7106
|
},
|
|
7066
7107
|
get: async (environmentId) => {
|
|
7067
|
-
return
|
|
7108
|
+
return normalizeEnvironmentData(
|
|
7109
|
+
await this.request(`/control/environments/${environmentId}`)
|
|
7110
|
+
);
|
|
7068
7111
|
},
|
|
7069
7112
|
create: async (sandboxId, data) => {
|
|
7070
|
-
|
|
7113
|
+
const environmentName = data.environment || data.envName;
|
|
7114
|
+
return normalizeEnvironmentData(await this.request(`/control/sandboxes/${sandboxId}/environments`, {
|
|
7071
7115
|
method: "POST",
|
|
7072
|
-
body: JSON.stringify(
|
|
7073
|
-
|
|
7116
|
+
body: JSON.stringify({
|
|
7117
|
+
...data,
|
|
7118
|
+
envName: environmentName
|
|
7119
|
+
})
|
|
7120
|
+
}));
|
|
7074
7121
|
},
|
|
7075
7122
|
delete: async (environmentId) => {
|
|
7076
7123
|
return this.request(`/control/environments/${environmentId}`, {
|