@tempoxyz/auth 0.0.0-pr-66.sha-8d0e9ba → 0.0.0-pr-66.sha-ad498a8

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.
@@ -35,11 +35,19 @@ export declare class ChainRequiredError extends Error {
35
35
  readonly name = "Decorator.ChainRequiredError";
36
36
  constructor();
37
37
  }
38
+ /**
39
+ * A sign-in that another sign-in or a sign-out overtook. The client keeps the newer state, so the
40
+ * overtaken authorization is never returned to sign with.
41
+ */
42
+ export declare class SupersededError extends Error {
43
+ readonly name = "Decorator.SupersededError";
44
+ constructor();
45
+ }
38
46
  /**
39
47
  * Returns a Viem client extension that adds Tempo Auth's actions as `client.auth`. Each member calls
40
48
  * the action of the same name in `Actions` with one instance, whose `chainId` is the client's chain.
41
- * Each sign-in sets the client's account to the authorization's, unless another sign-in or a
42
- * sign-out completed after it began, and `signOut` empties it at once. Throws
49
+ * Each sign-in sets the client's account to the authorization's, and `signOut` empties it at once.
50
+ * A sign-in that another sign-in or a sign-out overtook throws {@link SupersededError}. Throws
43
51
  * {@link ChainRequiredError} for a client without a chain, and {@link AccountRequiredError} for one
44
52
  * whose account is not an `Auth.account()`.
45
53
  *
package/dist/Decorator.js CHANGED
@@ -16,11 +16,21 @@ export class ChainRequiredError extends Error {
16
16
  super('The client has no chain. Create the client with a Tempo `chain`.');
17
17
  }
18
18
  }
19
+ /**
20
+ * A sign-in that another sign-in or a sign-out overtook. The client keeps the newer state, so the
21
+ * overtaken authorization is never returned to sign with.
22
+ */
23
+ export class SupersededError extends Error {
24
+ name = 'Decorator.SupersededError';
25
+ constructor() {
26
+ super('Another sign-in or a sign-out completed while this sign-in was pending. Sign in again.');
27
+ }
28
+ }
19
29
  /**
20
30
  * Returns a Viem client extension that adds Tempo Auth's actions as `client.auth`. Each member calls
21
31
  * the action of the same name in `Actions` with one instance, whose `chainId` is the client's chain.
22
- * Each sign-in sets the client's account to the authorization's, unless another sign-in or a
23
- * sign-out completed after it began, and `signOut` empties it at once. Throws
32
+ * Each sign-in sets the client's account to the authorization's, and `signOut` empties it at once.
33
+ * A sign-in that another sign-in or a sign-out overtook throws {@link SupersededError}. Throws
24
34
  * {@link ChainRequiredError} for a client without a chain, and {@link AccountRequiredError} for one
25
35
  * whose account is not an `Auth.account()`.
26
36
  *
@@ -46,13 +56,18 @@ export function tempoAuth(options) {
46
56
  let version = 0;
47
57
  /**
48
58
  * Begins an operation that changes the client's account, and returns the function that applies
49
- * its result: the account to sign with, or `undefined` to stop signing.
59
+ * its result: the account to sign with, or `undefined` to stop signing. Applying an account that
60
+ * a newer change overtook throws {@link SupersededError}, so the caller never holds an
61
+ * authorization the client does not sign with.
50
62
  */
51
63
  const begin = () => {
52
64
  const started = version;
53
65
  return (account) => {
54
- if (version !== started)
66
+ if (version !== started) {
67
+ if (account)
68
+ throw new SupersededError();
55
69
  return;
70
+ }
56
71
  state.account = account;
57
72
  version++;
58
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-66.sha-8d0e9ba",
3
+ "version": "0.0.0-pr-66.sha-ad498a8",
4
4
  "description": "Signs users in to Tempo through Tempo Auth, and returns Viem access key accounts on their Tempo Accounts.",
5
5
  "type": "module",
6
6
  "exports": {