@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,136 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { createConnectionService } from "../../connectors-core/src/server/index.js";
|
|
7
|
+
import { createFileConnectionStore, createCredentialProtection } from "../../connectors-core/src/server/fileStorage.js";
|
|
8
|
+
import { calendlyProvider } from "../src/server/calendly.js";
|
|
9
|
+
|
|
10
|
+
test("Calendly web OAuth uses Basic and PKCE, persists rotating refresh tokens and retains personal-token access", async (t) => {
|
|
11
|
+
const directory = await mkdtemp(path.join(tmpdir(), "calendly-test-"));
|
|
12
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
13
|
+
const callback = "https://example.test/integrations/calendly/callback";
|
|
14
|
+
const context = { applicationId: "app", subjectId: "owner" };
|
|
15
|
+
const input = { context, integrationId: "calendar" };
|
|
16
|
+
let time = Date.now(), exchanges = 0;
|
|
17
|
+
let tokenScope = "users:read event_types:read", apiStatus = 200;
|
|
18
|
+
const protection = createCredentialProtection({ keys: { current: new Uint8Array(32).fill(4) }, activeKeyId: "current" });
|
|
19
|
+
const options = {
|
|
20
|
+
configuration: { schemaVersion: 1, registrations: { calendar: { source: "own", clientId: "client", clientSecretRef: "env:SECRET", callbackUrlRef: "env:CALLBACK", tokenEndpointAuthMethod: "client_secret_basic" } }, integrations: {
|
|
21
|
+
calendar: { provider: "calendly", accountMode: "shared", scopes: ["users:read", "event_types:read"], authentication: { method: "oauth2", registrationRef: "calendar" } },
|
|
22
|
+
personal: { provider: "calendly", accountMode: "shared", scopes: ["users:read", "event_types:read"], authentication: { method: "api-key", secretRef: "env:TOKEN" } }
|
|
23
|
+
} }, providers: [calendlyProvider], authorize: async owner => owner,
|
|
24
|
+
store: createFileConnectionStore({ directory, protection }), now: () => time,
|
|
25
|
+
resolveReference: async ref => ref === "env:CALLBACK" ? callback : ref === "env:TOKEN" ? "personal" : "secret",
|
|
26
|
+
fetchImpl: async (address, init) => {
|
|
27
|
+
const url = new URL(String(address)), headers = new Headers(init.headers);
|
|
28
|
+
if (url.origin === "https://auth.calendly.com") {
|
|
29
|
+
assert.equal(url.pathname, "/oauth/token");
|
|
30
|
+
assert.equal(headers.get("authorization"), "Basic " + Buffer.from("client:secret").toString("base64"));
|
|
31
|
+
const body = new URLSearchParams(init.body);
|
|
32
|
+
assert.equal(body.has("client_secret"), false);
|
|
33
|
+
if (body.get("grant_type") === "authorization_code") {
|
|
34
|
+
assert.equal(body.get("redirect_uri"), callback);
|
|
35
|
+
assert.ok(body.get("code_verifier"));
|
|
36
|
+
} else assert.equal(body.get("refresh_token"), `refresh-${exchanges}`);
|
|
37
|
+
exchanges++;
|
|
38
|
+
return Response.json({ access_token: `access-${exchanges}`, refresh_token: `refresh-${exchanges}`, token_type: "Bearer", expires_in: 60, scope: tokenScope });
|
|
39
|
+
}
|
|
40
|
+
assert.equal(url.origin, "https://api.calendly.com");
|
|
41
|
+
assert.ok([`Bearer access-${exchanges}`, "Bearer personal"].includes(headers.get("authorization")));
|
|
42
|
+
if (apiStatus !== 200) return Response.json({ message: "private provider detail" }, { status: apiStatus });
|
|
43
|
+
return Response.json({ resource: { uri: "https://api.calendly.com/users/one", name: "Fixture" } });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const service = createConnectionService(options);
|
|
47
|
+
for (const outcome of ["cancel", "denied"]) {
|
|
48
|
+
const attempt = new URL((await service.beginAuthorization(input)).authorizationUrl);
|
|
49
|
+
const denied = new URL(callback);
|
|
50
|
+
denied.searchParams.set("state", attempt.searchParams.get("state"));
|
|
51
|
+
if (outcome === "cancel") {
|
|
52
|
+
await service.cancelAuthorization({ ...input, state: attempt.searchParams.get("state") });
|
|
53
|
+
denied.searchParams.set("code", "unused");
|
|
54
|
+
} else denied.searchParams.set("error", "access_denied");
|
|
55
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: denied.href }), {
|
|
56
|
+
code: outcome === "cancel" ? "connector_attempt_invalid" : "connector_consent_denied"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
assert.equal(exchanges, 0);
|
|
60
|
+
const { authorizationUrl } = await service.beginAuthorization(input);
|
|
61
|
+
const url = new URL(authorizationUrl);
|
|
62
|
+
assert.equal(url.origin + url.pathname, "https://auth.calendly.com/oauth/authorize");
|
|
63
|
+
assert.equal(url.searchParams.get("code_challenge_method"), "S256");
|
|
64
|
+
const returned = new URL(callback);
|
|
65
|
+
returned.searchParams.set("code", "code");
|
|
66
|
+
returned.searchParams.set("state", url.searchParams.get("state"));
|
|
67
|
+
assert.equal((await service.completeAuthorization({ ...input, callbackUrl: returned.href })).status, "connected");
|
|
68
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: returned.href }), { code: "connector_attempt_invalid" });
|
|
69
|
+
time += 40_000;
|
|
70
|
+
await Promise.all([service.invoke({ ...input, operation: "profile.read" }), service.invoke({ ...input, operation: "profile.read" })]);
|
|
71
|
+
assert.equal(exchanges, 2);
|
|
72
|
+
const restarted = createConnectionService({ ...options, store: createFileConnectionStore({ directory, protection }) });
|
|
73
|
+
time += 40_000;
|
|
74
|
+
await restarted.invoke({ ...input, operation: "profile.read" });
|
|
75
|
+
assert.equal(exchanges, 3);
|
|
76
|
+
assert.equal((await restarted.connectApiKey({ context, integrationId: "personal" })).status, "connected");
|
|
77
|
+
const reconnect = new URL((await restarted.beginAuthorization(input)).authorizationUrl);
|
|
78
|
+
returned.searchParams.set("state", reconnect.searchParams.get("state"));
|
|
79
|
+
tokenScope = "users:read";
|
|
80
|
+
await restarted.completeAuthorization({ ...input, callbackUrl: returned.href });
|
|
81
|
+
await assert.rejects(restarted.invoke({ ...input, operation: "eventTypes.list", input: { user: "https://api.calendly.com/users/one" } }), { code: "connector_scope_missing" });
|
|
82
|
+
apiStatus = 403;
|
|
83
|
+
await assert.rejects(restarted.invoke({ ...input, operation: "profile.read" }), { code: "connector_permission_denied" });
|
|
84
|
+
apiStatus = 401;
|
|
85
|
+
await assert.rejects(restarted.invoke({ ...input, operation: "profile.read" }), { code: "connector_reconnect_required" });
|
|
86
|
+
await restarted.disconnect(input);
|
|
87
|
+
assert.equal((await restarted.status(input)).status, "disconnected");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("Calendly scheduling retains booking details, scopes, pagination and explicit write outcomes", async t => {
|
|
91
|
+
const directory = await mkdtemp(path.join(tmpdir(), "calendly-scheduling-")); t.after(() => rm(directory, { recursive: true, force: true }));
|
|
92
|
+
const requests = []; const state = { response: { resource: { uri: "https://api.calendly.com/users/u", name: "Owner" } }, status: 200, fail: false, deny: false };
|
|
93
|
+
const identity = { context: { applicationId: "booking", subjectId: "owner" }, integrationId: "calendar" };
|
|
94
|
+
const service = createConnectionService({ configuration: { schemaVersion: 1, registrations: {}, integrations: {
|
|
95
|
+
calendar: { provider: "calendly", accountMode: "shared", scopes: ["users:read", "event_types:read", "availability:read", "scheduled_events:read", "scheduled_events:write", "scheduling_links:write"], authentication: { method: "api-key", secretRef: "env:CALENDLY_API_KEY" } }
|
|
96
|
+
} }, providers: [calendlyProvider], authorize: async context => { if (state.deny) throw new Error("denied"); return context; }, resolveReference: async () => "fixture-token",
|
|
97
|
+
store: createFileConnectionStore({ directory, protection: createCredentialProtection({ keys: { current: new Uint8Array(32).fill(6) }, activeKeyId: "current" }) }),
|
|
98
|
+
fetchImpl: async (url, init) => { requests.push({ url: new URL(url), init }); if (state.fail) throw new Error("uncertain booking");
|
|
99
|
+
return state.response === null ? new Response(null, { status: 204 }) : Response.json(state.response, { status: state.status }); }
|
|
100
|
+
});
|
|
101
|
+
await service.connectApiKey(identity);
|
|
102
|
+
const invoke = (operation, input = {}) => service.invoke({ ...identity, operation, input });
|
|
103
|
+
const event_type = "https://api.calendly.com/event_types/type1", event = "https://api.calendly.com/scheduled_events/event1";
|
|
104
|
+
const invitee = { uri: `${event}/invitees/invitee1`, email: "customer@example.test", status: "active", timezone: "Australia/Perth", reschedule_url: "https://calendly.com/reschedulings/fixture", cancel_url: "https://calendly.com/cancellations/fixture", questions_and_answers: [{ question: "Dog name", answer: "Fido", position: 0 }] };
|
|
105
|
+
const booking = { event_type, start_time: "2026-10-01T02:00:00Z", invitee: { email: invitee.email, name: "Sam", timezone: invitee.timezone }, questions_and_answers: invitee.questions_and_answers, event_guests: ["partner@example.test"] };
|
|
106
|
+
for (const [operation, method, endpoint, input, response] of [
|
|
107
|
+
["eventTypes.get", "GET", "event_types/type1", { uuid: "type1" }, { resource: { uri: event_type, scheduling_url: "https://calendly.com/owner/groom" } }],
|
|
108
|
+
["availability.list", "GET", "event_type_available_times", { event_type, start_time: booking.start_time, end_time: "2026-10-02T02:00:00Z" }, { collection: [{ start_time: booking.start_time, status: "available", invitees_remaining: 1 }] }],
|
|
109
|
+
["events.list", "GET", "scheduled_events", { user: "https://api.calendly.com/users/u", count: 1, page_token: "next", status: "active" }, { collection: [{ uri: event, status: "active" }], pagination: { count: 1, next_page_token: "next2" } }],
|
|
110
|
+
["events.get", "GET", "scheduled_events/event1", { uuid: "event1" }, { resource: { uri: event, status: "active" } }],
|
|
111
|
+
["invitees.list", "GET", "scheduled_events/event1/invitees", { uuid: "event1", count: 1 }, { collection: [invitee], pagination: { count: 1, next_page_token: null } }],
|
|
112
|
+
["invitees.get", "GET", "scheduled_events/event1/invitees/invitee1", { uuid: "event1", invitee_uuid: "invitee1" }, { resource: invitee }],
|
|
113
|
+
["invitees.create", "POST", "invitees", booking, { resource: invitee }],
|
|
114
|
+
["schedulingLinks.create", "POST", "scheduling_links", { owner: event_type, owner_type: "EventType", max_event_count: 1 }, { resource: { owner: event_type, owner_type: "EventType", booking_url: "https://calendly.com/d/fixture" } }],
|
|
115
|
+
["events.cancel", "POST", "scheduled_events/event1/cancellation", { uuid: "event1", reason: "Customer requested" }, { resource: { canceled_by: "Owner", created_at: "2026-09-12T00:00:00Z" } }],
|
|
116
|
+
["noShows.create", "POST", "invitee_no_shows", { invitee: invitee.uri }, { resource: { uri: "https://api.calendly.com/invitee_no_shows/n1", invitee: invitee.uri } }],
|
|
117
|
+
["noShows.get", "GET", "invitee_no_shows/n1", { uuid: "n1" }, { resource: { uri: "https://api.calendly.com/invitee_no_shows/n1", invitee: invitee.uri } }],
|
|
118
|
+
["noShows.delete", "DELETE", "invitee_no_shows/n1", { uuid: "n1" }, null]
|
|
119
|
+
]) { state.response = response; assert.deepEqual(await invoke(operation, input), response);
|
|
120
|
+
const request = requests.at(-1); assert.equal(request.url.origin, "https://api.calendly.com"); assert.equal(request.url.pathname, `/${endpoint}`); assert.equal(request.init.method, method);
|
|
121
|
+
const { uuid, invitee_uuid, ...values } = input;
|
|
122
|
+
if (method === "POST") assert.deepEqual(JSON.parse(request.init.body), values);
|
|
123
|
+
if (method === "GET") for (const [key, value] of Object.entries(values)) assert.equal(request.url.searchParams.get(key), String(value));
|
|
124
|
+
assert.equal(new Headers(request.init.headers).get("authorization"), "Bearer fixture-token"); assert.equal(request.init.redirect, "error");
|
|
125
|
+
}
|
|
126
|
+
const before = requests.length;
|
|
127
|
+
for (const [operation, input] of [["events.list", {}], ["events.get", { uuid: "../users/me" }],
|
|
128
|
+
["availability.list", { event_type, start_time: booking.start_time, end_time: "2026-12-01T00:00:00Z" }],
|
|
129
|
+
["invitees.create", { ...booking, invitee: { ...booking.invitee, timezone: "Not/AZone" } }],
|
|
130
|
+
["schedulingLinks.create", { owner: "https://evil.test/type", max_event_count: 2 }]]) await assert.rejects(invoke(operation, input));
|
|
131
|
+
state.deny = true; await assert.rejects(invoke("invitees.create", booking)); state.deny = false; assert.equal(requests.length, before);
|
|
132
|
+
state.response = { resource: { message: "No booking" } }; await assert.rejects(invoke("invitees.create", booking), { code: "connector_response_invalid" });
|
|
133
|
+
state.status = 403; await assert.rejects(invoke("invitees.create", booking), { code: "connector_permission_denied" });
|
|
134
|
+
state.status = 429; await assert.rejects(invoke("invitees.create", booking));
|
|
135
|
+
state.status = 200; state.fail = true; const uncertain = requests.length; await assert.rejects(invoke("invitees.create", booking)); assert.equal(requests.length, uncertain + 1);
|
|
136
|
+
});
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { createConnectionService } from "../../connectors-core/src/server/index.js";
|
|
7
|
+
import { createFileConnectionStore, createCredentialProtection } from "../../connectors-core/src/server/fileStorage.js";
|
|
8
|
+
import { parseIntegrationConfiguration } from "../../connectors-core/src/shared/configuration.js";
|
|
9
|
+
import { canvaProvider } from "../src/server/canva.js";
|
|
10
|
+
|
|
11
|
+
import { createCanvaClientMetadata } from "../src/shared/canva.js";
|
|
12
|
+
|
|
13
|
+
const context = { applicationId: "assistant-host", subjectId: "account-owner" };
|
|
14
|
+
const input = { context, integrationId: "work" };
|
|
15
|
+
const callback = "http://127.0.0.1:4919/canva/callback";
|
|
16
|
+
const resource = "https://mcp.canva.com";
|
|
17
|
+
const clientId = "https://assistant.example/oauth/canva.json";
|
|
18
|
+
const endpoint = `${resource}/mcp`;
|
|
19
|
+
const tokenEndpoint = "https://mcp.canva.com/token";
|
|
20
|
+
const scopes = ["profile:read", "design:meta:read"];
|
|
21
|
+
const discovery = { tools: [{ name: "get-design", inputSchema: { type: "object", properties: { design_id: { type: "string" } } } }] };
|
|
22
|
+
|
|
23
|
+
async function fixture(t, selectedScopes = scopes) {
|
|
24
|
+
const directory = await mkdtemp(path.join(tmpdir(), "canva-connector-"));
|
|
25
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
26
|
+
const protection = createCredentialProtection({ keys: { current: new Uint8Array(32).fill(3) }, activeKeyId: "current" });
|
|
27
|
+
const state = { time: Date.now(), scopes: selectedScopes, status: 200, list: discovery, call: { content: [{ type: "text", text: "Project work" }] } };
|
|
28
|
+
const requests = [];
|
|
29
|
+
const options = {
|
|
30
|
+
configuration: { schemaVersion: 1, registrations: { canva: { source: "own", clientId: clientId, tokenEndpointAuthMethod: "none", callbackUrlRef: "env:CANVA_CALLBACK" } }, integrations: {
|
|
31
|
+
work: { provider: "canva", accountMode: "assistant", scopes: selectedScopes,
|
|
32
|
+
authentication: { method: "oauth2", registrationRef: "canva" } }
|
|
33
|
+
} },
|
|
34
|
+
providers: [canvaProvider], store: createFileConnectionStore({ directory, protection }), now: () => state.time,
|
|
35
|
+
authorize: async (owner, request) => request.operation === "tools.call" &&
|
|
36
|
+
(state.authorizeTool ? !state.authorizeTool(request.input) :
|
|
37
|
+
request.input.name !== "get-design" || request.input.arguments.design_id !== "allowed-design") ? null : owner,
|
|
38
|
+
resolveReference: async (reference) => { assert.equal(reference, "env:CANVA_CALLBACK"); return callback; },
|
|
39
|
+
fetchImpl: async (address, init) => {
|
|
40
|
+
init.signal.throwIfAborted();
|
|
41
|
+
const url = String(address);
|
|
42
|
+
requests.push({ url, init, headers: new Headers(init.headers) });
|
|
43
|
+
if (url === tokenEndpoint) {
|
|
44
|
+
if (state.tokenError) return Response.json({ error: state.tokenError, error_description: "fixture-client-secret" }, { status: 400 });
|
|
45
|
+
const refresh = new URLSearchParams(init.body).get("grant_type") === "refresh_token";
|
|
46
|
+
return Response.json({ token_type: "Bearer", access_token: refresh ? "refreshed-access" : "initial-access",
|
|
47
|
+
refresh_token: refresh ? "rotated-refresh" : "initial-refresh", expires_in: 60, scope: state.scopes.join(" ") });
|
|
48
|
+
}
|
|
49
|
+
assert.equal(url, endpoint);
|
|
50
|
+
if (init.method === "DELETE") return new Response(null, { status: 204 });
|
|
51
|
+
if (init.method === "GET") return new Response(null, { status: 405 });
|
|
52
|
+
if (state.status !== 200) return new Response("initial-access fixture-client-secret", { status: state.status,
|
|
53
|
+
headers: { "WWW-Authenticate": 'Bearer resource_metadata="https://unexpected.invalid/auth"' } });
|
|
54
|
+
const message = JSON.parse(init.body);
|
|
55
|
+
requests.at(-1).message = message;
|
|
56
|
+
if (message.id === undefined) return new Response(null, { status: 202 });
|
|
57
|
+
const result = message.method === "initialize" ? { protocolVersion: message.params.protocolVersion,
|
|
58
|
+
capabilities: { tools: {} }, serverInfo: { name: "canva-fixture", version: "1" } }
|
|
59
|
+
: message.method === "tools/list" ? state.list : state.call;
|
|
60
|
+
if (state.pause && message.method === "tools/call") {
|
|
61
|
+
state.started();
|
|
62
|
+
return new Promise((resolve, reject) => init.signal.addEventListener("abort", () => reject(init.signal.reason), { once: true }));
|
|
63
|
+
}
|
|
64
|
+
return Response.json({ jsonrpc: "2.0", id: message.id, result }, { headers: { "Mcp-Session-Id": "canva-session" } });
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const service = createConnectionService(options);
|
|
68
|
+
const complete = async (start, extra = "code=fixture-code") => service.completeAuthorization({ ...input,
|
|
69
|
+
callbackUrl: `${callback}?state=${new URL(start.authorizationUrl).searchParams.get("state")}&${extra}` });
|
|
70
|
+
return { service, options, state, requests, directory, protection, complete };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
test("Canva metadata clients exchange and refresh PKCE grants without client secrets after file restart", async (t) => {
|
|
75
|
+
const { service, options, requests, state, complete, directory, protection } = await fixture(t);
|
|
76
|
+
const durations = [];
|
|
77
|
+
const timeout = AbortSignal.timeout;
|
|
78
|
+
t.mock.method(AbortSignal, "timeout", (duration) => { durations.push(duration); return timeout(duration); });
|
|
79
|
+
const start = await service.beginAuthorization(input);
|
|
80
|
+
const url = new URL(start.authorizationUrl);
|
|
81
|
+
assert.equal(url.origin + url.pathname, "https://mcp.canva.com/authorize");
|
|
82
|
+
assert.equal(url.searchParams.get("resource"), resource);
|
|
83
|
+
assert.equal(url.searchParams.get("client_id"), clientId);
|
|
84
|
+
assert.equal(url.searchParams.get("scope"), scopes.join(" "));
|
|
85
|
+
assert.equal(url.searchParams.get("code_challenge_method"), "S256");
|
|
86
|
+
assert.equal(requests.length, 0);
|
|
87
|
+
assert.equal((await complete(start)).status, "connected");
|
|
88
|
+
const grant = new URLSearchParams(requests.find(({ url }) => url === tokenEndpoint).init.body);
|
|
89
|
+
assert.equal(grant.get("resource"), resource);
|
|
90
|
+
assert.equal(grant.get("client_id"), clientId);
|
|
91
|
+
assert.equal(grant.has("client_secret"), false);
|
|
92
|
+
assert.equal(requests.find(({ url }) => url === tokenEndpoint).headers.get("authorization"), null);
|
|
93
|
+
assert.equal(grant.get("redirect_uri"), callback);
|
|
94
|
+
assert(grant.get("code_verifier"));
|
|
95
|
+
assert.equal(requests.filter(({ message }) => message?.method === "tools/call").length, 0);
|
|
96
|
+
const initialized = requests.find(({ message }) => message?.method === "initialize");
|
|
97
|
+
assert.deepEqual(initialized.message.params.capabilities, {});
|
|
98
|
+
for (const request of requests.filter(({ url }) => url === endpoint)) {
|
|
99
|
+
assert.equal(request.headers.get("authorization"), "Bearer initial-access");
|
|
100
|
+
assert.equal(request.init.redirect, "error");
|
|
101
|
+
assert.equal(request.init.credentials, "omit");
|
|
102
|
+
}
|
|
103
|
+
const restarted = createConnectionService({ ...options, store: createFileConnectionStore({ directory, protection }) });
|
|
104
|
+
state.time += 61_000;
|
|
105
|
+
assert.deepEqual(await restarted.invoke({ ...input, operation: "tools.list", input: { cursor: "next-page" } }), discovery);
|
|
106
|
+
assert.deepEqual(requests.findLast(({ message }) => message?.method === "tools/list").message.params, { cursor: "next-page" });
|
|
107
|
+
const refresh = new URLSearchParams(requests.findLast(({ url }) => url === tokenEndpoint).init.body);
|
|
108
|
+
assert.equal(refresh.get("resource"), resource);
|
|
109
|
+
assert.equal(refresh.get("refresh_token"), "initial-refresh");
|
|
110
|
+
assert.equal(refresh.get("client_id"), clientId);
|
|
111
|
+
assert.equal(refresh.has("client_secret"), false);
|
|
112
|
+
assert.equal(requests.at(-1).headers.get("authorization"), "Bearer refreshed-access");
|
|
113
|
+
assert.equal(requests.at(-1).init.method, "DELETE");
|
|
114
|
+
for (const name of await readdir(directory)) {
|
|
115
|
+
const stored = await readFile(path.join(directory, name), "utf8");
|
|
116
|
+
for (const secret of ["initial-access", "refreshed-access", "initial-refresh", "rotated-refresh", "fixture-client-secret", grant.get("code_verifier")]) assert(!stored.includes(secret));
|
|
117
|
+
}
|
|
118
|
+
const count = requests.length;
|
|
119
|
+
await assert.rejects(complete(start), { code: "connector_attempt_invalid" });
|
|
120
|
+
for (const owner of [{ ...context, applicationId: "another-host" }, { ...context, subjectId: "another-owner" }]) {
|
|
121
|
+
await assert.rejects(restarted.invoke({ ...input, context: owner, operation: "tools.list" }), { code: "connector_reconnect_required" });
|
|
122
|
+
}
|
|
123
|
+
assert.equal(requests.length, count);
|
|
124
|
+
await restarted.disconnect(input);
|
|
125
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
126
|
+
assert.equal(requests.length, count);
|
|
127
|
+
assert(durations.includes(60_000));
|
|
128
|
+
assert(durations.includes(15_000));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("Canva validates metadata URLs, client type and permissions before reusing a consent attempt", async (t) => {
|
|
132
|
+
const { options, service, requests } = await fixture(t);
|
|
133
|
+
const parse = (config) => parseIntegrationConfiguration(JSON.stringify(config), { providers: [canvaProvider] });
|
|
134
|
+
for (const [field, value] of [["accountMode", "shared"], ["accountMode", "per-user"], ["scopes", ["admin"]], ["scopes", []]]) {
|
|
135
|
+
const config = structuredClone(options.configuration);
|
|
136
|
+
config.integrations.work[field] = value;
|
|
137
|
+
assert.throws(() => parse(config));
|
|
138
|
+
}
|
|
139
|
+
const config = structuredClone(options.configuration);
|
|
140
|
+
config.integrations.work.scopes = canvaProvider.scopes.map(({ value }) => value);
|
|
141
|
+
assert.deepEqual(parse(config).integrations.work.scopes, config.integrations.work.scopes);
|
|
142
|
+
assert(canvaProvider.scopes.filter(({ value }) => /:write$/.test(value)).every(({ recommended }) => !recommended));
|
|
143
|
+
for (const clientId of ["ordinary-client", "https://assistant.example", "http://assistant.example/client.json", "https://user:secret@assistant.example/client.json", "https://assistant.example/client.json?key=secret"]) {
|
|
144
|
+
const invalid = structuredClone(options.configuration);
|
|
145
|
+
invalid.registrations.canva.clientId = clientId;
|
|
146
|
+
assert.throws(() => parse(invalid), (error) => Boolean(error.fieldErrors["registrations.canva.clientId"]));
|
|
147
|
+
}
|
|
148
|
+
const invalid = structuredClone(options.configuration);
|
|
149
|
+
invalid.registrations.canva.clientSecretRef = "env:SHOULD_NOT_BE_USED";
|
|
150
|
+
assert.throws(() => parse(invalid), (error) => Boolean(error.fieldErrors["registrations.canva.clientSecretRef"]));
|
|
151
|
+
const start = await service.beginAuthorization(input);
|
|
152
|
+
const changed = createConnectionService({ ...options, configuration: config });
|
|
153
|
+
await assert.rejects(changed.completeAuthorization({ ...input, callbackUrl: `${callback}?code=x&state=${new URL(start.authorizationUrl).searchParams.get("state")}` }), { code: "connector_attempt_invalid" });
|
|
154
|
+
assert.equal(requests.length, 0);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("Canva authorizes the exact tool and destination design, preserves tool errors and cancels without replay", async (t) => {
|
|
158
|
+
const { service, complete, requests, state } = await fixture(t);
|
|
159
|
+
await complete(await service.beginAuthorization(input));
|
|
160
|
+
const count = requests.length;
|
|
161
|
+
for (const payload of [{ name: "delete-design", arguments: {} }, { name: "get-design", arguments: { design_id: "another-design" } }]) {
|
|
162
|
+
await assert.rejects(service.invoke({ ...input, operation: "tools.call", input: payload }), { code: "connector_access_denied" });
|
|
163
|
+
}
|
|
164
|
+
await assert.rejects(service.invoke({ ...input, operation: "tools.list", input: { url: "https://unexpected.invalid" } }), { code: "connector_input_invalid" });
|
|
165
|
+
assert.equal(requests.length, count);
|
|
166
|
+
const payload = { name: "get-design", arguments: { design_id: "allowed-design" } };
|
|
167
|
+
state.call = { content: [{ type: "text", text: "This issue is not accessible" }], isError: true };
|
|
168
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "tools.call", input: payload }), state.call);
|
|
169
|
+
assert.deepEqual(requests.findLast(({ message }) => message?.method === "tools/call").message.params, payload);
|
|
170
|
+
state.pause = true;
|
|
171
|
+
const started = new Promise((resolve) => { state.started = resolve; });
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const pending = assert.rejects(service.invoke({ ...input, operation: "tools.call", input: payload, signal: controller.signal }), { code: "connector_cancelled" });
|
|
174
|
+
await started;
|
|
175
|
+
controller.abort();
|
|
176
|
+
await pending;
|
|
177
|
+
assert.equal(requests.filter(({ message }) => message?.method === "tools/call").length, 2);
|
|
178
|
+
assert.equal(requests.at(-1).init.method, "DELETE");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("Canva declined consent and malformed discovery do not persist a connection", async (t) => {
|
|
182
|
+
const { service, complete, requests, state } = await fixture(t);
|
|
183
|
+
await assert.rejects(complete(await service.beginAuthorization(input), "error=access_denied"), { code: "connector_consent_denied" });
|
|
184
|
+
assert.equal(requests.length, 0);
|
|
185
|
+
state.list = { wrong: [] };
|
|
186
|
+
await assert.rejects(complete(await service.beginAuthorization(input)), { code: "connector_provider_failed" });
|
|
187
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("Canva preserves the provider's reduced grant and permits empty discovery without claiming product access", async (t) => {
|
|
191
|
+
const { service, complete, state, requests } = await fixture(t);
|
|
192
|
+
state.scopes = ["profile:read"];
|
|
193
|
+
state.list = { tools: [] };
|
|
194
|
+
const connected = await complete(await service.beginAuthorization(input));
|
|
195
|
+
assert.deepEqual(connected.grantedScopes, ["profile:read"]);
|
|
196
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "tools.list" }), { tools: [] });
|
|
197
|
+
assert(!requests.some(({ message }) => message?.method === "tools/call"));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("Canva sanitizes HTTP/refresh failures, persists reconnect status and never follows injected auth metadata", async (t) => {
|
|
201
|
+
const { service, complete, requests, state } = await fixture(t);
|
|
202
|
+
for (const [status, code] of [[401, "connector_reconnect_required"], [403, "connector_permission_denied"], [429, "connector_rate_limited"], [500, "connector_provider_failed"]]) {
|
|
203
|
+
state.status = status;
|
|
204
|
+
await assert.rejects(complete(await service.beginAuthorization(input)), (error) => {
|
|
205
|
+
assert.equal(error.code, code);
|
|
206
|
+
assert(!error.message.includes("fixture-client-secret"));
|
|
207
|
+
assert.equal(error.cause, undefined);
|
|
208
|
+
return true;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
assert(requests.every(({ url }) => url === endpoint || url === tokenEndpoint));
|
|
212
|
+
state.status = 200;
|
|
213
|
+
await complete(await service.beginAuthorization(input));
|
|
214
|
+
state.time += 61_000;
|
|
215
|
+
state.tokenError = "invalid_grant";
|
|
216
|
+
await assert.rejects(service.invoke({ ...input, operation: "tools.list" }), { code: "connector_reconnect_required" });
|
|
217
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("Canva client metadata is a portable secret-free document with an exact identity and callback", () => {
|
|
221
|
+
const metadata = createCanvaClientMetadata({ clientId, clientName: "My assistant", callbackUrl: callback });
|
|
222
|
+
assert.deepEqual(metadata, { client_id: clientId, client_name: "My assistant", redirect_uris: [callback],
|
|
223
|
+
grant_types: ["authorization_code", "refresh_token"], response_types: ["code"], token_endpoint_auth_method: "none" });
|
|
224
|
+
assert.deepEqual(JSON.parse(JSON.stringify(metadata)), metadata);
|
|
225
|
+
for (const changes of [{ clientId: "http://example.test/client.json" }, { clientId: "https://example.test/" },
|
|
226
|
+
{ clientId: "https://example.test/client.json#fragment" }, { clientName: "" }, { callbackUrl: "http://remote.example/callback" },
|
|
227
|
+
{ callbackUrl: "https://example.test/callback?secret=1" }, { clientSecret: "raw-secret" }]) {
|
|
228
|
+
assert.throws(() => createCanvaClientMetadata({ clientId, clientName: "Client", callbackUrl: callback, ...changes }));
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
test("Canva design creation and editing preserve draft versus committed results and exact host approval", async t => {
|
|
234
|
+
const { service, complete, state, requests } = await fixture(t, [...scopes, "design:content:write"]);
|
|
235
|
+
await complete(await service.beginAuthorization(input));
|
|
236
|
+
const steps = [
|
|
237
|
+
["create-design-from-candidate", { job_id: "job-1", candidate_id: "chosen-1" }, { design_summary: { id: "allowed-design", title: "Grooming offer", urls: { edit_url: "https://www.canva.com/d/fixture" } } }],
|
|
238
|
+
["start-editing-transaction", { design_id: "allowed-design" }, { transaction: { status: "open", transaction_id: "txn-1" }, richtexts: [{ page_index: 1, element_id: "headline", regions: [{ type: "character", text: "Old headline" }] }] }],
|
|
239
|
+
["perform-editing-operations", { transaction_id: "txn-1", page_index: 1, operations: [{ type: "replace_text", element_id: "headline", text: "Spring grooming" }] }, { edit_operation_results: [{ status: "success", operation_info: { type: "replace_text", element_id: "headline" } }] }],
|
|
240
|
+
["commit-editing-transaction", { transaction_id: "txn-1" }, { transaction: { id: "txn-1", status: "committed" } }]
|
|
241
|
+
];
|
|
242
|
+
for (const [name, arguments_, result] of steps) {
|
|
243
|
+
const payload = { name, arguments: arguments_ };
|
|
244
|
+
state.authorizeTool = candidate => JSON.stringify(candidate) === JSON.stringify(payload);
|
|
245
|
+
state.call = { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
246
|
+
const count = requests.length;
|
|
247
|
+
await assert.rejects(service.invoke({ ...input, operation: "tools.call", input: { name, arguments: { ...arguments_, design_id: "unapproved-design" } } }), { code: "connector_access_denied" });
|
|
248
|
+
assert.equal(requests.length, count);
|
|
249
|
+
const response = await service.invoke({ ...input, operation: "tools.call", input: payload });
|
|
250
|
+
assert.deepEqual(JSON.parse(response.content[0].text), result);
|
|
251
|
+
assert.deepEqual(requests.findLast(({ message }) => message?.method === "tools/call").message.params, payload);
|
|
252
|
+
}
|
|
253
|
+
state.call = { isError: true, content: [{ type: "text", text: "Concurrent edit: cancel and start a fresh transaction" }] };
|
|
254
|
+
const count = requests.filter(({ message }) => message?.method === "tools/call").length;
|
|
255
|
+
const failed = await service.invoke({ ...input, operation: "tools.call", input: { name: "commit-editing-transaction", arguments: { transaction_id: "txn-1" } } });
|
|
256
|
+
assert.equal(failed.isError, true);
|
|
257
|
+
assert.equal(requests.filter(({ message }) => message?.method === "tools/call").length, count + 1);
|
|
258
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { createConnectionService } from "../../connectors-core/src/server/index.js";
|
|
7
|
+
import { createFileConnectionStore, createCredentialProtection } from "../../connectors-core/src/server/fileStorage.js";
|
|
8
|
+
import { parseIntegrationConfiguration } from "../../connectors-core/src/shared/configuration.js";
|
|
9
|
+
import { chargebeeProvider } from "../src/server/chargebee.js";
|
|
10
|
+
|
|
11
|
+
const context = { applicationId: "billing-app", subjectId: "finance-team" };
|
|
12
|
+
const input = { context, integrationId: "billing" };
|
|
13
|
+
const customers = { list: [{ customer: { id: "customer-1", object: "customer", first_name: "Alex" } }] };
|
|
14
|
+
|
|
15
|
+
async function fixture(t) {
|
|
16
|
+
const directory = await mkdtemp(path.join(tmpdir(), "chargebee-connector-"));
|
|
17
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
18
|
+
const protection = createCredentialProtection({ keys: { current: new Uint8Array(32).fill(6) }, activeKeyId: "current" });
|
|
19
|
+
const requests = [];
|
|
20
|
+
const state = { key: "test_fixture_key", status: 200, response: customers };
|
|
21
|
+
const options = {
|
|
22
|
+
configuration: { schemaVersion: 1, registrations: {}, integrations: { billing: {
|
|
23
|
+
provider: "chargebee", accountMode: "shared", scopes: [],
|
|
24
|
+
authentication: { method: "api-key", secretRef: "env:CHARGEBEE_API_KEY" },
|
|
25
|
+
settings: { siteName: "acme-test" }, extensions: { fromCli: true }
|
|
26
|
+
} } },
|
|
27
|
+
providers: [chargebeeProvider], authorize: async (owner) => state.deny ? null : owner,
|
|
28
|
+
store: createFileConnectionStore({ directory, protection }),
|
|
29
|
+
resolveReference: async (ref) => { assert.equal(ref, "env:CHARGEBEE_API_KEY"); return state.key; },
|
|
30
|
+
fetchImpl: async (address, init) => {
|
|
31
|
+
requests.push({ url: new URL(String(address)), init, headers: new Headers(init.headers) });
|
|
32
|
+
if (state.fail) throw new Error("uncertain write");
|
|
33
|
+
return Response.json(state.response, { status: state.status });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return { service: createConnectionService(options), options, requests, directory, protection, state };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
test("Chargebee verifies a site with Basic API-key authentication and retains file ownership across restart", async (t) => {
|
|
40
|
+
const { service, options, requests, directory, protection, state } = await fixture(t);
|
|
41
|
+
const connected = await service.connectApiKey(input);
|
|
42
|
+
assert.equal(connected.status, "connected");
|
|
43
|
+
const first = requests[0];
|
|
44
|
+
assert.equal(first.url.href, "https://acme-test.chargebee.com/api/v2/customers?limit=10&include_deleted=false");
|
|
45
|
+
assert.equal(first.init.method, "GET");
|
|
46
|
+
assert.equal(first.init.body, undefined);
|
|
47
|
+
assert.equal(first.init.redirect, "error");
|
|
48
|
+
assert.equal(first.headers.get("authorization"), `Basic ${Buffer.from(`${state.key}:`).toString("base64")}`);
|
|
49
|
+
for (const name of await readdir(directory)) {
|
|
50
|
+
const stored = await readFile(path.join(directory, name), "utf8");
|
|
51
|
+
assert.doesNotThrow(() => JSON.parse(stored));
|
|
52
|
+
assert.equal(stored.includes(state.key), false);
|
|
53
|
+
assert.equal(stored.includes(first.headers.get("authorization")), false);
|
|
54
|
+
}
|
|
55
|
+
const restarted = createConnectionService({ ...options, store: createFileConnectionStore({ directory, protection }) });
|
|
56
|
+
assert.deepEqual(await restarted.status(input), connected);
|
|
57
|
+
state.key = "test_rotated_key";
|
|
58
|
+
assert.deepEqual(await restarted.invoke({ ...input, operation: "customers.list" }), customers);
|
|
59
|
+
assert.equal(requests.at(-1).headers.get("authorization"), `Basic ${Buffer.from(`${state.key}:`).toString("base64")}`);
|
|
60
|
+
for (const owner of [{ ...context, applicationId: "other-app" }, { ...context, subjectId: "other-team" }]) {
|
|
61
|
+
await assert.rejects(restarted.invoke({ ...input, context: owner, operation: "customers.list" }), { code: "connector_reconnect_required" });
|
|
62
|
+
}
|
|
63
|
+
assert.equal(requests.length, 2);
|
|
64
|
+
await restarted.disconnect(input);
|
|
65
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("Chargebee rejects full URLs and invalid site labels or Basic credential separators before HTTP", async (t) => {
|
|
69
|
+
const { service, options, requests, state } = await fixture(t);
|
|
70
|
+
const parse = (configuration) => parseIntegrationConfiguration(JSON.stringify(configuration), { providers: [chargebeeProvider] });
|
|
71
|
+
for (const siteName of [undefined, "", "https://acme-test.chargebee.com", "acme.chargebee.com", "user@host", "acme/..", "acme?host=other", "acme#fragment", "acme:443", "-acme", "acme-", "a_b", "with space", "a".repeat(64)]) {
|
|
72
|
+
const configuration = structuredClone(options.configuration);
|
|
73
|
+
configuration.integrations.billing.settings.siteName = siteName;
|
|
74
|
+
assert.throws(() => parse(configuration), (error) => Boolean(error.fieldErrors["integrations.billing.settings.siteName"]));
|
|
75
|
+
}
|
|
76
|
+
const configuration = structuredClone(options.configuration);
|
|
77
|
+
configuration.integrations.billing.authentication.secretRef = "raw-key";
|
|
78
|
+
assert.throws(() => parse(configuration), (error) => Boolean(error.fieldErrors["integrations.billing.authentication.secretRef"]));
|
|
79
|
+
for (const key of ["key:password", "key with space", "key\nheader", "key\u0000"]) {
|
|
80
|
+
state.key = key;
|
|
81
|
+
await assert.rejects(service.connectApiKey(input), { code: "connector_binding_missing" });
|
|
82
|
+
}
|
|
83
|
+
assert.equal(requests.length, 0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("Chargebee site changes require verification and never fall back across sites", async (t) => {
|
|
87
|
+
const { service, options, requests } = await fixture(t);
|
|
88
|
+
await service.connectApiKey(input);
|
|
89
|
+
const configuration = structuredClone(options.configuration);
|
|
90
|
+
configuration.integrations.billing.settings.siteName = "acme-live";
|
|
91
|
+
const changed = createConnectionService({ ...options, configuration });
|
|
92
|
+
assert.equal((await changed.status(input)).status, "reconnect-required");
|
|
93
|
+
await assert.rejects(changed.invoke({ ...input, operation: "customers.list" }), { code: "connector_reconnect_required" });
|
|
94
|
+
const wrongHost = createConnectionService({ ...options, providers: [{ ...chargebeeProvider, operations: {
|
|
95
|
+
"customers.list": { scopes: [], request: () => ({ method: "GET", url: "https://acme-live.chargebee.com/api/v2/customers" }) }
|
|
96
|
+
} }] });
|
|
97
|
+
await assert.rejects(wrongHost.invoke({ ...input, operation: "customers.list" }), { code: "connector_destination_invalid" });
|
|
98
|
+
assert.equal(requests.length, 1);
|
|
99
|
+
await changed.connectApiKey(input);
|
|
100
|
+
assert.equal(requests.at(-1).url.origin, "https://acme-live.chargebee.com");
|
|
101
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("Chargebee preserves opaque customer pagination and opt-in deleted records while rejecting input overrides", async (t) => {
|
|
105
|
+
const { service, requests, state } = await fixture(t);
|
|
106
|
+
await service.connectApiKey(input);
|
|
107
|
+
state.response = { list: [{ customer: { id: "deleted-1", deleted: true } }], next_offset: "next+&=cursor" };
|
|
108
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "customers.list", input: { limit: 100, offset: "previous+&=cursor", include_deleted: true } }), state.response);
|
|
109
|
+
assert.deepEqual(Object.fromEntries(requests.at(-1).url.searchParams), { limit: "100", offset: "previous+&=cursor", include_deleted: "true" });
|
|
110
|
+
for (const invalid of [{ limit: 0 }, { limit: 101 }, { limit: 1.5 }, { offset: "" }, { offset: "x".repeat(1001) }, { include_deleted: "maybe" }, { siteName: "other-site" }, { url: "https://attacker.invalid" }, { api_key: "other-key" }]) {
|
|
111
|
+
await assert.rejects(service.invoke({ ...input, operation: "customers.list", input: invalid }), { code: "connector_input_invalid" });
|
|
112
|
+
}
|
|
113
|
+
assert.equal(requests.length, 2);
|
|
114
|
+
state.response = { list: [] };
|
|
115
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "customers.list" }), { list: [] });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("Chargebee failure responses never verify a key or expose provider details and revoked keys require reconnection", async (t) => {
|
|
119
|
+
const { service, state } = await fixture(t);
|
|
120
|
+
for (const [status, code] of [[200, "connector_response_invalid"], [401, "connector_reconnect_required"], [403, "connector_permission_denied"], [429, "connector_rate_limited"], [500, "connector_provider_failed"]]) {
|
|
121
|
+
state.status = status;
|
|
122
|
+
state.response = { message: state.key, api_error_code: "provider-fixture-error" };
|
|
123
|
+
await assert.rejects(service.connectApiKey(input), (error) => {
|
|
124
|
+
assert.equal(error.code, code);
|
|
125
|
+
assert.equal(error.message.includes(state.key), false);
|
|
126
|
+
assert.equal(JSON.stringify(error).includes(state.key), false);
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
130
|
+
}
|
|
131
|
+
state.status = 200;
|
|
132
|
+
state.response = customers;
|
|
133
|
+
await service.connectApiKey(input);
|
|
134
|
+
for (const malformed of [{ list: {} }, { list: [{}] }, { list: [{ customer: { id: "" } }] }, { ...customers, next_offset: 2 }, { ...customers, next_offset: "x".repeat(1001) }]) {
|
|
135
|
+
state.response = malformed;
|
|
136
|
+
await assert.rejects(service.invoke({ ...input, operation: "customers.list" }), { code: "connector_response_invalid" });
|
|
137
|
+
}
|
|
138
|
+
state.status = 401;
|
|
139
|
+
await assert.rejects(service.invoke({ ...input, operation: "customers.list" }), { code: "connector_reconnect_required" });
|
|
140
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
test("Chargebee app billing uses indexed forms, explicit idempotency and verified checkout state", async t => {
|
|
145
|
+
const { service, requests, state } = await fixture(t);
|
|
146
|
+
await service.connectApiKey(input);
|
|
147
|
+
const invoke = (operation, values = {}) => service.invoke({ ...input, operation, input: values });
|
|
148
|
+
const items = [{ item_price_id: "grooming-USD-monthly", quantity: 1 }];
|
|
149
|
+
const returns = { redirect_url: "https://app.example/billing/return", cancel_url: "https://app.example/billing/cancel" };
|
|
150
|
+
const samples = [
|
|
151
|
+
["customers.create", "customers", { email: "sam@example.test", first_name: "Sam", id: "customer-1" }, { customer: { id: "customer-1" } }],
|
|
152
|
+
["customers.update", "customers/customer-1", { resource: "customer-1", company: "Dog and Groom" }, { customer: { id: "customer-1", company: "Dog and Groom" } }],
|
|
153
|
+
["subscriptions.create", "customers/customer-1/subscription_for_items", { resource: "customer-1", subscription_items: items, auto_collection: "off", invoice_immediately: false }, { subscription: { id: "sub-1", status: "active" }, unbilled_charges: [{ id: "charge-1" }] }],
|
|
154
|
+
["subscriptions.updateAtTermEnd", "subscriptions/sub-1/update_for_items", { resource: "sub-1", subscription_items: items, replace_items_list: true }, { subscription: { id: "sub-1", has_scheduled_changes: true } }, { end_of_term: "true" }],
|
|
155
|
+
["subscriptions.cancelAtTermEnd", "subscriptions/sub-1/cancel_for_items", { resource: "sub-1" }, { subscription: { id: "sub-1", status: "non_renewing" } }, { cancel_option: "end_of_term" }],
|
|
156
|
+
["hostedPages.checkoutNew", "hosted_pages/checkout_new_for_items", { subscription_items: items, customer: { id: "customer-1" }, ...returns }, { hosted_page: { id: "page-1", state: "created", url: "https://acme-test.chargebee.com/pages/v3/fixture" } }],
|
|
157
|
+
["hostedPages.checkoutExisting", "hosted_pages/checkout_existing_for_items", { subscription_items: items, subscription: { id: "sub-1" }, ...returns }, { hosted_page: { id: "page-2", state: "created" } }],
|
|
158
|
+
["portalSessions.create", "portal_sessions", { customer: { id: "customer-1" }, redirect_url: returns.redirect_url }, { portal_session: { id: "portal-1", access_url: "https://acme-test.chargebeeportal.com/fixture" } }],
|
|
159
|
+
["invoices.pdf", "invoices/invoice-1/pdf", { resource: "invoice-1", disposition_type: "attachment" }, { download: { download_url: "https://downloads.example/invoice.pdf", valid_till: 1789290000 } }]
|
|
160
|
+
];
|
|
161
|
+
for (const [operation, endpoint, values, response, fixed = {}] of samples) {
|
|
162
|
+
state.response = response;
|
|
163
|
+
assert.deepEqual(await invoke(operation, { ...values, idempotencyKey: `intent-${operation.replaceAll(".", "-")}` }), response);
|
|
164
|
+
const request = requests.at(-1); assert.equal(request.init.method, "POST"); assert.equal(request.url.href, `https://acme-test.chargebee.com/api/v2/${endpoint}`);
|
|
165
|
+
assert.equal(request.headers.get("content-type"), "application/x-www-form-urlencoded");
|
|
166
|
+
assert.equal(request.headers.get("chargebee-idempotency-key"), `intent-${operation.replaceAll(".", "-")}`);
|
|
167
|
+
const body = new URLSearchParams(request.init.body); assert.equal(body.has("idempotencyKey"), false); assert.equal(body.has("resource"), false);
|
|
168
|
+
for (const [key, value] of Object.entries(fixed)) assert.equal(body.get(key), value);
|
|
169
|
+
if (values.subscription_items) { assert.equal(body.get("subscription_items[item_price_id][0]"), items[0].item_price_id); assert.equal(body.get("subscription_items[quantity][0]"), "1"); }
|
|
170
|
+
if (values.customer) assert.equal(body.get("customer[id]"), values.customer.id);
|
|
171
|
+
if (values.subscription) assert.equal(body.get("subscription[id]"), values.subscription.id);
|
|
172
|
+
if (values.auto_collection) { assert.equal(body.get("auto_collection"), "off"); assert.equal(body.get("invoice_immediately"), "false"); }
|
|
173
|
+
}
|
|
174
|
+
for (const [operation, endpoint, resourceKey] of [["itemFamilies.list", "item_families", "item_family"], ["items.list", "items", "item"], ["itemPrices.list", "item_prices", "item_price"], ["subscriptions.list", "subscriptions", "subscription"], ["invoices.list", "invoices", "invoice"], ["events.list", "events", "event"]]) {
|
|
175
|
+
state.response = { list: [{ [resourceKey]: { id: "resource-1" } }], next_offset: "opaque+next" };
|
|
176
|
+
assert.deepEqual(await invoke(operation, { offset: "previous+cursor" }), state.response);
|
|
177
|
+
assert.equal(requests.at(-1).url.pathname, `/api/v2/${endpoint}`); assert.equal(requests.at(-1).url.searchParams.get("offset"), "previous+cursor");
|
|
178
|
+
}
|
|
179
|
+
for (const [operation, endpoint, resourceKey] of [["customers.get", "customers", "customer"], ["items.get", "items", "item"], ["itemPrices.get", "item_prices", "item_price"], ["subscriptions.get", "subscriptions", "subscription"], ["invoices.get", "invoices", "invoice"], ["events.get", "events", "event"], ["hostedPages.get", "hosted_pages", "hosted_page"]]) {
|
|
180
|
+
state.response = { [resourceKey]: { id: "resource-1", state: "succeeded", content: { subscription: { id: "sub-1", customer_id: "customer-1" }, invoice: { id: "invoice-1", status: "payment_due" } } } };
|
|
181
|
+
assert.deepEqual(await invoke(operation, { resource: "resource-1" }), state.response);
|
|
182
|
+
assert.equal(requests.at(-1).url.pathname, `/api/v2/${endpoint}/resource-1`); assert.equal(requests.at(-1).init.method, "GET");
|
|
183
|
+
}
|
|
184
|
+
const before = requests.length;
|
|
185
|
+
for (const [operation, values] of [["customers.create", { email: "sam@example.test" }], ["subscriptions.create", { resource: "c", subscription_items: items, idempotencyKey: "x" }],
|
|
186
|
+
["hostedPages.checkoutNew", { subscription_items: [], customer: { id: "c" }, ...returns, idempotencyKey: "x" }],
|
|
187
|
+
["subscriptions.cancelAtTermEnd", { resource: "../other", idempotencyKey: "x" }],
|
|
188
|
+
["subscriptions.cancelAtTermEnd", { resource: "sub-1", idempotencyKey: "x", cancel_option: "immediately" }]]) await assert.rejects(invoke(operation, values), { code: "connector_input_invalid" });
|
|
189
|
+
state.deny = true; await assert.rejects(invoke("portalSessions.create", { customer: { id: "customer-1" }, redirect_url: returns.redirect_url, idempotencyKey: "portal" }), { code: "connector_access_denied" }); state.deny = false;
|
|
190
|
+
assert.equal(requests.length, before);
|
|
191
|
+
const cancel = { resource: "sub-1", idempotencyKey: "same-intent" };
|
|
192
|
+
state.response = { subscription: {} }; await assert.rejects(invoke("subscriptions.cancelAtTermEnd", cancel), { code: "connector_response_invalid" });
|
|
193
|
+
for (const status of [403, 409, 422, 429, 500]) { state.status = status; await assert.rejects(invoke("subscriptions.cancelAtTermEnd", cancel)); }
|
|
194
|
+
state.status = 200; state.fail = true; const uncertain = requests.length; await assert.rejects(invoke("subscriptions.cancelAtTermEnd", cancel)); assert.equal(requests.length, uncertain + 1);
|
|
195
|
+
});
|