@W-20726537 Data access layer middleware#3648
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…cy installations" This reverts commit 82679c3.
| @@ -1,4 +1,6 @@ | |||
| ## v3.16.0-dev (Dec 17, 2025) | |||
| - Add Data Store client [#3648](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3648) | |||
There was a problem hiding this comment.
Since this feature is currently inaccessible to end users, I'm wondering if I should omit this entry?
There was a problem hiding this comment.
Is it technically available but just not "officially released"? Or is it neither?
There was a problem hiding this comment.
It's an undocumented feature that's intended to only be used internally by ECOM and PWA Kit/SF Next (see my answer below).
There was a problem hiding this comment.
I ended up reverting this and adding the skip changelog PR label, but I can add it back if you prefer.
| // 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') |
There was a problem hiding this comment.
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.
| /** | ||
| * 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 | ||
| }) | ||
| ) | ||
| } |
There was a problem hiding this comment.
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.
| * @throws {DataStoreNotFoundError} An entry with the given key cannot be found | ||
| * @throws {DataStoreServiceError} An internal error occurred | ||
| */ | ||
| async getEntry(key) { |
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
bfeister
left a comment
There was a problem hiding this comment.
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.
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
Changes
DataStoremiddleware client (based heavily on theMetricsSender) with public methods for getting the singleton instance, checking if the data store is available, and then fetching an entry from the data access layerHow to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization