@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,573 @@
|
|
|
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 { twitchProvider, parseTwitchEventSubMessage } from "../src/server/twitch.js";
|
|
9
|
+
|
|
10
|
+
const callback = "https://app.example.test/twitch/callback";
|
|
11
|
+
const context = { applicationId: "app-one", subjectId: "user-one" };
|
|
12
|
+
const input = { context, integrationId: "twitch" };
|
|
13
|
+
const scopes = ["user:read:email", "user:read:follows"];
|
|
14
|
+
const followed = { total: 1, data: [{ broadcaster_id: "456", broadcaster_login: "channel", broadcaster_name: "Channel", followed_at: "2026-09-01T00:00:00Z" }], pagination: { cursor: "next +&2" } };
|
|
15
|
+
|
|
16
|
+
async function fixture(t, granted = scopes) {
|
|
17
|
+
const directory = await mkdtemp(path.join(tmpdir(), "twitch-connector-"));
|
|
18
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
19
|
+
const requests = [];
|
|
20
|
+
const state = {
|
|
21
|
+
time: Date.now(), tokenCount: 0, tokenScope: granted, tokenStatus: 200, validationStatus: 200, apiStatus: 200,
|
|
22
|
+
validation: { client_id: "fixture-client", user_id: "123", login: "reader", scopes: granted, expires_in: 60 },
|
|
23
|
+
profile: { data: [{ id: "123", login: "reader", email: "reader@example.test" }] }, followed
|
|
24
|
+
};
|
|
25
|
+
const protection = createCredentialProtection({ keys: { current: new Uint8Array(32).fill(7) }, activeKeyId: "current" });
|
|
26
|
+
const options = {
|
|
27
|
+
configuration: { schemaVersion: 1, integrations: {
|
|
28
|
+
twitch: { provider: "twitch", accountMode: "per-user", scopes: granted, authentication: { method: "oauth2", registrationRef: "twitch" } }
|
|
29
|
+
}, registrations: { twitch: { source: "own", clientId: "fixture-client", clientSecretRef: "env:TWITCH_SECRET", callbackUrlRef: "env:TWITCH_CALLBACK" } } },
|
|
30
|
+
providers: [twitchProvider], authorize: async (owner) => owner, now: () => state.time,
|
|
31
|
+
resolveReference: async (ref) => ref === "env:TWITCH_CALLBACK" ? callback : "fixture-client-secret",
|
|
32
|
+
store: createFileConnectionStore({ directory, protection }),
|
|
33
|
+
fetchImpl: async (address, init) => {
|
|
34
|
+
const url = new URL(String(address));
|
|
35
|
+
const headers = new Headers(init.headers);
|
|
36
|
+
requests.push({ url, init, headers });
|
|
37
|
+
assert.equal(init.redirect, url.pathname === "/oauth2/token" ? "manual" : "error");
|
|
38
|
+
if (state.interruptPath === url.pathname) {
|
|
39
|
+
state.controller.abort(new DOMException("fixture-client-secret", state.interruptName || "AbortError"));
|
|
40
|
+
throw init.signal.reason;
|
|
41
|
+
}
|
|
42
|
+
if (url.pathname === "/oauth2/token") {
|
|
43
|
+
assert.equal(url.origin, "https://id.twitch.tv");
|
|
44
|
+
assert.equal(init.method, "POST");
|
|
45
|
+
const body = new URLSearchParams(init.body);
|
|
46
|
+
assert.equal(body.get("client_id"), "fixture-client");
|
|
47
|
+
assert.equal(body.get("client_secret"), "fixture-client-secret");
|
|
48
|
+
if (body.get("grant_type") === "refresh_token") assert.equal(body.get("refresh_token"), `fixture-refresh-${state.tokenCount}+&%`);
|
|
49
|
+
state.tokenCount += 1;
|
|
50
|
+
if (state.tokenText !== undefined) return new Response(state.tokenText, { status: state.tokenStatus });
|
|
51
|
+
return Response.json(state.tokenResponse ?? {
|
|
52
|
+
access_token: `fixture-access-${state.tokenCount}`, refresh_token: `fixture-refresh-${state.tokenCount}+&%`,
|
|
53
|
+
token_type: "bearer", expires_in: 60, scope: state.tokenScope
|
|
54
|
+
}, { status: state.tokenStatus });
|
|
55
|
+
}
|
|
56
|
+
assert.equal(headers.get("Client-Id"), "fixture-client");
|
|
57
|
+
assert.equal(headers.get("Authorization"), `Bearer fixture-access-${state.tokenCount}`);
|
|
58
|
+
if (url.pathname === "/oauth2/validate") {
|
|
59
|
+
assert.equal(init.method, "GET");
|
|
60
|
+
assert.equal(url.origin, "https://id.twitch.tv");
|
|
61
|
+
return Response.json(state.validation, { status: state.validationStatus });
|
|
62
|
+
}
|
|
63
|
+
assert.equal(url.origin, "https://api.twitch.tv");
|
|
64
|
+
if (state.apiResponse !== undefined) return state.apiStatus === 204 ? new Response(null, { status: 204 }) : Response.json(state.apiResponse, { status: state.apiStatus });
|
|
65
|
+
assert.equal(init.method, "GET");
|
|
66
|
+
assert.ok(["/helix/users", "/helix/channels/followed"].includes(url.pathname));
|
|
67
|
+
return Response.json(url.pathname === "/helix/users" ? state.profile : state.followed, { status: state.apiStatus });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const service = createConnectionService(options);
|
|
71
|
+
async function start() {
|
|
72
|
+
const { authorizationUrl } = await service.beginAuthorization(input);
|
|
73
|
+
const url = new URL(authorizationUrl);
|
|
74
|
+
const redirect = new URL(callback);
|
|
75
|
+
redirect.searchParams.set("code", "fixture-code");
|
|
76
|
+
redirect.searchParams.set("state", url.searchParams.get("state"));
|
|
77
|
+
return { url, callbackUrl: redirect.href };
|
|
78
|
+
}
|
|
79
|
+
const connect = async () => service.completeAuthorization({ ...input, callbackUrl: (await start()).callbackUrl });
|
|
80
|
+
return { service, options, protection, directory, requests, state, start, connect };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test("Twitch exchanges code consent, validates client ownership, and persists encrypted user grants across restart", async (t) => {
|
|
84
|
+
const { service, options, protection, directory, requests, state, start } = await fixture(t);
|
|
85
|
+
const { url, callbackUrl } = await start();
|
|
86
|
+
assert.equal(url.origin + url.pathname, "https://id.twitch.tv/oauth2/authorize");
|
|
87
|
+
assert.equal(url.searchParams.get("response_type"), "code");
|
|
88
|
+
assert.equal(url.searchParams.get("client_id"), "fixture-client");
|
|
89
|
+
assert.equal(url.searchParams.get("redirect_uri"), callback);
|
|
90
|
+
assert.equal(url.searchParams.get("scope"), scopes.join(" "));
|
|
91
|
+
assert.equal(url.searchParams.has("client_secret"), false);
|
|
92
|
+
const connected = await service.completeAuthorization({ ...input, callbackUrl });
|
|
93
|
+
assert.equal(connected.status, "connected");
|
|
94
|
+
assert.deepEqual(connected.grantedScopes, scopes);
|
|
95
|
+
assert.deepEqual(requests.map(({ url }) => url.pathname), ["/oauth2/token", "/oauth2/validate"]);
|
|
96
|
+
const code = new URLSearchParams(requests[0].init.body);
|
|
97
|
+
assert.equal(code.get("grant_type"), "authorization_code");
|
|
98
|
+
assert.equal(code.get("redirect_uri"), callback);
|
|
99
|
+
assert.equal(code.get("code"), "fixture-code");
|
|
100
|
+
for (const name of await readdir(directory)) {
|
|
101
|
+
const text = await readFile(path.join(directory, name), "utf8");
|
|
102
|
+
for (const secret of ["fixture-client-secret", "fixture-access-1", "fixture-refresh-1"]) assert.equal(text.includes(secret), false);
|
|
103
|
+
}
|
|
104
|
+
const restarted = createConnectionService({ ...options, store: createFileConnectionStore({ directory, protection }) });
|
|
105
|
+
assert.deepEqual(await restarted.status(input), { ...connected, callbackUrl: callback });
|
|
106
|
+
assert.deepEqual(await restarted.invoke({ ...input, operation: "profile.read" }), state.profile);
|
|
107
|
+
assert.deepEqual(requests.slice(-2).map(({ url }) => url.pathname), ["/oauth2/validate", "/helix/users"]);
|
|
108
|
+
assert.equal(requests.at(-1).url.search, "");
|
|
109
|
+
for (const owner of [{ ...context, applicationId: "other-app" }, { ...context, subjectId: "other-user" }]) {
|
|
110
|
+
await assert.rejects(restarted.invoke({ ...input, context: owner, operation: "profile.read" }), { code: "connector_reconnect_required" });
|
|
111
|
+
}
|
|
112
|
+
const changed = structuredClone(options.configuration);
|
|
113
|
+
changed.registrations.twitch.clientId = "other-client";
|
|
114
|
+
const count = requests.length;
|
|
115
|
+
await assert.rejects(createConnectionService({ ...options, configuration: changed }).invoke({ ...input, operation: "profile.read" }), { code: "connector_reconnect_required" });
|
|
116
|
+
assert.equal(requests.length, count);
|
|
117
|
+
await restarted.disconnect(input);
|
|
118
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("Twitch discovers streams/channels and updates only the validated broadcaster", async t => {
|
|
122
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "channel:manage:broadcast"]);
|
|
123
|
+
await connect();
|
|
124
|
+
state.apiResponse = { data: [{ id: "900", user_id: "456", title: "Grooming live", viewer_count: 42 }], pagination: { cursor: "next +&" } };
|
|
125
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "streams.list", input: { user_id: "456", first: 5, after: "next +&" } }), state.apiResponse);
|
|
126
|
+
assert.equal(requests.at(-1).url.searchParams.get("after"), "next +&");
|
|
127
|
+
state.apiResponse = { data: [{ id: "456", display_name: "Groomer", is_live: true }], pagination: {} };
|
|
128
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "channels.search", input: { query: "dogs & grooming", live_only: true } }), state.apiResponse);
|
|
129
|
+
assert.equal(requests.at(-1).url.searchParams.get("query"), "dogs & grooming");
|
|
130
|
+
state.apiResponse = { data: [{ broadcaster_id: "456", title: "Dog grooming" }] };
|
|
131
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "channels.read", input: { broadcaster_id: "456" } }), state.apiResponse);
|
|
132
|
+
state.apiStatus = 204;
|
|
133
|
+
const changes = { title: " Dogs & grooming ", game_id: "0", tags: ["Dogs", "Café"], is_branded_content: false };
|
|
134
|
+
assert.equal(await service.invoke({ ...input, operation: "broadcast.update", input: changes }), null);
|
|
135
|
+
assert.equal(requests.at(-1).init.method, "PATCH");
|
|
136
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "123");
|
|
137
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), changes);
|
|
138
|
+
for (const invalid of [{}, { broadcaster_id: "456", title: "Other user" }, { title: "" }, { tags: ["two words"] }]) {
|
|
139
|
+
await assert.rejects(service.invoke({ ...input, operation: "broadcast.update", input: invalid }), { code: "connector_input_invalid" });
|
|
140
|
+
}
|
|
141
|
+
const before = requests.length;
|
|
142
|
+
state.validation = { ...state.validation, scopes };
|
|
143
|
+
await assert.rejects(service.invoke({ ...input, operation: "broadcast.update", input: { title: "Denied" } }), { code: "connector_reconnect_required" });
|
|
144
|
+
assert.equal(requests.length, before + 1); // validation only; no channel write
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("Twitch serializes refresh rotation, encodes reserved token characters and preserves verified permission reduction", async (t) => {
|
|
148
|
+
const { service, options, state, connect } = await fixture(t);
|
|
149
|
+
state.validation = { ...state.validation, scopes: ["user:read:follows"] };
|
|
150
|
+
assert.deepEqual((await connect()).grantedScopes, ["user:read:follows"]);
|
|
151
|
+
state.time += 40_000;
|
|
152
|
+
state.tokenScope = scopes.join(" ");
|
|
153
|
+
state.validation = { ...state.validation, scopes };
|
|
154
|
+
await Promise.all([service.invoke({ ...input, operation: "channels.followed" }), service.invoke({ ...input, operation: "channels.followed" })]);
|
|
155
|
+
assert.equal(state.tokenCount, 2);
|
|
156
|
+
assert.deepEqual((await service.status(input)).grantedScopes, ["user:read:follows"]);
|
|
157
|
+
const restarted = createConnectionService(options);
|
|
158
|
+
state.time += 40_000;
|
|
159
|
+
state.tokenScope = scopes;
|
|
160
|
+
await restarted.invoke({ ...input, operation: "token.validate" });
|
|
161
|
+
assert.equal(state.tokenCount, 3);
|
|
162
|
+
await assert.rejects(restarted.invoke({ ...input, operation: "profile.read" }), { code: "connector_scope_missing" });
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("Twitch polls, predictions and chat use granted identities and preserve provider outcomes", async t => {
|
|
166
|
+
const granted = [...scopes, "channel:manage:polls", "channel:manage:predictions", "user:write:chat"];
|
|
167
|
+
const { service, requests, state, connect } = await fixture(t, granted);
|
|
168
|
+
await connect();
|
|
169
|
+
const choices = [{ title: "Morning" }, { title: "Evening" }];
|
|
170
|
+
for (const [operation, values, method, endpoint] of [
|
|
171
|
+
["polls.create", { title: "Next stream?", choices, duration: 60 }, "POST", "polls"],
|
|
172
|
+
["polls.end", { id: "poll-one", status: "TERMINATED" }, "PATCH", "polls"],
|
|
173
|
+
["predictions.create", { title: "Which dog wins?", outcomes: choices, prediction_window: 60 }, "POST", "predictions"],
|
|
174
|
+
["predictions.end", { id: "prediction-one", status: "RESOLVED", winning_outcome_id: "morning" }, "PATCH", "predictions"]
|
|
175
|
+
]) {
|
|
176
|
+
state.apiResponse = { data: [{ id: "result-one", broadcaster_id: "123", status: values.status || "ACTIVE" }] };
|
|
177
|
+
assert.deepEqual(await service.invoke({ ...input, operation, input: values }), state.apiResponse);
|
|
178
|
+
assert.equal(requests.at(-1).url.pathname, `/helix/${endpoint}`);
|
|
179
|
+
assert.equal(requests.at(-1).init.method, method);
|
|
180
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { ...values, broadcaster_id: "123" });
|
|
181
|
+
}
|
|
182
|
+
for (const operation of ["polls.list", "predictions.list"]) {
|
|
183
|
+
state.apiResponse = { data: [], pagination: { cursor: "next +&" } };
|
|
184
|
+
assert.deepEqual(await service.invoke({ ...input, operation, input: { first: 5, after: "next +&" } }), state.apiResponse);
|
|
185
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "123");
|
|
186
|
+
assert.equal(requests.at(-1).url.searchParams.get("after"), "next +&");
|
|
187
|
+
}
|
|
188
|
+
state.apiResponse = { data: [{ message_id: "", is_sent: false, drop_reason: { code: "automod_held", message: "Held" } }] };
|
|
189
|
+
const chat = { broadcaster_id: "456", message: " Hello & welcome " };
|
|
190
|
+
assert.equal((await service.invoke({ ...input, operation: "chat.send", input: chat })).data[0].is_sent, false);
|
|
191
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { ...chat, sender_id: "123" });
|
|
192
|
+
for (const [operation, values] of [
|
|
193
|
+
["polls.create", { title: "Question", choices: [{ title: "Only" }], duration: 60 }],
|
|
194
|
+
["predictions.end", { id: "prediction", status: "RESOLVED" }],
|
|
195
|
+
["predictions.end", { id: "prediction", status: "CANCELED", winning_outcome_id: "wrong" }],
|
|
196
|
+
["chat.send", { ...chat, sender_id: "456" }]
|
|
197
|
+
]) await assert.rejects(service.invoke({ ...input, operation, input: values }), { code: "connector_input_invalid" });
|
|
198
|
+
const count = requests.length;
|
|
199
|
+
state.validation = { ...state.validation, scopes };
|
|
200
|
+
await assert.rejects(service.invoke({ ...input, operation: "chat.send", input: chat }), { code: "connector_reconnect_required" });
|
|
201
|
+
assert.equal(requests.length, count + 1);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("Twitch supports both documented token-scope formats and rejects malformed successful grants", async (t) => {
|
|
205
|
+
const { service, state, connect } = await fixture(t);
|
|
206
|
+
for (const scope of [scopes, scopes.join(" "), [], ""]) {
|
|
207
|
+
state.tokenScope = scope;
|
|
208
|
+
const connected = await connect();
|
|
209
|
+
assert.deepEqual(connected.grantedScopes, typeof scope === "string" ? scope.split(" ").filter(Boolean) : scope);
|
|
210
|
+
await service.disconnect(input);
|
|
211
|
+
}
|
|
212
|
+
for (const scope of [null, {}, [1], ["user:read:email user:read:follows"], "user:read:email\nuser:read:follows"]) {
|
|
213
|
+
state.tokenScope = scope;
|
|
214
|
+
await assert.rejects(connect(), { code: "connector_response_invalid" });
|
|
215
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
216
|
+
}
|
|
217
|
+
state.tokenText = "not JSON";
|
|
218
|
+
await assert.rejects(connect(), { code: "connector_response_invalid" });
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("Twitch EventSub parser binds notifications and control messages to the app's connection", () => {
|
|
222
|
+
const owner = { broadcasterId: "123", sessionId: "socket-one", subscriptionIds: ["event-one"] };
|
|
223
|
+
const message = { metadata: { message_id: "message-one", message_type: "notification", message_timestamp: "2026-09-13T00:00:00.123456789Z", subscription_type: "channel.poll.begin", subscription_version: "1" },
|
|
224
|
+
payload: { subscription: { id: "event-one", status: "enabled", type: "channel.poll.begin", version: "1", condition: { broadcaster_user_id: "123" }, transport: { method: "websocket", session_id: "socket-one" } },
|
|
225
|
+
event: { broadcaster_user_id: "123", id: "poll-one", title: "Choose a topic" } } };
|
|
226
|
+
assert.deepEqual(parseTwitchEventSubMessage(JSON.stringify(message), owner), message);
|
|
227
|
+
for (const wrong of [{ ...owner, broadcasterId: "456" }, { ...owner, sessionId: "other" }, { ...owner, subscriptionIds: [] }]) {
|
|
228
|
+
assert.throws(() => parseTwitchEventSubMessage(JSON.stringify(message), wrong), { code: "connector_event_invalid" });
|
|
229
|
+
}
|
|
230
|
+
const revoked = structuredClone(message);
|
|
231
|
+
revoked.metadata.message_type = "revocation";
|
|
232
|
+
revoked.payload.subscription.status = "authorization_revoked";
|
|
233
|
+
delete revoked.payload.event;
|
|
234
|
+
assert.deepEqual(parseTwitchEventSubMessage(JSON.stringify(revoked), owner), revoked);
|
|
235
|
+
const reconnect = { metadata: { ...message.metadata, message_type: "session_reconnect" }, payload: { session: { id: "socket-one", status: "reconnecting", reconnect_url: "wss://eventsub.wss.twitch.tv/ws?reconnect=opaque" } } };
|
|
236
|
+
assert.deepEqual(parseTwitchEventSubMessage(JSON.stringify(reconnect), owner), reconnect);
|
|
237
|
+
reconnect.payload.session.reconnect_url = "wss://attacker.example/ws";
|
|
238
|
+
assert.throws(() => parseTwitchEventSubMessage(JSON.stringify(reconnect), owner), { code: "connector_event_invalid" });
|
|
239
|
+
const welcome = { metadata: { ...message.metadata, message_type: "session_welcome" }, payload: { session: { id: "socket-new", status: "connected", keepalive_timeout_seconds: 10 } } };
|
|
240
|
+
assert.deepEqual(parseTwitchEventSubMessage(JSON.stringify(welcome), owner), welcome);
|
|
241
|
+
assert.throws(() => parseTwitchEventSubMessage("x".repeat(1048577), owner), { code: "connector_event_invalid" });
|
|
242
|
+
assert.throws(() => parseTwitchEventSubMessage("{", owner), { code: "connector_event_invalid" });
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("Twitch EventSub uses owned WebSocket sessions, explicit events and validated grants", async t => {
|
|
246
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "channel:read:polls"]);
|
|
247
|
+
await connect();
|
|
248
|
+
const subscription = { id: "event-one", type: "channel.poll.begin", status: "enabled", transport: { method: "websocket", session_id: "socket-one" } };
|
|
249
|
+
state.apiResponse = { data: [subscription], pagination: {} };
|
|
250
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "events.subscribe", input: { type: subscription.type, session_id: "socket-one" } }), state.apiResponse);
|
|
251
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { type: subscription.type, version: "1", condition: { broadcaster_user_id: "123" }, transport: subscription.transport });
|
|
252
|
+
await service.invoke({ ...input, operation: "events.list", input: { after: "next" } });
|
|
253
|
+
assert.equal(requests.at(-1).url.searchParams.get("after"), "next");
|
|
254
|
+
const before = requests.length;
|
|
255
|
+
await assert.rejects(service.invoke({ ...input, operation: "events.subscribe", input: { type: "unknown.event", session_id: "socket-one" } }), { code: "connector_input_invalid" });
|
|
256
|
+
await assert.rejects(service.invoke({ ...input, operation: "events.subscribe", input: { type: subscription.type, session_id: "socket-one", broadcaster_user_id: "456" } }), { code: "connector_input_invalid" });
|
|
257
|
+
assert.equal(requests.length, before);
|
|
258
|
+
state.apiStatus = 204;
|
|
259
|
+
assert.equal(await service.invoke({ ...input, operation: "events.delete", input: { id: "event-one" } }), null);
|
|
260
|
+
assert.equal(requests.at(-1).init.method, "DELETE");
|
|
261
|
+
state.validation.scopes = scopes;
|
|
262
|
+
const deniedBefore = requests.filter(request => request.url.pathname === "/helix/eventsub/subscriptions").length;
|
|
263
|
+
await assert.rejects(service.invoke({ ...input, operation: "events.subscribe", input: { type: subscription.type, session_id: "socket-one" } }), { code: "connector_reconnect_required" });
|
|
264
|
+
assert.equal(requests.filter(request => request.url.pathname === "/helix/eventsub/subscriptions").length, deniedBefore);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("Twitch schedule segment lifecycle uses the connected broadcaster and explicit recurrence", async t => {
|
|
268
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "channel:manage:schedule"]);
|
|
269
|
+
await connect();
|
|
270
|
+
state.apiResponse = { data: { broadcaster_id: "123", segments: [{ id: "segment-one", start_time: "2026-10-01T09:00:00Z", end_time: "2026-10-01T10:00:00Z" }] }, pagination: { cursor: "next" } };
|
|
271
|
+
await service.invoke({ ...input, operation: "schedule.get", input: { broadcaster_id: "123", after: "next" } });
|
|
272
|
+
assert.equal(requests.at(-1).url.searchParams.get("after"), "next");
|
|
273
|
+
await service.invoke({ ...input, operation: "schedule.create", input: {
|
|
274
|
+
start_time: "2026-10-01T09:00:00Z", timezone: "Australia/Perth", duration: 60, is_recurring: true, title: "Weekly stream"
|
|
275
|
+
} });
|
|
276
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "123");
|
|
277
|
+
assert.equal(JSON.parse(requests.at(-1).init.body).duration, "60");
|
|
278
|
+
await service.invoke({ ...input, operation: "schedule.update", input: { id: "segment-one", is_canceled: true } });
|
|
279
|
+
assert.equal(requests.at(-1).url.searchParams.get("id"), "segment-one");
|
|
280
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { is_canceled: true });
|
|
281
|
+
const before = requests.length;
|
|
282
|
+
for (const values of [{ id: "segment-one" }, { id: "segment-one", duration: 29 }, { id: "segment-one", timezone: "not/a/zone" },
|
|
283
|
+
{ id: "segment-one", broadcaster_id: "456", title: "Wrong owner" }]) {
|
|
284
|
+
await assert.rejects(service.invoke({ ...input, operation: "schedule.update", input: values }), { code: "connector_input_invalid" });
|
|
285
|
+
}
|
|
286
|
+
assert.equal(requests.length, before);
|
|
287
|
+
state.apiStatus = 204;
|
|
288
|
+
assert.equal(await service.invoke({ ...input, operation: "schedule.delete", input: { id: "segment-one" } }), null);
|
|
289
|
+
assert.equal(requests.at(-1).init.method, "DELETE");
|
|
290
|
+
assert.equal(requests.at(-1).init.body, undefined);
|
|
291
|
+
const vacation = { is_vacation_enabled: true, vacation_start_time: "2026-10-01T00:00:00Z",
|
|
292
|
+
vacation_end_time: "2026-10-08T00:00:00Z", timezone: "Australia/Perth" };
|
|
293
|
+
assert.equal(await service.invoke({ ...input, operation: "schedule.vacation", input: vacation }), null);
|
|
294
|
+
assert.equal(requests.at(-1).url.pathname, "/helix/schedule/settings");
|
|
295
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "123");
|
|
296
|
+
assert.equal(requests.at(-1).url.searchParams.get("timezone"), "Australia/Perth");
|
|
297
|
+
assert.equal(requests.at(-1).init.body, undefined);
|
|
298
|
+
const beforeVacation = requests.length;
|
|
299
|
+
for (const values of [{ is_vacation_enabled: true }, { ...vacation, vacation_end_time: vacation.vacation_start_time },
|
|
300
|
+
{ ...vacation, vacation_start_time: "2026-02-30T00:00:00Z" }]) {
|
|
301
|
+
await assert.rejects(service.invoke({ ...input, operation: "schedule.vacation", input: values }), { code: "connector_input_invalid" });
|
|
302
|
+
}
|
|
303
|
+
assert.equal(requests.length, beforeVacation);
|
|
304
|
+
assert.equal(await service.invoke({ ...input, operation: "schedule.vacation", input: { is_vacation_enabled: false } }), null);
|
|
305
|
+
assert.equal(requests.at(-1).url.searchParams.get("is_vacation_enabled"), "false");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("Twitch reward lifecycle binds the broadcaster and keeps redemption decisions explicit", async t => {
|
|
309
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "channel:manage:redemptions"]);
|
|
310
|
+
await connect();
|
|
311
|
+
const reward = { id: "reward-one", broadcaster_id: "123", title: "Choose a topic", cost: 100 };
|
|
312
|
+
state.apiResponse = { data: [reward] };
|
|
313
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "rewards.create", input: { title: reward.title, cost: 100 } }), state.apiResponse);
|
|
314
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "123");
|
|
315
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { title: reward.title, cost: 100 });
|
|
316
|
+
await service.invoke({ ...input, operation: "rewards.list", input: { only_manageable_rewards: true } });
|
|
317
|
+
await service.invoke({ ...input, operation: "rewards.update", input: { id: reward.id, is_paused: true } });
|
|
318
|
+
assert.equal(requests.at(-1).url.searchParams.get("id"), reward.id);
|
|
319
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { is_paused: true });
|
|
320
|
+
const limits = { is_max_per_stream_enabled: true, max_per_stream: 10,
|
|
321
|
+
is_max_per_user_per_stream_enabled: true, max_per_user_per_stream: 2,
|
|
322
|
+
is_global_cooldown_enabled: true, global_cooldown_seconds: 60 };
|
|
323
|
+
await service.invoke({ ...input, operation: "rewards.update", input: { id: reward.id, ...limits } });
|
|
324
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), limits);
|
|
325
|
+
const redemption = { id: "redeem-one", broadcaster_id: "123", user_id: "456", status: "UNFULFILLED", reward };
|
|
326
|
+
state.apiResponse = { data: [redemption], pagination: { cursor: "more" } };
|
|
327
|
+
await service.invoke({ ...input, operation: "redemptions.list", input: { reward_id: reward.id } });
|
|
328
|
+
assert.equal(requests.at(-1).url.searchParams.get("status"), "UNFULFILLED");
|
|
329
|
+
state.apiResponse = { data: [{ ...redemption, status: "CANCELED" }] };
|
|
330
|
+
await service.invoke({ ...input, operation: "redemptions.update", input: { reward_id: reward.id, id: redemption.id, status: "CANCELED" } });
|
|
331
|
+
assert.equal(requests.at(-1).url.searchParams.get("reward_id"), reward.id);
|
|
332
|
+
assert.deepEqual(JSON.parse(requests.at(-1).init.body), { status: "CANCELED" });
|
|
333
|
+
state.apiStatus = 204;
|
|
334
|
+
assert.equal(await service.invoke({ ...input, operation: "rewards.delete", input: { id: reward.id } }), null);
|
|
335
|
+
assert.equal(requests.at(-1).init.method, "DELETE");
|
|
336
|
+
assert.equal(requests.at(-1).init.body, undefined);
|
|
337
|
+
const before = requests.length;
|
|
338
|
+
for (const [operation, values] of [["rewards.create", { title: "bad", cost: 0 }], ["rewards.update", { id: reward.id }],
|
|
339
|
+
["rewards.update", { id: reward.id, is_max_per_stream_enabled: true }],
|
|
340
|
+
["rewards.update", { id: reward.id, is_global_cooldown_enabled: true, global_cooldown_seconds: 604801 }],
|
|
341
|
+
["redemptions.update", { reward_id: reward.id, id: redemption.id, status: "UNFULFILLED" }], ["rewards.list", { broadcaster_id: "456" }]]) {
|
|
342
|
+
await assert.rejects(service.invoke({ ...input, operation, input: values }), { code: "connector_input_invalid" });
|
|
343
|
+
}
|
|
344
|
+
assert.equal(requests.length, before);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test("Twitch creates clips once and lets the application resolve pending clips", async t => {
|
|
348
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "clips:edit"]);
|
|
349
|
+
await connect();
|
|
350
|
+
state.apiResponse = { data: [{ id: "NewClip", edit_url: "https://clips.twitch.tv/NewClip/edit" }] };
|
|
351
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "clips.create", input: { broadcaster_id: "456" } }), state.apiResponse);
|
|
352
|
+
assert.equal(requests.at(-1).url.searchParams.get("broadcaster_id"), "456");
|
|
353
|
+
assert.equal(requests.at(-1).init.method, "POST");
|
|
354
|
+
state.apiResponse = { data: [] };
|
|
355
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "clips.get", input: { id: "NewClip" } }), state.apiResponse);
|
|
356
|
+
state.apiResponse = { data: [{ id: "NewClip", broadcaster_id: "456", url: "https://clips.twitch.tv/NewClip", title: "A useful moment" }] };
|
|
357
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "clips.get", input: { id: "NewClip" } }), state.apiResponse);
|
|
358
|
+
assert.equal(requests.filter(request => request.url.pathname === "/helix/clips" && request.init.method === "POST").length, 1);
|
|
359
|
+
const before = requests.length;
|
|
360
|
+
await assert.rejects(service.invoke({ ...input, operation: "clips.create", input: { broadcaster_id: "bad" } }), { code: "connector_input_invalid" });
|
|
361
|
+
assert.equal(requests.length, before);
|
|
362
|
+
state.apiResponse = { data: [{ id: "NewClip", edit_url: "https://untrusted.example/edit" }] };
|
|
363
|
+
await assert.rejects(service.invoke({ ...input, operation: "clips.create", input: { broadcaster_id: "456" } }), { code: "connector_response_invalid" });
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test("Twitch analytics preserve private report links and validate date windows without downloading", async t => {
|
|
367
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "analytics:read:extensions", "analytics:read:games"]);
|
|
368
|
+
await connect();
|
|
369
|
+
for (const [kind, identity] of [["extensions", "extension_id"], ["games", "game_id"]]) {
|
|
370
|
+
state.apiResponse = { data: [{ [identity]: "report-owner", URL: "https://reports.example.test/report.csv?signature=private", type: "overview_v2",
|
|
371
|
+
date_range: { started_at: "2026-08-01T00:00:00Z", ended_at: "2026-08-31T00:00:00Z" } }], pagination: { cursor: "next/report" } };
|
|
372
|
+
assert.deepEqual(await service.invoke({ ...input, operation: `analytics.${kind}`, input: {
|
|
373
|
+
[identity]: "report-owner", first: 5, after: "next/report", started_at: "2026-08-01T00:00:00Z", ended_at: "2026-08-31T00:00:00Z"
|
|
374
|
+
} }), state.apiResponse);
|
|
375
|
+
assert.equal(requests.at(-1).url.pathname, `/helix/analytics/${kind}`);
|
|
376
|
+
assert.equal(requests.at(-1).url.searchParams.get(identity), "report-owner");
|
|
377
|
+
const before = requests.length;
|
|
378
|
+
for (const values of [{ started_at: "2026-08-01T00:00:00Z" },
|
|
379
|
+
{ started_at: "2026-08-02T00:00:00Z", ended_at: "2026-08-01T00:00:00Z" },
|
|
380
|
+
{ started_at: "2026-02-30T00:00:00Z", ended_at: "2026-03-01T00:00:00Z" }]) {
|
|
381
|
+
await assert.rejects(service.invoke({ ...input, operation: `analytics.${kind}`, input: values }), { code: "connector_input_invalid" });
|
|
382
|
+
}
|
|
383
|
+
assert.equal(requests.length, before);
|
|
384
|
+
state.apiResponse.data[0].URL = "http://reports.example.test/insecure";
|
|
385
|
+
await assert.rejects(service.invoke({ ...input, operation: `analytics.${kind}` }), { code: "connector_response_invalid" });
|
|
386
|
+
state.apiResponse = { data: [], pagination: {} };
|
|
387
|
+
assert.deepEqual(await service.invoke({ ...input, operation: `analytics.${kind}` }), state.apiResponse);
|
|
388
|
+
}
|
|
389
|
+
assert.equal(requests.some(request => request.url.hostname === "reports.example.test"), false);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("Twitch Bits leaderboard preserves ranking and rejects invalid inputs or records", async t => {
|
|
393
|
+
const { service, requests, state, connect } = await fixture(t, [...scopes, "bits:read"]);
|
|
394
|
+
await connect();
|
|
395
|
+
state.apiResponse = { data: [{ user_id: "456", rank: 2, score: 1200 }], total: 1,
|
|
396
|
+
date_range: { started_at: "2026-09-01T00:00:00Z", ended_at: "2026-10-01T00:00:00Z" } };
|
|
397
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "bits.leaderboard", input: {
|
|
398
|
+
count: 5, period: "month", started_at: "2026-09-05T00:00:00Z", user_id: "456"
|
|
399
|
+
} }), state.apiResponse);
|
|
400
|
+
assert.equal(requests.at(-1).url.pathname, "/helix/bits/leaderboard");
|
|
401
|
+
assert.equal(requests.at(-1).url.searchParams.get("user_id"), "456");
|
|
402
|
+
assert.equal(requests.at(-1).url.searchParams.get("count"), "5");
|
|
403
|
+
const before = requests.length;
|
|
404
|
+
for (const values of [{ count: 101 }, { period: "hour" }, { started_at: "yesterday" }, { broadcaster_id: "456" }]) {
|
|
405
|
+
await assert.rejects(service.invoke({ ...input, operation: "bits.leaderboard", input: values }), { code: "connector_input_invalid" });
|
|
406
|
+
}
|
|
407
|
+
assert.equal(requests.length, before);
|
|
408
|
+
state.apiResponse.data[0].score = -1;
|
|
409
|
+
await assert.rejects(service.invoke({ ...input, operation: "bits.leaderboard" }), { code: "connector_response_invalid" });
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test("Twitch channel reads bind protected account identities and preserve useful records", async t => {
|
|
413
|
+
const granted = [...scopes, "channel:read:subscriptions", "user:read:subscriptions", "channel:read:vips", "channel:read:editors", "moderation:read", "moderator:read:followers", "moderator:read:chatters", "channel:read:hype_train"];
|
|
414
|
+
const { service, requests, state, connect } = await fixture(t, granted);
|
|
415
|
+
await connect();
|
|
416
|
+
for (const [operation, endpoint, values, identity, response] of [
|
|
417
|
+
["subscriptions.list", "subscriptions", { user_id: "456" }, "broadcaster_id", { data: [{ user_id: "456", tier: "1000" }], pagination: { cursor: "next" } }],
|
|
418
|
+
["subscriptions.check", "subscriptions/user", { broadcaster_id: "456" }, "user_id", { data: [{ broadcaster_id: "456", tier: "1000" }] }],
|
|
419
|
+
["vips.list", "channels/vips", {}, "broadcaster_id", { data: [{ user_id: "456" }], pagination: {} }],
|
|
420
|
+
["editors.list", "channels/editors", {}, "broadcaster_id", { data: [{ user_id: "456" }] }],
|
|
421
|
+
["bannedUsers.list", "moderation/banned", {}, "broadcaster_id", { data: [{ user_id: "456", reason: "spam" }], pagination: {} }],
|
|
422
|
+
["moderators.list", "moderation/moderators", {}, "broadcaster_id", { data: [{ user_id: "456" }], pagination: {} }],
|
|
423
|
+
["followers.list", "channels/followers", {}, "broadcaster_id", { data: [{ user_id: "456" }], pagination: {}, total: 1 }],
|
|
424
|
+
["chatters.list", "chat/chatters", { broadcaster_id: "456" }, "moderator_id", { data: [{ user_id: "789" }], pagination: {}, total: 1 }],
|
|
425
|
+
["hypeTrain.status", "hypetrain/status", {}, "broadcaster_id", { data: [{ current: null, last: null }] }]
|
|
426
|
+
]) {
|
|
427
|
+
state.apiResponse = response;
|
|
428
|
+
assert.deepEqual(await service.invoke({ ...input, operation, input: values }), response);
|
|
429
|
+
assert.equal(requests.at(-1).url.pathname, `/helix/${endpoint}`);
|
|
430
|
+
assert.equal(requests.at(-1).url.searchParams.get(identity), "123");
|
|
431
|
+
}
|
|
432
|
+
const before = requests.length;
|
|
433
|
+
await assert.rejects(service.invoke({ ...input, operation: "editors.list", input: { broadcaster_id: "456" } }), { code: "connector_input_invalid" });
|
|
434
|
+
await assert.rejects(service.invoke({ ...input, operation: "chatters.list", input: { broadcaster_id: "456", moderator_id: "456" } }), { code: "connector_input_invalid" });
|
|
435
|
+
assert.equal(requests.length, before);
|
|
436
|
+
state.apiResponse = { data: [{ user_id: "bad" }], pagination: {} };
|
|
437
|
+
await assert.rejects(service.invoke({ ...input, operation: "vips.list" }), { code: "connector_response_invalid" });
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test("Twitch rejects invalid user-token validation and mismatched profiles without connecting another account", async (t) => {
|
|
441
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
442
|
+
const valid = structuredClone(state.validation);
|
|
443
|
+
for (const patch of [{ client_id: "other-client" }, { user_id: null, login: null }, { expires_in: 0 }, { expires_in: 1.5 }, { scopes: "user:read:email" }, { scopes: [7] }, { user_id: "" }]) {
|
|
444
|
+
state.validation = { ...valid, ...patch };
|
|
445
|
+
await assert.rejects(connect(), { code: patch.client_id ? "connector_reconnect_required" : "connector_response_invalid" });
|
|
446
|
+
assert.equal((await service.status(input)).status, "disconnected");
|
|
447
|
+
assert.equal(requests.some(({ url }) => url.origin === "https://api.twitch.tv"), false);
|
|
448
|
+
}
|
|
449
|
+
state.validation = valid;
|
|
450
|
+
await connect();
|
|
451
|
+
state.profile = { data: [{ id: "999", login: "someone-else" }] };
|
|
452
|
+
await assert.rejects(service.invoke({ ...input, operation: "profile.read" }), { code: "connector_response_invalid" });
|
|
453
|
+
state.profile = { data: [] };
|
|
454
|
+
await assert.rejects(service.invoke({ ...input, operation: "profile.read" }), { code: "connector_response_invalid" });
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test("Twitch derives followed-channel user identity, bounds pages and preserves opaque cursors without auto-paging", async (t) => {
|
|
458
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
459
|
+
await connect();
|
|
460
|
+
let count = requests.length;
|
|
461
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "channels.followed", input: { first: 100, after: "next +&2", broadcaster_id: "456" } }), followed);
|
|
462
|
+
assert.equal(requests.length, count + 2);
|
|
463
|
+
assert.deepEqual(Object.fromEntries(requests.at(-1).url.searchParams), { first: "100", after: "next +&2", broadcaster_id: "456", user_id: "123" });
|
|
464
|
+
count = requests.length;
|
|
465
|
+
for (const invalid of [{ first: 0 }, { first: 101 }, { first: 1.5 }, { after: "" }, { after: "a".repeat(4097) }, { broadcaster_id: "a" }, { user_id: "999" }, { url: "https://attacker.invalid" }, { access_token: "raw" }]) {
|
|
466
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed", input: invalid }), { code: "connector_input_invalid" });
|
|
467
|
+
}
|
|
468
|
+
await assert.rejects(service.invoke({ ...input, operation: "profile.read", input: { id: "999" } }), { code: "connector_input_invalid" });
|
|
469
|
+
await assert.rejects(service.invoke({ ...input, operation: "token.validate", input: { token: "raw" } }), { code: "connector_input_invalid" });
|
|
470
|
+
assert.equal(requests.length, count);
|
|
471
|
+
state.followed = { total: 0, data: [], pagination: {} };
|
|
472
|
+
assert.deepEqual(await service.invoke({ ...input, operation: "channels.followed" }), state.followed);
|
|
473
|
+
assert.equal(requests.at(-1).url.searchParams.get("first"), "20");
|
|
474
|
+
for (const malformed of [{ ...followed, pagination: [] }, { ...followed, pagination: "cursor" }, { ...followed, pagination: null }, { ...followed, pagination: { cursor: 4 } }, { ...followed, total: -1 }, { ...followed, data: [{}] }]) {
|
|
475
|
+
state.followed = malformed;
|
|
476
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed" }), { code: "connector_response_invalid" });
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test("Twitch cancellation, denial, wrong-owner completion and callback replay never exchange an unauthorized code", async (t) => {
|
|
481
|
+
const { service, start, requests, connect } = await fixture(t);
|
|
482
|
+
const cancelled = await start();
|
|
483
|
+
await service.cancelAuthorization({ ...input, state: cancelled.url.searchParams.get("state") });
|
|
484
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: cancelled.callbackUrl }), { code: "connector_attempt_invalid" });
|
|
485
|
+
const denied = await start();
|
|
486
|
+
const denial = new URL(denied.callbackUrl);
|
|
487
|
+
denial.searchParams.delete("code");
|
|
488
|
+
denial.searchParams.set("error", "access_denied");
|
|
489
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: denial.href }), { code: "connector_consent_denied" });
|
|
490
|
+
const pending = await start();
|
|
491
|
+
await assert.rejects(service.completeAuthorization({ ...input, context: { ...context, subjectId: "other-user" }, callbackUrl: pending.callbackUrl }), { code: "connector_attempt_invalid" });
|
|
492
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: pending.callbackUrl.replace("app.example.test", "other.example.test") }), { code: "connector_callback_invalid" });
|
|
493
|
+
assert.equal(requests.length, 0);
|
|
494
|
+
await service.completeAuthorization({ ...input, callbackUrl: pending.callbackUrl });
|
|
495
|
+
await assert.rejects(service.completeAuthorization({ ...input, callbackUrl: pending.callbackUrl }), { code: "connector_attempt_invalid" });
|
|
496
|
+
assert.equal(requests.length, 2);
|
|
497
|
+
await connect();
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test("Twitch validation detects revoked tokens and scopes before Helix and records reconnect state", async (t) => {
|
|
501
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
502
|
+
for (const failure of ["token", "scope"]) {
|
|
503
|
+
state.validationStatus = 200;
|
|
504
|
+
state.validation = { ...state.validation, scopes };
|
|
505
|
+
await connect();
|
|
506
|
+
if (failure === "token") state.validationStatus = 401;
|
|
507
|
+
else state.validation = { ...state.validation, scopes: ["user:read:email"] };
|
|
508
|
+
const count = requests.length;
|
|
509
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed" }), { code: "connector_reconnect_required" });
|
|
510
|
+
assert.equal(requests.length, count + 1);
|
|
511
|
+
assert.equal(requests.at(-1).url.pathname, "/oauth2/validate");
|
|
512
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
test("Twitch maps validation and API failures without retries or credential disclosure", async (t) => {
|
|
517
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
518
|
+
await connect();
|
|
519
|
+
for (const target of ["validation", "api"]) {
|
|
520
|
+
for (const [status, code] of [[403, "connector_permission_denied"], [429, "connector_rate_limited"], [500, "connector_provider_failed"]]) {
|
|
521
|
+
state.validationStatus = target === "validation" ? status : 200;
|
|
522
|
+
state.apiStatus = target === "api" ? status : 200;
|
|
523
|
+
const count = requests.length;
|
|
524
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed" }), (error) => {
|
|
525
|
+
assert.equal(error.code, code);
|
|
526
|
+
assert.equal(JSON.stringify(error).includes("fixture-"), false);
|
|
527
|
+
return true;
|
|
528
|
+
});
|
|
529
|
+
assert.equal(requests.length, count + (target === "validation" ? 1 : 2));
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
state.validationStatus = 200;
|
|
533
|
+
state.apiStatus = 401;
|
|
534
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed" }), { code: "connector_reconnect_required" });
|
|
535
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("Twitch handles documented invalid-refresh errors and preserves non-JSON token error status", async (t) => {
|
|
539
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
540
|
+
await connect();
|
|
541
|
+
state.time += 40_000;
|
|
542
|
+
state.tokenStatus = 400;
|
|
543
|
+
state.tokenResponse = { error: "Bad Request", status: 400, message: "Invalid refresh token" };
|
|
544
|
+
const count = requests.length;
|
|
545
|
+
await assert.rejects(service.invoke({ ...input, operation: "token.validate" }), { code: "connector_reconnect_required" });
|
|
546
|
+
assert.equal(requests.length, count + 1);
|
|
547
|
+
assert.equal((await service.status(input)).status, "reconnect-required");
|
|
548
|
+
for (const [status, code] of [[401, "connector_reconnect_required"], [429, "connector_rate_limited"], [500, "connector_provider_failed"]]) {
|
|
549
|
+
state.tokenStatus = status;
|
|
550
|
+
state.tokenText = "fixture-client-secret";
|
|
551
|
+
await assert.rejects(connect(), (error) => {
|
|
552
|
+
assert.equal(error.code, code);
|
|
553
|
+
assert.equal(error.message.includes("fixture-client-secret"), false);
|
|
554
|
+
return true;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test("Twitch propagates interruption across validation and Helix without continuing or replaying", async (t) => {
|
|
560
|
+
const { service, state, connect, requests } = await fixture(t);
|
|
561
|
+
await connect();
|
|
562
|
+
for (const interruptPath of ["/oauth2/validate", "/helix/channels/followed"]) {
|
|
563
|
+
for (const [name, code] of [["AbortError", "connector_cancelled"], ["TimeoutError", "connector_provider_timeout"]]) {
|
|
564
|
+
state.controller = new AbortController();
|
|
565
|
+
state.interruptPath = interruptPath;
|
|
566
|
+
state.interruptName = name;
|
|
567
|
+
const count = requests.length;
|
|
568
|
+
await assert.rejects(service.invoke({ ...input, operation: "channels.followed", signal: state.controller.signal }), { code });
|
|
569
|
+
assert.equal(requests.length, count + (interruptPath === "/oauth2/validate" ? 1 : 2));
|
|
570
|
+
assert.equal((await service.status(input)).status, "connected");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|