Skip to content

Commit d7fc746

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

File tree

8 files changed

+87
-17
lines changed

8 files changed

+87
-17
lines changed

Documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ everything set up correctly and that you are able to listen for events.
201201
disableRingtone: false, // optional, defaults to false
202202
ringtoneUrl: "./ringtone.mp3" // optional, defaults to CCP’s default ringtone if a falsy value is set
203203
},
204+
storageAccess: {
205+
canRequest: true, // By default this is set to true. You can set it to false to opt out from checking storage access.
206+
mode: "custom", // To use the default banner, set this to "default"
207+
/** More customization options can be found here: https://docs.aws.amazon.com/connect/latest/adminguide/admin-3pcookies.html#config-grant-access */
208+
},
204209
pageOptions: { //optional
205210
enableAudioDeviceSettings: false, //optional, defaults to 'false'
206211
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.4.11",
3+
"version": "2.4.12",
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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25652,7 +25652,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
2565225652

2565325653
connect.core = {};
2565425654
connect.core.initialized = false;
25655-
connect.version = "2.4.11";
25655+
connect.version = "2.4.12";
2565625656
connect.DEFAULT_BATCH_SIZE = 500;
2565725657

2565825658
var CCP_SYN_TIMEOUT = 1000; // 1 sec
@@ -29348,6 +29348,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
2934829348
/* ["custom", "default"] - decides the rsa page view */
2934929349
mode: 'default',
2935029350
custom: {
29351+
hideCCP: true, // only applicable in custom mode
2935129352
/**
2935229353
* Only applicable for custom type RSA page and these messages should be localized by customers
2935329354
*
@@ -29407,7 +29408,13 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
2940729408
* Custom Mode will show minimalistic UI - without any Connect references or Connect headers
2940829409
* This will allow fully Custom CCPs to use banner and use minimal real estate to show the storage access Content
2940929410
* */
29410-
const isCustomRequestAccessMode = () => storageParams && storageParams.mode !== 'default';
29411+
const isCustomRequestAccessMode = () => storageParams && storageParams.mode === 'custom';
29412+
29413+
/**
29414+
* Check if the user wants to hide CCP
29415+
* By default this is true
29416+
*/
29417+
const hideCCP = () => storageParams?.custom?.hideCCP;
2941129418

2941229419
const isConnectDomain = (origin) => origin.match(/.connect.aws.a2z.com|.my.connect.aws|.govcloud.connect.aws|.awsapps.com/)
2941329420

@@ -29565,7 +29572,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
2956529572

2956629573
requesthandlerUnsubscriber = onRequestHandler({
2956729574
onInit: (messageData) => {
29568-
console.log('%c[INIT]', 'background:lime; color: black; font-size:large');
29575+
console.log('%c[StorageAccess][INIT]', 'background:yellow; color:black; font-size:large');
2956929576
connect.getLog().info(`[StorageAccess][onInit] callback executed`).withObject(messageData?.data);
2957029577

2957129578
if (!messageData?.data.hasAccess && isCustomRequestAccessMode()) {
@@ -29574,17 +29581,17 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
2957429581
},
2957529582

2957629583
onDeny: () => {
29577-
console.log('%c[DENIED]', 'background:lime; color: black; font-size:large');
29584+
console.log('%c[StorageAccess][DENIED]', 'background:red; color:black; font-size:large');
2957829585
connect.getLog().info(`[StorageAccess][onDeny] callback executed`);
2957929586
if (isCustomRequestAccessMode()) {
2958029587
getRSAContainer().show();
2958129588
}
2958229589
},
2958329590

2958429591
onGrant: () => {
29585-
console.log('%c[Granted]', 'background:lime; color: black; font-size:large');
29592+
console.log('%c[StorageAccess][GRANTED]', 'background:lime; color:black; font-size:large');
2958629593
connect.getLog().info(`[StorageAccess][onGrant] callback executed`);
29587-
if (isCustomRequestAccessMode()) {
29594+
if (isCustomRequestAccessMode() && hideCCP()) {
2958829595
getRSAContainer().hide();
2958929596
}
2959029597
// 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
@@ -332,6 +332,11 @@ declare namespace connect {
332332
};
333333
/** Customize messaging on the request/deny banners */
334334
custom?: {
335+
/**
336+
* provides users the option to specify whether or not to hide CCP Iframe upon granting access when using custom mode
337+
* @default true
338+
*/
339+
hideCCP?: boolean;
335340
header?: string;
336341
title?: string;
337342
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
};
@@ -205,7 +206,7 @@ describe('Request Storage Access module', () => {
205206
expect(onGrantSpy.calledTwice).not.to.be.true;
206207
});
207208

208-
it('Should hide container if no access for custom types', () => {
209+
it('Should hide container if mode is custom after granting access', () => {
209210
mockMessageFromIframe({
210211
event: connect.storageAccess.storageAccessEvents.GRANTED,
211212
data: {},
@@ -220,7 +221,52 @@ describe('Request Storage Access module', () => {
220221
expect(container.style.display).to.be.equals('none');
221222
});
222223

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

0 commit comments

Comments
 (0)