Skip to content

Commit

Permalink
fix(protocol)!: Improve deprecation message on enum-like field usage (#…
Browse files Browse the repository at this point in the history
…2855)

While reviewing #2715 locally, I noticed that `/** @deprecated */` wasn't being marked in my editor. This is because `/** */` is just a block comment and not a doc comment.

Doc comments need to be in the form as I've changed this PR. Additionally, deprecating the top-level export didn't seem to mark anything in the editor, so each field needed to be marked as deprecated. Furthermore, overriding the type as `ArcjetEnum<>` seemed to lose the doc comments.

I also removed the exports locally and made everything compile once they are removed. They still exist for now but I want the removal to be seamless.
  • Loading branch information
blaine-arcjet authored Jan 14, 2025
1 parent 8053716 commit 6512258
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 95 deletions.
6 changes: 3 additions & 3 deletions arcjet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ArcjetBotRule,
ArcjetRule,
ArcjetLocalRule,
ArcjetMode,
ArcjetRequestDetails,
ArcjetTokenBucketRateLimitRule,
ArcjetFixedWindowRateLimitRule,
Expand All @@ -14,16 +15,15 @@ import type {
ArcjetIdentifiedEntity,
ArcjetWellKnownBot,
ArcjetBotCategory,
ArcjetEmailType,
ArcjetSensitiveInfoType,
} from "@arcjet/protocol";
import {
ArcjetBotReason,
ArcjetEmailReason,
ArcjetEmailType,
ArcjetErrorReason,
ArcjetMode,
ArcjetReason,
ArcjetRuleResult,
ArcjetSensitiveInfoType,
ArcjetSensitiveInfoReason,
ArcjetDecision,
ArcjetDenyDecision,
Expand Down
89 changes: 31 additions & 58 deletions arcjet/test/arcjet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { expect } from "expect";

import type { ArcjetRule, ArcjetLocalRule, Primitive, Arcjet } from "../index";
import arcjet, {
ArcjetMode,
detectBot,
validateEmail,
protectSignup,
ArcjetEmailType,
ArcjetAllowDecision,
ArcjetDenyDecision,
ArcjetErrorDecision,
Expand Down Expand Up @@ -481,10 +479,6 @@ describe("Primitive > detectBot", () => {
});

test("denies curl", async () => {
const options = {
mode: ArcjetMode.LIVE,
allow: [],
};
const context = {
key: "test-key",
fingerprint: "test-fingerprint",
Expand All @@ -507,7 +501,10 @@ describe("Primitive > detectBot", () => {
},
};

const [rule] = detectBot(options);
const [rule] = detectBot({
mode: "LIVE",
allow: [],
});
expect(rule.type).toEqual("BOT");
assertIsLocalRule(rule);
const result = await rule.protect(context, details);
Expand Down Expand Up @@ -560,7 +557,7 @@ describe("Primitive > detectBot", () => {
};

const [rule] = detectBot({
mode: ArcjetMode.LIVE,
mode: "LIVE",
deny: ["CURL"],
});
expect(rule.type).toEqual("BOT");
Expand Down Expand Up @@ -613,7 +610,7 @@ describe("Primitive > detectBot", () => {
};

const [rule] = detectBot({
mode: ArcjetMode.LIVE,
mode: "LIVE",
allow: ["CURL"],
});
expect(rule.type).toEqual("BOT");
Expand Down Expand Up @@ -1302,17 +1299,9 @@ describe("Primitive > validateEmail", () => {
});

test("allows specifying EmailTypes to deny", async () => {
const options = {
deny: [
ArcjetEmailType.DISPOSABLE,
ArcjetEmailType.FREE,
ArcjetEmailType.NO_GRAVATAR,
ArcjetEmailType.NO_MX_RECORDS,
ArcjetEmailType.INVALID,
],
};

const [rule] = validateEmail(options);
const [rule] = validateEmail({
deny: ["DISPOSABLE", "FREE", "NO_GRAVATAR", "NO_MX_RECORDS", "INVALID"],
});
expect(rule.type).toEqual("EMAIL");
expect(rule).toHaveProperty("deny", [
"DISPOSABLE",
Expand All @@ -1324,17 +1313,9 @@ describe("Primitive > validateEmail", () => {
});

test("allows specifying EmailTypes to block and maps these to deny", async () => {
const options = {
block: [
ArcjetEmailType.DISPOSABLE,
ArcjetEmailType.FREE,
ArcjetEmailType.NO_GRAVATAR,
ArcjetEmailType.NO_MX_RECORDS,
ArcjetEmailType.INVALID,
],
};

const [rule] = validateEmail(options);
const [rule] = validateEmail({
block: ["DISPOSABLE", "FREE", "NO_GRAVATAR", "NO_MX_RECORDS", "INVALID"],
});
expect(rule.type).toEqual("EMAIL");
expect(rule).toHaveProperty("deny", [
"DISPOSABLE",
Expand All @@ -1346,17 +1327,9 @@ describe("Primitive > validateEmail", () => {
});

test("allows specifying EmailTypes to allow", async () => {
const options = {
allow: [
ArcjetEmailType.DISPOSABLE,
ArcjetEmailType.FREE,
ArcjetEmailType.NO_GRAVATAR,
ArcjetEmailType.NO_MX_RECORDS,
ArcjetEmailType.INVALID,
],
};

const [rule] = validateEmail(options);
const [rule] = validateEmail({
allow: ["DISPOSABLE", "FREE", "NO_GRAVATAR", "NO_MX_RECORDS", "INVALID"],
});
expect(rule.type).toEqual("EMAIL");
expect(rule).toHaveProperty("allow", [
"DISPOSABLE",
Expand Down Expand Up @@ -2404,18 +2377,18 @@ describe("Products > protectSignup", () => {
test("allows configuration of rateLimit, bot, and email", () => {
const rules = protectSignup({
rateLimit: {
mode: ArcjetMode.DRY_RUN,
mode: "DRY_RUN",
characteristics: ["ip.src"],
interval: 60 /* minutes */ * 60 /* seconds */,
max: 1,
},
bots: {
mode: ArcjetMode.DRY_RUN,
mode: "DRY_RUN",
allow: [],
},
email: {
allow: [],
mode: ArcjetMode.LIVE,
mode: "LIVE",
},
});
expect(rules.length).toEqual(3);
Expand All @@ -2425,7 +2398,7 @@ describe("Products > protectSignup", () => {
describe("SDK", () => {
function testRuleLocalAllowed() {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_ALLOWED",
priority: 1,
validate: mock.fn(),
Expand All @@ -2438,11 +2411,11 @@ describe("SDK", () => {
reason: new ArcjetTestReason(),
}),
),
};
} as const;
}
function testRuleLocalDenied() {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_DENIED",
priority: 1,
validate: mock.fn(),
Expand All @@ -2455,16 +2428,16 @@ describe("SDK", () => {
reason: new ArcjetTestReason(),
}),
),
};
} as const;
}
function testRuleLocalIncorrect() {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_INCORRECT",
priority: 1,
validate: mock.fn(),
protect: mock.fn(async () => undefined),
};
} as const;
}

function testRuleRemote(): ArcjetRule {
Expand All @@ -2485,27 +2458,27 @@ describe("SDK", () => {

function testRuleInvalidType(): ArcjetRule {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_INVALID_TYPE",
priority: 1,
};
}

function testRuleLocalThrow() {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_THROW",
priority: 1,
validate: mock.fn(),
protect: mock.fn(async () => {
throw new Error("Local rule protect failed");
}),
};
} as const;
}

function testRuleLocalDryRun() {
return {
mode: ArcjetMode.DRY_RUN,
mode: "DRY_RUN",
type: "TEST_RULE_LOCAL_DRY_RUN",
priority: 1,
validate: mock.fn(),
Expand All @@ -2517,7 +2490,7 @@ describe("SDK", () => {
reason: new ArcjetTestReason(),
});
}),
};
} as const;
}

function testRuleProps(): Primitive<{ abc: number }> {
Expand Down Expand Up @@ -3688,7 +3661,7 @@ describe("SDK", () => {

function testRuleLocalThrowString(): ArcjetLocalRule {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_THROW_STRING",
priority: 1,
validate: mock.fn(),
Expand Down Expand Up @@ -3745,7 +3718,7 @@ describe("SDK", () => {

function testRuleLocalThrowNull(): ArcjetLocalRule {
return {
mode: ArcjetMode.LIVE,
mode: "LIVE",
type: "TEST_RULE_LOCAL_THROW_NULL",
priority: 1,
validate: mock.fn(),
Expand Down
3 changes: 2 additions & 1 deletion protocol/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import type {
ArcjetContext,
ArcjetRequestDetails,
ArcjetRule,
ArcjetStack,
} from "./index.js";
import { ArcjetDecision, ArcjetStack } from "./index.js";
import { ArcjetDecision } from "./index.js";
import { DecideService } from "./proto/decide/v1alpha1/decide_connect.js";
import {
DecideRequest,
Expand Down
10 changes: 5 additions & 5 deletions protocol/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import type {
ArcjetRule,
ArcjetRateLimitRule,
ArcjetBotRule,
ArcjetConclusion,
ArcjetEmailRule,
ArcjetEmailType,
ArcjetMode,
ArcjetRuleState,
ArcjetStack,
ArcjetTokenBucketRateLimitRule,
ArcjetFixedWindowRateLimitRule,
ArcjetSlidingWindowRateLimitRule,
Expand All @@ -22,13 +27,8 @@ import {
ArcjetRateLimitReason,
ArcjetRuleResult,
ArcjetShieldReason,
ArcjetConclusion,
ArcjetDecision,
ArcjetEmailType,
ArcjetMode,
ArcjetReason,
ArcjetRuleState,
ArcjetStack,
ArcjetIpDetails,
ArcjetSensitiveInfoReason,
} from "./index.js";
Expand Down
Loading

0 comments on commit 6512258

Please sign in to comment.