Skip to content

Commit 933ea84

Browse files
authored
Change env var names (backward compatible) (#385)
1 parent e7c16f1 commit 933ea84

6 files changed

Lines changed: 65 additions & 29 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@salesforce/mrt-utilities': patch
3+
---
4+
5+
Rename development data-store environment variables from `SFNEXT_DATA_STORE_DEFAULTS`/`SFNEXT_DATA_STORE_WARN_ON_MISSING` to `MRT_DATA_STORE_DEFAULTS`/`MRT_DATA_STORE_WARN_ON_MISSING` and update docs/examples accordingly.

docs/guide/mrt-utilities.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ const entry = await store.getEntry('custom-global-preferences');
168168

169169
Provide local data-store values through environment variables:
170170

171-
- `SFNEXT_DATA_STORE_DEFAULTS`: JSON map of data-store keys to object values
172-
- `SFNEXT_DATA_STORE_WARN_ON_MISSING`: set to `false` to suppress missing-key warnings
171+
- `MRT_DATA_STORE_DEFAULTS`: JSON map of data-store keys to object values
172+
- `MRT_DATA_STORE_WARN_ON_MISSING`: set to `false` to suppress missing-key warnings
173173

174174
Example:
175175

176176
```bash
177-
export SFNEXT_DATA_STORE_DEFAULTS='{"custom-global-preferences":{"featureFlag":true}}'
178-
export SFNEXT_DATA_STORE_WARN_ON_MISSING=true
177+
export MRT_DATA_STORE_DEFAULTS='{"custom-global-preferences":{"featureFlag":true}}'
178+
export MRT_DATA_STORE_WARN_ON_MISSING=true
179179
```
180180

181181
The development pseudo store keeps production parity for missing keys and throws `DataStoreNotFoundError` when a key is not found.

packages/mrt-utilities/DEV-DATA-STORE-PLAN.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ This behavior should be activated through the existing package export condition:
1212

1313
The pseudo local implementation must read default entry values from environment variables (as implied by the provided prototype):
1414

15-
- `SFNEXT_DATA_STORE_DEFAULTS` (JSON object map of key -> value object)
16-
- `SFNEXT_DATA_STORE_WARN_ON_MISSING` (`"false"` disables warnings; default is warning enabled)
15+
- `MRT_DATA_STORE_DEFAULTS` (JSON object map of key -> value object)
16+
- `MRT_DATA_STORE_WARN_ON_MISSING` (`"false"` disables warnings; default is warning enabled)
1717

1818
## Current State
1919

@@ -61,7 +61,7 @@ Use conditional exports to load the development implementation for local dev fro
6161

6262
## 4) Environment variable behavior in dev store
6363

64-
### `SFNEXT_DATA_STORE_DEFAULTS`
64+
### `MRT_DATA_STORE_DEFAULTS`
6565

6666
- Parse as JSON object.
6767
- Expected shape:
@@ -70,7 +70,7 @@ Use conditional exports to load the development implementation for local dev fro
7070
- fall back to empty defaults
7171
- warn once with clear message
7272

73-
### `SFNEXT_DATA_STORE_WARN_ON_MISSING`
73+
### `MRT_DATA_STORE_WARN_ON_MISSING`
7474

7575
- If unset: warnings enabled
7676
- If set to `"false"` (case-insensitive): disable missing-key warnings
@@ -91,10 +91,10 @@ Add/adjust tests to cover both modes:
9191
- **Production tests**
9292
- Keep current behavior assertions unchanged.
9393
- **Development tests**
94-
- Reads defaults from `SFNEXT_DATA_STORE_DEFAULTS`
94+
- Reads defaults from `MRT_DATA_STORE_DEFAULTS`
9595
- Throws `DataStoreNotFoundError` when key is absent (default behavior)
9696
- Warns once per missing key when warnings enabled
97-
- Does not warn when `SFNEXT_DATA_STORE_WARN_ON_MISSING=false`
97+
- Does not warn when `MRT_DATA_STORE_WARN_ON_MISSING=false`
9898
- Handles invalid JSON safely
9999
- (If lenient mode is added) returns `{}` only when explicitly enabled
100100

@@ -128,8 +128,8 @@ Update `packages/mrt-utilities/README.md` (or docs page if preferred) with:
128128
## Acceptance Criteria
129129

130130
- Local development using `--conditions development` no longer fails due to missing DynamoDB/MRT runtime vars.
131-
- Dev data-store entries are sourced from `SFNEXT_DATA_STORE_DEFAULTS`.
132-
- Missing-key behavior is predictable and configurable via `SFNEXT_DATA_STORE_WARN_ON_MISSING`.
131+
- Dev data-store entries are sourced from `MRT_DATA_STORE_DEFAULTS`.
132+
- Missing-key behavior is predictable and configurable via `MRT_DATA_STORE_WARN_ON_MISSING`.
133133
- Production behavior and API remain backward-compatible.
134134
- No breaking public interface changes: existing import paths, exported symbols, and type surface for `@salesforce/mrt-utilities` and `@salesforce/mrt-utilities/data-store` remain intact (except correcting the `development` export target to built `dist` output).
135135
- Default dev missing-key semantics match production (`DataStoreNotFoundError`), with no implicit `{}` fallback.

packages/mrt-utilities/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ const entry = await store.getEntry('custom-global-preferences');
6565

6666
Configure local values with environment variables:
6767

68-
- `SFNEXT_DATA_STORE_DEFAULTS`: JSON map of key to object value
69-
- `SFNEXT_DATA_STORE_WARN_ON_MISSING`: set to `false` to suppress missing-key warnings
68+
- `MRT_DATA_STORE_DEFAULTS`: JSON map of key to object value
69+
- `MRT_DATA_STORE_WARN_ON_MISSING`: set to `false` to suppress missing-key warnings
7070

7171
Example:
7272

7373
```bash
74-
export SFNEXT_DATA_STORE_DEFAULTS='{"custom-global-preferences":{"featureFlag":true}}'
75-
export SFNEXT_DATA_STORE_WARN_ON_MISSING=true
74+
export MRT_DATA_STORE_DEFAULTS='{"custom-global-preferences":{"featureFlag":true}}'
75+
export MRT_DATA_STORE_WARN_ON_MISSING=true
7676
```
7777

7878
By default, missing keys still throw `DataStoreNotFoundError` in development (matching production semantics).

packages/mrt-utilities/src/data-store/development.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class DataStore {
7575
}
7676

7777
function readDefaultsFromEnv(): Record<string, Record<string, unknown>> {
78-
const raw = process.env.SFNEXT_DATA_STORE_DEFAULTS;
78+
const raw = process.env.MRT_DATA_STORE_DEFAULTS ?? process.env.SFNEXT_DATA_STORE_DEFAULTS;
7979
if (!raw) {
8080
return {};
8181
}
@@ -86,14 +86,14 @@ function readDefaultsFromEnv(): Record<string, Record<string, unknown>> {
8686
return parsed as Record<string, Record<string, unknown>>;
8787
}
8888
} catch (error) {
89-
console.warn('Failed to parse SFNEXT_DATA_STORE_DEFAULTS JSON.', error);
89+
console.warn('Failed to parse MRT_DATA_STORE_DEFAULTS JSON.', error);
9090
}
9191

9292
return {};
9393
}
9494

