Skip to content

Commit 82609c8

Browse files
committed
Make schemaVersion required, remove alpha note, combine files
1 parent c70a20d commit 82609c8

File tree

4 files changed

+40
-47
lines changed

4 files changed

+40
-47
lines changed

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@
88

99
SDK for building [Saleor Apps](https://github.com/saleor/apps).
1010

11+
Supports Saleor version 3.20+
12+
1113
<div>
1214

1315
[![npm version badge](https://img.shields.io/npm/v/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk)
1416
[![npm downloads count](https://img.shields.io/npm/dt/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk)
1517

1618
</div>
1719

18-
## 🚨 Alpha phase
19-
20-
App SDK is in the early stage at the moment. Every API below 1.x.x release is likely to change.
21-
22-
Feel free to play with SDK and move its code directly to your app.
23-
2420
## Release flow
2521

2622
- The `main` branch is a current, latest branch.

src/handlers/shared/process-saleor-webhook.ts

-38
This file was deleted.

src/handlers/shared/protected-handler.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export type SaleorProtectedHandlerError =
22
| "OTHER"
33
| "MISSING_HOST_HEADER"
4-
| "MISSING_DOMAIN_HEADER"
54
| "MISSING_API_URL_HEADER"
65
| "MISSING_AUTHORIZATION_BEARER_HEADER"
76
| "NOT_REGISTERED"
@@ -11,7 +10,6 @@ export type SaleorProtectedHandlerError =
1110
export const ProtectedHandlerErrorCodeMap: Record<SaleorProtectedHandlerError, number> = {
1211
OTHER: 500,
1312
MISSING_HOST_HEADER: 400,
14-
MISSING_DOMAIN_HEADER: 400,
1513
MISSING_API_URL_HEADER: 400,
1614
NOT_REGISTERED: 401,
1715
JWT_VERIFICATION_FAILED: 401,

src/handlers/shared/saleor-webhook.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SaleorWebhookError } from "./process-saleor-webhook";
1+
import { AuthData } from "../../APL";
22

33
export const WebhookErrorCodeMap: Record<SaleorWebhookError, number> = {
44
OTHER: 500,
@@ -16,3 +16,40 @@ export const WebhookErrorCodeMap: Record<SaleorWebhookError, number> = {
1616
CANT_BE_PARSED: 400,
1717
CONFIGURATION_ERROR: 500,
1818
};
19+
20+
export type SaleorWebhookError =
21+
| "OTHER"
22+
| "MISSING_HOST_HEADER"
23+
| "MISSING_DOMAIN_HEADER"
24+
| "MISSING_API_URL_HEADER"
25+
| "MISSING_EVENT_HEADER"
26+
| "MISSING_PAYLOAD_HEADER"
27+
| "MISSING_SIGNATURE_HEADER"
28+
| "MISSING_REQUEST_BODY"
29+
| "WRONG_EVENT"
30+
| "NOT_REGISTERED"
31+
| "SIGNATURE_VERIFICATION_FAILED"
32+
| "WRONG_METHOD"
33+
| "CANT_BE_PARSED"
34+
| "CONFIGURATION_ERROR";
35+
36+
export class WebhookError extends Error {
37+
errorType: SaleorWebhookError = "OTHER";
38+
39+
constructor(message: string, errorType: SaleorWebhookError) {
40+
super(message);
41+
if (errorType) {
42+
this.errorType = errorType;
43+
}
44+
Object.setPrototypeOf(this, WebhookError.prototype);
45+
}
46+
}
47+
48+
export type WebhookContext<TPayload> = {
49+
baseUrl: string;
50+
event: string;
51+
payload: TPayload;
52+
authData: AuthData;
53+
/** Added in Saleor 3.15 */
54+
schemaVersion: number;
55+
};

0 commit comments

Comments
 (0)