Skip to content

Commit 8dc8d4a

Browse files
authored
Improved exported paths, added NextAppRouter specific platform (#418)
* export webApiWebhookHandler * generics for next app router * auth/browser * new export paths * remove auth/browser * update header name * fix auth export * fix exports * remove domain from app bridge state
1 parent 5e4eb20 commit 8dc8d4a

File tree

62 files changed

+448
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+448
-316
lines changed

.changeset/angry-boats-kick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": major
3+
---
4+
5+
Changed publically exported paths. New exports will be documented in docs and migration guide

.changeset/stale-flowers-serve.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": major
3+
---
4+
5+
Added new root exports: auth/browser and auth/node for token-related utilities

package.json

+12-17
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@
143143
"import": "./settings-manager/index.mjs",
144144
"require": "./settings-manager/index.js"
145145
},
146-
"./urls": {
147-
"types": "./urls.d.ts",
148-
"import": "./urls.mjs",
149-
"require": "./urls.js"
150-
},
151146
"./app-bridge": {
152147
"types": "./app-bridge/index.d.ts",
153148
"import": "./app-bridge/index.mjs",
@@ -188,25 +183,25 @@
188183
"import": "./saleor-app.mjs",
189184
"require": "./saleor-app.js"
190185
},
191-
"./verify-jwt": {
192-
"types": "./verify-jwt.d.ts",
193-
"import": "./verify-jwt.mjs",
194-
"require": "./verify-jwt.js"
195-
},
196-
"./verify-signature": {
197-
"types": "./verify-signature.d.ts",
198-
"import": "./verify-signature.mjs",
199-
"require": "./verify-signature.js"
186+
"./auth": {
187+
"types": "./auth/index.d.ts",
188+
"import": "./auth/index.mjs",
189+
"require": "./auth/index.js"
200190
},
201191
"./headers": {
202192
"types": "./headers.d.ts",
203193
"import": "./headers.mjs",
204194
"require": "./headers.js"
205195
},
206196
"./util": {
207-
"types": "./util/public/index.d.ts",
208-
"import": "./util/public/index.mjs",
209-
"require": "./util/public/index.js"
197+
"types": "./util/index.d.ts",
198+
"import": "./util/index.mjs",
199+
"require": "./util/index.js"
200+
},
201+
"./util/browser": {
202+
"types": "./util/public/browser/index.d.ts",
203+
"import": "./util/public/browser/index.mjs",
204+
"require": "./util/public/browser/index.js"
210205
},
211206
"./types": {
212207
"types": "./types.d.ts"

src/app-bridge/app-bridge-provider.test.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ describe("AppBridgeProvider", () => {
3939
<AppBridgeProvider
4040
appBridgeInstance={
4141
new AppBridge({
42-
targetDomain: domain,
4342
saleorApiUrl,
4443
})
4544
}
@@ -77,19 +76,18 @@ describe("useAppBridge hook", () => {
7776

7877
it("Returned instance provided in Provider", () => {
7978
const appBridge = new AppBridge({
80-
targetDomain: domain,
79+
saleorApiUrl,
8180
});
8281

8382
const { result } = renderHook(() => useAppBridge(), {
8483
wrapper: (props: {}) => <AppBridgeProvider {...props} appBridgeInstance={appBridge} />,
8584
});
8685

87-
expect(result.current.appBridge?.getState().domain).toBe(domain);
86+
expect(result.current.appBridge?.getState().saleorApiUrl).toBe(saleorApiUrl);
8887
});
8988

9089
it("Stores active state in React State", () => {
9190
const appBridge = new AppBridge({
92-
targetDomain: domain,
9391
saleorApiUrl,
9492
});
9593

@@ -120,7 +118,6 @@ describe("useAppBridge hook", () => {
120118
return waitFor(() => {
121119
expect(renderCallback).toHaveBeenCalledTimes(2);
122120
expect(renderCallback).toHaveBeenCalledWith({
123-
domain,
124121
id: "appid",
125122
path: "",
126123
ready: false,

src/app-bridge/app-bridge-state.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ describe("app-bridge-state.ts", () => {
88

99
expect(instance.getState()).toEqual({
1010
id: "",
11-
domain: "",
1211
ready: false,
1312
path: "/",
1413
theme: "light",
@@ -21,7 +20,6 @@ describe("app-bridge-state.ts", () => {
2120
const instance = new AppBridgeStateContainer();
2221

2322
const newState: Partial<AppBridgeState> = {
24-
domain: "my-saleor-instance.cloud",
2523
saleorApiUrl: "https://my-saleor-instance.cloud/graphql/",
2624
id: "foo-bar",
2725
path: "/",
@@ -42,15 +40,15 @@ describe("app-bridge-state.ts", () => {
4240
expect(
4341
new AppBridgeStateContainer({
4442
initialLocale: "pl",
45-
}).getState().locale
43+
}).getState().locale,
4644
).toBe("pl");
4745
});
4846

4947
it("Can be constructed with initial theme", () => {
5048
expect(
5149
new AppBridgeStateContainer({
5250
initialTheme: "dark",
53-
}).getState().theme
51+
}).getState().theme,
5452
).toBe("dark");
5553
});
5654
});

src/app-bridge/app-bridge-state.ts

-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ export type AppBridgeState = {
66
token?: string;
77
id: string;
88
ready: boolean;
9-
domain: string;
109
path: string;
1110
theme: ThemeType;
1211
locale: LocaleCode;
1312
saleorApiUrl: string;
14-
/**
15-
* Versions of Saleor that app is mounted. Passed from the Dashboard.
16-
* Works form Saleor 3.15
17-
*/
1813
saleorVersion?: string;
1914
dashboardVersion?: string;
2015
user?: {
@@ -39,7 +34,6 @@ type Options = {
3934
export class AppBridgeStateContainer {
4035
private state: AppBridgeState = {
4136
id: "",
42-
domain: "",
4337
saleorApiUrl: "",
4438
ready: false,
4539
path: "/",

src/app-bridge/app-bridge.test.ts

+12-28
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const mockDashboardActionResponse = (actionType: ActionType, actionID: string) =
6565
payload: { ok: true, actionId: actionID },
6666
} as DispatchResponseEvent,
6767
origin,
68-
})
68+
}),
6969
);
7070
}
7171
}
@@ -96,10 +96,6 @@ describe("AppBridge", () => {
9696
vi.clearAllMocks();
9797
});
9898

99-
it("correctly sets the default domain, if not set in constructor", () => {
100-
expect(appBridge.getState().domain).toEqual(domain);
101-
});
102-
10399
it("authenticates", () => {
104100
expect(appBridge.getState().ready).toBe(false);
105101

@@ -109,7 +105,7 @@ describe("AppBridge", () => {
109105
new MessageEvent("message", {
110106
data: { type: "handshake", payload: { token } },
111107
origin,
112-
})
108+
}),
113109
);
114110

115111
expect(appBridge.getState().ready).toBe(true);
@@ -135,7 +131,7 @@ describe("AppBridge", () => {
135131
new MessageEvent("message", {
136132
data: handshakeEvent,
137133
origin,
138-
})
134+
}),
139135
);
140136

141137
// incorrect event type
@@ -144,7 +140,7 @@ describe("AppBridge", () => {
144140
new MessageEvent("message", {
145141
data: { type: "invalid", payload: { token: "invalid" } },
146142
origin,
147-
})
143+
}),
148144
);
149145

150146
// incorrect origin
@@ -153,7 +149,7 @@ describe("AppBridge", () => {
153149
new MessageEvent("message", {
154150
data: { type: "handshake", payload: { token } },
155151
origin: "http://wrong.origin.com",
156-
})
152+
}),
157153
);
158154

159155
expect(callback).toHaveBeenCalledTimes(1);
@@ -168,7 +164,7 @@ describe("AppBridge", () => {
168164
new MessageEvent("message", {
169165
data: { type: "handshake", payload: { token: validJwtToken } },
170166
origin,
171-
})
167+
}),
172168
);
173169

174170
expect(callback).toHaveBeenCalledTimes(1);
@@ -188,7 +184,7 @@ describe("AppBridge", () => {
188184
new MessageEvent("message", {
189185
data: themeEvent,
190186
origin,
191-
})
187+
}),
192188
);
193189

194190
expect(callback).toHaveBeenCalledOnce();
@@ -197,10 +193,6 @@ describe("AppBridge", () => {
197193
unsubscribe();
198194
});
199195

200-
it("persists domain", () => {
201-
expect(appBridge.getState().domain).toEqual(domain);
202-
});
203-
204196
it("dispatches valid action", () => {
205197
const target = "/test";
206198
const action = actions.Redirect({ to: target });
@@ -225,7 +217,7 @@ describe("AppBridge", () => {
225217
new MessageEvent("message", {
226218
data: handshakeEvent,
227219
origin,
228-
})
220+
}),
229221
);
230222

231223
expect(cb1).toHaveBeenCalledTimes(1);
@@ -238,21 +230,13 @@ describe("AppBridge", () => {
238230
new MessageEvent("message", {
239231
data: handshakeEvent,
240232
origin,
241-
})
233+
}),
242234
);
243235

244236
expect(cb1).toHaveBeenCalledTimes(1);
245237
expect(cb2).toHaveBeenCalledTimes(1);
246238
});
247239

248-
it("attaches domain from options in constructor", () => {
249-
appBridge = new AppBridge({
250-
targetDomain: "https://foo.bar",
251-
});
252-
253-
expect(appBridge.getState().domain).toEqual("https://foo.bar");
254-
});
255-
256240
it.each<LocaleCode>(["pl", "en", "it"])("sets initial locale \"%s\" from constructor", (locale) => {
257241
const instance = new AppBridge({
258242
initialLocale: locale,
@@ -306,7 +290,7 @@ describe("AppBridge", () => {
306290
new MessageEvent("message", {
307291
data: handshakeEvent,
308292
origin,
309-
})
293+
}),
310294
);
311295

312296
expect(appBridge.getState().token).toEqual(handshakeEvent.payload.token);
@@ -316,7 +300,7 @@ describe("AppBridge", () => {
316300
new MessageEvent("message", {
317301
data: tokenRefreshEvent,
318302
origin,
319-
})
303+
}),
320304
);
321305

322306
expect(appBridge.getState().token).toEqual(tokenRefreshEvent.payload.token);
@@ -334,7 +318,7 @@ describe("AppBridge", () => {
334318
dashboard: "3.15.1",
335319
}),
336320
origin,
337-
})
321+
}),
338322
);
339323

340324
expect(appBridge.getState().token).toEqual(validJwtToken);

0 commit comments

Comments
 (0)