@jskit-ai/connectors-catalog 0.2.26 → 0.2.28

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/package.json +3 -3
  3. package/patterns/api-key-connection/example/connections.js +4 -1
  4. package/patterns/firebase-messaging/example/server/notifications.js +4 -1
  5. package/src/server/brevo.js +9 -8
  6. package/src/server/calendly.js +5 -4
  7. package/src/server/chargebee.js +6 -5
  8. package/src/server/firebase-cloud-messaging.js +2 -1
  9. package/src/server/gatewayapi.js +4 -3
  10. package/src/server/gmail.js +3 -2
  11. package/src/server/google-ads-search.js +3 -2
  12. package/src/server/incident-io.js +3 -2
  13. package/src/server/inngest.js +3 -2
  14. package/src/server/linkedin.js +2 -1
  15. package/src/server/mailgun.js +3 -2
  16. package/src/server/microsoft-outlook.js +5 -4
  17. package/src/server/microsoft-teams.js +4 -3
  18. package/src/server/resend.js +4 -3
  19. package/src/server/sideEffect.js +17 -0
  20. package/src/server/slack.js +3 -2
  21. package/src/server/telegram.js +3 -2
  22. package/src/server/twilio.js +5 -4
  23. package/src/server/twitch.js +3 -2
  24. package/src/server/wave.js +4 -3
  25. package/src/server/wixBookings.js +10 -9
  26. package/src/server/woocommerce.js +2 -1
  27. package/test/brevo.test.js +1 -1
  28. package/test/calendly.test.js +3 -3
  29. package/test/chargebee.test.js +4 -4
  30. package/test/firebase-cloud-messaging.test.js +4 -4
  31. package/test/google-ads.test.js +9 -9
  32. package/test/google.test.js +5 -5
  33. package/test/inngest.test.js +4 -4
  34. package/test/linkedin.test.js +6 -6
  35. package/test/mailgun.test.js +1 -1
  36. package/test/microsoft.test.js +5 -5
  37. package/test/resend.test.js +1 -1
  38. package/test/slack.test.js +5 -5
  39. package/test/telegram.test.js +1 -1
  40. package/test/tokens.test.js +18 -18
  41. package/test/twilio.test.js +5 -5
  42. package/test/twitch.test.js +4 -4
  43. package/test/wave.test.js +5 -5
  44. package/test/wix.test.js +4 -4
  45. package/test/wordpress.test.js +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Operations that act on the world are marked `sideEffect`, so a test copy (`SIDE_EFFECTS` is not `live`) simulates them: Brevo email, SMS, campaign sends and events; Calendly cancellations and invitees; Chargebee subscription changes; Firebase Cloud Messaging; GatewayAPI; Gmail sends; Google Ads campaign status; incident.io incidents; Inngest events; LinkedIn posts; Mailgun; Outlook mail and events; Teams messages; Resend emails and broadcasts; Slack messages; Telegram; Twilio messages and calls; Twitch chat; Wave invoice and estimate sends; Wix Bookings changes; WooCommerce refunds. The api-key and Firebase messaging patterns pass `sideEffects: resolveSideEffectsMode(env)`.
5
6
  - The browser catalog (`./shared`) no longer bundles the whole AI model snapshot. The AI connector definition now reads only the 13 configurable providers (0.2 MB, in `ai-models.json`). The other 200 providers, which are framework metadata (2.0 MB), moved to `ai-framework-models.json`, which only `./shared/ai` and `./server/ai` load. Exports, the catalogue and every configurable model's choices, hints and credential scopes are unchanged. The definition no longer recognises a framework provider's model key, which its settings schema already rejected.
6
7
  - The Resend guide shows local auth's `auth.local.confirmation-sender` next to its recovery sender.
7
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/connectors-catalog",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "description": "Provider definitions and focused API operations for JSKIT connectors.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -125,14 +125,14 @@
125
125
  "@aws-sdk/client-redshift-data": "3.1128.0",
126
126
  "@aws-sdk/client-s3": "3.1128.0",
127
127
  "@aws-sdk/s3-request-presigner": "3.1128.0",
128
- "@jskit-ai/connectors-core": "0.2.26",
128
+ "@jskit-ai/connectors-core": "0.2.28",
129
129
  "@modelcontextprotocol/sdk": "1.32.1",
130
130
  "@smithy/fetch-http-handler": "5.8.0",
131
131
  "jose": "^6.1.3",
132
132
  "json-rest-schema": "^1.0.20"
133
133
  },
134
134
  "peerDependencies": {
135
- "@jskit-ai/kernel": "0.2.18"
135
+ "@jskit-ai/kernel": "0.2.20"
136
136
  },
137
137
  "jskit": {
138
138
  "kind": "runtime",
@@ -1,6 +1,7 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
3
3
  import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
4
+ import { resolveSideEffectsMode } from "@jskit-ai/kernel/shared/support/sideEffects";
4
5
  import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
5
6
  import { resendProvider } from "@jskit-ai/connectors-catalog/server/resend";
6
7
  import { firecrawlProvider } from "@jskit-ai/connectors-catalog/server/firecrawl";
@@ -17,5 +18,7 @@ export async function applicationConnections({ authorize, env = process.env, con
17
18
  keys: { current: Buffer.from(env.CONNECTOR_STORAGE_KEY, "base64") }, activeKeyId: "current"
18
19
  });
19
20
  const store = createFileConnectionStore({ directory: env.CONNECTOR_STATE_DIRECTORY, protection });
20
- return createConnectionService({ configuration, providers, store, authorize, resolveReference: createEnvironmentReferenceResolver(env) });
21
+ // Sending email is a side effect: a test copy (SIDE_EFFECTS is not `live`) logs it and answers { simulated: true }.
22
+ return createConnectionService({ configuration, providers, store, authorize, resolveReference: createEnvironmentReferenceResolver(env),
23
+ sideEffects: resolveSideEffectsMode(env) });
21
24
  }
@@ -1,6 +1,7 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
3
3
  import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
4
+ import { resolveSideEffectsMode } from "@jskit-ai/kernel/shared/support/sideEffects";
4
5
  import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
5
6
  import { firebaseCloudMessagingProvider } from "@jskit-ai/connectors-catalog/server/firebase-cloud-messaging";
6
7
 
