@pageproof/sdk-pr 280.0.1604526415503 → 281.0.1602120194974
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 +0 -41
- package/lib/adapters/SchedulerCryptoAdapter.d.ts +1 -3
- package/lib/adapters/SchedulerCryptoAdapter.js +1 -1
- package/lib/adapters/SyncCryptoAdapter.d.ts +1 -3
- package/lib/adapters/SyncCryptoAdapter.js +1 -1
- package/lib/api/Encryption.d.ts +0 -219
- package/lib/api/Encryption.js +1 -1
- package/lib/api/Files.d.ts +2 -0
- package/lib/api/Files.js +1 -1
- package/lib/api/Profile.d.ts +0 -8
- package/lib/api/Profile.js +1 -1
- package/lib/api/Proofs.d.ts +1 -8
- package/lib/api/Proofs.js +1 -1
- package/lib/api/ProofsAssetsExtractedText.js +1 -1
- package/lib/api/ProofsCustomTools.d.ts +5 -6
- package/lib/api/Workflows.d.ts +2 -24
- package/lib/api/Workflows.js +1 -1
- package/lib/api/admin/Team.d.ts +4 -18
- package/lib/api/admin/Team.js +4 -29
- package/lib/api/admin/TeamFeatures.d.ts +0 -7
- package/lib/api/admin/TeamFeatures.js +0 -5
- package/lib/api/admin/TeamIntegrations.d.ts +10 -0
- package/lib/api/admin/{TeamWorkflows.js → TeamIntegrations.js} +16 -32
- package/lib/api/admin/TeamMondayDotCom.d.ts +15 -0
- package/lib/api/admin/{TeamCustomTools.js → TeamMondayDotCom.js} +18 -29
- package/lib/crypto/envelopes.d.ts +1 -2
- package/lib/crypto/envelopes.js +1 -1
- package/lib/crypto/index.d.ts +1 -2
- package/lib/crypto/index.js +1 -1
- package/lib/models/Proof.d.ts +0 -7
- package/lib/models/Proof.js +1 -1
- package/lib/models/TeamEmailFeatures.d.ts +1 -8
- package/lib/models/TeamEmailFeatures.js +1 -1
- package/lib/models/TeamFeatures.d.ts +0 -8
- package/lib/models/TeamFeatures.js +1 -1
- package/lib/models/Workflow.d.ts +0 -21
- package/lib/models/Workflow.js +1 -1
- package/lib/network/Request.js +1 -1
- package/lib/network/endpoints.json +4 -60
- package/lib/pageproof.js +1 -1
- package/lib/sync-crypto-adapter.js +1 -1
- package/lib/util/constants.d.ts +0 -2
- package/lib/util/constants.js +1 -1
- package/lib/worker-crypto-adapter.js +1 -1
- package/lib/worker.33813125.js +2 -0
- package/package.json +1 -1
- package/lib/api/Integrations.d.ts +0 -56
- package/lib/api/Integrations.js +0 -1
- package/lib/api/ProofsIntegrationReferences.d.ts +0 -41
- package/lib/api/ProofsIntegrationReferences.js +0 -1
- package/lib/api/admin/TeamCustomTools.d.ts +0 -22
- package/lib/api/admin/TeamWorkflows.d.ts +0 -19
- package/lib/crypto/transformFile.d.ts +0 -2
- package/lib/crypto/transformFile.js +0 -1
- package/lib/models/ProofIntegrationReference.d.ts +0 -33
- package/lib/models/ProofIntegrationReference.js +0 -1
- package/lib/models/TeamAccountFeatures.d.ts +0 -26
- package/lib/models/TeamAccountFeatures.js +0 -1
- package/lib/util/encryptionVersions.json +0 -52
- package/lib/worker.a2f0a156.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
## 2.0.0-beta.145
|
|
5
|
-
|
|
6
|
-
Released on the 2nd of November 2020.
|
|
7
|
-
|
|
8
|
-
- [[#279](https://github.com/PageProofCom/sdk/pull/279)] Added Support for sharing a workflow template with team. See [Workflows.create](https://docs.pageproof.tech/@pageproof/sdk/beta/class/src/api/Workflows.js~Workflows.html#instance-method-create) and [Workflows.update](https://docs.pageproof.tech/@pageproof/sdk/beta/class/src/api/Workflows.js~Workflows.html#instance-method-update).
|
|
9
|
-
- Added support for team admin to get team owned workflow templates [TeamWorkflows.owned](https://docs.pageproof.tech/@pageproof/sdk/beta/class/src/api/admin/TeamWorkflows.js~TeamWorkflows.html#instance-method-owned).
|
|
10
|
-
|
|
11
|
-
## 2.0.0-beta.144
|
|
12
|
-
|
|
13
|
-
Released on the 30th of October 2020.
|
|
14
|
-
|
|
15
|
-
- Support for integration references.
|
|
16
|
-
|
|
17
|
-
## 2.0.0-beta.143
|
|
18
|
-
|
|
19
|
-
Released on the 27th of October 2020.
|
|
20
|
-
|
|
21
|
-
- [[#283](https://github.com/PageProofCom/sdk/pull/283)]
|
|
22
|
-
- Support for updating whether using the team name should be used, instead of "PageProof Team" as the from name in emails. See [TeamEmailFeatures](https://docs.pageproof.tech/@pageproof/sdk/beta/class/src/models/TeamEmailFeatures.js~TeamEmailFeatures.html).
|
|
23
|
-
- Support for team account information in team admin API. see [TeamAccountFeatures](https://docs.pageproof.tech/@pageproof/sdk/beta/class/src/models/TeamAccountFeatures.js~TeamAccountFeatures.html).
|
|
24
|
-
|
|
25
|
-
## 2.0.0-beta.142
|
|
26
|
-
|
|
27
|
-
Released on the 22nd of October 2020.
|
|
28
|
-
|
|
29
|
-
- Support for team-level custom tools.
|
|
30
|
-
|
|
31
|
-
## 2.0.0-beta.141
|
|
32
|
-
|
|
33
|
-
Released on the 19th of October 2020.
|
|
34
|
-
|
|
35
|
-
- [[#270](https://github.com/PageProofCom/sdk/pull/270)] Support for retrieving configurations for services integrated with PageProof.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## 2.0.0-beta.140
|
|
39
|
-
|
|
40
|
-
Released on the 9th of October 2020.
|
|
41
|
-
|
|
42
|
-
- Minor bug fixes related to extracted text.
|
|
43
|
-
|
|
44
3
|
## 2.0.0-beta.139
|
|
45
4
|
|
|
46
5
|
Released on the 30th of September 2020.
|
|
@@ -2,7 +2,6 @@ export default SchedulerCryptoAdapter;
|
|
|
2
2
|
declare class SchedulerCryptoAdapter extends ICryptoAdapter {
|
|
3
3
|
constructor(options: any);
|
|
4
4
|
scheduler: Scheduler;
|
|
5
|
-
transformFile(direction: any, variant: any, raw: any, ioEncoding: any, envelope: any, privateKeyPEM: any, encryptionVersions: any, encryptionVersion: any): Promise<any>;
|
|
6
5
|
/**
|
|
7
6
|
* @param {string} data$ The encrypted (and encoded) data
|
|
8
7
|
* @param {string} envelope$ The envelope containing the key
|
|
@@ -65,10 +64,9 @@ declare class SchedulerCryptoAdapter extends ICryptoAdapter {
|
|
|
65
64
|
/**
|
|
66
65
|
* @param {string} secret The secret to seal within an envelope
|
|
67
66
|
* @param {Array<string>} publicKeyPEMs The list of public keys to encrypt the envelope for
|
|
68
|
-
* @param {boolean} includeEncryptionVersion Whether to include the encryption version prefix (used to create version-less envelopes)
|
|
69
67
|
* @returns {Promise<string>} The full envelope
|
|
70
68
|
*/
|
|
71
|
-
envelopeSeal(secret: string, publicKeyPEMs: string[]
|
|
69
|
+
envelopeSeal(secret: string, publicKeyPEMs: string[]): Promise<string>;
|
|
72
70
|
/**
|
|
73
71
|
* @param {string} envelope The full envelope to unseal
|
|
74
72
|
* @param {string} privateKeyPEM The user's private key (in PEM format), used to decrypt the envelope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _Scheduler=require("../util/Scheduler");var _Scheduler2=_interopRequireDefault(_Scheduler);var _ICryptoAdapter2=require("./ICryptoAdapter");var _ICryptoAdapter3=_interopRequireDefault(_ICryptoAdapter2);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 SchedulerCryptoAdapter=function(_ICryptoAdapter){_inherits(SchedulerCryptoAdapter,_ICryptoAdapter);function SchedulerCryptoAdapter(options){_classCallCheck(this,SchedulerCryptoAdapter);var _this=_possibleConstructorReturn(this,_ICryptoAdapter.call(this));_this.scheduler=new _Scheduler2.default(options);return _this}SchedulerCryptoAdapter.prototype.
|
|
1
|
+
"use strict";exports.__esModule=true;var _Scheduler=require("../util/Scheduler");var _Scheduler2=_interopRequireDefault(_Scheduler);var _ICryptoAdapter2=require("./ICryptoAdapter");var _ICryptoAdapter3=_interopRequireDefault(_ICryptoAdapter2);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 SchedulerCryptoAdapter=function(_ICryptoAdapter){_inherits(SchedulerCryptoAdapter,_ICryptoAdapter);function SchedulerCryptoAdapter(options){_classCallCheck(this,SchedulerCryptoAdapter);var _this=_possibleConstructorReturn(this,_ICryptoAdapter.call(this));_this.scheduler=new _Scheduler2.default(options);return _this}SchedulerCryptoAdapter.prototype.decryptBytes=function decryptBytes(comment$,envelope$,privateKeyPEM,before,after){return this.scheduler.send({type:"decryptBytes",args:[comment$,envelope$,privateKeyPEM,before,after]})};SchedulerCryptoAdapter.prototype.decryptComment=function decryptComment(comment$,envelope,privateKeyPEM){return this.scheduler.send({type:"decryptComment",args:[comment$,envelope,privateKeyPEM]})};SchedulerCryptoAdapter.prototype.decryptData=function decryptData(version,data$,envelope$,privateKeyPEM){return this.scheduler.send({type:"decryptData",args:[version,data$,envelope$,privateKeyPEM]})};SchedulerCryptoAdapter.prototype.decryptFileBlock=function decryptFileBlock(data$,privateKeyPEM){return this.scheduler.send({type:"decryptFileBlock",args:[data$,privateKeyPEM]})};SchedulerCryptoAdapter.prototype.decryptImage=function decryptImage(data$,privateKeyPEM){return this.scheduler.send({type:"decryptImage",args:[data$,privateKeyPEM]})};SchedulerCryptoAdapter.prototype.decryptPrivateKey=function decryptPrivateKey(privateKey$,password){return this.scheduler.send({type:"decryptPrivateKey",args:[privateKey$,password]})};SchedulerCryptoAdapter.prototype.encryptFileBlock=function encryptFileBlock(keyIV,fileBlock,decodeBlock){return this.scheduler.send({type:"encryptFileBlock",args:[keyIV,fileBlock,decodeBlock]})};SchedulerCryptoAdapter.prototype.encryptPrivateKey=function encryptPrivateKey(privateKeyPEM,password){return this.scheduler.send({type:"encryptPrivateKey",args:[privateKeyPEM,password]})};SchedulerCryptoAdapter.prototype.envelopeSeal=function envelopeSeal(secret,publicKeyPEMs){return this.scheduler.send({type:"envelopeSeal",args:[secret,publicKeyPEMs]})};SchedulerCryptoAdapter.prototype.envelopeUnseal=function envelopeUnseal(envelope,privateKeyPEM){return this.scheduler.send({type:"envelopeUnseal",args:[envelope,privateKeyPEM]})};SchedulerCryptoAdapter.prototype.generateAuthorizationHeaders=function generateAuthorizationHeaders(method,path,session){return this.scheduler.send({type:"generateAuthorizationHeaders",args:[method,path,session]})};SchedulerCryptoAdapter.prototype.generateKeyIV=function generateKeyIV(){return this.scheduler.send({type:"generateKeyIV"})};SchedulerCryptoAdapter.prototype.generateKeyPair=function generateKeyPair(){return this.scheduler.send({type:"generateKeyPair"})};SchedulerCryptoAdapter.prototype.generatePasswordHash=function generatePasswordHash(password){return this.scheduler.send({type:"generatePasswordHash",args:[password]})};SchedulerCryptoAdapter.prototype.generateWrappedSymmetricKey=function generateWrappedSymmetricKey(serverPublicKeyPEM){return this.scheduler.send({type:"generateWrappedSymmetricKey",args:[serverPublicKeyPEM]})};SchedulerCryptoAdapter.prototype.decryptManagedPrivateKey=function decryptManagedPrivateKey(privateKey$,keyBase64){return this.scheduler.send({type:"decryptManagedPrivateKey",args:[privateKey$,keyBase64]})};SchedulerCryptoAdapter.prototype.encryptComment=function encryptComment(comment,publicKeyPEMs){return this.scheduler.send({type:"encryptComment",args:[comment,publicKeyPEMs]})};return SchedulerCryptoAdapter}(_ICryptoAdapter3.default);exports.default=SchedulerCryptoAdapter;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export default SyncCryptoAdapter;
|
|
2
2
|
declare class SyncCryptoAdapter extends ICryptoAdapter {
|
|
3
|
-
transformFile(direction: any, variant: any, raw: any, ioEncoding: any, envelope: any, privateKeyPEM: any, encryptionVersions: any, encryptionVersion: any): any;
|
|
4
3
|
/**
|
|
5
4
|
* @param {string} data$ The encrypted (and encoded) data
|
|
6
5
|
* @param {string} envelope$ The envelope containing the key
|
|
@@ -56,10 +55,9 @@ declare class SyncCryptoAdapter extends ICryptoAdapter {
|
|
|
56
55
|
/**
|
|
57
56
|
* @param {string} secret The secret to seal within an envelope
|
|
58
57
|
* @param {Array<string>} publicKeyPEMs The list of public keys to encrypt the envelope for
|
|
59
|
-
* @param {boolean} includeEncryptionVersion Whether to include the encryption version prefix (used to create version-less envelopes)
|
|
60
58
|
* @returns {Promise<string>} The full envelope
|
|
61
59
|
*/
|
|
62
|
-
envelopeSeal(secret: string, publicKeyPEMs: string[]
|
|
60
|
+
envelopeSeal(secret: string, publicKeyPEMs: string[]): Promise<string>;
|
|
63
61
|
/**
|
|
64
62
|
* @param {string} envelope The full envelope to unseal
|
|
65
63
|
* @param {string} privateKeyPEM The user's private key (in PEM format), used to decrypt the envelope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _ICryptoAdapter2=require("./ICryptoAdapter");var _ICryptoAdapter3=_interopRequireDefault(_ICryptoAdapter2);var _crypto=require("../crypto");var crypto=_interopRequireWildcard(_crypto);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}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 SyncCryptoAdapter=function(_ICryptoAdapter){_inherits(SyncCryptoAdapter,_ICryptoAdapter);function SyncCryptoAdapter(){_classCallCheck(this,SyncCryptoAdapter);return _possibleConstructorReturn(this,_ICryptoAdapter.apply(this,arguments))}SyncCryptoAdapter.prototype.
|
|
1
|
+
"use strict";exports.__esModule=true;var _ICryptoAdapter2=require("./ICryptoAdapter");var _ICryptoAdapter3=_interopRequireDefault(_ICryptoAdapter2);var _crypto=require("../crypto");var crypto=_interopRequireWildcard(_crypto);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key]}}newObj.default=obj;return newObj}}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 SyncCryptoAdapter=function(_ICryptoAdapter){_inherits(SyncCryptoAdapter,_ICryptoAdapter);function SyncCryptoAdapter(){_classCallCheck(this,SyncCryptoAdapter);return _possibleConstructorReturn(this,_ICryptoAdapter.apply(this,arguments))}SyncCryptoAdapter.prototype.decryptBytes=function decryptBytes(comment$,envelope$,privateKeyPEM,before,after){return crypto.decryptBytes(comment$,envelope$,privateKeyPEM,before,after)};SyncCryptoAdapter.prototype.decryptComment=function decryptComment(comment$,envelope,privateKeyPEM){return crypto.decryptComment(comment$,envelope,privateKeyPEM)};SyncCryptoAdapter.prototype.decryptData=function decryptData(version,data$,envelope$,privateKeyPEM){return crypto.decryptData(version,data$,envelope$,privateKeyPEM)};SyncCryptoAdapter.prototype.decryptImage=function decryptImage(data$,privateKeyPEM){return crypto.decryptImage(data$,privateKeyPEM)};SyncCryptoAdapter.prototype.decryptPrivateKey=function decryptPrivateKey(privateKey$,password){return crypto.decryptPrivateKey(privateKey$,password)};SyncCryptoAdapter.prototype.encryptFileBlock=function encryptFileBlock(keyIV,fileBlock,decodeBlock){return crypto.encryptFileBlock(keyIV,fileBlock,decodeBlock)};SyncCryptoAdapter.prototype.encryptPrivateKey=function encryptPrivateKey(privateKeyPEM,password){return crypto.encryptPrivateKey(privateKeyPEM,password)};SyncCryptoAdapter.prototype.envelopeSeal=function envelopeSeal(secret,publicKeyPEMs){return crypto.envelopeSeal(secret,publicKeyPEMs)};SyncCryptoAdapter.prototype.envelopeUnseal=function envelopeUnseal(envelope,privateKeyPEM){return crypto.envelopeUnseal(envelope,privateKeyPEM)};SyncCryptoAdapter.prototype.generateAuthorizationHeaders=function generateAuthorizationHeaders(method,path,session){return crypto.generateAuthorizationHeaders(method,path,session)};SyncCryptoAdapter.prototype.generateKeyIV=function generateKeyIV(){return crypto.generateKeyIV()};SyncCryptoAdapter.prototype.generateKeyPair=function generateKeyPair(){return crypto.generateKeyPair()};SyncCryptoAdapter.prototype.generatePasswordHash=function generatePasswordHash(password){return crypto.generatePasswordHash(password)};SyncCryptoAdapter.prototype.generateWrappedSymmetricKey=function generateWrappedSymmetricKey(serverPublicKeyPEM){return crypto.generateWrappedSymmetricKey(serverPublicKeyPEM)};SyncCryptoAdapter.prototype.decryptManagedPrivateKey=function decryptManagedPrivateKey(privateKey$,keyBase64){return crypto.decryptManagedPrivateKey(privateKey$,keyBase64)};SyncCryptoAdapter.prototype.encryptComment=function encryptComment(comment,publicKeyPEMs){return crypto.encryptComment(comment,publicKeyPEMs)};return SyncCryptoAdapter}(_ICryptoAdapter3.default);exports.default=SyncCryptoAdapter;
|
package/lib/api/Encryption.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ declare class Encryption extends API {
|
|
|
15
15
|
* const image = URL.createObjectURL(thumbnail);
|
|
16
16
|
* document.querySelector('#thumbnail').src = image;
|
|
17
17
|
*
|
|
18
|
-
* @deprecated Use Encryption.decryptFileThumbnail or similar.
|
|
19
18
|
* @param {object} options
|
|
20
19
|
* @param {number} options.version The encryption version number
|
|
21
20
|
* @param {Buffer|Blob} options.data The data to decrypt (Blob or Buffer depending on the platform)
|
|
@@ -26,223 +25,5 @@ declare class Encryption extends API {
|
|
|
26
25
|
data: Blob | Buffer;
|
|
27
26
|
envelope: string;
|
|
28
27
|
}): any;
|
|
29
|
-
/**
|
|
30
|
-
* Generates an encryption key for a file.
|
|
31
|
-
*
|
|
32
|
-
* This method outputs the encryption version (encryptionVersion) and envelope - both of which are used in the encryption process.
|
|
33
|
-
*
|
|
34
|
-
* Note: Omitting the encryption version argument will result in the default encryption version your version of the SDK specifies.
|
|
35
|
-
*
|
|
36
|
-
* Note: When manually specifying an encryption version (by hard coding it), it's important you understand the implications that has on how the file is encrypted.
|
|
37
|
-
*
|
|
38
|
-
* @example <caption>Generating a file encryption key (using the default encryption version)</caption>
|
|
39
|
-
* const { encryptionVersion, envelope } = await client.encryption.generateFileEnvelope();
|
|
40
|
-
* console.log(encryptionVersion); // eg. "0001"
|
|
41
|
-
*
|
|
42
|
-
* @param {string} [encryptionVersion] The encryption version used when encrypting the file
|
|
43
|
-
* @returns {Promise<{ encryptionVersion: string, envelope: string | null, keyIV: { key: string, iv: string } | null }>}
|
|
44
|
-
*/
|
|
45
|
-
generateFileEnvelope(encryptionVersion?: string): Promise<{
|
|
46
|
-
encryptionVersion: string;
|
|
47
|
-
envelope: string;
|
|
48
|
-
keyIV: {
|
|
49
|
-
key: string;
|
|
50
|
-
iv: string;
|
|
51
|
-
};
|
|
52
|
-
}>;
|
|
53
|
-
/** @private */
|
|
54
|
-
_transformFile(variant: any, data: any, envelopeOrKeyIV: any, encryptionVersion: any, reverse?: boolean): any;
|
|
55
|
-
/**
|
|
56
|
-
* Encrypts a thumbnail (for a file).
|
|
57
|
-
*
|
|
58
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the thumbnail.
|
|
59
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the thumbnail.
|
|
60
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) thumbnail data.
|
|
61
|
-
* @returns {Buffer|Blob}
|
|
62
|
-
*/
|
|
63
|
-
encryptFileThumbnail(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
64
|
-
key: string;
|
|
65
|
-
iv: string;
|
|
66
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
67
|
-
/**
|
|
68
|
-
* Decrypts a thumbnail (for a file).
|
|
69
|
-
*
|
|
70
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the thumbnail.
|
|
71
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the thumbnail.
|
|
72
|
-
* @param {Buffer|Blob} data The encrypted thumbnail data.
|
|
73
|
-
* @returns {Buffer|Blob}
|
|
74
|
-
*/
|
|
75
|
-
decryptFileThumbnail(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
76
|
-
key: string;
|
|
77
|
-
iv: string;
|
|
78
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
79
|
-
/**
|
|
80
|
-
* Encrypts a sprite sheet (for a file).
|
|
81
|
-
*
|
|
82
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the sprite sheet.
|
|
83
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the sprite sheet.
|
|
84
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) sprite sheet data.
|
|
85
|
-
* @returns {Buffer|Blob}
|
|
86
|
-
*/
|
|
87
|
-
encryptFileSpriteSheet(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
88
|
-
key: string;
|
|
89
|
-
iv: string;
|
|
90
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
91
|
-
/**
|
|
92
|
-
* Decrypts a sprite sheet (for a file).
|
|
93
|
-
*
|
|
94
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the sprite sheet.
|
|
95
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the sprite sheet.
|
|
96
|
-
* @param {Buffer|Blob} data The encrypted sprite sheet data.
|
|
97
|
-
* @returns {Buffer|Blob}
|
|
98
|
-
*/
|
|
99
|
-
decryptFileSpriteSheet(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
100
|
-
key: string;
|
|
101
|
-
iv: string;
|
|
102
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
103
|
-
/**
|
|
104
|
-
* Encrypts a low resolution preview (for a file).
|
|
105
|
-
*
|
|
106
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the low resolution preview.
|
|
107
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the low resolution preview.
|
|
108
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) low resolution preview data.
|
|
109
|
-
* @returns {Buffer|Blob}
|
|
110
|
-
*/
|
|
111
|
-
encryptFilePreviewLow(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
112
|
-
key: string;
|
|
113
|
-
iv: string;
|
|
114
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
115
|
-
/**
|
|
116
|
-
* Decrypts a low resolution preview (for a file).
|
|
117
|
-
*
|
|
118
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the low resolution preview.
|
|
119
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the low resolution preview.
|
|
120
|
-
* @param {Buffer|Blob} data The encrypted low resolution preview data.
|
|
121
|
-
* @returns {Buffer|Blob}
|
|
122
|
-
*/
|
|
123
|
-
decryptFilePreviewLow(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
124
|
-
key: string;
|
|
125
|
-
iv: string;
|
|
126
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
127
|
-
/**
|
|
128
|
-
* Encrypts a high resolution preview (for a file).
|
|
129
|
-
*
|
|
130
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the high resolution preview.
|
|
131
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the high resolution preview.
|
|
132
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) high resolution preview data.
|
|
133
|
-
* @returns {Buffer|Blob}
|
|
134
|
-
*/
|
|
135
|
-
encryptFilePreviewHigh(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
136
|
-
key: string;
|
|
137
|
-
iv: string;
|
|
138
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
139
|
-
/**
|
|
140
|
-
* Decrypts a high resolution preview (for a file).
|
|
141
|
-
*
|
|
142
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the high resolution preview.
|
|
143
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the high resolution preview.
|
|
144
|
-
* @param {Buffer|Blob} data The encrypted sprite sheet data.
|
|
145
|
-
* @returns {Buffer|Blob}
|
|
146
|
-
*/
|
|
147
|
-
decryptFilePreviewHigh(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
148
|
-
key: string;
|
|
149
|
-
iv: string;
|
|
150
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
151
|
-
/**
|
|
152
|
-
* Encrypts a chunk of original contents (for a file).
|
|
153
|
-
*
|
|
154
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the chunk of original contents.
|
|
155
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the chunk of original contents.
|
|
156
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) chunk of original contents data.
|
|
157
|
-
* @returns {Buffer|Blob}
|
|
158
|
-
*/
|
|
159
|
-
encryptFileContentsPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
160
|
-
key: string;
|
|
161
|
-
iv: string;
|
|
162
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
163
|
-
/**
|
|
164
|
-
* Decrypts a chunk of original contents (for a file).
|
|
165
|
-
*
|
|
166
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the chunk of original contents.
|
|
167
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the chunk of original contents.
|
|
168
|
-
* @param {Buffer|Blob} data The encrypted chunk of original contents data.
|
|
169
|
-
* @returns {Buffer|Blob}
|
|
170
|
-
*/
|
|
171
|
-
decryptFileContentsPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
172
|
-
key: string;
|
|
173
|
-
iv: string;
|
|
174
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
175
|
-
/**
|
|
176
|
-
* Encrypts a chunk of extracted text (for a file).
|
|
177
|
-
*
|
|
178
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the chunk of extracted text.
|
|
179
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the chunk of extracted text.
|
|
180
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) chunk of extracted text data.
|
|
181
|
-
* @returns {Buffer|Blob}
|
|
182
|
-
*/
|
|
183
|
-
encryptFileExtractedTextPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
184
|
-
key: string;
|
|
185
|
-
iv: string;
|
|
186
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
187
|
-
/**
|
|
188
|
-
* Decrypts a chunk of extracted text (for a file).
|
|
189
|
-
*
|
|
190
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the chunk of extracted text.
|
|
191
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the chunk of extracted text.
|
|
192
|
-
* @param {Buffer|Blob} data The encrypted chunk of extracted text data.
|
|
193
|
-
* @returns {Buffer|Blob}
|
|
194
|
-
*/
|
|
195
|
-
decryptFileExtractedTextPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
196
|
-
key: string;
|
|
197
|
-
iv: string;
|
|
198
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
199
|
-
/**
|
|
200
|
-
* Encrypts a upload chunk (for a file).
|
|
201
|
-
*
|
|
202
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the upload chunk.
|
|
203
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the upload chunk.
|
|
204
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) upload chunk data.
|
|
205
|
-
* @returns {Buffer|Blob}
|
|
206
|
-
*/
|
|
207
|
-
encryptFileUploadPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
208
|
-
key: string;
|
|
209
|
-
iv: string;
|
|
210
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
211
|
-
/**
|
|
212
|
-
* Decrypts a upload chunk (for a file).
|
|
213
|
-
*
|
|
214
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the upload chunk.
|
|
215
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the upload chunk.
|
|
216
|
-
* @param {Buffer|Blob} data The encrypted upload chunk data.
|
|
217
|
-
* @returns {Buffer|Blob}
|
|
218
|
-
*/
|
|
219
|
-
decryptFileUploadPerChunk(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
220
|
-
key: string;
|
|
221
|
-
iv: string;
|
|
222
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
223
|
-
/**
|
|
224
|
-
* Encrypts a rendition (for a file).
|
|
225
|
-
*
|
|
226
|
-
* @param {string} encryptionVersion The encryption version used to encrypt the rendition.
|
|
227
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to encrypt the rendition.
|
|
228
|
-
* @param {Buffer|Blob} data The raw (un-encrypted) rendition data.
|
|
229
|
-
* @returns {Buffer|Blob}
|
|
230
|
-
*/
|
|
231
|
-
encryptFileRendition(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
232
|
-
key: string;
|
|
233
|
-
iv: string;
|
|
234
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
235
|
-
/**
|
|
236
|
-
* Decrypts a rendition (for a file).
|
|
237
|
-
*
|
|
238
|
-
* @param {string} encryptionVersion The encryption version used to decrypt the rendition.
|
|
239
|
-
* @param {string|{ key: string, iv: string }|null} envelopeOrKeyIV The envelope (or key IV object) used to decrypt the rendition.
|
|
240
|
-
* @param {Buffer|Blob} data The encrypted rendition data.
|
|
241
|
-
* @returns {Buffer|Blob}
|
|
242
|
-
*/
|
|
243
|
-
decryptFileRendition(encryptionVersion: string, envelopeOrKeyIV: string | {
|
|
244
|
-
key: string;
|
|
245
|
-
iv: string;
|
|
246
|
-
}, data: Blob | Buffer): Blob | Buffer;
|
|
247
28
|
}
|
|
248
29
|
import API from "./API";
|
package/lib/api/Encryption.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);
|
|
1
|
+
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);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 Encryption=function(_API){_inherits(Encryption,_API);function Encryption(){_classCallCheck(this,Encryption);return _possibleConstructorReturn(this,_API.apply(this,arguments))}Encryption.prototype.decrypt=function decrypt(_ref){var _this2=this;var version=_ref.version,data=_ref.data,envelope=_ref.envelope;var bluffer=new _bluffer2.default;var content=typeof data==="string"?bluffer.create(data):Promise.resolve(data);return content.then(function(content$){return bluffer.read(content$).then(function(data$){return _this2.client.crypto().decryptData(version,data$,envelope,_this2.client.session.privateKeyPEM).then(function(decrypted){return bluffer.create(decrypted)})})})};return Encryption}(_API3.default);exports.default=Encryption;
|
package/lib/api/Files.d.ts
CHANGED
package/lib/api/Files.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _File=require("../models/File");var _File2=_interopRequireDefault(_File);var _FileStatus=require("../enum/FileStatus");var _FileStatus2=_interopRequireDefault(_FileStatus);var _ImportProvider=require("../enum/ImportProvider");var _ImportProvider2=_interopRequireDefault(_ImportProvider);var _streamBlocks=require("../util/streamBlocks");var _streamBlocks2=_interopRequireDefault(_streamBlocks);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);var _getContentLength=require("../util/getContentLength");var _getContentLength2=_interopRequireDefault(_getContentLength);var _constants=require("../util/constants");var _throttle=require("../util/throttle");var _throttle2=_interopRequireDefault(_throttle);var _concurrent=require("../util/concurrent");var _concurrent2=_interopRequireDefault(_concurrent);var _whatwgURL=require("../util/whatwgURL");var _whatwgURL2=_interopRequireDefault(_whatwgURL);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target}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 parseFilename(filename){var extensionIndex=filename.lastIndexOf(".");var name=filename.substring(0,extensionIndex);var extension=filename.substring(extensionIndex+1);return{name:name,extension:extension}}function containPercentage(percent,left,right){var total=1-(left+right);return total*percent+left}var Files=function(_API){_inherits(Files,_API);function Files(){_classCallCheck(this,Files);return _possibleConstructorReturn(this,_API.apply(this,arguments))}Files.prototype.generateToken=function generateToken(assignedTo,assignedType){if(assignedTo&&!assignedType){return Promise.reject(Error('The "assignedType" option is required when specifying the "assignedTo" option.'))}if(!assignedTo&&assignedType){return Promise.reject(Error('The "assignedTo" option is required when specifying the "assignedType" option.'))}return this.client.request("files.legacy.generate-token",{relatedId:assignedTo,fileType:assignedType}).then(function(response){return response.data.Token})};Files.prototype.setCanDownload=function setCanDownload(fileId,canDownload){return this.client.request("files.can-download.update",{fileId:fileId,downloadOriginal:canDownload?1:0})};Files.prototype._waitFileProcessed=function _waitFileProcessed(id){var _this2=this;return new Promise(function(resolve,reject){var checkTimeout=null;var timeoutTimeout=null;var check=function check(){_this2.details(id).then(function(file){checkTimeout=null;switch(file.status){case _FileStatus2.default.OK:{resolve(file);break}case _FileStatus2.default.ERROR:{reject(new Error("File "+id+" encountered a processing error: "+file.message));break}default:{checkTimeout=setTimeout(check,5e3);break}}if(!checkTimeout||file.status===_FileStatus2.default.RIPPING){clearTimeout(timeoutTimeout)}}).catch(reject)};check();timeoutTimeout=setTimeout(function(){clearTimeout(checkTimeout);reject(new Error("File did not finish processing within specified duration."))},3e4)})};Files.prototype._createWebsiteFile=function _createWebsiteFile(url){var _this3=this;return this._generateKeyIVEnvelope().then(function(_ref){var envelope=_ref.envelope;return _this3.client.request("files.import.web",{url:url,envelope:envelope})}).then(function(response){return response.data})};Files.prototype._importFileFromUrl=function _importFileFromUrl(_ref2){var _this4=this;var name=_ref2.name,url=_ref2.url,provider=_ref2.provider,auth=_ref2.auth,download=_ref2.download;var endpoint=provider;if(provider===_ImportProvider2.default.NONE){endpoint="generic"}var _parseFilename=parseFilename(name),filename=_parseFilename.name,extension=_parseFilename.extension;return this._generateKeyIVEnvelope().then(function(_ref3){var envelope=_ref3.envelope;return _this4.client.request("files.import."+endpoint,{extn:extension,filename:filename,url:url,envelope:envelope,accessToken:auth,storeOriginal:download})}).then(function(response){return response.data})};Files.prototype.import=function _import(_ref4){var _this5=this;var name=_ref4.name,url=_ref4.url,_ref4$provider=_ref4.provider,provider=_ref4$provider===undefined?_ImportProvider2.default.NONE:_ref4$provider,auth=_ref4.auth,_ref4$download=_ref4.download,download=_ref4$download===undefined?false:_ref4$download,_ref4$process=_ref4.process,process=_ref4$process===undefined?false:_ref4$process;var providerSupported=Object.keys(_ImportProvider2.default).some(function(key){return _ImportProvider2.default[key]===provider});if(!providerSupported){return Promise.reject(new Error('Unsupported provider "'+provider+'"'))}return(provider===_ImportProvider2.default.WEBSITE?this._createWebsiteFile(url):this._importFileFromUrl({name:name,url:url,provider:provider,auth:auth,download:download})).then(function(token){if(process){return _this5._waitFileProcessed(token)}else{var file=new _File2.default;file.id=token;return file}})};Files.prototype.email=function email(){return this.client.request("files.create-email").then(function(response){return response.data})};Files.prototype._generateKeyIVEnvelope=function _generateKeyIVEnvelope(){var _this6=this;return this.client.crypto().generateKeyIV().then(function(keyIV){return Promise.all([keyIV,_this6.client.crypto().envelopeSeal(keyIV.keyIV,[_this6.client.session.serverPublicKeyPEM,_this6.client.session.publicKeyPEM])])}).then(function(_ref5){var keyIV=_ref5[0],envelope=_ref5[1];return{keyIV:keyIV,envelope:envelope}})};Files.prototype.upload=function upload(){return this.upload__v2.apply(this,arguments)};Files.prototype.upload__v2=function upload__v2(files){var _this7=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _options$concurrent=options.concurrent,concurrency=_options$concurrent===undefined?6:_options$concurrent,opts=_objectWithoutProperties(options,["concurrent"]);var scheduleChunk=(0,_concurrent2.default)(concurrency);var scheduleDone=(0,_concurrent2.default)(1);var doneFiles=[];var multipleFiles=Array.isArray(files);var filesList=multipleFiles?files:[files];var done=function done(result){doneFiles.push(result);return scheduleDone(function(){if(doneFiles.length){var _doneFiles=doneFiles.slice();doneFiles.length=0;return _this7.client.request("files.v2.upload-complete",{files:_doneFiles})}return null})};return this.client.request("files.v2.generate-credentials",{supports:{providers:["abs","custom"]},files:filesList.map(function(file){var name=void 0;var extension=void 0;if(file.extension){var _ref6=[file.name,file.extension];name=_ref6[0];extension=_ref6[1]}else{var parsed=parseFilename(file.name);var _ref7=[parsed.name,parsed.extension];name=_ref7[0];extension=_ref7[1]}var size=(0,_getContentLength2.default)(file.contents);var chunks=Math.ceil(size/_constants.BYTES_PER_BLOCK);if(file.onProgress){file.onProgress(0)}return{name:name,extension:extension,chunks:chunks,size:size,hash:null,adobeExportData:file.adobeExportData?JSON.stringify(file.adobeExportData):null,assignedTo:file.assignedTo,assignedType:file.assignedType,canDownload:typeof file.download!=="undefined"?!!file.download:true}})}).then(function(response){return Promise.all(filesList.map(function(file,index){var definition=response.data[index];if(file.onProgress){file.onProgress(1)}return _this7._upload__v2(file,definition,opts,scheduleChunk,done).then(function(){var entity=new _File2.default;entity.id=definition.FileId;return entity})}))}).then(function(results){return multipleFiles?results:results[0]})};Files.prototype._upload__v2=function _upload__v2(file,definition,options,schedule,done){var _this8=this;return this._generateKeyIVEnvelope().then(function(_ref8){var keyIV=_ref8.keyIV,envelope=_ref8.envelope;return new Promise(function(resolve){var fileId=definition.FileId,uploadCredentials=definition.UploadCredentials;var bluffer=new _bluffer2.default;var complete=false;var index=0;var blocks=(0,_streamBlocks2.default)(file.contents,function(b){return bluffer.readBase64(b)});var tasks=[];var count=Math.ceil((0,_getContentLength2.default)(file.contents)/_constants.BYTES_PER_BLOCK);var percent=new Array(count);var lastPercent=1;var onUploadProgress=function onUploadProgress(){};var onProgress=file.onProgress;if(onProgress){onUploadProgress=function onUploadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);var totalPercent=containPercentage(percent.reduce(function(a,b){return a+(b||0)},0)/count/100,.01,.01)*100;if(typeof options.progressDecimalPlaces!=="undefined"){totalPercent=+totalPercent.toFixed(options.progressDecimalPlaces)}if(lastPercent!==totalPercent){onProgress(totalPercent);lastPercent=totalPercent}}}function handle(block,blockIndex){var task=encryptAndUpload(block,blockIndex);tasks.push(task);return task}var abs=function abs(block,blockIndex){return _this8.client.rawRequest({method:"PUT",host:uploadCredentials.url,path:"/"+fileId+"/"+blockIndex,query:uploadCredentials.sas,body:block,headers:{"x-ms-blob-type":"BlockBlob"}},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})};var custom=function custom(block,blockIndex){var values={"file.id":fileId,"chunk.index":blockIndex};var interpolate=function interpolate(str){var map=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(a){return a};return str.replace(/\{([\w\.]+)\}/g,function(_,key){return map(values[key])})};var interpolatedHeaders={};Object.keys(uploadCredentials.headers).forEach(function(name){var value=interpolate(uploadCredentials.headers[name]);interpolatedHeaders[interpolate(name)]=value});return _this8.client.rawRequest({method:uploadCredentials.method,host:interpolate(uploadCredentials.host),path:interpolate(uploadCredentials.path,encodeURIComponent),query:interpolate(uploadCredentials.query,encodeURIComponent),body:block,headers:interpolatedHeaders},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})};var uploadData={abs:abs,custom:custom}[uploadCredentials.type];var encryptAndUpload=function encryptAndUpload(block,blockIndex){return _this8.client.crypto().encryptFileBlock(keyIV,block,true).then(function(block$_){return bluffer.createBase64(block$_)}).then(function(block$){return uploadData(block$,blockIndex)})};var finish=function finish(){return done({fileId:fileId,envelope:envelope}).then(function(){if(onProgress)onProgress(100)})};function next(){if(complete){return}schedule(function(){return blocks().then(function(data){if(data){next();return handle(data,index++)}else if(!complete){complete=true;var final=Promise.all(tasks).then(finish);resolve(final)}})})}next();if(file.async!==false){resolve()}})})};Files.prototype.upload__legacy=function upload__legacy(_ref9){var _this9=this;var name=_ref9.name,contents=_ref9.contents,adobeExportData=_ref9.adobeExportData,assignedTo=_ref9.assignedTo,assignedType=_ref9.assignedType,_ref9$download=_ref9.download,download=_ref9$download===undefined?false:_ref9$download,_ref9$async=_ref9.async,async=_ref9$async===undefined?true:_ref9$async,onProgress=_ref9.onProgress,onError=_ref9.onError;return this.generateToken(assignedTo,assignedType).then(function(token){return Promise.all([token,_this9._generateKeyIVEnvelope()])}).then(function(_ref10){var token=_ref10[0],_ref10$=_ref10[1],keyIV=_ref10$.keyIV,envelope=_ref10$.envelope;var process=_this9._upload__legacy({name:name,contents:contents,adobeExportData:adobeExportData,download:download,token:token,keyIV:keyIV,envelope:envelope,onProgress:onProgress,onError:onError});if(async){process=Promise.resolve()}return process.then(function(){return token})}).then(function(token){var file=new _File2.default;file.id=token;return file})};Files.prototype._upload__legacy=function _upload__legacy(_ref11){var _this10=this;var name=_ref11.name,contents=_ref11.contents,adobeExportData=_ref11.adobeExportData,download=_ref11.download,token=_ref11.token,keyIV=_ref11.keyIV,envelope=_ref11.envelope,onProgress=_ref11.onProgress;return new Promise(function(resolve){var concurrent=4;var _parseFilename2=parseFilename(name),filename=_parseFilename2.name,extension=_parseFilename2.extension;var blocks=(0,_streamBlocks2.default)(contents);var chain=Promise.resolve();var index=0;var end=false;var count=Math.ceil((0,_getContentLength2.default)(contents)/_constants.BYTES_PER_BLOCK);var percent=new Array(count);var onUploadProgress=function onUploadProgress(){};if(onProgress){onUploadProgress=function onUploadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);onProgress(percent.reduce(function(a,b){return a+(b||0)},0)/count*.99)}}var process=function process(block,blockIndex){return _this10.client.crypto().encryptFileBlock(keyIV,block).then(function(block$){return _this10.client.request("files.legacy.upload-block",{block:blockIndex,part:1,token:token,data:block$},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})})};function next(){blocks().then(function(block){if(end)return;if(block===null){end=true;resolve(chain.then(complete))}else{var handle=process(block,index++);chain=chain.then(function(){return handle});handle.then(next)}})}var complete=function complete(){return _this10.client.request("files.legacy.upload-complete",{block:0,blockCount:index,part:0,token:token,extn:extension,pages:1,filename:filename,storeoriginal:download?1:0,adobeExportData:adobeExportData?JSON.stringify(adobeExportData):null,envelope:envelope}).then(function(){return onProgress&&onProgress(100)})};while(concurrent--){next()}})};Files.prototype.download=function download(_options){var _this11=this;var options=typeof _options==="string"?{fileId:_options}:_options;var fileId=options.fileId,onFileDetails=options.onFileDetails;return this.details(fileId).then(function(file){if(!file.downloadable){throw new Error("File "+fileId+" is not downloadable.")}if(file.status!==_FileStatus2.default.OK){throw new Error("File "+fileId+" cannot be download. The file may still be uploading, processing or has errored.")}if(!file.blocks){throw new Error("File "+fileId+" is empty.")}if(onFileDetails){onFileDetails(file)}return _this11._downloadFile(file,options)})};Files.prototype._downloadFile=function _downloadFile(file,options){var _this12=this;return new Promise(function(resolve){var concurrent=4;var bluffer=new _bluffer2.default;var count=file.blocks;var blocks=new Array(count);var chain=Promise.resolve();var onData=options.onData||function onData(block,index){blocks[index]=block};var onDownloadProgress=function onDownloadProgress(){};if(options.onProgress){var percent=new Array(count);onDownloadProgress=function onDownloadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);options.onProgress(percent.reduce(function(a,b){return a+(b||0)},0)/count*.99)}}var process=function process(blockIndex){return _this12.client.request("files.download-block",{proofId:file.assignedTo,fileId:file.id,block:blockIndex+1},{onDownloadProgress:onDownloadProgress.bind(null,blockIndex)}).then(function(response){return _this12.client.crypto().decryptFileBlock(response.data,_this12.client.session.privateKeyPEM).then(function(blockBase64){return bluffer.createBase64(blockBase64)})})};var index=0;var end=false;function next(){if(end)return;if(index<blocks.length){var blockIndex=index++;var block=process(blockIndex);chain=chain.then(function(){return block.then(function(data){return onData(data,blockIndex,count)})});block.then(next)}else{end=true;resolve(chain.then(complete))}}var complete=function complete(){if(options.onProgress){options.onProgress(100)}if(!options.onData){return bluffer.combine.apply(bluffer,blocks)}return null};while(concurrent--){next()}})};Files.prototype.details=function details(fileId){return this.client.request("files.details",{fileId:fileId}).then(function(response){return(new _File2.default).fromFile(response.data)})};Files.prototype.thumbnail=function thumbnail(fileId){return this.thumbnails([fileId],{async:false}).then(function(thumbnails){return thumbnails[fileId]})};Files.prototype.thumbnails=function thumbnails(fileIds){var _this13=this;var _ref12=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref12$async=_ref12.async,async=_ref12$async===undefined?false:_ref12$async,onLoadThumbnail=_ref12.onLoadThumbnail,onLoadThumbnails=_ref12.onLoadThumbnails,_ref12$onLoadThumbnai=_ref12.onLoadThumbnailsThrottleMs,onLoadThumbnailsThrottleMs=_ref12$onLoadThumbnai===undefined?1e3:_ref12$onLoadThumbnai,onLoadError=_ref12.onLoadError;var scheduled=[];var pendingBatch={};var scheduleOnLoadThumbnails=onLoadThumbnails?(0,_throttle2.default)(function(){if(Object.keys(pendingBatch).length){onLoadThumbnails(pendingBatch);pendingBatch={}}},onLoadThumbnailsThrottleMs):function(){};return Promise.all(fileIds.map(function(fileId){return _this13.client.cache.auto(_constants.THUMBNAIL_CACHE_PREFIX+fileId,function(resolve){scheduled.push({fileId:fileId,resolve:resolve})}).then(function(thumbnail){var _ref13;return thumbnail&&(_ref13={},_ref13[fileId]=thumbnail,_ref13)})})).then(function(entries){var more=Promise.resolve({});if(scheduled.length){more=_this13.client.request("files.thumbnails",{fileIds:scheduled.map(function(_ref14){var fileId=_ref14.fileId;return fileId}).join(",")}).then(function(response){var thumbnails=response.data.thumbnails;return Promise.all(scheduled.map(function(_ref15){var fileId=_ref15.fileId,resolve=_ref15.resolve;var promise=void 0;if(fileId in thumbnails){var _thumbnails$fileId=thumbnails[fileId],encryptionVersion=_thumbnails$fileId.encryptionVersion,envelope=_thumbnails$fileId.envelope,url=_thumbnails$fileId.url;promise=_this13.client.rawRequest({method:"GET",url:new _whatwgURL2.default(url)},{bluffer:true}).then(function(res){return _this13.client.encryption.decryptFileThumbnail(encryptionVersion,envelope,res.body)})}else{var message="Failed to load thumbnail (unknown reason).";var errors=response.data.errors;if(errors){for(var i=0;i<errors.length;i++){if(errors[i].details.fileId===fileId){message=errors[i].message}}}promise=Promise.reject(new Error(message))}return promise.then(function(thumbnail){var _ref16;resolve(thumbnail);if(onLoadThumbnail){var _onLoadThumbnail;onLoadThumbnail((_onLoadThumbnail={},_onLoadThumbnail[fileId]=thumbnail,_onLoadThumbnail))}pendingBatch[fileId]=thumbnail;scheduleOnLoadThumbnails();return _ref16={},_ref16[fileId]=thumbnail,_ref16}).catch(function(err){if(onLoadError){onLoadError(err,fileId)}if(!async){return Promise.reject(err)}return{}})}))})}if(async){return entries}else{return more.then(function(moreEntries){return[].concat(entries,moreEntries)})}}).then(function(entries){return Object.assign.apply(Object,[{}].concat(entries))})};return Files}(_API3.default);exports.default=Files;
|
|
1
|
+
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _File=require("../models/File");var _File2=_interopRequireDefault(_File);var _FileStatus=require("../enum/FileStatus");var _FileStatus2=_interopRequireDefault(_FileStatus);var _ImportProvider=require("../enum/ImportProvider");var _ImportProvider2=_interopRequireDefault(_ImportProvider);var _streamBlocks=require("../util/streamBlocks");var _streamBlocks2=_interopRequireDefault(_streamBlocks);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);var _getContentLength=require("../util/getContentLength");var _getContentLength2=_interopRequireDefault(_getContentLength);var _constants=require("../util/constants");var _throttle=require("../util/throttle");var _throttle2=_interopRequireDefault(_throttle);var _concurrent=require("../util/concurrent");var _concurrent2=_interopRequireDefault(_concurrent);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target}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 parseFilename(filename){var extensionIndex=filename.lastIndexOf(".");var name=filename.substring(0,extensionIndex);var extension=filename.substring(extensionIndex+1);return{name:name,extension:extension}}function containPercentage(percent,left,right){var total=1-(left+right);return total*percent+left}var Files=function(_API){_inherits(Files,_API);function Files(){_classCallCheck(this,Files);return _possibleConstructorReturn(this,_API.apply(this,arguments))}Files.prototype.generateToken=function generateToken(assignedTo,assignedType){if(assignedTo&&!assignedType){return Promise.reject(Error('The "assignedType" option is required when specifying the "assignedTo" option.'))}if(!assignedTo&&assignedType){return Promise.reject(Error('The "assignedTo" option is required when specifying the "assignedType" option.'))}return this.client.request("files.legacy.generate-token",{relatedId:assignedTo,fileType:assignedType}).then(function(response){return response.data.Token})};Files.prototype.setCanDownload=function setCanDownload(fileId,canDownload){return this.client.request("files.can-download.update",{fileId:fileId,downloadOriginal:canDownload?1:0})};Files.prototype._waitFileProcessed=function _waitFileProcessed(id){var _this2=this;return new Promise(function(resolve,reject){var checkTimeout=null;var timeoutTimeout=null;var check=function check(){_this2.details(id).then(function(file){checkTimeout=null;switch(file.status){case _FileStatus2.default.OK:{resolve(file);break}case _FileStatus2.default.ERROR:{reject(new Error("File "+id+" encountered a processing error: "+file.message));break}default:{checkTimeout=setTimeout(check,5e3);break}}if(!checkTimeout||file.status===_FileStatus2.default.RIPPING){clearTimeout(timeoutTimeout)}}).catch(reject)};check();timeoutTimeout=setTimeout(function(){clearTimeout(checkTimeout);reject(new Error("File did not finish processing within specified duration."))},3e4)})};Files.prototype._createWebsiteFile=function _createWebsiteFile(url){var _this3=this;return this._generateKeyIVEnvelope().then(function(_ref){var envelope=_ref.envelope;return _this3.client.request("files.import.web",{url:url,envelope:envelope})}).then(function(response){return response.data})};Files.prototype._importFileFromUrl=function _importFileFromUrl(_ref2){var _this4=this;var name=_ref2.name,url=_ref2.url,provider=_ref2.provider,auth=_ref2.auth,download=_ref2.download;var endpoint=provider;if(provider===_ImportProvider2.default.NONE){endpoint="generic"}var _parseFilename=parseFilename(name),filename=_parseFilename.name,extension=_parseFilename.extension;return this._generateKeyIVEnvelope().then(function(_ref3){var envelope=_ref3.envelope;return _this4.client.request("files.import."+endpoint,{extn:extension,filename:filename,url:url,envelope:envelope,accessToken:auth,storeOriginal:download})}).then(function(response){return response.data})};Files.prototype.import=function _import(_ref4){var _this5=this;var name=_ref4.name,url=_ref4.url,_ref4$provider=_ref4.provider,provider=_ref4$provider===undefined?_ImportProvider2.default.NONE:_ref4$provider,auth=_ref4.auth,_ref4$download=_ref4.download,download=_ref4$download===undefined?false:_ref4$download,_ref4$process=_ref4.process,process=_ref4$process===undefined?false:_ref4$process;var providerSupported=Object.keys(_ImportProvider2.default).some(function(key){return _ImportProvider2.default[key]===provider});if(!providerSupported){return Promise.reject(new Error('Unsupported provider "'+provider+'"'))}return(provider===_ImportProvider2.default.WEBSITE?this._createWebsiteFile(url):this._importFileFromUrl({name:name,url:url,provider:provider,auth:auth,download:download})).then(function(token){if(process){return _this5._waitFileProcessed(token)}else{var file=new _File2.default;file.id=token;return file}})};Files.prototype.email=function email(){return this.client.request("files.create-email").then(function(response){return response.data})};Files.prototype._generateKeyIVEnvelope=function _generateKeyIVEnvelope(){var _this6=this;return this.client.crypto().generateKeyIV().then(function(keyIV){return Promise.all([keyIV,_this6.client.crypto().envelopeSeal(keyIV.keyIV,[_this6.client.session.serverPublicKeyPEM,_this6.client.session.publicKeyPEM])])}).then(function(_ref5){var keyIV=_ref5[0],envelope=_ref5[1];return{keyIV:keyIV,envelope:envelope}})};Files.prototype.upload=function upload(){return this.upload__v2.apply(this,arguments)};Files.prototype.upload__v2=function upload__v2(files){var _this7=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _options$concurrent=options.concurrent,concurrency=_options$concurrent===undefined?6:_options$concurrent,opts=_objectWithoutProperties(options,["concurrent"]);var scheduleChunk=(0,_concurrent2.default)(concurrency);var scheduleDone=(0,_concurrent2.default)(1);var doneFiles=[];var multipleFiles=Array.isArray(files);var filesList=multipleFiles?files:[files];var done=function done(result){doneFiles.push(result);return scheduleDone(function(){if(doneFiles.length){var _doneFiles=doneFiles.slice();doneFiles.length=0;return _this7.client.request("files.v2.upload-complete",{files:_doneFiles})}return null})};return this.client.request("files.v2.generate-credentials",{supports:{providers:["abs","custom"]},files:filesList.map(function(file){var name=void 0;var extension=void 0;if(file.extension){var _ref6=[file.name,file.extension];name=_ref6[0];extension=_ref6[1]}else{var parsed=parseFilename(file.name);var _ref7=[parsed.name,parsed.extension];name=_ref7[0];extension=_ref7[1]}var size=(0,_getContentLength2.default)(file.contents);var chunks=Math.ceil(size/_constants.BYTES_PER_BLOCK);if(file.onProgress){file.onProgress(0)}return{name:name,extension:extension,chunks:chunks,size:size,hash:null,adobeExportData:file.adobeExportData?JSON.stringify(file.adobeExportData):null,assignedTo:file.assignedTo,assignedType:file.assignedType,canDownload:typeof file.download!=="undefined"?!!file.download:true}})}).then(function(response){return Promise.all(filesList.map(function(file,index){var definition=response.data[index];if(file.onProgress){file.onProgress(1)}return _this7._upload__v2(file,definition,opts,scheduleChunk,done).then(function(){var entity=new _File2.default;entity.id=definition.FileId;return entity})}))}).then(function(results){return multipleFiles?results:results[0]})};Files.prototype._upload__v2=function _upload__v2(file,definition,options,schedule,done){var _this8=this;return this._generateKeyIVEnvelope().then(function(_ref8){var keyIV=_ref8.keyIV,envelope=_ref8.envelope;return new Promise(function(resolve){var fileId=definition.FileId,uploadCredentials=definition.UploadCredentials;var bluffer=new _bluffer2.default;var complete=false;var index=0;var blocks=(0,_streamBlocks2.default)(file.contents,function(b){return bluffer.readBase64(b)});var tasks=[];var count=Math.ceil((0,_getContentLength2.default)(file.contents)/_constants.BYTES_PER_BLOCK);var percent=new Array(count);var lastPercent=1;var onUploadProgress=function onUploadProgress(){};var onProgress=file.onProgress;if(onProgress){onUploadProgress=function onUploadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);var totalPercent=containPercentage(percent.reduce(function(a,b){return a+(b||0)},0)/count/100,.01,.01)*100;if(typeof options.progressDecimalPlaces!=="undefined"){totalPercent=+totalPercent.toFixed(options.progressDecimalPlaces)}if(lastPercent!==totalPercent){onProgress(totalPercent);lastPercent=totalPercent}}}function handle(block,blockIndex){var task=encryptAndUpload(block,blockIndex);tasks.push(task);return task}var abs=function abs(block,blockIndex){return _this8.client.rawRequest({method:"PUT",host:uploadCredentials.url,path:"/"+fileId+"/"+blockIndex,query:uploadCredentials.sas,body:block,headers:{"x-ms-blob-type":"BlockBlob"}},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})};var custom=function custom(block,blockIndex){var values={"file.id":fileId,"chunk.index":blockIndex};var interpolate=function interpolate(str){var map=arguments.length>1&&arguments[1]!==undefined?arguments[1]:function(a){return a};return str.replace(/\{([\w\.]+)\}/g,function(_,key){return map(values[key])})};var interpolatedHeaders={};Object.keys(uploadCredentials.headers).forEach(function(name){var value=interpolate(uploadCredentials.headers[name]);interpolatedHeaders[interpolate(name)]=value});return _this8.client.rawRequest({method:uploadCredentials.method,host:interpolate(uploadCredentials.host),path:interpolate(uploadCredentials.path,encodeURIComponent),query:interpolate(uploadCredentials.query,encodeURIComponent),body:block,headers:interpolatedHeaders},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})};var uploadData={abs:abs,custom:custom}[uploadCredentials.type];var encryptAndUpload=function encryptAndUpload(block,blockIndex){return _this8.client.crypto().encryptFileBlock(keyIV,block,true).then(function(block$_){return bluffer.createBase64(block$_)}).then(function(block$){return uploadData(block$,blockIndex)})};var finish=function finish(){return done({fileId:fileId,envelope:envelope}).then(function(){if(onProgress)onProgress(100)})};function next(){if(complete){return}schedule(function(){return blocks().then(function(data){if(data){next();return handle(data,index++)}else if(!complete){complete=true;var final=Promise.all(tasks).then(finish);resolve(final)}})})}next();if(file.async!==false){resolve()}})})};Files.prototype.upload__legacy=function upload__legacy(_ref9){var _this9=this;var name=_ref9.name,contents=_ref9.contents,adobeExportData=_ref9.adobeExportData,assignedTo=_ref9.assignedTo,assignedType=_ref9.assignedType,_ref9$download=_ref9.download,download=_ref9$download===undefined?false:_ref9$download,_ref9$async=_ref9.async,async=_ref9$async===undefined?true:_ref9$async,onProgress=_ref9.onProgress,onError=_ref9.onError;return this.generateToken(assignedTo,assignedType).then(function(token){return Promise.all([token,_this9._generateKeyIVEnvelope()])}).then(function(_ref10){var token=_ref10[0],_ref10$=_ref10[1],keyIV=_ref10$.keyIV,envelope=_ref10$.envelope;var process=_this9._upload__legacy({name:name,contents:contents,adobeExportData:adobeExportData,download:download,token:token,keyIV:keyIV,envelope:envelope,onProgress:onProgress,onError:onError});if(async){process=Promise.resolve()}return process.then(function(){return token})}).then(function(token){var file=new _File2.default;file.id=token;return file})};Files.prototype._upload__legacy=function _upload__legacy(_ref11){var _this10=this;var name=_ref11.name,contents=_ref11.contents,adobeExportData=_ref11.adobeExportData,download=_ref11.download,token=_ref11.token,keyIV=_ref11.keyIV,envelope=_ref11.envelope,onProgress=_ref11.onProgress;return new Promise(function(resolve){var concurrent=4;var _parseFilename2=parseFilename(name),filename=_parseFilename2.name,extension=_parseFilename2.extension;var blocks=(0,_streamBlocks2.default)(contents);var chain=Promise.resolve();var index=0;var end=false;var count=Math.ceil((0,_getContentLength2.default)(contents)/_constants.BYTES_PER_BLOCK);var percent=new Array(count);var onUploadProgress=function onUploadProgress(){};if(onProgress){onUploadProgress=function onUploadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);onProgress(percent.reduce(function(a,b){return a+(b||0)},0)/count*.99)}}var process=function process(block,blockIndex){return _this10.client.crypto().encryptFileBlock(keyIV,block).then(function(block$){return _this10.client.request("files.legacy.upload-block",{block:blockIndex,part:1,token:token,data:block$},{onUploadProgress:onUploadProgress.bind(null,blockIndex)})})};function next(){blocks().then(function(block){if(end)return;if(block===null){end=true;resolve(chain.then(complete))}else{var handle=process(block,index++);chain=chain.then(function(){return handle});handle.then(next)}})}var complete=function complete(){return _this10.client.request("files.legacy.upload-complete",{block:0,blockCount:index,part:0,token:token,extn:extension,pages:1,filename:filename,storeoriginal:download?1:0,adobeExportData:adobeExportData?JSON.stringify(adobeExportData):null,envelope:envelope}).then(function(){return onProgress&&onProgress(100)})};while(concurrent--){next()}})};Files.prototype.download=function download(_options){var _this11=this;var options=typeof _options==="string"?{fileId:_options}:_options;var fileId=options.fileId,onFileDetails=options.onFileDetails;return this.details(fileId).then(function(file){if(!file.downloadable){throw new Error("File "+fileId+" is not downloadable.")}if(file.status!==_FileStatus2.default.OK){throw new Error("File "+fileId+" cannot be download. The file may still be uploading, processing or has errored.")}if(!file.blocks){throw new Error("File "+fileId+" is empty.")}if(onFileDetails){onFileDetails(file)}return _this11._downloadFile(file,options)})};Files.prototype._downloadFile=function _downloadFile(file,options){var _this12=this;return new Promise(function(resolve){var concurrent=4;var bluffer=new _bluffer2.default;var count=file.blocks;var blocks=new Array(count);var chain=Promise.resolve();var onData=options.onData||function onData(block,index){blocks[index]=block};var onDownloadProgress=function onDownloadProgress(){};if(options.onProgress){var percent=new Array(count);onDownloadProgress=function onDownloadProgress(blockIndex,progress){percent[blockIndex]=Math.max(progress,percent[blockIndex]||0);options.onProgress(percent.reduce(function(a,b){return a+(b||0)},0)/count*.99)}}var process=function process(blockIndex){return _this12.client.request("files.download-block",{proofId:file.assignedTo,fileId:file.id,block:blockIndex+1},{onDownloadProgress:onDownloadProgress.bind(null,blockIndex)}).then(function(response){return _this12.client.crypto().decryptFileBlock(response.data,_this12.client.session.privateKeyPEM).then(function(blockBase64){return bluffer.createBase64(blockBase64)})})};var index=0;var end=false;function next(){if(end)return;if(index<blocks.length){var blockIndex=index++;var block=process(blockIndex);chain=chain.then(function(){return block.then(function(data){return onData(data,blockIndex,count)})});block.then(next)}else{end=true;resolve(chain.then(complete))}}var complete=function complete(){if(options.onProgress){options.onProgress(100)}if(!options.onData){return bluffer.combine.apply(bluffer,blocks)}return null};while(concurrent--){next()}})};Files.prototype.details=function details(fileId){return this.client.request("files.details",{fileId:fileId}).then(function(response){return(new _File2.default).fromFile(response.data)})};Files.prototype.thumbnail=function thumbnail(fileId){var _this13=this;return this.client.cache.auto(_constants.THUMBNAIL_CACHE_PREFIX+fileId,function(){return _this13._thumbnail(fileId)})};Files.prototype._thumbnail=function _thumbnail(fileId){var _this14=this;return this.client.request("files.thumbnail",{fileId:fileId}).then(function(response){return _this14.client.crypto().decryptImage(response.data,_this14.client.session.privateKeyPEM)}).then(function(imageBase64){var bluffer=new _bluffer2.default;return bluffer.createBase64(imageBase64)})};Files.prototype.thumbnails=function thumbnails(fileIds,_ref12){var _this15=this;var _ref12$async=_ref12.async,async=_ref12$async===undefined?false:_ref12$async,onLoadThumbnail=_ref12.onLoadThumbnail,onLoadThumbnails=_ref12.onLoadThumbnails,_ref12$onLoadThumbnai=_ref12.onLoadThumbnailsThrottleMs,onLoadThumbnailsThrottleMs=_ref12$onLoadThumbnai===undefined?1e3:_ref12$onLoadThumbnai,onLoadError=_ref12.onLoadError;var scheduled=[];var pendingBatch={};var scheduleOnLoadThumbnails=onLoadThumbnails?(0,_throttle2.default)(function(){if(Object.keys(pendingBatch).length){onLoadThumbnails(pendingBatch);pendingBatch={}}},onLoadThumbnailsThrottleMs):function(){};return Promise.all(fileIds.map(function(fileId){return _this15.client.cache.auto(_constants.THUMBNAIL_CACHE_PREFIX+fileId,function(resolve){scheduled.push({fileId:fileId,resolve:resolve})}).then(function(thumbnail){var _ref13;return thumbnail&&(_ref13={},_ref13[fileId]=thumbnail,_ref13)})})).then(function(entries){var more=Promise.all(scheduled.map(function(_ref14){var fileId=_ref14.fileId,resolve=_ref14.resolve;return _this15._thumbnail(fileId).then(function(thumbnail){var _ref15;resolve(thumbnail);if(onLoadThumbnail){var _onLoadThumbnail;onLoadThumbnail((_onLoadThumbnail={},_onLoadThumbnail[fileId]=thumbnail,_onLoadThumbnail))}pendingBatch[fileId]=thumbnail;scheduleOnLoadThumbnails();return _ref15={},_ref15[fileId]=thumbnail,_ref15}).catch(function(err){if(onLoadError){onLoadError(err,fileId)}if(!async){return Promise.reject(err)}return{}})}));if(async){return entries}else{return more.then(function(moreEntries){return[].concat(entries,moreEntries)})}}).then(function(entries){return Object.assign.apply(Object,[{}].concat(entries))})};return Files}(_API3.default);exports.default=Files;
|
package/lib/api/Profile.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
export default Profile;
|
|
2
2
|
declare class Profile extends API {
|
|
3
|
-
/** @private */
|
|
4
3
|
constructor(client: any);
|
|
5
|
-
/**
|
|
6
|
-
* The Integrations API.
|
|
7
|
-
*
|
|
8
|
-
* @type {Integrations}
|
|
9
|
-
*/
|
|
10
|
-
integrations: Integrations;
|
|
11
4
|
/**
|
|
12
5
|
* Uploads the avatar for the current user.
|
|
13
6
|
*
|
|
@@ -83,4 +76,3 @@ declare class Profile extends API {
|
|
|
83
76
|
clearStatus(): Promise<any>;
|
|
84
77
|
}
|
|
85
78
|
import API from "./API";
|
|
86
|
-
import Integrations from "./Integrations";
|
package/lib/api/Profile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);
|
|
1
|
+
"use strict";exports.__esModule=true;var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _bluffer=require("../bluffer");var _bluffer2=_interopRequireDefault(_bluffer);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 Profile=function(_API){_inherits(Profile,_API);function Profile(){_classCallCheck(this,Profile);return _possibleConstructorReturn(this,_API.apply(this,arguments))}Profile.prototype.uploadAvatar=function uploadAvatar(file){var _this2=this;var bluffer=new _bluffer2.default;return bluffer.readBase64(file).then(function(base64){return _this2.client.request("profile.upload-avatar",{uploadedImage:"data:image/png;base64,"+base64})})};Profile.prototype.changePassword=function changePassword(currentPassword,password){var _this3=this;var crypto=this.client.crypto();return Promise.all([crypto.generatePasswordHash(currentPassword),crypto.generatePasswordHash(password),crypto.encryptPrivateKey(this.client.session.privateKeyPEM,password)]).then(function(_ref){var oldPassword=_ref[0],newPassword=_ref[1],newPrivateKey=_ref[2];return _this3.client.request("profile.change-password",{oldPassword:oldPassword,newPassword:newPassword,newPrivateKey:newPrivateKey})})};Profile.prototype.getStatus=function getStatus(){return this.client.request("profile.status").then(function(response){return response.data.status})};Profile.prototype.setStatus=function setStatus(status){return this.client.request("profile.set-status",status)};Profile.prototype.clearStatus=function clearStatus(){return this.client.request("profile.clear-status")};return Profile}(_API3.default);exports.default=Profile;
|
package/lib/api/Proofs.d.ts
CHANGED
|
@@ -56,12 +56,6 @@ declare class Proofs extends API {
|
|
|
56
56
|
* @type {ProofsCustomTools}
|
|
57
57
|
*/
|
|
58
58
|
customTools: ProofsCustomTools;
|
|
59
|
-
/**
|
|
60
|
-
* The Proofs Integration References API.
|
|
61
|
-
*
|
|
62
|
-
* @type {ProofsIntegrationReferences}
|
|
63
|
-
*/
|
|
64
|
-
integrationReferences: ProofsIntegrationReferences;
|
|
65
59
|
linkCheck: ProofLinkCheck;
|
|
66
60
|
/**
|
|
67
61
|
* Assigns a workflow to a proof.
|
|
@@ -190,7 +184,7 @@ declare class Proofs extends API {
|
|
|
190
184
|
* @param {boolean} [options.start=true] Whether to immediately start the proof (sends invitation emails to reviewers in the workflow)
|
|
191
185
|
* @returns {Promise<Proof>}
|
|
192
186
|
*/
|
|
193
|
-
create({ name, tags, dueDate, messageToReviewers, workflow, workflowTemplate, file, group, previousProof, team, reference, customTools,
|
|
187
|
+
create({ name, tags, dueDate, messageToReviewers, workflow, workflowTemplate, file, group, previousProof, team, reference, customTools, reminders, owners, canDownload, start, }: {
|
|
194
188
|
name: string;
|
|
195
189
|
tags?: string[];
|
|
196
190
|
dueDate?: Date;
|
|
@@ -464,6 +458,5 @@ import ProofsGroups from "./ProofsGroups";
|
|
|
464
458
|
import ProofsAudit from "./ProofsAudit";
|
|
465
459
|
import ProofsAssets from "./ProofsAssets";
|
|
466
460
|
import ProofsCustomTools from "./ProofsCustomTools";
|
|
467
|
-
import ProofsIntegrationReferences from "./ProofsIntegrationReferences";
|
|
468
461
|
import ProofLinkCheck from "./ProofsLinkCheck";
|
|
469
462
|
import Proof from "../models/Proof";
|
package/lib/api/Proofs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _ProofsOwners=require("./ProofsOwners");var _ProofsOwners2=_interopRequireDefault(_ProofsOwners);var _ProofsEditors=require("./ProofsEditors");var _ProofsEditors2=_interopRequireDefault(_ProofsEditors);var _ProofsReviewers=require("./ProofsReviewers");var _ProofsReviewers2=_interopRequireDefault(_ProofsReviewers);var _ProofsVersions=require("./ProofsVersions");var _ProofsVersions2=_interopRequireDefault(_ProofsVersions);var _ProofsGroups=require("./ProofsGroups");var _ProofsGroups2=_interopRequireDefault(_ProofsGroups);var _ProofsAudit=require("./ProofsAudit");var _ProofsAudit2=_interopRequireDefault(_ProofsAudit);var _ProofsAssets=require("./ProofsAssets");var _ProofsAssets2=_interopRequireDefault(_ProofsAssets);var _ProofsCustomTools=require("./ProofsCustomTools");var _ProofsCustomTools2=_interopRequireDefault(_ProofsCustomTools);var _ProofsIntegrationReferences=require("./ProofsIntegrationReferences");var _ProofsIntegrationReferences2=_interopRequireDefault(_ProofsIntegrationReferences);var _ProofsLinkCheck=require("./ProofsLinkCheck");var _ProofsLinkCheck2=_interopRequireDefault(_ProofsLinkCheck);var _Proof=require("../models/Proof");var _Proof2=_interopRequireDefault(_Proof);var _Reminders=require("./Reminders");var _Reminders2=_interopRequireDefault(_Reminders);var _constants=require("../util/constants");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 transformProofsForUpdate(proofs){var proofsArrForUpdate=[].concat(proofs);proofsArrForUpdate.forEach(function(proof){proof.proofId=proof.id;delete proof.id});return proofsArrForUpdate}var Proofs=function(_API){_inherits(Proofs,_API);function Proofs(client){_classCallCheck(this,Proofs);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.owners=new _ProofsOwners2.default(client);_this.editors=new _ProofsEditors2.default(client);_this.reviewers=new _ProofsReviewers2.default(client);_this.versions=new _ProofsVersions2.default(client);_this.groups=new _ProofsGroups2.default(client);_this.reminders=new _Reminders2.default(client);_this.audit=new _ProofsAudit2.default(client);_this.assets=new _ProofsAssets2.default(client);_this.customTools=new _ProofsCustomTools2.default(client);_this.integrationReferences=new _ProofsIntegrationReferences2.default(client);_this.linkCheck=new _ProofsLinkCheck2.default(client);return _this}Proofs.prototype.setWorkflow=function setWorkflow(proofId,workflowId){var _this2=this;return this.client.request("proofs.normalize-workflow",{proofId:proofId,workflowId:workflowId}).then(function(){return _this2.client.request("proofs.set-workflow",{proofId:proofId,workflowId:workflowId})})};Proofs.prototype.setTags=function setTags(proofId,tags){return this.client.request("proofs.set-tags",{relatedId:proofId,tag:tags.join(",")})};Proofs.prototype.deleteTag=function deleteTag(proofId,tag){return this.client.request("proofs.tag-delete",{relatedId:proofId,tag:tag})};Proofs.prototype.setFile=function setFile(proofId,fileId){var _this3=this;return this.client.request("proofs.set-file",{proofId:proofId,fileId:fileId}).then(function(){return _this3.client.request("proofs.distribute-file",{proofId:proofId})})};Proofs.prototype.create=function create(_ref){var _this4=this;var name=_ref.name,_ref$tags=_ref.tags,tags=_ref$tags===undefined?[]:_ref$tags,_ref$dueDate=_ref.dueDate,dueDate=_ref$dueDate===undefined?new Date(Date.now()+3*_constants.DAY_IN_MS):_ref$dueDate,messageToReviewers=_ref.messageToReviewers,workflow=_ref.workflow,workflowTemplate=_ref.workflowTemplate,file=_ref.file,group=_ref.group,previousProof=_ref.previousProof,team=_ref.team,reference=_ref.reference,customTools=_ref.customTools,integrationReferences=_ref.integrationReferences,_ref$reminders=_ref.reminders,reminders=_ref$reminders===undefined?[]:_ref$reminders,owners=_ref.owners,canDownload=_ref.canDownload,_ref$start=_ref.start,start=_ref$start===undefined?true:_ref$start;return this.client.request("proofs.create",{proof:{name:name,tags:tags,dueDate:dueDate.toISOString(),messageToReviewers:messageToReviewers,workflowId:workflow&&workflow.id||undefined,workflowTemplateId:workflowTemplate&&workflowTemplate.id||undefined,fileId:file&&file.id||undefined,groupId:group&&group.id||undefined,previousProofId:previousProof&&previousProof.id||undefined,teamSlug:team&&team.slug||undefined,reference:reference,integrationReferences:integrationReferences,reminders:[].concat(reminders),owners:owners,canDownload:canDownload,start:start}}).then(function(response){var proof=(new _Proof2.default).fromProof(response.data);proof.calculateState();if(customTools&&!previousProof){return _this4.customTools.update(proof.id,customTools).then(function(){return proof})}return proof})};Proofs.prototype.archive=function archive(proofIdOrIds){return this.client.request("proofs.archive",{proofIds:proofIdOrIds})};Proofs.prototype.unarchive=function unarchive(proofId){return this.client.request("proofs.unarchive",{proofId:proofId})};Proofs.prototype.delete=function _delete(proofId){return this.client.request("proofs.delete",{proofId:proofId})};Proofs.prototype.finish=function finish(proofId,decision){return this.client.request("proofs.finish",{proofId:proofId,decision:decision})};Proofs.prototype.approve=function approve(proofId,message){return this.client.request("proofs.manual-approval",{proofId:proofId,message:message})};Proofs.prototype.withdrawApproval=function withdrawApproval(proofId,messageToSender){return this.client.request("proofs.withdraw-approval",{proofId:proofId,messageToSender:messageToSender})};Proofs.prototype.generateEmail=function generateEmail(proofId){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return this.client.request("email.proofs.generate",_extends({proofId:proofId},options)).then(function(response){return response.data})};Proofs.prototype.return=function _return(proofId){return this.client.request("proofs.return",{proofId:proofId})};Proofs.prototype.start=function start(proofId){return this.client.request("proofs.start",{proofId:proofId})};Proofs.prototype.removeEditor=function removeEditor(id){return this.client.request("proofs.remove-editor",{proofId:id})};Proofs.prototype.load=function load(proofId){return this.client.request("proofs.load",{proofId:proofId}).then(function(response){return(new _Proof2.default).fromProof(response.data)})};Proofs.prototype.lock=function lock(proofId){return this.client.request("proofs.lock",{proofId:proofId})};Proofs.prototype.unlock=function unlock(proofId){return this.client.request("proofs.unlock",{proofId:proofId})};Proofs.prototype.requestUnlock=function requestUnlock(proofId){return this.client.request("proofs.request-unlock",{proofId:proofId})};Proofs.prototype.requestAccess=function requestAccess(proofId){return this.client.request("proofs.request-access",{proofId:proofId})};Proofs.prototype.images=function images(proofId){return this.client.request("proofs.images",{proofId:proofId}).then(function(response){return response.data.proof.file})};Proofs.prototype.setMessageToReviewers=function setMessageToReviewers(proofId,messageToReviewers){return this.client.request("proofs.set-reviewers-message",{proofId:proofId,messageToReviewers:messageToReviewers})};Proofs.prototype.returnTodos=function returnTodos(proofIdOrIds,_ref2){var messageToOwners=_ref2.messageToOwners,_ref2$markCommentsAsT=_ref2.markCommentsAsTodo,markCommentsAsTodo=_ref2$markCommentsAsT===undefined?false:_ref2$markCommentsAsT;return this.client.request("proofs.return-todos",{proofIds:[].concat(proofIdOrIds),messageToOwners:messageToOwners,markCommentAsTodo:markCommentsAsTodo})};Proofs.prototype.updateDecision=function updateDecision(proofId,decision){return this.client.request("proofs.update-decision",{proofId:proofId,decision:decision})};Proofs.prototype.update=function update(proofOrProofs){if(proofOrProofs.length===1||typeof proofOrProofs.length==="undefined"){var _concat$=[].concat(proofOrProofs)[0],id=_concat$.id,name=_concat$.name,tags=_concat$.tags,dueDate=_concat$.dueDate,messageToReviewers=_concat$.messageToReviewers,workflow=_concat$.workflow,file=_concat$.file,reference=_concat$.reference,integrationReferences=_concat$.integrationReferences,reminders=_concat$.reminders,owners=_concat$.owners,canDownload=_concat$.canDownload,start=_concat$.start;return this.client.request("proofs.update",{proof:{id:id,name:name,tags:tags,dueDate:dueDate?dueDate.toISOString():undefined,messageToReviewers:messageToReviewers,workflowId:workflow&&workflow.id||undefined,fileId:file&&file.id||undefined,reference:reference,integrationReferences:integrationReferences,reminders:reminders?[].concat(reminders):undefined,owners:owners,canDownload:canDownload,start:start}}).then(function(response){var proof=(new _Proof2.default).fromProof(response.data);proof.calculateState();return proof})}return this.client.request("proofs.bulk-update",{proofs:transformProofsForUpdate(proofOrProofs)})};Proofs.prototype.next=function next(proofId){return this.client.request("proofs.next",{proofId:proofId}).then(function(response){return(new _Proof2.default).fromProof(response.data)})};return Proofs}(_API3.default);exports.default=Proofs;
|
|
1
|
+
"use strict";exports.__esModule=true;var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var _API2=require("./API");var _API3=_interopRequireDefault(_API2);var _ProofsOwners=require("./ProofsOwners");var _ProofsOwners2=_interopRequireDefault(_ProofsOwners);var _ProofsEditors=require("./ProofsEditors");var _ProofsEditors2=_interopRequireDefault(_ProofsEditors);var _ProofsReviewers=require("./ProofsReviewers");var _ProofsReviewers2=_interopRequireDefault(_ProofsReviewers);var _ProofsVersions=require("./ProofsVersions");var _ProofsVersions2=_interopRequireDefault(_ProofsVersions);var _ProofsGroups=require("./ProofsGroups");var _ProofsGroups2=_interopRequireDefault(_ProofsGroups);var _ProofsAudit=require("./ProofsAudit");var _ProofsAudit2=_interopRequireDefault(_ProofsAudit);var _ProofsAssets=require("./ProofsAssets");var _ProofsAssets2=_interopRequireDefault(_ProofsAssets);var _ProofsCustomTools=require("./ProofsCustomTools");var _ProofsCustomTools2=_interopRequireDefault(_ProofsCustomTools);var _ProofsLinkCheck=require("./ProofsLinkCheck");var _ProofsLinkCheck2=_interopRequireDefault(_ProofsLinkCheck);var _Proof=require("../models/Proof");var _Proof2=_interopRequireDefault(_Proof);var _Reminders=require("./Reminders");var _Reminders2=_interopRequireDefault(_Reminders);var _constants=require("../util/constants");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 transformProofsForUpdate(proofs){var proofsArrForUpdate=[].concat(proofs);proofsArrForUpdate.forEach(function(proof){proof.proofId=proof.id;delete proof.id});return proofsArrForUpdate}var Proofs=function(_API){_inherits(Proofs,_API);function Proofs(client){_classCallCheck(this,Proofs);var _this=_possibleConstructorReturn(this,_API.call(this,client));_this.owners=new _ProofsOwners2.default(client);_this.editors=new _ProofsEditors2.default(client);_this.reviewers=new _ProofsReviewers2.default(client);_this.versions=new _ProofsVersions2.default(client);_this.groups=new _ProofsGroups2.default(client);_this.reminders=new _Reminders2.default(client);_this.audit=new _ProofsAudit2.default(client);_this.assets=new _ProofsAssets2.default(client);_this.customTools=new _ProofsCustomTools2.default(client);_this.linkCheck=new _ProofsLinkCheck2.default(client);return _this}Proofs.prototype.setWorkflow=function setWorkflow(proofId,workflowId){var _this2=this;return this.client.request("proofs.normalize-workflow",{proofId:proofId,workflowId:workflowId}).then(function(){return _this2.client.request("proofs.set-workflow",{proofId:proofId,workflowId:workflowId})})};Proofs.prototype.setTags=function setTags(proofId,tags){return this.client.request("proofs.set-tags",{relatedId:proofId,tag:tags.join(",")})};Proofs.prototype.deleteTag=function deleteTag(proofId,tag){return this.client.request("proofs.tag-delete",{relatedId:proofId,tag:tag})};Proofs.prototype.setFile=function setFile(proofId,fileId){var _this3=this;return this.client.request("proofs.set-file",{proofId:proofId,fileId:fileId}).then(function(){return _this3.client.request("proofs.distribute-file",{proofId:proofId})})};Proofs.prototype.create=function create(_ref){var _this4=this;var name=_ref.name,_ref$tags=_ref.tags,tags=_ref$tags===undefined?[]:_ref$tags,_ref$dueDate=_ref.dueDate,dueDate=_ref$dueDate===undefined?new Date(Date.now()+3*_constants.DAY_IN_MS):_ref$dueDate,messageToReviewers=_ref.messageToReviewers,workflow=_ref.workflow,workflowTemplate=_ref.workflowTemplate,file=_ref.file,group=_ref.group,previousProof=_ref.previousProof,team=_ref.team,reference=_ref.reference,customTools=_ref.customTools,_ref$reminders=_ref.reminders,reminders=_ref$reminders===undefined?[]:_ref$reminders,owners=_ref.owners,canDownload=_ref.canDownload,_ref$start=_ref.start,start=_ref$start===undefined?true:_ref$start;return this.client.request("proofs.create",{proof:{name:name,tags:tags,dueDate:dueDate.toISOString(),messageToReviewers:messageToReviewers,workflowId:workflow&&workflow.id||undefined,workflowTemplateId:workflowTemplate&&workflowTemplate.id||undefined,fileId:file&&file.id||undefined,groupId:group&&group.id||undefined,previousProofId:previousProof&&previousProof.id||undefined,teamSlug:team&&team.slug||undefined,reference:reference,reminders:[].concat(reminders),owners:owners,canDownload:canDownload,start:start}}).then(function(response){var proof=(new _Proof2.default).fromProof(response.data);proof.calculateState();if(customTools&&!previousProof){return _this4.customTools.update(proof.id,customTools).then(function(){return proof})}return proof})};Proofs.prototype.archive=function archive(proofIdOrIds){return this.client.request("proofs.archive",{proofIds:proofIdOrIds})};Proofs.prototype.unarchive=function unarchive(proofId){return this.client.request("proofs.unarchive",{proofId:proofId})};Proofs.prototype.delete=function _delete(proofId){return this.client.request("proofs.delete",{proofId:proofId})};Proofs.prototype.finish=function finish(proofId,decision){return this.client.request("proofs.finish",{proofId:proofId,decision:decision})};Proofs.prototype.approve=function approve(proofId,message){return this.client.request("proofs.manual-approval",{proofId:proofId,message:message})};Proofs.prototype.withdrawApproval=function withdrawApproval(proofId,messageToSender){return this.client.request("proofs.withdraw-approval",{proofId:proofId,messageToSender:messageToSender})};Proofs.prototype.generateEmail=function generateEmail(proofId){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return this.client.request("email.proofs.generate",_extends({proofId:proofId},options)).then(function(response){return response.data})};Proofs.prototype.return=function _return(proofId){return this.client.request("proofs.return",{proofId:proofId})};Proofs.prototype.start=function start(proofId){return this.client.request("proofs.start",{proofId:proofId})};Proofs.prototype.removeEditor=function removeEditor(id){return this.client.request("proofs.remove-editor",{proofId:id})};Proofs.prototype.load=function load(proofId){return this.client.request("proofs.load",{proofId:proofId}).then(function(response){return(new _Proof2.default).fromProof(response.data)})};Proofs.prototype.lock=function lock(proofId){return this.client.request("proofs.lock",{proofId:proofId})};Proofs.prototype.unlock=function unlock(proofId){return this.client.request("proofs.unlock",{proofId:proofId})};Proofs.prototype.requestUnlock=function requestUnlock(proofId){return this.client.request("proofs.request-unlock",{proofId:proofId})};Proofs.prototype.requestAccess=function requestAccess(proofId){return this.client.request("proofs.request-access",{proofId:proofId})};Proofs.prototype.images=function images(proofId){return this.client.request("proofs.images",{proofId:proofId}).then(function(response){return response.data.proof.file})};Proofs.prototype.setMessageToReviewers=function setMessageToReviewers(proofId,messageToReviewers){return this.client.request("proofs.set-reviewers-message",{proofId:proofId,messageToReviewers:messageToReviewers})};Proofs.prototype.returnTodos=function returnTodos(proofIdOrIds,_ref2){var messageToOwners=_ref2.messageToOwners,_ref2$markCommentsAsT=_ref2.markCommentsAsTodo,markCommentsAsTodo=_ref2$markCommentsAsT===undefined?false:_ref2$markCommentsAsT;return this.client.request("proofs.return-todos",{proofIds:[].concat(proofIdOrIds),messageToOwners:messageToOwners,markCommentAsTodo:markCommentsAsTodo})};Proofs.prototype.updateDecision=function updateDecision(proofId,decision){return this.client.request("proofs.update-decision",{proofId:proofId,decision:decision})};Proofs.prototype.update=function update(proofOrProofs){if(proofOrProofs.length===1||typeof proofOrProofs.length==="undefined"){var _concat$=[].concat(proofOrProofs)[0],id=_concat$.id,name=_concat$.name,tags=_concat$.tags,dueDate=_concat$.dueDate,messageToReviewers=_concat$.messageToReviewers,workflow=_concat$.workflow,file=_concat$.file,reference=_concat$.reference,reminders=_concat$.reminders,owners=_concat$.owners,canDownload=_concat$.canDownload,start=_concat$.start;return this.client.request("proofs.update",{proof:{id:id,name:name,tags:tags,dueDate:dueDate?dueDate.toISOString():undefined,messageToReviewers:messageToReviewers,workflowId:workflow&&workflow.id||undefined,fileId:file&&file.id||undefined,reference:reference,reminders:reminders?[].concat(reminders):undefined,owners:owners,canDownload:canDownload,start:start}}).then(function(response){var proof=(new _Proof2.default).fromProof(response.data);proof.calculateState();return proof})}return this.client.request("proofs.bulk-update",{proofs:transformProofsForUpdate(proofOrProofs)})};Proofs.prototype.next=function next(proofId){return this.client.request("proofs.next",{proofId:proofId}).then(function(response){return(new _Proof2.default).fromProof(response.data)})};return Proofs}(_API3.default);exports.default=Proofs;
|