@soulcode/bexio-oauth 0.1.0 → 0.3.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.
Files changed (79) hide show
  1. package/README.md +9 -5
  2. package/dist/claims.d.ts +3 -3
  3. package/dist/claims.d.ts.map +1 -1
  4. package/dist/claims.js +5 -5
  5. package/dist/claims.js.map +1 -1
  6. package/dist/client.d.ts +4 -137
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +18 -629
  9. package/dist/client.js.map +1 -1
  10. package/dist/config.d.ts +22 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +57 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/connect-flow.d.ts +15 -0
  15. package/dist/connect-flow.d.ts.map +1 -0
  16. package/dist/connect-flow.js +123 -0
  17. package/dist/connect-flow.js.map +1 -0
  18. package/dist/crypto.d.ts +2 -2
  19. package/dist/crypto.d.ts.map +1 -1
  20. package/dist/crypto.js +20 -15
  21. package/dist/crypto.js.map +1 -1
  22. package/dist/errors.d.ts +1 -1
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/external-tokens.d.ts +8 -0
  25. package/dist/external-tokens.d.ts.map +1 -0
  26. package/dist/external-tokens.js +73 -0
  27. package/dist/external-tokens.js.map +1 -0
  28. package/dist/flow-cookie.d.ts +23 -0
  29. package/dist/flow-cookie.d.ts.map +1 -0
  30. package/dist/flow-cookie.js +44 -0
  31. package/dist/flow-cookie.js.map +1 -0
  32. package/dist/grants.d.ts +45 -0
  33. package/dist/grants.d.ts.map +1 -0
  34. package/dist/grants.js +143 -0
  35. package/dist/grants.js.map +1 -0
  36. package/dist/idle-sweep.d.ts +11 -0
  37. package/dist/idle-sweep.d.ts.map +1 -0
  38. package/dist/idle-sweep.js +70 -0
  39. package/dist/idle-sweep.js.map +1 -0
  40. package/dist/index.d.ts +3 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/migrations.generated.d.ts +3 -0
  45. package/dist/migrations.generated.d.ts.map +1 -0
  46. package/dist/migrations.generated.js +56 -0
  47. package/dist/migrations.generated.js.map +1 -0
  48. package/dist/oidc.d.ts +30 -0
  49. package/dist/oidc.d.ts.map +1 -0
  50. package/dist/oidc.js +67 -0
  51. package/dist/oidc.js.map +1 -0
  52. package/dist/refresh.d.ts +30 -0
  53. package/dist/refresh.d.ts.map +1 -0
  54. package/dist/refresh.js +147 -0
  55. package/dist/refresh.js.map +1 -0
  56. package/dist/return-to.d.ts +8 -0
  57. package/dist/return-to.d.ts.map +1 -0
  58. package/dist/return-to.js +31 -0
  59. package/dist/return-to.js.map +1 -0
  60. package/dist/sql.d.ts +6 -1
  61. package/dist/sql.d.ts.map +1 -1
  62. package/dist/sql.js +8 -12
  63. package/dist/sql.js.map +1 -1
  64. package/dist/store/memory.d.ts.map +1 -1
  65. package/dist/store/memory.js +82 -46
  66. package/dist/store/memory.js.map +1 -1
  67. package/dist/store/postgres.d.ts +4 -4
  68. package/dist/store/postgres.d.ts.map +1 -1
  69. package/dist/store/postgres.js +137 -59
  70. package/dist/store/postgres.js.map +1 -1
  71. package/dist/store/types.d.ts +61 -21
  72. package/dist/store/types.d.ts.map +1 -1
  73. package/dist/types.d.ts +164 -0
  74. package/dist/types.d.ts.map +1 -0
  75. package/dist/types.js +2 -0
  76. package/dist/types.js.map +1 -0
  77. package/package.json +3 -1
  78. package/sql/0001_bexio_oauth.sql +48 -0
  79. package/sql/0001_bexio_grants.sql +0 -32
package/README.md CHANGED
@@ -11,12 +11,14 @@ It is **not** an auth framework: your app keeps its own login. For "Sign in with
11
11
 
