Skip to content

Commit 4bfe62f

Browse files
committed
prep
1 parent 5711b8d commit 4bfe62f

File tree

4 files changed

+3
-132
lines changed

4 files changed

+3
-132
lines changed
Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,9 @@
1-
/*
2-
* <license header>
3-
*/
4-
5-
/**
6-
* This is a sample action showcasing how to access an external API
7-
*
8-
* Note:
9-
* You might want to disable authentication and authorization checks against Adobe Identity Management System for a generic action. In that case:
10-
* - Remove the require-adobe-auth annotation for this action in the manifest.yml of your application
11-
* - Remove the Authorization header from the array passed in checkMissingRequestInputs
12-
* - The two steps above imply that every client knowing the URL to this deployed action will be able to invoke it without any authentication and authorization checks against Adobe Identity Management System
13-
* - Make sure to validate these changes against your security requirements before deploying the action
14-
*/
15-
16-
171
const fetch = require('node-fetch')
182
const { Core } = require('@adobe/aio-sdk')
193
const { errorResponse, getBearerToken, stringParameters, checkMissingRequestInputs } = require('../utils')
204

215
async function main(params) {
22-
const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'info' })
23-
24-
try {
25-
logger.info('Calling the main action');
26-
27-
const requiredParams = ['tenet', 'apiKey'];
28-
const requiredHeaders = ['Authorization'];
29-
const errorMessage = checkMissingRequestInputs(params, requiredParams, requiredHeaders);
30-
31-
if (errorMessage) return errorResponse(400, 'oops ' + errorMessage, logger);
32-
33-
const { tenet, apiKey } = params;
34-
const token = getBearerToken(params);
35-
36-
const targetApi = `https://mc.adobe.io/${tenet}/target/audiences/`;
37-
const t = await fetch(targetApi, {
38-
method: 'get',
39-
headers: {
40-
'Authorization': `Bearer ${token}`,
41-
'Content-Type': 'application/json',
42-
'Accept': 'application/vnd.adobe.target.v3+json',
43-
'x-api-key': apiKey
44-
}
45-
});
46-
content = await t.json();
47-
48-
const aud = content.audiences.reduce((accumulator, item, index) => {
49-
if (item.name) { accumulator[index] = item.name }
50-
return accumulator;
51-
});
52-
53-
const elements = {
54-
"properties": {
55-
"elements": {
56-
"audiences": {
57-
"value": Object.values(aud)
58-
}
59-
}
60-
}
61-
};
62-
63-
const response = {
64-
statusCode: 200,
65-
body: content
66-
};
676

68-
logger.info(`${response.statusCode}: successful request`)
69-
return response
70-
} catch (error) {
71-
logger.error(error)
72-
return errorResponse(500, 'server error', logger)
73-
}
747
}
758

769
exports.main = main
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
extensionId: 'create-audience-variations',
3-
apiKey:'7601734ed1054af7a2ba00134db3bded',
3+
apiKey:'<copied API key>',
44
tenet:'adobeliveex40'
55
}

src/aem-cf-editor-1/web-src/src/components/CreateaudiencevariationsModal.js

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -91,69 +91,10 @@ export default function () {
9191
);
9292

9393
async function createVariations(conn) {
94-
conn.host.modal.set({ loading: true });
95-
const headers = {
96-
'Authorization': 'Bearer ' + guestConnection.sharedContext.get('auth').imsToken,
97-
'x-gw-ims-org-id': guestConnection.sharedContext.get('auth').imsOrg
98-
};
99-
100-
const { model, path } = await guestConnection.host.contentFragment.getContentFragment();
101-
console.log(selectedAudiences);
102-
const params = {
103-
aemHost: `https://${guestConnection.sharedContext.get('aemHost')}`,
104-
selectedAudiences: selectedAudiences,
105-
modelPath: model.path,
106-
fragmentPath: path.replace('/content/dam', '/api/assets')
107-
};
108-
109-
const action = 'create-variations';
110-
111-
try {
112-
const actionResponse = await actionWebInvoke(allActions[action], headers, params);
113-
console.log(`Response from ${action}:`, actionResponse);
114-
onCloseHandler();
115-
} catch (e) {
116-
console.error(e)
117-
}
94+
11895
}
11996

12097
async function fetchAudiences(conn) {
121-
console.log('fetch audiences');
122-
const headers = {
123-
'Authorization': 'Bearer ' + conn.sharedContext.get('auth').imsToken,
124-
'x-gw-ims-org-id': conn.sharedContext.get('auth').imsOrg
125-
};
126-
127-
const params = {
128-
tenet: tenet,
129-
apiKey: apiKey
130-
};
131-
132-
const action = 'fetch-audiences';
133-
134-
try {
135-
console.log(allActions[action]);
136-
const actionResponse = await actionWebInvoke(allActions[action], headers, params);
137-
138-
if (actionResponse.hasOwnProperty('data')) {
139-
let n = 0;
140-
const items = actionResponse.data.audienceConfigurationList.items[0].audiences.map((item) => {
141-
return { id: n++, name: item }
142-
});
143-
144-
setAudiences(items);
145-
} else {
146-
const items = actionResponse.audiences.filter((item) => {
147-
if (item.name)
148-
return { id: item.id, name: item.name }
149-
});
150-
setAudiences(items);
151-
}
15298

153-
console.log(`Response from ${action}:`, actionResponse)
154-
} catch (e) {
155-
console.error(e)
156-
}
157-
conn.host.modal.set({ loading: false });
15899
}
159100
}

src/aem-cf-editor-1/web-src/src/components/ExtensionRegistration.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ async function ExtensionRegistration() {
1717
id: 'create-audience-variations',
1818
label: 'Create Audience Variations',
1919
icon: 'OpenIn',
20-
variant: 'action',
21-
disabled: 'yes',
2220
onClick() {
2321
guestConnection.host.modal.showUrl({
2422
title: 'Create Variations from Audiences',
25-
url: 'index.html#/audiences',
26-
loading: true
23+
url: 'index.html#/audiences'
2724
});
2825
},
2926
},

0 commit comments

Comments
 (0)