@spreeloop/orange_money 1.0.7 → 1.0.9

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.
Files changed (49) hide show
  1. package/package.json +4 -1
  2. package/.eslintrc.js +0 -47
  3. package/.prettierrc +0 -6
  4. package/babel.config.js +0 -3
  5. package/index.spec.ts +0 -9
  6. package/index.ts +0 -1
  7. package/jest.before-test.ts +0 -3
  8. package/jest.config.ts +0 -54
  9. package/src/disbursements/implementations/disbursement_service.ts +0 -133
  10. package/src/disbursements/implementations/src/live.ts +0 -79
  11. package/src/disbursements/implementations/src/sandbox.ts +0 -124
  12. package/src/disbursements/operations/create_access_token.spec.ts +0 -87
  13. package/src/disbursements/operations/create_access_token.ts +0 -83
  14. package/src/disbursements/operations/get_transfer_status.spec.ts +0 -132
  15. package/src/disbursements/operations/get_transfer_status.ts +0 -265
  16. package/src/disbursements/operations/transfer.spec.ts +0 -158
  17. package/src/disbursements/operations/transfer.ts +0 -125
  18. package/src/disbursements/routes/routes.ts +0 -54
  19. package/src/disbursements/utils/constants.ts +0 -4
  20. package/src/disbursements/utils/regex.spec.ts +0 -39
  21. package/src/disbursements/utils/regex.ts +0 -10
  22. package/src/disbursements/utils/status.ts +0 -62
  23. package/src/disbursements/utils/utils.spec.ts +0 -42
  24. package/src/disbursements/utils/utils.ts +0 -24
  25. package/src/index.ts +0 -12
  26. package/src/payments/implementations/fake.ts +0 -133
  27. package/src/payments/implementations/live.ts +0 -87
  28. package/src/payments/operations/get_access_token.spec.ts +0 -60
  29. package/src/payments/operations/get_access_token.ts +0 -77
  30. package/src/payments/operations/get_pay_token.spec.ts +0 -65
  31. package/src/payments/operations/get_pay_token.ts +0 -66
  32. package/src/payments/operations/get_payment_status.spec.ts +0 -82
  33. package/src/payments/operations/get_payment_status.ts +0 -78
  34. package/src/payments/operations/initialize_om_payment.spec.ts +0 -234
  35. package/src/payments/operations/initialize_om_payment.ts +0 -191
  36. package/src/payments/payments.ts +0 -86
  37. package/src/payments/routes/routes.ts +0 -61
  38. package/src/payments/utils/constants.ts +0 -120
  39. package/src/payments/utils/joi_schema.ts +0 -117
  40. package/src/payments/utils/request_model.ts +0 -103
  41. package/src/payments/utils/utils.ts +0 -31
  42. package/src/utils/https.spec.ts +0 -101
  43. package/src/utils/https.ts +0 -266
  44. package/src/utils/logging_interface.ts +0 -25
  45. package/src/utils/operation_response.ts +0 -17
  46. package/src/utils/utils.ts +0 -5
  47. package/tsconfig.build.json +0 -4
  48. package/tsconfig.dev.json +0 -4
  49. package/tsconfig.json +0 -27
