@gofynd/fdk-client-javascript 1.0.3 → 1.1.0
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 +51 -2
- package/index.d.ts +7 -4
- package/index.js +22 -7
- package/package.json +23 -14
- package/partner.d.ts +4 -0
- package/partner.js +7 -0
- package/sdk/application/ApplicationAPIClient.js +2 -4
- package/sdk/application/Cart/CartApplicationClient.js +29 -28
- package/sdk/application/Cart/CartApplicationModel.js +3 -1
- package/sdk/application/Catalog/CatalogApplicationClient.js +43 -42
- package/sdk/application/Catalog/CatalogApplicationModel.js +5 -3
- package/sdk/application/Common/CommonApplicationClient.js +5 -4
- package/sdk/application/Communication/CommunicationApplicationClient.js +6 -5
- package/sdk/application/Configuration/ConfigurationApplicationClient.js +21 -20
- package/sdk/application/Content/ContentApplicationClient.js +26 -25
- package/sdk/application/FileStorage/FileStorageApplicationClient.js +6 -5
- package/sdk/application/Lead/LeadApplicationClient.js +10 -9
- package/sdk/application/Logistic/LogisticApplicationClient.d.ts +1 -3
- package/sdk/application/Logistic/LogisticApplicationClient.js +11 -12
- package/sdk/application/Logistic/LogisticApplicationValidator.js +0 -1
- package/sdk/application/Order/OrderApplicationClient.js +15 -14
- package/sdk/application/Order/OrderApplicationModel.js +9 -0
- package/sdk/application/Payment/PaymentApplicationClient.js +42 -41
- package/sdk/application/PosCart/PosCartApplicationClient.js +30 -29
- package/sdk/application/PosCart/PosCartApplicationModel.js +3 -1
- package/sdk/application/Rewards/RewardsApplicationClient.js +11 -10
- package/sdk/application/Share/ShareApplicationClient.js +10 -9
- package/sdk/application/Theme/ThemeApplicationClient.js +7 -6
- package/sdk/application/User/UserApplicationClient.js +38 -37
- package/sdk/common/AxiosHelper.js +17 -6
- package/sdk/common/BaseOAuthClient.d.ts +17 -0
- package/sdk/common/BaseOAuthClient.js +67 -0
- package/sdk/common/RequestSigner.js +0 -5
- package/sdk/partner/OAuthClient.d.ts +14 -0
- package/sdk/partner/OAuthClient.js +112 -0
- package/sdk/partner/PartnerAPIClient.d.ts +12 -0
- package/sdk/partner/PartnerAPIClient.js +42 -0
- package/sdk/partner/PartnerClient.d.ts +6 -0
- package/sdk/partner/PartnerClient.js +17 -0
- 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/Analytics/AnalyticsPlatformApplicationClient.js +3 -1
- package/sdk/platform/Analytics/AnalyticsPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Analytics/AnalyticsPlatformClient.js +5 -4
- package/sdk/platform/Analytics/AnalyticsPlatformValidator.js +1 -0
- package/sdk/platform/AuditTrail/AuditTrailPlatformClient.js +3 -2
- package/sdk/platform/AuditTrail/AuditTrailPlatformValidator.js +1 -0
- package/sdk/platform/Billing/BillingPlatformClient.d.ts +24 -0
- package/sdk/platform/Billing/BillingPlatformClient.js +137 -2
- 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 +15 -0
- package/sdk/platform/Cart/CartPlatformApplicationClient.d.ts +27 -0
- package/sdk/platform/Cart/CartPlatformApplicationClient.js +177 -1
- package/sdk/platform/Cart/CartPlatformApplicationValidator.d.ts +3 -0
- package/sdk/platform/Cart/CartPlatformApplicationValidator.js +17 -1
- package/sdk/platform/Cart/CartPlatformModel.js +7 -3
- package/sdk/platform/Catalog/CatalogPlatformApplicationClient.js +3 -1
- package/sdk/platform/Catalog/CatalogPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Catalog/CatalogPlatformClient.d.ts +2 -2
- package/sdk/platform/Catalog/CatalogPlatformClient.js +6 -9
- package/sdk/platform/Catalog/CatalogPlatformModel.js +9 -9
- package/sdk/platform/Catalog/CatalogPlatformValidator.js +2 -1
- package/sdk/platform/Common/CommonPlatformClient.js +7 -18
- package/sdk/platform/Common/CommonPlatformValidator.js +1 -0
- package/sdk/platform/Communication/CommunicationPlatformApplicationClient.js +3 -1
- package/sdk/platform/Communication/CommunicationPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Communication/CommunicationPlatformClient.js +4 -3
- package/sdk/platform/Communication/CommunicationPlatformValidator.js +1 -0
- package/sdk/platform/CompanyProfile/CompanyProfilePlatformClient.js +5 -4
- package/sdk/platform/CompanyProfile/CompanyProfilePlatformValidator.js +1 -0
- package/sdk/platform/Configuration/ConfigurationPlatformApplicationClient.js +3 -1
- package/sdk/platform/Configuration/ConfigurationPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Configuration/ConfigurationPlatformClient.js +9 -8
- package/sdk/platform/Configuration/ConfigurationPlatformValidator.js +1 -0
- package/sdk/platform/Content/ContentPlatformApplicationClient.js +3 -1
- package/sdk/platform/Content/ContentPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Discount/DiscountPlatformClient.js +3 -2
- package/sdk/platform/Discount/DiscountPlatformValidator.js +1 -0
- package/sdk/platform/FileStorage/FileStoragePlatformApplicationClient.d.ts +3 -3
- package/sdk/platform/FileStorage/FileStoragePlatformApplicationClient.js +27 -5
- package/sdk/platform/FileStorage/FileStoragePlatformApplicationValidator.js +1 -1
- package/sdk/platform/FileStorage/FileStoragePlatformClient.d.ts +3 -3
- package/sdk/platform/FileStorage/FileStoragePlatformClient.js +28 -6
- package/sdk/platform/FileStorage/FileStoragePlatformValidator.js +1 -0
- package/sdk/platform/Inventory/InventoryPlatformClient.js +3 -2
- package/sdk/platform/Inventory/InventoryPlatformValidator.js +1 -0
- package/sdk/platform/Lead/LeadPlatformApplicationClient.js +3 -1
- package/sdk/platform/Lead/LeadPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Lead/LeadPlatformClient.js +4 -3
- package/sdk/platform/Lead/LeadPlatformValidator.js +1 -0
- package/sdk/platform/OAuthClient.js +3 -9
- package/sdk/platform/Order/OrderPlatformApplicationClient.js +3 -1
- package/sdk/platform/Order/OrderPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Order/OrderPlatformClient.d.ts +1 -1
- package/sdk/platform/Order/OrderPlatformClient.js +16 -3
- package/sdk/platform/Order/OrderPlatformModel.js +1 -0
- package/sdk/platform/Order/OrderPlatformValidator.js +1 -0
- package/sdk/platform/Partner/PartnerPlatformApplicationClient.js +3 -1
- package/sdk/platform/Partner/PartnerPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Payment/PaymentPlatformApplicationClient.d.ts +1 -1
- package/sdk/platform/Payment/PaymentPlatformApplicationClient.js +14 -14
- package/sdk/platform/Payment/PaymentPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Payment/PaymentPlatformClient.js +3 -2
- package/sdk/platform/Payment/PaymentPlatformValidator.js +1 -0
- package/sdk/platform/PlatformApplicationClient.d.ts +5 -1
- package/sdk/platform/PlatformApplicationClient.js +4 -0
- package/sdk/platform/PlatformClient.d.ts +51 -12
- package/sdk/platform/PlatformClient.js +54 -11
- package/sdk/platform/Rewards/RewardsPlatformApplicationClient.d.ts +17 -19
- package/sdk/platform/Rewards/RewardsPlatformApplicationClient.js +88 -83
- package/sdk/platform/Rewards/RewardsPlatformApplicationValidator.d.ts +1 -1
- package/sdk/platform/Rewards/RewardsPlatformApplicationValidator.js +8 -9
- package/sdk/platform/Share/SharePlatformApplicationClient.js +3 -1
- package/sdk/platform/Share/SharePlatformApplicationValidator.js +1 -1
- package/sdk/platform/Theme/ThemePlatformApplicationClient.js +3 -1
- package/sdk/platform/Theme/ThemePlatformApplicationValidator.js +1 -1
- package/sdk/platform/User/UserPlatformApplicationClient.js +3 -1
- package/sdk/platform/User/UserPlatformApplicationValidator.js +1 -1
- package/sdk/platform/Webhook/WebhookPlatformClient.js +3 -2
- package/sdk/platform/Webhook/WebhookPlatformValidator.js +1 -0
- package/sdk/public/Configuration/ConfigurationPublicClient.js +2 -0
- package/sdk/public/Inventory/InventoryPublicClient.js +2 -0
- package/sdk/public/Webhook/WebhookPublicClient.js +2 -0
- package/.github/workflows/on_create_release.yml +0 -23
- package/.github/workflows/on_merge_main.yml +0 -38
- package/.github/workflows/on_pull_request.yml +0 -35
- package/.prettierrc +0 -5
- package/documentation/application/CART.md +0 -8771
- package/documentation/application/CATALOG.md +0 -8690
- package/documentation/application/COMMON.md +0 -325
- package/documentation/application/COMMUNICATION.md +0 -387
- package/documentation/application/CONFIGURATION.md +0 -2212
- package/documentation/application/CONTENT.md +0 -2629
- package/documentation/application/FILESTORAGE.md +0 -442
- package/documentation/application/LEAD.md +0 -1549
- package/documentation/application/LOGISTIC.md +0 -689
- package/documentation/application/ORDER.md +0 -2937
- package/documentation/application/PAYMENT.md +0 -4475
- package/documentation/application/POSCART.md +0 -9375
- package/documentation/application/README.md +0 -21
- package/documentation/application/REWARDS.md +0 -554
- package/documentation/application/SHARE.md +0 -635
- package/documentation/application/THEME.md +0 -5517
- package/documentation/application/USER.md +0 -3798
- package/documentation/platform/ANALYTICS.md +0 -1012
- package/documentation/platform/AUDITTRAIL.md +0 -493
- package/documentation/platform/BILLING.md +0 -1889
- package/documentation/platform/CART.md +0 -4711
- package/documentation/platform/CATALOG.md +0 -20522
- package/documentation/platform/COMMON.md +0 -325
- package/documentation/platform/COMMUNICATION.md +0 -4970
- package/documentation/platform/COMPANYPROFILE.md +0 -1646
- package/documentation/platform/CONFIGURATION.md +0 -6316
- package/documentation/platform/CONTENT.md +0 -8364
- package/documentation/platform/DISCOUNT.md +0 -767
- package/documentation/platform/FILESTORAGE.md +0 -945
- package/documentation/platform/INVENTORY.md +0 -1136
- package/documentation/platform/LEAD.md +0 -4394
- package/documentation/platform/ORDER.md +0 -6525
- package/documentation/platform/PARTNER.md +0 -193
- package/documentation/platform/PAYMENT.md +0 -3138
- package/documentation/platform/README.md +0 -27
- package/documentation/platform/REWARDS.md +0 -919
- package/documentation/platform/SHARE.md +0 -513
- package/documentation/platform/THEME.md +0 -35446
- package/documentation/platform/USER.md +0 -2174
- package/documentation/platform/WEBHOOK.md +0 -485
- package/documentation/public/CONFIGURATION.md +0 -325
- package/documentation/public/INVENTORY.md +0 -508
- package/documentation/public/WEBHOOK.md +0 -246
- package/jest.config.d.ts +0 -4
- package/jest.config.js +0 -6
- package/tests/application/catalog.spec.js +0 -54
- package/tests/common/action-url.spec.js +0 -35
- package/tests/common/schema/action-url.json +0 -178
- package/tests/common/schema/url-action.json +0 -683
- package/tests/common/url-action.spec.js +0 -48
- package/tests/helpers/cookie.helper.js +0 -31
- package/tests/helpers/oauth.helper.js +0 -43
- package/tests/platform/catalog.spec.js +0 -49
- package/tests/public/location.spec.js +0 -39
|
@@ -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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export = APIClient;
|
|
2
|
+
declare class APIClient {
|
|
3
|
+
/**
|
|
4
|
+
* @param {object} conf
|
|
5
|
+
* @param {string} method
|
|
6
|
+
* @param {string} url
|
|
7
|
+
* @param {object} query
|
|
8
|
+
* @param {object} body
|
|
9
|
+
*/
|
|
10
|
+
static execute(conf: object, method: string, url: string, query: object, body: object): Promise<any>;
|
|
11
|
+
get(url: any, config: any): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const { fdkAxios } = require("../common/AxiosHelper");
|
|
2
|
+
|
|
3
|
+
class APIClient {
|
|
4
|
+
/**
|
|
5
|
+
* @param {object} conf
|
|
6
|
+
* @param {string} method
|
|
7
|
+
* @param {string} url
|
|
8
|
+
* @param {object} query
|
|
9
|
+
* @param {object} body
|
|
10
|
+
*/
|
|
11
|
+
static async execute(conf, method, url, query, body) {
|
|
12
|
+
const token = await conf.oauthClient.getNewAccessToken();
|
|
13
|
+
|
|
14
|
+
const extraHeaders = conf.extraHeaders.reduce((acc, curr) => {
|
|
15
|
+
acc = { ...acc, ...curr };
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
|
|
19
|
+
const rawRequest = {
|
|
20
|
+
baseURL: conf.domain,
|
|
21
|
+
method: method,
|
|
22
|
+
url: url,
|
|
23
|
+
params: query,
|
|
24
|
+
data: body,
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: "Bearer " + token,
|
|
27
|
+
...extraHeaders,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return fdkAxios.request(rawRequest);
|
|
32
|
+
}
|
|
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
|
+
}
|
|
42
|
+
module.exports = APIClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { FDKClientValidationError } = require("../common/FDKError");
|
|
2
|
+
|
|
3
|
+
class PartnerClient {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
setExtraHeaders(header) {
|
|
9
|
+
if (typeof header === "object") {
|
|
10
|
+
this.config.extraHeaders.push(header);
|
|
11
|
+
} else {
|
|
12
|
+
throw new FDKClientValidationError("Context value should be an object");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
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;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const Paginator = require("../../common/Paginator");
|
|
2
1
|
const PlatformAPIClient = require("../PlatformAPIClient");
|
|
3
2
|
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
|
+
const Paginator = require("../../common/Paginator");
|
|
4
4
|
const AnalyticsValidator = require("./AnalyticsPlatformApplicationValidator");
|
|
5
5
|
const AnalyticsModel = require("./AnalyticsPlatformModel");
|
|
6
6
|
const { Logger } = require("./../../common/Logger");
|
|
7
|
+
const Joi = require("joi");
|
|
7
8
|
|
|
8
9
|
class Analytics {
|
|
9
10
|
constructor(config, applicationId) {
|
|
@@ -553,4 +554,5 @@ class Analytics {
|
|
|
553
554
|
return response;
|
|
554
555
|
}
|
|
555
556
|
}
|
|
557
|
+
|
|
556
558
|
module.exports = Analytics;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const Paginator = require("../../common/Paginator");
|
|
2
|
-
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
1
|
const PlatformAPIClient = require("../PlatformAPIClient");
|
|
2
|
+
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
|
+
const Paginator = require("../../common/Paginator");
|
|
4
4
|
const AnalyticsValidator = require("./AnalyticsPlatformValidator");
|
|
5
5
|
const AnalyticsModel = require("./AnalyticsPlatformModel");
|
|
6
6
|
const { Logger } = require("./../../common/Logger");
|
|
7
|
+
const Joi = require("joi");
|
|
7
8
|
|
|
8
9
|
class Analytics {
|
|
9
10
|
constructor(config) {
|
|
@@ -247,7 +248,7 @@ class Analytics {
|
|
|
247
248
|
});
|
|
248
249
|
return data;
|
|
249
250
|
};
|
|
250
|
-
paginator.setCallback(callback);
|
|
251
|
+
paginator.setCallback(callback.bind(this));
|
|
251
252
|
return paginator;
|
|
252
253
|
}
|
|
253
254
|
|
|
@@ -352,7 +353,7 @@ class Analytics {
|
|
|
352
353
|
});
|
|
353
354
|
return data;
|
|
354
355
|
};
|
|
355
|
-
paginator.setCallback(callback);
|
|
356
|
+
paginator.setCallback(callback.bind(this));
|
|
356
357
|
return paginator;
|
|
357
358
|
}
|
|
358
359
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const Paginator = require("../../common/Paginator");
|
|
2
|
-
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
1
|
const PlatformAPIClient = require("../PlatformAPIClient");
|
|
2
|
+
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
|
+
const Paginator = require("../../common/Paginator");
|
|
4
4
|
const AuditTrailValidator = require("./AuditTrailPlatformValidator");
|
|
5
5
|
const AuditTrailModel = require("./AuditTrailPlatformModel");
|
|
6
6
|
const { Logger } = require("./../../common/Logger");
|
|
7
|
+
const Joi = require("joi");
|
|
7
8
|
|
|
8
9
|
class AuditTrail {
|
|
9
10
|
constructor(config) {
|
|
@@ -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
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const Paginator = require("../../common/Paginator");
|
|
2
|
-
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
1
|
const PlatformAPIClient = require("../PlatformAPIClient");
|
|
2
|
+
const { FDKClientValidationError } = require("../../common/FDKError");
|
|
3
|
+
const Paginator = require("../../common/Paginator");
|
|
4
4
|
const BillingValidator = require("./BillingPlatformValidator");
|
|
5
5
|
const BillingModel = require("./BillingPlatformModel");
|
|
6
6
|
const { Logger } = require("./../../common/Logger");
|
|
7
|
+
const Joi = require("joi");
|
|
7
8
|
|
|
8
9
|
class Billing {
|
|
9
10
|
constructor(config) {
|
|
@@ -280,6 +281,73 @@ class Billing {
|
|
|
280
281
|
return response;
|
|
281
282
|
}
|
|
282
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
|
+
|
|
283
351
|
/**
|
|
284
352
|
* @param {Object} arg - Arg object.
|
|
285
353
|
* @param {string} arg.extensionId - Extension _id
|
|
@@ -349,6 +417,73 @@ class Billing {
|
|
|
349
417
|
return response;
|
|
350
418
|
}
|
|
351
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
|
+
|
|
352
487
|
/**
|
|
353
488
|
* @param {Object} arg - Arg object.
|
|
354
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;
|
|
@@ -39,6 +39,20 @@ class BillingModel {
|
|
|
39
39
|
is_valid: Joi.boolean(),
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
static CreateOneTimeCharge() {
|
|
43
|
+
return Joi.object({
|
|
44
|
+
charge: BillingModel.OneTimeChargeItem().required(),
|
|
45
|
+
is_test: Joi.boolean(),
|
|
46
|
+
name: Joi.string().allow("").required(),
|
|
47
|
+
return_url: Joi.string().allow("").required(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static CreateOneTimeChargeResponse() {
|
|
51
|
+
return Joi.object({
|
|
52
|
+
charge: BillingModel.OneTimeChargeEntity(),
|
|
53
|
+
confirm_url: Joi.string().allow(""),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
42
56
|
static CreateSubscriptionCharge() {
|
|
43
57
|
return Joi.object({
|
|
44
58
|
is_test: Joi.boolean(),
|
|
@@ -340,6 +354,35 @@ class BillingModel {
|
|
|
340
354
|
start: Joi.string().allow(""),
|
|
341
355
|
});
|
|
342
356
|
}
|
|
357
|
+
static OneTimeChargeEntity() {
|
|
358
|
+
return Joi.object({
|
|
359
|
+
_id: Joi.string().allow(""),
|
|
360
|
+
activated_on: Joi.string().allow(""),
|
|
361
|
+
cancelled_on: Joi.string().allow(""),
|
|
362
|
+
entity_id: Joi.string().allow(""),
|
|
363
|
+
entity_type: Joi.string().allow(""),
|
|
364
|
+
is_test: Joi.boolean(),
|
|
365
|
+
meta: Joi.any(),
|
|
366
|
+
metadata: Joi.any(),
|
|
367
|
+
name: Joi.string().allow(""),
|
|
368
|
+
price: BillingModel.EntityChargePrice(),
|
|
369
|
+
pricing_type: Joi.string().allow(""),
|
|
370
|
+
return_url: Joi.string().allow(""),
|
|
371
|
+
status: Joi.string().allow(""),
|
|
372
|
+
subscriber_id: Joi.string().allow(""),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
static OneTimeChargeItem() {
|
|
376
|
+
return Joi.object({
|
|
377
|
+
capped_amount: Joi.number(),
|
|
378
|
+
is_test: Joi.boolean(),
|
|
379
|
+
metadata: Joi.any(),
|
|
380
|
+
name: Joi.string().allow("").required(),
|
|
381
|
+
price: BillingModel.EntityChargePrice().required(),
|
|
382
|
+
pricing_type: Joi.string().allow("").required(),
|
|
383
|
+
term: Joi.string().allow(""),
|
|
384
|
+
});
|
|
385
|
+
}
|
|
343
386
|
static Page() {
|
|
344
387
|
return Joi.object({
|
|
345
388
|
current: Joi.number(),
|
|
@@ -551,6 +594,7 @@ class BillingModel {
|
|
|
551
594
|
static SubscriptionStatus() {
|
|
552
595
|
return Joi.object({
|
|
553
596
|
is_enabled: Joi.boolean(),
|
|
597
|
+
mandate_amount: Joi.number(),
|
|
554
598
|
subscription: BillingModel.Subscription(),
|
|
555
599
|
});
|
|
556
600
|
}
|
|
@@ -4,7 +4,9 @@ declare class BillingValidator {
|
|
|
4
4
|
static cancelSubscriptionCharge(): any;
|
|
5
5
|
static cancelSubscriptionPlan(): any;
|
|
6
6
|
static checkCouponValidity(): any;
|
|
7
|
+
static createOneTimeCharge(): any;
|
|
7
8
|
static createSubscriptionCharge(): any;
|
|
9
|
+
static getChargeDetails(): any;
|
|
8
10
|
static getCustomerDetail(): any;
|
|
9
11
|
static getFeatureLimitConfig(): any;
|
|
10
12
|
static getInvoiceById(): any;
|
|
@@ -28,6 +28,13 @@ class BillingValidator {
|
|
|
28
28
|
}).required();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
static createOneTimeCharge() {
|
|
32
|
+
return Joi.object({
|
|
33
|
+
extensionId: Joi.string().allow("").required(),
|
|
34
|
+
body: BillingModel.CreateOneTimeCharge().required(),
|
|
35
|
+
}).required();
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
static createSubscriptionCharge() {
|
|
32
39
|
return Joi.object({
|
|
33
40
|
extensionId: Joi.string().allow("").required(),
|
|
@@ -35,6 +42,13 @@ class BillingValidator {
|
|
|
35
42
|
}).required();
|
|
36
43
|
}
|
|
37
44
|
|
|
45
|
+
static getChargeDetails() {
|
|
46
|
+
return Joi.object({
|
|
47
|
+
extensionId: Joi.string().allow("").required(),
|
|
48
|
+
chargeId: Joi.string().allow("").required(),
|
|
49
|
+
}).required();
|
|
50
|
+
}
|
|
51
|
+
|
|
38
52
|
static getCustomerDetail() {
|
|
39
53
|
return Joi.object({}).required();
|
|
40
54
|
}
|
|
@@ -70,4 +84,5 @@ class BillingValidator {
|
|
|
70
84
|
}).required();
|
|
71
85
|
}
|
|
72
86
|
}
|
|
87
|
+
|
|
73
88
|
module.exports = BillingValidator;
|