@proconnect-gouv/proconnect.identite 10.5.0 → 11.0.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 +6 -0
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -2
- package/dist/repositories/oidc-client/index.d.ts +1 -1
- package/dist/repositories/oidc-client/index.d.ts.map +1 -1
- package/dist/repositories/oidc-client/index.js +1 -1
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +3 -0
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -0
- package/dist/repositories/oidc-client/upsert-authorization-request.js +30 -0
- package/dist/types/authorization-request.d.ts +20 -0
- package/dist/types/authorization-request.d.ts.map +1 -0
- package/dist/types/authorization-request.js +2 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/src/connectors/index.ts +2 -2
- package/src/repositories/oidc-client/index.ts +1 -1
- package/src/repositories/oidc-client/upsert-authorization-request.test.ts +95 -0
- package/src/repositories/oidc-client/upsert-authorization-request.ts +50 -0
- package/src/types/authorization-request.ts +23 -0
- package/src/types/index.ts +1 -1
- package/testing/index.ts +2 -0
- package/dist/repositories/oidc-client/add-connection.d.ts +0 -3
- package/dist/repositories/oidc-client/add-connection.d.ts.map +0 -1
- package/dist/repositories/oidc-client/add-connection.js +0 -22
- package/dist/types/connection.d.ts +0 -13
- package/dist/types/connection.d.ts.map +0 -1
- package/dist/types/connection.js +0 -2
- package/src/repositories/oidc-client/add-connection.test.ts +0 -43
- package/src/repositories/oidc-client/add-connection.ts +0 -36
- package/src/types/connection.ts +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 11.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#2345](https://github.com/proconnect-gouv/proconnect-identite/pull/2345) [`434653c`](https://github.com/proconnect-gouv/proconnect-identite/commit/434653cb36cc334edf2bdf81df47fe4904f4c6cc) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ajout des colonnes interaction_cid et outcome à users_oidc_clients, avec un index unique partiel sur interaction_cid ; addConnection devient upsertAuthorizationRequest (met à jour la ligne d'une même interaction au lieu d'en ajouter une), les types Connection et BaseConnection deviennent AuthorizationRequest et BaseAuthorizationRequest avec interaction_cid et outcome obligatoires ; AuthorizationRequestOutcomeEnum (zod) partage les valeurs de outcome
|
|
8
|
+
|
|
3
9
|
## 10.5.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -518,8 +518,8 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
|
|
|
518
518
|
}>;
|
|
519
519
|
};
|
|
520
520
|
oidc_clients: {
|
|
521
|
-
addConnection: ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, }: import("../types/connection.js").BaseConnection) => Promise<import("../types/connection.js").Connection>;
|
|
522
521
|
findByClientId: (client_id: string) => Promise<import("../types/oidc-client.js").OidcClient | undefined>;
|
|
522
|
+
upsertAuthorizationRequest: ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }: import("../types/authorization-request.js").BaseAuthorizationRequest) => Promise<import("../types/authorization-request.js").AuthorizationRequest>;
|
|
523
523
|
};
|
|
524
524
|
organizations: {
|
|
525
525
|
findById: (id: number) => Promise<import("../types/organization.js").Organization | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AAsEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8JP;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
package/dist/connectors/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { addDomainFactory, deleteEmailDomainsByVerificationTypesFactory, findEma
|
|
|
5
5
|
import { deleteFranceconnectUserinfoFactory, findFranceconnectUserinfoFactory, upsertFranceconnectUserinfoFactory, } from "#src/repositories/franceconnect_userinfo";
|
|
6
6
|
import { createModerationFactory, deleteModerationFactory, findModerationByIdFactory, findPendingModerationFactory, findRejectedModerationFactory, getModerationByIdFactory, reopenModerationFactory, } from "#src/repositories/moderation";
|
|
7
7
|
import { deleteOfficialContactEmailVerificationFactory, findOfficialContactEmailVerificationFactory, upsertOfficialContactEmailVerificationFactory, } from "#src/repositories/official-contact-email-verification";
|
|
8
|
-
import {
|
|
8
|
+
import { findByClientIdFactory, upsertAuthorizationRequestFactory, } from "#src/repositories/oidc-client";
|
|
9
9
|
import { findBySiretFactory, findByUserIdFactory, findByVerifiedEmailDomainFactory, findOrganizationByIdFactory, findPendingByUserIdFactory, findUsersByOrganizationFactory, getOrganizationByIdFactory, upsertFactory, } from "#src/repositories/organization";
|
|
10
10
|
import { createRecoveryWordsFactory, deleteRecoveryWordsByUserIdFactory, findRecoveryWordsByUserIdFactory, } from "#src/repositories/recovery-words";
|
|
11
11
|
import { createUserFactory, deleteUserFactory, findByEmailFactory, findByMagicLinkTokenFactory, findByResetPasswordTokenFactory, findByIdFactory as findUserByIdFactory, getByIdFactory, updateUserFactory, } from "#src/repositories/user";
|
|
@@ -50,8 +50,8 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
|
|
|
50
50
|
upsert: upsertOfficialContactEmailVerificationFactory({ pg }),
|
|
51
51
|
},
|
|
52
52
|
oidc_clients: {
|
|
53
|
-
addConnection: addConnectionFactory({ pg }),
|
|
54
53
|
findByClientId: findByClientIdFactory({ pg }),
|
|
54
|
+
upsertAuthorizationRequest: upsertAuthorizationRequestFactory({ pg }),
|
|
55
55
|
},
|
|
56
56
|
organizations: {
|
|
57
57
|
findById: findOrganizationByIdFactory({ pg }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/index.ts"],"names":[],"mappings":"AAEA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/index.ts"],"names":[],"mappings":"AAEA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AuthorizationRequest, BaseAuthorizationRequest, DatabaseContext } from "#src/types";
|
|
2
|
+
export declare function upsertAuthorizationRequestFactory({ pg }: DatabaseContext): ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }: BaseAuthorizationRequest) => Promise<AuthorizationRequest>;
|
|
3
|
+
//# sourceMappingURL=upsert-authorization-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsert-authorization-request.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/upsert-authorization-request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EAChB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,mGAQ9C,wBAAwB,mCA6B5B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
import {} from "pg";
|
|
3
|
+
//
|
|
4
|
+
export function upsertAuthorizationRequestFactory({ pg }) {
|
|
5
|
+
return async function upsertAuthorizationRequest({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }) {
|
|
6
|
+
const { rows } = await pg.query(`
|
|
7
|
+
INSERT INTO users_oidc_clients
|
|
8
|
+
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
|
|
9
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
10
|
+
ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
|
|
11
|
+
DO UPDATE SET
|
|
12
|
+
organization_id = EXCLUDED.organization_id,
|
|
13
|
+
outcome = EXCLUDED.outcome,
|
|
14
|
+
updated_at = EXCLUDED.updated_at,
|
|
15
|
+
user_id = EXCLUDED.user_id
|
|
16
|
+
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
|
|
17
|
+
`, [
|
|
18
|
+
user_id,
|
|
19
|
+
oidc_client_id,
|
|
20
|
+
organization_id,
|
|
21
|
+
sp_name,
|
|
22
|
+
user_ip_address,
|
|
23
|
+
new Date(),
|
|
24
|
+
new Date(),
|
|
25
|
+
interaction_cid,
|
|
26
|
+
outcome,
|
|
27
|
+
]);
|
|
28
|
+
return rows.shift();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AuthorizationRequestOutcomeEnum: z.ZodEnum<{
|
|
3
|
+
succeeded: "succeeded";
|
|
4
|
+
}>;
|
|
5
|
+
export type AuthorizationRequestOutcome = z.output<typeof AuthorizationRequestOutcomeEnum>;
|
|
6
|
+
export interface BaseAuthorizationRequest {
|
|
7
|
+
user_id: number;
|
|
8
|
+
oidc_client_id: number;
|
|
9
|
+
organization_id: number | null;
|
|
10
|
+
sp_name: string | null;
|
|
11
|
+
user_ip_address: string | null;
|
|
12
|
+
interaction_cid: string | null;
|
|
13
|
+
outcome: AuthorizationRequestOutcome | null;
|
|
14
|
+
}
|
|
15
|
+
export interface AuthorizationRequest extends BaseAuthorizationRequest {
|
|
16
|
+
id: number;
|
|
17
|
+
created_at: Date;
|
|
18
|
+
updated_at: Date;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=authorization-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request.d.ts","sourceRoot":"","sources":["../../src/types/authorization-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,+BAA+B;;EAAwB,CAAC;AAErE,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAChD,OAAO,+BAA+B,CACvC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,2BAA2B,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0CAA0C,CAAC;AACzD,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC"}
|
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
package/src/connectors/index.ts
CHANGED
|
@@ -33,8 +33,8 @@ import {
|
|
|
33
33
|
upsertOfficialContactEmailVerificationFactory,
|
|
34
34
|
} from "#src/repositories/official-contact-email-verification";
|
|
35
35
|
import {
|
|
36
|
-
addConnectionFactory,
|
|
37
36
|
findByClientIdFactory,
|
|
37
|
+
upsertAuthorizationRequestFactory,
|
|
38
38
|
} from "#src/repositories/oidc-client";
|
|
39
39
|
import {
|
|
40
40
|
findBySiretFactory,
|
|
@@ -126,8 +126,8 @@ export function createContext({
|
|
|
126
126
|
upsert: upsertOfficialContactEmailVerificationFactory({ pg }),
|
|
127
127
|
},
|
|
128
128
|
oidc_clients: {
|
|
129
|
-
addConnection: addConnectionFactory({ pg }),
|
|
130
129
|
findByClientId: findByClientIdFactory({ pg }),
|
|
130
|
+
upsertAuthorizationRequest: upsertAuthorizationRequestFactory({ pg }),
|
|
131
131
|
},
|
|
132
132
|
organizations: {
|
|
133
133
|
findById: findOrganizationByIdFactory({ pg }),
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { upsertAuthorizationRequestFactory } from "./upsert-authorization-request.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const upsertAuthorizationRequest = upsertAuthorizationRequestFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
suite("upsertAuthorizationRequestFactory", () => {
|
|
15
|
+
before(migrate);
|
|
16
|
+
beforeEach(emptyDatabase);
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO users
|
|
20
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
21
|
+
VALUES
|
|
22
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO oidc_clients
|
|
27
|
+
(id, client_id, client_name, client_secret, created_at, updated_at)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, '⚔️', 'Dark Angels', 'secret', '4444-04-04', '4444-04-04')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("should insert and return the authorization request", async () => {
|
|
35
|
+
const authorizationRequest = await upsertAuthorizationRequest({
|
|
36
|
+
user_id: 1,
|
|
37
|
+
oidc_client_id: 1,
|
|
38
|
+
organization_id: null,
|
|
39
|
+
sp_name: "proconnect",
|
|
40
|
+
user_ip_address: "127.0.0.1",
|
|
41
|
+
interaction_cid: "Rex5_Tq4tBqqwz0xPTJyd",
|
|
42
|
+
outcome: "succeeded",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
assert.equal(authorizationRequest.user_id, 1);
|
|
46
|
+
assert.equal(authorizationRequest.oidc_client_id, 1);
|
|
47
|
+
assert.equal(authorizationRequest.interaction_cid, "Rex5_Tq4tBqqwz0xPTJyd");
|
|
48
|
+
assert.equal(authorizationRequest.outcome, "succeeded");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("should update the authorization request of the same interaction", async () => {
|
|
52
|
+
const request = {
|
|
53
|
+
user_id: 1,
|
|
54
|
+
oidc_client_id: 1,
|
|
55
|
+
organization_id: null,
|
|
56
|
+
sp_name: null,
|
|
57
|
+
user_ip_address: null,
|
|
58
|
+
};
|
|
59
|
+
await upsertAuthorizationRequest({
|
|
60
|
+
...request,
|
|
61
|
+
interaction_cid: "caliban",
|
|
62
|
+
outcome: null,
|
|
63
|
+
});
|
|
64
|
+
await upsertAuthorizationRequest({
|
|
65
|
+
...request,
|
|
66
|
+
interaction_cid: "fallen",
|
|
67
|
+
outcome: null,
|
|
68
|
+
});
|
|
69
|
+
await upsertAuthorizationRequest({
|
|
70
|
+
...request,
|
|
71
|
+
interaction_cid: "caliban",
|
|
72
|
+
outcome: "succeeded",
|
|
73
|
+
});
|
|
74
|
+
await upsertAuthorizationRequest({
|
|
75
|
+
...request,
|
|
76
|
+
interaction_cid: null,
|
|
77
|
+
outcome: "succeeded",
|
|
78
|
+
});
|
|
79
|
+
await upsertAuthorizationRequest({
|
|
80
|
+
...request,
|
|
81
|
+
interaction_cid: null,
|
|
82
|
+
outcome: "succeeded",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const { rows } = await pg.query(
|
|
86
|
+
"SELECT interaction_cid, outcome FROM users_oidc_clients ORDER BY id",
|
|
87
|
+
);
|
|
88
|
+
assert.deepEqual(rows, [
|
|
89
|
+
{ interaction_cid: "caliban", outcome: "succeeded" },
|
|
90
|
+
{ interaction_cid: "fallen", outcome: null },
|
|
91
|
+
{ interaction_cid: null, outcome: "succeeded" },
|
|
92
|
+
{ interaction_cid: null, outcome: "succeeded" },
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AuthorizationRequest,
|
|
5
|
+
BaseAuthorizationRequest,
|
|
6
|
+
DatabaseContext,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import { type QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function upsertAuthorizationRequestFactory({ pg }: DatabaseContext) {
|
|
13
|
+
return async function upsertAuthorizationRequest({
|
|
14
|
+
user_id,
|
|
15
|
+
oidc_client_id,
|
|
16
|
+
organization_id,
|
|
17
|
+
sp_name,
|
|
18
|
+
user_ip_address,
|
|
19
|
+
interaction_cid,
|
|
20
|
+
outcome,
|
|
21
|
+
}: BaseAuthorizationRequest) {
|
|
22
|
+
const { rows }: QueryResult<AuthorizationRequest> = await pg.query(
|
|
23
|
+
`
|
|
24
|
+
INSERT INTO users_oidc_clients
|
|
25
|
+
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
|
|
26
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
27
|
+
ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
|
|
28
|
+
DO UPDATE SET
|
|
29
|
+
organization_id = EXCLUDED.organization_id,
|
|
30
|
+
outcome = EXCLUDED.outcome,
|
|
31
|
+
updated_at = EXCLUDED.updated_at,
|
|
32
|
+
user_id = EXCLUDED.user_id
|
|
33
|
+
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
|
|
34
|
+
`,
|
|
35
|
+
[
|
|
36
|
+
user_id,
|
|
37
|
+
oidc_client_id,
|
|
38
|
+
organization_id,
|
|
39
|
+
sp_name,
|
|
40
|
+
user_ip_address,
|
|
41
|
+
new Date(),
|
|
42
|
+
new Date(),
|
|
43
|
+
interaction_cid,
|
|
44
|
+
outcome,
|
|
45
|
+
],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return rows.shift()!;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const AuthorizationRequestOutcomeEnum = z.enum(["succeeded"]);
|
|
4
|
+
|
|
5
|
+
export type AuthorizationRequestOutcome = z.output<
|
|
6
|
+
typeof AuthorizationRequestOutcomeEnum
|
|
7
|
+
>;
|
|
8
|
+
|
|
9
|
+
export interface BaseAuthorizationRequest {
|
|
10
|
+
user_id: number;
|
|
11
|
+
oidc_client_id: number;
|
|
12
|
+
organization_id: number | null;
|
|
13
|
+
sp_name: string | null;
|
|
14
|
+
user_ip_address: string | null;
|
|
15
|
+
interaction_cid: string | null;
|
|
16
|
+
outcome: AuthorizationRequestOutcome | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AuthorizationRequest extends BaseAuthorizationRequest {
|
|
20
|
+
id: number;
|
|
21
|
+
created_at: Date;
|
|
22
|
+
updated_at: Date;
|
|
23
|
+
}
|
package/src/types/index.ts
CHANGED
package/testing/index.ts
CHANGED
|
@@ -39,6 +39,8 @@ export async function emptyDatabase() {
|
|
|
39
39
|
await pg.sql`ALTER SEQUENCE users_id_seq RESTART WITH 1`;
|
|
40
40
|
await pg.sql`delete from email_domains;`;
|
|
41
41
|
await pg.sql`ALTER SEQUENCE email_domains_id_seq RESTART WITH 1`;
|
|
42
|
+
await pg.sql`delete from oidc_clients;`;
|
|
43
|
+
await pg.sql`ALTER SEQUENCE oidc_clients_id_seq RESTART WITH 1`;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
//
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { BaseConnection, Connection, DatabaseContext } from "#src/types";
|
|
2
|
-
export declare function addConnectionFactory({ pg }: DatabaseContext): ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, }: BaseConnection) => Promise<Connection>;
|
|
3
|
-
//# sourceMappingURL=add-connection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-connection.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/add-connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAK9E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,yEAMjC,cAAc,yBAqBlB"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {} from "pg";
|
|
3
|
-
//
|
|
4
|
-
export function addConnectionFactory({ pg }) {
|
|
5
|
-
return async function addConnection({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, }) {
|
|
6
|
-
const { rows } = await pg.query(`
|
|
7
|
-
INSERT INTO users_oidc_clients
|
|
8
|
-
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at)
|
|
9
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
10
|
-
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id;
|
|
11
|
-
`, [
|
|
12
|
-
user_id,
|
|
13
|
-
oidc_client_id,
|
|
14
|
-
organization_id,
|
|
15
|
-
sp_name,
|
|
16
|
-
user_ip_address,
|
|
17
|
-
new Date(),
|
|
18
|
-
new Date(),
|
|
19
|
-
]);
|
|
20
|
-
return rows.shift();
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface BaseConnection {
|
|
2
|
-
user_id: number;
|
|
3
|
-
oidc_client_id: number;
|
|
4
|
-
organization_id: number | null;
|
|
5
|
-
sp_name: string | null;
|
|
6
|
-
user_ip_address: string | null;
|
|
7
|
-
}
|
|
8
|
-
export interface Connection extends BaseConnection {
|
|
9
|
-
id: number;
|
|
10
|
-
created_at: Date;
|
|
11
|
-
updated_at: Date;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/types/connection.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
package/dist/types/connection.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
-
import { addConnectionFactory } from "./add-connection.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const addConnection = addConnectionFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("addConnectionFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should insert and return the connection", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO users
|
|
19
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
20
|
-
VALUES
|
|
21
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
await pg.sql`
|
|
25
|
-
INSERT INTO oidc_clients
|
|
26
|
-
(id, client_id, client_name, client_secret, created_at, updated_at)
|
|
27
|
-
VALUES
|
|
28
|
-
(1, '⚔️', 'Dark Angels', 'secret', '4444-04-04', '4444-04-04')
|
|
29
|
-
;
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const connection = await addConnection({
|
|
33
|
-
user_id: 1,
|
|
34
|
-
oidc_client_id: 1,
|
|
35
|
-
organization_id: null,
|
|
36
|
-
sp_name: "proconnect",
|
|
37
|
-
user_ip_address: "127.0.0.1",
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
assert.equal(connection.user_id, 1);
|
|
41
|
-
assert.equal(connection.oidc_client_id, 1);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { BaseConnection, Connection, DatabaseContext } from "#src/types";
|
|
4
|
-
import { type QueryResult } from "pg";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export function addConnectionFactory({ pg }: DatabaseContext) {
|
|
9
|
-
return async function addConnection({
|
|
10
|
-
user_id,
|
|
11
|
-
oidc_client_id,
|
|
12
|
-
organization_id,
|
|
13
|
-
sp_name,
|
|
14
|
-
user_ip_address,
|
|
15
|
-
}: BaseConnection) {
|
|
16
|
-
const { rows }: QueryResult<Connection> = await pg.query(
|
|
17
|
-
`
|
|
18
|
-
INSERT INTO users_oidc_clients
|
|
19
|
-
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at)
|
|
20
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
21
|
-
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id;
|
|
22
|
-
`,
|
|
23
|
-
[
|
|
24
|
-
user_id,
|
|
25
|
-
oidc_client_id,
|
|
26
|
-
organization_id,
|
|
27
|
-
sp_name,
|
|
28
|
-
user_ip_address,
|
|
29
|
-
new Date(),
|
|
30
|
-
new Date(),
|
|
31
|
-
],
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
return rows.shift()!;
|
|
35
|
-
};
|
|
36
|
-
}
|
package/src/types/connection.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
export interface BaseConnection {
|
|
4
|
-
user_id: number;
|
|
5
|
-
oidc_client_id: number;
|
|
6
|
-
organization_id: number | null;
|
|
7
|
-
sp_name: string | null;
|
|
8
|
-
user_ip_address: string | null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface Connection extends BaseConnection {
|
|
12
|
-
id: number;
|
|
13
|
-
created_at: Date;
|
|
14
|
-
updated_at: Date;
|
|
15
|
-
}
|