@granular-software/sdk 0.4.61 → 0.4.62

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/index.mjs CHANGED
@@ -14761,6 +14761,15 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14761
14761
  is_final: Boolean!
14762
14762
  history: [StateMachineTransitionEvent!]!
14763
14763
  instances_in_state(state: String!): [Model!]!
14764
+ instance_population(state: String!, page: Int = 1, per_page: Int = 50): StateMachineInstancePopulation!
14765
+ }
14766
+
14767
+ type StateMachineInstancePopulation {
14768
+ count: Int!
14769
+ instances: [Model!]!
14770
+ page: Int!
14771
+ per_page: Int!
14772
+ has_more: Boolean!
14764
14773
  }
14765
14774
 
14766
14775
  type StateMachineState {
@@ -14969,6 +14978,13 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14969
14978
  value.model.target || value.model,
14970
14979
  value.name,
14971
14980
  state
14981
+ ),
14982
+ instance_population: async (value, { state, page, per_page }) => await stateMachines.instancePopulation(
14983
+ value.model.target || value.model,
14984
+ value.name,
14985
+ state,
14986
+ page,
14987
+ per_page
14972
14988
  )
14973
14989
  }
14974
14990
  };
@@ -18003,11 +18019,16 @@ var Granular = class _Granular {
18003
18019
  `${methodName}() requires at least one permission so the SDK can ensure assignments for new users.`
18004
18020
  );
18005
18021
  }
18006
- for (const profileName of user.permissions) {
18007
- const profileId = await this.ensurePermissionProfile(
18008
- sandbox.sandboxId,
18009
- profileName
18022
+ const permissionProfileIds = [];
18023
+ for (const profileReference of user.permissions) {
18024
+ permissionProfileIds.push(
18025
+ await this.ensurePermissionProfile(
18026
+ sandbox.sandboxId,
18027
+ profileReference
18028
+ )
18010
18029
  );
18030
+ }
18031
+ for (const profileId of permissionProfileIds) {
18011
18032
  await this.ensureAssignment(
18012
18033
  user.granularId,
18013
18034
  sandbox.sandboxId,
@@ -19012,25 +19033,37 @@ var Granular = class _Granular {
19012
19033
  }
19013
19034
  }
19014
19035
  /**
19015
- * Ensure a permission profile exists for a sandbox, creating it if needed.
19016
- * If profileName matches an existing profile name, returns its ID.
19017
- * Otherwise, creates a v1 source-profile file shape with an allow default.
19036
+ * Resolve an existing permission profile by exact name or ID.
19037
+ *
19038
+ * `allow-all` is the sole compatibility profile that the SDK may provision
19039
+ * automatically. Every other missing reference fails closed so a typo or
19040
+ * untrusted role value cannot become an allow-default profile.
19018
19041
  */
19019
- async ensurePermissionProfile(sandboxId, profileName) {
19020
- try {
19021
- const profiles = await this.permissionProfiles.list(sandboxId);
19022
- const existing = profiles.find((p) => p.name === profileName);
19023
- if (existing) {
19024
- return existing.permissionProfileId;
19025
- }
19026
- } catch {
19042
+ async ensurePermissionProfile(sandboxId, profileReference) {
19043
+ const normalizedReference = typeof profileReference === "string" ? profileReference.trim() : "";
19044
+ if (!normalizedReference) {
19045
+ throw new Error(
19046
+ "Permission profile references must be non-empty names or IDs."
19047
+ );
19048
+ }
19049
+ const profiles = await this.permissionProfiles.list(sandboxId);
19050
+ const existing = profiles.find(
19051
+ (profile) => profile.name === normalizedReference || profile.permissionProfileId === normalizedReference
19052
+ );
19053
+ if (existing) {
19054
+ return existing.permissionProfileId;
19055
+ }
19056
+ if (normalizedReference !== "allow-all") {
19057
+ throw new Error(
19058
+ `Permission profile "${normalizedReference}" was not found in sandbox ${sandboxId}. Provision it with granular build or granular deploy before calling openEnvironment(). Only the reserved "allow-all" profile can be created automatically.`
19059
+ );
19027
19060
  }
19028
19061
  const created = await this.permissionProfiles.create(sandboxId, {
19029
- name: profileName,
19062
+ name: normalizedReference,
19030
19063
  rules: {
19031
19064
  schemaVersion: 1,
19032
- name: profileName,
19033
- description: profileName === "allow-all" ? "Every declared action is visible unless a manifest policy denies it." : `Generated permission profile ${profileName}`,
19065
+ name: normalizedReference,
19066
+ description: "Every declared action is visible unless a manifest policy denies it.",
19034
19067
  defaults: { actionPolicy: "allow" },
19035
19068
  actions: []
19036
19069
  }