@jskit-ai/users-core 0.2.57 → 0.2.59

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Profile synchronization passes the sign-in's `invitation` on: `syncIdentityProfile(profile, { invitation })` gives it to every `afterIdentityProfileSynced` lifecycle contributor beside `profile`, `created` and `options` (null when the sign-in carries none), and keeps it out of the transaction's options, so provisioning can tell an account made from an invitation.
5
6
  - `users_core_generic_initial-collation`, a migration Knex runs just before `users_core_generic_initial` (run `npm run db:migrate`): on MySQL and MariaDB it creates `users` and `user_settings`, where they do not exist yet, in the collation of the existing tables (`users`, then `auth_local_users`) rather than the database's default, and converts one recorded in another collation when no character can be lost. It changes nothing where they match.
6
7
  - `@jskit-ai/users-core/server/usersIdentity` exports `USERS_IDENTITY_TABLES`, the users and user settings tables `UsersIdentityProvider` owns, with `createUsersIdentity`, so code outside a server (workspaces-core's `createStandaloneRoleContext`) owns the same tables through standalone resources.
7
8
  - Saving a profile picture (`POST /api/settings/profile/avatar`) answers 200 with the account's settings. The route sent the `settings.profile.avatar.upload` action's JSON:API result where its response schema, and the account settings page's upload, read the plain settings: the picture was saved and every save answered 500. The route now sends the settings the result carries (`jsonApiResultValue`); `accountProfileRoutes.test.js` proves it over HTTP.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/users-core",
3
- "version": "0.2.57",
3
+ "version": "0.2.59",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -19,10 +19,10 @@
19
19
  "./locales/en.json": "./locales/en.json"
20
20
  },
21
21
  "dependencies": {
22
- "@jskit-ai/resource-core": "0.1.220",
23
- "@jskit-ai/resource-crud-core": "0.1.222",
24
- "@jskit-ai/storage-runtime": "0.1.275",
25
- "@jskit-ai/uploads-runtime": "0.2.29",
22
+ "@jskit-ai/resource-core": "0.1.222",
23
+ "@jskit-ai/resource-crud-core": "0.1.224",
24
+ "@jskit-ai/storage-runtime": "0.1.277",
25
+ "@jskit-ai/uploads-runtime": "0.2.31",
26
26
  "json-rest-schema": "^1.0.20"
27
27
  },
28
28
  "description": "Users/account runtime plus HTTP routes for account features.",
@@ -201,10 +201,10 @@
201
201
  }
202
202
  },
203
203
  "peerDependencies": {
204
- "@jskit-ai/auth-core": "0.2.33",
205
- "@jskit-ai/database-runtime": "0.1.279",
206
- "@jskit-ai/http-runtime": "0.2.29",
207
- "@jskit-ai/kernel": "0.2.29",
208
- "@jskit-ai/resource-runtime": "0.2.43"
204
+ "@jskit-ai/auth-core": "0.2.35",
205
+ "@jskit-ai/database-runtime": "0.1.281",
206
+ "@jskit-ai/http-runtime": "0.2.31",
207
+ "@jskit-ai/kernel": "0.2.31",
208
+ "@jskit-ai/resource-runtime": "0.2.45"
209
209
  }
210
210
  }
@@ -10,9 +10,9 @@
10
10
  "./shared": "./src/shared/index.js"
11
11
  },
12
12
  "dependencies": {
13
- "@jskit-ai/crud-core": "0.2.47",
14
- "@jskit-ai/resource-crud-core": "0.1.222",
15
- "@jskit-ai/users-core": "0.2.57"
13
+ "@jskit-ai/crud-core": "0.2.49",
14
+ "@jskit-ai/resource-crud-core": "0.1.224",
15
+ "@jskit-ai/users-core": "0.2.59"
16
16
  },
17
17
  "jskit": {
18
18
  "kind": "runtime",
@@ -10,14 +10,14 @@
10
10
  "./shared": "./src/shared/index.js"
11
11
  },
12
12
  "dependencies": {
13
- "@jskit-ai/crud-core": "0.2.47",
14
- "@jskit-ai/resource-crud-core": "0.1.222",
15
- "@jskit-ai/users-core": "0.2.57",
16
- "@jskit-ai/workspaces-core": "0.2.57"
13
+ "@jskit-ai/crud-core": "0.2.49",
14
+ "@jskit-ai/resource-crud-core": "0.1.224",
15
+ "@jskit-ai/users-core": "0.2.59",
16
+ "@jskit-ai/workspaces-core": "0.2.59"
17
17
  },
