@getcronit/pylon 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { AuthRequireChecks } from '..';
2
+ export declare function requireAuth(checks?: AuthRequireChecks): (...args: any[]) => void;
@@ -0,0 +1,21 @@
1
+ import { MiddlewareHandler } from 'hono';
2
+ import type { IdTokenClaims, IntrospectionResponse } from 'openid-client';
3
+ export type AuthState = IntrospectionResponse & IdTokenClaims & {
4
+ roles: string[];
5
+ };
6
+ export type AuthRequireChecks = {
7
+ roles?: string[];
8
+ };
9
+ export declare const auth: {
10
+ initialize: () => MiddlewareHandler<{
11
+ Variables: {
12
+ auth: AuthState;
13
+ };
14
+ }, string, {}>;
15
+ require: (checks?: AuthRequireChecks) => MiddlewareHandler<{
16
+ Variables: {
17
+ auth?: AuthState;
18
+ };
19
+ }, string, {}>;
20
+ };
21
+ export { requireAuth } from './decorators/requireAuth';
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { Context as HonoContext } from 'hono';
3
+ import { AuthState } from './auth';
4
+ import { AsyncLocalStorage } from 'async_hooks';
5
+ export type Env = {
6
+ Bindings: {
7
+ NODE_ENV: string;
8
+ };
9
+ Variables: {
10
+ auth: AuthState;
11
+ };
12
+ };
13
+ export type Context = HonoContext<Env, string, {}>;
14
+ export declare const asyncContext: AsyncLocalStorage<Context>;
15
+ export declare const getContext: () => Context;
16
+ export declare const setContext: (context: Context) => void;
@@ -0,0 +1,44 @@
1
+ /// <reference types="bun-types" />
2
+ import { GraphQLError, GraphQLErrorExtensions } from 'graphql';
3
+ import { Hono as _Hono } from 'hono';
4
+ import { Server, WebSocketHandler } from 'bun';
5
+ import { Context, Env } from './context';
6
+ export interface Resolvers<Q, M> {
7
+ Query: Q;
8
+ Mutation: M;
9
+ }
10
+ type WebSocketHandlerFunction<T extends Record<string, any>> = (server: Server) => WebSocketHandler<T>;
11
+ type Hono = _Hono<Env>;
12
+ export interface PylonAPI {
13
+ defineService: typeof defineService;
14
+ configureApp: (app: Hono) => Hono | void | Promise<void> | Promise<Hono>;
15
+ configureServer: (server: Server) => void;
16
+ configureWebsocket: WebSocketHandlerFunction<any>;
17
+ }
18
+ type SingleResolver = ((...args: any[]) => any) | object;
19
+ type ReturnTypeOrContext<T> = T extends (...args: any) => any ? ReturnType<T> : Context;
20
+ export declare const defineService: <Q extends Record<string, SingleResolver>, M, Options extends {
21
+ context: (context: Context) => ReturnTypeOrContext<Options["context"]>;
22
+ }>(plainResolvers: {
23
+ Query?: Q | undefined;
24
+ Mutation?: M | undefined;
25
+ }, options?: Options | undefined) => {
26
+ graphqlResolvers: GraphQLResolvers;
27
+ plainResolvers: Resolvers<Q & {
28
+ version: string;
29
+ }, M>;
30
+ getContext: () => ReturnType<Options["context"]>;
31
+ };
32
+ type GraphQLResolvers = {
33
+ Query: Record<string, any>;
34
+ Mutation: Record<string, any>;
35
+ };
36
+ export declare class ServiceError extends GraphQLError {
37
+ extensions: GraphQLErrorExtensions;
38
+ constructor(message: string, extensions: {
39
+ code: string;
40
+ statusCode: number;
41
+ details?: Record<string, any>;
42
+ });
43
+ }
44
+ export {};
@@ -0,0 +1,4 @@
1
+ export { defineService, ServiceError, PylonAPI } from './define-pylon.js';
2
+ export { logger } from './logger/index.js';
3
+ export * from './auth/index.js';
4
+ export { Context, Env, asyncContext, getContext, setContext } from './context.js';