@tokengate/env-vite 0.1.0
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 +51 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @tokengate/env-vite
|
|
2
|
+
|
|
3
|
+
[Tokengate](https://tokengate.dev) environment variable integration for **Vite**.
|
|
4
|
+
|
|
5
|
+
Encrypted, type-safe env vars injected at dev and build time.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tokengate/env-vite @tokengate/env
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// vite.config.ts
|
|
17
|
+
import { defineConfig } from 'vite'
|
|
18
|
+
import { tokengate } from '@tokengate/env-vite'
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [
|
|
22
|
+
tokengate({
|
|
23
|
+
schema: {
|
|
24
|
+
VITE_API_URL: { type: 'url', required: true },
|
|
25
|
+
VITE_APP_NAME: { type: 'string', default: 'My App' },
|
|
26
|
+
DATABASE_URL: { type: 'string', required: true, sensitive: true },
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
]
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## How it works
|
|
34
|
+
|
|
35
|
+
- Variables prefixed with `VITE_` are injected into `import.meta.env` (client-safe)
|
|
36
|
+
- All variables are injected into `process.env` (server-side / SSR)
|
|
37
|
+
- Environment auto-detected from Vite's `mode` (`development`, `production`, etc.)
|
|
38
|
+
- Values fetched from Tokengate cloud, decrypted locally, validated against schema
|
|
39
|
+
- Falls back to `.env` files and `process.env`
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
tokengate(config, {
|
|
45
|
+
clientPrefix: 'VITE_', // Prefix for client-exposed vars (default: "VITE_")
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { EnvSchema, TokengateConfig } from "@tokengate/env";
|
|
2
|
+
interface VitePlugin {
|
|
3
|
+
name: string;
|
|
4
|
+
config: (config: Record<string, unknown>, env: {
|
|
5
|
+
mode: string;
|
|
6
|
+
command: string;
|
|
7
|
+
}) => Promise<Record<string, unknown>>;
|
|
8
|
+
configResolved?: (config: Record<string, unknown>) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Vite plugin that loads Tokengate env vars and injects them
|
|
12
|
+
* via Vite's define/env system.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // vite.config.ts
|
|
17
|
+
* import { defineConfig } from 'vite'
|
|
18
|
+
* import { tokengate } from '@tokengate/env-vite'
|
|
19
|
+
*
|
|
20
|
+
* export default defineConfig({
|
|
21
|
+
* plugins: [
|
|
22
|
+
* tokengate({
|
|
23
|
+
* schema: {
|
|
24
|
+
* VITE_API_URL: { type: 'url', required: true },
|
|
25
|
+
* VITE_APP_NAME: { type: 'string', default: 'My App' },
|
|
26
|
+
* DATABASE_URL: { type: 'string', required: true, sensitive: true },
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* ]
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Variables prefixed with `VITE_` are exposed to client code via `import.meta.env`.
|
|
34
|
+
* All others are server-only (available in `process.env` during SSR/build).
|
|
35
|
+
*/
|
|
36
|
+
export declare function tokengate<S extends EnvSchema>(tokengateConfig: TokengateConfig<S>, options?: {
|
|
37
|
+
/** Prefix for client-exposed variables (default: "VITE_") */
|
|
38
|
+
clientPrefix?: string;
|
|
39
|
+
}): VitePlugin;
|
|
40
|
+
/**
|
|
41
|
+
* Re-export core types for convenience.
|
|
42
|
+
*/
|
|
43
|
+
export { defineConfig } from "@tokengate/env";
|
|
44
|
+
export type { EnvSchema, EnvVarSchema, InferEnv, TokengateConfig } from "@tokengate/env";
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjE,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CAC5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAC3C,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE;IACR,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACA,UAAU,CAmDZ;AAED;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @tokengate/env-vite — Vite integration
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { loadEnv, defineConfig } from "@tokengate/env";
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin that loads Tokengate env vars and injects them
|
|
7
|
+
* via Vite's define/env system.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // vite.config.ts
|
|
12
|
+
* import { defineConfig } from 'vite'
|
|
13
|
+
* import { tokengate } from '@tokengate/env-vite'
|
|
14
|
+
*
|
|
15
|
+
* export default defineConfig({
|
|
16
|
+
* plugins: [
|
|
17
|
+
* tokengate({
|
|
18
|
+
* schema: {
|
|
19
|
+
* VITE_API_URL: { type: 'url', required: true },
|
|
20
|
+
* VITE_APP_NAME: { type: 'string', default: 'My App' },
|
|
21
|
+
* DATABASE_URL: { type: 'string', required: true, sensitive: true },
|
|
22
|
+
* }
|
|
23
|
+
* })
|
|
24
|
+
* ]
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Variables prefixed with `VITE_` are exposed to client code via `import.meta.env`.
|
|
29
|
+
* All others are server-only (available in `process.env` during SSR/build).
|
|
30
|
+
*/
|
|
31
|
+
export function tokengate(tokengateConfig, options) {
|
|
32
|
+
const clientPrefix = options?.clientPrefix ?? "VITE_";
|
|
33
|
+
let loaded = false;
|
|
34
|
+
let envResult = {};
|
|
35
|
+
return {
|
|
36
|
+
name: "tokengate-env",
|
|
37
|
+
async config(_config, { mode }) {
|
|
38
|
+
if (loaded)
|
|
39
|
+
return {};
|
|
40
|
+
// Auto-detect environment from Vite mode
|
|
41
|
+
const resolved = defineConfig({
|
|
42
|
+
...tokengateConfig,
|
|
43
|
+
environment: tokengateConfig.environment ?? mode,
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
const result = await loadEnv(resolved);
|
|
47
|
+
envResult = result.env;
|
|
48
|
+
loaded = true;
|
|
49
|
+
// Split into define (client) and env (server)
|
|
50
|
+
const define = {};
|
|
51
|
+
const envOverrides = {};
|
|
52
|
+
for (const [key, value] of Object.entries(envResult)) {
|
|
53
|
+
if (value === undefined || value === null)
|
|
54
|
+
continue;
|
|
55
|
+
const strVal = JSON.stringify(value);
|
|
56
|
+
// Client-exposed vars go into define
|
|
57
|
+
if (key.startsWith(clientPrefix)) {
|
|
58
|
+
define[`import.meta.env.${key}`] = strVal;
|
|
59
|
+
}
|
|
60
|
+
// All vars go into process.env for server-side
|
|
61
|
+
envOverrides[key] = String(value);
|
|
62
|
+
process.env[key] = String(value);
|
|
63
|
+
}
|
|
64
|
+
console.log(`[tokengate] Loaded ${Object.keys(envResult).length} env vars from ${result.source} (${result.loadTime}ms)`);
|
|
65
|
+
return { define };
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error("[tokengate] Failed to load env vars:", err);
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Re-export core types for convenience.
|
|
76
|
+
*/
|
|
77
|
+
export { defineConfig } from "@tokengate/env";
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yCAAyC;AACzC,8EAA8E;AAG9E,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,SAAS,CACvB,eAAmC,EACnC,OAGC;IAED,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,OAAO,CAAC;IACtD,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,SAAS,GAA4B,EAAE,CAAC;IAE5C,OAAO;QACL,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5G,CAAC;gBAEF,OAAO,EAAE,MAAM,EAAE,CAAC;YACpB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;gBAC3D,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokengate/env-vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tokengate environment variable integration for Vite",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"check": "tsc --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"vite",
|
|
24
|
+
"env",
|
|
25
|
+
"environment",
|
|
26
|
+
"secrets",
|
|
27
|
+
"tokengate",
|
|
28
|
+
"encryption"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"author": "Snowy7",
|
|
32
|
+
"homepage": "https://tokengate.dev",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/Snowy7/tokengate.git",
|
|
36
|
+
"directory": "packages/env-vite"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"vite": ">=5.0.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@tokengate/env": "^0.1.0"
|
|
43
|
+
}
|
|
44
|
+
}
|