@anddone/coretestautomation 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.
- package/.github/workflows/npm-release.yml +1 -1
- package/.github/workflows/publish-coretest.yml +145 -0
- package/.github/workflows/release-coretest.yml +104 -0
- package/dist/api/headers.d.ts +30 -0
- package/dist/api/headers.d.ts.map +1 -1
- package/dist/api/headers.js +30 -0
- package/dist/api/headers.js.map +1 -1
- package/dist/utils/apiUtils.d.ts +42 -13
- package/dist/utils/apiUtils.d.ts.map +1 -1
- package/dist/utils/apiUtils.js +42 -13
- package/dist/utils/apiUtils.js.map +1 -1
- package/dist/utils/fileCommonUtils.d.ts +115 -8
- package/dist/utils/fileCommonUtils.d.ts.map +1 -1
- package/dist/utils/fileCommonUtils.js +124 -25
- package/dist/utils/fileCommonUtils.js.map +1 -1
- package/package.json +4 -1
- package/src/api/headers.ts +31 -0
- package/src/utils/apiUtils.ts +43 -17
- package/src/utils/fileCommonUtils.ts +133 -34
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
name: Publish-CoreTestAutomation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
issues: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
with:
|
|
17
|
+
fetch-depth: 0
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 18
|
|
22
|
+
registry-url: https://registry.npmjs.org/
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: npm install
|
|
26
|
+
|
|
27
|
+
- name: Create approval issue
|
|
28
|
+
id: approval_issue
|
|
29
|
+
uses: actions/github-script@v7
|
|
30
|
+
with:
|
|
31
|
+
script: |
|
|
32
|
+
const body = [
|
|
33
|
+
"Approval required for npm publish",
|
|
34
|
+
"",
|
|
35
|
+
"Package: @anddone/coretestautomation",
|
|
36
|
+
`Run ID: ${context.runId}`,
|
|
37
|
+
"",
|
|
38
|
+
"Approvers:",
|
|
39
|
+
"@ad-amolpatil",
|
|
40
|
+
"@ad-rushabhGunjal",
|
|
41
|
+
"@ad-siddheshwaranajekar",
|
|
42
|
+
"@ad-dbharathidasan",
|
|
43
|
+
"",
|
|
44
|
+
"Please comment APPROVE to proceed."
|
|
45
|
+
].join("\n");
|
|
46
|
+
|
|
47
|
+
const { data: issue } = await github.rest.issues.create({
|
|
48
|
+
owner: context.repo.owner,
|
|
49
|
+
repo: context.repo.repo,
|
|
50
|
+
title: "Approval required: Publish coretestautomation",
|
|
51
|
+
body
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
core.setOutput("issue_number", issue.number);
|
|
55
|
+
|
|
56
|
+
- name: Wait for approval
|
|
57
|
+
uses: actions/github-script@v7
|
|
58
|
+
with:
|
|
59
|
+
script: |
|
|
60
|
+
const owner = context.repo.owner;
|
|
61
|
+
const repo = context.repo.repo;
|
|
62
|
+
const issue_number = Number('${{ steps.approval_issue.outputs.issue_number }}');
|
|
63
|
+
|
|
64
|
+
const APPROVERS = [
|
|
65
|
+
'ad-amolpatil',
|
|
66
|
+
'ad-rushabhGunjal',
|
|
67
|
+
'ad-siddheshwaranajekar',
|
|
68
|
+
'ad-dbharathidasan'
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const TIMEOUT_MINUTES = 60;
|
|
72
|
+
const POLL_MS = 30000;
|
|
73
|
+
const start = Date.now();
|
|
74
|
+
|
|
75
|
+
while (true) {
|
|
76
|
+
const { data: comments } = await github.rest.issues.listComments({
|
|
77
|
+
owner,
|
|
78
|
+
repo,
|
|
79
|
+
issue_number,
|
|
80
|
+
per_page: 100
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const approved = comments.some(c =>
|
|
84
|
+
APPROVERS.includes(c.user.login) &&
|
|
85
|
+
c.body.trim().toUpperCase() === 'APPROVE'
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (approved) break;
|
|
89
|
+
|
|
90
|
+
if ((Date.now() - start) / 60000 > TIMEOUT_MINUTES) {
|
|
91
|
+
core.setFailed('Timed out waiting for approval.');
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await new Promise(res => setTimeout(res, POLL_MS));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- name: Configure npm auth
|
|
99
|
+
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
|
|
100
|
+
env:
|
|
101
|
+
NODE_AUTH_TOKEN: ${{ secrets.TESTAUTOMATIONAUTH }}
|
|
102
|
+
|
|
103
|
+
- name: Publish to npm
|
|
104
|
+
run: npm publish --access public
|
|
105
|
+
env:
|
|
106
|
+
NODE_AUTH_TOKEN: ${{ secrets.TESTAUTOMATIONAUTH }}
|
|
107
|
+
|
|
108
|
+
- name: Read release notes from tag
|
|
109
|
+
if: success()
|
|
110
|
+
run: |
|
|
111
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
112
|
+
# Read annotated tag body and write to file — safest way to handle multiline/special chars
|
|
113
|
+
git for-each-ref --format='%(contents:body)' "refs/tags/v${VERSION}" 2>/dev/null > /tmp/release_notes.txt
|
|
114
|
+
|
|
115
|
+
if [ ! -s /tmp/release_notes.txt ]; then
|
|
116
|
+
echo "(No release notes available)" > /tmp/release_notes.txt
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
- name: Slack success (dev channel)
|
|
120
|
+
if: success()
|
|
121
|
+
continue-on-error: true
|
|
122
|
+
env:
|
|
123
|
+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
124
|
+
run: |
|
|
125
|
+
PACKAGE_NAME="@anddone/coretestautomation"
|
|
126
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
127
|
+
NOTES=$(cat /tmp/release_notes.txt)
|
|
128
|
+
|
|
129
|
+
PAYLOAD=$(jq -n \
|
|
130
|
+
--arg pkg "$PACKAGE_NAME" \
|
|
131
|
+
--arg ver "$VERSION" \
|
|
132
|
+
--arg notes "$NOTES" \
|
|
133
|
+
'{text: ("NPM package published\n\nPackage: " + $pkg + "\nVersion: " + $ver + "\n\nRelease Notes:\n" + $notes)}')
|
|
134
|
+
|
|
135
|
+
HTTP_STATUS=$(curl -s -o /tmp/slack_response.txt -w "%{http_code}" \
|
|
136
|
+
-X POST \
|
|
137
|
+
-H "Content-type: application/json" \
|
|
138
|
+
--data "$PAYLOAD" \
|
|
139
|
+
"$SLACK_WEBHOOK_URL")
|
|
140
|
+
|
|
141
|
+
echo "Slack response: HTTP $HTTP_STATUS — $(cat /tmp/slack_response.txt)"
|
|
142
|
+
|
|
143
|
+
if [ "$HTTP_STATUS" != "200" ]; then
|
|
144
|
+
echo "::warning::Slack notification failed with HTTP $HTTP_STATUS"
|
|
145
|
+
fi
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
release_notes:
|
|
16
|
+
description: "Release notes"
|
|
17
|
+
required: false
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
contents: write
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
release:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
with:
|
|
29
|
+
fetch-depth: 0
|
|
30
|
+
|
|
31
|
+
- uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: 18
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm install
|
|
37
|
+
|
|
38
|
+
- name: Build project
|
|
39
|
+
run: npm run build
|
|
40
|
+
|
|
41
|
+
- name: Configure Git
|
|
42
|
+
run: |
|
|
43
|
+
git config user.name "github-actions[bot]"
|
|
44
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
45
|
+
|
|
46
|
+
- name: Write release notes to file
|
|
47
|
+
env:
|
|
48
|
+
RELEASE_NOTES: ${{ github.event.inputs.release_notes }}
|
|
49
|
+
run: |
|
|
50
|
+
if [ -z "$RELEASE_NOTES" ]; then
|
|
51
|
+
echo "No release notes provided" > /tmp/release_notes.txt
|
|
52
|
+
else
|
|
53
|
+
echo "$RELEASE_NOTES" > /tmp/release_notes.txt
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
- name: Bump version and create annotated tag
|
|
57
|
+
run: |
|
|
58
|
+
RELEASE_TYPE="${{ inputs.release_type }}"
|
|
59
|
+
|
|
60
|
+
NEW_VERSION=$(npm version "$RELEASE_TYPE" --no-git-tag-version | sed 's/^v//')
|
|
61
|
+
|
|
62
|
+
git add package.json
|
|
63
|
+
git commit -m "chore(release): v$NEW_VERSION"
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
echo "Release v$NEW_VERSION"
|
|
67
|
+
echo ""
|
|
68
|
+
cat /tmp/release_notes.txt
|
|
69
|
+
} > /tmp/tag_message.txt
|
|
70
|
+
|
|
71
|
+
git tag -a "v${NEW_VERSION}" -F /tmp/tag_message.txt
|
|
72
|
+
git push origin HEAD --follow-tags
|
|
73
|
+
|
|
74
|
+
- name: Notify approvers on Slack
|
|
75
|
+
if: success()
|
|
76
|
+
continue-on-error: true
|
|
77
|
+
env:
|
|
78
|
+
SLACK_URL: ${{ secrets.SLACK_URL }}
|
|
79
|
+
run: |
|
|
80
|
+
PACKAGE_NAME="@anddone/coretestautomation"
|
|
81
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
82
|
+
NOTES=$(cat /tmp/release_notes.txt)
|
|
83
|
+
TAGS="<@U03U65PTMC3> <@U06KZU9FT4M> <@U06KN9E3ZFZ>"
|
|
84
|
+
PUBLISH_URL="https://github.com/${{ github.repository }}/actions/workflows/publish-coretest.yml"
|
|
85
|
+
|
|
86
|
+
PAYLOAD=$(jq -n \
|
|
87
|
+
--arg tags "$TAGS" \
|
|
88
|
+
--arg pkg "$PACKAGE_NAME" \
|
|
89
|
+
--arg ver "$VERSION" \
|
|
90
|
+
--arg notes "$NOTES" \
|
|
91
|
+
--arg url "$PUBLISH_URL" \
|
|
92
|
+
'{text: ($tags + " Release ready for approval\n\nPackage: " + $pkg + "\nVersion: " + $ver + "\n\nRelease Notes:\n" + $notes + "\n\nTrigger publish here:\n" + $url)}')
|
|
93
|
+
|
|
94
|
+
HTTP_STATUS=$(curl -s -o /tmp/slack_response.txt -w "%{http_code}" \
|
|
95
|
+
-X POST \
|
|
96
|
+
-H "Content-type: application/json" \
|
|
97
|
+
--data "$PAYLOAD" \
|
|
98
|
+
"$SLACK_URL")
|
|
99
|
+
|
|
100
|
+
echo "Slack response: HTTP $HTTP_STATUS — $(cat /tmp/slack_response.txt)"
|
|
101
|
+
|
|
102
|
+
if [ "$HTTP_STATUS" != "200" ]; then
|
|
103
|
+
echo "::warning::Slack notification failed with HTTP $HTTP_STATUS"
|
|
104
|
+
fi
|
package/dist/api/headers.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { Header } from "./base.api";
|
|
2
2
|
export declare class Headers {
|
|
3
3
|
static headers: Record<string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs and returns HTTP headers based on the provided options.
|
|
6
|
+
* Only the headers present in the options object will be added.
|
|
7
|
+
* If an authorization token is provided, it is automatically
|
|
8
|
+
* prefixed with "Bearer ".
|
|
9
|
+
* @param options - Optional header configuration object.
|
|
10
|
+
* Supported properties:
|
|
11
|
+
* - origin: Sets the "Origin" header
|
|
12
|
+
* - contentType: Sets the "Content-Type" header
|
|
13
|
+
* - authorization: Bearer token value (without "Bearer " prefix)
|
|
14
|
+
* - xVersion: Sets the "x-version" header
|
|
15
|
+
* - apiKey: Sets the "x-api-key" header
|
|
16
|
+
* - appKey: Sets the "x-app-key" header
|
|
17
|
+
*
|
|
18
|
+
* @returns An object containing the constructed HTTP headers.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* getHeaders({
|
|
22
|
+
* contentType: "application/json",
|
|
23
|
+
* authorization: "abc123",
|
|
24
|
+
* apiKey: "my-api-key"
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Returns:
|
|
28
|
+
* // {
|
|
29
|
+
* // "Content-Type": "application/json",
|
|
30
|
+
* // "Authorization": "Bearer abc123",
|
|
31
|
+
* // "x-api-key": "my-api-key"
|
|
32
|
+
* // }
|
|
33
|
+
*/
|
|
4
34
|
static getHeaders(options?: Header): Record<string, string>;
|
|
5
35
|
}
|
|
6
36
|
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -1 +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;
|
|
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;IAElB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,MAAW;CAWvC"}
|
package/dist/api/headers.js
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Headers = void 0;
|
|
4
4
|
class Headers {
|
|
5
|
+
/**
|
|
6
|
+
* Constructs and returns HTTP headers based on the provided options.
|
|
7
|
+
* Only the headers present in the options object will be added.
|
|
8
|
+
* If an authorization token is provided, it is automatically
|
|
9
|
+
* prefixed with "Bearer ".
|
|
10
|
+
* @param options - Optional header configuration object.
|
|
11
|
+
* Supported properties:
|
|
12
|
+
* - origin: Sets the "Origin" header
|
|
13
|
+
* - contentType: Sets the "Content-Type" header
|
|
14
|
+
* - authorization: Bearer token value (without "Bearer " prefix)
|
|
15
|
+
* - xVersion: Sets the "x-version" header
|
|
16
|
+
* - apiKey: Sets the "x-api-key" header
|
|
17
|
+
* - appKey: Sets the "x-app-key" header
|
|
18
|
+
*
|
|
19
|
+
* @returns An object containing the constructed HTTP headers.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* getHeaders({
|
|
23
|
+
* contentType: "application/json",
|
|
24
|
+
* authorization: "abc123",
|
|
25
|
+
* apiKey: "my-api-key"
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Returns:
|
|
29
|
+
* // {
|
|
30
|
+
* // "Content-Type": "application/json",
|
|
31
|
+
* // "Authorization": "Bearer abc123",
|
|
32
|
+
* // "x-api-key": "my-api-key"
|
|
33
|
+
* // }
|
|
34
|
+
*/
|
|
5
35
|
static getHeaders(options = {}) {
|
|
6
36
|
this.headers = {};
|
|
7
37
|
if (options.origin)
|
package/dist/api/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;IAIlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,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;AA7CD,0BA6CC"}
|
package/dist/utils/apiUtils.d.ts
CHANGED
|
@@ -42,19 +42,19 @@ export declare class ApiUtils {
|
|
|
42
42
|
*/
|
|
43
43
|
static getRequest(): APIRequestContext;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
* Sets the API method and API path based on the provided API data JSON object
|
|
46
|
+
* and API name key.
|
|
47
|
+
*
|
|
48
|
+
* This method is generic and works with any API data file that follows the
|
|
49
|
+
* ApiFile structure (Record<string, { method: string; path: string }>).
|
|
50
|
+
*
|
|
51
|
+
* @template T - Type of the API data object passed to the method
|
|
52
|
+
* @param apiName - Key name of the API entry inside the provided API data object
|
|
53
|
+
* @param api - API data JSON object containing method and path definitions
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ApiUtils.setApiData("login", apiData);
|
|
57
|
+
*/
|
|
58
58
|
static setApiData<T extends ApiFile>(apiName: keyof T, api: T): void;
|
|
59
59
|
/**
|
|
60
60
|
* This method is to get api method.
|
|
@@ -66,6 +66,35 @@ export declare class ApiUtils {
|
|
|
66
66
|
* @returns string
|
|
67
67
|
*/
|
|
68
68
|
static getApiPath(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Builds a complete API path by replacing path parameter placeholders
|
|
71
|
+
* in the given API path with actual values.
|
|
72
|
+
*
|
|
73
|
+
* Placeholders in the apiPath should be defined using curly braces,
|
|
74
|
+
* e.g. `/users/{userId}/orders/{orderId}`.
|
|
75
|
+
*
|
|
76
|
+
* Each placeholder will be replaced with the corresponding value from
|
|
77
|
+
* the pathParams object. Values are URL-encoded using encodeURIComponent
|
|
78
|
+
* to ensure safe transmission.
|
|
79
|
+
*
|
|
80
|
+
* @param apiPath - The API endpoint path containing optional placeholders (e.g., "/users/{id}")
|
|
81
|
+
* @param pathParams - An optional key-value map where:
|
|
82
|
+
* - key represents the placeholder name (without braces)
|
|
83
|
+
* - value represents the replacement value
|
|
84
|
+
*
|
|
85
|
+
* @returns The final API path with all placeholders replaced by their encoded values.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* buildPath("/users/{id}", { id: "123" });
|
|
89
|
+
* // Returns: "/users/123"
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* buildPath("/orders/{orderId}/items/{itemId}", {
|
|
93
|
+
* orderId: "ORD-001",
|
|
94
|
+
* itemId: "ITM-10"
|
|
95
|
+
* });
|
|
96
|
+
* // Returns: "/orders/ORD-001/items/ITM-10"
|
|
97
|
+
*/
|
|
69
98
|
private static buildPath;
|
|
70
99
|
/**
|
|
71
100
|
* This method to log request details in console if apiLogs flag is true.
|
|
@@ -1 +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;AAElE,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAExC,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,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AE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,OAAO,CAAC,MAAM,CAAC;CA+BnB"}
|
package/dist/utils/apiUtils.js
CHANGED
|
@@ -48,19 +48,19 @@ class ApiUtils {
|
|
|
48
48
|
return this.request;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
* Sets the API method and API path based on the provided API data JSON object
|
|
52
|
+
* and API name key.
|
|
53
|
+
*
|
|
54
|
+
* This method is generic and works with any API data file that follows the
|
|
55
|
+
* ApiFile structure (Record<string, { method: string; path: string }>).
|
|
56
|
+
*
|
|
57
|
+
* @template T - Type of the API data object passed to the method
|
|
58
|
+
* @param apiName - Key name of the API entry inside the provided API data object
|
|
59
|
+
* @param api - API data JSON object containing method and path definitions
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ApiUtils.setApiData("login", apiData);
|
|
63
|
+
*/
|
|
64
64
|
static setApiData(apiName, api) {
|
|
65
65
|
this.apiMethod = api[apiName].method;
|
|
66
66
|
this.apiPath = api[apiName].path;
|
|
@@ -79,6 +79,35 @@ class ApiUtils {
|
|
|
79
79
|
static getApiPath() {
|
|
80
80
|
return this.apiPath;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Builds a complete API path by replacing path parameter placeholders
|
|
84
|
+
* in the given API path with actual values.
|
|
85
|
+
*
|
|
86
|
+
* Placeholders in the apiPath should be defined using curly braces,
|
|
87
|
+
* e.g. `/users/{userId}/orders/{orderId}`.
|
|
88
|
+
*
|
|
89
|
+
* Each placeholder will be replaced with the corresponding value from
|
|
90
|
+
* the pathParams object. Values are URL-encoded using encodeURIComponent
|
|
91
|
+
* to ensure safe transmission.
|
|
92
|
+
*
|
|
93
|
+
* @param apiPath - The API endpoint path containing optional placeholders (e.g., "/users/{id}")
|
|
94
|
+
* @param pathParams - An optional key-value map where:
|
|
95
|
+
* - key represents the placeholder name (without braces)
|
|
96
|
+
* - value represents the replacement value
|
|
97
|
+
*
|
|
98
|
+
* @returns The final API path with all placeholders replaced by their encoded values.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* buildPath("/users/{id}", { id: "123" });
|
|
102
|
+
* // Returns: "/users/123"
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* buildPath("/orders/{orderId}/items/{itemId}", {
|
|
106
|
+
* orderId: "ORD-001",
|
|
107
|
+
* itemId: "ITM-10"
|
|
108
|
+
* });
|
|
109
|
+
* // Returns: "/orders/ORD-001/items/ITM-10"
|
|
110
|
+
*/
|
|
82
111
|
static buildPath(apiPath, pathParams) {
|
|
83
112
|
if (!pathParams)
|
|
84
113
|
return apiPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiUtils.js","sourceRoot":"","sources":["../../src/utils/apiUtils.ts"],"names":[],"mappings":";;;AAgBA,MAAa,gBAAgB;IAC3B,MAAM;QACJ,OAAO,CAAC,CAAC;IACX,CAAC;IACD,EAAE;QACA,OAAO,KAAK,CAAC;IACf,CAAC;IACD,GAAG;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAhBD,4CAgBC;AAED,MAAa,QAAQ;IAYnB;;;;OAIG;IACK,MAAM,CAAC,MAAM,CAAC,GAAY;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,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C,OAAO,KAAK,EAAE,CAAC;YACf,yEAAyE;YACzE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;;AA1TH,4BA2TC;AA1TgB,gBAAO,GAAG,KAAK,CAAC"}
|
|
@@ -1,23 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for handling files like Excel, CSV, JSON, XML, PDF, and Text.
|
|
3
|
+
* Provides helper methods for reading, writing, and manipulating files.
|
|
4
|
+
*/
|
|
1
5
|
export declare class FileCommonUtils {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Reads data from an Excel file and returns it as an array of objects.
|
|
8
|
+
* First row is treated as column headers.
|
|
9
|
+
*
|
|
10
|
+
* @template T - Type of row object
|
|
11
|
+
* @param filePath - Path to the Excel file
|
|
12
|
+
* @param sheetName - Optional sheet name (defaults to first sheet)
|
|
13
|
+
* @returns Promise resolving to array of row objects
|
|
14
|
+
*/
|
|
15
|
+
static readExcel<T = Record<string, any>>(filePath: string, sheetName?: string): Promise<T[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Writes data into an Excel file.
|
|
18
|
+
* Creates sheet if not exists, otherwise appends rows.
|
|
19
|
+
*
|
|
20
|
+
* @param filePath - Path to Excel file
|
|
21
|
+
* @param data - Array of objects to write
|
|
22
|
+
* @param sheetName - Sheet name (default: Sheet1)
|
|
23
|
+
*/
|
|
24
|
+
static writeExcel(filePath: string, data: Record<string, any>[], sheetName?: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns all sheet names from an Excel file.
|
|
27
|
+
*
|
|
28
|
+
* @param filePath - Path to Excel file
|
|
29
|
+
* @returns Promise resolving to array of sheet names
|
|
30
|
+
*/
|
|
31
|
+
static getExcelSheetNames(filePath: string): Promise<string[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads a CSV file and returns data as array of objects.
|
|
34
|
+
*
|
|
35
|
+
* @template T
|
|
36
|
+
* @param filePath - Path to CSV file
|
|
37
|
+
* @param delimiter - Column delimiter (default: ,)
|
|
38
|
+
* @returns Array of objects
|
|
39
|
+
*/
|
|
40
|
+
static readCSV<T = Record<string, string>>(filePath: string, delimiter?: string): T[];
|
|
41
|
+
/**
|
|
42
|
+
* Writes data into a CSV file.
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - Path to CSV file
|
|
45
|
+
* @param data - Array of objects
|
|
46
|
+
* @param delimiter - Column delimiter
|
|
47
|
+
*/
|
|
48
|
+
static writeCSV(filePath: string, data: Record<string, any>[], delimiter?: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Reads JSON file and converts to object.
|
|
51
|
+
*
|
|
52
|
+
* @template T
|
|
53
|
+
* @param filePath - Path to JSON file
|
|
54
|
+
* @returns Parsed object or null
|
|
55
|
+
*/
|
|
56
|
+
static readJson<T>(filePath: string): T | null;
|
|
57
|
+
/**
|
|
58
|
+
* Reads XML file and converts to object.
|
|
59
|
+
*
|
|
60
|
+
* @template T
|
|
61
|
+
* @param filePath - Path to XML file
|
|
62
|
+
* @returns Parsed XML object or null
|
|
63
|
+
*/
|
|
64
|
+
static readXml<T>(filePath: string): Promise<T | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns number of rows.
|
|
67
|
+
*/
|
|
10
68
|
static getRowCount<T>(data: T[]): number;
|
|
69
|
+
/**
|
|
70
|
+
* Returns number of columns.
|
|
71
|
+
*/
|
|
11
72
|
static getColumnCount<T extends Record<string, any>>(data: T[]): number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns column headers.
|
|
75
|
+
*/
|
|
12
76
|
static getColumnHeaders<T extends Record<string, any>>(data: T[]): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Returns value of a specific cell.
|
|
79
|
+
*/
|
|
13
80
|
static getCellData<T extends Record<string, any>>(data: T[], row: number, column: keyof T): any;
|
|
81
|
+
/**
|
|
82
|
+
* Filters rows by column value.
|
|
83
|
+
*/
|
|
14
84
|
static select<T extends Record<string, any>>(data: T[], column: keyof T, value: any): T[];
|
|
85
|
+
/**
|
|
86
|
+
* Reads text file.
|
|
87
|
+
*/
|
|
15
88
|
static readTextFile(filePath: string): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Reads PDF file and extracts text.
|
|
91
|
+
*/
|
|
16
92
|
static readPdfFile(filePath: string): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Replaces text inside a file.
|
|
95
|
+
*/
|
|
17
96
|
static editTextFile(filePath: string, search: string | RegExp, replace?: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Counts files in a folder.
|
|
99
|
+
*/
|
|
18
100
|
static getFileCount(folderPath: string): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns all file names in a folder.
|
|
103
|
+
*/
|
|
19
104
|
static getAllFileNames(folderPath: string): Promise<string[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Extracts all URLs from a PDF file and navigates to one of them in the browser.
|
|
107
|
+
*
|
|
108
|
+
* Reads the PDF file, searches for HTTP/HTTPS links using regex,
|
|
109
|
+
* and opens the selected link in the provided Playwright page.
|
|
110
|
+
*
|
|
111
|
+
* @param page - Playwright Page object used for navigation
|
|
112
|
+
* @param filePath - Path to the PDF file
|
|
113
|
+
* @param index - Index of the link to open (default: 0 = first link)
|
|
114
|
+
*
|
|
115
|
+
* @returns Promise that resolves when navigation is complete
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf");
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Open second link from PDF
|
|
122
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf", 1);
|
|
123
|
+
*/
|
|
20
124
|
static clickLinkInsidePdf(page: any, filePath: string, index?: number): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Executes shell command in a folder.
|
|
127
|
+
*/
|
|
21
128
|
static runCommand(folderPath: string, command: string): Promise<string>;
|
|
22
129
|
}
|
|
23
130
|
//# sourceMappingURL=fileCommonUtils.d.ts.map
|