@shopware-ag/app-server-sdk
Advanced tools
Comparing version 1.1.11 to 1.1.12
@@ -1,5 +0,10 @@ | ||
import type { ShopAuthroizeEvent } from "./registration.js"; | ||
import type { AppActivateEvent, AppDeactivateEvent, AppInstallEvent, AppUninstallEvent, AppUpdateEvent, ShopAuthorizeEvent } from "./registration.js"; | ||
import type { ShopInterface } from "./repository.js"; | ||
interface HookRegistry<Shop extends ShopInterface> { | ||
onAuthorize: (event: ShopAuthroizeEvent<Shop>) => Promise<void>; | ||
onAuthorize: (event: ShopAuthorizeEvent<Shop>) => Promise<void>; | ||
onAppInstall: (event: AppInstallEvent<Shop>) => Promise<void>; | ||
onAppUninstall: (event: AppUninstallEvent<Shop>) => Promise<void>; | ||
onAppActivate: (event: AppActivateEvent<Shop>) => Promise<void>; | ||
onAppDeactivate: (event: AppDeactivateEvent<Shop>) => Promise<void>; | ||
onAppUpdate: (event: AppUpdateEvent<Shop>) => Promise<void>; | ||
} | ||
@@ -6,0 +11,0 @@ export declare class Hooks<Shop extends ShopInterface = ShopInterface> { |
@@ -21,2 +21,3 @@ "use strict"; | ||
for (const cb of events) { | ||
// @ts-expect-error | ||
const res = cb(...args); | ||
@@ -23,0 +24,0 @@ if (res instanceof Promise) { |
@@ -38,2 +38,8 @@ import { AppServer } from "../app.js"; | ||
/** | ||
* The relative url of the app installation lifecycle endpoint | ||
* | ||
* @default "/app/install" | ||
*/ | ||
appInstallUrl?: string | null; | ||
/** | ||
* The relative url of the app activation lifecycle endpoint | ||
@@ -45,2 +51,8 @@ * | ||
/** | ||
* The relative url of the app update lifecycle endpoint | ||
* | ||
* @default "/app/update" | ||
*/ | ||
appUpdateUrl?: string | null; | ||
/** | ||
* The relative url of the app deactivation lifecycle endpoint | ||
@@ -47,0 +59,0 @@ * |
@@ -18,2 +18,4 @@ "use strict"; | ||
cfg.appPath = cfg.appPath || "/app/*"; | ||
cfg.appInstallUrl = cfg.appInstallUrl || "/app/install"; | ||
cfg.appUpdateUrl = cfg.appUpdateUrl || "/app/update"; | ||
cfg.appIframePath = cfg.appIframePath || "/client-api/*"; | ||
@@ -86,2 +88,6 @@ hono.use("*", async (ctx, next) => { | ||
}); | ||
hono.post(cfg.appInstallUrl, async (ctx) => { | ||
const app = ctx.get("app"); | ||
return await app.registration.install(ctx.req.raw); | ||
}); | ||
hono.post(cfg.appActivateUrl, async (ctx) => { | ||
@@ -91,2 +97,6 @@ const app = ctx.get("app"); | ||
}); | ||
hono.post(cfg.appUpdateUrl, async (ctx) => { | ||
const app = ctx.get("app"); | ||
return await app.registration.update(ctx.req.raw); | ||
}); | ||
hono.post(cfg.appDeactivateUrl, async (ctx) => { | ||
@@ -93,0 +103,0 @@ const app = ctx.get("app"); |
@@ -26,2 +26,10 @@ import type { AppServer } from "./app.js"; | ||
/** | ||
* This method should be called by Shopware when the app was installed. | ||
* | ||
* <webhooks> | ||
* <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/> | ||
* </webhooks> | ||
*/ | ||
install(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
@@ -35,2 +43,10 @@ * | ||
/** | ||
* This method should be called by Shopware when the app was updated. | ||
* | ||
* <webhooks> | ||
* <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/> | ||
* </webhooks> | ||
*/ | ||
update(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
@@ -45,3 +61,3 @@ * | ||
export declare function randomString(length?: number): string; | ||
export declare class ShopAuthroizeEvent<Shop extends ShopInterface = ShopInterface> { | ||
export declare class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
@@ -54,2 +70,30 @@ shop: Shop; | ||
} | ||
export declare class AppInstallEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
appVersion: string | null; | ||
constructor(request: Request, shop: Shop, appVersion?: string | null); | ||
} | ||
export declare class AppActivateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
constructor(request: Request, shop: Shop); | ||
} | ||
export declare class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
constructor(request: Request, shop: Shop); | ||
} | ||
export declare class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
appVersion: string | null; | ||
constructor(request: Request, shop: Shop, appVersion?: string | null); | ||
} | ||
export declare class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
keepUserData: boolean | null; | ||
constructor(request: Request, shop: Shop, keepUserData?: boolean | null); | ||
} | ||
//# sourceMappingURL=registration.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ShopAuthroizeEvent = exports.Registration = void 0; | ||
exports.AppUninstallEvent = exports.AppUpdateEvent = exports.AppDeactivateEvent = exports.AppActivateEvent = exports.AppInstallEvent = exports.ShopAuthorizeEvent = exports.Registration = void 0; | ||
exports.randomString = randomString; | ||
@@ -61,3 +61,3 @@ class Registration { | ||
if (!v) { | ||
// Shop has failed the verify. Delete it from our DB | ||
// Shop has failed the verification. Delete it from our DB. | ||
await this.app.repository.deleteShop(shop.getShopId()); | ||
@@ -67,3 +67,3 @@ return new InvalidRequestResponse("Cannot validate app signature"); | ||
shop.setShopCredentials(body.apiKey, body.secretKey); | ||
const event = new ShopAuthroizeEvent(req, shop); | ||
const event = new ShopAuthorizeEvent(req, shop); | ||
await this.app.hooks.publish("onAuthorize", event); | ||
@@ -86,2 +86,4 @@ if (event.reason) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppActivateEvent(req, ctx.shop); | ||
await this.app.hooks.publish("onAppActivate", event); | ||
ctx.shop.setShopActive(true); | ||
@@ -92,2 +94,15 @@ await this.app.repository.updateShop(ctx.shop); | ||
/** | ||
* This method should be called by Shopware when the app was installed. | ||
* | ||
* <webhooks> | ||
* <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/> | ||
* </webhooks> | ||
*/ | ||
async install(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppInstallEvent(req, ctx.shop, ctx.payload?.data?.payload?.appVersion ?? null); | ||
await this.app.hooks.publish("onAppInstall", event); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
@@ -101,2 +116,4 @@ * | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppDeactivateEvent(req, ctx.shop); | ||
await this.app.hooks.publish("onAppDeactivate", event); | ||
ctx.shop.setShopActive(false); | ||
@@ -107,2 +124,15 @@ await this.app.repository.updateShop(ctx.shop); | ||
/** | ||
* This method should be called by Shopware when the app was updated. | ||
* | ||
* <webhooks> | ||
* <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/> | ||
* </webhooks> | ||
*/ | ||
async update(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppUpdateEvent(req, ctx.shop, ctx.payload?.data?.payload?.appVersion ?? null); | ||
await this.app.hooks.publish("onAppUpdate", event); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
@@ -116,3 +146,7 @@ * | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
const event = new AppUninstallEvent(req, ctx.shop, ctx.payload?.data?.payload?.keepUserData ?? null); | ||
await this.app.hooks.publish("onAppUninstall", event); | ||
if (event.keepUserData === false) { | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
} | ||
return new Response(null, { status: 204 }); | ||
@@ -141,3 +175,3 @@ } | ||
} | ||
class ShopAuthroizeEvent { | ||
class ShopAuthorizeEvent { | ||
request; | ||
@@ -157,3 +191,54 @@ shop; | ||
} | ||
exports.ShopAuthroizeEvent = ShopAuthroizeEvent; | ||
exports.ShopAuthorizeEvent = ShopAuthorizeEvent; | ||
class AppInstallEvent { | ||
request; | ||
shop; | ||
appVersion; | ||
constructor(request, shop, appVersion = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.appVersion = appVersion; | ||
} | ||
} | ||
exports.AppInstallEvent = AppInstallEvent; | ||
class AppActivateEvent { | ||
request; | ||
shop; | ||
constructor(request, shop) { | ||
this.request = request; | ||
this.shop = shop; | ||
} | ||
} | ||
exports.AppActivateEvent = AppActivateEvent; | ||
class AppDeactivateEvent { | ||
request; | ||
shop; | ||
constructor(request, shop) { | ||
this.request = request; | ||
this.shop = shop; | ||
} | ||
} | ||
exports.AppDeactivateEvent = AppDeactivateEvent; | ||
class AppUpdateEvent { | ||
request; | ||
shop; | ||
appVersion; | ||
constructor(request, shop, appVersion = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.appVersion = appVersion; | ||
} | ||
} | ||
exports.AppUpdateEvent = AppUpdateEvent; | ||
class AppUninstallEvent { | ||
request; | ||
shop; | ||
keepUserData; | ||
constructor(request, shop, keepUserData = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.keepUserData = keepUserData; | ||
} | ||
} | ||
exports.AppUninstallEvent = AppUninstallEvent; | ||
//# sourceMappingURL=registration.js.map |
@@ -1,5 +0,10 @@ | ||
import type { ShopAuthroizeEvent } from "./registration.js"; | ||
import type { AppActivateEvent, AppDeactivateEvent, AppInstallEvent, AppUninstallEvent, AppUpdateEvent, ShopAuthorizeEvent } from "./registration.js"; | ||
import type { ShopInterface } from "./repository.js"; | ||
interface HookRegistry<Shop extends ShopInterface> { | ||
onAuthorize: (event: ShopAuthroizeEvent<Shop>) => Promise<void>; | ||
onAuthorize: (event: ShopAuthorizeEvent<Shop>) => Promise<void>; | ||
onAppInstall: (event: AppInstallEvent<Shop>) => Promise<void>; | ||
onAppUninstall: (event: AppUninstallEvent<Shop>) => Promise<void>; | ||
onAppActivate: (event: AppActivateEvent<Shop>) => Promise<void>; | ||
onAppDeactivate: (event: AppDeactivateEvent<Shop>) => Promise<void>; | ||
onAppUpdate: (event: AppUpdateEvent<Shop>) => Promise<void>; | ||
} | ||
@@ -6,0 +11,0 @@ export declare class Hooks<Shop extends ShopInterface = ShopInterface> { |
@@ -18,2 +18,3 @@ export class Hooks { | ||
for (const cb of events) { | ||
// @ts-expect-error | ||
const res = cb(...args); | ||
@@ -20,0 +21,0 @@ if (res instanceof Promise) { |
@@ -38,2 +38,8 @@ import { AppServer } from "../app.js"; | ||
/** | ||
* The relative url of the app installation lifecycle endpoint | ||
* | ||
* @default "/app/install" | ||
*/ | ||
appInstallUrl?: string | null; | ||
/** | ||
* The relative url of the app activation lifecycle endpoint | ||
@@ -45,2 +51,8 @@ * | ||
/** | ||
* The relative url of the app update lifecycle endpoint | ||
* | ||
* @default "/app/update" | ||
*/ | ||
appUpdateUrl?: string | null; | ||
/** | ||
* The relative url of the app deactivation lifecycle endpoint | ||
@@ -47,0 +59,0 @@ * |
@@ -15,2 +15,4 @@ import { getSignedCookie, setSignedCookie } from "hono/cookie"; | ||
cfg.appPath = cfg.appPath || "/app/*"; | ||
cfg.appInstallUrl = cfg.appInstallUrl || "/app/install"; | ||
cfg.appUpdateUrl = cfg.appUpdateUrl || "/app/update"; | ||
cfg.appIframePath = cfg.appIframePath || "/client-api/*"; | ||
@@ -83,2 +85,6 @@ hono.use("*", async (ctx, next) => { | ||
}); | ||
hono.post(cfg.appInstallUrl, async (ctx) => { | ||
const app = ctx.get("app"); | ||
return await app.registration.install(ctx.req.raw); | ||
}); | ||
hono.post(cfg.appActivateUrl, async (ctx) => { | ||
@@ -88,2 +94,6 @@ const app = ctx.get("app"); | ||
}); | ||
hono.post(cfg.appUpdateUrl, async (ctx) => { | ||
const app = ctx.get("app"); | ||
return await app.registration.update(ctx.req.raw); | ||
}); | ||
hono.post(cfg.appDeactivateUrl, async (ctx) => { | ||
@@ -90,0 +100,0 @@ const app = ctx.get("app"); |
@@ -26,2 +26,10 @@ import type { AppServer } from "./app.js"; | ||
/** | ||
* This method should be called by Shopware when the app was installed. | ||
* | ||
* <webhooks> | ||
* <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/> | ||
* </webhooks> | ||
*/ | ||
install(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
@@ -35,2 +43,10 @@ * | ||
/** | ||
* This method should be called by Shopware when the app was updated. | ||
* | ||
* <webhooks> | ||
* <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/> | ||
* </webhooks> | ||
*/ | ||
update(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
@@ -45,3 +61,3 @@ * | ||
export declare function randomString(length?: number): string; | ||
export declare class ShopAuthroizeEvent<Shop extends ShopInterface = ShopInterface> { | ||
export declare class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
@@ -54,2 +70,30 @@ shop: Shop; | ||
} | ||
export declare class AppInstallEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
appVersion: string | null; | ||
constructor(request: Request, shop: Shop, appVersion?: string | null); | ||
} | ||
export declare class AppActivateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
constructor(request: Request, shop: Shop); | ||
} | ||
export declare class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
constructor(request: Request, shop: Shop); | ||
} | ||
export declare class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
appVersion: string | null; | ||
constructor(request: Request, shop: Shop, appVersion?: string | null); | ||
} | ||
export declare class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> { | ||
request: Request; | ||
shop: Shop; | ||
keepUserData: boolean | null; | ||
constructor(request: Request, shop: Shop, keepUserData?: boolean | null); | ||
} | ||
//# sourceMappingURL=registration.d.ts.map |
@@ -57,3 +57,3 @@ export class Registration { | ||
if (!v) { | ||
// Shop has failed the verify. Delete it from our DB | ||
// Shop has failed the verification. Delete it from our DB. | ||
await this.app.repository.deleteShop(shop.getShopId()); | ||
@@ -63,3 +63,3 @@ return new InvalidRequestResponse("Cannot validate app signature"); | ||
shop.setShopCredentials(body.apiKey, body.secretKey); | ||
const event = new ShopAuthroizeEvent(req, shop); | ||
const event = new ShopAuthorizeEvent(req, shop); | ||
await this.app.hooks.publish("onAuthorize", event); | ||
@@ -82,2 +82,4 @@ if (event.reason) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppActivateEvent(req, ctx.shop); | ||
await this.app.hooks.publish("onAppActivate", event); | ||
ctx.shop.setShopActive(true); | ||
@@ -88,2 +90,15 @@ await this.app.repository.updateShop(ctx.shop); | ||
/** | ||
* This method should be called by Shopware when the app was installed. | ||
* | ||
* <webhooks> | ||
* <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/> | ||
* </webhooks> | ||
*/ | ||
async install(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppInstallEvent(req, ctx.shop, ctx.payload?.data?.payload?.appVersion ?? null); | ||
await this.app.hooks.publish("onAppInstall", event); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
@@ -97,2 +112,4 @@ * | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppDeactivateEvent(req, ctx.shop); | ||
await this.app.hooks.publish("onAppDeactivate", event); | ||
ctx.shop.setShopActive(false); | ||
@@ -103,2 +120,15 @@ await this.app.repository.updateShop(ctx.shop); | ||
/** | ||
* This method should be called by Shopware when the app was updated. | ||
* | ||
* <webhooks> | ||
* <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/> | ||
* </webhooks> | ||
*/ | ||
async update(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
const event = new AppUpdateEvent(req, ctx.shop, ctx.payload?.data?.payload?.appVersion ?? null); | ||
await this.app.hooks.publish("onAppUpdate", event); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
@@ -112,3 +142,7 @@ * | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
const event = new AppUninstallEvent(req, ctx.shop, ctx.payload?.data?.payload?.keepUserData ?? null); | ||
await this.app.hooks.publish("onAppUninstall", event); | ||
if (event.keepUserData === false) { | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
} | ||
return new Response(null, { status: 204 }); | ||
@@ -136,3 +170,3 @@ } | ||
} | ||
export class ShopAuthroizeEvent { | ||
export class ShopAuthorizeEvent { | ||
request; | ||
@@ -152,2 +186,48 @@ shop; | ||
} | ||
export class AppInstallEvent { | ||
request; | ||
shop; | ||
appVersion; | ||
constructor(request, shop, appVersion = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.appVersion = appVersion; | ||
} | ||
} | ||
export class AppActivateEvent { | ||
request; | ||
shop; | ||
constructor(request, shop) { | ||
this.request = request; | ||
this.shop = shop; | ||
} | ||
} | ||
export class AppDeactivateEvent { | ||
request; | ||
shop; | ||
constructor(request, shop) { | ||
this.request = request; | ||
this.shop = shop; | ||
} | ||
} | ||
export class AppUpdateEvent { | ||
request; | ||
shop; | ||
appVersion; | ||
constructor(request, shop, appVersion = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.appVersion = appVersion; | ||
} | ||
} | ||
export class AppUninstallEvent { | ||
request; | ||
shop; | ||
keepUserData; | ||
constructor(request, shop, keepUserData = null) { | ||
this.request = request; | ||
this.shop = shop; | ||
this.keepUserData = keepUserData; | ||
} | ||
} | ||
//# sourceMappingURL=registration.js.map |
{ | ||
"name": "@shopware-ag/app-server-sdk", | ||
"version": "1.1.11", | ||
"version": "1.1.12", | ||
"description": "App Server SDK for JavaScript", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
537673
5670