12
12
  ```bash
13
13
  npm install @soulcode/bexio-oauth pg
14
- npx @soulcode/bexio-oauth sql > migrations/0001_bexio_grants.sql # then apply it
14
+ npx @soulcode/bexio-oauth sql > migrations/0001_bexio_oauth.sql # then apply it
15
15
  npx @soulcode/bexio-oauth keygen # encryption key
16
16
  ```
17
17
 
18
18
  Requires Node ≥ 24 and PostgreSQL.
19
19
 
20
+ Use one Bexio OAuth client per app: Bexio keeps one refresh token chain per user, company and client, so apps sharing a client id invalidate each other's grants. Owners of your app that connect the same Bexio user and company share one connection, refreshed once for all of them ([guide §2](https://github.com/SoulcodeAgency/bexio-oauth/blob/main/docs/integration.md#why-owners-of-the-same-identity-share-a-connection)).
21
+
20
22
  ## Quickstart
21
23
 
22
24
  ```ts
@@ -37,14 +39,16 @@ export const bexio = createBexioOAuth({
37
39
  ```
38
40
 
39
41
  ```ts
40
- // GET /api/bexio/connect
42
+ // app/api/bexio/connect/route.ts
41
43
  export const GET = async (req: Request) =>
42
- bexio.start(req, {
44
+ bexio.start({
43
45
  ownerId: await currentWorkspaceId(req),
44
46
  returnTo: "/settings",
45
47
  });
48
+ ```
46
49
 
47
- // GET /api/bexio/callback (your redirectUri)
50
+ ```ts
51
+ // app/api/bexio/callback/route.ts (your redirectUri)
48
52
  export const GET = async (req: Request) =>
49
53
  bexio.callback(req, { ownerId: await currentWorkspaceId(req) });
50
54
  ```
@@ -60,7 +64,7 @@ await fetch("https://api.bexio.com/2.0/contact", {
60
64
  });
