@salesforce/mrt-utilities 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -45
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/metrics/index.d.ts +1 -0
- package/dist/cjs/metrics/index.js +7 -0
- package/dist/cjs/metrics/index.js.map +1 -0
- package/dist/cjs/metrics/metrics-sender.d.ts +136 -0
- package/dist/cjs/metrics/metrics-sender.js +240 -0
- package/dist/cjs/metrics/metrics-sender.js.map +1 -0
- package/dist/cjs/middleware/data-store.d.ts +56 -0
- package/dist/cjs/middleware/data-store.js +124 -0
- package/dist/cjs/middleware/data-store.js.map +1 -0
- package/dist/cjs/middleware/index.d.ts +3 -0
- package/dist/cjs/middleware/index.js +8 -0
- package/dist/cjs/middleware/index.js.map +1 -0
- package/dist/cjs/middleware/middleware.d.ts +126 -0
- package/dist/cjs/middleware/middleware.js +416 -0
- package/dist/cjs/middleware/middleware.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/streaming/create-lambda-adapter.d.ts +68 -0
- package/dist/cjs/streaming/create-lambda-adapter.js +797 -0
- package/dist/cjs/streaming/create-lambda-adapter.js.map +1 -0
- package/dist/cjs/streaming/index.d.ts +1 -0
- package/dist/cjs/streaming/index.js +7 -0
- package/dist/cjs/streaming/index.js.map +1 -0
- package/dist/cjs/utils/configure-proxying.d.ts +160 -0
- package/dist/cjs/utils/configure-proxying.js +204 -0
- package/dist/cjs/utils/configure-proxying.js.map +1 -0
- package/dist/cjs/utils/ssr-proxying.d.ts +300 -0
- package/dist/cjs/utils/ssr-proxying.js +713 -0
- package/dist/cjs/utils/ssr-proxying.js.map +1 -0
- package/dist/cjs/utils/utils.d.ts +27 -0
- package/dist/cjs/utils/utils.js +44 -0
- package/dist/cjs/utils/utils.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/metrics/index.d.ts +1 -0
- package/dist/esm/metrics/index.js +7 -0
- package/dist/esm/metrics/index.js.map +1 -0
- package/dist/esm/metrics/metrics-sender.d.ts +136 -0
- package/dist/esm/metrics/metrics-sender.js +240 -0
- package/dist/esm/metrics/metrics-sender.js.map +1 -0
- package/dist/esm/middleware/data-store.d.ts +56 -0
- package/dist/esm/middleware/data-store.js +124 -0
- package/dist/esm/middleware/data-store.js.map +1 -0
- package/dist/esm/middleware/index.d.ts +3 -0
- package/dist/esm/middleware/index.js +9 -0
- package/dist/esm/middleware/index.js.map +1 -0
- package/dist/esm/middleware/middleware.d.ts +126 -0
- package/dist/esm/middleware/middleware.js +416 -0
- package/dist/esm/middleware/middleware.js.map +1 -0
- package/dist/esm/streaming/create-lambda-adapter.d.ts +68 -0
- package/dist/esm/streaming/create-lambda-adapter.js +797 -0
- package/dist/esm/streaming/create-lambda-adapter.js.map +1 -0
- package/dist/esm/streaming/index.d.ts +1 -0
- package/dist/esm/streaming/index.js +7 -0
- package/dist/esm/streaming/index.js.map +1 -0
- package/dist/esm/utils/configure-proxying.d.ts +160 -0
- package/dist/esm/utils/configure-proxying.js +204 -0
- package/dist/esm/utils/configure-proxying.js.map +1 -0
- package/dist/esm/utils/ssr-proxying.d.ts +300 -0
- package/dist/esm/utils/ssr-proxying.js +713 -0
- package/dist/esm/utils/ssr-proxying.js.map +1 -0
- package/dist/esm/utils/utils.d.ts +27 -0
- package/dist/esm/utils/utils.js +44 -0
- package/dist/esm/utils/utils.js.map +1 -0
- package/package.json +130 -7
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
7
|
+
import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';
|
|
8
|
+
import { logMRTError } from '../utils/utils.js';
|
|
9
|
+
export class DataStoreNotFoundError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'DataStoreNotFoundError';
|
|
13
|
+
Object.setPrototypeOf(this, DataStoreNotFoundError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class DataStoreServiceError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'DataStoreServiceError';
|
|
20
|
+
Object.setPrototypeOf(this, DataStoreServiceError.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class DataStoreUnavailableError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = 'DataStoreUnavailableError';
|
|
27
|
+
Object.setPrototypeOf(this, DataStoreUnavailableError.prototype);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A class for reading entries from the data store.
|
|
32
|
+
*
|
|
33
|
+
* This class uses a singleton pattern.
|
|
34
|
+
* Use DataStore.getDataStore() to get the singleton instance.
|
|
35
|
+
*/
|
|
36
|
+
export class DataStore {
|
|
37
|
+
_tableName = '';
|
|
38
|
+
_ddb = null;
|
|
39
|
+
static _instance = null;
|
|
40
|
+
/** @internal Test hook: inject a document client for unit tests */
|
|
41
|
+
static _testDocumentClient = null;
|
|
42
|
+
/** @internal Test hook: inject logMRTError for unit tests */
|
|
43
|
+
static _testLogMRTError = null;
|
|
44
|
+
constructor() {
|
|
45
|
+
// Private constructor for singleton; use DataStore.getDataStore() instead.
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get or create a DynamoDB document client (for abstraction of attribute values).
|
|
49
|
+
*
|
|
50
|
+
* @private
|
|
51
|
+
* @returns The DynamoDB document client
|
|
52
|
+
* @throws {DataStoreUnavailableError} The data store is unavailable
|
|
53
|
+
*/
|
|
54
|
+
getClient() {
|
|
55
|
+
if (!this.isDataStoreAvailable()) {
|
|
56
|
+
throw new DataStoreUnavailableError('The data store is unavailable.');
|
|
57
|
+
}
|
|
58
|
+
if (DataStore._testDocumentClient) {
|
|
59
|
+
this._tableName = `DataAccessLayer-${process.env.AWS_REGION}`;
|
|
60
|
+
return DataStore._testDocumentClient;
|
|
61
|
+
}
|
|
62
|
+
if (!this._ddb) {
|
|
63
|
+
this._tableName = `DataAccessLayer-${process.env.AWS_REGION}`;
|
|
64
|
+
this._ddb = DynamoDBDocumentClient.from(new DynamoDBClient({
|
|
65
|
+
region: process.env.AWS_REGION,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return this._ddb;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get or create the singleton DataStore instance.
|
|
72
|
+
*
|
|
73
|
+
* @returns The singleton DataStore instance
|
|
74
|
+
*/
|
|
75
|
+
static getDataStore() {
|
|
76
|
+
if (!DataStore._instance) {
|
|
77
|
+
DataStore._instance = new DataStore();
|
|
78
|
+
}
|
|
79
|
+
return DataStore._instance;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether the data store can be used in the current environment.
|
|
83
|
+
*
|
|
84
|
+
* @returns true if the data store is available, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
isDataStoreAvailable() {
|
|
87
|
+
return Boolean(process.env.AWS_REGION && process.env.MOBIFY_PROPERTY_ID && process.env.DEPLOY_TARGET);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetch an entry from the data store.
|
|
91
|
+
*
|
|
92
|
+
* @param key The data store entry's key
|
|
93
|
+
* @returns An object containing the entry's key and value
|
|
94
|
+
* @throws {DataStoreUnavailableError} The data store is unavailable
|
|
95
|
+
* @throws {DataStoreNotFoundError} An entry with the given key cannot be found
|
|
96
|
+
* @throws {DataStoreServiceError} An internal error occurred
|
|
97
|
+
*/
|
|
98
|
+
async getEntry(key) {
|
|
99
|
+
if (!this.isDataStoreAvailable()) {
|
|
100
|
+
throw new DataStoreUnavailableError('The data store is unavailable.');
|
|
101
|
+
}
|
|
102
|
+
const ddb = this.getClient();
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await ddb.send(new GetCommand({
|
|
106
|
+
TableName: this._tableName,
|
|
107
|
+
Key: {
|
|
108
|
+
projectEnvironment: `${process.env.MOBIFY_PROPERTY_ID} ${process.env.DEPLOY_TARGET}`,
|
|
109
|
+
key,
|
|
110
|
+
},
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const logFn = DataStore._testLogMRTError ?? logMRTError;
|
|
115
|
+
logFn('data_store', error, { key, tableName: this._tableName });
|
|
116
|
+
throw new DataStoreServiceError('Data store request failed.');
|
|
117
|
+
}
|
|
118
|
+
if (!response.Item?.value) {
|
|
119
|
+
throw new DataStoreNotFoundError(`Data store entry '${key}' not found.`);
|
|
120
|
+
}
|
|
121
|
+
return { key, value: response.Item.value };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=data-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-store.js","sourceRoot":"","sources":["../../../src/middleware/data-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAC,sBAAsB,EAAE,UAAU,EAAwB,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,MAAM,CAAC,cAAc,CAAC,IAAI,E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AC,gBAAgB,IAAI,WAAW,CAAC;YACxD,KAAK,CAAC,YAAY,EAAE,KAAK,EAAE,EAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,EAAC,CAAC,CAAC;YAC9D,MAAM,IAAI,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;YAC1B,MAAM,IAAI,sBAAsB,CAAC,qBAAqB,GAAG,cAAc,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,EAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAC,CAAC;IAC3C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
export * from './data-store.js';
|
|
7
|
+
export * from './middleware.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type ProxyResult, type ProxyConfig, type CreateProxyMiddlewareFn } from '../utils/configure-proxying.js';
|
|
2
|
+
import { type RequestHandler, type Response } from 'express';
|
|
3
|
+
export declare const X_MOBIFY_REQUEST_CLASS = "x-mobify-request-class";
|
|
4
|
+
export declare const X_MOBIFY_QUERYSTRING = "x-mobify-querystring";
|
|
5
|
+
export declare const X_MOBIFY_REQUEST_PROCESSOR_LOCAL = "x-mobify-rp-local";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a middleware function that processes incoming requests using a custom request processor.
|
|
8
|
+
*
|
|
9
|
+
* This middleware handles:
|
|
10
|
+
* - Skipping processing for proxy and bundle paths
|
|
11
|
+
* - Loading and executing custom request processors
|
|
12
|
+
* - Processing custom query strings from headers
|
|
13
|
+
* - Removing API Gateway headers
|
|
14
|
+
* - Enforcing HTTP method restrictions for root path
|
|
15
|
+
* - Updating request paths and query strings when paths change
|
|
16
|
+
*
|
|
17
|
+
* @param requestProcessorPath - Path to the request processor module file
|
|
18
|
+
* @param proxyConfigs - Array of proxy configurations
|
|
19
|
+
* @returns Express middleware function
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const middleware = createMRTRequestProcessorMiddleware(
|
|
24
|
+
* '/path/to/processor.js',
|
|
25
|
+
* [{ host: 'https://api.example.com', path: 'api' }]
|
|
26
|
+
* );
|
|
27
|
+
* app.use(middleware);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const createMRTRequestProcessorMiddleware: (requestProcessorPath: string | undefined, proxyConfigs: ProxyConfig[] | undefined) => RequestHandler;
|
|
31
|
+
/**
|
|
32
|
+
* Creates proxy middleware functions for the specified proxy configurations.
|
|
33
|
+
*
|
|
34
|
+
* This function creates Express middleware functions that handle proxying requests
|
|
35
|
+
* to external services. It can optionally create both regular proxy and caching
|
|
36
|
+
* proxy middlewares for each configuration. The app hostname is automatically
|
|
37
|
+
* retrieved from environment variables (EXTERNAL_DOMAIN_NAME or defaults to 'localhost:2401').
|
|
38
|
+
*
|
|
39
|
+
* @param proxyConfigs - Array of proxy configurations
|
|
40
|
+
* @param appProtocol - The protocol to use for the app (defaults to 'http')
|
|
41
|
+
* @param includeCaching - Whether to include caching proxy middlewares (defaults to false)
|
|
42
|
+
* @returns Array of proxy middleware results with their paths
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const proxyMiddlewares = createMRTProxyMiddlewares(
|
|
47
|
+
* [{ host: 'https://api.example.com', path: 'api' }],
|
|
48
|
+
* 'https',
|
|
49
|
+
* true // Include caching middlewares
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* proxyMiddlewares.forEach(({ fn, path }) => {
|
|
53
|
+
* app.use(path, fn);
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const createMRTProxyMiddlewares: (proxyConfigs: ProxyConfig[], appProtocol?: string, includeCaching?: boolean, createProxyFn?: CreateProxyMiddlewareFn) => ProxyResult[];
|
|
58
|
+
/**
|
|
59
|
+
* Sets appropriate HTTP headers for local asset files.
|
|
60
|
+
*
|
|
61
|
+
* This function sets content-type, caching, and other headers for static assets
|
|
62
|
+
* served from the local filesystem. It uses the file's modification time for
|
|
63
|
+
* ETag and Last-Modified headers, and sets no-cache directives for local assets.
|
|
64
|
+
*
|
|
65
|
+
* @param res - Express response object
|
|
66
|
+
* @param assetPath - Path to the asset file
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* app.use('/static', express.static('public', {
|
|
71
|
+
* setHeaders: setLocalAssetHeaders
|
|
72
|
+
* }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare const setLocalAssetHeaders: (res: Response, assetPath: string) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Creates an Express static middleware configured for MRT asset serving.
|
|
78
|
+
*
|
|
79
|
+
* This function creates a static file serving middleware with MRT-specific
|
|
80
|
+
* configurations including custom header setting and security options.
|
|
81
|
+
*
|
|
82
|
+
* @param staticAssetDir - Directory path containing static assets
|
|
83
|
+
* @returns Express static middleware function
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const staticMiddleware = createMRTStaticAssetServingMiddleware('/path/to/assets');
|
|
88
|
+
* app.use('/static', staticMiddleware);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const createMRTStaticAssetServingMiddleware: (staticAssetDir: string) => RequestHandler;
|
|
92
|
+
/**
|
|
93
|
+
* Creates a common middleware function that sets the host header based on environment variables.
|
|
94
|
+
*
|
|
95
|
+
* The host header is set to EXTERNAL_DOMAIN_NAME if available, otherwise defaults to 'localhost:2401'.
|
|
96
|
+
* Use this middleware in all environments (local and deployed), at the top of your middleware stack.
|
|
97
|
+
*
|
|
98
|
+
* @returns Express middleware function
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const middleware = createMRTCommonMiddleware();
|
|
103
|
+
* app.use(middleware);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const createMRTCommonMiddleware: () => RequestHandler;
|
|
107
|
+
/**
|
|
108
|
+
* Creates a cleanup middleware function that removes internal headers and cleans up request state.
|
|
109
|
+
*
|
|
110
|
+
* This middleware performs cleanup operations on requests:
|
|
111
|
+
* - Removes internal MRT headers (X_MOBIFY_REQUEST_PROCESSOR_LOCAL, X_MOBIFY_QUERYSTRING)
|
|
112
|
+
* - Removes API Gateway headers that shouldn't be forwarded
|
|
113
|
+
* - Optionally updates the path and querystring if the request wasn't processed by the request processor
|
|
114
|
+
*
|
|
115
|
+
* Use this middleware in all environments (local and deployed), at the end of the middleware chain,
|
|
116
|
+
* to ensure all internal headers are removed before the request is handled by the application.
|
|
117
|
+
*
|
|
118
|
+
* @returns Express middleware function
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const cleanupMiddleware = createMRTCleanUpMiddleware();
|
|
123
|
+
* app.use(cleanupMiddleware);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare const createMRTCleanUpMiddleware: () => RequestHandler;
|