aws-appsync-subscription-link
Advanced tools
Comparing version 2.2.7 to 2.3.0
@@ -53,4 +53,4 @@ import { AUTH_TYPE } from "aws-appsync-auth-link"; | ||
}, | ||
region: 'us-east-1', | ||
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' | ||
region: 'us-west-2', | ||
url: 'https://firsttesturl12345678901234.appsync-api.us-west-2.amazonaws.com/graphql' | ||
}); | ||
@@ -61,2 +61,16 @@ | ||
test("Can instantiate link with custom domain", () => { | ||
expect.assertions(1); | ||
const link = new AppSyncRealTimeSubscriptionHandshakeLink({ | ||
auth: { | ||
type: AUTH_TYPE.API_KEY, | ||
apiKey: 'xxxxx' | ||
}, | ||
region: 'us-west-2', | ||
url: 'https://test1.testcustomdomain.com/graphql' | ||
}); | ||
expect(link).toBeInstanceOf(AppSyncRealTimeSubscriptionHandshakeLink); | ||
}); | ||
test("Initialize WebSocket correctly for API KEY", (done) => { | ||
@@ -68,3 +82,3 @@ expect.assertions(2); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSIsIngtYW16LWRhdGUiOiIyMDE5MTExM1QxODQ3MDRaIiwieC1hcGkta2V5IjoieHh4eHgifQ==&payload=e30='); | ||
expect(url).toBe('wss://apikeytesturl1234567890123.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJob3N0IjoiYXBpa2V5dGVzdHVybDEyMzQ1Njc4OTAxMjMuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20iLCJ4LWFtei1kYXRlIjoiMjAxOTExMTNUMTg0NzA0WiIsIngtYXBpLWtleSI6Inh4eHh4In0=&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
@@ -79,4 +93,4 @@ done(); | ||
}, | ||
region: 'us-east-1', | ||
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' | ||
region: 'us-west-2', | ||
url: 'https://apikeytesturl1234567890123.appsync-api.us-west-2.amazonaws.com/graphql' | ||
}); | ||
@@ -86,3 +100,3 @@ | ||
error: (err) => { | ||
console.log({ err }); | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
@@ -102,2 +116,39 @@ }, | ||
test("Initialize WebSocket correctly for API KEY with custom domain", (done) => { | ||
expect.assertions(2); | ||
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(jest.fn(() => { | ||
return "2019-11-13T18:47:04.733Z"; | ||
})); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://apikeytest.testcustomdomain.com/graphql/realtime?header=eyJob3N0IjoiYXBpa2V5dGVzdC50ZXN0Y3VzdG9tZG9tYWluLmNvbSIsIngtYW16LWRhdGUiOiIyMDE5MTExM1QxODQ3MDRaIiwieC1hcGkta2V5IjoieHh4eHgifQ==&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
done(); | ||
return new myWebSocket(); | ||
}); | ||
const link = new AppSyncRealTimeSubscriptionHandshakeLink({ | ||
auth: { | ||
type: AUTH_TYPE.API_KEY, | ||
apiKey: 'xxxxx' | ||
}, | ||
region: 'us-west-2', | ||
url: 'https://apikeytest.testcustomdomain.com/graphql' | ||
}); | ||
execute(link, { query }).subscribe({ | ||
error: (err) => { | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
}, | ||
next: (data) => { | ||
console.log({ data }); | ||
done(); | ||
}, | ||
complete: () => { | ||
console.log('done with this'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
test("Initialize WebSocket correctly for COGNITO USER POOLS", (done) => { | ||
@@ -109,3 +160,3 @@ expect.assertions(2); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30='); | ||
expect(url).toBe('wss://cognitouserpooltesturl1234.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiY29nbml0b3VzZXJwb29sdGVzdHVybDEyMzQuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ==&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
@@ -120,4 +171,4 @@ done(); | ||
}, | ||
region: 'us-east-1', | ||
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' | ||
region: 'us-west-2', | ||
url: 'https://cognitouserpooltesturl1234.appsync-api.us-west-2.amazonaws.com/graphql' | ||
}); | ||
@@ -127,3 +178,3 @@ | ||
error: (err) => { | ||
console.log({ err }); | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
@@ -143,2 +194,39 @@ }, | ||
test("Initialize WebSocket correctly for COGNITO USER POOLS with custom domain", (done) => { | ||
expect.assertions(2); | ||
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(jest.fn(() => { | ||
return "2019-11-13T18:47:04.733Z"; | ||
})); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://cognitouserpools.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiY29nbml0b3VzZXJwb29scy50ZXN0Y3VzdG9tZG9tYWluLmNvbSJ9&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
done(); | ||
return new myWebSocket(); | ||
}); | ||
const link = new AppSyncRealTimeSubscriptionHandshakeLink({ | ||
auth: { | ||
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, | ||
jwtToken: 'token' | ||
}, | ||
region: 'us-west-2', | ||
url: 'https://cognitouserpools.testcustomdomain.com/graphql' | ||
}); | ||
execute(link, { query }).subscribe({ | ||
error: (err) => { | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
}, | ||
next: (data) => { | ||
console.log({ data }); | ||
done(); | ||
}, | ||
complete: () => { | ||
console.log('done with this'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
test("Initialize WebSocket correctly for OPENID_CONNECT", (done) => { | ||
@@ -150,3 +238,3 @@ expect.assertions(2); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30='); | ||
expect(url).toBe('wss://openidconnecttesturl123456.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0Ijoib3BlbmlkY29ubmVjdHRlc3R1cmwxMjM0NTYuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ==&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
@@ -161,4 +249,4 @@ done(); | ||
}, | ||
region: 'us-east-1', | ||
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' | ||
region: 'us-west-2', | ||
url: 'https://openidconnecttesturl123456.appsync-api.us-west-2.amazonaws.com/graphql' | ||
}); | ||
@@ -168,3 +256,3 @@ | ||
error: (err) => { | ||
console.log({ err }); | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
@@ -184,2 +272,39 @@ }, | ||
test("Initialize WebSocket correctly for OPENID_CONNECT with custom domain", (done) => { | ||
expect.assertions(2); | ||
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(jest.fn(() => { | ||
return "2019-11-13T18:47:04.733Z"; | ||
})); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://openidconnecttesturl.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0Ijoib3BlbmlkY29ubmVjdHRlc3R1cmwudGVzdGN1c3RvbWRvbWFpbi5jb20ifQ==&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
done(); | ||
return new myWebSocket(); | ||
}); | ||
const link = new AppSyncRealTimeSubscriptionHandshakeLink({ | ||
auth: { | ||
type: AUTH_TYPE.OPENID_CONNECT, | ||
jwtToken: 'token' | ||
}, | ||
region: 'us-west-2', | ||
url: 'https://openidconnecttesturl.testcustomdomain.com/graphql' | ||
}); | ||
execute(link, { query }).subscribe({ | ||
error: (err) => { | ||
console.log(JSON.stringify(err)); | ||
fail; | ||
}, | ||
next: (data) => { | ||
console.log({ data }); | ||
done(); | ||
}, | ||
complete: () => { | ||
console.log('done with this'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
test('Initialize WebSocket correctly for AWS_LAMBDA', (done) => { | ||
@@ -191,3 +316,3 @@ expect.assertions(2); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30='); | ||
expect(url).toBe('wss://awslambdatesturl1234567890.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiYXdzbGFtYmRhdGVzdHVybDEyMzQ1Njc4OTAuYXBwc3luYy1hcGkudXMtd2VzdC0yLmFtYXpvbmF3cy5jb20ifQ==&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
@@ -202,4 +327,4 @@ done(); | ||
}, | ||
region: 'us-east-1', | ||
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' | ||
region: 'us-west-2', | ||
url: 'https://awslambdatesturl1234567890.appsync-api.us-west-2.amazonaws.com/graphql' | ||
}); | ||
@@ -221,2 +346,36 @@ | ||
test('Initialize WebSocket correctly for AWS_LAMBDA with custom domain', (done) => { | ||
expect.assertions(2); | ||
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(jest.fn(() => { | ||
return "2019-11-13T18:47:04.733Z"; | ||
})); | ||
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => { | ||
expect(url).toBe('wss://awslambdatesturl.testcustomdomain.com/graphql/realtime?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoiYXdzbGFtYmRhdGVzdHVybC50ZXN0Y3VzdG9tZG9tYWluLmNvbSJ9&payload=e30='); | ||
expect(protocol).toBe('graphql-ws'); | ||
done(); | ||
return new myWebSocket(); | ||
}); | ||
const link = new AppSyncRealTimeSubscriptionHandshakeLink({ | ||
auth: { | ||
type: AUTH_TYPE.AWS_LAMBDA, | ||
token: 'token' | ||
}, | ||
region: 'us-west-2', | ||
url: 'https://awslambdatesturl.testcustomdomain.com/graphql' | ||
}); | ||
execute(link, { query }).subscribe({ | ||
error: (err) => { | ||
fail; | ||
}, | ||
next: (data) => { | ||
done(); | ||
}, | ||
complete: () => { | ||
done(); | ||
} | ||
}); | ||
}) | ||
}); |
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="2.3.0"></a> | ||
# [2.3.0](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.7...aws-appsync-subscription-link@2.3.0) (2022-05-02) | ||
### Features | ||
* add custom domain support for Apollo V2 ([#698](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/698)) ([42db16d](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/42db16d)) | ||
<a name="2.2.7"></a> | ||
@@ -8,0 +19,0 @@ ## [2.2.7](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.5...aws-appsync-subscription-link@2.2.7) (2022-03-04) |
/*! | ||
* Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
@@ -19,2 +19,3 @@ */ | ||
constructor({ url: theUrl, region: theRegion, auth: theAuth }: UrlInfo); | ||
private isCustomDomain; | ||
request(operation: Operation): Observable<FetchResult<{ | ||
@@ -39,3 +40,2 @@ [key: string]: any; | ||
static createWebSocket(awsRealTimeUrl: string, protocol: string): WebSocket; | ||
private static _discoverAppSyncRealTimeEndpoint; | ||
} |
@@ -64,3 +64,3 @@ "use strict"; | ||
/*! | ||
* Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
@@ -97,2 +97,4 @@ */ | ||
var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000; | ||
var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i; | ||
var customDomainPath = '/realtime'; | ||
var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super) { | ||
@@ -112,2 +114,6 @@ __extends(AppSyncRealTimeSubscriptionHandshakeLink, _super); | ||
} | ||
// Check if url matches standard domain pattern | ||
AppSyncRealTimeSubscriptionHandshakeLink.prototype.isCustomDomain = function (url) { | ||
return url.match(standardDomainPattern) === null; | ||
}; | ||
AppSyncRealTimeSubscriptionHandshakeLink.prototype.request = function (operation) { | ||
@@ -359,3 +365,3 @@ var _a; | ||
return new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { | ||
var discoverableEndpoint, payloadString, headerString, _a, _b, headerQs, payloadQs, awsRealTimeUrl, err_2; | ||
var payloadString, headerString, _a, _b, headerQs, payloadQs, discoverableEndpoint, awsRealTimeUrl, err_2; | ||
return __generator(this, function (_c) { | ||
@@ -370,3 +376,2 @@ switch (_c.label) { | ||
this.socketStatus = types_1.SOCKET_STATUS.CONNECTING; | ||
discoverableEndpoint = AppSyncRealTimeSubscriptionHandshakeLink._discoverAppSyncRealTimeEndpoint(this.url); | ||
payloadString = "{}"; | ||
@@ -389,2 +394,12 @@ _b = (_a = JSON).stringify; | ||
payloadQs = Buffer.from(payloadString).toString("base64"); | ||
discoverableEndpoint = appSyncGraphqlEndpoint; | ||
if (this.isCustomDomain(discoverableEndpoint)) { | ||
discoverableEndpoint = discoverableEndpoint.concat(customDomainPath); | ||
} | ||
else { | ||
discoverableEndpoint = discoverableEndpoint.replace('appsync-api', 'appsync-realtime-api').replace('gogi-beta', 'grt-beta'); | ||
} | ||
discoverableEndpoint = discoverableEndpoint | ||
.replace("https://", "wss://") | ||
.replace('http://', 'ws://'); | ||
awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs; | ||
@@ -771,11 +786,4 @@ return [4 /*yield*/, this._initializeRetryableHandshake({ awsRealTimeUrl: awsRealTimeUrl })]; | ||
}; | ||
AppSyncRealTimeSubscriptionHandshakeLink._discoverAppSyncRealTimeEndpoint = function (url) { | ||
return url | ||
.replace("https://", "wss://") | ||
.replace("http://", "ws://") | ||
.replace("appsync-api", "appsync-realtime-api") | ||
.replace("gogi-beta", "grt-beta"); | ||
}; | ||
return AppSyncRealTimeSubscriptionHandshakeLink; | ||
}(apollo_link_1.ApolloLink)); | ||
exports.AppSyncRealTimeSubscriptionHandshakeLink = AppSyncRealTimeSubscriptionHandshakeLink; |
{ | ||
"name": "aws-appsync-subscription-link", | ||
"version": "2.2.7", | ||
"version": "2.3.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
286421
6322