import type * as WAFV2 from "@distilled.cloud/aws/wafv2";
import * as wafv2 from "@distilled.cloud/aws/wafv2";
import { Unowned } from "alchemy/AdoptPolicy";
import { deepEqual, isResolved } from "alchemy/Diff";
import { createPhysicalName } from "alchemy/PhysicalName";
import * as Provider from "alchemy/Provider";
import { Resource } from "alchemy/Resource";
import { createInternalTags, createTagsList, hasAlchemyTags } from "alchemy/Tags";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import type { Providers } from "../Providers.ts";
import {
fetchWafTags,
normalizeWafRules,
retryAssociatedItem,
retryOptimisticLock,
retryUnavailableEntity,
syncWafTags,
type WafScope,
withWafScope,
} from "./internal.ts";
export class WAFv2RuleGroupUnexpectedResponse extends Data.TaggedError(
"WAFv2RuleGroupUnexpectedResponse",
)<{
readonly message: string;
readonly cause?: unknown;
}> {}
export interface RuleGroupProps {
/**
* Name of the rule group. Must match `^[\w\-]+
.repos/alchemy-effect/packages/aws/src/WAFv2/RuleGroup.ts at main · sailfork/t3code-github · Sailfork
and be 1-128 characters.
* Changing the name replaces the rule group.
* @default a physical name derived from the app, stage and logical ID
*/
ruleGroupName?: string;
/**
* Scope of the rule group — `REGIONAL` (ambient region) or `CLOUDFRONT`
* (pinned to `us-east-1`). Must match the scope of the web ACLs that
* reference it. Changing the scope replaces the rule group.
* @default "REGIONAL"
*/
scope?: WafScope;
/**
* Web ACL capacity units (WCU) reserved for this rule group. Immutable —
* changing the capacity replaces the rule group.
*/
capacity: number;
/**
* Rules to evaluate, in `Priority` order. Raw WAFv2 API shapes.
*/
rules?: WAFV2.Rule[];
/**
* CloudWatch metrics and sampled-request settings for the rule group.
* @default sampled requests + metrics enabled, MetricName = the rule group name
*/
visibilityConfig?: WAFV2.VisibilityConfig;
/**
* Description of the rule group.
*/
description?: string;
/**
* Custom response bodies referenced by rule actions in this rule group.
*/
customResponseBodies?: {
[key: string]: WAFV2.CustomResponseBody | undefined;
};
/**
* User-defined tags to apply to the rule group.
*/
tags?: Record<string, string>;
}
export interface RuleGroup extends Resource<
"AWS.WAFv2.RuleGroup",
RuleGroupProps,
{
/**
* Name of the rule group.
*/
ruleGroupName: string;
/**
* WAF-assigned unique ID of the rule group.
*/
ruleGroupId: string;
/**
* ARN of the rule group — reference it from a web ACL rule's
* `RuleGroupReferenceStatement`.
*/
ruleGroupArn: string;
/**
* Scope the rule group was created in.
*/
scope: WafScope;
/**
* Immutable WCU capacity of the rule group.
*/
capacity: number;
},
never,
Providers
> {}
/**
* An AWS WAFv2 rule group — a reusable, capacity-bounded collection of rules
* referenced from web ACLs via `RuleGroupReferenceStatement`.
*
* The `capacity` (web ACL capacity units, WCU) is fixed at creation;
* changing it replaces the rule group.
*
* ### Creating Rule Groups
* **Example:** Rule Group with a Byte-Match Rule
* ```typescript
* const group = yield* AWS.WAFv2.RuleGroup("BlockAdminPaths", {
* capacity: 50,
* rules: [
* {
* Name: "block-admin",
* Priority: 0,
* Statement: {
* ByteMatchStatement: {
* SearchString: new TextEncoder().encode("/admin"),
* FieldToMatch: { UriPath: {} },
* TextTransformations: [{ Priority: 0, Type: "LOWERCASE" }],
* PositionalConstraint: "STARTS_WITH",
* },
* },
* Action: { Block: {} },
* VisibilityConfig: {
* SampledRequestsEnabled: true,
* CloudWatchMetricsEnabled: true,
* MetricName: "block-admin",
* },
* },
* ],
* });
* ```
*
* **Example:** Reference from a Web ACL
* ```typescript
* const acl = yield* AWS.WAFv2.WebACL("Firewall", {
* rules: [
* {
* Name: "custom-rules",
* Priority: 0,
* Statement: {
* RuleGroupReferenceStatement: { ARN: group.ruleGroupArn },
* },
* OverrideAction: { None: {} },
* VisibilityConfig: {
* SampledRequestsEnabled: true,
* CloudWatchMetricsEnabled: true,
* MetricName: "custom-rules",
* },
* },
* ],
* });
* ```
*
* @resource
*/
export const RuleGroup = Resource<RuleGroup>("AWS.WAFv2.RuleGroup");
const defaultScope: WafScope = "REGIONAL";
const defaultVisibilityConfig = (name: string): WAFV2.VisibilityConfig => ({
SampledRequestsEnabled: true,
CloudWatchMetricsEnabled: true,
MetricName: name,
});
const toAttrs = (group: WAFV2.RuleGroup, scope: WafScope) => ({
ruleGroupName: group.Name,
ruleGroupId: group.Id,
ruleGroupArn: group.ARN,
scope,
capacity: group.Capacity,
});
export const RuleGroupProvider = () =>
Provider.effect(
RuleGroup,
Effect.gen(function* () {
const createName = Effect.fn(function* (id: string, props: Partial<RuleGroupProps>) {
return props.ruleGroupName ?? (yield* createPhysicalName({ id, maxLength: 128 }));
});
const findRuleGroup = Effect.fn(function* (
scope: WafScope,
name: string,
cachedId: string | undefined,
) {
if (cachedId !== undefined) {
const byId = yield* withWafScope(
scope,
wafv2
.getRuleGroup({ Name: name, Scope: scope, Id: cachedId })
.pipe(Effect.catchTag("WAFNonexistentItemException", () => Effect.undefined)),
);
if (byId?.RuleGroup) {
return byId;
}
}
let marker: string | undefined;
for (let page = 0; page < 20; page++) {
const listed = yield* withWafScope(
scope,
wafv2.listRuleGroups({
Scope: scope,
NextMarker: marker,
Limit: 100,
}),
);
const summary = listed.RuleGroups?.find((s) => s.Name === name);
if (summary?.Id !== undefined) {
return yield* withWafScope(
scope,
wafv2
.getRuleGroup({ Name: name, Scope: scope, Id: summary.Id })
.pipe(Effect.catchTag("WAFNonexistentItemException", () => Effect.undefined)),
);
}
if (!listed.NextMarker || (listed.RuleGroups?.length ?? 0) === 0) {
break;
}
marker = listed.NextMarker;
}
return undefined;
});
const listScope = Effect.fn(function* (scope: WafScope) {
const rows: ReturnType<typeof toAttrs>[] = [];
let marker: string | undefined;
for (let page = 0; page < 50; page++) {
const listed = yield* withWafScope(
scope,
wafv2.listRuleGroups({
Scope: scope,
NextMarker: marker,
Limit: 100,
}),
);
const summaries = listed.RuleGroups ?? [];
const details = yield* Effect.forEach(
summaries,
(summary) =>
summary.Name !== undefined && summary.Id !== undefined
? withWafScope(
scope,
wafv2
.getRuleGroup({
Name: summary.Name,
Scope: scope,
Id: summary.Id,
})
.pipe(Effect.catchTag("WAFNonexistentItemException", () => Effect.undefined)),
)
: Effect.undefined,
{ concurrency: 5 },
);
for (const detail of details) {
if (detail?.RuleGroup) {
rows.push(toAttrs(detail.RuleGroup, scope));
}
}
if (!listed.NextMarker || summaries.length === 0) {
break;
}
marker = listed.NextMarker;
}
return rows;
});
return {
stables: ["ruleGroupName", "ruleGroupId", "ruleGroupArn", "scope", "capacity"],
list: () =>
Effect.gen(function* () {
const regional = yield* listScope("REGIONAL");
const cloudfront = yield* listScope("CLOUDFRONT");
return [...regional, ...cloudfront];
}),
diff: Effect.fn(function* ({ id, news, olds }) {
if (!isResolved(news)) return undefined;
const oldName = yield* createName(id, olds ?? {});
const newName = yield* createName(id, news);
if (
oldName !== newName ||
(olds?.scope ?? defaultScope) !== (news.scope ?? defaultScope) ||
olds?.capacity !== news.capacity
) {
return { action: "replace" } as const;
}
}),
read: Effect.fn(function* ({ id, olds, output }) {
const scope = output?.scope ?? olds?.scope ?? defaultScope;
const name = output?.ruleGroupName ?? (yield* createName(id, olds ?? {}));
const found = yield* findRuleGroup(scope, name, output?.ruleGroupId);
if (!found?.RuleGroup) {
return undefined;
}
const attrs = toAttrs(found.RuleGroup, scope);
const tags = yield* fetchWafTags(scope, found.RuleGroup.ARN);
return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs);
}),
reconcile: Effect.fn(function* ({ id, news, output, session }) {
const scope = news.scope ?? defaultScope;
const name = output?.ruleGroupName ?? (yield* createName(id, news));
const internalTags = yield* createInternalTags(id);
const desiredTags = { ...news.tags, ...internalTags };
const desiredVisibility = news.visibilityConfig ?? defaultVisibilityConfig(name);
// props survive engine serialization as plain JSON — restore
// ByteMatchStatement SearchString blobs to Uint8Array
const desiredRules = normalizeWafRules(news.rules);
// 1. Observe.
let observed = yield* findRuleGroup(scope, name, output?.ruleGroupId);
// 2. Ensure — tolerate a duplicate-create race and re-read.
if (!observed?.RuleGroup) {
yield* retryUnavailableEntity(
withWafScope(
scope,
wafv2
.createRuleGroup({
Name: name,
Scope: scope,
Capacity: news.capacity,
Rules: desiredRules,
VisibilityConfig: desiredVisibility,
Description: news.description,
CustomResponseBodies: news.customResponseBodies,
Tags: createTagsList(desiredTags),
})
.pipe(Effect.catchTag("WAFDuplicateItemException", () => Effect.undefined)),
),
);
observed = yield* findRuleGroup(scope, name, undefined);
}
if (!observed?.RuleGroup) {
return yield* new WAFv2RuleGroupUnexpectedResponse({
message: `Failed to observe RuleGroup '${name}' after create`,
});
}
const group = observed.RuleGroup;
yield* session.note(group.ARN);
// 3. Sync rules, visibility and description against OBSERVED state.
const observedAspects: Record<string, unknown> = {
Rules: group.Rules ?? [],
VisibilityConfig: group.VisibilityConfig,
Description: group.Description,
};
const desiredAspects: Record<string, unknown> = {
Rules: desiredRules,
VisibilityConfig: desiredVisibility,
Description: news.description,
};
if (news.customResponseBodies !== undefined) {
observedAspects.CustomResponseBodies = group.CustomResponseBodies;
desiredAspects.CustomResponseBodies = news.customResponseBodies;
}
if (!deepEqual(observedAspects, desiredAspects, { stripNullish: true })) {
yield* retryOptimisticLock(
Effect.gen(function* () {
const fresh = yield* findRuleGroup(scope, name, group.Id);
if (!fresh?.RuleGroup || fresh.LockToken === undefined) {
return;
}
yield* retryUnavailableEntity(
withWafScope(
scope,
wafv2.updateRuleGroup({
Name: name,
Scope: scope,
Id: fresh.RuleGroup.Id,
Rules: desiredRules,
VisibilityConfig: desiredVisibility,
Description: news.description,
CustomResponseBodies: news.customResponseBodies,
LockToken: fresh.LockToken,
}),
),
);
}),
);
}
// 3b. Sync tags against OBSERVED cloud tags.
yield* syncWafTags(scope, group.ARN, desiredTags);
// 4. Return fresh attributes.
return toAttrs(group, scope);
}),
delete: Effect.fn(function* ({ output }) {
const scope = output.scope;
// A rule group still referenced by a web ACL (deletion propagation)
// surfaces WAFAssociatedItemException — retry through it.
yield* Effect.gen(function* () {
const found = yield* withWafScope(
scope,
wafv2
.getRuleGroup({
Name: output.ruleGroupName,
Scope: scope,
Id: output.ruleGroupId,
})
.pipe(Effect.catchTag("WAFNonexistentItemException", () => Effect.undefined)),
);
if (!found?.RuleGroup || found.LockToken === undefined) {
return;
}
yield* withWafScope(
scope,
wafv2
.deleteRuleGroup({
Name: output.ruleGroupName,
Scope: scope,
Id: output.ruleGroupId,
LockToken: found.LockToken,
})
.pipe(Effect.catchTag("WAFNonexistentItemException", () => Effect.void)),
);
}).pipe(retryOptimisticLock, retryAssociatedItem);
}),
};
}),
);
.repos/alchemy-effect/packages/aws/src/WAFv2/RuleGroup.ts at main · sailfork/t3code-github · Sailfork
and be 1-128 characters.\n * Changing the name replaces the rule group.\n * @default a physical name derived from the app, stage and logical ID\n */\n ruleGroupName?: string;\n /**\n * Scope of the rule group — `REGIONAL` (ambient region) or `CLOUDFRONT`\n * (pinned to `us-east-1`). Must match the scope of the web ACLs that\n * reference it. Changing the scope replaces the rule group.\n * @default \"REGIONAL\"\n */\n scope?: WafScope;\n /**\n * Web ACL capacity units (WCU) reserved for this rule group. Immutable —\n * changing the capacity replaces the rule group.\n */\n capacity: number;\n /**\n * Rules to evaluate, in `Priority` order. Raw WAFv2 API shapes.\n */\n rules?: WAFV2.Rule[];\n /**\n * CloudWatch metrics and sampled-request settings for the rule group.\n * @default sampled requests + metrics enabled, MetricName = the rule group name\n */\n visibilityConfig?: WAFV2.VisibilityConfig;\n /**\n * Description of the rule group.\n */\n description?: string;\n /**\n * Custom response bodies referenced by rule actions in this rule group.\n */\n customResponseBodies?: {\n [key: string]: WAFV2.CustomResponseBody | undefined;\n };\n /**\n * User-defined tags to apply to the rule group.\n */\n tags?: Record\u003cstring, string>;\n}\n\nexport interface RuleGroup extends Resource\u003c\n \"AWS.WAFv2.RuleGroup\",\n RuleGroupProps,\n {\n /**\n * Name of the rule group.\n */\n ruleGroupName: string;\n /**\n * WAF-assigned unique ID of the rule group.\n */\n ruleGroupId: string;\n /**\n * ARN of the rule group — reference it from a web ACL rule's\n * `RuleGroupReferenceStatement`.\n */\n ruleGroupArn: string;\n /**\n * Scope the rule group was created in.\n */\n scope: WafScope;\n /**\n * Immutable WCU capacity of the rule group.\n */\n capacity: number;\n },\n never,\n Providers\n> {}\n\n/**\n * An AWS WAFv2 rule group — a reusable, capacity-bounded collection of rules\n * referenced from web ACLs via `RuleGroupReferenceStatement`.\n *\n * The `capacity` (web ACL capacity units, WCU) is fixed at creation;\n * changing it replaces the rule group.\n *\n * ### Creating Rule Groups\n * **Example:** Rule Group with a Byte-Match Rule\n * ```typescript\n * const group = yield* AWS.WAFv2.RuleGroup(\"BlockAdminPaths\", {\n * capacity: 50,\n * rules: [\n * {\n * Name: \"block-admin\",\n * Priority: 0,\n * Statement: {\n * ByteMatchStatement: {\n * SearchString: new TextEncoder().encode(\"/admin\"),\n * FieldToMatch: { UriPath: {} },\n * TextTransformations: [{ Priority: 0, Type: \"LOWERCASE\" }],\n * PositionalConstraint: \"STARTS_WITH\",\n * },\n * },\n * Action: { Block: {} },\n * VisibilityConfig: {\n * SampledRequestsEnabled: true,\n * CloudWatchMetricsEnabled: true,\n * MetricName: \"block-admin\",\n * },\n * },\n * ],\n * });\n * ```\n *\n * **Example:** Reference from a Web ACL\n * ```typescript\n * const acl = yield* AWS.WAFv2.WebACL(\"Firewall\", {\n * rules: [\n * {\n * Name: \"custom-rules\",\n * Priority: 0,\n * Statement: {\n * RuleGroupReferenceStatement: { ARN: group.ruleGroupArn },\n * },\n * OverrideAction: { None: {} },\n * VisibilityConfig: {\n * SampledRequestsEnabled: true,\n * CloudWatchMetricsEnabled: true,\n * MetricName: \"custom-rules\",\n * },\n * },\n * ],\n * });\n * ```\n *\n * @resource\n */\nexport const RuleGroup = Resource\u003cRuleGroup>(\"AWS.WAFv2.RuleGroup\");\n\nconst defaultScope: WafScope = \"REGIONAL\";\n\nconst defaultVisibilityConfig = (name: string): WAFV2.VisibilityConfig => ({\n SampledRequestsEnabled: true,\n CloudWatchMetricsEnabled: true,\n MetricName: name,\n});\n\nconst toAttrs = (group: WAFV2.RuleGroup, scope: WafScope) => ({\n ruleGroupName: group.Name,\n ruleGroupId: group.Id,\n ruleGroupArn: group.ARN,\n scope,\n capacity: group.Capacity,\n});\n\nexport const RuleGroupProvider = () =>\n Provider.effect(\n RuleGroup,\n Effect.gen(function* () {\n const createName = Effect.fn(function* (id: string, props: Partial\u003cRuleGroupProps>) {\n return props.ruleGroupName ?? (yield* createPhysicalName({ id, maxLength: 128 }));\n });\n\n const findRuleGroup = Effect.fn(function* (\n scope: WafScope,\n name: string,\n cachedId: string | undefined,\n ) {\n if (cachedId !== undefined) {\n const byId = yield* withWafScope(\n scope,\n wafv2\n .getRuleGroup({ Name: name, Scope: scope, Id: cachedId })\n .pipe(Effect.catchTag(\"WAFNonexistentItemException\", () => Effect.undefined)),\n );\n if (byId?.RuleGroup) {\n return byId;\n }\n }\n let marker: string | undefined;\n for (let page = 0; page \u003c 20; page++) {\n const listed = yield* withWafScope(\n scope,\n wafv2.listRuleGroups({\n Scope: scope,\n NextMarker: marker,\n Limit: 100,\n }),\n );\n const summary = listed.RuleGroups?.find((s) => s.Name === name);\n if (summary?.Id !== undefined) {\n return yield* withWafScope(\n scope,\n wafv2\n .getRuleGroup({ Name: name, Scope: scope, Id: summary.Id })\n .pipe(Effect.catchTag(\"WAFNonexistentItemException\", () => Effect.undefined)),\n );\n }\n if (!listed.NextMarker || (listed.RuleGroups?.length ?? 0) === 0) {\n break;\n }\n marker = listed.NextMarker;\n }\n return undefined;\n });\n\n const listScope = Effect.fn(function* (scope: WafScope) {\n const rows: ReturnType\u003ctypeof toAttrs>[] = [];\n let marker: string | undefined;\n for (let page = 0; page \u003c 50; page++) {\n const listed = yield* withWafScope(\n scope,\n wafv2.listRuleGroups({\n Scope: scope,\n NextMarker: marker,\n Limit: 100,\n }),\n );\n const summaries = listed.RuleGroups ?? [];\n const details = yield* Effect.forEach(\n summaries,\n (summary) =>\n summary.Name !== undefined && summary.Id !== undefined\n ? withWafScope(\n scope,\n wafv2\n .getRuleGroup({\n Name: summary.Name,\n Scope: scope,\n Id: summary.Id,\n })\n .pipe(Effect.catchTag(\"WAFNonexistentItemException\", () => Effect.undefined)),\n )\n : Effect.undefined,\n { concurrency: 5 },\n );\n for (const detail of details) {\n if (detail?.RuleGroup) {\n rows.push(toAttrs(detail.RuleGroup, scope));\n }\n }\n if (!listed.NextMarker || summaries.length === 0) {\n break;\n }\n marker = listed.NextMarker;\n }\n return rows;\n });\n\n return {\n stables: [\"ruleGroupName\", \"ruleGroupId\", \"ruleGroupArn\", \"scope\", \"capacity\"],\n\n list: () =>\n Effect.gen(function* () {\n const regional = yield* listScope(\"REGIONAL\");\n const cloudfront = yield* listScope(\"CLOUDFRONT\");\n return [...regional, ...cloudfront];\n }),\n\n diff: Effect.fn(function* ({ id, news, olds }) {\n if (!isResolved(news)) return undefined;\n const oldName = yield* createName(id, olds ?? {});\n const newName = yield* createName(id, news);\n if (\n oldName !== newName ||\n (olds?.scope ?? defaultScope) !== (news.scope ?? defaultScope) ||\n olds?.capacity !== news.capacity\n ) {\n return { action: \"replace\" } as const;\n }\n }),\n\n read: Effect.fn(function* ({ id, olds, output }) {\n const scope = output?.scope ?? olds?.scope ?? defaultScope;\n const name = output?.ruleGroupName ?? (yield* createName(id, olds ?? {}));\n const found = yield* findRuleGroup(scope, name, output?.ruleGroupId);\n if (!found?.RuleGroup) {\n return undefined;\n }\n const attrs = toAttrs(found.RuleGroup, scope);\n const tags = yield* fetchWafTags(scope, found.RuleGroup.ARN);\n return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs);\n }),\n\n reconcile: Effect.fn(function* ({ id, news, output, session }) {\n const scope = news.scope ?? defaultScope;\n const name = output?.ruleGroupName ?? (yield* createName(id, news));\n const internalTags = yield* createInternalTags(id);\n const desiredTags = { ...news.tags, ...internalTags };\n const desiredVisibility = news.visibilityConfig ?? defaultVisibilityConfig(name);\n // props survive engine serialization as plain JSON — restore\n // ByteMatchStatement SearchString blobs to Uint8Array\n const desiredRules = normalizeWafRules(news.rules);\n\n // 1. Observe.\n let observed = yield* findRuleGroup(scope, name, output?.ruleGroupId);\n\n // 2. Ensure — tolerate a duplicate-create race and re-read.\n if (!observed?.RuleGroup) {\n yield* retryUnavailableEntity(\n withWafScope(\n scope,\n wafv2\n .createRuleGroup({\n Name: name,\n Scope: scope,\n Capacity: news.capacity,\n Rules: desiredRules,\n VisibilityConfig: desiredVisibility,\n Description: news.description,\n CustomResponseBodies: news.customResponseBodies,\n Tags: createTagsList(desiredTags),\n })\n .pipe(Effect.catchTag(\"WAFDuplicateItemException\", () => Effect.undefined)),\n ),\n );\n observed = yield* findRuleGroup(scope, name, undefined);\n }\n\n if (!observed?.RuleGroup) {\n return yield* new WAFv2RuleGroupUnexpectedResponse({\n message: `Failed to observe RuleGroup '${name}' after create`,\n });\n }\n\n const group = observed.RuleGroup;\n yield* session.note(group.ARN);\n\n // 3. Sync rules, visibility and description against OBSERVED state.\n const observedAspects: Record\u003cstring, unknown> = {\n Rules: group.Rules ?? [],\n VisibilityConfig: group.VisibilityConfig,\n Description: group.Description,\n };\n const desiredAspects: Record\u003cstring, unknown> = {\n Rules: desiredRules,\n VisibilityConfig: desiredVisibility,\n Description: news.description,\n };\n if (news.customResponseBodies !== undefined) {\n observedAspects.CustomResponseBodies = group.CustomResponseBodies;\n desiredAspects.CustomResponseBodies = news.customResponseBodies;\n }\n if (!deepEqual(observedAspects, desiredAspects, { stripNullish: true })) {\n yield* retryOptimisticLock(\n Effect.gen(function* () {\n const fresh = yield* findRuleGroup(scope, name, group.Id);\n if (!fresh?.RuleGroup || fresh.LockToken === undefined) {\n return;\n }\n yield* retryUnavailableEntity(\n withWafScope(\n scope,\n wafv2.updateRuleGroup({\n Name: name,\n Scope: scope,\n Id: fresh.RuleGroup.Id,\n Rules: desiredRules,\n VisibilityConfig: desiredVisibility,\n Description: news.description,\n CustomResponseBodies: news.customResponseBodies,\n LockToken: fresh.LockToken,\n }),\n ),\n );\n }),\n );\n }\n\n // 3b. Sync tags against OBSERVED cloud tags.\n yield* syncWafTags(scope, group.ARN, desiredTags);\n\n // 4. Return fresh attributes.\n return toAttrs(group, scope);\n }),\n\n delete: Effect.fn(function* ({ output }) {\n const scope = output.scope;\n // A rule group still referenced by a web ACL (deletion propagation)\n // surfaces WAFAssociatedItemException — retry through it.\n yield* Effect.gen(function* () {\n const found = yield* withWafScope(\n scope,\n wafv2\n .getRuleGroup({\n Name: output.ruleGroupName,\n Scope: scope,\n Id: output.ruleGroupId,\n })\n .pipe(Effect.catchTag(\"WAFNonexistentItemException\", () => Effect.undefined)),\n );\n if (!found?.RuleGroup || found.LockToken === undefined) {\n return;\n }\n yield* withWafScope(\n scope,\n wafv2\n .deleteRuleGroup({\n Name: output.ruleGroupName,\n Scope: scope,\n Id: output.ruleGroupId,\n LockToken: found.LockToken,\n })\n .pipe(Effect.catchTag(\"WAFNonexistentItemException\", () => Effect.void)),\n );\n }).pipe(retryOptimisticLock, retryAssociatedItem);\n }),\n };\n }),\n );\n","preview":null,"history":null,"version":"d6556ab814c9d020f62fac1c3d93a0c8482e2be6"},"/_session?shell=1":null}