Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/eleven-rabbits-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@o2s/integrations.contentful-cms': minor
'@o2s/integrations.mocked-dxp': minor
'@o2s/integrations.strapi-cms': minor
'@o2s/integrations.mocked': minor
---

Added checkout block type cases (Cart, CheckoutCompanyData, CheckoutShippingAddress, CheckoutBillingPayment, CheckoutSummary, OrderConfirmation) to the getBlockConfig switch in mocked CMS service. Refactored mocked-dxp to use getBlockConfig override instead of individual block method overrides.
45 changes: 45 additions & 0 deletions .changeset/quick-hoops-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
'@o2s/blocks.checkout-shipping-address': minor
'@o2s/blocks.notification-details': minor
'@o2s/blocks.notification-summary': minor
'@o2s/blocks.checkout-billing-payment': minor
'@o2s/blocks.notification-list': minor
'@o2s/blocks.checkout-company-data': minor
'@o2s/blocks.featured-service-list': minor
'@o2s/blocks.article-search': minor
'@o2s/blocks.recommended-products': minor
'@o2s/blocks.feature-section-grid': minor
'@o2s/blocks.category-list': minor
'@o2s/blocks.order-confirmation': minor
'@o2s/blocks.article-list': minor
'@o2s/blocks.checkout-summary': minor
'@o2s/blocks.payments-history': minor
'@o2s/blocks.payments-summary': minor
'@o2s/blocks.product-details': minor
'@o2s/blocks.service-details': minor
'@o2s/blocks.feature-section': minor
'@o2s/blocks.pricing-section': minor
'@o2s/blocks.category': minor
'@o2s/blocks.ticket-details': minor
'@o2s/blocks.ticket-summary': minor
'@o2s/blocks.document-list': minor
'@o2s/blocks.media-section': minor
'@o2s/blocks.orders-summary': minor
'@o2s/blocks.product-list': minor
'@o2s/blocks.service-list': minor
'@o2s/blocks.ticket-recent': minor
'@o2s/blocks.user-account': minor
'@o2s/blocks.invoice-list': minor
'@o2s/blocks.hero-section': minor
'@o2s/blocks.order-details': minor
'@o2s/blocks.cta-section': minor
'@o2s/blocks.quick-links': minor
'@o2s/blocks.surveyjs-form': minor
'@o2s/blocks.ticket-list': minor
'@o2s/blocks.bento-grid': minor
'@o2s/blocks.order-list': minor
'@o2s/blocks.cart': minor
'@o2s/blocks.faq': minor
Comment thread
lukasz-hycom marked this conversation as resolved.
---

Updated all block services to use the generic getBlockConfig<T>() method instead of block-specific CMS service methods.
6 changes: 6 additions & 0 deletions .changeset/tired-brooms-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@o2s/api-harmonization': minor
'@o2s/framework': minor
Comment thread
lukasz-hycom marked this conversation as resolved.
---

Replaced 36+ block-specific abstract methods in CmsService with a single generic getBlockConfig<T>() method. Added Swagger decorators to all CMS block controller endpoints. Extended CmsBlockType union with checkout block types.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export class OrganizationsService {
) {}

