@webex/common
Advanced tools
Comparing version 1.80.17 to 1.80.18
@@ -20,5 +20,8 @@ 'use strict'; | ||
var hydraBaseResource = 'ciscospark://us'; | ||
var hydraBaseUrl = 'https://api.ciscospark.com/v1'; | ||
var isRequired = function isRequired() { | ||
throw Error('parameter is required'); | ||
}; | ||
/** | ||
@@ -29,15 +32,31 @@ * Constructs a Hydra ID for a given UUID and type. | ||
* @param {string} type one of PEOPLE, TEAM, ROOM | ||
* @param {any} id | ||
* @param {any} id identifying the "TYPE" object | ||
* @param {string} cluster containing the "TYPE" object | ||
* @returns {string} | ||
*/ | ||
function constructHydraId(type, id) { | ||
return (0, _base.encode)(hydraBaseResource + '/' + type.toUpperCase() + '/' + id); | ||
function constructHydraId() { | ||
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : isRequired(); | ||
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isRequired(); | ||
var cluster = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'us'; | ||
if (!type.toUpperCase) { | ||
throw Error('"type" must be a string'); | ||
} | ||
return (0, _base.encode)('ciscospark://' + cluster + '/' + type.toUpperCase() + '/' + id); | ||
} | ||
/** | ||
* Deconstructs a Hydra ID and provides the UUID. | ||
* @typedef {Object} DeconstructedHydraId | ||
* @property {UUID} id identifying the object | ||
* @property {String} type of the object | ||
* @property {String} cluster containing the object | ||
*/ | ||
/** | ||
* Deconstructs a Hydra ID. | ||
* | ||
* @export | ||
* @param {String} id | ||
* @returns {String} | ||
* @param {String} id Hydra style id | ||
* @returns {DeconstructedHydraId} deconstructed id | ||
*/ | ||
@@ -59,6 +78,7 @@ function deconstructHydraId(id) { | ||
* @param {any} uuid | ||
* @param {string} cluster containing the message | ||
* @returns {string} | ||
*/ | ||
function buildHydraMessageId(uuid) { | ||
return constructHydraId(_constants.hydraTypes.MESSAGE, uuid); | ||
function buildHydraMessageId(uuid, cluster) { | ||
return constructHydraId(_constants.hydraTypes.MESSAGE, uuid, cluster); | ||
} | ||
@@ -71,6 +91,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the person | ||
* @returns {string} | ||
*/ | ||
function buildHydraPersonId(uuid) { | ||
return constructHydraId(_constants.hydraTypes.PEOPLE, uuid); | ||
function buildHydraPersonId(uuid, cluster) { | ||
return constructHydraId(_constants.hydraTypes.PEOPLE, uuid, cluster); | ||
} | ||
@@ -83,6 +104,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the room | ||
* @returns {string} | ||
*/ | ||
function buildHydraRoomId(uuid) { | ||
return constructHydraId(_constants.hydraTypes.ROOM, uuid); | ||
function buildHydraRoomId(uuid, cluster) { | ||
return constructHydraId(_constants.hydraTypes.ROOM, uuid, cluster); | ||
} | ||
@@ -95,6 +117,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the organization | ||
* @returns {string} | ||
*/ | ||
function buildHydraOrgId(uuid) { | ||
return constructHydraId(_constants.hydraTypes.ORGANIZATION, uuid); | ||
function buildHydraOrgId(uuid, cluster) { | ||
return constructHydraId(_constants.hydraTypes.ORGANIZATION, uuid, cluster); | ||
} | ||
@@ -109,6 +132,7 @@ | ||
* @param {any} spaceUUID | ||
* @param {string} cluster containing the membership | ||
* @returns {string} | ||
*/ | ||
function buildHydraMembershipId(personUUID, spaceUUID) { | ||
return constructHydraId(_constants.hydraTypes.MEMBERSHIP, personUUID + ':' + spaceUUID); | ||
function buildHydraMembershipId(personUUID, spaceUUID, cluster) { | ||
return constructHydraId(_constants.hydraTypes.MEMBERSHIP, personUUID + ':' + spaceUUID, cluster); | ||
} | ||
@@ -137,5 +161,6 @@ | ||
* @param {Object} activity from mercury | ||
* @param {string} cluster containing the files | ||
* @returns {Array} file URLs | ||
*/ | ||
function getHydraFiles(activity) { | ||
function getHydraFiles(activity, cluster) { | ||
var hydraFiles = []; | ||
@@ -151,3 +176,3 @@ var files = activity.object.files; | ||
for (var i = 0; i < items.length; i += 1) { | ||
var contentId = constructHydraId(_constants.hydraTypes.CONTENT, activity.id + '/' + i); | ||
var contentId = constructHydraId(_constants.hydraTypes.CONTENT, activity.id + '/' + i, cluster); | ||
@@ -154,0 +179,0 @@ hydraFiles.push(hydraBaseUrl + '/contents/' + contentId); |
{ | ||
"name": "@webex/common", | ||
"version": "1.80.17", | ||
"version": "1.80.18", | ||
"description": "Common utilities for Cisco Webex", | ||
@@ -26,3 +26,3 @@ "license": "MIT", | ||
"lodash": "^4.17.15", | ||
"@webex/common": "1.80.17", | ||
"@webex/common": "1.80.18", | ||
"backoff": "^2.5.0", | ||
@@ -29,0 +29,0 @@ "core-decorators": "^0.20.0", |
import {encode, decode} from './base64'; | ||
import {SDK_EVENT, hydraTypes} from './constants'; | ||
const hydraBaseResource = 'ciscospark://us'; | ||
const hydraBaseUrl = 'https://api.ciscospark.com/v1'; | ||
const isRequired = () => { | ||
throw Error('parameter is required'); | ||
}; | ||
/** | ||
@@ -12,15 +15,31 @@ * Constructs a Hydra ID for a given UUID and type. | ||
* @param {string} type one of PEOPLE, TEAM, ROOM | ||
* @param {any} id | ||
* @param {any} id identifying the "TYPE" object | ||
* @param {string} cluster containing the "TYPE" object | ||
* @returns {string} | ||
*/ | ||
export function constructHydraId(type, id) { | ||
return encode(`${hydraBaseResource}/${type.toUpperCase()}/${id}`); | ||
export function constructHydraId( | ||
type = isRequired(), | ||
id = isRequired(), | ||
cluster = 'us' | ||
) { | ||
if (!type.toUpperCase) { | ||
throw Error('"type" must be a string'); | ||
} | ||
return encode(`ciscospark://${cluster}/${type.toUpperCase()}/${id}`); | ||
} | ||
/** | ||
* Deconstructs a Hydra ID and provides the UUID. | ||
* @typedef {Object} DeconstructedHydraId | ||
* @property {UUID} id identifying the object | ||
* @property {String} type of the object | ||
* @property {String} cluster containing the object | ||
*/ | ||
/** | ||
* Deconstructs a Hydra ID. | ||
* | ||
* @export | ||
* @param {String} id | ||
* @returns {String} | ||
* @param {String} id Hydra style id | ||
* @returns {DeconstructedHydraId} deconstructed id | ||
*/ | ||
@@ -42,6 +61,7 @@ export function deconstructHydraId(id) { | ||
* @param {any} uuid | ||
* @param {string} cluster containing the message | ||
* @returns {string} | ||
*/ | ||
export function buildHydraMessageId(uuid) { | ||
return constructHydraId(hydraTypes.MESSAGE, uuid); | ||
export function buildHydraMessageId(uuid, cluster) { | ||
return constructHydraId(hydraTypes.MESSAGE, uuid, cluster); | ||
} | ||
@@ -54,6 +74,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the person | ||
* @returns {string} | ||
*/ | ||
export function buildHydraPersonId(uuid) { | ||
return constructHydraId(hydraTypes.PEOPLE, uuid); | ||
export function buildHydraPersonId(uuid, cluster) { | ||
return constructHydraId(hydraTypes.PEOPLE, uuid, cluster); | ||
} | ||
@@ -66,6 +87,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the room | ||
* @returns {string} | ||
*/ | ||
export function buildHydraRoomId(uuid) { | ||
return constructHydraId(hydraTypes.ROOM, uuid); | ||
export function buildHydraRoomId(uuid, cluster) { | ||
return constructHydraId(hydraTypes.ROOM, uuid, cluster); | ||
} | ||
@@ -78,6 +100,7 @@ | ||
* @param {any} uuid | ||
* @param {string} cluster containing the organization | ||
* @returns {string} | ||
*/ | ||
export function buildHydraOrgId(uuid) { | ||
return constructHydraId(hydraTypes.ORGANIZATION, uuid); | ||
export function buildHydraOrgId(uuid, cluster) { | ||
return constructHydraId(hydraTypes.ORGANIZATION, uuid, cluster); | ||
} | ||
@@ -92,7 +115,8 @@ | ||
* @param {any} spaceUUID | ||
* @param {string} cluster containing the membership | ||
* @returns {string} | ||
*/ | ||
export function buildHydraMembershipId(personUUID, spaceUUID) { | ||
export function buildHydraMembershipId(personUUID, spaceUUID, cluster) { | ||
return constructHydraId(hydraTypes.MEMBERSHIP, | ||
`${personUUID}:${spaceUUID}`); | ||
`${personUUID}:${spaceUUID}`, cluster); | ||
} | ||
@@ -121,5 +145,6 @@ | ||
* @param {Object} activity from mercury | ||
* @param {string} cluster containing the files | ||
* @returns {Array} file URLs | ||
*/ | ||
export function getHydraFiles(activity) { | ||
export function getHydraFiles(activity, cluster) { | ||
const hydraFiles = []; | ||
@@ -134,3 +159,3 @@ const {files} = activity.object; | ||
const contentId = | ||
constructHydraId(hydraTypes.CONTENT, `${activity.id}/${i}`); | ||
constructHydraId(hydraTypes.CONTENT, `${activity.id}/${i}`, cluster); | ||
@@ -137,0 +162,0 @@ hydraFiles.push(`${hydraBaseUrl}/contents/${contentId}`); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156779
3263
Updated@webex/common@1.80.18