UNPKG

@erebus-sh/sdk

Version:
2 lines 1.74 kB
import{ErebusError}from"./error-CVJkstUc.js";import{ErebusSession,baseClient}from"./session-BwF7HMrP.js";import{z}from"zod";let Access$1=function(e){return e.Read=`read`,e.Write=`write`,e.ReadWrite=`read-write`,e.Huh=`huh?`,e}({});const GrantScopeEnum=z.enum(Object.values(Access$1)),GrantSchema=z.object({project_id:z.string(),key_id:z.string(),webhook_url:z.string(),channel:z.string(),topics:z.array(z.object({topic:z.string(),scope:GrantScopeEnum})),userId:z.string().min(1),issuedAt:z.number(),expiresAt:z.number()}),secretKeySchema=z.string().min(1).regex(/^(sk-er-|dv-er-)[\w-]{48}$/,`Invalid API key format`),grantRequestSchema=z.object({secret_key:secretKeySchema,channel:z.string().min(1),topics:z.array(z.object({topic:z.string(),scope:GrantScopeEnum})).min(1),userId:z.string().min(1),expiresAt:z.number()});var ErebusService=class{client;grantRequest={userId:``,channel:``,topics:[],expiresAt:0,secret_key:`dv-er-abcdefghijklmnopqrstuvwxyzABCDEFGsH1234abcdddddd`};constructor({secret_api_key:u,base_url:f}){if(!secretKeySchema.safeParse(u).success)throw new ErebusError(`Invalid API key format`);this.grantRequest.secret_key=u,this.client=baseClient({base_url:f??`https://api.erebus.sh`})}async prepareSession({userId:d}){if(!d)throw new ErebusError(`User ID is required to create a session. Use the ErebusService.prepareSession() method.`);return this.grantRequest.userId=d,new ErebusSession(this.grantRequest,this.client)}};function orgPattern(e){return`${e}:*`}function groupPattern(e,u){return u?`${e}:${u}:*`:`${e}:*`}var Access;(function(e){e.Read=`read`,e.Write=`write`,e.ReadWrite=`read-write`,e.Huh=`huh?`})(Access||={});export{Access,ErebusService,groupPattern,orgPattern}; //# sourceMappingURL=service-CiKZ56MZ.js.map