@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,69 @@
|
|
|
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 { ConnectorHttpClient } from "../http.mjs";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
|
|
8
|
+
//#region src/notion/index.d.ts
|
|
9
|
+
declare const notionConnectorId = "notion";
|
|
10
|
+
declare const notionApiTokenSlotId = "notion.api_token";
|
|
11
|
+
declare const notionApiBaseUrl = "https://api.notion.com/v1";
|
|
12
|
+
declare const notionVersion = "2022-06-28";
|
|
13
|
+
declare const NotionApiTokenSlot: CredentialSlot;
|
|
14
|
+
declare const notionAuthorizationHeaders: (token: string) => {
|
|
15
|
+
authorization: string;
|
|
16
|
+
'notion-version': string;
|
|
17
|
+
};
|
|
18
|
+
declare const NotionRichText: Schema.Struct<{
|
|
19
|
+
readonly type: Schema.optional<Schema.String>;
|
|
20
|
+
readonly plain_text: Schema.optional<Schema.String>;
|
|
21
|
+
readonly href: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
22
|
+
}>;
|
|
23
|
+
declare const NotionTitleProperty: Schema.Struct<{
|
|
24
|
+
readonly title: Schema.$Array<Schema.Struct<{
|
|
25
|
+
readonly type: Schema.optional<Schema.String>;
|
|
26
|
+
readonly plain_text: Schema.optional<Schema.String>;
|
|
27
|
+
readonly href: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
28
|
+
}>>;
|
|
29
|
+
}>;
|
|
30
|
+
declare const NotionProperties: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
31
|
+
declare const NotionPage_base: Schema.Class<NotionPage, Schema.Struct<{
|
|
32
|
+
readonly id: Schema.String;
|
|
33
|
+
readonly object: Schema.String;
|
|
34
|
+
readonly url: Schema.optional<Schema.String>;
|
|
35
|
+
readonly archived: Schema.optional<Schema.Boolean>;
|
|
36
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
37
|
+
}>, {}>;
|
|
38
|
+
declare class NotionPage extends NotionPage_base {}
|
|
39
|
+
declare const NotionSearchInput_base: Schema.Class<NotionSearchInput, Schema.Struct<{
|
|
40
|
+
readonly query: Schema.optional<Schema.String>;
|
|
41
|
+
readonly pageSize: Schema.optional<Schema.Number>;
|
|
42
|
+
readonly startCursor: Schema.optional<Schema.String>;
|
|
43
|
+
}>, {}>;
|
|
44
|
+
declare class NotionSearchInput extends NotionSearchInput_base {}
|
|
45
|
+
declare const NotionSearchOutput_base: Schema.Class<NotionSearchOutput, Schema.Struct<{
|
|
46
|
+
readonly results: Schema.$Array<Schema.Unknown>;
|
|
47
|
+
readonly nextCursor: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
48
|
+
readonly hasMore: Schema.Boolean;
|
|
49
|
+
}>, {}>;
|
|
50
|
+
declare class NotionSearchOutput extends NotionSearchOutput_base {}
|
|
51
|
+
declare const NotionGetPageInput_base: Schema.Class<NotionGetPageInput, Schema.Struct<{
|
|
52
|
+
readonly pageId: Schema.String;
|
|
53
|
+
}>, {}>;
|
|
54
|
+
declare class NotionGetPageInput extends NotionGetPageInput_base {}
|
|
55
|
+
declare const NotionCreatePageInput_base: Schema.Class<NotionCreatePageInput, Schema.Struct<{
|
|
56
|
+
readonly parentPageId: Schema.optional<Schema.String>;
|
|
57
|
+
readonly parentDatabaseId: Schema.optional<Schema.String>;
|
|
58
|
+
readonly title: Schema.String;
|
|
59
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
60
|
+
}>, {}>;
|
|
61
|
+
declare class NotionCreatePageInput extends NotionCreatePageInput_base {}
|
|
62
|
+
declare const notionSearchAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
63
|
+
declare const notionGetPageAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
64
|
+
declare const notionCreatePageAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
65
|
+
declare const notionActions: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>[];
|
|
66
|
+
declare const NotionConnector: Connector<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { NotionApiTokenSlot, NotionConnector, NotionCreatePageInput, NotionGetPageInput, NotionPage, NotionProperties, NotionRichText, NotionSearchInput, NotionSearchOutput, NotionTitleProperty, notionActions, notionApiBaseUrl, notionApiTokenSlotId, notionAuthorizationHeaders, notionConnectorId, notionCreatePageAction, notionGetPageAction, notionSearchAction, notionVersion };
|
|
69
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/notion/index.ts"],"mappings":";;;;;;;;cASa,iBAAA;AAAA,cACA,oBAAA;AAAA,cACA,gBAAA;AAAA,cACA,aAAA;AAAA,cAEA,kBAAA,EAAkB,cAG7B;AAAA,cAEW,0BAAA,GAA8B,KAAA;;;;cAoC9B,cAAA,EAAc,MAAA,CAAA,MAAA;EAAA;;;;cAMd,mBAAA,EAAmB,MAAA,CAAA,MAAA;EAAA;;;;;;cAInB,gBAAA,EAAgB,MAAA,CAAA,OAAA,CAAA,MAAA,CAAA,MAAA,EAAA,MAAA,CAAA,OAAA;AAAA,cAA+C,eAAA;;;;;;;cAE/D,UAAA,SAAmB,eAM9B;AAAA,cAAG,sBAAA;;;;;cAEQ,iBAAA,SAA0B,sBAIrC;AAAA,cAAG,uBAAA;;;;;cAEQ,kBAAA,SAA2B,uBAItC;AAAA,cAAG,uBAAA;;;cAEQ,kBAAA,SAA2B,uBAEtC;AAAA,cAAG,0BAAA;;;;;;cAEQ,qBAAA,SAA8B,0BAKzC;AAAA,cAuBW,kBAAA,EAAkB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAuClB,mBAAA,EAAmB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cA+BnB,sBAAA,EAAsB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAsCtB,aAAA,EAAa,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAEb,eAAA,EAAe,SAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { defineAction } from "../action.mjs";
|
|
2
|
+
import { defineConnector } from "../connector.mjs";
|
|
3
|
+
import { CredentialSlot, resolveCredential } from "../credential.mjs";
|
|
4
|
+
import { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from "../http.mjs";
|
|
5
|
+
import { ActionResult, ProviderFailure } from "../result.mjs";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
//#region src/notion/index.ts
|
|
9
|
+
const notionConnectorId = "notion";
|
|
10
|
+
const notionApiTokenSlotId = "notion.api_token";
|
|
11
|
+
const notionApiBaseUrl = "https://api.notion.com/v1";
|
|
12
|
+
const notionVersion = "2022-06-28";
|
|
13
|
+
const NotionApiTokenSlot = CredentialSlot.make({
|
|
14
|
+
id: notionApiTokenSlotId,
|
|
15
|
+
kind: "api_key"
|
|
16
|
+
});
|
|
17
|
+
const notionAuthorizationHeaders = (token) => ({
|
|
18
|
+
authorization: `Bearer ${token}`,
|
|
19
|
+
"notion-version": notionVersion
|
|
20
|
+
});
|
|
21
|
+
const isSuccessStatus = (status) => status >= 200 && status < 300;
|
|
22
|
+
const notionProviderFailure = (input) => ActionResult.failure(new ProviderFailure({
|
|
23
|
+
code: input.code,
|
|
24
|
+
message: input.message,
|
|
25
|
+
status: input.status,
|
|
26
|
+
underlying: input.body
|
|
27
|
+
}));
|
|
28
|
+
const resolveNotionToken = (integration) => Effect.gen(function* () {
|
|
29
|
+
const credential = yield* resolveCredential(integration, NotionApiTokenSlot);
|
|
30
|
+
switch (credential._tag) {
|
|
31
|
+
case "ApiKeyCredential": return credential.key;
|
|
32
|
+
case "BearerTokenCredential": return credential.token;
|
|
33
|
+
case "OAuthCredential": return credential.accessToken;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const NotionRichText = Schema.Struct({
|
|
37
|
+
type: Schema.optional(Schema.String),
|
|
38
|
+
plain_text: Schema.optional(Schema.String),
|
|
39
|
+
href: Schema.optional(Schema.NullOr(Schema.String))
|
|
40
|
+
});
|
|
41
|
+
const NotionTitleProperty = Schema.Struct({ title: Schema.Array(NotionRichText) });
|
|
42
|
+
const NotionProperties = Schema.Record(Schema.String, Schema.Unknown);
|
|
43
|
+
var NotionPage = class extends Schema.Class("NotionPage")({
|
|
44
|
+
id: Schema.String,
|
|
45
|
+
object: Schema.String,
|
|
46
|
+
url: Schema.optional(Schema.String),
|
|
47
|
+
archived: Schema.optional(Schema.Boolean),
|
|
48
|
+
properties: Schema.optional(NotionProperties)
|
|
49
|
+
}) {};
|
|
50
|
+
var NotionSearchInput = class extends Schema.Class("NotionSearchInput")({
|
|
51
|
+
query: Schema.optional(Schema.String),
|
|
52
|
+
pageSize: Schema.optional(Schema.Number),
|
|
53
|
+
startCursor: Schema.optional(Schema.String)
|
|
54
|
+
}) {};
|
|
55
|
+
var NotionSearchOutput = class extends Schema.Class("NotionSearchOutput")({
|
|
56
|
+
results: Schema.Array(Schema.Unknown),
|
|
57
|
+
nextCursor: Schema.optional(Schema.NullOr(Schema.String)),
|
|
58
|
+
hasMore: Schema.Boolean
|
|
59
|
+
}) {};
|
|
60
|
+
var NotionGetPageInput = class extends Schema.Class("NotionGetPageInput")({ pageId: Schema.String }) {};
|
|
61
|
+
var NotionCreatePageInput = class extends Schema.Class("NotionCreatePageInput")({
|
|
62
|
+
parentPageId: Schema.optional(Schema.String),
|
|
63
|
+
parentDatabaseId: Schema.optional(Schema.String),
|
|
64
|
+
title: Schema.String,
|
|
65
|
+
properties: Schema.optional(NotionProperties)
|
|
66
|
+
}) {};
|
|
67
|
+
const pageParent = (input) => {
|
|
68
|
+
if (input.parentDatabaseId !== void 0) return { database_id: input.parentDatabaseId };
|
|
69
|
+
return { page_id: input.parentPageId ?? "" };
|
|
70
|
+
};
|
|
71
|
+
const pageProperties = (input) => ({
|
|
72
|
+
...input.properties,
|
|
73
|
+
title: { title: [{ text: { content: input.title } }] }
|
|
74
|
+
});
|
|
75
|
+
const notionSearchAction = defineAction({
|
|
76
|
+
id: "notion.search",
|
|
77
|
+
description: "Search pages and databases available to the Notion integration.",
|
|
78
|
+
inputSchema: NotionSearchInput,
|
|
79
|
+
outputSchema: NotionSearchOutput,
|
|
80
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
81
|
+
const token = yield* resolveNotionToken(integration);
|
|
82
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
83
|
+
method: "POST",
|
|
84
|
+
url: `${notionApiBaseUrl}/search`,
|
|
85
|
+
headers: {
|
|
86
|
+
...notionAuthorizationHeaders(token),
|
|
87
|
+
"content-type": "application/json"
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
query: input.query,
|
|
91
|
+
page_size: input.pageSize,
|
|
92
|
+
start_cursor: input.startCursor
|
|
93
|
+
})
|
|
94
|
+
}));
|
|
95
|
+
if (!isSuccessStatus(response.status)) return notionProviderFailure({
|
|
96
|
+
code: "notion_search_failed",
|
|
97
|
+
message: "Notion search failed",
|
|
98
|
+
status: response.status,
|
|
99
|
+
body: response.body
|
|
100
|
+
});
|
|
101
|
+
const output = yield* decodeJsonResponse(NotionSearchOutput, response);
|
|
102
|
+
return ActionResult.success(output);
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
const notionGetPageAction = defineAction({
|
|
106
|
+
id: "notion.get_page",
|
|
107
|
+
description: "Get a Notion page by id.",
|
|
108
|
+
inputSchema: NotionGetPageInput,
|
|
109
|
+
outputSchema: NotionPage,
|
|
110
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
111
|
+
const token = yield* resolveNotionToken(integration);
|
|
112
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
113
|
+
method: "GET",
|
|
114
|
+
url: `${notionApiBaseUrl}/pages/${encodeURIComponent(input.pageId)}`,
|
|
115
|
+
headers: notionAuthorizationHeaders(token)
|
|
116
|
+
}));
|
|
117
|
+
if (!isSuccessStatus(response.status)) return notionProviderFailure({
|
|
118
|
+
code: "notion_get_page_failed",
|
|
119
|
+
message: "Notion get page failed",
|
|
120
|
+
status: response.status,
|
|
121
|
+
body: response.body
|
|
122
|
+
});
|
|
123
|
+
const output = yield* decodeJsonResponse(NotionPage, response);
|
|
124
|
+
return ActionResult.success(output);
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
const notionCreatePageAction = defineAction({
|
|
128
|
+
id: "notion.create_page",
|
|
129
|
+
description: "Create a Notion page under a parent page or database.",
|
|
130
|
+
inputSchema: NotionCreatePageInput,
|
|
131
|
+
outputSchema: NotionPage,
|
|
132
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
133
|
+
const token = yield* resolveNotionToken(integration);
|
|
134
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
135
|
+
method: "POST",
|
|
136
|
+
url: `${notionApiBaseUrl}/pages`,
|
|
137
|
+
headers: {
|
|
138
|
+
...notionAuthorizationHeaders(token),
|
|
139
|
+
"content-type": "application/json"
|
|
140
|
+
},
|
|
141
|
+
body: JSON.stringify({
|
|
142
|
+
parent: pageParent(input),
|
|
143
|
+
properties: pageProperties(input)
|
|
144
|
+
})
|
|
145
|
+
}));
|
|
146
|
+
if (!isSuccessStatus(response.status)) return notionProviderFailure({
|
|
147
|
+
code: "notion_create_page_failed",
|
|
148
|
+
message: "Notion create page failed",
|
|
149
|
+
status: response.status,
|
|
150
|
+
body: response.body
|
|
151
|
+
});
|
|
152
|
+
const output = yield* decodeJsonResponse(NotionPage, response);
|
|
153
|
+
return ActionResult.success(output);
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
const notionActions = [
|
|
157
|
+
notionSearchAction,
|
|
158
|
+
notionGetPageAction,
|
|
159
|
+
notionCreatePageAction
|
|
160
|
+
];
|
|
161
|
+
const NotionConnector = defineConnector({
|
|
162
|
+
id: notionConnectorId,
|
|
163
|
+
description: "Notion page and search connector actions.",
|
|
164
|
+
actions: notionActions
|
|
165
|
+
});
|
|
166
|
+
//#endregion
|
|
167
|
+
export { NotionApiTokenSlot, NotionConnector, NotionCreatePageInput, NotionGetPageInput, NotionPage, NotionProperties, NotionRichText, NotionSearchInput, NotionSearchOutput, NotionTitleProperty, notionActions, notionApiBaseUrl, notionApiTokenSlotId, notionAuthorizationHeaders, notionConnectorId, notionCreatePageAction, notionGetPageAction, notionSearchAction, notionVersion };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/notion/index.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { defineAction } from '../action.ts'\nimport { defineConnector } from '../connector.ts'\nimport { CredentialSlot, resolveCredential } from '../credential.ts'\nimport { ConnectorHttpClient, ConnectorHttpRequest, decodeJsonResponse } from '../http.ts'\nimport { ActionResult, ProviderFailure } from '../result.ts'\nimport type { ConnectorIntegration } from '../integration.ts'\n\nexport const notionConnectorId = 'notion'\nexport const notionApiTokenSlotId = 'notion.api_token'\nexport const notionApiBaseUrl = 'https://api.notion.com/v1'\nexport const notionVersion = '2022-06-28'\n\nexport const NotionApiTokenSlot = CredentialSlot.make({\n id: notionApiTokenSlotId,\n kind: 'api_key'\n})\n\nexport const notionAuthorizationHeaders = (token: string) => ({\n authorization: `Bearer ${token}`,\n 'notion-version': notionVersion\n})\n\nconst isSuccessStatus = (status: number) => status >= 200 && status < 300\n\nconst notionProviderFailure = (input: {\n readonly code: string\n readonly message: string\n readonly status: number\n readonly body: string\n}) =>\n ActionResult.failure(\n new ProviderFailure({\n code: input.code,\n message: input.message,\n status: input.status,\n underlying: input.body\n })\n )\n\nconst resolveNotionToken = (integration: ConnectorIntegration) =>\n Effect.gen(function* () {\n const credential = yield* resolveCredential(integration, NotionApiTokenSlot)\n\n switch (credential._tag) {\n case 'ApiKeyCredential':\n return credential.key\n case 'BearerTokenCredential':\n return credential.token\n case 'OAuthCredential':\n return credential.accessToken\n }\n })\n\nexport const NotionRichText = Schema.Struct({\n type: Schema.optional(Schema.String),\n plain_text: Schema.optional(Schema.String),\n href: Schema.optional(Schema.NullOr(Schema.String))\n})\n\nexport const NotionTitleProperty = Schema.Struct({\n title: Schema.Array(NotionRichText)\n})\n\nexport const NotionProperties = Schema.Record(Schema.String, Schema.Unknown)\n\nexport class NotionPage extends Schema.Class<NotionPage>('NotionPage')({\n id: Schema.String,\n object: Schema.String,\n url: Schema.optional(Schema.String),\n archived: Schema.optional(Schema.Boolean),\n properties: Schema.optional(NotionProperties)\n}) {}\n\nexport class NotionSearchInput extends Schema.Class<NotionSearchInput>('NotionSearchInput')({\n query: Schema.optional(Schema.String),\n pageSize: Schema.optional(Schema.Number),\n startCursor: Schema.optional(Schema.String)\n}) {}\n\nexport class NotionSearchOutput extends Schema.Class<NotionSearchOutput>('NotionSearchOutput')({\n results: Schema.Array(Schema.Unknown),\n nextCursor: Schema.optional(Schema.NullOr(Schema.String)),\n hasMore: Schema.Boolean\n}) {}\n\nexport class NotionGetPageInput extends Schema.Class<NotionGetPageInput>('NotionGetPageInput')({\n pageId: Schema.String\n}) {}\n\nexport class NotionCreatePageInput extends Schema.Class<NotionCreatePageInput>('NotionCreatePageInput')({\n parentPageId: Schema.optional(Schema.String),\n parentDatabaseId: Schema.optional(Schema.String),\n title: Schema.String,\n properties: Schema.optional(NotionProperties)\n}) {}\n\nconst pageParent = (input: NotionCreatePageInput) => {\n if (input.parentDatabaseId !== undefined) {\n return { database_id: input.parentDatabaseId }\n }\n\n return { page_id: input.parentPageId ?? '' }\n}\n\nconst pageProperties = (input: NotionCreatePageInput) => ({\n ...input.properties,\n title: {\n title: [\n {\n text: {\n content: input.title\n }\n }\n ]\n }\n})\n\nexport const notionSearchAction = defineAction({\n id: 'notion.search',\n description: 'Search pages and databases available to the Notion integration.',\n inputSchema: NotionSearchInput,\n outputSchema: NotionSearchOutput,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveNotionToken(integration)\n const http = yield* ConnectorHttpClient\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'POST',\n url: `${notionApiBaseUrl}/search`,\n headers: {\n ...notionAuthorizationHeaders(token),\n 'content-type': 'application/json'\n },\n body: JSON.stringify({\n query: input.query,\n page_size: input.pageSize,\n start_cursor: input.startCursor\n })\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return notionProviderFailure({\n code: 'notion_search_failed',\n message: 'Notion search failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(NotionSearchOutput, response)\n return ActionResult.success(output)\n })\n})\n\nexport const notionGetPageAction = defineAction({\n id: 'notion.get_page',\n description: 'Get a Notion page by id.',\n inputSchema: NotionGetPageInput,\n outputSchema: NotionPage,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveNotionToken(integration)\n const http = yield* ConnectorHttpClient\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'GET',\n url: `${notionApiBaseUrl}/pages/${encodeURIComponent(input.pageId)}`,\n headers: notionAuthorizationHeaders(token)\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return notionProviderFailure({\n code: 'notion_get_page_failed',\n message: 'Notion get page failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(NotionPage, response)\n return ActionResult.success(output)\n })\n})\n\nexport const notionCreatePageAction = defineAction({\n id: 'notion.create_page',\n description: 'Create a Notion page under a parent page or database.',\n inputSchema: NotionCreatePageInput,\n outputSchema: NotionPage,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const token = yield* resolveNotionToken(integration)\n const http = yield* ConnectorHttpClient\n const response = yield* http.request(\n ConnectorHttpRequest.make({\n method: 'POST',\n url: `${notionApiBaseUrl}/pages`,\n headers: {\n ...notionAuthorizationHeaders(token),\n 'content-type': 'application/json'\n },\n body: JSON.stringify({\n parent: pageParent(input),\n properties: pageProperties(input)\n })\n })\n )\n\n if (!isSuccessStatus(response.status)) {\n return notionProviderFailure({\n code: 'notion_create_page_failed',\n message: 'Notion create page failed',\n status: response.status,\n body: response.body\n })\n }\n\n const output = yield* decodeJsonResponse(NotionPage, response)\n return ActionResult.success(output)\n })\n})\n\nexport const notionActions = [notionSearchAction, notionGetPageAction, notionCreatePageAction]\n\nexport const NotionConnector = defineConnector({\n id: notionConnectorId,\n description: 'Notion page and search connector actions.',\n actions: notionActions\n})\n"],"mappings":";;;;;;;;AASA,MAAa,oBAAoB;AACjC,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAE7B,MAAa,qBAAqB,eAAe,KAAK;CACpD,IAAI;CACJ,MAAM;AACR,CAAC;AAED,MAAa,8BAA8B,WAAmB;CAC5D,eAAe,UAAU;CACzB,kBAAkB;AACpB;AAEA,MAAM,mBAAmB,WAAmB,UAAU,OAAO,SAAS;AAEtE,MAAM,yBAAyB,UAM7B,aAAa,QACX,IAAI,gBAAgB;CAClB,MAAM,MAAM;CACZ,SAAS,MAAM;CACf,QAAQ,MAAM;CACd,YAAY,MAAM;AACpB,CAAC,CACH;AAEF,MAAM,sBAAsB,gBAC1B,OA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|
+
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 { Context, Effect } from "effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
|
|
8
|
+
//#region src/r2-storage/index.d.ts
|
|
9
|
+
declare const r2StorageConnectorId = "r2-storage";
|
|
10
|
+
declare const r2AccessKeyIdSlotId = "r2-storage.access_key_id";
|
|
11
|
+
declare const r2SecretAccessKeySlotId = "r2-storage.secret_access_key";
|
|
12
|
+
declare const R2AccessKeyIdSlot: CredentialSlot;
|
|
13
|
+
declare const R2SecretAccessKeySlot: CredentialSlot;
|
|
14
|
+
declare const R2PresignInput_base: Schema.Class<R2PresignInput, Schema.Struct<{
|
|
15
|
+
readonly endpoint: Schema.String;
|
|
16
|
+
readonly accessKeyId: Schema.String;
|
|
17
|
+
readonly secretAccessKey: Schema.String;
|
|
18
|
+
readonly bucket: Schema.String;
|
|
19
|
+
readonly key: Schema.String;
|
|
20
|
+
readonly contentType: Schema.String;
|
|
21
|
+
}>, {}>;
|
|
22
|
+
declare class R2PresignInput extends R2PresignInput_base {}
|
|
23
|
+
declare const R2PresignOutput_base: Schema.Class<R2PresignOutput, Schema.Struct<{
|
|
24
|
+
readonly uploadUrl: Schema.String;
|
|
25
|
+
}>, {}>;
|
|
26
|
+
declare class R2PresignOutput extends R2PresignOutput_base {}
|
|
27
|
+
type R2PresignerApi = {
|
|
28
|
+
readonly presignPutObject: (input: R2PresignInput) => Effect.Effect<R2PresignOutput, ConnectorError>;
|
|
29
|
+
};
|
|
30
|
+
declare const R2Presigner_base: Context.ServiceClass<R2Presigner, "@yolk-sdk/connectors/R2Presigner", R2PresignerApi>;
|
|
31
|
+
declare class R2Presigner extends R2Presigner_base {}
|
|
32
|
+
declare const R2UploadUrlInput_base: Schema.Class<R2UploadUrlInput, Schema.Struct<{
|
|
33
|
+
readonly filename: Schema.String;
|
|
34
|
+
readonly contentType: Schema.String;
|
|
35
|
+
}>, {}>;
|
|
36
|
+
declare class R2UploadUrlInput extends R2UploadUrlInput_base {}
|
|
37
|
+
declare const R2UploadUrlOutput_base: Schema.Class<R2UploadUrlOutput, Schema.Struct<{
|
|
38
|
+
readonly uploadUrl: Schema.String;
|
|
39
|
+
readonly publicUrl: Schema.String;
|
|
40
|
+
readonly key: Schema.String;
|
|
41
|
+
}>, {}>;
|
|
42
|
+
declare class R2UploadUrlOutput extends R2UploadUrlOutput_base {}
|
|
43
|
+
declare const r2StorageUploadUrlAction: ConnectorAction<CredentialResolver | R2Presigner, ConnectorError>;
|
|
44
|
+
declare const r2StorageActions: ConnectorAction<CredentialResolver | R2Presigner, ConnectorError>[];
|
|
45
|
+
declare const R2StorageConnector: Connector<CredentialResolver | R2Presigner, ConnectorError>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { R2AccessKeyIdSlot, R2PresignInput, R2PresignOutput, R2Presigner, R2PresignerApi, R2SecretAccessKeySlot, R2StorageConnector, R2UploadUrlInput, R2UploadUrlOutput, r2AccessKeyIdSlotId, r2SecretAccessKeySlotId, r2StorageActions, r2StorageConnectorId, r2StorageUploadUrlAction };
|
|
48
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/r2-storage/index.ts"],"mappings":";;;;;;;;cAUa,oBAAA;AAAA,cACA,mBAAA;AAAA,cACA,uBAAA;AAAA,cAEA,iBAAA,EAAiB,cAAoE;AAAA,cACrF,qBAAA,EAAqB,cAGhC;AAAA,cAAA,mBAAA;;;;;;;;cAEW,cAAA,SAAuB,mBAOlC;AAAA,cAAG,oBAAA;;;cAEQ,eAAA,SAAwB,oBAEnC;AAAA,KAEU,cAAA;EAAA,SACD,gBAAA,GAAmB,KAAA,EAAO,cAAA,KAAmB,MAAA,CAAO,MAAA,CAAO,eAAA,EAAiB,cAAA;AAAA;AAAA,cACtF,gBAAA;cAEY,WAAA,SAAoB,gBAEhC;AAAA,cAAG,qBAAA;;;;cA0BS,gBAAA,SAAyB,qBAGpC;AAAA,cAAG,sBAAA;;;;;cAEQ,iBAAA,SAA0B,sBAIrC;AAAA,cAEW,wBAAA,EAAwB,eAAA,CAiCnC,kBAAA,GAjCmC,WAAA,EAAA,cAAA;AAAA,cAmCxB,gBAAA,EAAgB,eAAA,CAA6B,kBAAA,GAA7B,WAAA,EAAA,cAAA;AAAA,cAEhB,kBAAA,EAAkB,SAAA,CAI7B,kBAAA,GAJ6B,WAAA,EAAA,cAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { defineAction } from "../action.mjs";
|
|
2
|
+
import { requiredStringConfig } from "../config.mjs";
|
|
3
|
+
import { defineConnector } from "../connector.mjs";
|
|
4
|
+
import { CredentialSlot, resolveCredential } from "../credential.mjs";
|
|
5
|
+
import { ActionResult } from "../result.mjs";
|
|
6
|
+
import { Context, Effect } from "effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
//#region src/r2-storage/index.ts
|
|
9
|
+
const r2StorageConnectorId = "r2-storage";
|
|
10
|
+
const r2AccessKeyIdSlotId = "r2-storage.access_key_id";
|
|
11
|
+
const r2SecretAccessKeySlotId = "r2-storage.secret_access_key";
|
|
12
|
+
const R2AccessKeyIdSlot = CredentialSlot.make({
|
|
13
|
+
id: r2AccessKeyIdSlotId,
|
|
14
|
+
kind: "api_key"
|
|
15
|
+
});
|
|
16
|
+
const R2SecretAccessKeySlot = CredentialSlot.make({
|
|
17
|
+
id: r2SecretAccessKeySlotId,
|
|
18
|
+
kind: "api_key"
|
|
19
|
+
});
|
|
20
|
+
var R2PresignInput = class extends Schema.Class("R2PresignInput")({
|
|
21
|
+
endpoint: Schema.String,
|
|
22
|
+
accessKeyId: Schema.String,
|
|
23
|
+
secretAccessKey: Schema.String,
|
|
24
|
+
bucket: Schema.String,
|
|
25
|
+
key: Schema.String,
|
|
26
|
+
contentType: Schema.String
|
|
27
|
+
}) {};
|
|
28
|
+
var R2PresignOutput = class extends Schema.Class("R2PresignOutput")({ uploadUrl: Schema.String }) {};
|
|
29
|
+
var R2Presigner = class extends Context.Service()("@yolk-sdk/connectors/R2Presigner") {};
|
|
30
|
+
const resolveApiToken = (integration, slot) => Effect.gen(function* () {
|
|
31
|
+
const credential = yield* resolveCredential(integration, slot);
|
|
32
|
+
switch (credential._tag) {
|
|
33
|
+
case "ApiKeyCredential": return credential.key;
|
|
34
|
+
case "BearerTokenCredential": return credential.token;
|
|
35
|
+
case "OAuthCredential": return credential.accessToken;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const joinPublicUrl = (publicUrl, key) => {
|
|
39
|
+
return `${publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl}/${key}`;
|
|
40
|
+
};
|
|
41
|
+
const safeObjectKey = (filename) => {
|
|
42
|
+
const trimmed = filename.trim().replace(/^\/+/, "");
|
|
43
|
+
return trimmed === "" ? `uploads/${Date.now()}` : trimmed;
|
|
44
|
+
};
|
|
45
|
+
var R2UploadUrlInput = class extends Schema.Class("R2UploadUrlInput")({
|
|
46
|
+
filename: Schema.String,
|
|
47
|
+
contentType: Schema.String
|
|
48
|
+
}) {};
|
|
49
|
+
var R2UploadUrlOutput = class extends Schema.Class("R2UploadUrlOutput")({
|
|
50
|
+
uploadUrl: Schema.String,
|
|
51
|
+
publicUrl: Schema.String,
|
|
52
|
+
key: Schema.String
|
|
53
|
+
}) {};
|
|
54
|
+
const r2StorageUploadUrlAction = defineAction({
|
|
55
|
+
id: "r2_storage.upload_url",
|
|
56
|
+
description: "Create a presigned R2 PUT upload URL.",
|
|
57
|
+
inputSchema: R2UploadUrlInput,
|
|
58
|
+
outputSchema: R2UploadUrlOutput,
|
|
59
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
60
|
+
const endpoint = yield* requiredStringConfig(integration, "endpoint");
|
|
61
|
+
const bucket = yield* requiredStringConfig(integration, "bucket");
|
|
62
|
+
const publicUrl = yield* requiredStringConfig(integration, "publicUrl");
|
|
63
|
+
const accessKeyId = yield* resolveApiToken(integration, R2AccessKeyIdSlot);
|
|
64
|
+
const secretAccessKey = yield* resolveApiToken(integration, R2SecretAccessKeySlot);
|
|
65
|
+
const presigner = yield* R2Presigner;
|
|
66
|
+
const key = safeObjectKey(input.filename);
|
|
67
|
+
const presigned = yield* presigner.presignPutObject(R2PresignInput.make({
|
|
68
|
+
endpoint,
|
|
69
|
+
accessKeyId,
|
|
70
|
+
secretAccessKey,
|
|
71
|
+
bucket,
|
|
72
|
+
key,
|
|
73
|
+
contentType: input.contentType
|
|
74
|
+
}));
|
|
75
|
+
return ActionResult.success(R2UploadUrlOutput.make({
|
|
76
|
+
uploadUrl: presigned.uploadUrl,
|
|
77
|
+
publicUrl: joinPublicUrl(publicUrl, key),
|
|
78
|
+
key
|
|
79
|
+
}));
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const r2StorageActions = [r2StorageUploadUrlAction];
|
|
83
|
+
const R2StorageConnector = defineConnector({
|
|
84
|
+
id: r2StorageConnectorId,
|
|
85
|
+
description: "Cloudflare R2 storage connector actions.",
|
|
86
|
+
actions: r2StorageActions
|
|
87
|
+
});
|
|
88
|
+
//#endregion
|
|
89
|
+
export { R2AccessKeyIdSlot, R2PresignInput, R2PresignOutput, R2Presigner, R2SecretAccessKeySlot, R2StorageConnector, R2UploadUrlInput, R2UploadUrlOutput, r2AccessKeyIdSlotId, r2SecretAccessKeySlotId, r2StorageActions, r2StorageConnectorId, r2StorageUploadUrlAction };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/r2-storage/index.ts"],"sourcesContent":["import { Context, Effect } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { defineAction } from '../action.ts'\nimport { requiredStringConfig } from '../config.ts'\nimport { defineConnector } from '../connector.ts'\nimport { CredentialSlot, resolveCredential } from '../credential.ts'\nimport { ActionResult } from '../result.ts'\nimport type { ConnectorError } from '../error.ts'\nimport type { ConnectorIntegration } from '../integration.ts'\n\nexport const r2StorageConnectorId = 'r2-storage'\nexport const r2AccessKeyIdSlotId = 'r2-storage.access_key_id'\nexport const r2SecretAccessKeySlotId = 'r2-storage.secret_access_key'\n\nexport const R2AccessKeyIdSlot = CredentialSlot.make({ id: r2AccessKeyIdSlotId, kind: 'api_key' })\nexport const R2SecretAccessKeySlot = CredentialSlot.make({\n id: r2SecretAccessKeySlotId,\n kind: 'api_key'\n})\n\nexport class R2PresignInput extends Schema.Class<R2PresignInput>('R2PresignInput')({\n endpoint: Schema.String,\n accessKeyId: Schema.String,\n secretAccessKey: Schema.String,\n bucket: Schema.String,\n key: Schema.String,\n contentType: Schema.String\n}) {}\n\nexport class R2PresignOutput extends Schema.Class<R2PresignOutput>('R2PresignOutput')({\n uploadUrl: Schema.String\n}) {}\n\nexport type R2PresignerApi = {\n readonly presignPutObject: (input: R2PresignInput) => Effect.Effect<R2PresignOutput, ConnectorError>\n}\n\nexport class R2Presigner extends Context.Service<R2Presigner, R2PresignerApi>()(\n '@yolk-sdk/connectors/R2Presigner'\n) {}\n\nconst resolveApiToken = (integration: ConnectorIntegration, slot: CredentialSlot) =>\n Effect.gen(function* () {\n const credential = yield* resolveCredential(integration, slot)\n\n switch (credential._tag) {\n case 'ApiKeyCredential':\n return credential.key\n case 'BearerTokenCredential':\n return credential.token\n case 'OAuthCredential':\n return credential.accessToken\n }\n })\n\nconst joinPublicUrl = (publicUrl: string, key: string) => {\n const base = publicUrl.endsWith('/') ? publicUrl.slice(0, -1) : publicUrl\n return `${base}/${key}`\n}\n\nconst safeObjectKey = (filename: string) => {\n const trimmed = filename.trim().replace(/^\\/+/, '')\n return trimmed === '' ? `uploads/${Date.now()}` : trimmed\n}\n\nexport class R2UploadUrlInput extends Schema.Class<R2UploadUrlInput>('R2UploadUrlInput')({\n filename: Schema.String,\n contentType: Schema.String\n}) {}\n\nexport class R2UploadUrlOutput extends Schema.Class<R2UploadUrlOutput>('R2UploadUrlOutput')({\n uploadUrl: Schema.String,\n publicUrl: Schema.String,\n key: Schema.String\n}) {}\n\nexport const r2StorageUploadUrlAction = defineAction({\n id: 'r2_storage.upload_url',\n description: 'Create a presigned R2 PUT upload URL.',\n inputSchema: R2UploadUrlInput,\n outputSchema: R2UploadUrlOutput,\n execute: ({ integration, input }) =>\n Effect.gen(function* () {\n const endpoint = yield* requiredStringConfig(integration, 'endpoint')\n const bucket = yield* requiredStringConfig(integration, 'bucket')\n const publicUrl = yield* requiredStringConfig(integration, 'publicUrl')\n const accessKeyId = yield* resolveApiToken(integration, R2AccessKeyIdSlot)\n const secretAccessKey = yield* resolveApiToken(integration, R2SecretAccessKeySlot)\n const presigner = yield* R2Presigner\n const key = safeObjectKey(input.filename)\n const presigned = yield* presigner.presignPutObject(\n R2PresignInput.make({\n endpoint,\n accessKeyId,\n secretAccessKey,\n bucket,\n key,\n contentType: input.contentType\n })\n )\n\n return ActionResult.success(\n R2UploadUrlOutput.make({\n uploadUrl: presigned.uploadUrl,\n publicUrl: joinPublicUrl(publicUrl, key),\n key\n })\n )\n })\n})\n\nexport const r2StorageActions = [r2StorageUploadUrlAction]\n\nexport const R2StorageConnector = defineConnector({\n id: r2StorageConnectorId,\n description: 'Cloudflare R2 storage connector actions.',\n actions: r2StorageActions\n})\n"],"mappings":";;;;;;;;AAUA,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,0BAA0B;AAEvC,MAAa,oBAAoB,eAAe,KAAK;CAAE,IAAI;CAAqB,MAAM;AAAU,CAAC;AACjG,MAAa,wBAAwB,eAAe,KAAK;CACvD,IAAI;CACJ,MAAM;AACR,CAAC;AAED,IAAa,iBAAb,cAAoC,OAAO,MAAsB,gBAAgB,EAAE;CACjF,UAAU,OAAO;CACjB,aAAa,OAAO;C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OAAO,qBAAqB,aAAa,WAAW;EACtE,MAAM,cAAc,OAAO,gBAAgB,aAAa,iBAAiB;EACzE,MAAM,kBAAkB,OAAO,gBAAgB,aAAa,qBAAqB;EACjF,MAAM,YAAY,OAAO;EACzB,MAAM,MAAM,cAAc,MAAM,QAAQ;EACxC,MAAM,YAAY,OAAO,UAAU,iBACjC,eAAe,KAAK;GAClB;GACA;GACA;GACA;GACA;GACA,aAAa,MAAM;EACrB,CAAC,CACH;EAEA,OAAO,aAAa,QAClB,kBAAkB,KAAK;GACrB,WAAW,UAAU;GACrB,WAAW,cAAc,WAAW,GAAG;GACvC;EACF,CAAC,CACH;CACF,CAAC;AACL,CAAC;AAED,MAAa,mBAAmB,CAAC,wBAAwB;AAEzD,MAAa,qBAAqB,gBAAgB;CAChD,IAAI;CACJ,aAAa;CACb,SAAS;AACX,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
|
|
3
|
+
//#region src/result.d.ts
|
|
4
|
+
declare const ProviderFailure_base: Schema.Class<ProviderFailure, Schema.Struct<{
|
|
5
|
+
readonly code: Schema.String;
|
|
6
|
+
readonly message: Schema.String;
|
|
7
|
+
readonly status: Schema.optional<Schema.Number>;
|
|
8
|
+
readonly retryAfterMs: Schema.optional<Schema.Number>;
|
|
9
|
+
readonly underlying: Schema.optional<Schema.Unknown>;
|
|
10
|
+
}>, {}>;
|
|
11
|
+
declare class ProviderFailure extends ProviderFailure_base {}
|
|
12
|
+
type ProviderFailureInput = {
|
|
13
|
+
readonly code: string;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
readonly status?: number;
|
|
16
|
+
readonly retryAfterMs?: number;
|
|
17
|
+
readonly underlying?: unknown;
|
|
18
|
+
};
|
|
19
|
+
type ActionResult<Output> = {
|
|
20
|
+
readonly _tag: 'Success';
|
|
21
|
+
readonly value: Output;
|
|
22
|
+
} | {
|
|
23
|
+
readonly _tag: 'Failure';
|
|
24
|
+
readonly error: ProviderFailure;
|
|
25
|
+
};
|
|
26
|
+
declare const ActionResult: {
|
|
27
|
+
success: <Output>(value: Output) => ActionResult<Output>;
|
|
28
|
+
failure: (failure: ProviderFailure | ProviderFailureInput) => ActionResult<never>;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ActionResult, ProviderFailure, ProviderFailureInput };
|
|
32
|
+
//# sourceMappingURL=result.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.mts","names":[],"sources":["../src/result.ts"],"mappings":";;;cAAuC,oBAAA;;;;;;;cAE1B,eAAA,SAAwB,oBAMnC;AAAA,KAEU,oBAAA;EAAA,SACD,IAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;EAAA,SACA,YAAA;EAAA,SACA,UAAA;AAAA;AAAA,KAGC,YAAA;EAAA,SAEG,IAAA;EAAA,SACA,KAAA,EAAO,MAAA;AAAA;EAAA,SAGP,IAAA;EAAA,SACA,KAAA,EAAO,eAAe;AAAA;AAAA,cAGxB,YAAA;oBACK,KAAA,EAAS,MAAA,KAAS,YAAA,CAAa,MAAA;qBAC5B,eAAA,GAAkB,oBAAA,KAAuB,YAAA;AAAA"}
|
package/dist/result.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/result.ts
|
|
3
|
+
var ProviderFailure = class extends Schema.Class("ProviderFailure")({
|
|
4
|
+
code: Schema.String,
|
|
5
|
+
message: Schema.String,
|
|
6
|
+
status: Schema.optional(Schema.Number),
|
|
7
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
8
|
+
underlying: Schema.optional(Schema.Unknown)
|
|
9
|
+
}) {};
|
|
10
|
+
const ActionResult = {
|
|
11
|
+
success: (value) => ({
|
|
12
|
+
_tag: "Success",
|
|
13
|
+
value
|
|
14
|
+
}),
|
|
15
|
+
failure: (failure) => ({
|
|
16
|
+
_tag: "Failure",
|
|
17
|
+
error: failure instanceof ProviderFailure ? failure : ProviderFailure.make(failure)
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ActionResult, ProviderFailure };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=result.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.mjs","names":[],"sources":["../src/result.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\n\nexport class ProviderFailure extends Schema.Class<ProviderFailure>('ProviderFailure')({\n code: Schema.String,\n message: Schema.String,\n status: Schema.optional(Schema.Number),\n retryAfterMs: Schema.optional(Schema.Number),\n underlying: Schema.optional(Schema.Unknown)\n}) {}\n\nexport type ProviderFailureInput = {\n readonly code: string\n readonly message: string\n readonly status?: number\n readonly retryAfterMs?: number\n readonly underlying?: unknown\n}\n\nexport type ActionResult<Output> =\n | {\n readonly _tag: 'Success'\n readonly value: Output\n }\n | {\n readonly _tag: 'Failure'\n readonly error: ProviderFailure\n }\n\nexport const ActionResult = {\n success: <Output>(value: Output): ActionResult<Output> => ({ _tag: 'Success', value }),\n failure: (failure: ProviderFailure | ProviderFailureInput): ActionResult<never> => ({\n _tag: 'Failure',\n error: failure instanceof ProviderFailure ? failure : ProviderFailure.make(failure)\n })\n}\n"],"mappings":";;AAEA,IAAa,kBAAb,cAAqC,OAAO,MAAuB,iBAAiB,EAAE;CACpF,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,cAAc,OAAO,SAAS,OAAO,MAAM;CAC3C,YAAY,OAAO,SAAS,OAAO,OAAO;AAC5C,CAAC,EAAE,CAAC;AAoBJ,MAAa,eAAe;CAC1B,UAAkB,WAAyC;EAAE,MAAM;EAAW;CAAM;CACpF,UAAU,aAA0E;EAClF,MAAM;EACN,OAAO,mBAAmB,kBAAkB,UAAU,gBAAgB,KAAK,OAAO;CACpF;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { ConnectorHttpClient } from "../http.mjs";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
|
|
8
|
+
//#region src/telegram/index.d.ts
|
|
9
|
+
declare const telegramConnectorId = "telegram";
|
|
10
|
+
declare const telegramBotTokenSlotId = "telegram.bot_token";
|
|
11
|
+
declare const telegramApiBaseUrl = "https://api.telegram.org";
|
|
12
|
+
declare const TelegramBotTokenSlot: CredentialSlot;
|
|
13
|
+
declare const TelegramSendMessageInput_base: Schema.Class<TelegramSendMessageInput, Schema.Struct<{
|
|
14
|
+
readonly message: Schema.String;
|
|
15
|
+
readonly disableWebPagePreview: Schema.optional<Schema.Boolean>;
|
|
16
|
+
}>, {}>;
|
|
17
|
+
declare class TelegramSendMessageInput extends TelegramSendMessageInput_base {}
|
|
18
|
+
declare const TelegramSendMessageOutput_base: Schema.Class<TelegramSendMessageOutput, Schema.Struct<{
|
|
19
|
+
readonly sent: Schema.Boolean;
|
|
20
|
+
readonly chatId: Schema.String;
|
|
21
|
+
}>, {}>;
|
|
22
|
+
declare class TelegramSendMessageOutput extends TelegramSendMessageOutput_base {}
|
|
23
|
+
declare const TelegramValidateOutput_base: Schema.Class<TelegramValidateOutput, Schema.Struct<{
|
|
24
|
+
readonly ok: Schema.Boolean;
|
|
25
|
+
readonly chatId: Schema.String;
|
|
26
|
+
}>, {}>;
|
|
27
|
+
declare class TelegramValidateOutput extends TelegramValidateOutput_base {}
|
|
28
|
+
declare const telegramSendMessageAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
29
|
+
declare const telegramValidateAction: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
30
|
+
declare const telegramActions: ConnectorAction<ConnectorHttpClient | CredentialResolver, ConnectorError>[];
|
|
31
|
+
declare const TelegramConnector: Connector<ConnectorHttpClient | CredentialResolver, ConnectorError>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { TelegramBotTokenSlot, TelegramConnector, TelegramSendMessageInput, TelegramSendMessageOutput, TelegramValidateOutput, telegramActions, telegramApiBaseUrl, telegramBotTokenSlotId, telegramConnectorId, telegramSendMessageAction, telegramValidateAction };
|
|
34
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/telegram/index.ts"],"mappings":";;;;;;;;cAUa,mBAAA;AAAA,cACA,sBAAA;AAAA,cACA,kBAAA;AAAA,cAEA,oBAAA,EAAoB,cAG/B;AAAA,cAAA,6BAAA;;;;cAiCW,wBAAA,SAAiC,6BAK5C;AAAA,cAAG,8BAAA;;;;cAEQ,yBAAA,SAAkC,8BAK7C;AAAA,cAAG,2BAAA;;;;cAEQ,sBAAA,SAA+B,2BAG1C;AAAA,cAEW,yBAAA,EAAyB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAoCzB,sBAAA,EAAsB,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAgCtB,eAAA,EAAe,eAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA;AAAA,cAEf,iBAAA,EAAiB,SAAA,CAAA,mBAAA,GAAA,kBAAA,EAAA,cAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { defineAction } from "../action.mjs";
|
|
2
|
+
import { requiredStringConfig } from "../config.mjs";
|
|
3
|
+
import { defineConnector } from "../connector.mjs";
|
|
4
|
+
import { CredentialSlot, resolveCredential } from "../credential.mjs";
|
|
5
|
+
import { ConnectorHttpClient, ConnectorHttpRequest } from "../http.mjs";
|
|
6
|
+
import { ActionResult, ProviderFailure } from "../result.mjs";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
//#region src/telegram/index.ts
|
|
10
|
+
const telegramConnectorId = "telegram";
|
|
11
|
+
const telegramBotTokenSlotId = "telegram.bot_token";
|
|
12
|
+
const telegramApiBaseUrl = "https://api.telegram.org";
|
|
13
|
+
const TelegramBotTokenSlot = CredentialSlot.make({
|
|
14
|
+
id: telegramBotTokenSlotId,
|
|
15
|
+
kind: "api_key"
|
|
16
|
+
});
|
|
17
|
+
const resolveTelegramBotToken = (integration) => Effect.gen(function* () {
|
|
18
|
+
const credential = yield* resolveCredential(integration, TelegramBotTokenSlot);
|
|
19
|
+
switch (credential._tag) {
|
|
20
|
+
case "ApiKeyCredential": return credential.key;
|
|
21
|
+
case "BearerTokenCredential": return credential.token;
|
|
22
|
+
case "OAuthCredential": return credential.accessToken;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const isSuccessStatus = (status) => status >= 200 && status < 300;
|
|
26
|
+
const telegramProviderFailure = (input) => ActionResult.failure(new ProviderFailure({
|
|
27
|
+
code: input.code,
|
|
28
|
+
message: input.message,
|
|
29
|
+
status: input.status,
|
|
30
|
+
underlying: input.body
|
|
31
|
+
}));
|
|
32
|
+
var TelegramSendMessageInput = class extends Schema.Class("TelegramSendMessageInput")({
|
|
33
|
+
message: Schema.String,
|
|
34
|
+
disableWebPagePreview: Schema.optional(Schema.Boolean)
|
|
35
|
+
}) {};
|
|
36
|
+
var TelegramSendMessageOutput = class extends Schema.Class("TelegramSendMessageOutput")({
|
|
37
|
+
sent: Schema.Boolean,
|
|
38
|
+
chatId: Schema.String
|
|
39
|
+
}) {};
|
|
40
|
+
var TelegramValidateOutput = class extends Schema.Class("TelegramValidateOutput")({
|
|
41
|
+
ok: Schema.Boolean,
|
|
42
|
+
chatId: Schema.String
|
|
43
|
+
}) {};
|
|
44
|
+
const telegramSendMessageAction = defineAction({
|
|
45
|
+
id: "telegram.send_message",
|
|
46
|
+
description: "Send a Telegram message to the configured chat.",
|
|
47
|
+
inputSchema: TelegramSendMessageInput,
|
|
48
|
+
outputSchema: TelegramSendMessageOutput,
|
|
49
|
+
execute: ({ integration, input }) => Effect.gen(function* () {
|
|
50
|
+
const botToken = yield* resolveTelegramBotToken(integration);
|
|
51
|
+
const chatId = yield* requiredStringConfig(integration, "chatId");
|
|
52
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
53
|
+
method: "POST",
|
|
54
|
+
url: `${telegramApiBaseUrl}/bot${botToken}/sendMessage`,
|
|
55
|
+
headers: { "content-type": "application/json" },
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
chat_id: chatId,
|
|
58
|
+
text: input.message,
|
|
59
|
+
disable_web_page_preview: input.disableWebPagePreview ?? true
|
|
60
|
+
})
|
|
61
|
+
}));
|
|
62
|
+
if (!isSuccessStatus(response.status)) return telegramProviderFailure({
|
|
63
|
+
code: response.status === 429 ? "telegram_rate_limited" : "telegram_send_failed",
|
|
64
|
+
message: "Telegram send message failed",
|
|
65
|
+
status: response.status,
|
|
66
|
+
body: response.body
|
|
67
|
+
});
|
|
68
|
+
return ActionResult.success(TelegramSendMessageOutput.make({
|
|
69
|
+
sent: true,
|
|
70
|
+
chatId
|
|
71
|
+
}));
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
const telegramValidateAction = defineAction({
|
|
75
|
+
id: "telegram.validate",
|
|
76
|
+
description: "Validate the Telegram bot token and configured chat.",
|
|
77
|
+
inputSchema: Schema.Struct({}),
|
|
78
|
+
outputSchema: TelegramValidateOutput,
|
|
79
|
+
execute: ({ integration }) => Effect.gen(function* () {
|
|
80
|
+
const botToken = yield* resolveTelegramBotToken(integration);
|
|
81
|
+
const chatId = yield* requiredStringConfig(integration, "chatId");
|
|
82
|
+
const response = yield* (yield* ConnectorHttpClient).request(ConnectorHttpRequest.make({
|
|
83
|
+
method: "POST",
|
|
84
|
+
url: `${telegramApiBaseUrl}/bot${botToken}/getChat`,
|
|
85
|
+
headers: { "content-type": "application/json" },
|
|
86
|
+
body: JSON.stringify({ chat_id: chatId })
|
|
87
|
+
}));
|
|
88
|
+
if (!isSuccessStatus(response.status)) return telegramProviderFailure({
|
|
89
|
+
code: "telegram_validate_failed",
|
|
90
|
+
message: "Telegram validation failed",
|
|
91
|
+
status: response.status,
|
|
92
|
+
body: response.body
|
|
93
|
+
});
|
|
94
|
+
return ActionResult.success(TelegramValidateOutput.make({
|
|
95
|
+
ok: true,
|
|
96
|
+
chatId
|
|
97
|
+
}));
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
const telegramActions = [telegramSendMessageAction, telegramValidateAction];
|
|
101
|
+
const TelegramConnector = defineConnector({
|
|
102
|
+
id: telegramConnectorId,
|
|
103
|
+
description: "Telegram bot connector actions.",
|
|
104
|
+
actions: telegramActions
|
|
105
|
+
});
|
|
106
|
+
//#endregion
|
|
107
|
+
export { TelegramBotTokenSlot, TelegramConnector, TelegramSendMessageInput, TelegramSendMessageOutput, TelegramValidateOutput, telegramActions, telegramApiBaseUrl, telegramBotTokenSlotId, telegramConnectorId, telegramSendMessageAction, telegramValidateAction };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=index.mjs.map
|