Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: types #25

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class Hooks<Shop extends ShopInterface = ShopInterface> {
}

for (const cb of events) {
// @ts-expect-error
const res = cb(...args);

if (res instanceof Promise) {
Expand Down
2 changes: 2 additions & 0 deletions src/integration/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export function configureAppServer(hono: Hono, cfg: MiddlewareConfig) {
cfg.appDeactivateUrl = cfg.appDeactivateUrl || "/app/deactivate";
cfg.appDeleteUrl = cfg.appDeleteUrl || "/app/delete";
cfg.appPath = cfg.appPath || "/app/*";
cfg.appInstallUrl = cfg.appInstallUrl || "/app/install";
cfg.appUpdateUrl = cfg.appUpdateUrl || "/app/update";

cfg.appIframePath = cfg.appIframePath || "/client-api/*";

Expand Down
4 changes: 2 additions & 2 deletions src/registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, jest, test } from "bun:test";
import { AppServer } from "../src/app.js";
import { InMemoryShopRepository, type SimpleShop } from "../src/repository.js";
import { Hooks } from "./hooks.js";
import type { AppUninstallEvent } from "./registration.js";
import type { AppUninstallEvent, ShopAuthorizeEvent } from "./registration.js";

describe("src/registration.ts", async () => {
let app: AppServer<SimpleShop>;
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("src/registration.ts", async () => {
test("authorizeCallback: rejeced", async () => {
await app.repository.createShop("1", "http://localhost", "test");

app.hooks.on("onAuthorize", async (event) => {
app.hooks.on("onAuthorize", async (event: ShopAuthorizeEvent) => {
event.rejectRegistration("not you!");
});

Expand Down
12 changes: 9 additions & 3 deletions src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export class Registration<Shop extends ShopInterface = ShopInterface> {
* </webhooks>
*/
public async install(req: Request): Promise<Response> {
const ctx = await this.app.contextResolver.fromAPI(req);
const ctx = await this.app.contextResolver.fromAPI<{
data: { payload: { appVersion: string } };
}>(req);

const event = new AppInstallEvent(
req,
Expand Down Expand Up @@ -177,7 +179,9 @@ export class Registration<Shop extends ShopInterface = ShopInterface> {
* </webhooks>
*/
public async update(req: Request): Promise<Response> {
const ctx = await this.app.contextResolver.fromAPI(req);
const ctx = await this.app.contextResolver.fromAPI<{
data: { payload: { appVersion: string } };
}>(req);

const event = new AppUpdateEvent(
req,
Expand All @@ -197,7 +201,9 @@ export class Registration<Shop extends ShopInterface = ShopInterface> {
* </webhooks>
*/
public async delete(req: Request): Promise<Response> {
const ctx = await this.app.contextResolver.fromAPI(req);
const ctx = await this.app.contextResolver.fromAPI<{
data: { payload: { keepUserData?: boolean } };
}>(req);

const event = new AppUninstallEvent(
req,
Expand Down