@webstir-io/module-contract 0.1.13

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/dist/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { z } from 'zod';
2
+ // Centralized manifest contract version used by providers and examples.
3
+ export const CONTRACT_VERSION = '1.0.0';
4
+ export const contractVersionLiteral = z.literal(CONTRACT_VERSION);
5
+ export const moduleKindSchema = z.enum(['frontend', 'backend']);
6
+ export const logLevelSchema = z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']);
7
+ export const moduleErrorCodeSchema = z.enum(['validation', 'auth', 'not_found', 'domain', 'conflict', 'internal']);
8
+ export const moduleErrorSchema = z.object({
9
+ code: moduleErrorCodeSchema,
10
+ message: z.string(),
11
+ details: z.unknown().optional(),
12
+ cause: z.unknown().optional(),
13
+ correlationId: z.string().optional()
14
+ });
15
+ export const httpMethodSchema = z.enum(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']);
16
+ export const schemaReferenceSchema = z.object({
17
+ kind: z.enum(['zod', 'json-schema', 'ts-rest']).default('zod'),
18
+ name: z.string(),
19
+ source: z.string().optional()
20
+ });
21
+ export const routeInputSchema = z
22
+ .object({
23
+ params: schemaReferenceSchema.optional(),
24
+ query: schemaReferenceSchema.optional(),
25
+ body: schemaReferenceSchema.optional(),
26
+ headers: schemaReferenceSchema.optional()
27
+ })
28
+ .partial()
29
+ .strict();
30
+ export const routeOutputSchema = z.object({
31
+ body: schemaReferenceSchema,
32
+ status: z.number().int().min(100).max(599).optional(),
33
+ headers: schemaReferenceSchema.optional()
34
+ });
35
+ export const routeDefinitionSchema = z.object({
36
+ name: z.string().min(1),
37
+ method: httpMethodSchema,
38
+ path: z.string().min(1),
39
+ summary: z.string().optional(),
40
+ description: z.string().optional(),
41
+ tags: z.array(z.string()).optional(),
42
+ input: routeInputSchema.optional(),
43
+ output: routeOutputSchema.optional(),
44
+ errors: z.array(moduleErrorSchema).optional(),
45
+ renderMode: z.enum(['ssg', 'ssr', 'spa']).optional(),
46
+ staticPaths: z.array(z.string().min(1)).optional(),
47
+ ssg: z
48
+ .object({
49
+ revalidateSeconds: z.number().int().positive().optional()
50
+ })
51
+ .optional()
52
+ });
53
+ export const viewDefinitionSchema = z.object({
54
+ name: z.string().min(1),
55
+ path: z.string().min(1),
56
+ summary: z.string().optional(),
57
+ description: z.string().optional(),
58
+ tags: z.array(z.string()).optional(),
59
+ params: schemaReferenceSchema.optional(),
60
+ data: schemaReferenceSchema.optional(),
61
+ renderMode: z.enum(['ssg', 'ssr', 'spa']).optional(),
62
+ staticPaths: z.array(z.string().min(1)).optional(),
63
+ ssg: z
64
+ .object({
65
+ revalidateSeconds: z.number().int().positive().optional()
66
+ })
67
+ .optional()
68
+ });
69
+ export const jobDefinitionSchema = z.object({
70
+ name: z.string().min(1),
71
+ schedule: z.string().optional(),
72
+ priority: z.union([z.number().int(), z.string()]).optional()
73
+ });
74
+ export const eventDefinitionSchema = z.object({
75
+ name: z.string().min(1),
76
+ payload: schemaReferenceSchema.optional(),
77
+ description: z.string().optional()
78
+ });
79
+ export const serviceDefinitionSchema = z.object({
80
+ name: z.string().min(1),
81
+ description: z.string().optional()
82
+ });
83
+ export const moduleManifestSchema = z.object({
84
+ contractVersion: z.string().min(1),
85
+ name: z.string().min(1),
86
+ version: z.string().min(1),
87
+ kind: moduleKindSchema,
88
+ capabilities: z.array(z.string()).optional(),
89
+ // New: optional pass-through lists
90
+ assets: z.array(z.string()).optional(),
91
+ middlewares: z.array(z.string()).optional(),
92
+ routes: z.array(routeDefinitionSchema).optional(),
93
+ views: z.array(viewDefinitionSchema).optional(),
94
+ jobs: z.array(jobDefinitionSchema).optional(),
95
+ events: z.array(eventDefinitionSchema).optional(),
96
+ services: z.array(serviceDefinitionSchema).optional(),
97
+ init: z.string().optional(),
98
+ dispose: z.string().optional()
99
+ });
100
+ export function defineRoute(spec) {
101
+ return spec;
102
+ }
103
+ export function defineView(spec) {
104
+ return spec;
105
+ }
106
+ export function createModule(definition) {
107
+ return definition;
108
+ }
109
+ export { fromTsRestRoute, fromTsRestRouter } from './adapters/ts-rest.js';
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@webstir-io/module-contract",
3
+ "version": "0.1.13",
4
+ "description": "Public contract definitions for Webstir frontend and backend module providers.",
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
+ "default": "./dist/index.js"
13
+ },
14
+ "./ts-rest": {
15
+ "types": "./dist/adapters/ts-rest.d.ts",
16
+ "import": "./dist/adapters/ts-rest.js",
17
+ "default": "./dist/adapters/ts-rest.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "schema"
24
+ ],
25
+ "scripts": {
26
+ "clean": "rm -rf dist schema",
27
+ "build": "npm run build:types && npm run build:schema",
28
+ "build:types": "tsc -p tsconfig.json",
29
+ "build:schema": "node scripts/build-schema.mjs",
30
+ "test": "npm run test:examples",
31
+ "test:examples": "tsc -p tsconfig.examples.json",
32
+ "smoke": "node -e \"console.log('[smoke] no smoke tests configured');\"",
33
+ "release": "bash scripts/publish.sh",
34
+ "prepare": "npm run build"
35
+ },
36
+ "keywords": [
37
+ "webstir",
38
+ "contract",
39
+ "modules"
40
+ ],
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/webstir-io/module-contract"
45
+ },
46
+ "author": "Webstir",
47
+ "dependencies": {
48
+ "zod": "^3.23.8"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^20.19.21",
52
+ "@ts-rest/core": "^3.40.0",
53
+ "typescript": "^5.7.2",
54
+ "zod-to-json-schema": "^3.23.3"
55
+ },
56
+ "peerDependencies": {
57
+ "@ts-rest/core": "^3.40.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "@ts-rest/core": {
61
+ "optional": true
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$ref": "#/definitions/module-error",
3
+ "definitions": {
4
+ "module-error": {
5
+ "type": "object",
6
+ "properties": {
7
+ "code": {
8
+ "type": "string",
9
+ "enum": [
10
+ "validation",
11
+ "auth",
12
+ "not_found",
13
+ "domain",
14
+ "conflict",
15
+ "internal"
16
+ ]
17
+ },
18
+ "message": {
19
+ "type": "string"
20
+ },
21
+ "details": {},
22
+ "cause": {},
23
+ "correlationId": {
24
+ "type": "string"
25
+ }
26
+ },
27
+ "required": [
28
+ "code",
29
+ "message"
30
+ ],
31
+ "additionalProperties": false
32
+ }
33
+ },
34
+ "$schema": "http://json-schema.org/draft-07/schema#"
35
+ }
@@ -0,0 +1,357 @@
1
+ {
2
+ "$ref": "#/definitions/module-manifest",
3
+ "definitions": {
4
+ "module-manifest": {
5
+ "type": "object",
6
+ "properties": {
7
+ "contractVersion": {
8
+ "type": "string",
9
+ "minLength": 1
10
+ },
11
+ "name": {
12
+ "type": "string",
13
+ "minLength": 1
14
+ },
15
+ "version": {
16
+ "type": "string",
17
+ "minLength": 1
18
+ },
19
+ "kind": {
20
+ "type": "string",
21
+ "enum": [
22
+ "frontend",
23
+ "backend"
24
+ ]
25
+ },
26
+ "capabilities": {
27
+ "type": "array",
28
+ "items": {
29
+ "type": "string"
30
+ }
31
+ },
32
+ "assets": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ }
37
+ },
38
+ "middlewares": {
39
+ "type": "array",
40
+ "items": {
41
+ "type": "string"
42
+ }
43
+ },
44
+ "routes": {
45
+ "type": "array",
46
+ "items": {
47
+ "type": "object",
48
+ "properties": {
49
+ "name": {
50
+ "type": "string",
51
+ "minLength": 1
52
+ },
53
+ "method": {
54
+ "type": "string",
55
+ "enum": [
56
+ "GET",
57
+ "HEAD",
58
+ "POST",
59
+ "PUT",
60
+ "PATCH",
61
+ "DELETE",
62
+ "OPTIONS"
63
+ ]
64
+ },
65
+ "path": {
66
+ "type": "string",
67
+ "minLength": 1
68
+ },
69
+ "summary": {
70
+ "type": "string"
71
+ },
72
+ "description": {
73
+ "type": "string"
74
+ },
75
+ "tags": {
76
+ "type": "array",
77
+ "items": {
78
+ "type": "string"
79
+ }
80
+ },
81
+ "input": {
82
+ "type": "object",
83
+ "properties": {
84
+ "params": {
85
+ "type": "object",
86
+ "properties": {
87
+ "kind": {
88
+ "type": "string",
89
+ "enum": [
90
+ "zod",
91
+ "json-schema",
92
+ "ts-rest"
93
+ ],
94
+ "default": "zod"
95
+ },
96
+ "name": {
97
+ "type": "string"
98
+ },
99
+ "source": {
100
+ "type": "string"
101
+ }
102
+ },
103
+ "required": [
104
+ "name"
105
+ ],
106
+ "additionalProperties": false
107
+ },
108
+ "query": {
109
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
110
+ },
111
+ "body": {
112
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
113
+ },
114
+ "headers": {
115
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
116
+ }
117
+ },
118
+ "additionalProperties": false
119
+ },
120
+ "output": {
121
+ "type": "object",
122
+ "properties": {
123
+ "body": {
124
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
125
+ },
126
+ "status": {
127
+ "type": "integer",
128
+ "minimum": 100,
129
+ "maximum": 599
130
+ },
131
+ "headers": {
132
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
133
+ }
134
+ },
135
+ "required": [
136
+ "body"
137
+ ],
138
+ "additionalProperties": false
139
+ },
140
+ "errors": {
141
+ "type": "array",
142
+ "items": {
143
+ "type": "object",
144
+ "properties": {
145
+ "code": {
146
+ "type": "string",
147
+ "enum": [
148
+ "validation",
149
+ "auth",
150
+ "not_found",
151
+ "domain",
152
+ "conflict",
153
+ "internal"
154
+ ]
155
+ },
156
+ "message": {
157
+ "type": "string"
158
+ },
159
+ "details": {},
160
+ "cause": {},
161
+ "correlationId": {
162
+ "type": "string"
163
+ }
164
+ },
165
+ "required": [
166
+ "code",
167
+ "message"
168
+ ],
169
+ "additionalProperties": false
170
+ }
171
+ },
172
+ "renderMode": {
173
+ "type": "string",
174
+ "enum": [
175
+ "ssg",
176
+ "ssr",
177
+ "spa"
178
+ ]
179
+ },
180
+ "staticPaths": {
181
+ "type": "array",
182
+ "items": {
183
+ "type": "string",
184
+ "minLength": 1
185
+ }
186
+ },
187
+ "ssg": {
188
+ "type": "object",
189
+ "properties": {
190
+ "revalidateSeconds": {
191
+ "type": "integer",
192
+ "exclusiveMinimum": 0
193
+ }
194
+ },
195
+ "additionalProperties": false
196
+ }
197
+ },
198
+ "required": [
199
+ "name",
200
+ "method",
201
+ "path"
202
+ ],
203
+ "additionalProperties": false
204
+ }
205
+ },
206
+ "views": {
207
+ "type": "array",
208
+ "items": {
209
+ "type": "object",
210
+ "properties": {
211
+ "name": {
212
+ "type": "string",
213
+ "minLength": 1
214
+ },
215
+ "path": {
216
+ "type": "string",
217
+ "minLength": 1
218
+ },
219
+ "summary": {
220
+ "type": "string"
221
+ },
222
+ "description": {
223
+ "type": "string"
224
+ },
225
+ "tags": {
226
+ "type": "array",
227
+ "items": {
228
+ "type": "string"
229
+ }
230
+ },
231
+ "params": {
232
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
233
+ },
234
+ "data": {
235
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
236
+ },
237
+ "renderMode": {
238
+ "type": "string",
239
+ "enum": [
240
+ "ssg",
241
+ "ssr",
242
+ "spa"
243
+ ]
244
+ },
245
+ "staticPaths": {
246
+ "type": "array",
247
+ "items": {
248
+ "type": "string",
249
+ "minLength": 1
250
+ }
251
+ },
252
+ "ssg": {
253
+ "type": "object",
254
+ "properties": {
255
+ "revalidateSeconds": {
256
+ "type": "integer",
257
+ "exclusiveMinimum": 0
258
+ }
259
+ },
260
+ "additionalProperties": false
261
+ }
262
+ },
263
+ "required": [
264
+ "name",
265
+ "path"
266
+ ],
267
+ "additionalProperties": false
268
+ }
269
+ },
270
+ "jobs": {
271
+ "type": "array",
272
+ "items": {
273
+ "type": "object",
274
+ "properties": {
275
+ "name": {
276
+ "type": "string",
277
+ "minLength": 1
278
+ },
279
+ "schedule": {
280
+ "type": "string"
281
+ },
282
+ "priority": {
283
+ "anyOf": [
284
+ {
285
+ "type": "integer"
286
+ },
287
+ {
288
+ "type": "string"
289
+ }
290
+ ]
291
+ }
292
+ },
293
+ "required": [
294
+ "name"
295
+ ],
296
+ "additionalProperties": false
297
+ }
298
+ },
299
+ "events": {
300
+ "type": "array",
301
+ "items": {
302
+ "type": "object",
303
+ "properties": {
304
+ "name": {
305
+ "type": "string",
306
+ "minLength": 1
307
+ },
308
+ "payload": {
309
+ "$ref": "#/definitions/module-manifest/properties/routes/items/properties/input/properties/params"
310
+ },
311
+ "description": {
312
+ "type": "string"
313
+ }
314
+ },
315
+ "required": [
316
+ "name"
317
+ ],
318
+ "additionalProperties": false
319
+ }
320
+ },
321
+ "services": {
322
+ "type": "array",
323
+ "items": {
324
+ "type": "object",
325
+ "properties": {
326
+ "name": {
327
+ "type": "string",
328
+ "minLength": 1
329
+ },
330
+ "description": {
331
+ "type": "string"
332
+ }
333
+ },
334
+ "required": [
335
+ "name"
336
+ ],
337
+ "additionalProperties": false
338
+ }
339
+ },
340
+ "init": {
341
+ "type": "string"
342
+ },
343
+ "dispose": {
344
+ "type": "string"
345
+ }
346
+ },
347
+ "required": [
348
+ "contractVersion",
349
+ "name",
350
+ "version",
351
+ "kind"
352
+ ],
353
+ "additionalProperties": false
354
+ }
355
+ },
356
+ "$schema": "http://json-schema.org/draft-07/schema#"
357
+ }