@secretenvs/contracts 0.0.0-stage → 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ankit Yadav
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @secretenvs/contracts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Single source of truth for data shapes shared by the API, web app, SDK and CLI.
4
+ It exports Zod schemas (requests, responses, query/params, the startup
5
+ environment schema), their inferred types, enums (roles, etc.) and constants
6
+ (limits, key patterns). Inputs are validated with these schemas at every
7
+ boundary; none of the schemas for list responses contain variable values.
8
+
9
+ - `src/schemas.ts` request/response schemas and inferred types
10
+ - `src/enums.ts` and `src/constants.ts` shared enumerations and limits
11
+ - `src/index.ts` public entry point
12
+
13
+ Run `yarn workspace @secretenvs/contracts build` for ESM, CommonJS and matching
14
+ declarations; `dev` watches the sources. Typecheck and test also build the
15
+ package so downstream workspaces can be checked from a clean clone.
16
+
17
+ This package must not depend on any other workspace.
package/dist/index.cjs ADDED
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AddMemberInput: () => AddMemberInput,
24
+ ApiErrorBody: () => ApiErrorBody,
25
+ BulkUpsertVariablesInput: () => BulkUpsertVariablesInput,
26
+ BulkUpsertVariablesResponse: () => BulkUpsertVariablesResponse,
27
+ CSRF_HEADER_NAME: () => CSRF_HEADER_NAME,
28
+ CSRF_HEADER_VALUE: () => CSRF_HEADER_VALUE,
29
+ CreateEnvironmentInput: () => CreateEnvironmentInput,
30
+ CreateProjectInput: () => CreateProjectInput,
31
+ CreateSharedVariableInput: () => CreateSharedVariableInput,
32
+ CreateTokenInput: () => CreateTokenInput,
33
+ CreateVariableInput: () => CreateVariableInput,
34
+ CreatedTokenDto: () => CreatedTokenDto,
35
+ DEFAULT_VERSIONS_LIMIT: () => DEFAULT_VERSIONS_LIMIT,
36
+ EnvironmentDto: () => EnvironmentDto,
37
+ ErrorCode: () => ErrorCode,
38
+ ListVersionsQuery: () => ListVersionsQuery,
39
+ LoginInput: () => LoginInput,
40
+ MAX_BULK_VARIABLES: () => MAX_BULK_VARIABLES,
41
+ MAX_KEY_LENGTH: () => MAX_KEY_LENGTH,
42
+ MAX_NAME_LENGTH: () => MAX_NAME_LENGTH,
43
+ MAX_PASSWORD_LENGTH: () => MAX_PASSWORD_LENGTH,
44
+ MAX_VALUE_BYTES: () => MAX_VALUE_BYTES,
45
+ MAX_VERSIONS_LIMIT: () => MAX_VERSIONS_LIMIT,
46
+ MIN_PASSWORD_LENGTH: () => MIN_PASSWORD_LENGTH,
47
+ MemberDto: () => MemberDto,
48
+ PaginatedVersionsResponse: () => PaginatedVersionsResponse,
49
+ ProjectDto: () => ProjectDto,
50
+ ProjectRole: () => ProjectRole,
51
+ ProjectSummaryDto: () => ProjectSummaryDto,
52
+ RegisterInput: () => RegisterInput,
53
+ ResolvedVariableDto: () => ResolvedVariableDto,
54
+ ResolvedVariablesResponse: () => ResolvedVariablesResponse,
55
+ SLUG_REGEX: () => SLUG_REGEX,
56
+ SdkEnvironmentDto: () => SdkEnvironmentDto,
57
+ SdkProjectDto: () => SdkProjectDto,
58
+ SharedVariableMetaDto: () => SharedVariableMetaDto,
59
+ TOKEN_PREFIX: () => TOKEN_PREFIX,
60
+ TokenAccess: () => TokenAccess,
61
+ TokenDto: () => TokenDto,
62
+ UpdateEnvironmentInput: () => UpdateEnvironmentInput,
63
+ UpdateMemberInput: () => UpdateMemberInput,
64
+ UpdateProjectInput: () => UpdateProjectInput,
65
+ UpdateSharedVariableInput: () => UpdateSharedVariableInput,
66
+ UpdateVariableInput: () => UpdateVariableInput,
67
+ UserDto: () => UserDto,
68
+ VARIABLE_KEY_REGEX: () => VARIABLE_KEY_REGEX,
69
+ VariableMetaDto: () => VariableMetaDto,
70
+ VariableVersionMetaDto: () => VariableVersionMetaDto,
71
+ VariableVersionValueDto: () => VariableVersionValueDto,
72
+ VariableWithValueDto: () => VariableWithValueDto,
73
+ VersionChangeType: () => VersionChangeType,
74
+ apiEnvironmentSchema: () => apiEnvironmentSchema
75
+ });
76
+ module.exports = __toCommonJS(index_exports);
77
+ var import_zod3 = require("zod");
78
+
79
+ // src/constants.ts
80
+ var VARIABLE_KEY_REGEX = /^[A-Z_][A-Z0-9_]*$/;
81
+ var SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
82
+ var MAX_KEY_LENGTH = 128;
83
+ var MAX_VALUE_BYTES = 64 * 1024;
84
+ var MAX_NAME_LENGTH = 64;
85
+ var MAX_BULK_VARIABLES = 500;
86
+ var MIN_PASSWORD_LENGTH = 12;
87
+ var MAX_PASSWORD_LENGTH = 256;
88
+ var DEFAULT_VERSIONS_LIMIT = 20;
89
+ var MAX_VERSIONS_LIMIT = 100;
90
+ var CSRF_HEADER_NAME = "x-requested-with";
91
+ var CSRF_HEADER_VALUE = "secretenvs-web";
92
+ var TOKEN_PREFIX = "svt_";
93
+
94
+ // src/enums.ts
95
+ var import_zod = require("zod");
96
+ var ProjectRole = import_zod.z.enum(["OWNER", "ADMIN", "EDITOR", "VIEWER"]);
97
+ var TokenAccess = import_zod.z.enum(["READ", "READ_WRITE"]);
98
+ var VersionChangeType = import_zod.z.enum(["CREATED", "UPDATED", "ROLLBACK"]);
99
+ var ErrorCode = import_zod.z.enum([
100
+ "VALIDATION_ERROR",
101
+ "BAD_REQUEST",
102
+ "UNAUTHENTICATED",
103
+ "FORBIDDEN",
104
+ "NOT_FOUND",
105
+ "CONFLICT",
106
+ "RATE_LIMITED",
107
+ "INTERNAL"
108
+ ]);
109
+
110
+ // src/schemas.ts
111
+ var import_zod2 = require("zod");
112
+ var id = import_zod2.z.uuid();
113
+ var isoDate = import_zod2.z.iso.datetime();
114
+ var email = import_zod2.z.string().trim().toLowerCase().pipe(import_zod2.z.email().max(254));
115
+ var name = import_zod2.z.string().trim().min(1).max(MAX_NAME_LENGTH);
116
+ var slug = import_zod2.z.string().min(1).max(MAX_NAME_LENGTH).regex(SLUG_REGEX);
117
+ var variableKey = import_zod2.z.string().min(1).max(MAX_KEY_LENGTH).regex(VARIABLE_KEY_REGEX);
118
+ var variableValue = import_zod2.z.string().refine(
119
+ (value) => new TextEncoder().encode(value).length <= MAX_VALUE_BYTES,
120
+ {
121
+ message: `Value must be at most ${MAX_VALUE_BYTES} bytes`
122
+ }
123
+ );
124
+ var password = import_zod2.z.string().min(MIN_PASSWORD_LENGTH).max(MAX_PASSWORD_LENGTH);
125
+ var RegisterInput = import_zod2.z.object({ email, name, password }).strict();
126
+ var LoginInput = import_zod2.z.object({ email, password: import_zod2.z.string().min(1).max(MAX_PASSWORD_LENGTH) }).strict();
127
+ var UserDto = import_zod2.z.object({ id, email, name, createdAt: isoDate }).strict();
128
+ var CreateProjectInput = import_zod2.z.object({ name, slug, description: import_zod2.z.string().max(500).optional() }).strict();
129
+ var UpdateProjectInput = import_zod2.z.object({
130
+ name: name.optional(),
131
+ description: import_zod2.z.string().max(500).nullable().optional()
132
+ }).strict();
133
+ var ProjectDto = import_zod2.z.object({
134
+ id,
135
+ name,
136
+ slug,
137
+ description: import_zod2.z.string().nullable(),
138
+ createdAt: isoDate,
139
+ updatedAt: isoDate
140
+ }).strict();
141
+ var ProjectSummaryDto = ProjectDto.extend({ role: ProjectRole });
142
+ var AddMemberInput = import_zod2.z.object({ email, role: ProjectRole }).strict();
143
+ var UpdateMemberInput = import_zod2.z.object({ role: ProjectRole }).strict();
144
+ var MemberDto = import_zod2.z.object({ userId: id, email, name, role: ProjectRole, createdAt: isoDate }).strict();
145
+ var CreateEnvironmentInput = import_zod2.z.object({ name, slug }).strict();
146
+ var UpdateEnvironmentInput = import_zod2.z.object({ name: name.optional(), slug: slug.optional() }).strict();
147
+ var EnvironmentDto = import_zod2.z.object({
148
+ id,
149
+ projectId: id,
150
+ name,
151
+ slug,
152
+ createdAt: isoDate,
153
+ updatedAt: isoDate
154
+ }).strict();
155
+ var CreateVariableInput = import_zod2.z.object({ key: variableKey, value: variableValue }).strict();
156
+ var UpdateVariableInput = import_zod2.z.object({ value: variableValue }).strict();
157
+ var VariableMetaDto = import_zod2.z.object({
158
+ id,
159
+ key: variableKey,
160
+ currentVersion: import_zod2.z.number().int().min(1),
161
+ updatedAt: isoDate
162
+ }).strict();
163
+ var VariableWithValueDto = VariableMetaDto.extend({
164
+ value: import_zod2.z.string()
165
+ });
166
+ var BulkUpsertVariablesInput = import_zod2.z.object({
167
+ variables: import_zod2.z.array(CreateVariableInput).min(1).max(MAX_BULK_VARIABLES).refine(
168
+ (items) => new Set(items.map((item) => item.key)).size === items.length,
169
+ { message: "Duplicate keys are not allowed" }
170
+ )
171
+ }).strict();
172
+ var BulkUpsertVariablesResponse = import_zod2.z.object({
173
+ created: import_zod2.z.number().int().min(0),
174
+ updated: import_zod2.z.number().int().min(0),
175
+ unchanged: import_zod2.z.number().int().min(0)
176
+ }).strict();
177
+ var environmentIds = import_zod2.z.array(id).max(100);
178
+ var CreateSharedVariableInput = import_zod2.z.object({ key: variableKey, value: variableValue, environmentIds }).strict();
179
+ var UpdateSharedVariableInput = import_zod2.z.object({
180
+ value: variableValue.optional(),
181
+ environmentIds: environmentIds.optional()
182
+ }).strict().refine(
183
+ (input) => input.value !== void 0 || input.environmentIds !== void 0,
184
+ {
185
+ message: "Provide value and/or environmentIds"
186
+ }
187
+ );
188
+ var SharedVariableMetaDto = VariableMetaDto.extend({ environmentIds });
189
+ var ListVersionsQuery = import_zod2.z.object({
190
+ cursor: import_zod2.z.string().min(1).max(256).optional(),
191
+ limit: import_zod2.z.coerce.number().int().min(1).max(MAX_VERSIONS_LIMIT).default(20)
192
+ }).strict();
193
+ var VariableVersionMetaDto = import_zod2.z.object({
194
+ version: import_zod2.z.number().int().min(1),
195
+ changeType: VersionChangeType,
196
+ restoredFromVersion: import_zod2.z.number().int().min(1).nullable().optional(),
197
+ changedBy: import_zod2.z.object({ id, name: import_zod2.z.string() }).strict().nullable(),
198
+ createdAt: isoDate,
199
+ isCurrent: import_zod2.z.boolean()
200
+ }).strict();
201
+ var PaginatedVersionsResponse = import_zod2.z.object({
202
+ items: import_zod2.z.array(VariableVersionMetaDto),
203
+ nextCursor: import_zod2.z.string().optional()
204
+ }).strict();
205
+ var VariableVersionValueDto = import_zod2.z.object({ version: import_zod2.z.number().int().min(1), value: import_zod2.z.string() }).strict();
206
+ var ResolvedVariableDto = import_zod2.z.object({
207
+ key: variableKey,
208
+ value: import_zod2.z.string(),
209
+ source: import_zod2.z.enum(["environment", "shared"])
210
+ }).strict();
211
+ var ResolvedVariablesResponse = import_zod2.z.object({
212
+ project: import_zod2.z.object({ id, slug }).strict(),
213
+ environment: import_zod2.z.object({ id, slug }).strict(),
214
+ variables: import_zod2.z.array(ResolvedVariableDto)
215
+ }).strict();
216
+ var SdkEnvironmentDto = import_zod2.z.object({ id, slug, name }).strict();
217
+ var SdkProjectDto = import_zod2.z.object({
218
+ id,
219
+ slug,
220
+ name,
221
+ role: ProjectRole,
222
+ environments: import_zod2.z.array(SdkEnvironmentDto)
223
+ }).strict();
224
+ var CreateTokenInput = import_zod2.z.object({
225
+ name,
226
+ access: TokenAccess,
227
+ projectId: id.optional(),
228
+ environmentId: id.optional(),
229
+ expiresInDays: import_zod2.z.number().int().min(1).max(365).optional()
230
+ }).strict().refine((input) => !input.environmentId || !!input.projectId, {
231
+ message: "environmentId requires projectId",
232
+ path: ["environmentId"]
233
+ });
234
+ var TokenDto = import_zod2.z.object({
235
+ id,
236
+ name,
237
+ prefix: import_zod2.z.string().length(8),
238
+ access: TokenAccess,
239
+ projectId: id.nullable(),
240
+ environmentId: id.nullable(),
241
+ expiresAt: isoDate.nullable(),
242
+ revokedAt: isoDate.nullable(),
243
+ lastUsedAt: isoDate.nullable(),
244
+ createdAt: isoDate
245
+ }).strict();
246
+ var CreatedTokenDto = TokenDto.extend({ token: import_zod2.z.string().min(1) });
247
+ var ApiErrorBody = import_zod2.z.object({
248
+ error: import_zod2.z.object({
249
+ code: ErrorCode,
250
+ message: import_zod2.z.string(),
251
+ details: import_zod2.z.unknown().optional()
252
+ }).strict()
253
+ }).strict();
254
+
255
+ // src/index.ts
256
+ var apiEnvironmentSchema = import_zod3.z.object({
257
+ NODE_ENV: import_zod3.z.enum(["development", "test", "production"]),
258
+ HOST: import_zod3.z.string().min(1).default("0.0.0.0"),
259
+ PORT: import_zod3.z.coerce.number().int().min(1).max(65535),
260
+ WEB_ORIGIN: import_zod3.z.url().refine((value) => {
261
+ const url = new URL(value);
262
+ return ["http:", "https:"].includes(url.protocol) && url.origin === value;
263
+ }, "Expected an exact HTTP(S) origin"),
264
+ DATABASE_URL: import_zod3.z.url().refine((value) => {
265
+ const url = new URL(value);
266
+ return ["postgres:", "postgresql:"].includes(url.protocol) && !!url.hostname;
267
+ }, "Expected a PostgreSQL connection URL"),
268
+ MASTER_KEY: import_zod3.z.string().regex(
269
+ /^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/,
270
+ "Expected exactly 32 bytes encoded as canonical base64"
271
+ ),
272
+ COOKIE_SECURE: import_zod3.z.enum(["true", "false"]).optional(),
273
+ VARIABLE_HISTORY_LIMIT: import_zod3.z.coerce.number().int().min(1).max(500).default(50),
274
+ // Reverse-proxy hops in front of the API (Express `trust proxy`); 0 trusts none.
275
+ TRUST_PROXY: import_zod3.z.coerce.number().int().min(0).max(10).default(0)
276
+ }).strict().transform((environment) => ({
277
+ ...environment,
278
+ COOKIE_SECURE: environment.COOKIE_SECURE === void 0 ? environment.NODE_ENV === "production" : environment.COOKIE_SECURE === "true"
279
+ }));
280
+ // Annotate the CommonJS export names for ESM import in node:
281
+ 0 && (module.exports = {
282
+ AddMemberInput,
283
+ ApiErrorBody,
284
+ BulkUpsertVariablesInput,
285
+ BulkUpsertVariablesResponse,
286
+ CSRF_HEADER_NAME,
287
+ CSRF_HEADER_VALUE,
288
+ CreateEnvironmentInput,
289
+ CreateProjectInput,
290
+ CreateSharedVariableInput,
291
+ CreateTokenInput,
292
+ CreateVariableInput,
293
+ CreatedTokenDto,
294
+ DEFAULT_VERSIONS_LIMIT,
295
+ EnvironmentDto,
296
+ ErrorCode,
297
+ ListVersionsQuery,
298
+ LoginInput,
299
+ MAX_BULK_VARIABLES,
300
+ MAX_KEY_LENGTH,
301
+ MAX_NAME_LENGTH,
302
+ MAX_PASSWORD_LENGTH,
303
+ MAX_VALUE_BYTES,
304
+ MAX_VERSIONS_LIMIT,
305
+ MIN_PASSWORD_LENGTH,
306
+ MemberDto,
307
+ PaginatedVersionsResponse,
308
+ ProjectDto,
309
+ ProjectRole,
310
+ ProjectSummaryDto,
311
+ RegisterInput,
312
+ ResolvedVariableDto,
313
+ ResolvedVariablesResponse,
314
+ SLUG_REGEX,
315
+ SdkEnvironmentDto,
316
+ SdkProjectDto,
317
+ SharedVariableMetaDto,
318
+ TOKEN_PREFIX,
319
+ TokenAccess,
320
+ TokenDto,
321
+ UpdateEnvironmentInput,
322
+ UpdateMemberInput,
323
+ UpdateProjectInput,
324
+ UpdateSharedVariableInput,
325
+ UpdateVariableInput,
326
+ UserDto,
327
+ VARIABLE_KEY_REGEX,
328
+ VariableMetaDto,
329
+ VariableVersionMetaDto,
330
+ VariableVersionValueDto,
331
+ VariableWithValueDto,
332
+ VersionChangeType,
333
+ apiEnvironmentSchema
334
+ });