Skip to content

Commit cac0533

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

File tree

10 files changed

+89
-19
lines changed

10 files changed

+89
-19
lines changed

Documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ everything set up correctly and that you are able to listen for events.
209209
ringtoneUrl: "./ringtone.mp3",// optional, defaults to CCP’s default ringtone if a falsy value is set
210210
disableEchoCancellation: false// optional, defaults to false
211211
},
212+
storageAccess: {
213+
canRequest: true, // By default this is set to true. You can set it to false to opt out from checking storage access.
214+
mode: "custom", // To use the default banner, set this to "default"
215+
/** More customization options can be found here: https://docs.aws.amazon.com/connect/latest/adminguide/admin-3pcookies.html#config-grant-access */
216+
},
212217
pageOptions: { //optional
213218
enableAudioDeviceSettings: false, //optional, defaults to 'false'
214219
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": "2.6.7",
3+
"version": "2.6.8",
44
"description": "Amazon Connect Streams Library",
55
"engines": {
66
"node": ">=12.0.0"

release/connect-streams-dr-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-dr.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-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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26297,7 +26297,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
2629726297

2629826298
connect.core = {};
2629926299
connect.core.initialized = false;
26300-
connect.version = "2.6.7";
26300+
connect.version = "2.6.8";
2630126301
connect.outerContextStreamsVersion = null;
2630226302
connect.DEFAULT_BATCH_SIZE = 500;
2630326303

@@ -30473,6 +30473,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3047330473
/* ["custom", "default"] - decides the rsa page view */
3047430474
mode: 'default',
3047530475
custom: {
30476+
hideCCP: true, // only applicable in custom mode
3047630477
/**
3047730478
* Only applicable for custom type RSA page and these messages should be localized by customers
3047830479
*
@@ -30532,7 +30533,13 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3053230533
* Custom Mode will show minimalistic UI - without any Connect references or Connect headers
3053330534
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
3053430535
* */
30535-
const isCustomRequestAccessMode = () => storageParams && storageParams.mode !== 'default';
30536+
const isCustomRequestAccessMode = () => storageParams && storageParams.mode === 'custom';
30537+
30538+
/**
30539+
* Check if the user wants to hide CCP
30540+
* By default this is true
30541+
*/
30542+
const hideCCP = () => storageParams?.custom?.hideCCP;
3053630543

3053730544
const isConnectDomain = (origin) => origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/);
3053830545

@@ -30690,7 +30697,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3069030697

3069130698
requesthandlerUnsubscriber = onRequestHandler({
3069230699
onInit: (messageData) => {
30693-
console.log('%c[INIT]', 'background:lime; color: black; font-size:large');
30700+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
3069430701
connect.getLog().info(`[StorageAccess][onInit] callback executed`).withObject(messageData?.data);
3069530702

3069630703
if (!messageData?.data.hasAccess && isCustomRequestAccessMode()) {
@@ -30699,17 +30706,17 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3069930706
},
3070030707

3070130708
onDeny: () => {
30702-
console.log('%c[DENIED]', 'background:lime; color: black; font-size:large');
30709+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
3070330710
connect.getLog().info(`[StorageAccess][onDeny] callback executed`);
3070430711
if (isCustomRequestAccessMode()) {
3070530712
getRSAContainer().show();
3070630713
}
3070730714
},
3070830715

3070930716
onGrant: () => {
30710-
console.log('%c[Granted]', 'background:lime; color: black; font-size:large');
30717+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
3071130718
connect.getLog().info(`[StorageAccess][onGrant] callback executed`);
30712-
if (isCustomRequestAccessMode()) {
30719+
if (isCustomRequestAccessMode() && hideCCP()) {
3071330720
getRSAContainer().hide();
3071430721
}
3071530722
// Invoke onGrantCallback only once as it setsup initCCP callbacks and events

src/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ declare namespace connect {
347347
};
348348
/** Customize messaging on the request/deny banners */
349349
custom?: {
350+
/**
351+
* provides users the option to specify whether or not to hide CCP Iframe upon granting access when using custom mode
352+
* @default true
353+
*/
354+
hideCCP?: boolean;
350355
header?: string;
351356
title?: string;
352357
accessBannerDescription?: string;

src/request-storage-access.js

Lines changed: 12 additions & 5 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
*
@@ -100,7 +101,13 @@
100101
* Custom Mode will show minimalistic UI - without any Connect references or Connect headers
101102
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
102103
* */
103-
const isCustomRequestAccessMode = () => storageParams && storageParams.mode !== 'default';
104+
const isCustomRequestAccessMode = () => storageParams && storageParams.mode === 'custom';
105+
106+
/**
107+
* Check if the user wants to hide CCP
108+
* By default this is true
109+
*/
110+
const hideCCP = () => storageParams?.custom?.hideCCP;
104111

105112
const isConnectDomain = (origin) => origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/);
106113

@@ -258,7 +265,7 @@
258265

259266
requesthandlerUnsubscriber = onRequestHandler({
260267
onInit: (messageData) => {
261-
console.log('%c[INIT]', 'background:lime; color: black; font-size:large');
268+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
262269
connect.getLog().info(`[StorageAccess][onInit] callback executed`).withObject(messageData?.data);
263270

264271
if (!messageData?.data.hasAccess && isCustomRequestAccessMode()) {
@@ -267,17 +274,17 @@
267274
},
268275

269276
onDeny: () => {
270-
console.log('%c[DENIED]', 'background:lime; color: black; font-size:large');
277+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
271278
connect.getLog().info(`[StorageAccess][onDeny] callback executed`);
272279
if (isCustomRequestAccessMode()) {
273280
getRSAContainer().show();
274281
}
275282
},
276283

277284
onGrant: () => {
278-
console.log('%c[Granted]', 'background:lime; color: black; font-size:large');
285+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
279286
connect.getLog().info(`[StorageAccess][onGrant] callback executed`);
280-
if (isCustomRequestAccessMode()) {
287+
if (isCustomRequestAccessMode() && hideCCP()) {
281288
getRSAContainer().hide();
282289
}
283290
// 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
@@ -90,6 +90,7 @@ describe('Request Storage Access module', () => {
9090
},
9191
mode: 'custom',
9292
custom: {
93+
hideCCP: true,
9394
denyBannerButtonText: 'Try again',
9495
},
9596
};
@@ -207,7 +208,7 @@ describe('Request Storage Access module', () => {
207208
expect(onGrantSpy.calledTwice).not.to.be.true;
208209
});
209210

210-
it('Should hide container if no access for custom types', () => {
211+
it('Should hide container if mode is custom after granting access', () => {
211212
mockMessageFromIframe({
212213
event: connect.storageAccess.storageAccessEvents.GRANTED,
213214
data: {},
@@ -222,7 +223,52 @@ describe('Request Storage Access module', () => {
222223
expect(container.style.display).to.be.equals('none');
223224
});
224225

225-
it('Should display container if no access for custom types', () => {
226+
it('Should not hide container if specified not to hide the iframe in custom mode', () => {
227+
mockMessageFromIframe({
228+
event: connect.storageAccess.storageAccessEvents.GRANTED,
229+
data: {},
230+
});
231+
232+
connect.storageAccess.init(ccpUrl, container, { mode: 'custom', custom: { hideCCP: false } });
233+
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
234+
connect.storageAccess.request();
235+
236+
expect(postMessageSpy.called).to.be.true;
237+
238+
expect(container.style.display).not.to.be.equals('none');
239+
});
240+
241+
it('Should not hide container if mode is default and specified hideCCP to true', () => {
242+
mockMessageFromIframe({
243+
event: connect.storageAccess.storageAccessEvents.GRANTED,
244+
data: {},
245+
});
246+
247+
connect.storageAccess.init(ccpUrl, container, { mode: 'default' , custom: { hideCCP: true } });
248+
connect.storageAccess.setupRequestHandlers({ onGrant: onGrantSpy });
249+
connect.storageAccess.request();
250+
251+
expect(postMessageSpy.called).to.be.true;
252+
253+
expect(container.style.display).not.to.be.equals('none');
254+
});
255+
256+
it('Should not hide container if mode is default', () => {
257+
mockMessageFromIframe({
258+
event: connect.storageAccess.storageAccessEvents.GRANTED,
259+
data: {},
260+
});
261+
262+
connect.storageAccess.init(ccpUrl, container, { mode: 'default' });
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 display container if denied access for custom types', () => {
226272
mockMessageFromIframe({
227273
event: connect.storageAccess.storageAccessEvents.DENIED,
228274
data: {},

0 commit comments

Comments
 (0)