@game-infra/api-schemas-core 0.0.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 +62 -0
- package/dist/aiProvider.d.ts +23 -0
- package/dist/aiProvider.d.ts.map +1 -0
- package/dist/aiProvider.js +23 -0
- package/dist/aiProvider.js.map +1 -0
- package/dist/apiConfig.d.ts +49 -0
- package/dist/apiConfig.d.ts.map +1 -0
- package/dist/apiConfig.js +39 -0
- package/dist/apiConfig.js.map +1 -0
- package/dist/auth.d.ts +92 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +66 -0
- package/dist/auth.js.map +1 -0
- package/dist/backup.d.ts +82 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +51 -0
- package/dist/backup.js.map +1 -0
- package/dist/common.d.ts +36 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +37 -0
- package/dist/common.js.map +1 -0
- package/dist/contracts.d.ts +420 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +168 -0
- package/dist/contracts.js.map +1 -0
- package/dist/feedback.d.ts +36 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +28 -0
- package/dist/feedback.js.map +1 -0
- package/dist/gameEntity.d.ts +87 -0
- package/dist/gameEntity.d.ts.map +1 -0
- package/dist/gameEntity.js +64 -0
- package/dist/gameEntity.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/savegame.d.ts +55 -0
- package/dist/savegame.d.ts.map +1 -0
- package/dist/savegame.js +38 -0
- package/dist/savegame.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @game-infra/api-schemas-core
|
|
2
|
+
|
|
3
|
+
Generic service API contract: valibot schemas plus [toad-contracts](https://github.com/kibertoad/toad-contracts) `defineApiContract` definitions for auth, savegame, game-entity CRUD, admin backup, feedback, and heartbeat. This is the base contract every game backend and frontend shares; the event-editor, balance, file-storage, and progress-tracker contracts build on it.
|
|
4
|
+
|
|
5
|
+
Published to npm. Also consumable as sibling source (`exports` points at `src/`).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
// pnpm sibling checkout
|
|
11
|
+
"@game-infra/api-schemas-core": "link:../../game-infra/packages/schemas/api-schemas-core"
|
|
12
|
+
// or from npm
|
|
13
|
+
"@game-infra/api-schemas-core": "^0.1.0"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`valibot` is a peer dependency (`^1.4.0`); the consumer provides it.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Contracts carry method, path, params, and request/response schemas in one object. Build a URL with `pathResolver`, derive the route pattern with `mapApiContractToPath`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import {
|
|
24
|
+
authLoginContract,
|
|
25
|
+
gameEntityLoadContract,
|
|
26
|
+
LoginRequestSchema,
|
|
27
|
+
} from "@game-infra/api-schemas-core";
|
|
28
|
+
import { mapApiContractToPath } from "@toad-contracts/valibot";
|
|
29
|
+
|
|
30
|
+
authLoginContract.pathResolver(); // '/auth/login'
|
|
31
|
+
gameEntityLoadContract.pathResolver({ gameId: "g1", entityType: "item", entityId: "e1" });
|
|
32
|
+
// '/games/g1/entities/item/e1'
|
|
33
|
+
mapApiContractToPath(gameEntityLoadContract); // '/games/:gameId/entities/:entityType/:entityId'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Register on a Hono service with `@toad-contracts/hono` (`buildHonoRoute`) and call from a frontend with `@toad-contracts/frontend-http-client` (`sendByApiContract`) — both drive off the same contract objects.
|
|
37
|
+
|
|
38
|
+
The API URL is not hardcoded. Build a resolver per deployment:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createApiUrlResolver } from "@game-infra/api-schemas-core";
|
|
42
|
+
|
|
43
|
+
const { getApiUrl } = createApiUrlResolver({ productionUrl: "https://api.example.com" });
|
|
44
|
+
getApiUrl(window.location.hostname); // dev URL on localhost, prod otherwise
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Extension points
|
|
48
|
+
|
|
49
|
+
- **Entity types**: `entityType` is a plain `string()`. The old `EntityTypes` enum (spell/item/persona/secret) was dropped; games re-tighten it via their own config/validation.
|
|
50
|
+
- **AI provider**: `AI_PROVIDERS` / `AIProviderSchema` are the single source of truth for the `provider` field used across AI endpoints.
|
|
51
|
+
|
|
52
|
+
## Migrating from golem-forge
|
|
53
|
+
|
|
54
|
+
The old `ApiPaths` constants and `PathResolvers` / `resolve*Path` helpers are gone. Get a URL from the contract itself with `contract.pathResolver(params)` and the `:param` route pattern with `mapApiContractToPath(contract)`. Prefer driving requests through `@toad-contracts/frontend-http-client` (`sendByApiContract`) and routes through `@toad-contracts/hono` (`buildHonoRoute`), which consume the contract directly so you never touch a raw path. Event-editor and hex routes moved to their own packages.
|
|
55
|
+
|
|
56
|
+
## Dependencies
|
|
57
|
+
|
|
58
|
+
`@toad-contracts/core`, `@toad-contracts/valibot`; peer `valibot`. No internal `@game-infra/*` deps.
|
|
59
|
+
|
|
60
|
+
## Consumers
|
|
61
|
+
|
|
62
|
+
`core-service` (auth/feedback/backup/heartbeat endpoints), game frontends (`shared-fe`), and the other `*-schemas` packages, which re-use `createSuccessResponseSchema` and `AIProviderSchema`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported AI providers.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the provider field used by every AI-assisted
|
|
5
|
+
* endpoint contract (event generation, review, balance assist). Games and
|
|
6
|
+
* services pick one of these when calling an AI endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { AI_PROVIDERS, type AIProviderType } from '@game-infra/api-schemas-core'
|
|
11
|
+
*
|
|
12
|
+
* const provider: AIProviderType = 'claude'
|
|
13
|
+
* console.log(AI_PROVIDERS) // ['claude', 'mistral', 'openai']
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const AI_PROVIDERS: readonly ["claude", "mistral", "openai"];
|
|
17
|
+
export type AIProviderType = (typeof AI_PROVIDERS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* Valibot schema accepting any of {@link AI_PROVIDERS}. Use in request schemas
|
|
20
|
+
* that carry a `provider` field.
|
|
21
|
+
*/
|
|
22
|
+
export declare const AIProviderSchema: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"claude", undefined>, import("valibot").LiteralSchema<"mistral", undefined>, import("valibot").LiteralSchema<"openai", undefined>], undefined>;
|
|
23
|
+
//# sourceMappingURL=aiProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiProvider.d.ts","sourceRoot":"","sources":["../src/aiProvider.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,YAAI,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,+MAAoE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { literal, union } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Supported AI providers.
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for the provider field used by every AI-assisted
|
|
6
|
+
* endpoint contract (event generation, review, balance assist). Games and
|
|
7
|
+
* services pick one of these when calling an AI endpoint.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { AI_PROVIDERS, type AIProviderType } from '@game-infra/api-schemas-core'
|
|
12
|
+
*
|
|
13
|
+
* const provider: AIProviderType = 'claude'
|
|
14
|
+
* console.log(AI_PROVIDERS) // ['claude', 'mistral', 'openai']
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const AI_PROVIDERS = ["claude", "mistral", "openai"];
|
|
18
|
+
/**
|
|
19
|
+
* Valibot schema accepting any of {@link AI_PROVIDERS}. Use in request schemas
|
|
20
|
+
* that carry a `provider` field.
|
|
21
|
+
*/
|
|
22
|
+
export const AIProviderSchema = union([literal("claude"), literal("mistral"), literal("openai")]);
|
|
23
|
+
//# sourceMappingURL=aiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiProvider.js","sourceRoot":"","sources":["../src/aiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAIrE;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API URL configuration.
|
|
3
|
+
*
|
|
4
|
+
* The production URL was hardcoded to a golem-specific host in golem-forge. Here
|
|
5
|
+
* it is a factory: each consumer supplies its own production/development URLs and
|
|
6
|
+
* gets back a `getApiUrl(hostname)` resolver. This keeps the schema package free
|
|
7
|
+
* of any deployment-specific hostnames.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default development API URL (local Cloudflare Worker via `wrangler dev`).
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_DEVELOPMENT_API_URL = "http://localhost:8787";
|
|
13
|
+
/**
|
|
14
|
+
* Options for {@link createApiUrlResolver}.
|
|
15
|
+
*/
|
|
16
|
+
export interface ApiUrlResolverOptions {
|
|
17
|
+
/** URL used for every non-localhost hostname (your deployed backend). */
|
|
18
|
+
productionUrl: string;
|
|
19
|
+
/** URL used when the hostname is `localhost`. Defaults to {@link DEFAULT_DEVELOPMENT_API_URL}. */
|
|
20
|
+
developmentUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A hostname-aware API URL resolver.
|
|
24
|
+
*/
|
|
25
|
+
export interface ApiUrlResolver {
|
|
26
|
+
/** Resolve the API URL for a hostname (e.g. `window.location.hostname`). */
|
|
27
|
+
getApiUrl(hostname?: string): string;
|
|
28
|
+
/** The configured production URL. */
|
|
29
|
+
readonly productionUrl: string;
|
|
30
|
+
/** The configured development URL. */
|
|
31
|
+
readonly developmentUrl: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build an API URL resolver that returns the development URL on `localhost` and
|
|
35
|
+
* the production URL everywhere else.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createApiUrlResolver } from '@game-infra/api-schemas-core'
|
|
40
|
+
*
|
|
41
|
+
* const { getApiUrl } = createApiUrlResolver({
|
|
42
|
+
* productionUrl: 'https://api.example.com',
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* getApiUrl(window.location.hostname) // dev on localhost, prod otherwise
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function createApiUrlResolver(options: ApiUrlResolverOptions): ApiUrlResolver;
|
|
49
|
+
//# sourceMappingURL=apiConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiConfig.d.ts","sourceRoot":"","sources":["../src/apiConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,qCAAqC;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAWnF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API URL configuration.
|
|
3
|
+
*
|
|
4
|
+
* The production URL was hardcoded to a golem-specific host in golem-forge. Here
|
|
5
|
+
* it is a factory: each consumer supplies its own production/development URLs and
|
|
6
|
+
* gets back a `getApiUrl(hostname)` resolver. This keeps the schema package free
|
|
7
|
+
* of any deployment-specific hostnames.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default development API URL (local Cloudflare Worker via `wrangler dev`).
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_DEVELOPMENT_API_URL = "http://localhost:8787";
|
|
13
|
+
/**
|
|
14
|
+
* Build an API URL resolver that returns the development URL on `localhost` and
|
|
15
|
+
* the production URL everywhere else.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createApiUrlResolver } from '@game-infra/api-schemas-core'
|
|
20
|
+
*
|
|
21
|
+
* const { getApiUrl } = createApiUrlResolver({
|
|
22
|
+
* productionUrl: 'https://api.example.com',
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* getApiUrl(window.location.hostname) // dev on localhost, prod otherwise
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function createApiUrlResolver(options) {
|
|
29
|
+
const productionUrl = options.productionUrl;
|
|
30
|
+
const developmentUrl = options.developmentUrl ?? DEFAULT_DEVELOPMENT_API_URL;
|
|
31
|
+
return {
|
|
32
|
+
productionUrl,
|
|
33
|
+
developmentUrl,
|
|
34
|
+
getApiUrl(hostname = "localhost") {
|
|
35
|
+
return hostname === "localhost" ? developmentUrl : productionUrl;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=apiConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiConfig.js","sourceRoot":"","sources":["../src/apiConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AAwBnE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC5C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,2BAA2B,CAAC;IAE7E,OAAO;QACL,aAAa;QACb,cAAc;QACd,SAAS,CAAC,QAAQ,GAAG,WAAW;YAC9B,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type InferOutput } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Validation constants - single source of truth for both FE and BE
|
|
4
|
+
*/
|
|
5
|
+
export declare const AuthValidation: {
|
|
6
|
+
readonly MIN_PASSWORD_LENGTH: 6;
|
|
7
|
+
readonly MAX_PASSWORD_LENGTH: 128;
|
|
8
|
+
readonly MIN_USERNAME_LENGTH: 3;
|
|
9
|
+
readonly MAX_USERNAME_LENGTH: 64;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Registration request schema
|
|
13
|
+
*/
|
|
14
|
+
export declare const RegisterRequestSchema: import("valibot").ObjectSchema<{
|
|
15
|
+
readonly email: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").EmailAction<string, undefined>]>;
|
|
16
|
+
readonly username: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").MinLengthAction<string, 3, undefined>, import("valibot").MaxLengthAction<string, 64, undefined>]>;
|
|
17
|
+
readonly password: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").MinLengthAction<string, 6, undefined>, import("valibot").MaxLengthAction<string, 128, undefined>]>;
|
|
18
|
+
}, undefined>;
|
|
19
|
+
export type RegisterRequest = InferOutput<typeof RegisterRequestSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Common auth response fields (used by both register and login)
|
|
22
|
+
*/
|
|
23
|
+
export declare const AuthResponseFieldsSchema: {
|
|
24
|
+
token: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
25
|
+
userId: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
26
|
+
username: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Registration response schema
|
|
30
|
+
*/
|
|
31
|
+
export declare const RegisterResponseSchema: import("valibot").ObjectSchema<{
|
|
32
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
33
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
34
|
+
} & {
|
|
35
|
+
token: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
36
|
+
userId: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
37
|
+
username: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
38
|
+
}, undefined>;
|
|
39
|
+
export type RegisterResponse = InferOutput<typeof RegisterResponseSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* Login request schema
|
|
42
|
+
*/
|
|
43
|
+
export declare const LoginRequestSchema: import("valibot").ObjectSchema<{
|
|
44
|
+
readonly identifier: import("valibot").StringSchema<undefined>;
|
|
45
|
+
readonly password: import("valibot").StringSchema<undefined>;
|
|
46
|
+
}, undefined>;
|
|
47
|
+
export type LoginRequest = InferOutput<typeof LoginRequestSchema>;
|
|
48
|
+
/**
|
|
49
|
+
* Login response schema
|
|
50
|
+
* Reuses the same fields as RegisterResponse
|
|
51
|
+
*/
|
|
52
|
+
export declare const LoginResponseSchema: import("valibot").ObjectSchema<{
|
|
53
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
54
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
55
|
+
} & {
|
|
56
|
+
token: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
57
|
+
userId: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
58
|
+
username: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
59
|
+
}, undefined>;
|
|
60
|
+
export type LoginResponse = InferOutput<typeof LoginResponseSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* Validate token request schema
|
|
63
|
+
*/
|
|
64
|
+
export declare const ValidateTokenRequestSchema: import("valibot").ObjectSchema<{
|
|
65
|
+
readonly token: import("valibot").StringSchema<undefined>;
|
|
66
|
+
}, undefined>;
|
|
67
|
+
export type ValidateTokenRequest = InferOutput<typeof ValidateTokenRequestSchema>;
|
|
68
|
+
/**
|
|
69
|
+
* Validate token response schema
|
|
70
|
+
*/
|
|
71
|
+
export declare const ValidateTokenResponseSchema: import("valibot").ObjectSchema<{
|
|
72
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
73
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
74
|
+
} & {
|
|
75
|
+
valid: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
|
|
76
|
+
userId: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
77
|
+
username: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
78
|
+
}, undefined>;
|
|
79
|
+
export type ValidateTokenResponse = InferOutput<typeof ValidateTokenResponseSchema>;
|
|
80
|
+
/**
|
|
81
|
+
* Validate service token response schema
|
|
82
|
+
* Used by other services (e.g., file-storage-service) to validate API tokens against golem-castle
|
|
83
|
+
* This endpoint validates the shared API_TOKEN used for service-to-service communication
|
|
84
|
+
*/
|
|
85
|
+
export declare const ValidateServiceTokenResponseSchema: import("valibot").ObjectSchema<{
|
|
86
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
87
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
88
|
+
} & {
|
|
89
|
+
valid: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
|
|
90
|
+
}, undefined>;
|
|
91
|
+
export type ValidateServiceTokenResponse = InferOutput<typeof ValidateServiceTokenResponseSchema>;
|
|
92
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAUjB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,eAAO,MAAM,cAAc;aACzB,mBAAmB,EAAE,CAAC;aACtB,mBAAmB,EAAE,GAAG;aACxB,mBAAmB,EAAE,CAAC;aACtB,mBAAmB,EAAE,EAAE;CACf,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;aAYhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,wBAAwB;IACnC,KAAK;IACL,MAAM;IACN,QAAQ;CACT,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;aAAwD,CAAC;AAE5F,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;aAG7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAElE;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;aAAwD,CAAC;AAEzF,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,0BAA0B;;aAErC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;aAItC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEpF;;;;GAIG;AACH,eAAO,MAAM,kCAAkC;;;;;aAE7C,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,WAAW,CAAC,OAAO,kCAAkC,CAAC,CAAC"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { boolean, email, maxLength, minLength, number, object, optional, pipe, string, } from "valibot";
|
|
2
|
+
import { createSuccessResponseSchema } from "./common.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validation constants - single source of truth for both FE and BE
|
|
5
|
+
*/
|
|
6
|
+
export const AuthValidation = {
|
|
7
|
+
MIN_PASSWORD_LENGTH: 6,
|
|
8
|
+
MAX_PASSWORD_LENGTH: 128,
|
|
9
|
+
MIN_USERNAME_LENGTH: 3,
|
|
10
|
+
MAX_USERNAME_LENGTH: 64,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Registration request schema
|
|
14
|
+
*/
|
|
15
|
+
export const RegisterRequestSchema = object({
|
|
16
|
+
email: pipe(string(), email()),
|
|
17
|
+
username: pipe(string(), minLength(AuthValidation.MIN_USERNAME_LENGTH), maxLength(AuthValidation.MAX_USERNAME_LENGTH)),
|
|
18
|
+
password: pipe(string(), minLength(AuthValidation.MIN_PASSWORD_LENGTH), maxLength(AuthValidation.MAX_PASSWORD_LENGTH)),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Common auth response fields (used by both register and login)
|
|
22
|
+
*/
|
|
23
|
+
export const AuthResponseFieldsSchema = {
|
|
24
|
+
token: optional(string()),
|
|
25
|
+
userId: optional(number()),
|
|
26
|
+
username: optional(string()),
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Registration response schema
|
|
30
|
+
*/
|
|
31
|
+
export const RegisterResponseSchema = createSuccessResponseSchema(AuthResponseFieldsSchema);
|
|
32
|
+
/**
|
|
33
|
+
* Login request schema
|
|
34
|
+
*/
|
|
35
|
+
export const LoginRequestSchema = object({
|
|
36
|
+
identifier: string(), // email or username
|
|
37
|
+
password: string(),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Login response schema
|
|
41
|
+
* Reuses the same fields as RegisterResponse
|
|
42
|
+
*/
|
|
43
|
+
export const LoginResponseSchema = createSuccessResponseSchema(AuthResponseFieldsSchema);
|
|
44
|
+
/**
|
|
45
|
+
* Validate token request schema
|
|
46
|
+
*/
|
|
47
|
+
export const ValidateTokenRequestSchema = object({
|
|
48
|
+
token: string(),
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Validate token response schema
|
|
52
|
+
*/
|
|
53
|
+
export const ValidateTokenResponseSchema = createSuccessResponseSchema({
|
|
54
|
+
valid: optional(boolean()),
|
|
55
|
+
userId: optional(number()),
|
|
56
|
+
username: optional(string()),
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Validate service token response schema
|
|
60
|
+
* Used by other services (e.g., file-storage-service) to validate API tokens against golem-castle
|
|
61
|
+
* This endpoint validates the shared API_TOKEN used for service-to-service communication
|
|
62
|
+
*/
|
|
63
|
+
export const ValidateServiceTokenResponseSchema = createSuccessResponseSchema({
|
|
64
|
+
valid: optional(boolean()),
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,KAAK,EACL,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,GAAG;IACxB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,EAAE;CACf,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;IAC1C,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC;IAC9B,QAAQ,EAAE,IAAI,CACZ,MAAM,EAAE,EACR,SAAS,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAC7C,SAAS,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAC9C;IACD,QAAQ,EAAE,IAAI,CACZ,MAAM,EAAE,EACR,SAAS,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAC7C,SAAS,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAC9C;CACF,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,2BAA2B,CAAC,wBAAwB,CAAC,CAAC;AAI5F;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;IACvC,UAAU,EAAE,MAAM,EAAE,EAAE,oBAAoB;IAC1C,QAAQ,EAAE,MAAM,EAAE;CACnB,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,2BAA2B,CAAC,wBAAwB,CAAC,CAAC;AAIzF;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;IAC/C,KAAK,EAAE,MAAM,EAAE;CAChB,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;IACrE,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC7B,CAAC,CAAC;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,2BAA2B,CAAC;IAC5E,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;CAC3B,CAAC,CAAC"}
|
package/dist/backup.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type InferOutput } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Backup info schema
|
|
4
|
+
* Represents metadata about a stored backup
|
|
5
|
+
*/
|
|
6
|
+
export declare const BackupInfoSchema: import("valibot").ObjectSchema<{
|
|
7
|
+
readonly storageId: import("valibot").StringSchema<undefined>;
|
|
8
|
+
readonly filename: import("valibot").StringSchema<undefined>;
|
|
9
|
+
readonly recordCount: import("valibot").NumberSchema<undefined>;
|
|
10
|
+
readonly size: import("valibot").NumberSchema<undefined>;
|
|
11
|
+
readonly createdAt: import("valibot").StringSchema<undefined>;
|
|
12
|
+
readonly gameId: import("valibot").StringSchema<undefined>;
|
|
13
|
+
}, undefined>;
|
|
14
|
+
export type BackupInfo = InferOutput<typeof BackupInfoSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* Trigger backup response schema
|
|
17
|
+
*/
|
|
18
|
+
export declare const TriggerBackupResponseSchema: import("valibot").ObjectSchema<{
|
|
19
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
20
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
21
|
+
} & {
|
|
22
|
+
storageId: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
23
|
+
filename: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
24
|
+
recordCount: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
25
|
+
size: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
26
|
+
}, undefined>;
|
|
27
|
+
export type TriggerBackupResponse = InferOutput<typeof TriggerBackupResponseSchema>;
|
|
28
|
+
/**
|
|
29
|
+
* List backups response schema
|
|
30
|
+
*/
|
|
31
|
+
export declare const ListBackupsResponseSchema: import("valibot").ObjectSchema<{
|
|
32
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
33
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
34
|
+
} & {
|
|
35
|
+
backups: import("valibot").OptionalSchema<import("valibot").ArraySchema<import("valibot").ObjectSchema<{
|
|
36
|
+
readonly storageId: import("valibot").StringSchema<undefined>;
|
|
37
|
+
readonly filename: import("valibot").StringSchema<undefined>;
|
|
38
|
+
readonly recordCount: import("valibot").NumberSchema<undefined>;
|
|
39
|
+
readonly size: import("valibot").NumberSchema<undefined>;
|
|
40
|
+
readonly createdAt: import("valibot").StringSchema<undefined>;
|
|
41
|
+
readonly gameId: import("valibot").StringSchema<undefined>;
|
|
42
|
+
}, undefined>, undefined>, undefined>;
|
|
43
|
+
}, undefined>;
|
|
44
|
+
export type ListBackupsResponse = InferOutput<typeof ListBackupsResponseSchema>;
|
|
45
|
+
/**
|
|
46
|
+
* Restore from backup request schema
|
|
47
|
+
*/
|
|
48
|
+
export declare const RestoreBackupRequestSchema: import("valibot").ObjectSchema<{
|
|
49
|
+
readonly storageId: import("valibot").StringSchema<undefined>;
|
|
50
|
+
readonly gameId: import("valibot").StringSchema<undefined>;
|
|
51
|
+
}, undefined>;
|
|
52
|
+
export type RestoreBackupRequest = InferOutput<typeof RestoreBackupRequestSchema>;
|
|
53
|
+
/**
|
|
54
|
+
* Restore from backup response schema
|
|
55
|
+
*/
|
|
56
|
+
export declare const RestoreBackupResponseSchema: import("valibot").ObjectSchema<{
|
|
57
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
58
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
59
|
+
} & {
|
|
60
|
+
restoredCount: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, undefined>;
|
|
61
|
+
preRestoreBackupStorageId: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
62
|
+
}, undefined>;
|
|
63
|
+
export type RestoreBackupResponse = InferOutput<typeof RestoreBackupResponseSchema>;
|
|
64
|
+
/**
|
|
65
|
+
* Download backup response schema
|
|
66
|
+
* Content is streamed back
|
|
67
|
+
*/
|
|
68
|
+
export declare const DownloadBackupResponseSchema: import("valibot").ObjectSchema<{
|
|
69
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
70
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
71
|
+
} & {
|
|
72
|
+
backup: import("valibot").OptionalSchema<import("valibot").ObjectSchema<{
|
|
73
|
+
readonly storageId: import("valibot").StringSchema<undefined>;
|
|
74
|
+
readonly filename: import("valibot").StringSchema<undefined>;
|
|
75
|
+
readonly recordCount: import("valibot").NumberSchema<undefined>;
|
|
76
|
+
readonly size: import("valibot").NumberSchema<undefined>;
|
|
77
|
+
readonly createdAt: import("valibot").StringSchema<undefined>;
|
|
78
|
+
readonly gameId: import("valibot").StringSchema<undefined>;
|
|
79
|
+
}, undefined>, undefined>;
|
|
80
|
+
}, undefined>;
|
|
81
|
+
export type DownloadBackupResponse = InferOutput<typeof DownloadBackupResponseSchema>;
|
|
82
|
+
//# sourceMappingURL=backup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAA2C,MAAM,SAAS,CAAC;AAGpF;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;aAO3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;aAKtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEpF;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;aAEpC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;aAGrC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;aAGtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEpF;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;aAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,OAAO,4BAA4B,CAAC,CAAC"}
|
package/dist/backup.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { array, number, object, optional, string } from "valibot";
|
|
2
|
+
import { createSuccessResponseSchema } from "./common.js";
|
|
3
|
+
/**
|
|
4
|
+
* Backup info schema
|
|
5
|
+
* Represents metadata about a stored backup
|
|
6
|
+
*/
|
|
7
|
+
export const BackupInfoSchema = object({
|
|
8
|
+
storageId: string(),
|
|
9
|
+
filename: string(),
|
|
10
|
+
recordCount: number(),
|
|
11
|
+
size: number(),
|
|
12
|
+
createdAt: string(),
|
|
13
|
+
gameId: string(), // Which game this backup belongs to
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Trigger backup response schema
|
|
17
|
+
*/
|
|
18
|
+
export const TriggerBackupResponseSchema = createSuccessResponseSchema({
|
|
19
|
+
storageId: optional(string()),
|
|
20
|
+
filename: optional(string()),
|
|
21
|
+
recordCount: optional(number()),
|
|
22
|
+
size: optional(number()),
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* List backups response schema
|
|
26
|
+
*/
|
|
27
|
+
export const ListBackupsResponseSchema = createSuccessResponseSchema({
|
|
28
|
+
backups: optional(array(BackupInfoSchema)),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Restore from backup request schema
|
|
32
|
+
*/
|
|
33
|
+
export const RestoreBackupRequestSchema = object({
|
|
34
|
+
storageId: string(),
|
|
35
|
+
gameId: string(), // Which game database to restore to
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Restore from backup response schema
|
|
39
|
+
*/
|
|
40
|
+
export const RestoreBackupResponseSchema = createSuccessResponseSchema({
|
|
41
|
+
restoredCount: optional(number()),
|
|
42
|
+
preRestoreBackupStorageId: optional(string()),
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Download backup response schema
|
|
46
|
+
* Content is streamed back
|
|
47
|
+
*/
|
|
48
|
+
export const DownloadBackupResponseSchema = createSuccessResponseSchema({
|
|
49
|
+
backup: optional(BackupInfoSchema),
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=backup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.js","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;IACrC,SAAS,EAAE,MAAM,EAAE;IACnB,QAAQ,EAAE,MAAM,EAAE;IAClB,WAAW,EAAE,MAAM,EAAE;IACrB,IAAI,EAAE,MAAM,EAAE;IACd,SAAS,EAAE,MAAM,EAAE;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,oCAAoC;CACvD,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;IACrE,SAAS,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CACzB,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;IACnE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;IAC/C,SAAS,EAAE,MAAM,EAAE;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,oCAAoC;CACvD,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;IACrE,aAAa,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACjC,yBAAyB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC9C,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,2BAA2B,CAAC;IACtE,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC;CACnC,CAAC,CAAC"}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type InferOutput, type ObjectSchema } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Common base schemas used across all API endpoints
|
|
4
|
+
* Single source of truth for response wrappers and shared fields
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base API response schema with success/error fields
|
|
8
|
+
* All API responses should extend this schema
|
|
9
|
+
*/
|
|
10
|
+
export declare const ApiResponseSchema: ObjectSchema<{
|
|
11
|
+
readonly success: import("valibot").BooleanSchema<undefined>;
|
|
12
|
+
readonly error: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
13
|
+
}, undefined>;
|
|
14
|
+
export type ApiResponse = InferOutput<typeof ApiResponseSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* Helper to create a success response schema with additional data fields
|
|
17
|
+
* Usage: createSuccessResponseSchema({ data: string() })
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSuccessResponseSchema<T extends Record<string, any>>(dataFields: T): ObjectSchema<(typeof ApiResponseSchema)["entries"] & T, undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Timestamp fields commonly used for entity metadata
|
|
22
|
+
*/
|
|
23
|
+
export declare const TimestampFieldsSchema: ObjectSchema<{
|
|
24
|
+
readonly createdAt: import("valibot").StringSchema<undefined>;
|
|
25
|
+
readonly updatedAt: import("valibot").StringSchema<undefined>;
|
|
26
|
+
}, undefined>;
|
|
27
|
+
export type TimestampFields = InferOutput<typeof TimestampFieldsSchema>;
|
|
28
|
+
/**
|
|
29
|
+
* Common metadata fields for entities
|
|
30
|
+
*/
|
|
31
|
+
export declare const EntityMetadataSchema: ObjectSchema<{
|
|
32
|
+
readonly createdAt: import("valibot").StringSchema<undefined>;
|
|
33
|
+
readonly updatedAt: import("valibot").StringSchema<undefined>;
|
|
34
|
+
}, undefined>;
|
|
35
|
+
export type EntityMetadata = InferOutput<typeof EntityMetadataSchema>;
|
|
36
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAqC,MAAM,SAAS,CAAC;AAEjG;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;aAG5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACvE,UAAU,EAAE,CAAC,GACZ,YAAY,CAAC,CAAC,OAAO,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAKpE;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;aAGhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;aAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { boolean, object, optional, string } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Common base schemas used across all API endpoints
|
|
4
|
+
* Single source of truth for response wrappers and shared fields
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base API response schema with success/error fields
|
|
8
|
+
* All API responses should extend this schema
|
|
9
|
+
*/
|
|
10
|
+
export const ApiResponseSchema = object({
|
|
11
|
+
success: boolean(),
|
|
12
|
+
error: optional(string()),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Helper to create a success response schema with additional data fields
|
|
16
|
+
* Usage: createSuccessResponseSchema({ data: string() })
|
|
17
|
+
*/
|
|
18
|
+
export function createSuccessResponseSchema(dataFields) {
|
|
19
|
+
return object({
|
|
20
|
+
...ApiResponseSchema.entries,
|
|
21
|
+
...dataFields,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Timestamp fields commonly used for entity metadata
|
|
26
|
+
*/
|
|
27
|
+
export const TimestampFieldsSchema = object({
|
|
28
|
+
createdAt: string(),
|
|
29
|
+
updatedAt: string(),
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Common metadata fields for entities
|
|
33
|
+
*/
|
|
34
|
+
export const EntityMetadataSchema = object({
|
|
35
|
+
...TimestampFieldsSchema.entries,
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjG;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;IACtC,OAAO,EAAE,OAAO,EAAE;IAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC1B,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAa;IAEb,OAAO,MAAM,CAAC;QACZ,GAAG,iBAAiB,CAAC,OAAO;QAC5B,GAAG,UAAU;KACd,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;IAC1C,SAAS,EAAE,MAAM,EAAE;IACnB,SAAS,EAAE,MAAM,EAAE;CACpB,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;IACzC,GAAG,qBAAqB,CAAC,OAAO;CACjC,CAAC,CAAC"}
|