actor-kit
Version:
Actor Kit is a library for running state machines in Cloudflare Workers, leveraging XState for robust state management. It provides a framework for managing the logic, lifecycle, persistence, synchronization, and access control of actors in a distributed
3 lines (2 loc) • 2.04 kB
JavaScript
import{z as e}from"zod";const t=e.object({corporateProxy:e.boolean(),verifiedBot:e.boolean(),jsDetection:e.object({passed:e.boolean()}),staticResource:e.boolean(),detectionIds:e.record(e.any()),score:e.number()}),s=e.object({ACTOR_KIT_SECRET:e.string(),ACTOR_KIT_HOST:e.string()}),r=e.object({longitude:e.string(),latitude:e.string(),continent:e.string(),country:e.string(),city:e.string(),timezone:e.string(),postalCode:e.string(),region:e.string(),regionCode:e.string(),metroCode:e.string(),botManagement:t}),o=e.object({id:e.string(),type:e.enum(["client","system","service"])}),i=e.object({type:e.string()}),n=e.discriminatedUnion("type",[e.object({type:e.literal("INITIALIZE"),caller:e.object({type:e.literal("system"),id:e.string()})}),e.object({type:e.literal("CONNECT"),caller:e.object({type:e.literal("system"),id:e.string()}),connectingCaller:o}),e.object({type:e.literal("DISCONNECT"),caller:e.object({type:e.literal("system"),id:e.string()}),disconnectingCaller:o}),e.object({type:e.literal("RESUME"),caller:e.object({type:e.literal("system"),id:e.string()})}),e.object({type:e.literal("MIGRATE"),caller:e.object({type:e.literal("system"),id:e.string()}),operations:e.array(e.any())})]),c=e.enum(["client","service","system"]),a=e.string().transform(((t,s)=>{if("anonymous"===t)return{type:"client",id:"anonymous"};const r=t.split("-");if(r.length<2)return s.addIssue({code:e.ZodIssueCode.custom,message:`Caller string must be in the format 'type-id' or 'anonymous'. Received '${t}'.`}),e.NEVER;const o=r[0],i=r.slice(1).join("-"),n=c.safeParse(o);if(!n.success)return n.error.issues.forEach(s.addIssue),e.NEVER;const a=n.data;return i.length>0?{type:a,id:i}:(s.addIssue({code:e.ZodIssueCode.custom,message:`The ID part cannot be empty after the type prefix. Received '${i}' for value '${t}'.`}),e.NEVER)}));export{i as AnyEventSchema,t as BotManagementSchema,c as CallerIdTypeSchema,o as CallerSchema,a as CallerStringSchema,s as EnvironmentSchema,r as RequestInfoSchema,n as SystemEventSchema};
//# sourceMappingURL=index.js.map