@friggframework/core 2.0.0--canary.681.d970b9e.0 → 2.0.0--canary.681.ce2a674.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.681.d970b9e.0",
4
+ "version": "2.0.0--canary.681.ce2a674.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -48,9 +48,9 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "@friggframework/eslint-config": "2.0.0--canary.681.d970b9e.0",
52
- "@friggframework/prettier-config": "2.0.0--canary.681.d970b9e.0",
53
- "@friggframework/test": "2.0.0--canary.681.d970b9e.0",
51
+ "@friggframework/eslint-config": "2.0.0--canary.681.ce2a674.0",
52
+ "@friggframework/prettier-config": "2.0.0--canary.681.ce2a674.0",
53
+ "@friggframework/test": "2.0.0--canary.681.ce2a674.0",
54
54
  "@prisma/client": "^6.19.3",
55
55
  "@types/lodash": "4.17.15",
56
56
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -90,5 +90,5 @@
90
90
  "publishConfig": {
91
91
  "access": "public"
92
92
  },
93
- "gitHead": "d970b9e1776a2ec45a07e08a527bf5c02c248461"
93
+ "gitHead": "ce2a674fe0f71a495778aa93bdf0ed8619419bad"
94
94
  }
@@ -3,11 +3,17 @@ const {
3
3
  findAppUsers,
4
4
  createMissingAppUsers,
5
5
  buildUser,
6
+ wantsIndividual,
6
7
  } = require('../app-user-helpers');
7
8
  const { getLogger } = require('../../logs');
8
9
 
9
10
  const log = getLogger('frigg.user.x_frigg_headers');
10
11
 
12
+ const NOT_A_MEMBER_MESSAGE =
13
+ 'Not a member: the user identified by x-frigg-appUserId is not a member of the ' +
14
+ 'organization identified by x-frigg-appOrgId, and strict membership does not ' +
15
+ 'allow these headers to add them.';
16
+
11
17
  /**
12
18
  * Use case for retrieving or creating a user from x-frigg header identifiers.
13
19
  * Supports backend-to-backend API communication using application user IDs.
@@ -80,6 +86,18 @@ class GetUserFromXFriggHeaders {
80
86
  // exempt, since it has no members to disagree with.
81
87
  const refuseNewMembers = this.strict && Boolean(organizationUserData);
82
88
 
89
+ // A person who does not exist yet cannot already be a member, so refuse
90
+ // now, before anything is persisted: refusing after creating them would
91
+ // leave an orphan individual behind on every refused request.
92
+ if (
93
+ refuseNewMembers &&
94
+ appUserId &&
95
+ wantsIndividual(this.userConfig) &&
96
+ !individualUserData
97
+ ) {
98
+ throw Boom.badRequest(NOT_A_MEMBER_MESSAGE);
99
+ }
100
+
83
101
  // Auto-create users independently if they don't exist and are required
84
102
  const created = await createMissingAppUsers(
85
103
  this.userRepository,
@@ -102,11 +120,7 @@ class GetUserFromXFriggHeaders {
102
120
  requireExisting: refuseNewMembers,
103
121
  });
104
122
  if (refuseNewMembers && individualUserData && !ensured.membership) {
105
- throw Boom.badRequest(
106
- 'Not a member: the user identified by x-frigg-appUserId is not a member of the ' +
107
- 'organization identified by x-frigg-appOrgId, and strict membership does not ' +
108
- 'allow these headers to add them.'
109
- );
123
+ throw Boom.badRequest(NOT_A_MEMBER_MESSAGE);
110
124
  }
111
125
  individualUserData = ensured.individual;
112
126