@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.
@@ -14736,6 +14736,15 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14736
14736
  is_final: Boolean!
14737
14737
  history: [StateMachineTransitionEvent!]!
14738
14738
  instances_in_state(state: String!): [Model!]!
14739
+ instance_population(state: String!, page: Int = 1, per_page: Int = 50): StateMachineInstancePopulation!
14740
+ }
14741
+
14742
+ type StateMachineInstancePopulation {
14743
+ count: Int!
14744
+ instances: [Model!]!
14745
+ page: Int!
14746
+ per_page: Int!
14747
+ has_more: Boolean!
14739
14748
  }
14740
14749
 
14741
14750
  type StateMachineState {
@@ -14944,6 +14953,13 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14944
14953
  value.model.target || value.model,
14945
14954
  value.name,
14946
14955
  state
14956
+ ),
14957
+ instance_population: async (value, { state, page, per_page }) => await stateMachines.instancePopulation(
14958
+ value.model.target || value.model,
14959
+ value.name,
14960
+ state,
14961
+ page,
14962
+ per_page
14947
14963
  )
14948
14964
  }
14949
14965
  };
@@ -17880,11 +17896,16 @@ var Granular = class _Granular {
17880
17896
  `${methodName}() requires at least one permission so the SDK can ensure assignments for new users.`
17881
17897
  );
17882
17898
  }
17883
- for (const profileName of user.permissions) {
17884
- const profileId = await this.ensurePermissionProfile(
17885
- sandbox.sandboxId,
17886
- profileName
17899
+ const permissionProfileIds = [];
17900
+ for (const profileReference of user.permissions) {
17901
+ permissionProfileIds.push(
17902
+ await this.ensurePermissionProfile(
17903
+ sandbox.sandboxId,
17904
+ profileReference
17905
+ )
17887
17906
  );
17907
+ }
17908
+ for (const profileId of permissionProfileIds) {
17888
17909
  await this.ensureAssignment(
17889
17910
  user.granularId,
17890
17911
  sandbox.sandboxId,
@@ -18889,25 +18910,37 @@ var Granular = class _Granular {
18889
18910
  }
18890
18911
  }
18891
18912
  /**
18892
- * Ensure a permission profile exists for a sandbox, creating it if needed.
18893
- * If profileName matches an existing profile name, returns its ID.
18894
- * Otherwise, creates a v1 source-profile file shape with an allow default.
18913
+ * Resolve an existing permission profile by exact name or ID.
18914
+ *
18915
+ * `allow-all` is the sole compatibility profile that the SDK may provision
18916
+ * automatically. Every other missing reference fails closed so a typo or
18917
+ * untrusted role value cannot become an allow-default profile.
18895
18918
  */
18896
- async ensurePermissionProfile(sandboxId, profileName) {
18897
- try {
18898
- const profiles = await this.permissionProfiles.list(sandboxId);
18899
- const existing = profiles.find((p) => p.name === profileName);
18900
- if (existing) {
18901
- return existing.permissionProfileId;
18902
- }
18903
- } catch {
18919
+ async ensurePermissionProfile(sandboxId, profileReference) {
18920
+ const normalizedReference = typeof profileReference === "string" ? profileReference.trim() : "";
18921
+ if (!normalizedReference) {
18922
+ throw new Error(
18923
+ "Permission profile references must be non-empty names or IDs."
18924
+ );
18925
+ }
18926
+ const profiles = await this.permissionProfiles.list(sandboxId);
18927
+ const existing = profiles.find(
18928
+ (profile) => profile.name === normalizedReference || profile.permissionProfileId === normalizedReference
18929
+ );
18930
+ if (existing) {
18931
+ return existing.permissionProfileId;
18932
+ }
18933
+ if (normalizedReference !== "allow-all") {
18934
+ throw new Error(
18935
+ `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.`
18936
+ );
18904
18937
  }
18905
18938
  const created = await this.permissionProfiles.create(sandboxId, {
18906
- name: profileName,
18939
+ name: normalizedReference,
18907
18940
  rules: {
18908
18941
  schemaVersion: 1,
18909
- name: profileName,
18910
- description: profileName === "allow-all" ? "Every declared action is visible unless a manifest policy denies it." : `Generated permission profile ${profileName}`,
18942
+ name: normalizedReference,
18943
+ description: "Every declared action is visible unless a manifest policy denies it.",
18911
18944
  defaults: { actionPolicy: "allow" },
18912
18945
  actions: []
18913
18946
  }