Skip to content

Commit 61344d9

Browse files
andywang219Andy Wang
andauthored
Adding new param to support hiding/ showing CCP for request storage access after access granted (#796)
Co-authored-by: Andy Wang <wangdy@amazon.com>
1 parent b20771f commit 61344d9

File tree

7 files changed

+86
-27
lines changed

7 files changed

+86
-27
lines changed

Documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ everything set up correctly and that you are able to listen for events.
170170
disableRingtone: false, // optional, defaults to false
171171
ringtoneUrl: "./ringtone.mp3" // optional, defaults to CCP’s default ringtone if a falsy value is set
172172
},
173+
storageAccess: {
174+
canRequest: true, // By default this is set to true. You can set it to false to opt out from checking storage access.
175+
mode: "custom", // To use the default banner, set this to "default"
176+
/** More customization options can be found here: https://docs.aws.amazon.com/connect/latest/adminguide/admin-3pcookies.html#config-grant-access */
177+
},
173178
pageOptions: { //optional
174179
enableAudioDeviceSettings: false, //optional, defaults to 'false'
175180
enablePhoneTypeSettings: true //optional, defaults to 'true'

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amazon-connect-streams",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"description": "Amazon Connect Streams Library",
55
"engines": {
66
"node": ">=12.0.0"

release/connect-streams-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/connect-streams.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5990,7 +5990,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
59905990
global.lily = connect;
59915991
connect.core = {};
59925992
connect.core.initialized = false;
5993-
connect.version = "1.8.1";
5993+
connect.version = "1.8.2";
59945994
connect.DEFAULT_BATCH_SIZE = 500;
59955995
var CCP_SYN_TIMEOUT = 1000; // 1 sec
59965996
var CCP_ACK_TIMEOUT = 3000; // 3 sec
@@ -9468,6 +9468,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
94689468
/* ["custom", "default"] - decides the rsa page view */
94699469
mode: "default",
94709470
custom: {
9471+
hideCCP: true // only applicable in custom mode
94719472
/**
94729473
* Only applicable for custom type RSA page and these messages should be localized by customers
94739474
*
@@ -9477,6 +9478,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
94779478
*/
94789479
}
94799480
};
9481+
94809482
var storageParams = {};
94819483
var originalCCPUrl = "";
94829484
var rsaContainer = null;
@@ -9522,7 +9524,16 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
95229524
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
95239525
* */
95249526
var isCustomRequestAccessMode = function isCustomRequestAccessMode() {
9525-
return storageParams && storageParams.mode !== "default";
9527+
return storageParams && storageParams.mode === 'custom';
9528+
};
9529+
9530+
/**
9531+
* Check if the user wants to hide CCP
9532+
* By default this is true
9533+
*/
9534+
var hideCCP = function hideCCP() {
9535+
var _storageParams;
9536+
return (_storageParams = storageParams) === null || _storageParams === void 0 || (_storageParams = _storageParams.custom) === null || _storageParams === void 0 ? void 0 : _storageParams.hideCCP;
95269537
};
95279538
var isConnectDomain = function isConnectDomain(origin) {
95289539
return origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/);
@@ -9675,23 +9686,23 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
96759686
}
96769687
requesthandlerUnsubscriber = onRequestHandler({
96779688
onInit: function onInit(messageData) {
9678-
console.log("%c[INIT]", "background:lime; color: black; font-size:large");
9689+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
96799690
connect.getLog().info("[StorageAccess][onInit] callback executed").withObject(messageData === null || messageData === void 0 ? void 0 : messageData.data);
96809691
if (!(messageData !== null && messageData !== void 0 && messageData.data.hasAccess) && isCustomRequestAccessMode()) {
96819692
getRSAContainer().show();
96829693
}
96839694
},
96849695
onDeny: function onDeny() {
9685-
console.log("%c[DENIED]", "background:lime; color: black; font-size:large");
9696+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
96869697
connect.getLog().info("[StorageAccess][onDeny] callback executed");
96879698
if (isCustomRequestAccessMode()) {
96889699
getRSAContainer().show();
96899700
}
96909701
},
96919702
onGrant: function onGrant() {
9692-
console.log("%c[Granted]", "background:lime; color: black; font-size:large");
9703+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
96939704
connect.getLog().info("[StorageAccess][onGrant] callback executed");
9694-
if (isCustomRequestAccessMode()) {
9705+
if (isCustomRequestAccessMode() && hideCCP()) {
96959706
getRSAContainer().hide();
96969707
}
96979708
// Invoke onGrantCallback only once as it setsup initCCP callbacks and events

src/request-storage-access.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
/* ["custom", "default"] - decides the rsa page view */
4242
mode: "default",
4343
custom: {
44+
hideCCP: true, // only applicable in custom mode
4445
/**
4546
* Only applicable for custom type RSA page and these messages should be localized by customers
4647
*
@@ -102,8 +103,13 @@
102103
* Custom Mode will show minimalistic UI - without any Connect references or Connect headers
103104
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
104105
* */
105-
const isCustomRequestAccessMode = () =>
106-
storageParams && storageParams.mode !== "default";
106+
const isCustomRequestAccessMode = () => storageParams && storageParams.mode === 'custom';
107+
108+
/**
109+
* Check if the user wants to hide CCP
110+
* By default this is true
111+
*/
112+
const hideCCP = () => storageParams?.custom?.hideCCP;
107113

108114
const isConnectDomain = (origin) =>
109115
origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/);
@@ -283,10 +289,7 @@
283289

284290
requesthandlerUnsubscriber = onRequestHandler({
285291
onInit: (messageData) => {
286-
console.log(
287-
"%c[INIT]",
288-
"background:lime; color: black; font-size:large"
289-
);
292+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
290293
connect
291294
.getLog()
292295
.info(`[StorageAccess][onInit] callback executed`)
@@ -298,23 +301,17 @@
298301
},
299302

300303
onDeny: () => {
301-
console.log(
302-
"%c[DENIED]",
303-
"background:lime; color: black; font-size:large"
304-
);
304+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
305305
connect.getLog().info(`[StorageAccess][onDeny] callback executed`);
306306
if (isCustomRequestAccessMode()) {
307307
getRSAContainer().show();
308308
}
309309
},
310310

311311
onGrant: () => {
312-
console.log(
313-
"%c[Granted]",
314-
"background:lime; color: black; font-size:large"
315-
);
312+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
316313
connect.getLog().info(`[StorageAccess][onGrant] callback executed`);
317-
if (isCustomRequestAccessMode()) {
314+
if (isCustomRequestAccessMode() && hideCCP()) {
318315
getRSAContainer().hide();
319316
}
320317
// Invoke onGrantCallback only once as it setsup initCCP callbacks and events

test/unit/request-storage-access.spec.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe("Request Storage Access module", () => {
9696
},
9797
mode: "custom",
9898
custom: {
99+
hideCCP: true,
99100
denyBannerButtonText: "Try again",
100101
},
101102
};
@@ -237,7 +238,7 @@ describe("Request Storage Access module", () => {
237238
expect(onGrantSpy.calledTwice).not.to.be.true;
238239
});
239240

240-
it("Should hide container if no access for custom types", () => {
241+
it('Should hide container if mode is custom after granting access', () => {
241242
mockMessageFromIframe({
242243
event: connect.storageAccess.storageAccessEvents.GRANTED,
243244
data: {},
@@ -252,7 +253,52 @@ describe("Request Storage Access module", () => {
252253
expect(container.style.display).to.be.equals("none");
253254
});
254255

255-
it("Should display container if no access for custom types", () => {
256+
it('Should not hide container if specified not to hide the iframe in custom mode', () => {
257+
mockMessageFromIframe({
258+
event: connect.storageAccess.storageAccessEvents.GRANTED,
259+
data: {},
260+
});
261+
262+
connect.storageAccess.init(ccpUrl, container, { mode: 'custom', custom: { hideCCP: false } });
263+
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
264+
connect.storageAccess.request();
265+
266+
expect(postMessageSpy.called).to.be.true;
267+
268+
expect(container.style.display).not.to.be.equals('none');
269+
});
270+
271+
it('Should not hide container if mode is default and specified hideCCP to true', () => {
272+
mockMessageFromIframe({
273+
event: connect.storageAccess.storageAccessEvents.GRANTED,
274+
data: {},
275+
});
276+
277+
connect.storageAccess.init(ccpUrl, container, { mode: 'default' , custom: { hideCCP: true } });
278+
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
279+
connect.storageAccess.request();
280+
281+
expect(postMessageSpy.called).to.be.true;
282+
283+
expect(container.style.display).not.to.be.equals('none');
284+
});
285+
286+
it('Should not hide container if mode is default', () => {
287+
mockMessageFromIframe({
288+
event: connect.storageAccess.storageAccessEvents.GRANTED,
289+
data: {},
290+
});
291+
292+
connect.storageAccess.init(ccpUrl, container, { mode: 'default' });
293+
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
294+
connect.storageAccess.request();
295+
296+
expect(postMessageSpy.called).to.be.true;
297+
298+
expect(container.style.display).not.to.be.equals('none');
299+
});
300+
301+
it('Should display container if denied access for custom types', () => {
256302
mockMessageFromIframe({
257303
event: connect.storageAccess.storageAccessEvents.DENIED,
258304
data: {},

0 commit comments

Comments
 (0)