61
65
  ```
62
66
 
63
- Also: `listGrants`, `disconnect`, `refreshIdle` (keep idle grants alive), `saveGrant` (tokens from your auth framework). Every error is a `BexioOAuthError` with a stable `code`.
67
+ Also: `listGrants`, `disconnect`, `refreshIdle` (keep idle connections alive), `saveGrant` (tokens from your auth framework). Every error is a `BexioOAuthError` with a stable `code`.
64
68
 
65
69
  ## License
66
70
 
package/dist/claims.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare const BEXIO_API_BASE_URL = "https://api.bexio.com";
6
6
  * Always requested. `company_profile` adds the company claims; `offline_access`
7
7
  * issues a refresh token that keeps working without the user present.
8
8
  */
9
- export declare const BASE_SCOPES: string[];
9
+ export declare const BASE_SCOPES: readonly string[];
10
10
  export type ClaimBag = Record<string, unknown>;
11
11
  /** Who granted access, as read from Bexio's ID token, access token and userinfo. */
12
12
  export interface BexioIdentity {
@@ -26,6 +26,6 @@ export interface BexioIdentity {
26
26
  * missing.
27
27
  */
28
28
  export declare function mapClaims(claims: ClaimBag): BexioIdentity;
29
- /** The value a grant's ciphertext is bound to (see `TokenCipher`). */
30
- export declare function grantBinding(ownerId: string, companyId: string, userId: string): string;
29
+ /** The value a connection's ciphertext is bound to (see `TokenCipher`). */
30
+ export declare function connectionBinding(companyId: string, userId: string): string;
31
31
  //# sourceMappingURL=claims.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"claims.d.ts","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAClE,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D;;;GAGG;AACH,eAAO,MAAM,WAAW,UAMvB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAaD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,GAAG,aAAa,CAwBzD;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,CAER"}
1
+ {"version":3,"file":"claims.d.ts","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAClE,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAMvC,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAaD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,GAAG,aAAa,CAwBzD;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3E"}
package/dist/claims.js CHANGED
@@ -7,13 +7,13 @@ export const BEXIO_API_BASE_URL = "https://api.bexio.com";
7
7
  * Always requested. `company_profile` adds the company claims; `offline_access`
8
8
  * issues a refresh token that keeps working without the user present.
9
9
  */
10
- export const BASE_SCOPES = [
10
+ export const BASE_SCOPES = Object.freeze([
11
11
  "openid",
12
12
  "profile",
13
13
  "email",
14
14
  "company_profile",
15
15
  "offline_access",
16
- ];
16
+ ]);
17
17
  function text(value) {
18
18
  if (typeof value === "string" && value.length > 0)
19
19
  return value;
@@ -51,8 +51,8 @@ export function mapClaims(claims) {
51
51
  userEmail: text(claims.email),
52
52
  };
53
53
  }
54
- /** The value a grant's ciphertext is bound to (see `TokenCipher`). */
55
- export function grantBinding(ownerId, companyId, userId) {
56
- return `${ownerId}\u0000${companyId}\u0000${userId}`;
54
+ /** The value a connection's ciphertext is bound to (see `TokenCipher`). */
55
+ export function connectionBinding(companyId, userId) {
56
+ return `${companyId}\u0000${userId}`;
57
57
  }
58
58
  //# sourceMappingURL=claims.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"claims.js","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,uDAAuD;AACvD,MAAM,CAAC,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAClE,uCAAuC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAC1D;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,QAAQ;IACR,SAAS;IACT,OAAO;IACP,iBAAiB;IACjB,gBAAgB;CACjB,CAAC;AAiBF,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9E,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAgB;IACxC,MAAM,MAAM,GAAG,IAAI,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AG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACxC,OAAO;QACL,MAAM;QACN,SAAS;QACT,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QACtC,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;QAC9C,QAAQ,EACN,KAAK,IAAI,MAAM;YACb,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,EAAE;YACtB,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC;QAC5C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,MAAc;IACjE,OAAO,GAAG,SAAS,SAAS,MAAM,EAAE,CAAC;AACvC,CAAC"}
package/dist/client.d.ts CHANGED
@@ -1,140 +1,7 @@
1
- import { type Keyring } from "./crypto.js";
2
- import { type Duration } from "./duration.js";
3
- import { type Role } from "./permissions.js";
4
- import type { GrantRecord, GrantStore } from "./store/types.js";
5
- export interface BexioOAuthConfig {
6
- /** From your Bexio OAuth app. */
7
- clientId: string;
8
- clientSecret: string;
9
- /** Must exactly match a redirect URI registered at Bexio. */
10
- redirectUri: string;
11
- /** Bexio API scopes your app needs; `BASE_SCOPES` are always added. */
12
- scopes?: string[];
13
- /** Encryption keyring (see `generateKey`). */
14
- keys: Keyring;
15
- store: GrantStore;
16
- /** Defaults to Bexio's production issuer. Override only to point at a mock. */
17
- issuer?: string;
18
- /** Defaults to `https://api.bexio.com`. Override only to point at a mock. */
19
- apiBaseUrl?: string;
20
- /** How long one refresh may hold a grant's lock. Default `"30s"`. */
21
- refreshLockTtl?: Duration;
22
- /** Where `callback` redirects when the flow cookie is gone. Default `"/"`. */
23
- defaultReturnTo?: string;
24
- /** Custom `fetch` for every outgoing request (tests, proxies). */
25
- fetch?: typeof fetch;
26
- /** Clock override for tests. */
27
- clock?: () => Date;
28
- }
29
- /** A grant as the app sees it: no token material. */
30
- export interface Grant {
31
- id: string;
32
- ownerId: string;
33
- companyId: string;
34
- companyName: string | null;
35
- userId: string;
36
- userName: string | null;
37
- userEmail: string | null;
38
- companyUserId: number | null;
39
- role: Role;
40
- status: GrantRecord["status"];
41
- scope: string | null;
42
- accessExpiresAt: Date | null;
43
- lastRefreshedAt: Date;
44
- createdAt: Date;
45
- updatedAt: Date;
46
- }
47
- /** Identifies one grant of an owner. */
48
- export interface GrantSelector {
49
- ownerId: string;
50
- companyId?: string;
51
- grantId?: string;
52
- }
53
- export interface AccessToken {
54
- accessToken: string;
55
- expiresAt: Date | null;
56
- grant: Grant;
57
- }
58
- /** Tokens obtained by your auth framework, for `saveGrant`. */
59
- export interface ExternalTokens {
60
- accessToken: string;
61
- refreshToken?: string | null;
62
- idToken?: string | null;
63
- /** Access-token expiry; defaults to the access token's `exp` claim. */
64
- expiresAt?: Date | null;
65
- scope?: string | null;
66
- }
67
- export interface RefreshIdleResult {
68
- refreshed: number;
69
- /** Idle grants another process was refreshing at the same time. */
70
- skipped: number;
71
- reauthRequired: number;
72
- failed: number;
73
- }
1
+ import type { BexioOAuth, BexioOAuthConfig } from "./types.js";
74
2
  /**
75
- * How the callback checks the owner. Either the `ownerId` your app derives
76
- * from the signed-in session (must equal the one passed to `start`), or
77
- * `authorizeOwner`, which receives the owner recorded at `start` and returns
78
- * whether the signed-in user may connect Bexio for it. Use the latter when
79
- * one callback URL serves many owners (e.g. workspaces).
3
+ * Creates the client. Validates the config up front (throws `invalid_config`);
4
+ * OIDC discovery runs lazily on first use.
80
5
  */
