@owlmeans/auth 0.1.18-rc.2 → 0.1.18-rc.20

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  import type { JSONSchemaType } from 'ajv'
3
3
  import type { Profile } from '../types.js'
4
- import { EntityValueSchema, IdValueSchema } from '../consts.js'
4
+ import { EntitySlugValueSchema, IdValueSchema } from '../consts.js'
5
5
  import { PermissionSetSchema, AttributeSetSchema } from '../permission/model.js'
6
6
 
7
7
  export const ProfileSchema: JSONSchemaType<Profile> = {
@@ -12,7 +12,7 @@ export const ProfileSchema: JSONSchemaType<Profile> = {
12
12
  credential: { type: 'string', nullable: true },
13
13
  secret: { type: 'string', nullable: true },
14
14
  groups: { type: 'array', items: { type: 'string' }, nullable: true },
15
- entityId: {...EntityValueSchema, nullable: true},
15
+ entitySlug: {...EntitySlugValueSchema, nullable: true},
16
16
  scopes: { type: 'array', items: { type: 'string' } },
17
17
  permissions: { type: 'array', items: PermissionSetSchema, nullable: true },
18
18
  attributes: { type: 'array', items: AttributeSetSchema, nullable: true },
package/src/helper.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Auth, AuthCredentials, AuthToken } from './types.js'
1
+ import type { Auth, AuthCredentials, AuthToken, Authorization } from './types.js'
2
2
  import { Ajv } from 'ajv'
3
3
  import formatsPlugin from 'ajv-formats'
4
4
  import { AuthCredentialsSchema, AuthSchema } from './allowance/model.js'
@@ -30,3 +30,15 @@ export const isAuthCredentials = (auth: unknown): auth is AuthCredentials =>
30
30
  export const isAuthToken = (auth: unknown): auth is AuthToken =>
31
31
  typeof auth === 'object' && auth != null
32
32
  && ("token" in auth) && typeof auth.token === 'string'
33
+
34
+ /**
35
+ * The organization slug carried by an auth payload, tolerating tokens minted before the field
36
+ * was named.
37
+ *
38
+ * Tokens outlive deployments: one signed with the previous release still arrives with the value
39
+ * under `entityId`, and it stays valid until it expires. Everything that reads the organization
40
+ * off a payload goes through here so that window needs no second code path — and so the day the
41
+ * fallback can be deleted is a single-line change rather than an audit.
42
+ */
43
+ export const entitySlugOf = (payload?: Partial<Authorization> | null): string | undefined =>
44
+ payload?.entitySlug ?? (payload as { entityId?: string } | null | undefined)?.entityId
package/src/types.ts CHANGED
@@ -15,7 +15,7 @@ export interface AuthCredentials extends AuthPayload {
15
15
  ProfilePayload:
16
16
  groups?: string[]
17
17
  Authorization:
18
- entityId?: string
18
+ entitySlug?: string
19
19
  scopes: string[]
20
20
  permissions?: PermissionSet[]
21
21
  attributes?: AttributeSet[]
@@ -47,7 +47,7 @@ export interface AuthPayload extends ProfilePayload {
47
47
  ProfilePayload:
48
48
  groups?: string[]
49
49
  Authorization:
50
- entityId?: string
50
+ entitySlug?: string
51
51
  scopes: string[]
52
52
  permissions?: PermissionSet[]
53
53
  attributes?: AttributeSet[]
@@ -65,7 +65,7 @@ export interface ProfilePayload extends Authorization {
65
65
  groups?: string[]
66
66
  /**
67
67
  Authorization:
68
- entityId?: string
68
+ entitySlug?: string
69
69
  scopes: string[]
70
70
  permissions?: PermissionSet[]
71
71
  attributes?: AttributeSet[]
@@ -75,7 +75,17 @@ export interface ProfilePayload extends Authorization {
75
75
  }
76
76
 
77
77
  export interface Authorization {
78
- entityId?: string
78
+ /**
79
+ * The organization entity's slug — renameable, and the ONLY entity value that travels on the
80
+ * wire: in tokens, in URLs and in request bodies.
81
+ *
82
+ * It is deliberately NOT a database key. An implementation that stores things per organization
83
+ * keeps its own stable `entityId` on its records and resolves this slug to it at the boundary,
84
+ * so a rename costs one registry write instead of a migration of every collection, object name
85
+ * and third-party record that ever referenced the organization. Basic auth knows nothing about
86
+ * that id — see `@owlmeans/auth-common`'s entity resolver for the contract that does.
87
+ */
88
+ entitySlug?: string
79
89
  scopes: string[]
80
90
  permissions?: PermissionSet[]
81
91
  attributes?: AttributeSet[]
@@ -98,7 +108,7 @@ export interface Profile extends ProfilePayload {
98
108
  ProfilePayload:
99
109
  groups?: string[]
100
110
  Authorization:
101
- entityId?: string
111
+ entitySlug?: string
102
112
  scopes: string[]
103
113
  permissions?: PermissionSet[]
104
114
  attributes?: AttributeSet[]
@@ -122,7 +132,7 @@ export interface Auth extends AuthPayload {
122
132
  ProfilePayload:
123
133
  groups?: string[]
124
134
  Authorization:
125
- entityId?: string
135
+ entitySlug?: string
126
136
  scopes: string[]
127
137
  permissions?: PermissionSet[]
128
138
  attributes?: AttributeSet[]
@@ -160,7 +170,7 @@ export interface AllowanceRequest extends Partial<AuthPayload> {
160
170
  ProfilePayload:
161
171
  groups?: string[]
162
172
  Authorization:
163
- entityId?: string
173
+ entitySlug?: string
164
174
  scopes?: string[]
165
175
  permissions?: PermissionSet[]
166
176
  attributes?: AttributeSet[]
package/build/.gitkeep DELETED
File without changes