1import * as Cloudflare from "@/Cloudflare";
2import * as Provider from "@/Provider";
3import * as Test from "@/Test/Alchemy";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7
8const { test } = Test.make({ providers: Cloudflare.providers() });
9
10const logLevel = Effect.provideService(
11 MinimumLogLevel,
12 process.env.DEBUG ? "Debug" : "Info",
13);
14
15// DLP is a paid Zero Trust add-on. Writes (create entry/profile) surface the
16// typed `Forbidden` error on unentitled accounts (see Dlp.test.ts). The
17// account-scoped list endpoint (GET /accounts/{id}/dlp/entries) is read-only
18// and returns an empty collection on the standard testing account, so the
19// read-only `list()` assertion runs ungated. The deploy+presence assertion is
20// gated behind an entitled account supplied via CLOUDFLARE_TEST_DLP.
21const entitled = !!process.env.CLOUDFLARE_TEST_DLP;
22
23// Read-only: `list()` enumerates every custom DLP entry in the account,
24// exhaustively paginated, hydrated into the exact `read` Attributes shape.
25// On an unentitled account this is the empty array (well-typed []); the
26// assertion proves the op is callable and returns the correct shape.
27test.provider(
28 "list returns the account's custom DLP entries",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const provider = yield* Provider.findProvider(Cloudflare.Dlp.Entry);
34 const all = yield* provider.list();
35
36 expect(Array.isArray(all)).toBe(true);
37 for (const entry of all) {
38 expect(typeof entry.entryId).toBe("string");
39 expect(typeof entry.accountId).toBe("string");
40 expect(typeof entry.name).toBe("string");
41 expect(typeof entry.enabled).toBe("boolean");
42 expect(typeof entry.pattern.regex).toBe("string");
43 }
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 {
48 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
49 timeout: 90_000,
50 },
51);
52
53// Entitled-only: deploy a profile + standalone entry and assert `list()`
54// surfaces the deployed entry by id.
55test.provider.skipIf(!entitled)(
56 "list enumerates the deployed DLP entry",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const deployed = yield* stack.deploy(
62 Effect.gen(function* () {
63 const profile = yield* Cloudflare.Dlp.Profile("EmployeeIds", {
64 name: "alchemy-test-dlp-entry-list-profile",
65 allowedMatchCount: 0,
66 entries: [
67 {
68 name: "employee-id",
69 enabled: true,
70 pattern: { regex: "EMP-[0-9]{6}" },
71 },
72 ],
73 });
74 const entry = yield* Cloudflare.Dlp.Entry("CardNumber", {
75 name: "alchemy-test-dlp-entry-list",
76 pattern: { regex: "[0-9]{13,16}", validation: "luhn" },
77 profileId: profile.profileId,
78 });
79 return { entry };
80 }),
81 );
82
83 const provider = yield* Provider.findProvider(Cloudflare.Dlp.Entry);
84 const all = yield* provider.list();
85
86 expect(all.some((e) => e.entryId === deployed.entry.entryId)).toBe(true);
87
88 yield* stack.destroy();
89 }).pipe(logLevel),
90 {
91 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
92 timeout: 120_000,
93 },
94);