@buoy-gg/env 3.0.1 → 3.0.2
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/lib/commonjs/env/hooks/useDynamicEnv.js +13 -8
- package/lib/commonjs/env/utils/remoteEnv.js +24 -0
- package/lib/commonjs/index.js +17 -1
- package/lib/commonjs/sync/envSyncAdapter.js +38 -0
- package/lib/module/env/hooks/useDynamicEnv.js +13 -8
- package/lib/module/env/utils/remoteEnv.js +19 -0
- package/lib/module/index.js +6 -0
- package/lib/module/sync/envSyncAdapter.js +34 -0
- package/lib/typescript/env/hooks/useDynamicEnv.d.ts.map +1 -1
- package/lib/typescript/env/utils/remoteEnv.d.ts +11 -0
- package/lib/typescript/env/utils/remoteEnv.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/sync/envSyncAdapter.d.ts +19 -0
- package/lib/typescript/sync/envSyncAdapter.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useDynamicEnv = useDynamicEnv;
|
|
7
7
|
var _react = require("react");
|
|
8
|
+
var _remoteEnv = require("../utils/remoteEnv");
|
|
8
9
|
/**
|
|
9
10
|
* Hook that returns all available environment variables with parsed values
|
|
10
11
|
* Includes all available environment variables by default (only EXPO_PUBLIC_ prefixed vars are loaded by Expo)
|
|
@@ -33,11 +34,16 @@ var _react = require("react");
|
|
|
33
34
|
function useDynamicEnv({
|
|
34
35
|
envFilter = () => true // Default: include all available environment variables (EXPO_PUBLIC_ only)
|
|
35
36
|
} = {}) {
|
|
37
|
+
// In remote mirror mode (desktop dashboard) env values come from the
|
|
38
|
+
// synced device instead of the local process.env
|
|
39
|
+
const envSource =
|
|
40
|
+
// @ts-ignore process.env does exist
|
|
41
|
+
(0, _remoteEnv.getRemoteEnv)() ?? process.env;
|
|
42
|
+
|
|
36
43
|
// Helper function to get a single environment variable value
|
|
37
44
|
const getEnvValue = (0, _react.useMemo)(() => {
|
|
38
45
|
return key => {
|
|
39
|
-
|
|
40
|
-
const value = process.env[key];
|
|
46
|
+
const value = envSource[key];
|
|
41
47
|
if (value === undefined) {
|
|
42
48
|
return null;
|
|
43
49
|
}
|
|
@@ -67,21 +73,20 @@ function useDynamicEnv({
|
|
|
67
73
|
return value;
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
|
-
}, []);
|
|
76
|
+
}, [envSource]);
|
|
71
77
|
|
|
72
78
|
// Get all environment variables and process them
|
|
73
79
|
const envResults = (0, _react.useMemo)(() => {
|
|
74
|
-
|
|
75
|
-
const allEnvKeys = Object.keys(process.env);
|
|
80
|
+
const allEnvKeys = Object.keys(envSource);
|
|
76
81
|
const filteredKeys = allEnvKeys.filter(key => {
|
|
77
|
-
|
|
78
|
-
const value = process.env[key];
|
|
82
|
+
const value = envSource[key];
|
|
79
83
|
return envFilter(key, value);
|
|
80
84
|
});
|
|
81
85
|
return filteredKeys.map(key => ({
|
|
82
86
|
key,
|
|
83
87
|
data: getEnvValue(key)
|
|
84
88
|
}));
|
|
85
|
-
|
|
89
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
|
+
}, [envFilter, getEnvValue, envSource]);
|
|
86
91
|
return envResults;
|
|
87
92
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getRemoteEnv = getRemoteEnv;
|
|
7
|
+
exports.setRemoteEnv = setRemoteEnv;
|
|
8
|
+
/**
|
|
9
|
+
* Remote env override for remote mirror mode (desktop dashboard).
|
|
10
|
+
*
|
|
11
|
+
* The dashboard has no meaningful process.env of its own — the env values it
|
|
12
|
+
* shows come from the synced device. When set, useDynamicEnv reads from this
|
|
13
|
+
* map instead of process.env.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
let remoteEnv = null;
|
|
17
|
+
|
|
18
|
+
/** Override the env source. Pass null to restore process.env. */
|
|
19
|
+
function setRemoteEnv(env) {
|
|
20
|
+
remoteEnv = env;
|
|
21
|
+
}
|
|
22
|
+
function getRemoteEnv() {
|
|
23
|
+
return remoteEnv;
|
|
24
|
+
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
envToolPreset: true,
|
|
8
8
|
createEnvTool: true,
|
|
9
|
-
EnvVarsModal: true
|
|
9
|
+
EnvVarsModal: true,
|
|
10
|
+
createEnvSyncAdapter: true,
|
|
11
|
+
setRemoteEnv: true
|
|
10
12
|
};
|
|
11
13
|
Object.defineProperty(exports, "EnvVarsModal", {
|
|
12
14
|
enumerable: true,
|
|
@@ -14,6 +16,12 @@ Object.defineProperty(exports, "EnvVarsModal", {
|
|
|
14
16
|
return _EnvVarsModal.EnvVarsModal;
|
|
15
17
|
}
|
|
16
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "createEnvSyncAdapter", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _envSyncAdapter.createEnvSyncAdapter;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
17
25
|
Object.defineProperty(exports, "createEnvTool", {
|
|
18
26
|
enumerable: true,
|
|
19
27
|
get: function () {
|
|
@@ -26,8 +34,16 @@ Object.defineProperty(exports, "envToolPreset", {
|
|
|
26
34
|
return _preset.envToolPreset;
|
|
27
35
|
}
|
|
28
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "setRemoteEnv", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _remoteEnv.setRemoteEnv;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
29
43
|
var _preset = require("./preset");
|
|
30
44
|
var _EnvVarsModal = require("./env/components/EnvVarsModal");
|
|
45
|
+
var _envSyncAdapter = require("./sync/envSyncAdapter");
|
|
46
|
+
var _remoteEnv = require("./env/utils/remoteEnv");
|
|
31
47
|
var _types = require("./env/types");
|
|
32
48
|
Object.keys(_types).forEach(function (key) {
|
|
33
49
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEnvSyncAdapter = createEnvSyncAdapter;
|
|
7
|
+
/** Collect the device's env vars (only EXPO_PUBLIC_-style vars exist in RN). */
|
|
8
|
+
function collectEnv() {
|
|
9
|
+
const env = {};
|
|
10
|
+
// @ts-ignore process.env does exist
|
|
11
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
12
|
+
if (typeof value === "string") {
|
|
13
|
+
env[key] = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return env;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a sync adapter for the env tool, consumed by @buoy-gg/external-sync's
|
|
21
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
22
|
+
* this package doesn't need a dependency on it).
|
|
23
|
+
*
|
|
24
|
+
* Env vars are baked into the bundle, so the snapshot is static — it's sent
|
|
25
|
+
* once when a dashboard starts watching. Pass the same `requiredEnvVars`
|
|
26
|
+
* config you give FloatingDevTools so the dashboard validates against it.
|
|
27
|
+
*/
|
|
28
|
+
function createEnvSyncAdapter(requiredEnvVars = []) {
|
|
29
|
+
return {
|
|
30
|
+
version: 1,
|
|
31
|
+
getSnapshot: () => ({
|
|
32
|
+
env: collectEnv(),
|
|
33
|
+
requiredEnvVars
|
|
34
|
+
}),
|
|
35
|
+
// Env never changes at runtime — nothing to subscribe to
|
|
36
|
+
subscribe: () => () => {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
import { getRemoteEnv } from "../utils/remoteEnv";
|
|
4
5
|
/**
|
|
5
6
|
* Hook that returns all available environment variables with parsed values
|
|
6
7
|
* Includes all available environment variables by default (only EXPO_PUBLIC_ prefixed vars are loaded by Expo)
|
|
@@ -29,11 +30,16 @@ import { useMemo } from "react";
|
|
|
29
30
|
export function useDynamicEnv({
|
|
30
31
|
envFilter = () => true // Default: include all available environment variables (EXPO_PUBLIC_ only)
|
|
31
32
|
} = {}) {
|
|
33
|
+
// In remote mirror mode (desktop dashboard) env values come from the
|
|
34
|
+
// synced device instead of the local process.env
|
|
35
|
+
const envSource =
|
|
36
|
+
// @ts-ignore process.env does exist
|
|
37
|
+
getRemoteEnv() ?? process.env;
|
|
38
|
+
|
|
32
39
|
// Helper function to get a single environment variable value
|
|
33
40
|
const getEnvValue = useMemo(() => {
|
|
34
41
|
return key => {
|
|
35
|
-
|
|
36
|
-
const value = process.env[key];
|
|
42
|
+
const value = envSource[key];
|
|
37
43
|
if (value === undefined) {
|
|
38
44
|
return null;
|
|
39
45
|
}
|
|
@@ -63,21 +69,20 @@ export function useDynamicEnv({
|
|
|
63
69
|
return value;
|
|
64
70
|
}
|
|
65
71
|
};
|
|
66
|
-
}, []);
|
|
72
|
+
}, [envSource]);
|
|
67
73
|
|
|
68
74
|
// Get all environment variables and process them
|
|
69
75
|
const envResults = useMemo(() => {
|
|
70
|
-
|
|
71
|
-
const allEnvKeys = Object.keys(process.env);
|
|
76
|
+
const allEnvKeys = Object.keys(envSource);
|
|
72
77
|
const filteredKeys = allEnvKeys.filter(key => {
|
|
73
|
-
|
|
74
|
-
const value = process.env[key];
|
|
78
|
+
const value = envSource[key];
|
|
75
79
|
return envFilter(key, value);
|
|
76
80
|
});
|
|
77
81
|
return filteredKeys.map(key => ({
|
|
78
82
|
key,
|
|
79
83
|
data: getEnvValue(key)
|
|
80
84
|
}));
|
|
81
|
-
|
|
85
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
|
+
}, [envFilter, getEnvValue, envSource]);
|
|
82
87
|
return envResults;
|
|
83
88
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Remote env override for remote mirror mode (desktop dashboard).
|
|
5
|
+
*
|
|
6
|
+
* The dashboard has no meaningful process.env of its own — the env values it
|
|
7
|
+
* shows come from the synced device. When set, useDynamicEnv reads from this
|
|
8
|
+
* map instead of process.env.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
let remoteEnv = null;
|
|
12
|
+
|
|
13
|
+
/** Override the env source. Pass null to restore process.env. */
|
|
14
|
+
export function setRemoteEnv(env) {
|
|
15
|
+
remoteEnv = env;
|
|
16
|
+
}
|
|
17
|
+
export function getRemoteEnv() {
|
|
18
|
+
return remoteEnv;
|
|
19
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -6,6 +6,12 @@ export { envToolPreset, createEnvTool } from "./preset";
|
|
|
6
6
|
// Export main modal component
|
|
7
7
|
export { EnvVarsModal } from "./env/components/EnvVarsModal";
|
|
8
8
|
|
|
9
|
+
// External sync (adapter for @buoy-gg/external-sync's useExternalSync)
|
|
10
|
+
export { createEnvSyncAdapter } from "./sync/envSyncAdapter";
|
|
11
|
+
|
|
12
|
+
/** @internal - Remote mirror mode only (desktop dashboard). */
|
|
13
|
+
export { setRemoteEnv } from "./env/utils/remoteEnv";
|
|
14
|
+
|
|
9
15
|
// Export types (Environment, UserRole, RequiredEnvVar, etc.)
|
|
10
16
|
export * from "./env/types";
|
|
11
17
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/** Collect the device's env vars (only EXPO_PUBLIC_-style vars exist in RN). */
|
|
4
|
+
function collectEnv() {
|
|
5
|
+
const env = {};
|
|
6
|
+
// @ts-ignore process.env does exist
|
|
7
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
env[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return env;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a sync adapter for the env tool, consumed by @buoy-gg/external-sync's
|
|
17
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
18
|
+
* this package doesn't need a dependency on it).
|
|
19
|
+
*
|
|
20
|
+
* Env vars are baked into the bundle, so the snapshot is static — it's sent
|
|
21
|
+
* once when a dashboard starts watching. Pass the same `requiredEnvVars`
|
|
22
|
+
* config you give FloatingDevTools so the dashboard validates against it.
|
|
23
|
+
*/
|
|
24
|
+
export function createEnvSyncAdapter(requiredEnvVars = []) {
|
|
25
|
+
return {
|
|
26
|
+
version: 1,
|
|
27
|
+
getSnapshot: () => ({
|
|
28
|
+
env: collectEnv(),
|
|
29
|
+
requiredEnvVars
|
|
30
|
+
}),
|
|
31
|
+
// Env never changes at runtime — nothing to subscribe to
|
|
32
|
+
subscribe: () => () => {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicEnv.d.ts","sourceRoot":"","sources":["../../../../src/env/hooks/useDynamicEnv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDynamicEnv.d.ts","sourceRoot":"","sources":["../../../../src/env/hooks/useDynamicEnv.ts"],"names":[],"mappings":"AAGA,UAAU,oBAAoB;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;CACjE;AAED,UAAU,SAAS;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,SAAsB,GACvB,GAAE,oBAAyB,GAAG,SAAS,EAAE,CA6DzC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote env override for remote mirror mode (desktop dashboard).
|
|
3
|
+
*
|
|
4
|
+
* The dashboard has no meaningful process.env of its own — the env values it
|
|
5
|
+
* shows come from the synced device. When set, useDynamicEnv reads from this
|
|
6
|
+
* map instead of process.env.
|
|
7
|
+
*/
|
|
8
|
+
/** Override the env source. Pass null to restore process.env. */
|
|
9
|
+
export declare function setRemoteEnv(env: Record<string, string> | null): void;
|
|
10
|
+
export declare function getRemoteEnv(): Record<string, string> | null;
|
|
11
|
+
//# sourceMappingURL=remoteEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteEnv.d.ts","sourceRoot":"","sources":["../../../../src/env/utils/remoteEnv.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAErE;AAED,wBAAgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAE5D"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { envToolPreset, createEnvTool } from "./preset";
|
|
2
2
|
export { EnvVarsModal } from "./env/components/EnvVarsModal";
|
|
3
|
+
export { createEnvSyncAdapter } from "./sync/envSyncAdapter";
|
|
4
|
+
/** @internal - Remote mirror mode only (desktop dashboard). */
|
|
5
|
+
export { setRemoteEnv } from "./env/utils/remoteEnv";
|
|
3
6
|
export * from "./env/types";
|
|
4
7
|
export * from "./env/utils";
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,+DAA+D;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RequiredEnvVar } from "../env/types/types";
|
|
2
|
+
/**
|
|
3
|
+
* Create a sync adapter for the env tool, consumed by @buoy-gg/external-sync's
|
|
4
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
5
|
+
* this package doesn't need a dependency on it).
|
|
6
|
+
*
|
|
7
|
+
* Env vars are baked into the bundle, so the snapshot is static — it's sent
|
|
8
|
+
* once when a dashboard starts watching. Pass the same `requiredEnvVars`
|
|
9
|
+
* config you give FloatingDevTools so the dashboard validates against it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createEnvSyncAdapter(requiredEnvVars?: RequiredEnvVar[]): {
|
|
12
|
+
version: number;
|
|
13
|
+
getSnapshot: () => {
|
|
14
|
+
env: Record<string, string>;
|
|
15
|
+
requiredEnvVars: RequiredEnvVar[];
|
|
16
|
+
};
|
|
17
|
+
subscribe: () => () => void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=envSyncAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envSyncAdapter.d.ts","sourceRoot":"","sources":["../../../src/sync/envSyncAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAczD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,GAAE,cAAc,EAAO;;;;;;;EAU1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/env",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Environment variables dev tooling",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@buoy-gg/floating-tools-core": "3.0.
|
|
30
|
-
"@buoy-gg/shared-ui": "3.0.
|
|
29
|
+
"@buoy-gg/floating-tools-core": "3.0.2",
|
|
30
|
+
"@buoy-gg/shared-ui": "3.0.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "*",
|