@ndustrial/contxt-sdk 5.3.0 → 5.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [v5.3.1](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.3.1) (2022-03-17)
2
+
3
+ **Changed**
4
+
5
+ - exposed `peek` operation on message bus channel for a given subscription
6
+
7
+ ## [v5.3.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.3.1) (2022-03-17)
8
+
9
+ **Changed**
10
+
11
+ - add auto-ack flag on message bus client constructor
12
+
1
13
  ## [v4.3.1](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.3.1) (2022-03-17)
2
14
 
3
15
  **Changed**
@@ -223,6 +223,58 @@ var Channels = function () {
223
223
 
224
224
  return this._request.put(this._baseUrl + '/organizations/' + organizationId + '/services/' + serviceId + '/channels/' + channelId, toSnakeCase(_update));
225
225
  }
226
+
227
+ /**
228
+ * Peeks messages from a channel subscription
229
+ *
230
+ * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId/peek/:subscription'
231
+ * Method: GET
232
+ *
233
+ * @param {string} organizationId UUID of the organization
234
+ * @param {string} serviceId ID of the service
235
+ * @param {string} channelId UUID of the channel
236
+ * @param {string} subscription name of the subscription
237
+ * @param {number} messagePos the number of messages to peek
238
+ *
239
+ * @returns {Promise}
240
+ * @fulfill {MessageBusChannel} Information about an event
241
+ * @reject {Error}
242
+ *
243
+ * @example
244
+ * contxtSdk.bus.channels
245
+ * .peek(
246
+ * '875afddd-091c-4385-bc21-0edf38804d27',
247
+ * 'ab123service',
248
+ * '175afdec-291c-4385-bc21-0edf38804d21',
249
+ * 'test-subscription'
250
+ * )
251
+ * .then((channel) => console.log(channel))
252
+ * .catch((err) => console.log(err));
253
+ */
254
+
255
+ }, {
256
+ key: 'peek',
257
+ value: function peek(organizationId, serviceId, channelId, subscription, messagePos) {
258
+ var errorMsg = void 0;
259
+
260
+ if (!organizationId) {
261
+ errorMsg = 'An organizationId is required to peek a message bus channel subscription.';
262
+ } else if (!serviceId) {
263
+ errorMsg = 'A serviceId is required to peek a message bus channel subscription.';
264
+ } else if (!channelId) {
265
+ errorMsg = 'A channelId is required to peek a message bus channel subscription.';
266
+ } else if (!subscription) {
267
+ errorMsg = 'A subscription name is required to peek a message bus channel subscription.';
268
+ }
269
+
270
+ if (errorMsg) {
271
+ return Promise.reject(new Error(errorMsg));
272
+ }
273
+
274
+ return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/services/' + serviceId + '/channels/' + channelId + '/peek/' + subscription, { params: { messagePos: messagePos } }).then(function (response) {
275
+ return toCamelCase(response);
276
+ });
277
+ }
226
278
  }]);
227
279
 
228
280
  return Channels;
@@ -1 +1 @@
1
- {"version":3,"sources":["bus/channels.js"],"names":["isPlainObject","toCamelCase","toSnakeCase","Channels","sdk","request","baseUrl","_baseUrl","_request","_sdk","channel","requiredFields","i","length","field","Promise","reject","Error","post","organizationId","serviceId","then","response","channelId","errorMsg","delete","get","update","put"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;AAQA;;;;;;IAKMC,Q;AACJ;;;;;AAKA,oBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyBqB;AAAA,UAAdM,OAAc,uEAAJ,EAAI;;AACnB,UAAMC,iBAAiB,CAAC,MAAD,EAAS,gBAAT,EAA2B,WAA3B,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAAb,EAAgBD,eAAeE,MAAf,GAAwBD,CAAxC,EAA2CA,GAA3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AQC,MAAR,CAAe,IAAIC,KAAJ,CAAUO,QAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKhB,QAAL,CACJkB,GADI,CAGD,KAAKnB,QAHJ,uBAIeY,cAJf,kBAI0CC,SAJ1C,kBAIgEG,SAJhE,EAMJF,IANI,CAMC,UAACC,QAAD;AAAA,eAAcrB,YAAYqB,QAAZ,CAAd;AAAA,OAND,CAAP;AAOD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAyBOH,c,EAAgBC,S,EAAWG,S,EAAWI,O,EAAQ;AACnD,UAAIH,iBAAJ;;AAEA,UAAI,CAACL,cAAL,EAAqB;AACnBK,mBACE,gEADF;AAED,OAHD,MAGO,IAAI,CAACJ,SAAL,EAAgB;AACrBI,mBAAW,0DAAX;AACD,OAFM,MAEA,IAAI,CAACD,SAAL,EAAgB;AACrBC,mBAAW,0DAAX;AACD;;AAED,UAAIA,QAAJ,EAAc;AACZ,eAAOT,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAUO,QAAV,CAAf,CAAP;AACD;;AAED,UAAI,CAACG,OAAL,EAAa;AACX,eAAOZ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,wDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACjB,cAAc2B,OAAd,CAAL,EAA4B;AAC1B,eAAOZ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,+FADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKT,QAAL,CAAcoB,GAAd,CAEH,KAAKrB,QAFF,uBAGaY,cAHb,kBAGwCC,SAHxC,kBAG8DG,SAH9D,EAILrB,YAAYyB,OAAZ,CAJK,CAAP;AAMD;;;;;;AAGH,eAAexB,QAAf","file":"channels.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} MessageBusChannel\n * @property {string} id UUID formatted ID\n * @property {string} name\n * @property {string} organizationId UUID of the organization to which the channel belongs\n * @property {string} serviceId\n */\n\n/**\n * Module that provides access to message bus channels\n *\n * @typicalname contxtSdk.bus.channels\n */\nclass Channels {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules\n * @param {Object} request An instance of the request module tied to this module's audience.\n * @param {string} baseUrl The base URL provided by the parent module\n */\n constructor(sdk, request, baseUrl) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n }\n\n /**\n * Creates a new message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels'\n * Method: POST\n *\n * @param {Object} channel\n * @param {string} channel.name\n * @param {string} channel.organizationId UUID corresponding with an organization\n * @param {string} channel.serviceId ID of a service\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about the new channel\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .create({\n * name: 'Channel 46',\n * organizationId: '28cc036c-d87f-4f06-bd30-1e78c2701064',\n * serviceId: 'abc123service'\n * })\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n create(channel = {}) {\n const requiredFields = ['name', 'organizationId', 'serviceId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!channel[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new message bus channel.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${channel.organizationId}/services/${\n channel.serviceId\n }/channels`,\n toSnakeCase(channel)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: DELETE\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .delete(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * );\n */\n delete(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n );\n }\n\n /**\n * Gets information about a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .get(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n get(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to get a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to get a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to get a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Updates a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: PUT\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel to update\n * @param {Object} update An object containing the updated data for the channel\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .update(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * { name: 'An Updated Channel Name' }\n * );\n */\n update(organizationId, serviceId, channelId, update) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a message bus channel.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The message bus channel update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request.put(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`,\n toSnakeCase(update)\n );\n }\n}\n\nexport default Channels;\n"]}
1
+ {"version":3,"sources":["bus/channels.js"],"names":["isPlainObject","toCamelCase","toSnakeCase","Channels","sdk","request","baseUrl","_baseUrl","_request","_sdk","channel","requiredFields","i","length","field","Promise","reject","Error","post","organizationId","serviceId","then","response","channelId","errorMsg","delete","get","update","put","subscription","messagePos","params"],"mappings":";;;;AAAA,OAAOA,aAAP,MAA0B,sBAA1B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;AAQA;;;;;;IAKMC,Q;AACJ;;;;;AAKA,oBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyBqB;AAAA,UAAdM,OAAc,uEAAJ,EAAI;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A2BKR,c,EAAgBC,S,EAAWG,S,EAAWM,Y,EAAcC,U,EAAY;AACnE,UAAIN,iBAAJ;;AAEA,UAAI,CAACL,cAAL,EAAqB;AACnBK,mBAAW,2EAAX;AACD,OAFD,MAEO,IAAI,CAACJ,SAAL,EAAgB;AACrBI,mBAAW,qEAAX;AACD,OAFM,MAEA,IAAI,CAACD,SAAL,EAAgB;AACrBC,mBAAW,qEAAX;AACD,OAFM,MAEA,IAAI,CAACK,YAAL,EAAmB;AACxBL,mBAAW,6EAAX;AACD;;AAED,UAAIA,QAAJ,EAAc;AACZ,eAAOT,QAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAUO,QAAV,CAAf,CAAP;AACD;;AAED,aAAO,KAAKhB,QAAL,CACJkB,GADI,CAGD,KAAKnB,QAHJ,uBAIeY,cAJf,kBAI0CC,SAJ1C,kBAIgEG,SAJhE,cAIkFM,YAJlF,EAKH,EAAEE,QAAQ,EAAED,sBAAF,EAAV,EALG,EAOJT,IAPI,CAOC,UAACC,QAAD;AAAA,eAAcrB,YAAYqB,QAAZ,CAAd;AAAA,OAPD,CAAP;AAQD;;;;;;AAGH,eAAenB,QAAf","file":"channels.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} MessageBusChannel\n * @property {string} id UUID formatted ID\n * @property {string} name\n * @property {string} organizationId UUID of the organization to which the channel belongs\n * @property {string} serviceId\n */\n\n/**\n * Module that provides access to message bus channels\n *\n * @typicalname contxtSdk.bus.channels\n */\nclass Channels {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules\n * @param {Object} request An instance of the request module tied to this module's audience.\n * @param {string} baseUrl The base URL provided by the parent module\n */\n constructor(sdk, request, baseUrl) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n }\n\n /**\n * Creates a new message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels'\n * Method: POST\n *\n * @param {Object} channel\n * @param {string} channel.name\n * @param {string} channel.organizationId UUID corresponding with an organization\n * @param {string} channel.serviceId ID of a service\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about the new channel\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .create({\n * name: 'Channel 46',\n * organizationId: '28cc036c-d87f-4f06-bd30-1e78c2701064',\n * serviceId: 'abc123service'\n * })\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n create(channel = {}) {\n const requiredFields = ['name', 'organizationId', 'serviceId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!channel[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new message bus channel.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${channel.organizationId}/services/${\n channel.serviceId\n }/channels`,\n toSnakeCase(channel)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: DELETE\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .delete(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * );\n */\n delete(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n );\n }\n\n /**\n * Gets information about a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .get(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n get(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to get a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to get a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to get a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Updates a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: PUT\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel to update\n * @param {Object} update An object containing the updated data for the channel\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .update(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * { name: 'An Updated Channel Name' }\n * );\n */\n update(organizationId, serviceId, channelId, update) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a message bus channel.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The message bus channel update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request.put(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`,\n toSnakeCase(update)\n );\n }\n\n /**\n * Peeks messages from a channel subscription\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId/peek/:subscription'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n * @param {string} subscription name of the subscription\n * @param {number} messagePos the number of messages to peek\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .peek(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21',\n * 'test-subscription'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n peek(organizationId, serviceId, channelId, subscription, messagePos) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to peek a message bus channel subscription.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to peek a message bus channel subscription.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to peek a message bus channel subscription.';\n } else if (!subscription) {\n errorMsg = 'A subscription name is required to peek a message bus channel subscription.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}/peek/${subscription}`,\n { params: { messagePos } }\n )\n .then((response) => toCamelCase(response));\n }\n}\n\nexport default Channels;\n"]}
@@ -233,6 +233,58 @@ var Channels = function () {
233
233
 
234
234
  return this._request.put(this._baseUrl + '/organizations/' + organizationId + '/services/' + serviceId + '/channels/' + channelId, (0, _objects.toSnakeCase)(_update));
235
235
  }
236
+
237
+ /**
238
+ * Peeks messages from a channel subscription
239
+ *
240
+ * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId/peek/:subscription'
241
+ * Method: GET
242
+ *
243
+ * @param {string} organizationId UUID of the organization
244
+ * @param {string} serviceId ID of the service
245
+ * @param {string} channelId UUID of the channel
246
+ * @param {string} subscription name of the subscription
247
+ * @param {number} messagePos the number of messages to peek
248
+ *
249
+ * @returns {Promise}
250
+ * @fulfill {MessageBusChannel} Information about an event
251
+ * @reject {Error}
252
+ *
253
+ * @example
254
+ * contxtSdk.bus.channels
255
+ * .peek(
256
+ * '875afddd-091c-4385-bc21-0edf38804d27',
257
+ * 'ab123service',
258
+ * '175afdec-291c-4385-bc21-0edf38804d21',
259
+ * 'test-subscription'
260
+ * )
261
+ * .then((channel) => console.log(channel))
262
+ * .catch((err) => console.log(err));
263
+ */
264
+
265
+ }, {
266
+ key: 'peek',
267
+ value: function peek(organizationId, serviceId, channelId, subscription, messagePos) {
268
+ var errorMsg = void 0;
269
+
270
+ if (!organizationId) {
271
+ errorMsg = 'An organizationId is required to peek a message bus channel subscription.';
272
+ } else if (!serviceId) {
273
+ errorMsg = 'A serviceId is required to peek a message bus channel subscription.';
274
+ } else if (!channelId) {
275
+ errorMsg = 'A channelId is required to peek a message bus channel subscription.';
276
+ } else if (!subscription) {
277
+ errorMsg = 'A subscription name is required to peek a message bus channel subscription.';
278
+ }
279
+
280
+ if (errorMsg) {
281
+ return Promise.reject(new Error(errorMsg));
282
+ }
283
+
284
+ return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/services/' + serviceId + '/channels/' + channelId + '/peek/' + subscription, { params: { messagePos: messagePos } }).then(function (response) {
285
+ return (0, _objects.toCamelCase)(response);
286
+ });
287
+ }
236
288
  }]);
237
289
 
238
290
  return Channels;
@@ -1 +1 @@
1
- {"version":3,"sources":["bus/channels.js"],"names":["Channels","sdk","request","baseUrl","_baseUrl","_request","_sdk","channel","requiredFields","i","length","field","Promise","reject","Error","post","organizationId","serviceId","then","response","channelId","errorMsg","delete","get","update","put"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;;;AAEA;;;;;;;;AAQA;;;;;IAKMA,Q;AACJ;;;;;AAKA,oBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyBqB;AAAA,UAAdM,OAAc,uEAAJ,EAAI;;AACnB,UAAMC,iBAAiB,CAAC,MAAD,EAAS,gBAAT,EAA2B,WAA3B,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAAb,EAAgBD,eAAeE,MAAf,GAAwBD,CAAxC,EAA2CA,GAA3C,EAAgD;AAC9C,YAAME,QAAQH,eAAeC,CAAf,CAAd;;AAEA,YAAI,CAACF,QAAQI,KAAR,CAAL,EAAqB;AACnB,iBAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,QACOH,KADP,uDADK,CAAP;AAKD;AACF;;AAED,aAAO,KAAKN,QAAL,CACJU,IADI,CAEA,KAAKX,QAFL,uBAE+BG,QAAQS,cAFvC,kBAGDT,QAAQU,SAHP,gBAKH,0BAAYV,OAAZ,CALG,EAOJW,IAPI,CAOC,UAACC,QAAD;AAAA,eAAc,0BAAYA,QAAZ,CAAd;AAAA,OAPD,CAAP;AAQD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;4BAsBOH,c,EAAgBC,S,EAAWG,S,EAAW;AAC3C,UAAIC,iBAAJ;;AAEA,UAAI,CAACL,cAAL,EAAqB;AACnBK,mBACE,gEADF;AAED,OAHD,MAGO,IAAI,CAACJ,SAAL,EAAgB;AACrBI,mBAAW,0DAAX;AACD,OAFM,MAE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CAAUO,QAAV,CAAf,CAAP;AACD;;AAED,UAAI,CAACG,OAAL,EAAa;AACX,eAAOZ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,wDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAAC,sBAAcU,OAAd,CAAL,EAA4B;AAC1B,eAAOZ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,+FADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKT,QAAL,CAAcoB,GAAd,CAEH,KAAKrB,QAFF,uBAGaY,cAHb,kBAGwCC,SAHxC,kBAG8DG,SAH9D,EAIL,0BAAYI,OAAZ,CAJK,CAAP;AAMD;;;;;;kBAGYxB,Q","file":"channels.js","sourcesContent":["import isPlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} MessageBusChannel\n * @property {string} id UUID formatted ID\n * @property {string} name\n * @property {string} organizationId UUID of the organization to which the channel belongs\n * @property {string} serviceId\n */\n\n/**\n * Module that provides access to message bus channels\n *\n * @typicalname contxtSdk.bus.channels\n */\nclass Channels {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules\n * @param {Object} request An instance of the request module tied to this module's audience.\n * @param {string} baseUrl The base URL provided by the parent module\n */\n constructor(sdk, request, baseUrl) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n }\n\n /**\n * Creates a new message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels'\n * Method: POST\n *\n * @param {Object} channel\n * @param {string} channel.name\n * @param {string} channel.organizationId UUID corresponding with an organization\n * @param {string} channel.serviceId ID of a service\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about the new channel\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .create({\n * name: 'Channel 46',\n * organizationId: '28cc036c-d87f-4f06-bd30-1e78c2701064',\n * serviceId: 'abc123service'\n * })\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n create(channel = {}) {\n const requiredFields = ['name', 'organizationId', 'serviceId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!channel[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new message bus channel.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${channel.organizationId}/services/${\n channel.serviceId\n }/channels`,\n toSnakeCase(channel)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: DELETE\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .delete(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * );\n */\n delete(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n );\n }\n\n /**\n * Gets information about a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .get(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n get(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to get a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to get a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to get a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Updates a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: PUT\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel to update\n * @param {Object} update An object containing the updated data for the channel\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .update(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * { name: 'An Updated Channel Name' }\n * );\n */\n update(organizationId, serviceId, channelId, update) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a message bus channel.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The message bus channel update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request.put(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`,\n toSnakeCase(update)\n );\n }\n}\n\nexport default Channels;\n"]}
1
+ {"version":3,"sources":["bus/channels.js"],"names":["Channels","sdk","request","baseUrl","_baseUrl","_request","_sdk","channel","requiredFields","i","length","field","Promise","reject","Error","post","organizationId","serviceId","then","response","channelId","errorMsg","delete","get","update","put","subscription","messagePos","params"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;;;AAEA;;;;;;;;AAQA;;;;;IAKMA,Q;AACJ;;;;;AAKA,oBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAAmC;AAAA;;AACjC,SAAKC,QAAL,GAAgBD,OAAhB;AACA,SAAKE,QAAL,GAAgBH,OAAhB;AACA,SAAKI,IAAL,GAAYL,GAAZ;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyBqB;AAAA,UAAdM,OAAc,uEAAJ,EAAI;;AACnB,UAAMC,iBAAiB,CAAC,MAAD,EAAS,gBAAT,EAA2B,WAA3B,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAAb,EAAgBD,eAAeE,MAAf,GAAwBD,CAAxC,EAA2CA,GAA3C,EAAgD;AAC9C,YAAME,QAAQH,eAAeC,CAAf,CAAd;;AAEA,YAAI,CAACF,QAAQI,KAAR,CAAL,EAAqB;AACnB,iBAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,QACOH,KADP,uDADK,CAAP;AAKD;AACF;;AAED,aAAO,KAAKN,QAAL,CACJU,IADI,CAEA,KAAKX,QAFL,uBAE+BG,QAAQS,cAFvC,kBAGDT,QAAQU,SAHP,gBAKH,0BAAYV,OAAZ,CALG,EAOJW,IAPI,CAOC,UAACC,QAAD;AAAA,eAAc,0BAAYA,QAAZ,CAAd;AAAA,OAPD,CAAP;AAQD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;4BAsBOH,c,EAAgBC,S,EAAWG,S,EAAW;AAC3C,UAAIC,iBAAJ;;AAEA,UAAI,CAACL,cAAL,EAAqB;AACnBK,mBACE,gEADF;AAED,OAHD,MAGO,IAAI,CAACJ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PlainObject from 'lodash.isplainobject';\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} MessageBusChannel\n * @property {string} id UUID formatted ID\n * @property {string} name\n * @property {string} organizationId UUID of the organization to which the channel belongs\n * @property {string} serviceId\n */\n\n/**\n * Module that provides access to message bus channels\n *\n * @typicalname contxtSdk.bus.channels\n */\nclass Channels {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules\n * @param {Object} request An instance of the request module tied to this module's audience.\n * @param {string} baseUrl The base URL provided by the parent module\n */\n constructor(sdk, request, baseUrl) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n }\n\n /**\n * Creates a new message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels'\n * Method: POST\n *\n * @param {Object} channel\n * @param {string} channel.name\n * @param {string} channel.organizationId UUID corresponding with an organization\n * @param {string} channel.serviceId ID of a service\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about the new channel\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .create({\n * name: 'Channel 46',\n * organizationId: '28cc036c-d87f-4f06-bd30-1e78c2701064',\n * serviceId: 'abc123service'\n * })\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n create(channel = {}) {\n const requiredFields = ['name', 'organizationId', 'serviceId'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!channel[field]) {\n return Promise.reject(\n new Error(\n `A ${field} is required to create a new message bus channel.`\n )\n );\n }\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${channel.organizationId}/services/${\n channel.serviceId\n }/channels`,\n toSnakeCase(channel)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: DELETE\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .delete(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * );\n */\n delete(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n );\n }\n\n /**\n * Gets information about a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .get(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n get(organizationId, serviceId, channelId) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to get a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to get a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to get a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Updates a message bus channel\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId'\n * Method: PUT\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel to update\n * @param {Object} update An object containing the updated data for the channel\n * @param {string} [update.name]\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .update(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21'\n * { name: 'An Updated Channel Name' }\n * );\n */\n update(organizationId, serviceId, channelId, update) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg =\n 'An organizationId is required to delete a message bus channel.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to delete a message bus channel.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to delete a message bus channel.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n if (!update) {\n return Promise.reject(\n new Error('An update is required to update a message bus channel.')\n );\n }\n\n if (!isPlainObject(update)) {\n return Promise.reject(\n new Error(\n 'The message bus channel update must be a well-formed object with the data you wish to update.'\n )\n );\n }\n\n return this._request.put(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}`,\n toSnakeCase(update)\n );\n }\n\n /**\n * Peeks messages from a channel subscription\n *\n * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId/peek/:subscription'\n * Method: GET\n *\n * @param {string} organizationId UUID of the organization\n * @param {string} serviceId ID of the service\n * @param {string} channelId UUID of the channel\n * @param {string} subscription name of the subscription\n * @param {number} messagePos the number of messages to peek\n *\n * @returns {Promise}\n * @fulfill {MessageBusChannel} Information about an event\n * @reject {Error}\n *\n * @example\n * contxtSdk.bus.channels\n * .peek(\n * '875afddd-091c-4385-bc21-0edf38804d27',\n * 'ab123service',\n * '175afdec-291c-4385-bc21-0edf38804d21',\n * 'test-subscription'\n * )\n * .then((channel) => console.log(channel))\n * .catch((err) => console.log(err));\n */\n peek(organizationId, serviceId, channelId, subscription, messagePos) {\n let errorMsg;\n\n if (!organizationId) {\n errorMsg = 'An organizationId is required to peek a message bus channel subscription.';\n } else if (!serviceId) {\n errorMsg = 'A serviceId is required to peek a message bus channel subscription.';\n } else if (!channelId) {\n errorMsg = 'A channelId is required to peek a message bus channel subscription.';\n } else if (!subscription) {\n errorMsg = 'A subscription name is required to peek a message bus channel subscription.';\n }\n\n if (errorMsg) {\n return Promise.reject(new Error(errorMsg));\n }\n\n return this._request\n .get(\n `${\n this._baseUrl\n }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}/peek/${subscription}`,\n { params: { messagePos } }\n )\n .then((response) => toCamelCase(response));\n }\n}\n\nexport default Channels;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndustrial/contxt-sdk",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -231,6 +231,60 @@ class Channels {
231
231
  toSnakeCase(update)
232
232
  );
233
233
  }
234
+
235
+ /**
236
+ * Peeks messages from a channel subscription
237
+ *
238
+ * API Endpoint: '/organizations/:organizationId/services/:serviceId/channels/:channelId/peek/:subscription'
239
+ * Method: GET
240
+ *
241
+ * @param {string} organizationId UUID of the organization
242
+ * @param {string} serviceId ID of the service
243
+ * @param {string} channelId UUID of the channel
244
+ * @param {string} subscription name of the subscription
245
+ * @param {number} messagePos the number of messages to peek
246
+ *
247
+ * @returns {Promise}
248
+ * @fulfill {MessageBusChannel} Information about an event
249
+ * @reject {Error}
250
+ *
251
+ * @example
252
+ * contxtSdk.bus.channels
253
+ * .peek(
254
+ * '875afddd-091c-4385-bc21-0edf38804d27',
255
+ * 'ab123service',
256
+ * '175afdec-291c-4385-bc21-0edf38804d21',
257
+ * 'test-subscription'
258
+ * )
259
+ * .then((channel) => console.log(channel))
260
+ * .catch((err) => console.log(err));
261
+ */
262
+ peek(organizationId, serviceId, channelId, subscription, messagePos) {
263
+ let errorMsg;
264
+
265
+ if (!organizationId) {
266
+ errorMsg = 'An organizationId is required to peek a message bus channel subscription.';
267
+ } else if (!serviceId) {
268
+ errorMsg = 'A serviceId is required to peek a message bus channel subscription.';
269
+ } else if (!channelId) {
270
+ errorMsg = 'A channelId is required to peek a message bus channel subscription.';
271
+ } else if (!subscription) {
272
+ errorMsg = 'A subscription name is required to peek a message bus channel subscription.';
273
+ }
274
+
275
+ if (errorMsg) {
276
+ return Promise.reject(new Error(errorMsg));
277
+ }
278
+
279
+ return this._request
280
+ .get(
281
+ `${
282
+ this._baseUrl
283
+ }/organizations/${organizationId}/services/${serviceId}/channels/${channelId}/peek/${subscription}`,
284
+ { params: { messagePos } }
285
+ )
286
+ .then((response) => toCamelCase(response));
287
+ }
234
288
  }
235
289
 
236
290
  export default Channels;
@@ -344,4 +344,111 @@ describe('Bus/Channels', function() {
344
344
  });
345
345
  });
346
346
  });
347
+
348
+ describe('peek', function() {
349
+ context('the required fields are provided', function() {
350
+ let channelFromServerAfterFormat;
351
+ let channelFromServerBeforeFormat;
352
+ let expectedOrganizationId;
353
+ let expectedServiceId;
354
+ let expectedChannelId;
355
+ let expectedSubscription;
356
+ let promise;
357
+ let request;
358
+ let toCamelCase;
359
+
360
+ beforeEach(function() {
361
+ channelFromServerAfterFormat = fixture.build('channel');
362
+ expectedSubscription = "test";
363
+ expectedChannelId = channelFromServerAfterFormat.id;
364
+ expectedOrganizationId = channelFromServerAfterFormat.organizationId;
365
+ expectedServiceId = channelFromServerAfterFormat.serviceId;
366
+ channelFromServerBeforeFormat = fixture.build(
367
+ 'channel',
368
+ channelFromServerAfterFormat,
369
+ { fromServer: true }
370
+ );
371
+
372
+ request = {
373
+ ...baseRequest,
374
+ get: sinon.stub().resolves(channelFromServerBeforeFormat)
375
+ };
376
+ toCamelCase = sinon
377
+ .stub(objectUtils, 'toCamelCase')
378
+ .returns(channelFromServerAfterFormat);
379
+
380
+ const channels = new Channels(baseSdk, request);
381
+ channels._baseUrl = expectedHost;
382
+
383
+ promise = channels.peek(
384
+ expectedOrganizationId,
385
+ expectedServiceId,
386
+ expectedChannelId,
387
+ expectedSubscription
388
+ );
389
+ });
390
+
391
+ it('gets the channel from the server', function() {
392
+ expect(request.get).to.be.calledWith(
393
+ `${expectedHost}/organizations/${expectedOrganizationId}/services/${expectedServiceId}/channels/${expectedChannelId}/peek/${expectedSubscription}`
394
+ );
395
+ });
396
+
397
+ it('formats the channel object', function() {
398
+ return promise.then(() => {
399
+ expect(toCamelCase).to.be.calledWith(channelFromServerBeforeFormat);
400
+ });
401
+ });
402
+
403
+ it('returns the requested event', function() {
404
+ return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
405
+ channelFromServerAfterFormat
406
+ );
407
+ });
408
+ });
409
+
410
+ context('the organizationId is not provided', function() {
411
+ it('throws an error', function() {
412
+ const channels = new Channels(baseSdk, baseRequest);
413
+ const promise = channels.peek();
414
+
415
+ return expect(promise).to.be.rejectedWith(
416
+ 'An organizationId is required to peek a message bus channel subscription.'
417
+ );
418
+ });
419
+ });
420
+
421
+ context('the serviceId is not provided', function() {
422
+ it('throws an error', function() {
423
+ const channels = new Channels(baseSdk, baseRequest);
424
+ const promise = channels.peek('1');
425
+
426
+ return expect(promise).to.be.rejectedWith(
427
+ 'A serviceId is required to peek a message bus channel subscription.'
428
+ );
429
+ });
430
+ });
431
+
432
+ context('the channelId is not provided', function() {
433
+ it('throws an error', function() {
434
+ const channels = new Channels(baseSdk, baseRequest);
435
+ const promise = channels.peek('1', '2');
436
+
437
+ return expect(promise).to.be.rejectedWith(
438
+ 'A channelId is required to peek a message bus channel subscription.'
439
+ );
440
+ });
441
+ });
442
+
443
+ context('the subscription is not provided', function() {
444
+ it('throws an error', function() {
445
+ const channels = new Channels(baseSdk, baseRequest);
446
+ const promise = channels.peek('1', '2', '3');
447
+
448
+ return expect(promise).to.be.rejectedWith(
449
+ 'A subscription name is required to peek a message bus channel subscription.'
450
+ );
451
+ });
452
+ });
453
+ });
347
454
  });