From 470346903a2573c95033c14e27daa1f54f1ef0e7 Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Wed, 29 Nov 2023 12:38:45 +0100 Subject: [PATCH 1/4] fix(enmeshed): Fix endpoints to reenable user journey --- .../internals/server/enmeshed-middleware.ts | 95 +++++++++++-------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/packages/server/src/internals/server/enmeshed-middleware.ts b/packages/server/src/internals/server/enmeshed-middleware.ts index 74a67d987..a0ccc57d6 100644 --- a/packages/server/src/internals/server/enmeshed-middleware.ts +++ b/packages/server/src/internals/server/enmeshed-middleware.ts @@ -59,7 +59,7 @@ export function applyEnmeshedMiddleware({ return `${basePath}/init` } -const EventBody = t.type({ +const GenericEventBody = t.type({ trigger: t.string, }) @@ -80,9 +80,24 @@ const Relationship = t.type({ type Relationship = t.TypeOf -const RelationshipChangedEventBody = t.type({ - data: Relationship, - trigger: t.literal('transport.relationshipChanged'), +const Attribute = t.type({ + id: t.string, + content: t.type({ + '@type': t.union([ + t.literal('IdentityAttribute'), + t.literal('RelationshipAttribute'), + ]), + owner: t.string, + value: t.unknown, + }), +}) + +const EventBody = t.type({ + data: t.union([Relationship, Attribute]), + trigger: t.union([ + t.literal('transport.relationshipChanged'), + t.literal('consumption.attributeCreated'), + ]), }) const Session = t.intersection([ @@ -397,62 +412,68 @@ function createEnmeshedWebhookMiddleware( const body = req.body as unknown - if (!EventBody.is(body)) { + if (!GenericEventBody.is(body)) { res.status(400).send('Illegal trigger body') return } - if (body.trigger !== 'transport.relationshipChanged') { + if ( + body.trigger !== 'transport.relationshipChanged' && + body.trigger !== 'consumption.attributeCreated' + ) { res.sendStatus(200) return } - if (!RelationshipChangedEventBody.is(body)) { + if (!EventBody.is(body)) { captureErrorEvent({ - error: new Error('Illegal body for relationship change event'), + error: new Error('Illegal body event'), errorContext: { body, route: '/enmeshed/webhook' }, }) res.status(400).send('Illegal trigger body') return } - const relationship = body.data - - const sessionId = - relationship.template.content?.onNewRelationship?.metadata?.sessionId ?? - null - - for (const change of relationship.changes) { - if ( - [ConnectorRelationshipChangeType.CREATION as string].includes( - change.type, - ) && - [ - ConnectorRelationshipChangeStatus.PENDING as string, - ConnectorRelationshipChangeStatus.REJECTED as string, - ].includes(change.status) - ) { - await acceptRelationshipRequest(relationship, change, client) - if (!sessionId) { - await sendWelcomeMessage({ relationship, client }) - await sendAttributesChangeRequest({ relationship, client }) + const data = body.data + + if (Relationship.is(data)) { + const sessionId = + data.template.content?.onNewRelationship?.metadata?.sessionId ?? null + + for (const change of data.changes) { + if ( + [ConnectorRelationshipChangeType.CREATION as string].includes( + change.type, + ) && + [ + ConnectorRelationshipChangeStatus.PENDING as string, + ConnectorRelationshipChangeStatus.REJECTED as string, + ].includes(change.status) + ) { + await acceptRelationshipRequest(data, change, client) + if (!sessionId) { + await sendWelcomeMessage({ relationship: data, client }) + await sendAttributesChangeRequest({ relationship: data, client }) + } } } - } - // FIXME: Uncomment next line when prototype frontend has been replaced - // if (!sessionId) return validationError(res, 'Missing required parameter: sessionId.') - const session = await getSession(cache, sessionId) + // FIXME: Uncomment next line when prototype frontend has been replaced + // if (!sessionId) return validationError(res, 'Missing required parameter: sessionId.') + const session = await getSession(cache, sessionId) - if (session) { - await setSession(cache, sessionId, { - relationshipTemplateId: relationship.template.id, - content: relationship.template.content as Session['content'], - }) + if (session) { + await setSession(cache, sessionId, { + relationshipTemplateId: data.template.id, + enmeshedId: data.peer, + content: data.template.content as Session['content'], + }) + } } res.status(200).end('') } + return (request, response) => { handleRequest(request, response).catch((error: Error) => { captureErrorEvent({ From a5deb39038fa55ce9167b9fe70a71211258e8c9d Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Wed, 29 Nov 2023 12:41:47 +0100 Subject: [PATCH 2/4] Release version 0.58.2-staging.0 --- lerna.json | 6 ++++-- packages/authorization/package.json | 4 ++-- packages/server/package.json | 4 ++-- packages/types/package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lerna.json b/lerna.json index c3c02cc39..819354822 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,8 @@ { - "packages": ["packages/*"], + "packages": [ + "packages/*" + ], "npmClient": "yarn", - "version": "0.58.1", + "version": "0.58.2-staging.0", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/authorization/package.json b/packages/authorization/package.json index 79eaf906c..d105d6d00 100644 --- a/packages/authorization/package.json +++ b/packages/authorization/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/authorization", - "version": "0.58.0", + "version": "0.58.2-staging.0", "repository": "serlo/api.serlo.org", "license": "Apache-2.0", "author": "Serlo Education e.V.", @@ -11,7 +11,7 @@ "build": "tsdx build --tsconfig tsconfig.prod.json" }, "dependencies": { - "@serlo/api": "^0.58.0" + "@serlo/api": "^0.58.2-staging.0" }, "publishConfig": { "access": "public" diff --git a/packages/server/package.json b/packages/server/package.json index 73d79c434..58194c93e 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/api.serlo.org", - "version": "0.58.1", + "version": "0.58.2-staging.0", "private": true, "repository": "serlo/api.serlo.org", "license": "Apache-2.0", @@ -31,7 +31,7 @@ "@nmshd/connector-sdk": "^2.2.4", "@ory/client": "^1.4.3", "@sentry/node": "^7.82.0", - "@serlo/authorization": "^0.58.0", + "@serlo/authorization": "^0.58.2-staging.0", "@types/basic-auth": "^1.1.6", "@types/bull-arena": "^3.0.10", "@types/graphql-modules": "^0.58.0", diff --git a/packages/types/package.json b/packages/types/package.json index ef457c2b8..336342ef6 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/api", - "version": "0.58.0", + "version": "0.58.2-staging.0", "repository": "serlo/api.serlo.org", "license": "Apache-2.0", "author": "Serlo Education e.V.", diff --git a/yarn.lock b/yarn.lock index a2c1cf221..704f60cfa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4096,7 +4096,7 @@ __metadata: "@nmshd/connector-sdk": ^2.2.4 "@ory/client": ^1.4.3 "@sentry/node": ^7.82.0 - "@serlo/authorization": ^0.58.0 + "@serlo/authorization": ^0.58.2-staging.0 "@types/basic-auth": ^1.1.6 "@types/bull-arena": ^3.0.10 "@types/graphql-modules": ^0.58.0 @@ -4138,7 +4138,7 @@ __metadata: languageName: unknown linkType: soft -"@serlo/api@^0.58.0, @serlo/api@workspace:packages/types": +"@serlo/api@^0.58.2-staging.0, @serlo/api@workspace:packages/types": version: 0.0.0-use.local resolution: "@serlo/api@workspace:packages/types" dependencies: @@ -4149,11 +4149,11 @@ __metadata: languageName: unknown linkType: soft -"@serlo/authorization@^0.58.0, @serlo/authorization@workspace:packages/authorization": +"@serlo/authorization@^0.58.2-staging.0, @serlo/authorization@workspace:packages/authorization": version: 0.0.0-use.local resolution: "@serlo/authorization@workspace:packages/authorization" dependencies: - "@serlo/api": ^0.58.0 + "@serlo/api": ^0.58.2-staging.0 languageName: unknown linkType: soft From 8465e9ea7c7e350fb48820f6e317a3a91031461e Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Thu, 30 Nov 2023 17:21:12 +0100 Subject: [PATCH 3/4] Release 0.59.1-staging.0 --- lerna.json | 2 +- packages/authorization/package.json | 4 ++-- packages/graphql-modules/package.json | 2 +- packages/server/package.json | 6 +++--- packages/types/package.json | 2 +- yarn.lock | 12 ++++++------ 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lerna.json b/lerna.json index d6ad3ba4f..e3c4e1af1 100644 --- a/lerna.json +++ b/lerna.json @@ -3,6 +3,6 @@ "packages/*" ], "npmClient": "yarn", - "version": "0.59.0", + "version": "0.59.1-staging.0", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/authorization/package.json b/packages/authorization/package.json index 07675aa44..661ac40ef 100644 --- a/packages/authorization/package.json +++ b/packages/authorization/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/authorization", - "version": "0.59.0", + "version": "0.59.1-staging.0", "repository": "serlo/api.serlo.org", "license": "Apache-2.0", "author": "Serlo Education e.V.", @@ -11,7 +11,7 @@ "build": "tsdx build --tsconfig tsconfig.prod.json" }, "dependencies": { - "@serlo/api": "^0.59.0" + "@serlo/api": "^0.59.1-staging.0" }, "publishConfig": { "access": "public" diff --git a/packages/graphql-modules/package.json b/packages/graphql-modules/package.json index 54cb0a827..8598bb2ef 100644 --- a/packages/graphql-modules/package.json +++ b/packages/graphql-modules/package.json @@ -1,6 +1,6 @@ { "name": "@types/graphql-modules", - "version": "0.59.0", + "version": "0.59.1-staging.0", "private": true, "repository": "serlo/api.serlo.org", "license": "Apache-2.0", diff --git a/packages/server/package.json b/packages/server/package.json index cc9de29ac..93d49af31 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/api.serlo.org", - "version": "0.59.0", + "version": "0.59.1-staging.0", "private": true, "repository": "serlo/api.serlo.org", "license": "Apache-2.0", @@ -32,10 +32,10 @@ "@nmshd/connector-sdk": "^2.2.4", "@ory/client": "^1.4.3", "@sentry/node": "^7.82.0", - "@serlo/authorization": "^0.59.0", + "@serlo/authorization": "^0.59.1-staging.0", "@types/basic-auth": "^1.1.6", "@types/bull-arena": "^3.0.10", - "@types/graphql-modules": "^0.59.0", + "@types/graphql-modules": "^0.59.1-staging.0", "@types/jsonwebtoken": "^9.0.5", "@types/pg": "^8.10.9", "@types/ramda": "^0.29.9", diff --git a/packages/types/package.json b/packages/types/package.json index f3af999ac..246e99a53 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/api", - "version": "0.59.0", + "version": "0.59.1-staging.0", "repository": "serlo/api.serlo.org", "license": "Apache-2.0", "author": "Serlo Education e.V.", diff --git a/yarn.lock b/yarn.lock index 573c9076c..df10730d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4096,10 +4096,10 @@ __metadata: "@nmshd/connector-sdk": ^2.2.4 "@ory/client": ^1.4.3 "@sentry/node": ^7.82.0 - "@serlo/authorization": ^0.59.0 + "@serlo/authorization": ^0.59.1-staging.0 "@types/basic-auth": ^1.1.6 "@types/bull-arena": ^3.0.10 - "@types/graphql-modules": ^0.59.0 + "@types/graphql-modules": ^0.59.1-staging.0 "@types/jsonwebtoken": ^9.0.5 "@types/pg": ^8.10.9 "@types/ramda": ^0.29.9 @@ -4138,7 +4138,7 @@ __metadata: languageName: unknown linkType: soft -"@serlo/api@^0.59.0, @serlo/api@workspace:packages/types": +"@serlo/api@^0.59.1-staging.0, @serlo/api@workspace:packages/types": version: 0.0.0-use.local resolution: "@serlo/api@workspace:packages/types" dependencies: @@ -4149,11 +4149,11 @@ __metadata: languageName: unknown linkType: soft -"@serlo/authorization@^0.59.0, @serlo/authorization@workspace:packages/authorization": +"@serlo/authorization@^0.59.1-staging.0, @serlo/authorization@workspace:packages/authorization": version: 0.0.0-use.local resolution: "@serlo/authorization@workspace:packages/authorization" dependencies: - "@serlo/api": ^0.59.0 + "@serlo/api": ^0.59.1-staging.0 languageName: unknown linkType: soft @@ -4433,7 +4433,7 @@ __metadata: languageName: node linkType: hard -"@types/graphql-modules@^0.59.0, @types/graphql-modules@workspace:packages/graphql-modules": +"@types/graphql-modules@^0.59.1-staging.0, @types/graphql-modules@workspace:packages/graphql-modules": version: 0.0.0-use.local resolution: "@types/graphql-modules@workspace:packages/graphql-modules" languageName: unknown From fc05519cda240bbfaff2de24ab2323bc7f862473 Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Fri, 1 Dec 2023 11:22:21 +0100 Subject: [PATCH 4/4] Release version 0.59.2 --- CHANGELOG.md | 18 ++++++++++++++++++ lerna.json | 2 +- packages/authorization/package.json | 2 +- packages/server/package.json | 4 ++-- scripts/changelog.ts | 14 ++++++++++++++ yarn.lock | 4 ++-- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af322229c..96bb35cdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to this project will be documented in this file. +## [v0.59.2](https://github.com/serlo/api.serlo.org/compare/v0.59.1..v0.59.2) - December 1, 2023 + +### Fixed + +- Fix enmeshed endpoints to reenable user journey + +- Set always a ttl for each key + +### Internal + +- Add pact tests to github repo + +- Remove unnecessary test redis + +- Improve CI speed + +- Make tests run parallel + ## [v0.59.1](https://github.com/serlo/api.serlo.org/compare/v0.59.0..v0.59.1) - November 30, 2023 ### Internal diff --git a/lerna.json b/lerna.json index e3c4e1af1..e77f19db7 100644 --- a/lerna.json +++ b/lerna.json @@ -3,6 +3,6 @@ "packages/*" ], "npmClient": "yarn", - "version": "0.59.1-staging.0", + "version": "0.59.2", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/authorization/package.json b/packages/authorization/package.json index c1627343f..cd1e84c38 100644 --- a/packages/authorization/package.json +++ b/packages/authorization/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/authorization", - "version": "0.59.1-staging.0", + "version": "0.59.2", "repository": "serlo/api.serlo.org", "license": "Apache-2.0", "author": "Serlo Education e.V.", diff --git a/packages/server/package.json b/packages/server/package.json index f6463788a..82ef67fdb 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@serlo/api.serlo.org", - "version": "0.59.1-staging.0", + "version": "0.59.2", "private": true, "repository": "serlo/api.serlo.org", "license": "Apache-2.0", @@ -32,7 +32,7 @@ "@nmshd/connector-sdk": "^2.2.4", "@ory/client": "^1.4.3", "@sentry/node": "^7.82.0", - "@serlo/authorization": "^0.59.1-staging.0", + "@serlo/authorization": "^0.59.2", "@types/basic-auth": "^1.1.6", "@types/bull-arena": "^3.0.10", "@types/jsonwebtoken": "^9.0.5", diff --git a/scripts/changelog.ts b/scripts/changelog.ts index 44210caef..0da6cb8c3 100755 --- a/scripts/changelog.ts +++ b/scripts/changelog.ts @@ -1650,6 +1650,20 @@ async function exec(): Promise { date: '2023-11-30', internal: ['`@serlo/authorization`: Remove dependency of `@ſerlo/api`'], }, + { + tagName: 'v0.59.2', + date: '2023-12-01', + internal: [ + 'Add pact tests to github repo', + 'Remove unnecessary test redis', + 'Improve CI speed', + 'Make tests run parallel', + ], + fixed: [ + 'Fix enmeshed endpoints to reenable user journey', + 'Set always a ttl for each key', + ], + }, ], }) diff --git a/yarn.lock b/yarn.lock index 977f7f47b..daf1fbabd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4096,7 +4096,7 @@ __metadata: "@nmshd/connector-sdk": ^2.2.4 "@ory/client": ^1.4.3 "@sentry/node": ^7.82.0 - "@serlo/authorization": ^0.59.1-staging.0 + "@serlo/authorization": ^0.59.2 "@types/basic-auth": ^1.1.6 "@types/bull-arena": ^3.0.10 "@types/jsonwebtoken": ^9.0.5 @@ -4137,7 +4137,7 @@ __metadata: languageName: unknown linkType: soft -"@serlo/authorization@^0.59.1-staging.0, @serlo/authorization@workspace:packages/authorization": +"@serlo/authorization@^0.59.2, @serlo/authorization@workspace:packages/authorization": version: 0.0.0-use.local resolution: "@serlo/authorization@workspace:packages/authorization" languageName: unknown