Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcjet/protocol

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcjet/protocol - npm Package Compare versions

Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5

10

convert.d.ts
import { ArcjetRuleResult, ArcjetBotType, ArcjetConclusion, ArcjetDecision, ArcjetEmailType, ArcjetMode, ArcjetReason, ArcjetRuleState, ArcjetStack, ArcjetRule } from "./index";
import { BotType, Conclusion, Decision, EmailType, Mode, Reason, Rule, RuleResult, RuleState, SDKStack } from "./gen/es/decide/v1alpha1/decide_pb.js";
export declare function ArcjetModeToProtocol(value: ArcjetMode): Mode;
export declare function ArcjetModeToProtocol(mode: ArcjetMode): Mode;
export declare function ArcjetBotTypeToProtocol(botType: ArcjetBotType): BotType;
export declare function ArcjetBotTypeFromProtocol(botType: BotType): ArcjetBotType;
export declare function ArcjetEmailTypeToProtocol(emailType: ArcjetEmailType): EmailType;
export declare function ArcjetEmailTypeFromProtocol(proto: EmailType): ArcjetEmailType;
export declare function ArcjetEmailTypeFromProtocol(emailType: EmailType): ArcjetEmailType;
export declare function ArcjetStackToProtocol(stack: ArcjetStack): SDKStack;
export declare function ArcjetRuleStateToProtocol(ruleState: ArcjetRuleState): RuleState;
export declare function ArcjetRuleStateFromProtocol(proto: RuleState): ArcjetRuleState;
export declare function ArcjetRuleStateToProtocol(stack: ArcjetRuleState): RuleState;
export declare function ArcjetRuleStateFromProtocol(ruleState: RuleState): ArcjetRuleState;
export declare function ArcjetConclusionToProtocol(conclusion: ArcjetConclusion): Conclusion;
export declare function ArcjetConclusionFromProtocol(proto: Conclusion): ArcjetConclusion;
export declare function ArcjetConclusionFromProtocol(conclusion: Conclusion): ArcjetConclusion;
export declare function ArcjetReasonFromProtocol(proto?: Reason): ArcjetReason;

@@ -14,0 +14,0 @@ export declare function ArcjetReasonToProtocol(reason: ArcjetReason): Reason;

@@ -5,4 +5,4 @@ import { Timestamp } from '@bufbuild/protobuf';

