@shopware-ag/app-server-sdk
Advanced tools
Comparing version 1.0.1 to 1.1.0
205
package.json
{ | ||
"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" | ||
} | ||
} | ||
} | ||
"name": "@shopware-ag/app-server-sdk", | ||
"version": "1.1.0", | ||
"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" | ||
} | ||
}, | ||
"./integration/hono": { | ||
"import": { | ||
"types": "./dist/esm/integration/hono.d.ts", | ||
"default": "./dist/esm/integration/hono.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/integration/hono.d.ts", | ||
"default": "./dist/commonjs/integration/hono.js" | ||
} | ||
}, | ||
"./integration/cloudflare-kv": { | ||
"import": { | ||
"types": "./dist/esm/integration/cloudflare-kv.d.ts", | ||
"default": "./dist/esm/integration/cloudflare-kv.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/integration/cloudflare-kv.d.ts", | ||
"default": "./dist/commonjs/integration/cloudflare-kv.js" | ||
} | ||
}, | ||
"./integration/deno-kv": { | ||
"import": { | ||
"types": "./dist/esm/integration/deno-kv.d.ts", | ||
"default": "./dist/esm/integration/deno-kv.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/integration/deno-kv.d.ts", | ||
"default": "./dist/commonjs/integration/deno-kv.js" | ||
} | ||
}, | ||
"./integration/dynamodb": { | ||
"import": { | ||
"types": "./dist/esm/integration/dynamodb.d.ts", | ||
"default": "./dist/esm/integration/dynamodb.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/integration/dynamodb.d.ts", | ||
"default": "./dist/commonjs/integration/dynamodb.js" | ||
} | ||
}, | ||
"./integration/bun-sqlite": { | ||
"import": { | ||
"types": "./dist/esm/integration/bun-sqlite.d.ts", | ||
"default": "./dist/esm/integration/bun-sqlite.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/integration/bun-sqlite.d.ts", | ||
"default": "./dist/commonjs/integration/bun-sqlite.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"], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"hono": "^4", | ||
"@aws-sdk/client-dynamodb": "~3.637", | ||
"@aws-sdk/lib-dynamodb": "~3.637" | ||
}, | ||
"peerDependenciesMeta": { | ||
"hono": { | ||
"optional": true | ||
}, | ||
"@aws-sdk/client-dynamodb": { | ||
"optional": true | ||
}, | ||
"@aws-sdk/lib-dynamodb": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.8.3", | ||
"@types/bun": "^1.1.6", | ||
"tshy": "^3.0.2", | ||
"hono": "^4.5.6", | ||
"@cloudflare/workers-types": "^4.20240821.1", | ||
"@aws-sdk/client-dynamodb": "~3.637", | ||
"@aws-sdk/lib-dynamodb": "~3.637" | ||
}, | ||
"tshy": { | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./src/mod.ts", | ||
"./helper/app-actions": "./src/helper/app-actions.ts", | ||
"./integration/hono": "./src/integration/hono.ts", | ||
"./integration/cloudflare-kv": "./src/integration/cloudflare-kv.ts", | ||
"./integration/deno-kv": "./src/integration/deno-kv.ts", | ||
"./integration/dynamodb": "./src/integration/dynamodb.ts", | ||
"./integration/bun-sqlite": "./src/integration/bun-sqlite.ts", | ||
"./types": "./src/types.ts" | ||
} | ||
}, | ||
"scripts": { | ||
"init": "tshy && biome format . --write", | ||
"lint": "biome ci .", | ||
"lint:fix": "biome lint . --write && biome format . --write && biome check . --write", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"trustedDependencies": ["@biomejs/biome"] | ||
} |
@@ -1,48 +0,53 @@ | ||
# App Server | ||
# Shopware App Server SDK in TypeScript | ||
This package can be used to create a Shopware App Backend. It's build independent of any JavaScript framework. It relies on Fetch-standardized Request and Response objects. | ||
This SDK is written in pure Typescript with portability in mind being able to use it on Node (20+), Deno, Cloudflare Worker or other runtimes. | ||
## Standalone example with Bun | ||
## Features | ||
```js | ||
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"; | ||
- Provides registration process for app | ||
- Verify and signing of requests / responses | ||
- preconfigured API Client | ||
- Complete Registration Handshake between Shopware and this | ||
const app = new AppServer( | ||
{ | ||
appName: "MyApp", | ||
appSecret: "my-secret", | ||
authorizeCallbackUrl: "http://localhost:3000/app/callback", | ||
}, | ||
new InMemoryShopRepository(), | ||
); | ||
## How to use it? | ||
```bash | ||
npm install @shopware-ag/app-server-sdk --save | ||
``` | ||
## Example | ||
```typescript | ||
import { AppServer, InMemoryShopRepository } from '@shopware-ag/app-server-sdk' | ||
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 server = Bun.serve({ | ||
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); | ||
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); | ||
// 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 notification; | ||
} | ||
return resp; | ||
} | ||
return new Response("Not found", { status: 404 }); | ||
}, | ||
return new Response('Not found', { status: 404 }); | ||
}, | ||
}); | ||
@@ -52,1 +57,7 @@ | ||
``` | ||
Checkout the [examples](./examples) folder for more examples using: | ||
- [Cloudflare Worker with Hono](./examples/cloudflare-hono) | ||
- [Deno with Hono](./examples/deno-hono) | ||
- [Node with Hono](./examples/node-hono) |
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
417835
205
3706
63
3
7