Skip to content

Commit 1598a1f

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

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
@@ -168,6 +168,11 @@ everything set up correctly and that you are able to listen for events.
168168
disableRingtone: false, // optional, defaults to false
169169
ringtoneUrl: "./ringtone.mp3" // optional, defaults to CCP’s default ringtone if a falsy value is set
170170
},
171+
storageAccess: {
172+
canRequest: true, // By default this is set to true. You can set it to false to opt out from checking storage access.
173+
mode: "custom", // To use the default banner, set this to "default"
174+
/** More customization options can be found here: https://docs.aws.amazon.com/connect/latest/adminguide/admin-3pcookies.html#config-grant-access */
175+
},
171176
pageOptions: { //optional
172177
enableAudioDeviceSettings: false, //optional, defaults to 'false'
173178
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.7.7",
3+
"version": "1.7.8",
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
@@ -5991,7 +5991,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
59915991
global.lily = connect;
59925992
connect.core = {};
59935993
connect.core.initialized = false;
5994-
connect.version = "1.7.7";
5994+
connect.version = "1.7.8";
59955995
connect.DEFAULT_BATCH_SIZE = 500;
59965996
var CCP_SYN_TIMEOUT = 1000; // 1 sec
59975997
var CCP_ACK_TIMEOUT = 3000; // 3 sec
@@ -9469,6 +9469,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
94699469
/* ["custom", "default"] - decides the rsa page view */
94709470
mode: "default",
94719471
custom: {
9472+
hideCCP: true // only applicable in custom mode
94729473
/**
94739474
* Only applicable for custom type RSA page and these messages should be localized by customers
94749475
*
@@ -9478,6 +9479,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
94789479
*/
94799480
}
94809481
};
9482+
94819483
var storageParams = {};
94829484
var originalCCPUrl = "";
94839485
var rsaContainer = null;
@@ -9523,7 +9525,16 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
95239525
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
95249526
* */
95259527
var isCustomRequestAccessMode = function isCustomRequestAccessMode() {
9526-
return storageParams && storageParams.mode !== "default";
9528+
return storageParams && storageParams.mode === 'custom';
9529+
};
9530+
9531+
/**
9532+
* Check if the user wants to hide CCP
9533+
* By default this is true
9534+
*/
9535+
var hideCCP = function hideCCP() {
9536+
var _storageParams;
9537+
return (_storageParams = storageParams) === null || _storageParams === void 0 || (_storageParams = _storageParams.custom) === null || _storageParams === void 0 ? void 0 : _storageParams.hideCCP;
95279538
};
95289539
var isConnectDomain = function isConnectDomain(origin) {
95299540
return origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/);
@@ -9676,23 +9687,23 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
96769687
}
96779688
requesthandlerUnsubscriber = onRequestHandler({
96789689
onInit: function onInit(messageData) {
9679-
console.log("%c[INIT]", "background:lime; color: black; font-size:large");
9690+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
96809691
connect.getLog().info("[StorageAccess][onInit] callback executed").withObject(messageData === null || messageData === void 0 ? void 0 : messageData.data);
96819692
if (!(messageData !== null && messageData !== void 0 && messageData.data.hasAccess) && isCustomRequestAccessMode()) {
96829693
getRSAContainer().show();
96839694
}
96849695
},
96859696
onDeny: function onDeny() {
9686-
console.log("%c[DENIED]", "background:lime; color: black; font-size:large");
9697+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
96879698
connect.getLog().info("[StorageAccess][onDeny] callback executed");
96889699
if (isCustomRequestAccessMode()) {
96899700
getRSAContainer().show();
96909701
}
96919702
},
96929703
onGrant: function onGrant() {
9693-
console.log("%c[Granted]", "background:lime; color: black; font-size:large");
9704+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
96949705
connect.getLog().info("[StorageAccess][onGrant] callback executed");
9695-
if (isCustomRequestAccessMode()) {
9706+
if (isCustomRequestAccessMode() && hideCCP()) {
96969707
getRSAContainer().hide();
96979708
}
96989709
// 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)