@shopware-ag/app-server-sdk
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -16,4 +16,28 @@ import type { AppServer } from "./app.js"; | ||
authorizeCallback(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/> | ||
* </webhooks> | ||
*/ | ||
activate(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDeactivated" url="http://localhost:3000/app/deactivated" event="app.deactivated"/> | ||
* </webhooks> | ||
*/ | ||
deactivate(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDelete" url="http://localhost:3000/app/delete" event="app.deleted"/> | ||
* </webhooks> | ||
*/ | ||
delete(req: Request): Promise<Response>; | ||
} | ||
export declare function randomString(length?: number): string; | ||
//# sourceMappingURL=registration.d.ts.map |
@@ -23,8 +23,9 @@ "use strict"; | ||
} | ||
const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${url.searchParams.get("shop-id")}&shop-url=${url.searchParams.get("shop-url")}×tamp=${url.searchParams.get("timestamp")}`, this.app.cfg.appSecret); | ||
const shopId = url.searchParams.get("shop-id"); | ||
const shopUrl = url.searchParams.get("shop-url"); | ||
const timestamp = url.searchParams.get("timestamp"); | ||
const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${shopId}&shop-url=${shopUrl}×tamp=${timestamp}`, this.app.cfg.appSecret); | ||
if (!v) { | ||
return new InvalidRequestResponse("Cannot validate app signature"); | ||
} | ||
const shopId = url.searchParams.get("shop-id"); | ||
const shopUrl = url.searchParams.get("shop-url"); | ||
const shopSecret = randomString(); | ||
@@ -69,2 +70,40 @@ await this.app.repository.createShop(shopId, shopUrl, shopSecret); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/> | ||
* </webhooks> | ||
*/ | ||
async activate(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
ctx.shop.setShopActive(true); | ||
await this.app.repository.updateShop(ctx.shop); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDeactivated" url="http://localhost:3000/app/deactivated" event="app.deactivated"/> | ||
* </webhooks> | ||
*/ | ||
async deactivate(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
ctx.shop.setShopActive(false); | ||
await this.app.repository.updateShop(ctx.shop); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDelete" url="http://localhost:3000/app/delete" event="app.deleted"/> | ||
* </webhooks> | ||
*/ | ||
async delete(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
return new Response(null, { status: 204 }); | ||
} | ||
} | ||
@@ -71,0 +110,0 @@ exports.Registration = Registration; |
@@ -10,3 +10,5 @@ /** | ||
getShopClientSecret(): string | null; | ||
getShopActive(): boolean; | ||
setShopCredentials(clientId: string, clientSecret: string): void; | ||
setShopActive(active: boolean): void; | ||
} | ||
@@ -32,4 +34,6 @@ /** | ||
private shopClientSecret; | ||
yes(): void; | ||
private shopActive; | ||
constructor(shopId: string, shopUrl: string, shopSecret: string); | ||
getShopActive(): boolean; | ||
setShopActive(active: boolean): void; | ||
getShopId(): string; | ||
@@ -36,0 +40,0 @@ getShopUrl(): string; |
@@ -13,3 +13,3 @@ "use strict"; | ||
shopClientSecret; | ||
yes() { } | ||
shopActive = true; | ||
constructor(shopId, shopUrl, shopSecret) { | ||
@@ -22,2 +22,8 @@ this.shopId = shopId; | ||
} | ||
getShopActive() { | ||
return this.shopActive; | ||
} | ||
setShopActive(active) { | ||
this.shopActive = active; | ||
} | ||
getShopId() { | ||
@@ -24,0 +30,0 @@ return this.shopId; |
@@ -16,4 +16,28 @@ import type { AppServer } from "./app.js"; | ||
authorizeCallback(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/> | ||
* </webhooks> | ||
*/ | ||
activate(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDeactivated" url="http://localhost:3000/app/deactivated" event="app.deactivated"/> | ||
* </webhooks> | ||
*/ | ||
deactivate(req: Request): Promise<Response>; | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDelete" url="http://localhost:3000/app/delete" event="app.deleted"/> | ||
* </webhooks> | ||
*/ | ||
delete(req: Request): Promise<Response>; | ||
} | ||
export declare function randomString(length?: number): string; | ||
//# sourceMappingURL=registration.d.ts.map |
@@ -19,8 +19,9 @@ export class Registration { | ||
} | ||
const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${url.searchParams.get("shop-id")}&shop-url=${url.searchParams.get("shop-url")}×tamp=${url.searchParams.get("timestamp")}`, this.app.cfg.appSecret); | ||
const shopId = url.searchParams.get("shop-id"); | ||
const shopUrl = url.searchParams.get("shop-url"); | ||
const timestamp = url.searchParams.get("timestamp"); | ||
const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${shopId}&shop-url=${shopUrl}×tamp=${timestamp}`, this.app.cfg.appSecret); | ||
if (!v) { | ||
return new InvalidRequestResponse("Cannot validate app signature"); | ||
} | ||
const shopId = url.searchParams.get("shop-id"); | ||
const shopUrl = url.searchParams.get("shop-url"); | ||
const shopSecret = randomString(); | ||
@@ -65,2 +66,40 @@ await this.app.repository.createShop(shopId, shopUrl, shopSecret); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/> | ||
* </webhooks> | ||
*/ | ||
async activate(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
ctx.shop.setShopActive(true); | ||
await this.app.repository.updateShop(ctx.shop); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to set the shop in-active. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDeactivated" url="http://localhost:3000/app/deactivated" event="app.deactivated"/> | ||
* </webhooks> | ||
*/ | ||
async deactivate(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
ctx.shop.setShopActive(false); | ||
await this.app.repository.updateShop(ctx.shop); | ||
return new Response(null, { status: 204 }); | ||
} | ||
/** | ||
* This method should be called by Shopware Shop to delete the app. | ||
* | ||
* <webhooks> | ||
* <webhook name="appDelete" url="http://localhost:3000/app/delete" event="app.deleted"/> | ||
* </webhooks> | ||
*/ | ||
async delete(req) { | ||
const ctx = await this.app.contextResolver.fromAPI(req); | ||
await this.app.repository.deleteShop(ctx.shop.getShopId()); | ||
return new Response(null, { status: 204 }); | ||
} | ||
} | ||
@@ -67,0 +106,0 @@ export function randomString(length = 120) { |
@@ -10,3 +10,5 @@ /** | ||
getShopClientSecret(): string | null; | ||
getShopActive(): boolean; | ||
setShopCredentials(clientId: string, clientSecret: string): void; | ||
setShopActive(active: boolean): void; | ||
} | ||
@@ -32,4 +34,6 @@ /** | ||
private shopClientSecret; | ||
yes(): void; | ||
private shopActive; | ||
constructor(shopId: string, shopUrl: string, shopSecret: string); | ||
getShopActive(): boolean; | ||
setShopActive(active: boolean): void; | ||
getShopId(): string; | ||
@@ -36,0 +40,0 @@ getShopUrl(): string; |
@@ -10,3 +10,3 @@ /** | ||
shopClientSecret; | ||
yes() { } | ||
shopActive = true; | ||
constructor(shopId, shopUrl, shopSecret) { | ||
@@ -19,2 +19,8 @@ this.shopId = shopId; | ||
} | ||
getShopActive() { | ||
return this.shopActive; | ||
} | ||
setShopActive(active) { | ||
this.shopActive = active; | ||
} | ||
getShopId() { | ||
@@ -21,0 +27,0 @@ return this.shopId; |
134
package.json
{ | ||
"name": "@shopware-ag/app-server-sdk", | ||
"version": "1.0.0", | ||
"description": "App Server SDK for JavaScript", | ||
"type": "module", | ||
"license": "MIT", | ||
"keywords": ["shopware", "app-server"], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"deno": { | ||
"types": "./dist/deno/mod.d.ts", | ||
"default": "./dist/deno/mod.js" | ||
}, | ||
"import": { | ||
"types": "./dist/esm/mod.d.ts", | ||
"default": "./dist/esm/mod.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/mod.d.ts", | ||
"default": "./dist/commonjs/mod.js" | ||
} | ||
}, | ||
"./helper/app-actions": { | ||
"deno": { | ||
"types": "./dist/deno/helper/app-actions.d.ts", | ||
"default": "./dist/deno/helper/app-actions.js" | ||
}, | ||
"import": { | ||
"types": "./dist/esm/helper/app-actions.d.ts", | ||
"default": "./dist/esm/helper/app-actions.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/helper/app-actions.d.ts", | ||
"default": "./dist/commonjs/helper/app-actions.js" | ||
} | ||
}, | ||
"./types": { | ||
"deno": { | ||
"types": "./dist/deno/types.d.ts", | ||
"default": "./dist/deno/types.js" | ||
}, | ||
"import": { | ||
"types": "./dist/esm/types.d.ts", | ||
"default": "./dist/esm/types.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/types.d.ts", | ||
"default": "./dist/commonjs/types.js" | ||
} | ||
} | ||
}, | ||
"main": "./dist/commonjs/mod.js", | ||
"module": "./dist/esm/mod.js", | ||
"types": "./dist/commonjs/mod.d.ts", | ||
"files": ["dist"], | ||
"devDependencies": { | ||
"@biomejs/biome": "1.8.3", | ||
"@types/bun": "^1.1.6", | ||
"tshy": "^3.0.2", | ||
"hono": "^4.5.6" | ||
}, | ||
"tshy": { | ||
"esmDialects": ["deno"], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./src/mod.ts", | ||
"./helper/app-actions": "./src/helper/app-actions.ts", | ||
"./types": "./src/types.ts" | ||
} | ||
} | ||
} | ||
"name": "@shopware-ag/app-server-sdk", | ||
"version": "1.0.1", | ||
"description": "App Server SDK for JavaScript", | ||
"type": "module", | ||
"license": "MIT", | ||
"keywords": [ | ||
"shopware", | ||
"app-server" | ||
], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/mod.d.ts", | ||
"default": "./dist/esm/mod.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/mod.d.ts", | ||
"default": "./dist/commonjs/mod.js" | ||
} | ||
}, | ||
"./helper/app-actions": { | ||
"import": { | ||
"types": "./dist/esm/helper/app-actions.d.ts", | ||
"default": "./dist/esm/helper/app-actions.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/helper/app-actions.d.ts", | ||
"default": "./dist/commonjs/helper/app-actions.js" | ||
} | ||
}, | ||
"./types": { | ||
"import": { | ||
"types": "./dist/esm/types.d.ts", | ||
"default": "./dist/esm/types.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/types.d.ts", | ||
"default": "./dist/commonjs/types.js" | ||
} | ||
} | ||
}, | ||
"main": "./dist/commonjs/mod.js", | ||
"module": "./dist/esm/mod.js", | ||
"types": "./dist/commonjs/mod.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"@biomejs/biome": "1.8.3", | ||
"@types/bun": "^1.1.6", | ||
"tshy": "^3.0.2", | ||
"hono": "^4.5.6" | ||
}, | ||
"tshy": { | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./src/mod.ts", | ||
"./helper/app-actions": "./src/helper/app-actions.ts", | ||
"./types": "./src/types.ts" | ||
} | ||
} | ||
} |
@@ -8,34 +8,42 @@ # App Server | ||
```js | ||
import { AppServer, InMemoryShopRepository } from '@shopware-ag/app-server-sdk' | ||
import { createNotificationResponse } from '@shopware-ag/app-server-sdk/helper/app-actions' | ||
import { AppServer, InMemoryShopRepository } from "@shopware-ag/app-server-sdk"; | ||
import { ActionButtonRequest } from "@shopware-ag/app-server-sdk/types"; | ||
import { createNotificationResponse } from "@shopware-ag/app-server-sdk/helper/app-actions"; | ||
const app = new AppServer({ | ||
appName: 'MyApp', | ||
appSecret: 'my-secret', | ||
authorizeCallbackUrl: 'http://localhost:3000/authorize/callback', | ||
}, new InMemoryShopRepository()); | ||
const app = new AppServer( | ||
{ | ||
appName: "MyApp", | ||
appSecret: "my-secret", | ||
authorizeCallbackUrl: "http://localhost:3000/app/callback", | ||
}, | ||
new InMemoryShopRepository(), | ||
); | ||
const server = Bun.serve({ | ||
port: 3000, | ||
async fetch(request) { | ||
const { pathname } = new URL(request.url); | ||
if (pathname === '/authorize') { | ||
return app.registration.authorize(request); | ||
} else if (pathname === '/authorize/callback') { | ||
return app.registration.authorizeCallback(request); | ||
} else if (pathname === '/app/product') { | ||
const context = await app.contextResolver.fromSource(request); | ||
port: 3000, | ||
async fetch(request) { | ||
const { pathname } = new URL(request.url); | ||
if (pathname === "/app/register") { | ||
return app.registration.authorize(request); | ||
} else if (pathname === "/app/callback") { | ||
return app.registration.authorizeCallback(request); | ||
} else if (pathname === "/app/product") { | ||
const context = | ||
await app.contextResolver.fromAPI<ActionButtonRequest>(request); | ||
// do something with payload, and http client | ||
// do something with payload, and http client | ||
const notification = createNotificationResponse('success', 'Product created'); | ||
const notification = createNotificationResponse( | ||
"success", | ||
"Product created", | ||
); | ||
// sign the response, with the shop secret | ||
await app.signer.signResponse(notification, context.shop.getShopSecret()); | ||
// sign the response, with the shop secret | ||
await app.signer.signResponse(notification, context.shop.getShopSecret()); | ||
return resp; | ||
} | ||
return notification; | ||
} | ||
return new Response('Not found', { status: 404 }); | ||
}, | ||
return new Response("Not found", { status: 404 }); | ||
}, | ||
}); | ||
@@ -42,0 +50,0 @@ |
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
52
160687
77
1651