@pageproof/sdk-pr 475.0.1669606122734 → 476.0.1669764968949

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.
@@ -14,6 +14,12 @@ declare class Accounts extends API {
14
14
  * @type {AccountsMFA}
15
15
  */
16
16
  mfa: AccountsMFA;
17
+ /**
18
+ * The Accounts Magic Links API.
19
+ *
20
+ * @type {AccountsMagicLinks}
21
+ */
22
+ magicLinks: AccountsMagicLinks;
17
23
  /** @private */
18
24
  _generateCredentials(password: any): any;
19
25
  /**
@@ -214,4 +220,5 @@ declare class Accounts extends API {
214
220
  import API from "./API";
215
221
  import AccountsSSO from "./AccountsSSO";
216
222
  import AccountsMFA from "./AccountsMFA";
223
+ import AccountsMagicLinks from "./AccountsMagicLinks";
217
224
  import Session from "../models/Session";
@@ -1 +1 @@
1
- "use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _Session=require("../models/Session");var _Session2=_interopRequireDefault(_Session);var _AccountsSSO=require("./AccountsSSO");var _AccountsSSO2=_interopRequireDefault(_AccountsSSO);var _AccountsMFA=require("./AccountsMFA");var _AccountsMFA2=_interopRequireDefault(_AccountsMFA);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var Accounts=function(_API){_inherits(Accounts,_API);function Accounts(client){_classCallCheck(this,Accounts);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.sso=new _AccountsSSO2.default(client);_this.mfa=new _AccountsMFA2.default(client);return _this}Accounts.prototype._generateCredentials=function _generateCredentials(password){var _this2=this;return this.client.crypto().generatePasswordHash(password).then(function(passwordHash){return Promise.all([passwordHash,_this2.client.crypto().generateKeyPair()])}).then(function(_ref){var passwordHash=_ref[0],keyPair=_ref[1];return Promise.all([passwordHash,keyPair,_this2.client.crypto().encryptPrivateKey(keyPair.privateKeyPEM,password)])})};Accounts.prototype.register=function register(email,password){var _this3=this;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(typeof options==="string"){console.warn("Warning: Passing the user's activation code during account creation has been moved into an options object. For compatibility reasons, the legacy behaviour still functions as expected, but please update your code as this will be changed in a future version.");options={activationCode:options}}return this._generateCredentials(password).then(function(_ref2){var passwordHash=_ref2[0],keyPair=_ref2[1],privateKeyPEM$=_ref2[2];return Promise.all([keyPair,_this3.client.request("accounts.register",{email:email,password:passwordHash,privateKey:privateKeyPEM$,publicKey:keyPair.publicKeyPEM,referrer:options.referrer})])}).then(function(_ref3){var keyPair=_ref3[0];return Promise.all([keyPair,_this3.login(email,password,undefined,false)])}).then(function(_ref4){var keyPair=_ref4[0],session=_ref4[1];return Promise.all([keyPair,session,options.activationCode?_this3.activate(options.activationCode).catch(function(){return _this3.generateActivationCode()}):_this3.generateActivationCode()])}).then(function(_ref5){var keyPair=_ref5[0],session=_ref5[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.generateActivationCode=function generateActivationCode(){return this.client.request("accounts.generate-activation-code",{userId:this.client.session.userId})};Accounts.prototype.activate=function activate(activationCode){var _this4=this;return this.client.request("accounts.activate",{userId:this.client.session.userId,authCode:activationCode}).then(function(){_this4.client.session.user.hasActivated=true})};Accounts.prototype.login=function login(email,password,totp){var _this5=this;var _decryptPrivateKey=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;return this.client.crypto().generatePasswordHash(password).then(function(passwordHash){return _this5.client.request("accounts.login",{email:email,password:passwordHash,totp:totp})}).then(function(response){var session=(new _Session2.default).fromSession(response.data);session.user.email=email;return session}).then(function(session){if(_decryptPrivateKey){return _this5.client.crypto().decryptPrivateKey(session.privateKeyPEM$,password).then(function(privateKeyPEM){session.privateKeyPEM=privateKeyPEM;return session})}return session}).then(function(session){_this5.client.setSession(session);return session})};Accounts.prototype.resetPassword=function resetPassword(_ref6){var _this6=this;var email=_ref6.email,code=_ref6.code,password=_ref6.password;return this._generateCredentials(password).then(function(_ref7){var passwordHash=_ref7[0],keyPair=_ref7[1],privateKeyPEM$=_ref7[2];return Promise.all([keyPair,_this6.client.request("accounts.reset-password",{email:email,secret:code,newPassword:passwordHash,newPrivateKey:privateKeyPEM$,newPublicKey:keyPair.publicKeyPEM})])}).then(function(_ref8){var keyPair=_ref8[0];return Promise.all([keyPair,_this6.login(email,password,undefined,false)])}).then(function(_ref9){var keyPair=_ref9[0],session=_ref9[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.forgotPassword=function forgotPassword(email){return this.client.request("accounts.forgot-password",{email:email})};Accounts.prototype.setPasswordRequest=function setPasswordRequest(email){return this.client.request("accounts.set-password-request",{email:email})};Accounts.prototype.setPassword=function setPassword(_ref10){var _this7=this;var email=_ref10.email,code=_ref10.code,password=_ref10.password;return this._generateCredentials(password).then(function(_ref11){var passwordHash=_ref11[0],keyPair=_ref11[1],privateKeyPEM$=_ref11[2];return Promise.all([keyPair,_this7.client.request("accounts.set-password",{email:email,secret:code,newPassword:passwordHash,newPrivateKey:privateKeyPEM$,newPublicKey:keyPair.publicKeyPEM})])}).then(function(_ref12){var keyPair=_ref12[0];return Promise.all([keyPair,_this7.login(email,password,undefined,false)])}).then(function(_ref13){var keyPair=_ref13[0],session=_ref13[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.logout=function logout(){var _this8=this;return this.client.request("accounts.logout").catch(function(err){_this8.client.setSession(null);return Promise.reject(err)}).then(function(){_this8.client.setSession(null)})};return Accounts}(_API3.default);exports.default=Accounts;
1
+ "use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _Session=require("../models/Session");var _Session2=_interopRequireDefault(_Session);var _AccountsSSO=require("./AccountsSSO");var _AccountsSSO2=_interopRequireDefault(_AccountsSSO);var _AccountsMFA=require("./AccountsMFA");var _AccountsMFA2=_interopRequireDefault(_AccountsMFA);var _AccountsMagicLinks=require("./AccountsMagicLinks");var _AccountsMagicLinks2=_interopRequireDefault(_AccountsMagicLinks);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var Accounts=function(_API){_inherits(Accounts,_API);function Accounts(client){_classCallCheck(this,Accounts);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.sso=new _AccountsSSO2.default(client);_this.mfa=new _AccountsMFA2.default(client);_this.magicLinks=new _AccountsMagicLinks2.default(client);return _this}Accounts.prototype._generateCredentials=function _generateCredentials(password){var _this2=this;return this.client.crypto().generatePasswordHash(password).then(function(passwordHash){return Promise.all([passwordHash,_this2.client.crypto().generateKeyPair()])}).then(function(_ref){var passwordHash=_ref[0],keyPair=_ref[1];return Promise.all([passwordHash,keyPair,_this2.client.crypto().encryptPrivateKey(keyPair.privateKeyPEM,password)])})};Accounts.prototype.register=function register(email,password){var _this3=this;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(typeof options==="string"){console.warn("Warning: Passing the user's activation code during account creation has been moved into an options object. For compatibility reasons, the legacy behaviour still functions as expected, but please update your code as this will be changed in a future version.");options={activationCode:options}}return this._generateCredentials(password).then(function(_ref2){var passwordHash=_ref2[0],keyPair=_ref2[1],privateKeyPEM$=_ref2[2];return Promise.all([keyPair,_this3.client.request("accounts.register",{email:email,password:passwordHash,privateKey:privateKeyPEM$,publicKey:keyPair.publicKeyPEM,referrer:options.referrer})])}).then(function(_ref3){var keyPair=_ref3[0];return Promise.all([keyPair,_this3.login(email,password,undefined,false)])}).then(function(_ref4){var keyPair=_ref4[0],session=_ref4[1];return Promise.all([keyPair,session,options.activationCode?_this3.activate(options.activationCode).catch(function(){return _this3.generateActivationCode()}):_this3.generateActivationCode()])}).then(function(_ref5){var keyPair=_ref5[0],session=_ref5[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.generateActivationCode=function generateActivationCode(){return this.client.request("accounts.generate-activation-code",{userId:this.client.session.userId})};Accounts.prototype.activate=function activate(activationCode){var _this4=this;return this.client.request("accounts.activate",{userId:this.client.session.userId,authCode:activationCode}).then(function(){_this4.client.session.user.hasActivated=true})};Accounts.prototype.login=function login(email,password,totp){var _this5=this;var _decryptPrivateKey=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;return this.client.crypto().generatePasswordHash(password).then(function(passwordHash){return _this5.client.request("accounts.login",{email:email,password:passwordHash,totp:totp})}).then(function(response){var session=(new _Session2.default).fromSession(response.data);session.user.email=email;return session}).then(function(session){if(_decryptPrivateKey){return _this5.client.crypto().decryptPrivateKey(session.privateKeyPEM$,password).then(function(privateKeyPEM){session.privateKeyPEM=privateKeyPEM;return session})}return session}).then(function(session){_this5.client.setSession(session);return session})};Accounts.prototype.resetPassword=function resetPassword(_ref6){var _this6=this;var email=_ref6.email,code=_ref6.code,password=_ref6.password;return this._generateCredentials(password).then(function(_ref7){var passwordHash=_ref7[0],keyPair=_ref7[1],privateKeyPEM$=_ref7[2];return Promise.all([keyPair,_this6.client.request("accounts.reset-password",{email:email,secret:code,newPassword:passwordHash,newPrivateKey:privateKeyPEM$,newPublicKey:keyPair.publicKeyPEM})])}).then(function(_ref8){var keyPair=_ref8[0];return Promise.all([keyPair,_this6.login(email,password,undefined,false)])}).then(function(_ref9){var keyPair=_ref9[0],session=_ref9[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.forgotPassword=function forgotPassword(email){return this.client.request("accounts.forgot-password",{email:email})};Accounts.prototype.setPasswordRequest=function setPasswordRequest(email){return this.client.request("accounts.set-password-request",{email:email})};Accounts.prototype.setPassword=function setPassword(_ref10){var _this7=this;var email=_ref10.email,code=_ref10.code,password=_ref10.password;return this._generateCredentials(password).then(function(_ref11){var passwordHash=_ref11[0],keyPair=_ref11[1],privateKeyPEM$=_ref11[2];return Promise.all([keyPair,_this7.client.request("accounts.set-password",{email:email,secret:code,newPassword:passwordHash,newPrivateKey:privateKeyPEM$,newPublicKey:keyPair.publicKeyPEM})])}).then(function(_ref12){var keyPair=_ref12[0];return Promise.all([keyPair,_this7.login(email,password,undefined,false)])}).then(function(_ref13){var keyPair=_ref13[0],session=_ref13[1];session.privateKeyPEM=keyPair.privateKeyPEM;return session})};Accounts.prototype.logout=function logout(){var _this8=this;return this.client.request("accounts.logout").catch(function(err){_this8.client.setSession(null);return Promise.reject(err)}).then(function(){_this8.client.setSession(null)})};return Accounts}(_API3.default);exports.default=Accounts;
@@ -0,0 +1,67 @@
1
+ export default AccountsMagicLinks;
2
+ /**
3
+ * The Accounts Magic Link API.
4
+ *
5
+ * This API is experimental. Please contact your PageProof SDK account manager for assistance.
6
+ */
7
+ declare class AccountsMagicLinks extends API {
8
+ constructor(client: any);
9
+ /** @private */
10
+ _generateNonce(): any;
11
+ /**
12
+ * Sends a magic link to the email address.
13
+ *
14
+ * This is otherwise known as a "manual login". A manual login requires the magic link to be consumed by the same
15
+ * device that generated it. The `nonce` property returned by this function should be stored locally, temporarily, and
16
+ * passed to the {@link login} function when the magic link is consumed.
17
+ *
18
+ * The nonce should never be manually transmitted over the network!
19
+ *
20
+ * The `id` property returned by this function can be used to verify the magic link was generated for the same device.
21
+ * It should match the one returned by {@link parseMagicLink}. If it doesn't - calling {@link login} will error.
22
+ *
23
+ * @param {string} email The email address to send the magic link to.
24
+ * @returns {Promise<MagicLinkRequest>}
25
+ */
26
+ send(email: string): Promise<MagicLinkRequest>;
27
+ /**
28
+ * Whether the supplied URL is a magic link URL.
29
+ *
30
+ * @param {string} url The URL to check.
31
+ * @returns {boolean}
32
+ */
33
+ isMagicLink(url: string): boolean;
34
+ /**
35
+ * Parses a URL that contains a magic link token.
36
+ *
37
+ * The `id` property may not be present if the URL was not generated for a manual login.
38
+ * The `safeUrl` property on the returning object contains the URL supplied but without the magic link parameters.
39
+ * The `requiresNonce` property tells you whether a pre-generated nonce is required for logging in.
40
+ *
41
+ * @param {string} url The URL to parse.
42
+ * @returns {MagicLinkParsedURL | null}
43
+ */
44
+ parseMagicLink(url: string): MagicLinkParsedURL;
45
+ /**
46
+ * Creates a session from a magic link.
47
+ *
48
+ * If the nonce is not supplied, a nonce will be generated on the fly. You can check whether a nonce is required by
49
+ * calling {@link parseMagicLink} and checking the `requiresNonce` property from the result.
50
+ *
51
+ * @param {string} token The magic token - parsed by calling `parseUrl`.
52
+ * @param {MagicLinkNonce} [nonce] The nonce to use to decrypt the session credentials.
53
+ * @returns {Promise<Session>}
54
+ */
55
+ getSession(token: string, maybeNonce: any): Promise<Session>;
56
+ /**
57
+ * Logs in using a magic link.
58
+ *
59
+ * @see {@link getSession} for more information.
60
+ * @param {string} token The magic token - parsed by calling `parseUrl`.
61
+ * @param {MagicLinkNonce} [nonce] The nonce to use to decrypt the session credentials.
62
+ * @returns {Promise<Session>}
63
+ */
64
+ login(token: string, nonce?: MagicLinkNonce): Promise<Session>;
65
+ }
66
+ import API from "./API";
67
+ import Session from "../models/Session";
@@ -0,0 +1 @@
1
+ "use strict";exports.__esModule=true;var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _Session=require("../models/Session");var _Session2=_interopRequireDefault(_Session);var _whatwgURL=require("../util/whatwgURL");var _whatwgURL2=_interopRequireDefault(_whatwgURL);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var ID_PARAM="mli";var TOKEN_PARAM="mlt";var SAFE_URL_EXCLUDE_PARAMS=[ID_PARAM,TOKEN_PARAM];var MAGIC_LINK_PARAM_PREFIX="ml";for(var index=97;index<=122;index+=1){SAFE_URL_EXCLUDE_PARAMS.push(MAGIC_LINK_PARAM_PREFIX+String.fromCharCode(index))}var AccountsMagicLinks=function(_API){_inherits(AccountsMagicLinks,_API);function AccountsMagicLinks(){_classCallCheck(this,AccountsMagicLinks);return _possibleConstructorReturn(this,_API.apply(this,arguments))}AccountsMagicLinks.prototype._generateNonce=function _generateNonce(){var _this2=this;return this.client.request("sso.get-public-key").then(function(response){return response.data.ServerPublicKey}).then(function(serverPublicKey){return _this2.client.crypto().generateWrappedSymmetricKey(serverPublicKey)})};AccountsMagicLinks.prototype.send=function send(email){var _this3=this;return this._generateNonce().then(function(nonce){return Promise.all([nonce,_this3.client.request("accounts.magic-links.send",{email:email,nonce:nonce.key$})])}).then(function(_ref){var nonce=_ref[0],response=_ref[1];return{id:response.data.magicLink.id,nonce:nonce}})};AccountsMagicLinks.prototype.isMagicLink=function isMagicLink(url){return this.parseMagicLink(url)!==null};AccountsMagicLinks.prototype.parseMagicLink=function parseMagicLink(url){try{var parsed=new _whatwgURL2.default(url);var id=parsed.searchParams.get(ID_PARAM)||null;var token=parsed.searchParams.get(TOKEN_PARAM);if(token){var safeUrl=new _whatwgURL2.default(url);SAFE_URL_EXCLUDE_PARAMS.forEach(function(param){return safeUrl.searchParams.delete(param)});return{id:id,token:token,safeUrl:safeUrl.toString(),requiresNonce:id!==null}}}catch(err){}return null};AccountsMagicLinks.prototype.getSession=function getSession(token,maybeNonce){var _this4=this;if(typeof token!=="string"){return Promise.reject(new Error("Magic token must be a string - got "+(typeof token==="undefined"?"undefined":_typeof(token))+"."))}var noncePromise=maybeNonce?Promise.resolve(maybeNonce):this._generateNonce();return noncePromise.then(function(nonce){if(!nonce||typeof nonce.key!=="string"||typeof nonce.key$!=="string"){throw new Error("Invalid nonce supplied.")}return Promise.all([nonce,_this4.client.request("accounts.magic-links.login",{token:token,nonce:nonce.key$})])}).then(function(_ref2){var nonce=_ref2[0],response=_ref2[1];var session=(new _Session2.default).fromSession(response.data.session);return Promise.all([session,_this4.client.crypto().decryptManagedPrivateKey(session.privateKeyPEM$,nonce.key)])}).then(function(_ref3){var session=_ref3[0],privateKeyPEM=_ref3[1];session.privateKeyPEM=privateKeyPEM;return session})};AccountsMagicLinks.prototype.login=function login(token,nonce){var _this5=this;return this.getSession(token,nonce).then(function(session){return _this5.client.setSession(session)})};return AccountsMagicLinks}(_API3.default);exports.default=AccountsMagicLinks;
@@ -433,20 +433,6 @@ declare class Workflows extends API {
433
433
  _setWorkflowStepUsersMutate(workflowId: any, workflowStep: any, users: any, start: any): any;
434
434
  /** @private */
435
435
  _addProofOwnerToWorkflowTemplate(workflowId: any, user: any): any;
436
- /**
437
- * Loads all the emails attached to the user's own workflow templates
438
- * Returns workflow id and emails array
439
- *
440
- * @private
441
- */
442
- _getOwnedEmailList(): any;
443
- /**
444
- * Loads all the emails attached to the workflow templates.
445
- * Returns workflow id and emails array
446
- *
447
- * @private
448
- */
449
- _getSharedEmailList(): any;
450
436
  }
451
437
  import API from "./API";
452
438
  import WorkflowsSteps from "./WorkflowsSteps";
@@ -1 +1 @@
1
- "use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _Workflow=require("../models/Workflow");var _Workflow2=_interopRequireDefault(_Workflow);var _WorkflowStep=require("../models/WorkflowStep");var _WorkflowStep2=_interopRequireDefault(_WorkflowStep);var _WorkflowUser=require("../models/WorkflowUser");var _WorkflowUser2=_interopRequireDefault(_WorkflowUser);var _id=require("../util/id");var _WorkflowsSteps=require("./WorkflowsSteps");var _WorkflowsSteps2=_interopRequireDefault(_WorkflowsSteps);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}function hasEnoughUserDetails(workflowUser){return workflowUser&&((0,_id.isUserId)(workflowUser.id)||workflowUser.email)}function transformWorkflows(workflows){return(workflows||[]).map(function(workflowData){return(new _Workflow2.default).fromWorkflow(workflowData)})}var Workflows=function(_API){_inherits(Workflows,_API);function Workflows(client){_classCallCheck(this,Workflows);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.steps=new _WorkflowsSteps2.default(client);return _this}Workflows.prototype.create=function create(_ref){var _this2=this;var _ref$save=_ref.save,save=_ref$save===undefined?false:_ref$save,name=_ref.name,_ref$steps=_ref.steps,_steps=_ref$steps===undefined?[]:_ref$steps,reviewers=_ref.reviewers,approver=_ref.approver,owners=_ref.owners,_ref$isOwnedByTeam=_ref.isOwnedByTeam,isOwnedByTeam=_ref$isOwnedByTeam===undefined?false:_ref$isOwnedByTeam;if(approver&&!hasEnoughUserDetails(approver)){return Promise.reject(Error("Please provide an approver id or email address."))}if(save&&!name){return Promise.reject(Error("A workflow must have a name when saving it as a workflow template."))}var steps=_steps;if(reviewers&&reviewers.length){steps.splice(0,0,{users:reviewers})}if(approver){steps.push({position:1e3,users:[approver],start:approver.start})}var largestPosition=0;for(var i=0;i<steps.length;i++){var step=steps[i];step.users=step.users||[];if(!step.position||step.position<largestPosition){step.position=largestPosition+1}largestPosition=Math.max(largestPosition,step.position);for(var ii=0;ii<step.users.length;ii++){var user=step.users[ii];if(!hasEnoughUserDetails(user)){return Promise.reject(Error("A user id or email address must be provided for a workflow user."))}}}var workflowId=void 0;return this._createWorkflow(name,isOwnedByTeam).then(function(workflow){workflowId=workflow.id;return Promise.all([workflow,Promise.all(steps.map(function(step){var workflowStep=workflow.getStepByPosition(step.position);return workflowStep?Promise.resolve(step.dueDate&&_this2.steps.update(workflowStep.id,{dueDate:step.dueDate}).then(function(updatedWorkflowStep){workflowStep.dueDate=updatedWorkflowStep.dueDate})).then(function(){return _this2._setWorkflowStepUsersMutate(workflow.id,workflowStep,step.users,step.start)}):_this2._addWorkflowStepAndUsers(workflow.id,step,step.start)})),owners&&Promise.all(owners.map(function(owner){return _this2._addProofOwnerToWorkflowTemplate(workflowId,owner)}))])}).then(function(_ref2){var workflow=_ref2[0],workflowSteps=_ref2[1];workflow.steps=workflowSteps;return workflow}).then(function(workflow){if(save){return _this2._duplicateWorkflow(workflowId)}return workflow}).catch(function(err){return Promise.resolve(workflowId&&_this2._deleteWorkflow(workflowId)).then(function(){return Promise.reject(err)})})};Workflows.prototype.load=function load(workflowId){return this.client.request("workflows.load",{workflowId:workflowId}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype.use=function use(workflowId,options){return this.duplicate(workflowId,options)};Workflows.prototype.duplicate=function duplicate(workflowId,options){return this._duplicateWorkflow(workflowId,options)};Workflows.prototype.delete=function _delete(workflowId){return this._deleteWorkflow(workflowId)};Workflows.prototype.all=function all(){return Promise.all([this.owned(),this.shared()]).then(function(_ref3){var owned=_ref3[0],shared=_ref3[1];return[].concat(owned,shared)})};Workflows.prototype.owned=function owned(){return this.client.request("workflows.owned").then(function(response){return transformWorkflows(response.data)})};Workflows.prototype.shared=function shared(){return this.client.request("workflows.shared").then(function(response){return transformWorkflows(response.data)})};Workflows.prototype.setApprover=function setApprover(workflowId,user){return this.client.request("workflows.users.set",{workflowId:workflowId,position:1e3,users:[user]})};Workflows.prototype.skipAll=function skipAll(workflowId){return this.client.request("workflows.users.skip-all",{workflowId:workflowId})};Workflows.prototype.nudgeUser=function nudgeUser(workflowId,userId){var message=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;return this.client.request("workflows.user.nudge",{workflowId:workflowId,userId:userId,message:message})};Workflows.prototype.nudgeAll=function nudgeAll(workflowIdOrIds){var message=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;return this.client.request("workflows.nudge-all",{workflowIds:[].concat(workflowIdOrIds),message:message}).then(function(response){return{nudgedWorkflows:response.data.NudgedWorkflows.map(function(nudgedWorkflow){return{workflowId:nudgedWorkflow.WorkflowId,users:nudgedWorkflow.Users.map(function(user){return{userId:user.UserId,role:user.Role,stepId:user.StepId,position:Number(user.Position)}})}}),errors:response.data.Errors.map(function(error){return{workflowId:error.WorkflowId,errorCode:error.ErrorCode,errorMessage:error.ErrorMessage}})}})};Workflows.prototype.setStartingStep=function setStartingStep(workflowId,stepId){return this.client.request("workflows.set-starting-step",{workflowId:workflowId,stepId:stepId})};Workflows.prototype.replaceApprover=function replaceApprover(workflowIdOrIds,user){return this.client.request("workflows.replace-approver",{workflowIds:[].concat(workflowIdOrIds),user:user})};Workflows.prototype.update=function update(workflowId,_ref4){var name=_ref4.name,isOwnedByTeam=_ref4.isOwnedByTeam;return this.client.request("workflows.update",{workflowId:workflowId,title:name,ownedByTeam:isOwnedByTeam}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype.getNudgeAllMessage=function getNudgeAllMessage(workflowId){return this.client.request("workflows.nudge-message",{workflowId:workflowId}).then(function(response){return response.data.Message})};Workflows.prototype.getNudgeMessage=function getNudgeMessage(workflowId,userId){return this.client.request("workflows.nudge-message",{workflowId:workflowId,userId:userId}).then(function(response){return response.data.Message})};Workflows.prototype.favorite=function favorite(workflowId){return this.client.request("workflows.favorite",{workflowId:workflowId})};Workflows.prototype.unfavorite=function unfavorite(workflowId){return this.client.request("workflows.unfavorite",{workflowId:workflowId})};Workflows.prototype._duplicateWorkflow=function _duplicateWorkflow(workflowId,options){var _this3=this;return this.client.request("workflows.duplicate",{workflowId:workflowId,noOwners:options&&options.includeOwners===false?true:undefined,excludeStepDueDates:options&&options.includeStepDueDates===false?true:undefined,includeOwnedByTeam:options&&options.includeOwnedByTeam===true||undefined,includeSharedUsers:options&&options.includeSharedUsers===true||undefined}).then(function(response){var duplicatedWorkflowId=response.data.WorkflowId;return _this3.load(duplicatedWorkflowId)})};Workflows.prototype._deleteWorkflow=function _deleteWorkflow(workflowId){return this.client.request("workflows.delete",{workflowId:workflowId})};Workflows.prototype._createWorkflow=function _createWorkflow(name,isOwnedByTeam){return this.client.request("workflows.create",{title:name,ownedByTeam:isOwnedByTeam}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype._addWorkflowStepAndUsers=function _addWorkflowStepAndUsers(workflowId,step,start){var _this4=this;return this.client.request("workflows.steps.add",{workflowId:workflowId,title:step.name,position:step.position,dueDate:step.dueDate,mandatoryDecisionThreshold:step.mandatoryDecisionThreshold}).then(function(response){var workflowStep=(new _WorkflowStep2.default).fromWorkflowStep(response.data);return _this4._setWorkflowStepUsersMutate(workflowId,workflowStep,step.users,start)})};Workflows.prototype._setWorkflowStepUsersMutate=function _setWorkflowStepUsersMutate(workflowId,workflowStep,users,start){var _this5=this;return this.client.request("workflows.users.set",{workflowId:workflowId,stepId:workflowStep.id,users:users.map(function(user){return{email:user.email,userId:user.id,role:user.role,permissions:user.permissions&&{inviter:!!user.permissions.inviter}}})}).then(function(response){var workflowUsers=response.data.map(function(user){return(new _WorkflowUser2.default).fromWorkflowUser(user)});workflowStep.users=workflowUsers}).then(function(){if(start===true){return _this5.setStartingStep(workflowId,workflowStep.id).then(function(){return workflowStep})}return workflowStep})};Workflows.prototype._addProofOwnerToWorkflowTemplate=function _addProofOwnerToWorkflowTemplate(workflowId,user){return this.client.request("workflows.proof-owners.add",{relatedId:workflowId,workflowCopyToProof:1,userId:user.id,email:user.email})};Workflows.prototype._getOwnedEmailList=function _getOwnedEmailList(){return this.client.request("workflows.owned.email-list").then(function(response){return response.data.map(function(data){return{id:data.WorkflowId,emails:data.Emails}})})};Workflows.prototype._getSharedEmailList=function _getSharedEmailList(){return this.client.request("workflows.shared.email-list").then(function(response){return response.data.map(function(data){return{id:data.WorkflowId,emails:data.Emails}})})};return Workflows}(_API3.default);exports.default=Workflows;
1
+ "use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _Workflow=require("../models/Workflow");var _Workflow2=_interopRequireDefault(_Workflow);var _WorkflowStep=require("../models/WorkflowStep");var _WorkflowStep2=_interopRequireDefault(_WorkflowStep);var _WorkflowUser=require("../models/WorkflowUser");var _WorkflowUser2=_interopRequireDefault(_WorkflowUser);var _id=require("../util/id");var _WorkflowsSteps=require("./WorkflowsSteps");var _WorkflowsSteps2=_interopRequireDefault(_WorkflowsSteps);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}function hasEnoughUserDetails(workflowUser){return workflowUser&&((0,_id.isUserId)(workflowUser.id)||workflowUser.email)}function transformWorkflows(workflows){return(workflows||[]).map(function(workflowData){return(new _Workflow2.default).fromWorkflow(workflowData)})}var Workflows=function(_API){_inherits(Workflows,_API);function Workflows(client){_classCallCheck(this,Workflows);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.steps=new _WorkflowsSteps2.default(client);return _this}Workflows.prototype.create=function create(_ref){var _this2=this;var _ref$save=_ref.save,save=_ref$save===undefined?false:_ref$save,name=_ref.name,_ref$steps=_ref.steps,_steps=_ref$steps===undefined?[]:_ref$steps,reviewers=_ref.reviewers,approver=_ref.approver,owners=_ref.owners,_ref$isOwnedByTeam=_ref.isOwnedByTeam,isOwnedByTeam=_ref$isOwnedByTeam===undefined?false:_ref$isOwnedByTeam;if(approver&&!hasEnoughUserDetails(approver)){return Promise.reject(Error("Please provide an approver id or email address."))}if(save&&!name){return Promise.reject(Error("A workflow must have a name when saving it as a workflow template."))}var steps=_steps;if(reviewers&&reviewers.length){steps.splice(0,0,{users:reviewers})}if(approver){steps.push({position:1e3,users:[approver],start:approver.start})}var largestPosition=0;for(var i=0;i<steps.length;i++){var step=steps[i];step.users=step.users||[];if(!step.position||step.position<largestPosition){step.position=largestPosition+1}largestPosition=Math.max(largestPosition,step.position);for(var ii=0;ii<step.users.length;ii++){var user=step.users[ii];if(!hasEnoughUserDetails(user)){return Promise.reject(Error("A user id or email address must be provided for a workflow user."))}}}var workflowId=void 0;return this._createWorkflow(name,isOwnedByTeam).then(function(workflow){workflowId=workflow.id;return Promise.all([workflow,Promise.all(steps.map(function(step){var workflowStep=workflow.getStepByPosition(step.position);return workflowStep?Promise.resolve(step.dueDate&&_this2.steps.update(workflowStep.id,{dueDate:step.dueDate}).then(function(updatedWorkflowStep){workflowStep.dueDate=updatedWorkflowStep.dueDate})).then(function(){return _this2._setWorkflowStepUsersMutate(workflow.id,workflowStep,step.users,step.start)}):_this2._addWorkflowStepAndUsers(workflow.id,step,step.start)})),owners&&Promise.all(owners.map(function(owner){return _this2._addProofOwnerToWorkflowTemplate(workflowId,owner)}))])}).then(function(_ref2){var workflow=_ref2[0],workflowSteps=_ref2[1];workflow.steps=workflowSteps;return workflow}).then(function(workflow){if(save){return _this2._duplicateWorkflow(workflowId)}return workflow}).catch(function(err){return Promise.resolve(workflowId&&_this2._deleteWorkflow(workflowId)).then(function(){return Promise.reject(err)})})};Workflows.prototype.load=function load(workflowId){return this.client.request("workflows.load",{workflowId:workflowId}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype.use=function use(workflowId,options){return this.duplicate(workflowId,options)};Workflows.prototype.duplicate=function duplicate(workflowId,options){return this._duplicateWorkflow(workflowId,options)};Workflows.prototype.delete=function _delete(workflowId){return this._deleteWorkflow(workflowId)};Workflows.prototype.all=function all(){return Promise.all([this.owned(),this.shared()]).then(function(_ref3){var owned=_ref3[0],shared=_ref3[1];return[].concat(owned,shared)})};Workflows.prototype.owned=function owned(){return this.client.request("workflows.owned").then(function(response){return transformWorkflows(response.data)})};Workflows.prototype.shared=function shared(){return this.client.request("workflows.shared").then(function(response){return transformWorkflows(response.data)})};Workflows.prototype.setApprover=function setApprover(workflowId,user){return this.client.request("workflows.users.set",{workflowId:workflowId,position:1e3,users:[user]})};Workflows.prototype.skipAll=function skipAll(workflowId){return this.client.request("workflows.users.skip-all",{workflowId:workflowId})};Workflows.prototype.nudgeUser=function nudgeUser(workflowId,userId){var message=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;return this.client.request("workflows.user.nudge",{workflowId:workflowId,userId:userId,message:message})};Workflows.prototype.nudgeAll=function nudgeAll(workflowIdOrIds){var message=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;return this.client.request("workflows.nudge-all",{workflowIds:[].concat(workflowIdOrIds),message:message}).then(function(response){return{nudgedWorkflows:response.data.NudgedWorkflows.map(function(nudgedWorkflow){return{workflowId:nudgedWorkflow.WorkflowId,users:nudgedWorkflow.Users.map(function(user){return{userId:user.UserId,role:user.Role,stepId:user.StepId,position:Number(user.Position)}})}}),errors:response.data.Errors.map(function(error){return{workflowId:error.WorkflowId,errorCode:error.ErrorCode,errorMessage:error.ErrorMessage}})}})};Workflows.prototype.setStartingStep=function setStartingStep(workflowId,stepId){return this.client.request("workflows.set-starting-step",{workflowId:workflowId,stepId:stepId})};Workflows.prototype.replaceApprover=function replaceApprover(workflowIdOrIds,user){return this.client.request("workflows.replace-approver",{workflowIds:[].concat(workflowIdOrIds),user:user})};Workflows.prototype.update=function update(workflowId,_ref4){var name=_ref4.name,isOwnedByTeam=_ref4.isOwnedByTeam;return this.client.request("workflows.update",{workflowId:workflowId,title:name,ownedByTeam:isOwnedByTeam}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype.getNudgeAllMessage=function getNudgeAllMessage(workflowId){return this.client.request("workflows.nudge-message",{workflowId:workflowId}).then(function(response){return response.data.Message})};Workflows.prototype.getNudgeMessage=function getNudgeMessage(workflowId,userId){return this.client.request("workflows.nudge-message",{workflowId:workflowId,userId:userId}).then(function(response){return response.data.Message})};Workflows.prototype.favorite=function favorite(workflowId){return this.client.request("workflows.favorite",{workflowId:workflowId})};Workflows.prototype.unfavorite=function unfavorite(workflowId){return this.client.request("workflows.unfavorite",{workflowId:workflowId})};Workflows.prototype._duplicateWorkflow=function _duplicateWorkflow(workflowId,options){var _this3=this;return this.client.request("workflows.duplicate",{workflowId:workflowId,noOwners:options&&options.includeOwners===false?true:undefined,excludeStepDueDates:options&&options.includeStepDueDates===false?true:undefined,includeOwnedByTeam:options&&options.includeOwnedByTeam===true||undefined,includeSharedUsers:options&&options.includeSharedUsers===true||undefined}).then(function(response){var duplicatedWorkflowId=response.data.WorkflowId;return _this3.load(duplicatedWorkflowId)})};Workflows.prototype._deleteWorkflow=function _deleteWorkflow(workflowId){return this.client.request("workflows.delete",{workflowId:workflowId})};Workflows.prototype._createWorkflow=function _createWorkflow(name,isOwnedByTeam){return this.client.request("workflows.create",{title:name,ownedByTeam:isOwnedByTeam}).then(function(response){return(new _Workflow2.default).fromWorkflow(response.data)})};Workflows.prototype._addWorkflowStepAndUsers=function _addWorkflowStepAndUsers(workflowId,step,start){var _this4=this;return this.client.request("workflows.steps.add",{workflowId:workflowId,title:step.name,position:step.position,dueDate:step.dueDate,mandatoryDecisionThreshold:step.mandatoryDecisionThreshold}).then(function(response){var workflowStep=(new _WorkflowStep2.default).fromWorkflowStep(response.data);return _this4._setWorkflowStepUsersMutate(workflowId,workflowStep,step.users,start)})};Workflows.prototype._setWorkflowStepUsersMutate=function _setWorkflowStepUsersMutate(workflowId,workflowStep,users,start){var _this5=this;return this.client.request("workflows.users.set",{workflowId:workflowId,stepId:workflowStep.id,users:users.map(function(user){return{email:user.email,userId:user.id,role:user.role,permissions:user.permissions&&{inviter:!!user.permissions.inviter}}})}).then(function(response){var workflowUsers=response.data.map(function(user){return(new _WorkflowUser2.default).fromWorkflowUser(user)});workflowStep.users=workflowUsers}).then(function(){if(start===true){return _this5.setStartingStep(workflowId,workflowStep.id).then(function(){return workflowStep})}return workflowStep})};Workflows.prototype._addProofOwnerToWorkflowTemplate=function _addProofOwnerToWorkflowTemplate(workflowId,user){return this.client.request("workflows.proof-owners.add",{relatedId:workflowId,workflowCopyToProof:1,userId:user.id,email:user.email})};return Workflows}(_API3.default);exports.default=Workflows;
@@ -14,13 +14,6 @@ declare class TeamWorkflows extends API {
14
14
  *
15
15
  */
16
16
  owned(): Promise<Workflow[]>;
17
- /**
18
- * Loads all the emails attached to the team workflow templates.
19
- * Returns workflow id and emails array
20
- *
21
- * @private
22
- */
23
- _getOwnedEmailList(): any;
24
17
  }
25
18
  import API from "../API";
26
19
  import Workflow from "../../models/Workflow";
@@ -56,25 +56,6 @@ var TeamWorkflows = function (_API) {
56
56
  });
