Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Commit e650d67

Browse files
authored
Merge pull request Shopify#310 from Shopify/paulo/update_api_versions
Update supported Admin API versions
2 parents 85458e1 + 519bb4d commit e650d67

File tree

6 files changed

+433
-399
lines changed

6 files changed

+433
-399
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
99

1010
### Added
1111

12+
- ⚠️ [Breaking] Update supported Admin API versions [#310](https://github.com/Shopify/shopify-node-api/pull/310)
1213
- Allow full paths in REST requests [#301](https://github.com/Shopify/shopify-node-api/pull/301)
1314

1415
### Fixed

Diff for: src/base_types.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@ export interface ContextParams {
1616
}
1717

1818
export enum ApiVersion {
19-
April19 = '2019-04',
20-
July19 = '2019-07',
21-
October19 = '2019-10',
22-
January20 = '2020-01',
23-
April20 = '2020-04',
24-
July20 = '2020-07',
25-
October20 = '2020-10',
26-
January21 = '2021-01',
2719
April21 = '2021-04',
2820
July21 = '2021-07',
2921
October21 = '2021-10',
3022
January22 = '2022-01',
23+
April22 = '2022-04',
3124
Unstable = 'unstable',
32-
Unversioned = 'unversioned',
3325
}
3426

3527
export enum ShopifyHeader {

Diff for: src/utils/version-compatible.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export default function versionCompatible(
99
currentVersion: ApiVersion = Context.API_VERSION,
1010
): boolean {
1111
// Return true if not using a dated version
12-
if (
13-
currentVersion === ApiVersion.Unstable ||
14-
currentVersion === ApiVersion.Unversioned
15-
) {
12+
if (currentVersion === ApiVersion.Unstable) {
1613
return true;
1714
}
1815
const numericVersion = (version: string) =>

Diff for: src/webhooks/registry.ts

+17-44
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
RegisterReturn,
1616
WebhookRegistryEntry,
1717
WebhookCheckResponse,
18-
WebhookCheckResponseLegacy,
1918
ShortenedRegisterOptions,
2019
} from './types';
2120

@@ -113,35 +112,20 @@ function isSuccess(
113112
);
114113
}
115114

116-
// 2020-07 onwards
117-
function versionSupportsEndpointField() {
118-
return ShopifyUtilities.versionCompatible(ApiVersion.July20);
119-
}
120-
121115
function versionSupportsPubSub() {
122116
return ShopifyUtilities.versionCompatible(ApiVersion.July21);
123117
}
124118

125119
function validateDeliveryMethod(deliveryMethod: DeliveryMethod) {
126-
if (
127-
deliveryMethod === DeliveryMethod.EventBridge &&
128-
!versionSupportsEndpointField()
129-
) {
130-
throw new ShopifyErrors.UnsupportedClientType(
131-
`EventBridge webhooks are not supported in API version "${Context.API_VERSION}".`,
132-
);
133-
} else if (
134-
deliveryMethod === DeliveryMethod.PubSub &&
135-
!versionSupportsPubSub()
136-
) {
120+
if (deliveryMethod === DeliveryMethod.PubSub && !versionSupportsPubSub()) {
137121
throw new ShopifyErrors.UnsupportedClientType(
138122
`Pub/Sub webhooks are not supported in API version "${Context.API_VERSION}".`,
139123
);
140124
}
141125
}
142126

143127
function buildCheckQuery(topic: string): string {
144-
const query = `{
128+
return `{
145129
webhookSubscriptions(first: 1, topics: ${topic}) {
146130
edges {
147131
node {
@@ -167,19 +151,6 @@ function buildCheckQuery(topic: string): string {
167151
}
168152
}
169153
}`;
170-
171-
const legacyQuery = `{
172-
webhookSubscriptions(first: 1, topics: ${topic}) {
173-
edges {
174-
node {
175-
id
176-
callbackUrl
177-
}
178-
}
179-
}
180-
}`;
181-
182-
return versionSupportsEndpointField() ? query : legacyQuery;
183154
}
184155

185156
function buildQuery(
@@ -243,7 +214,10 @@ function buildQuery(
243214
const WebhooksRegistry: RegistryInterface = {
244215
webhookRegistry: {},
245216

246-
addHandler(topic: string, {path, webhookHandler}: WebhookRegistryEntry): void {
217+
addHandler(
218+
topic: string,
219+
{path, webhookHandler}: WebhookRegistryEntry,
220+
): void {
247221
WebhooksRegistry.webhookRegistry[topic] = {path, webhookHandler};
248222
},
249223

@@ -256,7 +230,7 @@ const WebhooksRegistry: RegistryInterface = {
256230
},
257231

258232
getHandler(topic: string): WebhookRegistryEntry | null {
259-
return topic in WebhooksRegistry.webhookRegistry ? WebhooksRegistry.webhookRegistry[topic] : null;
233+
return WebhooksRegistry.webhookRegistry[topic] ?? null;
260234
},
261235

262236
getTopics(): string[] {
@@ -279,21 +253,18 @@ const WebhooksRegistry: RegistryInterface = {
279253
: path;
280254
const checkResult = (await client.query({
281255
data: buildCheckQuery(topic),
282-
})) as {body: WebhookCheckResponse | WebhookCheckResponseLegacy;};
256+
})) as {body: WebhookCheckResponse;};
283257
let webhookId: string | undefined;
284258
let mustRegister = true;
285259
if (checkResult.body.data.webhookSubscriptions.edges.length) {
286260
const {node} = checkResult.body.data.webhookSubscriptions.edges[0];
287261
let endpointAddress = '';
288-
if ('endpoint' in node) {
289-
if (node.endpoint.__typename === 'WebhookHttpEndpoint') {
290-
endpointAddress = node.endpoint.callbackUrl;
291-
} else if (node.endpoint.__typename === 'WebhookEventBridgeEndpoint') {
292-
endpointAddress = node.endpoint.arn;
293-
}
294-
} else {
295-
endpointAddress = node.callbackUrl;
262+
if (node.endpoint.__typename === 'WebhookHttpEndpoint') {
263+
endpointAddress = node.endpoint.callbackUrl;
264+
} else if (node.endpoint.__typename === 'WebhookEventBridgeEndpoint') {
265+
endpointAddress = node.endpoint.arn;
296266
}
267+
297268
webhookId = node.id;
298269
if (endpointAddress === address) {
299270
mustRegister = false;
@@ -336,7 +307,7 @@ const WebhooksRegistry: RegistryInterface = {
336307
shop,
337308
deliveryMethod,
338309
};
339-
const returnedRegister: RegisterReturn = await WebhooksRegistry.register(webhook);
310+
const returnedRegister = await WebhooksRegistry.register(webhook);
340311
registerReturn = {...registerReturn, ...returnedRegister};
341312
}
342313
}
@@ -414,7 +385,9 @@ const WebhooksRegistry: RegistryInterface = {
414385
.digest('base64');
415386

416387
if (ShopifyUtilities.safeCompare(generatedHash, hmac as string)) {
417-
const graphqlTopic = (topic as string).toUpperCase().replace(/\//g, '_');
388+
const graphqlTopic = (topic as string)
389+
.toUpperCase()
390+
.replace(/\//g, '_');
418391
const webhookEntry = WebhooksRegistry.getHandler(graphqlTopic);
419392

420393
if (webhookEntry) {

0 commit comments

Comments
 (0)