@friggframework/core 2.0.0--canary.685.a13fdab.0 → 2.0.0--canary.679.a2bcc2f.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/CLAUDE.md +0 -25
- package/README.md +0 -105
- package/application/commands/integration-commands.js +2 -2
- package/application/commands/user-commands.js +5 -17
- package/credential/use-cases/credential-operations-for-user.js +25 -110
- package/credential/use-cases/reauthorize-credential-for-user.js +8 -15
- package/database/documentdb-utils.js +1 -6
- package/generated/prisma-mongodb/edge.js +4 -15
- package/generated/prisma-mongodb/index-browser.js +1 -12
- package/generated/prisma-mongodb/index.d.ts +86 -2027
- package/generated/prisma-mongodb/index.js +4 -15
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +0 -47
- package/generated/prisma-mongodb/wasm.js +4 -15
- package/generated/prisma-postgresql/edge.js +4 -15
- package/generated/prisma-postgresql/index-browser.js +1 -12
- package/generated/prisma-postgresql/index.d.ts +63 -2162
- package/generated/prisma-postgresql/index.js +4 -15
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +0 -44
- package/generated/prisma-postgresql/wasm.js +4 -15
- package/handlers/app-definition-loader.js +1 -24
- package/index.js +0 -22
- package/integrations/integration-router.js +73 -115
- package/integrations/repositories/integration-repository-documentdb.js +3 -35
- package/integrations/repositories/integration-repository-interface.js +1 -17
- package/integrations/repositories/integration-repository-mongo.js +76 -59
- package/integrations/repositories/integration-repository-postgres.js +76 -62
- package/integrations/tests/doubles/test-integration-repository.js +1 -12
- package/integrations/use-cases/create-integration.js +20 -55
- package/integrations/use-cases/get-integrations-for-user.js +40 -80
- package/integrations/use-cases/index.js +1 -5
- package/integrations/use-cases/integration-operations-for-user.js +24 -55
- package/management-api/management-api-config.js +2 -71
- package/management-api/openapi/components.js +0 -40
- package/management-api/openapi/v2-operations.js +4 -16
- package/management-api/v2/dependencies.js +15 -40
- package/management-api/v2/dto.js +0 -20
- package/management-api/v2/handlers/authorization.js +0 -1
- package/management-api/v2/handlers/credentials.js +2 -6
- package/management-api/v2/handlers/entities.js +7 -10
- package/management-api/v2/handlers/integrations.js +3 -6
- package/management-api/v2/request.js +1 -32
- package/modules/index.js +0 -8
- package/modules/repositories/module-repository-documentdb.js +6 -51
- package/modules/repositories/module-repository-interface.js +2 -19
- package/modules/repositories/module-repository-mongo.js +74 -67
- package/modules/repositories/module-repository-postgres.js +74 -66
- package/modules/repositories/module-repository.js +1 -2
- package/modules/use-cases/entity-operations-for-user.js +13 -50
- package/modules/use-cases/entity-types.js +7 -31
- package/modules/use-cases/execute-entity-proxy-request.js +3 -50
- package/modules/use-cases/get-entities-for-user.js +5 -16
- package/modules/use-cases/get-entity-module-for-user.js +5 -32
- package/modules/use-cases/get-entity-options-by-id.js +3 -9
- package/modules/use-cases/get-module.js +3 -9
- package/modules/use-cases/multi-step-authorization.js +12 -39
- package/modules/use-cases/process-authorization-callback.js +18 -52
- package/modules/use-cases/refresh-entity-options.js +3 -9
- package/modules/use-cases/test-module-auth.js +3 -9
- package/package.json +5 -6
- package/prisma-mongodb/schema.prisma +0 -47
- package/prisma-postgresql/schema.prisma +0 -44
- package/types/index.d.ts +0 -1
- package/types/modules/index.d.ts +0 -129
- package/user/repositories/user-repository-documentdb.js +2 -27
- package/user/repositories/user-repository-interface.js +0 -18
- package/user/repositories/user-repository-mongo.js +0 -24
- package/user/repositories/user-repository-postgres.js +0 -18
- package/user/use-cases/authenticate-user.js +1 -7
- package/user/use-cases/get-user-from-adopter-jwt.js +124 -95
- package/user/use-cases/get-user-from-x-frigg-headers.js +80 -83
- package/user/user.js +1 -64
- package/database/organization-where.js +0 -18
- package/database/unique-violation.js +0 -25
- package/integrations/repositories/integration-not-found.js +0 -14
- package/integrations/use-cases/resolve-integration-ownership.js +0 -177
- package/modules/entity-scope.js +0 -15
- package/modules/repositories/entity-not-found.js +0 -18
- package/modules/scope-config.js +0 -192
- package/modules/scope-policy.js +0 -112
- package/modules/scope-resolution.js +0 -288
- package/modules/scope-visibility.js +0 -247
- package/modules/tests/doubles/ownership-matching.js +0 -18
- package/modules/use-cases/authorize-entity-for-user.js +0 -61
- package/modules/use-cases/create-entity-from-credential.js +0 -113
- package/modules/use-cases/manage-access.js +0 -21
- package/prisma-postgresql/migrations/20261015000000_add_organization_membership/migration.sql +0 -26
- package/prisma-postgresql/migrations/20261016000000_add_entity_integration_organization/migration.sql +0 -25
- package/types/user/index.d.ts +0 -134
- package/user/adopter-jwt-config.js +0 -177
- package/user/adopter-jwt-errors.js +0 -59
- package/user/adopter-token-verifier.js +0 -122
- package/user/app-user-helpers.js +0 -97
- package/user/create-user-authentication.js +0 -64
- package/user/membership.js +0 -51
- package/user/repositories/organization-membership-record.js +0 -19
- package/user/repositories/organization-membership-repository-documentdb.js +0 -106
- package/user/repositories/organization-membership-repository-factory.js +0 -42
- package/user/repositories/organization-membership-repository-interface.js +0 -57
- package/user/repositories/organization-membership-repository-mongo.js +0 -13
- package/user/repositories/organization-membership-repository-postgres.js +0 -29
- package/user/repositories/organization-membership-repository-prisma.js +0 -81
- package/user/tests/doubles/adopter-jwt-fixtures.js +0 -220
- package/user/use-cases/ensure-organization-membership.js +0 -92
- package/user/use-cases/find-individual-users-by-organization.js +0 -54
|
@@ -56,14 +56,6 @@ model User {
|
|
|
56
56
|
integrations Integration[]
|
|
57
57
|
processes Process[]
|
|
58
58
|
|
|
59
|
-
// Organization memberships (ADR-056 §3.6). `organizationId` above is the legacy
|
|
60
|
-
// single-org pointer: set on a person's first link, never moved afterwards, and
|
|
61
|
-
// read as an implicit membership when no row exists for it.
|
|
62
|
-
// As an individual: the organizations this person belongs to.
|
|
63
|
-
memberships OrganizationMembership[] @relation("IndividualMemberships")
|
|
64
|
-
// As an organization: the people who belong to it.
|
|
65
|
-
orgMembers OrganizationMembership[] @relation("OrganizationMemberships")
|
|
66
|
-
|
|
67
59
|
@@unique([username, appUserId])
|
|
68
60
|
@@index([type])
|
|
69
61
|
@@index([appUserId])
|
|
@@ -134,14 +126,6 @@ model Entity {
|
|
|
134
126
|
moduleName String?
|
|
135
127
|
externalId String?
|
|
136
128
|
|
|
137
|
-
// Organization this entity was connected in (ADR-056 §3.6): the active
|
|
138
|
-
// organization for `individual`, the owner for `organization`, null for
|
|
139
|
-
// `global`. Null on an `individual` entity is also what every row written
|
|
140
|
-
// before this column existed has, and what `individualAcross: 'all'` writes.
|
|
141
|
-
// Deliberately not a relation: a deleted organization must leave its rows
|
|
142
|
-
// invisible, not turn them into "unscoped" ones (SetNull would do that).
|
|
143
|
-
organizationId String? @db.ObjectId
|
|
144
|
-
|
|
145
129
|
data Json @default("{}")
|
|
146
130
|
|
|
147
131
|
createdAt DateTime @default(now())
|
|
@@ -158,7 +142,6 @@ model Entity {
|
|
|
158
142
|
associationObjects AssociationObject[]
|
|
159
143
|
|
|
160
144
|
@@index([userId])
|
|
161
|
-
@@index([userId, organizationId])
|
|
162
145
|
@@index([externalId])
|
|
163
146
|
@@index([moduleName])
|
|
164
147
|
@@index([credentialId])
|
|
@@ -176,11 +159,6 @@ model Integration {
|
|
|
176
159
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
177
160
|
status IntegrationStatus @default(IN_CREATION)
|
|
178
161
|
|
|
179
|
-
// Organization this integration was created in (ADR-056 §3.6): the active
|
|
180
|
-
// organization at create time. Null for rows that predate the column. Not a
|
|
181
|
-
// relation, for the same reason as Entity.organizationId.
|
|
182
|
-
organizationId String? @db.ObjectId
|
|
183
|
-
|
|
184
162
|
// Configuration and version
|
|
185
163
|
config Json? // Integration configuration object
|
|
186
164
|
version String?
|
|
@@ -205,7 +183,6 @@ model Integration {
|
|
|
205
183
|
processes Process[]
|
|
206
184
|
|
|
207
185
|
@@index([userId])
|
|
208
|
-
@@index([userId, organizationId])
|
|
209
186
|
@@index([status])
|
|
210
187
|
@@map("Integration")
|
|
211
188
|
}
|
|
@@ -503,27 +480,3 @@ model AuthorizationSession {
|
|
|
503
480
|
@@index([expiresAt])
|
|
504
481
|
@@map("AuthorizationSession")
|
|
505
482
|
}
|
|
506
|
-
|
|
507
|
-
// ============================================================================
|
|
508
|
-
// ORGANIZATION MEMBERSHIP (ADR-056 §3.6)
|
|
509
|
-
// ============================================================================
|
|
510
|
-
|
|
511
|
-
/// One person's membership of one organization. Unique on the pair, so adding a
|
|
512
|
-
/// membership is an idempotent upsert. `orgRole` is the organization role the
|
|
513
|
-
/// adopter token carried when the membership was created (MEMBER when it named none). NoAction on delete
|
|
514
|
-
/// because MongoDB gives no referential integrity: delete a user's memberships
|
|
515
|
-
/// before the user.
|
|
516
|
-
model OrganizationMembership {
|
|
517
|
-
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
518
|
-
individualUserId String @db.ObjectId
|
|
519
|
-
organizationUserId String @db.ObjectId
|
|
520
|
-
orgRole String @default("MEMBER")
|
|
521
|
-
createdAt DateTime @default(now())
|
|
522
|
-
|
|
523
|
-
individualUser User @relation("IndividualMemberships", fields: [individualUserId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
524
|
-
organizationUser User @relation("OrganizationMemberships", fields: [organizationUserId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
525
|
-
|
|
526
|
-
@@unique([individualUserId, organizationUserId])
|
|
527
|
-
@@index([organizationUserId])
|
|
528
|
-
@@map("OrganizationMembership")
|
|
529
|
-
}
|
|
@@ -56,14 +56,6 @@ model User {
|
|
|
56
56
|
integrations Integration[]
|
|
57
57
|
processes Process[]
|
|
58
58
|
|
|
59
|
-
// Organization memberships (ADR-056 §3.6). `organizationId` above is the legacy
|
|
60
|
-
// single-org pointer: set on a person's first link, never moved afterwards, and
|
|
61
|
-
// read as an implicit membership when no row exists for it.
|
|
62
|
-
// As an individual: the organizations this person belongs to.
|
|
63
|
-
memberships OrganizationMembership[] @relation("IndividualMemberships")
|
|
64
|
-
// As an organization: the people who belong to it.
|
|
65
|
-
orgMembers OrganizationMembership[] @relation("OrganizationMemberships")
|
|
66
|
-
|
|
67
59
|
@@unique([username, appUserId])
|
|
68
60
|
@@index([type])
|
|
69
61
|
@@index([appUserId])
|
|
@@ -131,14 +123,6 @@ model Entity {
|
|
|
131
123
|
moduleName String?
|
|
132
124
|
externalId String?
|
|
133
125
|
|
|
134
|
-
// Organization this entity was connected in (ADR-056 §3.6): the active
|
|
135
|
-
// organization for `individual`, the owner for `organization`, null for
|
|
136
|
-
// `global`. Null on an `individual` entity is also what every row written
|
|
137
|
-
// before this column existed has, and what `individualAcross: 'all'` writes.
|
|
138
|
-
// Deliberately not a relation: a deleted organization must leave its rows
|
|
139
|
-
// invisible, not turn them into "unscoped" ones (SetNull would do that).
|
|
140
|
-
organizationId Int?
|
|
141
|
-
|
|
142
126
|
data Json @default("{}")
|
|
143
127
|
|
|
144
128
|
createdAt DateTime @default(now())
|
|
@@ -152,7 +136,6 @@ model Entity {
|
|
|
152
136
|
associationObjects AssociationObject[]
|
|
153
137
|
|
|
154
138
|
@@index([userId])
|
|
155
|
-
@@index([userId, organizationId])
|
|
156
139
|
@@index([externalId])
|
|
157
140
|
@@index([moduleName])
|
|
158
141
|
@@index([credentialId])
|
|
@@ -169,11 +152,6 @@ model Integration {
|
|
|
169
152
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
170
153
|
status IntegrationStatus @default(IN_CREATION)
|
|
171
154
|
|
|
172
|
-
// Organization this integration was created in (ADR-056 §3.6): the active
|
|
173
|
-
// organization at create time. Null for rows that predate the column. Not a
|
|
174
|
-
// relation, for the same reason as Entity.organizationId.
|
|
175
|
-
organizationId Int?
|
|
176
|
-
|
|
177
155
|
// Configuration and version
|
|
178
156
|
config Json? // Integration configuration object
|
|
179
157
|
version String?
|
|
@@ -197,7 +175,6 @@ model Integration {
|
|
|
197
175
|
processes Process[]
|
|
198
176
|
|
|
199
177
|
@@index([userId])
|
|
200
|
-
@@index([userId, organizationId])
|
|
201
178
|
@@index([status])
|
|
202
179
|
}
|
|
203
180
|
|
|
@@ -483,24 +460,3 @@ model AuthorizationSession {
|
|
|
483
460
|
@@index([userId, entityType])
|
|
484
461
|
@@index([expiresAt])
|
|
485
462
|
}
|
|
486
|
-
|
|
487
|
-
// ============================================================================
|
|
488
|
-
// ORGANIZATION MEMBERSHIP (ADR-056 §3.6)
|
|
489
|
-
// ============================================================================
|
|
490
|
-
|
|
491
|
-
/// One person's membership of one organization. Unique on the pair, so adding a
|
|
492
|
-
/// membership is an idempotent upsert. `orgRole` is the organization role the
|
|
493
|
-
/// adopter token carried when the membership was created (MEMBER when it named none).
|
|
494
|
-
model OrganizationMembership {
|
|
495
|
-
id Int @id @default(autoincrement())
|
|
496
|
-
individualUserId Int
|
|
497
|
-
organizationUserId Int
|
|
498
|
-
orgRole String @default("MEMBER")
|
|
499
|
-
createdAt DateTime @default(now())
|
|
500
|
-
|
|
501
|
-
individualUser User @relation("IndividualMemberships", fields: [individualUserId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
|
502
|
-
organizationUser User @relation("OrganizationMemberships", fields: [organizationUserId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
|
503
|
-
|
|
504
|
-
@@unique([individualUserId, organizationUserId])
|
|
505
|
-
@@index([organizationUserId])
|
|
506
|
-
}
|
package/types/index.d.ts
CHANGED
package/types/modules/index.d.ts
CHANGED
|
@@ -36,137 +36,13 @@ declare module "@friggframework/core" {
|
|
|
36
36
|
[entityType: string]: EntityRegistration | boolean | undefined;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
* One level's setting: a scope, or a default plus the scopes a request may
|
|
41
|
-
* choose from (ADR-056 §3.1). `global` is never chosen by a tenant request.
|
|
42
|
-
*/
|
|
43
|
-
export type ScopeSetting =
|
|
44
|
-
| EntityScope
|
|
45
|
-
| { default?: EntityScope; allow?: EntityScope[] };
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* `appDefinition.ownership` (ADR-056 §3, §3.6). Resolution order for a new
|
|
49
|
-
* connection: request, binding, integration, entity type (`entities[name].scope`),
|
|
50
|
-
* this `scope`, then `organization` for an organization-primary app and
|
|
51
|
-
* `individual` otherwise.
|
|
52
|
-
*/
|
|
53
|
-
export interface AppOwnership {
|
|
54
|
-
scope?: ScopeSetting;
|
|
55
|
-
/**
|
|
56
|
-
* `'organization'` (default): an individual entity belongs to the organization
|
|
57
|
-
* it was connected in. `'all'`: one connection per person across every
|
|
58
|
-
* organization, stored with no `organizationId`.
|
|
59
|
-
*/
|
|
60
|
-
individualAcross?: "organization" | "all";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** `Definition.ownership` on an integration (ADR-056 §3.1, §3.3). */
|
|
64
|
-
export interface IntegrationOwnership {
|
|
65
|
-
/** Scope every binding of this integration accepts unless it sets its own. */
|
|
66
|
-
scope?: ScopeSetting;
|
|
67
|
-
/** `'derive'` (default): organization when every entity it uses is organization-scoped. */
|
|
68
|
-
owner?: "derive" | "individual" | "organization";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** One operation a module or the app lets the entity proxy forward (ADR-052). */
|
|
72
|
-
export interface ProxyAllowRule {
|
|
73
|
-
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "*";
|
|
74
|
-
/** Relative to the module's base URL. `:param` is one segment; a trailing `/**` is a subtree. */
|
|
75
|
-
path: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** `appDefinition.managementApi.proxy`: the entity proxy, POST /api/v2/entities/:id/proxy (ADR-052). */
|
|
79
|
-
export interface ManagementApiProxyConfig {
|
|
80
|
-
/** Mount the route. Default false. */
|
|
81
|
-
enable?: boolean;
|
|
82
|
-
/** Upstream timeout in ms; can only be lowered from 25000. */
|
|
83
|
-
timeoutMs?: number;
|
|
84
|
-
/** Largest request body in bytes; default 1 MiB, at most 10 MiB. */
|
|
85
|
-
maxRequestBytes?: number;
|
|
86
|
-
/** Largest response body in bytes; can only be lowered from 5 MiB. */
|
|
87
|
-
maxResponseBytes?: number;
|
|
88
|
-
/**
|
|
89
|
-
* Entity scopes the proxy accepts (ADR-056 §3.5). Default `['individual']`.
|
|
90
|
-
* Add `'organization'` to let a member with use access proxy through the
|
|
91
|
-
* organization's shared credential. `global` is never accepted. An unknown,
|
|
92
|
-
* empty or repeated value throws ManagementApiConfigError at load.
|
|
93
|
-
*/
|
|
94
|
-
scopes?: Array<Exclude<EntityScope, "global">>;
|
|
95
|
-
/** Per-module allow-list override; `'module'` uses the module's own list. */
|
|
96
|
-
modules?: Record<string, { allow: "module" | ProxyAllowRule[] }>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** `appDefinition.managementApi` (ADR-052, ADR-053). */
|
|
100
|
-
export interface ManagementApiConfig {
|
|
101
|
-
/** Serve the deprecated v1 routes. Default true. */
|
|
102
|
-
v1?: boolean;
|
|
103
|
-
proxy?: ManagementApiProxyConfig;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
39
|
export interface AppDefinition {
|
|
107
40
|
integrations: any[];
|
|
108
41
|
/** App-level entity type registry (ADR-059). */
|
|
109
42
|
entities?: AppDefinitionEntities;
|
|
110
|
-
/** Who owns what a person connects (ADR-056). */
|
|
111
|
-
ownership?: AppOwnership;
|
|
112
|
-
/** Management API versions and the entity proxy (ADR-052, ADR-053, ADR-056 §3.5). */
|
|
113
|
-
managementApi?: ManagementApiConfig;
|
|
114
43
|
[key: string]: unknown;
|
|
115
44
|
}
|
|
116
45
|
|
|
117
|
-
/** Whose a record is and what the caller may do with it (ADR-056 §3.4). */
|
|
118
|
-
export interface RecordTenancy {
|
|
119
|
-
scope: Exclude<EntityScope, "global">;
|
|
120
|
-
owner: { type: Exclude<EntityScope, "global">; id: string };
|
|
121
|
-
/** Null for an individual entity connected outside an organization, or under `individualAcross: 'all'`. */
|
|
122
|
-
organizationId: string | null;
|
|
123
|
-
/** `manage`: create, reauthorize, delete. `use`: bind it, proxy through it. `view`: metadata only. */
|
|
124
|
-
access: "manage" | "use" | "view";
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Which scope a connection gets, and from which level of the order (ADR-056 §3.1). */
|
|
128
|
-
export interface ResolvedScope {
|
|
129
|
-
scope: EntityScope;
|
|
130
|
-
/** Where `scope` came from. `request` when the request chose within the allowed list. */
|
|
131
|
-
source: "request" | "binding" | "integration" | "entityType" | "app" | "default";
|
|
132
|
-
/** The level that decided what a request may choose from. */
|
|
133
|
-
decidedBy: "binding" | "integration" | "entityType" | "app" | "default";
|
|
134
|
-
allow: EntityScope[];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* First match wins, each level overriding the ones below it. A request may
|
|
139
|
-
* choose only from the deciding level's `allow`; `global` never comes from a
|
|
140
|
-
* tenant request. Throws a Boom 400/403 for a request scope that is not allowed.
|
|
141
|
-
*/
|
|
142
|
-
export function resolveScope(levels: {
|
|
143
|
-
request?: EntityScope;
|
|
144
|
-
binding?: ScopeSetting;
|
|
145
|
-
integration?: ScopeSetting;
|
|
146
|
-
entityType?: ScopeSetting;
|
|
147
|
-
app?: ScopeSetting;
|
|
148
|
-
primary?: "individual" | "organization";
|
|
149
|
-
}): ResolvedScope;
|
|
150
|
-
|
|
151
|
-
/** Every binding of every integration with its resolved scope (for tooling that wants to show the chain). */
|
|
152
|
-
export function listBindingScopes(
|
|
153
|
-
appDefinition: Pick<AppDefinition, "integrations" | "ownership">,
|
|
154
|
-
entityTypeRegistry: EntityTypeRegistry,
|
|
155
|
-
primary?: "individual" | "organization"
|
|
156
|
-
): Array<{
|
|
157
|
-
integration: string;
|
|
158
|
-
binding: string;
|
|
159
|
-
moduleName: string | null;
|
|
160
|
-
scope: EntityScope;
|
|
161
|
-
source: ResolvedScope["source"];
|
|
162
|
-
owner: "derive" | "individual" | "organization";
|
|
163
|
-
}>;
|
|
164
|
-
|
|
165
|
-
/** Invalid ownership or scope setting, thrown at app-definition load. `code` is always `OWNERSHIP_CONFIG_INVALID`. */
|
|
166
|
-
export class OwnershipConfigError extends Error {
|
|
167
|
-
code: "OWNERSHIP_CONFIG_INVALID";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
46
|
/**
|
|
171
47
|
* Builds the registry from `entities` plus the modules integrations bind.
|
|
172
48
|
* Throws EntityRegistryError on an invalid registry.
|
|
@@ -175,11 +51,6 @@ declare module "@friggframework/core" {
|
|
|
175
51
|
appDefinition?: Pick<AppDefinition, "entities" | "integrations">
|
|
176
52
|
): EntityTypeRegistry;
|
|
177
53
|
|
|
178
|
-
/** Invalid `managementApi` setting (today: `proxy.scopes`), thrown at app-definition load. */
|
|
179
|
-
export class ManagementApiConfigError extends Error {
|
|
180
|
-
code: "MANAGEMENT_API_CONFIG_INVALID";
|
|
181
|
-
}
|
|
182
|
-
|
|
183
54
|
/**
|
|
184
55
|
* @deprecated ADR-059. Use `getEntityTypeRegistry(appDefinition)` and read
|
|
185
56
|
* each entry's `definition`. Returns the registry's definitions for these
|
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
toObjectId,
|
|
5
5
|
fromObjectId,
|
|
6
6
|
findOne,
|
|
7
|
-
|
|
7
|
+
findMany,
|
|
8
8
|
insertOne,
|
|
9
9
|
updateOne,
|
|
10
10
|
deleteOne,
|
|
@@ -72,9 +72,7 @@ class UserRepositoryDocumentDB extends UserRepositoryInterface {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async findIndividualUsersByOrganizationId(organizationUserId) {
|
|
75
|
-
|
|
76
|
-
// drop people from a large organization.
|
|
77
|
-
const docs = await findManyDrained(this.prisma, 'User', {
|
|
75
|
+
const docs = await findMany(this.prisma, 'User', {
|
|
78
76
|
organizationId: toObjectId(organizationUserId),
|
|
79
77
|
type: 'INDIVIDUAL',
|
|
80
78
|
});
|
|
@@ -423,29 +421,6 @@ class UserRepositoryDocumentDB extends UserRepositoryInterface {
|
|
|
423
421
|
);
|
|
424
422
|
return this._mapUser(decrypted);
|
|
425
423
|
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Set the legacy organizationId only if it is still null or absent (see the
|
|
429
|
-
* interface): the filter carries the condition, so it is one atomic update.
|
|
430
|
-
* @param {string} individualUserId
|
|
431
|
-
* @param {string} organizationUserId
|
|
432
|
-
* @returns {Promise<Object|null>} The individual user as stored afterwards
|
|
433
|
-
*/
|
|
434
|
-
async linkIndividualToOrganizationIfUnset(individualUserId, organizationUserId) {
|
|
435
|
-
await updateOne(
|
|
436
|
-
this.prisma,
|
|
437
|
-
'User',
|
|
438
|
-
{
|
|
439
|
-
_id: toObjectId(individualUserId),
|
|
440
|
-
type: 'INDIVIDUAL',
|
|
441
|
-
// Raw MongoDB query (not Prisma): `{ field: null }` matches both a
|
|
442
|
-
// null value and a missing field, so no `$exists` branch is needed.
|
|
443
|
-
organizationId: null,
|
|
444
|
-
},
|
|
445
|
-
{ $set: { organizationId: toObjectId(organizationUserId) } }
|
|
446
|
-
);
|
|
447
|
-
return this.findIndividualUserById(individualUserId);
|
|
448
|
-
}
|
|
449
424
|
}
|
|
450
425
|
|
|
451
426
|
module.exports = { UserRepositoryDocumentDB };
|
|
@@ -209,24 +209,6 @@ class UserRepositoryInterface {
|
|
|
209
209
|
'Method linkIndividualToOrganization must be implemented by subclass'
|
|
210
210
|
);
|
|
211
211
|
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Set an individual user's legacy `organizationId` pointer only if it is
|
|
215
|
-
* not set yet (their first link), decided by the database in the same
|
|
216
|
-
* statement so two concurrent first logins cannot overwrite each other.
|
|
217
|
-
* Never changes an existing pointer (ADR-056 §3.6).
|
|
218
|
-
*
|
|
219
|
-
* @param {string|number} individualUserId - Individual user ID
|
|
220
|
-
* @param {string|number} organizationUserId - Organization user ID
|
|
221
|
-
* @returns {Promise<Object|null>} The individual user as stored afterwards
|
|
222
|
-
* (null if there is no such individual)
|
|
223
|
-
* @abstract
|
|
224
|
-
*/
|
|
225
|
-
async linkIndividualToOrganizationIfUnset(individualUserId, organizationUserId) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
'Method linkIndividualToOrganizationIfUnset must be implemented by subclass'
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
212
|
}
|
|
231
213
|
|
|
232
214
|
module.exports = { UserRepositoryInterface };
|
|
@@ -318,30 +318,6 @@ class UserRepositoryMongo extends UserRepositoryInterface {
|
|
|
318
318
|
},
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Set the legacy organizationId only if it is still null (see the interface).
|
|
324
|
-
* @param {string} individualUserId
|
|
325
|
-
* @param {string} organizationUserId
|
|
326
|
-
* @returns {Promise<Object|null>} The individual user as stored afterwards
|
|
327
|
-
*/
|
|
328
|
-
async linkIndividualToOrganizationIfUnset(individualUserId, organizationUserId) {
|
|
329
|
-
await this.prisma.user.updateMany({
|
|
330
|
-
where: {
|
|
331
|
-
id: individualUserId,
|
|
332
|
-
type: 'INDIVIDUAL',
|
|
333
|
-
// Prisma on MongoDB: `null` matches only an explicit null, and
|
|
334
|
-
// `isSet: false` only a missing field. An individual created
|
|
335
|
-
// without the field is the common case, so match both.
|
|
336
|
-
OR: [
|
|
337
|
-
{ organizationId: null },
|
|
338
|
-
{ organizationId: { isSet: false } },
|
|
339
|
-
],
|
|
340
|
-
},
|
|
341
|
-
data: { organizationId: organizationUserId },
|
|
342
|
-
});
|
|
343
|
-
return this.findIndividualUserById(individualUserId);
|
|
344
|
-
}
|
|
345
321
|
}
|
|
346
322
|
|
|
347
323
|
module.exports = { UserRepositoryMongo };
|
|
@@ -372,24 +372,6 @@ class UserRepositoryPostgres extends UserRepositoryInterface {
|
|
|
372
372
|
});
|
|
373
373
|
return this._convertUserIds(user);
|
|
374
374
|
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Set the legacy organizationId only if it is still null (see the interface).
|
|
378
|
-
* @param {string} individualUserId - Individual user ID (string from application layer)
|
|
379
|
-
* @param {string} organizationUserId - Organization user ID (string from application layer)
|
|
380
|
-
* @returns {Promise<Object|null>} The individual user as stored afterwards, with string IDs
|
|
381
|
-
*/
|
|
382
|
-
async linkIndividualToOrganizationIfUnset(individualUserId, organizationUserId) {
|
|
383
|
-
await this.prisma.user.updateMany({
|
|
384
|
-
where: {
|
|
385
|
-
id: this._convertId(individualUserId),
|
|
386
|
-
type: 'INDIVIDUAL',
|
|
387
|
-
organizationId: null,
|
|
388
|
-
},
|
|
389
|
-
data: { organizationId: this._convertId(organizationUserId) },
|
|
390
|
-
});
|
|
391
|
-
return this.findIndividualUserById(individualUserId);
|
|
392
|
-
}
|
|
393
375
|
}
|
|
394
376
|
|
|
395
377
|
module.exports = { UserRepositoryPostgres };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const Boom = require('@hapi/boom');
|
|
2
2
|
const { getLogger } = require('../../logs');
|
|
3
|
-
const { AUTH_SOURCES } = require('../user');
|
|
4
3
|
|
|
5
4
|
const log = getLogger('frigg.user.authentication');
|
|
6
5
|
|
|
@@ -69,13 +68,10 @@ class AuthenticateUser {
|
|
|
69
68
|
// Validate the API key (authentication)
|
|
70
69
|
await this.authenticateWithSharedSecret.execute(apiKey);
|
|
71
70
|
// Get user from x-frigg headers (authorization)
|
|
72
|
-
|
|
71
|
+
return await this.getUserFromXFriggHeaders.execute(
|
|
73
72
|
appUserId,
|
|
74
73
|
appOrgId
|
|
75
74
|
);
|
|
76
|
-
// The app's own backend: trusted to manage organization things.
|
|
77
|
-
user.setAuthSource(AUTH_SOURCES.SHARED_SECRET);
|
|
78
|
-
return user;
|
|
79
75
|
}
|
|
80
76
|
log.debug('No x-frigg-api-key header, skipping shared secret', {
|
|
81
77
|
eventName: `${log.name}.shared_secret_skipped`,
|
|
@@ -94,7 +90,6 @@ class AuthenticateUser {
|
|
|
94
90
|
// Detect JWT format (3 parts separated by dots)
|
|
95
91
|
if (token && token.split('.').length === 3) {
|
|
96
92
|
const user = await this.getUserFromAdopterJwt.execute(token);
|
|
97
|
-
user.setAuthSource(AUTH_SOURCES.ADOPTER_JWT);
|
|
98
93
|
// Validate x-frigg headers match JWT claims if present
|
|
99
94
|
if (appUserId || appOrgId) {
|
|
100
95
|
this.validateUserMatch(user, appUserId, appOrgId);
|
|
@@ -111,7 +106,6 @@ class AuthenticateUser {
|
|
|
111
106
|
const user = await this.getUserFromBearerToken.execute(
|
|
112
107
|
req.headers.authorization
|
|
113
108
|
);
|
|
114
|
-
user.setAuthSource(AUTH_SOURCES.BEARER_TOKEN);
|
|
115
109
|
// Validate x-frigg headers match token user if present
|
|
116
110
|
if (appUserId || appOrgId) {
|
|
117
111
|
this.validateUserMatch(user, appUserId, appOrgId);
|