@cloud-copilot/iam-lens 0.1.3 → 0.1.4

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.
Files changed (65) hide show
  1. package/dist/cjs/cli.d.ts +3 -0
  2. package/dist/cjs/cli.d.ts.map +1 -0
  3. package/dist/cjs/cli.js +113 -0
  4. package/dist/cjs/cli.js.map +1 -0
  5. package/dist/cjs/collect/client.d.ts +33 -0
  6. package/dist/cjs/collect/client.d.ts.map +1 -1
  7. package/dist/cjs/collect/client.js +58 -71
  8. package/dist/cjs/collect/client.js.map +1 -1
  9. package/dist/cjs/collect/inMemoryClient.d.ts +6 -0
  10. package/dist/cjs/collect/inMemoryClient.d.ts.map +1 -0
  11. package/dist/cjs/collect/inMemoryClient.js +11 -0
  12. package/dist/cjs/collect/inMemoryClient.js.map +1 -0
  13. package/dist/cjs/contextKeys.d.ts +5 -0
  14. package/dist/cjs/contextKeys.d.ts.map +1 -0
  15. package/dist/cjs/contextKeys.js +111 -0
  16. package/dist/cjs/contextKeys.js.map +1 -0
  17. package/dist/cjs/principals.d.ts +19 -20
  18. package/dist/cjs/principals.d.ts.map +1 -1
  19. package/dist/cjs/principals.js +44 -7
  20. package/dist/cjs/principals.js.map +1 -1
  21. package/dist/cjs/resources.d.ts +1 -0
  22. package/dist/cjs/resources.d.ts.map +1 -1
  23. package/dist/cjs/resources.js +20 -2
  24. package/dist/cjs/resources.js.map +1 -1
  25. package/dist/cjs/simulate.d.ts +11 -0
  26. package/dist/cjs/simulate.d.ts.map +1 -0
  27. package/dist/cjs/simulate.js +121 -0
  28. package/dist/cjs/simulate.js.map +1 -0
  29. package/dist/esm/cli.d.ts +3 -0
  30. package/dist/esm/cli.d.ts.map +1 -0
  31. package/dist/esm/cli.js +111 -0
  32. package/dist/esm/cli.js.map +1 -0
  33. package/dist/esm/collect/client.d.ts +33 -0
  34. package/dist/esm/collect/client.d.ts.map +1 -1
  35. package/dist/esm/collect/client.js +47 -60
  36. package/dist/esm/collect/client.js.map +1 -1
  37. package/dist/esm/collect/inMemoryClient.d.ts +6 -0
  38. package/dist/esm/collect/inMemoryClient.d.ts.map +1 -0
  39. package/dist/esm/collect/inMemoryClient.js +8 -0
  40. package/dist/esm/collect/inMemoryClient.js.map +1 -0
  41. package/dist/esm/contextKeys.d.ts +5 -0
  42. package/dist/esm/contextKeys.d.ts.map +1 -0
  43. package/dist/esm/contextKeys.js +108 -0
  44. package/dist/esm/contextKeys.js.map +1 -0
  45. package/dist/esm/principals.d.ts +19 -20
  46. package/dist/esm/principals.d.ts.map +1 -1
  47. package/dist/esm/principals.js +37 -4
  48. package/dist/esm/principals.js.map +1 -1
  49. package/dist/esm/resources.d.ts +1 -0
  50. package/dist/esm/resources.d.ts.map +1 -1
  51. package/dist/esm/resources.js +18 -1
  52. package/dist/esm/resources.js.map +1 -1
  53. package/dist/esm/simulate.d.ts +11 -0
  54. package/dist/esm/simulate.d.ts.map +1 -0
  55. package/dist/esm/simulate.js +118 -0
  56. package/dist/esm/simulate.js.map +1 -0
  57. package/package.json +8 -2
  58. package/dist/cjs/util/arn.d.ts +0 -26
  59. package/dist/cjs/util/arn.d.ts.map +0 -1
  60. package/dist/cjs/util/arn.js +0 -68
  61. package/dist/cjs/util/arn.js.map +0 -1
  62. package/dist/esm/util/arn.d.ts +0 -26
  63. package/dist/esm/util/arn.d.ts.map +0 -1
  64. package/dist/esm/util/arn.js +0 -64
  65. package/dist/esm/util/arn.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ import { iamActionDetails } from '@cloud-copilot/iam-data';
