Skip to content

Commit e3bf7a2

Browse files
Merge pull request #1 from aspose-email-cloud/develop
Aspose.Email Cloud 19.11 released
2 parents 7143643 + b88ef4b commit e3bf7a2

File tree

12 files changed

+6752
-1556
lines changed

12 files changed

+6752
-1556
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
package-lock.json
3+
dist

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ All Aspose.Email for Cloud SDKs, helper scripts and templates are licensed under
2222
+ [**Free Support Forum**](https://forum.aspose.cloud/c/email)
2323
+ [**Paid Support Helpdesk**](https://helpdesk.aspose.cloud/)
2424
+ [**Blog**](https://blog.aspose.cloud/category/aspose-products/aspose-email-cloud/)
25+
+ [**Git repository: Aspose.Email Cloud SDK for .Net**](https://github.com/aspose-email-cloud/aspose-email-cloud-dotnet)
26+
+ [**Git repository: Aspose.Email Cloud SDK for Ruby**](https://github.com/aspose-email-cloud/aspose-email-cloud-ruby)
27+
+ [**Git repository: Aspose.Email Cloud SDK for Python**](https://github.com/aspose-email-cloud/aspose-email-cloud-python)
28+
+ [**Git repository: Aspose.Email Cloud SDK for PHP**](https://github.com/aspose-email-cloud/aspose-email-cloud-php)
29+
+ [**Git repository: Aspose.Email Cloud SDK for Typescript**](https://github.com/aspose-email-cloud/aspose-email-cloud-node)
30+
+ [**Git repository: Aspose.Email Cloud SDK for Java**](https://github.com/aspose-email-cloud/aspose-email-cloud-java)

package.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "@asposecloud/asposeemailcloud",
3+
"version": "19.11.0",
4+
"description": "Aspose.Email Cloud Node.js SDK",
5+
"homepage": "https://products.aspose.cloud/email",
6+
"author": {
7+
"name": "Aspose Pty Ltd",
8+
"url": "https://github.com/aspose-email-cloud"
9+
},
10+
"license": "MIT",
11+
"engines": {
12+
"node": ">=6.15"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/aspose-email-cloud/aspose-email-cloud-node.git"
17+
},
18+
"keywords": [
19+
"Aspose",
20+
"Email",
21+
"Cloud",
22+
"REST",
23+
"API",
24+
"SDK",
25+
"Outlook",
26+
"MSG",
27+
"EML",
28+
"MHT"
29+
],
30+
"readmeFilename": "README.md",
31+
"main": "dist/lib/api.js",
32+
"types": "dist/lib/api.d.ts",
33+
"files": [
34+
"dist"
35+
],
36+
"scripts": {
37+
"compile": "tsc --build tsconfig.json"
38+
},
39+
"dependencies": {
40+
"@types/request": "^2.47.0",
41+
"request": "^2.87.0",
42+
"request-debug": "^0.2.0"
43+
},
44+
"devDependencies": {
45+
"@types/node": "^12.0.10",
46+
"@types/jest": "^23.3.9",
47+
"@types/jest-each": "^0.3.2",
48+
"jest": "^23.6.0",
49+
"jest-each": "^23.6.0",
50+
"jest-junit": "^5.2.0",
51+
"ts-jest": "^23.10.4",
52+
"ts-node": "^4.0.2",
53+
"tslint": "^5.8.0",
54+
"typescript": "^3.1.1",
55+
"cross-var": "^1.1.0"
56+
}
57+
}

src/api.ts

Lines changed: 2088 additions & 479 deletions
Large diffs are not rendered by default.

src/internal/api-error.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* MIT License
3+
4+
* Copyright (c) Aspose Pty Ltd. All rights reserved.
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import * as model from "../model/model";
26+
27+
/**
28+
* API error class.
29+
*/
30+
export class ApiError extends Error {
31+
32+
/**
33+
* Status code
34+
*/
35+
public readonly statusCode: number;
36+
37+
/**
38+
* Request error
39+
*/
40+
public readonly error: model.ModelError;
41+
42+
/**
43+
*
44+
* @param message Error message
45+
* @param status Status code
46+
* @param requestError Request error
47+
*/
48+
constructor(message: string, status: number, requestError: model.ModelError) {
49+
super(message);
50+
51+
this.statusCode = status;
52+
this.error = requestError;
53+
54+
// Set the prototype explicitly.
55+
Object.setPrototypeOf(this, ApiError.prototype);
56+
}
57+
}

src/internal/auth.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* MIT License
3+
4+
* Copyright (c) 2018-2019 Aspose Pty Ltd. All rights reserved.
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import request = require("request");
26+
import { ApiError } from "./api-error";
27+
import { Configuration } from "./configuration";
28+
import { invokeApiMethod } from "./request-helper";
29+
30+
/**
31+
* Authentication logic for api calls
32+
*/
33+
export interface IAuthentication {
34+
/**
35+
* Apply authentication settings to header and query params.
36+
*/
37+
applyToRequest(requestOptions: request.Options, configuration: Configuration): void;
38+
39+
/**
40+
* Handle 401 response.
41+
*/
42+
handle401response();
43+
}
44+
45+
/**
46+
* Implements JWT authentication
47+
*/
48+
export class JwtAuth implements IAuthentication {
49+
private accessTokenValue: string;
50+
51+
/**
52+
* Apply authentication settings to header and query params.
53+
*/
54+
public async applyToRequest(requestOptions: request.Options, configuration: Configuration): Promise<void> {
55+
if (this.accessTokenValue == null) {
56+
await this.requestToken(configuration);
57+
}
58+
59+
if (requestOptions && requestOptions.headers) {
60+
requestOptions.headers.Authorization = "Bearer " + this.accessTokenValue;
61+
}
62+
63+
return Promise.resolve();
64+
}
65+
66+
/**
67+
* Handle 401 response.
68+
*/
69+
public handle401response() {
70+
throw new ApiError("Authentication failed!", 401, null);
71+
}
72+
73+
private async requestToken(configuration: Configuration): Promise<void> {
74+
let postData = "grant_type=client_credentials";
75+
postData += "&client_id=" + configuration.appSID;
76+
postData += "&client_secret=" + configuration.appKey;
77+
78+
const requestOptions: request.Options = {
79+
method: "POST",
80+
uri: configuration.baseUrl + "connect/token",
81+
body: postData,
82+
headers: {
83+
"Content-Type": "application/x-www-form-urlencoded",
84+
},
85+
};
86+
87+
const response = await invokeApiMethod(requestOptions, configuration, true);
88+
const parsedResponse = JSON.parse(response.body);
89+
this.accessTokenValue = parsedResponse.access_token;
90+
return Promise.resolve();
91+
}
92+
}

src/internal/configuration.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* MIT License
3+
4+
* Copyright (c) 2018-2019 Aspose Pty Ltd. All rights reserved.
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import { IAuthentication, JwtAuth } from "../internal/auth";
26+
const defaultBasePath = "https://api.aspose.cloud/";
27+
28+
/**
29+
* Aspose.Imaging Cloud API configuration
30+
*/
31+
export class Configuration {
32+
/**
33+
* Authentication.
34+
*/
35+
public authentication: IAuthentication;
36+
37+
/**
38+
* App SID.
39+
*/
40+
public appSID: string;
41+
42+
/**
43+
* App key.
44+
*/
45+
public appKey: string;
46+
47+
/**
48+
* Base Url.
49+
*/
50+
public baseUrl: string = defaultBasePath;
51+
52+
/**
53+
* Gets or sets a value indicating whether debug mode. In debug mode all requests and responses are logged to console.
54+
*/
55+
public debugMode: boolean;
56+
57+
/**
58+
* Gets or sets the API version.
59+
*/
60+
public apiVersion: string = "v3.0";
61+
62+
/**
63+
* If you use custom on-premise server with metered license.
64+
* This way, you only need to specify the API base URL.
65+
*/
66+
public onPremise: boolean = false;
67+
68+
constructor(appKey: string, appSID: string, baseUrl?: string, debugMode?: boolean, apiVersion?: string) {
69+
if (appKey && appSID) {
70+
this.onPremise = false;
71+
} else if (baseUrl) {
72+
this.onPremise = true;
73+
}
74+
75+
if (baseUrl) {
76+
if (!baseUrl.endsWith("/")) {
77+
baseUrl = baseUrl + "/";
78+
}
79+
80+
this.baseUrl = baseUrl;
81+
}
82+
83+
this.appSID = appSID;
84+
this.appKey = appKey;
85+
this.debugMode = debugMode;
86+
87+
if (apiVersion) {
88+
if (apiVersion.startsWith("v1") || apiVersion.startsWith("v2")) {
89+
throw new Error("This Aspose.Imaging Cloud SDK version is intended to be used with API v3.0 or later!");
90+
}
91+
92+
this.apiVersion = apiVersion;
93+
}
94+
95+
if (!this.onPremise) {
96+
this.authentication = new JwtAuth() as IAuthentication;
97+
}
98+
}
99+
100+
/**
101+
* Returns api base url
102+
*/
103+
public getApiBaseUrl(): string {
104+
return this.baseUrl + this.apiVersion;
105+
}
106+
}

0 commit comments

Comments
 (0)