@selvajs/server 1.5.0-beta.7 → 1.5.0-beta.8

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.
Files changed (77) hide show
  1. package/dist/access/guards.d.ts.map +1 -1
  2. package/dist/access/guards.js +2 -6
  3. package/dist/access/guards.js.map +1 -1
  4. package/dist/api/respond.d.ts +6 -1
  5. package/dist/api/respond.d.ts.map +1 -1
  6. package/dist/api/respond.js +2 -2
  7. package/dist/api/respond.js.map +1 -1
  8. package/dist/definitions/definition-service.d.ts.map +1 -1
  9. package/dist/definitions/definition-service.js +7 -1
  10. package/dist/definitions/definition-service.js.map +1 -1
  11. package/dist/definitions/index.d.ts +1 -1
  12. package/dist/definitions/index.d.ts.map +1 -1
  13. package/dist/definitions/index.js +1 -1
  14. package/dist/definitions/index.js.map +1 -1
  15. package/dist/definitions/visibility.d.ts +35 -1
  16. package/dist/definitions/visibility.d.ts.map +1 -1
  17. package/dist/definitions/visibility.js +91 -5
  18. package/dist/definitions/visibility.js.map +1 -1
  19. package/dist/handlers/apiTokens.d.ts +34 -3
  20. package/dist/handlers/apiTokens.d.ts.map +1 -1
  21. package/dist/handlers/apiTokens.js +45 -12
  22. package/dist/handlers/apiTokens.js.map +1 -1
  23. package/dist/handlers/definitions.d.ts +7 -1
  24. package/dist/handlers/definitions.d.ts.map +1 -1
  25. package/dist/handlers/definitions.js +24 -7
  26. package/dist/handlers/definitions.js.map +1 -1
  27. package/dist/handlers/index.d.ts +2 -1
  28. package/dist/handlers/index.d.ts.map +1 -1
  29. package/dist/handlers/index.js +2 -1
  30. package/dist/handlers/index.js.map +1 -1
  31. package/dist/handlers/me.d.ts.map +1 -1
  32. package/dist/handlers/me.js +5 -1
  33. package/dist/handlers/me.js.map +1 -1
  34. package/dist/handlers/oauthConsent.d.ts +37 -0
  35. package/dist/handlers/oauthConsent.d.ts.map +1 -0
  36. package/dist/handlers/oauthConsent.js +63 -0
  37. package/dist/handlers/oauthConsent.js.map +1 -0
  38. package/dist/handlers/projects.d.ts +5 -0
  39. package/dist/handlers/projects.d.ts.map +1 -1
  40. package/dist/handlers/projects.js +19 -3
  41. package/dist/handlers/projects.js.map +1 -1
  42. package/dist/http/api-token.d.ts +8 -3
  43. package/dist/http/api-token.d.ts.map +1 -1
  44. package/dist/http/api-token.js +11 -1
  45. package/dist/http/api-token.js.map +1 -1
  46. package/dist/oauth/index.d.ts +30 -5
  47. package/dist/oauth/index.d.ts.map +1 -1
  48. package/dist/oauth/index.js +65 -15
  49. package/dist/oauth/index.js.map +1 -1
  50. package/dist/organizations/index.d.ts +1 -0
  51. package/dist/organizations/index.d.ts.map +1 -1
  52. package/dist/organizations/index.js +1 -0
  53. package/dist/organizations/index.js.map +1 -1
  54. package/dist/organizations/user-memberships.d.ts +11 -0
  55. package/dist/organizations/user-memberships.d.ts.map +1 -0
  56. package/dist/organizations/user-memberships.js +23 -0
  57. package/dist/organizations/user-memberships.js.map +1 -0
  58. package/dist/testing/harness.d.ts +3 -1
  59. package/dist/testing/harness.d.ts.map +1 -1
  60. package/dist/testing/harness.js +6 -1
  61. package/dist/testing/harness.js.map +1 -1
  62. package/dist/testing/index.d.ts +1 -1
  63. package/dist/testing/index.d.ts.map +1 -1
  64. package/dist/testing/index.js +1 -1
  65. package/dist/testing/index.js.map +1 -1
  66. package/dist/testing/scenarios.d.ts +6 -0
  67. package/dist/testing/scenarios.d.ts.map +1 -1
  68. package/dist/testing/scenarios.js +12 -1
  69. package/dist/testing/scenarios.js.map +1 -1
  70. package/dist/tokens/api-token-holder.d.ts +22 -6
  71. package/dist/tokens/api-token-holder.d.ts.map +1 -1
  72. package/dist/tokens/api-token-holder.js +25 -4
  73. package/dist/tokens/api-token-holder.js.map +1 -1
  74. package/dist/tokens/index.d.ts +1 -1
  75. package/dist/tokens/index.d.ts.map +1 -1
  76. package/dist/tokens/index.js.map +1 -1
  77. package/package.json +6 -6