@@ -26,6 +27,8 @@ export async function openNotificationConnections({
26
27
  const store = createFileConnectionStore({ directory: runtimeDirectory, protection });
27
28
  return createConnectionService({ configuration, providers, store,
28
29
  resolveReference: createEnvironmentReferenceResolver(environment),
29
- authorize: authorizeConnectionOperation
30
+ authorize: authorizeConnectionOperation,
31
+ // A push notification is a side effect: a test copy (SIDE_EFFECTS is not `live`) logs it and sends none.
32
+ sideEffects: resolveSideEffectsMode(environment)
30
33
  });
31
34
  }
@@ -3,6 +3,7 @@ import { createSchema } from "json-rest-schema";
3
3
  import { brevoDefinition } from "../shared/tokens.js";
4
4
  import { jsonOperation, validatedOperation, withQuery } from "./jsonOperation.js";
5
5
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
6
+ import { sideEffect } from "./sideEffect.js";
6
7
 
7
8
  const text = { type: "string", minLength: 1, maxLength: 1000 };
8
9
  const email = { ...text, maxLength: 320, pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$" };
@@ -40,18 +41,18 @@ const brevoProvider = Object.freeze({
40
41
  apiKey: { headers: (key) => ({ "api-key": key }) },
41
42
  checkOperation: "contacts.list",
42
43
  operations: {
43
- "email.send": operation("POST", "smtp/email", { sender: { ...mailbox, required: true },
44
+ "email.send": sideEffect(operation("POST", "smtp/email", { sender: { ...mailbox, required: true },
44
45
  to: { type: "array", required: true, items: mailbox, validator: value => value.length > 0 && value.length <= 50 || "Supply 1–50 recipients." },
45
46
  subject: text, htmlContent: { ...text, maxLength: 1000000 }, textContent: { ...text, maxLength: 1000000 },
46
47
  templateId: { ...id, required: false }, params: bag, replyTo: mailbox
47
- }, result => typeof result?.messageId === "string", content),
48
- "sms.send": operation("POST", "transactionalSMS/sms", { sender: { ...text, required: true, maxLength: 15,
48
+ }, result => typeof result?.messageId === "string", content)),
49
+ "sms.send": sideEffect(operation("POST", "transactionalSMS/sms", { sender: { ...text, required: true, maxLength: 15,
49
50
  validator: value => /^[A-Za-z0-9]{1,11}$/.test(value) || /^[0-9]{12,15}$/.test(value) || "Use 1–11 letters/digits or 12–15 digits for the SMS sender." },
50
51
  recipient: { type: "string", required: true, pattern: "^\\+?[0-9]{6,15}$" }, type: { type: "string", required: true, enum: ["transactional", "marketing"] },
51
52
  content: { ...text, maxLength: 10000 }, templateId: { ...id, required: false }, params: bag, unicodeEnabled: bool, organisationPrefix: text, tag: text
52
53
  }, result => Number.isInteger(result?.messageId) && typeof result.reference === "string", value => {
53
54
  if ((value.content === undefined) === (value.templateId === undefined)) throw new ConnectorError("connector_input_invalid", "Choose SMS content or a template, not both.", { statusCode: 422, messageCode: "connectors.brevo.smsContentOrTemplate" }); return value;
54
- }),
55
+ })),
55
56
  "contacts.get": operation("GET", "contacts/{resource}", { resource: { ...email, required: true } }, record),
56
57
  "contacts.create": operation("POST", "contacts", { email: { ...email, required: true }, ...contact,
57
58
  updateEnabled: { ...bool, defaultTo: false } }, result => empty(result) || record(result)),
@@ -74,17 +75,17 @@ const brevoProvider = Object.freeze({
74
75
  validator: value => value.length > 0 && value.length <= 100 || "Choose 1–100 recipient lists." }, exclusionListIds: ids }) },
75
76
  replyTo: email, previewText: text, tag: text
76
77
  }, record, content),
77
- "campaigns.sendTest": operation("POST", "emailCampaigns/{resource}/sendTest", { resource: id, emailTo: { ...emails, required: true } }, empty),
78
- "campaigns.sendNow": operation("POST", "emailCampaigns/{resource}/sendNow", { resource: id }, empty),
78
+ "campaigns.sendTest": sideEffect(operation("POST", "emailCampaigns/{resource}/sendTest", { resource: id, emailTo: { ...emails, required: true } }, empty)),
79
+ "campaigns.sendNow": sideEffect(operation("POST", "emailCampaigns/{resource}/sendNow", { resource: id }, empty)),
79
80
  "email.events": operation("GET", "smtp/statistics/events", { ...page, messageId: text, email, days: { type: "integer", min: 1, max: 90 },
80
81
  event: { type: "string", enum: ["blocked", "bounces", "deferred", "delivered", "hardBounces", "invalid", "opened", "requests", "softBounces", "spam", "unsubscribed", "clicks", "error", "loadedByProxy"] }
81
82
  }, result => Array.isArray(result?.events)),
82
83
  "sms.events": operation("GET", "transactionalSMS/statistics/events", { ...page, phoneNumber: text, days: { type: "integer", min: 1, max: 90 } }, result => Array.isArray(result?.events)),
83
- "events.create": operation("POST", "events", { event_name: { type: "string", required: true, maxLength: 255, pattern: "^[A-Za-z0-9_-]+$" },
84
+ "events.create": sideEffect(operation("POST", "events", { event_name: { type: "string", required: true, maxLength: 255, pattern: "^[A-Za-z0-9_-]+$" },
84
85
  identifiers: { type: "object", required: true, schema: createSchema({ email_id: { ...email, required: true } }) },
85
86
  event_properties: { ...bag, validator: value => Buffer.byteLength(JSON.stringify(value)) <= 50000 || "Event properties exceed 50KB." }, contact_properties: bag,
86
87
  event_date: { ...text, validator: value => Number.isFinite(Date.parse(value)) && /^\d{4}-\d{2}-\d{2}T/.test(value) || "Use an ISO timestamp." }
87
- }, empty),
88
+ }, empty)),
88
89
  "contacts.list": jsonOperation("https://api.brevo.com/v3/contacts", {
89
90
  limit: { type: "integer", min: 1, max: 1000, defaultTo: 50 },
90
91
  offset: { type: "integer", min: 0, defaultTo: 0 },
@@ -2,6 +2,7 @@ import { ConnectorError } from "@jskit-ai/connectors-core/server";
2
2
  import { createSchema } from "json-rest-schema";
3
3
  import { calendlyDefinition } from "../shared/tokens.js";
4
4
  import { jsonOperation, validatedOperation, withQuery } from "./jsonOperation.js";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  const id = { type: "string", required: true, minLength: 1, maxLength: 100, pattern: "^[A-Za-z0-9_-]+$" };
7
8
  const text = { type: "string", minLength: 1, maxLength: 1000 };
@@ -43,18 +44,18 @@ const calendlyProvider = Object.freeze({
43
44
  if (!(value.user || value.organization || value.group)) throw new ConnectorError("connector_input_invalid", "Choose the user, organization or group whose events to read.", { statusCode: 422, messageCode: "connectors.calendly.chooseEventOwner" }); return value;
44
45
  }),
45
46
  "events.get": operation("GET", "scheduled_events/{uuid}", { uuid: id }, "scheduled_events:read", record),
46
- "events.cancel": operation("POST", "scheduled_events/{uuid}/cancellation", { uuid: id, reason: { ...text, maxLength: 10000 } },
47
- "scheduled_events:write", result => typeof result?.resource?.canceled_by === "string" && typeof result.resource.created_at === "string"),
47
+ "events.cancel": sideEffect(operation("POST", "scheduled_events/{uuid}/cancellation", { uuid: id, reason: { ...text, maxLength: 10000 } },
48
+ "scheduled_events:write", result => typeof result?.resource?.canceled_by === "string" && typeof result.resource.created_at === "string")),
48
49
  "invitees.list": operation("GET", "scheduled_events/{uuid}/invitees", { uuid: id, ...page, status, email,
49
50
  sort: { type: "string", enum: ["created_at:asc", "created_at:desc"] } }, "scheduled_events:read", collection),
50
51
  "invitees.get": operation("GET", "scheduled_events/{uuid}/invitees/{invitee_uuid}", { uuid: id, invitee_uuid: id }, "scheduled_events:read", record),
51
- "invitees.create": operation("POST", "invitees", { event_type: { ...uri("event_types"), required: true }, start_time: { ...date, required: true },
52
+ "invitees.create": sideEffect(operation("POST", "invitees", { event_type: { ...uri("event_types"), required: true }, start_time: { ...date, required: true },
52
53
  invitee: { type: "object", required: true, schema: createSchema({ email: { ...email, required: true }, name: text,
53
54
  timezone: { ...text, required: true, validator: value => { try { new Intl.DateTimeFormat("en", { timeZone: value }); return true; } catch { return "Choose an IANA timezone."; } } } }) },
54
55
  questions_and_answers: { type: "array", items: { type: "object", schema: createSchema({ question: { ...text, required: true }, answer: { ...text, required: true }, position: { type: "integer", required: true, min: 0 } }) },
55
56
  validator: value => value.length <= 100 || "Use at most 100 answers." },
56
57
  event_guests: { type: "array", items: email, validator: value => value.length <= 10 || "Use at most 10 guests." }
57
- }, "scheduled_events:write", record),
58
+ }, "scheduled_events:write", record)),
58
59
  "schedulingLinks.create": operation("POST", "scheduling_links", { owner: { ...uri("event_types"), required: true },
59
60
  owner_type: { type: "string", enum: ["EventType"], defaultTo: "EventType" }, max_event_count: { type: "integer", enum: [1], defaultTo: 1 }
60
61
  }, "scheduling_links:write", result => typeof result?.resource?.booking_url === "string" && typeof result.resource.owner === "string"),
@@ -2,6 +2,7 @@ import { ConnectorError } from "@jskit-ai/connectors-core/server";
2
2
  import { createSchema } from "json-rest-schema";
3
3
  import { chargebeeDefinition } from "../shared/chargebee.js";
4
4
  import { jsonOperation, validatedOperation } from "./jsonOperation.js";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  const origin = ({ siteName }) => `https://${siteName.toLowerCase()}.chargebee.com`;
7
8
  const text = { type: "string", minLength: 1, maxLength: 250 };
@@ -52,14 +53,14 @@ const chargebeeProvider = Object.freeze({
52
53
  "itemPrices.get": operation("GET", "item_prices/{resource}", { resource }, record("item_price")),
53
54
  "subscriptions.list": operation("GET", "subscriptions", { ...pagination, "customer_id[is]": text }, collection("subscription")),
54
55
  "subscriptions.get": operation("GET", "subscriptions/{resource}", { resource }, record("subscription")),
55
- "subscriptions.create": operation("POST", "customers/{resource}/subscription_for_items", { resource, subscription_items: itemList,
56
+ "subscriptions.create": sideEffect(operation("POST", "customers/{resource}/subscription_for_items", { resource, subscription_items: itemList,
56
57
  auto_collection: { type: "string", required: true, enum: ["on", "off"] }, invoice_immediately: { type: "boolean", required: true },
57
58
  id: { ...resource, required: false }, trial_end: { type: "integer", min: 0 }
58
- }, record("subscription")),
59
- "subscriptions.updateAtTermEnd": operation("POST", "subscriptions/{resource}/update_for_items", { resource, subscription_items: itemList,
59
+ }, record("subscription"))),
60
+ "subscriptions.updateAtTermEnd": sideEffect(operation("POST", "subscriptions/{resource}/update_for_items", { resource, subscription_items: itemList,
60
61
  replace_items_list: { type: "boolean", required: true }
61
- }, record("subscription"), { end_of_term: true }),
62
- "subscriptions.cancelAtTermEnd": operation("POST", "subscriptions/{resource}/cancel_for_items", { resource, cancel_reason_code: text }, record("subscription"), { cancel_option: "end_of_term" }),
62
+ }, record("subscription"), { end_of_term: true })),
63
+ "subscriptions.cancelAtTermEnd": sideEffect(operation("POST", "subscriptions/{resource}/cancel_for_items", { resource, cancel_reason_code: text }, record("subscription"), { cancel_option: "end_of_term" })),
63
64
  "invoices.list": operation("GET", "invoices", { ...pagination, "customer_id[is]": text, "subscription_id[is]": text }, collection("invoice")),
64
65
  "invoices.get": operation("GET", "invoices/{resource}", { resource, line_items_limit: { type: "integer", min: 1, max: 300 }, line_items_offset: { ...text, maxLength: 1000 } }, record("invoice")),
65
66
  "invoices.pdf": operation("POST", "invoices/{resource}/pdf", { resource, disposition_type: { type: "string", enum: ["inline", "attachment"], defaultTo: "attachment" } }, result => typeof result?.download?.download_url === "string"),
@@ -4,6 +4,7 @@ import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
4
4
  import { ConnectorError, providerStatusError } from "@jskit-ai/connectors-core/server";
5
5
  import { firebaseCloudMessagingDefinition, firebaseMessagingScope, firebaseProjectId } from "../shared/firebase-cloud-messaging.js";
6
6
  import { jsonOperation } from "./jsonOperation.js";
7
+ import { sideEffect } from "./sideEffect.js";
7
8
 
8
9
  const tokenUrl = "https://oauth2.googleapis.com/token";
9
10
  const endpoint = ({ projectId }) => `https://fcm.googleapis.com/v1/projects/${projectId}/messages:send`;
@@ -82,7 +83,7 @@ const firebaseCloudMessagingProvider = Object.freeze({
82
83
  "connection.check": { ...check, scopes: [firebaseMessagingScope], request(input, settings) {
83
84
  return { ...check.request(input, settings), body: { validate_only: true, message: { topic: "jskit-connection-check", data: { connectionCheck: "true" } } } };
84
85
  } },
85
- "messages.validate": messageOperation(true), "messages.send": messageOperation(false)
86
+ "messages.validate": messageOperation(true), "messages.send": sideEffect(messageOperation(false))
86
87
  },
87
88
  async exchange(address, options, { fetchImpl, settings }) {
88
89
  const response = await fetchImpl(address, { ...options, body: JSON.stringify(options.body), credentials: "omit", redirect: "error",
@@ -3,6 +3,7 @@ import { ConnectorError } from "@jskit-ai/connectors-core/server";
3
3
  import { createSchema } from "json-rest-schema";
4
4
  import { gatewayApiDefinition } from "../shared/tokens.js";
5
5
  import { jsonOperation } from "./jsonOperation.js";
6
+ import { sideEffect } from "./sideEffect.js";
6
7
 
7
8
  const origins = { global: "https://gatewayapi.com", eu: "https://gatewayapi.eu" };
8
9
  const messagingOrigins = { global: "https://messaging.gatewayapi.com", eu: "https://messaging.gatewayapi.eu" };
@@ -22,11 +23,11 @@ const gatewayApiProvider = Object.freeze({
22
23
  apiKey: { headers: (key) => ({ Authorization: `Token ${key}` }) },
23
24
  checkOperation: "balance.read",
24
25
  operations: {
25
- "messages.send": jsonOperation(settings => `${messagingOrigins[settings.region]}/mobile/single`, messageFields, validReceipt, "POST"),
26
- "messages.sendBatch": jsonOperation(settings => `${messagingOrigins[settings.region]}/mobile/multi`, {
26
+ "messages.send": sideEffect(jsonOperation(settings => `${messagingOrigins[settings.region]}/mobile/single`, messageFields, validReceipt, "POST")),
27
+ "messages.sendBatch": sideEffect(jsonOperation(settings => `${messagingOrigins[settings.region]}/mobile/multi`, {
27
28
  messages: { type: "array", required: true, items: { type: "object", schema: messageSchema },
28
29
  validator: value => value.length >= 1 && value.length <= 1000 || "Send 1–1000 messages per batch." }
29
- }, result => Array.isArray(result?.responses) && result.responses.every(validReceipt), "POST"),
30
+ }, result => Array.isArray(result?.responses) && result.responses.every(validReceipt), "POST")),
30
31
  "balance.read": jsonOperation((settings) => `${origins[settings.region]}/rest/me`, {},
31
32
  (result) => Number.isInteger(result?.id) && typeof result.credit === "string" && typeof result.currency === "string")
32
33
  }
@@ -1,6 +1,7 @@
1
1
  import { ConnectorError } from "@jskit-ai/connectors-core/server";
2
2
  import { gmailDefinition } from "../shared/google.js";
3
3
  import { googleOperation, googleRead, googleProvider, documentId, pageToken } from "./google.js";
4
+ import { sideEffect } from "./sideEffect.js";
4
5
  const origin = "https://gmail.googleapis.com";
5
6
  const read = ["gmail.readonly", "gmail.modify", "gmail.metadata", "https://mail.google.com/"];
6
7
  const contentScopes = ["gmail.readonly", "gmail.modify", "https://mail.google.com/"];
@@ -23,7 +24,7 @@ const gmailProvider = Object.freeze({ ...googleProvider(gmailDefinition, origin,
23
24
  "messages.read": googleRead(contentScopes, { id: documentId, format: { type: "string", enum: ["full", "raw"], defaultTo: "full" } }, ({ id, format }) => ({ url: `${origin}/gmail/v1/users/me/messages/${encodeURIComponent(id)}`, query: { format } }), messageResult),
24
25
  "messages.search": googleRead(contentScopes, { ...listFields, q: { type: "string", required: true, minLength: 1, maxLength: 4096 } }, query => ({ url: `${origin}/gmail/v1/users/me/messages`, query }), value => Number.isInteger(value?.resultSizeEstimate) && (value.messages === undefined || Array.isArray(value.messages))),
25
26
  "attachments.get": googleRead(contentScopes, { messageId: documentId, id: documentId }, ({ messageId, id }) => ({ url: `${origin}/gmail/v1/users/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(id)}` }), value => Number.isInteger(value?.size) && typeof value.data === "string"),
26
- "messages.send": gmailWrite(["gmail.send", ...composeScopes], { raw: rawField, threadId: { ...documentId, required: false } }, body => ({ path: "/messages/send", body }), messageResult),
27
+ "messages.send": sideEffect(gmailWrite(["gmail.send", ...composeScopes], { raw: rawField, threadId: { ...documentId, required: false } }, body => ({ path: "/messages/send", body }), messageResult)),
27
28
  "messages.modify": gmailWrite(modifyScopes, { id: documentId, addLabelIds: labelIds, removeLabelIds: labelIds }, ({ id, ...body }) => {
28
29
  if (!body.addLabelIds?.length && !body.removeLabelIds?.length) throw new ConnectorError("connector_input_invalid", "Supply labels to add or remove.", { statusCode: 422, messageCode: "connectors.gmail.supplyLabelsAddRemove" });
29
30
  return { path: `/messages/${encodeURIComponent(id)}/modify`, body };
@@ -35,7 +36,7 @@ const gmailProvider = Object.freeze({ ...googleProvider(gmailDefinition, origin,
35
36
  "drafts.create": gmailWrite(composeScopes, { raw: rawField, threadId: { ...documentId, required: false } }, message => ({ path: "/drafts", body: { message } }), draftResult),
36
37
  "drafts.update": gmailWrite(composeScopes, { id: documentId, raw: rawField, threadId: { ...documentId, required: false } }, ({ id, ...message }) => ({ path: `/drafts/${encodeURIComponent(id)}`, body: { message } }), draftResult, "PUT"),
37
38
  "drafts.delete": gmailWrite(composeScopes, { id: documentId }, ({ id }) => ({ path: `/drafts/${encodeURIComponent(id)}` }), value => value === null, "DELETE"),
38
- "drafts.send": gmailWrite(composeScopes, { id: documentId }, body => ({ path: "/drafts/send", body }), messageResult),
39
+ "drafts.send": sideEffect(gmailWrite(composeScopes, { id: documentId }, body => ({ path: "/drafts/send", body }), messageResult)),
39
40
  "labels.list": googleRead([...read, "gmail.labels"], {}, () => ({ url: `${origin}/gmail/v1/users/me/labels` }), value => Array.isArray(value?.labels)),
40
41
  "labels.delete": gmailWrite(labelScopes, { id: documentId }, ({ id }) => ({ path: `/labels/${encodeURIComponent(id)}` }), value => value === null, "DELETE"),
41
42
  "labels.create": gmailWrite(labelScopes, { name: { type: "string", required: true, minLength: 1, maxLength: 225 } }, body => ({ path: "/labels", body }), value => typeof value?.id === "string" && typeof value.name === "string"),
@@ -6,6 +6,7 @@ import { validateGoogleAdsSearchPlan } from "../shared/google-ads-search.js";
6
6
  import { validatedOperation } from "./jsonOperation.js";
7
7
  import { googleAdsApi, googleAdsScope, loginCustomerHeaders } from "./googleAdsApi.js";
8
8
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
9
+ import { sideEffect } from "./sideEffect.js";
9
10
 
10
11
  const customerId = { type: "string", required: true, validator: value => /^[0-9]{10}$/.test(value) || "Use a ten-digit customer ID." };
11
12
  const id = { type: "string", required: true, validator: value => /^[0-9]{1,20}$/.test(value) || "Use a numeric campaign ID." };
@@ -41,8 +42,8 @@ function searchMutation(plan, validateOnly) {
41
42
  const googleAdsSearchOperations = {
42
43
  "search.validate": { scopes: [googleAdsScope], request: (input, settings) => ({ method: "POST", ...searchMutation(input, true), headers: loginCustomerHeaders(settings) }), validateResult: mutated },
43
44
  "search.createPaused": { scopes: [googleAdsScope], request: (input, settings) => ({ method: "POST", ...searchMutation(input, false), headers: loginCustomerHeaders(settings) }), validateResult: result => mutated(result) && Array.isArray(result.mutateOperationResponses) && result.mutateOperationResponses.some(item => /^customers\/[0-9]{10}\/campaigns\/[0-9]+$/.test(item.campaignResult?.resourceName || "")) },
44
- "campaigns.setStatus": requestOperation({ customerId, campaignId: id, status: { type: "string", required: true, enum: ["PAUSED", "ENABLED"] } },
45
- p => ({ url: `${googleAdsApi}/customers/${p.customerId}/campaigns:mutate`, body: { operations: [{ update: { resourceName: `customers/${p.customerId}/campaigns/${p.campaignId}`, status: p.status }, updateMask: "status" }] } }), result => mutated(result) && result.results?.length === 1),
45
+ "campaigns.setStatus": sideEffect(requestOperation({ customerId, campaignId: id, status: { type: "string", required: true, enum: ["PAUSED", "ENABLED"] } },
46
+ p => ({ url: `${googleAdsApi}/customers/${p.customerId}/campaigns:mutate`, body: { operations: [{ update: { resourceName: `customers/${p.customerId}/campaigns/${p.campaignId}`, status: p.status }, updateMask: "status" }] } }), result => mutated(result) && result.results?.length === 1)),
46
47
  "conversions.createWebsite": requestOperation({ customerId, name: { type: "string", required: true, minLength: 1, maxLength: 100 } },
47
48
  p => ({ url: `${googleAdsApi}/customers/${p.customerId}/conversionActions:mutate`, body: { operations: [{ create: { name: p.name, type: "WEBPAGE", category: "SUBMIT_LEAD_FORM", status: "ENABLED", countingType: "ONE_PER_CLICK", primaryForGoal: true } }] } }), result => mutated(result) && result.results?.length === 1)
48
49
  };
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { incidentIoDefinition } from "../shared/tokens.js";
3
3
  import { jsonOperation, validatedOperation } from "./jsonOperation.js";
4
4
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  const id = { type: "string", required: true, minLength: 1, maxLength: 200,
7
8
  validator: value => /^[a-zA-Z0-9_-]+$/u.test(value) || "Use the incident.io resource ID, not a URL." };
@@ -34,10 +35,10 @@ const incidentIoProvider = Object.freeze({
34
35
  ["alerts.get", "/v2/alerts", "alert"], ["schedules.get", "/v2/schedules", "schedule"],
35
36
  ["catalog.get", "/v3/catalog_entries", "catalog_entry"]
36
37
  ].map(([name, path, key]) => [name, validatedOperation({ id }, ({ id }) => ({ method: "GET", url: address(`${path}/${id}`) }), result(key))])),
37
- "incidents.create": validatedOperation({ ...incidentFields, idempotency_key: { ...text, required: true, maxLength: 200 },
38
+ "incidents.create": sideEffect(validatedOperation({ ...incidentFields, idempotency_key: { ...text, required: true, maxLength: 200 },
38
39
  visibility: { type: "string", required: true, enum: ["public", "private"] },
39
40
  mode: { type: "string", enum: ["standard", "retrospective", "test", "tutorial"], defaultTo: "standard" }, incident_type_id: optionalId
40
- }, body => ({ method: "POST", url: address("/v2/incidents"), body }), result("incident")),
41
+ }, body => ({ method: "POST", url: address("/v2/incidents"), body }), result("incident"))),
41
42
  "incidents.update": validatedOperation({ id, incident: { type: "object", required: true, schema: createSchema(incidentFields),
42
43
  validator: value => Object.keys(value).length > 0 || "Provide at least one incident field." },
43
44
  notify_incident_channel: { type: "boolean", required: true }
@@ -3,6 +3,7 @@ import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
3
3
  import { ConnectorError } from "@jskit-ai/connectors-core/server";
4
4
  import { inngestDefinition } from "../shared/inngest.js";
5
5
  import { jsonOperation } from "./jsonOperation.js";
6
+ import { sideEffect } from "./sideEffect.js";
6
7
 
7
8
  const api = "https://api.inngest.com/v2";
8
9
  const eventEndpoint = "https://inn.gs/e/";
@@ -65,7 +66,7 @@ const inngestProvider = Object.freeze({
65
66
  },
66
67
  validateResult: validPage
67
68
  },
68
- "events.send": {
69
+ "events.send": sideEffect({
69
70
  scopes: [],
70
71
  request(input, settings) {
71
72
  const event = validateSchemaPayload({ schema: eventSchema, mode: "replace" }, input, { statusCode: 422 });
@@ -79,7 +80,7 @@ const inngestProvider = Object.freeze({
79
80
  return result?.status === 200 && !result.error && Array.isArray(result.ids) && result.ids.length === 1 &&
80
81
  result.ids.every((id) => typeof id === "string" && id.length > 0);
81
82
  }
82
- }
83
+ })
83
84
  }
84
85
  });
85
86
 
@@ -1,6 +1,7 @@
1
1
  import { ConnectorError, providerStatusError } from "@jskit-ai/connectors-core/server";
2
2
  import { linkedinDefinition } from "../shared/linkedin.js";
3
3
  import { jsonOperation } from "./jsonOperation.js";
4
+ import { sideEffect } from "./sideEffect.js";
4
5
 
5
6
  async function normalizeTokenResponse(response, { grantType }) {
6
7
  let value;
@@ -59,7 +60,7 @@ const linkedinProvider = Object.freeze({
59
60
  return { id: response.headers.get("x-restli-id") };
60
61
  },
61
62
  operations: {
62
- "posts.create": { ...publish, scopes: ["w_member_social"] },
63
+ "posts.create": sideEffect({ ...publish, scopes: ["w_member_social"] }),
63
64
  "profile.read": {
64
65
  ...jsonOperation("https://api.linkedin.com/v2/userinfo", {}, (value) =>
65
66
  typeof value?.sub === "string" && value.sub.length > 0 && value.sub.length <= 1024 &&
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
3
3
  import { mailgunDefinition } from "../shared/tokens.js";
4
4
  import { jsonOperation } from "./jsonOperation.js";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  const origins = { us: "https://api.mailgun.net", eu: "https://api.eu.mailgun.net" };
7
8
  const domainField = { type: "string", required: true, minLength: 3, maxLength: 253,
@@ -40,13 +41,13 @@ const mailgunProvider = Object.freeze({
40
41
  apiKey: { headers: (key) => ({ Authorization: `Basic ${Buffer.from(`api:${key}`).toString("base64")}` }) },
41
42
  checkOperation: "domains.list",
42
43
  operations: {
43
- "messages.send": { scopes: [], request(input, settings) {
44
+ "messages.send": sideEffect({ scopes: [], request(input, settings) {
44
45
  const { domain, to, ...fields } = validateSchemaPayload({ schema: sendSchema, mode: "replace" }, input, { statusCode: 422 });
45
46
  const body = new FormData();
46
47
  for (const [name, value] of Object.entries(fields)) body.append(name, value);
47
48
  for (const recipient of to) body.append("to", recipient);
48
49
  return { method: "POST", url: `${origins[settings.region]}/v3/${encodeURIComponent(domain)}/messages`, body };
49
- }, validateResult: result => typeof result?.id === "string" && result.id.length > 0 && typeof result.message === "string" },
50
+ }, validateResult: result => typeof result?.id === "string" && result.id.length > 0 && typeof result.message === "string" }),
50
51
  "domains.get": domainOperation("GET"),
51
52
  "domains.verify": domainOperation("PUT", "/verify"),
52
53
  "domains.create": { scopes: [], request(input, settings) {
@@ -4,6 +4,7 @@ import { ConnectorError, providerStatusError } from "@jskit-ai/connectors-core/s
4
4
  import { microsoftOutlookDefinition } from "../shared/microsoft.js";
5
5
  import { hasStringId } from "./connectorValues.js";
6
6
  import { graphRead, microsoftProvider, pageSize } from "./microsoft.js";
7
+ import { sideEffect } from "./sideEffect.js";
7
8
 
8
9
  const id = { type: "string", required: true, minLength: 1, maxLength: 2048,
9
10
  validator: value => /^[A-Za-z0-9_+=-]+$/u.test(value) || "Use the returned Outlook resource ID." };
@@ -24,16 +25,16 @@ const base = microsoftProvider(microsoftOutlookDefinition, "common", "folders.li
24
25
  "attachments.get": operation(["Mail.Read"], { messageId: id, attachmentId: id }, ({ messageId, attachmentId }) => ({ method: "GET", url: url(`/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`) }), value => hasStringId(value) && value["@odata.type"] === "#microsoft.graph.fileAttachment" && typeof value.contentBytes === "string" && value.contentBytes.length <= 6666668),
25
26
  "messages.setRead": operation(["Mail.ReadWrite"], { messageId: id, isRead: { type: "boolean", required: true } }, ({ messageId, isRead }) => ({ method: "PATCH", url: url(`/messages/${encodeURIComponent(messageId)}`), body: { isRead } })),
26
27
  "messages.move": operation(["Mail.ReadWrite"], { messageId: id, destinationId: id }, ({ messageId, destinationId }) => ({ method: "POST", url: url(`/messages/${encodeURIComponent(messageId)}/move`), body: { destinationId } })),
27
- "messages.send": operation(["Mail.Send"], {
28
+ "messages.send": sideEffect(operation(["Mail.Send"], {
28
29
  subject: { ...text, maxLength: 998 }, text,
29
30
  to: { type: "array", required: true, validator: value => value.length > 0 && value.length <= 20 && value.every(address => typeof address === "string" && address.length <= 320 && /^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/u.test(address)) || "Supply 1–20 recipient email addresses." }
30
- }, ({ subject, text, to }) => ({ method: "POST", url: url("/sendMail"), body: { message: { subject, body: { contentType: "Text", content: text }, toRecipients: to.map(address => ({ emailAddress: { address } })) }, saveToSentItems: true } }), value => value?.accepted === true),
31
+ }, ({ subject, text, to }) => ({ method: "POST", url: url("/sendMail"), body: { message: { subject, body: { contentType: "Text", content: text }, toRecipients: to.map(address => ({ emailAddress: { address } })) }, saveToSentItems: true } }), value => value?.accepted === true)),
31
32
  "calendars.list": { ...graphRead("Calendars.Read", {}, () => ({ pathname: "/me/calendars" })), scopes: ["Calendars.Read", "Calendars.ReadWrite"] },
32
33
  "events.list": { ...graphRead("Calendars.Read", { calendarId: id, pageSize }, ({ calendarId, pageSize }) => ({ pathname: `/me/calendars/${encodeURIComponent(calendarId)}/events`, query: { $top: pageSize } })), scopes: ["Calendars.Read", "Calendars.ReadWrite"] },
33
- "events.create": operation(["Calendars.ReadWrite"], { calendarId: id, subject: { ...text, maxLength: 255 }, start: instant, end: instant }, ({ calendarId, subject, start, end }) => {
34
+ "events.create": sideEffect(operation(["Calendars.ReadWrite"], { calendarId: id, subject: { ...text, maxLength: 255 }, start: instant, end: instant }, ({ calendarId, subject, start, end }) => {
34
35
  if (Date.parse(end) <= Date.parse(start)) throw new ConnectorError("connector_input_invalid", "End must follow start.", { statusCode: 422, messageCode: "connectors.microsoftOutlook.endMustFollowStart" });
35
36
  return { method: "POST", url: url(`/calendars/${encodeURIComponent(calendarId)}/events`), body: { subject, start: { dateTime: start.slice(0, -1), timeZone: "UTC" }, end: { dateTime: end.slice(0, -1), timeZone: "UTC" } } };
36
- }),
37
+ })),
37
38
  "folders.list": graphRead("Mail.Read", {
38
39
  pageSize, includeHiddenFolders: { type: "boolean", defaultTo: false }
39
40
  }, (params) => ({ pathname: "/me/mailFolders", query: {
@@ -3,6 +3,7 @@ import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
3
3
  import { microsoftTeamsDefinition } from "../shared/microsoft.js";
4
4
  import { graphRead, microsoftProvider } from "./microsoft.js";
5
5
  import { hasStringId } from "./connectorValues.js";
6
+ import { sideEffect } from "./sideEffect.js";
6
7
 
7
8
  const id = { type: "string", required: true, minLength: 1, maxLength: 1024,
8
9
  validator: value => /^[A-Za-z0-9_:@.=-]+$/u.test(value) && value !== "." && value !== ".." || "Use the returned Teams resource ID." };
@@ -21,10 +22,10 @@ const microsoftTeamsProvider = microsoftProvider(microsoftTeamsDefinition, "orga
21
22
  "channels.list": graphRead("Channel.ReadBasic.All", { teamId: id }, ({ teamId }) => ({ pathname: `/teams/${encodeURIComponent(teamId)}/channels` })),
22
23
  "messages.list": graphRead("ChannelMessage.Read.All", { ...channel, pageSize }, input => ({ pathname: `${channelPath(input)}/messages`, query: { $top: input.pageSize } })),
23
24
  "replies.list": graphRead("ChannelMessage.Read.All", { ...channel, messageId: id }, input => ({ pathname: `${channelPath(input)}/messages/${encodeURIComponent(input.messageId)}/replies` })),
24
- "messages.send": send("ChannelMessage.Send", channel, input => `${channelPath(input)}/messages`),
25
- "replies.send": send("ChannelMessage.Send", { ...channel, messageId: id }, input => `${channelPath(input)}/messages/${encodeURIComponent(input.messageId)}/replies`),
25
+ "messages.send": sideEffect(send("ChannelMessage.Send", channel, input => `${channelPath(input)}/messages`)),
26
+ "replies.send": sideEffect(send("ChannelMessage.Send", { ...channel, messageId: id }, input => `${channelPath(input)}/messages/${encodeURIComponent(input.messageId)}/replies`)),
26
27
  "chats.list": graphRead("Chat.ReadWrite", {}, () => ({ pathname: "/me/chats" })),
27
28
  "chatMessages.list": graphRead("Chat.ReadWrite", { chatId: id, pageSize }, ({ chatId, pageSize }) => ({ pathname: `/chats/${encodeURIComponent(chatId)}/messages`, query: { $top: pageSize } })),
28
- "chatMessages.send": send("Chat.ReadWrite", { chatId: id }, ({ chatId }) => `/chats/${encodeURIComponent(chatId)}/messages`)
29
+ "chatMessages.send": sideEffect(send("Chat.ReadWrite", { chatId: id }, ({ chatId }) => `/chats/${encodeURIComponent(chatId)}/messages`))
29
30
  });
30
31
  export { microsoftTeamsProvider };
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
3
3
  import { resendDefinition } from "../shared/resend.js";
4
4
  import { validatedOperation, withQuery } from "./jsonOperation.js";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  const pagination = createSchema({
7
8
  limit: { type: "integer", min: 1, max: 100, defaultTo: 20 },
@@ -63,9 +64,9 @@ const resendProvider = Object.freeze({
63
64
  "broadcasts.get": marketingOperation({ id: resourceId }, "GET", ({ id }) => `broadcasts/${id}`),
64
65
  "broadcasts.list": marketingOperation(listFields, "GET", () => "broadcasts", listResult),
65
66
  "broadcasts.update": marketingOperation({ id: resourceId, ...broadcastFields }, "PATCH", ({ id }) => `broadcasts/${id}`),
66
- "broadcasts.send": marketingOperation({ id: resourceId }, "POST", ({ id }) => `broadcasts/${id}/send`),
67
+ "broadcasts.send": sideEffect(marketingOperation({ id: resourceId }, "POST", ({ id }) => `broadcasts/${id}/send`)),
67
68
  "domains.get": marketingOperation({ id: resourceId }, "GET", ({ id }) => `domains/${id}`),
68
- "emails.send": {
69
+ "emails.send": sideEffect({
69
70
  scopes: [],
70
71
  request(input) {
71
72
  const { idempotencyKey, ...body } = validateSchemaPayload({ schema: email, mode: "replace" }, input, { statusCode: 422 });
@@ -73,7 +74,7 @@ const resendProvider = Object.freeze({
73
74
  headers: { "Idempotency-Key": idempotencyKey }, body };
74
75
  },
75
76
  validateResult: (result) => typeof result?.id === "string" && result.id.length > 0
76
- },
77
+ }),
77
78
  "domains.list": {
78
79
  scopes: [],
79
80
  request(input) {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Marks a provider operation that acts on the outside world on someone's behalf: it sends an email, SMS, push
3
+ * notification or chat message, publishes a post, books or cancels a meeting, moves money or sends an invoice, or
4
+ * triggers another system's events. A test copy (SIDE_EFFECTS is not `live`) logs a marked operation and answers
5
+ * `{ simulated: true }` instead of sending it; reads and ordinary record changes are not marked.
6
+ * @template {object} Operation
7
+ * @param {Operation} operation
8
+ * @returns {Operation & { sideEffect: true }}
9
+ */
10
+ function sideEffect(operation) {
11
+ return Object.freeze({
12
+ ...operation,
13
+ sideEffect: true
14
+ });
15
+ }
16
+
17
+ export { sideEffect };
@@ -2,6 +2,7 @@ import { createHmac, timingSafeEqual } from "node:crypto";
2
2
  import { ConnectorError } from "@jskit-ai/connectors-core/server";
3
3
  import { slackDefinition } from "../shared/slack.js";
4
4
  import { jsonOperation } from "./jsonOperation.js";
5
+ import { sideEffect } from "./sideEffect.js";
5
6
 
6
7
  function checkReply(value) {
7
8
  if (value?.ok === true) return value;
@@ -88,13 +89,13 @@ for (const [name, permission] of [["channels.history", "channels:history"], ["gr
88
89
  operations["users.info"] = { ...jsonOperation("https://slack.com/api/users.info", {
89
90
  user: { type: "string", required: true, validator: (value) => /^[UW][A-Z0-9]+$/u.test(value) || "Use a Slack user ID.", maxLength: 100 }
90
91
  }, (value) => value?.ok === true && typeof value.user?.id === "string" && typeof value.user?.name === "string"), scopes: ["users:read"] };
91
- operations["messages.send"] = { ...jsonOperation("https://slack.com/api/chat.postMessage", {
92
+ operations["messages.send"] = sideEffect({ ...jsonOperation("https://slack.com/api/chat.postMessage", {
92
93
  channel, text: { type: "string", required: true, minLength: 1, maxLength: 4000, noTrim: true },
93
94
  thread_ts: timestamp, unfurl_links: { type: "boolean", defaultTo: false },
94
95
  unfurl_media: { type: "boolean", defaultTo: false }
95
96
  }, (value) => value?.ok === true && typeof value.channel === "string" &&
96
97
  typeof value.ts === "string" && /^[0-9]+\.[0-9]+$/u.test(value.ts) &&
97
- value.message !== null && typeof value.message === "object", "POST"), scopes: ["chat:write"] };
98
+ value.message !== null && typeof value.message === "object", "POST"), scopes: ["chat:write"] });
98
99
 
99
100
  const slackProvider = Object.freeze({
100
101
  ...slackDefinition,
@@ -1,6 +1,7 @@
1
1
  import { ConnectorError, providerStatusError } from "@jskit-ai/connectors-core/server";
2
2
  import { telegramDefinition } from "../shared/tokens.js";
3
3
  import { jsonOperation } from "./jsonOperation.js";
4
+ import { sideEffect } from "./sideEffect.js";
4
5
 
5
6
  function telegramResult(response, validate) {
6
7
  if (response?.ok === false) throw providerStatusError(Number(response.error_code));
@@ -21,14 +22,14 @@ const telegramProvider = Object.freeze({
21
22
  } },
22
23
  checkOperation: "profile.read",
23
24
  operations: {
24
- "messages.send": jsonOperation("https://api.telegram.org/sendMessage", {
25
+ "messages.send": sideEffect(jsonOperation("https://api.telegram.org/sendMessage", {
25
26
  chat_id: chatIdField,
26
27
  text: { type: "string", required: true, noTrim: true, minLength: 1, maxLength: 4096 },
27
28
  message_thread_id: { type: "integer", min: 1 },
28
29
  disable_notification: { type: "boolean", defaultTo: false },
29
30
  protect_content: { type: "boolean", defaultTo: false }
30
31
  }, (response) => telegramResult(response, (message) => Number.isSafeInteger(message?.message_id) &&
31
- Number.isSafeInteger(message.chat?.id) && typeof message.text === "string"), "POST"),
32
+ Number.isSafeInteger(message.chat?.id) && typeof message.text === "string"), "POST")),
32
33
  "chats.action": jsonOperation("https://api.telegram.org/sendChatAction", {
33
34
  chat_id: chatIdField, message_thread_id: { type: "integer", min: 1 },
34
35
  action: { type: "string", required: true, enum: ["typing", "upload_photo", "record_video", "upload_video", "record_voice", "upload_voice", "upload_document", "choose_sticker", "find_location", "record_video_note", "upload_video_note"] }
@@ -4,6 +4,7 @@ import { ConnectorError } from "@jskit-ai/connectors-core/server";
4
4
  import { createSchema } from "json-rest-schema";
5
5
  import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
6
6
  import { createHmac, timingSafeEqual } from "node:crypto";
7
+ import { sideEffect } from "./sideEffect.js";
7
8
 
8
9
  const origins = {
9
10
  us1: "https://api.twilio.com", ie1: "https://api.dublin.ie1.twilio.com", au1: "https://api.sydney.au1.twilio.com"
@@ -36,20 +37,20 @@ const twilioProvider = Object.freeze({
36
37
  apiKey: { headers: (secret, settings) => ({ Authorization: `Basic ${Buffer.from(`${settings.apiKeySid}:${secret}`).toString("base64")}` }) },
37
38
  checkOperation: "calls.list",
38
39
  operations: {
39
- "messages.send": resourceOperation("Messages", "POST", {
40
+ "messages.send": sideEffect(resourceOperation("Messages", "POST", {
40
41
  To: phone, From: { ...phone, required: false }, MessagingServiceSid: { ...sid("MG"), required: false },
41
42
  Body: { type: "string", required: true, noTrim: true, minLength: 1, maxLength: 1600 }, StatusCallback: callbackUrl
42
43
  }, values => {
43
44
  if (Boolean(values.From) === Boolean(values.MessagingServiceSid)) throw new ConnectorError("connector_input_invalid", "Choose one sender number or Messaging Service SID.", { statusCode: 422, messageCode: "connectors.twilio.chooseSenderNumberMessagingService" });
44
- }),
45
+ })),
45
46
  "messages.get": resourceOperation("Messages", "GET", { resourceSid: sid("SM") }),
46
- "calls.create": resourceOperation("Calls", "POST", {
47
+ "calls.create": sideEffect(resourceOperation("Calls", "POST", {
47
48
  To: phone, From: phone, Url: callbackUrl,
48
49
  Twiml: { type: "string", noTrim: true, minLength: 1, maxLength: 4000 },
49
50
  StatusCallback: callbackUrl, Timeout: { type: "integer", min: 5, max: 600, defaultTo: 60 }
50
51
  }, values => {
51
52
  if (Boolean(values.Url) === Boolean(values.Twiml)) throw new ConnectorError("connector_input_invalid", "Supply either a call-control URL or inline TwiML.", { statusCode: 422, messageCode: "connectors.twilio.supplyEitherCallControlUrl" });
52
- }),
53
+ })),
53
54
  "calls.get": resourceOperation("Calls", "GET", { resourceSid: sid("CA") }),
54
55
  "calls.list": jsonOperation((settings) => `${origins[settings.region]}/2010-04-01/Accounts/${settings.accountSid}/Calls.json`, {
55
56
  PageSize: { type: "integer", min: 1, max: 1000, defaultTo: 50 },
@@ -3,6 +3,7 @@ import { twitchDefinition } from "../shared/twitch.js";
3
3
  import { jsonOperation } from "./jsonOperation.js";
4
4
  import { createSchema } from "json-rest-schema";
5
5
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
6
+ import { sideEffect } from "./sideEffect.js";
6
7
 
7
8
  const validationUrl = "https://id.twitch.tv/oauth2/validate";
8
9
  const userId = (value) => typeof value === "string" && /^[1-9]\d*$/u.test(value);
@@ -330,10 +331,10 @@ const twitchProvider = Object.freeze({
330
331
  }, ["channel:manage:predictions"], interactionResult, "PATCH", values => {
331
332
  if ((values.status === "RESOLVED") !== Boolean(values.winning_outcome_id)) throw new ConnectorError("connector_input_invalid", "Supply a winning outcome only when resolving the prediction.", { statusCode: 422, messageCode: "connectors.twitch.supplyWinningOutcomeResolvingPrediction" });
332
333
  }),
333
- "chat.send": helixOperation("chat/messages", { broadcaster_id: { ...idField, required: true },
334
+ "chat.send": sideEffect(helixOperation("chat/messages", { broadcaster_id: { ...idField, required: true },
334
335
  message: { type: "string", required: true, noTrim: true, minLength: 1, maxLength: 500 }, reply_parent_message_id: { ...opaqueId, required: false }
335
336
  }, ["user:write:chat"], value => Array.isArray(value?.data) && value.data.length === 1 &&
336
- typeof value.data[0]?.message_id === "string" && typeof value.data[0].is_sent === "boolean", "POST"),
337
+ typeof value.data[0]?.message_id === "string" && typeof value.data[0].is_sent === "boolean", "POST")),
337
338
  "streams.list": jsonOperation("https://api.twitch.tv/helix/streams", {
338
339
  ...pageFields, user_id: idField, game_id: idField,
339
340
  user_login: { type: "string", minLength: 1, maxLength: 25, pattern: "^[A-Za-z0-9_]+$" },