Skip to content

Commit a7e03e6

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

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
@@ -208,6 +208,11 @@ everything set up correctly and that you are able to listen for events.
208208
ringtoneUrl: "./ringtone.mp3",// optional, defaults to CCP’s default ringtone if a falsy value is set
209209
disableEchoCancellation: false// optional, defaults to false
210210
},
211+
storageAccess: {
212+
canRequest: true, // By default this is set to true. You can set it to false to opt out from checking storage access.
213+
mode: "custom", // To use the default banner, set this to "default"
214+
/** More customization options can be found here: https://docs.aws.amazon.com/connect/latest/adminguide/admin-3pcookies.html#config-grant-access */
215+
},
211216
pageOptions: { //optional
212217
enableAudioDeviceSettings: false, //optional, defaults to 'false'
213218
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.7.3",
3+
"version": "2.7.4",
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
@@ -26296,7 +26296,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
2629626296

2629726297
connect.core = {};
2629826298
connect.core.initialized = false;
26299-
connect.version = "2.7.3";
26299+
connect.version = "2.7.4";
2630026300
connect.outerContextStreamsVersion = null;
2630126301
connect.DEFAULT_BATCH_SIZE = 500;
2630226302

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

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

@@ -30689,7 +30696,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3068930696

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

3069530702
if (!messageData?.data.hasAccess && isCustomRequestAccessMode()) {
@@ -30698,17 +30705,17 @@ var __WEBPACK_AMD_DEFINE_RESULT__;// AWS SDK for JavaScript v2.1377.0
3069830705
},
3069930706

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

3070830715
onGrant: () => {
30709-
console.log('%c[Granted]', 'background:lime; color: black; font-size:large');
30716+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
3071030717
connect.getLog().info(`[StorageAccess][onGrant] callback executed`);
30711-
if (isCustomRequestAccessMode()) {
30718+
if (isCustomRequestAccessMode() && hideCCP()) {
3071230719
getRSAContainer().hide();
3071330720
}
3071430721
// 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)