@gofynd/fdk-client-javascript 1.0.4 → 1.1.1
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/README.md +19 -0
- package/index.d.ts +4 -1
- package/index.js +19 -3
- package/package.json +13 -4
- package/partner.d.ts +4 -0
- package/partner.js +7 -0
- package/sdk/application/ApplicationAPIClient.js +2 -4
- package/sdk/application/Catalog/CatalogApplicationClient.d.ts +6 -1
- package/sdk/application/Catalog/CatalogApplicationClient.js +11 -2
- package/sdk/application/Catalog/CatalogApplicationModel.js +4 -2
- package/sdk/application/Catalog/CatalogApplicationValidator.js +2 -0
- package/sdk/application/Content/ContentApplicationModel.js +0 -5
- package/sdk/application/Lead/LeadApplicationModel.js +1 -0
- package/sdk/application/Order/OrderApplicationClient.d.ts +0 -15
- package/sdk/application/Order/OrderApplicationClient.js +0 -68
- package/sdk/application/Order/OrderApplicationModel.d.ts +0 -17
- package/sdk/application/Order/OrderApplicationModel.js +0 -111
- package/sdk/application/Order/OrderApplicationValidator.d.ts +0 -1
- package/sdk/application/Order/OrderApplicationValidator.js +0 -7
- package/sdk/common/AxiosHelper.js +1 -1
- package/sdk/common/BaseOAuthClient.d.ts +17 -0
- package/sdk/common/BaseOAuthClient.js +67 -0
- package/sdk/common/Constant.d.ts +0 -18
- package/sdk/common/Constant.js +0 -22
- package/sdk/common/RequestSigner.js +0 -5
- package/sdk/partner/OAuthClient.d.ts +14 -0
- package/sdk/partner/OAuthClient.js +112 -0
- package/sdk/{APIClient.d.ts → partner/PartnerAPIClient.d.ts} +2 -1
- package/sdk/{APIClient.js → partner/PartnerAPIClient.js} +13 -6
- package/sdk/{Client.d.ts → partner/PartnerClient.d.ts} +2 -2
- package/sdk/{Client.js → partner/PartnerClient.js} +2 -2
- package/sdk/partner/PartnerConfig.d.ts +30 -0
- package/sdk/partner/PartnerConfig.js +39 -0
- package/sdk/partner/index.d.ts +3 -0
- package/sdk/partner/index.js +5 -0
- package/sdk/platform/Billing/BillingPlatformClient.d.ts +24 -0
- package/sdk/platform/Billing/BillingPlatformClient.js +134 -0
- package/sdk/platform/Billing/BillingPlatformModel.d.ts +4 -0
- package/sdk/platform/Billing/BillingPlatformModel.js +44 -0
- package/sdk/platform/Billing/BillingPlatformValidator.d.ts +2 -0
- package/sdk/platform/Billing/BillingPlatformValidator.js +14 -0
- package/sdk/platform/Cart/CartPlatformApplicationClient.d.ts +29 -0
- package/sdk/platform/Cart/CartPlatformApplicationClient.js +181 -0
- package/sdk/platform/Cart/CartPlatformApplicationValidator.d.ts +3 -0
- package/sdk/platform/Cart/CartPlatformApplicationValidator.js +17 -0
- package/sdk/platform/Cart/CartPlatformModel.d.ts +4 -0
- package/sdk/platform/Cart/CartPlatformModel.js +37 -0
- package/sdk/platform/Catalog/CatalogPlatformApplicationClient.d.ts +3 -1
- package/sdk/platform/Catalog/CatalogPlatformApplicationClient.js +5 -0
- package/sdk/platform/Catalog/CatalogPlatformApplicationValidator.js +1 -0
- package/sdk/platform/Catalog/CatalogPlatformClient.d.ts +1 -1
- package/sdk/platform/Catalog/CatalogPlatformClient.js +1 -1
- package/sdk/platform/Catalog/CatalogPlatformModel.js +1 -5
- package/sdk/platform/Communication/CommunicationPlatformApplicationClient.d.ts +0 -183
- package/sdk/platform/Communication/CommunicationPlatformApplicationClient.js +0 -417
- package/sdk/platform/Communication/CommunicationPlatformClient.d.ts +0 -10
- package/sdk/platform/Communication/CommunicationPlatformClient.js +0 -26
- package/sdk/platform/CompanyProfile/CompanyProfilePlatformModel.js +4 -0
- package/sdk/platform/Configuration/ConfigurationPlatformClient.d.ts +0 -22
- package/sdk/platform/Configuration/ConfigurationPlatformClient.js +0 -56
- package/sdk/platform/Content/ContentPlatformApplicationClient.d.ts +22 -1
- package/sdk/platform/Content/ContentPlatformApplicationClient.js +123 -2
- package/sdk/platform/Content/ContentPlatformApplicationValidator.d.ts +2 -0
- package/sdk/platform/Content/ContentPlatformApplicationValidator.js +12 -0
- package/sdk/platform/Content/ContentPlatformModel.js +0 -5
- package/sdk/platform/Discount/DiscountPlatformClient.d.ts +2 -2
- package/sdk/platform/Discount/DiscountPlatformClient.js +1 -1
- package/sdk/platform/Discount/DiscountPlatformModel.d.ts +1 -0
- package/sdk/platform/Discount/DiscountPlatformModel.js +15 -0
- package/sdk/platform/Discount/DiscountPlatformValidator.js +1 -1
- package/sdk/platform/FileStorage/FileStoragePlatformClient.js +1 -1
- package/sdk/platform/Lead/LeadPlatformModel.js +1 -0
- package/sdk/platform/OAuthClient.js +3 -9
- package/sdk/platform/Order/OrderPlatformApplicationClient.d.ts +1 -47
- package/sdk/platform/Order/OrderPlatformApplicationClient.js +5 -201
- package/sdk/platform/Order/OrderPlatformApplicationValidator.d.ts +1 -3
- package/sdk/platform/Order/OrderPlatformApplicationValidator.js +1 -26
- package/sdk/platform/Order/OrderPlatformClient.d.ts +51 -183
- package/sdk/platform/Order/OrderPlatformClient.js +243 -931
- package/sdk/platform/Order/OrderPlatformModel.d.ts +4 -20
- package/sdk/platform/Order/OrderPlatformModel.js +38 -182
- package/sdk/platform/Order/OrderPlatformValidator.d.ts +3 -12
- package/sdk/platform/Order/OrderPlatformValidator.js +19 -95
- package/sdk/platform/Payment/PaymentPlatformApplicationClient.d.ts +24 -10
- package/sdk/platform/Payment/PaymentPlatformApplicationClient.js +111 -44
- package/sdk/platform/Payment/PaymentPlatformApplicationValidator.d.ts +2 -1
- package/sdk/platform/Payment/PaymentPlatformApplicationValidator.js +13 -5
- package/sdk/platform/Payment/PaymentPlatformModel.d.ts +2 -0
- package/sdk/platform/Payment/PaymentPlatformModel.js +12 -0
- package/sdk/platform/PlatformApplicationClient.d.ts +16 -41
- package/sdk/platform/PlatformApplicationClient.js +17 -45
- package/sdk/platform/PlatformClient.d.ts +124 -263
- package/sdk/platform/PlatformClient.js +148 -315
- package/sdk/platform/Rewards/RewardsPlatformApplicationClient.d.ts +14 -16
- package/sdk/platform/Rewards/RewardsPlatformApplicationClient.js +63 -77
- package/sdk/platform/Rewards/RewardsPlatformApplicationValidator.d.ts +1 -1
- package/sdk/platform/Rewards/RewardsPlatformApplicationValidator.js +7 -8
- package/sdk/platform/Share/SharePlatformApplicationClient.d.ts +11 -0
- package/sdk/platform/Share/SharePlatformApplicationClient.js +61 -0
- package/sdk/platform/Share/SharePlatformApplicationValidator.d.ts +1 -0
- package/sdk/platform/Share/SharePlatformApplicationValidator.js +6 -0
- package/sdk/platform/Share/SharePlatformModel.d.ts +2 -0
- package/sdk/platform/Share/SharePlatformModel.js +11 -0
- package/sdk/platform/index.d.ts +0 -1
- package/sdk/platform/index.js +0 -2
- package/sdk/Config.d.ts +0 -9
- package/sdk/Config.js +0 -17
- package/sdk/constructUrl.d.ts +0 -5
- package/sdk/constructUrl.js +0 -13
- package/sdk/index.d.ts +0 -3
- package/sdk/index.js +0 -5
- package/sdk/platform/Analytics/AnalyticsPlatformApplicationClient.d.ts +0 -109
- package/sdk/platform/Analytics/AnalyticsPlatformApplicationClient.js +0 -558
- package/sdk/platform/Analytics/AnalyticsPlatformApplicationValidator.d.ts +0 -11
- package/sdk/platform/Analytics/AnalyticsPlatformApplicationValidator.js +0 -56
- package/sdk/platform/Analytics/AnalyticsPlatformClient.d.ts +0 -88
- package/sdk/platform/Analytics/AnalyticsPlatformClient.js +0 -361
- package/sdk/platform/Analytics/AnalyticsPlatformModel.d.ts +0 -23
- package/sdk/platform/Analytics/AnalyticsPlatformModel.js +0 -169
- package/sdk/platform/Analytics/AnalyticsPlatformValidator.d.ts +0 -7
- package/sdk/platform/Analytics/AnalyticsPlatformValidator.js +0 -38
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export = BaseOAuthClient;
|
|
2
|
+
declare class BaseOAuthClient {
|
|
3
|
+
constructor(config: any);
|
|
4
|
+
config: any;
|
|
5
|
+
token: any;
|
|
6
|
+
refreshToken: any;
|
|
7
|
+
retryOAuthTokenTimer: NodeJS.Timeout;
|
|
8
|
+
raw_token: any;
|
|
9
|
+
token_expires_in: any;
|
|
10
|
+
token_expires_at: number;
|
|
11
|
+
useAutoRenewTimer: any;
|
|
12
|
+
getAccessToken(): Promise<any>;
|
|
13
|
+
isTokenExpired(ttl?: number): boolean;
|
|
14
|
+
setToken(token: any): void;
|
|
15
|
+
retryOAuthToken(expires_in: any): void;
|
|
16
|
+
renewAccessToken(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { Logger } = require("./Logger");
|
|
2
|
+
|
|
3
|
+
class BaseOAuthClient {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
this.token = null;
|
|
7
|
+
this.refreshToken = null;
|
|
8
|
+
this.retryOAuthTokenTimer = null;
|
|
9
|
+
this.raw_token = null;
|
|
10
|
+
this.token_expires_in = null;
|
|
11
|
+
this.token_expires_at = 0;
|
|
12
|
+
this.useAutoRenewTimer =
|
|
13
|
+
config.useAutoRenewTimer !== undefined ? config.useAutoRenewTimer : true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async getAccessToken() {
|
|
17
|
+
if (
|
|
18
|
+
!this.useAutoRenewTimer &&
|
|
19
|
+
this.refreshToken &&
|
|
20
|
+
this.isTokenExpired(120)
|
|
21
|
+
) {
|
|
22
|
+
// Check if token is about to expire in less than 2 mins.
|
|
23
|
+
// Renew if to be expired and auto renew timer is not enabled.
|
|
24
|
+
await this.renewAccessToken();
|
|
25
|
+
}
|
|
26
|
+
return this.token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// default TTL checked 0 seconds
|
|
30
|
+
isTokenExpired(ttl = 0) {
|
|
31
|
+
const currentTimestamp = new Date().getTime();
|
|
32
|
+
// Check if token is about to expire in less than 2 mins
|
|
33
|
+
if ((this.token_expires_at - currentTimestamp) / 1000 < ttl) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setToken(token) {
|
|
40
|
+
this.raw_token = token;
|
|
41
|
+
this.token_expires_in = token.expires_in;
|
|
42
|
+
this.token = token.access_token;
|
|
43
|
+
this.token_expires_at = token.expires_at || this.token_expires_at;
|
|
44
|
+
this.refreshToken = token.refresh_token ? token.refresh_token : null;
|
|
45
|
+
if (this.refreshToken && this.useAutoRenewTimer) {
|
|
46
|
+
this.retryOAuthToken(token.expires_in);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
retryOAuthToken(expires_in) {
|
|
51
|
+
Logger({ type: "INFO", message: "Retrying OAuth Token" });
|
|
52
|
+
if (this.retryOAuthTokenTimer) {
|
|
53
|
+
clearTimeout(this.retryOAuthTokenTimer);
|
|
54
|
+
}
|
|
55
|
+
if (expires_in > 60) {
|
|
56
|
+
this.retryOAuthTokenTimer = setTimeout(() => {
|
|
57
|
+
this.renewAccessToken();
|
|
58
|
+
}, (expires_in - 60) * 1000);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async renewAccessToken() {
|
|
63
|
+
// Impementation to renew Access Token
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = BaseOAuthClient;
|
package/sdk/common/Constant.d.ts
CHANGED
|
@@ -20,8 +20,6 @@ export namespace AVAILABLE_PAGE_TYPE {
|
|
|
20
20
|
const PAGE: string;
|
|
21
21
|
const POLICY: string;
|
|
22
22
|
const PRODUCT: string;
|
|
23
|
-
const PRODUCT_REVIEWS: string;
|
|
24
|
-
const ADD_PRODUCT_REVIEW: string;
|
|
25
23
|
const PRODUCT_REQUEST: string;
|
|
26
24
|
const PRODUCTS: string;
|
|
27
25
|
const PROFILE: string;
|
|
@@ -168,22 +166,6 @@ export const NAVIGATORS: {
|
|
|
168
166
|
required: boolean;
|
|
169
167
|
}[];
|
|
170
168
|
};
|
|
171
|
-
"product-reviews": {
|
|
172
|
-
name: string;
|
|
173
|
-
link: string;
|
|
174
|
-
params: {
|
|
175
|
-
key: string;
|
|
176
|
-
required: boolean;
|
|
177
|
-
}[];
|
|
178
|
-
};
|
|
179
|
-
"add-product-review": {
|
|
180
|
-
name: string;
|
|
181
|
-
link: string;
|
|
182
|
-
params: {
|
|
183
|
-
key: string;
|
|
184
|
-
required: boolean;
|
|
185
|
-
}[];
|
|
186
|
-
};
|
|
187
169
|
"product-request": {
|
|
188
170
|
name: string;
|
|
189
171
|
link: string;
|
package/sdk/common/Constant.js
CHANGED
|
@@ -20,8 +20,6 @@ const AVAILABLE_PAGE_TYPE = {
|
|
|
20
20
|
PAGE: "page",
|
|
21
21
|
POLICY: "policy",
|
|
22
22
|
PRODUCT: "product",
|
|
23
|
-
PRODUCT_REVIEWS: "product-reviews",
|
|
24
|
-
ADD_PRODUCT_REVIEW: "add-product-review",
|
|
25
23
|
PRODUCT_REQUEST: "product-request",
|
|
26
24
|
PRODUCTS: "products",
|
|
27
25
|
PROFILE: "profile",
|
|
@@ -189,26 +187,6 @@ const NAVIGATORS = {
|
|
|
189
187
|
},
|
|
190
188
|
],
|
|
191
189
|
},
|
|
192
|
-
"product-reviews": {
|
|
193
|
-
name: "Product Reviews",
|
|
194
|
-
link: "/product/:slug/reviews",
|
|
195
|
-
params: [
|
|
196
|
-
{
|
|
197
|
-
key: "slug",
|
|
198
|
-
required: true,
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
},
|
|
202
|
-
"add-product-review": {
|
|
203
|
-
name: "Add Product review",
|
|
204
|
-
link: "/product/:slug/add-review",
|
|
205
|
-
params: [
|
|
206
|
-
{
|
|
207
|
-
key: "slug",
|
|
208
|
-
required: true,
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
},
|
|
212
190
|
"product-request": {
|
|
213
191
|
name: "Product Request",
|
|
214
192
|
link: "/product-request/",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const url = require("url");
|
|
4
3
|
const querystring = require("query-string");
|
|
5
4
|
const sha256 = require("crypto-js/sha256");
|
|
6
5
|
const hmacSHA256 = require("crypto-js/hmac-sha256");
|
|
@@ -39,10 +38,6 @@ const HEADERS_TO_INCLUDE = ["x-fp-.*", "host"];
|
|
|
39
38
|
// request: { path | body, [host], [method], [headers], [service], [region] }
|
|
40
39
|
class RequestSigner {
|
|
41
40
|
constructor(request) {
|
|
42
|
-
if (typeof request === "string") {
|
|
43
|
-
request = url.parse(request);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
41
|
let headers = (request.headers = request.headers || {});
|
|
47
42
|
this.request = request;
|
|
48
43
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export = OAuthClient;
|
|
2
|
+
declare class OAuthClient extends BaseOAuthClient {
|
|
3
|
+
startAuthorization(options: any): string;
|
|
4
|
+
verifyCallback(query: any): Promise<void>;
|
|
5
|
+
renewAccessToken(isOfflineToken?: boolean): Promise<any>;
|
|
6
|
+
getNewAccessToken(): Promise<any>;
|
|
7
|
+
getAccesstokenObj({ grant_type, client_id, client_secret, scope }: {
|
|
8
|
+
grant_type: any;
|
|
9
|
+
client_id: any;
|
|
10
|
+
client_secret: any;
|
|
11
|
+
scope: any;
|
|
12
|
+
}): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
import BaseOAuthClient = require("../common/BaseOAuthClient");
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const { fdkAxios } = require("../common/AxiosHelper");
|
|
2
|
+
const { FDKTokenIssueError } = require("../common/FDKError");
|
|
3
|
+
const { Logger } = require("../common/Logger");
|
|
4
|
+
const BaseOAuthClient = require("../common/BaseOAuthClient");
|
|
5
|
+
const querystring = require("querystring");
|
|
6
|
+
const { sign } = require("../common/RequestSigner");
|
|
7
|
+
|
|
8
|
+
class OAuthClient extends BaseOAuthClient {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
startAuthorization(options) {
|
|
14
|
+
Logger({ type: "DEBUG", message: "Starting Authorization" });
|
|
15
|
+
let query = {
|
|
16
|
+
client_id: this.config.apiKey,
|
|
17
|
+
scope: options.scope.join(","),
|
|
18
|
+
redirect_uri: options.redirectUri,
|
|
19
|
+
state: options.state,
|
|
20
|
+
access_mode: options.access_mode,
|
|
21
|
+
response_type: "code",
|
|
22
|
+
extension_id: this.config.extensionId,
|
|
23
|
+
};
|
|
24
|
+
const queryString = querystring.stringify(query);
|
|
25
|
+
|
|
26
|
+
let reqPath = `/service/panel/authentication/v1.0/organization/${this.config.organizationId}/oauth/authorize?${queryString}`;
|
|
27
|
+
let signingOptions = {
|
|
28
|
+
method: "GET",
|
|
29
|
+
host: new URL(this.config.domain).host,
|
|
30
|
+
path: reqPath,
|
|
31
|
+
body: null,
|
|
32
|
+
headers: {},
|
|
33
|
+
signQuery: true,
|
|
34
|
+
};
|
|
35
|
+
signingOptions = sign(signingOptions);
|
|
36
|
+
Logger({ type: "DEBUG", message: "Authorization successful" });
|
|
37
|
+
|
|
38
|
+
return `${this.config.domain}${signingOptions.path}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async verifyCallback(query) {
|
|
42
|
+
if (query.error) {
|
|
43
|
+
throw new FDKOAuthCodeError(query.error_description, {
|
|
44
|
+
error: query.error,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
let res = await this.getAccesstokenObj({
|
|
50
|
+
grant_type: "authorization_code",
|
|
51
|
+
code: query.code,
|
|
52
|
+
});
|
|
53
|
+
res.expires_at =
|
|
54
|
+
res.expires_at || new Date().getTime() + res.expires_in * 1000;
|
|
55
|
+
this.setToken(res);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.isAxiosError) {
|
|
58
|
+
throw new FDKTokenIssueError(error.message);
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async renewAccessToken(isOfflineToken = true) {
|
|
65
|
+
if (isOfflineToken) {
|
|
66
|
+
await this.getNewAccessToken();
|
|
67
|
+
} else {
|
|
68
|
+
res = await this.getAccesstokenObj({
|
|
69
|
+
grant_type: "refresh_token",
|
|
70
|
+
refresh_token: this.refreshToken,
|
|
71
|
+
});
|
|
72
|
+
res.expires_at =
|
|
73
|
+
res.expires_at || new Date().getTime() + res.expires_in * 1000;
|
|
74
|
+
this.setToken(res);
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getNewAccessToken() {
|
|
80
|
+
try {
|
|
81
|
+
let res = await this.getAccesstokenObj({
|
|
82
|
+
grant_type: "client_credentials",
|
|
83
|
+
client_id: this.config.apiKey,
|
|
84
|
+
client_secret: this.config.apiSecret,
|
|
85
|
+
scope: this.config.scope,
|
|
86
|
+
});
|
|
87
|
+
res.expires_at =
|
|
88
|
+
res.expires_at || new Date().getTime() + res.expires_in * 1000;
|
|
89
|
+
this.setToken(res);
|
|
90
|
+
return this.token;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error.isAxiosError) {
|
|
93
|
+
throw new FDKTokenIssueError(error.message);
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getAccesstokenObj({ grant_type, client_id, client_secret, scope }) {
|
|
100
|
+
Logger({ type: "DEBUG", message: "Processing Access token object..." });
|
|
101
|
+
let reqData = {
|
|
102
|
+
grant_type: grant_type,
|
|
103
|
+
client_id,
|
|
104
|
+
client_secret,
|
|
105
|
+
scope,
|
|
106
|
+
};
|
|
107
|
+
let url = `${this.config.domain}/service/panel/authentication/v1.0/organization/${this.config.organizationId}/oauth/token`;
|
|
108
|
+
return fdkAxios.post(url, reqData);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = OAuthClient;
|
|
@@ -7,5 +7,6 @@ declare class APIClient {
|
|
|
7
7
|
* @param {object} query
|
|
8
8
|
* @param {object} body
|
|
9
9
|
*/
|
|
10
|
-
static execute(conf: object, method: string, url: string, query: object, body: object
|
|
10
|
+
static execute(conf: object, method: string, url: string, query: object, body: object): Promise<any>;
|
|
11
|
+
get(url: any, config: any): Promise<any>;
|
|
11
12
|
}
|
|
@@ -8,9 +8,8 @@ class APIClient {
|
|
|
8
8
|
* @param {object} query
|
|
9
9
|
* @param {object} body
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let headers = {};
|
|
11
|
+
static async execute(conf, method, url, query, body) {
|
|
12
|
+
const token = await conf.oauthClient.getNewAccessToken();
|
|
14
13
|
|
|
15
14
|
const extraHeaders = conf.extraHeaders.reduce((acc, curr) => {
|
|
16
15
|
acc = { ...acc, ...curr };
|
|
@@ -18,18 +17,26 @@ class APIClient {
|
|
|
18
17
|
}, {});
|
|
19
18
|
|
|
20
19
|
const rawRequest = {
|
|
20
|
+
baseURL: conf.domain,
|
|
21
21
|
method: method,
|
|
22
22
|
url: url,
|
|
23
23
|
params: query,
|
|
24
24
|
data: body,
|
|
25
25
|
headers: {
|
|
26
|
-
|
|
26
|
+
Authorization: "Bearer " + token,
|
|
27
27
|
...extraHeaders,
|
|
28
|
-
...xHeaders,
|
|
29
28
|
},
|
|
30
29
|
};
|
|
30
|
+
|
|
31
31
|
return fdkAxios.request(rawRequest);
|
|
32
32
|
}
|
|
33
|
-
}
|
|
34
33
|
|
|
34
|
+
async get(url, config) {
|
|
35
|
+
let access_token = await this.configuration.getAccessToken();
|
|
36
|
+
config = config || {};
|
|
37
|
+
config.headers = config.headers || {};
|
|
38
|
+
config.headers.Authorization = "Bearer " + access_token;
|
|
39
|
+
return axios.get(url);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
35
42
|
module.exports = APIClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { FDKClientValidationError } = require("../common/FDKError");
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class PartnerClient {
|
|
4
4
|
constructor(config) {
|
|
5
5
|
this.config = config;
|
|
6
6
|
}
|
|
@@ -14,4 +14,4 @@ class Client {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
module.exports =
|
|
17
|
+
module.exports = PartnerClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export = PartnerConfig;
|
|
2
|
+
declare class PartnerConfig {
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} config
|
|
5
|
+
* @param {string} config.companyId
|
|
6
|
+
* @param {string} config.domain
|
|
7
|
+
* @param {string} config.apiKey
|
|
8
|
+
* @param {string} config.apiSecret
|
|
9
|
+
* @param {boolean} config.useAutoRenewTimer
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: {
|
|
12
|
+
companyId: string;
|
|
13
|
+
domain: string;
|
|
14
|
+
apiKey: string;
|
|
15
|
+
apiSecret: string;
|
|
16
|
+
useAutoRenewTimer: boolean;
|
|
17
|
+
});
|
|
18
|
+
organizationId: any;
|
|
19
|
+
domain: string;
|
|
20
|
+
apiKey: string;
|
|
21
|
+
apiSecret: string;
|
|
22
|
+
scope: any;
|
|
23
|
+
useAutoRenewTimer: boolean;
|
|
24
|
+
oauthClient: OauthClient;
|
|
25
|
+
logLevel: any;
|
|
26
|
+
extraHeaders: any[];
|
|
27
|
+
setLogLevel(level: any): void;
|
|
28
|
+
getAccessToken(): Promise<any>;
|
|
29
|
+
}
|
|
30
|
+
import OauthClient = require("./OAuthClient");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const OauthClient = require("./OAuthClient");
|
|
2
|
+
const { setLoggerLevel } = require("../common/Logger");
|
|
3
|
+
|
|
4
|
+
class PartnerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Object} config
|
|
7
|
+
* @param {string} config.companyId
|
|
8
|
+
* @param {string} config.domain
|
|
9
|
+
* @param {string} config.apiKey
|
|
10
|
+
* @param {string} config.apiSecret
|
|
11
|
+
* @param {boolean} config.useAutoRenewTimer
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.organizationId = config.organizationId;
|
|
15
|
+
this.domain = config.domain || "https://api.fynd.com";
|
|
16
|
+
this.apiKey = config.apiKey;
|
|
17
|
+
this.apiSecret = config.apiSecret;
|
|
18
|
+
(this.scope = config.scope),
|
|
19
|
+
(this.useAutoRenewTimer =
|
|
20
|
+
config.useAutoRenewTimer !== undefined
|
|
21
|
+
? config.useAutoRenewTimer
|
|
22
|
+
: true);
|
|
23
|
+
this.oauthClient = new OauthClient(this);
|
|
24
|
+
this.logLevel = config.logLevel || "ERROR";
|
|
25
|
+
this.setLogLevel(this.logLevel);
|
|
26
|
+
this.extraHeaders = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setLogLevel(level) {
|
|
30
|
+
setLoggerLevel(level);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getAccessToken() {
|
|
34
|
+
let token = await this.oauthClient.getAccessToken();
|
|
35
|
+
return token.access_token;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = PartnerConfig;
|
|
@@ -46,6 +46,18 @@ declare class Billing {
|
|
|
46
46
|
plan: string;
|
|
47
47
|
couponCode: string;
|
|
48
48
|
}): Promise<CheckValidityResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* @param {Object} arg - Arg object.
|
|
51
|
+
* @param {string} arg.extensionId - Extension _id
|
|
52
|
+
* @param {CreateOneTimeCharge} arg.body
|
|
53
|
+
* @returns {Promise<CreateOneTimeChargeResponse>} - Success response
|
|
54
|
+
* @summary: Create one time subscription charge
|
|
55
|
+
* @description: Register one time subscription charge for a seller of your extension.
|
|
56
|
+
*/
|
|
57
|
+
createOneTimeCharge({ extensionId, body }?: {
|
|
58
|
+
extensionId: string;
|
|
59
|
+
body: CreateOneTimeCharge;
|
|
60
|
+
}): Promise<CreateOneTimeChargeResponse>;
|
|
49
61
|
/**
|
|
50
62
|
* @param {Object} arg - Arg object.
|
|
51
63
|
* @param {string} arg.extensionId - Extension _id
|
|
@@ -58,6 +70,18 @@ declare class Billing {
|
|
|
58
70
|
extensionId: string;
|
|
59
71
|
body: CreateSubscriptionCharge;
|
|
60
72
|
}): Promise<CreateSubscriptionResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* @param {Object} arg - Arg object.
|
|
75
|
+
* @param {string} arg.extensionId - Extension _id
|
|
76
|
+
* @param {string} arg.chargeId - Standalone charge _id
|
|
77
|
+
* @returns {Promise<OneTimeChargeEntity>} - Success response
|
|
78
|
+
* @summary: Get subscription charge details
|
|
79
|
+
* @description: Get created subscription charge details
|
|
80
|
+
*/
|
|
81
|
+
getChargeDetails({ extensionId, chargeId }?: {
|
|
82
|
+
extensionId: string;
|
|
83
|
+
chargeId: string;
|
|
84
|
+
}): Promise<OneTimeChargeEntity>;
|
|
61
85
|
/**
|
|
62
86
|
* @param {Object} arg - Arg object.
|
|
63
87
|
* @returns {Promise<SubscriptionCustomer>} - Success response
|
|
@@ -281,6 +281,73 @@ class Billing {
|
|
|
281
281
|
return response;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* @param {Object} arg - Arg object.
|
|
286
|
+
* @param {string} arg.extensionId - Extension _id
|
|
287
|
+
* @param {CreateOneTimeCharge} arg.body
|
|
288
|
+
* @returns {Promise<CreateOneTimeChargeResponse>} - Success response
|
|
289
|
+
* @summary: Create one time subscription charge
|
|
290
|
+
* @description: Register one time subscription charge for a seller of your extension.
|
|
291
|
+
*/
|
|
292
|
+
async createOneTimeCharge({ extensionId, body } = {}) {
|
|
293
|
+
const { error } = BillingValidator.createOneTimeCharge().validate(
|
|
294
|
+
{
|
|
295
|
+
extensionId,
|
|
296
|
+
body,
|
|
297
|
+
},
|
|
298
|
+
{ abortEarly: false, allowUnknown: true }
|
|
299
|
+
);
|
|
300
|
+
if (error) {
|
|
301
|
+
return Promise.reject(new FDKClientValidationError(error));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Showing warrnings if extra unknown parameters are found
|
|
305
|
+
const { error: warrning } = BillingValidator.createOneTimeCharge().validate(
|
|
306
|
+
{
|
|
307
|
+
extensionId,
|
|
308
|
+
body,
|
|
309
|
+
},
|
|
310
|
+
{ abortEarly: false, allowUnknown: false }
|
|
311
|
+
);
|
|
312
|
+
if (warrning) {
|
|
313
|
+
Logger({
|
|
314
|
+
level: "WARN",
|
|
315
|
+
message: "Parameter Validation warrnings for createOneTimeCharge",
|
|
316
|
+
});
|
|
317
|
+
Logger({ level: "WARN", message: warrning });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const query_params = {};
|
|
321
|
+
|
|
322
|
+
const xHeaders = {};
|
|
323
|
+
|
|
324
|
+
const response = await PlatformAPIClient.execute(
|
|
325
|
+
this.config,
|
|
326
|
+
"post",
|
|
327
|
+
`/service/platform/billing/v1.0/company/${this.config.companyId}/extension/${extensionId}/one_time_charge`,
|
|
328
|
+
query_params,
|
|
329
|
+
body,
|
|
330
|
+
xHeaders
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const {
|
|
334
|
+
error: res_error,
|
|
335
|
+
} = BillingModel.CreateOneTimeChargeResponse().validate(response, {
|
|
336
|
+
abortEarly: false,
|
|
337
|
+
allowUnknown: false,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
if (res_error) {
|
|
341
|
+
Logger({
|
|
342
|
+
level: "WARN",
|
|
343
|
+
message: "Response Validation Warnnings for createOneTimeCharge",
|
|
344
|
+
});
|
|
345
|
+
Logger({ level: "WARN", message: res_error });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return response;
|
|
349
|
+
}
|
|
350
|
+
|
|
284
351
|
/**
|
|
285
352
|
* @param {Object} arg - Arg object.
|
|
286
353
|
* @param {string} arg.extensionId - Extension _id
|
|
@@ -350,6 +417,73 @@ class Billing {
|
|
|
350
417
|
return response;
|
|
351
418
|
}
|
|
352
419
|
|
|
420
|
+
/**
|
|
421
|
+
* @param {Object} arg - Arg object.
|
|
422
|
+
* @param {string} arg.extensionId - Extension _id
|
|
423
|
+
* @param {string} arg.chargeId - Standalone charge _id
|
|
424
|
+
* @returns {Promise<OneTimeChargeEntity>} - Success response
|
|
425
|
+
* @summary: Get subscription charge details
|
|
426
|
+
* @description: Get created subscription charge details
|
|
427
|
+
*/
|
|
428
|
+
async getChargeDetails({ extensionId, chargeId } = {}) {
|
|
429
|
+
const { error } = BillingValidator.getChargeDetails().validate(
|
|
430
|
+
{
|
|
431
|
+
extensionId,
|
|
432
|
+
chargeId,
|
|
433
|
+
},
|
|
434
|
+
{ abortEarly: false, allowUnknown: true }
|
|
435
|
+
);
|
|
436
|
+
if (error) {
|
|
437
|
+
return Promise.reject(new FDKClientValidationError(error));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Showing warrnings if extra unknown parameters are found
|
|
441
|
+
const { error: warrning } = BillingValidator.getChargeDetails().validate(
|
|
442
|
+
{
|
|
443
|
+
extensionId,
|
|
444
|
+
chargeId,
|
|
445
|
+
},
|
|
446
|
+
{ abortEarly: false, allowUnknown: false }
|
|
447
|
+
);
|
|
448
|
+
if (warrning) {
|
|
449
|
+
Logger({
|
|
450
|
+
level: "WARN",
|
|
451
|
+
message: "Parameter Validation warrnings for getChargeDetails",
|
|
452
|
+
});
|
|
453
|
+
Logger({ level: "WARN", message: warrning });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const query_params = {};
|
|
457
|
+
|
|
458
|
+
const xHeaders = {};
|
|
459
|
+
|
|
460
|
+
const response = await PlatformAPIClient.execute(
|
|
461
|
+
this.config,
|
|
462
|
+
"get",
|
|
463
|
+
`/service/platform/billing/v1.0/company/${this.config.companyId}/extension/${extensionId}/charge/${chargeId}`,
|
|
464
|
+
query_params,
|
|
465
|
+
undefined,
|
|
466
|
+
xHeaders
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
const {
|
|
470
|
+
error: res_error,
|
|
471
|
+
} = BillingModel.OneTimeChargeEntity().validate(response, {
|
|
472
|
+
abortEarly: false,
|
|
473
|
+
allowUnknown: false,
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
if (res_error) {
|
|
477
|
+
Logger({
|
|
478
|
+
level: "WARN",
|
|
479
|
+
message: "Response Validation Warnnings for getChargeDetails",
|
|
480
|
+
});
|
|
481
|
+
Logger({ level: "WARN", message: res_error });
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return response;
|
|
485
|
+
}
|
|
486
|
+
|
|
353
487
|
/**
|
|
354
488
|
* @param {Object} arg - Arg object.
|
|
355
489
|
* @returns {Promise<SubscriptionCustomer>} - Success response
|
|
@@ -5,6 +5,8 @@ declare class BillingModel {
|
|
|
5
5
|
static CancelSubscriptionRes(): any;
|
|
6
6
|
static ChargeLineItem(): any;
|
|
7
7
|
static CheckValidityResponse(): any;
|
|
8
|
+
static CreateOneTimeCharge(): any;
|
|
9
|
+
static CreateOneTimeChargeResponse(): any;
|
|
8
10
|
static CreateSubscriptionCharge(): any;
|
|
9
11
|
static CreateSubscriptionResponse(): any;
|
|
10
12
|
static CurrentPeriod(): any;
|
|
@@ -34,6 +36,8 @@ declare class BillingModel {
|
|
|
34
36
|
static InvoicesDataClient(): any;
|
|
35
37
|
static InvoicesDataPaymentMethod(): any;
|
|
36
38
|
static InvoicesDataPeriod(): any;
|
|
39
|
+
static OneTimeChargeEntity(): any;
|
|
40
|
+
static OneTimeChargeItem(): any;
|
|
37
41
|
static Page(): any;
|
|
38
42
|
static Phone(): any;
|
|
39
43
|
static Plan(): any;
|