@proconnect-gouv/proconnect.identite.runtime 0.1.0 → 0.3.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/activity/activity-context-schemas.d.ts +46 -0
  3. package/dist/activity/activity-context-schemas.d.ts.map +1 -0
  4. package/dist/activity/activity-context-schemas.js +8 -0
  5. package/dist/activity/index.d.ts +3 -0
  6. package/dist/activity/index.d.ts.map +1 -0
  7. package/dist/activity/index.js +3 -0
  8. package/dist/activity/types.d.ts +36 -0
  9. package/dist/activity/types.d.ts.map +1 -0
  10. package/dist/activity/types.js +2 -0
  11. package/dist/database/index.d.ts +5 -0
  12. package/dist/database/index.d.ts.map +1 -0
  13. package/dist/database/index.js +2 -0
  14. package/dist/domains/activities.d.ts +19 -0
  15. package/dist/domains/activities.d.ts.map +1 -0
  16. package/dist/domains/activities.js +16 -0
  17. package/dist/domains/index.d.ts +3 -0
  18. package/dist/domains/index.d.ts.map +1 -0
  19. package/dist/domains/index.js +3 -0
  20. package/dist/domains/mark-domain-as-verified.d.ts +25 -0
  21. package/dist/domains/mark-domain-as-verified.d.ts.map +1 -0
  22. package/dist/domains/mark-domain-as-verified.js +103 -0
  23. package/dist/index.d.ts +4 -33
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +4 -88
  26. package/dist/journal/index.d.ts +2 -0
  27. package/dist/journal/index.d.ts.map +1 -0
  28. package/dist/journal/index.js +2 -0
  29. package/dist/journal/insert-activity.d.ts +8 -0
  30. package/dist/journal/insert-activity.d.ts.map +1 -0
  31. package/dist/journal/insert-activity.js +22 -0
  32. package/dist/memberships/activities.d.ts +30 -0
  33. package/dist/memberships/activities.d.ts.map +1 -0
  34. package/dist/memberships/activities.js +14 -0
  35. package/dist/memberships/index.d.ts +2 -0
  36. package/dist/memberships/index.d.ts.map +1 -0
  37. package/dist/memberships/index.js +2 -0
  38. package/dist/runtime/create-identite-runtime.d.ts +32 -0
  39. package/dist/runtime/create-identite-runtime.d.ts.map +1 -0
  40. package/dist/runtime/create-identite-runtime.js +14 -0
  41. package/dist/runtime/index.d.ts +2 -0
  42. package/dist/runtime/index.d.ts.map +1 -0
  43. package/dist/runtime/index.js +2 -0
  44. package/package.json +11 -5
  45. package/src/activity/activity-context-schemas.ts +14 -0
  46. package/src/activity/index.ts +4 -0
  47. package/src/activity/types.ts +39 -0
  48. package/src/{database.ts → database/index.ts} +4 -0
  49. package/src/domains/activities.ts +19 -0
  50. package/src/domains/index.ts +4 -0
  51. package/src/domains/mark-domain-as-verified.test.ts +423 -0
  52. package/src/{mark-domain-as-verified.ts → domains/mark-domain-as-verified.ts} +54 -11
  53. package/src/index.ts +3 -12
  54. package/src/journal/index.ts +3 -0
  55. package/src/journal/insert-activity.ts +43 -0
  56. package/src/memberships/activities.ts +17 -0
  57. package/src/memberships/index.ts +3 -0
  58. package/src/runtime/create-identite-runtime.test.ts +148 -0
  59. package/src/runtime/create-identite-runtime.ts +33 -0
  60. package/src/runtime/index.ts +3 -0
  61. package/tsconfig.json +6 -3
  62. package/src/mark-domain-as-verified.test.ts +0 -226
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @proconnect-gouv/proconnect.identite.runtime
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2370](https://github.com/proconnect-gouv/proconnect-identite/pull/2370) [`d3dd8ca`](https://github.com/proconnect-gouv/proconnect-identite/commit/d3dd8cada634db4d3ed9a08d3b6f0ff4000ea97c) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Journalise les membres promus par une vérification de domaine. `markDomainAsVerified` ajoute, dans sa transaction, une ligne `member.promoted` par membre promu, sous l'acteur `{ type: "app", job: "domain.promote_members" }`, avec `user_id`, `organization_id` et `cause_activity_id` pointant vers la ligne `domain.verified`. `activityContextSchemas` décrit la nouvelle action : `inputs.previous_verification_type`, `outcome.verification_type`.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`d3dd8ca`](https://github.com/proconnect-gouv/proconnect-identite/commit/d3dd8cada634db4d3ed9a08d3b6f0ff4000ea97c)]:
12
+ - @proconnect-gouv/proconnect.identite.database@1.12.0
13
+
14
+ ## 0.2.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [#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`.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`6971b21`](https://github.com/proconnect-gouv/proconnect-identite/commit/6971b2172c4aeeb7a58f121e88d9d4548fbb87b3)]:
23
+ - @proconnect-gouv/proconnect.identite.database@1.11.0
24
+
3
25
  ## 0.1.0
4
26
 
5
27
  ### Minor Changes
@@ -0,0 +1,46 @@
1
+ import type { ContextsOf } from "./types.js";
2
+ export declare const activityContextSchemas: {
3
+ "member.promoted": import("zod").ZodObject<{
4
+ inputs: import("zod").ZodObject<{
5
+ previous_verification_type: import("zod").ZodString;
6
+ }, import("zod/v4/core").$strip>;
7
+ outcome: import("zod").ZodObject<{
8
+ verification_type: import("zod").ZodEnum<{
9
+ domain: "domain";
10
+ organization_dirigeant: "organization_dirigeant";
11
+ code_sent_to_official_contact_email: "code_sent_to_official_contact_email";
12
+ imported_from_coop_mediation_numerique: "imported_from_coop_mediation_numerique";
13
+ imported_from_inclusion_connect: "imported_from_inclusion_connect";
14
+ in_liste_dirigeants_rna: "in_liste_dirigeants_rna";
15
+ in_liste_dirigeants_rne: "in_liste_dirigeants_rne";
16
+ official_contact_email: "official_contact_email";
17
+ ordre_professionnel_domain: "ordre_professionnel_domain";
18
+ proof_received: "proof_received";
19
+ verified_by_coop_mediation_numerique: "verified_by_coop_mediation_numerique";
20
+ bypassed: "bypassed";
21
+ domain_not_verified_yet: "domain_not_verified_yet";
22
+ no_validation_means_available: "no_validation_means_available";
23
+ no_verification_means_for_entreprise_unipersonnelle: "no_verification_means_for_entreprise_unipersonnelle";
24
+ no_verification_means_for_small_association: "no_verification_means_for_small_association";
25
+ no_verification_means_for_small_organization: "no_verification_means_for_small_organization";
26
+ }>;
27
+ }, import("zod/v4/core").$strip>;
28
+ }, import("zod/v4/core").$strip>;
29
+ "domain.verified": import("zod").ZodObject<{
30
+ inputs: import("zod").ZodObject<{
31
+ domain: import("zod").ZodString;
32
+ verification_type: import("zod").ZodEnum<{
33
+ official_contact: "official_contact";
34
+ trackdechets_postal_mail: "trackdechets_postal_mail";
35
+ verified: "verified";
36
+ external: "external";
37
+ }>;
38
+ }, import("zod/v4/core").$strip>;
39
+ outcome: import("zod").ZodObject<{
40
+ email_domain_id: import("zod").ZodNumber;
41
+ replaced_verification_types: import("zod").ZodArray<import("zod").ZodString>;
42
+ }, import("zod/v4/core").$strip>;
43
+ }, import("zod/v4/core").$strip>;
44
+ };
45
+ export type ActivityContexts = ContextsOf<typeof activityContextSchemas>;
46
+ //# 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":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGlC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ //
2
+ import { domainActivities } from "#src/domains";
3
+ import { membershipActivities } from "#src/memberships";
4
+ //
5
+ export const activityContextSchemas = {
6
+ ...domainActivities,
7
+ ...membershipActivities,
8
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./activity-context-schemas.js";
2
+ export * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ //
2
+ export * from "./activity-context-schemas.js";
3
+ export * from "./types.js";
@@ -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,2 @@
1
+ //
2
+ export {};
@@ -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,2 @@
1
+ //
2
+ export {};
@@ -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,3 @@
1
+ export * from "./activities.js";
2
+ export * from "./mark-domain-as-verified.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ //
2
+ export * from "./activities.js";
3
+ export * from "./mark-domain-as-verified.js";
@@ -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,CA4HzC"}
@@ -0,0 +1,103 @@
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 promoted_members = memberships
32
+ .filter(({ user_id }) => promoted_member_ids.includes(user_id))
33
+ .map(({ user_id, verification_type }) => ({
34
+ previous_verification_type: verification_type,
35
+ user_id,
36
+ }));
37
+ const replaced = await tx
38
+ .delete(email_domains)
39
+ .where(and(eq(email_domains.organization_id, organization_id), eq(email_domains.domain, domain), inArray(email_domains.verification_type, [
40
+ ...EmailDomainApprovedVerificationValues,
41
+ ...EmailDomainPendingVerificationValues,
42
+ ...EmailDomainRejectedVerificationValues,
43
+ ])))
44
+ .returning({ verification_type: email_domains.verification_type });
45
+ const [email_domain] = await tx
46
+ .insert(email_domains)
47
+ .values({
48
+ domain,
49
+ organization_id,
50
+ verification_type: domain_verification_type,
51
+ verified_at: sql `now()`,
52
+ })
53
+ .returning({ id: email_domains.id });
54
+ const replaced_verification_types = replaced.map(({ verification_type }) => verification_type);
55
+ const { activity_id } = await insertActivity(tx, {
56
+ action: "domain.verified",
57
+ actor,
58
+ app,
59
+ context: {
60
+ inputs: { domain, verification_type: domain_verification_type },
61
+ outcome: {
62
+ email_domain_id: email_domain.id,
63
+ replaced_verification_types,
64
+ },
65
+ },
66
+ organization_id,
67
+ });
68
+ if (promoted_member_ids.length > 0) {
69
+ await tx
70
+ .update(users_organizations)
71
+ .set({
72
+ updated_at: sql `now()`,
73
+ verification_type: LinkEnum.enum.domain,
74
+ })
75
+ .where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, promoted_member_ids)));
76
+ for (const { previous_verification_type, user_id, } of promoted_members) {
77
+ await insertActivity(tx, {
78
+ action: "member.promoted",
79
+ actor: { type: "app", job: "domain.promote_members" },
80
+ app,
81
+ cause_activity_id: activity_id,
82
+ context: {
83
+ inputs: { previous_verification_type },
84
+ outcome: { verification_type: LinkEnum.enum.domain },
85
+ },
86
+ organization_id,
87
+ user_id,
88
+ });
89
+ }
90
+ }
91
+ return {
92
+ kind: "domain_verified",
93
+ activity_id,
94
+ email_domain: {
95
+ id: email_domain.id,
96
+ verification_type: domain_verification_type,
97
+ },
98
+ promoted_members,
99
+ replaced_verification_types,
100
+ };
101
+ });
102
+ };
103
+ }
package/dist/index.d.ts CHANGED
@@ -1,33 +1,4 @@
1
- import * as _proconnect_gouv_proconnect_identite_types from '@proconnect-gouv/proconnect.identite/types';
2
- import * as schema from '@proconnect-gouv/proconnect.identite.database/drizzle';
3
- import { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":["../src/database.ts","../src/index.ts"],"mappings":";;;;AAOM,KAAM,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,SAAS,MAAM;;ACEzE,iBAAgB,qBAAqB;QAAe,gBAAgB","names":[]}
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
- import { email_domains, users_organizations } from '@proconnect-gouv/proconnect.identite.database/drizzle';
2
- import { getMemberIdsPromotedByDomain } from '@proconnect-gouv/proconnect.identite/services/organization';
3
- import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, LinkEnum } from '@proconnect-gouv/proconnect.identite/types';
4
- import { and, eq, inArray, sql } from 'drizzle-orm';
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,2 @@
1
+ export * from "./insert-activity.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ //
2
+ export * from "./insert-activity.js";
@@ -0,0 +1,8 @@
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"> & {
4
+ cause_activity_id?: number;
5
+ }): Promise<{
6
+ activity_id: number;
7
+ }>;
8
+ //# 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,GAAG;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE;;GAQzE"}
@@ -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,30 @@
1
+ import * as z from "zod";
2
+ export declare const membershipActivities: {
3
+ "member.promoted": z.ZodObject<{
4
+ inputs: z.ZodObject<{
5
+ previous_verification_type: z.ZodString;
6
+ }, z.core.$strip>;
7
+ outcome: z.ZodObject<{
8
+ verification_type: z.ZodEnum<{
9
+ domain: "domain";
10
+ organization_dirigeant: "organization_dirigeant";
11
+ code_sent_to_official_contact_email: "code_sent_to_official_contact_email";
12
+ imported_from_coop_mediation_numerique: "imported_from_coop_mediation_numerique";
13
+ imported_from_inclusion_connect: "imported_from_inclusion_connect";
14
+ in_liste_dirigeants_rna: "in_liste_dirigeants_rna";
15
+ in_liste_dirigeants_rne: "in_liste_dirigeants_rne";
16
+ official_contact_email: "official_contact_email";
17
+ ordre_professionnel_domain: "ordre_professionnel_domain";
18
+ proof_received: "proof_received";
19
+ verified_by_coop_mediation_numerique: "verified_by_coop_mediation_numerique";
20
+ bypassed: "bypassed";
21
+ domain_not_verified_yet: "domain_not_verified_yet";
22
+ no_validation_means_available: "no_validation_means_available";
23
+ no_verification_means_for_entreprise_unipersonnelle: "no_verification_means_for_entreprise_unipersonnelle";
24
+ no_verification_means_for_small_association: "no_verification_means_for_small_association";
25
+ no_verification_means_for_small_organization: "no_verification_means_for_small_organization";
26
+ }>;
27
+ }, z.core.$strip>;
28
+ }, z.core.$strip>;
29
+ };
30
+ //# sourceMappingURL=activities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/memberships/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAShC,CAAC"}
@@ -0,0 +1,14 @@
1
+ //
2
+ import { LinkEnum } from "@proconnect-gouv/proconnect.identite/types";
3
+ import * as z from "zod";
4
+ //
5
+ export const membershipActivities = {
6
+ "member.promoted": z.object({
7
+ inputs: z.object({
8
+ previous_verification_type: z.string(),
9
+ }),
10
+ outcome: z.object({
11
+ verification_type: LinkEnum,
12
+ }),
13
+ }),
14
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./activities.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memberships/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ //
2
+ export * from "./activities.js";
@@ -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