-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from saleor/add-schema-version
Parse schema version when processing saleor webhook
- Loading branch information
Showing
6 changed files
with
80 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@saleor/app-sdk": minor | ||
--- | ||
|
||
Fix wrong logic introduced in [0.49.0](https://github.com/saleor/app-sdk/releases/tag/v0.49.0): there is not header `saleor-schema-version` when app-sdk is processing saleor webhook. This header is only present on install request. | ||
|
||
Now app-sdk will try to parse version from `version` field on GraphQL subscription [Event](https://docs.saleor.io/docs/3.x/api-storefront/miscellaneous/interfaces/event#code-style-fontweight-normal-eventbversionbcodestring-). If field is not present `null` will be returned. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./is-in-iframe"; | ||
export * from "./schema-version"; | ||
export * from "./use-is-mounted"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { parseSchemaVersion } from "./schema-version"; | ||
|
||
describe("parseSchemaVersion", () => { | ||
test.each([ | ||
{ | ||
rawVersion: "3", | ||
parsedVersion: null, | ||
}, | ||
{ | ||
rawVersion: "3.19", | ||
parsedVersion: 3.19, | ||
}, | ||
{ | ||
rawVersion: "3.19.1", | ||
parsedVersion: 3.19, | ||
}, | ||
{ | ||
rawVersion: "malformed", | ||
parsedVersion: null, | ||
}, | ||
{ | ||
rawVersion: "malformed.raw", | ||
parsedVersion: null, | ||
}, | ||
{ | ||
rawVersion: "malformed.raw.version", | ||
parsedVersion: null, | ||
}, | ||
{ | ||
rawVersion: null, | ||
parsedVersion: null, | ||
}, | ||
{ | ||
rawVersion: undefined, | ||
parsedVersion: null, | ||
}, | ||
])( | ||
"Parses version string from: $rawVersion to: $parsedVersion", | ||
({ rawVersion, parsedVersion }) => { | ||
expect(parseSchemaVersion(rawVersion)).toBe(parsedVersion); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const parseSchemaVersion = (rawVersion: string | undefined | null): number | null => { | ||
if (!rawVersion) { | ||
return null; | ||
} | ||
|
||
const [majorString, minorString] = rawVersion.split("."); | ||
const major = parseInt(majorString, 10); | ||
const minor = parseInt(minorString, 10); | ||
|
||
if (major && minor) { | ||
return parseFloat(`${major}.${minor}`); | ||
} | ||
|
||
return null; | ||
}; |