@cloud-copilot/iam-utils 0.1.43 → 0.1.45
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/cjs/actions.d.ts +9 -0
- package/dist/cjs/actions.d.ts.map +1 -0
- package/dist/cjs/actions.js +65 -0
- package/dist/cjs/actions.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources.d.ts +8 -0
- package/dist/cjs/resources.d.ts.map +1 -0
- package/dist/cjs/resources.js +14 -0
- package/dist/cjs/resources.js.map +1 -0
- package/dist/esm/actions.d.ts +9 -0
- package/dist/esm/actions.d.ts.map +1 -0
- package/dist/esm/actions.js +62 -0
- package/dist/esm/actions.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources.d.ts +8 -0
- package/dist/esm/resources.d.ts.map +1 -0
- package/dist/esm/resources.js +11 -0
- package/dist/esm/resources.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to check, should not contain wildcards
|
|
5
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
6
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function actionMatchesPattern(action: string, pattern: string): boolean;
|
|
9
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAuC7E"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.actionMatchesPattern = actionMatchesPattern;
|
|
4
|
+
/**
|
|
5
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
6
|
+
*
|
|
7
|
+
* @param action the action to check, should not contain wildcards
|
|
8
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
9
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
function actionMatchesPattern(action, pattern) {
|
|
12
|
+
const unescapedAction = unescapeUnicodeCharacters(action);
|
|
13
|
+
const unescapedPattern = unescapeUnicodeCharacters(pattern);
|
|
14
|
+
// Full wildcard matches everything
|
|
15
|
+
if (unescapedPattern === '*') {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
// Split into service and action parts
|
|
19
|
+
const patternColonIndex = unescapedPattern.indexOf(':');
|
|
20
|
+
const actionColonIndex = unescapedAction.indexOf(':');
|
|
21
|
+
// If pattern has no colon, it must match the entire action exactly (case-insensitive)
|
|
22
|
+
if (patternColonIndex === -1) {
|
|
23
|
+
if (actionColonIndex === -1) {
|
|
24
|
+
return unescapedAction.toLowerCase() === unescapedPattern.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
// If action has no colon but pattern does, no match
|
|
29
|
+
if (actionColonIndex === -1) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const patternService = unescapedPattern.substring(0, patternColonIndex);
|
|
33
|
+
const patternAction = unescapedPattern.substring(patternColonIndex + 1);
|
|
34
|
+
const actionService = unescapedAction.substring(0, actionColonIndex);
|
|
35
|
+
const actionAction = unescapedAction.substring(actionColonIndex + 1);
|
|
36
|
+
// Service must match exactly (case-insensitive), no wildcards allowed
|
|
37
|
+
if (patternService.toLowerCase() !== actionService.toLowerCase()) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// Match the action part with wildcards
|
|
41
|
+
const regex = convertStringToPattern(patternAction);
|
|
42
|
+
return regex.test(actionAction);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Converts an action string pattern to a regular expression for matching.
|
|
46
|
+
*
|
|
47
|
+
* @param actionString the IAM action pattern string to convert
|
|
48
|
+
* @returns RegExp that matches the pattern (case-insensitive)
|
|
49
|
+
*/
|
|
50
|
+
function convertStringToPattern(actionString) {
|
|
51
|
+
const pattern = '^' + actionString.replace(/\?/g, '.').replace(/\*/g, '.*?') + '$';
|
|
52
|
+
return new RegExp(pattern, 'i');
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Unescapes unicode characters in a string.
|
|
56
|
+
*
|
|
57
|
+
* @param str The string to unescape
|
|
58
|
+
* @returns The string with any escaped unicode characters replaced with their actual characters
|
|
59
|
+
*/
|
|
60
|
+
function unescapeUnicodeCharacters(str) {
|
|
61
|
+
return str.replace(/\\u([\dA-Fa-f]{4})/gi, (match, code) => {
|
|
62
|
+
return String.fromCharCode(parseInt(code, 16));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":";;AAOA,oDAuCC;AA9CD;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,MAAc,EAAE,OAAe;IAClE,MAAM,eAAe,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACzD,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAA;IAE3D,mCAAmC;IACnC,IAAI,gBAAgB,KAAK,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sCAAsC;IACtC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,C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AAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,GAAW;IAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACzD,OAAO,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { actionMatchesPattern } from './actions.js';
|
|
1
2
|
export { getResourceSegments, splitArnParts, type ArnParts } from './arn.js';
|
|
2
3
|
export { convertAssumedRoleArnToRoleArn, convertRoleArnToAssumedRoleArn, isArnPrincipal, isAssumedRoleArn, isFederatedUserArn, isIamRoleArn, isIamUserArn, isServicePrincipal } from './principals.js';
|
|
4
|
+
export { resourceArnWithWildcardsToRegex } from './resources.js';
|
|
3
5
|
export { bucketArn, isS3BucketOrObjectArn } from './s3.js';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isS3BucketOrObjectArn = exports.bucketArn = exports.isServicePrincipal = exports.isIamUserArn = exports.isIamRoleArn = exports.isFederatedUserArn = exports.isAssumedRoleArn = exports.isArnPrincipal = exports.convertRoleArnToAssumedRoleArn = exports.convertAssumedRoleArnToRoleArn = exports.splitArnParts = exports.getResourceSegments = void 0;
|
|
3
|
+
exports.isS3BucketOrObjectArn = exports.bucketArn = exports.resourceArnWithWildcardsToRegex = exports.isServicePrincipal = exports.isIamUserArn = exports.isIamRoleArn = exports.isFederatedUserArn = exports.isAssumedRoleArn = exports.isArnPrincipal = exports.convertRoleArnToAssumedRoleArn = exports.convertAssumedRoleArnToRoleArn = exports.splitArnParts = exports.getResourceSegments = exports.actionMatchesPattern = void 0;
|
|
4
|
+
var actions_js_1 = require("./actions.js");
|
|
5
|
+
Object.defineProperty(exports, "actionMatchesPattern", { enumerable: true, get: function () { return actions_js_1.actionMatchesPattern; } });
|
|
4
6
|
var arn_js_1 = require("./arn.js");
|
|
5
7
|
Object.defineProperty(exports, "getResourceSegments", { enumerable: true, get: function () { return arn_js_1.getResourceSegments; } });
|
|
6
8
|
Object.defineProperty(exports, "splitArnParts", { enumerable: true, get: function () { return arn_js_1.splitArnParts; } });
|
|
@@ -13,6 +15,8 @@ Object.defineProperty(exports, "isFederatedUserArn", { enumerable: true, get: fu
|
|
|
13
15
|
Object.defineProperty(exports, "isIamRoleArn", { enumerable: true, get: function () { return principals_js_1.isIamRoleArn; } });
|
|
14
16
|
Object.defineProperty(exports, "isIamUserArn", { enumerable: true, get: function () { return principals_js_1.isIamUserArn; } });
|
|
15
17
|
Object.defineProperty(exports, "isServicePrincipal", { enumerable: true, get: function () { return principals_js_1.isServicePrincipal; } });
|
|
18
|
+
var resources_js_1 = require("./resources.js");
|
|
19
|
+
Object.defineProperty(exports, "resourceArnWithWildcardsToRegex", { enumerable: true, get: function () { return resources_js_1.resourceArnWithWildcardsToRegex; } });
|
|
16
20
|
var s3_js_1 = require("./s3.js");
|
|
17
21
|
Object.defineProperty(exports, "bucketArn", { enumerable: true, get: function () { return s3_js_1.bucketArn; } });
|
|
18
22
|
Object.defineProperty(exports, "isS3BucketOrObjectArn", { enumerable: true, get: function () { return s3_js_1.isS3BucketOrObjectArn; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4E;AAAnE,6GAAA,mBAAmB,OAAA;AAAE,uGAAA,aAAa,OAAA;AAC3C,iDASwB;AARtB,+HAAA,8BAA8B,OAAA;AAC9B,+HAAA,8BAA8B,OAAA;AAC9B,+GAAA,cAAc,OAAA;AACd,iHAAA,gBAAgB,OAAA;AAChB,mHAAA,kBAAkB,OAAA;AAClB,6GAAA,YAAY,OAAA;AACZ,6GAAA,YAAY,OAAA;AACZ,mHAAA,kBAAkB,OAAA;AAEpB,iCAA0D;AAAjD,kGAAA,SAAS,OAAA;AAAE,8GAAA,qBAAqB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AAA1C,kHAAA,oBAAoB,OAAA;AAC7B,mCAA4E;AAAnE,6GAAA,mBAAmB,OAAA;AAAE,uGAAA,aAAa,OAAA;AAC3C,iDASwB;AARtB,+HAAA,8BAA8B,OAAA;AAC9B,+HAAA,8BAA8B,OAAA;AAC9B,+GAAA,cAAc,OAAA;AACd,iHAAA,gBAAgB,OAAA;AAChB,mHAAA,kBAAkB,OAAA;AAClB,6GAAA,YAAY,OAAA;AACZ,6GAAA,YAAY,OAAA;AACZ,mHAAA,kBAAkB,OAAA;AAEpB,+CAAgE;AAAvD,+HAAA,+BAA+B,OAAA;AACxC,iCAA0D;AAAjD,kGAAA,SAAS,OAAA;AAAE,8GAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export declare function resourceArnWithWildcardsToRegex(pattern: string): RegExp;
|
|
8
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resourceArnWithWildcardsToRegex = resourceArnWithWildcardsToRegex;
|
|
4
|
+
/**
|
|
5
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
6
|
+
*
|
|
7
|
+
* @param pattern The ARN pattern string with wildcards
|
|
8
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
9
|
+
*/
|
|
10
|
+
function resourceArnWithWildcardsToRegex(pattern) {
|
|
11
|
+
const parts = pattern.split('*').map((s) => s.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&'));
|
|
12
|
+
return new RegExp('^' + parts.join('.*?') + '$');
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":";;AAMA,0EAGC;AATD;;;;;GAKG;AACH,SAAgB,+BAA+B,CAAC,OAAe;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC,CAAA;IACtF,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to check, should not contain wildcards
|
|
5
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
6
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function actionMatchesPattern(action: string, pattern: string): boolean;
|
|
9
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAuC7E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to check, should not contain wildcards
|
|
5
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
6
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export function actionMatchesPattern(action, pattern) {
|
|
9
|
+
const unescapedAction = unescapeUnicodeCharacters(action);
|
|
10
|
+
const unescapedPattern = unescapeUnicodeCharacters(pattern);
|
|
11
|
+
// Full wildcard matches everything
|
|
12
|
+
if (unescapedPattern === '*') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
// Split into service and action parts
|
|
16
|
+
const patternColonIndex = unescapedPattern.indexOf(':');
|
|
17
|
+
const actionColonIndex = unescapedAction.indexOf(':');
|
|
18
|
+
// If pattern has no colon, it must match the entire action exactly (case-insensitive)
|
|
19
|
+
if (patternColonIndex === -1) {
|
|
20
|
+
if (actionColonIndex === -1) {
|
|
21
|
+
return unescapedAction.toLowerCase() === unescapedPattern.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// If action has no colon but pattern does, no match
|
|
26
|
+
if (actionColonIndex === -1) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const patternService = unescapedPattern.substring(0, patternColonIndex);
|
|
30
|
+
const patternAction = unescapedPattern.substring(patternColonIndex + 1);
|
|
31
|
+
const actionService = unescapedAction.substring(0, actionColonIndex);
|
|
32
|
+
const actionAction = unescapedAction.substring(actionColonIndex + 1);
|
|
33
|
+
// Service must match exactly (case-insensitive), no wildcards allowed
|
|
34
|
+
if (patternService.toLowerCase() !== actionService.toLowerCase()) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Match the action part with wildcards
|
|
38
|
+
const regex = convertStringToPattern(patternAction);
|
|
39
|
+
return regex.test(actionAction);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts an action string pattern to a regular expression for matching.
|
|
43
|
+
*
|
|
44
|
+
* @param actionString the IAM action pattern string to convert
|
|
45
|
+
* @returns RegExp that matches the pattern (case-insensitive)
|
|
46
|
+
*/
|
|
47
|
+
function convertStringToPattern(actionString) {
|
|
48
|
+
const pattern = '^' + actionString.replace(/\?/g, '.').replace(/\*/g, '.*?') + '$';
|
|
49
|
+
return new RegExp(pattern, 'i');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unescapes unicode characters in a string.
|
|
53
|
+
*
|
|
54
|
+
* @param str The string to unescape
|
|
55
|
+
* @returns The string with any escaped unicode characters replaced with their actual characters
|
|
56
|
+
*/
|
|
57
|
+
function unescapeUnicodeCharacters(str) {
|
|
58
|
+
return str.replace(/\\u([\dA-Fa-f]{4})/gi, (match, code) => {
|
|
59
|
+
return String.fromCharCode(parseInt(code, 16));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,OAAe;IAClE,MAAM,eAAe,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACzD,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAA;IAE3D,mCAAmC;IACnC,IAAI,gBAAgB,KAAK,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sCAAsC;IACtC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACvD,MAAM,gBAAgB,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAErD,sFAAsF;IACtF,IAAI,iBAAiB,KAAK,CAAC,CAAC,EAAE,CAAC;QAC7B,IAAI,gBAAgB,KAA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EAAE;QACzD,OAAO,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { actionMatchesPattern } from './actions.js';
|
|
1
2
|
export { getResourceSegments, splitArnParts, type ArnParts } from './arn.js';
|
|
2
3
|
export { convertAssumedRoleArnToRoleArn, convertRoleArnToAssumedRoleArn, isArnPrincipal, isAssumedRoleArn, isFederatedUserArn, isIamRoleArn, isIamUserArn, isServicePrincipal } from './principals.js';
|
|
4
|
+
export { resourceArnWithWildcardsToRegex } from './resources.js';
|
|
3
5
|
export { bucketArn, isS3BucketOrObjectArn } from './s3.js';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { actionMatchesPattern } from './actions.js';
|
|
1
2
|
export { getResourceSegments, splitArnParts } from './arn.js';
|
|
2
3
|
export { convertAssumedRoleArnToRoleArn, convertRoleArnToAssumedRoleArn, isArnPrincipal, isAssumedRoleArn, isFederatedUserArn, isIamRoleArn, isIamUserArn, isServicePrincipal } from './principals.js';
|
|
4
|
+
export { resourceArnWithWildcardsToRegex } from './resources.js';
|
|
3
5
|
export { bucketArn, isS3BucketOrObjectArn } from './s3.js';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAiB,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAiB,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export declare function resourceArnWithWildcardsToRegex(pattern: string): RegExp;
|
|
8
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export function resourceArnWithWildcardsToRegex(pattern) {
|
|
8
|
+
const parts = pattern.split('*').map((s) => s.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&'));
|
|
9
|
+
return new RegExp('^' + parts.join('.*?') + '$');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAAC,OAAe;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC,CAAA;IACtF,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAA;AAClD,CAAC"}
|