Skip to content

@W-20726537 Data access layer middleware#3648

Merged
raiyaj merged 19 commits intodevelopfrom
w-20726537-data-access-layer-middleware
Feb 13, 2026
Merged

@W-20726537 Data access layer middleware#3648
raiyaj merged 19 commits intodevelopfrom
w-20726537-data-access-layer-middleware

Conversation

@raiyaj
Copy link
Contributor

@raiyaj raiyaj commented Feb 9, 2026

This PR adds a client for querying the MRT data store, which is backed by DynamoDB. The idea is for this client to be abstracted by a PWA Kit helper which will be called by customer code.

Description

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Add a singleton DataStore middleware client (based heavily on the MetricsSender) with public methods for getting the singleton instance, checking if the data store is available, and then fetching an entry from the data access layer
  • Add a reference app route to facilitate testing the client
  • Add unit tests

How to Test-Drive This PR

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@cc-prodsec
Copy link
Collaborator

cc-prodsec commented Feb 9, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@@ -1,4 +1,6 @@
## v3.16.0-dev (Dec 17, 2025)
- Add Data Store client [#3648](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3648)
Copy link
Contributor Author

@raiyaj raiyaj Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this feature is currently inaccessible to end users, I'm wondering if I should omit this entry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it technically available but just not "officially released"? Or is it neither?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an undocumented feature that's intended to only be used internally by ECOM and PWA Kit/SF Next (see my answer below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up reverting this and adding the skip changelog PR label, but I can add it back if you prefer.

Comment on lines +66 to +69
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {DynamoDBClient} = require('@aws-sdk/client-dynamodb')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {DynamoDBDocumentClient} = require('@aws-sdk/lib-dynamodb')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pwa-kit-runtime seems unable to statically analyze module-level AWS SDK imports (it results in the error enoent: no such file or directory, open 'node:stream'), so these are imported lazily following the pattern in metrics-sender.js.

Comment on lines +145 to +163
/**
* Log an internal MRT error.
*
* @param namespace Namespace for the error (e.g. data_store, redirect) to facilitate searching
* @param err Error to log
* @param context Optional context to include in the log
*/
export const logMRTError = (namespace, err, context) => {
const error = err instanceof Error ? err : new Error(String(err))
console.error(
JSON.stringify({
[`__MRT__${namespace}`]: 'error',
type: 'MRT_internal',
error: error.message,
stack: error.stack,
...context
})
)
}
Copy link
Contributor Author

@raiyaj raiyaj Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, errors with the MRT_internal type are filtered out of log tailing and Log Center forwarding, so they're obscured from customers when thrown from Lambda.

@raiyaj raiyaj marked this pull request as ready for review February 10, 2026 02:47
@raiyaj raiyaj requested a review from a team as a code owner February 10, 2026 02:47
npeternel-sf
npeternel-sf previously approved these changes Feb 10, 2026
* @throws {DataStoreNotFoundError} An entry with the given key cannot be found
* @throws {DataStoreServiceError} An internal error occurred
*/
async getEntry(key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raiyaj last I heard about this feature, there was an assumption the data is PUSHed from ECOM into MRT. Assuming that's still true, what is the mechanism by which customers will know whether their key is valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there docs for this somewhere? PR description doesn't seem to cover how a customer would know about creating a key / populating the data store, etc.

Copy link
Contributor Author

@raiyaj raiyaj Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. Yup, customers will be able to change their site metadata in ECOM, which will trigger a data store upsert in MRT – that's documented here in the HLD. Customers don't need to know the entry keys, though, instead they would call a generic helper (something like getCustomSitePreferences()) which would fetch the entry with the right key.

Does your team still plan to implement this helper in PWA Kit and SF Next?

Copy link
Contributor

@bfeister bfeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main question is:

Are there docs for this somewhere? PR description doesn't seem to cover how a customer would know about creating a key / populating the data store, etc.

@raiyaj raiyaj added the skip changelog Skip the "Changelog Check" GitHub Actions step even if the Changelog.md files are not updated label Feb 12, 2026
@raiyaj raiyaj merged commit 8151418 into develop Feb 13, 2026
42 checks passed
@raiyaj raiyaj deleted the w-20726537-data-access-layer-middleware branch February 13, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changelog Skip the "Changelog Check" GitHub Actions step even if the Changelog.md files are not updated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants