@proconnect-gouv/proconnect.identite.runtime 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- package/dist/activity/activity-context-schemas.d.ts +20 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -0
- package/dist/activity/activity-context-schemas.js +4 -0
- package/dist/activity/index.d.ts +3 -0
- package/dist/activity/index.d.ts.map +1 -0
- package/dist/activity/index.js +3 -0
- package/dist/activity/types.d.ts +36 -0
- package/dist/activity/types.d.ts.map +1 -0
- package/dist/activity/types.js +2 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +2 -0
- package/dist/domains/activities.d.ts +19 -0
- package/dist/domains/activities.d.ts.map +1 -0
- package/dist/domains/activities.js +16 -0
- package/dist/domains/index.d.ts +3 -0
- package/dist/domains/index.d.ts.map +1 -0
- package/dist/domains/index.js +3 -0
- package/dist/domains/mark-domain-as-verified.d.ts +25 -0
- package/dist/domains/mark-domain-as-verified.d.ts.map +1 -0
- package/dist/domains/mark-domain-as-verified.js +88 -0
- package/dist/index.d.ts +4 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -88
- package/dist/journal/index.d.ts +2 -0
- package/dist/journal/index.d.ts.map +1 -0
- package/dist/journal/index.js +2 -0
- package/dist/journal/insert-activity.d.ts +6 -0
- package/dist/journal/insert-activity.d.ts.map +1 -0
- package/dist/journal/insert-activity.js +22 -0
- package/dist/runtime/create-identite-runtime.d.ts +32 -0
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -0
- package/dist/runtime/create-identite-runtime.js +14 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/package.json +11 -5
- package/src/activity/activity-context-schemas.ts +10 -0
- package/src/activity/index.ts +4 -0
- package/src/activity/types.ts +39 -0
- package/src/{database.ts → database/index.ts} +4 -0
- package/src/domains/activities.ts +19 -0
- package/src/domains/index.ts +4 -0
- package/src/{mark-domain-as-verified.test.ts → domains/mark-domain-as-verified.test.ts} +143 -23
- package/src/{mark-domain-as-verified.ts → domains/mark-domain-as-verified.ts} +28 -5
- package/src/index.ts +3 -12
- package/src/journal/index.ts +3 -0
- package/src/journal/insert-activity.ts +43 -0
- package/src/runtime/create-identite-runtime.test.ts +147 -0
- package/src/runtime/create-identite-runtime.ts +33 -0
- package/src/runtime/index.ts +3 -0
- package/tsconfig.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite.runtime
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2369](https://github.com/proconnect-gouv/proconnect-identite/pull/2369) [`6971b21`](https://github.com/proconnect-gouv/proconnect-identite/commit/6971b2172c4aeeb7a58f121e88d9d4548fbb87b3) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Journalise les vérifications de domaine. Changement non rétrocompatible : `createIdentiteRuntime({ app, db })` reçoit l'application appelante (`"hyyypertool"` ou `"proconnect-identite"`, enregistrée dans la colonne `app` de chaque ligne) et renvoie `as(actor)` (type `Actor` exporté : `{ type: "app", job }` ou `{ type: "moderator", sub }`), qui renvoie la commande `markDomainAsVerified` et `record` liées à l'acteur. La commande ajoute une ligne `domain.verified` dans `activity_logs` dans sa transaction et son issue `domain_verified` porte `activity_id`. Le `context` de chaque action est décrit par un schéma zod : le runtime exporte `activityContextSchemas` (`domain.verified`) et le type déduit `ActivityContexts`. Une application décrit ses propres actions avec `ContextsOf` et les passe en paramètre de type, `createIdentiteRuntime<ContextesDeLApplication>({ app, db })` ; `record(tx, { action, context, organization_id?, user_id?, moderation_id? })` écrit alors l'une de ces actions dans la transaction de l'appelant (type `IdentiteTransaction` exporté) et renvoie `{ activity_id }`. Ne compilent pas : une action déjà définie par le runtime, un `context` qui ne correspond pas à son action, la base `db` au lieu d'une transaction. Nouvelle dépendance : `zod`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`6971b21`](https://github.com/proconnect-gouv/proconnect-identite/commit/6971b2172c4aeeb7a58f121e88d9d4548fbb87b3)]:
|
|
12
|
+
- @proconnect-gouv/proconnect.identite.database@1.11.0
|
|
13
|
+
|
|
3
14
|
## 0.1.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContextsOf } from "./types.js";
|
|
2
|
+
export declare const activityContextSchemas: {
|
|
3
|
+
"domain.verified": import("zod").ZodObject<{
|
|
4
|
+
inputs: import("zod").ZodObject<{
|
|
5
|
+
domain: import("zod").ZodString;
|
|
6
|
+
verification_type: import("zod").ZodEnum<{
|
|
7
|
+
official_contact: "official_contact";
|
|
8
|
+
trackdechets_postal_mail: "trackdechets_postal_mail";
|
|
9
|
+
verified: "verified";
|
|
10
|
+
external: "external";
|
|
11
|
+
}>;
|
|
12
|
+
}, import("zod/v4/core").$strip>;
|
|
13
|
+
outcome: import("zod").ZodObject<{
|
|
14
|
+
email_domain_id: import("zod").ZodNumber;
|
|
15
|
+
replaced_verification_types: import("zod").ZodArray<import("zod").ZodString>;
|
|
16
|
+
}, import("zod/v4/core").$strip>;
|
|
17
|
+
}, import("zod/v4/core").$strip>;
|
|
18
|
+
};
|
|
19
|
+
export type ActivityContexts = ContextsOf<typeof activityContextSchemas>;
|
|
20
|
+
//# sourceMappingURL=activity-context-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-context-schemas.d.ts","sourceRoot":"","sources":["../../src/activity/activity-context-schemas.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;CAA0B,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/activity/index.ts"],"names":[],"mappings":"AAEA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IdentiteDatabase } from "#src/database";
|
|
2
|
+
import type * as z from "zod";
|
|
3
|
+
export type Actor = {
|
|
4
|
+
type: "app";
|
|
5
|
+
job: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "moderator";
|
|
8
|
+
sub: string;
|
|
9
|
+
};
|
|
10
|
+
export type App = "hyyypertool" | "proconnect-identite";
|
|
11
|
+
export type RuntimeContext = {
|
|
12
|
+
actor: Actor;
|
|
13
|
+
app: App;
|
|
14
|
+
db: IdentiteDatabase;
|
|
15
|
+
};
|
|
16
|
+
type ContextShape = {
|
|
17
|
+
inputs: unknown;
|
|
18
|
+
outcome: unknown;
|
|
19
|
+
};
|
|
20
|
+
export type ContextMap = Record<string, ContextShape>;
|
|
21
|
+
export type ContextsOf<Schemas extends Record<string, z.ZodType<ContextShape>>> = {
|
|
22
|
+
[Action in keyof Schemas]: z.infer<Schemas[Action]>;
|
|
23
|
+
};
|
|
24
|
+
export type ActivityOf<Contexts extends ContextMap> = {
|
|
25
|
+
[Action in keyof Contexts & string]: {
|
|
26
|
+
action: Action;
|
|
27
|
+
context: Contexts[Action];
|
|
28
|
+
};
|
|
29
|
+
}[keyof Contexts & string];
|
|
30
|
+
export type ActivityTargets = {
|
|
31
|
+
moderation_id?: number;
|
|
32
|
+
organization_id?: number;
|
|
33
|
+
user_id?: number;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/activity/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAI9B,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,MAAM,MAAM,GAAG,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,EAAE,EAAE,gBAAgB,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEtD,MAAM,MAAM,UAAU,CACpB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IACrD;KAAG,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;CAAE,CAAC;AAE5D,MAAM,MAAM,UAAU,CAAC,QAAQ,SAAS,UAAU,IAAI;KACnD,MAAM,IAAI,MAAM,QAAQ,GAAG,MAAM,GAAG;QACnC,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC3B;CACF,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC;AAE3B,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
2
|
+
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
3
|
+
export type IdentiteDatabase = PgDatabase<PgQueryResultHKT, typeof schema>;
|
|
4
|
+
export type IdentiteTransaction = Parameters<Parameters<IdentiteDatabase["transaction"]>[0]>[0];
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,MAAM,uDAAuD,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,EAAE,OAAO,MAAM,CAAC,CAAC;AAE3E,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAC1C,UAAU,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAC/C,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const domainActivities: {
|
|
3
|
+
"domain.verified": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{
|
|
5
|
+
domain: z.ZodString;
|
|
6
|
+
verification_type: z.ZodEnum<{
|
|
7
|
+
official_contact: "official_contact";
|
|
8
|
+
trackdechets_postal_mail: "trackdechets_postal_mail";
|
|
9
|
+
verified: "verified";
|
|
10
|
+
external: "external";
|
|
11
|
+
}>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
outcome: z.ZodObject<{
|
|
14
|
+
email_domain_id: z.ZodNumber;
|
|
15
|
+
replaced_verification_types: z.ZodArray<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/domains/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAW5B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { EmailDomainApprovedVerificationEnum } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//
|
|
5
|
+
export const domainActivities = {
|
|
6
|
+
"domain.verified": z.object({
|
|
7
|
+
inputs: z.object({
|
|
8
|
+
domain: z.string(),
|
|
9
|
+
verification_type: EmailDomainApprovedVerificationEnum,
|
|
10
|
+
}),
|
|
11
|
+
outcome: z.object({
|
|
12
|
+
email_domain_id: z.number(),
|
|
13
|
+
replaced_verification_types: z.array(z.string()),
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domains/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import { type EmailDomainApprovedVerificationType } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type MarkDomainAsVerifiedOutcome = {
|
|
4
|
+
kind: "domain_verified";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
email_domain: {
|
|
7
|
+
id: number;
|
|
8
|
+
verification_type: EmailDomainApprovedVerificationType;
|
|
9
|
+
};
|
|
10
|
+
promoted_members: ReadonlyArray<{
|
|
11
|
+
previous_verification_type: string;
|
|
12
|
+
user_id: number;
|
|
13
|
+
}>;
|
|
14
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "organization_not_found";
|
|
17
|
+
organization_id: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function markDomainAsVerifiedFactory({ actor, app, db, }: RuntimeContext): ({ domain, domain_verification_type, organization_id, }: {
|
|
20
|
+
domain: string;
|
|
21
|
+
domain_verification_type: EmailDomainApprovedVerificationType;
|
|
22
|
+
organization_id: number;
|
|
23
|
+
}) => Promise<MarkDomainAsVerifiedOutcome>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=mark-domain-as-verified.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../src/domains/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAOtE,OAAO,EAKL,KAAK,mCAAmC,EACzC,MAAM,4CAA4C,CAAC;AAKpD,KAAK,2BAA2B,GAC5B;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,mCAAmC,CAAC;KACxD,CAAC;IACF,gBAAgB,EAAE,aAAa,CAAC;QAC9B,0BAA0B,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,2BAA2B,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACpD,GACD;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IACsB,wDAIlC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,mCAAmC,CAAC;IAC9D,eAAe,EAAE,MAAM,CAAC;CACzB,KAAG,OAAO,CAAC,2BAA2B,CAAC,CAwGzC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { email_domains, users_organizations, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { getMemberIdsPromotedByDomain } from "@proconnect-gouv/proconnect.identite/services/organization";
|
|
5
|
+
import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, LinkEnum, } from "@proconnect-gouv/proconnect.identite/types";
|
|
6
|
+
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
7
|
+
export function markDomainAsVerifiedFactory({ actor, app, db, }) {
|
|
8
|
+
return function markDomainAsVerified({ domain, domain_verification_type, organization_id, }) {
|
|
9
|
+
return db.transaction(async (tx) => {
|
|
10
|
+
const organization = await tx.query.organizations.findFirst({
|
|
11
|
+
columns: { id: true },
|
|
12
|
+
where: (table, { eq }) => eq(table.id, organization_id),
|
|
13
|
+
});
|
|
14
|
+
if (!organization) {
|
|
15
|
+
return { kind: "organization_not_found", organization_id };
|
|
16
|
+
}
|
|
17
|
+
const memberships = await tx.query.users_organizations.findMany({
|
|
18
|
+
columns: { user_id: true, verification_type: true },
|
|
19
|
+
where: (table, { eq }) => eq(table.organization_id, organization_id),
|
|
20
|
+
with: { user: { columns: { email: true } } },
|
|
21
|
+
});
|
|
22
|
+
const members = memberships.map(({ user: { email }, user_id, verification_type }) => ({
|
|
23
|
+
email,
|
|
24
|
+
id: user_id,
|
|
25
|
+
verification_type,
|
|
26
|
+
}));
|
|
27
|
+
const promoted_member_ids = getMemberIdsPromotedByDomain({
|
|
28
|
+
domain,
|
|
29
|
+
members,
|
|
30
|
+
});
|
|
31
|
+
const replaced = await tx
|
|
32
|
+
.delete(email_domains)
|
|
33
|
+
.where(and(eq(email_domains.organization_id, organization_id), eq(email_domains.domain, domain), inArray(email_domains.verification_type, [
|
|
34
|
+
...EmailDomainApprovedVerificationValues,
|
|
35
|
+
...EmailDomainPendingVerificationValues,
|
|
36
|
+
...EmailDomainRejectedVerificationValues,
|
|
37
|
+
])))
|
|
38
|
+
.returning({ verification_type: email_domains.verification_type });
|
|
39
|
+
const [email_domain] = await tx
|
|
40
|
+
.insert(email_domains)
|
|
41
|
+
.values({
|
|
42
|
+
domain,
|
|
43
|
+
organization_id,
|
|
44
|
+
verification_type: domain_verification_type,
|
|
45
|
+
verified_at: sql `now()`,
|
|
46
|
+
})
|
|
47
|
+
.returning({ id: email_domains.id });
|
|
48
|
+
const replaced_verification_types = replaced.map(({ verification_type }) => verification_type);
|
|
49
|
+
const { activity_id } = await insertActivity(tx, {
|
|
50
|
+
action: "domain.verified",
|
|
51
|
+
actor,
|
|
52
|
+
app,
|
|
53
|
+
context: {
|
|
54
|
+
inputs: { domain, verification_type: domain_verification_type },
|
|
55
|
+
outcome: {
|
|
56
|
+
email_domain_id: email_domain.id,
|
|
57
|
+
replaced_verification_types,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
organization_id,
|
|
61
|
+
});
|
|
62
|
+
if (promoted_member_ids.length > 0) {
|
|
63
|
+
await tx
|
|
64
|
+
.update(users_organizations)
|
|
65
|
+
.set({
|
|
66
|
+
updated_at: sql `now()`,
|
|
67
|
+
verification_type: LinkEnum.enum.domain,
|
|
68
|
+
})
|
|
69
|
+
.where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, promoted_member_ids)));
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
kind: "domain_verified",
|
|
73
|
+
activity_id,
|
|
74
|
+
email_domain: {
|
|
75
|
+
id: email_domain.id,
|
|
76
|
+
verification_type: domain_verification_type,
|
|
77
|
+
},
|
|
78
|
+
promoted_members: memberships
|
|
79
|
+
.filter(({ user_id }) => promoted_member_ids.includes(user_id))
|
|
80
|
+
.map(({ user_id, verification_type }) => ({
|
|
81
|
+
previous_verification_type: verification_type,
|
|
82
|
+
user_id,
|
|
83
|
+
})),
|
|
84
|
+
replaced_verification_types,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type IdentiteDatabase = PgDatabase<PgQueryResultHKT, typeof schema>;
|
|
6
|
-
|
|
7
|
-
declare function createIdentiteRuntime({ db }: {
|
|
8
|
-
db: IdentiteDatabase;
|
|
9
|
-
}): {
|
|
10
|
-
markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
|
|
11
|
-
domain: string;
|
|
12
|
-
domain_verification_type: _proconnect_gouv_proconnect_identite_types.EmailDomainApprovedVerificationType;
|
|
13
|
-
organization_id: number;
|
|
14
|
-
}) => Promise<{
|
|
15
|
-
kind: "domain_verified";
|
|
16
|
-
email_domain: {
|
|
17
|
-
id: number;
|
|
18
|
-
verification_type: _proconnect_gouv_proconnect_identite_types.EmailDomainApprovedVerificationType;
|
|
19
|
-
};
|
|
20
|
-
promoted_members: ReadonlyArray<{
|
|
21
|
-
previous_verification_type: string;
|
|
22
|
-
user_id: number;
|
|
23
|
-
}>;
|
|
24
|
-
replaced_verification_types: ReadonlyArray<string>;
|
|
25
|
-
} | {
|
|
26
|
-
kind: "organization_not_found";
|
|
27
|
-
organization_id: number;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export { createIdentiteRuntime };
|
|
32
|
-
export type { IdentiteDatabase };
|
|
33
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from "./activity/index.js";
|
|
2
|
+
export * from "./database/index.js";
|
|
3
|
+
export * from "./runtime/index.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,88 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function markDomainAsVerifiedFactory({ db }) {
|
|
7
|
-
return function markDomainAsVerified({
|
|
8
|
-
domain,
|
|
9
|
-
domain_verification_type,
|
|
10
|
-
organization_id
|
|
11
|
-
}) {
|
|
12
|
-
return db.transaction(async (tx) => {
|
|
13
|
-
const organization = await tx.query.organizations.findFirst({
|
|
14
|
-
columns: { id: true },
|
|
15
|
-
where: (table, { eq: eq2 }) => eq2(table.id, organization_id)
|
|
16
|
-
});
|
|
17
|
-
if (!organization) {
|
|
18
|
-
return { kind: "organization_not_found", organization_id };
|
|
19
|
-
}
|
|
20
|
-
const memberships = await tx.query.users_organizations.findMany({
|
|
21
|
-
columns: { user_id: true, verification_type: true },
|
|
22
|
-
where: (table, { eq: eq2 }) => eq2(table.organization_id, organization_id),
|
|
23
|
-
with: { user: { columns: { email: true } } }
|
|
24
|
-
});
|
|
25
|
-
const members = memberships.map(
|
|
26
|
-
({ user: { email }, user_id, verification_type }) => ({
|
|
27
|
-
email,
|
|
28
|
-
id: user_id,
|
|
29
|
-
verification_type
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
const promoted_member_ids = getMemberIdsPromotedByDomain({
|
|
33
|
-
domain,
|
|
34
|
-
members
|
|
35
|
-
});
|
|
36
|
-
const replaced = await tx.delete(email_domains).where(
|
|
37
|
-
and(
|
|
38
|
-
eq(email_domains.organization_id, organization_id),
|
|
39
|
-
eq(email_domains.domain, domain),
|
|
40
|
-
inArray(email_domains.verification_type, [
|
|
41
|
-
...EmailDomainApprovedVerificationValues,
|
|
42
|
-
...EmailDomainPendingVerificationValues,
|
|
43
|
-
...EmailDomainRejectedVerificationValues
|
|
44
|
-
])
|
|
45
|
-
)
|
|
46
|
-
).returning({ verification_type: email_domains.verification_type });
|
|
47
|
-
const [email_domain] = await tx.insert(email_domains).values({
|
|
48
|
-
domain,
|
|
49
|
-
organization_id,
|
|
50
|
-
verification_type: domain_verification_type,
|
|
51
|
-
verified_at: sql`now()`
|
|
52
|
-
}).returning({ id: email_domains.id });
|
|
53
|
-
if (promoted_member_ids.length > 0) {
|
|
54
|
-
await tx.update(users_organizations).set({
|
|
55
|
-
updated_at: sql`now()`,
|
|
56
|
-
verification_type: LinkEnum.enum.domain
|
|
57
|
-
}).where(
|
|
58
|
-
and(
|
|
59
|
-
eq(users_organizations.organization_id, organization_id),
|
|
60
|
-
inArray(users_organizations.user_id, promoted_member_ids)
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
kind: "domain_verified",
|
|
66
|
-
email_domain: {
|
|
67
|
-
id: email_domain.id,
|
|
68
|
-
verification_type: domain_verification_type
|
|
69
|
-
},
|
|
70
|
-
promoted_members: memberships.filter(({ user_id }) => promoted_member_ids.includes(user_id)).map(({ user_id, verification_type }) => ({
|
|
71
|
-
previous_verification_type: verification_type,
|
|
72
|
-
user_id
|
|
73
|
-
})),
|
|
74
|
-
replaced_verification_types: replaced.map(
|
|
75
|
-
({ verification_type }) => verification_type
|
|
76
|
-
)
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function createIdentiteRuntime({ db }) {
|
|
83
|
-
return {
|
|
84
|
-
markDomainAsVerified: markDomainAsVerifiedFactory({ db })
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { createIdentiteRuntime };
|
|
1
|
+
//
|
|
2
|
+
export * from "./activity/index.js";
|
|
3
|
+
export * from "./database/index.js";
|
|
4
|
+
export * from "./runtime/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/journal/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ActivityOf, ActivityTargets, ContextMap, RuntimeContext } from "#src/activity";
|
|
2
|
+
import type { IdentiteTransaction } from "#src/database";
|
|
3
|
+
export declare function insertActivity<Contexts extends ContextMap>(tx: IdentiteTransaction, { actor, app, ...activity }: ActivityOf<Contexts> & ActivityTargets & Pick<RuntimeContext, "actor" | "app">): Promise<{
|
|
4
|
+
activity_id: number;
|
|
5
|
+
}>;
|
|
6
|
+
//# sourceMappingURL=insert-activity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-activity.d.ts","sourceRoot":"","sources":["../../src/journal/insert-activity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAKzD,wBAAsB,cAAc,CAAC,QAAQ,SAAS,UAAU,EAC9D,EAAE,EAAE,mBAAmB,EACvB,EACE,KAAK,EACL,GAAG,EACH,GAAG,QAAQ,EACZ,EAAE,UAAU,CAAC,QAAQ,CAAC,GACrB,eAAe,GACf,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,KAAK,CAAC;;GAQxC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { activity_logs } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
3
|
+
//
|
|
4
|
+
export async function insertActivity(tx, { actor, app, ...activity }) {
|
|
5
|
+
const [row] = await tx
|
|
6
|
+
.insert(activity_logs)
|
|
7
|
+
.values({ ...activity, ...toActorColumns({ actor, app }) })
|
|
8
|
+
.returning({ id: activity_logs.id });
|
|
9
|
+
return { activity_id: row.id };
|
|
10
|
+
}
|
|
11
|
+
function toActorColumns({ actor, app }) {
|
|
12
|
+
switch (actor.type) {
|
|
13
|
+
case "app":
|
|
14
|
+
return { actor_ref: actor.job, actor_type: "app", app };
|
|
15
|
+
case "moderator":
|
|
16
|
+
return { actor_ref: actor.sub, actor_type: "moderator", app };
|
|
17
|
+
default: {
|
|
18
|
+
const unhandled_actor = actor;
|
|
19
|
+
throw new Error(`Unhandled actor: ${JSON.stringify(unhandled_actor)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ActivityContexts, ActivityOf, ActivityTargets, Actor, ContextMap, RuntimeContext } from "#src/activity";
|
|
2
|
+
import type { IdentiteTransaction } from "#src/database";
|
|
3
|
+
export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
4
|
+
[Action in keyof ActivityContexts]?: never;
|
|
5
|
+
} = {}>({ app, db }: Omit<RuntimeContext, "actor">): {
|
|
6
|
+
as(actor: Actor): {
|
|
7
|
+
markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
|
|
8
|
+
domain: string;
|
|
9
|
+
domain_verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
10
|
+
organization_id: number;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
kind: "domain_verified";
|
|
13
|
+
activity_id: number;
|
|
14
|
+
email_domain: {
|
|
15
|
+
id: number;
|
|
16
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
17
|
+
};
|
|
18
|
+
promoted_members: ReadonlyArray<{
|
|
19
|
+
previous_verification_type: string;
|
|
20
|
+
user_id: number;
|
|
21
|
+
}>;
|
|
22
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "organization_not_found";
|
|
25
|
+
organization_id: number;
|
|
26
|
+
}>;
|
|
27
|
+
record: (tx: IdentiteTransaction, activity: ActivityOf<OwnContexts> & ActivityTargets) => Promise<{
|
|
28
|
+
activity_id: number;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=create-identite-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-identite-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/create-identite-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAMzD,wBAAgB,qBAAqB,CACnC,WAAW,SAAS,UAAU,GAAG;KAC9B,MAAM,IAAI,MAAM,gBAAgB,CAAC,CAAC,EAAE,KAAK;CAC3C,GAAG,EAAE,EACN,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;cAE9B,KAAK;;;;;;;;;;;;;;;;;;;;;qBAIL,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;EAK5D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { markDomainAsVerifiedFactory } from "#src/domains";
|
|
3
|
+
import { insertActivity } from "#src/journal";
|
|
4
|
+
//
|
|
5
|
+
export function createIdentiteRuntime({ app, db }) {
|
|
6
|
+
return {
|
|
7
|
+
as(actor) {
|
|
8
|
+
return {
|
|
9
|
+
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
10
|
+
record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAEA,cAAc,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite.runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/runtime#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"type": "module",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#src/*": {
|
|
16
|
+
"types": "./dist/*/index.d.ts",
|
|
17
|
+
"default": "./dist/*/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
14
20
|
"exports": {
|
|
15
21
|
".": {
|
|
16
22
|
"import": "./dist/index.js",
|
|
@@ -18,22 +24,22 @@
|
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
21
|
-
"build": "
|
|
27
|
+
"build": "tsc --build tsconfig.lib.json",
|
|
22
28
|
"check": "npm run build -- --noEmit",
|
|
23
29
|
"dev": "npm run build -- --watch --preserveWatchOutput",
|
|
24
30
|
"dev:test": "tsx --watch --test src/**/*.test.ts",
|
|
25
|
-
"test": "tsx --test --test-reporter=spec
|
|
31
|
+
"test": "tsc --noEmit && tsx --test --test-reporter=spec"
|
|
26
32
|
},
|
|
27
33
|
"dependencies": {
|
|
28
34
|
"@proconnect-gouv/proconnect.identite": "^12.0.0",
|
|
29
|
-
"@proconnect-gouv/proconnect.identite.database": "^1.
|
|
35
|
+
"@proconnect-gouv/proconnect.identite.database": "^1.11.0",
|
|
36
|
+
"zod": "^4.6.7"
|
|
30
37
|
},
|
|
31
38
|
"devDependencies": {
|
|
32
39
|
"@electric-sql/pglite": "^0.3.12",
|
|
33
40
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
34
41
|
"@types/node": "^22.18.6",
|
|
35
42
|
"drizzle-orm": "^0.45.4",
|
|
36
|
-
"pkgroll": "^2.22.0",
|
|
37
43
|
"tsx": "^4.20.3"
|
|
38
44
|
},
|
|
39
45
|
"peerDependencies": {
|