@jskit-ai/connectors-catalog 0.1.63 → 0.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +12 -17
  2. package/docs/ai.md +5 -17
  3. package/docs/amazon-redshift.md +6 -8
  4. package/docs/apollo-io.md +0 -8
  5. package/docs/ashby.md +0 -8
  6. package/docs/attention.md +0 -8
  7. package/docs/aws-athena.md +2 -2
  8. package/docs/aws-credentials.md +1 -1
  9. package/docs/aws-s3.md +1 -1
  10. package/docs/bigquery.md +2 -4
  11. package/docs/calendly.md +4 -14
  12. package/docs/chargebee.md +0 -9
  13. package/docs/clickhouse.md +1 -1
  14. package/docs/confidence-oauth.md +3 -9
  15. package/docs/contentful.md +4 -13
  16. package/docs/databricks.md +35 -3
  17. package/docs/dbt-semantic-layer.md +2 -8
  18. package/docs/figma.md +5 -5
  19. package/docs/firebase-cloud-messaging.md +3 -3
  20. package/docs/firecrawl.md +1 -1
  21. package/docs/fireflies.md +7 -10
  22. package/docs/gemini-enterprise.md +33 -3
  23. package/docs/gong.md +0 -9
  24. package/docs/google-ads.md +53 -11
  25. package/docs/google-analytics.md +2 -2
  26. package/docs/google-maps-platform.md +3 -9
  27. package/docs/granola.md +1 -1
  28. package/docs/hubspot.md +25 -0
  29. package/docs/klipy.md +0 -13
  30. package/docs/lexware.md +0 -8
  31. package/docs/lightspeed.md +32 -3
  32. package/docs/linear.md +24 -7
  33. package/docs/linkedin.md +16 -16
  34. package/docs/logo-dev.md +7 -25
  35. package/docs/mailgun.md +1 -14
  36. package/docs/mapbox.md +0 -8
  37. package/docs/microsoft-fabric.md +50 -13
  38. package/docs/microsoft-oauth.md +33 -0
  39. package/docs/microsoft-powerpoint.md +2 -13
  40. package/docs/microsoft-word.md +2 -13
  41. package/docs/miro.md +2 -2
  42. package/docs/oura.md +4 -3
  43. package/docs/polar.md +3 -5
  44. package/docs/posthog.md +2 -17
  45. package/docs/prestashop.md +5 -9
  46. package/docs/salesforce.md +41 -12
  47. package/docs/sentry.md +1 -12
  48. package/docs/sevdesk.md +2 -13
  49. package/docs/shopify.md +35 -2
  50. package/docs/slack.md +39 -14
  51. package/docs/snowflake.md +27 -2
  52. package/docs/telegram.md +0 -10
  53. package/docs/tiktok.md +19 -1
  54. package/docs/twilio.md +1 -1
  55. package/docs/twitch.md +34 -4
  56. package/docs/wave.md +36 -15
  57. package/docs/wix.md +4 -17
  58. package/docs/wiz.md +4 -4
  59. package/docs/wordpress-com.md +4 -13
  60. package/docs/workday.md +28 -9
  61. package/docs/x-twitter.md +0 -9
  62. package/docs/xero.md +39 -11
  63. package/docs/zoho-books.md +41 -10
  64. package/docs/zoho-crm.md +36 -12
  65. package/package.json +3 -3
  66. package/patterns/oauth-connection/PATTERN.md +27 -610
  67. package/patterns/paddle-catalogue/example/create-products.js +2 -1
  68. package/patterns/redshift-queries/PATTERN.md +1 -1
  69. package/src/server/attention.js +8 -11
  70. package/src/server/bigquery.js +7 -11
  71. package/src/server/brevo.js +7 -10
  72. package/src/server/calendly.js +7 -9
  73. package/src/server/chargebee.js +3 -6
  74. package/src/server/firecrawl.js +3 -3
  75. package/src/server/gatewayapi.js +4 -4
  76. package/src/server/github-api.js +1 -1
  77. package/src/server/gitlab-api.js +1 -1
  78. package/src/server/gmail.js +6 -11
  79. package/src/server/gong.js +4 -4
  80. package/src/server/google-ads-search.js +4 -5
  81. package/src/server/google-docs.js +10 -22
  82. package/src/server/google-drive.js +6 -6
  83. package/src/server/google-maps-platform.js +4 -8
  84. package/src/server/google-search-console.js +2 -2
  85. package/src/server/google-sheets.js +12 -18
  86. package/src/server/google-slides.js +10 -16
  87. package/src/server/google.js +17 -9
  88. package/src/server/jsonOperation.js +17 -18
  89. package/src/server/lexware.js +4 -9
  90. package/src/server/resend.js +8 -14
  91. package/src/server/semrush.js +70 -89
  92. package/src/server/wix.js +152 -222
  93. package/src/server/x-twitter.js +21 -18
  94. package/src/shared/ai.js +3 -1
  95. package/src/shared/definitions.js +2 -34
  96. package/src/shared/firecrawl.js +17 -0
  97. package/src/shared/gemini-enterprise.js +1 -1
  98. package/src/shared/google-ads.js +1 -1
  99. package/src/shared/google.js +2 -2
  100. package/src/shared/logo-dev.js +1 -1
  101. package/src/shared/mapbox.js +2 -2
  102. package/src/shared/mcp.js +2 -5
  103. package/src/shared/microsoft-fabric.js +1 -1
  104. package/src/shared/microsoft.js +12 -24
  105. package/src/shared/resend.js +20 -0
  106. package/src/shared/siteUrl.js +1 -1
  107. package/src/shared/tokens.js +4 -6
  108. package/src/shared/workday.js +1 -1
  109. package/test/firecrawl.test.js +1 -1
  110. package/test/github-api.test.js +2 -1
  111. package/test/gitlab-api.test.js +2 -1
  112. package/test/gong.test.js +2 -2
  113. package/test/google.test.js +20 -10
  114. package/test/setupGuides.test.js +18 -0
  115. package/test/tokens.test.js +1 -1
  116. package/test/wix.test.js +13 -0
  117. package/test/wiz.test.js +9 -3
package/src/server/wix.js CHANGED
@@ -13,6 +13,12 @@ function serializeNativeJson(value) {
13
13
  }
14
14
 
15
15
  const guid = (value) => typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/iu.test(value);
16
+ // Results are checked against the operation's own request; a different record is reported with what Wix got wrong.
17
+ const requestPath = (request, index) => decodeURIComponent(new URL(request.url).pathname.split("/").at(index));
18
+ function sameRecord(matches, message) {
19
+ if (!matches) throw new ConnectorError("connector_response_invalid", message, { statusCode: 502 });
20
+ return true;
21
+ }
16
22
  const cursor = (value) => typeof value === "string" && value.length > 0 && value.length <= 16000 && !/[\p{Cc}]/u.test(value);
