Skip to content

Commit 6876e2a

Browse files
committed
update ts docs
1 parent fc48266 commit 6876e2a

File tree

5 files changed

+129
-36
lines changed

5 files changed

+129
-36
lines changed

packages/artifact/src/internal/shared/util.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,23 @@ export function getBackendIdsFromToken(): BackendIds {
7373

7474
/**
7575
* Masks the `sig` parameter in a URL and sets it as a secret.
76-
* @param url The URL containing the `sig` parameter.
77-
* @returns A masked URL where the sig parameter value is replaced with '***' if found,
78-
* or the original URL if no sig parameter is present.
76+
*
77+
* @param url - The URL containing the signature parameter to mask
78+
* @remarks
79+
* This function attempts to parse the provided URL and identify the 'sig' query parameter.
80+
* If found, it registers both the raw and URL-encoded signature values as secrets using
81+
* the Actions `setSecret` API, which prevents them from being displayed in logs.
82+
*
83+
* The function handles errors gracefully if URL parsing fails, logging them as debug messages.
84+
*
85+
* @example
86+
* ```typescript
87+
* // Mask a signature in an Azure SAS token URL
88+
* maskSigUrl('https://example.blob.core.windows.net/container/file.txt?sig=abc123&se=2023-01-01');
89+
* ```
7990
*/
80-
export function maskSigUrl(url: string): string {
81-
if (!url) return url
82-
91+
export function maskSigUrl(url: string): void {
92+
if (!url) return
8393
try {
8494
const parsedUrl = new URL(url)
8595
const signature = parsedUrl.searchParams.get('sig')
@@ -88,7 +98,6 @@ export function maskSigUrl(url: string): string {
8898
setSecret(signature)
8999
setSecret(encodeURIComponent(signature))
90100
parsedUrl.searchParams.set('sig', '***')
91-
return parsedUrl.toString()
92101
}
93102
} catch (error) {
94103
debug(
@@ -97,11 +106,28 @@ export function maskSigUrl(url: string): string {
97106
}`
98107
)
99108
}
100-
return url
101109
}
102110

103111
/**
104-
* Masks any URLs containing signature parameters in the provided object
112+
* Masks sensitive information in URLs containing signature parameters.
113+
* Currently supports masking 'sig' parameters in the 'signed_upload_url'
114+
* and 'signed_download_url' properties of the provided object.
115+
*
116+
* @param body - The object should contain a signature
117+
* @remarks
118+
* This function extracts URLs from the object properties and calls maskSigUrl
119+
* on each one to redact sensitive signature information. The function doesn't
120+
* modify the original object; it only marks the signatures as secrets for
121+
* logging purposes.
122+
*
123+
* @example
124+
* ```typescript
125+
* const responseBody = {
126+
* signed_upload_url: 'https://example.com?sig=abc123',
127+
* signed_download_url: 'https://example.com?sig=def456'
128+
* };
129+
* maskSecretUrls(responseBody);
130+
* ```
105131
*/
106132
export function maskSecretUrls(body: Record<string, unknown> | null): void {
107133
if (typeof body !== 'object' || body === null) {

packages/cache/__tests__/util.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,28 @@ describe('maskSigUrl', () => {
88
jest.clearAllMocks()
99
})
1010

11-
it('returns the original URL if no sig parameter is present', () => {
11+
it('does nothing if no sig parameter is present', () => {
1212
const url = 'https://example.com'
13-
const maskedUrl = maskSigUrl(url)
14-
expect(maskedUrl).toBe(url)
13+
maskSigUrl(url)
1514
expect(setSecret).not.toHaveBeenCalled()
1615
})
1716

1817
it('masks the sig parameter in the middle of the URL and sets it as a secret', () => {
1918
const url = 'https://example.com/?param1=value1&sig=12345&param2=value2'
20-
const maskedUrl = maskSigUrl(url)
21-
expect(maskedUrl).toBe(
22-
'https://example.com/?param1=value1&sig=***&param2=value2'
23-
)
19+
maskSigUrl(url)
2420
expect(setSecret).toHaveBeenCalledWith('12345')
2521
expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345'))
2622
})
2723

28-
it('returns the original URL if it is empty', () => {
24+
it('does nothing if the URL is empty', () => {
2925
const url = ''
30-
const maskedUrl = maskSigUrl(url)
31-
expect(maskedUrl).toBe('')
26+
maskSigUrl(url)
3227
expect(setSecret).not.toHaveBeenCalled()
3328
})
3429

3530
it('handles URLs with fragments', () => {
3631
const url = 'https://example.com?sig=12345#fragment'
37-
const maskedUrl = maskSigUrl(url)
38-
expect(maskedUrl).toBe('https://example.com/?sig=***#fragment')
32+
maskSigUrl(url)
3933
expect(setSecret).toHaveBeenCalledWith('12345')
4034
expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345'))
4135
})

packages/cache/src/internal/shared/util.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ import {debug, setSecret} from '@actions/core'
22

33
/**
44
* Masks the `sig` parameter in a URL and sets it as a secret.
5-
* @param url The URL containing the `sig` parameter.
6-
* @returns A masked URL where the sig parameter value is replaced with '***' if found,
7-
* or the original URL if no sig parameter is present.
5+
*
6+
* @param url - The URL containing the signature parameter to mask
7+
* @remarks
8+
* This function attempts to parse the provided URL and identify the 'sig' query parameter.
9+
* If found, it registers both the raw and URL-encoded signature values as secrets using
10+
* the Actions `setSecret` API, which prevents them from being displayed in logs.
11+
*
12+
* The function handles errors gracefully if URL parsing fails, logging them as debug messages.
13+
*
14+
* @example
15+
* ```typescript
16+
* // Mask a signature in an Azure SAS token URL
17+
* maskSigUrl('https://example.blob.core.windows.net/container/file.txt?sig=abc123&se=2023-01-01');
18+
* ```
819
*/
9-
export function maskSigUrl(url: string): string {
10-
if (!url) return url
11-
20+
export function maskSigUrl(url: string): void {
21+
if (!url) return
1222
try {
1323
const parsedUrl = new URL(url)
1424
const signature = parsedUrl.searchParams.get('sig')
@@ -17,7 +27,6 @@ export function maskSigUrl(url: string): string {
1727
setSecret(signature)
1828
setSecret(encodeURIComponent(signature))
1929
parsedUrl.searchParams.set('sig', '***')
20-
return parsedUrl.toString()
2130
}
2231
} catch (error) {
2332
debug(
@@ -26,18 +35,34 @@ export function maskSigUrl(url: string): string {
2635
}`
2736
)
2837
}
29-
return url
3038
}
3139

3240
/**
33-
* Masks any URLs containing signature parameters in the provided object
41+
* Masks sensitive information in URLs containing signature parameters.
42+
* Currently supports masking 'sig' parameters in the 'signed_upload_url'
43+
* and 'signed_download_url' properties of the provided object.
44+
*
45+
* @param body - The object should contain a signature
46+
* @remarks
47+
* This function extracts URLs from the object properties and calls maskSigUrl
48+
* on each one to redact sensitive signature information. The function doesn't
49+
* modify the original object; it only marks the signatures as secrets for
50+
* logging purposes.
51+
*
52+
* @example
53+
* ```typescript
54+
* const responseBody = {
55+
* signed_upload_url: 'https://blob.core.windows.net/?sig=abc123',
56+
* signed_download_url: 'https://blob.core/windows.net/?sig=def456'
57+
* };
58+
* maskSecretUrls(responseBody);
59+
* ```
3460
*/
3561
export function maskSecretUrls(body: Record<string, unknown> | null): void {
3662
if (typeof body !== 'object' || body === null) {
3763
debug('body is not an object or is null')
3864
return
3965
}
40-
4166
if (
4267
'signed_upload_url' in body &&
4368
typeof body.signed_upload_url === 'string'

packages/core/src/command.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,37 @@ export interface CommandProperties {
1111
}
1212

1313
/**
14-
* Commands
14+
* Issues a command to the GitHub Actions runner
15+
*
16+
* @param command - The command name to issue
17+
* @param properties - Additional properties for the command (key-value pairs)
18+
* @param message - The message to include with the command
19+
* @remarks
20+
* This function outputs a specially formatted string to stdout that the Actions
21+
* runner interprets as a command. These commands can control workflow behavior,
22+
* set outputs, create annotations, mask values, and more.
1523
*
1624
* Command Format:
1725
* ::name key=value,key=value::message
1826
*
19-
* Examples:
20-
* ::warning::This is the message
21-
* ::set-env name=MY_VAR::some value
27+
* @example
28+
* ```typescript
29+
* // Issue a warning annotation
30+
* issueCommand('warning', {}, 'This is a warning message');
31+
* // Output: ::warning::This is a warning message
32+
*
33+
* // Set an environment variable
34+
* issueCommand('set-env', { name: 'MY_VAR' }, 'some value');
35+
* // Output: ::set-env name=MY_VAR::some value
36+
*
37+
* // Add a secret mask
38+
* issueCommand('add-mask', {}, 'secretValue123');
39+
* // Output: ::add-mask::secretValue123
40+
* ```
41+
*
42+
* @internal
43+
* This is an internal utility function that powers the public API functions
44+
* such as setSecret, warning, error, and exportVariable.
2245
*/
2346
export function issueCommand(
2447
command: string,

packages/core/src/core.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,32 @@ export function exportVariable(name: string, val: any): void {
9494

9595
/**
9696
* Registers a secret which will get masked from logs
97-
* @param secret value of the secret
97+
*
98+
* @param secret - Value of the secret to be masked
99+
* @remarks
100+
* This function instructs the Actions runner to mask the specified value in any
101+
* logs produced during the workflow run. Once registered, the secret value will
102+
* be replaced with asterisks (***) whenever it appears in console output, logs,
103+
* or error messages.
104+
*
105+
* This is useful for protecting sensitive information such as:
106+
* - API keys
107+
* - Access tokens
108+
* - Authentication credentials
109+
* - URL parameters containing signatures (SAS tokens)
110+
*
111+
* Note that masking only affects future logs; any previous appearances of the
112+
* secret in logs before calling this function will remain unmasked.
113+
*
114+
* @example
115+
* ```typescript
116+
* // Register an API token as a secret
117+
* const apiToken = "abc123xyz456";
118+
* setSecret(apiToken);
119+
*
120+
* // Now any logs containing this value will show *** instead
121+
* console.log(`Using token: ${apiToken}`); // Outputs: "Using token: ***"
122+
* ```
98123
*/
99124
export function setSecret(secret: string): void {
100125
issueCommand('add-mask', {}, secret)

0 commit comments

Comments
 (0)