@jskit-ai/auth-core 0.2.10 → 0.2.12

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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - `AuthProfileProjector.syncIdentityProfile` documents `onlyWhenChanged`, which providers pass on an ordinary request so a profile that already matches is only read; sign-in and session refresh synchronize in full.
6
+ - `normalizeAuthCapabilities` carries `features.password.selfRegister`: whether anyone may register, not only an invited person or the first account. A provider that doesn't say gets the value of `register`.
5
7
  - The register body takes `setupCode`, the first account's one-time setup code, and the capability `features.firstAccountSetupCode` says a provider is waiting for it. New message key: `jskit.auth.validation.setupCodeInvalid`.
6
8
  - Registration confirmation: the action and command `auth.register.confirm` (`POST /api/register/confirm`, body `{ token }`, answer `{ ok, email, username, message }` with a message code) confirm a registration's email from the code in its link, and `authApi.confirmRegistration()` calls it. `AuthService.confirmRegistration(input)` creates the waiting account and its session; a provider without it answers `AUTH_OPERATION_UNSUPPORTED`. The capability `features.emailConfirmationCode` says the provider takes a code that way. The register and resend answers may carry `confirmationUrl`, the link itself in development. New message keys: `jskit.auth.login.emailUnconfirmed` (refused sign-in, status 403) and `jskit.auth.validation.confirmationCodeRequired`.
7
9
  - The dev auth policy and the CSRF cookie's default decide production with the kernel's `isProductionEnv`, the check every JSKIT package now shares; what counts as production is unchanged. `./server/devAuth` no longer exports `isProductionNodeEnv(nodeEnv)`: call `isProductionEnv(env)` from `@jskit-ai/kernel/server/runtime/runtimeMode` instead.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-core",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "type": "module",
5
5
  "scripts": {
6
- "test": "node --test --test-concurrency=1"
6
+ "test": "jskit test"
7
7
  },
8
8
  "exports": {
9
9
  "./server/providers/AuthAccessProvider": "./src/server/providers/AuthAccessProvider.js",
@@ -143,6 +143,6 @@
143
143
  }
144
144
  },
145
145
  "peerDependencies": {
146
- "@jskit-ai/kernel": "0.2.10"
146
+ "@jskit-ai/kernel": "0.2.12"
147
147
  }
148
148
  }
@@ -24,9 +24,12 @@
24
24
  * identities that sign in. An auth provider without one uses noAppProfiles
25
25
  * (`@jskit-ai/auth-core/server/noAppProfiles`), which keeps none.
26
26
  * @typedef {object} AuthProfileProjector
27
- * @property {(profile: object, options?: object) => Promise<object | null>} syncIdentityProfile
27
+ * @property {(profile: object, options?: { onlyWhenChanged?: boolean }) => Promise<object | null>} syncIdentityProfile
28
28
  * Creates or updates the application's profile of a signed-in identity and answers it,
29
- * or null when the application keeps no profiles.
29
+ * or null when the application keeps no profiles. Providers synchronize in full at sign-in and
30
+ * at each session refresh; an ordinary request passes `onlyWhenChanged`, which answers an
31
+ * existing profile that already matches the identity after one read and synchronizes only a
32
+ * missing or changed one.
30
33
  * @property {(identity: object, options?: object) => Promise<object | null>} findByIdentity
31
34
  * Answers the existing profile without synchronizing it, or null when there is none.
32
35
  */
@@ -122,6 +122,9 @@ function normalizeAuthCapabilities(value = {}) {
122
122
  password: Object.freeze({
123
123
  login: normalizeBoolean(passwordSource.login),
124
124
  register: normalizeBoolean(passwordSource.register),
125
+ // Anyone may register, not only an invited person or the first account; a provider that says nothing means
126
+ // whatever register says.
127
+ selfRegister: normalizeBoolean(passwordSource.selfRegister, normalizeBoolean(passwordSource.register)),
125
128
  change: normalizeBoolean(passwordSource.change),
126
129
  methodToggle: normalizeBoolean(passwordSource.methodToggle)
127
130
  }),
@@ -286,6 +286,7 @@ const authCapabilityProviderOutputSchema = createSchema({
286
286
  const authPasswordCapabilitiesOutputSchema = createSchema({
287
287
  login: { type: "boolean", required: true },
288
288
  register: { type: "boolean", required: true },
289
+ selfRegister: { type: "boolean", required: true },
289
290
  change: { type: "boolean", required: true },
290
291
  methodToggle: { type: "boolean", required: true }
291
292
  });
@@ -56,6 +56,13 @@ test("normalizeAuthCapabilities returns one provider-neutral feature shape", ()
56
56
  assert.equal(capabilities.provider.label, "Local");
57
57
  assert.equal(capabilities.features.password.login, true);
58
58
  assert.equal(capabilities.features.password.methodToggle, false);
59
+ // Self-registration follows register unless the provider says otherwise.
60
+ assert.equal(capabilities.features.password.selfRegister, true);
61
+ assert.equal(
62
+ normalizeAuthCapabilities({ features: { password: { register: true, selfRegister: false } } }).features.password.selfRegister,
63
+ false
64
+ );
65
+ assert.equal(normalizeAuthCapabilities({ features: { password: { selfRegister: true } } }).features.password.selfRegister, true);
59
66
  assert.equal(capabilities.features.passwordRecovery.delivery, "email");
60
67
  assert.deepEqual(capabilities.features.oauthLogin.providers, [
61
68
  { id: "google", label: "Google" },