2
+ import { runSimulation } from '@cloud-copilot/iam-simulate';
3
+ import { splitArnParts } from '@cloud-copilot/iam-utils';
4
+ import { createContextKeys } from './contextKeys.js';
5
+ import { getAllPoliciesForPrincipal, isServiceLinkedRole } from './principals.js';
6
+ import { getAccountIdForResource, getRcpsForResource, getResourcePolicyForResource } from './resources.js';
7
+ export async function simulateRequest(simulationRequest, collectClient) {
8
+ simulationRequest.resourceAccount =
9
+ simulationRequest.resourceAccount ||
10
+ (await getAccountIdForResource(collectClient, simulationRequest.resourceArn));
11
+ if (!simulationRequest.resourceAccount) {
12
+ throw new Error(`Unable to find account ID for resource ${simulationRequest.resourceArn}`);
13
+ }
14
+ const actionParts = simulationRequest.action.split(':');
15
+ const service = actionParts[0];
16
+ const serviceAction = actionParts[1];
17
+ const actionDetails = await iamActionDetails(service, serviceAction);
18
+ if (!actionDetails) {
19
+ throw new Error(`Unable to find action details for ${simulationRequest.action}`);
20
+ }
21
+ if (actionDetails.isWildcardOnly) {
22
+ simulationRequest.resourceAccount = splitArnParts(simulationRequest.principal).accountId;
23
+ }
24
+ //Lookup the principal policies
25
+ const principalPolicies = await getAllPoliciesForPrincipal(collectClient, simulationRequest.principal);
26
+ const resourcePolicy = await getResourcePolicyForResource(collectClient, simulationRequest.resourceArn);
27
+ const resourceRcps = await getRcpsForResource(collectClient, simulationRequest.resourceArn);
28
+ const context = await createContextKeys(collectClient, simulationRequest, simulationRequest.customContextKeys);
29
+ const applicableScps = isServiceLinkedRole(simulationRequest.principal)
30
+ ? []
31
+ : principalPolicies.scps;
32
+ const simulation = {
33
+ request: {
34
+ action: simulationRequest.action,
35
+ resource: {
36
+ resource: simulationRequest.resourceArn,
37
+ accountId: simulationRequest.resourceAccount
38
+ },
39
+ principal: simulationRequest.principal,
40
+ contextVariables: context
41
+ },
42
+ identityPolicies: prepareIdentityPolicies(simulationRequest.principal, principalPolicies),
43
+ serviceControlPolicies: applicableScps,
44
+ resourceControlPolicies: rcpsForRequest(simulationRequest.principal, actionDetails.isWildcardOnly, resourceRcps, principalPolicies.scps),
45
+ resourcePolicy: resourcePolicy,
46
+ permissionBoundaryPolicies: preparePermissionBoundary(principalPolicies)
47
+ };
48
+ const result = await runSimulation(simulation, {});
49
+ return result;
50
+ }
51
+ function rcpsForRequest(principalArn, actionIsWildcard, resourceRcps, principalRcps) {
52
+ if (isServiceLinkedRole(principalArn)) {
53
+ return [];
54
+ }
55
+ let theRcps = resourceRcps;
56
+ if (actionIsWildcard) {
57
+ theRcps = principalRcps;
58
+ }
59
+ return theRcps.map((rcp) => {
60
+ rcp.orgIdentifier;
61
+ return {
62
+ orgIdentifier: rcp.orgIdentifier,
63
+ policies: rcp.policies.filter((policy) => {
64
+ return !policy.name.toLowerCase().endsWith('rcpfullawsaccess');
65
+ })
66
+ };
67
+ });
68
+ }
69
+ function prepareIdentityPolicies(principalArn, principalPolicies) {
70
+ //Collect unique managed policies
71
+ const uniqueIdentityPolicies = {};
72
+ principalPolicies.managedPolicies.forEach((policy) => {
73
+ if (!uniqueIdentityPolicies[policy.arn]) {
74
+ uniqueIdentityPolicies[policy.arn] = {
75
+ name: policy.arn,
76
+ policy: policy.policy
77
+ };
78
+ }
79
+ });
80
+ principalPolicies.groupPolicies?.forEach((groupPolicy) => {
81
+ groupPolicy.managedPolicies.forEach((policy) => {
82
+ if (!uniqueIdentityPolicies[policy.arn]) {
83
+ uniqueIdentityPolicies[policy.arn] = {
84
+ name: policy.arn,
85
+ policy: policy.policy
86
+ };
87
+ }
88
+ });
89
+ });
90
+ const identityPolicies = Object.values(uniqueIdentityPolicies);
91
+ principalPolicies.inlinePolicies.forEach((policy) => {
92
+ identityPolicies.push({
93
+ name: `${principalArn}#${policy.name}`,
94
+ policy: policy.policy
95
+ });
96
+ });
97
+ principalPolicies.groupPolicies?.forEach((groupPolicy) => {
98
+ groupPolicy.inlinePolicies.forEach((policy) => {
99
+ identityPolicies.push({
100
+ name: `${groupPolicy.group}#${policy.name}`,
101
+ policy: policy.policy
102
+ });
103
+ });
104
+ });
105
+ return identityPolicies;
106
+ }
107
+ function preparePermissionBoundary(principalPolicies) {
108
+ if (principalPolicies.permissionBoundary) {
109
+ return [
110
+ {
111
+ name: principalPolicies.permissionBoundary.arn,
112
+ policy: principalPolicies.permissionBoundary.policy
113
+ }
114
+ ];
115
+ }
116
+ return undefined;
117
+ }
118
+ //# sourceMappingURL=simulate.js.map
@@ -0,0 +1 @@
1
+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ED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-copilot/iam-lens",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Visibility in IAM in and across AWS accounts",
5
5
  "keywords": [
6
6
  "aws",
@@ -9,6 +9,9 @@
9
9
  "identity"
10
10
  ],
