@soulcode/bexio-oauth 0.1.0 → 0.2.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/README.md +1 -1
- package/dist/claims.d.ts +1 -1
- package/dist/claims.d.ts.map +1 -1
- package/dist/claims.js +2 -2
- package/dist/claims.js.map +1 -1
- package/dist/client.d.ts +4 -137
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -629
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +22 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/connect-flow.d.ts +15 -0
- package/dist/connect-flow.d.ts.map +1 -0
- package/dist/connect-flow.js +123 -0
- package/dist/connect-flow.js.map +1 -0
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +15 -10
- package/dist/crypto.js.map +1 -1
- package/dist/external-tokens.d.ts +8 -0
- package/dist/external-tokens.d.ts.map +1 -0
- package/dist/external-tokens.js +73 -0
- package/dist/external-tokens.js.map +1 -0
- package/dist/flow-cookie.d.ts +23 -0
- package/dist/flow-cookie.d.ts.map +1 -0
- package/dist/flow-cookie.js +44 -0
- package/dist/flow-cookie.js.map +1 -0
- package/dist/grants.d.ts +36 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +115 -0
- package/dist/grants.js.map +1 -0
- package/dist/idle-sweep.d.ts +11 -0
- package/dist/idle-sweep.d.ts.map +1 -0
- package/dist/idle-sweep.js +70 -0
- package/dist/idle-sweep.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/migrations.generated.d.ts +3 -0
- package/dist/migrations.generated.d.ts.map +1 -0
- package/dist/migrations.generated.js +40 -0
- package/dist/migrations.generated.js.map +1 -0
- package/dist/oidc.d.ts +30 -0
- package/dist/oidc.d.ts.map +1 -0
- package/dist/oidc.js +67 -0
- package/dist/oidc.js.map +1 -0
- package/dist/refresh.d.ts +30 -0
- package/dist/refresh.d.ts.map +1 -0
- package/dist/refresh.js +139 -0
- package/dist/refresh.js.map +1 -0
- package/dist/return-to.d.ts +8 -0
- package/dist/return-to.d.ts.map +1 -0
- package/dist/return-to.js +31 -0
- package/dist/return-to.js.map +1 -0
- package/dist/sql.d.ts +6 -1
- package/dist/sql.d.ts.map +1 -1
- package/dist/sql.js +8 -12
- package/dist/sql.js.map +1 -1
- package/dist/store/postgres.d.ts +1 -1
- package/dist/store/postgres.d.ts.map +1 -1
- package/dist/store/postgres.js +11 -2
- package/dist/store/postgres.js.map +1 -1
- package/dist/types.d.ts +150 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"return-to.js","sourceRoot":"","sources":["../src/return-to.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAyB,EACzB,QAAgB;IAEhB,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5B,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,IAAI,eAAe,CACjB,gBAAgB,EAChB,iDAAiD,CAClD,CAAC;IACJ,4CAA4C;IAC5C,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC;QAC3D,MAAM,OAAO,EAAE,CAAC;IAClB,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,OAAO,EAAE,CAAC;IAClB,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,cAAc;QAAE,MAAM,OAAO,EAAE,CAAC;IACnD,2EAA2E;IAC3E,uEAAuE;IACvE,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,OAAO,EAAE,CAAC;IACnD,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/sql.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ export interface Migration {
|
|
|
4
4
|
name: string;
|
|
5
5
|
sql: string;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The schema migrations shipped with this version, in order.
|
|
9
|
+
*
|
|
10
|
+
* The SQL is embedded in the build (generated from `sql/*.sql`), not read from
|
|
11
|
+
* disk, so this works unchanged when a bundler inlines the library.
|
|
12
|
+
*/
|
|
8
13
|
export declare function migrations(): Promise<Migration[]>;
|
|
9
14
|
//# sourceMappingURL=sql.d.ts.map
|
package/dist/sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAEvD"}
|
package/dist/sql.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { MIGRATIONS } from "./migrations.generated.js";
|
|
2
|
+
/**
|
|
3
|
+
* The schema migrations shipped with this version, in order.
|
|
4
|
+
*
|
|
5
|
+
* The SQL is embedded in the build (generated from `sql/*.sql`), not read from
|
|
6
|
+
* disk, so this works unchanged when a bundler inlines the library.
|
|
7
|
+
*/
|
|
5
8
|
export async function migrations() {
|
|
6
|
-
|
|
7
|
-
.filter((f) => /^\d{4}_.+\.sql$/.test(f))
|
|
8
|
-
.sort();
|
|
9
|
-
return Promise.all(files.map(async (name) => ({
|
|
10
|
-
number: Number.parseInt(name.slice(0, 4), 10),
|
|
11
|
-
name,
|
|
12
|
-
sql: await readFile(new URL(name, SQL_DIR), "utf8"),
|
|
13
|
-
})));
|
|
9
|
+
return MIGRATIONS.map((m) => ({ ...m }));
|
|
14
10
|
}
|
|
15
11
|
//# sourceMappingURL=sql.js.map
|
package/dist/sql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AASvD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/store/postgres.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/store/postgres.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/store/postgres.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;CACvE;AAoED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,GAAG,UAAU,CA0KxD"}
|
package/dist/store/postgres.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { BexioOAuthError } from "../errors.js";
|
|
2
|
+
// `id` is a uuid column: any other value matches no row, and would make
|
|
3
|
+
// Postgres reject the cast instead of returning nothing.
|
|
4
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1
5
|
const COLUMNS = `id, owner_id, bexio_company_id, bexio_user_id, bexio_company_user_id,
|
|
2
6
|
company_name, user_name, user_email, role, status, access_token, refresh_token,
|
|
3
7
|
access_expires_at, refresh_expires_at, scope, refresh_locked_until,
|
|
@@ -85,11 +89,14 @@ export function postgresStore(sql) {
|
|
|
85
89
|
g.scope,
|
|
86
90
|
g.now,
|
|
87
91
|
]);
|
|
88
|
-
if (!row)
|
|
89
|
-
throw new
|
|
92
|
+
if (!row) {
|
|
93
|
+
throw new BexioOAuthError("invalid_config", "SqlClient returned no row for INSERT … RETURNING; check the driver wrapper");
|
|
94
|
+
}
|
|
90
95
|
return row;
|
|
91
96
|
},
|
|
92
97
|
async findGrants({ ownerId, companyId, grantId }) {
|
|
98
|
+
if (grantId !== undefined && !UUID.test(grantId))
|
|
99
|
+
return [];
|
|
93
100
|
return many(`SELECT ${COLUMNS} FROM bexio_grants
|
|
94
101
|
WHERE owner_id = $1
|
|
95
102
|
AND ($2::text IS NULL OR bexio_company_id = $2)
|
|
@@ -97,6 +104,8 @@ export function postgresStore(sql) {
|
|
|
97
104
|
ORDER BY created_at, id`, [ownerId, companyId ?? null, grantId ?? null]);
|
|
98
105
|
},
|
|
99
106
|
async getGrant(id) {
|
|
107
|
+
if (!UUID.test(id))
|
|
108
|
+
return null;
|
|
100
109
|
return one(`SELECT ${COLUMNS} FROM bexio_grants WHERE id = $1`, [id]);
|
|
101
110
|
},
|
|
102
111
|
async acquireRefreshLock({ id, now, lockUntil, lockToken, accessExpiresBefore, refreshedBefore, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/store/postgres.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/store/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAW/C,wEAAwE;AACxE,yDAAyD;AACzD,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAE/E,MAAM,OAAO,GAAG;;;4CAG4B,CAAC;AA2B7C,SAAS,IAAI,CAAC,KAA2B;IACvC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,OAAO,EAAE,GAAG,CAAC,QAAQ;QACrB,SAAS,EAAE,GAAG,CAAC,gBAAgB;QAC/B,MAAM,EAAE,GAAG,CAAC,aAAa;QACzB,aAAa,EACX,GAAG,CAAC,qBAAqB,KAAK,IAAI;YAChC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC;QACvC,WAAW,EAAE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C;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { Keyring } from "./crypto.js";
|
|
2
|
+
import type { Duration } from "./duration.js";
|
|
3
|
+
import type { Role } from "./permissions.js";
|
|
4
|
+
import type { GrantStatus, 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: GrantStatus;
|
|
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
|
+
/**
|
|
74
|
+
* Idle grants not attempted because `timeBudget` ran out (0 when every idle
|
|
75
|
+
* grant of this run was attempted). The next run picks them up first.
|
|
76
|
+
*/
|
|
77
|
+
remaining: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* How the callback checks the owner. Either the `ownerId` your app derives
|
|
81
|
+
* from the signed-in session (must equal the one passed to `start`), or
|
|
82
|
+
* `authorizeOwner`, which receives the owner recorded at `start` and returns
|
|
83
|
+
* whether the signed-in user may connect Bexio for it. Use the latter when
|
|
84
|
+
* one callback URL serves many owners (e.g. workspaces).
|
|
85
|
+
*/
|
|
86
|
+
export type CallbackOptions = {
|
|
87
|
+
ownerId: string;
|
|
88
|
+
} | {
|
|
89
|
+
authorizeOwner: (ownerId: string) => boolean | Promise<boolean>;
|
|
90
|
+
};
|
|
91
|
+
export interface CallbackResult {
|
|
92
|
+
grant: Grant;
|
|
93
|
+
returnTo: string;
|
|
94
|
+
/** Contains the `Set-Cookie` that deletes the flow cookie; copy it onto your response. */
|
|
95
|
+
headers: Headers;
|
|
96
|
+
}
|
|
97
|
+
/** The client returned by `createBexioOAuth`. */
|
|
98
|
+
export interface BexioOAuth {
|
|
99
|
+
/**
|
|
100
|
+
* Starts the Connect flow: returns a redirect to Bexio that sets the
|
|
101
|
+
* encrypted flow cookie. Derive `ownerId` from your authenticated session.
|
|
102
|
+
* `returnTo` must be a relative path (default: `defaultReturnTo`).
|
|
103
|
+
*/
|
|
104
|
+
start(options: {
|
|
105
|
+
ownerId: string;
|
|
106
|
+
returnTo?: string;
|
|
107
|
+
}): Promise<Response>;
|
|
108
|
+
/**
|
|
109
|
+
* Handles the redirect back from Bexio, saves the grant, and redirects to
|
|
110
|
+
* `returnTo` (or `returnTo?bexio_error=<code>` on failure). Only
|
|
111
|
+
* `invalid_config` and non-library errors are thrown.
|
|
112
|
+
*/
|
|
113
|
+
callback(request: Request, options: CallbackOptions): Promise<Response>;
|
|
114
|
+
/**
|
|
115
|
+
* Handles the redirect back from Bexio and saves the grant. Throws a
|
|
116
|
+
* `BexioOAuthError` on failure; use `callback` for a ready-made redirect.
|
|
117
|
+
*/
|
|
118
|
+
handleCallback(request: Request, options: CallbackOptions): Promise<CallbackResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Saves tokens obtained by your auth framework ("Sign in with Bexio").
|
|
121
|
+
* Verifies the tokens' signatures against Bexio's keys first.
|
|
122
|
+
*/
|
|
123
|
+
saveGrant(input: {
|
|
124
|
+
ownerId: string;
|
|
125
|
+
tokens: ExternalTokens;
|
|
126
|
+
}): Promise<Grant>;
|
|
127
|
+
/**
|
|
128
|
+
* A valid access token for the owner's grant, refreshed when needed.
|
|
129
|
+
* Safe to call from background jobs and from many instances at once.
|
|
130
|
+
*/
|
|
131
|
+
getAccessToken(selector: GrantSelector): Promise<AccessToken>;
|
|
132
|
+
/** The owner's grants, without token material. */
|
|
133
|
+
listGrants(query: {
|
|
134
|
+
ownerId: string;
|
|
135
|
+
}): Promise<Grant[]>;
|
|
136
|
+
/** Revokes the refresh token at Bexio (best effort) and deletes the grant. */
|
|
137
|
+
disconnect(selector: GrantSelector): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Refreshes active grants not refreshed for `idleFor`, so Bexio doesn't end
|
|
140
|
+
* their offline sessions. Run it on a schedule. `limit` (default 100) caps
|
|
141
|
+
* the grants one run looks at; `timeBudget` stops the run before the next
|
|
142
|
+
* grant once that much time has passed.
|
|
143
|
+
*/
|
|
144
|
+
refreshIdle(options: {
|
|
145
|
+
idleFor: Duration;
|
|
146
|
+
limit?: number;
|
|
147
|
+
timeBudget?: Duration;
|
|
148
|
+
}): Promise<RefreshIdleResult>;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,8C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AAC,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAE9E;;;OAGG;IACH,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAE9D,kDAAkD;IAClD,UAAU,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAEzD,8EAA8E;IAC9E,UAAU,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE;QACnB,OAAO,EAAE,QAAQ,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,QAAQ,CAAC;KACvB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAChC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcode/bexio-oauth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Bexio OAuth token custody for Node apps: connect Bexio accounts, store tokens encrypted in Postgres, get a valid access token anywhere.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bexio",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"node": ">=24"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
+
"sql:generate": "node ../../scripts/generate-migrations.mjs",
|
|
42
|
+
"prebuild": "node ../../scripts/generate-migrations.mjs --check",
|
|
41
43
|
"build": "tsc -p tsconfig.build.json",
|
|
42
44
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
43
45
|
"test": "vitest run",
|