-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add includeData parameter to
GET /credentials
(#12220)
Co-authored-by: r00gm <[email protected]>
- Loading branch information
1 parent
096329d
commit f56ad8c
Showing
15 changed files
with
526 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ | |
"dependencies": { | ||
"xss": "catalog:", | ||
"zod": "catalog:", | ||
"zod-class": "0.0.15" | ||
"zod-class": "0.0.16" | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ges/@n8n/api-types/src/dto/credentials/__tests__/credentials-get-many-request.dto.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { CredentialsGetManyRequestQuery } from '../credentials-get-many-request.dto'; | ||
|
||
describe('CredentialsGetManyRequestQuery', () => { | ||
describe('should pass validation', () => { | ||
it('with empty object', () => { | ||
const data = {}; | ||
|
||
const result = CredentialsGetManyRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
|
||
test.each([ | ||
{ field: 'includeScopes', value: 'true' }, | ||
{ field: 'includeScopes', value: 'false' }, | ||
{ field: 'includeData', value: 'true' }, | ||
{ field: 'includeData', value: 'false' }, | ||
])('with $field set to $value', ({ field, value }) => { | ||
const data = { [field]: value }; | ||
|
||
const result = CredentialsGetManyRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('with both parameters set', () => { | ||
const data = { | ||
includeScopes: 'true', | ||
includeData: 'true', | ||
}; | ||
|
||
const result = CredentialsGetManyRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('should fail validation', () => { | ||
test.each([ | ||
{ field: 'includeScopes', value: true }, | ||
{ field: 'includeScopes', value: false }, | ||
{ field: 'includeScopes', value: 'invalid' }, | ||
{ field: 'includeData', value: true }, | ||
{ field: 'includeData', value: false }, | ||
{ field: 'includeData', value: 'invalid' }, | ||
])('with invalid value $value for $field', ({ field, value }) => { | ||
const data = { [field]: value }; | ||
|
||
const result = CredentialsGetManyRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(false); | ||
expect(result.error?.issues[0].path[0]).toBe(field); | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...ages/@n8n/api-types/src/dto/credentials/__tests__/credentials-get-one-request.dto.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CredentialsGetOneRequestQuery } from '../credentials-get-one-request.dto'; | ||
|
||
describe('CredentialsGetManyRequestQuery', () => { | ||
describe('should pass validation', () => { | ||
it('with empty object', () => { | ||
const data = {}; | ||
|
||
const result = CredentialsGetOneRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
// defaults to false | ||
expect(result.data?.includeData).toBe(false); | ||
}); | ||
|
||
test.each([ | ||
{ field: 'includeData', value: 'true' }, | ||
{ field: 'includeData', value: 'false' }, | ||
])('with $field set to $value', ({ field, value }) => { | ||
const data = { [field]: value }; | ||
|
||
const result = CredentialsGetOneRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('with both parameters set', () => { | ||
const data = { | ||
includeScopes: 'true', | ||
includeData: 'true', | ||
}; | ||
|
||
const result = CredentialsGetOneRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('should fail validation', () => { | ||
test.each([ | ||
{ field: 'includeData', value: true }, | ||
{ field: 'includeData', value: false }, | ||
{ field: 'includeData', value: 'invalid' }, | ||
])('with invalid value $value for $field', ({ field, value }) => { | ||
const data = { [field]: value }; | ||
|
||
const result = CredentialsGetOneRequestQuery.safeParse(data); | ||
|
||
expect(result.success).toBe(false); | ||
expect(result.error?.issues[0].path[0]).toBe(field); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/@n8n/api-types/src/dto/credentials/credentials-get-many-request.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Z } from 'zod-class'; | ||
|
||
import { booleanFromString } from '../../schemas/booleanFromString'; | ||
|
||
export class CredentialsGetManyRequestQuery extends Z.class({ | ||
/** | ||
* Adds the `scopes` field to each credential which includes all scopes the | ||
* requesting user has in relation to the credential, e.g. | ||
* ['credential:read', 'credential:update'] | ||
*/ | ||
includeScopes: booleanFromString.optional(), | ||
|
||
/** | ||
* Adds the decrypted `data` field to each credential. | ||
* | ||
* It only does this for credentials for which the user has the | ||
* `credential:update` scope. | ||
* | ||
* This switches `includeScopes` to true to be able to check for the scopes | ||
*/ | ||
includeData: booleanFromString.optional(), | ||
}) {} |
13 changes: 13 additions & 0 deletions
13
packages/@n8n/api-types/src/dto/credentials/credentials-get-one-request.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Z } from 'zod-class'; | ||
|
||
import { booleanFromString } from '../../schemas/booleanFromString'; | ||
|
||
export class CredentialsGetOneRequestQuery extends Z.class({ | ||
/** | ||
* Adds the decrypted `data` field to each credential. | ||
* | ||
* It only does this for credentials for which the user has the | ||
* `credential:update` scope. | ||
*/ | ||
includeData: booleanFromString.optional().default('false'), | ||
}) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { z } from 'zod'; | ||
|
||
export const booleanFromString = z.enum(['true', 'false']).transform((value) => value === 'true'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.