@@ -1,266 +0,0 @@
1
- import * as axios from 'axios';
2
- import { AxiosError } from 'axios';
3
- import base64url from 'base64url';
4
- import * as https from 'https';
5
- import { LoggerInterface } from './logging_interface';
6
-
7
- export enum RequestStatusCode {
8
- unauthorized = 401,
9
- expectationFailed = 417,
10
- }
11
-
12
- export type RequestResponse<T> = {
13
- response?: {
14
- data: T;
15
- status: number;
16
- };
17
- error?: unknown;
18
- };
19
-
20
- /**
21
- * Posts an http request to the given route.
22
- * @param {Record<string, string | undefined> | string} data The data to be posted.
23
- * @param {string} route The end point url.
24
- * @param {Record<string, string>} headers The type content of request.
25
- * @param {LoggerInterface} logger The logger to use when posting data.
26
- * @return {Promise<unknown | undefined>} The server response.
27
- */
28
- export async function postRequest<T>({
29
- data,
30
- route,
31
- headers,
32
- logger,
33
- rejectUnauthorized = true,
34
- }: {
35
- data?: Record<string, unknown> | string | null;
36
- route: string;
37
- logger: LoggerInterface;
38
- headers?: Record<string, string>;
39
- rejectUnauthorized?: boolean;
40
- }): Promise<RequestResponse<T>> {
41
- try {
42
- logger.info(
43
- `Request on the route ${route} is running with data : ${JSON.stringify({
44
- headers,
45
- data,
46
- route,
47
- })}`
48
- );
49
- const agent = new https.Agent({
50
- rejectUnauthorized: rejectUnauthorized,
51
- });
52
- const response = await axios.default({
53
- method: 'post',
54
- url: route,
55
- headers: headers,
56
- data: data,
57
- httpsAgent: agent,
58
- });
59
- logger.info(
60
- `Request on the route ${route} completed successfully with data : ${JSON.stringify(
61
- {
62
- response: response.data,
63
- status: response.status,
64
- statusText: response.statusText,
65
- }
66
- )}`
67
- );
68
- return { response: { data: response.data, status: response.status } };
69
- } catch (error) {
70
- logger.warn(
71
- `[Axios] failed to post request on the route: ${route} with data : ${JSON.stringify(
72
- { headers, data, route }
73
- )}`
74
- );
75
- const parsedError = parseAxiosError(error);
76
- logger.warn(JSON.stringify(error));
77
- if (error instanceof AxiosError) {
78
- if (error.response) {
79
- return {
80
- response: {
81
- status: error.response.status,
82
- data: error.response.data,
83
- },
84
- error: parsedError,
85
- };
86
- }
87
- }
88
-
89
- return { error: parsedError };
90
- }
91
- }
92
-
93
- /**
94
- * Gets an http request to the given route.
95
- * @param {Record<string, string | undefined> | string} data The data to be posted.
96
- * @param {string} route The end point url.
97
- * @param {Record<string, string>} headers The type content of request.
98
- * @param {LoggerInterface} logger The logger to use when getting data.
99
- * @return {Promise<unknown | undefined>} The server response.
100
- */
101
- export async function getRequest<T>({
102
- data,
103
- route,
104
- headers,
105
- logger,
106
- rejectUnauthorized = true,
107
- }: {
108
- data?: Record<string, string | undefined> | string;
109
- route: string;
110
- headers?: Record<string, string>;
111
- logger: LoggerInterface;
112
- rejectUnauthorized?: boolean;
113
- }): Promise<RequestResponse<T>> {
114
- try {
115
- logger.info(
116
- `Request on the route ${route} is running with data : ${JSON.stringify({
117
- headers,
118
- data,
119
- route,
120
- })}`
121
- );
122
- const agent = new https.Agent({
123
- rejectUnauthorized: rejectUnauthorized,
124
- });
125
- const response = await axios.default({
126
- method: 'get',
127
- url: route,
128
- headers: headers,
129
- data: data,
130
- httpsAgent: agent,
131
- });
132
- logger.info(
133
- `Request on the route ${route} completed successfully with data : ${JSON.stringify(
134
- {
135
- response: response.data,
136
- status: response.status,
137
- statusText: response.statusText,
138
- }
139
- )}`
140
- );
141
- return { response: { data: response.data, status: response.status } };
142
- } catch (error) {
143
- logger.warn(
144
- `[Axios] failed to get request on the route: ${route} with data : ${JSON.stringify(
145
- { headers, data, route }
146
- )}`
147
- );
148
- const parsedError = parseAxiosError(error);
149
- logger.warn(JSON.stringify(error));
150
- if (error instanceof AxiosError) {
151
- if (error.response) {
152
- return {
153
- response: {
154
- status: error.response.status,
155
- data: error.response.data,
156
- },
157
- error: parsedError,
158
- };
159
- }
160
- }
161
-
162
- return { error: parsedError };
163
- }
164
- }
165
-
166
- /**
167
- * Parses an Axios error and returns a modified error object.
168
- *
169
- * @param {unknown} error - The error object to be parsed.
170
- * @return {unknown} The modified error object.
171
- */
172
- export function parseAxiosError(error: unknown): unknown {
173
- let err = error;
174
- if (error instanceof AxiosError) {
175
- if (error.response) {
176
- err = {
177
- responseError: {
178
- data: error.response.data,
179
- status: error.response.status,
180
- statusText: error.response.statusText,
181
- headers: error.response.headers,
182
- },
183
- requestBody: error.request.body,
184
- };
185
- } else if (error.request) {
186
- err = {
187
- requestFailed: {
188
- headers: error.config?.headers,
189
- data: error.config?.data,
190
- },
191
- };
192
- } else {
193
- err = {
194
- configFailed: error.message,
195
- };
196
- }
197
- }
198
- return err;
199
- }
200
-
201
- /**
202
- * Generates a hash using the given key and secret.
203
- *
204
- * @param {string} key - The key to be hashed.
205
- * @param {string} secret - The secret to be hashed.
206
- * @return {string} - The generated hash.
207
- */
208
- export function hash(key: string, secret: string): string {
209
- const toHash = `${key}:${secret}`;
210
- if (!global.btoa) {
211
- return Buffer.from(toHash).toString('base64');
212
- }
213
- return global.btoa(toHash);
214
- }
215
-
216
- /**
217
- * Encode the body of the request.
218
- * @param {Record<string, string>} bodyRequest the body request.
219
- * @return {string} the encoded body request result.
220
- */
221
- export function encodeTheBodyOfRequest(
222
- bodyRequest: Record<string, string>
223
- ): string {
224
- const formBody = [];
225
- for (const key in bodyRequest) {
226
- if ({}.hasOwnProperty.call(bodyRequest, key)) {
227
- const encodedKey = encodeURIComponent(key);
228
- const encodedValue = encodeURIComponent(bodyRequest[key]);
229
- formBody.push(encodedKey + '=' + encodedValue);
230
- }
231
- }
232
- return formBody.join('&');
233
- }
234
-
235
- // Encode to base64
236
- export const encodeToBase64 = (
237
- apiUsername: string,
238
- apiPassword: string
239
- ): string => {
240
- return base64url(`${apiUsername}:${apiPassword}`);
241
- };
242
-
243
- /**
244
- * Encode the data to w3 x form encoded url.
245
- * @param {Record<string, string>} data the data to encode.
246
- * @return {string} the encoded value.
247
- */
248
- export function encodeDataToXFormUrl(data: Record<string, string>): string {
249
- const segments: string[] = [];
250
- for (const key in data) {
251
- if (Object.hasOwnProperty.call(data, key)) {
252
- const encodedKey = encodeURIComponent(key);
253
- const encodedValue = encodeURIComponent(data[key]);
254
- segments.push(`${encodedKey}=${encodedValue}`);
255
- }
256
- }
257
- return segments.join('&');
258
- }
259
-
260
- /**
261
- * Checks if the code is a successful code response.
262
- * @param {num} code .
263
- * @return {boolean} true if the code is valid.
264
- */
265
- export const isSuccessfulCodeResponse = (code: number): boolean =>
266
- code >= 200 && code < 300;
@@ -1,25 +0,0 @@
1
- export interface LoggerInterface {
2
- /**
3
- * Logs a debug level message.
4
- * @param {string[]} args
5
- */
6
- log(...args: string[]): void;
7
-
8
- /**
9
- * Logs an info level message.
10
- * @param {string[]} args
11
- */
12
- info(...args: string[]): void;
13
-
14
- /**
15
- * Logs a waning level message.
16
- * @param {string[]} args
17
- */
18
- warn(...args: string[]): void;
19
-
20
- /**
21
- * Logs an error level message.
22
- * @param {string[]} args
23
- */
24
- error(...args: string[]): void;
25
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Data return to user when requesting an operation.
3
- */
4
- export type OperationResponse<T, T2 = unknown, R = unknown> = Promise<
5
- SuccessfulOperationResponse<T, T2> | FailedOperationResponse<R>
6
- >;
7
- type SuccessfulOperationResponse<T, T2 = unknown> = {
8
- data: T;
9
- raw: T2;
10
- error?: never;
11
- };
12
-
13
- type FailedOperationResponse<R = unknown> = {
14
- data?: never;
15
- raw?: unknown;
16
- error: R;
17
- };
@@ -1,5 +0,0 @@
1
- export enum TargetEnvironment {
2
- sandbox = 'dev',
3
- prod = 'prod',
4
- fake = 'fake',
5
- }
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["**/*.spec.ts"]
4
- }
package/tsconfig.dev.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "include": [".eslintrc.js", "index.spec.ts", "jest.config.ts", "jest.before-test.ts", "babel.config.js"],
3
- "exclude": []
4
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
- "module": "commonjs", /* Specify what module code is generated. */
5
- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
6
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
7
- "declarationMap": true, /* Create sourcemaps for d.ts files. */
8
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
9
- "outDir": "dist", /* Specify an output folder for all emitted files. */
10
- "removeComments": false, /* Disable emitting comments. */
11
- "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
12
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
13
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
14
- "strict": true, /* Enable all strict type-checking options. */
15
- "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
16
- "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
17
- "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
18
- "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
19
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
20
- "baseUrl": ".",
21
- "paths": {
22
- "@spreeloop-core/logging": ["../logging"]
23
- }
24
- },
25
- "include": ["src", "index.ts"],
26
- "exclude": []
27
- }