diff --git a/app/__test__/api/ModuleApi.spec.ts b/app/__test__/api/ModuleApi.spec.ts index 5fb6976..9577fd1 100644 --- a/app/__test__/api/ModuleApi.spec.ts +++ b/app/__test__/api/ModuleApi.spec.ts @@ -27,10 +27,7 @@ describe("ModuleApi", () => { it("fetches endpoint", async () => { const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" })); - const api = new Api({ host }); - - // @ts-expect-error it's protected - api.fetcher = app.request as typeof fetch; + const api = new Api({ host }, app.request as typeof fetch); const res = await api.get("/endpoint"); expect(res.res.ok).toEqual(true); @@ -41,10 +38,7 @@ describe("ModuleApi", () => { it("has accessible request", async () => { const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" })); - const api = new Api({ host }); - - // @ts-expect-error it's protected - api.fetcher = app.request as typeof fetch; + const api = new Api({ host }, app.request as typeof fetch); const promise = api.get("/endpoint"); expect(promise.request).toBeDefined(); diff --git a/app/src/Api.ts b/app/src/Api.ts index 835ff14..2310c0f 100644 --- a/app/src/Api.ts +++ b/app/src/Api.ts @@ -23,6 +23,7 @@ export type ApiOptions = { headers?: Headers; key?: string; localStorage?: boolean; + fetcher?: typeof fetch; }; export type AuthState = { @@ -163,14 +164,18 @@ export class Api { headers: this.options.headers, token_transport: this.token_transport }; + const fetcher = this.options.fetcher; - this.system = new SystemApi(baseParams); - this.data = new DataApi(baseParams); - this.auth = new AuthApi({ - ...baseParams, - onTokenUpdate: (token) => this.updateToken(token, true) - }); - this.media = new MediaApi(baseParams); + this.system = new SystemApi(baseParams, fetcher); + this.data = new DataApi(baseParams, fetcher); + this.auth = new AuthApi( + { + ...baseParams, + onTokenUpdate: (token) => this.updateToken(token, true) + }, + fetcher + ); + this.media = new MediaApi(baseParams, fetcher); } } diff --git a/app/src/App.ts b/app/src/App.ts index b98fc67..d32d57c 100644 --- a/app/src/App.ts +++ b/app/src/App.ts @@ -1,6 +1,7 @@ import type { CreateUserPayload } from "auth/AppAuth"; import { Event } from "core/events"; import { Connection, type LibSqlCredentials, LibsqlConnection } from "data"; +import type { Hono } from "hono"; import { type InitialModuleConfigs, ModuleManager, @@ -132,7 +133,7 @@ export class App { return this.modules.ctx().em; } - get fetch(): any { + get fetch(): Hono["fetch"] { return this.server.fetch; } @@ -155,6 +156,10 @@ export class App { return this.modules.version(); } + isBuilt(): boolean { + return this.modules.isBuilt(); + } + registerAdminController(config?: AdminControllerOptions) { // register admin this.adminController = new AdminController(this, config); diff --git a/app/src/adapter/astro/index.ts b/app/src/adapter/astro/index.ts index 818174e..d5010a5 100644 --- a/app/src/adapter/astro/index.ts +++ b/app/src/adapter/astro/index.ts @@ -1,2 +1 @@ export * from "./astro.adapter"; -export { registerLocalMediaAdapter } from "bknd/adapter/node"; diff --git a/app/src/adapter/nextjs/index.ts b/app/src/adapter/nextjs/index.ts index e691401..957fa9e 100644 --- a/app/src/adapter/nextjs/index.ts +++ b/app/src/adapter/nextjs/index.ts @@ -1,2 +1 @@ export * from "./nextjs.adapter"; -export { registerLocalMediaAdapter } from "bknd/adapter/node"; diff --git a/app/src/adapter/remix/index.ts b/app/src/adapter/remix/index.ts index 6c9f7db..e02c2c0 100644 --- a/app/src/adapter/remix/index.ts +++ b/app/src/adapter/remix/index.ts @@ -1,3 +1,2 @@ export * from "./remix.adapter"; export * from "./AdminPage"; -export { registerLocalMediaAdapter } from "bknd/adapter/node"; diff --git a/app/src/adapter/vite/index.ts b/app/src/adapter/vite/index.ts index 0519488..832bcde 100644 --- a/app/src/adapter/vite/index.ts +++ b/app/src/adapter/vite/index.ts @@ -1,2 +1 @@ export * from "./vite.adapter"; -export { registerLocalMediaAdapter } from "bknd/adapter/node"; diff --git a/app/src/auth/authenticate/Authenticator.ts b/app/src/auth/authenticate/Authenticator.ts index 7b81ed7..19088d9 100644 --- a/app/src/auth/authenticate/Authenticator.ts +++ b/app/src/auth/authenticate/Authenticator.ts @@ -259,7 +259,7 @@ export class Authenticator = Record< } async requestCookieRefresh(c: Context) { - if (this.config.cookie.renew) { + if (this.config.cookie.renew && this.isUserLoggedIn()) { const token = await this.getAuthCookie(c); if (token) { await this.setAuthCookie(c, token); diff --git a/app/src/index.ts b/app/src/index.ts index 44b1ca5..bedbe45 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -12,7 +12,6 @@ export { export * as middlewares from "modules/middlewares"; export { registries } from "modules/registries"; -export type * from "./adapter"; export { Api, type ApiOptions } from "./Api"; export type { MediaFieldSchema } from "media/AppMedia"; diff --git a/app/src/modules/ModuleApi.ts b/app/src/modules/ModuleApi.ts index 882cb90..a088170 100644 --- a/app/src/modules/ModuleApi.ts +++ b/app/src/modules/ModuleApi.ts @@ -23,9 +23,10 @@ export type ApiResponse = { export type TInput = string | (string | number | PrimaryFieldType)[]; export abstract class ModuleApi { - protected fetcher?: typeof fetch; - - constructor(protected readonly _options: Partial = {}) {} + constructor( + protected readonly _options: Partial = {}, + protected fetcher?: typeof fetch + ) {} protected getDefaultOptions(): Partial { return {}; diff --git a/app/src/modules/ModuleManager.ts b/app/src/modules/ModuleManager.ts index efe7a09..b1868fb 100644 --- a/app/src/modules/ModuleManager.ts +++ b/app/src/modules/ModuleManager.ts @@ -171,6 +171,10 @@ export class ModuleManager { } } + isBuilt(): boolean { + return this._built; + } + /** * This is set through module's setListener * It's called everytime a module's config is updated in SchemaObject