@proconnect-gouv/proconnect.identite.runtime 0.0.0-stage → 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 +24 -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 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- 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 +50 -4
- 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/index.ts +12 -0
- package/src/domains/activities.ts +19 -0
- package/src/domains/index.ts +4 -0
- package/src/domains/mark-domain-as-verified.test.ts +346 -0
- package/src/domains/mark-domain-as-verified.ts +154 -0
- package/src/index.ts +5 -0
- 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 +14 -0
- package/tsconfig.lib.json +9 -0
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @proconnect-gouv/proconnect.identite.runtime
|
|
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
|
+
|
|
14
|
+
## 0.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [#2365](https://github.com/proconnect-gouv/proconnect-identite/pull/2365) [`e47d7dd`](https://github.com/proconnect-gouv/proconnect-identite/commit/e47d7dd69c76c7b8c8dc8094c8ec4ac574278e75) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Première version : `createIdentiteRuntime({ db })` reçoit une instance Drizzle construite par l'appelant avec le schéma de `@proconnect-gouv/proconnect.identite.database` et renvoie la commande `markDomainAsVerified`. Elle vérifie un domaine avec un type approuvé dans une seule transaction (remplace les états du domaine pour l'organisation et promeut les membres concernés) et renvoie une issue `domain_verified` (ligne `email_domain` créée, `promoted_members` avec leur rattachement précédent, `replaced_verification_types` supprimés) ou `organization_not_found` (avec `organization_id`). Le type `IdentiteDatabase` est exporté.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`e47d7dd`](https://github.com/proconnect-gouv/proconnect-identite/commit/e47d7dd69c76c7b8c8dc8094c8ec4ac574278e75), [`e47d7dd`](https://github.com/proconnect-gouv/proconnect-identite/commit/e47d7dd69c76c7b8c8dc8094c8ec4ac574278e75), [`da31f6d`](https://github.com/proconnect-gouv/proconnect-identite/commit/da31f6d036c7569c0184962bb9bc6d14d12f04a1)]:
|
|
23
|
+
- @proconnect-gouv/proconnect.identite.database@1.10.1
|
|
24
|
+
- @proconnect-gouv/proconnect.identite@12.0.0
|
|
@@ -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
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -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,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite.runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/runtime#readme",
|
|
5
|
+
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/proconnect-gouv/proconnect-identite.git",
|
|
9
|
+
"directory": "packages/runtime"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"type": "module",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#src/*": {
|
|
16
|
+
"types": "./dist/*/index.d.ts",
|
|
17
|
+
"default": "./dist/*/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc --build tsconfig.lib.json",
|
|
28
|
+
"check": "npm run build -- --noEmit",
|
|
29
|
+
"dev": "npm run build -- --watch --preserveWatchOutput",
|
|
30
|
+
"dev:test": "tsx --watch --test src/**/*.test.ts",
|
|
31
|
+
"test": "tsc --noEmit && tsx --test --test-reporter=spec"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@proconnect-gouv/proconnect.identite": "^12.0.0",
|
|
35
|
+
"@proconnect-gouv/proconnect.identite.database": "^1.11.0",
|
|
36
|
+
"zod": "^4.6.7"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@electric-sql/pglite": "^0.3.12",
|
|
40
|
+
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
41
|
+
"@types/node": "^22.18.6",
|
|
42
|
+
"drizzle-orm": "^0.45.4",
|
|
43
|
+
"tsx": "^4.20.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"drizzle-orm": "^0.45.4"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { IdentiteDatabase } from "#src/database";
|
|
4
|
+
import type * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export type Actor =
|
|
9
|
+
| { type: "app"; job: string }
|
|
10
|
+
| { type: "moderator"; sub: string };
|
|
11
|
+
|
|
12
|
+
export type App = "hyyypertool" | "proconnect-identite";
|
|
13
|
+
|
|
14
|
+
export type RuntimeContext = {
|
|
15
|
+
actor: Actor;
|
|
16
|
+
app: App;
|
|
17
|
+
db: IdentiteDatabase;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ContextShape = { inputs: unknown; outcome: unknown };
|
|
21
|
+
|
|
22
|
+
export type ContextMap = Record<string, ContextShape>;
|
|
23
|
+
|
|
24
|
+
export type ContextsOf<
|
|
25
|
+
Schemas extends Record<string, z.ZodType<ContextShape>>,
|
|
26
|
+
> = { [Action in keyof Schemas]: z.infer<Schemas[Action]> };
|
|
27
|
+
|
|
28
|
+
export type ActivityOf<Contexts extends ContextMap> = {
|
|
29
|
+
[Action in keyof Contexts & string]: {
|
|
30
|
+
action: Action;
|
|
31
|
+
context: Contexts[Action];
|
|
32
|
+
};
|
|
33
|
+
}[keyof Contexts & string];
|
|
34
|
+
|
|
35
|
+
export type ActivityTargets = {
|
|
36
|
+
moderation_id?: number;
|
|
37
|
+
organization_id?: number;
|
|
38
|
+
user_id?: number;
|
|
39
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export type IdentiteDatabase = PgDatabase<PgQueryResultHKT, typeof schema>;
|
|
9
|
+
|
|
10
|
+
export type IdentiteTransaction = Parameters<
|
|
11
|
+
Parameters<IdentiteDatabase["transaction"]>[0]
|
|
12
|
+
>[0];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { EmailDomainApprovedVerificationEnum } from "@proconnect-gouv/proconnect.identite/types";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export const domainActivities = {
|
|
9
|
+
"domain.verified": z.object({
|
|
10
|
+
inputs: z.object({
|
|
11
|
+
domain: z.string(),
|
|
12
|
+
verification_type: EmailDomainApprovedVerificationEnum,
|
|
13
|
+
}),
|
|
14
|
+
outcome: z.object({
|
|
15
|
+
email_domain_id: z.number(),
|
|
16
|
+
replaced_verification_types: z.array(z.string()),
|
|
17
|
+
}),
|
|
18
|
+
}),
|
|
19
|
+
};
|