@@ -1,14 +1,30 @@
1
- import { type RequestContext } from '@selvajs/platform';
1
+ import { type ApiScope, type RequestContext } from '@selvajs/platform';
2
+ import { type VisibilityDeps } from '../definitions/visibility.js';
2
3
  /**
3
- * Who may hold API tokens in the context's acting org, decided by the host.
4
- * Without one, holding a key needs the platform permission `manage_api_tokens`.
4
+ * Who may hold an API token with `scopes` in the context's acting org, decided
5
+ * by the host. It replaces the default rule ({@link canHoldApiTokens}) whole.
5
6
  *
6
7
  * Asked at mint, and again by the resolver on every request against the
7
8
  * owner's live context in the token's org, so a key stops working (403
8
9
  * `API_TOKEN_HOLDER_REFUSED`) the moment its owner no longer qualifies,
9
10
  * without being revoked.
10
11
  */
11
- export type ApiTokenHolderPolicy = (ctx: RequestContext) => boolean;
12
- /** The one place the "no policy means `manage_api_tokens`" default lives. */
13
- export declare function canHoldApiTokens(ctx: RequestContext, policy?: ApiTokenHolderPolicy): boolean;
12
+ export type ApiTokenHolderPolicy = (ctx: RequestContext, scopes: readonly ApiScope[]) => boolean | Promise<boolean>;
13
+ export interface ApiTokenHolderOptions {
14
+ policy?: ApiTokenHolderPolicy;
15
+ /** What the default rule reads to find a project the owner may create a definition in. */
16
+ deps: VisibilityDeps;
17
+ }
18
+ /**
19
+ * May `ctx` hold a key with `scopes` in its acting org? Without a host policy:
20
+ *
21
+ * - `manage_api_tokens` holds any key.
22
+ * - A key that only reads and uploads needs only the right to create a
23
+ * definition in one project of the org. It can do nothing the owner's
24
+ * browser session can't.
25
+ *
26
+ * A scope this version can't parse counts as broad, so it needs
27
+ * `manage_api_tokens`.
28
+ */
29
+ export declare function canHoldApiTokens(ctx: RequestContext, scopes: readonly string[], { policy, deps }: ApiTokenHolderOptions): Promise<boolean>;
14
30
  //# sourceMappingURL=api-token-holder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-token-holder.d.ts","sourceRoot":"","sources":["../../src/tokens/api-token-holder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC;AAEpE,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAE5F"}
