Skip to content

Commit 2189246

Browse files
Merge pull request #1540 from opencomponents/fix/registry-env-value-types
Allow arbitrary registry environment value types
2 parents fdd5ab1 + e1a61e0 commit 2189246

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"oc": patch
3+
---
4+
5+
Allow registry environment values passed to component `context.env` to use arbitrary JavaScript value types.

‎packages/oc/src/types.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,12 @@ export interface Config<
307307
*/
308308
discoveryFunc?: (opts: { host?: string; secure: boolean }) => boolean;
309309
/**
310-
* Environment variables passed to components in `context.env`.
310+
* Environment values passed to components in `context.env` and the data
311+
* provider's `process.env` shim.
311312
*
312313
* @default {}
313314
*/
314-
env: Record<string, string>;
315+
env: Record<string, any>;
315316
/**
316317
* Maximum execution time of a component’s server-side logic, expressed in
317318
* seconds. When the timeout elapses the registry returns a 500 error.

‎packages/oc/test/fixtures/mocked-components/env.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
}
2121
}
2222
},
23-
data: '"use strict";module.exports.data=function (ctx, cb){cb(null,{ mySecret:ctx.env.secret});};',
23+
data: '"use strict";module.exports.data=function (ctx, cb){cb(null,{ mySecret:ctx.env.secret, contextBoolean:ctx.env.booleanValue, processBoolean:process.env.booleanValue});};',
2424
view:
2525
'var oc=oc||{};oc.components=oc.components||{},oc.components["8c1fbd954f2b0d8cd5cf11c885fed4805225749f"]' +
2626
'=function(){var o=[];return o.push("<div>hello</div>"),o.join("")};'

‎packages/oc/test/unit/registry-routes-helpers-get-component.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('registry : routes : helpers : get-component', () => {
9090
parameters: {},
9191
version: '1.X.X',
9292
conf: {
93-
env: { registry: 'REGISTRYVALUE' },
93+
env: { registry: 'REGISTRYVALUE', booleanValue: false },
9494
baseUrl: 'http://components.com/'
9595
}
9696
},
@@ -100,7 +100,9 @@ describe('registry : routes : helpers : get-component', () => {
100100

101101
it('should put the env data as part of the context, available to the server', () => {
102102
expect(callBack.args[0][0].response.data).to.deep.equal({
103-
mySecret: 'secretvalue'
103+
mySecret: 'secretvalue',
104+
contextBoolean: false,
105+
processBoolean: false
104106
});
105107
});
106108
});

0 commit comments

Comments
 (0)