@yolk-sdk/connectors 0.0.1-canary.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/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/action.d.mts +37 -0
- package/dist/action.d.mts.map +1 -0
- package/dist/action.mjs +24 -0
- package/dist/action.mjs.map +1 -0
- package/dist/agent.d.mts +21 -0
- package/dist/agent.d.mts.map +1 -0
- package/dist/agent.mjs +66 -0
- package/dist/agent.mjs.map +1 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +21 -0
- package/dist/config.mjs.map +1 -0
- package/dist/connector.d.mts +27 -0
- package/dist/connector.d.mts.map +1 -0
- package/dist/connector.mjs +32 -0
- package/dist/connector.mjs.map +1 -0
- package/dist/credential.d.mts +62 -0
- package/dist/credential.d.mts.map +1 -0
- package/dist/credential.mjs +62 -0
- package/dist/credential.mjs.map +1 -0
- package/dist/error.d.mts +17 -0
- package/dist/error.d.mts.map +1 -0
- package/dist/error.mjs +22 -0
- package/dist/error.mjs.map +1 -0
- package/dist/figma/index.d.mts +48 -0
- package/dist/figma/index.d.mts.map +1 -0
- package/dist/figma/index.mjs +97 -0
- package/dist/figma/index.mjs.map +1 -0
- package/dist/google/calendar.d.mts +53 -0
- package/dist/google/calendar.d.mts.map +1 -0
- package/dist/google/calendar.mjs +111 -0
- package/dist/google/calendar.mjs.map +1 -0
- package/dist/google/gmail.d.mts +53 -0
- package/dist/google/gmail.d.mts.map +1 -0
- package/dist/google/gmail.mjs +103 -0
- package/dist/google/gmail.mjs.map +1 -0
- package/dist/google/index.d.mts +14 -0
- package/dist/google/index.d.mts.map +1 -0
- package/dist/google/index.mjs +15 -0
- package/dist/google/index.mjs.map +1 -0
- package/dist/google/oauth.d.mts +18 -0
- package/dist/google/oauth.d.mts.map +1 -0
- package/dist/google/oauth.mjs +25 -0
- package/dist/google/oauth.mjs.map +1 -0
- package/dist/google/shared.d.mts +20 -0
- package/dist/google/shared.d.mts.map +1 -0
- package/dist/google/shared.mjs +36 -0
- package/dist/google/shared.mjs.map +1 -0
- package/dist/http.d.mts +32 -0
- package/dist/http.d.mts.map +1 -0
- package/dist/http.mjs +36 -0
- package/dist/http.mjs.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +9 -0
- package/dist/integration.d.mts +24 -0
- package/dist/integration.d.mts.map +1 -0
- package/dist/integration.mjs +22 -0
- package/dist/integration.mjs.map +1 -0
- package/dist/linkedin-search/index.d.mts +60 -0
- package/dist/linkedin-search/index.d.mts.map +1 -0
- package/dist/linkedin-search/index.mjs +162 -0
- package/dist/linkedin-search/index.mjs.map +1 -0
- package/dist/notion/index.d.mts +69 -0
- package/dist/notion/index.d.mts.map +1 -0
- package/dist/notion/index.mjs +169 -0
- package/dist/notion/index.mjs.map +1 -0
- package/dist/r2-storage/index.d.mts +48 -0
- package/dist/r2-storage/index.d.mts.map +1 -0
- package/dist/r2-storage/index.mjs +91 -0
- package/dist/r2-storage/index.mjs.map +1 -0
- package/dist/result.d.mts +32 -0
- package/dist/result.d.mts.map +1 -0
- package/dist/result.mjs +23 -0
- package/dist/result.mjs.map +1 -0
- package/dist/telegram/index.d.mts +34 -0
- package/dist/telegram/index.d.mts.map +1 -0
- package/dist/telegram/index.mjs +109 -0
- package/dist/telegram/index.mjs.map +1 -0
- package/dist/todoist/index.d.mts +70 -0
- package/dist/todoist/index.d.mts.map +1 -0
- package/dist/todoist/index.mjs +176 -0
- package/dist/todoist/index.mjs.map +1 -0
- package/package.json +96 -0
- package/src/action.ts +75 -0
- package/src/agent.ts +120 -0
- package/src/config.ts +28 -0
- package/src/connector.ts +62 -0
- package/src/credential.ts +86 -0
- package/src/error.ts +20 -0
- package/src/figma/index.ts +121 -0
- package/src/google/calendar.ts +145 -0
- package/src/google/gmail.ts +127 -0
- package/src/google/index.ts +46 -0
- package/src/google/oauth.ts +26 -0
- package/src/google/shared.ts +56 -0
- package/src/http.ts +51 -0
- package/src/index.ts +36 -0
- package/src/integration.ts +28 -0
- package/src/linkedin-search/index.ts +217 -0
- package/src/notion/index.ts +234 -0
- package/src/r2-storage/index.ts +118 -0
- package/src/result.ts +35 -0
- package/src/telegram/index.ts +144 -0
- package/src/todoist/index.ts +227 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.mjs","names":[],"sources":["../src/credential.ts"],"sourcesContent":["import { Context, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { ConnectorError } from './error.ts'\nimport type { ConnectorIntegration } from './integration.ts'\n\nexport const CredentialKind = Schema.Literals(['api_key', 'bearer_token', 'oauth'])\nexport type CredentialKind = typeof CredentialKind.Type\n\nexport class CredentialSlot extends Schema.Class<CredentialSlot>('CredentialSlot')({\n id: Schema.String,\n kind: CredentialKind,\n requiredScopes: Schema.optional(Schema.Array(Schema.String))\n}) {}\n\nexport class CredentialBinding extends Schema.Class<CredentialBinding>('CredentialBinding')({\n slotId: Schema.String,\n credentialRef: Schema.String,\n metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))\n}) {}\n\nexport class ApiKeyCredential extends Schema.Class<ApiKeyCredential>('ApiKeyCredential')({\n _tag: Schema.Literal('ApiKeyCredential'),\n key: Schema.String\n}) {}\n\nexport class BearerTokenCredential extends Schema.Class<BearerTokenCredential>('BearerTokenCredential')({\n _tag: Schema.Literal('BearerTokenCredential'),\n token: Schema.String,\n expiresAt: Schema.optional(Schema.Number)\n}) {}\n\nexport class OAuthCredential extends Schema.Class<OAuthCredential>('OAuthCredential')({\n _tag: Schema.Literal('OAuthCredential'),\n provider: Schema.String,\n accessToken: Schema.String,\n expiresAt: Schema.Number,\n accountId: Schema.optional(Schema.String),\n scopes: Schema.optional(Schema.Array(Schema.String))\n}) {}\n\nexport const RuntimeCredential = Schema.Union([ApiKeyCredential, BearerTokenCredential, OAuthCredential])\nexport type RuntimeCredential = typeof RuntimeCredential.Type\n\nexport type CredentialResolveRequest = {\n readonly integration: ConnectorIntegration\n readonly slot: CredentialSlot\n readonly binding: CredentialBinding\n}\n\nexport type CredentialResolverApi = {\n readonly resolve: (\n request: CredentialResolveRequest\n ) => Effect.Effect<RuntimeCredential, ConnectorError>\n}\n\nexport class CredentialResolver extends Context.Service<CredentialResolver, CredentialResolverApi>()(\n '@yolk-sdk/connectors/CredentialResolver'\n) {}\n\nexport const makeCredentialBinding = (input: {\n readonly slotId: string\n readonly credentialRef: string\n readonly metadata?: Readonly<Record<string, unknown>>\n}) => CredentialBinding.make(input)\n\nexport const findCredentialBinding = (integration: ConnectorIntegration, slot: CredentialSlot) =>\n Option.fromNullishOr(integration.credentialBindings.find(binding => binding.slotId === slot.id))\n\nexport const resolveCredential = (integration: ConnectorIntegration, slot: CredentialSlot) =>\n Effect.gen(function* () {\n const binding = findCredentialBinding(integration, slot)\n\n if (Option.isNone(binding)) {\n return yield* Effect.fail(\n new ConnectorError({\n cause: 'credential_binding_missing',\n message: `Missing credential binding for slot: ${slot.id}`,\n connectorId: integration.connectorId,\n slotId: slot.id\n })\n )\n }\n\n const resolver = yield* CredentialResolver\n return yield* resolver.resolve({ integration, slot, binding: binding.value })\n })\n"],"mappings":";;;;AAKA,MAAa,iBAAiB,OAAO,SAAS;CAAC;CAAW;CAAgB;AAAO,CAAC;AAGlF,IAAa,iBAAb,cAAoC,OAAO,MAAsB,gBAAgB,EAAE;CACjF,IAAI,OAAO;CACX,MAAM;CACN,gBAAgB,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC;AAC7D,CAAC,EAAE,CAAC;AAEJ,IAAa,oBAAb,cAAuC,OAAO,MAAyB,mBAAmB,EAAE;CAC1F,QAAQ,OAAO;CACf,eAAe,OAAO;CACtB,UAAU,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;AACxE,CAAC,EAAE,CAAC;AAEJ,IAAa,mBAAb,cAAsC,OAAO,MAAwB,kBAAkB,EAAE;CACvF,MAAM,OAAO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ts
|
|
4
|
+
declare const ConnectorErrorCause: Schema.Literals<readonly ["action_not_found", "connector_mismatch", "credential_binding_missing", "credential_invalid", "credential_missing", "validation_failed"]>;
|
|
5
|
+
type ConnectorErrorCause = typeof ConnectorErrorCause.Type;
|
|
6
|
+
declare const ConnectorError_base: Schema.Class<ConnectorError, Schema.TaggedStruct<"ConnectorError", {
|
|
7
|
+
readonly cause: Schema.Literals<readonly ["action_not_found", "connector_mismatch", "credential_binding_missing", "credential_invalid", "credential_missing", "validation_failed"]>;
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
readonly connectorId: Schema.optional<Schema.String>;
|
|
10
|
+
readonly actionId: Schema.optional<Schema.String>;
|
|
11
|
+
readonly slotId: Schema.optional<Schema.String>;
|
|
12
|
+
readonly underlying: Schema.optional<Schema.Unknown>;
|
|
13
|
+
}>, import("effect/Cause").YieldableError>;
|
|
14
|
+
declare class ConnectorError extends ConnectorError_base {}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ConnectorError, ConnectorErrorCause };
|
|
17
|
+
//# sourceMappingURL=error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.mts","names":[],"sources":["../src/error.ts"],"mappings":";;;cAEa,mBAAA,EAAmB,MAAA,CAAA,QAAA;AAAA,KAQpB,mBAAA,UAA6B,mBAAA,CAAoB,IAAI;AAAA,cAAA,mBAAA;;;;;;;;cAEpD,cAAA,SAAuB,mBAOlC"}
|
package/dist/error.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/error.ts
|
|
3
|
+
const ConnectorErrorCause = Schema.Literals([
|
|
4
|
+
"action_not_found",
|
|
5
|
+
"connector_mismatch",
|
|
6
|
+
"credential_binding_missing",
|
|
7
|
+
"credential_invalid",
|
|
8
|
+
"credential_missing",
|
|
9
|
+
"validation_failed"
|
|
10
|
+
]);
|
|
11
|
+
var ConnectorError = class extends Schema.TaggedErrorClass()("ConnectorError", {
|
|
12
|
+
cause: ConnectorErrorCause,
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
connectorId: Schema.optional(Schema.String),
|
|
15
|
+
actionId: Schema.optional(Schema.String),
|
|
16
|
+
slotId: Schema.optional(Schema.String),
|
|
17
|
+
underlying: Schema.optional(Schema.Unknown)
|
|
18
|
+
}) {};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ConnectorError, ConnectorErrorCause };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.mjs","names":[],"sources":["../src/error.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\n\nexport const ConnectorErrorCause = Schema.Literals([\n 'action_not_found',\n 'connector_mismatch',\n 'credential_binding_missing',\n 'credential_invalid',\n 'credential_missing',\n 'validation_failed'\n])\nexport type ConnectorErrorCause = typeof ConnectorErrorCause.Type\n\nexport class ConnectorError extends Schema.TaggedErrorClass<ConnectorError>()('ConnectorError', {\n cause: ConnectorErrorCause,\n message: Schema.String,\n connectorId: Schema.optional(Schema.String),\n actionId: Schema.optional(Schema.String),\n slotId: Schema.optional(Schema.String),\n underlying: Schema.optional(Schema.Unknown)\n}) {}\n"],"mappings":";;AAEA,MAAa,sBAAsB,OAAO,SAAS;CACjD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,IAAa,iBAAb,cAAoC,OAAO,iBAAiC,EAAE,kBAAkB;CAC9F,OAAO;CACP,SAAS,OAAO;CAChB,aAAa,OAAO,SAAS,OAAO,MAAM;CAC1C,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,YAAY,OAAO,SAAS,OAAO,OAAO;AAC5C,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ConnectorError } from "../error.mjs";
|
|
2
|
+
import { CredentialResolver, CredentialSlot } from "../credential.mjs";
|
|
3
|
+
import { ConnectorAction } from "../action.mjs";
|
|
4
|
+
import { Connector } from "../connector.mjs";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
|
|
7
|
+
//#region src/figma/index.d.ts
|
|
8
|
+
declare const figmaConnectorId = "figma";
|
|
9
|
+
declare const figmaOAuthSlotId = "figma.oauth";
|
|
10
|
+
declare const figmaMcpServerUrl = "https://mcp.figma.com/mcp";
|
|
11
|
+
declare const figmaOAuthRegisterUrl = "https://api.figma.com/v1/oauth/mcp/register";
|
|
12
|
+
declare const figmaOAuthAuthorizeUrl = "https://www.figma.com/oauth/mcp";
|
|
13
|
+
declare const figmaOAuthTokenUrl = "https://api.figma.com/v1/oauth/token";
|
|
14
|
+
declare const figmaMcpScope = "mcp:connect";
|
|
15
|
+
declare const FigmaOAuthCredentialSlot: CredentialSlot;
|
|
16
|
+
declare const FigmaMcpAuthInput_base: Schema.Class<FigmaMcpAuthInput, Schema.Struct<{}>, {}>;
|
|
17
|
+
declare class FigmaMcpAuthInput extends FigmaMcpAuthInput_base {}
|
|
18
|
+
declare const FigmaMcpTokens_base: Schema.Class<FigmaMcpTokens, Schema.Struct<{
|
|
19
|
+
readonly accessToken: Schema.String;
|
|
20
|
+
readonly refreshToken: Schema.optional<Schema.String>;
|
|
21
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
22
|
+
}>, {}>;
|
|
23
|
+
declare class FigmaMcpTokens extends FigmaMcpTokens_base {}
|
|
24
|
+
declare const FigmaMcpClientInfo_base: Schema.Class<FigmaMcpClientInfo, Schema.Struct<{
|
|
25
|
+
readonly clientId: Schema.optional<Schema.String>;
|
|
26
|
+
readonly clientSecret: Schema.optional<Schema.String>;
|
|
27
|
+
}>, {}>;
|
|
28
|
+
declare class FigmaMcpClientInfo extends FigmaMcpClientInfo_base {}
|
|
29
|
+
declare const FigmaMcpAuthOutput_base: Schema.Class<FigmaMcpAuthOutput, Schema.Struct<{
|
|
30
|
+
readonly provider: Schema.Literal<"figma">;
|
|
31
|
+
readonly serverUrl: Schema.String;
|
|
32
|
+
readonly tokens: typeof FigmaMcpTokens;
|
|
33
|
+
readonly clientInfo: typeof FigmaMcpClientInfo;
|
|
34
|
+
}>, {}>;
|
|
35
|
+
declare class FigmaMcpAuthOutput extends FigmaMcpAuthOutput_base {}
|
|
36
|
+
declare const makeFigmaMcpAuthData: (input: {
|
|
37
|
+
readonly accessToken: string;
|
|
38
|
+
readonly refreshToken?: string;
|
|
39
|
+
readonly expiresAt?: number;
|
|
40
|
+
readonly clientId?: string;
|
|
41
|
+
readonly clientSecret?: string;
|
|
42
|
+
}) => FigmaMcpAuthOutput;
|
|
43
|
+
declare const figmaMcpAuthAction: ConnectorAction<CredentialResolver, ConnectorError>;
|
|
44
|
+
declare const figmaActions: ConnectorAction<CredentialResolver, ConnectorError>[];
|
|
45
|
+
declare const FigmaConnector: Connector<CredentialResolver, ConnectorError>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { FigmaConnector, FigmaMcpAuthInput, FigmaMcpAuthOutput, FigmaMcpClientInfo, FigmaMcpTokens, FigmaOAuthCredentialSlot, figmaActions, figmaConnectorId, figmaMcpAuthAction, figmaMcpScope, figmaMcpServerUrl, figmaOAuthAuthorizeUrl, figmaOAuthRegisterUrl, figmaOAuthSlotId, figmaOAuthTokenUrl, makeFigmaMcpAuthData };
|
|
48
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/figma/index.ts"],"mappings":";;;;;;;cAUa,gBAAA;AAAA,cACA,gBAAA;AAAA,cACA,iBAAA;AAAA,cACA,qBAAA;AAAA,cACA,sBAAA;AAAA,cACA,kBAAA;AAAA,cACA,aAAA;AAAA,cAEA,wBAAA,EAAwB,cAInC;AAAA,cAAA,sBAAA;cA+BW,iBAAA,SAA0B,sBAAwD;AAAA,cAAG,mBAAA;;;;;cAErF,cAAA,SAAuB,mBAIlC;AAAA,cAAG,uBAAA;;;;cAEQ,kBAAA,SAA2B,uBAGtC;AAAA,cAAG,uBAAA;;;;;;cAEQ,kBAAA,SAA2B,uBAKtC;AAAA,cAEW,oBAAA,GAAwB,KAAA;EAAA,SAC1B,WAAA;EAAA,SACA,YAAA;EAAA,SACA,SAAA;EAAA,SACA,QAAA;EAAA,SACA,YAAA;AAAA,MACV,kBAaG;AAAA,cAES,kBAAA,EAAkB,eAAA,CAkB7B,kBAAA,EAlB6B,cAAA;AAAA,cAoBlB,YAAA,EAAY,eAAA,CAAuB,kBAAA,EAAvB,cAAA;AAAA,cAEZ,cAAA,EAAc,SAAA,CAIzB,kBAAA,EAJyB,cAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ConnectorError } from "../error.mjs";
|
|
2
|
+
import { defineAction } from "../action.mjs";
|
|
3
|
+
import { optionalStringConfig } from "../config.mjs";
|
|
4
|
+
import { defineConnector } from "../connector.mjs";
|
|
5
|
+
import { CredentialSlot, resolveCredential } from "../credential.mjs";
|
|
6
|
+
import { ActionResult } from "../result.mjs";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
//#region src/figma/index.ts
|
|
10
|
+
const figmaConnectorId = "figma";
|
|
11
|
+
const figmaOAuthSlotId = "figma.oauth";
|
|
12
|
+
const figmaMcpServerUrl = "https://mcp.figma.com/mcp";
|
|
13
|
+
const figmaOAuthRegisterUrl = "https://api.figma.com/v1/oauth/mcp/register";
|
|
14
|
+
const figmaOAuthAuthorizeUrl = "https://www.figma.com/oauth/mcp";
|
|
15
|
+
const figmaOAuthTokenUrl = "https://api.figma.com/v1/oauth/token";
|
|
16
|
+
const figmaMcpScope = "mcp:connect";
|
|
17
|
+
const FigmaOAuthCredentialSlot = CredentialSlot.make({
|
|
18
|
+
id: figmaOAuthSlotId,
|
|
19
|
+
kind: "oauth",
|
|
20
|
+
requiredScopes: [figmaMcpScope]
|
|
21
|
+
});
|
|
22
|
+
const resolveFigmaAccessToken = (integration) => Effect.gen(function* () {
|
|
23
|
+
const credential = yield* resolveCredential(integration, FigmaOAuthCredentialSlot);
|
|
24
|
+
switch (credential._tag) {
|
|
25
|
+
case "OAuthCredential": return {
|
|
26
|
+
accessToken: credential.accessToken,
|
|
27
|
+
expiresAt: credential.expiresAt,
|
|
28
|
+
refreshToken: optionalStringConfig(integration, "refreshToken")
|
|
29
|
+
};
|
|
30
|
+
case "BearerTokenCredential": return {
|
|
31
|
+
accessToken: credential.token,
|
|
32
|
+
expiresAt: credential.expiresAt,
|
|
33
|
+
refreshToken: optionalStringConfig(integration, "refreshToken")
|
|
34
|
+
};
|
|
35
|
+
case "ApiKeyCredential": return yield* Effect.fail(new ConnectorError({
|
|
36
|
+
cause: "credential_invalid",
|
|
37
|
+
message: "Figma connector requires an OAuth or bearer token credential",
|
|
38
|
+
connectorId: integration.connectorId,
|
|
39
|
+
slotId: FigmaOAuthCredentialSlot.id
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var FigmaMcpAuthInput = class extends Schema.Class("FigmaMcpAuthInput")({}) {};
|
|
44
|
+
var FigmaMcpTokens = class extends Schema.Class("FigmaMcpTokens")({
|
|
45
|
+
accessToken: Schema.String,
|
|
46
|
+
refreshToken: Schema.optional(Schema.String),
|
|
47
|
+
expiresAt: Schema.optional(Schema.Number)
|
|
48
|
+
}) {};
|
|
49
|
+
var FigmaMcpClientInfo = class extends Schema.Class("FigmaMcpClientInfo")({
|
|
50
|
+
clientId: Schema.optional(Schema.String),
|
|
51
|
+
clientSecret: Schema.optional(Schema.String)
|
|
52
|
+
}) {};
|
|
53
|
+
var FigmaMcpAuthOutput = class extends Schema.Class("FigmaMcpAuthOutput")({
|
|
54
|
+
provider: Schema.Literal("figma"),
|
|
55
|
+
serverUrl: Schema.String,
|
|
56
|
+
tokens: FigmaMcpTokens,
|
|
57
|
+
clientInfo: FigmaMcpClientInfo
|
|
58
|
+
}) {};
|
|
59
|
+
const makeFigmaMcpAuthData = (input) => FigmaMcpAuthOutput.make({
|
|
60
|
+
provider: "figma",
|
|
61
|
+
serverUrl: figmaMcpServerUrl,
|
|
62
|
+
tokens: FigmaMcpTokens.make({
|
|
63
|
+
accessToken: input.accessToken,
|
|
64
|
+
refreshToken: input.refreshToken,
|
|
65
|
+
expiresAt: input.expiresAt
|
|
66
|
+
}),
|
|
67
|
+
clientInfo: FigmaMcpClientInfo.make({
|
|
68
|
+
clientId: input.clientId,
|
|
69
|
+
clientSecret: input.clientSecret
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
const figmaMcpAuthAction = defineAction({
|
|
73
|
+
id: "figma.mcp_auth",
|
|
74
|
+
description: "Build Figma remote MCP auth data from host-provided OAuth credentials.",
|
|
75
|
+
inputSchema: FigmaMcpAuthInput,
|
|
76
|
+
outputSchema: FigmaMcpAuthOutput,
|
|
77
|
+
execute: ({ integration }) => Effect.gen(function* () {
|
|
78
|
+
const token = yield* resolveFigmaAccessToken(integration);
|
|
79
|
+
return ActionResult.success(makeFigmaMcpAuthData({
|
|
80
|
+
accessToken: token.accessToken,
|
|
81
|
+
refreshToken: token.refreshToken,
|
|
82
|
+
expiresAt: token.expiresAt,
|
|
83
|
+
clientId: optionalStringConfig(integration, "clientId"),
|
|
84
|
+
clientSecret: optionalStringConfig(integration, "clientSecret")
|
|
85
|
+
}));
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
const figmaActions = [figmaMcpAuthAction];
|
|
89
|
+
const FigmaConnector = defineConnector({
|
|
90
|
+
id: figmaConnectorId,
|
|
91
|
+
description: "Figma remote MCP connector actions.",
|
|
92
|
+
actions: figmaActions
|
|
93
|
+
});
|
|
94
|
+
//#endregion
|
|
95
|
+
export { FigmaConnector, FigmaMcpAuthInput, FigmaMcpAuthOutput, FigmaMcpClientInfo, FigmaMcpTokens, FigmaOAuthCredentialSlot, figmaActions, figmaConnectorId, figmaMcpAuthAction, figmaMcpScope, figmaMcpServerUrl, figmaOAuthAuthorizeUrl, figmaOAuthRegisterUrl, figmaOAuthSlotId, figmaOAuthTokenUrl, makeFigmaMcpAuthData };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/figma/index.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { defineAction } from '../action.ts'\nimport { optionalStringConfig } from '../config.ts'\nimport { defineConnector } from '../connector.ts'\nimport { CredentialSlot, resolveCredential } from '../credential.ts'\nimport { ConnectorError } from '../error.ts'\nimport { ActionResult } from '../result.ts'\nimport type { ConnectorIntegration } from '../integration.ts'\n\nexport const figmaConnectorId = 'figma'\nexport const figmaOAuthSlotId = 'figma.oauth'\nexport const figmaMcpServerUrl = 'https://mcp.figma.com/mcp'\nexport const figmaOAuthRegisterUrl = 'https://api.figma.com/v1/oauth/mcp/register'\nexport const figmaOAuthAuthorizeUrl = 'https://www.figma.com/oauth/mcp'\nexport const figmaOAuthTokenUrl = 'https://api.figma.com/v1/oauth/token'\nexport const figmaMcpScope = 'mcp:connect'\n\nexport const FigmaOAuthCredentialSlot = CredentialSlot.make({\n id: figmaOAuthSlotId,\n kind: 'oauth',\n requiredScopes: [figmaMcpScope]\n})\n\nconst resolveFigmaAccessToken = (integration: ConnectorIntegration) =>\n Effect.gen(function* () {\n const credential = yield* resolveCredential(integration, FigmaOAuthCredentialSlot)\n\n switch (credential._tag) {\n case 'OAuthCredential':\n return {\n accessToken: credential.accessToken,\n expiresAt: credential.expiresAt,\n refreshToken: optionalStringConfig(integration, 'refreshToken')\n }\n case 'BearerTokenCredential':\n return {\n accessToken: credential.token,\n expiresAt: credential.expiresAt,\n refreshToken: optionalStringConfig(integration, 'refreshToken')\n }\n case 'ApiKeyCredential':\n return yield* Effect.fail(\n new ConnectorError({\n cause: 'credential_invalid',\n message: 'Figma connector requires an OAuth or bearer token credential',\n connectorId: integration.connectorId,\n slotId: FigmaOAuthCredentialSlot.id\n })\n )\n }\n })\n\nexport class FigmaMcpAuthInput extends Schema.Class<FigmaMcpAuthInput>('FigmaMcpAuthInput')({}) {}\n\nexport class FigmaMcpTokens extends Schema.Class<FigmaMcpTokens>('FigmaMcpTokens')({\n accessToken: Schema.String,\n refreshToken: Schema.optional(Schema.String),\n expiresAt: Schema.optional(Schema.Number)\n}) {}\n\nexport class FigmaMcpClientInfo extends Schema.Class<FigmaMcpClientInfo>('FigmaMcpClientInfo')({\n clientId: Schema.optional(Schema.String),\n clientSecret: Schema.optional(Schema.String)\n}) {}\n\nexport class FigmaMcpAuthOutput extends Schema.Class<FigmaMcpAuthOutput>('FigmaMcpAuthOutput')({\n provider: Schema.Literal('figma'),\n serverUrl: Schema.String,\n tokens: FigmaMcpTokens,\n clientInfo: FigmaMcpClientInfo\n}) {}\n\nexport const makeFigmaMcpAuthData = (input: {\n readonly accessToken: string\n readonly refreshToken?: string\n readonly expiresAt?: number\n readonly clientId?: string\n readonly clientSecret?: string\n}) =>\n FigmaMcpAuthOutput.make({\n provider: 'figma',\n serverUrl: figmaMcpServerUrl,\n tokens: FigmaMcpTokens.make({\n accessToken: input.accessToken,\n refreshToken: input.refreshToken,\n expiresAt: input.expiresAt\n }),\n clientInfo: FigmaMcpClientInfo.make({\n clientId: input.clientId,\n clientSecret: input.clientSecret\n })\n })\n\nexport const figmaMcpAuthAction = defineAction({\n id: 'figma.mcp_auth',\n description: 'Build Figma remote MCP auth data from host-provided OAuth credentials.',\n inputSchema: FigmaMcpAuthInput,\n outputSchema: FigmaMcpAuthOutput,\n execute: ({ integration }) =>\n Effect.gen(function* () {\n const token = yield* resolveFigmaAccessToken(integration)\n return ActionResult.success(\n makeFigmaMcpAuthData({\n accessToken: token.accessToken,\n refreshToken: token.refreshToken,\n expiresAt: token.expiresAt,\n clientId: optionalStringConfig(integration, 'clientId'),\n clientSecret: optionalStringConfig(integration, 'clientSecret')\n })\n )\n })\n})\n\nexport const figmaActions = [figmaMcpAuthAction]\n\nexport const FigmaConnector = defineConnector({\n id: figmaConnectorId,\n description: 'Figma remote MCP connector actions.',\n actions: figmaActions\n})\n"],"mappings":";;;;;;;;;AAUA,MAAa,mBAAmB;AAChC,MAAa,mBAAmB;AAChC,MAAa,oBAAoB;AACjC,MAAa,wBAAwB;AACrC,MAAa,yBAAyB;AACtC,MAAa,qBAAqB;AAClC,MAAa,gBAAgB;AAE7B,MAAa,2BAA2B,eAAe,KAAK;CAC1D,IAAI;CACJ,MAAM;CACN,gBAAgB,CAAC,aAAa;AAChC,CAAC;AAED,MAAM,2BAA2B,gBAC/B,OAAO,IAAI,aAAa;CACtB,MAAM,aAAa,OAAO,kBAAkB,aAAa,wBAAwB;CAEjF,QAAQ,WAAW,MAAnB;EACE,KAAK,mBACH,OAAO;GACL,aAAa,WAAW;GACxB,WAAW,WAAW;GACtB,cAAc,qBAAqB,aAAa,cAAc;EAChE;EACF,KAAK,yBACH,OAAO;GACL,aAAa,WAAW;GACxB,WAAW,WAAW;GACtB,cAAc,qBAAqB,aAAa,cAAc;EAChE;EACF,KAAK,oBACH,OAAO,OAAO,OAAO,KACnB,IAAI,eAAe;GACjB,OAAO;GACP,SAAS;GACT,aAAa,YAAY;GACzB,QAAQ,yBAAyB;EACnC,CAAC,CACH;CACJ;AACF,CAAC;AAEH,IAAa,oBAAb,cAAuC,OAAO,MAAyB,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAC;AAEjG,IAAa,iBAAb,cAAoC,OAAO,MAAsB,gBAAgB,EAAE;CACjF,aAAa,OAAO;CACpB,cAAc,OAAO,SAAS,OAAO,MAAM;CAC3C,WAAW,OAAO,SAAS,OAAO,MAAM;AAC1C,CAAC,EAAE,CAAC;AAEJ,IAAa,qBAAb,cAAwC,OAAO,MAA0B,oBAAoB,EAAE;CAC7F,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,cAAc,OAAO,SAAS,OAAO,MAAM;AAC7C,CAAC,EAAE,CAAC;AAEJ,IAAa,qBAAb,cAAwC,OAAO,MAA0B,oBAAoB,EAAE;CAC7F,UAAU,OAAO,QAAQ,OAAO;CAChC,WAAW,OAAO;CAClB,QAAQ;CACR,YAAY;AACd,CAAC,EAAE,CAAC;AAEJ,MAAa,wBAAwB,UAOnC,mBAAmB,KAAK;CACtB,UAAU;CACV,WAAW;CACX,QAAQ,eAAe,KAAK;EAC1B,aAAa,MAAM;EACnB,cAAc,MAAM;EACpB,WAAW,MAAM;CACnB,CAAC;CACD,YAAY,mBAAmB,KAAK;EAClC,UAAU,MAAM;EAChB,cAAc,MAAM;CACtB,CAAC;AACH,CAAC;AAEH,MAAa,qBAAqB,aAAa;CAC7C,IAAI;CACJ,aAAa;CACb,aAAa;CACb,cAAc;CACd,UAAU,EAAE,kBACV,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,wBAAwB,WAAW;EACxD,OAAO,aAAa,QAClB,qBAAqB;GACnB,aAAa,MAAM;GACnB,cAAc,MAAM;GACpB,WAAW,MAAM;GACjB,UAAU,qBAAqB,aAAa,UAAU;GACtD,cAAc,qBAAqB,aAAa,cAAc;EAChE,CAAC,CACH;CACF,CAAC;AACL,CAAC;AAED,MAAa,eAAe,CAAC,kBAAkB;AAE/C,MAAa,iBAAiB,gBAAgB;CAC5C,IAAI;CACJ,aAAa;CACb,SAAS;AACX,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConnectorError } from "../error.mjs";
|
|
2
|
+
import { CredentialResolver } from "../credential.mjs";
|
|
3
|
+
import { ConnectorAction } from "../action.mjs";
|
|
4
|
+
import { ConnectorHttpClient } from "../http.mjs";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
|
|
7
|
+
//#region src/google/calendar.d.ts
|
|
8
|
+
declare const googleCalendarApiBaseUrl = "https://www.googleapis.com/calendar/v3";
|
|
9
|
+
declare const GoogleCalendarEventDateTime_base: Schema.Class<GoogleCalendarEventDateTime, Schema.Struct<{
|
|
10
|
+
readonly date: Schema.optional<Schema.String>;
|
|
11
|
+
readonly dateTime: Schema.optional<Schema.String>;
|
|
12
|
+
readonly timeZone: Schema.optional<Schema.String>;
|
|
13
|
+
}>, {}>;
|
|
14
|
+
declare class GoogleCalendarEventDateTime extends GoogleCalendarEventDateTime_base {}
|
|
15
|
+
declare const GoogleCalendarEvent_base: Schema.Class<GoogleCalendarEvent, Schema.Struct<{
|
|
16
|
+
readonly id: Schema.optional<Schema.String>;
|
|
17
|
+
readonly status: Schema.optional<Schema.String>;
|
|
18
|
+
readonly htmlLink: Schema.optional<Schema.String>;
|
|
19
|
+
readonly summary: Schema.optional<Schema.String>;
|
|
20
|
+
readonly description: Schema.optional<Schema.String>;
|
|
21
|
+
readonly location: Schema.optional<Schema.String>;
|
|
22
|
+
readonly start: Schema.optional<typeof GoogleCalendarEventDateTime>;
|
|
23
|
+
readonly end: Schema.optional<typeof GoogleCalendarEventDateTime>;
|
|
24
|
+
}>, {}>;
|
|
25
|
+
declare class GoogleCalendarEvent extends GoogleCalendarEvent_base {}
|
|
26
|
+
declare const GoogleCalendarListEventsInput_base: Schema.Class<GoogleCalendarListEventsInput, Schema.Struct<{
|
|
27
|
+
readonly calendarId: Schema.optional<Schema.String>;
|
|
28
|
+
readonly timeMin: Schema.optional<Schema.String>;
|
|
29
|
+
readonly timeMax: Schema.optional<Schema.String>;
|
|
30
|
+
readonly query: Schema.optional<Schema.String>;
|
|
31
|
+
readonly maxResults: Schema.optional<Schema.Number>;
|
|
32
|
+
}>, {}>;
|
|
33
|
+
declare class GoogleCalendarListEventsInput extends GoogleCalendarListEventsInput_base {}
|
|
34
|
+
declare const GoogleCalendarListEventsOutput_base: Schema.Class<GoogleCalendarListEventsOutput, Schema.Struct<{
|
|
35
|
+
readonly items: Schema.optional<Schema.$Array<typeof GoogleCalendarEvent>>;
|
|
36
|
+
readonly nextPageToken: Schema.optional<Schema.String>;
|
|
37
|
+
}>, {}>;
|
|
38
|
+
declare class GoogleCalendarListEventsOutput extends GoogleCalendarListEventsOutput_base {}
|
|
39
|
+
declare const GoogleCalendarCreateEventInput_base: Schema.Class<GoogleCalendarCreateEventInput, Schema.Struct<{
|
|
40
|
+
readonly calendarId: Schema.optional<Schema.String>;
|
|
41
|
+
readonly summary: Schema.String;
|
|
42
|
+
readonly description: Schema.optional<Schema.String>;
|
|
43
|
+
readonly location: Schema.optional<Schema.String>;
|
|
44
|
+
readonly start: typeof GoogleCalendarEventDateTime;
|
|
45
|
+
readonly end: typeof GoogleCalendarEventDateTime;
|
|
46
|
+
}>, {}>;
|
|
47
|
+
declare class GoogleCalendarCreateEventInput extends GoogleCalendarCreateEventInput_base {}
|
|
48
|
+
declare const googleCalendarListEventsAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
49
|
+
declare const googleCalendarCreateEventAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
50
|
+
declare const googleCalendarActions: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>[];
|
|
51
|
+
//#endregion
|
|
52
|
+
export { GoogleCalendarCreateEventInput, GoogleCalendarEvent, GoogleCalendarEventDateTime, GoogleCalendarListEventsInput, GoogleCalendarListEventsOutput, googleCalendarActions, googleCalendarApiBaseUrl, googleCalendarCreateEventAction, googleCalendarListEventsAction };
|
|
53
|
+
//# sourceMappingURL=calendar.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.d.mts","names":[],"sources":["../../src/google/calendar.ts"],"mappings":";;;;;;;cAca,wBAAA;AAAA,cAAmE,gCAAA;;;;;cAEnE,2BAAA,SAAoC,gCAM/C;AAAA,cAAG,wBAAA;;;;;;;;;;cAEQ,mBAAA,SAA4B,wBASvC;AAAA,cAAG,kCAAA;;;;;;;cAEQ,6BAAA,SAAsC,kCAQjD;AAAA,cAAG,mCAAA;;;;cAEQ,8BAAA,SAAuC,mCAKlD;AAAA,cAAG,mCAAA;;;;;;;;cAEQ,8BAAA,SAAuC,mCASlD;AAAA,cAIW,8BAAA,EAA8B,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAsC9B,+BAAA,EAA+B,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAyC/B,qBAAA,EAAqB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { defineAction } from "../action.mjs";
|
|
2
|
+
import { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from "../http.mjs";
|
|
3
|
+
import { ActionResult } from "../result.mjs";
|
|
4
|
+
import { googleAuthorizationHeaders } from "./oauth.mjs";
|
|
5
|
+
import { appendNumberSearchParam, appendSearchParam, isSuccessStatus, providerFailureFromResponse, resolveGoogleAccessToken } from "./shared.mjs";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
//#region src/google/calendar.ts
|
|
9
|
+
const googleCalendarApiBaseUrl = "https://www.googleapis.com/calendar/v3";
|
|
10
|
+
var GoogleCalendarEventDateTime = class extends Schema.Class("GoogleCalendarEventDateTime")({
|
|
11
|
+
date: Schema.optional(Schema.String),
|
|
12
|
+
dateTime: Schema.optional(Schema.String),
|
|
13
|
+
timeZone: Schema.optional(Schema.String)
|
|
14
|
+
}) {};
|
|
15
|
+
var GoogleCalendarEvent = class extends Schema.Class("GoogleCalendarEvent")({
|
|
16
|
+
id: Schema.optional(Schema.String),
|
|
17
|
+
status: Schema.optional(Schema.String),
|
|
18
|
+
htmlLink: Schema.optional(Schema.String),
|
|
19
|
+
summary: Schema.optional(Schema.String),
|
|
20
|
+
description: Schema.optional(Schema.String),
|
|
21
|
+
location: Schema.optional(Schema.String),
|
|
22
|
+
start: Schema.optional(GoogleCalendarEventDateTime),
|
|
23
|
+
end: Schema.optional(GoogleCalendarEventDateTime)
|
|
24
|
+
}) {};
|
|
25
|
+
var GoogleCalendarListEventsInput = class extends Schema.Class("GoogleCalendarListEventsInput")({
|
|
26
|
+
calendarId: Schema.optional(Schema.String),
|
|
27
|
+
timeMin: Schema.optional(Schema.String),
|
|
28
|
+
timeMax: Schema.optional(Schema.String),
|
|
29
|
+
query: Schema.optional(Schema.String),
|
|
30
|
+
maxResults: Schema.optional(Schema.Number)
|
|
31
|
+
}) {};
|
|
32
|
+
var GoogleCalendarListEventsOutput = class extends Schema.Class("GoogleCalendarListEventsOutput")({
|
|
33
|
+
items: Schema.optional(Schema.Array(GoogleCalendarEvent)),
|
|
34
|
+
nextPageToken: Schema.optional(Schema.String)
|
|
35
|
+
}) {};
|
|
36
|
+
var GoogleCalendarCreateEventInput = class extends Schema.Class("GoogleCalendarCreateEventInput")({
|
|
37
|
+
calendarId: Schema.optional(Schema.String),
|
|
38
|
+
summary: Schema.String,
|
|
39
|
+
description: Schema.optional(Schema.String),
|
|
40
|
+
location: Schema.optional(Schema.String),
|
|
41
|
+
start: GoogleCalendarEventDateTime,
|
|
42
|
+
end: GoogleCalendarEventDateTime
|
|
43
|
+
}) {};
|
|
44
|
+
const calendarIdOrPrimary = (calendarId) => calendarId ?? "primary";
|
|
45
|
+
const googleCalendarListEventsAction = defineAction({
|
|
46
|
+
id: "calendar.list_events",
|
|
47
|
+
description: "List Google Calendar events for the integration account.",
|
|
48
|
+
inputSchema: GoogleCalendarListEventsInput,
|
|
49
|
+
outputSchema: GoogleCalendarListEventsOutput,
|
|
50
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
51
|
+
const token = yield* resolveGoogleAccessToken(integration);
|
|
52
|
+
const http = yield* ConnectorHttpClient;
|
|
53
|
+
const params = new URLSearchParams();
|
|
54
|
+
appendSearchParam(params, "timeMin", input.timeMin);
|
|
55
|
+
appendSearchParam(params, "timeMax", input.timeMax);
|
|
56
|
+
appendSearchParam(params, "q", input.query);
|
|
57
|
+
appendNumberSearchParam(params, "maxResults", input.maxResults);
|
|
58
|
+
const query = params.toString();
|
|
59
|
+
const url = `${googleCalendarApiBaseUrl}/calendars/${encodeURIComponent(calendarIdOrPrimary(input.calendarId))}/events${query === "" ? "" : `?${query}`}`;
|
|
60
|
+
const response = yield* http.request(ConnectorHttpRequest.make({
|
|
61
|
+
method: "GET",
|
|
62
|
+
url,
|
|
63
|
+
headers: googleAuthorizationHeaders(token)
|
|
64
|
+
}));
|
|
65
|
+
if (!isSuccessStatus(response.status)) return providerFailureFromResponse({
|
|
66
|
+
code: "calendar_list_events_failed",
|
|
67
|
+
message: "Google Calendar list events failed",
|
|
68
|
+
status: response.status,
|
|
69
|
+
body: response.body
|
|
70
|
+
});
|
|
71
|
+
const output = yield* decodeJsonResponse(GoogleCalendarListEventsOutput, response);
|
|
72
|
+
return ActionResult.success(output);
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
const googleCalendarCreateEventAction = defineAction({
|
|
76
|
+
id: "calendar.create_event",
|
|
77
|
+
description: "Create a Google Calendar event for the integration account.",
|
|
78
|
+
inputSchema: GoogleCalendarCreateEventInput,
|
|
79
|
+
outputSchema: GoogleCalendarEvent,
|
|
80
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
81
|
+
const token = yield* resolveGoogleAccessToken(integration);
|
|
82
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
83
|
+
method: "POST",
|
|
84
|
+
url: `${googleCalendarApiBaseUrl}/calendars/${encodeURIComponent(calendarIdOrPrimary(input.calendarId))}/events`,
|
|
85
|
+
headers: {
|
|
86
|
+
...googleAuthorizationHeaders(token),
|
|
87
|
+
"content-type": "application/json"
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
summary: input.summary,
|
|
91
|
+
description: input.description,
|
|
92
|
+
location: input.location,
|
|
93
|
+
start: input.start,
|
|
94
|
+
end: input.end
|
|
95
|
+
})
|
|
96
|
+
}));
|
|
97
|
+
if (!isSuccessStatus(response.status)) return providerFailureFromResponse({
|
|
98
|
+
code: "calendar_create_event_failed",
|
|
99
|
+
message: "Google Calendar create event failed",
|
|
100
|
+
status: response.status,
|
|
101
|
+
body: response.body
|
|
102
|
+
});
|
|
103
|
+
const output = yield* decodeJsonResponse(GoogleCalendarEvent, response);
|
|
104
|
+
return ActionResult.success(output);
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
const googleCalendarActions = [googleCalendarListEventsAction, googleCalendarCreateEventAction];
|
|
108
|
+
//#endregion
|
|
109
|
+
export { GoogleCalendarCreateEventInput, GoogleCalendarEvent, GoogleCalendarEventDateTime, GoogleCalendarListEventsInput, GoogleCalendarListEventsOutput, googleCalendarActions, googleCalendarApiBaseUrl, googleCalendarCreateEventAction, googleCalendarListEventsAction };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=calendar.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.mjs","names":[],"sources":["../../src/google/calendar.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { defineAction } from '../action.ts'\nimport { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from '../http.ts'\nimport { ActionResult } from '../result.ts'\nimport { googleAuthorizationHeaders } from './oauth.ts'\nimport {\n appendNumberSearchParam,\n appendSearchParam,\n isSuccessStatus,\n providerFailureFromResponse,\n resolveGoogleAccessToken\n} from './shared.ts'\n\nexport const googleCalendarApiBaseUrl = 'https://www.googleapis.com/calendar/v3'\n\nexport class GoogleCalendarEventDateTime extends Schema.Class<GoogleCalendarEventDateTime>(\n 'GoogleCalendarEventDateTime'\n)({\n date: Schema.optional(Schema.String),\n dateTime: Schema.optional(Schema.String),\n timeZone: Schema.optional(Schema.String)\n}) {}\n\nexport class GoogleCalendarEvent extends Schema.Class<GoogleCalendarEvent>('GoogleCalendarEvent')({\n id: Schema.optional(Schema.String),\n status: Schema.optional(Schema.String),\n htmlLink: Schema.optional(Schema.String),\n summary: Schema.optional(Schema.String),\n description: Schema.optional(Schema.String),\n location: Schema.optional(Schema.String),\n start: Schema.optional(GoogleCalendarEventDateTime),\n end: Schema.optional(GoogleCalendarEventDateTime)\n}) {}\n\nexport class GoogleCalendarListEventsInput extends Schema.Class<GoogleCalendarListEventsInput>(\n 'GoogleCalendarListEventsInput'\n)({\n calendarId: Schema.optional(Schema.String),\n timeMin: Schema.optional(Schema.String),\n timeMax: Schema.optional(Schema.String),\n query: Schema.optional(Schema.String),\n maxResults: Schema.optional(Schema.Number)\n}) {}\n\nexport class GoogleCalendarListEventsOutput extends Schema.Class<GoogleCalendarListEventsOutput>(\n 'GoogleCalendarListEventsOutput'\n)({\n items: Schema.optional(Schema.Array(GoogleCalendarEvent)),\n nextPageToken: Schema.optional(Schema.String)\n}) {}\n\nexport class GoogleCalendarCreateEventInput extends Schema.Class<GoogleCalendarCreateEventInput>(\n 'GoogleCalendarCreateEventInput'\n)({\n calendarId: Schema.optional(Schema.String),\n summary: Schema.String,\n description: Schema.optional(Schema.String),\n location: Schema.optional(Schema.String),\n start: GoogleCalendarEventDateTime,\n end: GoogleCalendarEventDateTime\n}) {}\n\nconst calendarIdOrPrimary = (calendarId: string | undefined) => calendarId ?? 'primary'\n\nexport const googleCalendarListEventsAction = defineAction({\n id: 'calendar.list_events',\n description: 'List Google Calendar events for the integration account.',\n inputSchema: GoogleCalendarListEventsInput,\n outputSchema: GoogleCalendarListEventsOutput,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveGoogleAccessToken(integration)\n const http = yield* ConnectorHttpClient\n const params = new URLSearchParams()\n appendSearchParam(params, 'timeMin', input.timeMin)\n appendSearchParam(params, 'timeMax', input.timeMax)\n appendSearchParam(params, 'q', input.query)\n appendNumberSearchParam(params, 'maxResults', input.maxResults)\n const query = params.toString()\n const url = `${googleCalendarApiBaseUrl}/calendars/${encodeURIComponent(calendarIdOrPrimary(input.calendarId))}/events${query === '' ? '' : `?${query}`}`\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'GET',\n url,\n headers: googleAuthorizationHeaders(token)\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return providerFailureFromResponse({\n code: 'calendar_list_events_failed',\n message: 'Google Calendar list events failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(GoogleCalendarListEventsOutput, response)\n return ActionResult.success(output)\n })\n})\n\nexport const googleCalendarCreateEventAction = defineAction({\n id: 'calendar.create_event',\n description: 'Create a Google Calendar event for the integration account.',\n inputSchema: GoogleCalendarCreateEventInput,\n outputSchema: GoogleCalendarEvent,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveGoogleAccessToken(integration)\n const http = yield* ConnectorHttpClient\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'POST',\n url: `${googleCalendarApiBaseUrl}/calendars/${encodeURIComponent(calendarIdOrPrimary(input.calendarId))}/events`,\n headers: {\n ...googleAuthorizationHeaders(token),\n 'content-type': 'application/json'\n },\n body: JSON.stringify({\n summary: input.summary,\n description: input.description,\n location: input.location,\n start: input.start,\n end: input.end\n })\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return providerFailureFromResponse({\n code: 'calendar_create_event_failed',\n message: 'Google Calendar create event failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(GoogleCalendarEvent, response)\n return ActionResult.success(output)\n })\n})\n\nexport const googleCalendarActions = [googleCalendarListEventsAction, googleCalendarCreateEventAction]\n"],"mappings":";;;;;;;;AAcA,MAAa,2BAA2B;AAExC,IAAa,8BAAb,cAAiD,OAAO,MACtD,6BACF,EAAE;CACA,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,UAAU,OAAO,SAAS,OAAO,MAAM;AACzC,CAAC,EAAE,CAAC;AAEJ,IAAa,sBAAb,cAAyC,OAAO,MAA2B,qBAAqB,EAAE;CAChG,IAAI,OAAO,SAAS,OAAO,MAAM;CACjC,QAAQ,OAA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qB,QAAQ;EACtE,OAAO,aAAa,QAAQ,MAAM;CACpC,CAAC;AACL,CAAC;AAED,MAAa,wBAAwB,CAAC,gCAAgC,+BAA+B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConnectorError } from "../error.mjs";
|
|
2
|
+
import { CredentialResolver } from "../credential.mjs";
|
|
3
|
+
import { ConnectorAction } from "../action.mjs";
|
|
4
|
+
import { ConnectorHttpClient } from "../http.mjs";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
|
|
7
|
+
//#region src/google/gmail.d.ts
|
|
8
|
+
declare const googleGmailApiBaseUrl = "https://gmail.googleapis.com/gmail/v1";
|
|
9
|
+
declare const GmailMessageRef_base: Schema.Class<GmailMessageRef, Schema.Struct<{
|
|
10
|
+
readonly id: Schema.String;
|
|
11
|
+
readonly threadId: Schema.optional<Schema.String>;
|
|
12
|
+
}>, {}>;
|
|
13
|
+
declare class GmailMessageRef extends GmailMessageRef_base {}
|
|
14
|
+
declare const GmailSearchInput_base: Schema.Class<GmailSearchInput, Schema.Struct<{
|
|
15
|
+
readonly query: Schema.optional<Schema.String>;
|
|
16
|
+
readonly maxResults: Schema.optional<Schema.Number>;
|
|
17
|
+
}>, {}>;
|
|
18
|
+
declare class GmailSearchInput extends GmailSearchInput_base {}
|
|
19
|
+
declare const GmailSearchOutput_base: Schema.Class<GmailSearchOutput, Schema.Struct<{
|
|
20
|
+
readonly messages: Schema.optional<Schema.$Array<typeof GmailMessageRef>>;
|
|
21
|
+
readonly nextPageToken: Schema.optional<Schema.String>;
|
|
22
|
+
readonly resultSizeEstimate: Schema.optional<Schema.Number>;
|
|
23
|
+
}>, {}>;
|
|
24
|
+
declare class GmailSearchOutput extends GmailSearchOutput_base {}
|
|
25
|
+
declare const GmailGetMessageInput_base: Schema.Class<GmailGetMessageInput, Schema.Struct<{
|
|
26
|
+
readonly id: Schema.String;
|
|
27
|
+
readonly format: Schema.optional<Schema.Literals<readonly ["minimal", "full", "raw", "metadata"]>>;
|
|
28
|
+
}>, {}>;
|
|
29
|
+
declare class GmailGetMessageInput extends GmailGetMessageInput_base {}
|
|
30
|
+
declare const GmailMessagePayloadHeader: Schema.Struct<{
|
|
31
|
+
readonly name: Schema.String;
|
|
32
|
+
readonly value: Schema.String;
|
|
33
|
+
}>;
|
|
34
|
+
declare const GmailMessageOutput_base: Schema.Class<GmailMessageOutput, Schema.Struct<{
|
|
35
|
+
readonly id: Schema.String;
|
|
36
|
+
readonly threadId: Schema.optional<Schema.String>;
|
|
37
|
+
readonly snippet: Schema.optional<Schema.String>;
|
|
38
|
+
readonly labelIds: Schema.optional<Schema.$Array<Schema.String>>;
|
|
39
|
+
readonly payload: Schema.optional<Schema.Struct<{
|
|
40
|
+
readonly headers: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
41
|
+
readonly name: Schema.String;
|
|
42
|
+
readonly value: Schema.String;
|
|
43
|
+
}>>>;
|
|
44
|
+
}>>;
|
|
45
|
+
readonly raw: Schema.optional<Schema.String>;
|
|
46
|
+
}>, {}>;
|
|
47
|
+
declare class GmailMessageOutput extends GmailMessageOutput_base {}
|
|
48
|
+
declare const gmailSearchAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
49
|
+
declare const gmailGetMessageAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
50
|
+
declare const gmailActions: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>[];
|
|
51
|
+
//#endregion
|
|
52
|
+
export { GmailGetMessageInput, GmailMessageOutput, GmailMessagePayloadHeader, GmailMessageRef, GmailSearchInput, GmailSearchOutput, gmailActions, gmailGetMessageAction, gmailSearchAction, googleGmailApiBaseUrl };
|
|
53
|
+
//# sourceMappingURL=gmail.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmail.d.mts","names":[],"sources":["../../src/google/gmail.ts"],"mappings":";;;;;;;cAca,qBAAA;AAAA,cAA+D,oBAAA;;;;cAE/D,eAAA,SAAwB,oBAGnC;AAAA,cAAG,qBAAA;;;;cAEQ,gBAAA,SAAyB,qBAGpC;AAAA,cAAG,sBAAA;;;;;cAEQ,iBAAA,SAA0B,sBAIrC;AAAA,cAAG,yBAAA;;;;cAEQ,oBAAA,SAA6B,yBAGxC;AAAA,cAEW,yBAAA,EAAyB,MAAA,CAAA,MAAA;EAAA;;;cAGpC,uBAAA;;;;;;;;;;;;;cAEW,kBAAA,SAA2B,uBAWtC;AAAA,cAEW,iBAAA,EAAiB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAoCjB,qBAAA,EAAqB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAmCrB,YAAA,EAAY,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { defineAction } from "../action.mjs";
|
|
2
|
+
import { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from "../http.mjs";
|
|
3
|
+
import { ActionResult } from "../result.mjs";
|
|
4
|
+
import { googleAuthorizationHeaders } from "./oauth.mjs";
|
|
5
|
+
import { appendNumberSearchParam, appendSearchParam, isSuccessStatus, providerFailureFromResponse, resolveGoogleAccessToken } from "./shared.mjs";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
//#region src/google/gmail.ts
|
|
9
|
+
const googleGmailApiBaseUrl = "https://gmail.googleapis.com/gmail/v1";
|
|
10
|
+
var GmailMessageRef = class extends Schema.Class("GmailMessageRef")({
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
threadId: Schema.optional(Schema.String)
|
|
13
|
+
}) {};
|
|
14
|
+
var GmailSearchInput = class extends Schema.Class("GmailSearchInput")({
|
|
15
|
+
query: Schema.optional(Schema.String),
|
|
16
|
+
maxResults: Schema.optional(Schema.Number)
|
|
17
|
+
}) {};
|
|
18
|
+
var GmailSearchOutput = class extends Schema.Class("GmailSearchOutput")({
|
|
19
|
+
messages: Schema.optional(Schema.Array(GmailMessageRef)),
|
|
20
|
+
nextPageToken: Schema.optional(Schema.String),
|
|
21
|
+
resultSizeEstimate: Schema.optional(Schema.Number)
|
|
22
|
+
}) {};
|
|
23
|
+
var GmailGetMessageInput = class extends Schema.Class("GmailGetMessageInput")({
|
|
24
|
+
id: Schema.String,
|
|
25
|
+
format: Schema.optional(Schema.Literals([
|
|
26
|
+
"minimal",
|
|
27
|
+
"full",
|
|
28
|
+
"raw",
|
|
29
|
+
"metadata"
|
|
30
|
+
]))
|
|
31
|
+
}) {};
|
|
32
|
+
const GmailMessagePayloadHeader = Schema.Struct({
|
|
33
|
+
name: Schema.String,
|
|
34
|
+
value: Schema.String
|
|
35
|
+
});
|
|
36
|
+
var GmailMessageOutput = class extends Schema.Class("GmailMessageOutput")({
|
|
37
|
+
id: Schema.String,
|
|
38
|
+
threadId: Schema.optional(Schema.String),
|
|
39
|
+
snippet: Schema.optional(Schema.String),
|
|
40
|
+
labelIds: Schema.optional(Schema.Array(Schema.String)),
|
|
41
|
+
payload: Schema.optional(Schema.Struct({ headers: Schema.optional(Schema.Array(GmailMessagePayloadHeader)) })),
|
|
42
|
+
raw: Schema.optional(Schema.String)
|
|
43
|
+
}) {};
|
|
44
|
+
const gmailSearchAction = defineAction({
|
|
45
|
+
id: "gmail.search",
|
|
46
|
+
description: "Search Gmail messages for the integration account.",
|
|
47
|
+
inputSchema: GmailSearchInput,
|
|
48
|
+
outputSchema: GmailSearchOutput,
|
|
49
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
50
|
+
const token = yield* resolveGoogleAccessToken(integration);
|
|
51
|
+
const http = yield* ConnectorHttpClient;
|
|
52
|
+
const params = new URLSearchParams();
|
|
53
|
+
appendSearchParam(params, "q", input.query);
|
|
54
|
+
appendNumberSearchParam(params, "maxResults", input.maxResults);
|
|
55
|
+
const query = params.toString();
|
|
56
|
+
const url = `${googleGmailApiBaseUrl}/users/me/messages${query === "" ? "" : `?${query}`}`;
|
|
57
|
+
const response = yield* http.request(ConnectorHttpRequest.make({
|
|
58
|
+
method: "GET",
|
|
59
|
+
url,
|
|
60
|
+
headers: googleAuthorizationHeaders(token)
|
|
61
|
+
}));
|
|
62
|
+
if (!isSuccessStatus(response.status)) return providerFailureFromResponse({
|
|
63
|
+
code: "gmail_search_failed",
|
|
64
|
+
message: "Gmail search failed",
|
|
65
|
+
status: response.status,
|
|
66
|
+
body: response.body
|
|
67
|
+
});
|
|
68
|
+
const output = yield* decodeJsonResponse(GmailSearchOutput, response);
|
|
69
|
+
return ActionResult.success(output);
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
const gmailGetMessageAction = defineAction({
|
|
73
|
+
id: "gmail.get_message",
|
|
74
|
+
description: "Get a Gmail message by id for the integration account.",
|
|
75
|
+
inputSchema: GmailGetMessageInput,
|
|
76
|
+
outputSchema: GmailMessageOutput,
|
|
77
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
78
|
+
const token = yield* resolveGoogleAccessToken(integration);
|
|
79
|
+
const http = yield* ConnectorHttpClient;
|
|
80
|
+
const params = new URLSearchParams();
|
|
81
|
+
appendSearchParam(params, "format", input.format);
|
|
82
|
+
const query = params.toString();
|
|
83
|
+
const url = `${googleGmailApiBaseUrl}/users/me/messages/${encodeURIComponent(input.id)}${query === "" ? "" : `?${query}`}`;
|
|
84
|
+
const response = yield* http.request(ConnectorHttpRequest.make({
|
|
85
|
+
method: "GET",
|
|
86
|
+
url,
|
|
87
|
+
headers: googleAuthorizationHeaders(token)
|
|
88
|
+
}));
|
|
89
|
+
if (!isSuccessStatus(response.status)) return providerFailureFromResponse({
|
|
90
|
+
code: "gmail_get_message_failed",
|
|
91
|
+
message: "Gmail get message failed",
|
|
92
|
+
status: response.status,
|
|
93
|
+
body: response.body
|
|
94
|
+
});
|
|
95
|
+
const output = yield* decodeJsonResponse(GmailMessageOutput, response);
|
|
96
|
+
return ActionResult.success(output);
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
const gmailActions = [gmailSearchAction, gmailGetMessageAction];
|
|
100
|
+
//#endregion
|
|
101
|
+
export { GmailGetMessageInput, GmailMessageOutput, GmailMessagePayloadHeader, GmailMessageRef, GmailSearchInput, GmailSearchOutput, gmailActions, gmailGetMessageAction, gmailSearchAction, googleGmailApiBaseUrl };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=gmail.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmail.mjs","names":[],"sources":["../../src/google/gmail.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { defineAction } from '../action.ts'\nimport { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from '../http.ts'\nimport { ActionResult } from '../result.ts'\nimport { googleAuthorizationHeaders } from './oauth.ts'\nimport {\n appendNumberSearchParam,\n appendSearchParam,\n isSuccessStatus,\n providerFailureFromResponse,\n resolveGoogleAccessToken\n} from './shared.ts'\n\nexport const googleGmailApiBaseUrl = 'https://gmail.googleapis.com/gmail/v1'\n\nexport class GmailMessageRef extends Schema.Class<GmailMessageRef>('GmailMessageRef')({\n id: Schema.String,\n threadId: Schema.optional(Schema.String)\n}) {}\n\nexport class GmailSearchInput extends Schema.Class<GmailSearchInput>('GmailSearchInput')({\n query: Schema.optional(Schema.String),\n maxResults: Schema.optional(Schema.Number)\n}) {}\n\nexport class GmailSearchOutput extends Schema.Class<GmailSearchOutput>('GmailSearchOutput')({\n messages: Schema.optional(Schema.Array(GmailMessageRef)),\n nextPageToken: Schema.optional(Schema.String),\n resultSizeEstimate: Schema.optional(Schema.Number)\n}) {}\n\nexport class GmailGetMessageInput extends Schema.Class<GmailGetMessageInput>('GmailGetMessageInput')({\n id: Schema.String,\n format: Schema.optional(Schema.Literals(['minimal', 'full', 'raw', 'metadata']))\n}) {}\n\nexport const GmailMessagePayloadHeader = Schema.Struct({\n name: Schema.String,\n value: Schema.String\n})\n\nexport class GmailMessageOutput extends Schema.Class<GmailMessageOutput>('GmailMessageOutput')({\n id: Schema.String,\n threadId: Schema.optional(Schema.String),\n snippet: Schema.optional(Schema.String),\n labelIds: Schema.optional(Schema.Array(Schema.String)),\n payload: Schema.optional(\n Schema.Struct({\n headers: Schema.optional(Schema.Array(GmailMessagePayloadHeader))\n })\n ),\n raw: Schema.optional(Schema.String)\n}) {}\n\nexport const gmailSearchAction = defineAction({\n id: 'gmail.search',\n description: 'Search Gmail messages for the integration account.',\n inputSchema: GmailSearchInput,\n outputSchema: GmailSearchOutput,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveGoogleAccessToken(integration)\n const http = yield* ConnectorHttpClient\n const params = new URLSearchParams()\n appendSearchParam(params, 'q', input.query)\n appendNumberSearchParam(params, 'maxResults', input.maxResults)\n const query = params.toString()\n const url = `${googleGmailApiBaseUrl}/users/me/messages${query === '' ? '' : `?${query}`}`\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'GET',\n url,\n headers: googleAuthorizationHeaders(token)\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return providerFailureFromResponse({\n code: 'gmail_search_failed',\n message: 'Gmail search failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(GmailSearchOutput, response)\n return ActionResult.success(output)\n })\n})\n\nexport const gmailGetMessageAction = defineAction({\n id: 'gmail.get_message',\n description: 'Get a Gmail message by id for the integration account.',\n inputSchema: GmailGetMessageInput,\n outputSchema: GmailMessageOutput,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveGoogleAccessToken(integration)\n const http = yield* ConnectorHttpClient\n const params = new URLSearchParams()\n appendSearchParam(params, 'format', input.format)\n const query = params.toString()\n const url = `${googleGmailApiBaseUrl}/users/me/messages/${encodeURIComponent(input.id)}${query === '' ? '' : `?${query}`}`\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'GET',\n url,\n headers: googleAuthorizationHeaders(token)\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return providerFailureFromResponse({\n code: 'gmail_get_message_failed',\n message: 'Gmail get message failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(GmailMessageOutput, response)\n return ActionResult.success(output)\n })\n})\n\nexport const gmailActions = [gmailSearchAction, gmailGetMessageAction]\n"],"mappings":";;;;;;;;AAcA,MAAa,wBAAwB;AAErC,IAAa,kBAAb,cAAqC,OAAO,MAAuB,iBAAiB,EAAE;CACpF,IAAI,OAAO;CACX,UAAU,OAAO,SAAS,OAAO,MAAM;AACzC,CAAC,EAAE,CAAC;AAEJ,IAAa,mBAAb,cAAsC,OAAO,MAAwB,kBAAkB,EAAE;CACvF,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,YAAY,OAAO,SAAS,OAAO,MAAM;AAC3C,CAAC,EAAE,CAAC;AAEJ,IAAa,oBAAb,cAAuC,OAAO,MAAyB,mBAAmB,EAAE;CAC1F,UAAU,OAAO,SAAS,OAAO,MAAM,eAAe,CAAC;CACvD,eAAe,OAAO,SAAS,OAAO,MAAM;CAC5C,oBAAoB,OAAO,SAAS,OAAO,MAAM;AACnD,CAAC,EAAE,CAAC;AAEJ,IAAa,uBAAb,cAA0C,OAAO,MAA4B,sBAAsB,EAAE;CACnG,IAAI,OAAO;CACX,QAAQ,OAAO,SAAS,OAAO,SAAS;EAAC;EAAW;EAAQ;EAAO;CAAU,CAAC,CAAC;AACjF,CAAC,EAAE,CAAC;AAEJ,MAAa,4BAA4B,OAAO,OAAO;CACrD,MAAM,OAAO;CACb,OAAO,OAAO;AAChB,CAAC;AAED,IAAa,qBAAb,cAAwC,OAAO,MAA0B,oBAAoB,EAAE;CAC7F,IAAI,OAAO;CACX,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,UAAU,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC;CACr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mB,MAAM,EAAE,IAAI,UAAU,KAAK,KAAK,IAAI;EACjH,MAAM,WAAW,OAAO,KAAK,QAC3B,qBAAqB,KAAK;GACxB,QAAQ;GACR;GACA,SAAS,2BAA2B,KAAK;EAC3C,CAAC,CACH;EAEA,IAAI,CAAC,gBAAgB,SAAS,MAAM,GAClC,OAAO,4BAA4B;GACjC,MAAM;GACN,SAAS;GACT,QAAQ,SAAS;GACjB,MAAM,SAAS;EACjB,CAAC;EAGH,MAAM,SAAS,OAAO,mBAAmB,oBAAoB,QAAQ;EACrE,OAAO,aAAa,QAAQ,MAAM;CACpC,CAAC;AACL,CAAC;AAED,MAAa,eAAe,CAAC,mBAAmB,qBAAqB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConnectorError } from "../error.mjs";
|
|
2
|
+
import { CredentialResolver } from "../credential.mjs";
|
|
3
|
+
import { Connector } from "../connector.mjs";
|
|
4
|
+
import { ConnectorHttpClient } from "../http.mjs";
|
|
5
|
+
import { GoogleCalendarCreateEventInput, GoogleCalendarEvent, GoogleCalendarEventDateTime, GoogleCalendarListEventsInput, GoogleCalendarListEventsOutput, googleCalendarActions, googleCalendarApiBaseUrl, googleCalendarCreateEventAction, googleCalendarListEventsAction } from "./calendar.mjs";
|
|
6
|
+
import { GmailGetMessageInput, GmailMessageOutput, GmailMessageRef, GmailSearchInput, GmailSearchOutput, gmailActions, gmailGetMessageAction, gmailSearchAction, googleGmailApiBaseUrl } from "./gmail.mjs";
|
|
7
|
+
import { GoogleOAuthCredentialSlot, googleAuthorizationHeaders, googleCalendarEventsScope, googleCalendarReadonlyScope, googleConnectorId, googleGmailReadonlyScope, googleGmailSendScope, googleOAuthAuthorizeUrl, googleOAuthSlotId, googleOAuthTokenUrl } from "./oauth.mjs";
|
|
8
|
+
import { resolveGoogleAccessToken } from "./shared.mjs";
|
|
9
|
+
|
|
10
|
+
//#region src/google/index.d.ts
|
|
11
|
+
declare const GoogleConnector: Connector<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GmailGetMessageInput, GmailMessageOutput, GmailMessageRef, GmailSearchInput, GmailSearchOutput, GoogleCalendarCreateEventInput, GoogleCalendarEvent, GoogleCalendarEventDateTime, GoogleCalendarListEventsInput, GoogleCalendarListEventsOutput, GoogleConnector, GoogleOAuthCredentialSlot, gmailActions, gmailGetMessageAction, gmailSearchAction, googleAuthorizationHeaders, googleCalendarActions, googleCalendarApiBaseUrl, googleCalendarCreateEventAction, googleCalendarEventsScope, googleCalendarListEventsAction, googleCalendarReadonlyScope, googleConnectorId, googleGmailApiBaseUrl, googleGmailReadonlyScope, googleGmailSendScope, googleOAuthAuthorizeUrl, googleOAuthSlotId, googleOAuthTokenUrl, resolveGoogleAccessToken };
|
|
14
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/google/index.ts"],"mappings":";;;;;;;;;;cAyCa,eAAA,EAAe,SAAA,CAI1B,mBAAA,GAJ0B,kBAAA,EAAA,cAAA"}
|