Skip to content

Commit 0546ef0

Browse files
committed
final review
1 parent c5be9b5 commit 0546ef0

File tree

10 files changed

+38
-45
lines changed

10 files changed

+38
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
## Varlock
1717
> add declarative schema to your .env files using @env-spec decorator comments
1818
19-
- 🛡️ validation, coercion, type safety w/ Intellisense
19+
- 🛡️ validation, coercion, type safety w/ IntelliSense
2020
- 🔏 protection for sensitive config values (log redaction, leak prevention)
2121
- 🌐 flexible multi-environment management
2222
- 💫 composition of values, functions, load from external sources

example-monorepo/packages/plugin-test/.env.schema

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
z# @defaultRequired=infer @defaultSensitive=false
1+
# @defaultRequired=infer @defaultSensitive=false
22
# @generateTypes(lang=ts, path=env.d.ts)
33
#
44
# @currentEnv=$APP_ENV
@@ -25,3 +25,8 @@ FOR_ENV_CHECK=forEnv(dev)
2525
EQ_CHECK=eq(1, 2)
2626

2727
IF_EQ_CHECK=if(eq(1, 1), "yes", "no")
28+
29+
# @required @sensitive
30+
# @docs(https://xyz.com/docs/api-keys)
31+
# @docs("Authentication guide", https://xyz.com/docs/auth-guide)
32+
XYZ_API_KEY=
41.9 KB
Loading

packages/varlock-website/src/content/docs/guides/environments.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ While many have traditionally shied away from using environment-specific `.env`
1414

1515

1616
### Process overrides
17-
`varlock` will always treat environment variables passed into the process with the most precedence. This means you can rely on your external hosting platform to inject environment-specific values and still benefit from `varlock`'s validation and coercion logic.
17+
`varlock` will always treat environment variables passed into the process with the most precedence. Generally, we recommend moving as much configuration as possible into your `.env` files, but there are cases where you may want to override specific values at runtime, either from the environment itself, or by prepending them to your command (e.g., `APP_ENV=prod pnpm run build`).
1818

19-
Sometimes you also may want to pass in env vars via the command line while running a command (e.g. `APP_ENV=prod pnpm run build`).
20-
21-
However, we recommend using injected overrides sparingly, and instead moving more config into your `.env` files.
19+
At the very least, you'll often need to to inject an environment flag (e.g., `APP_ENV`) and a _secret-zero_ which allows access to the rest of your secrets.
2220

21+
That said, as a first step to adopting `varlock`, you could rely entirely on process overrides to inject all config values, but still benefit from having a clear schema with validation applied to them.
2322

2423
### Loading environment-specific `.env` files
2524

packages/varlock-website/src/content/docs/guides/plugins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Plugins allow extending the functionality of Varlock. Specifically they may intr
77

