@anddone/coretestautomation 1.0.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.
Files changed (72) hide show
  1. package/.github/workflows/npm-release.yml +102 -0
  2. package/dist/api/base.api.d.ts +32 -0
  3. package/dist/api/base.api.d.ts.map +1 -0
  4. package/dist/api/base.api.js +7 -0
  5. package/dist/api/base.api.js.map +1 -0
  6. package/dist/api/headers.d.ts +6 -0
  7. package/dist/api/headers.d.ts.map +1 -0
  8. package/dist/api/headers.js +23 -0
  9. package/dist/api/headers.js.map +1 -0
  10. package/dist/index.d.ts +13 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +29 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/pages/basepage.d.ts +6 -0
  15. package/dist/pages/basepage.d.ts.map +1 -0
  16. package/dist/pages/basepage.js +10 -0
  17. package/dist/pages/basepage.js.map +1 -0
  18. package/dist/testData/api.data.json +6 -0
  19. package/dist/utils/apiUtils.d.ts +123 -0
  20. package/dist/utils/apiUtils.d.ts.map +1 -0
  21. package/dist/utils/apiUtils.js +264 -0
  22. package/dist/utils/apiUtils.js.map +1 -0
  23. package/dist/utils/assertionUtils.d.ts +223 -0
  24. package/dist/utils/assertionUtils.d.ts.map +1 -0
  25. package/dist/utils/assertionUtils.js +400 -0
  26. package/dist/utils/assertionUtils.js.map +1 -0
  27. package/dist/utils/commonUtils.d.ts +590 -0
  28. package/dist/utils/commonUtils.d.ts.map +1 -0
  29. package/dist/utils/commonUtils.js +1292 -0
  30. package/dist/utils/commonUtils.js.map +1 -0
  31. package/dist/utils/fakerStaticData.d.ts +16 -0
  32. package/dist/utils/fakerStaticData.d.ts.map +1 -0
  33. package/dist/utils/fakerStaticData.js +88 -0
  34. package/dist/utils/fakerStaticData.js.map +1 -0
  35. package/dist/utils/fileCommonUtils.d.ts +22 -0
  36. package/dist/utils/fileCommonUtils.d.ts.map +1 -0
  37. package/dist/utils/fileCommonUtils.js +243 -0
  38. package/dist/utils/fileCommonUtils.js.map +1 -0
  39. package/dist/utils/generationUtils.d.ts +424 -0
  40. package/dist/utils/generationUtils.d.ts.map +1 -0
  41. package/dist/utils/generationUtils.js +869 -0
  42. package/dist/utils/generationUtils.js.map +1 -0
  43. package/dist/utils/pageUtils.d.ts +90 -0
  44. package/dist/utils/pageUtils.d.ts.map +1 -0
  45. package/dist/utils/pageUtils.js +214 -0
  46. package/dist/utils/pageUtils.js.map +1 -0
  47. package/dist/utils/tableUtils.d.ts +304 -0
  48. package/dist/utils/tableUtils.d.ts.map +1 -0
  49. package/dist/utils/tableUtils.js +555 -0
  50. package/dist/utils/tableUtils.js.map +1 -0
  51. package/dist/utils/validationUtils.d.ts +80 -0
  52. package/dist/utils/validationUtils.d.ts.map +1 -0
  53. package/dist/utils/validationUtils.js +172 -0
  54. package/dist/utils/validationUtils.js.map +1 -0
  55. package/package.json +23 -0
  56. package/playwright.config.ts +79 -0
  57. package/src/api/base.api.ts +39 -0
  58. package/src/api/headers.ts +17 -0
  59. package/src/index.ts +12 -0
  60. package/src/pages/basepage.ts +11 -0
  61. package/src/testData/api.data.json +6 -0
  62. package/src/types/pdf-parse.d.ts +6 -0
  63. package/src/utils/apiUtils.ts +307 -0
  64. package/src/utils/assertionUtils.ts +455 -0
  65. package/src/utils/commonUtils.ts +1544 -0
  66. package/src/utils/fakerStaticData.ts +91 -0
  67. package/src/utils/fileCommonUtils.ts +239 -0
  68. package/src/utils/generationUtils.ts +929 -0
  69. package/src/utils/pageUtils.ts +224 -0
  70. package/src/utils/tableUtils.ts +715 -0
  71. package/src/utils/validationUtils.ts +179 -0
  72. package/tsconfig.json +19 -0