9595
function readWarnOnMissingFromEnv(): boolean {
96-
const raw = process.env.SFNEXT_DATA_STORE_WARN_ON_MISSING;
96+
const raw = process.env.MRT_DATA_STORE_WARN_ON_MISSING ?? process.env.SFNEXT_DATA_STORE_WARN_ON_MISSING;
9797
if (!raw) {
9898
return true;
9999
}

packages/mrt-utilities/test/data-store-development.test.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('DataStore (development)', () => {
2828
expect(store.isDataStoreAvailable()).to.equal(true);
2929
});
3030

31-
it('returns entries from SFNEXT_DATA_STORE_DEFAULTS', async () => {
32-
process.env.SFNEXT_DATA_STORE_DEFAULTS = JSON.stringify({
31+
it('returns entries from MRT_DATA_STORE_DEFAULTS', async () => {
32+
process.env.MRT_DATA_STORE_DEFAULTS = JSON.stringify({
3333
'my-key': {theme: 'dark'},
3434
});
3535

@@ -42,8 +42,22 @@ describe('DataStore (development)', () => {
4242
});
4343
});
4444

45-
it('throws DataStoreNotFoundError for missing keys by default', async () => {
45+
it('falls back to SFNEXT_DATA_STORE_DEFAULTS for backward compatibility', async () => {
4646
process.env.SFNEXT_DATA_STORE_DEFAULTS = JSON.stringify({
47+
'my-key': {theme: 'legacy'},
48+
});
49+
50+
const store = DataStore.getDataStore();
51+
const result = await store.getEntry('my-key');
52+
53+
expect(result).to.deep.equal({
54+
key: 'my-key',
55+
value: {theme: 'legacy'},
56+
});
57+
});
58+
59+
it('throws DataStoreNotFoundError for missing keys by default', async () => {
60+
process.env.MRT_DATA_STORE_DEFAULTS = JSON.stringify({
4761
'other-key': {theme: 'dark'},
4862
});
4963

@@ -59,7 +73,7 @@ describe('DataStore (development)', () => {
5973
});
6074

6175
it('warns once per missing key when warnings are enabled', async () => {
62-
process.env.SFNEXT_DATA_STORE_DEFAULTS = '{}';
76+
process.env.MRT_DATA_STORE_DEFAULTS = '{}';
6377
const warnStub = sinon.stub(console, 'warn');
6478
const store = DataStore.getDataStore();
6579

@@ -75,9 +89,9 @@ describe('DataStore (development)', () => {
7589
expect(warnStub.firstCall.firstArg).to.include("Local data-store provider did not find 'my-key'");
7690
});
7791

78-
it('does not warn for missing keys when SFNEXT_DATA_STORE_WARN_ON_MISSING=false', async () => {
79-
process.env.SFNEXT_DATA_STORE_DEFAULTS = '{}';
80-
process.env.SFNEXT_DATA_STORE_WARN_ON_MISSING = 'false';
92+
it('does not warn for missing keys when MRT_DATA_STORE_WARN_ON_MISSING=false', async () => {
93+
process.env.MRT_DATA_STORE_DEFAULTS = '{}';
94+
process.env.MRT_DATA_STORE_WARN_ON_MISSING = 'false';
8195

8296
const warnStub = sinon.stub(console, 'warn');
8397
const store = DataStore.getDataStore();
@@ -92,8 +106,8 @@ describe('DataStore (development)', () => {
92106
expect(warnStub.called).to.equal(false);
93107
});
94108

95-
it('warns when SFNEXT_DATA_STORE_DEFAULTS is invalid JSON', async () => {
96-
process.env.SFNEXT_DATA_STORE_DEFAULTS = '{"my-key": ';
109+
it('falls back to SFNEXT_DATA_STORE_WARN_ON_MISSING for backward compatibility', async () => {
110+
process.env.MRT_DATA_STORE_DEFAULTS = '{}';
97111
process.env.SFNEXT_DATA_STORE_WARN_ON_MISSING = 'false';
98112

99113
const warnStub = sinon.stub(console, 'warn');
@@ -106,7 +120,24 @@ describe('DataStore (development)', () => {
106120
expect(error).to.be.an.instanceOf(DataStoreNotFoundError);
107121
}
108122

123+
expect(warnStub.called).to.equal(false);
124+
});
125+
126+
it('warns when MRT_DATA_STORE_DEFAULTS is invalid JSON', async () => {
127+
process.env.MRT_DATA_STORE_DEFAULTS = '{"my-key": ';
128+
process.env.MRT_DATA_STORE_WARN_ON_MISSING = 'false';
129+
130+
const warnStub = sinon.stub(console, 'warn');
131+
const store = DataStore.getDataStore();
132+
133+
try {
134+
await store.getEntry('my-key');
135+
expect.fail('should have thrown');
136+
} catch (error) {
137+
expect(error).to.be.an.instanceOf(DataStoreNotFoundError);
138+
}
139+
109140
expect(warnStub.calledOnce).to.equal(true);
110-
expect(warnStub.firstCall.firstArg).to.equal('Failed to parse SFNEXT_DATA_STORE_DEFAULTS JSON.');
141+
expect(warnStub.firstCall.firstArg).to.equal('Failed to parse MRT_DATA_STORE_DEFAULTS JSON.');
111142
});
112143
});

0 commit comments

Comments
 (0)