@apso/cli 0.48.0 → 0.49.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 +28 -1
- package/dist/commands/dev.d.ts +2 -0
- package/dist/commands/dev.js +20 -3
- package/dist/commands/generate.js +49 -13
- package/dist/commands/mcp/serve.js +24 -41
- package/dist/commands/schema/diff.js +3 -4
- package/dist/commands/schema/pull.js +13 -11
- package/dist/commands/schema/push.js +6 -5
- package/dist/commands/schema/validate.d.ts +10 -0
- package/dist/commands/schema/validate.js +54 -0
- package/dist/commands/test/access.d.ts +11 -0
- package/dist/commands/test/access.js +65 -0
- package/dist/lib/access/cases.d.ts +120 -0
- package/dist/lib/access/cases.js +1163 -0
- package/dist/lib/access/index.d.ts +4 -0
- package/dist/lib/access/index.js +7 -0
- package/dist/lib/access/report.d.ts +75 -0
- package/dist/lib/access/report.js +118 -0
- package/dist/lib/access/rules.json +207 -0
- package/dist/lib/access/run.d.ts +38 -0
- package/dist/lib/access/run.js +111 -0
- package/dist/lib/access/tokens.d.ts +46 -0
- package/dist/lib/access/tokens.js +139 -0
- package/dist/lib/api/services.d.ts +10 -7
- package/dist/lib/api/services.js +19 -32
- package/dist/lib/apsorc-parser.d.ts +1 -1
- package/dist/lib/apsorc-parser.js +2 -0
- package/dist/lib/deploy/server-push.js +3 -1
- package/dist/lib/generators/go.d.ts +13 -1
- package/dist/lib/generators/go.js +144 -33
- package/dist/lib/generators/python.d.ts +3 -3
- package/dist/lib/generators/python.js +48 -24
- package/dist/lib/generators/typescript.d.ts +3 -5
- package/dist/lib/generators/typescript.js +78 -64
- package/dist/lib/guards.d.ts +111 -13
- package/dist/lib/guards.js +287 -23
- package/dist/lib/templates/go/handlers/handler.eta +8 -8
- package/dist/lib/templates/go/handlers/scope.eta +3 -2
- package/dist/lib/templates/go/index-module.eta +8 -5
- package/dist/lib/templates/go/mcp.eta +307 -0
- package/dist/lib/templates/go/middleware/auth.eta +587 -166
- package/dist/lib/templates/go/middleware/permission.eta +174 -0
- package/dist/lib/templates/go/services/service.eta +37 -16
- package/dist/lib/templates/go/utils/query.eta +37 -2
- package/dist/lib/templates/guards/guards.module.eta +37 -29
- package/dist/lib/templates/guards/index.eta +4 -0
- package/dist/lib/templates/guards/jwt-auth.guard.eta +114 -29
- package/dist/lib/templates/guards/key.guard.eta +280 -0
- package/dist/lib/templates/guards/permission.guard.eta +168 -0
- package/dist/lib/templates/guards/relations.interceptor.eta +124 -0
- package/dist/lib/templates/guards/scope.guard.eta +189 -41
- package/dist/lib/templates/python/auth.eta +354 -95
- package/dist/lib/templates/python/index-module.eta +7 -7
- package/dist/lib/templates/python/mcp.eta +284 -0
- package/dist/lib/templates/python/models/model.eta +6 -5
- package/dist/lib/templates/python/permissions.eta +121 -0
- package/dist/lib/templates/python/routers/router.eta +39 -1
- package/dist/lib/templates/python/schemas/schema.eta +18 -5
- package/dist/lib/templates/python/services/service.eta +38 -15
- package/dist/lib/templates/python/utils/query.eta +52 -25
- package/dist/lib/templates/rest/controller-rest.eta +43 -23
- package/dist/lib/templates/rest/index-module-rest.eta +0 -4
- package/dist/lib/templates/rest/service-rest.eta +3 -44
- package/dist/lib/types/auth.d.ts +84 -80
- package/dist/lib/types/auth.js +77 -60
- package/dist/lib/types/entity.d.ts +17 -9
- package/dist/lib/types/entity.js +3 -0
- package/dist/lib/types/index.d.ts +2 -2
- package/dist/lib/types/index.js +6 -5
- package/dist/lib/utils/crud-deps.d.ts +77 -6
- package/dist/lib/utils/crud-deps.js +197 -14
- package/dist/lib/utils/schema-convert.d.ts +20 -43
- package/dist/lib/utils/schema-convert.js +28 -78
- package/dist/lib/utils/template.d.ts +11 -0
- package/dist/lib/utils/template.js +36 -1
- package/dist/lib/verify/index.d.ts +6 -1
- package/dist/lib/verify/index.js +30 -13
- package/npm-shrinkwrap.json +2 -2
- package/oclif.manifest.json +36 -1
- package/package.json +1 -1
- package/dist/lib/templates/guards/api-key-auth.guard.eta +0 -145
- package/dist/lib/templates/guards/auth.guard.eta +0 -233
package/dist/lib/types/auth.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Supported authentication provider types
|
|
2
|
+
* Supported authentication provider types. The auth block is for user sign-in
|
|
3
|
+
* only: the API key check is built into every generated service and is set
|
|
4
|
+
* through its environment (APSO_API_KEY), not here.
|
|
3
5
|
*/
|
|
4
|
-
export type AuthProviderType = "better-auth" | "
|
|
6
|
+
export type AuthProviderType = "better-auth" | "auth0" | "clerk" | "cognito" | "jwt";
|
|
5
7
|
/**
|
|
6
8
|
* Base configuration common to all auth providers
|
|
7
9
|
*/
|
|
@@ -10,36 +12,12 @@ export interface BaseAuthConfig {
|
|
|
10
12
|
* The authentication provider type
|
|
11
13
|
*/
|
|
12
14
|
provider: AuthProviderType;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Configuration for DB-backed session providers (Better Auth, custom-db-session)
|
|
16
|
-
*/
|
|
17
|
-
export interface DbSessionAuthConfig extends BaseAuthConfig {
|
|
18
|
-
provider: "better-auth" | "custom-db-session";
|
|
19
|
-
/**
|
|
20
|
-
* Entity name for sessions. Default: "session"
|
|
21
|
-
*/
|
|
22
|
-
sessionEntity?: string;
|
|
23
15
|
/**
|
|
24
|
-
* Entity
|
|
16
|
+
* Entity whose rows grant permissions to roles at runtime (fields `role`
|
|
17
|
+
* and `permission`, e.g. "invoice:delete"). Used only when the entity
|
|
18
|
+
* exists in .apsorc. Default: "RolePermission"
|
|
25
19
|
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Junction entity for user-organization mapping. Default: "AccountUser"
|
|
29
|
-
*/
|
|
30
|
-
accountUserEntity?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Cookie name prefix for session tokens. Default: service name
|
|
33
|
-
*/
|
|
34
|
-
cookiePrefix?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Field name on accountUserEntity for organization ID. Default: "organizationId"
|
|
37
|
-
*/
|
|
38
|
-
organizationField?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Field name on accountUserEntity for user's role. Default: "role"
|
|
41
|
-
*/
|
|
42
|
-
roleField?: string;
|
|
20
|
+
permissionEntity?: string;
|
|
43
21
|
}
|
|
44
22
|
/**
|
|
45
23
|
* JWT configuration for token-based providers
|
|
@@ -60,8 +38,8 @@ export interface JwtConfig {
|
|
|
60
38
|
*/
|
|
61
39
|
jwksUri?: string;
|
|
62
40
|
/**
|
|
63
|
-
* Algorithms to accept. Default: ["RS256"].
|
|
64
|
-
*
|
|
41
|
+
* Algorithms to accept. Default: ["RS256"]. The better-auth provider
|
|
42
|
+
* always accepts EdDSA (Better Auth's default) as well.
|
|
65
43
|
*/
|
|
66
44
|
algorithms?: string[];
|
|
67
45
|
/**
|
|
@@ -94,6 +72,11 @@ export interface JwtClaimsMapping {
|
|
|
94
72
|
* Claim for user email
|
|
95
73
|
*/
|
|
96
74
|
email?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Claim holding permission strings ("invoice:delete"), for providers that
|
|
77
|
+
* manage permissions themselves (Auth0 RBAC). Default: "permissions"
|
|
78
|
+
*/
|
|
79
|
+
permissions?: string;
|
|
97
80
|
}
|
|
98
81
|
/**
|
|
99
82
|
* Configuration for JWT-based providers (Auth0, Clerk, Cognito, or any issuer
|
|
@@ -115,36 +98,58 @@ export interface JwtAuthConfig extends BaseAuthConfig {
|
|
|
115
98
|
userEntity?: string;
|
|
116
99
|
}
|
|
117
100
|
/**
|
|
118
|
-
*
|
|
101
|
+
* Better Auth, verified by the JWTs it issues: the JWT plugin's token for the
|
|
102
|
+
* app's own REST calls, and the OAuth access tokens (header type at+jwt) its
|
|
103
|
+
* OAuth provider issues to MCP clients. The service does not look sessions up.
|
|
104
|
+
*
|
|
105
|
+
* The token's `iss` is `url`, or the origin of `url`: the OAuth provider signs
|
|
106
|
+
* with the base URL, the JWT plugin with Better Auth's `baseURL` option, which
|
|
107
|
+
* is normally the origin. Both are checked against the keys at `url`/jwks.
|
|
119
108
|
*/
|
|
120
|
-
export interface
|
|
121
|
-
provider: "
|
|
122
|
-
/**
|
|
123
|
-
* Header name for API key. Default: "x-api-key"
|
|
124
|
-
*/
|
|
125
|
-
apiKeyHeader?: string;
|
|
109
|
+
export interface BetterAuthConfig extends BaseAuthConfig {
|
|
110
|
+
provider: "better-auth";
|
|
126
111
|
/**
|
|
127
|
-
*
|
|
112
|
+
* Better Auth's base URL including its base path, e.g.
|
|
113
|
+
* "https://app.example.com/api/auth". The issuer and the JWKS URL
|
|
114
|
+
* (`url`/jwks) default from it.
|
|
128
115
|
*/
|
|
129
|
-
|
|
116
|
+
url: string;
|
|
130
117
|
/**
|
|
131
|
-
*
|
|
118
|
+
* Overrides. `audience` defaults to the origin of `url`, which is what the
|
|
119
|
+
* JWT plugin puts in `aud` unless its `jwt.audience` option is set.
|
|
132
120
|
*/
|
|
133
|
-
|
|
121
|
+
jwt?: Partial<JwtConfig>;
|
|
134
122
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
123
|
+
* Claim names. Defaults: userId "sub", email "email", tenant
|
|
124
|
+
* "activeOrganizationId", roles "roles", permissions "permissions". Better
|
|
125
|
+
* Auth puts only the user in the token by default; the tenant and roles are
|
|
126
|
+
* added with the JWT plugin's `definePayload`.
|
|
137
127
|
*/
|
|
138
|
-
|
|
128
|
+
claims?: JwtClaimsMapping;
|
|
139
129
|
/**
|
|
140
|
-
*
|
|
130
|
+
* The entities that store Better Auth's session, user and membership rows
|
|
131
|
+
* in this service (written by @apso/better-auth-adapter with an API key).
|
|
132
|
+
* They are not read to sign a caller in; naming them marks them as auth
|
|
133
|
+
* entities, which only a service caller reaches. Defaults: "session",
|
|
134
|
+
* "User", "AccountUser".
|
|
141
135
|
*/
|
|
142
|
-
|
|
136
|
+
sessionEntity?: string;
|
|
137
|
+
userEntity?: string;
|
|
138
|
+
accountUserEntity?: string;
|
|
143
139
|
}
|
|
140
|
+
/** Kept under its old name for code that marks the auth entities. */
|
|
141
|
+
export type DbSessionAuthConfig = BetterAuthConfig;
|
|
144
142
|
/**
|
|
145
|
-
*
|
|
143
|
+
* One sign-in provider
|
|
146
144
|
*/
|
|
147
|
-
export type
|
|
145
|
+
export type AuthProviderConfig = BetterAuthConfig | JwtAuthConfig;
|
|
146
|
+
/**
|
|
147
|
+
* The .apsorc auth block: one provider, or a list of providers when the
|
|
148
|
+
* service trusts more than one issuer. A token is matched to its provider by
|
|
149
|
+
* its `iss` claim and checked against that provider's keys, audience and
|
|
150
|
+
* claim mapping only.
|
|
151
|
+
*/
|
|
152
|
+
export type AuthConfig = AuthProviderConfig | AuthProviderConfig[];
|
|
148
153
|
/**
|
|
149
154
|
* The normalized AuthContext that all providers produce.
|
|
150
155
|
* This is what scopeBy and RBAC consume.
|
|
@@ -171,7 +176,7 @@ export interface AuthContext {
|
|
|
171
176
|
*/
|
|
172
177
|
roles: string[];
|
|
173
178
|
/**
|
|
174
|
-
*
|
|
179
|
+
* Set for a service caller (a valid API key): the key's identifier
|
|
175
180
|
*/
|
|
176
181
|
serviceId?: string;
|
|
177
182
|
/**
|
|
@@ -184,40 +189,26 @@ export interface AuthContext {
|
|
|
184
189
|
session?: unknown;
|
|
185
190
|
}
|
|
186
191
|
/**
|
|
187
|
-
* Default
|
|
192
|
+
* Default names of the entities that store Better Auth's rows
|
|
188
193
|
*/
|
|
189
|
-
export declare const DB_SESSION_AUTH_DEFAULTS:
|
|
190
|
-
|
|
194
|
+
export declare const DB_SESSION_AUTH_DEFAULTS: {
|
|
195
|
+
sessionEntity: string;
|
|
196
|
+
userEntity: string;
|
|
197
|
+
accountUserEntity: string;
|
|
191
198
|
};
|
|
192
199
|
/**
|
|
193
200
|
* Default values for JWT auth configuration
|
|
194
201
|
*/
|
|
195
202
|
export declare const JWT_AUTH_DEFAULTS: Required<Pick<JwtAuthConfig, "claims">> & Partial<JwtConfig>;
|
|
196
203
|
/**
|
|
197
|
-
*
|
|
204
|
+
* True for the provider whose own tables (sessions, users, memberships) are
|
|
205
|
+
* stored in this service: Better Auth. The name predates the removal of the
|
|
206
|
+
* session lookup; every provider is verified as a JWT now.
|
|
198
207
|
*/
|
|
199
|
-
export declare
|
|
200
|
-
/**
|
|
201
|
-
* Type guard: Check if auth config is DB session based
|
|
202
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
203
|
-
* @returns {boolean} True if the auth config is DB session based
|
|
204
|
-
*/
|
|
205
|
-
export declare function isDbSessionAuth(auth: AuthConfig): auth is DbSessionAuthConfig;
|
|
206
|
-
/**
|
|
207
|
-
* Type guard: Check if auth config is JWT based
|
|
208
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
209
|
-
* @returns {boolean} True if the auth config is JWT based
|
|
210
|
-
*/
|
|
211
|
-
export declare function isJwtAuth(auth: AuthConfig): auth is JwtAuthConfig;
|
|
212
|
-
/**
|
|
213
|
-
* Type guard: Check if auth config is API key based
|
|
214
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
215
|
-
* @returns {boolean} True if the auth config is API key based
|
|
216
|
-
*/
|
|
217
|
-
export declare function isApiKeyAuth(auth: AuthConfig): auth is ApiKeyAuthConfig;
|
|
208
|
+
export declare function isDbSessionAuth(auth: AuthProviderConfig): auth is BetterAuthConfig;
|
|
218
209
|
/** A JWT auth config with every default filled in, as the templates use it. */
|
|
219
210
|
export interface ResolvedJwtAuth {
|
|
220
|
-
provider:
|
|
211
|
+
provider: AuthProviderConfig["provider"];
|
|
221
212
|
issuer: string;
|
|
222
213
|
audience?: string;
|
|
223
214
|
jwksUri: string;
|
|
@@ -225,13 +216,26 @@ export interface ResolvedJwtAuth {
|
|
|
225
216
|
authorizedParties: string[];
|
|
226
217
|
claims: Required<Pick<JwtClaimsMapping, "userId">> & Omit<JwtClaimsMapping, "userId">;
|
|
227
218
|
}
|
|
228
|
-
/** An API key auth config with every default filled in. */
|
|
229
|
-
export type ResolvedApiKeyAuth = Required<Omit<ApiKeyAuthConfig, "roleField">> & Pick<ApiKeyAuthConfig, "roleField">;
|
|
230
219
|
/**
|
|
231
220
|
* Fill JWT defaults and reject configs that would generate an unsafe check.
|
|
232
221
|
* Only asymmetric algorithms are accepted: the key comes from the issuer's
|
|
233
222
|
* JWKS, so there is no shared secret to configure or leak.
|
|
234
223
|
*/
|
|
235
|
-
export declare function resolveJwtAuth(auth:
|
|
236
|
-
/**
|
|
237
|
-
|
|
224
|
+
export declare function resolveJwtAuth(auth: AuthProviderConfig): ResolvedJwtAuth;
|
|
225
|
+
/**
|
|
226
|
+
* Reject the removed providers with what replaced them.
|
|
227
|
+
*/
|
|
228
|
+
export declare function assertSignInProvider(auth?: {
|
|
229
|
+
provider?: string;
|
|
230
|
+
}): void;
|
|
231
|
+
/**
|
|
232
|
+
* The auth block as a list of providers, rejecting lists that cannot be
|
|
233
|
+
* generated. Every provider is checked as a JWT: a token names its issuer, so
|
|
234
|
+
* the guard can pick one provider before checking anything.
|
|
235
|
+
*/
|
|
236
|
+
export declare function authProviders(auth?: AuthConfig): AuthProviderConfig[];
|
|
237
|
+
/**
|
|
238
|
+
* The providers of the auth block with defaults filled in. Empty for no auth
|
|
239
|
+
* block.
|
|
240
|
+
*/
|
|
241
|
+
export declare function resolveJwtProviders(auth?: AuthConfig): ResolvedJwtAuth[];
|
package/dist/lib/types/auth.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveJwtProviders = exports.authProviders = exports.assertSignInProvider = exports.resolveJwtAuth = exports.isDbSessionAuth = exports.JWT_AUTH_DEFAULTS = exports.DB_SESSION_AUTH_DEFAULTS = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Default
|
|
5
|
+
* Default names of the entities that store Better Auth's rows
|
|
6
6
|
*/
|
|
7
7
|
exports.DB_SESSION_AUTH_DEFAULTS = {
|
|
8
8
|
sessionEntity: "session",
|
|
9
9
|
userEntity: "User",
|
|
10
10
|
accountUserEntity: "AccountUser",
|
|
11
|
-
organizationField: "organizationId",
|
|
12
|
-
roleField: "role",
|
|
13
|
-
cookiePrefix: undefined, // Will use service name if not specified
|
|
14
11
|
};
|
|
15
12
|
/**
|
|
16
13
|
* Default values for JWT auth configuration
|
|
@@ -23,52 +20,25 @@ exports.JWT_AUTH_DEFAULTS = {
|
|
|
23
20
|
},
|
|
24
21
|
};
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
apiKeyHeader: "x-api-key",
|
|
30
|
-
apiKeyEntity: "ApiKey",
|
|
31
|
-
keyField: "keyHash",
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Type guard: Check if auth config is DB session based
|
|
35
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
36
|
-
* @returns {boolean} True if the auth config is DB session based
|
|
23
|
+
* True for the provider whose own tables (sessions, users, memberships) are
|
|
24
|
+
* stored in this service: Better Auth. The name predates the removal of the
|
|
25
|
+
* session lookup; every provider is verified as a JWT now.
|
|
37
26
|
*/
|
|
38
27
|
function isDbSessionAuth(auth) {
|
|
39
|
-
return auth.provider === "better-auth"
|
|
28
|
+
return auth.provider === "better-auth";
|
|
40
29
|
}
|
|
41
30
|
exports.isDbSessionAuth = isDbSessionAuth;
|
|
42
|
-
/**
|
|
43
|
-
* Type guard: Check if auth config is JWT based
|
|
44
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
45
|
-
* @returns {boolean} True if the auth config is JWT based
|
|
46
|
-
*/
|
|
47
|
-
function isJwtAuth(auth) {
|
|
48
|
-
return (auth.provider === "auth0" ||
|
|
49
|
-
auth.provider === "clerk" ||
|
|
50
|
-
auth.provider === "cognito" ||
|
|
51
|
-
auth.provider === "jwt");
|
|
52
|
-
}
|
|
53
|
-
exports.isJwtAuth = isJwtAuth;
|
|
54
|
-
/**
|
|
55
|
-
* Type guard: Check if auth config is API key based
|
|
56
|
-
* @param {AuthConfig} auth - The auth configuration to check
|
|
57
|
-
* @returns {boolean} True if the auth config is API key based
|
|
58
|
-
*/
|
|
59
|
-
function isApiKeyAuth(auth) {
|
|
60
|
-
return auth.provider === "api-key";
|
|
61
|
-
}
|
|
62
|
-
exports.isApiKeyAuth = isApiKeyAuth;
|
|
63
31
|
/**
|
|
64
32
|
* Claim defaults per provider. Clerk's v2 session token nests the active
|
|
65
33
|
* organization under `o`; Cognito puts group membership in `cognito:groups`.
|
|
66
34
|
*/
|
|
67
35
|
const PROVIDER_CLAIMS = {
|
|
68
|
-
|
|
36
|
+
// Names for the app's definePayload to use; Better Auth has no defaults for these.
|
|
37
|
+
"better-auth": { userId: "sub", email: "email", workspaceId: "activeOrganizationId", roles: "roles", permissions: "permissions" },
|
|
38
|
+
auth0: { userId: "sub", email: "email", permissions: "permissions" },
|
|
69
39
|
clerk: { userId: "sub", email: "email", workspaceId: "o.id", roles: "o.rol" },
|
|
70
40
|
cognito: { userId: "sub", email: "email", roles: "cognito:groups" },
|
|
71
|
-
jwt: { userId: "sub", email: "email", roles: "roles" },
|
|
41
|
+
jwt: { userId: "sub", email: "email", roles: "roles", permissions: "permissions" },
|
|
72
42
|
};
|
|
73
43
|
const ALLOWED_ALGORITHMS = new Set([
|
|
74
44
|
"RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384",
|
|
@@ -80,13 +50,21 @@ const ALLOWED_ALGORITHMS = new Set([
|
|
|
80
50
|
* JWKS, so there is no shared secret to configure or leak.
|
|
81
51
|
*/
|
|
82
52
|
function resolveJwtAuth(auth) {
|
|
83
|
-
var _a, _b, _c, _d, _e, _f;
|
|
84
|
-
const
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
54
|
+
const betterAuth = auth.provider === "better-auth";
|
|
55
|
+
const url = betterAuth ? (_a = auth.url) === null || _a === void 0 ? void 0 : _a.trim().replace(/\/+$/, "") : undefined;
|
|
56
|
+
if (betterAuth && !/^https?:\/\/[^/]/.test(url !== null && url !== void 0 ? url : ""))
|
|
57
|
+
throw new Error('auth.url is required for the "better-auth" provider: Better Auth\'s base URL starting with http:// or https://, for example "https://app.example.com/api/auth". The service no longer looks sessions up in its database. It verifies the JWTs Better Auth issues, so turn on Better Auth\'s JWT plugin and send its token in the Authorization: Bearer header.');
|
|
58
|
+
const issuer = ((_c = (_b = auth.jwt) === null || _b === void 0 ? void 0 : _b.issuer) === null || _c === void 0 ? void 0 : _c.trim()) || url;
|
|
85
59
|
if (!issuer)
|
|
86
60
|
throw new Error(`auth.jwt.issuer is required for the "${auth.provider}" provider`);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
61
|
+
const configured = (_e = (_d = auth.jwt) === null || _d === void 0 ? void 0 : _d.algorithms) !== null && _e !== void 0 ? _e : [];
|
|
62
|
+
// EdDSA is Better Auth's default key type, so it is always accepted there.
|
|
63
|
+
const algorithms = betterAuth
|
|
64
|
+
? [...new Set(["EdDSA", ...configured])]
|
|
65
|
+
: configured.length > 0
|
|
66
|
+
? configured
|
|
67
|
+
: ["RS256"];
|
|
90
68
|
const bad = algorithms.filter((a) => !ALLOWED_ALGORITHMS.has(a));
|
|
91
69
|
if (bad.length > 0)
|
|
92
70
|
throw new Error(`auth.jwt.algorithms: ${bad.join(", ")} not supported; use ${[
|
|
@@ -96,24 +74,63 @@ function resolveJwtAuth(auth) {
|
|
|
96
74
|
return {
|
|
97
75
|
provider: auth.provider,
|
|
98
76
|
issuer,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
77
|
+
// Better Auth's default audience (the origin) is filled in by the service,
|
|
78
|
+
// from the issuer it runs with.
|
|
79
|
+
audience: ((_g = (_f = auth.jwt) === null || _f === void 0 ? void 0 : _f.audience) === null || _g === void 0 ? void 0 : _g.trim()) || undefined,
|
|
80
|
+
jwksUri: ((_j = (_h = auth.jwt) === null || _h === void 0 ? void 0 : _h.jwksUri) === null || _j === void 0 ? void 0 : _j.trim()) ||
|
|
81
|
+
(url
|
|
82
|
+
? `${url}/jwks`
|
|
83
|
+
: `${issuer.replace(/\/+$/, "")}/.well-known/jwks.json`),
|
|
102
84
|
algorithms,
|
|
103
|
-
authorizedParties: (
|
|
85
|
+
authorizedParties: (_l = (_k = auth.jwt) === null || _k === void 0 ? void 0 : _k.authorizedParties) !== null && _l !== void 0 ? _l : [],
|
|
104
86
|
claims: { ...claims, userId: claims.userId || "sub" },
|
|
105
87
|
};
|
|
106
88
|
}
|
|
107
89
|
exports.resolveJwtAuth = resolveJwtAuth;
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Reject the removed providers with what replaced them.
|
|
92
|
+
*/
|
|
93
|
+
function assertSignInProvider(auth) {
|
|
94
|
+
if ((auth === null || auth === void 0 ? void 0 : auth.provider) === "api-key")
|
|
95
|
+
throw new Error('auth.provider "api-key" was removed. The API key check is now built into every generated service: remove the auth block (or set it to your user sign-in provider), set APSO_API_KEY in the service\'s environment, and send the key in the x-api-key header. The ApiKey entity is no longer read.');
|
|
96
|
+
if ((auth === null || auth === void 0 ? void 0 : auth.provider) === "custom-db-session")
|
|
97
|
+
throw new Error('auth.provider "custom-db-session" was removed. Generated services no longer look sessions up in the database; they verify JWTs. Use "jwt" with the issuer that signs your users\' tokens (auth.jwt.issuer, and auth.jwt.jwksUri for its public keys), or "better-auth" with auth.url if the sessions come from Better Auth.');
|
|
98
|
+
}
|
|
99
|
+
exports.assertSignInProvider = assertSignInProvider;
|
|
100
|
+
/**
|
|
101
|
+
* The auth block as a list of providers, rejecting lists that cannot be
|
|
102
|
+
* generated. Every provider is checked as a JWT: a token names its issuer, so
|
|
103
|
+
* the guard can pick one provider before checking anything.
|
|
104
|
+
*/
|
|
105
|
+
function authProviders(auth) {
|
|
106
|
+
if (!auth)
|
|
107
|
+
return [];
|
|
108
|
+
const list = Array.isArray(auth) ? auth : [auth];
|
|
109
|
+
if (list.length === 0)
|
|
110
|
+
throw new Error("auth is an empty list. List at least one provider, or remove the auth block.");
|
|
111
|
+
for (const provider of list)
|
|
112
|
+
assertSignInProvider(provider);
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
for (const provider of list) {
|
|
115
|
+
const { issuer } = resolveJwtAuth(provider);
|
|
116
|
+
// Better Auth's JWT plugin signs with the origin of its URL.
|
|
117
|
+
const issuers = provider.provider === "better-auth"
|
|
118
|
+
? new Set([issuer, new URL(issuer).origin])
|
|
119
|
+
: [issuer];
|
|
120
|
+
for (const name of issuers) {
|
|
121
|
+
if (seen.has(name))
|
|
122
|
+
throw new Error(`auth lists the issuer "${name}" twice. Each provider needs its own issuer: the token's iss claim is what picks the provider.`);
|
|
123
|
+
seen.add(name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return list;
|
|
127
|
+
}
|
|
128
|
+
exports.authProviders = authProviders;
|
|
129
|
+
/**
|
|
130
|
+
* The providers of the auth block with defaults filled in. Empty for no auth
|
|
131
|
+
* block.
|
|
132
|
+
*/
|
|
133
|
+
function resolveJwtProviders(auth) {
|
|
134
|
+
return authProviders(auth).map((provider) => resolveJwtAuth(provider));
|
|
118
135
|
}
|
|
119
|
-
exports.
|
|
136
|
+
exports.resolveJwtProviders = resolveJwtProviders;
|
|
@@ -10,20 +10,15 @@ export type ScopeOperation = "find" | "get" | "create" | "update" | "delete";
|
|
|
10
10
|
* Configuration options for scope enforcement behavior
|
|
11
11
|
*/
|
|
12
12
|
export interface ScopeOptions {
|
|
13
|
-
/**
|
|
14
|
-
* If true (default), scope fields are automatically injected from
|
|
15
|
-
* the request context on create when not provided.
|
|
16
|
-
*/
|
|
17
|
-
injectOnCreate?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Which operations should enforce scope. Defaults to all operations.
|
|
20
|
-
*/
|
|
21
|
-
enforceOn?: ScopeOperation[];
|
|
22
13
|
/**
|
|
23
14
|
* Roles allowed to bypass scope enforcement (e.g., 'system_admin').
|
|
24
15
|
*/
|
|
25
16
|
bypassRoles?: string[];
|
|
26
17
|
}
|
|
18
|
+
/** Operations a role list can guard (read covers list and get by id). */
|
|
19
|
+
export declare const PERMISSION_OPERATIONS: readonly ["read", "create", "update", "delete"];
|
|
20
|
+
export type PermissionOperation = typeof PERMISSION_OPERATIONS[number];
|
|
21
|
+
export type EntityPermissions = Partial<Record<PermissionOperation, string[]>>;
|
|
27
22
|
export interface Entity {
|
|
28
23
|
name: string;
|
|
29
24
|
/**
|
|
@@ -51,6 +46,19 @@ export interface Entity {
|
|
|
51
46
|
* Optional configuration for how scope enforcement should behave.
|
|
52
47
|
*/
|
|
53
48
|
scopeOptions?: ScopeOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Roles allowed to perform each operation. A missing key lets any
|
|
51
|
+
* authenticated caller do it; an empty list lets nobody. Requires `auth`.
|
|
52
|
+
* Example: { "delete": ["admin"] }
|
|
53
|
+
*/
|
|
54
|
+
permissions?: EntityPermissions;
|
|
55
|
+
/**
|
|
56
|
+
* Expose this entity's CRUD routes as MCP tools (TypeScript, needs `auth`
|
|
57
|
+
* and @apso/mcp). `true` exposes read, create, update and delete; a list
|
|
58
|
+
* exposes only those operations. Off by default.
|
|
59
|
+
* Example: ["read", "create"]
|
|
60
|
+
*/
|
|
61
|
+
mcp?: boolean | PermissionOperation[];
|
|
54
62
|
/**
|
|
55
63
|
* When true, state changes to this entity (insert/update/remove) emit a
|
|
56
64
|
* durable DomainEvent row written in the SAME database transaction as the
|
package/dist/lib/types/entity.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { Entity, ScopeOptions, ScopeOperation } from "./entity";
|
|
1
|
+
export { Entity, ScopeOptions, ScopeOperation, EntityPermissions, PermissionOperation, PERMISSION_OPERATIONS, } from "./entity";
|
|
2
2
|
export { FieldType, Field, ComputedField } from "./field";
|
|
3
3
|
export { Index } from "./indices";
|
|
4
4
|
export { JSONValue } from "./json";
|
|
5
5
|
export { RelationshipType, Association, ApsorcRelationship, Relationship, RelationshipForTemplate, RelationshipMap, } from "./relationship";
|
|
6
|
-
export { AuthProviderType, BaseAuthConfig, DbSessionAuthConfig, JwtConfig, JwtClaimsMapping, JwtAuthConfig,
|
|
6
|
+
export { AuthProviderType, BaseAuthConfig, DbSessionAuthConfig, JwtConfig, JwtClaimsMapping, JwtAuthConfig, AuthConfig, AuthProviderConfig, AuthContext, DB_SESSION_AUTH_DEFAULTS, JWT_AUTH_DEFAULTS, isDbSessionAuth, BetterAuthConfig, assertSignInProvider, ResolvedJwtAuth, resolveJwtAuth, authProviders, resolveJwtProviders, } from "./auth";
|
|
7
7
|
export { TargetLanguage, GeneratedFile, ValidationResult, PythonLanguageConfig, GoLanguageConfig, TypeScriptLanguageConfig, LanguageConfig, GeneratorConfig, EntityGenerationOptions, ControllerGenerationOptions, ServiceGenerationOptions, DtoGenerationOptions, MigrationGenerationOptions, LanguageGenerator, GeneratorFactory, GeneratorRegistry, } from "./generator";
|
package/dist/lib/types/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveJwtProviders = exports.authProviders = exports.resolveJwtAuth = exports.assertSignInProvider = exports.isDbSessionAuth = exports.JWT_AUTH_DEFAULTS = exports.DB_SESSION_AUTH_DEFAULTS = exports.PERMISSION_OPERATIONS = void 0;
|
|
4
|
+
var entity_1 = require("./entity");
|
|
5
|
+
Object.defineProperty(exports, "PERMISSION_OPERATIONS", { enumerable: true, get: function () { return entity_1.PERMISSION_OPERATIONS; } });
|
|
4
6
|
var auth_1 = require("./auth");
|
|
5
7
|
Object.defineProperty(exports, "DB_SESSION_AUTH_DEFAULTS", { enumerable: true, get: function () { return auth_1.DB_SESSION_AUTH_DEFAULTS; } });
|
|
6
8
|
Object.defineProperty(exports, "JWT_AUTH_DEFAULTS", { enumerable: true, get: function () { return auth_1.JWT_AUTH_DEFAULTS; } });
|
|
7
|
-
Object.defineProperty(exports, "API_KEY_AUTH_DEFAULTS", { enumerable: true, get: function () { return auth_1.API_KEY_AUTH_DEFAULTS; } });
|
|
8
9
|
Object.defineProperty(exports, "isDbSessionAuth", { enumerable: true, get: function () { return auth_1.isDbSessionAuth; } });
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
Object.defineProperty(exports, "isApiKeyAuth", { enumerable: true, get: function () { return auth_1.isApiKeyAuth; } });
|
|
10
|
+
Object.defineProperty(exports, "assertSignInProvider", { enumerable: true, get: function () { return auth_1.assertSignInProvider; } });
|
|
11
11
|
Object.defineProperty(exports, "resolveJwtAuth", { enumerable: true, get: function () { return auth_1.resolveJwtAuth; } });
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "authProviders", { enumerable: true, get: function () { return auth_1.authProviders; } });
|
|
13
|
+
Object.defineProperty(exports, "resolveJwtProviders", { enumerable: true, get: function () { return auth_1.resolveJwtProviders; } });
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Runtime packages the generated TypeScript code imports (entities, services,
|
|
3
|
-
* controllers, guards).
|
|
4
|
-
*
|
|
3
|
+
* controllers, guards). These are the first releases with the `dialects`
|
|
4
|
+
* option, Content-Range counts and PostgREST OpenAPI parameters, which the
|
|
5
|
+
* generated controllers rely on. The service template declares the same
|
|
6
|
+
* ranges (see TEMPLATE_REFS in ./template.ts); bump both together.
|
|
7
|
+
*
|
|
8
|
+
* @apso/postgrest-request is not imported by generated code. It is listed so
|
|
9
|
+
* a project whose lockfile holds an older copy moves to the one @apso/crud
|
|
10
|
+
* needs.
|
|
5
11
|
*/
|
|
6
12
|
export declare const APSO_CRUD_DEPS: Record<string, string>;
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
14
|
+
* Declare the @apso/crud runtime packages in the project's package.json, and
|
|
15
|
+
* raise a range that starts below the version the generated code needs.
|
|
9
16
|
*
|
|
10
17
|
* Projects created from the v1 template (@nestjsx/crud) don't declare them, so
|
|
11
18
|
* freshly generated code fails `nest build` with TS2307 "Cannot find module
|
|
@@ -13,7 +20,7 @@ export declare const APSO_CRUD_DEPS: Record<string, string>;
|
|
|
13
20
|
* hand-written code may still import them.
|
|
14
21
|
*
|
|
15
22
|
* @param {string} projectDir - Directory holding the project's package.json.
|
|
16
|
-
* @returns {string[]} Names added (empty when nothing changed or no package.json).
|
|
23
|
+
* @returns {string[]} Names added or raised (empty when nothing changed or no package.json).
|
|
17
24
|
*/
|
|
18
25
|
export declare function ensureCrudDeps(projectDir: string): string[];
|
|
19
26
|
/**
|
|
@@ -21,9 +28,73 @@ export declare function ensureCrudDeps(projectDir: string): string[];
|
|
|
21
28
|
*
|
|
22
29
|
* @param {string} projectDir - Directory holding the project's package.json.
|
|
23
30
|
* @param {Record<string, string>} deps - Package names and version ranges.
|
|
24
|
-
* @
|
|
31
|
+
* @param {boolean} [raise] - Also replace a declared range that starts below the given one.
|
|
32
|
+
* @returns {string[]} Names added or raised (empty when nothing changed or no package.json).
|
|
33
|
+
*/
|
|
34
|
+
export declare function addMissingDeps(projectDir: string, deps: Record<string, string>, raise?: boolean): string[];
|
|
35
|
+
/** MCP library the generated controllers import when an entity sets `mcp`. */
|
|
36
|
+
export declare const MCP_DEP: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Wire @apso/mcp into a TypeScript project: declare the package and call
|
|
39
|
+
* mountMcp where the app builds its OpenAPI document. Safe to run again.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} projectDir - Directory holding the project's package.json.
|
|
42
|
+
* @param {string} rootFolder - Source folder from .apsorc (usually "src").
|
|
43
|
+
* @returns {string[]} Files changed (empty when the project was already wired).
|
|
44
|
+
*/
|
|
45
|
+
export declare function ensureMcpWiring(projectDir: string, rootFolder: string): string[];
|
|
46
|
+
/** The official MCP SDK for Python; 2.x has the constructor-handler server the generated mcp.py uses. */
|
|
47
|
+
export declare const PYTHON_MCP_DEP = "mcp>=2.3,<3";
|
|
48
|
+
/**
|
|
49
|
+
* Take the MCP call back out of a Python or Go entry point when no entity has
|
|
50
|
+
* `mcp` any more: the generated file it calls is no longer written, so the
|
|
51
|
+
* service would not build or start. Only the exact lines the CLI added are
|
|
52
|
+
* removed.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} projectDir - The project root.
|
|
55
|
+
* @param {"python" | "go"} language - The project's language.
|
|
56
|
+
* @returns {string[]} Files changed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function removeAppMcpWiring(projectDir: string, language: "python" | "go"): string[];
|
|
59
|
+
/**
|
|
60
|
+
* Wire the generated MCP endpoint into a Python or Go project: one call in the
|
|
61
|
+
* app's entry point, after the generated routes are registered (and the SDK in
|
|
62
|
+
* pyproject.toml for Python; go mod tidy adds it for Go). Safe to run again.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} projectDir - The project root.
|
|
65
|
+
* @param {"python" | "go"} language - The project's language.
|
|
66
|
+
* @returns {string[]} Files changed (empty when the project was already wired).
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureAppMcpWiring(projectDir: string, language: "python" | "go"): string[];
|
|
69
|
+
/** Request logging library every generated TypeScript service uses. */
|
|
70
|
+
export declare const LOGGING_DEP: Record<string, string>;
|
|
71
|
+
/**
|
|
72
|
+
* Wire @apso/logging into a TypeScript project: declare the package and call
|
|
73
|
+
* useApsoLogging straight after NestFactory.create in the server entry point
|
|
74
|
+
* (main.ts) and the Lambda handler (lambda.ts). Safe to run again.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} projectDir - Directory holding the project's package.json.
|
|
77
|
+
* @param {string} rootFolder - Source folder from .apsorc (usually "src").
|
|
78
|
+
* @returns {{ changed: string[], manual: string[] }} Files changed, and entry
|
|
79
|
+
* points that no longer look like the template's and were left alone.
|
|
80
|
+
*/
|
|
81
|
+
export declare function ensureLoggingWiring(projectDir: string, rootFolder: string): {
|
|
82
|
+
changed: string[];
|
|
83
|
+
manual: string[];
|
|
84
|
+
};
|
|
85
|
+
/** Version of the access rules the generated code enforces. */
|
|
86
|
+
export declare const ACCESS_CONTRACT = 1;
|
|
87
|
+
/**
|
|
88
|
+
* Record in .apso/manifest.json that the generated code has the built-in
|
|
89
|
+
* access check (no valid API key or signed-in user, no access). The hosted
|
|
90
|
+
* platform reads this from the pushed source before it opens a service to
|
|
91
|
+
* requests it has not checked a key for. Other fields in the file are kept.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} projectDir - The project root.
|
|
94
|
+
* @param {string} cliVersion - Version of the CLI that generated the code.
|
|
95
|
+
* @returns {boolean} True when git ignores the file, so it would not be pushed.
|
|
25
96
|
*/
|
|
26
|
-
export declare function
|
|
97
|
+
export declare function writeAccessManifest(projectDir: string, cliVersion: string): boolean;
|
|
27
98
|
/** JWT verification library the generated TypeScript JWT guard imports. */
|
|
28
99
|
export declare const JOSE_DEP: Record<string, string>;
|
|
29
100
|
/** JWT verification library the generated Python auth module imports. */
|