function ArcjetModeToProtocol(value) {
switch (value) {
function ArcjetModeToProtocol(mode) {
switch (mode) {
case "LIVE":

@@ -13,3 +13,2 @@ return Mode.LIVE;

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return Mode.UNSPECIFIED;

@@ -31,3 +30,2 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return BotType.UNSPECIFIED;

@@ -51,3 +49,2 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
throw new Error("Invalid BotType");

@@ -69,8 +66,7 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return EmailType.UNSPECIFIED;
}
}
function ArcjetEmailTypeFromProtocol(proto) {
switch (proto) {
function ArcjetEmailTypeFromProtocol(emailType) {
switch (emailType) {
case EmailType.UNSPECIFIED:

@@ -89,3 +85,2 @@ throw new Error("Invalid EmailType");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
throw new Error("Invalid EmailType");

@@ -101,8 +96,7 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return SDKStack.SDK_STACK_UNSPECIFIED;
}
}
function ArcjetRuleStateToProtocol(ruleState) {
switch (ruleState) {
function ArcjetRuleStateToProtocol(stack) {
switch (stack) {
case "RUN":

@@ -117,8 +111,7 @@ return RuleState.RUN;

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return RuleState.UNSPECIFIED;
}
}
function ArcjetRuleStateFromProtocol(proto) {
switch (proto) {
function ArcjetRuleStateFromProtocol(ruleState) {
switch (ruleState) {
case RuleState.UNSPECIFIED:

@@ -135,3 +128,2 @@ throw new Error("Invalid RuleState");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
throw new Error("Invalid RuleState");

@@ -151,8 +143,7 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
return Conclusion.UNSPECIFIED;
}
}
function ArcjetConclusionFromProtocol(proto) {
switch (proto) {
function ArcjetConclusionFromProtocol(conclusion) {
switch (conclusion) {
case Conclusion.UNSPECIFIED:

@@ -169,3 +160,2 @@ throw new Error("Invalid Conclusion");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
throw new Error("Invalid Conclusion");

@@ -178,2 +168,5 @@ }

}
if (typeof proto !== "object" || typeof proto.reason !== "object") {
throw new Error("Invalid Reason");
}
switch (proto.reason.case) {

@@ -221,5 +214,9 @@ case "rateLimit": {

}
default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
case undefined: {
return new ArcjetReason();
}
default: {
proto.reason;
return new ArcjetReason();
}
}

@@ -272,3 +269,5 @@ }

case: "suspicious",
value: new SuspiciousReason({}),
value: new SuspiciousReason({
wafTriggered: reason.wafTriggered,
}),
},

@@ -302,2 +301,3 @@ });

ruleId: ruleResult.ruleId,
ttl: ruleResult.ttl,
state: ArcjetRuleStateToProtocol(ruleResult.state),

@@ -310,2 +310,3 @@ conclusion: ArcjetConclusionToProtocol(ruleResult.conclusion),

return new ArcjetRuleResult({
ttl: proto.ttl,
state: ArcjetRuleStateFromProtocol(proto.state),

@@ -319,2 +320,3 @@ conclusion: ArcjetConclusionFromProtocol(proto.conclusion),

id: decision.id,
ttl: decision.ttl,
conclusion: ArcjetConclusionToProtocol(decision.conclusion),

@@ -329,6 +331,9 @@ reason: ArcjetReasonToProtocol(decision.reason),

reason: new ArcjetErrorReason("Missing Decision"),
ttl: 0,
results: [],
});
}
const results = decision.ruleResults.map(ArcjetRuleResultFromProtocol);
const results = Array.isArray(decision.ruleResults)
? decision.ruleResults.map(ArcjetRuleResultFromProtocol)
: [];
switch (decision.conclusion) {

@@ -338,2 +343,3 @@ case Conclusion.ALLOW:

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -345,2 +351,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -352,2 +359,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -359,2 +367,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: new ArcjetErrorReason(decision.reason),

@@ -366,5 +375,13 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: new ArcjetErrorReason("Invalid Conclusion"),
results,
});
default:
decision.conclusion;
return new ArcjetErrorDecision({
ttl: 0,
reason: new ArcjetErrorReason("Missing Conclusion"),
results: [],
});
}

@@ -398,2 +415,5 @@ }

if (isEmailRule(rule)) {
const block = Array.isArray(rule.block)
? rule.block.map(ArcjetEmailTypeToProtocol)
: [];
return new Rule({

@@ -404,3 +424,3 @@ rule: {

mode: ArcjetModeToProtocol(rule.mode),
block: rule.block.map(ArcjetEmailTypeToProtocol),
block,
requireTopLevelDomain: rule.requireTopLevelDomain,

@@ -413,6 +433,11 @@ allowDomainLiteral: rule.allowDomainLiteral,

if (isBotRule(rule)) {
const add = rule.add.map(([key, botType]) => [
key,
ArcjetBotTypeToProtocol(botType),
]);
const block = Array.isArray(rule.block)
? rule.block.map(ArcjetBotTypeToProtocol)
: [];
const add = Array.isArray(rule.add)
? rule.add.map(([key, botType]) => [
key,
ArcjetBotTypeToProtocol(botType),
])
: [];
return new Rule({

@@ -423,3 +448,3 @@ rule: {

mode: ArcjetModeToProtocol(rule.mode),
block: rule.block.map(ArcjetBotTypeToProtocol),
block,
patterns: {

@@ -426,0 +451,0 @@ add: Object.fromEntries(add),

@@ -46,4 +46,4 @@ import { Timestamp } from "@bufbuild/protobuf";

export function ArcjetModeToProtocol(value: ArcjetMode) {
switch (value) {
export function ArcjetModeToProtocol(mode: ArcjetMode) {
switch (mode) {
case "LIVE":

@@ -54,3 +54,3 @@ return Mode.LIVE;

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = mode;
return Mode.UNSPECIFIED;

@@ -73,3 +73,3 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = botType;
return BotType.UNSPECIFIED;

@@ -94,3 +94,3 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = botType;
throw new Error("Invalid BotType");

@@ -115,3 +115,3 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = emailType;
return EmailType.UNSPECIFIED;

@@ -121,4 +121,6 @@ }

export function ArcjetEmailTypeFromProtocol(proto: EmailType): ArcjetEmailType {
switch (proto) {
export function ArcjetEmailTypeFromProtocol(
emailType: EmailType,
): ArcjetEmailType {
switch (emailType) {
case EmailType.UNSPECIFIED:

@@ -137,3 +139,3 @@ throw new Error("Invalid EmailType");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = emailType;
throw new Error("Invalid EmailType");

@@ -150,3 +152,3 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = stack;
return SDKStack.SDK_STACK_UNSPECIFIED;

@@ -156,6 +158,4 @@ }

export function ArcjetRuleStateToProtocol(
ruleState: ArcjetRuleState,
): RuleState {
switch (ruleState) {
export function ArcjetRuleStateToProtocol(stack: ArcjetRuleState): RuleState {
switch (stack) {
case "RUN":

@@ -170,3 +170,3 @@ return RuleState.RUN;

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = stack;
return RuleState.UNSPECIFIED;

@@ -176,4 +176,6 @@ }

export function ArcjetRuleStateFromProtocol(proto: RuleState): ArcjetRuleState {
switch (proto) {
export function ArcjetRuleStateFromProtocol(
ruleState: RuleState,
): ArcjetRuleState {
switch (ruleState) {
case RuleState.UNSPECIFIED:

@@ -190,3 +192,3 @@ throw new Error("Invalid RuleState");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = ruleState;
throw new Error("Invalid RuleState");

@@ -209,3 +211,3 @@ }

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = conclusion;
return Conclusion.UNSPECIFIED;

@@ -216,5 +218,5 @@ }

export function ArcjetConclusionFromProtocol(
proto: Conclusion,
conclusion: Conclusion,
): ArcjetConclusion {
switch (proto) {
switch (conclusion) {
case Conclusion.UNSPECIFIED:

@@ -231,3 +233,3 @@ throw new Error("Invalid Conclusion");

default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
const _exhaustive: never = conclusion;
throw new Error("Invalid Conclusion");

@@ -242,2 +244,6 @@ }

if (typeof proto !== "object" || typeof proto.reason !== "object") {
throw new Error("Invalid Reason");
}
switch (proto.reason.case) {

@@ -285,5 +291,9 @@ case "rateLimit": {

}
default:
// TODO(#210): TypeScript exhaustiveness check that doesn't mess up coverage stats
case undefined: {
return new ArcjetReason();
}
default: {
const _exhaustive: never = proto.reason;
return new ArcjetReason();
}
}

@@ -340,3 +350,5 @@ }

case: "suspicious",
value: new SuspiciousReason({}),
value: new SuspiciousReason({
wafTriggered: reason.wafTriggered,
}),
},

@@ -376,2 +388,3 @@ });

ruleId: ruleResult.ruleId,
ttl: ruleResult.ttl,
state: ArcjetRuleStateToProtocol(ruleResult.state),

@@ -387,2 +400,3 @@ conclusion: ArcjetConclusionToProtocol(ruleResult.conclusion),

return new ArcjetRuleResult({
ttl: proto.ttl,
state: ArcjetRuleStateFromProtocol(proto.state),

@@ -397,2 +411,3 @@ conclusion: ArcjetConclusionFromProtocol(proto.conclusion),

id: decision.id,
ttl: decision.ttl,
conclusion: ArcjetConclusionToProtocol(decision.conclusion),

@@ -410,2 +425,3 @@ reason: ArcjetReasonToProtocol(decision.reason),

reason: new ArcjetErrorReason("Missing Decision"),
ttl: 0,
results: [],

@@ -415,3 +431,5 @@ });

const results = decision.ruleResults.map(ArcjetRuleResultFromProtocol);
const results = Array.isArray(decision.ruleResults)
? decision.ruleResults.map(ArcjetRuleResultFromProtocol)
: [];

@@ -422,2 +440,3 @@ switch (decision.conclusion) {

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -429,2 +448,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -436,2 +456,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: ArcjetReasonFromProtocol(decision.reason),

@@ -443,2 +464,3 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: new ArcjetErrorReason(decision.reason),

@@ -450,5 +472,13 @@ results,

id: decision.id,
ttl: decision.ttl,
reason: new ArcjetErrorReason("Invalid Conclusion"),
results,
});
default:
const _exhaustive: never = decision.conclusion;
return new ArcjetErrorDecision({
ttl: 0,
reason: new ArcjetErrorReason("Missing Conclusion"),
results: [],
});
}

@@ -495,2 +525,5 @@ }

if (isEmailRule(rule)) {
const block = Array.isArray(rule.block)
? rule.block.map(ArcjetEmailTypeToProtocol)
: [];
return new Rule({

@@ -501,3 +534,3 @@ rule: {

mode: ArcjetModeToProtocol(rule.mode),
block: rule.block.map(ArcjetEmailTypeToProtocol),
block,
requireTopLevelDomain: rule.requireTopLevelDomain,

@@ -511,6 +544,11 @@ allowDomainLiteral: rule.allowDomainLiteral,

if (isBotRule(rule)) {
const add = rule.add.map(([key, botType]) => [
key,
ArcjetBotTypeToProtocol(botType),
]);
const block = Array.isArray(rule.block)
? rule.block.map(ArcjetBotTypeToProtocol)
: [];
const add = Array.isArray(rule.add)
? rule.add.map(([key, botType]) => [
key,
ArcjetBotTypeToProtocol(botType),
])
: [];
return new Rule({

@@ -521,3 +559,3 @@ rule: {

mode: ArcjetModeToProtocol(rule.mode),
block: rule.block.map(ArcjetBotTypeToProtocol),
block,
patterns: {

@@ -524,0 +562,0 @@ add: Object.fromEntries(add),

@@ -876,2 +876,10 @@ // @generated by protoc-gen-es v1.4.2

/**
* The duration in milliseconds this result should be considered valid, also
* known as time-to-live.
*
* @generated from field: int32 ttl = 5;
*/
ttl: number;
constructor(data?: PartialMessage<RuleResult>);

@@ -993,2 +1001,10 @@

/**
* The duration in milliseconds this decision should be considered valid,
* also known as time-to-live.
*
* @generated from field: int32 ttl = 5;
*/
ttl: number;
constructor(data?: PartialMessage<Decision>);

@@ -995,0 +1011,0 @@

@@ -290,2 +290,3 @@ // @generated by protoc-gen-es v1.4.2

{ no: 4, name: "reason", kind: "message", T: Reason },
{ no: 5, name: "ttl", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
],

@@ -326,2 +327,3 @@ );

{ no: 4, name: "rule_results", kind: "message", T: RuleResult, repeated: true },
{ no: 5, name: "ttl", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
],

@@ -328,0 +330,0 @@ );

@@ -85,2 +85,7 @@ type ArcjetEnum<T extends string> = {

ruleId: string;
/**
* The duration in milliseconds this result should be considered valid, also
* known as time-to-live.
*/
ttl: number;
state: ArcjetRuleState;

@@ -90,2 +95,3 @@ conclusion: ArcjetConclusion;

constructor(init: {
ttl: number;
state: ArcjetRuleState;

@@ -108,2 +114,4 @@ conclusion: ArcjetConclusion;

* {@link ArcjetEmailReason}, or {@link ArcjetErrorReason}.
* @property `ttl` - The duration in milliseconds this decision should be
* considered valid, also known as time-to-live.
* @property `results` - Each separate {@link ArcjetRuleResult} can be found here

@@ -114,2 +122,7 @@ * or by logging into the Arcjet dashboard and searching for the decision `id`.

id: string;
/**
* The duration in milliseconds this decision should be considered valid, also
* known as time-to-live.
*/
ttl: number;
results: ArcjetRuleResult[];

@@ -121,2 +134,3 @@ abstract conclusion: ArcjetConclusion;

results: ArcjetRuleResult[];
ttl: number;
});

@@ -134,2 +148,3 @@ isAllowed(): this is ArcjetAllowDecision | ArcjetErrorDecision;

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -144,2 +159,3 @@ });

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -154,2 +170,3 @@ });

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -164,2 +181,3 @@ });

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetErrorReason;

@@ -166,0 +184,0 @@ });

@@ -152,2 +152,7 @@ import { typeid } from 'typeid-js';

ruleId;
/**
* The duration in milliseconds this result should be considered valid, also
* known as time-to-live.
*/
ttl;
state;

@@ -159,2 +164,3 @@ conclusion;

this.ruleId = "";
this.ttl = init.ttl;
this.state = init.state;

@@ -179,2 +185,4 @@ this.conclusion = init.conclusion;

* {@link ArcjetEmailReason}, or {@link ArcjetErrorReason}.
* @property `ttl` - The duration in milliseconds this decision should be
* considered valid, also known as time-to-live.
* @property `results` - Each separate {@link ArcjetRuleResult} can be found here

@@ -185,2 +193,7 @@ * or by logging into the Arcjet dashboard and searching for the decision `id`.

id;
/**
* The duration in milliseconds this decision should be considered valid, also
* known as time-to-live.
*/
ttl;
results;

@@ -195,2 +208,3 @@ constructor(init) {

this.results = init.results;
this.ttl = init.ttl;
}

@@ -197,0 +211,0 @@ isAllowed() {

@@ -220,2 +220,7 @@ import { typeid } from "typeid-js";

ruleId: string;
/**
* The duration in milliseconds this result should be considered valid, also
* known as time-to-live.
*/
ttl: number;
state: ArcjetRuleState;

@@ -226,2 +231,3 @@ conclusion: ArcjetConclusion;

constructor(init: {
ttl: number,
state: ArcjetRuleState;

@@ -234,2 +240,3 @@ conclusion: ArcjetConclusion;

this.ttl = init.ttl;
this.state = init.state;

@@ -256,2 +263,4 @@ this.conclusion = init.conclusion;

* {@link ArcjetEmailReason}, or {@link ArcjetErrorReason}.
* @property `ttl` - The duration in milliseconds this decision should be
* considered valid, also known as time-to-live.
* @property `results` - Each separate {@link ArcjetRuleResult} can be found here

@@ -262,2 +271,7 @@ * or by logging into the Arcjet dashboard and searching for the decision `id`.

id: string;
/**
* The duration in milliseconds this decision should be considered valid, also
* known as time-to-live.
*/
ttl: number;
results: ArcjetRuleResult[];

@@ -268,3 +282,3 @@

constructor(init: { id?: string; results: ArcjetRuleResult[] }) {
constructor(init: { id?: string; results: ArcjetRuleResult[]; ttl: number }) {
if (typeof init.id === "string") {

@@ -277,2 +291,3 @@ this.id = init.id;

this.results = init.results;
this.ttl = init.ttl;
}

@@ -304,2 +319,3 @@

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -320,2 +336,3 @@ }) {

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -335,2 +352,3 @@ }) {

results: ArcjetRuleResult[];
ttl: number;
reason: ArcjetReason;

@@ -351,2 +369,3 @@ }) {

results: ArcjetRuleResult[];
ttl: number,
reason: ArcjetErrorReason;

@@ -353,0 +372,0 @@ }) {

{
"name": "@arcjet/protocol",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "The TypeScript & JavaScript interface into the Arcjet protocol",

@@ -13,4 +13,3 @@ "license": "Apache-2.0",

"engines": {
"node": ">=18",
"npm": ">=10"
"node": ">=18"
},

@@ -34,3 +33,3 @@ "type": "module",

"pretest": "npm run build",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
},

@@ -43,5 +42,5 @@ "dependencies": {

"devDependencies": {
"@arcjet/eslint-config": "1.0.0-alpha.4",
"@arcjet/rollup-config": "1.0.0-alpha.4",
"@arcjet/tsconfig": "1.0.0-alpha.4",
"@arcjet/eslint-config": "1.0.0-alpha.5",
"@arcjet/rollup-config": "1.0.0-alpha.5",
"@arcjet/tsconfig": "1.0.0-alpha.5",
"@jest/globals": "29.7.0",

@@ -48,0 +47,0 @@ "@rollup/wasm-node": "4.8.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc