@whereby.com/assistant-sdk 1.1.10 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -695,6 +695,55 @@ function buildRoomUrl(roomPath, wherebySubdomain, baseDomain = "whereby.com") {
695
695
  return `https://${wherebyDomain}${roomPath}`;
696
696
  }
697
697
 
698
+ function calculateTrigger(_a) {
699
+ return __awaiter(this, arguments, void 0, function* ({ body: rawBody, eventType, webhookTriggers, }) {
700
+ if (!webhookTriggers[eventType]) {
701
+ return null;
702
+ }
703
+ switch (eventType) {
704
+ case "assistant.requested": {
705
+ const body = rawBody;
706
+ const trigger = webhookTriggers["assistant.requested"];
707
+ return {
708
+ data: body.data,
709
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
710
+ };
711
+ }
712
+ case "room.client.joined": {
713
+ const body = rawBody;
714
+ const trigger = webhookTriggers["room.client.joined"];
715
+ return {
716
+ data: body.data,
717
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
718
+ };
719
+ }
720
+ case "room.client.left": {
721
+ const body = rawBody;
722
+ const trigger = webhookTriggers["room.client.left"];
723
+ return {
724
+ data: body.data,
725
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
726
+ };
727
+ }
728
+ case "room.session.started": {
729
+ const body = rawBody;
730
+ const trigger = webhookTriggers["room.session.started"];
731
+ return {
732
+ data: body.data,
733
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
734
+ };
735
+ }
736
+ case "room.session.ended": {
737
+ const body = rawBody;
738
+ const trigger = webhookTriggers["room.session.ended"];
739
+ return {
740
+ data: body.data,
741
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
742
+ };
743
+ }
744
+ }
745
+ });
746
+ }
698
747
  const webhookRouter = (webhookTriggers, emitter) => {
699
748
  const router = express.Router();
700
749
  const jsonParser = bodyParser.json();
@@ -703,30 +752,16 @@ const webhookRouter = (webhookTriggers, emitter) => {
703
752
  res.end();
704
753
  });
705
754
  router.post("/", jsonParser, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
706
- var _a, _b, _c, _d, _e, _f, _g, _h;
707
755
  assert(req.body, "message body is required");
708
756
  assert("type" in req.body, "webhook type is required");
709
- let shouldTriggerOnReceivedWebhook = false;
710
- switch (req.body.type) {
711
- case "room.client.joined":
712
- shouldTriggerOnReceivedWebhook =
713
- (_b = (yield ((_a = webhookTriggers["room.client.joined"]) === null || _a === void 0 ? void 0 : _a.call(webhookTriggers, req.body)))) !== null && _b !== void 0 ? _b : false;
714
- break;
715
- case "room.client.left":
716
- shouldTriggerOnReceivedWebhook =
717
- (_d = (yield ((_c = webhookTriggers["room.client.left"]) === null || _c === void 0 ? void 0 : _c.call(webhookTriggers, req.body)))) !== null && _d !== void 0 ? _d : false;
718
- break;
719
- case "room.session.started":
720
- shouldTriggerOnReceivedWebhook =
721
- (_f = (yield ((_e = webhookTriggers["room.session.started"]) === null || _e === void 0 ? void 0 : _e.call(webhookTriggers, req.body)))) !== null && _f !== void 0 ? _f : false;
722
- break;
723
- case "room.session.ended":
724
- shouldTriggerOnReceivedWebhook =
725
- (_h = (yield ((_g = webhookTriggers["room.session.ended"]) === null || _g === void 0 ? void 0 : _g.call(webhookTriggers, req.body)))) !== null && _h !== void 0 ? _h : false;
726
- break;
727
- }
728
- if (shouldTriggerOnReceivedWebhook) {
729
- const roomUrl = buildRoomUrl(req.body.data.roomName, req.body.data.subdomain);
757
+ const result = yield calculateTrigger({
758
+ body: req.body,
759
+ eventType: req.body.type,
760
+ webhookTriggers,
761
+ });
762
+ if (result === null || result === void 0 ? void 0 : result.shouldTriggerOnReceivedWebhook) {
763
+ const { data } = result;
764
+ const roomUrl = buildRoomUrl(data.roomName, data.subdomain);
730
765
  emitter.emit(TRIGGER_EVENT_SUCCESS, { roomUrl, triggerWebhook: req.body });
731
766
  }
732
767
  res.status(200);
package/dist/index.d.cts CHANGED
@@ -36,10 +36,10 @@ declare global {
36
36
  }
37
37
  }
38
38
 
39
- type WebhookType = "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
39
+ type WebhookEventType = "assistant.requested" | "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
40
40
  declare const TRIGGER_EVENT_SUCCESS = "trigger_event_success";
41
41
  interface WherebyWebhookBase {
42
- type: WebhookType;
42
+ type: WebhookEventType;
43
43
  apiVersion: "1.0";
44
44
  id: string;
45
45
  createdAt: string;
@@ -62,6 +62,9 @@ interface WherebyWebhookDataClientJoinLeave {
62
62
  numClients: number;
63
63
  numClientsByRoleName: Record<WherebyRoleName, number>;
64
64
  }
65
+ interface WherebyWebhookAssistantRequested extends WherebyWebhookBase {
66
+ data: WherebyWebhookInRoom;
67
+ }
65
68
  interface WherebyWebhookRoomClientJoined extends WherebyWebhookBase {
66
69
  data: WherebyWebhookInRoom & WherebyWebhookDataClientJoinLeave & WherebyWebhookDataClient;
67
70
  }
@@ -80,8 +83,9 @@ type TriggerEvents = {
80
83
  triggerWebhook: WherebyWebhookType;
81
84
  }];
82
85
  };
83
- type WherebyWebhookType = WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
86
+ type WherebyWebhookType = WherebyWebhookAssistantRequested | WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
84
87
  type WherebyWebhookTriggerTypes = {
88
+ "assistant.requested": WherebyWebhookAssistantRequested;
85
89
  "room.client.joined": WherebyWebhookRoomClientJoined;
86
90
  "room.client.left": WherebyWebhookRoomClientLeft;
87
91
  "room.session.started": WherebyWebhookRoomSessionStarted;
package/dist/index.d.mts CHANGED
@@ -36,10 +36,10 @@ declare global {
36
36
  }
37
37
  }
38
38
 
39
- type WebhookType = "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
39
+ type WebhookEventType = "assistant.requested" | "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
40
40
  declare const TRIGGER_EVENT_SUCCESS = "trigger_event_success";
41
41
  interface WherebyWebhookBase {
42
- type: WebhookType;
42
+ type: WebhookEventType;
43
43
  apiVersion: "1.0";
44
44
  id: string;
45
45
  createdAt: string;
@@ -62,6 +62,9 @@ interface WherebyWebhookDataClientJoinLeave {
62
62
  numClients: number;
63
63
  numClientsByRoleName: Record<WherebyRoleName, number>;
64
64
  }
65
+ interface WherebyWebhookAssistantRequested extends WherebyWebhookBase {
66
+ data: WherebyWebhookInRoom;
67
+ }
65
68
  interface WherebyWebhookRoomClientJoined extends WherebyWebhookBase {
66
69
  data: WherebyWebhookInRoom & WherebyWebhookDataClientJoinLeave & WherebyWebhookDataClient;
67
70
  }
@@ -80,8 +83,9 @@ type TriggerEvents = {
80
83
  triggerWebhook: WherebyWebhookType;
81
84
  }];
82
85
  };
83
- type WherebyWebhookType = WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
86
+ type WherebyWebhookType = WherebyWebhookAssistantRequested | WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
84
87
  type WherebyWebhookTriggerTypes = {
88
+ "assistant.requested": WherebyWebhookAssistantRequested;
85
89
  "room.client.joined": WherebyWebhookRoomClientJoined;
86
90
  "room.client.left": WherebyWebhookRoomClientLeft;
87
91
  "room.session.started": WherebyWebhookRoomSessionStarted;
package/dist/index.d.ts CHANGED
@@ -36,10 +36,10 @@ declare global {
36
36
  }
37
37
  }