1
+ {"version":3,"file":"api-token-holder.d.ts","sourceRoot":"","sources":["../../src/tokens/api-token-holder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7F;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAClC,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,SAAS,QAAQ,EAAE,KACvB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,WAAW,qBAAqB;IACrC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,0FAA0F;IAC1F,IAAI,EAAE,cAAc,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,qBAAqB,GACrC,OAAO,CAAC,OAAO,CAAC,CAWlB"}
@@ -1,6 +1,27 @@
1
- import { hasPermission } from '@selvajs/platform';
2
- /** The one place the "no policy means `manage_api_tokens`" default lives. */
3
- export function canHoldApiTokens(ctx, policy) {
4
- return policy ? policy(ctx) : hasPermission(ctx, 'manage_api_tokens');
1
+ import { hasPermission, parseApiScope } from '@selvajs/platform';
2
+ import { canCreateDefinitionInOrg } from '../definitions/visibility.js';
3
+ /**
4
+ * May `ctx` hold a key with `scopes` in its acting org? Without a host policy:
5
+ *
6
+ * - `manage_api_tokens` holds any key.
7
+ * - A key that only reads and uploads needs only the right to create a
8
+ * definition in one project of the org. It can do nothing the owner's
9
+ * browser session can't.
10
+ *
11
+ * A scope this version can't parse counts as broad, so it needs
12
+ * `manage_api_tokens`.
13
+ */
14
+ export async function canHoldApiTokens(ctx, scopes, { policy, deps }) {
15
+ const parsed = scopes.map(parseApiScope).filter((s) => s !== null);
16
+ if (policy)
17
+ return policy(ctx, parsed);
18
+ if (hasPermission(ctx, 'manage_api_tokens'))
19
+ return true;
20
+ const readAndUploadOnly = parsed.length > 0 &&
21
+ parsed.length === scopes.length &&
22
+ parsed.every((s) => s.action === 'read' || s.action === 'upload');
23
+ if (!readAndUploadOnly || !ctx.actingOrgId)
24
+ return false;
25
+ return canCreateDefinitionInOrg(ctx, ctx.actingOrgId, deps);
5
26
  }
6
27
  //# sourceMappingURL=api-token-holder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-token-holder.js","sourceRoot":"","sources":["../../src/tokens/api-token-holder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,mBAAmB,CAAC;AAavE,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,GAAmB,EAAE,MAA6B;IAClF,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"api-token-holder.js","sourceRoot":"","sources":["../../src/tokens/api-token-holder.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,aAAa,EAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAuB,MAAM,8BAA8B,CAAC;AAsB7F;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,GAAmB,EACnB,MAAyB,EACzB,EAAE,MAAM,EAAE,IAAI,EAAyB;IAEvC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAiB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAClF,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzD,MAAM,iBAAiB,GACtB,MAAM,CAAC,MAAM,GAAG,CAAC;QACjB,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;QAC/B,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC;IACnE,IAAI,CAAC,iBAAiB,IAAI,CAAC,GAAG,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IACzD,OAAO,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export { createTokenCodec, MIN_TOKEN_SECRET_LENGTH, type TokenCodec, type TokenCodecConfig } from './token-codec.js';
2
2
  export { createApiTokenCodec, API_TOKEN_PREFIX, looksLikeApiToken, type ApiTokenCodec } from './api-token-codec.js';
3
- export { canHoldApiTokens, type ApiTokenHolderPolicy } from './api-token-holder.js';
3
+ export { canHoldApiTokens, type ApiTokenHolderOptions, type ApiTokenHolderPolicy } from './api-token-holder.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,aAAa,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,aAAa,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,MAAM,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EAGvB,MAAM,kBAAkB,CAAC;AAE1B,wEAAwE;AACxE,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAA6B,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EAGvB,MAAM,kBAAkB,CAAC;AAE1B,wEAAwE;AACxE,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,gBAAgB,EAGhB,MAAM,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selvajs/server",
3
- "version": "1.5.0-beta.7",
3
+ "version": "1.5.0-beta.8",
4
4
  "description": "Transport-agnostic server building blocks for apps built on the Selva engine (limits, rate limiting, SSRF guard, remote-definition fetch, definition service + render loader); the solve core lives in @selvajs/solve/server",
5
5
  "license": "MIT",
6
6
  "author": "VektorNode",
@@ -115,10 +115,10 @@
115
115
  ],
116
116
  "dependencies": {
117
117
  "zod": "^4.6.5",
118
- "@selvajs/compute": "^4.2.2-beta.0",
119
- "@selvajs/notifications": "^0.3.0-beta.2",
120
- "@selvajs/platform": "^0.21.0-beta.2",
121
- "@selvajs/schemas": "^5.2.0"
118
+ "@selvajs/platform": "^0.21.0-beta.3",
119
+ "@selvajs/schemas": "^5.3.0-beta.0",
120
+ "@selvajs/notifications": "^0.3.0-beta.3",
121
+ "@selvajs/compute": "^4.3.0-beta.1"
122
122
  },
123
123
  "peerDependencies": {
124
124
  "@sentry/node": ">=8",
@@ -143,7 +143,7 @@
143
143
  "typescript": "~6.0.3",
144
144
  "vitest": "^5.0.2",
145
145
  "@selvajs/config": "0.0.4",
146
- "@selvajs/local-provider": "0.16.0-beta.1"
146
+ "@selvajs/local-provider": "0.16.0-beta.2"
147
147
  },
148
148
  "scripts": {
149
149
  "build": "tsc",