Skip to content

Commit 4bed018

Browse files
committed
Code Cleanup and review alignments
1 parent 6838c84 commit 4bed018

17 files changed

Lines changed: 91 additions & 130 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ coverage
4141
# logs folder for aio-run-detached
4242
logs
4343

44-
adobe-api/mesh/mesh.json
44+
adobe-api/mesh/mesh.json
45+
server.js
46+
test-placeholder-handler.js
47+
key.pem
48+
cert.pem

INSTALL.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@
99

1010
### Create a new project
1111

12-
Go to console.adobe.io and create a new project from template: "App Builder"
12+
Go to https://developer.adobe.com/console and create a new project from template: "App Builder"
1313

1414
To required environment add:
1515

1616
* I/O Management API with OAuth Server-to-Server
1717
* I/O Events
1818

1919

20-
### Adobe Api Mesh (Optional)
20+
### Adobe API Mesh (Optional)
2121

22-
1. Add "Api Mesh" service to your environment.
22+
1. Add "API Mesh" service to your environment.
2323
2. Rename file `adobe-api/mesh/mesh.json.dist` into `adobe-api/mesh/mesh.json`.
2424
3. Change required options inside `adobe-api/mesh/mesh.json`.
2525
* AC-URL (This should be your Adobe Commerce system's base URL to GQL Endpoint)
2626

27-
3. Provision Mesh by using this file with `aio api-mesh create adobe-api/mesh/mesh.json`.
27+
4. Provision Mesh by using this file with `aio api-mesh create adobe-api/mesh/mesh.json`.
2828

2929
## Installation
3030

3131
1. Clone the repository
3232
2. Run `npm install` to install the dependencies
3333
3. Go to [Project](https://developer.adobe.com/console), select Environment and click on "Download All" button.
34+
4. Copy the env.dist file into .env file. `cp env.dist .env`
3435
4. Execute `aio app use <path-to-file>` with file you just downloaded. (Merge files if you already have .env file)
3536
5. Edit `.env` file with your project details.
3637
Set following variables:
@@ -39,8 +40,25 @@ Set following variables:
3940
AC_GRAPHQL_URL= // Your GraphQL URL
4041
AC_DEFAULT_STORE_CODE= // Default Adobe Commerce Store Code
4142
AC_ENVIRONMENT_ID= // Your Environment ID for Catalog Service if used (optional)
43+
COMMERCE_BASE_URL= // Commerce instance REST API Url
4244
```
4345

46+
> [!NOTE]
47+
> When configuring the `COMMERCE_BASE_URL` environment variable, the format differs between PaaS and SaaS:
48+
>
49+
> For PaaS (On-Premise/Cloud):
50+
>
51+
> - Must include your base site URL + `/rest/` suffix
52+
> - Example: `https://[environment-name].us-4.magentosite.cloud/rest/`
53+
>
54+
> For SaaS:
55+
>
56+
> - Must be the REST API endpoint provided by Adobe Commerce
57+
> - Example: `https://na1-sandbox.api.commerce.adobe.com/[tenant-id]/`
58+
>
59+
> Make sure to use your actual environment name or tenant ID in the URL. The examples above use placeholder values.
60+
61+
4462
6. Configure Adobe Commerce Authorization
4563

4664
In env.dist file you will find set of Auth parameters.

README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Feed Generator is a service that simplifies the process of generating product fe
44

55
## Installation
66

7-
Module compartible with both Adobe Commerce SaaS and PaaS.
7+
Module compatible with both Adobe Commerce SaaS and PaaS.
88

99
Please see [INSTALL.md](INSTALL.md) for more details.
1010

@@ -191,22 +191,22 @@ For that go to Settings and click on clean the cache button.
191191

192192
#### Fixed Variables
193193

194-
Header and Footer currently have a support to variables (Only 1 actualy)
194+
Header and Footer currently have a support to variables (Only 1 actually)
195195

196196
`{{DATA}}` - Current Date/Time - will be in format 2024-10-21T14:45:30.123Z
197197

198198
### Dynamic variables
199199

200200
Variables are defined using double curly braces (`{{ }}`) and correspond to fields in the Adobe Commerce GraphQL product output. For example, `{{sku}}` will be replaced with the product's SKU.
201201

202-
##### Additonal parameters
202+
##### Additional parameters
203203

204204
###### Repeating Tags with `count`
205205

206206
When a variable corresponds to an array, you can use the `count` property to repeat the XML tag for each element in the array. For instance, using `count=5` will generate up to 5 tags, each containing a different value from the array.
207207

208208
```xml
209-
<g:brand>{{manufacturer count="5"}}</g:brand>
209+
<image>{{media_gallery.url count="2"}}</image>
210210
```
211211

212212
##### Selecting Specific Array Elements with `index`
@@ -226,28 +226,51 @@ To select a specific element from an array, use the `index` property. This will
226226
Add attributes.value is an Array of attributes, to get specific attribute, you can use "code" parameter and define attribute with which code you want to use.
227227

228228

229-
#### Example
229+
#### Example for Google Feed
230+
231+
##### Header
232+
```xml
233+
<?xml version="1.0"?>
234+
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
235+
<channel>
236+
```
237+
238+
##### Body (PaaS)
230239

231240
```xml
232241
<item>
233242
<g:id>{{sku}}</g:id>
234243
<title>{{name}}</title>
235244
<description>{{description.html}}</description>
236-
<link>https://www.native-instruments.com/{{detail_page}}</link>
245+
<link>https://www.URL.com/{{detail_page}}</link>
237246
<g:image_link>{{image.url}}</g:image_link>
238247
<g:condition>new</g:condition>
239248
<g:price>{{price_range.maximum_price.final_price.value}} {{price_range.maximum_price.final_price.currency}}</g:price>
240-
<g:availability>In Stock</g:availability>
241-
<g:google_product_category><![CDATA[Arts &amp; Entertainment &gt; Hobbies &amp; Creative Arts &gt; Musical Instruments &gt; Electronic Musical Instruments]]></g:google_product_category>
242-
<g:identifier_exists>true</g:identifier_exists>
243249
<g:product_type index=2>{{categories.name}}</g:product_type>
244-
<g:sale_price>{{price_range.minimum_price.final_price.value}}</g:sale_price>
245-
<g:brand count=5>{{manufacturer}}</g:brand>
246250
<g:mpn>{{sku}}</g:mpn>
247251
<g:additional_image_link><![CDATA[{{image.url}}?width=350&height=350&fit=crop]]></g:additional_image_link>
248252
</item>
249253
```
250254

255+
256+
##### Body (SaaS)
257+
```xml
258+
<item>
259+
<sku>{{sku}}</sku>
260+
<weight>{{SimpleProduct||weight}}</weight>
261+
<image>{{media_gallery.url count="2"}}</image>
262+
<color>{{attributes.value code='color'}}</color>
263+
<price>{{SimpleProduct||price_range.maximum_price.final_price.value}}</price>
264+
</item>
265+
```
266+
267+
##### Footer
268+
```xml
269+
</channel>
270+
</rss>
271+
```
272+
273+
251274
## Technical Module implementation
252275

253276
Delete Feed - deleting current feed from the database and from all schedules
@@ -285,7 +308,7 @@ Regenerate Feed - will trigger the event “generate.feed” for a particular fe
285308

286309
* `getAllStores` - get all Adobe Commerce Stores by API
287310

288-
* `generateByCron` - trigger feed generation by OpenWisk alarms.
311+
* `generateByCron` - trigger feed generation by OpenWhisk alarms.
289312

290313
* `getConfig` - receive public module configs. Currently only return type of authorization (ims vs oauth).
291314

@@ -306,8 +329,8 @@ Action is running every 30 minutes and checking by feed settings if it have to b
306329
Edit / Create New Feed form will contain form to save new Feed.
307330

308331
Current elements:
309-
* Feed Format - select - JSON | XML
310-
* Feed Item: Big text field to have XML | JSON there with feed item body
332+
* Feed Format - select - XML
333+
* Feed Item: Big text field to have XML there with feed item body
311334
* Feed Header
312335
* Feed Footer
313336
* Store View - select with list of available store views on Adobe Commerce (websites also have to be there, but it is not possible to select them)
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44

55
const { Config } = require('@adobe/aio-sdk').Core
66
const fs = require('fs')
7-
const fetch = require('node-fetch')
87

98
// get action url
109
const namespace = Config.get('runtime.namespace')
1110
const hostname = Config.get('cna.hostname') || 'adobeioruntime.net'
12-
const packagejson = JSON.parse(fs.readFileSync('package.json').toString())
1311
const runtimePackage = 'feed-generator'
14-
const actionUrl = `https://${namespace}.${hostname}/api/v1/web/${runtimePackage}/generic`
12+
const actionUrl = `https://${namespace}.${hostname}/api/v1/web/${runtimePackage}/getConfig`
1513

1614
// The deployed actions are secured with the `require-adobe-auth` annotation.
1715
// If the authorization header is missing, Adobe I/O Runtime returns with a 401 before the action is executed.
1816
test('returns a 401 when missing Authorization header', async () => {
1917
const res = await fetch(actionUrl)
20-
expect(res).toEqual(expect.objectContaining({
21-
status: 401
22-
}))
18+
expect(res.status).toBe(401)
2319
})

e2e/publish-events.e2e.test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/commerce-backend-ui-1/actions/utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
* <license header>
3-
*/
4-
51
/* This file exposes some common utilities for your actions */
62

73
const { handlePlaceholder } = require('./utils/placeholderHandler');

src/commerce-backend-ui-1/actions/utils/generation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ async function generateFeed(uuid, params) {
4242
"expiration": "2023-03-03T12:58:47.000Z",
4343
"value": {
4444
"created_at": "2023-03-02T12:58:47.770Z",
45-
"feedBody": "<item>\n <g:id>{{sku}}</g:id>\n <title>{{name}}</title>\n <description>{{description}}</description>\n <g:image_link>{{images.url count='2'}}</g:image_link>\n <price>{{SimpleProductView||price.final.amount.value}} {{SimpleProductView||price.final.amount.currency}}</price>\n <weight>{{attributes.value code='weight'}}</weight>\n </item>",
45+
"feedBody": "<item>\n <g:id>{{sku}}</g:id>\n <title>{{SimpleProduct||weight}}</title>\n \n <g:image_link>{{image.url count='2'}}</g:image_link>\n </item>",
4646
"feedFooter": "</items>",
4747
"feedHeader": "<items>",
4848
"feedName": "Test XML",
4949
"feed_type": "xml",
5050
"generated_at": "",
5151
"status": "pending",
52-
"store_code": "default||main_website_store||base",
53-
"searchQuery": "basebal",
54-
"filterQuery": "{\n \"attribute\": \"price\",\n \"range\": {\n \"from\": 10,\n \"to\": 100\n }\n}"
52+
"store_code": "de||main_website_store||base",
53+
"searchQuery": "Motiv",
54+
// "filterQuery": "{\n \"attribute\": \"price\",\n \"range\": {\n \"from\": 10,\n \"to\": 100\n }\n}"
5555
}
5656
}
5757
}

src/commerce-backend-ui-1/actions/utils/placeholderHandler.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,23 @@ const handleNoProperties = (placeholder, item, feed, type) => {
106106

107107
const handleCategories = (placeholder, item, feed, type) => {
108108

109-
// const logger = Core.Logger('main', {level: 'info'})
110-
111109
// eslint-disable-next-line no-unused-vars
112110
const [dataKey, placeholderProperties] = extractFromPlaceholder(placeholder);
113111

114-
// logger.error("handleCategories START");
115-
116112
let placeholderParts = dataKey.split(".");
117113

118114
if (placeholderParts[0] !== 'categories') {
119115
return null;
120116
}
121117

122-
// logger.error("item " + JSON.stringify(item));
123-
// logger.error("placeholderParts " + JSON.stringify(placeholderParts));
124-
// logger.error("placeholderParts0 " + JSON.stringify(placeholderParts[0]));
125-
126118
let value = "";
127119
let itemCounter = 0;
128120
for (let placeholderPart of placeholderParts) {
129121

130-
// logger.error("placeholderPart " + JSON.stringify(placeholderPart));
131122
if (value.toString() === "") {
132123

133-
// logger.error("item[placeholderPart] " + JSON.stringify(item[placeholderPart]));
134124
if (itemCounter === 0) {
135125

136-
// logger.error("item[placeholderPart] VALUE " + JSON.stringify(item[placeholderPart][0]));
137126
/**
138127
* @ToDo Consider to use index as a property for define position of the value in the array if there are multiple values
139128
* Example:
@@ -152,12 +141,9 @@ const handleCategories = (placeholder, item, feed, type) => {
152141
value = item[placeholderPart][0];
153142
// }
154143
} else {
155-
// logger.error("item[placeholderPart] VALUE itemCounter > 0" + JSON.stringify(item[placeholderPart]));
156144
value = item[placeholderPart]
157145
}
158146
} else {
159-
// logger.error("value[placeholderPart] " + JSON.stringify(value[placeholderPart]));
160-
// logger.error("value " + JSON.stringify(value));
161147
value = value[placeholderPart];
162148
}
163149
itemCounter++;

src/commerce-backend-ui-1/ext.config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runtimeManifest:
1616
inputs:
1717
LOG_LEVEL: debug
1818
annotations:
19-
require-adobe-auth: false
19+
require-adobe-auth: true
2020
final: true
2121
feed-generator:
2222
license: Apache-2.0
@@ -36,7 +36,6 @@ runtimeManifest:
3636
COMMERCE_CONSUMER_SECRET: $COMMERCE_CONSUMER_SECRET
3737
COMMERCE_ACCESS_TOKEN: $COMMERCE_ACCESS_TOKEN
3838
COMMERCE_ACCESS_TOKEN_SECRET: $COMMERCE_ACCESS_TOKEN_SECRET
39-
COMMERCE_HUBSPOT_CONTACT_ID_FIELD: $COMMERCE_HUBSPOT_CONTACT_ID_FIELD
4039
AC_ENVIRONMENT_ID: $AC_ENVIRONMENT_ID
4140
providerId: $FEED_GENERATOR_PROVIDER_ID
4241
eventCode: feed.generate
@@ -107,7 +106,7 @@ runtimeManifest:
107106
web: 'yes'
108107
runtime: nodejs:22
109108
annotations:
110-
require-adobe-auth: true
109+
require-adobe-auth: false
111110
final: true
112111
getGqlSchema:
113112
function: actions/magentoActions/getGqlSchema.js
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<!-- <license header> -->
2-
31
404

0 commit comments

Comments
 (0)