@gofynd/fdk-client-javascript 1.4.8 → 1.4.10-beta.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.
@@ -1,349 +0,0 @@
1
- const PublicAPIClient = require("../PublicAPIClient");
2
- const {
3
- FDKClientValidationError,
4
- FDKResponseValidationError,
5
- } = require("../../common/FDKError");
6
- const constructUrl = require("../constructUrl");
7
- const Paginator = require("../../common/Paginator");
8
- const BillingPublicValidator = require("./BillingPublicValidator");
9
- const BillingPublicModel = require("./BillingPublicModel");
10
- const { Logger } = require("./../../common/Logger");
11
- const Joi = require("joi");
12
-
13
- class Billing {
14
- constructor(_conf) {
15
- this._conf = _conf;
16
- this._relativeUrls = {
17
- getPlanDetails: "/service/public/billing/v1.0/plan/details/{plan_id}",
18
- getStandardPlans: "/service/public/billing/v1.0/plan/detailed-list/",
19
- getTenureConfig:
20
- "/service/public/billing/v1.0/tenure-config/{country_code}",
21
- planList: "/service/public/billing/v1.0/plan/list",
22
- };
23
- this._urls = Object.entries(this._relativeUrls).reduce(
24
- (urls, [method, relativeUrl]) => {
25
- urls[method] = `${_conf.domain}${relativeUrl}`;
26
- return urls;
27
- },
28
- {}
29
- );
30
- }
31
-
32
- updateUrls(urls) {
33
- this._urls = {
34
- ...this._urls,
35
- ...urls,
36
- };
37
- }
38
-
39
- /**
40
- * @param {BillingPublicValidator.GetPlanDetailsParam} arg - Arg object.
41
- * @param {object} [arg.requestHeaders={}] - Request headers. Default is `{}`
42
- * @param {import("../PublicAPIClient").Options} - Options
43
- * @returns {Promise<BillingPublicModel.PlanDetails>} - Success response
44
- * @name getPlanDetails
45
- * @summary: Get plan details
46
- * @description: Get plan details.
47
- * - Check out [method documentation](https://partners.fynd.com/help/docs/sdk/public/billing/getPlanDetails/).
48
- */
49
- async getPlanDetails(
50
- { planId, requestHeaders } = { requestHeaders: {} },
51
- { responseHeaders } = { responseHeaders: false }
52
- ) {
53
- const { error } = BillingPublicValidator.getPlanDetails().validate(
54
- { planId },
55
- { abortEarly: false, allowUnknown: true }
56
- );
57
- if (error) {
58
- return Promise.reject(new FDKClientValidationError(error));
59
- }
60
-
61
- // Showing warrnings if extra unknown parameters are found
62
- const {
63
- error: warrning,
64
- } = BillingPublicValidator.getPlanDetails().validate(
65
- { planId },
66
- { abortEarly: false, allowUnknown: false }
67
- );
68
- if (warrning) {
69
- Logger({
70
- level: "WARN",
71
- message: `Parameter Validation warrnings for public > Billing > getPlanDetails \n ${warrning}`,
72
- });
73
- }
74
-
75
- const query_params = {};
76
-
77
- const xHeaders = {};
78
-
79
- const response = await PublicAPIClient.execute(
80
- this._conf,
81
- "get",
82
- constructUrl({
83
- url: this._urls["getPlanDetails"],
84
- params: { planId },
85
- }),
86
- query_params,
87
- undefined,
88
- { ...xHeaders, ...requestHeaders },
89
- { responseHeaders }
90
- );
91
-
92
- let responseData = response;
93
- if (responseHeaders) {
94
- responseData = response[0];
95
- }
96
-
97
- const {
98
- error: res_error,
99
- } = BillingPublicModel.PlanDetails().validate(responseData, {
100
- abortEarly: false,
101
- allowUnknown: true,
102
- });
103
-
104
- if (res_error) {
105
- if (this._conf.options.strictResponseCheck === true) {
106
- return Promise.reject(new FDKResponseValidationError(res_error));
107
- } else {
108
- Logger({
109
- level: "WARN",
110
- message: `Response Validation Warnings for public > Billing > getPlanDetails \n ${res_error}`,
111
- });
112
- }
113
- }
114
-
115
- return response;
116
- }
117
-
118
- /**
119
- * @param {BillingPublicValidator.GetStandardPlansParam} arg - Arg object.
120
- * @param {object} [arg.requestHeaders={}] - Request headers. Default is `{}`
121
- * @param {import("../PublicAPIClient").Options} - Options
122
- * @returns {Promise<BillingPublicModel.DetailList>} - Success response
123
- * @name getStandardPlans
124
- * @summary: Get Standard/Public Plans
125
- * @description: Get Standard/Public Plans. - Check out [method documentation](https://partners.fynd.com/help/docs/sdk/public/billing/getStandardPlans/).
126
- */
127
- async getStandardPlans(
128
- { platform, requestHeaders } = { requestHeaders: {} },
129
- { responseHeaders } = { responseHeaders: false }
130
- ) {
131
- const { error } = BillingPublicValidator.getStandardPlans().validate(
132
- { platform },
133
- { abortEarly: false, allowUnknown: true }
134
- );
135
- if (error) {
136
- return Promise.reject(new FDKClientValidationError(error));
137
- }
138
-
139
- // Showing warrnings if extra unknown parameters are found
140
- const {
141
- error: warrning,
142
- } = BillingPublicValidator.getStandardPlans().validate(
143
- { platform },
144
- { abortEarly: false, allowUnknown: false }
145
- );
146
- if (warrning) {
147
- Logger({
148
- level: "WARN",
149
- message: `Parameter Validation warrnings for public > Billing > getStandardPlans \n ${warrning}`,
150
- });
151
- }
152
-
153
- const query_params = {};
154
- query_params["platform"] = platform;
155
-
156
- const xHeaders = {};
157
-
158
- const response = await PublicAPIClient.execute(
159
- this._conf,
160
- "get",
161
- constructUrl({
162
- url: this._urls["getStandardPlans"],
163
- params: {},
164
- }),
165
- query_params,
166
- undefined,
167
- { ...xHeaders, ...requestHeaders },
168
- { responseHeaders }
169
- );
170
-
171
- let responseData = response;
172
- if (responseHeaders) {
173
- responseData = response[0];
174
- }
175
-
176
- const {
177
- error: res_error,
178
- } = BillingPublicModel.DetailList().validate(responseData, {
179
- abortEarly: false,
180
- allowUnknown: true,
181
- });
182
-
183
- if (res_error) {
184
- if (this._conf.options.strictResponseCheck === true) {
185
- return Promise.reject(new FDKResponseValidationError(res_error));
186
- } else {
187
- Logger({
188
- level: "WARN",
189
- message: `Response Validation Warnings for public > Billing > getStandardPlans \n ${res_error}`,
190
- });
191
- }
192
- }
193
-
194
- return response;
195
- }
196
-
197
- /**
198
- * @param {BillingPublicValidator.GetTenureConfigParam} arg - Arg object.
199
- * @param {object} [arg.requestHeaders={}] - Request headers. Default is `{}`
200
- * @param {import("../PublicAPIClient").Options} - Options
201
- * @returns {Promise<BillingPublicModel.TenureConfigResponse>} - Success response
202
- * @name getTenureConfig
203
- * @summary: Get Tenure Configuration
204
- * @description: Retrieve the tenure configuration for a specific country. - Check out [method documentation](https://partners.fynd.com/help/docs/sdk/public/billing/getTenureConfig/).
205
- */
206
- async getTenureConfig(
207
- { countryCode, requestHeaders } = { requestHeaders: {} },
208
- { responseHeaders } = { responseHeaders: false }
209
- ) {
210
- const { error } = BillingPublicValidator.getTenureConfig().validate(
211
- { countryCode },
212
- { abortEarly: false, allowUnknown: true }
213
- );
214
- if (error) {
215
- return Promise.reject(new FDKClientValidationError(error));
216
- }
217
-
218
- // Showing warrnings if extra unknown parameters are found
219
- const {
220
- error: warrning,
221
- } = BillingPublicValidator.getTenureConfig().validate(
222
- { countryCode },
223
- { abortEarly: false, allowUnknown: false }
224
- );
225
- if (warrning) {
226
- Logger({
227
- level: "WARN",
228
- message: `Parameter Validation warrnings for public > Billing > getTenureConfig \n ${warrning}`,
229
- });
230
- }
231
-
232
- const query_params = {};
233
-
234
- const xHeaders = {};
235
-
236
- const response = await PublicAPIClient.execute(
237
- this._conf,
238
- "get",
239
- constructUrl({
240
- url: this._urls["getTenureConfig"],
241
- params: { countryCode },
242
- }),
243
- query_params,
244
- undefined,
245
- { ...xHeaders, ...requestHeaders },
246
- { responseHeaders }
247
- );
248
-
249
- let responseData = response;
250
- if (responseHeaders) {
251
- responseData = response[0];
252
- }
253
-
254
- const {
255
- error: res_error,
256
- } = BillingPublicModel.TenureConfigResponse().validate(responseData, {
257
- abortEarly: false,
258
- allowUnknown: true,
259
- });
260
-
261
- if (res_error) {
262
- if (this._conf.options.strictResponseCheck === true) {
263
- return Promise.reject(new FDKResponseValidationError(res_error));
264
- } else {
265
- Logger({
266
- level: "WARN",
267
- message: `Response Validation Warnings for public > Billing > getTenureConfig \n ${res_error}`,
268
- });
269
- }
270
- }
271
-
272
- return response;
273
- }
274
-
275
- /**
276
- * @param {BillingPublicValidator.PlanListParam} arg - Arg object.
277
- * @param {object} [arg.requestHeaders={}] - Request headers. Default is `{}`
278
- * @param {import("../PublicAPIClient").Options} - Options
279
- * @returns {Promise<BillingPublicModel.PlanList[]>} - Success response
280
- * @name planList
281
- * @summary: Get List of all plans
282
- * @description: Get List of all plans - Check out [method documentation](https://partners.fynd.com/help/docs/sdk/public/billing/planList/).
283
- */
284
- async planList(
285
- { requestHeaders } = { requestHeaders: {} },
286
- { responseHeaders } = { responseHeaders: false }
287
- ) {
288
- const { error } = BillingPublicValidator.planList().validate(
289
- {},
290
- { abortEarly: false, allowUnknown: true }
291
- );
292
- if (error) {
293
- return Promise.reject(new FDKClientValidationError(error));
294
- }
295
-
296
- // Showing warrnings if extra unknown parameters are found
297
- const { error: warrning } = BillingPublicValidator.planList().validate(
298
- {},
299
- { abortEarly: false, allowUnknown: false }
300
- );
301
- if (warrning) {
302
- Logger({
303
- level: "WARN",
304
- message: `Parameter Validation warrnings for public > Billing > planList \n ${warrning}`,
305
- });
306
- }
307
-
308
- const query_params = {};
309
-
310
- const xHeaders = {};
311
-
312
- const response = await PublicAPIClient.execute(
313
- this._conf,
314
- "get",
315
- constructUrl({
316
- url: this._urls["planList"],
317
- params: {},
318
- }),
319
- query_params,
320
- undefined,
321
- { ...xHeaders, ...requestHeaders },
322
- { responseHeaders }
323
- );
324
-
325
- let responseData = response;
326
- if (responseHeaders) {
327
- responseData = response[0];
328
- }
329
-
330
- const { error: res_error } = Joi.array()
331
- .items(BillingPublicModel.PlanList())
332
- .validate(responseData, { abortEarly: false, allowUnknown: true });
333
-
334
- if (res_error) {
335
- if (this._conf.options.strictResponseCheck === true) {
336
- return Promise.reject(new FDKResponseValidationError(res_error));
337
- } else {
338
- Logger({
339
- level: "WARN",
340
- message: `Response Validation Warnings for public > Billing > planList \n ${res_error}`,
341
- });
342
- }
343
- }
344
-
345
- return response;
346
- }
347
- }
348
-
349
- module.exports = Billing;