81
- export type CallbackOptions = {
82
- ownerId: string;
83
- } | {
84
- authorizeOwner: (ownerId: string) => boolean | Promise<boolean>;
85
- };
86
- export interface CallbackResult {
87
- grant: Grant;
88
- returnTo: string;
89
- /** Contains the `Set-Cookie` that deletes the flow cookie; copy it onto your response. */
90
- headers: Headers;
91
- }
92
- export type BexioOAuth = ReturnType<typeof createBexioOAuth>;
93
- export declare function createBexioOAuth(config: BexioOAuthConfig): {
94
- /**
95
- * Starts the Connect flow: redirects to Bexio and sets the encrypted flow
96
- * cookie. Derive `ownerId` from your authenticated session.
97
- */
98
- start(_request: Request, options: {
99
- ownerId: string;
100
- returnTo?: string;
101
- }): Promise<Response>;
102
- /**
103
- * Handles the redirect back from Bexio and saves the grant. Throws a
104
- * `BexioOAuthError` on failure; use `callback` for a ready-made redirect.
105
- */
106
- handleCallback(request: Request, options: CallbackOptions): Promise<CallbackResult>;
107
- /**
108
- * Handles the redirect back from Bexio, saves the grant, and redirects to
109
- * `returnTo` (or `returnTo?bexio_error=<code>` on failure).
110
- */
111
- callback(request: Request, options: CallbackOptions): Promise<Response>;
112
- /**
113
- * Saves tokens obtained by your auth framework ("Sign in with Bexio").
114
- * Verifies the tokens' signatures against Bexio's keys first.
115
- */
116
- saveGrant(input: {
117
- ownerId: string;
118
- tokens: ExternalTokens;
119
- }): Promise<Grant>;
120
- /**
121
- * A valid access token for the owner's grant, refreshed when needed.
122
- * Safe to call from background jobs and from many instances at once.
123
- */
124
- getAccessToken(selector: GrantSelector): Promise<AccessToken>;
125
- /** The owner's grants, without token material. */
126
- listGrants(query: {
127
- ownerId: string;
128
- }): Promise<Grant[]>;
129
- /** Revokes the refresh token at Bexio (best effort) and deletes the grant. */
130
- disconnect(selector: GrantSelector): Promise<void>;
131
- /**
132
- * Refreshes active grants not refreshed for `idleFor`, so Bexio doesn't end
133
- * their offline sessions. Run it on a schedule.
134
- */
135
- refreshIdle(options: {
136
- idleFor: Duration;
137
- limit?: number;
138
- }): Promise<RefreshIdleResult>;
139
- };
6
+ export declare function createBexioOAuth(config: BexioOAuthConfig): BexioOAuth;
140
7
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAe,KAAK,OAAO,EAAE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