@jskit-ai/connectors-catalog 0.1.63 → 0.1.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -17
- package/docs/ai.md +5 -17
- package/docs/amazon-redshift.md +6 -8
- package/docs/apollo-io.md +0 -8
- package/docs/ashby.md +0 -8
- package/docs/attention.md +0 -8
- package/docs/aws-athena.md +2 -2
- package/docs/aws-credentials.md +1 -1
- package/docs/aws-s3.md +1 -1
- package/docs/bigquery.md +2 -4
- package/docs/calendly.md +4 -14
- package/docs/chargebee.md +0 -9
- package/docs/clickhouse.md +1 -1
- package/docs/confidence-oauth.md +3 -9
- package/docs/contentful.md +4 -13
- package/docs/databricks.md +35 -3
- package/docs/dbt-semantic-layer.md +2 -8
- package/docs/figma.md +5 -5
- package/docs/firebase-cloud-messaging.md +3 -3
- package/docs/firecrawl.md +1 -1
- package/docs/fireflies.md +7 -10
- package/docs/gemini-enterprise.md +33 -3
- package/docs/gong.md +0 -9
- package/docs/google-ads.md +53 -11
- package/docs/google-analytics.md +2 -2
- package/docs/google-maps-platform.md +3 -9
- package/docs/granola.md +1 -1
- package/docs/hubspot.md +25 -0
- package/docs/klipy.md +0 -13
- package/docs/lexware.md +0 -8
- package/docs/lightspeed.md +32 -3
- package/docs/linear.md +24 -7
- package/docs/linkedin.md +16 -16
- package/docs/logo-dev.md +7 -25
- package/docs/mailgun.md +1 -14
- package/docs/mapbox.md +0 -8
- package/docs/microsoft-fabric.md +50 -13
- package/docs/microsoft-oauth.md +33 -0
- package/docs/microsoft-powerpoint.md +2 -13
- package/docs/microsoft-word.md +2 -13
- package/docs/miro.md +2 -2
- package/docs/oura.md +4 -3
- package/docs/polar.md +3 -5
- package/docs/posthog.md +2 -17
- package/docs/prestashop.md +5 -9
- package/docs/salesforce.md +41 -12
- package/docs/sentry.md +1 -12
- package/docs/sevdesk.md +2 -13
- package/docs/shopify.md +35 -2
- package/docs/slack.md +39 -14
- package/docs/snowflake.md +27 -2
- package/docs/telegram.md +0 -10
- package/docs/tiktok.md +19 -1
- package/docs/twilio.md +1 -1
- package/docs/twitch.md +34 -4
- package/docs/wave.md +36 -15
- package/docs/wix.md +4 -17
- package/docs/wiz.md +4 -4
- package/docs/wordpress-com.md +4 -13
- package/docs/workday.md +28 -9
- package/docs/x-twitter.md +0 -9
- package/docs/xero.md +39 -11
- package/docs/zoho-books.md +41 -10
- package/docs/zoho-crm.md +36 -12
- package/package.json +3 -3
- package/patterns/oauth-connection/PATTERN.md +27 -610
- package/patterns/paddle-catalogue/example/create-products.js +2 -1
- package/patterns/redshift-queries/PATTERN.md +1 -1
- package/src/server/attention.js +8 -11
- package/src/server/bigquery.js +7 -11
- package/src/server/brevo.js +7 -10
- package/src/server/calendly.js +7 -9
- package/src/server/chargebee.js +3 -6
- package/src/server/firecrawl.js +3 -3
- package/src/server/gatewayapi.js +4 -4
- package/src/server/github-api.js +1 -1
- package/src/server/gitlab-api.js +1 -1
- package/src/server/gmail.js +6 -11
- package/src/server/gong.js +4 -4
- package/src/server/google-ads-search.js +4 -5
- package/src/server/google-docs.js +10 -22
- package/src/server/google-drive.js +6 -6
- package/src/server/google-maps-platform.js +4 -8
- package/src/server/google-search-console.js +2 -2
- package/src/server/google-sheets.js +12 -18
- package/src/server/google-slides.js +10 -16
- package/src/server/google.js +17 -9
- package/src/server/jsonOperation.js +17 -18
- package/src/server/lexware.js +4 -9
- package/src/server/resend.js +8 -14
- package/src/server/semrush.js +70 -89
- package/src/server/wix.js +152 -222
- package/src/server/x-twitter.js +21 -18
- package/src/shared/ai.js +3 -1
- package/src/shared/definitions.js +2 -34
- package/src/shared/firecrawl.js +17 -0
- package/src/shared/gemini-enterprise.js +1 -1
- package/src/shared/google-ads.js +1 -1
- package/src/shared/google.js +2 -2
- package/src/shared/logo-dev.js +1 -1
- package/src/shared/mapbox.js +2 -2
- package/src/shared/mcp.js +2 -5
- package/src/shared/microsoft-fabric.js +1 -1
- package/src/shared/microsoft.js +12 -24
- package/src/shared/resend.js +20 -0
- package/src/shared/siteUrl.js +1 -1
- package/src/shared/tokens.js +4 -6
- package/src/shared/workday.js +1 -1
- package/test/firecrawl.test.js +1 -1
- package/test/github-api.test.js +2 -1
- package/test/gitlab-api.test.js +2 -1
- package/test/gong.test.js +2 -2
- package/test/google.test.js +20 -10
- package/test/setupGuides.test.js +18 -0
- package/test/tokens.test.js +1 -1
- package/test/wix.test.js +13 -0
- package/test/wiz.test.js +9 -3
|
@@ -42,7 +42,7 @@ invoking the service. Matching the configured warehouse is only a target check.
|
|
|
42
42
|
The library does not resolve ambient AWS profiles or switch to a more privileged
|
|
43
43
|
account after a denial. The application resolves its own credential bindings; editable references do
|
|
44
44
|
not grant AWS permissions. This shared credential mode has no provider callback
|
|
45
|
-
URL and does not depend on
|
|
45
|
+
URL and does not depend on a hosting platform's registration or allocation.
|
|
46
46
|
|
|
47
47
|
## Framework APIs
|
|
48
48
|
|
package/src/server/attention.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
2
2
|
import { createSchema } from "json-rest-schema";
|
|
3
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
3
|
import { attentionDefinition } from "../shared/tokens.js";
|
|
5
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
4
|
+
import { jsonOperation, validatedOperation, withQuery } from "./jsonOperation.js";
|
|
6
5
|
|
|
7
6
|
const text = { type: "string", minLength: 1, maxLength: 2000 };
|
|
8
7
|
const id = { type: "string", minLength: 1, maxLength: 100, pattern: "^[A-Za-z0-9_-]+$" };
|
|
@@ -15,16 +14,14 @@ const list = result => Array.isArray(result?.data);
|
|
|
15
14
|
const record = result => result?.data !== null && typeof result?.data === "object" && !Array.isArray(result.data) && typeof (result.data.uuid ?? result.data.id) === "string";
|
|
16
15
|
const conversation = result => result?.type === "conversations" && typeof result.id === "string" && result.attributes !== null && typeof result.attributes === "object" && !Array.isArray(result.attributes);
|
|
17
16
|
function operation(method, endpoint, fields, validateResult, prepare = value => value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (method === "GET") { for (const [key, value] of Object.entries(body)) url.searchParams.set(key, String(value)); return { method, url: url.href }; }
|
|
24
|
-
if (method === "DELETE") return { method, url: url.href };
|
|
17
|
+
return validatedOperation(fields, values => {
|
|
18
|
+
const { id: resource, ...body } = prepare(values);
|
|
19
|
+
const url = `https://api.attention.tech/v2/${endpoint.replace("{id}", resource || "")}`;
|
|
20
|
+
if (method === "GET") return { method, url: withQuery(url, body) };
|
|
21
|
+
if (method === "DELETE") return { method, url: new URL(url).href };
|
|
25
22
|
if (!Object.keys(body).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
|
26
|
-
return { method, url: url.href, body };
|
|
27
|
-
}, validateResult
|
|
23
|
+
return { method, url: new URL(url).href, body };
|
|
24
|
+
}, validateResult);
|
|
28
25
|
}
|
|
29
26
|
const team = { type: "object", schema: createSchema({ uuid: requiredId, primary: bool }) };
|
|
30
27
|
const attentionProvider = Object.freeze({
|
package/src/server/bigquery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSchema } from "json-rest-schema";
|
|
2
2
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
3
|
+
import { jsonOperation, validatedOperation } from "./jsonOperation.js";
|
|
4
4
|
import { bigqueryDefinition } from "../shared/google.js";
|
|
5
5
|
import { googleRead, googleProvider, pageToken } from "./google.js";
|
|
6
6
|
const origin = "https://bigquery.googleapis.com";
|
|
@@ -46,16 +46,12 @@ const validPage = (result, field, reference) => Boolean(result && typeof result
|
|
|
46
46
|
(result.nextPageToken === undefined || typeof result.nextPageToken === "string"));
|
|
47
47
|
|
|
48
48
|
function projectOperation(fields, destination, validateResult, scopes = metadataScopes, method = "GET") {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const [name, value] of Object.entries(query)) if (value !== undefined) url.searchParams.set(name, String(value));
|
|
56
|
-
return { method, url: url.href };
|
|
57
|
-
}
|
|
58
|
-
};
|
|
49
|
+
return validatedOperation(fields, (values, settings) => {
|
|
50
|
+
const { path, query = {} } = destination(values);
|
|
51
|
+
const url = new URL(`${origin}/bigquery/v2/projects/${encodeURIComponent(settings.projectId)}${path}`);
|
|
52
|
+
for (const [name, value] of Object.entries(query)) if (value !== undefined) url.searchParams.set(name, String(value));
|
|
53
|
+
return { method, url: url.href };
|
|
54
|
+
}, validateResult, scopes);
|
|
59
55
|
}
|
|
60
56
|
const bigqueryProvider = googleProvider(bigqueryDefinition, origin, "projects.list", {
|
|
61
57
|
"datasets.list": projectOperation(metadataPage, (query) => ({ path: "/datasets", query }),
|
package/src/server/brevo.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
2
2
|
import { createSchema } from "json-rest-schema";
|
|
3
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
3
|
import { brevoDefinition } from "../shared/tokens.js";
|
|
5
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
4
|
+
import { jsonOperation, validatedOperation, withQuery } from "./jsonOperation.js";
|
|
6
5
|
|
|
7
6
|
const text = { type: "string", minLength: 1, maxLength: 1000 };
|
|
8
7
|
const email = { ...text, maxLength: 320, pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$" };
|
|
@@ -17,14 +16,12 @@ const domain = { type: "string", minLength: 3, maxLength: 253, pattern: "^(?:[A-
|
|
|
17
16
|
const empty = result => result === null || result !== null && typeof result === "object" && !Array.isArray(result) && Object.keys(result).length === 0;
|
|
18
17
|
const record = result => Number.isInteger(result?.id);
|
|
19
18
|
function operation(method, endpoint, fields, validateResult, prepare = value => value) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { method, url: url.href, ...(Object.keys(body).length ? { body } : {}) };
|
|
27
|
-
}, validateResult };
|
|
19
|
+
return validatedOperation(fields, values => {
|
|
20
|
+
const { resource, ...body } = prepare(values);
|
|
21
|
+
const url = `https://api.brevo.com/v3/${endpoint.replace("{resource}", encodeURIComponent(resource ?? ""))}`;
|
|
22
|
+
if (method === "GET") return { method, url: withQuery(url, body) };
|
|
23
|
+
return { method, url: new URL(url).href, ...(Object.keys(body).length ? { body } : {}) };
|
|
24
|
+
}, validateResult);
|
|
28
25
|
}
|
|
29
26
|
function changed(value) {
|
|
30
27
|
if (Object.keys(value).every(key => key === "resource")) throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
package/src/server/calendly.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
2
2
|
import { createSchema } from "json-rest-schema";
|
|
3
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
3
|
import { calendlyDefinition } from "../shared/tokens.js";
|
|
5
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
4
|
+
import { jsonOperation, validatedOperation, withQuery } from "./jsonOperation.js";
|
|
6
5
|
|
|
7
6
|
const id = { type: "string", required: true, minLength: 1, maxLength: 100, pattern: "^[A-Za-z0-9_-]+$" };
|
|
8
7
|
const text = { type: "string", minLength: 1, maxLength: 1000 };
|
|
@@ -14,13 +13,12 @@ const record = result => typeof result?.resource?.uri === "string";
|
|
|
14
13
|
const collection = result => Array.isArray(result?.collection) && Number.isInteger(result?.pagination?.count);
|
|
15
14
|
function uri(kind) { return { type: "string", maxLength: 2048, pattern: `^https://api\\.calendly\\.com/${kind}/[A-Za-z0-9_-]+$` }; }
|
|
16
15
|
function operation(method, endpoint, fields, scope, validateResult, prepare = value => value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, validateResult };
|
|
16
|
+
return validatedOperation(fields, input => {
|
|
17
|
+
const { uuid, invitee_uuid, ...values } = prepare(input);
|
|
18
|
+
const url = `https://api.calendly.com/${endpoint.replace("{uuid}", uuid || "").replace("{invitee_uuid}", invitee_uuid || "")}`;
|
|
19
|
+
if (method === "GET") return { method, url: withQuery(url, values) };
|
|
20
|
+
return { method, url: new URL(url).href, ...(method === "POST" ? { body: values } : {}) };
|
|
21
|
+
}, validateResult, [scope]);
|
|
24
22
|
}
|
|
25
23
|
const calendlyProvider = Object.freeze({
|
|
26
24
|
...calendlyDefinition, apiOrigins: ["https://api.calendly.com"],
|
package/src/server/chargebee.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
2
2
|
import { createSchema } from "json-rest-schema";
|
|
3
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
3
|
import { chargebeeDefinition } from "../shared/chargebee.js";
|
|
5
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
4
|
+
import { jsonOperation, validatedOperation } from "./jsonOperation.js";
|
|
6
5
|
|
|
7
6
|
const origin = ({ siteName }) => `https://${siteName.toLowerCase()}.chargebee.com`;
|
|
8
7
|
const text = { type: "string", minLength: 1, maxLength: 250 };
|
|
@@ -20,9 +19,7 @@ const record = key => result => typeof result?.[key]?.id === "string" && result[
|
|
|
20
19
|
const collection = key => result => Array.isArray(result?.list) && result.list.every(entry => record(key)(entry)) &&
|
|
21
20
|
(result.next_offset === undefined || typeof result.next_offset === "string");
|
|
22
21
|
function operation(method, endpoint, fields, validateResult, defaults = {}) {
|
|
23
|
-
|
|
24
|
-
return { scopes: [], request(input, settings) {
|
|
25
|
-
const { resource: id, idempotencyKey, ...values } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
22
|
+
return validatedOperation({ ...fields, ...(method === "POST" ? { idempotencyKey: { ...resource } } : {}) }, ({ resource: id, idempotencyKey, ...values }, settings) => {
|
|
26
23
|
const body = new URLSearchParams();
|
|
27
24
|
for (const [key, value] of Object.entries({ ...values, ...defaults })) {
|
|
28
25
|
if (Array.isArray(value)) value.forEach((entry, index) => { for (const [field, child] of Object.entries(entry)) body.set(`${key}[${field}][${index}]`, String(child)); });
|
|
@@ -32,7 +29,7 @@ function operation(method, endpoint, fields, validateResult, defaults = {}) {
|
|
|
32
29
|
const url = new URL(`${origin(settings)}/api/v2/${endpoint.replace("{resource}", id || "")}`);
|
|
33
30
|
if (method === "GET") { url.search = body.toString(); return { method, url: url.href }; }
|
|
34
31
|
return { method, url: url.href, body: body.toString(), headers: { "Content-Type": "application/x-www-form-urlencoded", "chargebee-idempotency-key": idempotencyKey } };
|
|
35
|
-
}, validateResult
|
|
32
|
+
}, validateResult);
|
|
36
33
|
}
|
|
37
34
|
const chargebeeProvider = Object.freeze({
|
|
38
35
|
...chargebeeDefinition,
|
package/src/server/firecrawl.js
CHANGED
|
@@ -2,7 +2,7 @@ import { validatedOperation } from "./jsonOperation.js";
|
|
|
2
2
|
import { createSchema } from "json-rest-schema";
|
|
3
3
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
4
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
5
|
-
import { firecrawlDefinition } from "../shared/
|
|
5
|
+
import { firecrawlDefinition } from "../shared/firecrawl.js";
|
|
6
6
|
|
|
7
7
|
const empty = createSchema({});
|
|
8
8
|
const pageUrl = {
|
|
@@ -43,8 +43,8 @@ const firecrawlProvider = Object.freeze({
|
|
|
43
43
|
} }), result => result?.success === true && typeof result.id === "string"),
|
|
44
44
|
"crawls.get": validatedOperation({ id: jobId, next: { type: "string", maxLength: 8192 } }, ({ id, next }) => {
|
|
45
45
|
const expected = `https://api.firecrawl.dev/v2/crawl/${id}`;
|
|
46
|
-
let url; try { url = new URL(next || expected); } catch { throw new ConnectorError("connector_input_invalid", "Use the returned next-page URL for this crawl."); }
|
|
47
|
-
if (url.origin + url.pathname !== expected || url.username || url.password || url.hash) throw new ConnectorError("connector_input_invalid", "Use the returned next-page URL for this crawl.");
|
|
46
|
+
let url; try { url = new URL(next || expected); } catch { throw new ConnectorError("connector_input_invalid", "Use the returned next-page URL for this crawl.", { statusCode: 422 }); }
|
|
47
|
+
if (url.origin + url.pathname !== expected || url.username || url.password || url.hash) throw new ConnectorError("connector_input_invalid", "Use the returned next-page URL for this crawl.", { statusCode: 422 });
|
|
48
48
|
return { method: "GET", url: url.href };
|
|
49
49
|
}, result => typeof result?.status === "string" && Array.isArray(result.data) && Number.isInteger(result.total) && result.total >= 0 && Number.isInteger(result.completed) && result.completed >= 0),
|
|
50
50
|
"crawls.errors": validatedOperation({ id: jobId }, ({ id }) => ({ method: "GET", url: `https://api.firecrawl.dev/v2/crawl/${id}/errors` }), result => Array.isArray(result?.errors)),
|
package/src/server/gatewayapi.js
CHANGED
|
@@ -34,14 +34,14 @@ const gatewayApiProvider = Object.freeze({
|
|
|
34
34
|
// Call at the application's webhook route before trusting or persisting its body.
|
|
35
35
|
function verifyGatewayApiEvent({ rawBody, signature, secret }) {
|
|
36
36
|
if (!(rawBody instanceof Uint8Array) || rawBody.byteLength > 1048576 || typeof secret !== "string" || secret.length < 1 || typeof signature !== "string" || !/^v1=[a-fA-F0-9]{64}$/.test(signature)) {
|
|
37
|
-
throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook signature.");
|
|
37
|
+
throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook signature.", { statusCode: 401 });
|
|
38
38
|
}
|
|
39
39
|
const expected = createHmac("sha256", secret).update(rawBody).digest();
|
|
40
|
-
if (!timingSafeEqual(expected, Buffer.from(signature.slice(3), "hex"))) throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook signature.");
|
|
40
|
+
if (!timingSafeEqual(expected, Buffer.from(signature.slice(3), "hex"))) throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook signature.", { statusCode: 401 });
|
|
41
41
|
let event;
|
|
42
|
-
try { event = JSON.parse(Buffer.from(rawBody).toString("utf8")); } catch { throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook event."); }
|
|
42
|
+
try { event = JSON.parse(Buffer.from(rawBody).toString("utf8")); } catch { throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook event.", { statusCode: 401 }); }
|
|
43
43
|
if (typeof event?.event_id !== "string" || !event.event_id || typeof event.event_type !== "string" || !Number.isFinite(Date.parse(event.timestamp)) || !event.event || typeof event.event !== "object" || Array.isArray(event.event)) {
|
|
44
|
-
throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook event.");
|
|
44
|
+
throw new ConnectorError("connector_webhook_invalid", "Invalid GatewayAPI webhook event.", { statusCode: 401 });
|
|
45
45
|
}
|
|
46
46
|
return event;
|
|
47
47
|
}
|
package/src/server/github-api.js
CHANGED
|
@@ -34,7 +34,7 @@ function repositoryOperation(suffix, fields, validateResult, method = "GET") {
|
|
|
34
34
|
for (const [key, value] of Object.entries(values)) url.searchParams.set(key, String(value));
|
|
35
35
|
return { method, url: url.href };
|
|
36
36
|
}
|
|
37
|
-
if (!Object.keys(values).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.");
|
|
37
|
+
if (!Object.keys(values).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
|
38
38
|
return { method, url: url.href, body: values };
|
|
39
39
|
}, validateResult };
|
|
40
40
|
}
|
package/src/server/gitlab-api.js
CHANGED
|
@@ -21,7 +21,7 @@ function projectOperation(suffix, fields, validateResult, method = "GET") {
|
|
|
21
21
|
for (const [key, value] of Object.entries(values)) url.searchParams.set(key, String(value));
|
|
22
22
|
return { method, url: url.href };
|
|
23
23
|
}
|
|
24
|
-
if (!Object.keys(values).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.");
|
|
24
|
+
if (!Object.keys(values).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
|
25
25
|
return { method, url: url.href, body: values };
|
|
26
26
|
}, validateResult };
|
|
27
27
|
}
|
package/src/server/gmail.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { createSchema } from "json-rest-schema";
|
|
2
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
1
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
4
2
|
import { gmailDefinition } from "../shared/google.js";
|
|
5
|
-
import { googleRead, googleProvider, documentId, pageToken } from "./google.js";
|
|
3
|
+
import { googleOperation, googleRead, googleProvider, documentId, pageToken } from "./google.js";
|
|
6
4
|
const origin = "https://gmail.googleapis.com";
|
|
7
5
|
const read = ["gmail.readonly", "gmail.modify", "gmail.metadata", "https://mail.google.com/"];
|
|
8
6
|
const contentScopes = ["gmail.readonly", "gmail.modify", "https://mail.google.com/"];
|
|
@@ -16,13 +14,10 @@ const rawField = { type: "string", required: true, minLength: 4, maxLength: 1400
|
|
|
16
14
|
const labelIds = { type: "array", items: { type: "string", minLength: 1, maxLength: 200 }, validator: value => value.length <= 100 || "Supply no more than 100 labels." };
|
|
17
15
|
const listFields = { pageToken, maxResults: { type: "integer", min: 1, max: 500, defaultTo: 100 }, labelIds, includeSpamTrash: { type: "boolean", defaultTo: false } };
|
|
18
16
|
function gmailWrite(scopes, fields, destination, validateResult, method = "POST") {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { path, body } = destination(values);
|
|
24
|
-
return { method, url: `${origin}/gmail/v1/users/me${path}`, ...(body ? { body } : {}) };
|
|
25
|
-
} };
|
|
17
|
+
return googleOperation(scopes, fields, values => {
|
|
18
|
+
const { path, body } = destination(values);
|
|
19
|
+
return { method, url: `${origin}/gmail/v1/users/me${path}`, ...(body ? { body } : {}) };
|
|
20
|
+
}, validateResult);
|
|
26
21
|
}
|
|
27
22
|
const gmailProvider = Object.freeze({ ...googleProvider(gmailDefinition, origin, "profile.read", {
|
|
28
23
|
"messages.read": googleRead(contentScopes, { id: documentId, format: { type: "string", enum: ["full", "raw"], defaultTo: "full" } }, ({ id, format }) => ({ url: `${origin}/gmail/v1/users/me/messages/${encodeURIComponent(id)}`, query: { format } }), messageResult),
|
|
@@ -30,7 +25,7 @@ const gmailProvider = Object.freeze({ ...googleProvider(gmailDefinition, origin,
|
|
|
30
25
|
"attachments.get": googleRead(contentScopes, { messageId: documentId, id: documentId }, ({ messageId, id }) => ({ url: `${origin}/gmail/v1/users/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(id)}` }), value => Number.isInteger(value?.size) && typeof value.data === "string"),
|
|
31
26
|
"messages.send": gmailWrite(["gmail.send", ...composeScopes], { raw: rawField, threadId: { ...documentId, required: false } }, body => ({ path: "/messages/send", body }), messageResult),
|
|
32
27
|
"messages.modify": gmailWrite(modifyScopes, { id: documentId, addLabelIds: labelIds, removeLabelIds: labelIds }, ({ id, ...body }) => {
|
|
33
|
-
if (!body.addLabelIds?.length && !body.removeLabelIds?.length) throw new ConnectorError("connector_input_invalid", "Supply labels to add or remove.");
|
|
28
|
+
if (!body.addLabelIds?.length && !body.removeLabelIds?.length) throw new ConnectorError("connector_input_invalid", "Supply labels to add or remove.", { statusCode: 422 });
|
|
34
29
|
return { path: `/messages/${encodeURIComponent(id)}/modify`, body };
|
|
35
30
|
}, messageResult),
|
|
36
31
|
"messages.trash": gmailWrite(modifyScopes, { id: documentId }, ({ id }) => ({ path: `/messages/${encodeURIComponent(id)}/trash` }), messageResult),
|
package/src/server/gong.js
CHANGED
|
@@ -14,9 +14,9 @@ const recordsValid = value => ["totalRecords", "currentPageSize", "currentPageNu
|
|
|
14
14
|
function callOperation(path, field, extensive = false) {
|
|
15
15
|
const schema = createSchema({ ...callFields, ...(extensive ? { includeMedia: { type: "boolean", defaultTo: false } } : {}) });
|
|
16
16
|
return { scopes: [], request(input, settings) {
|
|
17
|
-
if (Array.isArray(input.callIds) && input.callIds.some(id => typeof id !== "string") || input.workspaceId !== undefined && typeof input.workspaceId !== "string") throw new ConnectorError("connector_input_invalid", "Supply Gong IDs as strings to preserve all digits.");
|
|
17
|
+
if (Array.isArray(input.callIds) && input.callIds.some(id => typeof id !== "string") || input.workspaceId !== undefined && typeof input.workspaceId !== "string") throw new ConnectorError("connector_input_invalid", "Supply Gong IDs as strings to preserve all digits.", { statusCode: 422 });
|
|
18
18
|
const { cursor, includeMedia, ...filter } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
19
|
-
if ((!filter.fromDateTime !== !filter.toDateTime) || (filter.fromDateTime && Date.parse(filter.fromDateTime) >= Date.parse(filter.toDateTime)) || (!filter.callIds && !filter.fromDateTime)) throw new ConnectorError("connector_input_invalid", "Supply call IDs or an ordered timestamp range.");
|
|
19
|
+
if ((!filter.fromDateTime !== !filter.toDateTime) || (filter.fromDateTime && Date.parse(filter.fromDateTime) >= Date.parse(filter.toDateTime)) || (!filter.callIds && !filter.fromDateTime)) throw new ConnectorError("connector_input_invalid", "Supply call IDs or an ordered timestamp range.", { statusCode: 422 });
|
|
20
20
|
const body = { filter, ...(cursor ? { cursor } : {}) };
|
|
21
21
|
if (extensive) body.contentSelector = { context: "Extended", contextTiming: ["Now", "TimeOfCall"], exposedFields: {
|
|
22
22
|
parties: true, content: { brief: true, outline: true, topics: true, keyPoints: true, callOutcome: true },
|
|
@@ -36,9 +36,9 @@ const gongProvider = Object.freeze({
|
|
|
36
36
|
"calls.extensive": callOperation("/v2/calls/extensive", "calls", true),
|
|
37
37
|
"calls.transcripts": callOperation("/v2/calls/transcript", "callTranscripts"),
|
|
38
38
|
"stats.interaction": { scopes: [], request(input, settings) {
|
|
39
|
-
if (Array.isArray(input.userIds) && input.userIds.some(id => typeof id !== "string")) throw new ConnectorError("connector_input_invalid", "Supply Gong IDs as strings to preserve all digits.");
|
|
39
|
+
if (Array.isArray(input.userIds) && input.userIds.some(id => typeof id !== "string")) throw new ConnectorError("connector_input_invalid", "Supply Gong IDs as strings to preserve all digits.", { statusCode: 422 });
|
|
40
40
|
const { cursor, ...filter } = validateSchemaPayload({ schema: statsSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
41
|
-
if (filter.fromDate >= filter.toDate) throw new ConnectorError("connector_input_invalid", "The end date must follow the start date.");
|
|
41
|
+
if (filter.fromDate >= filter.toDate) throw new ConnectorError("connector_input_invalid", "The end date must follow the start date.", { statusCode: 422 });
|
|
42
42
|
return { method: "POST", url: `${origin(settings)}/v2/stats/interaction`, body: { filter, ...(cursor ? { cursor } : {}) } };
|
|
43
43
|
}, validateResult: value => Array.isArray(value?.peopleInteractionStats) && recordsValid(value) },
|
|
44
44
|
"users.list": jsonOperation((settings) => `${origin(settings)}/v2/users`, {
|
|
@@ -3,6 +3,7 @@ import { createSchema } from "json-rest-schema";
|
|
|
3
3
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
4
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
5
5
|
import { validateGoogleAdsSearchPlan } from "../shared/google-ads-search.js";
|
|
6
|
+
import { validatedOperation } from "./jsonOperation.js";
|
|
6
7
|
|
|
7
8
|
const api = "https://googleads.googleapis.com/v25";
|
|
8
9
|
const scope = "https://www.googleapis.com/auth/adwords";
|
|
@@ -11,11 +12,9 @@ const id = { type: "string", required: true, validator: value => /^[0-9]{1,20}$/
|
|
|
11
12
|
const error = message => { throw new ConnectorError("connector_input_invalid", message, { statusCode: 422 }); };
|
|
12
13
|
const hash = value => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
13
14
|
function requestOperation(fields, build, validateResult) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return { method: "POST", ...build(values), headers: settings.loginCustomerId ? { "login-customer-id": settings.loginCustomerId } : {} };
|
|
18
|
-
}, validateResult };
|
|
15
|
+
return validatedOperation(fields, (values, settings) => (
|
|
16
|
+
{ method: "POST", ...build(values), headers: settings.loginCustomerId ? { "login-customer-id": settings.loginCustomerId } : {} }
|
|
17
|
+
), validateResult, [scope]);
|
|
19
18
|
}
|
|
20
19
|
const mutated = result => result && typeof result === "object" && !Array.isArray(result) && !result.partialFailureError &&
|
|
21
20
|
(result.results === undefined || Array.isArray(result.results)) && (result.mutateOperationResponses === undefined || Array.isArray(result.mutateOperationResponses));
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
import { createSchema } from "json-rest-schema";
|
|
2
|
-
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
1
|
import { googleDocsDefinition } from "../shared/google.js";
|
|
4
|
-
import { googleRead, googleProvider, googleFileVerification, documentId } from "./google.js";
|
|
2
|
+
import { googleOperation, googleBatchRequests, googleRead, googleProvider, googleFileVerification, documentId } from "./google.js";
|
|
5
3
|
const origin = "https://docs.googleapis.com";
|
|
6
4
|
const readScopes = ["documents.readonly", "documents", "drive.readonly", "drive.file", "drive"];
|
|
7
|
-
const writable = ["documents", "drive.file", "drive"]
|
|
5
|
+
const writable = ["documents", "drive.file", "drive"];
|
|
8
6
|
const validDocument = value => typeof value?.documentId === "string" && typeof value.title === "string";
|
|
9
7
|
const get = googleRead(readScopes, { documentId }, ({ documentId }) => ({
|
|
10
8
|
url: `${origin}/v1/documents/${encodeURIComponent(documentId)}`, query: { includeTabsContent: true }
|
|
11
9
|
}), validDocument);
|
|
12
|
-
const create = createSchema({ title: { type: "string", required: true, minLength: 1, maxLength: 1024 } });
|
|
13
|
-
const batch = createSchema({ documentId, requests: { type: "array", required: true }, requiredRevisionId: { type: "string", minLength: 1, maxLength: 1024 } });
|
|
14
10
|
const base = googleProvider(googleDocsDefinition, origin, "connection.verify", {
|
|
15
11
|
"connection.verify": googleFileVerification(get, "documentId"),
|
|
16
12
|
"documents.get": get,
|
|
17
|
-
"documents.create": {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
"documents.batchUpdate": {
|
|
24
|
-
scopes: writable,
|
|
25
|
-
validateResult: value => typeof value?.documentId === "string" && (value.replies === undefined || Array.isArray(value.replies)),
|
|
26
|
-
request(input) {
|
|
27
|
-
const { documentId, requests, requiredRevisionId } = validateSchemaPayload({ schema: batch, mode: "replace" }, input, { statusCode: 422 });
|
|
28
|
-
if (!requests.length || requests.length > 100 || JSON.stringify(requests).length > 1048576 || requests.some(request => !request || typeof request !== "object" || Array.isArray(request) || Object.keys(request).length !== 1 || !/^[a-zA-Z][a-zA-Z0-9]+$/.test(Object.keys(request)[0]) || !Object.values(request)[0] || typeof Object.values(request)[0] !== "object" || Array.isArray(Object.values(request)[0]))) {
|
|
29
|
-
throw Object.assign(new Error("Supply 1–100 Google Docs request objects, one native operation per object, within 1 MiB."), { statusCode: 422 });
|
|
30
|
-
}
|
|
13
|
+
"documents.create": googleOperation(writable, { title: { type: "string", required: true, minLength: 1, maxLength: 1024 } },
|
|
14
|
+
body => ({ method: "POST", url: `${origin}/v1/documents`, body }), validDocument),
|
|
15
|
+
"documents.batchUpdate": googleOperation(writable,
|
|
16
|
+
{ documentId, requests: { type: "array", required: true }, requiredRevisionId: { type: "string", minLength: 1, maxLength: 1024 } },
|
|
17
|
+
({ documentId, requests, requiredRevisionId }) => {
|
|
18
|
+
googleBatchRequests(requests, "Google Docs");
|
|
31
19
|
return { method: "POST", url: `${origin}/v1/documents/${encodeURIComponent(documentId)}:batchUpdate`, body: { requests, ...(requiredRevisionId ? { writeControl: { requiredRevisionId } } : {}) } };
|
|
32
|
-
}
|
|
33
|
-
|
|
20
|
+
},
|
|
21
|
+
value => typeof value?.documentId === "string" && (value.replies === undefined || Array.isArray(value.replies)))
|
|
34
22
|
});
|
|
35
23
|
const googleDocsProvider = Object.freeze({ ...base, apiOrigins: [origin, "https://www.googleapis.com"] });
|
|
36
24
|
export { googleDocsProvider };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
3
3
|
import { googleDriveDefinition } from "../shared/google.js";
|
|
4
|
-
import { googleOperation, googleRead, googleProvider, pageToken } from "./google.js";
|
|
4
|
+
import { googleOperation, googleRead, googleProvider, inputInvalid, pageToken } from "./google.js";
|
|
5
5
|
const origin = "https://www.googleapis.com";
|
|
6
6
|
const fileId = { type: "string", required: true, minLength: 1, maxLength: 1024, validator: value => /^[A-Za-z0-9_-]+$/.test(value) || "Use a Drive file ID, not a URL." };
|
|
7
7
|
const contentScopes = ["drive", "drive.file", "drive.readonly"];
|
|
@@ -20,7 +20,7 @@ const baseProvider = googleProvider(googleDriveDefinition, origin, "files.list",
|
|
|
20
20
|
"files.export": googleRead(contentScopes, { fileId, mimeType: { type: "string", required: true, minLength: 1, maxLength: 200 } }, ({ fileId, mimeType }) => ({ url: url(fileId, { mimeType }, "/export") }), validBytes),
|
|
21
21
|
"files.create": googleOperation(writeScopes, { name: { type: "string", required: true, minLength: 1, maxLength: 1024 }, parentId: { ...fileId, required: false }, folder: { type: "boolean", defaultTo: false } }, ({ name, parentId, folder }) => ({ method: "POST", url: url(undefined, { supportsAllDrives: true, fields }), body: { name, ...(parentId ? { parents: [parentId] } : {}), ...(folder ? { mimeType: "application/vnd.google-apps.folder" } : {}) } }), validFile),
|
|
22
22
|
"files.update": googleOperation([...writeScopes, "drive.metadata"], { fileId, name: { type: "string", minLength: 1, maxLength: 1024 }, description: { type: "string", maxLength: 16384 }, trashed: { type: "boolean" } }, ({ fileId, ...body }) => {
|
|
23
|
-
if (!Object.keys(body).length) throw
|
|
23
|
+
if (!Object.keys(body).length) throw inputInvalid("Supply a name, description or trashed value.");
|
|
24
24
|
return { method: "PATCH", url: url(fileId, { supportsAllDrives: true, fields }), body };
|
|
25
25
|
}, validFile),
|
|
26
26
|
"files.upload": googleOperation(writeScopes, {
|
|
@@ -28,11 +28,11 @@ const baseProvider = googleProvider(googleDriveDefinition, origin, "files.list",
|
|
|
28
28
|
parentId: { ...fileId, required: false }, contentType: { type: "string", required: true, minLength: 3, maxLength: 200 },
|
|
29
29
|
bodyBase64: { type: "string", required: true, maxLength: 6666668, noTrim: true }
|
|
30
30
|
}, ({ fileId, name, parentId, contentType, bodyBase64 }) => {
|
|
31
|
-
if (!/^[A-Za-z0-9!#$&^_.+-]+\/[A-Za-z0-9!#$&^_.+-]+$/.test(contentType)) throw
|
|
31
|
+
if (!/^[A-Za-z0-9!#$&^_.+-]+\/[A-Za-z0-9!#$&^_.+-]+$/.test(contentType)) throw inputInvalid("Use a MIME type without header parameters.");
|
|
32
32
|
const data = Buffer.from(bodyBase64, "base64");
|
|
33
|
-
if (data.toString("base64") !== bodyBase64) throw
|
|
34
|
-
if (data.byteLength > 5_000_000) throw
|
|
35
|
-
if (fileId && parentId) throw
|
|
33
|
+
if (data.toString("base64") !== bodyBase64) throw inputInvalid("Use standard padded base64 file data.");
|
|
34
|
+
if (data.byteLength > 5_000_000) throw inputInvalid("Uploads above 5 MB require the framework's native resumable client.", 413);
|
|
35
|
+
if (fileId && parentId) throw inputInvalid("parentId applies to new files; moving files requires native addParents/removeParents wiring.");
|
|
36
36
|
const boundary = `drive_${randomUUID()}`;
|
|
37
37
|
const metadata = { name, ...(parentId ? { parents: [parentId] } : {}) };
|
|
38
38
|
const body = Buffer.concat([Buffer.from(`--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${JSON.stringify(metadata)}\r\n--${boundary}\r\nContent-Type: ${contentType}\r\n\r\n`), data, Buffer.from(`\r\n--${boundary}--\r\n`)]);
|
|
@@ -2,7 +2,7 @@ import { createSchema } from "json-rest-schema";
|
|
|
2
2
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
3
|
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
4
4
|
import { googleMapsPlatformDefinition } from "../shared/google-maps-platform.js";
|
|
5
|
-
import { jsonOperation } from "./jsonOperation.js";
|
|
5
|
+
import { jsonOperation, validatedOperation } from "./jsonOperation.js";
|
|
6
6
|
|
|
7
7
|
const endpoint = "https://maps.googleapis.com/maps/api/geocode/json";
|
|
8
8
|
const language = { type: "string", minLength: 2, maxLength: 35,
|
|
@@ -37,10 +37,6 @@ function validateGeocoding(result) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function mapsOperation(fields, request, validateResult) {
|
|
41
|
-
const schema = createSchema(fields);
|
|
42
|
-
return { scopes: [], validateResult, request(input) { return request(validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 })); } };
|
|
43
|
-
}
|
|
44
40
|
const latitude = { type: "number", required: true, min: -90, max: 90 };
|
|
45
41
|
const longitude = { type: "number", required: true, min: -180, max: 180 };
|
|
46
42
|
const placeFields = "id,displayName,formattedAddress,location,attributions,googleMapsUri";
|
|
@@ -56,10 +52,10 @@ const googleMapsPlatformProvider = Object.freeze({
|
|
|
56
52
|
return request(target.href, { ...options, headers: { ...options.headers, "X-Goog-Api-Key": apiKey } });
|
|
57
53
|
},
|
|
58
54
|
operations: {
|
|
59
|
-
"places.search":
|
|
55
|
+
"places.search": validatedOperation({ textQuery: { type: "string", required: true, minLength: 1, maxLength: 1000 }, pageSize: { type: "integer", min: 1, max: 20, defaultTo: 10 }, pageToken: { type: "string", minLength: 1, maxLength: 4096 }, languageCode: language }, body => ({ method: "POST", url: "https://places.googleapis.com/v1/places:searchText", headers: { "X-Goog-FieldMask": placeFields.split(",").map(field => `places.${field}`).join(",") + ",nextPageToken" }, body }),
|
|
60
56
|
result => Boolean(result && typeof result === "object" && !Array.isArray(result) && !result.error && (result.places === undefined || Array.isArray(result.places) && result.places.every(place => typeof place?.id === "string")))),
|
|
61
|
-
"places.get":
|
|
62
|
-
"routes.compute":
|
|
57
|
+
"places.get": validatedOperation({ placeId: { type: "string", required: true, minLength: 1, maxLength: 512, validator: value => /^[A-Za-z0-9_-]+$/.test(value) || "Use a place ID, not a URL." } }, ({ placeId }) => ({ method: "GET", url: `https://places.googleapis.com/v1/places/${encodeURIComponent(placeId)}`, headers: { "X-Goog-FieldMask": placeFields } }), result => typeof result?.id === "string"),
|
|
58
|
+
"routes.compute": validatedOperation({ originLatitude: latitude, originLongitude: longitude, destinationLatitude: latitude, destinationLongitude: longitude,
|
|
63
59
|
travelMode: { type: "string", enum: ["DRIVE", "WALK", "BICYCLE"], defaultTo: "DRIVE" }
|
|
64
60
|
}, ({ originLatitude, originLongitude, destinationLatitude, destinationLongitude, travelMode }) => ({ method: "POST", url: "https://routes.googleapis.com/directions/v2:computeRoutes", headers: { "X-Goog-FieldMask": "routes.distanceMeters,routes.duration,routes.polyline.geoJsonLinestring" }, body: {
|
|
65
61
|
origin: { location: { latLng: { latitude: originLatitude, longitude: originLongitude } } },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { googleSearchConsoleDefinition } from "../shared/google.js";
|
|
2
|
-
import { googleOperation, googleRead, googleProvider } from "./google.js";
|
|
2
|
+
import { googleOperation, googleRead, googleProvider, inputInvalid } from "./google.js";
|
|
3
3
|
const origin = "https://searchconsole.googleapis.com";
|
|
4
4
|
const readScopes = ["webmasters.readonly", "webmasters"];
|
|
5
5
|
const website = value => { try { const url = new URL(value); return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && !url.hash; } catch { return false; } };
|
|
@@ -17,7 +17,7 @@ const googleSearchConsoleProvider = googleProvider(googleSearchConsoleDefinition
|
|
|
17
17
|
type: { type: "string", enum: ["web", "image", "video", "news", "discover", "googleNews"], defaultTo: "web" },
|
|
18
18
|
rowLimit: { type: "integer", min: 1, max: 25000, defaultTo: 1000 }, startRow: { type: "integer", min: 0, defaultTo: 0 }
|
|
19
19
|
}, ({ siteUrl, filters, ...body }) => {
|
|
20
|
-
if (body.startDate > body.endDate) throw
|
|
20
|
+
if (body.startDate > body.endDate) throw inputInvalid("startDate must not follow endDate.");
|
|
21
21
|
return { method: "POST", url: `${propertyPath(siteUrl)}/searchAnalytics/query`, body: { ...body, dataState: "final", ...(filters?.length ? { dimensionFilterGroups: [{ groupType: "and", filters }] } : {}) } };
|
|
22
22
|
}, value => plain(value) && (value.rows === undefined || Array.isArray(value.rows))),
|
|
23
23
|
"urlInspection.inspect": googleOperation(readScopes, { siteUrl, inspectionUrl: { ...feedpath }, languageCode: { type: "string", minLength: 2, maxLength: 35 } }, body => ({ method: "POST", url: `${origin}/v1/urlInspection/index:inspect`, body }), value => plain(value?.inspectionResult)),
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { createSchema } from "json-rest-schema";
|
|
2
2
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
3
|
import { googleSheetsDefinition } from "../shared/google.js";
|
|
4
|
-
import { googleRead, googleProvider, googleFileVerification, documentId } from "./google.js";
|
|
4
|
+
import { googleOperation, googleBatchRequests, inputInvalid, googleRead, googleProvider, googleFileVerification, documentId } from "./google.js";
|
|
5
5
|
const origin = "https://sheets.googleapis.com";
|
|
6
6
|
const scopes = ["spreadsheets.readonly", "spreadsheets", "drive.readonly", "drive.file", "drive"];
|
|
7
|
-
const writable = ["spreadsheets", "drive.file", "drive"]
|
|
7
|
+
const writable = ["spreadsheets", "drive.file", "drive"];
|
|
8
8
|
const range = { type: "string", required: true, minLength: 1, maxLength: 2048 };
|
|
9
|
-
const inputOption = { type: "string", enum: ["RAW", "USER_ENTERED"],
|
|
9
|
+
const inputOption = { type: "string", enum: ["RAW", "USER_ENTERED"], defaultTo: "RAW" };
|
|
10
10
|
const values = { type: "array", required: true };
|
|
11
11
|
const validSheet = value => typeof value?.spreadsheetId === "string" && typeof value.properties?.title === "string";
|
|
12
12
|
const sheetUrl = id => `${origin}/v4/spreadsheets/${encodeURIComponent(id)}`;
|
|
13
13
|
const get = googleRead(scopes, { spreadsheetId: documentId }, ({ spreadsheetId }) => ({ url: sheetUrl(spreadsheetId), query: { includeGridData: false } }), validSheet);
|
|
14
|
-
function write(fields, destination, validateResult) {
|
|
15
|
-
const schema = createSchema(fields);
|
|
16
|
-
return { scopes: writable, validateResult, request(input) {
|
|
17
|
-
return destination(validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 }));
|
|
18
|
-
} };
|
|
19
|
-
}
|
|
20
14
|
function checkValues(rows) {
|
|
21
15
|
if (!rows.length || rows.length > 10000 || rows.some(row => !Array.isArray(row) || row.some(cell => cell !== null && typeof cell !== "string" && typeof cell !== "boolean" && !(typeof cell === "number" && Number.isFinite(cell)))) || rows.reduce((count, row) => count + row.length, 0) > 10000 || Buffer.byteLength(JSON.stringify(rows)) > 1048576) {
|
|
22
|
-
throw
|
|
16
|
+
throw inputInvalid("Supply a matrix of at most 10,000 cells and 1 MiB, containing strings, finite numbers, booleans or null.");
|
|
23
17
|
}
|
|
24
18
|
return rows;
|
|
25
19
|
}
|
|
@@ -27,32 +21,32 @@ const validUpdate = value => typeof value?.spreadsheetId === "string" && typeof
|
|
|
27
21
|
const base = googleProvider(googleSheetsDefinition, origin, "connection.verify", {
|
|
28
22
|
"connection.verify": googleFileVerification(get, "spreadsheetId"),
|
|
29
23
|
"spreadsheets.get": get,
|
|
30
|
-
"spreadsheets.create":
|
|
24
|
+
"spreadsheets.create": googleOperation(writable, { title: { type: "string", required: true, minLength: 1, maxLength: 1024 } }, ({ title }) => ({ method: "POST", url: `${origin}/v4/spreadsheets`, body: { properties: { title } } }), validSheet),
|
|
31
25
|
"values.get": googleRead(scopes, {
|
|
32
26
|
spreadsheetId: documentId, range,
|
|
33
27
|
valueRenderOption: { type: "string", enum: ["FORMATTED_VALUE", "UNFORMATTED_VALUE", "FORMULA"] },
|
|
34
28
|
dateTimeRenderOption: { type: "string", enum: ["SERIAL_NUMBER", "FORMATTED_STRING"] }
|
|
35
29
|
}, ({ spreadsheetId, range, ...query }) => ({ url: `${sheetUrl(spreadsheetId)}/values/${encodeURIComponent(range)}`, query }), value => typeof value?.range === "string" && (value.values === undefined || Array.isArray(value.values))),
|
|
36
|
-
"values.update":
|
|
30
|
+
"values.update": googleOperation(writable, { spreadsheetId: documentId, range, values, valueInputOption: inputOption }, ({ spreadsheetId, range, values, valueInputOption }) => ({
|
|
37
31
|
method: "PUT", url: `${sheetUrl(spreadsheetId)}/values/${encodeURIComponent(range)}?valueInputOption=${valueInputOption}`,
|
|
38
32
|
body: { range, majorDimension: "ROWS", values: checkValues(values) }
|
|
39
33
|
}), validUpdate),
|
|
40
|
-
"values.append":
|
|
34
|
+
"values.append": googleOperation(writable, { spreadsheetId: documentId, range, values, valueInputOption: inputOption, insertDataOption: { type: "string", enum: ["INSERT_ROWS", "OVERWRITE"], defaultTo: "INSERT_ROWS" } }, ({ spreadsheetId, range, values, valueInputOption, insertDataOption }) => ({
|
|
41
35
|
method: "POST", url: `${sheetUrl(spreadsheetId)}/values/${encodeURIComponent(range)}:append?valueInputOption=${valueInputOption}&insertDataOption=${insertDataOption}`,
|
|
42
36
|
body: { range, majorDimension: "ROWS", values: checkValues(values) }
|
|
43
37
|
}), value => typeof value?.spreadsheetId === "string" && validUpdate(value.updates)),
|
|
44
|
-
"values.clear":
|
|
45
|
-
"values.batchUpdate":
|
|
38
|
+
"values.clear": googleOperation(writable, { spreadsheetId: documentId, range }, ({ spreadsheetId, range }) => ({ method: "POST", url: `${sheetUrl(spreadsheetId)}/values/${encodeURIComponent(range)}:clear`, body: {} }), value => typeof value?.spreadsheetId === "string" && typeof value.clearedRange === "string"),
|
|
39
|
+
"values.batchUpdate": googleOperation(writable, { spreadsheetId: documentId, data: { type: "array", required: true }, valueInputOption: inputOption }, ({ spreadsheetId, data, valueInputOption }) => {
|
|
46
40
|
const schema = createSchema({ range, values });
|
|
47
|
-
if (!data.length || data.length > 100 || Buffer.byteLength(JSON.stringify(data)) > 1048576) throw
|
|
41
|
+
if (!data.length || data.length > 100 || Buffer.byteLength(JSON.stringify(data)) > 1048576) throw inputInvalid("Supply 1–100 ranges within 1 MiB.");
|
|
48
42
|
const ranges = data.map(value => {
|
|
49
43
|
const parsed = validateSchemaPayload({ schema, mode: "replace" }, value, { statusCode: 422 });
|
|
50
44
|
return { ...parsed, majorDimension: "ROWS", values: checkValues(parsed.values) };
|
|
51
45
|
});
|
|
52
46
|
return { method: "POST", url: `${sheetUrl(spreadsheetId)}/values:batchUpdate`, body: { data: ranges, valueInputOption } };
|
|
53
47
|
}, value => typeof value?.spreadsheetId === "string" && Array.isArray(value.responses)),
|
|
54
|
-
"spreadsheets.batchUpdate":
|
|
55
|
-
|
|
48
|
+
"spreadsheets.batchUpdate": googleOperation(writable, { spreadsheetId: documentId, requests: { type: "array", required: true } }, ({ spreadsheetId, requests }) => {
|
|
49
|
+
googleBatchRequests(requests, "Sheets");
|
|
56
50
|
return { method: "POST", url: `${sheetUrl(spreadsheetId)}:batchUpdate`, body: { requests } };
|
|
57
51
|
}, value => typeof value?.spreadsheetId === "string" && (value.replies === undefined || Array.isArray(value.replies)))
|
|
58
52
|
});
|