18
18
  "peerDependencies": {
19
- "@jskit-ai/kernel": "0.2.29",
20
- "@jskit-ai/resource-runtime": "0.2.43"
19
+ "@jskit-ai/kernel": "0.2.31",
20
+ "@jskit-ai/resource-runtime": "0.2.45"
21
21
  },
22
22
  "jskit": {
23
23
  "kind": "runtime",
@@ -94,10 +94,12 @@ function createService({ userProfilesRepository, resolveLifecycleContributors, u
94
94
  * matches the identity is answered after one read, without that work: an ordinary request's check. A first
95
95
  * sign-in that loses its insert to the same identity's other first sign-in answers the winner's profile, so there
96
96
  * is one user either way; inside a caller's transaction (`trx`) that loss fails the caller's transaction instead.
97
+ * `invitation` is the invitation the sign-in carries, as the auth invitation context resolver resolved it (a
98
+ * registration's, or a provider sign-in's started from an invitation): the contributors receive it, or null.
97
99
  * @param {object} profileLike
98
- * @param {{ onlyWhenChanged?: boolean, trx?: object, context?: object }} [options]
100
+ * @param {{ onlyWhenChanged?: boolean, invitation?: object | null, trx?: object, context?: object }} [options]
99
101
  */
100
- async function syncIdentityProfile(profileLike, { onlyWhenChanged = false, ...options } = {}) {
102
+ async function syncIdentityProfile(profileLike, { onlyWhenChanged = false, invitation = null, ...options } = {}) {
101
103
  const normalized = buildNormalizedIdentityProfile(profileLike);
102
104
  if (onlyWhenChanged) {
103
105
  const existing = await findByIdentity(normalized, options);
@@ -115,6 +117,7 @@ function createService({ userProfilesRepository, resolveLifecycleContributors, u
115
117
  await contributor.afterIdentityProfileSynced({
116
118
  profile: synchronizedProfile,
117
119
  created,
120
+ invitation,
118
121
  options: operationOptions
119
122
  });
120
123
  }
@@ -129,6 +132,7 @@ function createService({ userProfilesRepository, resolveLifecycleContributors, u
129
132
  await contributor.afterIdentityProfileSynced({
130
133
  profile: synchronizedProfile,
131
134
  created,
135
+ invitation,
132
136
  options: operationOptions
133
137
  });
134
138
  }
@@ -231,3 +231,31 @@ test("an ordinary request's profile check (onlyWhenChanged) reads a matching pro
231
231
  await service.syncIdentityProfile(identity("Ada Lovelace"));
232
232
  assert.deepEqual(calls.splice(0), ["transaction", "find in transaction", "ensure settings", "lifecycle"]);
233
233
  });
234
+
235
+ test("the invitation a sign-in carries reaches every lifecycle contributor, kept out of the transaction's options", async () => {
236
+ const seen = [];
237
+ const stored = { id: "21", authProvider: "local", authProviderUserSid: "u-21", email: "ivy@example.com", displayName: "Ivy" };
238
+ const service = createService({
239
+ userProfilesRepository: {
240
+ async findByIdentity() { return null; },
241
+ async upsert() { return stored; },
242
+ async withTransaction(options, work) { return work({ trx: "tx", ...(options.context ? { context: options.context } : {}) }); }
243
+ },
244
+ userSettingsRepository: { async ensureForUserId() {} },
245
+ resolveLifecycleContributors: () => [{
246
+ contributorId: "test.lifecycle",
247
+ async afterIdentityProfileSynced({ invitation, options }) {
248
+ seen.push({ invitation, options });
249
+ }
250
+ }]
251
+ });
252
+ const invitation = { token: "opaque", workspaceId: "3", email: "ivy@example.com" };
253
+
254
+ await service.syncIdentityProfile(stored, { source: "workspace-invite", invitation });
255
+ await service.syncIdentityProfile(stored);
256
+
257
+ assert.deepEqual(seen, [
258
+ { invitation, options: { trx: "tx" } },
259
+ { invitation: null, options: { trx: "tx" } }
260
+ ]);
261
+ });