@jskit-ai/connectors-catalog 0.1.1
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 +192 -0
- package/docs/ai-upstream-notices.md +51 -0
- package/docs/ai.md +191 -0
- package/docs/airtable.md +130 -0
- package/docs/algolia.md +190 -0
- package/docs/amazon-redshift.md +229 -0
- package/docs/amplitude.md +210 -0
- package/docs/apify.md +162 -0
- package/docs/apollo-io.md +200 -0
- package/docs/asana.md +126 -0
- package/docs/ashby.md +188 -0
- package/docs/atlassian.md +224 -0
- package/docs/attention.md +162 -0
- package/docs/aws-athena.md +150 -0
- package/docs/aws-credentials.md +75 -0
- package/docs/aws-s3.md +193 -0
- package/docs/bigquery.md +146 -0
- package/docs/brevo.md +122 -0
- package/docs/calendly.md +158 -0
- package/docs/canva.md +191 -0
- package/docs/chargebee.md +192 -0
- package/docs/clay.md +194 -0
- package/docs/clickhouse.md +242 -0
- package/docs/confidence-exp.md +74 -0
- package/docs/confidence-flags.md +75 -0
- package/docs/confidence-oauth.md +137 -0
- package/docs/contentful.md +123 -0
- package/docs/databricks.md +180 -0
- package/docs/dbt-semantic-layer.md +175 -0
- package/docs/elevenlabs.md +102 -0
- package/docs/figma.md +132 -0
- package/docs/firebase-cloud-messaging.md +262 -0
- package/docs/firecrawl.md +137 -0
- package/docs/fireflies.md +95 -0
- package/docs/fireworks-ai.md +53 -0
- package/docs/gatewayapi.md +113 -0
- package/docs/gemini-enterprise.md +224 -0
- package/docs/github-api.md +133 -0
- package/docs/gitlab-api.md +138 -0
- package/docs/gmail.md +133 -0
- package/docs/gong.md +205 -0
- package/docs/google-ads.md +156 -0
- package/docs/google-analytics.md +202 -0
- package/docs/google-docs.md +105 -0
- package/docs/google-drive.md +108 -0
- package/docs/google-maps-platform.md +208 -0
- package/docs/google-oauth.md +123 -0
- package/docs/google-search-console.md +124 -0
- package/docs/google-sheets.md +94 -0
- package/docs/google-slides.md +95 -0
- package/docs/granola.md +178 -0
- package/docs/hex.md +161 -0
- package/docs/heygen.md +124 -0
- package/docs/hubspot.md +142 -0
- package/docs/incident-io.md +118 -0
- package/docs/inngest.md +178 -0
- package/docs/klipy.md +149 -0
- package/docs/lexware.md +144 -0
- package/docs/lightspeed.md +193 -0
- package/docs/linear.md +137 -0
- package/docs/linkedin.md +196 -0
- package/docs/logo-dev.md +152 -0
- package/docs/mailgun.md +153 -0
- package/docs/mapbox.md +174 -0
- package/docs/microsoft-excel.md +97 -0
- package/docs/microsoft-fabric.md +249 -0
- package/docs/microsoft-oauth.md +143 -0
- package/docs/microsoft-onedrive.md +76 -0
- package/docs/microsoft-onenote.md +75 -0
- package/docs/microsoft-outlook.md +90 -0
- package/docs/microsoft-powerpoint.md +119 -0
- package/docs/microsoft-sharepoint.md +75 -0
- package/docs/microsoft-teams.md +72 -0
- package/docs/microsoft-word.md +119 -0
- package/docs/miro.md +117 -0
- package/docs/n8n.md +169 -0
- package/docs/notion.md +137 -0
- package/docs/oura.md +161 -0
- package/docs/paddle.md +168 -0
- package/docs/perplexity.md +85 -0
- package/docs/pipedrive.md +120 -0
- package/docs/polar.md +63 -0
- package/docs/posthog.md +227 -0
- package/docs/prestashop.md +151 -0
- package/docs/replicate.md +60 -0
- package/docs/resend.md +153 -0
- package/docs/salesforce.md +234 -0
- package/docs/sanity.md +122 -0
- package/docs/semrush.md +276 -0
- package/docs/sentry.md +112 -0
- package/docs/sevdesk.md +107 -0
- package/docs/shopify.md +206 -0
- package/docs/slack.md +257 -0
- package/docs/snowflake.md +271 -0
- package/docs/storyblok.md +130 -0
- package/docs/stripe.md +77 -0
- package/docs/supabase.md +51 -0
- package/docs/tally.md +105 -0
- package/docs/telegram.md +165 -0
- package/docs/tiktok.md +201 -0
- package/docs/twilio.md +284 -0
- package/docs/twitch.md +428 -0
- package/docs/wave.md +440 -0
- package/docs/wix.md +1249 -0
- package/docs/wiz.md +177 -0
- package/docs/woocommerce.md +400 -0
- package/docs/wordpress-com.md +358 -0
- package/docs/wordpress-self-hosted.md +252 -0
- package/docs/workday.md +292 -0
- package/docs/x-twitter.md +188 -0
- package/docs/xero.md +429 -0
- package/docs/zoho-books.md +214 -0
- package/docs/zoho-crm.md +192 -0
- package/package.json +153 -0
- package/patterns/ai-connections/PATTERN.md +84 -0
- package/patterns/ai-connections/example/ai-model.js +11 -0
- package/patterns/ai-connections/example/perplexity-answer.js +29 -0
- package/patterns/api-key-connection/PATTERN.md +368 -0
- package/patterns/api-key-connection/example/connections.js +18 -0
- package/patterns/api-key-connection/example/integrations.json +19 -0
- package/patterns/assistant-mcp/PATTERN.md +110 -0
- package/patterns/assistant-mcp/example/integrations.json +13 -0
- package/patterns/assistant-mcp-oauth/PATTERN.md +235 -0
- package/patterns/assistant-mcp-oauth/example/integrations.json +102 -0
- package/patterns/aws-storage-queries/PATTERN.md +169 -0
- package/patterns/aws-storage-queries/example/formats/data-formats.js +35 -0
- package/patterns/aws-storage-queries/example/formats/package-lock.json +49 -0
- package/patterns/aws-storage-queries/example/formats/package.json +12 -0
- package/patterns/aws-storage-queries/example/formats/verify-formats.mjs +37 -0
- package/patterns/aws-storage-queries/example/integrations.json +38 -0
- package/patterns/aws-storage-queries/example/s3-transfer.js +34 -0
- package/patterns/event-delivery/PATTERN.md +151 -0
- package/patterns/event-delivery/example/integrations.json +17 -0
- package/patterns/firebase-messaging/PATTERN.md +156 -0
- package/patterns/firebase-messaging/example/server/notifications.js +23 -0
- package/patterns/google-ads-search/PATTERN.md +92 -0
- package/patterns/google-ads-search/example/ads-setup.js +25 -0
- package/patterns/oauth-connection/PATTERN.md +724 -0
- package/patterns/oauth-connection/example/integrations.json +20 -0
- package/patterns/paddle-catalogue/PATTERN.md +78 -0
- package/patterns/paddle-catalogue/example/create-products.js +38 -0
- package/patterns/public-image/PATTERN.md +84 -0
- package/patterns/public-image/example/integrations.json +13 -0
- package/patterns/public-image/example/logo-url.js +16 -0
- package/patterns/redshift-queries/PATTERN.md +150 -0
- package/patterns/redshift-queries/example/integrations.json +33 -0
- package/patterns/source-scanning/PATTERN.md +83 -0
- package/patterns/source-scanning/example/source-scanner.js +13 -0
- package/src/client/firebase-cloud-messaging.js +10 -0
- package/src/client/google-analytics.js +72 -0
- package/src/client/google-maps-platform.js +39 -0
- package/src/client/logo-dev.js +36 -0
- package/src/server/ai.js +46 -0
- package/src/server/airtable.js +67 -0
- package/src/server/algolia.js +63 -0
- package/src/server/amazon-redshift.js +96 -0
- package/src/server/amplitude.js +31 -0
- package/src/server/apify.js +68 -0
- package/src/server/apollo-io.js +85 -0
- package/src/server/asana.js +64 -0
- package/src/server/ashby.js +61 -0
- package/src/server/atlassian.js +32 -0
- package/src/server/attention.js +93 -0
- package/src/server/aws-athena.js +82 -0
- package/src/server/aws-s3.js +49 -0
- package/src/server/awsTransport.js +75 -0
- package/src/server/bigquery.js +97 -0
- package/src/server/brevo.js +97 -0
- package/src/server/calendly.js +77 -0
- package/src/server/canva.js +13 -0
- package/src/server/chargebee.js +88 -0
- package/src/server/clay.js +78 -0
- package/src/server/clickhouse.js +66 -0
- package/src/server/confidence.js +29 -0
- package/src/server/contentful.js +40 -0
- package/src/server/databricks.js +55 -0
- package/src/server/dbt-semantic-layer.js +95 -0
- package/src/server/elevenlabs.js +81 -0
- package/src/server/figma.js +24 -0
- package/src/server/firebase-cloud-messaging.js +111 -0
- package/src/server/firecrawl.js +70 -0
- package/src/server/fireflies.js +31 -0
- package/src/server/fireworks-ai.js +16 -0
- package/src/server/gatewayapi.js +48 -0
- package/src/server/gemini-enterprise.js +47 -0
- package/src/server/github-api.js +90 -0
- package/src/server/gitlab-api.js +67 -0
- package/src/server/gmail.js +60 -0
- package/src/server/gong.js +52 -0
- package/src/server/google-ads-search.js +134 -0
- package/src/server/google-ads.js +80 -0
- package/src/server/google-docs.js +36 -0
- package/src/server/google-drive.js +71 -0
- package/src/server/google-maps-platform.js +90 -0
- package/src/server/google-search-console.js +31 -0
- package/src/server/google-sheets.js +60 -0
- package/src/server/google-slides.js +36 -0
- package/src/server/google.js +61 -0
- package/src/server/granola.js +115 -0
- package/src/server/graphqlOperation.js +15 -0
- package/src/server/hex.js +29 -0
- package/src/server/heygen.js +54 -0
- package/src/server/hubspot.js +85 -0
- package/src/server/incident-io.js +68 -0
- package/src/server/inngest.js +86 -0
- package/src/server/jsonOperation.js +34 -0
- package/src/server/klipy.js +34 -0
- package/src/server/lexware.js +59 -0
- package/src/server/lightspeed.js +82 -0
- package/src/server/linear.js +52 -0
- package/src/server/linkedin.js +74 -0
- package/src/server/mailgun.js +76 -0
- package/src/server/mapbox.js +46 -0
- package/src/server/mcpRegistration.js +41 -0
- package/src/server/mcpTransport.js +60 -0
- package/src/server/microsoft-excel.js +67 -0
- package/src/server/microsoft-fabric.js +81 -0
- package/src/server/microsoft-onedrive.js +58 -0
- package/src/server/microsoft-onenote.js +52 -0
- package/src/server/microsoft-outlook.js +58 -0
- package/src/server/microsoft-powerpoint.js +5 -0
- package/src/server/microsoft-sharepoint.js +46 -0
- package/src/server/microsoft-teams.js +29 -0
- package/src/server/microsoft-word.js +5 -0
- package/src/server/microsoft.js +88 -0
- package/src/server/miro.js +29 -0
- package/src/server/n8n.js +78 -0
- package/src/server/notion.js +76 -0
- package/src/server/oura.js +48 -0
- package/src/server/paddle.js +83 -0
- package/src/server/perplexity.js +15 -0
- package/src/server/pipedrive.js +95 -0
- package/src/server/polar.js +20 -0
- package/src/server/posthog.js +44 -0
- package/src/server/prestashop.js +42 -0
- package/src/server/replicate.js +42 -0
- package/src/server/resend.js +93 -0
- package/src/server/salesforce.js +84 -0
- package/src/server/sanity.js +31 -0
- package/src/server/semrush.js +359 -0
- package/src/server/sentry.js +30 -0
- package/src/server/sevdesk.js +20 -0
- package/src/server/shopify.js +99 -0
- package/src/server/slack.js +143 -0
- package/src/server/snowflake.js +139 -0
- package/src/server/storyblok.js +49 -0
- package/src/server/stripe.js +13 -0
- package/src/server/supabase.js +13 -0
- package/src/server/tally.js +78 -0
- package/src/server/telegram.js +55 -0
- package/src/server/tiktok.js +86 -0
- package/src/server/twilio.js +90 -0
- package/src/server/twitch.js +409 -0
- package/src/server/wave.js +520 -0
- package/src/server/wix.js +1048 -0
- package/src/server/wiz.js +117 -0
- package/src/server/woocommerce.js +412 -0
- package/src/server/wordpress-com.js +236 -0
- package/src/server/wordpress-self-hosted.js +134 -0
- package/src/server/workday.js +136 -0
- package/src/server/x-twitter.js +110 -0
- package/src/server/xero.js +397 -0
- package/src/server/zoho-books.js +90 -0
- package/src/server/zoho-crm.js +89 -0
- package/src/server/zohoOAuth.js +21 -0
- package/src/shared/ai-models.json +8049 -0
- package/src/shared/ai.js +63 -0
- package/src/shared/algolia.js +29 -0
- package/src/shared/amazon-redshift.js +51 -0
- package/src/shared/amplitude.js +28 -0
- package/src/shared/atlassian.js +43 -0
- package/src/shared/aws.js +72 -0
- package/src/shared/canva.js +66 -0
- package/src/shared/chargebee.js +26 -0
- package/src/shared/clickhouse.js +38 -0
- package/src/shared/confidence.js +28 -0
- package/src/shared/databricks.js +33 -0
- package/src/shared/dbt-semantic-layer.js +32 -0
- package/src/shared/definitions.js +140 -0
- package/src/shared/figma.js +21 -0
- package/src/shared/firebase-cloud-messaging.js +45 -0
- package/src/shared/gemini-enterprise.js +33 -0
- package/src/shared/gong.js +33 -0
- package/src/shared/google-ads-search.js +31 -0
- package/src/shared/google-ads.js +28 -0
- package/src/shared/google-maps-platform.js +28 -0
- package/src/shared/google.js +133 -0
- package/src/shared/granola.js +25 -0
- package/src/shared/hex.js +28 -0
- package/src/shared/inngest.js +35 -0
- package/src/shared/lightspeed.js +75 -0
- package/src/shared/linkedin.js +27 -0
- package/src/shared/logo-dev.js +21 -0
- package/src/shared/mapbox.js +38 -0
- package/src/shared/mcp.js +92 -0
- package/src/shared/microsoft-fabric.js +47 -0
- package/src/shared/microsoft.js +231 -0
- package/src/shared/miro.js +27 -0
- package/src/shared/oura.js +23 -0
- package/src/shared/posthog.js +33 -0
- package/src/shared/prestashop.js +23 -0
- package/src/shared/salesforce.js +36 -0
- package/src/shared/semrush.js +24 -0
- package/src/shared/shopify.js +51 -0
- package/src/shared/siteUrl.js +12 -0
- package/src/shared/slack.js +88 -0
- package/src/shared/snowflake.js +55 -0
- package/src/shared/tiktok.js +22 -0
- package/src/shared/tokens.js +747 -0
- package/src/shared/twilio.js +41 -0
- package/src/shared/twitch.js +49 -0
- package/src/shared/wave.js +52 -0
- package/src/shared/wix.js +40 -0
- package/src/shared/wiz.js +41 -0
- package/src/shared/wordpress-com.js +30 -0
- package/src/shared/wordpress.js +69 -0
- package/src/shared/workday.js +50 -0
- package/src/shared/x-twitter.js +19 -0
- package/src/shared/xero.js +46 -0
- package/src/shared/zoho-books.js +39 -0
- package/src/shared/zoho-crm.js +43 -0
- package/src/shared/zoho-regions.js +12 -0
- package/test/ai.test.js +136 -0
- package/test/airtable.test.js +125 -0
- package/test/algolia.test.js +207 -0
- package/test/amazon-redshift.test.js +272 -0
- package/test/amplitude.test.js +239 -0
- package/test/apify.test.js +93 -0
- package/test/apollo-io.test.js +125 -0
- package/test/asana.test.js +99 -0
- package/test/ashby.test.js +97 -0
- package/test/atlassian.test.js +249 -0
- package/test/attention.test.js +79 -0
- package/test/aws.test.js +405 -0
- package/test/brevo.test.js +71 -0
- package/test/calendly.test.js +136 -0
- package/test/canva.test.js +258 -0
- package/test/chargebee.test.js +195 -0
- package/test/clickhouse.test.js +278 -0
- package/test/confidence.test.js +205 -0
- package/test/databricks.test.js +253 -0
- package/test/dbt-semantic-layer.test.js +221 -0
- package/test/designMcp.test.js +336 -0
- package/test/elevenlabs.test.js +52 -0
- package/test/firebase-cloud-messaging.test.js +242 -0
- package/test/firecrawl.test.js +66 -0
- package/test/gemini-enterprise.test.js +218 -0
- package/test/github-api.test.js +167 -0
- package/test/gitlab-api.test.js +160 -0
- package/test/gong.test.js +192 -0
- package/test/google-ads.test.js +350 -0
- package/test/google-maps-platform.test.js +191 -0
- package/test/google.test.js +710 -0
- package/test/granola.test.js +240 -0
- package/test/hex.test.js +253 -0
- package/test/heygen.test.js +121 -0
- package/test/hubspot.test.js +103 -0
- package/test/inngest.test.js +219 -0
- package/test/lightspeed.test.js +250 -0
- package/test/linear.test.js +146 -0
- package/test/linkedin.test.js +243 -0
- package/test/logo-dev.test.js +79 -0
- package/test/mailgun.test.js +107 -0
- package/test/mapbox.test.js +181 -0
- package/test/mcp.test.js +227 -0
- package/test/microsoft-fabric.test.js +258 -0
- package/test/microsoft.test.js +554 -0
- package/test/n8nOAuth.test.js +188 -0
- package/test/notionOAuth.test.js +183 -0
- package/test/oura.test.js +211 -0
- package/test/paddleCatalogue.test.js +51 -0
- package/test/paddlePermissions.test.js +101 -0
- package/test/perplexityComposition.test.js +39 -0
- package/test/pipedriveOAuth.test.js +140 -0
- package/test/posthog.test.js +200 -0
- package/test/prestashop.test.js +207 -0
- package/test/resend.test.js +163 -0
- package/test/salesforce.test.js +276 -0
- package/test/semrush.test.js +479 -0
- package/test/sentry.test.js +35 -0
- package/test/shopify.test.js +247 -0
- package/test/slack.test.js +320 -0
- package/test/snowflake.test.js +391 -0
- package/test/tally.test.js +75 -0
- package/test/telegram.test.js +58 -0
- package/test/tiktok.test.js +243 -0
- package/test/tokens.test.js +1079 -0
- package/test/twilio.test.js +221 -0
- package/test/twitch.test.js +573 -0
- package/test/wave.test.js +678 -0
- package/test/wix.test.js +1099 -0
- package/test/wiz.test.js +185 -0
- package/test/wordpress-com.test.js +469 -0
- package/test/wordpress.test.js +660 -0
- package/test/workday.test.js +314 -0
- package/test/x-twitter.test.js +256 -0
- package/test/xero.test.js +700 -0
- package/test/zoho-books.test.js +253 -0
- package/test/zoho-crm.test.js +223 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { createSchema } from "json-rest-schema";
|
|
2
|
+
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
|
+
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
4
|
+
import { wordpressComDefinition } from "../shared/wordpress-com.js";
|
|
5
|
+
import { jsonOperation } from "./jsonOperation.js";
|
|
6
|
+
|
|
7
|
+
const postsSchema = createSchema({
|
|
8
|
+
siteId: { type: "integer", required: true, min: 1, max: Number.MAX_SAFE_INTEGER },
|
|
9
|
+
number: { type: "integer", min: 1, max: 100, defaultTo: 20 },
|
|
10
|
+
page_handle: { type: "string", minLength: 1, maxLength: 4096 },
|
|
11
|
+
search: { type: "string", minLength: 1, maxLength: 500 },
|
|
12
|
+
status: { type: "string", enum: ["publish", "private", "draft", "pending", "future", "trash", "any"], defaultTo: "publish" },
|
|
13
|
+
context: { type: "string", enum: ["display", "edit"], defaultTo: "display" },
|
|
14
|
+
type: { type: "string", enum: ["post", "page"] }
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const resourceId = { type: "integer", required: true, min: 1, max: Number.MAX_SAFE_INTEGER };
|
|
18
|
+
const batchSchema = createSchema({
|
|
19
|
+
siteId: resourceId,
|
|
20
|
+
resources: { type: "array", required: true, items: { type: "string", enum: ["posts", "media", "comments", "categories", "tags", "stats"] },
|
|
21
|
+
validator: values => values.length >= 1 && values.length <= 6 && new Set(values).size === values.length || "Select one to six distinct site resources." }
|
|
22
|
+
});
|
|
23
|
+
const editContext = { type: "string", enum: ["display", "edit"], defaultTo: "edit" };
|
|
24
|
+
const contentFields = {
|
|
25
|
+
title: { type: "string", noTrim: true, maxLength: 10000 },
|
|
26
|
+
content: { type: "string", noTrim: true, maxLength: 1000000 },
|
|
27
|
+
excerpt: { type: "string", noTrim: true, maxLength: 100000 },
|
|
28
|
+
slug: { type: "string", minLength: 1, maxLength: 200 },
|
|
29
|
+
status: { type: "string", enum: ["draft", "pending", "publish", "private"] },
|
|
30
|
+
type: { type: "string", enum: ["post", "page"] },
|
|
31
|
+
parent: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER },
|
|
32
|
+
categories: { type: "array", items: { type: "integer", min: 1, max: Number.MAX_SAFE_INTEGER }, validator: values => values.length <= 100 || "Use at most 100 category IDs." },
|
|
33
|
+
tags: { type: "array", items: { type: "integer", min: 1, max: Number.MAX_SAFE_INTEGER }, validator: values => values.length <= 100 || "Use at most 100 tag IDs." },
|
|
34
|
+
featured_image: { type: "string", maxLength: 20, validator: value => value === "" || /^[1-9][0-9]*$/u.test(value) || "Use an attachment ID or an empty string to clear it." },
|
|
35
|
+
publicize: { type: "boolean" }
|
|
36
|
+
};
|
|
37
|
+
const postRecord = value => Number.isSafeInteger(value?.ID) && value.ID > 0 &&
|
|
38
|
+
Number.isSafeInteger(value.site_ID) && value.site_ID > 0 && typeof value.title === "string" && typeof value.status === "string";
|
|
39
|
+
function siteOperation(action, fields, { resource = "posts", scope = resource, read = false, changesRequired = false, collection = false, validateResult = postRecord } = {}) {
|
|
40
|
+
const schema = createSchema({ siteId: resourceId, ...fields, context: editContext });
|
|
41
|
+
return {
|
|
42
|
+
scopes: [scope],
|
|
43
|
+
request(input) {
|
|
44
|
+
const { siteId, postId, mediaId, commentId, termSlug, context, ...values } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
45
|
+
delete values.confirmDeletion;
|
|
46
|
+
if (changesRequired && !Object.keys(values).length) {
|
|
47
|
+
throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
|
48
|
+
}
|
|
49
|
+
const target = termSlug === undefined ? postId ?? mediaId ?? commentId ?? (collection ? "" : "new") : `slug:${encodeURIComponent(termSlug)}`;
|
|
50
|
+
const url = new URL(`https://public-api.wordpress.com/rest/v1.1/sites/${siteId}/${resource}/${target}${action ? `/${action}` : ""}`);
|
|
51
|
+
url.searchParams.set("context", context);
|
|
52
|
+
if (read) {
|
|
53
|
+
for (const [key, value] of Object.entries(values)) url.searchParams.set(key, String(value));
|
|
54
|
+
return { method: "GET", url: url.href };
|
|
55
|
+
}
|
|
56
|
+
const body = new URLSearchParams();
|
|
57
|
+
for (const [key, value] of Object.entries(values)) body.set(key, String(value));
|
|
58
|
+
return { method: "POST", url: url.href, headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: body.toString() };
|
|
59
|
+
},
|
|
60
|
+
validateResult
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const mediaRecord = value => Number.isSafeInteger(value?.ID) && value.ID > 0 && typeof value.URL === "string" && typeof value.title === "string";
|
|
65
|
+
const commentRecord = value => Number.isSafeInteger(value?.ID) && value.ID > 0 && typeof value.content === "string" && typeof value.status === "string";
|
|
66
|
+
const commentOptions = { resource: "comments", validateResult: commentRecord };
|
|
67
|
+
const commentText = { type: "string", required: true, minLength: 1, maxLength: 100000, noTrim: true };
|
|
68
|
+
const termRecord = value => Number.isSafeInteger(value?.ID) && value.ID > 0 && typeof value.name === "string" && typeof value.slug === "string";
|
|
69
|
+
const termSlug = { type: "string", required: true, minLength: 1, maxLength: 600,
|
|
70
|
+
validator: value => !/[\\/\p{Cc}]/u.test(value) && ![".", ".."].includes(value) || "Use a term slug, not a path." };
|
|
71
|
+
const taxonomyOperations = Object.fromEntries(["categories", "tags"].flatMap(resource => {
|
|
72
|
+
const fields = {
|
|
73
|
+
name: { type: "string", minLength: 1, maxLength: 200 },
|
|
74
|
+
description: { type: "string", maxLength: 100000, noTrim: true },
|
|
75
|
+
...(resource === "categories" ? { parent: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER } } : {})
|
|
76
|
+
};
|
|
77
|
+
const options = { resource, scope: "taxonomy", validateResult: termRecord };
|
|
78
|
+
return [
|
|
79
|
+
[`${resource}.list`, siteOperation("", {
|
|
80
|
+
number: { type: "integer", min: 1, max: 1000, defaultTo: 100 },
|
|
81
|
+
page: { type: "integer", min: 1, max: 100000, defaultTo: 1 },
|
|
82
|
+
search: { type: "string", minLength: 1, maxLength: 500 }
|
|
83
|
+
}, { ...options, read: true, collection: true,
|
|
84
|
+
validateResult: value => Number.isSafeInteger(value?.found) && value.found >= 0 && Array.isArray(value[resource]) && value[resource].every(termRecord) })],
|
|
85
|
+
[`${resource}.get`, siteOperation("", { termSlug }, { ...options, read: true })],
|
|
86
|
+
[`${resource}.create`, siteOperation("", { ...fields, name: { ...fields.name, required: true } }, options)],
|
|
87
|
+
[`${resource}.update`, siteOperation("", { termSlug, ...fields }, { ...options, changesRequired: true })],
|
|
88
|
+
[`${resource}.delete`, siteOperation("delete", {
|
|
89
|
+
termSlug, confirmDeletion: { type: "boolean", required: true, validator: value => value === true || "Confirm removal of this category or tag." }
|
|
90
|
+
}, options)]
|
|
91
|
+
];
|
|
92
|
+
}));
|
|
93
|
+
const mediaOptions = { resource: "media", validateResult: mediaRecord };
|
|
94
|
+
const mediaFields = {
|
|
95
|
+
title: contentFields.title, caption: contentFields.excerpt, description: contentFields.content,
|
|
96
|
+
alt: { type: "string", maxLength: 10000, noTrim: true },
|
|
97
|
+
parent_id: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER }
|
|
98
|
+
};
|
|
99
|
+
const mediaUploadSchema = createSchema({
|
|
100
|
+
siteId: resourceId, ...mediaFields,
|
|
101
|
+
filename: { type: "string", required: true, minLength: 1, maxLength: 255,
|
|
102
|
+
validator: value => !/[\\/\p{Cc}"]/u.test(value) && ![".", ".."].includes(value) || "Use a filename without paths, quotes or control characters." },
|
|
103
|
+
mimeType: { type: "string", required: true, maxLength: 150, pattern: "^[a-zA-Z0-9.+-]+/[a-zA-Z0-9.+-]+$" },
|
|
104
|
+
contentBase64: { type: "string", required: true, minLength: 4, maxLength: 6990508, noTrim: true }
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const wordpressComProvider = Object.freeze({
|
|
108
|
+
...wordpressComDefinition,
|
|
109
|
+
oauth: {
|
|
110
|
+
issuer: "https://public-api.wordpress.com",
|
|
111
|
+
authorization_endpoint: "https://public-api.wordpress.com/oauth2/authorize",
|
|
112
|
+
token_endpoint: "https://public-api.wordpress.com/oauth2/token"
|
|
113
|
+
},
|
|
114
|
+
scopeSeparator: ",",
|
|
115
|
+
apiOrigins: ["https://public-api.wordpress.com"], checkOperation: "profile.read",
|
|
116
|
+
grantedScopesFromVerification(profile, { clientId }) {
|
|
117
|
+
if (String(profile.token_client_id) !== clientId) {
|
|
118
|
+
throw new ConnectorError("connector_response_invalid", "The verified token belongs to a different application.", { statusCode: 502 });
|
|
119
|
+
}
|
|
120
|
+
return profile.token_scope;
|
|
121
|
+
},
|
|
122
|
+
operations: {
|
|
123
|
+
...taxonomyOperations,
|
|
124
|
+
"batch.read": {
|
|
125
|
+
scopes: ["batch"],
|
|
126
|
+
request(input) {
|
|
127
|
+
const { siteId, resources } = validateSchemaPayload({ schema: batchSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
128
|
+
const url = new URL("https://public-api.wordpress.com/rest/v1.3/batch/");
|
|
129
|
+
for (const resource of resources) {
|
|
130
|
+
url.searchParams.append("urls[]", `/sites/${siteId}/${resource}?context=edit${resource === "stats" ? "" : "&number=20"}`);
|
|
131
|
+
}
|
|
132
|
+
return { method: "GET", url: url.href };
|
|
133
|
+
},
|
|
134
|
+
validateResult: value => value !== null && typeof value === "object" && !Array.isArray(value) &&
|
|
135
|
+
Object.keys(value).length > 0 && Object.values(value).every(entry => entry !== null && typeof entry === "object")
|
|
136
|
+
},
|
|
137
|
+
"stats.read": siteOperation("", {}, {
|
|
138
|
+
resource: "stats", read: true, collection: true,
|
|
139
|
+
validateResult: value => typeof value?.date === "string" && value.stats !== null && typeof value.stats === "object" &&
|
|
140
|
+
value.visits !== null && typeof value.visits === "object"
|
|
141
|
+
}),
|
|
142
|
+
"comments.list": siteOperation("", {
|
|
143
|
+
number: { type: "integer", min: 1, max: 100, defaultTo: 20 },
|
|
144
|
+
page: { type: "integer", min: 1, max: 100000, defaultTo: 1 },
|
|
145
|
+
status: { type: "string", enum: ["approved", "unapproved", "spam", "trash", "all"], defaultTo: "approved" },
|
|
146
|
+
order: { type: "string", enum: ["ASC", "DESC"], defaultTo: "DESC" }
|
|
147
|
+
}, { ...commentOptions, read: true, collection: true,
|
|
148
|
+
validateResult: value => Number.isSafeInteger(value?.found) && value.found >= 0 && Array.isArray(value.comments) && value.comments.every(commentRecord) }),
|
|
149
|
+
"comments.get": siteOperation("", { commentId: resourceId }, { ...commentOptions, read: true }),
|
|
150
|
+
"comments.create": siteOperation("replies/new", { postId: resourceId, content: commentText }, {
|
|
151
|
+
resource: "posts", scope: "comments", validateResult: commentRecord
|
|
152
|
+
}),
|
|
153
|
+
"comments.reply": siteOperation("replies/new", { commentId: resourceId, content: commentText }, commentOptions),
|
|
154
|
+
"comments.update": siteOperation("", {
|
|
155
|
+
commentId: resourceId, content: { ...commentText, required: false },
|
|
156
|
+
status: { type: "string", required: true, enum: ["approved", "unapproved", "spam", "unspam", "trash", "untrash"] }
|
|
157
|
+
}, commentOptions),
|
|
158
|
+
"comments.delete": siteOperation("delete", {
|
|
159
|
+
commentId: resourceId,
|
|
160
|
+
confirmDeletion: { type: "boolean", required: true, validator: value => value === true || "Confirm deletion, which may permanently remove the comment." }
|
|
161
|
+
}, commentOptions),
|
|
162
|
+
"posts.get": siteOperation("", { postId: resourceId }, { read: true }),
|
|
163
|
+
"posts.create": siteOperation("", {
|
|
164
|
+
...contentFields,
|
|
165
|
+
title: { ...contentFields.title, required: true, minLength: 1 },
|
|
166
|
+
status: { ...contentFields.status, defaultTo: "draft" },
|
|
167
|
+
type: { ...contentFields.type, defaultTo: "post" },
|
|
168
|
+
publicize: { ...contentFields.publicize, defaultTo: false }
|
|
169
|
+
}),
|
|
170
|
+
"posts.update": siteOperation("", { ...contentFields, postId: resourceId }, { changesRequired: true }),
|
|
171
|
+
"posts.delete": siteOperation("delete", {
|
|
172
|
+
postId: resourceId,
|
|
173
|
+
confirmDeletion: { type: "boolean", required: true, validator: value => value === true || "Confirm deletion, which may be permanent on this site or for an already-trashed post." }
|
|
174
|
+
}),
|
|
175
|
+
"posts.restore": siteOperation("restore", { postId: resourceId }),
|
|
176
|
+
"media.list": siteOperation("", {
|
|
177
|
+
number: { type: "integer", min: 1, max: 100, defaultTo: 20 },
|
|
178
|
+
page_handle: { type: "string", minLength: 1, maxLength: 4096 },
|
|
179
|
+
search: { type: "string", minLength: 1, maxLength: 500 },
|
|
180
|
+
post_ID: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER },
|
|
181
|
+
mime_type: { type: "string", minLength: 1, maxLength: 150 }
|
|
182
|
+
}, { ...mediaOptions, read: true, collection: true,
|
|
183
|
+
validateResult: value => Number.isSafeInteger(value?.found) && value.found >= 0 && Array.isArray(value.media) && value.media.every(mediaRecord) &&
|
|
184
|
+
(value.meta?.next_page == null || typeof value.meta.next_page === "string") }),
|
|
185
|
+
"media.get": siteOperation("", { mediaId: resourceId }, { ...mediaOptions, read: true }),
|
|
186
|
+
"media.update": siteOperation("", { mediaId: resourceId, ...mediaFields }, { ...mediaOptions, changesRequired: true }),
|
|
187
|
+
"media.delete": siteOperation("delete", {
|
|
188
|
+
mediaId: resourceId,
|
|
189
|
+
confirmDeletion: { type: "boolean", required: true, validator: value => value === true || "Confirm permanent media deletion." }
|
|
190
|
+
}, { ...mediaOptions, validateResult: value => mediaRecord(value) && value.status === "deleted" }),
|
|
191
|
+
"media.upload": {
|
|
192
|
+
scopes: ["media"],
|
|
193
|
+
request(input) {
|
|
194
|
+
const { siteId, filename, mimeType, contentBase64, ...metadata } = validateSchemaPayload({ schema: mediaUploadSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
195
|
+
const bytes = Buffer.from(contentBase64, "base64");
|
|
196
|
+
if (!bytes.length || bytes.length > 5 * 1024 * 1024 || bytes.toString("base64") !== contentBase64) {
|
|
197
|
+
throw new ConnectorError("connector_input_invalid", "Supply canonical base64 for a nonempty file of at most 5 MiB.", { statusCode: 422 });
|
|
198
|
+
}
|
|
199
|
+
const body = new FormData();
|
|
200
|
+
body.append("media[0]", new Blob([bytes], { type: mimeType }), filename);
|
|
201
|
+
for (const [key, value] of Object.entries(metadata)) body.append(`attrs[0][${key}]`, String(value));
|
|
202
|
+
return { method: "POST", url: `https://public-api.wordpress.com/rest/v1.1/sites/${siteId}/media/new?context=edit`, body };
|
|
203
|
+
},
|
|
204
|
+
validateResult: value => Array.isArray(value?.media) && value.media.every(mediaRecord) &&
|
|
205
|
+
(value.media_errors == null || Array.isArray(value.media_errors) || typeof value.media_errors === "object")
|
|
206
|
+
},
|
|
207
|
+
"profile.read": {
|
|
208
|
+
...jsonOperation("https://public-api.wordpress.com/rest/v1.1/me?fields=ID,username,display_name,token_scope,token_client_id,token_site_id", {},
|
|
209
|
+
(result) => Number.isSafeInteger(result?.ID) && result.ID > 0 && typeof result.username === "string" &&
|
|
210
|
+
typeof result.display_name === "string" && Number.isSafeInteger(result.token_client_id) && result.token_client_id > 0 &&
|
|
211
|
+
Number.isSafeInteger(result.token_site_id) && result.token_site_id >= 0 &&
|
|
212
|
+
Array.isArray(result.token_scope) && result.token_scope.every((scope) => typeof scope === "string" && scope.length > 0)),
|
|
213
|
+
scopes: ["users"]
|
|
214
|
+
},
|
|
215
|
+
"sites.list": {
|
|
216
|
+
...jsonOperation("https://public-api.wordpress.com/rest/v1.1/me/sites", {
|
|
217
|
+
site_visibility: { type: "string", enum: ["all", "visible", "hidden"], defaultTo: "all" },
|
|
218
|
+
site_activity: { type: "string", enum: ["all", "active", "inactive"], defaultTo: "all" }
|
|
219
|
+
}, (result) => Array.isArray(result?.sites) && result.sites.every((site) => Number.isSafeInteger(site?.ID) && site.ID > 0 && typeof site.URL === "string")),
|
|
220
|
+
scopes: ["sites"]
|
|
221
|
+
},
|
|
222
|
+
"posts.list": {
|
|
223
|
+
scopes: ["posts"],
|
|
224
|
+
request(input) {
|
|
225
|
+
const { siteId, ...values } = validateSchemaPayload({ schema: postsSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
226
|
+
const url = new URL(`https://public-api.wordpress.com/rest/v1.1/sites/${siteId}/posts/`);
|
|
227
|
+
for (const [key, value] of Object.entries(values)) url.searchParams.set(key, String(value));
|
|
228
|
+
return { method: "GET", url: url.href };
|
|
229
|
+
},
|
|
230
|
+
validateResult: (result) => Number.isSafeInteger(result?.found) && result.found >= 0 && Array.isArray(result.posts) &&
|
|
231
|
+
result.posts.every((post) => Number.isSafeInteger(post?.ID) && post.ID > 0 && typeof post.title === "string") &&
|
|
232
|
+
(result.meta?.next_page == null || typeof result.meta.next_page === "string")
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
export { wordpressComProvider };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
2
|
+
import { createSchema } from "json-rest-schema";
|
|
3
|
+
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
4
|
+
import { wordpressSelfHostedDefinition } from "../shared/wordpress.js";
|
|
5
|
+
import { jsonOperation } from "./jsonOperation.js";
|
|
6
|
+
|
|
7
|
+
const baseUrl = (settings) => `${settings.siteUrl.replace(/\/+$/u, "")}/wp-json/wp/v2`;
|
|
8
|
+
const id = { type: "integer", min: 1, max: Number.MAX_SAFE_INTEGER, required: true };
|
|
9
|
+
const view = { type: "string", enum: ["view", "edit", "embed"], defaultTo: "view" };
|
|
10
|
+
const status = { type: "string", enum: ["publish", "draft", "pending", "private"] };
|
|
11
|
+
const contentRecord = (value) => Number.isSafeInteger(value?.id) && value.id > 0 && typeof value.title?.rendered === "string";
|
|
12
|
+
const contentFields = {
|
|
13
|
+
title: { type: "string", maxLength: 10000, noTrim: true },
|
|
14
|
+
content: { type: "string", maxLength: 1000000, noTrim: true },
|
|
15
|
+
excerpt: { type: "string", maxLength: 100000, noTrim: true },
|
|
16
|
+
slug: { type: "string", minLength: 1, maxLength: 200 },
|
|
17
|
+
status,
|
|
18
|
+
featured_media: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER },
|
|
19
|
+
comment_status: { type: "string", enum: ["open", "closed"] }
|
|
20
|
+
};
|
|
21
|
+
function wordpressOperation(resource, fields, method, validateResult, { write = false } = {}) {
|
|
22
|
+
const schema = createSchema(fields);
|
|
23
|
+
return { scopes: [], request(input, settings) {
|
|
24
|
+
const { id: resourceId, ...values } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
25
|
+
const url = new URL(`${baseUrl(settings)}/${resource}${resourceId ? `/${resourceId}` : ""}`);
|
|
26
|
+
if (write) {
|
|
27
|
+
if (!Object.keys(values).length) throw new ConnectorError("connector_input_invalid", "Supply at least one change.", { statusCode: 422 });
|
|
28
|
+
return { method, url: url.href, body: values };
|
|
29
|
+
}
|
|
30
|
+
for (const [key, value] of Object.entries(values)) url.searchParams.set(key, String(value));
|
|
31
|
+
if (method === "DELETE" && !url.searchParams.has("force")) url.searchParams.set("force", "false");
|
|
32
|
+
return { method, url: url.href };
|
|
33
|
+
}, validateResult };
|
|
34
|
+
}
|
|
35
|
+
const contentOperations = Object.fromEntries(["posts", "pages"].flatMap((resource) => {
|
|
36
|
+
const fields = { ...contentFields, ...(resource === "pages" ? {
|
|
37
|
+
parent: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER },
|
|
38
|
+
menu_order: { type: "integer", min: -2147483648, max: 2147483647 }
|
|
39
|
+
} : {}) };
|
|
40
|
+
return [
|
|
41
|
+
[`${resource}.get`, wordpressOperation(resource, { id, context: view }, "GET", contentRecord)],
|
|
42
|
+
[`${resource}.create`, wordpressOperation(resource, { ...fields,
|
|
43
|
+
title: { ...fields.title, required: true, minLength: 1 }, status: { ...status, defaultTo: "draft" }
|
|
44
|
+
}, "POST", contentRecord, { write: true })],
|
|
45
|
+
[`${resource}.update`, wordpressOperation(resource, { id, ...fields }, "POST", contentRecord, { write: true })],
|
|
46
|
+
[`${resource}.trash`, wordpressOperation(resource, { id }, "DELETE",
|
|
47
|
+
value => contentRecord(value) && value.status === "trash")]
|
|
48
|
+
];
|
|
49
|
+
}));
|
|
50
|
+
const listFields = {
|
|
51
|
+
page: { type: "integer", min: 1, max: 100000, defaultTo: 1 },
|
|
52
|
+
per_page: { type: "integer", min: 1, max: 100, defaultTo: 10 },
|
|
53
|
+
search: { type: "string", minLength: 1, maxLength: 500 }, context: view
|
|
54
|
+
};
|
|
55
|
+
const mediaRecord = (value) => contentRecord(value) && typeof value.source_url === "string";
|
|
56
|
+
const userRecord = (value) => Number.isSafeInteger(value?.id) && value.id > 0 && typeof value.name === "string" &&
|
|
57
|
+
typeof value.slug === "string" && !Object.hasOwn(value, "password");
|
|
58
|
+
const permanent = { type: "boolean", required: true, validator: value => value === true || "Explicitly confirm permanent deletion with force: true." };
|
|
59
|
+
const mediaFields = {
|
|
60
|
+
title: contentFields.title,
|
|
61
|
+
caption: contentFields.excerpt,
|
|
62
|
+
description: contentFields.content,
|
|
63
|
+
alt_text: { type: "string", maxLength: 10000, noTrim: true },
|
|
64
|
+
post: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER }
|
|
65
|
+
};
|
|
66
|
+
const uploadSchema = createSchema({ ...mediaFields,
|
|
67
|
+
filename: { type: "string", required: true, minLength: 1, maxLength: 255,
|
|
68
|
+
validator: value => !/[\\/\p{Cc}"]/u.test(value) && ![".", ".."].includes(value) || "Use a filename without paths, quotes or control characters." },
|
|
69
|
+
mimeType: { type: "string", required: true, maxLength: 150, pattern: "^[a-zA-Z0-9.+-]+/[a-zA-Z0-9.+-]+$" },
|
|
70
|
+
contentBase64: { type: "string", required: true, minLength: 4, maxLength: 6990508, noTrim: true }
|
|
71
|
+
});
|
|
72
|
+
const userFields = {
|
|
73
|
+
name: { type: "string", maxLength: 250 }, first_name: { type: "string", maxLength: 250 },
|
|
74
|
+
last_name: { type: "string", maxLength: 250 }, nickname: { type: "string", maxLength: 250 },
|
|
75
|
+
description: { type: "string", maxLength: 10000, noTrim: true },
|
|
76
|
+
email: { type: "string", maxLength: 320, validator: value => /^[^\s@]+@[^\s@]+\.[^\s@]+$/u.test(value) || "Enter an email address." },
|
|
77
|
+
password: { type: "string", minLength: 1, maxLength: 4096, noTrim: true },
|
|
78
|
+
roles: { type: "array", items: { type: "string", minLength: 1, maxLength: 100, pattern: "^[a-zA-Z0-9_-]+$" },
|
|
79
|
+
validator: values => values.length >= 1 && values.length <= 10 && new Set(values).size === values.length || "Choose one to ten distinct WordPress roles." }
|
|
80
|
+
};
|
|
81
|
+
const wordpressSelfHostedProvider = Object.freeze({
|
|
82
|
+
...wordpressSelfHostedDefinition,
|
|
83
|
+
apiOrigins: (settings) => [new URL(settings.siteUrl).origin],
|
|
84
|
+
apiKey: { headers: (password, settings) => ({ Authorization: `Basic ${Buffer.from(`${settings.username}:${password}`).toString("base64")}` }) },
|
|
85
|
+
checkOperation: "users.me",
|
|
86
|
+
operations: {
|
|
87
|
+
...contentOperations,
|
|
88
|
+
"media.list": wordpressOperation("media", { ...listFields,
|
|
89
|
+
media_type: { type: "string", enum: ["image", "video", "text", "application", "audio"] }
|
|
90
|
+
}, "GET", value => Array.isArray(value) && value.every(mediaRecord)),
|
|
91
|
+
"media.get": wordpressOperation("media", { id, context: view }, "GET", mediaRecord),
|
|
92
|
+
"media.update": wordpressOperation("media", { id, ...mediaFields }, "POST", mediaRecord, { write: true }),
|
|
93
|
+
"media.delete": wordpressOperation("media", { id, force: permanent }, "DELETE",
|
|
94
|
+
value => value?.deleted === true && mediaRecord(value.previous)),
|
|
95
|
+
"media.upload": { scopes: [], request(input, settings) {
|
|
96
|
+
const { filename, mimeType, contentBase64, ...metadata } = validateSchemaPayload({ schema: uploadSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
97
|
+
const bytes = Buffer.from(contentBase64, "base64");
|
|
98
|
+
if (!bytes.length || bytes.length > 5 * 1024 * 1024 || bytes.toString("base64") !== contentBase64) {
|
|
99
|
+
throw new ConnectorError("connector_input_invalid", "Supply canonical base64 for a nonempty file of at most 5 MiB.", { statusCode: 422 });
|
|
100
|
+
}
|
|
101
|
+
const body = new FormData();
|
|
102
|
+
body.append("file", new Blob([bytes], { type: mimeType }), filename);
|
|
103
|
+
for (const [name, value] of Object.entries(metadata)) body.append(name, String(value));
|
|
104
|
+
return { method: "POST", url: `${baseUrl(settings)}/media`, body };
|
|
105
|
+
}, validateResult: mediaRecord },
|
|
106
|
+
"users.list": wordpressOperation("users", listFields, "GET", value => Array.isArray(value) && value.every(userRecord)),
|
|
107
|
+
"users.get": wordpressOperation("users", { id, context: view }, "GET", userRecord),
|
|
108
|
+
"users.create": wordpressOperation("users", { ...userFields,
|
|
109
|
+
username: { type: "string", required: true, minLength: 1, maxLength: 60, pattern: "^[^:\\s]+$" },
|
|
110
|
+
email: { ...userFields.email, required: true }, password: { ...userFields.password, required: true },
|
|
111
|
+
roles: { ...userFields.roles, required: true }
|
|
112
|
+
}, "POST", userRecord, { write: true }),
|
|
113
|
+
"users.update": wordpressOperation("users", { id, ...userFields }, "POST", userRecord, { write: true }),
|
|
114
|
+
"users.delete": wordpressOperation("users", { id, force: permanent, reassign: id }, "DELETE",
|
|
115
|
+
value => value?.deleted === true && userRecord(value.previous)),
|
|
116
|
+
"pages.list": wordpressOperation("pages", {
|
|
117
|
+
page: { type: "integer", min: 1, max: 100000, defaultTo: 1 },
|
|
118
|
+
per_page: { type: "integer", min: 1, max: 100, defaultTo: 10 },
|
|
119
|
+
search: { type: "string", minLength: 1, maxLength: 500 },
|
|
120
|
+
context: view, status: { ...status, defaultTo: "publish" }
|
|
121
|
+
}, "GET", value => Array.isArray(value) && value.every(contentRecord)),
|
|
122
|
+
"users.me": jsonOperation((settings) => `${baseUrl(settings)}/users/me`, {},
|
|
123
|
+
(result) => Number.isInteger(result?.id) && result.id > 0 && typeof result.name === "string" && typeof result.slug === "string"),
|
|
124
|
+
"posts.list": jsonOperation((settings) => `${baseUrl(settings)}/posts`, {
|
|
125
|
+
page: { type: "integer", min: 1, max: 100000, defaultTo: 1 },
|
|
126
|
+
per_page: { type: "integer", min: 1, max: 100, defaultTo: 10 },
|
|
127
|
+
search: { type: "string", minLength: 1, maxLength: 500 },
|
|
128
|
+
status: { type: "string", enum: ["publish", "future", "draft", "pending", "private"], defaultTo: "publish" },
|
|
129
|
+
context: { type: "string", enum: ["view", "edit", "embed"], defaultTo: "view" }
|
|
130
|
+
}, (result) => Array.isArray(result) && result.every((post) => Number.isInteger(post?.id) && post.id > 0 && typeof post.title?.rendered === "string"))
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export { wordpressSelfHostedProvider };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { workdayDefinition, workdayRestEndpoint } from "../shared/workday.js";
|
|
2
|
+
import { jsonOperation } from "./jsonOperation.js";
|
|
3
|
+
import { createSchema } from "json-rest-schema";
|
|
4
|
+
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
5
|
+
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
6
|
+
|
|
7
|
+
function workersUrl(settings) {
|
|
8
|
+
const { host, prefix = "", tenant } = workdayRestEndpoint(settings.restApiEndpoint);
|
|
9
|
+
return `https://${host}${prefix}/api/staffing/v7/${tenant}/workers`;
|
|
10
|
+
}
|
|
11
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
const worker = (value) => object(value) && /^[a-f0-9]{32}$/u.test(value.id) && typeof value.descriptor === "string" &&
|
|
13
|
+
(value.workerId === undefined || typeof value.workerId === "string");
|
|
14
|
+
const pageFields = {
|
|
15
|
+
limit: { type: "integer", min: 1, max: 100, defaultTo: 20 },
|
|
16
|
+
offset: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER, defaultTo: 0 }
|
|
17
|
+
};
|
|
18
|
+
const organizationRecord = (value) => object(value) && typeof value.id === "string" && value.id.length > 0 &&
|
|
19
|
+
typeof value.descriptor === "string";
|
|
20
|
+
const organizationPage = (value) => object(value) && !value.error && !value.errors && Number.isSafeInteger(value.total) && value.total >= 0 &&
|
|
21
|
+
Array.isArray(value.data) && value.data.length <= 100 && value.data.every(organizationRecord);
|
|
22
|
+
function organizationRead(part) {
|
|
23
|
+
const schema = createSchema({
|
|
24
|
+
id: { type: "string", required: true, maxLength: 256, noTrim: true,
|
|
25
|
+
validator: value => /^([0-9a-f]{32}|Organization_Reference_ID=\S+)$/u.test(value) || "Use a Workday organization ID or Organization_Reference_ID=value." },
|
|
26
|
+
...(part ? pageFields : {})
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
scopes: [],
|
|
30
|
+
request(input, settings) {
|
|
31
|
+
const { id, ...query } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
32
|
+
const url = new URL(`${workersUrl(settings).replace(/\/workers$/u, "/supervisoryOrganizations")}/${encodeURIComponent(id)}${part ? `/${part}` : ""}`);
|
|
33
|
+
for (const [key, value] of Object.entries(query)) url.searchParams.set(key, String(value));
|
|
34
|
+
return { method: "GET", url: url.href };
|
|
35
|
+
},
|
|
36
|
+
validateResult: part ? organizationPage : organizationRecord
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const workdayId = { type: "string", minLength: 32, maxLength: 32,
|
|
40
|
+
validator: value => /^[a-f0-9]{32}$/u.test(value) || "Use the returned Workday ID." };
|
|
41
|
+
const dateField = { type: "string", noTrim: true,
|
|
42
|
+
validator: value => /^\d{4}-\d{2}-\d{2}$/u.test(value) && Number.isFinite(Date.parse(value)) &&
|
|
43
|
+
new Date(value).toISOString().slice(0, 10) === value || "Use a valid YYYY-MM-DD date." };
|
|
44
|
+
function absenceRead(kind) {
|
|
45
|
+
const schema = createSchema(kind === "statuses" ? {} : {
|
|
46
|
+
...pageFields,
|
|
47
|
+
worker: { ...workdayId, required: true },
|
|
48
|
+
...(kind === "balances" ? { category: workdayId, effective: dateField } : {
|
|
49
|
+
fromDate: dateField, toDate: dateField,
|
|
50
|
+
status: { type: "array", validator: values => values.length > 0 && values.length <= 20 || "Choose 1–20 statuses.", items: workdayId },
|
|
51
|
+
timeOffType: { type: "array", validator: values => values.length > 0 && values.length <= 100 || "Choose 1–100 time-off types.", items: workdayId }
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
scopes: [],
|
|
56
|
+
request(input, settings) {
|
|
57
|
+
const { worker: workerId, ...query } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
|
|
58
|
+
if (query.fromDate && query.toDate && query.fromDate > query.toDate) {
|
|
59
|
+
throw new ConnectorError("connector_input_invalid", "The start date must not follow the end date.", { statusCode: 422 });
|
|
60
|
+
}
|
|
61
|
+
const { host, prefix = "", tenant } = workdayRestEndpoint(settings.restApiEndpoint);
|
|
62
|
+
const path = kind === "statuses" ? "values/timeOff/status/" : kind === "balances" ? "balances" : `workers/${workerId}/timeOffDetails`;
|
|
63
|
+
const url = new URL(`https://${host}${prefix}/api/absenceManagement/v5/${tenant}/${path}`);
|
|
64
|
+
if (kind === "balances") url.searchParams.set("worker", workerId);
|
|
65
|
+
for (const [key, value] of Object.entries(query)) {
|
|
66
|
+
for (const item of Array.isArray(value) ? value : [value]) url.searchParams.append(key, String(item));
|
|
67
|
+
}
|
|
68
|
+
return { method: "GET", url: url.href };
|
|
69
|
+
},
|
|
70
|
+
validateResult(value) {
|
|
71
|
+
return object(value) && !value.error && !value.errors && Number.isSafeInteger(value.total) && value.total >= 0 &&
|
|
72
|
+
Array.isArray(value.data) && value.data.length <= 100 && value.data.every(row =>
|
|
73
|
+
kind === "statuses" ? organizationRecord(row) : object(row) && Number.isFinite(row.quantity) && object(row.unit) &&
|
|
74
|
+
(kind === "balances" ? object(row.absencePlan) : typeof row.date === "string" && object(row.status)));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const reportSegment = { type: "string", required: true, minLength: 1, maxLength: 256, noTrim: true,
|
|
79
|
+
// eslint-disable-next-line no-control-regex -- Reject literal control characters in provider input.
|
|
80
|
+
validator: value => !/[\\/\s%?#\u0000-\u001f]/u.test(value) && value !== "." && value !== ".." || "Copy the report URL's owner/name segment without separators or escaping." };
|
|
81
|
+
const reportSchema = createSchema({
|
|
82
|
+
owner: reportSegment, report: reportSegment,
|
|
83
|
+
prompts: { type: "array", validator: values => values.length <= 50 || "Use at most 50 report prompts.",
|
|
84
|
+
items: { type: "object", schema: createSchema({
|
|
85
|
+
name: { type: "string", required: true, minLength: 1, maxLength: 256,
|
|
86
|
+
validator: value => /^[A-Za-z_][A-Za-z0-9_.-]*(?:!WID)?$/u.test(value) && value.toLowerCase() !== "format" || "Use a report prompt XML alias, optionally ending !WID; format is fixed." },
|
|
87
|
+
value: { type: "string", required: true, maxLength: 4096, noTrim: true }
|
|
88
|
+
}) }
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const workdayProvider = Object.freeze({
|
|
92
|
+
...workdayDefinition,
|
|
93
|
+
// Workday's captured confidential registration issues a secret when PKCE is disabled.
|
|
94
|
+
oauthPkce: false,
|
|
95
|
+
oauth: (settings) => ({ issuer: new URL(settings.authorizationEndpoint).origin,
|
|
96
|
+
authorization_endpoint: settings.authorizationEndpoint, token_endpoint: settings.tokenEndpoint }),
|
|
97
|
+
apiOrigins: (settings) => [new URL(settings.restApiEndpoint).origin],
|
|
98
|
+
checkOperation: "workers.me",
|
|
99
|
+
operations: {
|
|
100
|
+
"reports.read": {
|
|
101
|
+
scopes: [],
|
|
102
|
+
request(input, settings) {
|
|
103
|
+
const { owner, report, prompts = [] } = validateSchemaPayload({ schema: reportSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
104
|
+
const { host, tenant } = workdayRestEndpoint(settings.restApiEndpoint);
|
|
105
|
+
const url = new URL(`https://${host}/ccx/service/customreport2/${tenant}/${encodeURIComponent(owner)}/${encodeURIComponent(report)}`);
|
|
106
|
+
const names = new Set();
|
|
107
|
+
for (const { name, value } of prompts) {
|
|
108
|
+
if (names.has(name)) throw new ConnectorError("connector_input_invalid", "Supply each report prompt once; join multi-instance WIDs with !.", { statusCode: 422 });
|
|
109
|
+
names.add(name); url.searchParams.set(name, value);
|
|
110
|
+
}
|
|
111
|
+
url.searchParams.set("format", "json");
|
|
112
|
+
if (url.href.length > 16384) throw new ConnectorError("connector_input_invalid", "Use a smaller report prompt request.", { statusCode: 422 });
|
|
113
|
+
return { method: "GET", url: url.href };
|
|
114
|
+
},
|
|
115
|
+
validateResult: result => object(result) && !result.error && !result.errors && Array.isArray(result.Report_Entry) && result.Report_Entry.every(object)
|
|
116
|
+
},
|
|
117
|
+
"timeOff.balances": absenceRead("balances"),
|
|
118
|
+
"timeOff.details": absenceRead("details"),
|
|
119
|
+
"timeOff.statuses": absenceRead("statuses"),
|
|
120
|
+
"organizations.list": jsonOperation((settings) => workersUrl(settings).replace(/\/workers$/u, "/supervisoryOrganizations"), {
|
|
121
|
+
...pageFields, includeInactive: { type: "boolean" }
|
|
122
|
+
}, organizationPage),
|
|
123
|
+
"organizations.get": organizationRead(""),
|
|
124
|
+
"organizations.members": organizationRead("members"),
|
|
125
|
+
"organizations.orgChart": organizationRead("orgChart"),
|
|
126
|
+
"workers.me": jsonOperation((settings) => `${workersUrl(settings)}/me`, {}, worker),
|
|
127
|
+
"workers.list": jsonOperation(workersUrl, {
|
|
128
|
+
limit: { type: "integer", min: 1, max: 100, defaultTo: 20 },
|
|
129
|
+
offset: { type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER, defaultTo: 0 },
|
|
130
|
+
search: { type: "string", minLength: 1, maxLength: 512, noTrim: true },
|
|
131
|
+
includeTerminatedWorkers: { type: "boolean" }, filterByOrgVisibility: { type: "boolean" }
|
|
132
|
+
}, (result) => object(result) && !result.error && !result.errors && Number.isSafeInteger(result.total) && result.total >= 0 &&
|
|
133
|
+
Array.isArray(result.data) && result.data.length <= 100 && result.data.every(worker))
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
export { workdayProvider };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createSchema } from "json-rest-schema";
|
|
2
|
+
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
|
+
import { ConnectorError } from "@jskit-ai/connectors-core/server";
|
|
4
|
+
import { xTwitterDefinition } from "../shared/x-twitter.js";
|
|
5
|
+
|
|
6
|
+
const validId = (value) => typeof value === "string" && /^[0-9]{1,19}$/u.test(value);
|
|
7
|
+
const validUsername = (value) => typeof value === "string" && /^[A-Za-z0-9_]{1,15}$/u.test(value);
|
|
8
|
+
const validCursor = (value) => typeof value === "string" && value.length > 0 && value.length <= 4096 && !/[\p{Cc}]/u.test(value);
|
|
9
|
+
const lookupSchema = createSchema({ username: { type: "string", required: true, noTrim: true,
|
|
10
|
+
validator: (value) => validUsername(value) || "Enter an X username without @, spaces or a URL." } });
|
|
11
|
+
const postsSchema = createSchema({
|
|
12
|
+
userId: { type: "string", required: true, noTrim: true, validator: (value) => validId(value) || "Enter an X user ID as a string of 1–19 digits." },
|
|
13
|
+
maxResults: { type: "integer", min: 5, max: 100, defaultTo: 10 },
|
|
14
|
+
paginationToken: { type: "string", noTrim: true, validator: (value) => validCursor(value) || "Use the returned pagination token (up to 4096 characters)." }
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const searchSchema = createSchema({
|
|
18
|
+
query: { type: "string", required: true, noTrim: true,
|
|
19
|
+
validator: (value) => value.trim().length > 0 && value.length <= 512 && !/[\p{Cc}]/u.test(value) || "Enter a search query of 1–512 characters without control characters." },
|
|
20
|
+
maxResults: { type: "integer", min: 10, max: 100, defaultTo: 10 },
|
|
21
|
+
nextToken: { type: "string", noTrim: true, validator: (value) => validCursor(value) || "Use the returned next token." }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const xTwitterProvider = Object.freeze({
|
|
25
|
+
...xTwitterDefinition, apiOrigins: ["https://api.x.com"],
|
|
26
|
+
apiKey: { headers: (key) => {
|
|
27
|
+
if (!/^[\x21-\x7e]+$/u.test(key) || key.length > 8192) {
|
|
28
|
+
throw new ConnectorError("connector_binding_missing", "Use the X app-only token without spaces, control characters or a Bearer prefix.");
|
|
29
|
+
}
|
|
30
|
+
return { Authorization: `Bearer ${key}` };
|
|
31
|
+
} },
|
|
32
|
+
checkOperation: "users.lookup",
|
|
33
|
+
operations: {
|
|
34
|
+
"posts.searchRecent": {
|
|
35
|
+
scopes: [],
|
|
36
|
+
request(input) {
|
|
37
|
+
const values = validateSchemaPayload({ schema: searchSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
38
|
+
const url = new URL("https://api.x.com/2/tweets/search/recent");
|
|
39
|
+
url.searchParams.set("query", values.query);
|
|
40
|
+
url.searchParams.set("max_results", String(values.maxResults));
|
|
41
|
+
if (values.nextToken !== undefined) url.searchParams.set("next_token", values.nextToken);
|
|
42
|
+
url.searchParams.set("tweet.fields", "created_at,author_id,attachments,entities,public_metrics");
|
|
43
|
+
url.searchParams.set("expansions", "author_id,attachments.media_keys");
|
|
44
|
+
url.searchParams.set("user.fields", "name,username,profile_image_url");
|
|
45
|
+
url.searchParams.set("media.fields", "type,url,preview_image_url,alt_text");
|
|
46
|
+
return { method: "GET", url: url.href };
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"users.lookup": {
|
|
50
|
+
scopes: [],
|
|
51
|
+
request(input) {
|
|
52
|
+
const { username } = validateSchemaPayload({ schema: lookupSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
53
|
+
const url = new URL(`https://api.x.com/2/users/by/username/${username}`);
|
|
54
|
+
url.searchParams.set("user.fields", "description,profile_image_url,public_metrics");
|
|
55
|
+
return { method: "GET", url: url.href };
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"users.posts": {
|
|
59
|
+
scopes: [],
|
|
60
|
+
request(input) {
|
|
61
|
+
// Snowflake IDs exceed JS's safe integer range; reject numbers before the schema can coerce them.
|
|
62
|
+
if (typeof input?.userId !== "string") {
|
|
63
|
+
const error = new ConnectorError("connector_input_invalid", "Pass the X user ID as a string.", { statusCode: 422 });
|
|
64
|
+
error.fieldErrors = { userId: "Pass the X user ID as a string." };
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
const values = validateSchemaPayload({ schema: postsSchema, mode: "replace" }, input, { statusCode: 422 });
|
|
68
|
+
const url = new URL(`https://api.x.com/2/users/${values.userId}/tweets`);
|
|
69
|
+
url.searchParams.set("max_results", String(values.maxResults));
|
|
70
|
+
if (values.paginationToken !== undefined) url.searchParams.set("pagination_token", values.paginationToken);
|
|
71
|
+
return { method: "GET", url: url.href };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async exchange(address, options, { request }) {
|
|
76
|
+
let result;
|
|
77
|
+
try { result = await request(address, options); } catch (error) {
|
|
78
|
+
const status = Number(error?.status || error?.statusCode);
|
|
79
|
+
if (status === 402) throw new ConnectorError("connector_billing_required", "Check this X application's API credits and billing access.", { statusCode: 402 });
|
|
80
|
+
if (status === 404) throw new ConnectorError("connector_resource_not_found", "The X resource was not found or is not available.", { statusCode: 404 });
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(result?.errors) && result.errors.length) {
|
|
84
|
+
if (!result.data && result.errors.every((error) => [
|
|
85
|
+
"https://api.x.com/2/problems/resource-not-found", "https://api.twitter.com/2/problems/resource-not-found"
|
|
86
|
+
].includes(error?.type))) {
|
|
87
|
+
throw new ConnectorError("connector_resource_not_found", "The X resource was not found or is not available.", { statusCode: 404 });
|
|
88
|
+
}
|
|
89
|
+
throw new ConnectorError("connector_response_incomplete", "X could not return the complete requested data.", { statusCode: 502 });
|
|
90
|
+
}
|
|
91
|
+
const url = new URL(address);
|
|
92
|
+
let valid = result && typeof result === "object" && !Array.isArray(result) &&
|
|
93
|
+
(result.errors === undefined || Array.isArray(result.errors));
|
|
94
|
+
if (url.pathname.startsWith("/2/users/by/username/")) {
|
|
95
|
+
valid &&= validId(result.data?.id) && validUsername(result.data?.username) && typeof result.data.name === "string" &&
|
|
96
|
+
result.data.username.toLowerCase() === url.pathname.split("/").at(-1).toLowerCase();
|
|
97
|
+
} else {
|
|
98
|
+
const count = result?.meta?.result_count;
|
|
99
|
+
valid &&= Number.isSafeInteger(count) && count >= 0 && count <= Number(url.searchParams.get("max_results")) &&
|
|
100
|
+
(result.data === undefined ? count === 0 : Array.isArray(result.data) && result.data.length === count &&
|
|
101
|
+
result.data.every((post) => validId(post?.id) && typeof post.text === "string")) &&
|
|
102
|
+
["next_token", "previous_token"].every((field) => result.meta[field] === undefined || validCursor(result.meta[field])) &&
|
|
103
|
+
["newest_id", "oldest_id"].every((field) => result.meta[field] === undefined || validId(result.meta[field]));
|
|
104
|
+
}
|
|
105
|
+
if (!valid) throw new ConnectorError("connector_response_invalid", "X returned unexpected data.", { statusCode: 502 });
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export { xTwitterProvider };
|