57
57
  };
58
58
 
59
- /**
60
- * Loads all the emails attached to the team workflow templates.
61
- * Returns workflow id and emails array
62
- *
63
- * @private
64
- */
65
-
66
-
67
- TeamWorkflows.prototype._getOwnedEmailList = function _getOwnedEmailList() {
68
- return this.client.request('admin.team.workflows.owned.email-list').then(function (response) {
69
- return response.data.map(function (data) {
70
- return {
71
- id: data.WorkflowId,
72
- emails: data.Emails
73
- };
74
- });
75
- });
76
- };
77
-
78
59
  return TeamWorkflows;
79
60
  }(_API3.default);
80
61
 
@@ -692,16 +692,6 @@
692
692
  "path": "/api/workflows/share/user",
693
693
  "trailing": true
694
694
  },
695
- "workflows.owned.email-list": {
696
- "method": "GET",
697
- "path": "/api/workflows/emaillist",
698
- "trailing": true
699
- },
700
- "workflows.shared.email-list": {
701
- "method": "GET",
702
- "path": "/api/workflows/share/emaillist",
703
- "trailing": true
704
- },
705
695
  "workflows.replace-approver": {
706
696
  "version": 2,
707
697
  "method": "POST",
@@ -933,10 +923,6 @@
933
923
  "method": "GET",
934
924
  "path": "/api/admin/workflows/templates"
935
925
  },
936
- "admin.team.workflows.owned.email-list": {
937
- "method": "GET",
938
- "path": "/api/admin/workflows/emaillist"
939
- },
940
926
  "admin.team.custom-tools.load": {
941
927
  "method": "GET",
942
928
  "path": "/api/custom-tools/admin/team"
@@ -1146,6 +1132,20 @@
1146
1132
  "path": "/api/public-proofs/proof/send-share-link",
1147
1133
  "body": ["proofId", "message", "emailAddresses"]
1148
1134
  },
1135
+ "accounts.magic-links.send": {
1136
+ "version": 2,
1137
+ "method": "POST",
1138
+ "path": "/api/magic-links/request",
1139
+ "body": true,
1140
+ "anonymous": true
1141
+ },
1142
+ "accounts.magic-links.login": {
1143
+ "version": 2,
1144
+ "method": "POST",
1145
+ "path": "/api/magic-links/login",
1146
+ "body": true,
1147
+ "anonymous": true
1148
+ },
1149
1149
  "graphql": {
1150
1150
  "version": 2,
1151
1151
  "method": "POST",