@@ -0,0 +1,102 @@
1
+ name: Release CoreTestAutomation
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ release_type:
7
+ description: "Release type (semantic versioning)"
8
+ required: true
9
+ default: patch
10
+ type: choice
11
+ options:
12
+ - patch
13
+ - minor
14
+ - major
15
+
16
+ jobs:
17
+ release:
18
+ runs-on: ubuntu-latest
19
+
20
+ steps:
21
+ # 1. Checkout repo
22
+ - uses: actions/checkout@v4
23
+ with:
24
+ fetch-depth: 0
25
+
26
+ # 2. Setup Node
27
+ - uses: actions/setup-node@v4
28
+ with:
29
+ node-version: 18
30
+ registry-url: https://registry.npmjs.org/
31
+
32
+ # 3. Install dependencies
33
+ - run: npm install
34
+
35
+ # 4. Build project
36
+ - run: npm run build
37
+
38
+ # 5. Configure Git for tags/commits
39
+ - name: Configure Git
40
+ run: |
41
+ git config user.name "github-actions[bot]"
42
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
43
+
44
+ # 6. Bump version safely
45
+ - name: Bump version
46
+ run: |
47
+ # Get release type (patch/minor/major)
48
+ RELEASE_TYPE=${{ inputs.release_type }}
49
+
50
+ # Get current version
51
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
52
+
53
+ # Calculate new version without creating a tag yet
54
+ NEW_VERSION=$(npm version $RELEASE_TYPE --no-git-tag-version)
55
+
56
+ echo "Current version: $CURRENT_VERSION"
57
+ echo "New version: $NEW_VERSION"
58
+
59
+ # Commit package.json changes
60
+ git add package.json
61
+ git commit -m "chore(release): $NEW_VERSION"
62
+
63
+ # Delete tag if exists (avoid errors in CI)
64
+ if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then
65
+ git tag -d "v$NEW_VERSION"
66
+ git push origin :refs/tags/v$NEW_VERSION
67
+ fi
68
+
69
+ # Create new tag
70
+ git tag "v$NEW_VERSION"
71
+
72
+ # Push commit + tag
73
+ git push origin master --follow-tags
74
+
75
+ # 7. Publish to npm
76
+ - name: Publish to npm
77
+ run: npm publish --access public
78
+ env:
79
+ NODE_AUTH_TOKEN: ${{ secrets.TESTAUTOMATIONAUTH }}
80
+
81
+ # 8. Slack Success Notification
82
+ - name: Slack Success
83
+ if: success()
84
+ run: |
85
+ PACKAGE_NAME="@anddone/coretestautomation"
86
+ VERSION=$(node -p "require('./package.json').version")
87
+ curl -X POST -H 'Content-type: application/json' \
88
+ --data "{
89
+ \"username\": \"CoreTestAutomation\",
90
+ \"text\": \":white_check_mark: npm package published!\n*Package:* $PACKAGE_NAME\n*Version:* $VERSION\n*Release Notes:*\n• Added Core Test Automation\n• Payment Page methods\"
91
+
92
+
93
+ }" \
94
+ ${{ secrets.SLACK_WEBHOOK_URL }}
95
+
96
+ # 9. Slack Failure Notification
97
+ - name: Slack Failure
98
+ if: failure()
99
+ run: |
100
+ curl -X POST -H 'Content-type: application/json' \
101
+ --data '{"text":":x: npm publish failed. Check GitHub Actions logs."}' \
102
+ ${{ secrets.SLACK_WEBHOOK_URL }}
@@ -0,0 +1,32 @@
1
+ export type Header = {
2
+ origin?: string;
3
+ contentType?: string;
4
+ authorization?: string;
5
+ appKey?: string;
6
+ apiKey?: string;
7
+ xVersion?: string;
8
+ };
9
+ export type Customer = {
10
+ firstName?: string;
11
+ lastName?: string;
12
+ phone?: string;
13
+ email?: string;
14
+ };
15
+ export type Reference = {
16
+ referenceType?: string;
17
+ referenceKey?: string;
18
+ referenceNumber?: string;
19
+ };
20
+ export type Split = {
21
+ virtualAccount?: string;
22
+ amount?: number | string;
23
+ reference?: string;
24
+ chargeIndicator?: string;
25
+ };
26
+ export type Login = {
27
+ userName?: string;
28
+ password?: string;
29
+ };
30
+ export declare class BaseAPI {
31
+ }
32
+ //# sourceMappingURL=base.api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.api.d.ts","sourceRoot":"","sources":["../../src/api/base.api.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,MAAM,GAAG;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAA;AAED,qBAAa,OAAO;CAGnB"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAPI = void 0;
4
+ class BaseAPI {
5
+ }
6
+ exports.BaseAPI = BaseAPI;
7
+ //# sourceMappingURL=base.api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.api.js","sourceRoot":"","sources":["../../src/api/base.api.ts"],"names":[],"mappings":";;;AAmCA,MAAa,OAAO;CAGnB;AAHD,0BAGC"}
@@ -0,0 +1,6 @@
1
+ import { Header } from "./base.api";
2
+ export declare class Headers {
3
+ static headers: Record<string, string>;
4
+ static getHeaders(options?: Header): Record<string, string>;
5
+ }
6
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,qBAAa,OAAO;IAClB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,MAAW;CAWvC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Headers = void 0;
4
+ class Headers {
5
+ static getHeaders(options = {}) {
6
+ this.headers = {};
7
+ if (options.origin)
8
+ this.headers["Origin"] = options.origin;
9
+ if (options.contentType)
10
+ this.headers["Content-Type"] = options.contentType;
11
+ if (options.authorization)
12
+ this.headers["Authorization"] = "Bearer " + options.authorization;
13
+ if (options.xVersion)
14
+ this.headers["x-version"] = options.xVersion;
15
+ if (options.apiKey)
16
+ this.headers["x-api-key"] = options.apiKey;
17
+ if (options.appKey)
18
+ this.headers["x-app-key"] = options.appKey;
19
+ return this.headers;
20
+ }
21
+ }
22
+ exports.Headers = Headers;
23
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;IAGlB,MAAM,CAAC,UAAU,CAAC,UAAkB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC5D,IAAI,OAAO,CAAC,WAAW;YAAE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QAC5E,IAAI,OAAO,CAAC,aAAa;YACvB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC;QACpE,IAAI,OAAO,CAAC,QAAQ;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;QACnE,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/D,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAdD,0BAcC"}
@@ -0,0 +1,13 @@
1
+ export * from "./pages/basepage";
2
+ export * from "./utils/apiUtils";
3
+ export * from "./utils/assertionUtils";
4
+ export * from "./utils/commonUtils";
5
+ export * from "./utils/fakerStaticData";
6
+ export * from "./utils/fileCommonUtils";
7
+ export * from "./utils/generationUtils";
8
+ export * from "./utils/pageUtils";
9
+ export * from "./utils/tableUtils";
10
+ export * from "./utils/validationUtils";
11
+ export * from "./api/base.api";
12
+ export * from "./api/headers";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./pages/basepage"), exports);
18
+ __exportStar(require("./utils/apiUtils"), exports);
19
+ __exportStar(require("./utils/assertionUtils"), exports);
20
+ __exportStar(require("./utils/commonUtils"), exports);
21
+ __exportStar(require("./utils/fakerStaticData"), exports);
22
+ __exportStar(require("./utils/fileCommonUtils"), exports);
23
+ __exportStar(require("./utils/generationUtils"), exports);
24
+ __exportStar(require("./utils/pageUtils"), exports);
25
+ __exportStar(require("./utils/tableUtils"), exports);
26
+ __exportStar(require("./utils/validationUtils"), exports);
27
+ __exportStar(require("./api/base.api"), exports);
28
+ __exportStar(require("./api/headers"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,mDAAiC;AACjC,yDAAuC;AACvC,sDAAoC;AACpC,0DAAwC;AACxC,0DAAwC;AACxC,0DAAwC;AACxC,oDAAkC;AAClC,qDAAmC;AACnC,0DAAwC;AACxC,iDAA+B;AAC/B,gDAA8B"}
@@ -0,0 +1,6 @@
1
+ import { Page } from "@playwright/test";
2
+ export declare class BasePage {
3
+ readonly page: Page;
4
+ constructor(page: Page);
5
+ }
6
+ //# sourceMappingURL=basepage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basepage.d.ts","sourceRoot":"","sources":["../../src/pages/basepage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,QAAQ;IAEjB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAER,IAAI,EAAE,IAAI;CAIzB"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePage = void 0;
4
+ class BasePage {
5
+ constructor(page) {
6
+ this.page = page;
7
+ }
8
+ }
9
+ exports.BasePage = BasePage;
10
+ //# sourceMappingURL=basepage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basepage.js","sourceRoot":"","sources":["../../src/pages/basepage.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAIjB,YAAY,IAAU;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CAEJ;AARD,4BAQC"}
@@ -0,0 +1,6 @@
1
+ {
2
+ "login": {
3
+ "method": "POST",
4
+ "path": "/users/sessions"
5
+ }
6
+ }
@@ -0,0 +1,123 @@
1
+ import { APIRequestContext, APIResponse } from "@playwright/test";
2
+ import apiData from "../testData/api.data.json";
3
+ type ApiName = keyof typeof apiData;
4
+ type RequestOptions = {
5
+ body?: unknown;
6
+ headers?: Record<string, string>;
7
+ queryParams?: Record<string, string | number | boolean>;
8
+ pathParams?: Record<string, string>;
9
+ };
10
+ export declare class EmptyApiResponse {
11
+ status(): number;
12
+ ok(): boolean;
13
+ url(): string;
14
+ json(): Promise<{}>;
15
+ text(): Promise<string>;
16
+ }
17
+ export declare class ApiUtils {
18
+ private static apiLogs;
19
+ private static request;
20
+ private static response;
21
+ private static apiMethod;
22
+ private static apiPath;
23
+ private static responseCode;
24
+ private static responseBody;
25
+ /**
26
+ * This is private method to print json value in pretty format.
27
+ * @param obj
28
+ * @returns
29
+ */
30
+ private static pretty;
31
+ /**
32
+ * This method to set APIRequestContext object.
33
+ * @param request APIRequestContext
34
+ */
35
+ static setRequest(request: APIRequestContext): void;
36
+ /**
37
+ * This method will returns APIRequestContext object.
38
+ * @returns APIRequestContext
39
+ */
40
+ static getRequest(): APIRequestContext;
41
+ /**
42
+ * This method set apiMethod and apiPath using apiData object of the json file.
43
+ * @param apiName ApiName
44
+ */
45
+ static setApiData(apiName: ApiName): void;
46
+ /**
47
+ * This method is to get api method.
48
+ * @returns string
49
+ */
50
+ static geApiMethod(): string;
51
+ /**
52
+ * This method is get api path.
53
+ * @returns string
54
+ */
55
+ static getApiPath(): string;
56
+ private static buildPath;
57
+ /**
58
+ * This method to log request details in console if apiLogs flag is true.
59
+ * @param method string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
60
+ * @param url string
61
+ * @param options RequestOptions
62
+ */
63
+ static logRequest(method: string | "GET" | "POST" | "PUT" | "DELETE" | "PATCH", url: string, options?: RequestOptions): void;
64
+ /**
65
+ * This method is set APIResponse object along with responseCode and responseBody.
66
+ * Also log response details in console if apiLogs flag is true.
67
+ * @param response APIResponse
68
+ */
69
+ static setResponse(response: APIResponse): Promise<void>;
70
+ /**
71
+ * This method is get APIResponse object.
72
+ * @returns APIResponse
73
+ */
74
+ static getResponse(): APIResponse;
75
+ /**
76
+ * This method is get response code.
77
+ * @returns number
78
+ */
79
+ static getResponseCode(): number;
80
+ /**
81
+ * This method is get response body.
82
+ * @returns T = unknown
83
+ */
84
+ static getResponseBody<T = unknown>(): T;
85
+ /**
86
+ * This method is log response details in console if apiLogs flag is true.
87
+ */
88
+ static logResponse(): void;
89
+ /**
90
+ * This method is to send respuest as per passed details and return response.
91
+ * @param method string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
92
+ * @param url string - passed Base Url and endpoint together, example: {BaseUrl}+{ApiPath}
93
+ * @param options RequestOptions - this is optional.
94
+ * @returns @link APIResponse
95
+ *
96
+ * Examples:
97
+ * const response = sendRequest('POST', {BaseUrl}+{ApiPath}, {headers: {...headers}, body: {...payload}});
98
+ */
99
+ static sendRequest(method: string | "GET" | "POST" | "PUT" | "DELETE" | "PATCH", url: string, options?: RequestOptions): Promise<any>;
100
+ /**
101
+ * This method is get response object value as per passed path.
102
+ * Also if object value not found then you set return some defaultValue which is optional.
103
+ * @param path string - example 'token', 'intent.paymentTypes', 'customers[0].firstName'
104
+ * @param defaultValue T = any
105
+ * @returns T = any
106
+ */
107
+ static getResponseValue<T = any>(path: string, defaultValue?: T): Promise<T>;
108
+ /**
109
+ * This method is get response object value as array.
110
+ * @param path string - example 'customers'
111
+ * @returns T = any []
112
+ */
113
+ static getResponseArray<T = any>(path: string): Promise<T[]>;
114
+ /**
115
+ * Finds an object inside an array and returns its id where multiple fields match
116
+ * @param arrayPath Path to array. Example: "data"
117
+ * @param match Object with fields to match. Example: { allyName: "Zbook1201", status: "ACTIVE" }
118
+ * @param objectName Object name of which value return . "id"
119
+ */
120
+ static getResponseValueFromArray(arrayPath: string, objectName: string, match: Record<string, any>): Promise<string>;
121
+ }
122
+ export {};
123
+ //# sourceMappingURL=apiUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/apiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAEhD,KAAK,OAAO,GAAG,MAAM,OAAO,OAAO,CAAC;AAEpC,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAEF,qBAAa,gBAAgB;IAC3B,MAAM;IAGN,EAAE;IAGF,GAAG;IAGG,IAAI;IAGJ,IAAI;CAGX;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAE/B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAoB;IAC1C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IAErC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IACjC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAE/B,OAAO,CAAC,MAAM,CAAC,YAAY,CAAS;IACpC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAM;IAEjC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM;IAQrB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB;IAI5C;;;OAGG;IACH,MAAM,CAAC,UAAU;IAIjB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO;IAKlC;;;OAGG;IACH,MAAM,CAAC,WAAW;IAIlB;;;OAGG;IACH,MAAM,CAAC,UAAU;IAIjB,OAAO,CAAC,MAAM,CAAC,SAAS;IAexB;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CACf,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,EAC5D,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc;IAa1B;;;;OAIG;WACU,WAAW,CAAC,QAAQ,EAAE,WAAW;IAe9C;;;OAGG;IACH,MAAM,CAAC,WAAW;IAIlB;;;OAGG;IACH,MAAM,CAAC,eAAe,IAAI,MAAM;IAIhC;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC;IAIxC;;OAEG;IACH,MAAM,CAAC,WAAW;IAQlB;;;;;;;;;OASG;WACU,WAAW,CACtB,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,EAC5D,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,cAAc;IAyB1B;;;;;;OAMG;WACU,gBAAgB,CAAC,CAAC,GAAG,GAAG,EACnC,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,CAAC,GACf,OAAO,CAAC,CAAC,CAAC;IAmBb;;;;OAIG;WACU,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAKlE;;;;;OAKG;WACU,yBAAyB,CACpC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,OAAO,CAAC,MAAM,CAAC;CA+BnB"}
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ApiUtils = exports.EmptyApiResponse = void 0;
7
+ const api_data_json_1 = __importDefault(require("../testData/api.data.json"));
8
+ class EmptyApiResponse {
9
+ status() {
10
+ return 0;
11
+ }
12
+ ok() {
13
+ return false;
14
+ }
15
+ url() {
16
+ return "";
17
+ }
18
+ async json() {
19
+ return {};
20
+ }
21
+ async text() {
22
+ return "";
23
+ }
24
+ }
25
+ exports.EmptyApiResponse = EmptyApiResponse;
26
+ class ApiUtils {
27
+ /**
28
+ * This is private method to print json value in pretty format.
29
+ * @param obj
30
+ * @returns
31
+ */
32
+ static pretty(obj) {
33
+ try {
34
+ return JSON.stringify(obj, null, 2);
35
+ }
36
+ catch {
37
+ return String(obj);
38
+ }
39
+ }
40
+ /**
41
+ * This method to set APIRequestContext object.
42
+ * @param request APIRequestContext
43
+ */
44
+ static setRequest(request) {
45
+ this.request = request;
46
+ }
47
+ /**
48
+ * This method will returns APIRequestContext object.
49
+ * @returns APIRequestContext
50
+ */
51
+ static getRequest() {
52
+ return this.request;
53
+ }
54
+ /**
55
+ * This method set apiMethod and apiPath using apiData object of the json file.
56
+ * @param apiName ApiName
57
+ */
58
+ static setApiData(apiName) {
59
+ this.apiMethod = api_data_json_1.default[apiName].method;
60
+ this.apiPath = api_data_json_1.default[apiName].path;
61
+ }
62
+ /**
63
+ * This method is to get api method.
64
+ * @returns string
65
+ */
66
+ static geApiMethod() {
67
+ return this.apiMethod;
68
+ }
69
+ /**
70
+ * This method is get api path.
71
+ * @returns string
72
+ */
73
+ static getApiPath() {
74
+ return this.apiPath;
75
+ }
76
+ static buildPath(apiPath, pathParams) {
77
+ if (!pathParams)
78
+ return apiPath;
79
+ let finalPath = apiPath;
80
+ for (const [key, value] of Object.entries(pathParams)) {
81
+ finalPath = finalPath.replace(new RegExp(`{${key}}`, "g"), encodeURIComponent(String(value)));
82
+ }
83
+ return finalPath;
84
+ }
85
+ /**
86
+ * This method to log request details in console if apiLogs flag is true.
87
+ * @param method string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
88
+ * @param url string
89
+ * @param options RequestOptions
90
+ */
91
+ static logRequest(method, url, options) {
92
+ if (this.apiLogs) {
93
+ console.log("Request:");
94
+ console.log(method, url);
95
+ if (options?.headers)
96
+ console.log("Headers:", this.pretty(options.headers));
97
+ if (options?.body)
98
+ console.log("Body:", this.pretty(options.body));
99
+ if (options?.queryParams)
100
+ console.log("Query Params:", this.pretty(options.queryParams));
101
+ }
102
+ }
103
+ /**
104
+ * This method is set APIResponse object along with responseCode and responseBody.
105
+ * Also log response details in console if apiLogs flag is true.
106
+ * @param response APIResponse
107
+ */
108
+ static async setResponse(response) {
109
+ this.response = response;
110
+ try {
111
+ this.responseCode = this.response?.status?.() ?? 0;
112
+ }
113
+ catch (e) {
114
+ this.responseCode = 0;
115
+ }
116
+ try {
117
+ this.responseBody = await response.json();
118
+ }
119
+ catch (e) {
120
+ this.responseBody = {};
121
+ }
122
+ this.logResponse();
123
+ }
124
+ /**
125
+ * This method is get APIResponse object.
126
+ * @returns APIResponse
127
+ */
128
+ static getResponse() {
129
+ return this.response;
130
+ }
131
+ /**
132
+ * This method is get response code.
133
+ * @returns number
134
+ */
135
+ static getResponseCode() {
136
+ return this.responseCode;
137
+ }
138
+ /**
139
+ * This method is get response body.
140
+ * @returns T = unknown
141
+ */
142
+ static getResponseBody() {
143
+ return this.responseBody;
144
+ }
145
+ /**
146
+ * This method is log response details in console if apiLogs flag is true.
147
+ */
148
+ static logResponse() {
149
+ if (this.apiLogs) {
150
+ console.log("Response:");
151
+ console.log("Status Code:", this.getResponseCode());
152
+ console.log("Body:", this.pretty(this.getResponseBody()));
153
+ }
154
+ }
155
+ /**
156
+ * This method is to send respuest as per passed details and return response.
157
+ * @param method string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
158
+ * @param url string - passed Base Url and endpoint together, example: {BaseUrl}+{ApiPath}
159
+ * @param options RequestOptions - this is optional.
160
+ * @returns @link APIResponse
161
+ *
162
+ * Examples:
163
+ * const response = sendRequest('POST', {BaseUrl}+{ApiPath}, {headers: {...headers}, body: {...payload}});
164
+ */
165
+ static async sendRequest(method, url, options) {
166
+ url = this.buildPath(url, options?.pathParams);
167
+ this.logRequest(method, url, options);
168
+ const reqOptions = {};
169
+ if (options?.headers)
170
+ reqOptions.headers = options.headers;
171
+ if (options?.queryParams)
172
+ reqOptions.params = options.queryParams;
173
+ if (options?.body)
174
+ reqOptions.data = options.body;
175
+ try {
176
+ const response = await this.getRequest().fetch(url, {
177
+ method,
178
+ ...reqOptions,
179
+ });
180
+ return response;
181
+ }
182
+ catch (error) {
183
+ const empty = new EmptyApiResponse();
184
+ await this.setResponse(empty);
185
+ return empty;
186
+ }
187
+ }
188
+ /**
189
+ * This method is get response object value as per passed path.
190
+ * Also if object value not found then you set return some defaultValue which is optional.
191
+ * @param path string - example 'token', 'intent.paymentTypes', 'customers[0].firstName'
192
+ * @param defaultValue T = any
193
+ * @returns T = any
194
+ */
195
+ static async getResponseValue(path, defaultValue) {
196
+ try {
197
+ const body = (await this.getResponseBody());
198
+ if (!body || !path) {
199
+ return defaultValue !== undefined ? defaultValue : "";
200
+ }
201
+ const result = path
202
+ .replace(/\[(\d+)\]/g, ".$1")
203
+ .split(".")
204
+ .reduce((obj, key) => obj?.[key], body);
205
+ if (result === undefined || result === null) {
206
+ return defaultValue !== undefined ? defaultValue : "";
207
+ }
208
+ return result;
209
+ }
210
+ catch {
211
+ return defaultValue !== undefined ? defaultValue : "";
212
+ }
213
+ }
214
+ /**
215
+ * This method is get response object value as array.
216
+ * @param path string - example 'customers'
217
+ * @returns T = any []
218
+ */
219
+ static async getResponseArray(path) {
220
+ const value = await this.getResponseValue(path, []);
221
+ return Array.isArray(value) ? value : [];
222
+ }
223
+ /**
224
+ * Finds an object inside an array and returns its id where multiple fields match
225
+ * @param arrayPath Path to array. Example: "data"
226
+ * @param match Object with fields to match. Example: { allyName: "Zbook1201", status: "ACTIVE" }
227
+ * @param objectName Object name of which value return . "id"
228
+ */
229
+ static async getResponseValueFromArray(arrayPath, objectName, match) {
230
+ try {
231
+ if (!match || typeof match !== "object") {
232
+ return "";
233
+ }
234
+ let arr;
235
+ if (!arrayPath) {
236
+ const body = await this.getResponseBody();
237
+ arr = Array.isArray(body) ? body : [];
238
+ }
239
+ else {
240
+ arr = await this.getResponseArray(arrayPath);
241
+ }
242
+ if (!Array.isArray(arr) || arr.length === 0) {
243
+ return "";
244
+ }
245
+ const found = arr.find((item) => {
246
+ if (!item || typeof item !== "object")
247
+ return false;
248
+ return Object.entries(match).every(([key, value]) => item?.[key] === value);
249
+ });
250
+ if (!found || typeof found !== "object") {
251
+ return "";
252
+ }
253
+ const result = found?.[objectName];
254
+ return result !== undefined && result !== null ? String(result) : "";
255
+ }
256
+ catch (error) {
257
+ // Optional: console.warn("⚠️ getResponseValueFromArray failed:", error);
258
+ return "";
259
+ }
260
+ }
261
+ }
262
+ exports.ApiUtils = ApiUtils;
263
+ ApiUtils.apiLogs = false;
264
+ //# sourceMappingURL=apiUtils.js.map