@almadar/integrations 2.37.0 → 2.39.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/dist/index.d.ts +44 -4
- package/dist/index.js +100 -33
- package/dist/index.js.map +1 -1
- package/dist/mocks/index.js +2 -2
- package/dist/mocks/index.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +99 -32
- package/dist/runtime/index.js.map +1 -1
- package/dist/{store-RNvxZO-q.d.ts → store-DG5OGiuQ.d.ts} +8 -2
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { e as IntegrationLogger, c as IntegrationErrorCode, a as IntegrationConfig, B as BaseIntegration, d as IntegrationFactory, g as IntegrationParams, h as IntegrationResult, I as IntegrationCallContext } from './BaseIntegration-CWdas-N_.js';
|
|
2
2
|
export { b as IntegrationError, f as IntegrationParamValue, U as UnknownActionError, V as ValidationError, i as ValidationResult, j as getIntegrationFactory, r as resetIntegrationFactory, v as validateParams } from './BaseIntegration-CWdas-N_.js';
|
|
3
|
-
import { e as CredentialStore, d as CredentialPersistence, H as HookDeclaration } from './store-
|
|
4
|
-
export { A as ArxivActions, C as CLIActions, a as CREDENTIAL_ENTITY_TYPE, b as CREDENTIAL_MASTER_KEY_ENV, c as CredentialEntry, D as DatabaseActions, f as DatabaseDriver, g as DatabaseQueryParamValue, h as DatabaseQueryParams, i as DatabaseQueryResult, j as DatabaseRow, k as DeepAgentActions, l as DockerActions, E as EmailActions, G as GitHubActions, I as IconifyActions, m as IntegrationActionName, n as IntegrationContracts, o as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, p as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, q as StripeActions, T as TwilioActions, W as WebhookActions, r as WikimediaActions, Y as YouTubeActions, s as allCredentialEnvVars, t as declaredCredentialEnvVars, u as serviceHooks } from './store-
|
|
3
|
+
import { e as CredentialStore, d as CredentialPersistence, H as HookDeclaration } from './store-DG5OGiuQ.js';
|
|
4
|
+
export { A as ArxivActions, C as CLIActions, a as CREDENTIAL_ENTITY_TYPE, b as CREDENTIAL_MASTER_KEY_ENV, c as CredentialEntry, D as DatabaseActions, f as DatabaseDriver, g as DatabaseQueryParamValue, h as DatabaseQueryParams, i as DatabaseQueryResult, j as DatabaseRow, k as DeepAgentActions, l as DockerActions, E as EmailActions, G as GitHubActions, I as IconifyActions, m as IntegrationActionName, n as IntegrationContracts, o as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, p as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, q as StripeActions, T as TwilioActions, W as WebhookActions, r as WikimediaActions, Y as YouTubeActions, s as allCredentialEnvVars, t as declaredCredentialEnvVars, u as serviceHooks } from './store-DG5OGiuQ.js';
|
|
5
5
|
import { LogMeta, EntityRow, EventPayload } from '@almadar/core';
|
|
6
6
|
export { GitHubIntegration } from './integrations/github/index.js';
|
|
7
7
|
|
|
@@ -766,11 +766,44 @@ declare class OtelIntegration extends BaseIntegration {
|
|
|
766
766
|
|
|
767
767
|
/** Supported OAuth providers */
|
|
768
768
|
type OAuthProvider = 'google' | 'github' | 'auth0';
|
|
769
|
+
/** `token` result: the grant's tokens plus the scopes granted and the subject bound at `authorize`. */
|
|
770
|
+
interface OAuthTokenResult {
|
|
771
|
+
accessToken: string;
|
|
772
|
+
refreshToken: string;
|
|
773
|
+
expiresIn: number;
|
|
774
|
+
tokenType: 'bearer';
|
|
775
|
+
scope: string[];
|
|
776
|
+
subject?: string;
|
|
777
|
+
}
|
|
778
|
+
/** `authorize` input: `subject` is the opaque id of whoever starts the flow, handed back by `token`. */
|
|
779
|
+
interface OAuthAuthorizeInput {
|
|
780
|
+
provider: OAuthProvider;
|
|
781
|
+
scopes: string[];
|
|
782
|
+
redirectUri: string;
|
|
783
|
+
subject?: string;
|
|
784
|
+
}
|
|
785
|
+
/** `token` input: the provider's code, the `state` returned by `authorize`, and who is completing. */
|
|
786
|
+
interface OAuthTokenInput {
|
|
787
|
+
code: string;
|
|
788
|
+
state: string;
|
|
789
|
+
/** Must equal the grant's bound subject; checked before any code exchange. */
|
|
790
|
+
subject?: string;
|
|
791
|
+
}
|
|
792
|
+
/** No pending grant for this `state`: never issued, already used, or expired. */
|
|
793
|
+
declare class OAuthGrantNotFoundError extends Error {
|
|
794
|
+
constructor(state: string);
|
|
795
|
+
}
|
|
796
|
+
/** The completing subject is not the one bound at `authorize`; the grant is consumed, nothing exchanged. */
|
|
797
|
+
declare class OAuthSubjectMismatchError extends Error {
|
|
798
|
+
constructor();
|
|
799
|
+
}
|
|
769
800
|
/** Server-held per-authorization state (never leaves the process). */
|
|
770
801
|
interface PendingAuthorization {
|
|
771
802
|
provider: OAuthProvider;
|
|
772
803
|
redirectUri: string;
|
|
773
804
|
pkceVerifier: string;
|
|
805
|
+
/** Opaque id the host bound at `authorize` (the verified user who started); `token` returns it. */
|
|
806
|
+
subject?: string;
|
|
774
807
|
}
|
|
775
808
|
/**
|
|
776
809
|
* Where pending OIDC authorizations (PKCE verifier, redirect URI) live
|
|
@@ -814,7 +847,7 @@ declare function installPendingGrantStore(store: PendingGrantStore | null): void
|
|
|
814
847
|
* and single-use.
|
|
815
848
|
*/
|
|
816
849
|
declare class OAuthIntegration extends BaseIntegration {
|
|
817
|
-
/** Maps state token ->
|
|
850
|
+
/** Maps state token -> pending MOCK authorization */
|
|
818
851
|
private states;
|
|
819
852
|
/** Maps access token -> token set (mock backend) */
|
|
820
853
|
private tokens;
|
|
@@ -832,6 +865,13 @@ declare class OAuthIntegration extends BaseIntegration {
|
|
|
832
865
|
private readonly real;
|
|
833
866
|
constructor(config: IntegrationConfig);
|
|
834
867
|
execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
|
|
868
|
+
/** Build the provider authorization URL and hold the pending grant (PKCE verifier, subject) under `state`. */
|
|
869
|
+
startAuthorization(input: OAuthAuthorizeInput): Promise<{
|
|
870
|
+
authUrl: string;
|
|
871
|
+
state: string;
|
|
872
|
+
}>;
|
|
873
|
+
/** Consume the pending grant once and exchange the code; throws on an unknown, replayed or expired `state`. */
|
|
874
|
+
completeAuthorization(input: OAuthTokenInput): Promise<OAuthTokenResult>;
|
|
835
875
|
private issuerFor;
|
|
836
876
|
private configurationFor;
|
|
837
877
|
private oidcAuthorize;
|
|
@@ -1039,4 +1079,4 @@ declare class RiggerIntegration extends BaseIntegration {
|
|
|
1039
1079
|
private generate;
|
|
1040
1080
|
}
|
|
1041
1081
|
|
|
1042
|
-
export { AccountingIntegration, type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, ArxivIntegration, type ArxivResult, BankingIntegration, BaseIntegration, CLIIntegration, CREDENTIALS_FILE_ENV, CalendarIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, CredentialPersistence, CredentialStore, CredentialsIntegration, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, DriveIntegration, EmailIntegration, EsignIntegration, FileCredentialPersistence, HookDeclaration, type HookProviderInput, type HookProviderResult, IconifyIntegration, InMemoryPendingGrantStore, IntegrationCallContext, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationFactory, IntegrationLogger, IntegrationParams, IntegrationResult, LLMIntegration, MLIntegration, MetaAdsIntegration, OAuthIntegration, OtelIntegration, type PendingGrantStore, PushIntegration, QueueIntegration, RedisIntegration, type RegisteredHookProvider, type RetryConfig, RiggerIntegration, type SqlGuardResult, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, allHookDeclarations, assertReadOnlySelect, getActiveFactory, getInstalledCredentialStore, getIntegration, getRegisteredIntegrations, googleCalendarHookProvider, installActiveFactory, installCredentialStore, installPendingGrantStore, isKnownIntegration, parseCalendarPushNotification, registerIntegration, registeredHookProviders, resolveCredentialRef, uninstallCredentialStore, verifyAndParseStripeEvent, withRetry };
|
|
1082
|
+
export { AccountingIntegration, type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, ArxivIntegration, type ArxivResult, BankingIntegration, BaseIntegration, CLIIntegration, CREDENTIALS_FILE_ENV, CalendarIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, CredentialPersistence, CredentialStore, CredentialsIntegration, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, DriveIntegration, EmailIntegration, EsignIntegration, FileCredentialPersistence, HookDeclaration, type HookProviderInput, type HookProviderResult, IconifyIntegration, InMemoryPendingGrantStore, IntegrationCallContext, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationFactory, IntegrationLogger, IntegrationParams, IntegrationResult, LLMIntegration, MLIntegration, MetaAdsIntegration, type OAuthAuthorizeInput, OAuthGrantNotFoundError, OAuthIntegration, type OAuthProvider, OAuthSubjectMismatchError, type OAuthTokenInput, type OAuthTokenResult, OtelIntegration, type PendingAuthorization, type PendingGrantStore, PushIntegration, QueueIntegration, RedisIntegration, type RegisteredHookProvider, type RetryConfig, RiggerIntegration, type SqlGuardResult, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, allHookDeclarations, assertReadOnlySelect, getActiveFactory, getInstalledCredentialStore, getIntegration, getRegisteredIntegrations, googleCalendarHookProvider, installActiveFactory, installCredentialStore, installPendingGrantStore, isKnownIntegration, parseCalendarPushNotification, registerIntegration, registeredHookProviders, resolveCredentialRef, uninstallCredentialStore, verifyAndParseStripeEvent, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -132,8 +132,8 @@ var serviceCredentials = {
|
|
|
132
132
|
{ envVar: "REDIS_URL", required: true, description: "Redis connection URL" }
|
|
133
133
|
],
|
|
134
134
|
oauth: [
|
|
135
|
-
{ envVar: "OAUTH_CLIENT_ID", required: true, description: "OIDC client ID" },
|
|
136
|
-
{ envVar: "OAUTH_CLIENT_SECRET", required: true, description: "OIDC client secret" },
|
|
135
|
+
{ envVar: "OAUTH_CLIENT_ID", required: true, description: "OAuth/OIDC client ID" },
|
|
136
|
+
{ envVar: "OAUTH_CLIENT_SECRET", required: true, description: "OAuth/OIDC client secret" },
|
|
137
137
|
{ envVar: "OAUTH_REDIRECT_URI", required: false, description: "OIDC redirect URI (default per-call param)" },
|
|
138
138
|
{ envVar: "OIDC_ISSUER_URL", required: false, description: "OIDC issuer URL (default https://accounts.google.com)" }
|
|
139
139
|
],
|
|
@@ -4029,6 +4029,31 @@ var PROVIDER_AUTH_URLS = {
|
|
|
4029
4029
|
var PROVIDER_ISSUERS = {
|
|
4030
4030
|
google: "https://accounts.google.com"
|
|
4031
4031
|
};
|
|
4032
|
+
var PROVIDER_SERVER_METADATA = {
|
|
4033
|
+
github: {
|
|
4034
|
+
issuer: "https://github.com",
|
|
4035
|
+
authorization_endpoint: "https://github.com/login/oauth/authorize",
|
|
4036
|
+
token_endpoint: "https://github.com/login/oauth/access_token"
|
|
4037
|
+
}
|
|
4038
|
+
};
|
|
4039
|
+
var OAuthGrantNotFoundError = class extends Error {
|
|
4040
|
+
constructor(state) {
|
|
4041
|
+
super(`Invalid or expired state token: ${state}`);
|
|
4042
|
+
this.name = "OAuthGrantNotFoundError";
|
|
4043
|
+
}
|
|
4044
|
+
};
|
|
4045
|
+
var OAuthSubjectMismatchError = class extends Error {
|
|
4046
|
+
constructor() {
|
|
4047
|
+
super("OAuth completion refused: the completing subject is not the one that started the authorization");
|
|
4048
|
+
this.name = "OAuthSubjectMismatchError";
|
|
4049
|
+
}
|
|
4050
|
+
};
|
|
4051
|
+
function assertSubject(bound, completer) {
|
|
4052
|
+
if (bound !== completer) throw new OAuthSubjectMismatchError();
|
|
4053
|
+
}
|
|
4054
|
+
function grantedScopes(scope) {
|
|
4055
|
+
return (scope ?? "").split(/[\s,]+/).filter((s) => s.length > 0);
|
|
4056
|
+
}
|
|
4032
4057
|
var PENDING_GRANT_TTL_MS = 10 * 60 * 1e3;
|
|
4033
4058
|
var InMemoryPendingGrantStore = class {
|
|
4034
4059
|
constructor() {
|
|
@@ -4057,7 +4082,7 @@ function installPendingGrantStore(store) {
|
|
|
4057
4082
|
var OAuthIntegration = class extends BaseIntegration {
|
|
4058
4083
|
constructor(config) {
|
|
4059
4084
|
super(config);
|
|
4060
|
-
/** Maps state token ->
|
|
4085
|
+
/** Maps state token -> pending MOCK authorization */
|
|
4061
4086
|
this.states = /* @__PURE__ */ new Map();
|
|
4062
4087
|
/** Maps access token -> token set (mock backend) */
|
|
4063
4088
|
this.tokens = /* @__PURE__ */ new Map();
|
|
@@ -4086,12 +4111,25 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4086
4111
|
try {
|
|
4087
4112
|
let data;
|
|
4088
4113
|
switch (action) {
|
|
4089
|
-
case "authorize":
|
|
4090
|
-
|
|
4114
|
+
case "authorize": {
|
|
4115
|
+
const input = {
|
|
4116
|
+
provider: params.provider,
|
|
4117
|
+
scopes: params.scopes,
|
|
4118
|
+
redirectUri: params.redirectUri,
|
|
4119
|
+
...params.subject === void 0 ? {} : { subject: params.subject }
|
|
4120
|
+
};
|
|
4121
|
+
data = await this.executeWithRetry(() => this.startAuthorization(input));
|
|
4091
4122
|
break;
|
|
4092
|
-
|
|
4093
|
-
|
|
4123
|
+
}
|
|
4124
|
+
case "token": {
|
|
4125
|
+
const input = {
|
|
4126
|
+
code: params.code,
|
|
4127
|
+
state: params.state,
|
|
4128
|
+
...params.subject === void 0 ? {} : { subject: params.subject }
|
|
4129
|
+
};
|
|
4130
|
+
data = await this.executeWithRetry(() => this.completeAuthorization(input));
|
|
4094
4131
|
break;
|
|
4132
|
+
}
|
|
4095
4133
|
case "refresh":
|
|
4096
4134
|
data = await this.executeWithRetry(() => this.real ? this.oidcRefresh(params) : this.refresh(params));
|
|
4097
4135
|
break;
|
|
@@ -4113,6 +4151,14 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4113
4151
|
return this.handleError(action, error);
|
|
4114
4152
|
}
|
|
4115
4153
|
}
|
|
4154
|
+
/** Build the provider authorization URL and hold the pending grant (PKCE verifier, subject) under `state`. */
|
|
4155
|
+
async startAuthorization(input) {
|
|
4156
|
+
return this.real ? this.oidcAuthorize(input) : this.authorize(input);
|
|
4157
|
+
}
|
|
4158
|
+
/** Consume the pending grant once and exchange the code; throws on an unknown, replayed or expired `state`. */
|
|
4159
|
+
async completeAuthorization(input) {
|
|
4160
|
+
return this.real ? this.oidcToken(input) : this.token(input);
|
|
4161
|
+
}
|
|
4116
4162
|
// ---------------------------------------------------------------------------
|
|
4117
4163
|
// OIDC backend (openid-client)
|
|
4118
4164
|
// ---------------------------------------------------------------------------
|
|
@@ -4128,6 +4174,19 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4128
4174
|
return issuer;
|
|
4129
4175
|
}
|
|
4130
4176
|
async configurationFor(provider) {
|
|
4177
|
+
const metadata = PROVIDER_SERVER_METADATA[provider];
|
|
4178
|
+
if (metadata && !this.config.env.OIDC_ISSUER_URL) {
|
|
4179
|
+
const cached2 = this.discovered.get(metadata.issuer);
|
|
4180
|
+
if (cached2) return cached2;
|
|
4181
|
+
const configuration2 = new oidc.Configuration(
|
|
4182
|
+
metadata,
|
|
4183
|
+
this.config.env.OAUTH_CLIENT_ID,
|
|
4184
|
+
this.config.env.OAUTH_CLIENT_SECRET,
|
|
4185
|
+
oidc.ClientSecretPost(this.config.env.OAUTH_CLIENT_SECRET)
|
|
4186
|
+
);
|
|
4187
|
+
this.discovered.set(metadata.issuer, configuration2);
|
|
4188
|
+
return configuration2;
|
|
4189
|
+
}
|
|
4131
4190
|
const issuer = this.issuerFor(provider);
|
|
4132
4191
|
const cached = this.discovered.get(issuer);
|
|
4133
4192
|
if (cached) return cached;
|
|
@@ -4139,10 +4198,9 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4139
4198
|
this.discovered.set(issuer, configuration);
|
|
4140
4199
|
return configuration;
|
|
4141
4200
|
}
|
|
4142
|
-
async oidcAuthorize(
|
|
4143
|
-
const provider =
|
|
4144
|
-
const
|
|
4145
|
-
const redirectUri = params.redirectUri || this.config.env.OAUTH_REDIRECT_URI;
|
|
4201
|
+
async oidcAuthorize(input) {
|
|
4202
|
+
const { provider, scopes, subject } = input;
|
|
4203
|
+
const redirectUri = input.redirectUri || this.config.env.OAUTH_REDIRECT_URI;
|
|
4146
4204
|
const configuration = await this.configurationFor(provider);
|
|
4147
4205
|
const state = oidc.randomState();
|
|
4148
4206
|
const pkceVerifier = oidc.randomPKCECodeVerifier();
|
|
@@ -4159,17 +4217,21 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4159
4217
|
parameters.prompt = "consent";
|
|
4160
4218
|
}
|
|
4161
4219
|
const authUrl = oidc.buildAuthorizationUrl(configuration, parameters);
|
|
4162
|
-
await this.pendingStore().put(
|
|
4220
|
+
await this.pendingStore().put(
|
|
4221
|
+
state,
|
|
4222
|
+
{ provider, redirectUri, pkceVerifier, ...subject === void 0 ? {} : { subject } },
|
|
4223
|
+
PENDING_GRANT_TTL_MS
|
|
4224
|
+
);
|
|
4163
4225
|
void this.pendingStore().sweep();
|
|
4164
4226
|
return { authUrl: authUrl.toString(), state };
|
|
4165
4227
|
}
|
|
4166
|
-
async oidcToken(
|
|
4167
|
-
const code =
|
|
4168
|
-
const state = params.state;
|
|
4228
|
+
async oidcToken(input) {
|
|
4229
|
+
const { code, state } = input;
|
|
4169
4230
|
const pendingAuth = await this.pendingStore().take(state);
|
|
4170
4231
|
if (!pendingAuth) {
|
|
4171
|
-
throw new
|
|
4232
|
+
throw new OAuthGrantNotFoundError(state);
|
|
4172
4233
|
}
|
|
4234
|
+
assertSubject(pendingAuth.subject, input.subject);
|
|
4173
4235
|
const configuration = await this.configurationFor(pendingAuth.provider);
|
|
4174
4236
|
const callbackUrl = new URL(pendingAuth.redirectUri);
|
|
4175
4237
|
callbackUrl.searchParams.set("code", code);
|
|
@@ -4186,7 +4248,9 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4186
4248
|
accessToken: tokens.access_token,
|
|
4187
4249
|
refreshToken: tokens.refresh_token ?? "",
|
|
4188
4250
|
expiresIn: tokens.expires_in ?? 3600,
|
|
4189
|
-
tokenType: "bearer"
|
|
4251
|
+
tokenType: "bearer",
|
|
4252
|
+
scope: grantedScopes(tokens.scope),
|
|
4253
|
+
...pendingAuth.subject === void 0 ? {} : { subject: pendingAuth.subject }
|
|
4190
4254
|
};
|
|
4191
4255
|
}
|
|
4192
4256
|
async oidcRefresh(params) {
|
|
@@ -4249,13 +4313,11 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4249
4313
|
// ---------------------------------------------------------------------------
|
|
4250
4314
|
// Mock backend actions
|
|
4251
4315
|
// ---------------------------------------------------------------------------
|
|
4252
|
-
async authorize(
|
|
4253
|
-
const provider =
|
|
4254
|
-
const scopes = params.scopes;
|
|
4255
|
-
const redirectUri = params.redirectUri;
|
|
4316
|
+
async authorize(input) {
|
|
4317
|
+
const { provider, scopes, redirectUri, subject } = input;
|
|
4256
4318
|
this.logger.debug("OAuth AUTHORIZE", { provider, scopes: scopes.join(", "), redirectUri });
|
|
4257
4319
|
const state = this.generateToken(16);
|
|
4258
|
-
this.states.set(state, provider);
|
|
4320
|
+
this.states.set(state, { provider, scopes, ...subject === void 0 ? {} : { subject } });
|
|
4259
4321
|
const baseUrl = PROVIDER_AUTH_URLS[provider];
|
|
4260
4322
|
const queryParams = new URLSearchParams({
|
|
4261
4323
|
response_type: "code",
|
|
@@ -4267,17 +4329,15 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4267
4329
|
const authUrl = `${baseUrl}?${queryParams.toString()}`;
|
|
4268
4330
|
return { authUrl, state };
|
|
4269
4331
|
}
|
|
4270
|
-
async token(
|
|
4271
|
-
const code =
|
|
4272
|
-
const state = params.state;
|
|
4332
|
+
async token(input) {
|
|
4333
|
+
const { code, state } = input;
|
|
4273
4334
|
this.logger.debug("OAuth TOKEN", { code, state });
|
|
4274
|
-
const
|
|
4275
|
-
if (!
|
|
4276
|
-
throw new
|
|
4277
|
-
`Invalid or expired state token: ${state}`
|
|
4278
|
-
);
|
|
4335
|
+
const pending = this.states.get(state);
|
|
4336
|
+
if (!pending) {
|
|
4337
|
+
throw new OAuthGrantNotFoundError(state);
|
|
4279
4338
|
}
|
|
4280
4339
|
this.states.delete(state);
|
|
4340
|
+
assertSubject(pending.subject, input.subject);
|
|
4281
4341
|
const accessToken = this.generateToken(32);
|
|
4282
4342
|
const refreshToken = this.generateToken(32);
|
|
4283
4343
|
const expiresIn = 3600;
|
|
@@ -4289,8 +4349,15 @@ var OAuthIntegration = class extends BaseIntegration {
|
|
|
4289
4349
|
this.tokens.set(accessToken, tokenSet);
|
|
4290
4350
|
this.refreshIndex.set(refreshToken, accessToken);
|
|
4291
4351
|
const sub = this.generateToken(8);
|
|
4292
|
-
this.sessions.set(accessToken, this.generateMockUser(provider, sub));
|
|
4293
|
-
return {
|
|
4352
|
+
this.sessions.set(accessToken, this.generateMockUser(pending.provider, sub));
|
|
4353
|
+
return {
|
|
4354
|
+
accessToken,
|
|
4355
|
+
refreshToken,
|
|
4356
|
+
expiresIn,
|
|
4357
|
+
tokenType: "bearer",
|
|
4358
|
+
scope: pending.scopes,
|
|
4359
|
+
...pending.subject === void 0 ? {} : { subject: pending.subject }
|
|
4360
|
+
};
|
|
4294
4361
|
}
|
|
4295
4362
|
async refresh(params) {
|
|
4296
4363
|
const refreshToken = params.refreshToken;
|
|
@@ -5758,6 +5825,6 @@ var RiggerIntegration = class extends BaseIntegration {
|
|
|
5758
5825
|
};
|
|
5759
5826
|
registerIntegration("rigger", RiggerIntegration);
|
|
5760
5827
|
|
|
5761
|
-
export { AccountingIntegration, ArxivIntegration, BankingIntegration, BaseIntegration, CLIIntegration, CREDENTIALS_FILE_ENV, CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CalendarIntegration, ConsoleLogger, CredentialStore, CredentialsIntegration, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, DriveIntegration, EmailIntegration, EsignIntegration, FileCredentialPersistence, GitHubIntegration, IconifyIntegration, InMemoryPendingGrantStore, IntegrationError, IntegrationFactory, LLMIntegration, MLIntegration, MetaAdsIntegration, OAuthIntegration, OtelIntegration, PushIntegration, QueueIntegration, RedisIntegration, RiggerIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, UnknownActionError, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, allCredentialEnvVars, allHookDeclarations, assertReadOnlySelect, declaredCredentialEnvVars, getActiveFactory, getInstalledCredentialStore, getIntegration, getIntegrationFactory, getRegisteredIntegrations, googleCalendarHookProvider, installActiveFactory, installCredentialStore, installPendingGrantStore, isKnownIntegration, parseCalendarPushNotification, registerIntegration, registeredHookProviders, resetIntegrationFactory, resolveCredentialRef, serviceHooks, uninstallCredentialStore, validateParams, verifyAndParseStripeEvent, withRetry };
|
|
5828
|
+
export { AccountingIntegration, ArxivIntegration, BankingIntegration, BaseIntegration, CLIIntegration, CREDENTIALS_FILE_ENV, CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CalendarIntegration, ConsoleLogger, CredentialStore, CredentialsIntegration, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, DriveIntegration, EmailIntegration, EsignIntegration, FileCredentialPersistence, GitHubIntegration, IconifyIntegration, InMemoryPendingGrantStore, IntegrationError, IntegrationFactory, LLMIntegration, MLIntegration, MetaAdsIntegration, OAuthGrantNotFoundError, OAuthIntegration, OAuthSubjectMismatchError, OtelIntegration, PushIntegration, QueueIntegration, RedisIntegration, RiggerIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, UnknownActionError, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, allCredentialEnvVars, allHookDeclarations, assertReadOnlySelect, declaredCredentialEnvVars, getActiveFactory, getInstalledCredentialStore, getIntegration, getIntegrationFactory, getRegisteredIntegrations, googleCalendarHookProvider, installActiveFactory, installCredentialStore, installPendingGrantStore, isKnownIntegration, parseCalendarPushNotification, registerIntegration, registeredHookProviders, resetIntegrationFactory, resolveCredentialRef, serviceHooks, uninstallCredentialStore, validateParams, verifyAndParseStripeEvent, withRetry };
|
|
5762
5829
|
//# sourceMappingURL=index.js.map
|
|
5763
5830
|
//# sourceMappingURL=index.js.map
|