Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol)!: Improve deprecation message on enum-like field usage #2855

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {
blaine-arcjet marked this conversation as resolved.
Show resolved Hide resolved
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
Loading