Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yesil committed Jul 10, 2024
1 parent 4283779 commit d36b52c
Show file tree
Hide file tree
Showing 21 changed files with 3,442 additions and 16,613 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"search.followSymlinks": false,
"files.exclude": {
"mas.js": true
"mas.js": true,
"libs": true
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
36 changes: 31 additions & 5 deletions commons/src/aem.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Fragment } from '../../studio/src/store/Fragment';

const accessToken = localStorage.getItem('masAccessToken');

const headers = {
Expand All @@ -13,7 +15,7 @@ const headers = {
* @param {string} [params.query] - The search query
* @returns {Promise<Array>} - A promise that resolves to an array of search results
*/
async function fragmentSearch({ path, query }) {
export async function searchFragment({ path, query }) {
const filter = {};
if (path) {
filter.path = path;
Expand All @@ -31,23 +33,47 @@ async function fragmentSearch({ path, query }) {
headers,
})
.then((res) => res.json())
.then(({ items }) => items);
.then(({ items }) => {
return items.map((item) => {
const data = item.fields.reduce(
(acc, { name, multiple, values }) => {
acc[name] = multiple ? values : values[0];
return acc;
},
{},
);
data.path = item.path;
data.model = item.model;
return data;
});
});
}

async function getCfByPath(path) {
/**
* @param {string} path fragment path
* @returns the raw fragment item
*/
export async function getFragmentByPath(path) {
return fetch(`${this.cfFragmentsUrl}?path=${path}`, {
headers,
})
.then((res) => res.json())
.then(({ items: [item] }) => item);
}

/**
* Save given fragment
* @param {Fragment} fragment
*/
export async function saveFragment(fragment) {}

class AEM {
sites = {
cf: {
fragments: {
search: fragmentSearch.bind(this),
getCfByPath: getCfByPath.bind(this),
search: searchFragment.bind(this),
getCfByPath: getFragmentByPath.bind(this),
save: saveFragment.bind(this),
},
},
};
Expand Down
4 changes: 0 additions & 4 deletions mas.css

This file was deleted.

2 changes: 1 addition & 1 deletion mas.js

Large diffs are not rendered by default.

53 changes: 34 additions & 19 deletions mocks/offers.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@
"qQiJqQPZXOSrog8SR5yfiLR03-thGECfV5Gm9jzeK6k"
],
"offerId": "B576669D9AAE20A3B4B0FDE65504BB30",
"startDate": "2021-12-08T08:01:00.000Z",
"endDate": "2050-01-31T19:59:00.000Z",
"priceDetails": {
"price": 263.88,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -569,8 +567,6 @@
"AoyCNxLmjibbiE84-I9xlAJEayihAmviExxfyy04g8w"
],
"offerId": "B85C86D4214EF804F8951D7E0A0E1945",
"startDate": "2021-12-08T08:01:00.000Z",
"endDate": "2050-01-31T19:59:00.000Z",
"priceDetails": {
"price": 34.49,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -605,8 +601,6 @@
"JzW8dgW8U1SrgbHDmTE-ABsOKPgtl5jugiW8bA5PtKg"
],
"offerId": "65BA7CA7573834AC4D043B0E7CBD2349",
"startDate": "2021-12-08T08:01:00.000Z",
"endDate": "2050-01-31T19:59:00.000Z",
"priceDetails": {
"price": 59.99,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -641,8 +635,6 @@
"7QWcHXX6VIH_2BeNYI1GizMNGHJ3ZFz9-IMoC0gC-4c"
],
"offerId": "1AB23148DED3D18062177AFEACEA6ECE",
"startDate": "2021-12-08T08:01:00.000Z",
"endDate": "2050-01-31T19:59:00.000Z",
"priceDetails": {
"price": 659.88,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -677,8 +669,6 @@
"MasJgjrlDjj72m_B1q1_4VhTDtxldl6yG4C16DkznhI"
],
"offerId": "76EB6C3E0486E92E67A0BC1AB3CC7E19",
"startDate": "2021-12-08T08:01:00.000Z",
"endDate": "2050-01-31T19:59:00.000Z",
"priceDetails": {
"price": 89.99,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -713,8 +703,6 @@
"OInILOo_tvV3OiYdJTxo1NhsVX4GxbHnM8JWexA9N8w"
],
"offerId": "2D25B85032A7A139D38BEEABA53451D4",
"startDate": "2023-11-01T07:01:00.000Z",
"endDate": "2099-12-13T07:58:00.000Z",
"priceDetails": {
"price": 9.99,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -749,8 +737,6 @@
"5OFXVGxVYBZAJIrzV7Z8dsv2ve3oiRzed8f9UB8gbTw"
],
"offerId": "0B5AC1661376C332EE96BACC473AC0BB",
"startDate": "2023-11-01T07:01:00.000Z",
"endDate": "2099-12-13T07:58:00.000Z",
"priceDetails": {
"price": 119.09,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -785,7 +771,6 @@
"tNF8YrqR3DslSda-1L6pK5z-nYWDQYnjdHkwFDjGAas"
],
"offerId": "0CDCA0CDDC5EE1F3E127E3D77AAA47DE",
"startDate": "2021-11-11T08:01:00.000Z",
"priceDetails": {
"price": 19.99,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -820,7 +805,6 @@
"9zqYpoVccNVW1OM7GKwYCfFEamktcNIamRJYBMknc-E"
],
"offerId": "194C2964E964DE2BAB7A297D547388A5",
"startDate": "2021-11-11T08:01:00.000Z",
"priceDetails": {
"price": 239.88,
"priceWithoutTax": 0.0,
Expand Down Expand Up @@ -1038,8 +1022,6 @@
"r_JXAnlFI7xD6FxWKl2ODvZriLYBoSL701Kd1hRyhe8"
],
"offerId": "632B3ADD940A7FBB7864AA5AD19B8D28",
"startDate": "2015-12-04T17:38:19.000Z",
"endDate": "2100-04-13T21:20:00.000Z",
"priceDetails": {
"price": 35.99,
"priceWithoutDiscount": 59.99,
Expand Down Expand Up @@ -1075,7 +1057,6 @@
"A1xn6EL4pK93bWjM8flffQpfEL-bnvtoQKQAvkx574M"
],
"offerId": "30404A88D89A328584307175B8B27616",
"startDate": "2015-11-17T20:52:25.000Z",
"priceDetails": {
"price": 22.99,
"priceWithoutTax": 22.99,
Expand All @@ -1102,5 +1083,39 @@
"language": "MULT",
"merchant": "ADOBE"
}
],
"MV-_1XzZ6JAft_2wXu3a-z28noWUucHMdMtyIYcodak": [
{
"offerSelectorIds": [
"MV-_1XzZ6JAft_2wXu3a-z28noWUucHMdMtyIYcodak"
],
"offerId": "EFB7A26C4B3D746630FB086C45593394",
"priceDetails": {
"price": 59.99,
"priceWithoutTax": 0.0,
"priceWithoutDiscountAndTax": 59.99,
"usePrecision": true,
"formatString": "'US$'#,##0.00",
"taxDisplay": "TAX_EXCLUSIVE",
"taxTerm": "TAX"
},
"analytics": "{\"offerId\":\"EFB7A26C4B3D746630FB086C45593394\",\"label\":\"ccsn_direct_individual\",\"price\":\"59.99\",\"amountWithoutTax\":\"0.0\",\"commitmentType\":\"YEAR\",\"billingFrequency\":\"MONTHLY\",\"currencyCode\":\"USD\"}",
"productArrangementCode": "ccsn_direct_individual",
"productArrangement": {
"productFamily": "CC_ALL_APPS"
},
"buyingProgram": "RETAIL",
"commitment": "YEAR",
"term": "MONTHLY",
"customerSegment": "INDIVIDUAL",
"marketSegments": [
"COM"
],
"salesChannel": "DIRECT",
"offerType": "TRIAL",
"pricePoint": "TRIAL_ZOOM_CCSN_2MTWP_ABM_PUF_D2P",
"language": "MULT",
"merchant": "ADOBE"
}
]
}
4 changes: 2 additions & 2 deletions mocks/sites/cf/fragments/search/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"status": "PUBLISHED",
"fields": [
{
"name": "type",
"name": "variant",
"type": "enumeration",
"multiple": false,
"values": [
Expand Down Expand Up @@ -141,7 +141,7 @@
"status": "PUBLISHED",
"fields": [
{
"name": "type",
"name": "variant",
"type": "enumeration",
"multiple": false,
"values": [
Expand Down
10 changes: 6 additions & 4 deletions mocks/wcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export async function withWcs(originalFetch) {
.get('offer_selector_ids')
.split(',')
.map((osi) =>
offers[`${osi}-${language}`]?.map((offer) => ({
...offer,
offerSelectorIds: [osi],
})),
(offers[`${osi}-${language}`] ?? offers[osi])?.map(
(offer) => ({
...offer,
offerSelectorIds: [osi],
}),
),
);

// 404 if any of requested osis does not exist
Expand Down
70 changes: 38 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d36b52c

Please sign in to comment.