@adonis-agora/authkit-core 0.7.0 → 0.8.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/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { Identity, SessionResolver } from './src/types/identity.js';
2
+ export { ORG_ID_CLAIMS, deriveOrgId, deriveOrgSlug, deriveOrgRole, } from './src/types/identity.js';
2
3
  export type { ClientConfig, TtlConfig, JwksConfig, KeystoreStoreConfig, ObservabilityConfig, ResolvedAuthServerConfig, AccessTokenFormat, AccessTokenResourceConfig, AccessTokensConfig, } from './src/types/server_config.js';
3
4
  export { AUTHKIT_METRICS } from './src/metrics.js';
4
5
  export type { AuthkitMetricName } from './src/metrics.js';
package/build/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export { ORG_ID_CLAIMS, deriveOrgId, deriveOrgSlug, deriveOrgRole, } from './src/types/identity.js';
1
2
  export { AUTHKIT_METRICS } from './src/metrics.js';
2
3
  export { InMemorySnapshot, NoopRecorder } from './src/metrics_recorder.js';
@@ -18,7 +18,11 @@ export class InMemorySnapshot {
18
18
  this.#updatedAt = Date.now();
19
19
  }
20
20
  read() {
21
- return { counters: { ...this.#counters }, histograms: { ...this.#histograms }, updatedAt: this.#updatedAt };
21
+ return {
22
+ counters: { ...this.#counters },
23
+ histograms: { ...this.#histograms },
24
+ updatedAt: this.#updatedAt,
25
+ };
22
26
  }
23
27
  }
24
28
  /** No-op: usado quando observability está desligada. */
@@ -16,6 +16,18 @@ export interface Identity {
16
16
  };
17
17
  /** `sid` quando presente */
18
18
  sessionId?: string;
19
+ /**
20
+ * Organização (tenant) ATIVA da sessão, derivada das claims — `null` quando o
21
+ * usuário não tem org ativa. Campo de primeira classe (e não só
22
+ * `raw.org_id`) porque é o eixo de multi-tenancy: é o que o app usa para
23
+ * escopar queries e o que a ponte de contexto publica como `tenantId` para o
24
+ * `@adonis-agora/authz`. Ver {@link ORG_ID_CLAIMS} para os aliases aceitos.
25
+ */
26
+ orgId?: string | null;
27
+ /** Slug da org ativa (claim `org_slug`), quando presente. */
28
+ orgSlug?: string | null;
29
+ /** Papel do usuário DENTRO da org ativa (claim `org_role`), quando presente. */
30
+ orgRole?: string | null;
19
31
  /** `iat` em epoch ms */
20
32
  issuedAt: number;
21
33
  /** `exp` em epoch ms */
@@ -30,3 +42,19 @@ export interface Identity {
30
42
  export interface SessionResolver {
31
43
  resolve(ctx: HttpContext): Promise<Identity | null>;
32
44
  }
45
+ /**
46
+ * Claims OIDC candidatas a "organização/tenant ativo", em ordem de precedência.
47
+ * A primeira presente (string não vazia) vence.
48
+ *
49
+ * A lista existe porque o authkit é apenas UM dos IdPs possíveis: quando o app
50
+ * está atrás de um IdP de terceiro (ver `byo-idp`), o tenant chega com outro
51
+ * nome (`tid` no Entra ID, `organization_id` em vários). Derivar em UM lugar só
52
+ * evita que cada app — e cada lib do Agora — reescreva essa tabela.
53
+ */
54
+ export declare const ORG_ID_CLAIMS: readonly ["active_organization_id", "org_id", "organization_id", "tenant_id", "tid"];
55
+ /** Deriva a org/tenant ativo das claims cruas. `null` quando ausente. */
56
+ export declare function deriveOrgId(claims: Record<string, unknown> | undefined): string | null;
57
+ /** Deriva o slug da org ativa das claims cruas. `null` quando ausente. */
58
+ export declare function deriveOrgSlug(claims: Record<string, unknown> | undefined): string | null;
59
+ /** Deriva o papel do usuário na org ativa. `null` quando ausente. */
60
+ export declare function deriveOrgRole(claims: Record<string, unknown> | undefined): string | null;
@@ -1 +1,39 @@
1
- export {};
1
+ /**
2
+ * Claims OIDC candidatas a "organização/tenant ativo", em ordem de precedência.
3
+ * A primeira presente (string não vazia) vence.
4
+ *
5
+ * A lista existe porque o authkit é apenas UM dos IdPs possíveis: quando o app
6
+ * está atrás de um IdP de terceiro (ver `byo-idp`), o tenant chega com outro
7
+ * nome (`tid` no Entra ID, `organization_id` em vários). Derivar em UM lugar só
8
+ * evita que cada app — e cada lib do Agora — reescreva essa tabela.
9
+ */
10
+ export const ORG_ID_CLAIMS = [
11
+ 'active_organization_id',
12
+ 'org_id',
13
+ 'organization_id',
14
+ 'tenant_id',
15
+ 'tid',
16
+ ];
17
+ /** Lê a primeira claim string não-vazia de `names`, ou `null`. */
18
+ function firstStringClaim(claims, names) {
19
+ if (!claims)
20
+ return null;
21
+ for (const name of names) {
22
+ const value = claims[name];
23
+ if (typeof value === 'string' && value.length > 0)
24
+ return value;
25
+ }
26
+ return null;
27
+ }
28
+ /** Deriva a org/tenant ativo das claims cruas. `null` quando ausente. */
29
+ export function deriveOrgId(claims) {
30
+ return firstStringClaim(claims, ORG_ID_CLAIMS);
31
+ }
32
+ /** Deriva o slug da org ativa das claims cruas. `null` quando ausente. */
33
+ export function deriveOrgSlug(claims) {
34
+ return firstStringClaim(claims, ['org_slug', 'organization_slug']);
35
+ }
36
+ /** Deriva o papel do usuário na org ativa. `null` quando ausente. */
37
+ export function deriveOrgRole(claims) {
38
+ return firstStringClaim(claims, ['org_role', 'organization_role']);
39
+ }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-core",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Shared core types and utilities for AuthKit — the AdonisJS OIDC/OAuth2 server and client toolkits.",
5
5
  "license": "MIT",
6
6
  "author": "dudousxd",
7
- "homepage": "https://github.com/DavideCarvalho/adonis-authkit/tree/main/packages/authkit-core#readme",
7
+ "homepage": "https://github.com/DavideCarvalho/adonis-agora-authkit/tree/main/packages/authkit-core#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/DavideCarvalho/adonis-authkit.git",
10
+ "url": "https://github.com/DavideCarvalho/adonis-agora-authkit.git",
11
11
  "directory": "packages/authkit-core"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/DavideCarvalho/adonis-authkit/issues"
14
+ "url": "https://github.com/DavideCarvalho/adonis-agora-authkit/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "adonisjs",
@@ -35,13 +35,17 @@
35
35
  "./types": "./build/index.js"
36
36
  },
37
37
  "devDependencies": {
38
- "@adonisjs/core": "7.3.3",
38
+ "@adonisjs/core": "7.4.0",
39
39
  "@adonisjs/tsconfig": "2.0.0",
40
+ "@japa/assert": "4.2.0",
41
+ "@japa/runner": "5.3.0",
42
+ "@poppinss/ts-exec": "1.4.4",
40
43
  "@types/node": "25.9.1",
41
44
  "typescript": "6.0.3"
42
45
  },
43
46
  "scripts": {
44
47
  "build": "tsc",
45
- "typecheck": "tsc --noEmit"
48
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",
49
+ "test": "node --import=@poppinss/ts-exec bin/test.ts"
46
50
  }
47
51
  }