11
11
  "homepage": "https://github.com/cloud-copilot/iam-lens#readme",
12
+ "bin": {
13
+ "iam-lens": "dist/esm/cli.js"
14
+ },
12
15
  "exports": {
13
16
  ".": {
14
17
  "import": "./dist/esm/index.js",
@@ -107,8 +110,11 @@
107
110
  ]
108
111
  },
109
112
  "dependencies": {
113
+ "@cloud-copilot/cli": "^0.1.28",
110
114
  "@cloud-copilot/iam-collect": "^0.1.63",
115
+ "@cloud-copilot/iam-data": "^0.9.202505241",
111
116
  "@cloud-copilot/iam-policy": "^0.1.24",
112
- "@cloud-copilot/iam-simulate": "^0.1.35"
117
+ "@cloud-copilot/iam-simulate": "^0.1.35",
118
+ "@cloud-copilot/iam-utils": "^0.1.4"
113
119
  }
114
120
  }
@@ -1,26 +0,0 @@
1
- export interface ArnParts {
2
- partition: string | undefined;
3
- service: string | undefined;
4
- region: string | undefined;
5
- accountId: string | undefined;
6
- resource: string | undefined;
7
- resourceType: string | undefined;
8
- resourcePath: string | undefined;
9
- }
10
- /**
11
- * Split an ARN into its parts
12
- *
13
- * @param arn the arn to split
14
- * @returns the parts of the ARN
15
- */
16
- export declare function splitArnParts(arn: string): ArnParts;
17
- /**
18
- * Get the product/id segments of the resource portion of an ARN.
19
- * The first segment is the product segment and the second segment is the resource id segment.
20
- * This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
21
- *
22
- * @param resource The resource to get the resource segments. Must be an ARN resource.
23
- * @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
24
- */
25
- export declare function getResourceSegments(service: string, accountId: string, region: string, resourceString: string): [string, string];
26
- //# sourceMappingURL=arn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBnD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BlB"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- // Copied from https://github.com/cloud-copilot/iam-simulate/blob/main/src/util.ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.splitArnParts = splitArnParts;
5
- exports.getResourceSegments = getResourceSegments;
6
- /**
7
- * Split an ARN into its parts
8
- *
9
- * @param arn the arn to split
10
- * @returns the parts of the ARN
11
- */
12
- function splitArnParts(arn) {
13
- const parts = arn.split(':');
14
- const partition = parts.at(1);
15
- const service = parts.at(2);
16
- const region = parts.at(3);
17
- const accountId = parts.at(4);
18
- const resource = parts.slice(5).join(':');
19
- const [resourceType, resourcePath] = getResourceSegments(service, accountId, region, resource);
20
- return {
21
- partition,
22
- service,
23
- region,
24
- accountId,
25
- resource,
26
- resourceType,
27
- resourcePath
28
- };
29
- }
30
- /**
31
- * Get the product/id segments of the resource portion of an ARN.
32
- * The first segment is the product segment and the second segment is the resource id segment.
33
- * This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
34
- *
35
- * @param resource The resource to get the resource segments. Must be an ARN resource.
36
- * @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
37
- */
38
- function getResourceSegments(service, accountId, region, resourceString) {
39
- // This is terrible, and I hate it
40
- if ((service === 's3' && accountId === '' && region === '') ||
41
- service === 'sns' ||
42
- service === 'sqs') {
43
- return ['', resourceString];
44
- }
45
- if (resourceString.startsWith('/')) {
46
- resourceString = resourceString.slice(1);
47
- }
48
- const slashIndex = resourceString.indexOf('/');
49
- const colonIndex = resourceString.indexOf(':');
50
- let splitIndex = slashIndex;
51
- if (slashIndex != -1 && colonIndex != -1) {
52
- splitIndex = Math.min(slashIndex, colonIndex) + 1;
53
- }
54
- else if (slashIndex == -1 && colonIndex == -1) {
55
- splitIndex = resourceString.length + 1;
56
- }
57
- else if (colonIndex == -1) {
58
- splitIndex = slashIndex + 1;
59
- }
60
- else if (slashIndex == -1) {
61
- splitIndex = colonIndex + 1;
62
- }
63
- else {
64
- throw new Error(`Unable to split resource ${resourceString}`);
65
- }
66
- return [resourceString.slice(0, splitIndex - 1), resourceString.slice(splitIndex)];
67
- }
68
- //# sourceMappingURL=arn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.js","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":";AAAA,kFAAkF;;AAkBlF,sCAkBC;AAUD,kDAoCC;AAtED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,K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CAAC;QAChD,UAAU,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAA;IACxC,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;AACpF,CAAC"}
@@ -1,26 +0,0 @@
1
- export interface ArnParts {
2
- partition: string | undefined;
3
- service: string | undefined;
4
- region: string | undefined;
5
- accountId: string | undefined;
6
- resource: string | undefined;
7
- resourceType: string | undefined;
8
- resourcePath: string | undefined;
9
- }
10
- /**
11
- * Split an ARN into its parts
12
- *
13
- * @param arn the arn to split
14
- * @returns the parts of the ARN
15
- */
16
- export declare function splitArnParts(arn: string): ArnParts;
17
- /**
18
- * Get the product/id segments of the resource portion of an ARN.
19
- * The first segment is the product segment and the second segment is the resource id segment.
20
- * This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
21
- *
22
- * @param resource The resource to get the resource segments. Must be an ARN resource.
23
- * @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
24
- */
25
- export declare function getResourceSegments(service: string, accountId: string, region: string, resourceString: string): [string, string];
26
- //# sourceMappingURL=arn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBnD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BlB"}
@@ -1,64 +0,0 @@
1
- // Copied from https://github.com/cloud-copilot/iam-simulate/blob/main/src/util.ts
2
- /**
3
- * Split an ARN into its parts
4
- *
5
- * @param arn the arn to split
6
- * @returns the parts of the ARN
7
- */
8
- export function splitArnParts(arn) {
9
- const parts = arn.split(':');
10
- const partition = parts.at(1);
11
- const service = parts.at(2);
12
- const region = parts.at(3);
13
- const accountId = parts.at(4);
14
- const resource = parts.slice(5).join(':');
15
- const [resourceType, resourcePath] = getResourceSegments(service, accountId, region, resource);
16
- return {
17
- partition,
18
- service,
19
- region,
20
- accountId,
21
- resource,
22
- resourceType,
23
- resourcePath
24
- };
25
- }
26
- /**
27
- * Get the product/id segments of the resource portion of an ARN.
28
- * The first segment is the product segment and the second segment is the resource id segment.
29
- * This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
30
- *
31
- * @param resource The resource to get the resource segments. Must be an ARN resource.
32
- * @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
33
- */
34
- export function getResourceSegments(service, accountId, region, resourceString) {
35
- // This is terrible, and I hate it
36
- if ((service === 's3' && accountId === '' && region === '') ||
37
- service === 'sns' ||
38
- service === 'sqs') {
39
- return ['', resourceString];
40
- }
41
- if (resourceString.startsWith('/')) {
42
- resourceString = resourceString.slice(1);
43
- }
44
- const slashIndex = resourceString.indexOf('/');
45
- const colonIndex = resourceString.indexOf(':');
46
- let splitIndex = slashIndex;
47
- if (slashIndex != -1 && colonIndex != -1) {
48
- splitIndex = Math.min(slashIndex, colonIndex) + 1;
49
- }
50
- else if (slashIndex == -1 && colonIndex == -1) {
51
- splitIndex = resourceString.length + 1;
52
- }
53
- else if (colonIndex == -1) {
54
- splitIndex = slashIndex + 1;
55
- }
56
- else if (slashIndex == -1) {
57
- splitIndex = colonIndex + 1;
58
- }
59
- else {
60
- throw new Error(`Unable to split resource ${resourceString}`);
61
- }
62
- return [resourceString.slice(0, splitIndex - 1), resourceString.slice(splitIndex)];
63
- }
64
- //# sourceMappingURL=arn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.js","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAYlF;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;I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