Skip to content

Commit b9f01dd

Browse files
committed
drop domain header
1 parent c367eb2 commit b9f01dd

30 files changed

+20
-145
lines changed

.changeset/tough-socks-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": major
3+
---
4+
5+
Breaking change: Remove checking "domain" header from Saleor requests. It should be replaced with the "saleor-api-url" header.

src/APL/apl.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface AuthData {
2-
domain?: string;
32
token: string;
43
saleorApiUrl: string;
54
appId: string;

src/APL/auth-data-from-object.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ export const authDataFromObject = (parsed: unknown): AuthData | undefined => {
1212
debug("Given object did not contained AuthData");
1313
return undefined;
1414
}
15-
const { saleorApiUrl, appId, domain, token, jwks } = parsed as AuthData;
15+
const { saleorApiUrl, appId, token, jwks } = parsed as AuthData;
1616
return {
1717
saleorApiUrl,
1818
appId,
19-
domain,
2019
token,
2120
jwks,
2221
};

src/APL/env-apl.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const getMockAuthData = (): AuthData => ({
1414
appId: "app-id",
1515
token: "some-token",
1616
jwks: "{}",
17-
domain: "my-saleor-instance.cloud",
1817
});
1918

2019
describe("EnvAPL", () => {
@@ -58,8 +57,7 @@ describe("EnvAPL", () => {
5857
"saleorApiUrl": "https://my-saleor-instance.cloud/graphql/",
5958
"appId": "app-id",
6059
"token": "some-token",
61-
"jwks": "{}",
62-
"domain": "my-saleor-instance.cloud"
60+
"jwks": "{}"
6361
}`
6462
);
6563
});

src/APL/file-apl.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { AuthData } from "./apl";
55
import { FileAPL } from "./file-apl";
66

77
const stubAuthData: AuthData = {
8-
domain: "example.com",
98
token: "example-token",
109
saleorApiUrl: "https://example.com/graphql/",
1110
appId: "42",

src/APL/file-apl.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,17 @@ export class FileAPL implements APL {
4848
return undefined;
4949
}
5050

51-
const { token, domain, saleorApiUrl, appId, jwks } = parsedData;
51+
const { token, saleorApiUrl, appId, jwks } = parsedData;
5252

5353
if (token && saleorApiUrl && appId) {
54-
debug("Token and domain found, returning values: %s, %s", domain, `${token[0]}***`);
54+
debug("Token found, returning values: %s", `${token[0]}***`);
5555

5656
const authData: AuthData = { token, saleorApiUrl, appId };
5757

5858
if (jwks) {
5959
authData.jwks = jwks;
6060
}
6161

62-
if (domain) {
63-
authData.domain = domain;
64-
}
65-
6662
return authData;
6763
}
6864

src/APL/has-auth-data.ts

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { hasProp } from "../has-prop";
44
* Checks if given object has fields used by the AuthData
55
*/
66
export const hasAuthData = (data: unknown) =>
7-
hasProp(data, "domain") &&
8-
data.domain &&
97
hasProp(data, "token") &&
108
data.token &&
119
hasProp(data, "appId") &&

src/APL/saleor-cloud/saleor-cloud-apl.test.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const aplConfig: SaleorCloudAPLConfig = {
1414
};
1515

1616
const stubAuthData: AuthData = {
17-
domain: "example.com",
1817
token: "example-token",
1918
saleorApiUrl: "https://example.com/graphql/",
2019
appId: "42",
@@ -47,7 +46,6 @@ describe("APL", () => {
4746
saleor_app_id: "42",
4847
saleor_api_url: "https://example.com/graphql/",
4948
jwks: "{}",
50-
domain: "example.com",
5149
token: "example-token",
5250
}),
5351
headers: {
@@ -129,7 +127,6 @@ describe("APL", () => {
129127
saleor_app_id: stubAuthData.appId,
130128
saleor_api_url: stubAuthData.saleorApiUrl,
131129
jwks: stubAuthData.jwks,
132-
domain: stubAuthData.domain,
133130
token: stubAuthData.token,
134131
}),
135132
});
@@ -170,7 +167,6 @@ describe("APL", () => {
170167
saleor_app_id: stubAuthData.appId,
171168
saleor_api_url: stubAuthData.saleorApiUrl,
172169
jwks: stubAuthData.jwks,
173-
domain: stubAuthData.domain,
174170
token: stubAuthData.token,
175171
}),
176172
});
@@ -219,7 +215,7 @@ describe("APL", () => {
219215
saleor_app_id: "x",
220216
},
221217
{
222-
domain: "example2.com",
218+
domain: "example.com",
223219
jwks: "{}",
224220
token: "token2",
225221
saleor_api_url: "https://example2.com/graphql/",
@@ -237,14 +233,12 @@ describe("APL", () => {
237233
expect(await apl.getAll()).toStrictEqual([
238234
{
239235
appId: "x",
240-
domain: "example.com",
241236
jwks: "{}",
242237
saleorApiUrl: "https://example.com/graphql/",
243238
token: "token1",
244239
},
245240
{
246241
appId: "y",
247-
domain: "example2.com",
248242
jwks: "{}",
249243
saleorApiUrl: "https://example2.com/graphql/",
250244
token: "token2",
@@ -285,7 +279,7 @@ describe("APL", () => {
285279
previous: "https://example.com?page=1",
286280
results: [
287281
{
288-
domain: "example2.com",
282+
domain: "example.com",
289283
jwks: "{}",
290284
token: "token2",
291285
saleor_api_url: "https://example2.com/graphql/",
@@ -303,14 +297,12 @@ describe("APL", () => {
303297
expect(await apl.getAll()).toStrictEqual([
304298
{
305299
appId: "x",
306-
domain: "example.com",
307300
jwks: "{}",
308301
saleorApiUrl: "https://example.com/graphql/",
309302
token: "token1",
310303
},
311304
{
312305
appId: "y",
313-
domain: "example2.com",
314306
jwks: "{}",
315307
saleorApiUrl: "https://example2.com/graphql/",
316308
token: "token2",

src/APL/saleor-cloud/saleor-cloud-apl.ts

-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ const mapAuthDataToAPIBody = (authData: AuthData) => ({
5151
saleor_app_id: authData.appId,
5252
saleor_api_url: authData.saleorApiUrl,
5353
jwks: authData.jwks,
54-
domain: authData.domain,
5554
token: authData.token,
5655
});
5756

5857
const mapAPIResponseToAuthData = (response: CloudAPLAuthDataShape): AuthData => ({
5958
appId: response.saleor_app_id,
60-
domain: response.domain,
6159
jwks: response.jwks,
6260
saleorApiUrl: response.saleor_api_url,
6361
token: response.token,

src/APL/upstash-apl.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const aplConfig: UpstashAPLConfig = {
1313
};
1414

1515
const stubAuthData: AuthData = {
16-
domain: "example.com",
1716
token: "example-token",
1817
saleorApiUrl: "https://example.com/graphql/",
1918
appId: "42",

src/APL/vercel-kv/vercel-kv-apl.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const getMockAuthData = (saleorApiUrl = "https://demo.saleor.io/graphql"): AuthD
2222
appId: "foobar",
2323
saleorApiUrl,
2424
token: "token",
25-
domain: "domain",
2625
jwks: "{}",
2726
});
2827

src/app-bridge/fetch.test.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from "vitest";
22

3-
import { SALEOR_AUTHORIZATION_BEARER_HEADER, SALEOR_DOMAIN_HEADER } from "../const";
3+
import { SALEOR_AUTHORIZATION_BEARER_HEADER } from "../const";
44
import { AppBridge } from "./app-bridge";
55
import { AppBridgeState } from "./app-bridge-state";
66
import { createAuthenticatedFetch } from "./fetch";
@@ -35,9 +35,6 @@ describe("createAuthenticatedFetch", () => {
3535
const fetchCallArguments = spiedFetch.mock.lastCall;
3636
const fetchCallHeaders = fetchCallArguments![1]?.headers;
3737

38-
expect((fetchCallHeaders as Headers).get(SALEOR_DOMAIN_HEADER)).toBe(
39-
"master.staging.saleor.cloud"
40-
);
4138
expect((fetchCallHeaders as Headers).get(SALEOR_AUTHORIZATION_BEARER_HEADER)).toBe("XXX_YYY");
4239
});
4340

@@ -59,9 +56,6 @@ describe("createAuthenticatedFetch", () => {
5956
const fetchCallArguments = spiedFetch.mock.lastCall;
6057
const fetchCallHeaders = fetchCallArguments![1]?.headers;
6158

62-
expect((fetchCallHeaders as Headers).get(SALEOR_DOMAIN_HEADER)).toBe(
63-
"master.staging.saleor.cloud"
64-
);
6559
expect((fetchCallHeaders as Headers).get(SALEOR_AUTHORIZATION_BEARER_HEADER)).toBe("XXX_YYY");
6660
expect((fetchCallHeaders as Headers).get("foo")).toBe("bar");
6761
});

src/app-bridge/fetch.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { useMemo } from "react";
22

3-
import {
4-
SALEOR_API_URL_HEADER,
5-
SALEOR_AUTHORIZATION_BEARER_HEADER,
6-
SALEOR_DOMAIN_HEADER,
7-
} from "../const";
3+
import { SALEOR_API_URL_HEADER, SALEOR_AUTHORIZATION_BEARER_HEADER } from "../const";
84
import { AppBridge } from "./app-bridge";
95
import { useAppBridge } from "./app-bridge-provider";
106

@@ -16,11 +12,10 @@ type HasAppBridgeState = Pick<AppBridge, "getState">;
1612
export const createAuthenticatedFetch =
1713
(appBridge: HasAppBridgeState, fetch = global.fetch): typeof global.fetch =>
1814
(input, init) => {
19-
const { token, domain, saleorApiUrl } = appBridge.getState();
15+
const { token, saleorApiUrl } = appBridge.getState();
2016

2117
const headers = new Headers(init?.headers);
2218

23-
headers.set(SALEOR_DOMAIN_HEADER, domain);
2419
headers.set(SALEOR_AUTHORIZATION_BEARER_HEADER, token ?? "");
2520
headers.set(SALEOR_API_URL_HEADER, saleorApiUrl ?? "");
2621

src/const.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export const SALEOR_DOMAIN_HEADER = "saleor-domain";
21
export const SALEOR_EVENT_HEADER = "saleor-event";
32
export const SALEOR_SIGNATURE_HEADER = "saleor-signature";
43
export const SALEOR_AUTHORIZATION_BEARER_HEADER = "authorization-bearer";

src/handlers/next/create-app-register-handler.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe("create-app-register-handler", () => {
5252
*/
5353
expect(mockApl.set).toHaveBeenCalledWith({
5454
saleorApiUrl: "https://mock-saleor-domain.saleor.cloud/graphql/",
55-
domain: "https://mock-saleor-domain.saleor.cloud/",
5655
token: "mock-auth-token",
5756
appId: "42",
5857
jwks: "{}",
@@ -122,7 +121,6 @@ describe("create-app-register-handler", () => {
122121

123122
const expectedAuthData: AuthData = {
124123
token: "mock-auth-token",
125-
domain: "https://mock-saleor-domain.saleor.cloud/",
126124
saleorApiUrl: "https://mock-saleor-domain.saleor.cloud/graphql/",
127125
jwks: mockJwksValue,
128126
appId: mockAppId,
@@ -134,7 +132,6 @@ describe("create-app-register-handler", () => {
134132
expect.anything(/* Assume original request */),
135133
expect.objectContaining({
136134
authToken: "mock-auth-token",
137-
saleorDomain: "https://mock-saleor-domain.saleor.cloud/",
138135
saleorApiUrl: "https://mock-saleor-domain.saleor.cloud/graphql/",
139136
})
140137
);
@@ -186,7 +183,6 @@ describe("create-app-register-handler", () => {
186183

187184
const expectedAuthData: AuthData = {
188185
token: "mock-auth-token",
189-
domain: "https://mock-saleor-domain.saleor.cloud/",
190186
saleorApiUrl: "https://mock-saleor-domain.saleor.cloud/graphql/",
191187
jwks: mockJwksValue,
192188
appId: mockAppId,

src/handlers/next/create-app-register-handler.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { withMethod } from "retes/middleware";
44
import { Response } from "retes/response";
55

66
import { AuthData } from "../../APL";
7-
import { SALEOR_API_URL_HEADER, SALEOR_DOMAIN_HEADER } from "../../const";
7+
import { SALEOR_API_URL_HEADER } from "../../const";
88
import { createDebug } from "../../debug";
99
import { fetchRemoteJwks } from "../../fetch-remote-jwks";
1010
import { getAppId } from "../../get-app-id";
11-
import { withAuthTokenRequired, withSaleorDomainPresent } from "../../middleware";
11+
import { withAuthTokenRequired } from "../../middleware";
1212
import { HasAPL } from "../../saleor-app";
1313
import { validateAllowSaleorUrls } from "./validate-allow-saleor-urls";
1414

@@ -134,7 +134,6 @@ export const createAppRegisterHandler = ({
134134
debug("Request received");
135135

136136
const authToken = request.params.auth_token;
137-
const saleorDomain = request.headers[SALEOR_DOMAIN_HEADER] as string;
138137
const saleorApiUrl = request.headers[SALEOR_API_URL_HEADER] as string;
139138

140139
if (onRequestStart) {
@@ -144,7 +143,6 @@ export const createAppRegisterHandler = ({
144143
await onRequestStart(request, {
145144
authToken,
146145
saleorApiUrl,
147-
saleorDomain,
148146
respondWithError: createCallbackError,
149147
});
150148
} catch (e: RegisterCallbackError | unknown) {
@@ -218,7 +216,6 @@ export const createAppRegisterHandler = ({
218216
}
219217

220218
const authData = {
221-
domain: saleorDomain,
222219
token: authToken,
223220
saleorApiUrl,
224221
appId,
@@ -288,10 +285,5 @@ export const createAppRegisterHandler = ({
288285
return Response.OK(createRegisterHandlerResponseBody(true));
289286
};
290287

291-
return toNextHandler([
292-
withMethod("POST"),
293-
withSaleorDomainPresent,
294-
withAuthTokenRequired,
295-
baseHandler,
296-
]);
288+
return toNextHandler([withMethod("POST"), withAuthTokenRequired, baseHandler]);
297289
};

src/handlers/next/process-protected-handler.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ describe("processSaleorProtectedHandler", () => {
5656

5757
expect(await processSaleorProtectedHandler({ apl: mockAPL, req: mockRequest })).toStrictEqual({
5858
authData: {
59-
domain: mockAPL.workingSaleorDomain,
6059
token: mockAPL.mockToken,
6160
saleorApiUrl: mockAPL.workingSaleorApiUrl,
6261
appId: mockAPL.mockAppId,

src/handlers/next/saleor-webhooks/process-saleor-webhook.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ describe("processAsyncSaleorWebhook", () => {
160160
).resolves.toStrictEqual({
161161
authData: {
162162
appId: "mock-app-id",
163-
domain: "example.com",
164163
jwks: "{}",
165164
saleorApiUrl: "https://example.com/graphql/",
166165
token: "mock-token",

src/handlers/next/saleor-webhooks/process-saleor-webhook.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const debug = createDebug("processSaleorWebhook");
1616
export type SaleorWebhookError =
1717
| "OTHER"
1818
| "MISSING_HOST_HEADER"
19-
| "MISSING_DOMAIN_HEADER"
2019
| "MISSING_API_URL_HEADER"
2120
| "MISSING_EVENT_HEADER"
2221
| "MISSING_PAYLOAD_HEADER"

src/handlers/next/saleor-webhooks/saleor-async-webhook.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe("SaleorAsyncWebhook", () => {
6565
payload: { data: "test_payload" },
6666
schemaVersion: 3.19,
6767
authData: {
68-
domain: "example.com",
6968
token: "token",
7069
jwks: "",
7170
saleorApiUrl: "https://example.com/graphql/",

src/handlers/next/saleor-webhooks/saleor-sync-webhook.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe("SaleorSyncWebhook", () => {
1717
payload: { data: "test_payload" },
1818
schemaVersion: 3.19,
1919
authData: {
20-
domain: mockApl.workingSaleorDomain,
2120
token: mockApl.mockToken,
2221
jwks: mockApl.mockJwks,
2322
saleorApiUrl: mockApl.workingSaleorApiUrl,

src/handlers/next/saleor-webhooks/saleor-webhook.ts

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export interface WebhookConfig<Event = AsyncWebhookEventType | SyncWebhookEventT
3939
export const WebhookErrorCodeMap: Record<SaleorWebhookError, number> = {
4040
OTHER: 500,
4141
MISSING_HOST_HEADER: 400,
42-
MISSING_DOMAIN_HEADER: 400,
4342
MISSING_API_URL_HEADER: 400,
4443
MISSING_EVENT_HEADER: 400,
4544
MISSING_PAYLOAD_HEADER: 400,

src/headers.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
SALEOR_API_URL_HEADER,
33
SALEOR_AUTHORIZATION_BEARER_HEADER,
4-
SALEOR_DOMAIN_HEADER,
54
SALEOR_EVENT_HEADER,
65
SALEOR_SCHEMA_VERSION,
76
SALEOR_SIGNATURE_HEADER,
@@ -17,7 +16,6 @@ const toFloatOrNull = (value: string | string[] | undefined) =>
1716
* Extracts Saleor-specific headers from the response.
1817
*/
1918
export const getSaleorHeaders = (headers: { [name: string]: string | string[] | undefined }) => ({
20-
domain: toStringOrUndefined(headers[SALEOR_DOMAIN_HEADER]),
2119
authorizationBearer: toStringOrUndefined(headers[SALEOR_AUTHORIZATION_BEARER_HEADER]),
2220
signature: toStringOrUndefined(headers[SALEOR_SIGNATURE_HEADER]),
2321
event: toStringOrUndefined(headers[SALEOR_EVENT_HEADER]),

0 commit comments

Comments
 (0)