88
```env-spec title="1Password plugin example" "@plugin" "@initOp" "opServiceAccountToken" /op\\(.*\\)/
99
# @plugin(@varlock/1password-plugin) # load + install plugin
10-
# @initOp(allowAppAuth=true) # init via custom root decorator
10+
# @initOp(token=$OP_TOKEN, allowAppAuth=true) # init via custom root decorator
1111
# ---
1212
# @type=opServiceAccountToken # custom data type
1313
OP_TOKEN=

packages/varlock-website/src/content/docs/guides/schema.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Values may be static, or set using [functions](/reference/functions/), which can
4141

4242
**Quote rules:**
4343
- Static values can be wrapped in quotes or not -- all quotes styles (<code>\`</code>, `"`, `'`) are supported
44-
- Values wrapped in single quotes do not support [expansion](#expansion)
44+
- Values wrapped in single quotes do not support [expansion](#ref-expansion)
4545
- Single line values may not contain newlines, but `\n` will be converted to an actual newline except in single quotes
4646
- Multiline values can be wrapped in <code>```</code>, `"""`. Also supported is `"` and `'` but not recommended.
4747
- Unquoted values will be parsed as a number/boolean/undefined where possible (`ITEM=foo` -> `"foo"`, while `ITEM=true` -> `true`), however data-types may further coerce values
@@ -55,6 +55,7 @@ STATIC_VALUE_QUOTED="#hashtag" # and are necessary in some cases
5555
BOOLEAN_VALUE=true
5656
NUMERIC_VALUE=123.456
5757
FUNCTION_VALUE=exec(`op read "op://api-config/item/credential"`)
58+
EXPANSION_VALUE=${OTHER_VAR}-suffix
5859
MULTILINE_VALUE="""
5960
multiple
6061
lines
@@ -112,7 +113,7 @@ Read more about string expansion in the [@env-spec reference](/env-spec/referenc
112113
## Decorator details
113114

114115
### Functions vs single use
115-
Most decorators take a single value (e.g., `@sensitive`) and may be used only once per item, while some are function calls (e.g., `@docs()`) and may be called multiple times.
116+
Most decorators take a single value (e.g., `@sensitive`, `@currentEnv`) and may be used only once per item (or file in the case of a root decorator). Some decorators however, are function calls (e.g., `@docs()`, `@import()`) and may be called multiple times.
116117

117118
```env-spec
118119
# @sensitive=true
@@ -128,7 +129,7 @@ Values passed to decorators will be resolved, meaning if a decorator is expectin
128129
# @required=false
129130
NEVER_REQUIRED=
130131
131-
# @required=forEnv(prod)
132+
# @required=forEnv(prod) # resolves to true/false depending on the current environment
132133
REQUIRED_FOR_PROD=
133134
```
134135

packages/varlock-website/src/content/docs/plugins/1password.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ DB_PASS=op(op://my-vault/database-password/password)
128128
The secret reference for invidivual fields within an item can be found by clicking on the down arrow icon on the field and selecting `Copy Secret Reference`.
129129
:::
130130

131-
If you used the `id` param during initialization and have multiple instances, the `op()` function accepts an optional first parameter to specify which instance id to use.
131+
If you have multiple plugin instances, the `op()` function accepts an optional first parameter to specify which instance id to use.
132132

133133
```env-spec /dev|prod/
134-
# @initOp(id=dev, token=$OP_TOKEN_DEV, allowAppAuth=forEnv(dev))
134+
# @initOp(id=dev, token=$OP_TOKEN_DEV, allowAppAuth=true)
135135
# @initOp(id=prod, token=$OP_TOKEN_PROD, allowAppAuth=false)
136136
# ---
137137
DEV_ITEM=op(dev, op://vault-name/item-name/field-name)

packages/varlock-website/src/content/docs/reference/item-decorators.mdx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "Config Item @decorators"
33
description: A reference page of available env-spec decorators for items
44
---
55
import Decorator from '@/components/decorator-doc-entry.astro'
6+
import docsImg from '@/assets/docs/multiple-docs-intellisense.png'
67

78
Decorators in a comment block _directly_ preceeding a config item will be attached to that item.
89
Multiple decorators can be specified on the same line.
@@ -18,16 +19,19 @@ More details of the minutiae of decorator handling can be found in the [@env-spe
1819

1920
## Built-in item decorators
2021

22+
These are the item decorators that are built into Varlock. [Plugins](/guides/plugins/) may introduce more.
23+
2124
<div class="reference-docs">
2225
<div>
2326
### `@required`
24-
2527
**Value type:** `boolean`
2628

2729
Sets whether an item is _required_ - meaning validation will fail if the value resolves to `undefined` or an empty string.
2830

2931
Default behavior for all items within the same file can be toggled using the [`@defaultRequired` root decorator](/reference/root-decorators/#defaultRequired).
3032

33+
💡 Use the [`forEnv()` function](/reference/functions/#forenv) to set required based on the current environment.
34+
3135
```env-spec
3236
# @defaultRequired=false
3337
# ---
@@ -40,13 +44,10 @@ REQUIRED_FOR_PROD_ITEM=
4044
# @required=eq($OTHER, foo)
4145
REQUIRED_IF_OTHER_IS_FOO=
4246
```
43-
44-
You can also use the [`forEnv()` function](/reference/functions/#forenv) to dynamically set the value based on the current environment.
4547
</div>
4648

4749
<div>
4850
### `@optional`
49-
5051
**Value type:** `boolean`
5152

5253
Opposite of [`@required`](#required). Equivalent to writing `@required=false`.
@@ -57,16 +58,13 @@ Opposite of [`@required`](#required). Equivalent to writing `@required=false`.
5758
# @optional
5859
OPTIONAL_ITEM=
5960
```
60-
61-
You can also use the [`forEnv()` function](/reference/functions/#forenv) to dynamically set the value based on the current environment.
6261
</div>
6362

6463
<div>
6564
### `@sensitive`
66-
6765
**Value type:** `boolean`
6866

69-
Sets whether the item should be considered _sensitive_ - meaning it must be protected from leaking. The value will be always be redacted in CLI output, and client integrations can take further action to prevent leaks.
67+
Sets whether the item should be considered _sensitive_ - meaning it cannot be exposed to the public. The value will be always be redacted in CLI output, and client integrations can take further action to prevent leaks.
7068

7169
Default behavior for all items can be set using the [`@defaultSensitive` root decorator](/reference/root-decorators/#defaultSensitive)
7270

@@ -80,13 +78,12 @@ SERVICE_X_CLIENT_ID=
8078

8179
<div>
8280
### `@type`
83-
8481
**Value type:** [`data type`](/reference/data-types) (name only or function call)
8582

8683
Sets the data type of the item - which affects validation, coercion, and generated types.
8784
Note that some data types take additional arguments. See [data types reference](/reference/data-types) for more details.
8885

89-
If not specified, a data type will be inferred if a static value is set, or default to `string` otherwise.
86+
If not specified, a data type will be inferred when possible, or default to `string` otherwise.
9087

9188
```env-spec
9289
# @type=url # name only
@@ -101,7 +98,6 @@ INFER_NUMBER=123 # data type of `number` will be inferred from the value
10198

10299
<div>
103100
### `@example`
104-
105101
**Value type:** `string`
106102

107103
Provides an example value for the item. This lets you avoid setting placeholder values that are not meant to be used.
@@ -114,30 +110,27 @@ SECRET_KEY=
114110

115111
<div>
116112
### `@docs()`
117-
118113
**Arg types:** `[ url: string ] | [ description: string, url: string ]`
119114

120-
URL of documentation related to the item. Can be called multiple times.
115+
URL of documentation related to the item. Will be included in [generated types](/reference/root-decorators/#generatetypes). _Can be called multiple times._
121116

122117
```env-spec
123118
# @docs(https://xyz.com/docs/api-keys)
124-
# @docs(Authentication guide, https://xyz.com/docs/auth-guide)
119+
# @docs("Authentication guide", https://xyz.com/docs/auth-guide)
125120
XYZ_API_KEY=
126121
```
122+
123+
<img src={docsImg.src} alt="example of docs() in generated types" style="max-width:280px"/>_example of `docs()` info in generated types / IntelliSense_
127124
</div>
128125

129126
<div>
130127
### `@docsUrl` (deprecated) ||docsurl||
131-
132128
**Value type:** `string`
133129

134130
URL of documentation related to the item.
135131

136-
```env-spec
137-
# @docsUrl=https://platform.openai.com/docs/api-reference/authentication
138-
OPENAI_API_KEY=
139-
```
140-
</div>
141-
132+
Use [`@docs()`](#docs) instead, which supports multiple docs entries with optional descriptions.
142133

134+
`@docsUrl=https://example.com` -> `@docs(https://example.com)`
135+
</div>
143136
</div>

packages/varlock-website/src/content/docs/reference/root-decorators.mdx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ Root decorators appear in the _header_ section of a .env file - which is a comme
1212
# @defaultSensitive=false @defaultRequired=infer
1313
# @generateTypes(lang=ts, path=./env.d.ts)
1414
# ---
15-
16-
# ...
15+
# ... config items
1716
```
1817

1918

2019
More details of the minutiae of decorator handling can be found in the [@env-spec reference](/env-spec/reference/#comments-and-decorators).
2120

2221
## Built-in root decorators
2322

23+
These are the root decorators that are built into Varlock. [Plugins](/guides/plugins/) may introduce more.
24+
2425
<div class="reference-docs">
2526

2627
<div>
2728
### `@currentEnv`
28-
2929
**Value type:** [`ref()`](/reference/functions/#ref) (usually written as `$ITEM_NAME`)
3030

3131
Sets the current _environment_ value, which will be used when determining if environment-specific .env files will be loaded (e.g. `.env.production`),
@@ -49,7 +49,6 @@ APP_ENV=dev
4949

5050
<div>
5151
### `@envFlag` (deprecated) ||envflag||
52-
5352
**Value type:** `string` (must be a valid item name within same file)
5453

5554
Sets the current _environment flag_ by name.
@@ -62,12 +61,11 @@ Sets the current _environment flag_ by name.
6261

6362
<div>
6463
### `@defaultRequired`
65-
6664
**Value type:** `boolean | "infer"`
6765

6866
Sets the default behavior of each item being _required_. Only applied to items that have a definition within the same file. Can be overridden on individual items using [`@required`](/reference/item-decorators/#required)/[`@optional`](/reference/item-decorators/#optional).
6967

70-
- `infer` (default): Items with a value set in the same file will be required; items with an empty string or no value are optional. Can be overridden per item.
68+
- `infer` (default): Items with a value set in the same file will be required; items with an empty string or no value are optional.
7169
- `true`: All items are required unless marked optional.
7270
- `false`: All items are optional unless marked required.
7371

@@ -90,7 +88,6 @@ REQUIRED_ITEM= # required (explicit)
9088

9189
<div>
9290
### `@defaultSensitive`
93-
9491
**Value type:** `boolean | inferFromPrefix(PREFIX)`
9592

9693
Sets the default state of each item being treated as [_sensitive_](/guides/secrets/). Only applied to items that have a definition within the same file. Can be overridden on individual items using [`@sensitive`](/reference/item-decorators/#sensitive).
@@ -134,7 +131,6 @@ FOO=bar # will be ignored
134131

135132
<div>
136133
### `@import()`
137-
138134
**Arg types:** `[ path: string, ...keys?: string[] ]`
139135

140136
Imports other `.env` file(s) - useful for sharing config across monorepos and splitting up large schemas. _Can be called multiple times._
@@ -156,7 +152,6 @@ IMPORTED_ITEM=overriden-value
156152

157153
<div>
158154
### `@plugin()`
159-
160155
**Arg types:** `[ identifier: string ]`
161156

162157
Loads a plugin, which can register new root decorators, item decorators, and resolver functions. _Can be called multiple times._
@@ -177,7 +172,6 @@ XYZ_API_KEY=op(op://api-prod/xyz/api-key) # new resolver
177172

178173
<div>
179174
### `@generateTypes()`
180-
181175
**Arg types (key/value):**
182176
- `lang`: Language to generate types for. Supported languages:
183177
- `ts` - TypeScript
@@ -193,7 +187,6 @@ Enables automatic type generation based on your schema. _Can be called multiple
193187

194188
<div>
195189
### `@redactLogs`
196-
197190
**Value type:** `boolean`
198191

199192
Controls whether sensitive config values are automatically redacted from console output. When enabled, any sensitive values will be replaced with `▒▒▒▒▒` in logs.
@@ -226,6 +219,8 @@ We feel that they are beneficial enough to have them on by default but you can a
226219

227220
<div>
228221
### `@preventLeaks`
222+
**Value type:** `boolean`
223+
229224
Controls whether leak prevention is enabled. When enabled, varlock will scan outgoing HTTP responses to detect if sensitive values are being leaked.
230225

231226
_Only applies in JavaScript based projects where varlock runtime code is imported._

packages/varlock-website/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ XYZ_TOKEN=exec('op read "op://api-prod/xyz/auth-token"')
101101
</div>
102102
<Image
103103
src={intellisenseImg}
104-
alt="Intellisense demo"
104+
alt="IntelliSense demo"
105105
class="img-with-border"
106106
/>
107107
</div>

0 commit comments

Comments
 (0)