@cloud-copilot/iam-expand 0.1.6 → 0.1.8

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/src/expand.ts CHANGED
@@ -37,15 +37,7 @@ export interface ExpandIamActionsOptions {
37
37
  * If false, an empty array will be returned
38
38
  * Default: false
39
39
  */
40
- errorOnMissingService: boolean
41
-
42
- /**
43
- * If true, only unique values will be returned, while maintaining order
44
- * If false, all values will be returned, even if they are duplicates
45
- * Default: false
46
- */
47
- distinct: boolean
48
-
40
+ errorOnInvalidService: boolean
49
41
 
50
42
  /**
51
43
  * The behavior to use when an invalid action is encountered without wildcards
@@ -56,23 +48,14 @@ export interface ExpandIamActionsOptions {
56
48
  * Default: InvalidActionBehavior.Remove
57
49
  */
58
50
  invalidActionBehavior: InvalidActionBehavior
59
-
60
- /**
61
- * If true, the returned array will be sorted
62
- * If false, the returned array will be in the order they were expanded
63
- * Default: false
64
- */
65
- sort: boolean
66
51
  }
67
52
 
68
53
  const defaultOptions: ExpandIamActionsOptions = {
69
54
  expandAsterisk: false,
70
55
  expandServiceAsterisk: false,
71
56
  errorOnInvalidFormat: false,
72
- errorOnMissingService: false,
57
+ errorOnInvalidService: false,
73
58
  invalidActionBehavior: InvalidActionBehavior.Remove,
74
- distinct: false,
75
- sort: false
76
59
  }
77
60
 
78
61
  const allAsterisksPattern = /^\*+$/i
@@ -101,21 +84,9 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
101
84
  return expandIamActions(actionString, options);
102
85
  }))
103
86
 
104
- let allMatches = actionLists.flat()
105
-
106
- if(options.distinct) {
107
- const aSet = new Set<string>()
108
- allMatches = allMatches.filter((value) => {
109
- if(aSet.has(value)) {
110
- return false
111
- }
112
- aSet.add(value)
113
- return true
114
- })
115
- }
116
- if(options.sort) {
117
- allMatches.sort()
118
- }
87
+ const allMatches = Array.from(new Set(actionLists.flat()))
88
+ allMatches.sort()
89
+
119
90
  return allMatches
120
91
  }
121
92
 
@@ -152,7 +123,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
152
123
 
153
124
  const [service, wildcardActions] = parts.map(part => part.toLowerCase())
154
125
  if(!await iamServiceExists(service)) {
155
- if(options.errorOnMissingService) {
126
+ if(options.errorOnInvalidService) {
156
127
  throw new Error(`Service not found: ${service}`)
157
128
  }
158
129
  return []
@@ -189,9 +160,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
189
160
  const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$"
190
161
  const regex = new RegExp(pattern, 'i')
191
162
  const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`)
192
- if(options.sort) {
193
- matchingActions.sort()
194
- }
163
+ matchingActions.sort()
195
164
 
196
165
  return matchingActions
197
166
  }
@@ -55,7 +55,6 @@ describe('expand_file', () => {
55
55
  }
56
56
  }
57
57
  vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
58
- expect(options?.distinct).toBe(true)
59
58
  return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
60
59
  })
61
60
 
@@ -134,7 +133,6 @@ describe('expand_file', () => {
134
133
  }
135
134
  }
136
135
  vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
137
- expect(options?.distinct).toBe(true)
138
136
  return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
139
137
  })
140
138
 
@@ -14,7 +14,7 @@ export async function expandJsonDocument(options: Partial<ExpandIamActionsOption
14
14
  return await expandIamActions(document, options)
15
15
  }
16
16
  if(Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
17
- const value = await expandIamActions(document, {...options, distinct: true})
17
+ const value = await expandIamActions(document, {...options})
18
18
  return value
19
19
  }
20
20
  }