17
23
  const querySchema = createSchema({
18
24
  limit: { type: "integer", min: 1, max: 100, defaultTo: 20 },
@@ -27,11 +33,10 @@ function bookingDirectoryOperation(kind) {
27
33
  const staff = kind === "staff";
28
34
  return {
29
35
  scopes: [],
30
- request(input, settings) {
36
+ request(input) {
31
37
  const cursorPaging = validateSchemaPayload({ schema: querySchema, mode: "replace" }, input, { statusCode: 422 });
32
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
33
38
  return { method: "POST", url: staff ? "https://www.wixapis.com/bookings/v1/staff-members/query" : "https://www.wixapis.com/bookings/v2/categories/query",
34
- headers: { "wix-site-id": settings.siteId }, body: {
39
+ body: {
35
40
  query: { cursorPaging, sort: [{ fieldName: "id", order: "ASC" }], ...(staff ? { filter: { serviceProvider: true } } : {}) },
36
41
  ...(staff ? { fields: ["RESOURCE_DETAILS"] } : {})
37
42
  } };
@@ -68,18 +73,18 @@ function contactOperation(action) {
68
73
  const schema = createSchema(fields);
69
74
  return {
70
75
  scopes: [],
71
- request(input, settings) {
76
+ request(input) {
72
77
  const { contactId, ...body } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
73
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the project's Wix Site ID first.", { statusCode: 422 });
74
78
  if (action !== "get" && (!Object.keys(body.info).length || (action === "create" &&
75
79
  !(body.info.name?.first || body.info.name?.last || body.info.emails?.items?.length || body.info.phones?.items?.length)))) {
76
80
  throw new ConnectorError("connector_input_invalid", "Provide contact details; creation requires a name, email or phone.", { statusCode: 422 });
77
81
  }
78
82
  return { method: action === "get" ? "GET" : action === "create" ? "POST" : "PATCH",
79
83
  url: `https://www.wixapis.com/contacts/v4/contacts${contactId ? `/${contactId}` : ""}`,
80
- headers: { "wix-site-id": settings.siteId }, ...(action === "get" ? {} : { body }) };
84
+ ...(action === "get" ? {} : { body }) };
81
85
  },
82
- validateResult: value => validContact(value?.contact)
86
+ validateResult: (value, request) => validContact(value?.contact) && (action === "create" ||
87
+ sameRecord(value.contact.id === requestPath(request, -1), "Wix returned a different contact. Check the operation outcome before retrying."))
83
88
  };
84
89
  }
85
90
  const servicePagingSchema = createSchema({ limit: { type: "integer", min: 1, max: 100, defaultTo: 20 }, offset: { type: "integer", min: 0, max: 100000, defaultTo: 0 } });
@@ -115,6 +120,14 @@ const availabilityLocationSchema = createSchema({
115
120
  locationType: { type: "string", required: true, enum: ["BUSINESS", "CUSTOM", "CUSTOMER"] },
116
121
  name: { type: "string", maxLength: 1000 }, formattedAddress: { type: "string", maxLength: 4000 }
117
122
  });
123
+ // Availability must answer for the requested service, local time window and time zone.
124
+ function requestedAvailability(value, requested, events) {
125
+ const slots = value.timeSlots ?? [value.timeSlot];
126
+ sameRecord(!(requested.timeZone && value.timeZone !== requested.timeZone || slots.some(slot => requested.serviceId && slot.serviceId !== requested.serviceId ||
127
+ requested.localStartDate && (slot.localStartDate !== requested.localStartDate || slot.localEndDate !== requested.localEndDate))),
128
+ "Wix returned availability for a different service, time or time zone.");
129
+ return !events || !requested.serviceIds || sameRecord(slots.every(slot => requested.serviceIds.includes(slot.serviceId)), "Wix returned a class slot for a different service.");
130
+ }
118
131
  function availabilityOperation(action, events = false) {
119
132
  const schema = createSchema({
120
133
  ...(!events ? {
@@ -149,9 +162,8 @@ function availabilityOperation(action, events = false) {
149
162
  });
150
163
  return {
151
164
  scopes: [],
152
- request(input, settings) {
165
+ request(input) {
153
166
  const { limit, cursor: next, ...body } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
154
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
155
167
  if (next && Object.keys(body).length) throw new ConnectorError("connector_input_invalid", "Use only cursor and limit for the next availability page.", { statusCode: 422 });
156
168
  if (body.customerChoices && !Object.keys(body.customerChoices).length) throw new ConnectorError("connector_input_invalid", "Select a duration or add-ons before supplying customer choices.", { statusCode: 422 });
157
169
  if (!next && (!body.serviceId || !body.timeZone || (action === "list" ? !body.fromLocalDate || !body.toLocalDate || body.fromLocalDate >= body.toLocalDate : body.localStartDate >= body.localEndDate))) {
@@ -161,13 +173,14 @@ function availabilityOperation(action, events = false) {
161
173
  if (locations.some(location => location.locationType === "BUSINESS" && !location.id)) throw new ConnectorError("connector_input_invalid", "Choose the business location ID.", { statusCode: 422 });
162
174
  const { serviceId, ...eventBody } = body;
163
175
  return { method: "POST", url: `https://www.wixapis.com/_api/service-availability/v2/time-slots${events ? "/event" : action === "get" ? "/get" : ""}`,
164
- headers: { "wix-site-id": settings.siteId }, body: action === "get" ? body : next ? { cursorPaging: { limit, cursor: next } } : { ...(events ? { ...eventBody, serviceIds: [serviceId], includeNonBookable: false } : { ...body, bookable: true }), cursorPaging: { limit } } };
176
+ body: action === "get" ? body : next ? { cursorPaging: { limit, cursor: next } } : { ...(events ? { ...eventBody, serviceIds: [serviceId], includeNonBookable: false } : { ...body, bookable: true }), cursorPaging: { limit } } };
165
177
  },
166
- validateResult: value => typeof value?.timeZone === "string" && (action === "get" ? validSlot(value.timeSlot) :
178
+ validateResult: (value, request) => typeof value?.timeZone === "string" && (action === "get" ? validSlot(value.timeSlot) :
167
179
  Array.isArray(value.timeSlots) && value.timeSlots.length <= 1000 && value.timeSlots.every(slot => validSlot(slot) && (!events || typeof slot.eventInfo?.eventId === "string" && slot.eventInfo.eventId.length >= 36 && slot.eventInfo.eventId.length <= 250)) &&
168
180
  (value[events ? "pagingMetadata" : "cursorPagingMetadata"] === undefined || value[events ? "pagingMetadata" : "cursorPagingMetadata"] && typeof value[events ? "pagingMetadata" : "cursorPagingMetadata"] === "object" && !Array.isArray(value[events ? "pagingMetadata" : "cursorPagingMetadata"]) &&
169
181
  (value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors === undefined || value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors && typeof value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors === "object" && !Array.isArray(value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors) &&
170
- ["next", "prev"].every(key => value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors[key] === undefined || cursor(value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors[key])))))
182
+ ["next", "prev"].every(key => value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors[key] === undefined || cursor(value[events ? "pagingMetadata" : "cursorPagingMetadata"].cursors[key]))))) &&
183
+ requestedAvailability(value, request.body, events)
171
184
  };
172
185
  }
173
186
  const eventSlotSchema = createSchema({
@@ -187,16 +200,15 @@ function productReadOperation(version, action) {
187
200
  const validProduct = value => guid(value?.id) && typeof value.name === "string" && value.name.length > 0;
188
201
  return {
189
202
  scopes: [],
190
- request(input, settings) {
203
+ request(input) {
191
204
  const value = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
192
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
193
205
  const base = version === 1 ? "https://www.wixapis.com/stores-reader/v1/products" : "https://www.wixapis.com/stores/v3/products";
194
- if (action === "get") return { method: "GET", url: `${base}/${value.productId}`, headers: { "wix-site-id": settings.siteId } };
206
+ if (action === "get") return { method: "GET", url: `${base}/${value.productId}` };
195
207
  const { includeVariants, ...paging } = value;
196
- return { method: "POST", url: `${base}/query`, headers: { "wix-site-id": settings.siteId },
208
+ return { method: "POST", url: `${base}/query`,
197
209
  body: version === 1 ? { query: { paging }, includeVariants } : { query: { cursorPaging: paging } } };
198
210
  },
199
- validateResult: value => action === "get" ? validProduct(value?.product) : Array.isArray(value?.products) && value.products.length <= 100 && value.products.every(validProduct) &&
211
+ validateResult: (value, request) => action === "get" ? validProduct(value?.product) && sameRecord(value.product.id === requestPath(request, -1), "Wix returned a different product.") : Array.isArray(value?.products) && value.products.length <= 100 && value.products.every(validProduct) &&
200
212
  (version === 1 ? (value.totalResults === undefined || Number.isSafeInteger(value.totalResults) && value.totalResults >= 0) &&
201
213
  (value.metadata === undefined || value.metadata && typeof value.metadata === "object" && !Array.isArray(value.metadata) &&
202
214
  ["items", "offset"].every(key => value.metadata[key] === undefined || Number.isSafeInteger(value.metadata[key]) && value.metadata[key] >= 0)) :
@@ -307,9 +319,8 @@ function locationWriteOperation(action) {
307
319
  });
308
320
  return {
309
321
  scopes: [],
310
- request(input, settings) {
322
+ request(input) {
311
323
  const { locationId, ...location } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
312
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
313
324
  if (!Object.keys(location.address).length) throw new ConnectorError("connector_input_invalid", "Provide the location address.", { statusCode: 422 });
314
325
  if (location.businessSchedule && (["periods", "specialHourPeriod"].some(key => location.businessSchedule[key] !== undefined &&
315
326
  (!Array.isArray(location.businessSchedule[key]) || location.businessSchedule[key].length > 100)) ||
@@ -317,22 +328,23 @@ function locationWriteOperation(action) {
317
328
  throw new ConnectorError("connector_input_invalid", "Use native businessSchedule periods and specialHourPeriod arrays with at most 100 entries each.", { statusCode: 422 });
318
329
  }
319
330
  return { method: action === "create" ? "POST" : "PUT", url: `https://www.wixapis.com/locations/v1/locations${locationId ? `/${locationId}` : ""}`,
320
- headers: { "wix-site-id": settings.siteId }, body: { location: { ...(locationId ? { id: locationId } : {}), ...location } } };
331
+ body: { location: { ...(locationId ? { id: locationId } : {}), ...location } } };
321
332
  },
322
- validateResult: value => validLocation(value?.location) && typeof value.location.revision === "string" && /^\d{1,19}$/u.test(value.location.revision)
333
+ validateResult: (value, request) => validLocation(value?.location) && typeof value.location.revision === "string" && /^\d{1,19}$/u.test(value.location.revision) &&
334
+ (action === "create" || sameRecord(value.location.id === requestPath(request, -1), "Wix returned a different business location."))
323
335
  };
324
336
  }
325
337
  function locationActionOperation(action) {
326
338
  const schema = createSchema({ locationId: contactIdField });
327
339
  return {
328
340
  scopes: [],
329
- request(input, settings) {
341
+ request(input) {
330
342
  const { locationId } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
331
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
332
343
  return { method: "POST", url: `https://www.wixapis.com/locations/v1/locations/${locationId}/${action}`,
333
- headers: { "wix-site-id": settings.siteId }, body: {} };
344
+ body: {} };
334
345
  },
335
- validateResult: value => validLocation(value?.location) && (action === "archive" ? value.location.archived === true : value.location.default === true)
346
+ validateResult: (value, request) => validLocation(value?.location) && sameRecord(value.location.id === requestPath(request, -2), "Wix returned a different business location.") &&
347
+ (action === "archive" ? value.location.archived === true : value.location.default === true)
336
348
  };
337
349
  }
338
350
  const locationQuerySchema = createSchema({
@@ -453,15 +465,16 @@ function bookingConfirmationOperation(action) {
453
465
  });
454
466
  return {
455
467
  scopes: [],
456
- request(input, settings) {
468
+ request(input) {
457
469
  const { bookingId, paymentStatus, revision, notifyParticipants, message } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
458
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
459
470
  if (message !== undefined && !notifyParticipants) throw new ConnectorError("connector_input_invalid", "Enable participant notification before supplying a message.", { statusCode: 422 });
460
471
  return { method: "POST", url: automatic ? `https://www.wixapis.com/bookings/v2/confirmation/${bookingId}:confirmOrDecline` :
461
- `https://www.wixapis.com/_api/bookings-service/v2/bookings/${bookingId}/${action}`, headers: { "wix-site-id": settings.siteId },
472
+ `https://www.wixapis.com/_api/bookings-service/v2/bookings/${bookingId}/${action}`,
462
473
  body: automatic ? { paymentStatus } : { revision, participantNotification: { notifyParticipants, ...(message === undefined ? {} : { message }) } } };
463
474
  },
464
- validateResult: value => guid(value?.booking?.id) && typeof value.booking.revision === "string" && /^\d{1,19}$/u.test(value.booking.revision) &&
475
+ validateResult: (value, request) => guid(value?.booking?.id) &&
476
+ sameRecord(value.booking.id === (automatic ? requestPath(request, -1).split(":")[0] : requestPath(request, -2)), "Wix returned a different booking. Check the operation outcome before retrying.") &&
477
+ typeof value.booking.revision === "string" && /^\d{1,19}$/u.test(value.booking.revision) &&
465
478
  BigInt(value.booking.revision) <= 9223372036854775807n && (automatic ? ["CONFIRMED", "PENDING", "DECLINED"].includes(value.booking.status) : value.booking.status === (action === "confirm" ? "CONFIRMED" : "DECLINED"))
466
479
  };
467
480
  }
@@ -485,9 +498,8 @@ function fulfillmentWriteOperation(update) {
485
498
  });
486
499
  return {
487
500
  scopes: [],
488
- request(input, settings) {
501
+ request(input) {
489
502
  const { orderId, fulfillmentId, ...fulfillment } = validateSchemaPayload({ schema, mode: "replace" }, input, { statusCode: 422 });
490
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
491
503
  if (!Object.keys(fulfillment).length || fulfillment.trackingInfo && !Object.keys(fulfillment.trackingInfo).length) {
492
504
  throw new ConnectorError("connector_input_invalid", "Supply the fulfillment properties to write.", { statusCode: 422 });
493
505
  }
@@ -499,103 +511,34 @@ function fulfillmentWriteOperation(update) {
499
511
  return { method: update ? "PATCH" : "POST", url: update
500
512
  ? `https://www.wixapis.com/ecom/v1/fulfillments/${fulfillmentId}/orders/${encodeURIComponent(orderId)}`
501
513
  : `https://www.wixapis.com/ecom/v1/fulfillments/orders/${encodeURIComponent(orderId)}/create-fulfillment`,
502
- headers: { "wix-site-id": settings.siteId }, body: { fulfillment } };
514
+ body: { fulfillment } };
503
515
  },
504
- validateResult: value => typeof value?.orderWithFulfillments?.orderId === "string" && Array.isArray(value.orderWithFulfillments.fulfillments) &&
516
+ validateResult: (value, request) => typeof value?.orderWithFulfillments?.orderId === "string" &&
517
+ sameRecord(value.orderWithFulfillments.orderId === requestPath(request, update ? -1 : -2), "Wix returned fulfillments for a different order.") &&
518
+ Array.isArray(value.orderWithFulfillments.fulfillments) &&
505
519
  value.orderWithFulfillments.fulfillments.every(item => guid(item?.id) && Array.isArray(item.lineItems) && item.lineItems.length <= 300 &&
506
520
  item.lineItems.every(line => guid(line?.id) && Number.isInteger(line.quantity) && line.quantity >= 1 && line.quantity <= 100000)) &&
507
- (update || guid(value.fulfillmentId) && value.orderWithFulfillments.fulfillments.some(item => item.id === value.fulfillmentId))
521
+ (update ? sameRecord(value.orderWithFulfillments.fulfillments.some(item => item.id === requestPath(request, -3)),
522
+ "Wix did not return the updated fulfillment. Inspect the order before retrying.") :
523
+ guid(value.fulfillmentId) && value.orderWithFulfillments.fulfillments.some(item => item.id === value.fulfillmentId))
508
524
  };
509
525
  }
510
526
  const wixRuntime = {
511
527
  ...wixDefinition, apiOrigins: ["https://www.wixapis.com"],
512
528
  apiKey: { headers: (key, settings) => ({ Authorization: key, "wix-account-id": settings.accountId }) },
513
529
  checkOperation: "sites.list",
530
+ // Site-scoped calls authenticate by site, so the account header is dropped when a site is addressed.
514
531
  async exchange(address, options, { request }) {
515
532
  const headers = { ...options.headers };
516
533
  if (headers["wix-site-id"]) delete headers["wix-account-id"];
517
- const result = await request(address, { ...options, headers });
518
- const contactMatch = /\/contacts\/v4\/contacts\/([a-f0-9-]{36})$/iu.exec(new URL(address).pathname);
519
- if (contactMatch && result?.contact?.id !== contactMatch[1]) {
520
- throw new ConnectorError("connector_response_invalid", "Wix returned a different contact. Check the operation outcome before retrying.", { statusCode: 502 });
521
- }
522
- const serviceMatch = /\/_api\/bookings\/v2\/services\/([a-f0-9-]{36})(?:\/locations)?$/iu.exec(new URL(address).pathname);
523
- if (serviceMatch && result?.service?.id !== serviceMatch[1]) {
524
- throw new ConnectorError("connector_response_invalid", "Wix returned a different booking service. Check the outcome before retrying.", { statusCode: 502 });
525
- }
526
- const bookingMatch = /\/_api\/bookings-service\/v2\/bookings\/([a-f0-9-]{36})\/(?:cancel|confirm|decline|reschedule)$/iu.exec(new URL(address).pathname) ??
527
- /^\/bookings\/v2\/confirmation\/([a-f0-9-]{36}):confirmOrDecline$/iu.exec(new URL(address).pathname);
528
- const variantsMatch = /^\/bookings\/v1\/serviceOptionsAndVariants\/service_id\/([a-f0-9-]{36})$/iu.exec(new URL(address).pathname);
529
- if (variantsMatch && result?.serviceVariants?.serviceId !== variantsMatch[1]) {
530
- throw new ConnectorError("connector_response_invalid", "Wix returned variants for a different service.", { statusCode: 502 });
531
- }
532
- if (bookingMatch && result?.booking?.id !== bookingMatch[1]) {
533
- throw new ConnectorError("connector_response_invalid", "Wix returned a different booking. Check the operation outcome before retrying.", { statusCode: 502 });
534
- }
535
- if (new URL(address).pathname === "/_api/bookings-reader/v2/extended-bookings/query") {
536
- const id = options.body?.query?.filter?.id;
537
- if (id && Array.isArray(result?.extendedBookings) && (result.extendedBookings.length > 1 || result.extendedBookings.some(value => value?.booking?.id !== id))) {
538
- throw new ConnectorError("connector_response_invalid", "Wix returned an unexpected booking for the requested ID.", { statusCode: 502 });
539
- }
540
- }
541
- if (new URL(address).pathname.startsWith("/_api/service-availability/v2/time-slots")) {
542
- const requested = options.body;
543
- const slots = result?.timeSlots ?? (result?.timeSlot ? [result.timeSlot] : []);
544
- if (Array.isArray(slots) && (requested?.timeZone && result?.timeZone !== requested.timeZone || slots.some(slot =>
545
- requested?.serviceId && slot?.serviceId !== requested.serviceId || requested?.localStartDate && (slot?.localStartDate !== requested.localStartDate || slot?.localEndDate !== requested.localEndDate)))) {
546
- throw new ConnectorError("connector_response_invalid", "Wix returned availability for a different service, time or time zone.", { statusCode: 502 });
547
- }
548
- }
549
- const formMatch = /\/form-schema-service\/v4\/forms\/([a-f0-9-]{36})\/summary$/iu.exec(new URL(address).pathname);
550
- if (formMatch && result?.formSummary?.id !== formMatch[1]) {
551
- throw new ConnectorError("connector_response_invalid", "Wix returned a different form summary.", { statusCode: 502 });
552
- }
553
- const eventMatch = /\/_api\/service-availability\/v2\/time-slots\/event\/(.+)$/u.exec(new URL(address).pathname);
554
- if (eventMatch && (result?.timeSlot?.eventInfo?.eventId !== decodeURIComponent(eventMatch[1]) || result?.timeZone !== new URL(address).searchParams.get("timeZone"))) {
555
- throw new ConnectorError("connector_response_invalid", "Wix returned a different event slot or time zone.", { statusCode: 502 });
556
- }
557
- if (new URL(address).pathname === "/_api/service-availability/v2/time-slots/event" && options.body?.serviceIds && Array.isArray(result?.timeSlots) &&
558
- result.timeSlots.some(slot => !options.body.serviceIds.includes(slot?.serviceId))) {
559
- throw new ConnectorError("connector_response_invalid", "Wix returned a class slot for a different service.", { statusCode: 502 });
560
- }
561
- const orderMatch = /\/ecom\/v1\/orders\/([^/]+)$/u.exec(new URL(address).pathname);
562
- if (options.method === "GET" && orderMatch && result?.order?.id !== decodeURIComponent(orderMatch[1])) {
563
- throw new ConnectorError("connector_response_invalid", "Wix returned a different order.", { statusCode: 502 });
564
- }
565
- const fulfillmentOrderMatch = /\/ecom\/v1\/fulfillments(?:\/[a-f0-9-]{36})?\/orders\/([^/]+)(?:\/create-fulfillment)?$/iu.exec(new URL(address).pathname);
566
- if (fulfillmentOrderMatch && result?.orderWithFulfillments?.orderId !== decodeURIComponent(fulfillmentOrderMatch[1])) {
567
- throw new ConnectorError("connector_response_invalid", "Wix returned fulfillments for a different order.", { statusCode: 502 });
568
- }
569
- const updatedFulfillmentMatch = /^\/ecom\/v1\/fulfillments\/([a-f0-9-]{36})\/orders\//iu.exec(new URL(address).pathname);
570
- if (options.method === "PATCH" && updatedFulfillmentMatch &&
571
- (!Array.isArray(result?.orderWithFulfillments?.fulfillments) || !result.orderWithFulfillments.fulfillments.some(item => item?.id === updatedFulfillmentMatch[1]))) {
572
- throw new ConnectorError("connector_response_invalid", "Wix did not return the updated fulfillment. Inspect the order before retrying.", { statusCode: 502 });
573
- }
574
- const productMatch = /\/(?:stores-reader\/v1|stores\/v1|stores\/v3)\/products\/([a-f0-9-]{36})$/iu.exec(new URL(address).pathname);
575
- if (productMatch && result?.product?.id !== productMatch[1]) {
576
- throw new ConnectorError("connector_response_invalid", "Wix returned a different product.", { statusCode: 502 });
577
- }
578
- const locationMatch = /\/locations\/v1\/locations\/([a-f0-9-]{36})(?:\/(?:archive|set-default))?$/iu.exec(new URL(address).pathname);
579
- if (locationMatch && result?.location?.id !== locationMatch[1]) throw new ConnectorError("connector_response_invalid", "Wix returned a different business location.", { statusCode: 502 });
580
- const collectionMatch = /^\/wix-data\/v2\/collections\/(.+)$/u.exec(new URL(address).pathname);
581
- if (collectionMatch && result?.collection?.id !== decodeURIComponent(collectionMatch[1])) throw new ConnectorError("connector_response_invalid", "Wix returned a different CMS collection.", { statusCode: 502 });
582
- if (new URL(address).pathname === "/wix-data/v2/items/query" && Array.isArray(result?.dataItems) &&
583
- result.dataItems.some(item => item?.dataCollectionId !== options.body.dataCollectionId)) throw new ConnectorError("connector_response_invalid", "Wix returned items from a different CMS collection.", { statusCode: 502 });
584
- const itemMatch = /^\/wix-data\/v2\/items\/([^/]+)$/u.exec(new URL(address).pathname);
585
- if (itemMatch && ["GET", "PATCH"].includes(options.method) &&
586
- (result?.dataItem?.id !== decodeURIComponent(itemMatch[1]) || result?.dataItem?.dataCollectionId !==
587
- (options.method === "GET" ? new URL(address).searchParams.get("dataCollectionId") : options.body.dataCollectionId))) {
588
- throw new ConnectorError("connector_response_invalid", "Wix returned a different CMS item or collection. Check write outcomes before retrying.", { statusCode: 502 });
589
- }
590
- return result;
534
+ return request(address, { ...options, headers });
591
535
  },
592
536
  operations: {
593
537
  "carts.create": {
594
538
  scopes: [],
595
- request(input, settings) {
539
+ request(input) {
596
540
  const { note, catalogItems } = validateSchemaPayload({ schema: cartCreateSchema, mode: "replace" }, input, { statusCode: 422 });
597
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
598
- return { method: "POST", url: "https://www.wixapis.com/ecom/v2/carts", headers: { "wix-site-id": settings.siteId },
541
+ return { method: "POST", url: "https://www.wixapis.com/ecom/v2/carts",
599
542
  body: { cart: { source: { channelType: "WEB" }, ...(note === undefined ? {} : { note }) }, catalogItems } };
600
543
  },
601
544
  validateResult: value => guid(value?.cart?.id) && Array.isArray(value.cart.lineItems) && value.cart.lineItems.length <= 300 &&
@@ -603,10 +546,9 @@ const wixRuntime = {
603
546
  },
604
547
  "carts.getCheckoutUrl": {
605
548
  scopes: [],
606
- request(input, settings) {
549
+ request(input) {
607
550
  const { cartId } = validateSchemaPayload({ schema: cartIdSchema, mode: "replace" }, input, { statusCode: 422 });
608
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
609
- return { method: "POST", url: `https://www.wixapis.com/ecom/v2/carts/${cartId}/get-checkout-url`, headers: { "wix-site-id": settings.siteId }, body: {} };
551
+ return { method: "POST", url: `https://www.wixapis.com/ecom/v2/carts/${cartId}/get-checkout-url`, body: {} };
610
552
  },
611
553
  validateResult(value) {
612
554
  if (typeof value?.checkoutUrl !== "string" || value.checkoutUrl.length > 8000 || /[\p{Cc}]/u.test(value.checkoutUrl)) return false;
@@ -615,9 +557,8 @@ const wixRuntime = {
615
557
  },
616
558
  "bookings.reschedule": {
617
559
  scopes: [],
618
- request(input, settings) {
560
+ request(input) {
619
561
  const { bookingId, revision, slot, notifyParticipants, message } = validateSchemaPayload({ schema: bookingRescheduleSchema, mode: "replace" }, input, { statusCode: 422 });
620
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
621
562
  if (message !== undefined && !notifyParticipants) throw new ConnectorError("connector_input_invalid", "Enable participant notification before supplying a message.", { statusCode: 422 });
622
563
  if (slot.eventId !== undefined) {
623
564
  if (Object.keys(slot).length !== 1 || typeof slot.eventId !== "string" || slot.eventId.length < 36 || slot.eventId.length > 250 || /[\p{Cc}]/u.test(slot.eventId)) {
@@ -630,10 +571,10 @@ const wixRuntime = {
630
571
  throw new ConnectorError("connector_input_invalid", "For an appointment, supply its service/schedule IDs, increasing local slot dates and IANA timezone. Courses cannot be rescheduled.", { statusCode: 422 });
631
572
  }
632
573
  }
633
- return { method: "POST", url: `https://www.wixapis.com/_api/bookings-service/v2/bookings/${bookingId}/reschedule`, headers: { "wix-site-id": settings.siteId },
574
+ return { method: "POST", url: `https://www.wixapis.com/_api/bookings-service/v2/bookings/${bookingId}/reschedule`,
634
575
  body: { revision, slot, participantNotification: { notifyParticipants, ...(message === undefined ? {} : { message }) } } };
635
576
  },
636
- validateResult: value => guid(value?.booking?.id) && typeof value.booking.revision === "string" && /^\d{1,19}$/u.test(value.booking.revision) &&
577
+ validateResult: (value, request) => guid(value?.booking?.id) && sameRecord(value.booking.id === requestPath(request, -2), "Wix returned a different booking. Check the operation outcome before retrying.") && typeof value.booking.revision === "string" && /^\d{1,19}$/u.test(value.booking.revision) &&
637
578
  BigInt(value.booking.revision) <= 9223372036854775807n && typeof value.booking.status === "string" && value.booking.status.length > 0
638
579
  },
639
580
  "bookings.confirm": bookingConfirmationOperation("confirm"),
@@ -641,11 +582,10 @@ const wixRuntime = {
641
582
  "bookings.confirmOrDecline": bookingConfirmationOperation("confirmOrDecline"),
642
583
  "bookingServices.listAddOnGroups": {
643
584
  scopes: [],
644
- request(input, settings) {
585
+ request(input) {
645
586
  const value = validateSchemaPayload({ schema: serviceIdSchema, mode: "replace" }, input, { statusCode: 422 });
646
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
647
587
  return { method: "POST", url: "https://www.wixapis.com/_api/bookings/v2/services/add-on-groups/list-add-on-groups-by-service-id",
648
- headers: { "wix-site-id": settings.siteId }, body: value };
588
+ body: value };
649
589
  },
650
590
  validateResult: value => Array.isArray(value?.addOnGroupsDetails) && value.addOnGroupsDetails.length <= 3 &&
651
591
  value.addOnGroupsDetails.every(group => guid(group?.groupId) && typeof group.groupName === "string" &&
@@ -654,14 +594,13 @@ const wixRuntime = {
654
594
  },
655
595
  "bookingServices.getVariants": {
656
596
  scopes: [],
657
- request(input, settings) {
597
+ request(input) {
658
598
  const { serviceId } = validateSchemaPayload({ schema: serviceIdSchema, mode: "replace" }, input, { statusCode: 422 });
659
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
660
- return { method: "GET", url: `https://www.wixapis.com/bookings/v1/serviceOptionsAndVariants/service_id/${serviceId}`, headers: { "wix-site-id": settings.siteId } };
599
+ return { method: "GET", url: `https://www.wixapis.com/bookings/v1/serviceOptionsAndVariants/service_id/${serviceId}` };
661
600
  },
662
- validateResult(value) {
601
+ validateResult(value, request) {
663
602
  const variants = value?.serviceVariants;
664
- return guid(variants?.id) && guid(variants.serviceId) &&
603
+ return guid(variants?.id) && guid(variants.serviceId) && sameRecord(variants.serviceId === requestPath(request, -1), "Wix returned variants for a different service.") &&
665
604
  Array.isArray(variants.options?.values) && variants.options.values.every(option => guid(option?.id) && typeof option.type === "string") &&
666
605
  Array.isArray(variants.variants?.values) && variants.variants.values.every(variant =>
667
606
  Array.isArray(variant?.choices) && variant.choices.every(choice => guid(choice?.optionId)));
@@ -671,9 +610,8 @@ const wixRuntime = {
671
610
  "bookingStaff.list": bookingDirectoryOperation("staff"),
672
611
  "bookingServices.setLocations": {
673
612
  scopes: [],
674
- request(input, settings) {
613
+ request(input) {
675
614
  const { serviceId, locations, removedLocationAction: action, moveToLocation, notifyParticipants, notificationMessage } = validateSchemaPayload({ schema: setServiceLocationsSchema, mode: "replace" }, input, { statusCode: 422 });
676
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
677
615
  if ((action === "MOVE_TO_LOCATION") !== (moveToLocation !== undefined)) throw new ConnectorError("connector_input_invalid", "Provide a destination only when moving future sessions.", { statusCode: 422 });
678
616
  if (notificationMessage !== undefined && !notifyParticipants) throw new ConnectorError("connector_input_invalid", "Enable participant notification before supplying a message.", { statusCode: 422 });
679
617
  for (const location of [...locations, ...(moveToLocation ? [moveToLocation] : [])]) {
@@ -683,19 +621,18 @@ const wixRuntime = {
683
621
  throw new ConnectorError("connector_input_invalid", "Supply the details matching each service location type.", { statusCode: 422 });
684
622
  }
685
623
  }
686
- return { method: "POST", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}/locations`, headers: { "wix-site-id": settings.siteId }, body: {
624
+ return { method: "POST", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}/locations`, body: {
687
625
  locations, removedLocationSessionsAction: { action, ...(moveToLocation ? { moveToLocationOptions: { newLocation: moveToLocation } } : {}) },
688
626
  participantNotification: { notifyParticipants, ...(notificationMessage !== undefined ? { message: notificationMessage } : {}) }
689
627
  } };
690
628
  },
691
- validateResult: value => validService(value?.service)
629
+ validateResult: (value, request) => validService(value?.service) && sameRecord(value.service.id === requestPath(request, -2), "Wix returned a different booking service. Check the outcome before retrying.")
692
630
  },
693
631
  "bookingServices.create": {
694
632
  scopes: [],
695
- request(input, settings) {
633
+ request(input) {
696
634
  const { service } = validateSchemaPayload({ schema: serviceCreateSchema, mode: "replace" }, input, { statusCode: 422 });
697
635
  const invalid = message => { throw new ConnectorError("connector_input_invalid", message, { statusCode: 422 }); };
698
- if (!guid(settings.siteId)) invalid("Configure the Wix Site ID first.");
699
636
  if (!["APPOINTMENT", "CLASS", "COURSE"].includes(service.type) || typeof service.name !== "string" || !service.name.trim() || service.name.length > 400) invalid("Provide a service type and name of up to 400 characters.");
700
637
  if (["id", "revision", "createdByAppId", "createdDate", "updatedDate", "addOnGroups"].some(key => Object.hasOwn(service, key))) invalid("Do not send generated service identity fields or existing add-on groups when creating a service.");
701
638
  if (!Number.isInteger(service.defaultCapacity) || service.defaultCapacity < 1 || service.defaultCapacity > 1000 || service.type === "APPOINTMENT" && service.defaultCapacity !== 1) invalid("Set appointment capacity to 1, or class/course capacity from 1 to 1000.");
@@ -718,67 +655,66 @@ const wixRuntime = {
718
655
  if (!Array.isArray(service.staffMemberIds) || !service.staffMemberIds.length || !service.staffMemberIds.every(guid)) invalid("Select at least one staff resource ID for the appointment service.");
719
656
  if (!Array.isArray(durations) || !durations.length || !durations.every(value => Number.isInteger(value) && value > 0)) invalid("Provide appointment session durations in minutes.");
720
657
  } else if (durations !== undefined) invalid("Class/course session durations belong to their sessions, not service availability constraints.");
721
- return { method: "POST", url: "https://www.wixapis.com/_api/bookings/v2/services", headers: { "wix-site-id": settings.siteId }, body: { service } };
658
+ return { method: "POST", url: "https://www.wixapis.com/_api/bookings/v2/services", body: { service } };
722
659
  },
723
660
  validateResult: value => validService(value?.service)
724
661
  },
725
662
  "cmsItems.get": {
726
663
  scopes: [],
727
- request(input, settings) {
664
+ request(input) {
728
665
  const { collectionId: dataCollectionId, itemId, consistentRead } = validateSchemaPayload({ schema: cmsItemGetSchema, mode: "replace" }, input, { statusCode: 422 });
729
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
730
666
  const url = new URL(`https://www.wixapis.com/wix-data/v2/items/${encodeURIComponent(itemId)}`);
731
667
  url.searchParams.set("dataCollectionId", dataCollectionId); url.searchParams.set("consistentRead", String(consistentRead));
732
- return { method: "GET", url: url.href, headers: { "wix-site-id": settings.siteId } };
668
+ return { method: "GET", url: url.href };
733
669
  },
734
- validateResult: value => value?.dataItem?.data && typeof value.dataItem.data === "object" && !Array.isArray(value.dataItem.data)
670
+ validateResult: (value, request) => value?.dataItem?.data && typeof value.dataItem.data === "object" && !Array.isArray(value.dataItem.data) &&
671
+ sameRecord(value.dataItem.id === requestPath(request, -1) && value.dataItem.dataCollectionId === new URL(request.url).searchParams.get("dataCollectionId"), "Wix returned a different CMS item or collection. Check write outcomes before retrying.")
735
672
  },
736
673
  "cmsItems.patch": {
737
674
  scopes: [],
738
- request(input, settings) {
675
+ request(input) {
739
676
  const { collectionId: dataCollectionId, itemId, fieldModifications, conditionFilter } = validateSchemaPayload({ schema: cmsItemPatchSchema, mode: "replace" }, input, { statusCode: 422 });
740
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
741
- return { method: "PATCH", url: `https://www.wixapis.com/wix-data/v2/items/${encodeURIComponent(itemId)}`, headers: { "wix-site-id": settings.siteId },
677
+ return { method: "PATCH", url: `https://www.wixapis.com/wix-data/v2/items/${encodeURIComponent(itemId)}`,
742
678
  body: { dataCollectionId, patch: { dataItemId: itemId, fieldModifications }, ...(conditionFilter !== undefined ? { condition: { filter: conditionFilter } } : {}) } };
743
679
  },
744
- validateResult: value => value?.dataItem?.data && typeof value.dataItem.data === "object" && !Array.isArray(value.dataItem.data)
680
+ validateResult: (value, request) => value?.dataItem?.data && typeof value.dataItem.data === "object" && !Array.isArray(value.dataItem.data) &&
681
+ sameRecord(value.dataItem.id === requestPath(request, -1) && value.dataItem.dataCollectionId === request.body.dataCollectionId, "Wix returned a different CMS item or collection. Check write outcomes before retrying.")
745
682
  },
746
683
  "cmsItems.list": {
747
684
  scopes: [],
748
- request(input, settings) {
685
+ request(input) {
749
686
  const { collectionId: dataCollectionId, consistentRead, filter, sort, fields, returnTotalCount, includeReferences, ...paging } = validateSchemaPayload({ schema: cmsItemQuerySchema, mode: "replace" }, input, { statusCode: 422 });
750
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
751
- return { method: "POST", url: "https://www.wixapis.com/wix-data/v2/items/query", headers: { "wix-site-id": settings.siteId },
687
+ return { method: "POST", url: "https://www.wixapis.com/wix-data/v2/items/query",
752
688
  body: { dataCollectionId, consistentRead,
753
689
  ...(returnTotalCount !== undefined ? { returnTotalCount } : {}), ...(includeReferences !== undefined ? { includeReferences } : {}),
754
690
  query: { paging, ...(filter !== undefined ? { filter } : {}), ...(sort !== undefined ? { sort } : {}), ...(fields !== undefined ? { fields } : {}) } } };
755
691
  },
756
- validateResult: value => Array.isArray(value?.dataItems) && value.dataItems.length <= 100 && value.dataItems.every(item =>
692
+ validateResult: (value, request) => Array.isArray(value?.dataItems) && value.dataItems.length <= 100 && value.dataItems.every(item =>
757
693
  typeof item?.id === "string" && item.id.length > 0 && collectionId(item.dataCollectionId) && item.data && typeof item.data === "object" && !Array.isArray(item.data)) &&
758
- (value.pagingMetadata === undefined || value.pagingMetadata && typeof value.pagingMetadata === "object" && !Array.isArray(value.pagingMetadata))
694
+ (value.pagingMetadata === undefined || value.pagingMetadata && typeof value.pagingMetadata === "object" && !Array.isArray(value.pagingMetadata)) &&
695
+ sameRecord(value.dataItems.every(item => item.dataCollectionId === request.body.dataCollectionId), "Wix returned items from a different CMS collection.")
759
696
  },
760
697
  "cmsCollections.list": {
761
698
  scopes: [],
762
- request(input, settings) {
699
+ request(input) {
763
700
  const value = validateSchemaPayload({ schema: collectionListSchema, mode: "replace" }, input, { statusCode: 422 });
764
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
765
701
  const url = new URL("https://www.wixapis.com/wix-data/v2/collections");
766
702
  url.searchParams.set("paging.limit", String(value.limit)); url.searchParams.set("paging.offset", String(value.offset));
767
703
  url.searchParams.set("consistentRead", String(value.consistentRead));
768
- return { method: "GET", url: url.href, headers: { "wix-site-id": settings.siteId } };
704
+ return { method: "GET", url: url.href };
769
705
  },
770
706
  validateResult: value => Array.isArray(value?.collections) && value.collections.length <= 100 && value.collections.every(validCollection) &&
771
707
  (value.pagingMetadata === undefined || value.pagingMetadata && typeof value.pagingMetadata === "object" && !Array.isArray(value.pagingMetadata))
772
708
  },
773
709
  "cmsCollections.get": {
774
710
  scopes: [],
775
- request(input, settings) {
711
+ request(input) {
776
712
  const value = validateSchemaPayload({ schema: collectionGetSchema, mode: "replace" }, input, { statusCode: 422 });
777
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
778
713
  const id = value.collectionId.split("/").map(encodeURIComponent).join("/");
779
- return { method: "GET", url: `https://www.wixapis.com/wix-data/v2/collections/${id}?consistentRead=${value.consistentRead}`, headers: { "wix-site-id": settings.siteId } };
714
+ return { method: "GET", url: `https://www.wixapis.com/wix-data/v2/collections/${id}?consistentRead=${value.consistentRead}` };
780
715
  },
781
- validateResult: value => validCollection(value?.collection)
716
+ validateResult: (value, request) => validCollection(value?.collection) &&
717
+ sameRecord(value.collection.id === new URL(request.url).pathname.split("/").slice(4).map(decodeURIComponent).join("/"), "Wix returned a different CMS collection.")
782
718
  },
783
719
  "locations.archive": locationActionOperation("archive"),
784
720
  "locations.setDefault": locationActionOperation("set-default"),
@@ -786,10 +722,9 @@ const wixRuntime = {
786
722
  "locations.update": locationWriteOperation("update"),
787
723
  "locations.list": {
788
724
  scopes: [],
789
- request(input, settings) {
725
+ request(input) {
790
726
  const { archived, ...paging } = validateSchemaPayload({ schema: locationQuerySchema, mode: "replace" }, input, { statusCode: 422 });
791
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
792
- return { method: "POST", url: "https://www.wixapis.com/locations/v1/locations/query", headers: { "wix-site-id": settings.siteId },
727
+ return { method: "POST", url: "https://www.wixapis.com/locations/v1/locations/query",
793
728
  body: { query: { filter: { archived }, paging }, filterAuthorizedLocationEntities: true } };
794
729
  },
795
730
  validateResult: value => Array.isArray(value?.locations) && value.locations.length <= 100 && value.locations.every(validLocation) &&
@@ -798,56 +733,53 @@ const wixRuntime = {
798
733
  },
799
734
  "locations.get": {
800
735
  scopes: [],
801
- request(input, settings) {
736
+ request(input) {
802
737
  const { locationId } = validateSchemaPayload({ schema: locationGetSchema, mode: "replace" }, input, { statusCode: 422 });
803
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
804
- return { method: "GET", url: `https://www.wixapis.com/locations/v1/locations/${locationId}`, headers: { "wix-site-id": settings.siteId } };
738
+ return { method: "GET", url: `https://www.wixapis.com/locations/v1/locations/${locationId}` };
805
739
  },
806
- validateResult: value => validLocation(value?.location)
740
+ validateResult: (value, request) => validLocation(value?.location) && sameRecord(value.location.id === requestPath(request, -1), "Wix returned a different business location.")
807
741
  },
808
742
  "productsV1.list": productReadOperation(1, "list"),
809
743
  "productsV1.get": productReadOperation(1, "get"),
810
744
  "productsV1.update": {
811
745
  scopes: [],
812
- request(input, settings) {
746
+ request(input) {
813
747
  const { productId, price, ...changes } = validateSchemaPayload({ schema: productV1UpdateSchema, mode: "replace" }, input, { statusCode: 422 });
814
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
815
748
  if (!Object.keys(changes).length && price === undefined) throw new ConnectorError("connector_input_invalid", "Provide a product name, visibility or base-price change.", { statusCode: 422 });
816
749
  return { method: "PATCH", url: `https://www.wixapis.com/stores/v1/products/${productId}`,
817
- headers: { "wix-site-id": settings.siteId }, body: { product: { ...changes, ...(price === undefined ? {} : { priceData: { price } }) } } };
750
+ body: { product: { ...changes, ...(price === undefined ? {} : { priceData: { price } }) } } };
818
751
  },
819
- validateResult: value => guid(value?.product?.id) && typeof value.product.name === "string" && value.product.name.length > 0
752
+ validateResult: (value, request) => guid(value?.product?.id) && typeof value.product.name === "string" && value.product.name.length > 0 &&
753
+ sameRecord(value.product.id === requestPath(request, -1), "Wix returned a different product.")
820
754
  },
821
755
  "productsV3.list": productReadOperation(3, "list"),
822
756
  "productsV3.get": productReadOperation(3, "get"),
823
757
  "productsV3.update": {
824
758
  scopes: [],
825
- request(input, settings) {
759
+ request(input) {
826
760
  const { productId, revision, ...changes } = validateSchemaPayload({ schema: productV3UpdateSchema, mode: "replace" }, input, { statusCode: 422 });
827
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
828
761
  if (!Object.keys(changes).length) throw new ConnectorError("connector_input_invalid", "Provide a product name or visibility change.", { statusCode: 422 });
829
762
  return { method: "PATCH", url: `https://www.wixapis.com/stores/v3/products/${productId}`,
830
- headers: { "wix-site-id": settings.siteId }, body: { product: { id: productId, revision, ...changes } } };
763
+ body: { product: { id: productId, revision, ...changes } } };
831
764
  },
832
- validateResult: value => guid(value?.product?.id) && typeof value.product.name === "string" && value.product.name.length > 0 &&
765
+ validateResult: (value, request) => guid(value?.product?.id) && typeof value.product.name === "string" && value.product.name.length > 0 &&
766
+ sameRecord(value.product.id === requestPath(request, -1), "Wix returned a different product.") &&
833
767
  typeof value.product.revision === "string" && /^\d{1,19}$/u.test(value.product.revision) && BigInt(value.product.revision) <= 9223372036854775807n
834
768
  },
835
769
  "catalog.version": {
836
770
  scopes: [],
837
- request(input, settings) {
771
+ request(input) {
838
772
  validateSchemaPayload({ schema: catalogVersionSchema, mode: "replace" }, input, { statusCode: 422 });
839
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
840
- return { method: "GET", url: "https://www.wixapis.com/stores/v3/provision/version", headers: { "wix-site-id": settings.siteId } };
773
+ return { method: "GET", url: "https://www.wixapis.com/stores/v3/provision/version" };
841
774
  }, validateResult: value => ["V1_CATALOG", "V3_CATALOG", "STORES_NOT_INSTALLED"].includes(value?.catalogVersion)
842
775
  },
843
776
  "orders.list": {
844
777
  scopes: [],
845
- request(input, settings) {
778
+ request(input) {
846
779
  const { status, contactId, ...cursorPaging } = validateSchemaPayload({ schema: orderSearchSchema, mode: "replace" }, input, { statusCode: 422 });
847
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
848
780
  if (cursorPaging.cursor && (status || contactId)) throw new ConnectorError("connector_input_invalid", "Use only cursor and limit for the next order page.", { statusCode: 422 });
849
781
  const filter = { ...(status ? { status } : {}), ...(contactId ? { "buyerInfo.contactId": contactId } : {}) };
850
- return { method: "POST", url: "https://www.wixapis.com/ecom/v1/orders/search", headers: { "wix-site-id": settings.siteId },
782
+ return { method: "POST", url: "https://www.wixapis.com/ecom/v1/orders/search",
851
783
  body: { search: { cursorPaging, ...(Object.keys(filter).length ? { filter } : {}) } } };
852
784
  },
853
785
  validateResult: value => Array.isArray(value?.orders) && value.orders.length <= 100 && value.orders.every(validOrder) &&
@@ -859,53 +791,52 @@ const wixRuntime = {
859
791
  },
860
792
  "orders.get": {
861
793
  scopes: [],
862
- request(input, settings) {
794
+ request(input) {
863
795
  const { orderId } = validateSchemaPayload({ schema: orderIdSchema, mode: "replace" }, input, { statusCode: 422 });
864
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
865
- return { method: "GET", url: `https://www.wixapis.com/ecom/v1/orders/${encodeURIComponent(orderId)}`, headers: { "wix-site-id": settings.siteId } };
866
- }, validateResult: value => validOrder(value?.order)
796
+ return { method: "GET", url: `https://www.wixapis.com/ecom/v1/orders/${encodeURIComponent(orderId)}` };
797
+ }, validateResult: (value, request) => validOrder(value?.order) && sameRecord(value.order.id === requestPath(request, -1), "Wix returned a different order.")
867
798
  },
868
799
  "orderFulfillments.create": fulfillmentWriteOperation(false),
869
800
  "orderFulfillments.update": fulfillmentWriteOperation(true),
870
801
  "orderFulfillments.list": {
871
802
  scopes: [],
872
- request(input, settings) {
803
+ request(input) {
873
804
  const { orderId } = validateSchemaPayload({ schema: orderIdSchema, mode: "replace" }, input, { statusCode: 422 });
874
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
875
- return { method: "GET", url: `https://www.wixapis.com/ecom/v1/fulfillments/orders/${encodeURIComponent(orderId)}`, headers: { "wix-site-id": settings.siteId } };
805
+ return { method: "GET", url: `https://www.wixapis.com/ecom/v1/fulfillments/orders/${encodeURIComponent(orderId)}` };
876
806
  },
877
- validateResult: value => guid(value?.orderWithFulfillments?.orderId) && Array.isArray(value.orderWithFulfillments.fulfillments) &&
807
+ validateResult: (value, request) => guid(value?.orderWithFulfillments?.orderId) &&
808
+ sameRecord(value.orderWithFulfillments.orderId === requestPath(request, -1), "Wix returned fulfillments for a different order.") &&
809
+ Array.isArray(value.orderWithFulfillments.fulfillments) &&
878
810
  value.orderWithFulfillments.fulfillments.every(item => guid(item?.id) && Array.isArray(item.lineItems) && item.lineItems.length <= 300 &&
879
811
  item.lineItems.every(line => guid(line?.id) && Number.isInteger(line.quantity) && line.quantity >= 1 && line.quantity <= 100000))
880
812
  },
881
813
  "classAvailability.list": availabilityOperation("list", true),
882
814
  "classAvailability.get": {
883
815
  scopes: [],
884
- request(input, settings) {
816
+ request(input) {
885
817
  const { eventId, timeZone } = validateSchemaPayload({ schema: eventSlotSchema, mode: "replace" }, input, { statusCode: 422 });
886
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
887
818
  const url = new URL(`https://www.wixapis.com/_api/service-availability/v2/time-slots/event/${encodeURIComponent(eventId)}`);
888
819
  url.searchParams.set("timeZone", timeZone);
889
- return { method: "GET", url: url.href, headers: { "wix-site-id": settings.siteId } };
890
- }, validateResult: value => validSlot(value?.timeSlot) && typeof value.timeSlot.eventInfo?.eventId === "string" && typeof value.timeZone === "string"
820
+ return { method: "GET", url: url.href };
821
+ }, validateResult: (value, request) => validSlot(value?.timeSlot) && typeof value.timeSlot.eventInfo?.eventId === "string" && typeof value.timeZone === "string" &&
822
+ sameRecord(value.timeSlot.eventInfo.eventId === requestPath(request, -1) && value.timeZone === new URL(request.url).searchParams.get("timeZone"), "Wix returned a different event slot or time zone.")
891
823
  },
892
824
  "forms.summary": {
893
825
  scopes: [],
894
- request(input, settings) {
826
+ request(input) {
895
827
  const { formId } = validateSchemaPayload({ schema: formSummarySchema, mode: "replace" }, input, { statusCode: 422 });
896
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
897
- return { method: "GET", url: `https://www.wixapis.com/form-schema-service/v4/forms/${formId}/summary`, headers: { "wix-site-id": settings.siteId } };
828
+ return { method: "GET", url: `https://www.wixapis.com/form-schema-service/v4/forms/${formId}/summary` };
898
829
  },
899
- validateResult: value => guid(value?.formSummary?.id) && Array.isArray(value.formSummary.fields) && value.formSummary.fields.length <= 500 &&
830
+ validateResult: (value, request) => guid(value?.formSummary?.id) && sameRecord(value.formSummary.id === requestPath(request, -2), "Wix returned a different form summary.") &&
831
+ Array.isArray(value.formSummary.fields) && value.formSummary.fields.length <= 500 &&
900
832
  value.formSummary.fields.every(field => guid(field?.id) && typeof field.target === "string" && field.target.length > 0 && field.target.length <= 200 &&
901
833
  typeof field.type === "string" && field.type.length > 0 && (field.label === undefined || typeof field.label === "string" && field.label.length <= 350) &&
902
834
  (field.deleted === undefined || typeof field.deleted === "boolean") && (field.options === undefined || Array.isArray(field.options) && field.options.length <= 400))
903
835
  },
904
836
  "bookings.create": {
905
837
  scopes: [],
906
- request(input, settings) {
838
+ request(input) {
907
839
  const value = validateSchemaPayload({ schema: bookingCreateSchema, mode: "replace" }, input, { statusCode: 422 });
908
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
909
840
  const { kind, serviceId, timeZone, startDate, endDate, eventId, scheduleId, resourceId, location, totalParticipants, participantsChoices, bookedAddOns, formSubmission, notifyParticipants, sendSmsReminder } = value;
910
841
  if (participantsChoices) {
911
842
  if (totalParticipants !== undefined) throw new ConnectorError("connector_input_invalid", "Use participant choices or a fixed participant total, not both.", { statusCode: 422 });
@@ -922,7 +853,7 @@ const wixRuntime = {
922
853
  if (location?.locationType === "OWNER_BUSINESS" && !location.id) throw new ConnectorError("connector_input_invalid", "Choose the business location ID.", { statusCode: 422 });
923
854
  const bookedEntity = kind === "COURSE" ? { schedule: { scheduleId, serviceId, timezone: timeZone } } :
924
855
  { slot: { serviceId, timezone: timeZone, ...(kind === "CLASS" ? { eventId } : { startDate, endDate, resource: { id: resourceId }, location }) } };
925
- return { method: "POST", url: "https://www.wixapis.com/_api/bookings-service/v2/bookings", headers: { "wix-site-id": settings.siteId },
856
+ return { method: "POST", url: "https://www.wixapis.com/_api/bookings-service/v2/bookings",
926
857
  body: { booking: { bookedEntity, ...(participantsChoices ? { participantsChoices } : { totalParticipants: totalParticipants ?? 1 }),
927
858
  ...(bookedAddOns ? { bookedAddOns } : {}) }, formSubmission, participantNotification: { notifyParticipants }, sendSmsReminder } };
928
859
  },
@@ -933,40 +864,39 @@ const wixRuntime = {
933
864
  "availability.get": availabilityOperation("get"),
934
865
  "bookings.list": {
935
866
  scopes: [],
936
- request(input, settings) {
867
+ request(input) {
937
868
  const { bookingId, ...paging } = validateSchemaPayload({ schema: bookingQuerySchema, mode: "replace" }, input, { statusCode: 422 });
938
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
939
869
  return { method: "POST", url: "https://www.wixapis.com/_api/bookings-reader/v2/extended-bookings/query",
940
- headers: { "wix-site-id": settings.siteId }, body: { query: { paging, ...(bookingId ? { filter: { id: bookingId } } : {}) }, withBookingAllowedActions: true } };
870
+ body: { query: { paging, ...(bookingId ? { filter: { id: bookingId } } : {}) }, withBookingAllowedActions: true } };
941
871
  },
942
- validateResult: value => Array.isArray(value?.extendedBookings) && value.extendedBookings.length <= 100 && value.extendedBookings.every(record =>
872
+ validateResult: (value, request) => Array.isArray(value?.extendedBookings) && value.extendedBookings.length <= 100 && value.extendedBookings.every(record =>
943
873
  guid(record?.booking?.id) && typeof record.booking.revision === "string" && /^\d{1,19}$/u.test(record.booking.revision) && BigInt(record.booking.revision) <= 9223372036854775807n &&
944
874
  typeof record.booking.status === "string" && record.booking.status.length > 0 &&
945
875
  (record.allowedActions === undefined || record.allowedActions && typeof record.allowedActions === "object" && !Array.isArray(record.allowedActions) &&
946
876
  ["cancel", "reschedule"].every(key => record.allowedActions[key] === undefined || typeof record.allowedActions[key] === "boolean"))) &&
947
877
  (value.pagingMetadata === undefined || value.pagingMetadata && typeof value.pagingMetadata === "object" && !Array.isArray(value.pagingMetadata) &&
948
878
  ["count", "offset", "total"].every(key => value.pagingMetadata[key] === undefined || Number.isSafeInteger(value.pagingMetadata[key]) && value.pagingMetadata[key] >= 0) &&
949
- (value.pagingMetadata.count === undefined || value.pagingMetadata.count === value.extendedBookings.length))
879
+ (value.pagingMetadata.count === undefined || value.pagingMetadata.count === value.extendedBookings.length)) &&
880
+ (!request.body.query.filter?.id || sameRecord(value.extendedBookings.length <= 1 && value.extendedBookings.every(record => record.booking.id === request.body.query.filter.id),
881
+ "Wix returned an unexpected booking for the requested ID."))
950
882
  },
951
883
  "bookings.cancel": {
952
884
  scopes: [],
953
- request(input, settings) {
885
+ request(input) {
954
886
  const { bookingId, revision, notifyParticipants, message, waiveCharges } = validateSchemaPayload({ schema: bookingCancelSchema, mode: "replace" }, input, { statusCode: 422 });
955
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
956
887
  if (message && !notifyParticipants) throw new ConnectorError("connector_input_invalid", "Enable participant notification to send a cancellation message.", { statusCode: 422 });
957
888
  return { method: "POST", url: `https://www.wixapis.com/_api/bookings-service/v2/bookings/${bookingId}/cancel`,
958
- headers: { "wix-site-id": settings.siteId }, body: { revision, waiveCharges,
889
+ body: { revision, waiveCharges,
959
890
  participantNotification: { notifyParticipants, ...(message === undefined ? {} : { message }) } } };
960
891
  },
961
- validateResult: value => guid(value?.booking?.id) && value.booking.status === "CANCELED" &&
892
+ validateResult: (value, request) => guid(value?.booking?.id) && sameRecord(value.booking.id === requestPath(request, -2), "Wix returned a different booking. Check the operation outcome before retrying.") && value.booking.status === "CANCELED" &&
962
893
  typeof value.booking.revision === "string" && /^\d{1,19}$/u.test(value.booking.revision) && BigInt(value.booking.revision) <= 9223372036854775807n
963
894
  },
964
895
  "bookingServices.list": {
965
896
  scopes: [],
966
- request(input, settings) {
897
+ request(input) {
967
898
  const paging = validateSchemaPayload({ schema: servicePagingSchema, mode: "replace" }, input, { statusCode: 422 });
968
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
969
- return { method: "POST", url: "https://www.wixapis.com/_api/bookings/v2/services/query", headers: { "wix-site-id": settings.siteId }, body: { query: { paging } } };
899
+ return { method: "POST", url: "https://www.wixapis.com/_api/bookings/v2/services/query", body: { query: { paging } } };
970
900
  },
971
901
  validateResult: value => Array.isArray(value?.services) && value.services.length <= 100 && value.services.every(validService) &&
972
902
  (value.pagingMetadata === undefined || value.pagingMetadata && typeof value.pagingMetadata === "object" && !Array.isArray(value.pagingMetadata) &&
@@ -975,35 +905,31 @@ const wixRuntime = {
975
905
  },
976
906
  "bookingServices.get": {
977
907
  scopes: [],
978
- request(input, settings) {
908
+ request(input) {
979
909
  const { serviceId } = validateSchemaPayload({ schema: serviceIdSchema, mode: "replace" }, input, { statusCode: 422 });
980
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
981
- return { method: "GET", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}`, headers: { "wix-site-id": settings.siteId } };
982
- }, validateResult: value => validService(value?.service)
910
+ return { method: "GET", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}` };
911
+ }, validateResult: (value, request) => validService(value?.service) && sameRecord(value.service.id === requestPath(request, -1), "Wix returned a different booking service. Check the outcome before retrying.")
983
912
  },
984
913
  "bookingServices.update": {
985
914
  scopes: [],
986
- request(input, settings) {
915
+ request(input) {
987
916
  const { serviceId, ...service } = validateSchemaPayload({ schema: serviceUpdateSchema, mode: "replace" }, input, { statusCode: 422 });
988
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
989
917
  if (Object.keys(service).length < 2) throw new ConnectorError("connector_input_invalid", "Choose a service field to update.", { statusCode: 422 });
990
918
  if (["payment", "onlineBooking"].some(key => service[key] !== undefined && !Object.keys(service[key]).length) ||
991
919
  service.schedule && !Object.keys(service.schedule.availabilityConstraints).length) {
992
920
  throw new ConnectorError("connector_input_invalid", "Provide the selected service settings instead of an empty object.", { statusCode: 422 });
993
921
  }
994
- return { method: "PATCH", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}`, headers: { "wix-site-id": settings.siteId }, body: { service: { id: serviceId, ...service } } };
995
- }, validateResult: value => validService(value?.service)
922
+ return { method: "PATCH", url: `https://www.wixapis.com/_api/bookings/v2/services/${serviceId}`, body: { service: { id: serviceId, ...service } } };
923
+ }, validateResult: (value, request) => validService(value?.service) && sameRecord(value.service.id === requestPath(request, -1), "Wix returned a different booking service. Check the outcome before retrying.")
996
924
  },
997
925
  "contacts.get": contactOperation("get"),
998
926
  "contacts.create": contactOperation("create"),
999
927
  "contacts.update": contactOperation("update"),
1000
928
  "contacts.list": {
1001
929
  scopes: [],
1002
- request(input, settings) {
930
+ request(input) {
1003
931
  const { search, ...paging } = validateSchemaPayload({ schema: contactsSchema, mode: "replace" }, input, { statusCode: 422 });
1004
- if (!guid(settings.siteId)) throw new ConnectorError("connector_input_invalid", "Configure the project's Wix Site ID before querying contacts.", { statusCode: 422 });
1005
932
  return { method: "POST", url: "https://www.wixapis.com/contacts/v4/contacts/query",
1006
- headers: { "wix-site-id": settings.siteId },
1007
933
  body: { query: { paging }, ...(search === undefined ? {} : { search }) } };
1008
934
  },
1009
935
  validateResult: value => Array.isArray(value?.contacts) && value.contacts.length <= 100 &&
@@ -1028,16 +954,20 @@ const wixRuntime = {
1028
954
  }
1029
955
  }
1030
956
  };
957
+ // Every operation except sites.list addresses one site: this resolves it, requires it and sends it.
1031
958
  function wixSiteOperation(operation) {
1032
959
  return {
1033
960
  ...operation,
1034
961
  request(input, settings) {
1035
- if (!input || !Object.hasOwn(input, "siteId")) return operation.request(input, settings);
1036
- const { siteId, ...values } = input;
1037
- if (!guid(siteId)) throw new ConnectorError("connector_input_invalid", "Choose a valid Wix Site ID.", { statusCode: 422 });
1038
- const allowed = (settings.selectableSiteIds || "").split(",").map(id => id.trim().toLowerCase());
1039
- if (!allowed.includes(siteId.toLowerCase())) throw new ConnectorError("connector_input_invalid", "This site is not enabled in the project's Selectable Site IDs.", { statusCode: 422 });
1040
- return operation.request(values, { ...settings, siteId });
962
+ let siteId = settings.siteId, values = input;
963
+ if (input && Object.hasOwn(input, "siteId")) {
964
+ ({ siteId, ...values } = input);
965
+ if (!guid(siteId)) throw new ConnectorError("connector_input_invalid", "Choose a valid Wix Site ID.", { statusCode: 422 });
966
+ const allowed = (settings.selectableSiteIds || "").split(",").map(id => id.trim().toLowerCase());
967
+ if (!allowed.includes(siteId.toLowerCase())) throw new ConnectorError("connector_input_invalid", "This site is not enabled in the project's Selectable Site IDs.", { statusCode: 422 });
968
+ } else if (!guid(siteId)) throw new ConnectorError("connector_input_invalid", "Configure the Wix Site ID first.", { statusCode: 422 });
969
+ const request = operation.request(values, { ...settings, siteId });
970
+ return { ...request, headers: { ...request.headers, "wix-site-id": siteId } };
1041
971
  }
1042
972
  };
1043
973
  }