getCustomers(query: GetCustomersQuery, headers: AppHeaders): Observable<CustomerList> {
const cms = this.cmsService.getOrganizationList({ locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.OrganizationList.OrganizationList>({
id: 'organizations',
locale: headers[H.Locale],
blockType: 'OrganizationList',
});
// Pass authorization token to filter organizations by current user
const organizations = this.organizationsService.getOrganizationList(
{
Expand All @@ -29,8 +33,8 @@ export class OrganizationsService {
headers[H.Authorization],
);

return forkJoin([organizations, cms]).pipe(
map(([organizations, cms]) => {
return forkJoin({ organizations, cms }).pipe(
map(({ organizations, cms }) => {
if (!organizations) {
throw new NotFoundException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ export class TicketListService {
) {}

getTicketListBlock(query, headers): Observable<TicketListBlock> {
const cms = this.cmsService.getTicketListBlock({ ...query, locale: headers['x-locale'] });
const cms = this.cmsService.getBlockConfig<CMS.Model.TicketListBlock.TicketListBlock>({
...query, locale: headers[H.Locale], blockType: 'TicketListBlock',
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const documents = this.documentService.getDocumentList({ limit: 5 });

return forkJoin([cms, documents]).pipe(
Expand Down
12 changes: 8 additions & 4 deletions apps/docs/docs/integrations/cms/strapi/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ fragment FaqComponent on ComponentComponentsFaq {
}
```

**Service Method:**
**Service Method (inside `getBlockConfig` switch):**

```typescript
getFaqBlock(options: CMS.Request.GetCmsEntryParams) {
const key = `faq-component-${options.id}-${options.locale}`;
return this.getCachedBlock(key, () => this.getBlock(options).pipe(map(mapFaqBlock)));
getBlockConfig<T>(options: CMS.Request.GetCmsBlockConfigParams): Observable<T> {
const key = `${options.blockType}-component-${options.id}-${options.locale}`;
switch (options.blockType) {
case 'FaqBlock':
return this.getCachedBlock(key, () => this.getBlock(options).pipe(map(mapFaqBlock))) as Observable<T>;
// ... other block types
}
}
```
22 changes: 11 additions & 11 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class UserAccountService {

getUserAccountBlock(query: GetUserAccountBlockQuery, headers: AppHeaders): Observable<UserAccountBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getUserAccountBlock({ id: query.id, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.UserAccountBlock.UserAccountBlock>({
id: query.id,
locale: headers[H.Locale],
blockType: 'UserAccountBlock',
});
const user = this.usersService.getUser({ id: query.userId }, authorization);

return forkJoin([cms, user]).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export class InvoiceListService {

getInvoiceListBlock(query: GetInvoiceListBlockQuery, headers: AppHeaders): Observable<InvoiceListBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getInvoiceListBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.InvoiceListBlock.InvoiceListBlock>({
...query,
locale: headers[H.Locale],
blockType: 'InvoiceListBlock',
});

return forkJoin([cms]).pipe(
concatMap(([cms]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export class PaymentsHistoryService {
headers: AppHeaders,
): Observable<PaymentsHistoryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getPaymentsHistoryBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.PaymentsHistoryBlock.PaymentsHistoryBlock>({
...query,
locale: headers[H.Locale],
blockType: 'PaymentsHistoryBlock',
});
const invoices = this.invoiceService.getInvoiceList(
{
limit: query.limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export class PaymentsSummaryService {
headers: AppHeaders,
): Observable<PaymentsSummaryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getPaymentsSummaryBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.PaymentsSummaryBlock.PaymentsSummaryBlock>({
...query,
locale: headers[H.Locale],
blockType: 'PaymentsSummaryBlock',
});
const invoices = this.invoiceService.getInvoiceList(
{
limit: query.limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export class CartService {
constructor(private readonly cmsService: CMS.Service) {}

getCartBlock(query: GetCartBlockQuery, headers: AppHeaders): Observable<CartBlock> {
return this.cmsService.getCartBlock({ ...query, locale: headers[H.Locale] }).pipe(map(mapCart));
return this.cmsService
.getBlockConfig<CMS.Model.CartBlock.CartBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CartBlock',
})
.pipe(map(mapCart));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export class CheckoutBillingPaymentService {
headers: AppHeaders,
): Observable<CheckoutBillingPaymentBlock> {
return this.cmsService
.getCheckoutBillingPaymentBlock({ ...query, locale: headers[H.Locale] })
.getBlockConfig<CMS.Model.CheckoutBillingPaymentBlock.CheckoutBillingPaymentBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CheckoutBillingPaymentBlock',
})
.pipe(map(mapCheckoutBillingPayment));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export class CheckoutCompanyDataService {
headers: AppHeaders,
): Observable<CheckoutCompanyDataBlock> {
return this.cmsService
.getCheckoutCompanyDataBlock({ ...query, locale: headers[H.Locale] })
.getBlockConfig<CMS.Model.CheckoutCompanyDataBlock.CheckoutCompanyDataBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CheckoutCompanyDataBlock',
})
.pipe(map(mapCheckoutCompanyData));

// Optional: Add permission flags to the response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export class CheckoutShippingAddressService {
headers: AppHeaders,
): Observable<CheckoutShippingAddressBlock> {
return forkJoin([
this.cmsService.getCheckoutShippingAddressBlock({ ...query, locale: headers[H.Locale] }),
this.cmsService.getBlockConfig<CMS.Model.CheckoutShippingAddressBlock.CheckoutShippingAddressBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CheckoutShippingAddressBlock',
}),
]).pipe(
map(([cms]) => {
const result = mapCheckoutShippingAddress(cms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export class CheckoutSummaryService {
headers: AppHeaders,
): Observable<CheckoutSummaryBlock> {
return this.cmsService
.getCheckoutSummaryBlock({ ...query, locale: headers[H.Locale] })
.getBlockConfig<CMS.Model.CheckoutSummaryBlock.CheckoutSummaryBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CheckoutSummaryBlock',
})
.pipe(map(mapCheckoutSummary));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class OrderConfirmationService {
}

return forkJoin([
this.cmsService.getOrderConfirmationBlock({ ...query, locale: headers[H.Locale] }),
this.cmsService.getBlockConfig<CMS.Model.OrderConfirmationBlock.OrderConfirmationBlock>({
...query,
locale: headers[H.Locale],
blockType: 'OrderConfirmationBlock',
}),
this.ordersService.getOrder({ id: query.orderId }, headers[H.Authorization]),
]).pipe(
map(([cms, order]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class BentoGridService {
constructor(private readonly cmsService: CMS.Service) {}

getBentoGridBlock(query: GetBentoGridBlockQuery, headers: AppHeaders): Observable<BentoGridBlock> {
const cms = this.cmsService.getBentoGridBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.BentoGridBlock.BentoGridBlock>({
...query,
locale: headers[H.Locale],
blockType: 'BentoGridBlock',
});

return forkJoin([cms]).pipe(map(([cms]) => mapBentoGrid(cms, headers[H.Locale])));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class CtaSectionService {
constructor(private readonly cmsService: CMS.Service) {}

getCtaSectionBlock(query: GetCtaSectionBlockQuery, headers: AppHeaders): Observable<CtaSectionBlock> {
const cms = this.cmsService.getCtaSectionBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.CtaSectionBlock.CtaSectionBlock>({
...query,
locale: headers[H.Locale],
blockType: 'CtaSectionBlock',
});

return forkJoin([cms]).pipe(map(([cms]) => mapCtaSection(cms, headers[H.Locale])));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class DocumentListService {
constructor(private readonly cmsService: CMS.Service) {}

getDocumentListBlock(query: GetDocumentListBlockQuery, headers: AppHeaders): Observable<DocumentListBlock> {
const cms = this.cmsService.getDocumentListBlock({ ...query, locale: headers[H.Locale] });
const cms = this.cmsService.getBlockConfig<CMS.Model.DocumentListBlock.DocumentListBlock>({
...query,
locale: headers[H.Locale],
blockType: 'DocumentListBlock',
});

return forkJoin([cms]).pipe(map(([cms]) => mapDocumentList(cms, headers[H.Locale])));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export class FaqService {
constructor(private readonly cmsService: CMS.Service) {}

getFaqBlock(query: GetFaqBlockQuery, headers: AppHeaders): Observable<FaqBlock> {
const cms = this.cmsService.getFaqBlock({
const cms = this.cmsService.getBlockConfig<CMS.Model.FaqBlock.FaqBlock>({
...query,
locale: headers[H.Locale],
blockType: 'FaqBlock',
});

return forkJoin([cms]).pipe(map(([cms]) => mapFaq(cms)));
Expand Down
Loading
Loading