@dereekb/firebase-server 13.31.0 → 13.33.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/calcom/index.cjs.default.js +1 -0
- package/calcom/index.cjs.js +1451 -0
- package/calcom/index.cjs.mjs +2 -0
- package/calcom/index.d.ts +1 -0
- package/calcom/index.esm.js +1437 -0
- package/calcom/package.json +29 -0
- package/calcom/src/index.d.ts +1 -0
- package/calcom/src/lib/calcom.oauth.connection.cache.d.ts +49 -0
- package/calcom/src/lib/calcom.oauth.connection.config.d.ts +75 -0
- package/calcom/src/lib/calcom.oauth.connection.context.d.ts +84 -0
- package/calcom/src/lib/calcom.oauth.connection.controller.d.ts +18 -0
- package/calcom/src/lib/calcom.oauth.connection.module.d.ts +55 -0
- package/calcom/src/lib/calcom.oauth.connection.service.d.ts +33 -0
- package/calcom/src/lib/index.d.ts +6 -0
- package/discord/index.cjs.default.js +1 -0
- package/discord/index.cjs.js +761 -0
- package/discord/index.cjs.mjs +2 -0
- package/discord/index.d.ts +1 -0
- package/discord/index.esm.js +753 -0
- package/discord/package.json +29 -0
- package/discord/src/index.d.ts +1 -0
- package/discord/src/lib/discord.oauth.connection.config.d.ts +69 -0
- package/discord/src/lib/discord.oauth.connection.controller.d.ts +18 -0
- package/discord/src/lib/discord.oauth.connection.module.d.ts +39 -0
- package/discord/src/lib/discord.oauth.connection.service.d.ts +43 -0
- package/discord/src/lib/index.d.ts +4 -0
- package/index.cjs.js +14 -3
- package/index.esm.js +14 -3
- package/mailgun/package.json +9 -9
- package/mcp/package.json +11 -11
- package/model/index.cjs.js +11077 -6072
- package/model/index.esm.js +11020 -6081
- package/model/package.json +10 -9
- package/model/src/lib/index.d.ts +1 -0
- package/model/src/lib/mailgun/index.d.ts +1 -0
- package/model/src/lib/mailgun/notification.healthcheck.mailgun.d.ts +115 -0
- package/model/src/lib/notification/index.d.ts +2 -0
- package/model/src/lib/notification/notification.action.server.d.ts +42 -3
- package/model/src/lib/notification/notification.error.d.ts +31 -0
- package/model/src/lib/notification/notification.healthcheck.d.ts +39 -0
- package/model/src/lib/notification/notification.healthcheck.service.d.ts +118 -0
- package/model/src/lib/notification/notification.send.service.d.ts +22 -0
- package/model/src/lib/userexternalconnection/index.d.ts +8 -0
- package/model/src/lib/userexternalconnection/oauth/index.d.ts +7 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.config.d.ts +110 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.controller.d.ts +68 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.error.d.ts +29 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.refresh.d.ts +24 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.registry.d.ts +54 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.service.d.ts +216 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.state.d.ts +114 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.accessor.service.d.ts +111 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.action.server.d.ts +172 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.error.d.ts +44 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.module.d.ts +129 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.private.d.ts +192 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.reader.service.d.ts +157 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.refresh.service.d.ts +46 -0
- package/oidc/index.cjs.js +104 -78
- package/oidc/index.esm.js +104 -78
- package/oidc/package.json +10 -10
- package/package.json +24 -10
- package/src/lib/env/env.config.d.ts +15 -0
- package/src/lib/env/env.service.d.ts +7 -0
- package/src/lib/nest/env/env.service.d.ts +1 -0
- package/test/index.cjs.js +14 -2
- package/test/index.esm.js +15 -3
- package/test/package.json +11 -11
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +1 -1
- package/twilio/package.json +8 -8
- package/zoho/README.md +8 -0
- package/zoho/index.cjs.js +1223 -33
- package/zoho/index.esm.js +1212 -36
- package/zoho/package.json +12 -9
- package/zoho/src/lib/index.d.ts +5 -0
- package/zoho/src/lib/zoho.oauth.connection.cache.d.ts +45 -0
- package/zoho/src/lib/zoho.oauth.connection.config.d.ts +80 -0
- package/zoho/src/lib/zoho.oauth.connection.controller.d.ts +18 -0
- package/zoho/src/lib/zoho.oauth.connection.module.d.ts +43 -0
- package/zoho/src/lib/zoho.oauth.connection.service.d.ts +107 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dereekb/firebase-server/calcom",
|
|
3
|
+
"version": "13.33.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@dereekb/analytics": "13.33.0",
|
|
6
|
+
"@dereekb/calcom": "13.33.0",
|
|
7
|
+
"@dereekb/date": "13.33.0",
|
|
8
|
+
"@dereekb/firebase": "13.33.0",
|
|
9
|
+
"@dereekb/firebase-server": "13.33.0",
|
|
10
|
+
"@dereekb/model": "13.33.0",
|
|
11
|
+
"@dereekb/nestjs": "13.33.0",
|
|
12
|
+
"@dereekb/rxjs": "13.33.0",
|
|
13
|
+
"@dereekb/util": "13.33.0",
|
|
14
|
+
"@nestjs/common": "^11.1.19",
|
|
15
|
+
"express": "^5.2.1"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"module": "./index.esm.js",
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"import": "./index.cjs.mjs",
|
|
23
|
+
"default": "./index.cjs.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"module": "./index.esm.js",
|
|
27
|
+
"main": "./index.cjs.js",
|
|
28
|
+
"types": "./index.d.ts"
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type CalcomAccessToken, type CalcomAccessTokenCache } from '@dereekb/calcom';
|
|
2
|
+
import { type FirebaseAuthUserId } from '@dereekb/firebase';
|
|
3
|
+
import { type UserExternalConnectionAccessor, type UserExternalConnectionCredentials, type UserExternalConnectionCredentialsWriter } from '@dereekb/firebase-server/model';
|
|
4
|
+
import { type Maybe } from '@dereekb/util';
|
|
5
|
+
/**
|
|
6
|
+
* Maps stored connection credentials to a {@link CalcomAccessToken}.
|
|
7
|
+
*
|
|
8
|
+
* @param credentials - The credentials stored for the `calcom` provider.
|
|
9
|
+
* @returns The equivalent Cal.com access token, or null when the credentials cannot form one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function calcomAccessTokenFromUserExternalConnectionCredentials(credentials: Maybe<UserExternalConnectionCredentials>): Maybe<CalcomAccessToken>;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for {@link userExternalConnectionCalcomAccessTokenCache}.
|
|
14
|
+
*/
|
|
15
|
+
export interface UserExternalConnectionCalcomAccessTokenCacheConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Used to read the user's currently stored Cal.com credentials.
|
|
18
|
+
*
|
|
19
|
+
* The accessor rather than `UserExternalConnectionReader`: the contract below is explicitly that an
|
|
20
|
+
* EXPIRED token may be returned, so a surface that could refresh would be the wrong tool — see
|
|
21
|
+
* `loadCachedToken`.
|
|
22
|
+
*/
|
|
23
|
+
readonly accessor: UserExternalConnectionAccessor;
|
|
24
|
+
/**
|
|
25
|
+
* Used to persist a rotated token back onto the connection pair.
|
|
26
|
+
*/
|
|
27
|
+
readonly actions: UserExternalConnectionCredentialsWriter;
|
|
28
|
+
readonly uid: FirebaseAuthUserId;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a {@link CalcomAccessTokenCache} backed by a user's UserExternalConnection pair.
|
|
32
|
+
*
|
|
33
|
+
* This is what keeps a Cal.com connection working past its first refresh. Cal.com invalidates a
|
|
34
|
+
* refresh token on every use and returns a rotated one, but it hands that rotated token to its
|
|
35
|
+
* `CalcomAccessTokenCache` — not back to us. With the default in-memory or file cache, the token
|
|
36
|
+
* stored on `uecp` is spent the first time it is used: nothing looks wrong, the entry stays
|
|
37
|
+
* `connected`, and the next process that starts with a cold cache replays a dead token.
|
|
38
|
+
*
|
|
39
|
+
* Pointing the cache at the connection pair makes the pair the single store of record, so a rotation
|
|
40
|
+
* is durable the moment it happens.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately NOT registered as a `CalcomOAuthAccessTokenCacheService`: that service's `cacheForKey`
|
|
43
|
+
* is keyed by an opaque string, whereas this cache is per-user and needs a uid. Build one per user at
|
|
44
|
+
* the call site and pass it in explicitly.
|
|
45
|
+
*
|
|
46
|
+
* @param config - The accessor, the actions, and the user the cache is for.
|
|
47
|
+
* @returns A CalcomAccessTokenCache reading and writing the user's connection pair.
|
|
48
|
+
*/
|
|
49
|
+
export declare function userExternalConnectionCalcomAccessTokenCache(config: UserExternalConnectionCalcomAccessTokenCacheConfig): CalcomAccessTokenCache;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type CalcomOAuthScope } from '@dereekb/calcom';
|
|
2
|
+
import { type FirebaseServerEnvService } from '@dereekb/firebase-server';
|
|
3
|
+
import { UserExternalConnectionOAuthServiceConfig } from '@dereekb/firebase-server/model';
|
|
4
|
+
import { type Maybe } from '@dereekb/util';
|
|
5
|
+
/**
|
|
6
|
+
* Controller path the Cal.com external-connection OAuth endpoints are mounted at.
|
|
7
|
+
*
|
|
8
|
+
* Derived from the framework's path factory, the same expression the redirect URI and the
|
|
9
|
+
* global-prefix exclusion are built from, so the three cannot drift apart.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH: string;
|
|
12
|
+
/**
|
|
13
|
+
* Routes to exclude from an app's global API route prefix so the Cal.com callback controller stays
|
|
14
|
+
* mounted at `/oauth/calcom/*`.
|
|
15
|
+
*
|
|
16
|
+
* Spread this into the `exclude` list of the app's `globalApiRoutePrefix` config, alongside
|
|
17
|
+
* `FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE: string[];
|
|
20
|
+
/**
|
|
21
|
+
* The scopes requested when an app does not declare its own.
|
|
22
|
+
*
|
|
23
|
+
* Declared in code, deliberately NOT read from the environment: the set to request follows from what
|
|
24
|
+
* the integration actually does, so it is a property of the code rather than of a deployment.
|
|
25
|
+
* Requesting less than the code uses does not make it work — it moves the failure from the consent
|
|
26
|
+
* screen to the first API call.
|
|
27
|
+
*
|
|
28
|
+
* Least privilege for a per-user calendar connect: read which meeting types exist, read the user's
|
|
29
|
+
* availability, and read/write bookings. Excludes `EVENT_TYPE_WRITE` and `SCHEDULE_WRITE` —
|
|
30
|
+
* connecting a calendar does not involve editing the user's meeting types or availability — and
|
|
31
|
+
* `PROFILE_READ`, which is only needed to label the connection with the Cal.com account it belongs
|
|
32
|
+
* to.
|
|
33
|
+
*
|
|
34
|
+
* Cal.com refuses the authorize request outright when the requested set exceeds what the OAuth
|
|
35
|
+
* client is registered for ("Requested scope exceeds the client's registered scopes"). That is a
|
|
36
|
+
* registration problem: register the scopes the code needs, rather than narrowing the request to fit.
|
|
37
|
+
* An app whose integration genuinely does less can declare its own set on the module metadata, in
|
|
38
|
+
* code where it is reviewable.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_CALCOM_OAUTH_SCOPES: readonly CalcomOAuthScope[];
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for the {@link CalcomUserExternalConnectionOAuthService}.
|
|
43
|
+
*
|
|
44
|
+
* Extends the framework config with the one thing that is Cal.com's own — which scopes to request.
|
|
45
|
+
*/
|
|
46
|
+
export declare abstract class CalcomUserExternalConnectionOAuthServiceConfig extends UserExternalConnectionOAuthServiceConfig {
|
|
47
|
+
readonly scopes: readonly CalcomOAuthScope[];
|
|
48
|
+
}
|
|
49
|
+
export interface CalcomUserExternalConnectionOAuthServiceConfigFactoryConfig {
|
|
50
|
+
readonly envService: FirebaseServerEnvService;
|
|
51
|
+
/**
|
|
52
|
+
* Path on the app URL the user is returned to after connecting, e.g. `/app/settings`.
|
|
53
|
+
*/
|
|
54
|
+
readonly successPath: string;
|
|
55
|
+
/**
|
|
56
|
+
* Path on the app URL the user is returned to after a failed connect. Defaults to `successPath`.
|
|
57
|
+
*/
|
|
58
|
+
readonly failurePath?: Maybe<string>;
|
|
59
|
+
/**
|
|
60
|
+
* The scopes to request. Defaults to {@link DEFAULT_CALCOM_OAUTH_SCOPES}.
|
|
61
|
+
*/
|
|
62
|
+
readonly scopes?: Maybe<readonly CalcomOAuthScope[]>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds the Cal.com connect flow's configuration from the app's configured origins.
|
|
66
|
+
*
|
|
67
|
+
* Nothing here is read from the environment as a value: the redirect URI is derived from the app's
|
|
68
|
+
* OAuth origin plus the mounted controller path, and the return URLs from the app URL plus
|
|
69
|
+
* code-declared paths. Registering Cal.com therefore adds no deployment configuration beyond the
|
|
70
|
+
* client credentials themselves.
|
|
71
|
+
*
|
|
72
|
+
* @param config - The env service, the return paths, and the optional scope override.
|
|
73
|
+
* @returns The validated service configuration.
|
|
74
|
+
*/
|
|
75
|
+
export declare function calcomUserExternalConnectionOAuthServiceConfigFactory(config: CalcomUserExternalConnectionOAuthServiceConfigFactoryConfig): CalcomUserExternalConnectionOAuthServiceConfig;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type CalcomApi, type CalcomApiContextInstance } from '@dereekb/calcom/nestjs';
|
|
2
|
+
import { type FirebaseAuthUserIdRef, type UserExternalConnectionErrorCode } from '@dereekb/firebase';
|
|
3
|
+
import { type UserExternalConnectionAccessor, type UserExternalConnectionCredentialsAndFailureWriter } from '@dereekb/firebase-server/model';
|
|
4
|
+
import { type Maybe } from '@dereekb/util';
|
|
5
|
+
/**
|
|
6
|
+
* Maps an error thrown while calling Cal.com as a user to the code to record on their connection.
|
|
7
|
+
*
|
|
8
|
+
* Returns null for anything that is not the grant being refused — a rate limit, a validation error, a
|
|
9
|
+
* network failure, or a 403 all leave the connection itself intact, and marking it `error` for those
|
|
10
|
+
* would send the user to a reconnect that fixes nothing.
|
|
11
|
+
*
|
|
12
|
+
* @param error - The error thrown by a Cal.com call.
|
|
13
|
+
* @returns The error code to record, or null when the connection is not at fault.
|
|
14
|
+
*
|
|
15
|
+
* @__NO_SIDE_EFFECTS__
|
|
16
|
+
*/
|
|
17
|
+
export declare function userExternalConnectionErrorCodeFromCalcomError(error: unknown): Maybe<UserExternalConnectionErrorCode>;
|
|
18
|
+
/**
|
|
19
|
+
* Turns a uid into a Cal.com API instance that acts as that user.
|
|
20
|
+
*
|
|
21
|
+
* The provider-specific sibling of `UserExternalConnectionReader.readerForUser`, and the only correct
|
|
22
|
+
* way to make per-user Cal.com calls in an app that stores connections on the pair:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* const calcom = await calcomUserContextService.calcomUserContextForUser({ uid });
|
|
26
|
+
* const me = await calcom.getMe();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Do NOT assemble this by hand from `readUsableUserExternalConnectionCredentials()`. Cal.com runs its
|
|
30
|
+
* own refresh loop through the access token cache, so a reader refresh followed by a library refresh
|
|
31
|
+
* spends a rotated refresh token twice and destroys one of two valid grants.
|
|
32
|
+
*/
|
|
33
|
+
export declare abstract class UserExternalConnectionCalcomUserContextService {
|
|
34
|
+
/**
|
|
35
|
+
* Builds a Cal.com API instance scoped to the given user.
|
|
36
|
+
*
|
|
37
|
+
* Token rotations land durably on the user's connection pair, and a refused grant is recorded on
|
|
38
|
+
* the connection entry before the error reaches the caller.
|
|
39
|
+
*
|
|
40
|
+
* @param input - The user to act as.
|
|
41
|
+
* @returns The Cal.com API instance for that user.
|
|
42
|
+
* @throws When the user is not connected to Cal.com, or their stored credentials carry no refresh
|
|
43
|
+
* token and so cannot produce an access token.
|
|
44
|
+
*/
|
|
45
|
+
abstract calcomUserContextForUser(input: FirebaseAuthUserIdRef): Promise<CalcomApiContextInstance>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Reference to a {@link UserExternalConnectionCalcomUserContextService} instance.
|
|
49
|
+
*/
|
|
50
|
+
export interface UserExternalConnectionCalcomUserContextServiceRef {
|
|
51
|
+
readonly userExternalConnectionCalcomUserContextService: UserExternalConnectionCalcomUserContextService;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for {@link userExternalConnectionCalcomUserContextService}.
|
|
55
|
+
*
|
|
56
|
+
* Deliberately holds no surface that can refresh credentials itself. `UserExternalConnectionReader`
|
|
57
|
+
* is absent for that reason: its `readUsableUserExternalConnectionCredentials` is the one call this
|
|
58
|
+
* path must never make, and taking the accessor instead makes that mistake unrepresentable here.
|
|
59
|
+
*/
|
|
60
|
+
export interface UserExternalConnectionCalcomUserContextServiceConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Builds the user context and wraps it into an API instance.
|
|
63
|
+
*/
|
|
64
|
+
readonly calcomApi: CalcomApi;
|
|
65
|
+
/**
|
|
66
|
+
* Reads the stored refresh token, and backs the per-user token cache.
|
|
67
|
+
*/
|
|
68
|
+
readonly accessor: UserExternalConnectionAccessor;
|
|
69
|
+
/**
|
|
70
|
+
* Persists a rotated token, and records a refused grant.
|
|
71
|
+
*/
|
|
72
|
+
readonly actions: UserExternalConnectionCredentialsAndFailureWriter;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a {@link UserExternalConnectionCalcomUserContextService}.
|
|
76
|
+
*
|
|
77
|
+
* Instances are NOT cached per user. Each call builds a fresh token factory, so the in-memory token
|
|
78
|
+
* tier lives only as long as the returned instance and one request's tokens are never visible to the
|
|
79
|
+
* next. The pair-backed cache means the cost of that is a document read, not a token refresh.
|
|
80
|
+
*
|
|
81
|
+
* @param config - The Cal.com API, the accessor, and the write surface.
|
|
82
|
+
* @returns A concrete UserExternalConnectionCalcomUserContextService implementation.
|
|
83
|
+
*/
|
|
84
|
+
export declare function userExternalConnectionCalcomUserContextService(config: UserExternalConnectionCalcomUserContextServiceConfig): UserExternalConnectionCalcomUserContextService;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AbstractUserExternalConnectionOAuthController } from '@dereekb/firebase-server/model';
|
|
2
|
+
import { CalcomUserExternalConnectionOAuthService } from './calcom.oauth.connection.service';
|
|
3
|
+
/**
|
|
4
|
+
* Endpoints for the Cal.com external-connection authorization-code handoff.
|
|
5
|
+
*
|
|
6
|
+
* Mounted at `/oauth/calcom`, matching the Angular registry's default authorize path of
|
|
7
|
+
* `/oauth/<providerType>/authorize`. Hosting rewrites do not strip the path, so this prefix is the
|
|
8
|
+
* public path — but an app with a global API route prefix must ALSO exclude these routes from it via
|
|
9
|
+
* {@link CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE}, or they land under
|
|
10
|
+
* that prefix instead and no longer match the redirect URI registered with Cal.com.
|
|
11
|
+
*
|
|
12
|
+
* The `authorize` and `callback` routes come from the base class, so this declares only where they
|
|
13
|
+
* mount and which service serves them.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CalcomUserExternalConnectionOAuthController extends AbstractUserExternalConnectionOAuthController {
|
|
16
|
+
readonly oauthService: CalcomUserExternalConnectionOAuthService;
|
|
17
|
+
constructor(oauthService: CalcomUserExternalConnectionOAuthService);
|
|
18
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ModuleMetadata, type Provider } from '@nestjs/common';
|
|
2
|
+
import { type CalcomOAuthScope } from '@dereekb/calcom';
|
|
3
|
+
import { type Maybe } from '@dereekb/util';
|
|
4
|
+
export interface ProvideAppCalcomUserExternalConnectionOAuthMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
5
|
+
/**
|
|
6
|
+
* This module requires the following dependencies in order to initialize properly:
|
|
7
|
+
* - CalcomOAuthApi
|
|
8
|
+
*
|
|
9
|
+
* This module declaration makes it easier to import a module that exports that dependency.
|
|
10
|
+
*/
|
|
11
|
+
readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
|
|
12
|
+
/**
|
|
13
|
+
* Path on the app URL the user is returned to after connecting, e.g. `/app/settings`.
|
|
14
|
+
*/
|
|
15
|
+
readonly successPath: string;
|
|
16
|
+
/**
|
|
17
|
+
* Path on the app URL the user is returned to after a failed connect. Defaults to `successPath`.
|
|
18
|
+
*/
|
|
19
|
+
readonly failurePath?: Maybe<string>;
|
|
20
|
+
/**
|
|
21
|
+
* The scopes to request. Defaults to `DEFAULT_CALCOM_OAUTH_SCOPES`.
|
|
22
|
+
*/
|
|
23
|
+
readonly scopes?: Maybe<readonly CalcomOAuthScope[]>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convenience function used to generate ModuleMetadata for an app's Cal.com external-connection
|
|
27
|
+
* OAuth module.
|
|
28
|
+
*
|
|
29
|
+
* Opt-in, like the webhook module: importing the Cal.com OAuth module alone never mounts HTTP
|
|
30
|
+
* routes, so an app that only makes outbound Cal.com calls exposes no endpoints.
|
|
31
|
+
*
|
|
32
|
+
* The importing module must also supply `UserExternalConnectionServerActions` and
|
|
33
|
+
* `UserExternalConnectionStateCoder` — both exported by `appUserExternalConnectionModuleMetadata`,
|
|
34
|
+
* so pass that module in `imports`.
|
|
35
|
+
*
|
|
36
|
+
* @param config - The module metadata configuration.
|
|
37
|
+
* @returns NestJS ModuleMetadata mounting the Cal.com connect endpoints.
|
|
38
|
+
*/
|
|
39
|
+
export declare function appCalcomUserExternalConnectionOAuthModuleMetadata(config: ProvideAppCalcomUserExternalConnectionOAuthMetadataConfig): ModuleMetadata;
|
|
40
|
+
/**
|
|
41
|
+
* Creates the NestJS provider for the {@link UserExternalConnectionCalcomUserContextService}.
|
|
42
|
+
*
|
|
43
|
+
* A provider rather than a module, because the three tokens it needs are never declared together:
|
|
44
|
+
* `CalcomApi` comes from the app's Cal.com module and the accessor and actions from its
|
|
45
|
+
* UserExternalConnection module. Declare this in a module that imports both.
|
|
46
|
+
*
|
|
47
|
+
* Separate from {@link appCalcomUserExternalConnectionOAuthModuleMetadata} on purpose — that module
|
|
48
|
+
* needs only `CalcomOAuthApi`, and folding this in would force every app running the connect flow to
|
|
49
|
+
* also provide `CalcomApi` whether it makes outbound Cal.com calls or not.
|
|
50
|
+
*
|
|
51
|
+
* @returns The NestJS provider.
|
|
52
|
+
*
|
|
53
|
+
* @__NO_SIDE_EFFECTS__
|
|
54
|
+
*/
|
|
55
|
+
export declare function userExternalConnectionCalcomUserContextServiceProvider(): Provider;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CalcomAccessToken, type CalcomOAuthAuthorizeUrlFactory } from '@dereekb/calcom';
|
|
2
|
+
import { CalcomOAuthApi } from '@dereekb/calcom/nestjs';
|
|
3
|
+
import { AbstractUserExternalConnectionOAuthService, UserExternalConnectionAccessor, UserExternalConnectionServerActions, UserExternalConnectionStateCoder, type UserExternalConnectionCredentials, type UserExternalConnectionOAuthExchangeInput, type UserExternalConnectionOAuthRefreshCredentialsInput, type UserExternalConnectionOAuthState } from '@dereekb/firebase-server/model';
|
|
4
|
+
import { type WebsiteUrl } from '@dereekb/util';
|
|
5
|
+
import { CalcomUserExternalConnectionOAuthServiceConfig } from './calcom.oauth.connection.config';
|
|
6
|
+
/**
|
|
7
|
+
* Maps an exchanged Cal.com token to the credentials stored on the private connection document.
|
|
8
|
+
*
|
|
9
|
+
* The `refreshToken` written here is the rotated one from the exchange — Cal.com invalidates the
|
|
10
|
+
* token each use, so persisting the one we sent would break the next refresh.
|
|
11
|
+
*
|
|
12
|
+
* @param accessToken - The exchanged Cal.com access token.
|
|
13
|
+
* @returns The credentials to store.
|
|
14
|
+
*/
|
|
15
|
+
export declare function calcomUserExternalConnectionCredentials(accessToken: CalcomAccessToken): UserExternalConnectionCredentials;
|
|
16
|
+
/**
|
|
17
|
+
* Cal.com's half of the external-connection authorization-code handoff.
|
|
18
|
+
*
|
|
19
|
+
* Everything else — resolving who is connecting, surfacing a refusal, persisting the credentials,
|
|
20
|
+
* choosing the redirect — is the framework's.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CalcomUserExternalConnectionOAuthService extends AbstractUserExternalConnectionOAuthService {
|
|
23
|
+
readonly config: CalcomUserExternalConnectionOAuthServiceConfig;
|
|
24
|
+
readonly stateCoder: UserExternalConnectionStateCoder;
|
|
25
|
+
readonly userExternalConnectionActions: UserExternalConnectionServerActions;
|
|
26
|
+
readonly userExternalConnectionAccessor: UserExternalConnectionAccessor;
|
|
27
|
+
readonly oauthApi: CalcomOAuthApi;
|
|
28
|
+
readonly authorizeUrlFactory: CalcomOAuthAuthorizeUrlFactory;
|
|
29
|
+
constructor(config: CalcomUserExternalConnectionOAuthServiceConfig, stateCoder: UserExternalConnectionStateCoder, userExternalConnectionActions: UserExternalConnectionServerActions, userExternalConnectionAccessor: UserExternalConnectionAccessor, oauthApi: CalcomOAuthApi);
|
|
30
|
+
protected authorizeUrlForState(state: UserExternalConnectionOAuthState): WebsiteUrl;
|
|
31
|
+
protected credentialsForAuthorizationCode(input: UserExternalConnectionOAuthExchangeInput): Promise<UserExternalConnectionCredentials>;
|
|
32
|
+
refreshCredentials(input: UserExternalConnectionOAuthRefreshCredentialsInput): Promise<UserExternalConnectionCredentials>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './calcom.oauth.connection.cache';
|
|
2
|
+
export * from './calcom.oauth.connection.config';
|
|
3
|
+
export * from './calcom.oauth.connection.context';
|
|
4
|
+
export * from './calcom.oauth.connection.controller';
|
|
5
|
+
export * from './calcom.oauth.connection.module';
|
|
6
|
+
export * from './calcom.oauth.connection.service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|