38
38
 
39
- type WebhookType = "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
39
+ type WebhookEventType = "assistant.requested" | "room.client.joined" | "room.client.left" | "room.session.started" | "room.session.ended";
40
40
  declare const TRIGGER_EVENT_SUCCESS = "trigger_event_success";
41
41
  interface WherebyWebhookBase {
42
- type: WebhookType;
42
+ type: WebhookEventType;
43
43
  apiVersion: "1.0";
44
44
  id: string;
45
45
  createdAt: string;
@@ -62,6 +62,9 @@ interface WherebyWebhookDataClientJoinLeave {
62
62
  numClients: number;
63
63
  numClientsByRoleName: Record<WherebyRoleName, number>;
64
64
  }
65
+ interface WherebyWebhookAssistantRequested extends WherebyWebhookBase {
66
+ data: WherebyWebhookInRoom;
67
+ }
65
68
  interface WherebyWebhookRoomClientJoined extends WherebyWebhookBase {
66
69
  data: WherebyWebhookInRoom & WherebyWebhookDataClientJoinLeave & WherebyWebhookDataClient;
67
70
  }
@@ -80,8 +83,9 @@ type TriggerEvents = {
80
83
  triggerWebhook: WherebyWebhookType;
81
84
  }];
82
85
  };
83
- type WherebyWebhookType = WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
86
+ type WherebyWebhookType = WherebyWebhookAssistantRequested | WherebyWebhookRoomClientJoined | WherebyWebhookRoomClientLeft | WherebyWebhookRoomSessionStarted | WherebyWebhookRoomSessionEnded;
84
87
  type WherebyWebhookTriggerTypes = {
88
+ "assistant.requested": WherebyWebhookAssistantRequested;
85
89
  "room.client.joined": WherebyWebhookRoomClientJoined;
86
90
  "room.client.left": WherebyWebhookRoomClientLeft;
87
91
  "room.session.started": WherebyWebhookRoomSessionStarted;
package/dist/index.mjs CHANGED
@@ -693,6 +693,55 @@ function buildRoomUrl(roomPath, wherebySubdomain, baseDomain = "whereby.com") {
693
693
  return `https://${wherebyDomain}${roomPath}`;
694
694
  }
695
695
 
696
+ function calculateTrigger(_a) {
697
+ return __awaiter(this, arguments, void 0, function* ({ body: rawBody, eventType, webhookTriggers, }) {
698
+ if (!webhookTriggers[eventType]) {
699
+ return null;
700
+ }
701
+ switch (eventType) {
702
+ case "assistant.requested": {
703
+ const body = rawBody;
704
+ const trigger = webhookTriggers["assistant.requested"];
705
+ return {
706
+ data: body.data,
707
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
708
+ };
709
+ }
710
+ case "room.client.joined": {
711
+ const body = rawBody;
712
+ const trigger = webhookTriggers["room.client.joined"];
713
+ return {
714
+ data: body.data,
715
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
716
+ };
717
+ }
718
+ case "room.client.left": {
719
+ const body = rawBody;
720
+ const trigger = webhookTriggers["room.client.left"];
721
+ return {
722
+ data: body.data,
723
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
724
+ };
725
+ }
726
+ case "room.session.started": {
727
+ const body = rawBody;
728
+ const trigger = webhookTriggers["room.session.started"];
729
+ return {
730
+ data: body.data,
731
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
732
+ };
733
+ }
734
+ case "room.session.ended": {
735
+ const body = rawBody;
736
+ const trigger = webhookTriggers["room.session.ended"];
737
+ return {
738
+ data: body.data,
739
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
740
+ };
741
+ }
742
+ }
743
+ });
744
+ }
696
745
  const webhookRouter = (webhookTriggers, emitter) => {
697
746
  const router = express.Router();
698
747
  const jsonParser = bodyParser.json();
@@ -701,30 +750,16 @@ const webhookRouter = (webhookTriggers, emitter) => {
701
750
  res.end();
702
751
  });
703
752
  router.post("/", jsonParser, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
704
- var _a, _b, _c, _d, _e, _f, _g, _h;
705
753
  assert(req.body, "message body is required");
706
754
  assert("type" in req.body, "webhook type is required");
707
- let shouldTriggerOnReceivedWebhook = false;
708
- switch (req.body.type) {
709
- case "room.client.joined":
710
- shouldTriggerOnReceivedWebhook =
711
- (_b = (yield ((_a = webhookTriggers["room.client.joined"]) === null || _a === void 0 ? void 0 : _a.call(webhookTriggers, req.body)))) !== null && _b !== void 0 ? _b : false;
712
- break;
713
- case "room.client.left":
714
- shouldTriggerOnReceivedWebhook =
715
- (_d = (yield ((_c = webhookTriggers["room.client.left"]) === null || _c === void 0 ? void 0 : _c.call(webhookTriggers, req.body)))) !== null && _d !== void 0 ? _d : false;
716
- break;
717
- case "room.session.started":
718
- shouldTriggerOnReceivedWebhook =
719
- (_f = (yield ((_e = webhookTriggers["room.session.started"]) === null || _e === void 0 ? void 0 : _e.call(webhookTriggers, req.body)))) !== null && _f !== void 0 ? _f : false;
720
- break;
721
- case "room.session.ended":
722
- shouldTriggerOnReceivedWebhook =
723
- (_h = (yield ((_g = webhookTriggers["room.session.ended"]) === null || _g === void 0 ? void 0 : _g.call(webhookTriggers, req.body)))) !== null && _h !== void 0 ? _h : false;
724
- break;
725
- }
726
- if (shouldTriggerOnReceivedWebhook) {
727
- const roomUrl = buildRoomUrl(req.body.data.roomName, req.body.data.subdomain);
755
+ const result = yield calculateTrigger({
756
+ body: req.body,
757
+ eventType: req.body.type,
758
+ webhookTriggers,
759
+ });
760
+ if (result === null || result === void 0 ? void 0 : result.shouldTriggerOnReceivedWebhook) {
761
+ const { data } = result;
762
+ const roomUrl = buildRoomUrl(data.roomName, data.subdomain);
728
763
  emitter.emit(TRIGGER_EVENT_SUCCESS, { roomUrl, triggerWebhook: req.body });
729
764
  }
730
765
  res.status(200);
@@ -693,6 +693,55 @@ function buildRoomUrl(roomPath, wherebySubdomain, baseDomain = "whereby.com") {
693
693
  return `https://${wherebyDomain}${roomPath}`;
694
694
  }
695
695
 
696
+ function calculateTrigger(_a) {
697
+ return __awaiter(this, arguments, void 0, function* ({ body: rawBody, eventType, webhookTriggers, }) {
698
+ if (!webhookTriggers[eventType]) {
699
+ return null;
700
+ }
701
+ switch (eventType) {
702
+ case "assistant.requested": {
703
+ const body = rawBody;
704
+ const trigger = webhookTriggers["assistant.requested"];
705
+ return {
706
+ data: body.data,
707
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
708
+ };
709
+ }
710
+ case "room.client.joined": {
711
+ const body = rawBody;
712
+ const trigger = webhookTriggers["room.client.joined"];
713
+ return {
714
+ data: body.data,
715
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
716
+ };
717
+ }
718
+ case "room.client.left": {
719
+ const body = rawBody;
720
+ const trigger = webhookTriggers["room.client.left"];
721
+ return {
722
+ data: body.data,
723
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
724
+ };
725
+ }
726
+ case "room.session.started": {
727
+ const body = rawBody;
728
+ const trigger = webhookTriggers["room.session.started"];
729
+ return {
730
+ data: body.data,
731
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
732
+ };
733
+ }
734
+ case "room.session.ended": {
735
+ const body = rawBody;
736
+ const trigger = webhookTriggers["room.session.ended"];
737
+ return {
738
+ data: body.data,
739
+ shouldTriggerOnReceivedWebhook: yield trigger(body),
740
+ };
741
+ }
742
+ }
743
+ });
744
+ }
696
745
  const webhookRouter = (webhookTriggers, emitter) => {
697
746
  const router = express.Router();
698
747
  const jsonParser = bodyParser.json();
@@ -701,30 +750,16 @@ const webhookRouter = (webhookTriggers, emitter) => {
701
750
  res.end();
702
751
  });
703
752
  router.post("/", jsonParser, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
704
- var _a, _b, _c, _d, _e, _f, _g, _h;
705
753
  assert(req.body, "message body is required");
706
754
  assert("type" in req.body, "webhook type is required");
707
- let shouldTriggerOnReceivedWebhook = false;
708
- switch (req.body.type) {
709
- case "room.client.joined":
710
- shouldTriggerOnReceivedWebhook =
711
- (_b = (yield ((_a = webhookTriggers["room.client.joined"]) === null || _a === void 0 ? void 0 : _a.call(webhookTriggers, req.body)))) !== null && _b !== void 0 ? _b : false;
712
- break;
713
- case "room.client.left":
714
- shouldTriggerOnReceivedWebhook =
715
- (_d = (yield ((_c = webhookTriggers["room.client.left"]) === null || _c === void 0 ? void 0 : _c.call(webhookTriggers, req.body)))) !== null && _d !== void 0 ? _d : false;
716
- break;
717
- case "room.session.started":
718
- shouldTriggerOnReceivedWebhook =
719
- (_f = (yield ((_e = webhookTriggers["room.session.started"]) === null || _e === void 0 ? void 0 : _e.call(webhookTriggers, req.body)))) !== null && _f !== void 0 ? _f : false;
720
- break;
721
- case "room.session.ended":
722
- shouldTriggerOnReceivedWebhook =
723
- (_h = (yield ((_g = webhookTriggers["room.session.ended"]) === null || _g === void 0 ? void 0 : _g.call(webhookTriggers, req.body)))) !== null && _h !== void 0 ? _h : false;
724
- break;
725
- }
726
- if (shouldTriggerOnReceivedWebhook) {
727
- const roomUrl = buildRoomUrl(req.body.data.roomName, req.body.data.subdomain);
755
+ const result = yield calculateTrigger({
756
+ body: req.body,
757
+ eventType: req.body.type,
758
+ webhookTriggers,
759
+ });
760
+ if (result === null || result === void 0 ? void 0 : result.shouldTriggerOnReceivedWebhook) {
761
+ const { data } = result;
762
+ const roomUrl = buildRoomUrl(data.roomName, data.subdomain);
728
763
  emitter.emit(TRIGGER_EVENT_SUCCESS, { roomUrl, triggerWebhook: req.body });
729
764
  }
730
765
  res.status(200);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@whereby.com/assistant-sdk",
3
3
  "description": "Assistant SDK for whereby.com",
4
4
  "author": "Whereby AS",
5
- "version": "1.1.10",
5
+ "version": "1.2.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "dist",
@@ -51,9 +51,9 @@
51
51
  "prettier": "^3.5.3",
52
52
  "typescript": "^5.8.3",
53
53
  "@whereby.com/eslint-config": "0.1.0",
54
- "@whereby.com/jest-config": "0.1.0",
55
54
  "@whereby.com/prettier-config": "0.1.0",
56
55
  "@whereby.com/rollup-config": "0.1.1",
56
+ "@whereby.com/jest-config": "0.1.0",
57
57
  "@whereby.com/tsconfig": "0.1.0"
58
58
  },
59
59
  "dependencies": {