Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discoverability flow and scopes notice for HTTP Request node #3229

Merged
merged 116 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
2808ee9
:sparkles: Added node credentials type proxy. Changed node credential…
alexgrozav Apr 26, 2022
d074e52
:zap: Add computed property from versioning branch
ivov Apr 28, 2022
403e570
:bug: Fix cred ref lost and unsaved
ivov Apr 29, 2022
59cb1a2
:zap: Make options consistent with cred type names
ivov May 2, 2022
ca0f0df
:zap: Use prop to set component order
ivov May 2, 2022
81aeefa
:zap: Use constant and version
ivov May 2, 2022
3d5b92b
:zap: Fix rendering for generic auth creds
ivov May 2, 2022
452139f
:zap: Mark as required on first selection
ivov May 2, 2022
c19df79
:zap: Implement discoverability flow
ivov May 2, 2022
9b3e9a2
:zap: Mark as required on subsequent selections
ivov May 2, 2022
bd02a61
:zap: Fix marking as required after cred deletion
ivov May 2, 2022
791ed95
:zap: Refactor to clean up
ivov May 3, 2022
aedbbe5
:twisted_rightwards_arrows: Merge parent branch
ivov May 3, 2022
cacd43f
:zap: Detect position automatically
ivov May 3, 2022
9bd62c7
:twisted_rightwards_arrows: Merge parent branch
ivov May 3, 2022
fa4f484
:zap: Add i18n to option label
ivov May 3, 2022
b290ad5
:twisted_rightwards_arrows: Merge parent branch
ivov May 3, 2022
4997569
:zap: Hide subtitle for custom action
ivov May 3, 2022
64e08c8
:zap: Detect active credential type
ivov May 3, 2022
aa986e1
:zap: Prop drilling to re-render select
ivov May 4, 2022
0d4dbdc
:fire: Remove unneeded property
ivov May 4, 2022
5743da3
:pencil2: Rename arg
ivov May 4, 2022
2904562
:fire: Remove unused import
ivov May 4, 2022
238565b
:fire: Remove unneeded getters
ivov May 4, 2022
9f15c93
:fire: Remove unused import
ivov May 4, 2022
75eea89
:zap: Generalize cred component positioning
ivov May 4, 2022
77747f8
:zap: Set up request
ivov May 4, 2022
04997c5
:bug: Fix edge case in endpoint
ivov May 4, 2022
1efedfd
:zap: Display scopes alert box
ivov May 4, 2022
2eaf05e
:rewind: Revert "Generalize cred comp positioning"
ivov May 5, 2022
fec2fc1
:zap: Consolidate HTTPRN check
ivov May 5, 2022
24b8a56
:zap: Fix hue percentage to degree
ivov May 5, 2022
cb96d78
:fire: Remove unused import
ivov May 5, 2022
b8357e0
:fire: Remove unused import
ivov May 5, 2022
9151dec
:fire: Remove unused class
ivov May 5, 2022
cf54e6a
:fire: Remove unused import
ivov May 5, 2022
f7cff03
:blue_book: Create type for HTTPRN v2 auth params
ivov May 5, 2022
bc4aaa6
:pencil2: Rename check
ivov May 5, 2022
43f7e2c
:fire: Remove unused import
ivov May 5, 2022
760ef5a
:pencil2: Add i18n to `reportUnsetCredential()`
ivov May 5, 2022
0a221f3
:zap: Refactor Alex's spacing changes
ivov May 5, 2022
5c11a1b
:twisted_rightwards_arrows: Merge parent branch
ivov May 5, 2022
d8de1cf
:twisted_rightwards_arrows: Merge parent branch
ivov May 5, 2022
af455e0
:twisted_rightwards_arrows: Merge parent branch
ivov May 5, 2022
eebc6dd
:twisted_rightwards_arrows: Merge parent branch
ivov May 5, 2022
e530bd4
:zap: Post-merge fixes
ivov May 5, 2022
a708b31
:twisted_rightwards_arrows: Merge scopes branch
ivov May 5, 2022
4450b6c
:zap: Add docs link
ivov May 5, 2022
6d2bb7e
:fire: Exclude Notion OAuth cred
ivov May 5, 2022
e983266
:pencil2: Update copy
ivov May 5, 2022
5501bc8
:pencil2: Rename param
ivov May 5, 2022
a294201
:art: Reposition notice and simplify styling
ivov May 5, 2022
aa89404
:pencil2: Update copy
ivov May 5, 2022
ba9c85e
:pencil2: Update copy
ivov May 6, 2022
216d2e0
:zap: Hide params during custom action
ivov May 9, 2022
e543b04
:zap: Show notice if any cred type supported
ivov May 9, 2022
83b4225
:twisted_rightwards_arrows: Merge parent branch
ivov May 9, 2022
dc8d266
:bug: Prevent scopes text overflow
ivov May 9, 2022
1420386
:fire: Remove superfluous check
ivov May 9, 2022
e6332a7
:pencil2: Break up docstring
ivov May 9, 2022
2c8805c
:art: Tweak notice styling
ivov May 9, 2022
6d07fc2
:zap: Reorder cred param in Webhook node
ivov May 9, 2022
4a6e78d
:pencil2: Shorten cred name in scopes notice
ivov May 9, 2022
0380403
:test_tube: Update Notice snapshots
ivov May 9, 2022
3f2c4a6
:bug: Fix check when `globalRole` is `undefined`
ivov May 9, 2022
1c0cb25
:rewind: Revert 3f2c4a6
ivov May 9, 2022
f06d77d
:zap: Apply feedback from Product
ivov May 10, 2022
517079f
:test_tube: Update snapshot
ivov May 10, 2022
7b67774
:zap: Adjust regex expansion pattern for singular
ivov May 10, 2022
c607997
:twisted_rightwards_arrows: Merge parent branch
ivov May 11, 2022
8e307c6
:fire: Remove unused import
ivov May 11, 2022
804896d
:fire: Remove logging
ivov May 11, 2022
dc743f8
:zap: Make `somethingElse` key more unique
ivov May 11, 2022
7e961a5
:zap: Move something else to constants
ivov May 11, 2022
638d93d
:zap: Consolidate notice component
ivov May 11, 2022
4ab10d0
:zap: Apply latest feedback
ivov May 11, 2022
f961612
:test_tube: Update tests
ivov May 11, 2022
baa4b08
:test_tube: Update snapshot
ivov May 11, 2022
93bfb7e
:pencil2: Fix singular version
ivov May 11, 2022
4b2ecf8
:test_tube: Finalize tests
ivov May 11, 2022
d6e2895
:pencil2: Rename constant
ivov May 11, 2022
4f3738d
:test_tube: Expand tests
ivov May 11, 2022
1640e9b
:fire: Remove `truncate` prop
ivov May 11, 2022
dac800d
:truck: Move scopes fetching to store
ivov May 12, 2022
9cbcf0b
:truck: Move method to component
ivov May 12, 2022
b445f72
:zap: Use constant
ivov May 12, 2022
6f0ed1c
:zap: Refactor `Notice` component
ivov May 12, 2022
7d7773e
:test_tube: Update tests
ivov May 12, 2022
e475399
:fire: Remove unused keys
ivov May 12, 2022
fc3fc95
:zap: Inject custom API call option
ivov May 12, 2022
4acf25b
:fire: Remove unused props
ivov May 12, 2022
bc58827
:art: Use `compact` prop
ivov May 12, 2022
56fd98b
:test_tube: Update snapshots
ivov May 12, 2022
989ddc1
:truck: Move scopes to store
ivov May 12, 2022
705d6cd
:truck: Move `nodeCredentialTypes` to parent
ivov May 12, 2022
04eff36
:pencil2: Rename cred types per branding
ivov May 12, 2022
9bf01d8
:bug: Clear scopes when none
ivov May 12, 2022
5f0d5b9
:zap: Add default
ivov May 12, 2022
9c7a086
:truck: Move `newHttpRequestNodeCredentialType` to parent
ivov May 12, 2022
f2e901a
:fire: Remove test data
ivov May 13, 2022
43d1ffe
:zap: Separate lines for readability
ivov May 13, 2022
64db4e4
:zap: Change reference from node to node name
ivov May 13, 2022
3d44b18
:pencil2: Rename i18n keys
ivov May 13, 2022
6fa4c9c
:zap: Refactor OAuth check
ivov May 13, 2022
7991e5a
:fire: Remove unused key
ivov May 13, 2022
9a7686f
:truck: Move `OAuth1/2 API` to i18n
ivov May 13, 2022
db8225c
:zap: Refactor `skipCheck`
ivov May 13, 2022
a6d9e26
:zap: Add `stopPropagation` and `preventDefault`
ivov May 13, 2022
7f304a3
:truck: Move active credential scopes logic to store
ivov May 13, 2022
959d57d
:art: Fix spacing for `NodeWebhooks` component
ivov May 13, 2022
4f1c1e9
:zap: Implement feedback
ivov May 16, 2022
6612848
:zap: Update HTTPRN default and issue copy
ivov May 16, 2022
343b148
:twisted_rightwards_arrows: Merge master
ivov May 16, 2022
333506a
:twisted_rightwards_arrows: Merge parent branch
ivov May 19, 2022
2ac022e
Refactor to use `CredentialsSelect` param (#3304)
ivov May 19, 2022
9389a32
Extend metrics for HTTP Request node (#3282)
ivov May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,33 +286,6 @@ export class CredentialsHelper extends ICredentialsHelper {
return combineProperties;
}

/**
* Returns the scope of a credential type
*
* @param {string} type
* @returns {string[]}
* @memberof CredentialsHelper
*/
getScopes(type: string): string[] {
const scopeProperty = this.getCredentialsProperties(type).find(({ name }) => name === 'scope');

if (!scopeProperty?.default || typeof scopeProperty.default !== 'string') {
const errorMessage = `No \`scope\` property found for credential type: ${type}`;

Logger.error(errorMessage);

throw new Error(errorMessage);
}

const { default: scopeDefault } = scopeProperty;

if (/ /.test(scopeDefault)) return scopeDefault.split(' ');

if (/,/.test(scopeDefault)) return scopeDefault.split(',');

return [scopeDefault];
}

/**
* Returns the decrypted credential data with applied overwrites
*
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/LoadNodesAndCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class LoadNodesAndCredentialsClass {
// In case "n8n" package is the root and the packages are
// in the "node_modules" folder underneath it.
path.join(__dirname, '..', '..', 'node_modules', 'n8n-workflow'),
path.join(__dirname, '..', 'node_modules', 'n8n-workflow'), // for test run
];
for (const checkPath of checkPaths) {
try {
Expand Down
62 changes: 57 additions & 5 deletions packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ import { ExecutionEntity } from './databases/entities/ExecutionEntity';
import { SharedWorkflow } from './databases/entities/SharedWorkflow';
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from './constants';
import { credentialsController } from './api/credentials.api';
import { oauth2CredentialController } from './api/oauth2Credential.api';
import {
getInstanceBaseUrl,
isEmailSetUp,
Expand Down Expand Up @@ -1457,7 +1456,7 @@ class App {
if (defaultLocale === 'en') {
return nodeInfos.reduce<INodeTypeDescription[]>((acc, { name, version }) => {
const { description } = NodeTypes().getByNameAndVersion(name, version);
acc.push(description);
acc.push(injectCustomApiCallOption(description));
return acc;
}, []);
}
Expand All @@ -1481,7 +1480,7 @@ class App {
// ignore - no translation exists at path
}

nodeTypes.push(description);
nodeTypes.push(injectCustomApiCallOption(description));
}

const nodeTypes: INodeTypeDescription[] = [];
Expand Down Expand Up @@ -1929,8 +1928,6 @@ class App {
// OAuth2-Credential/Auth
// ----------------------------------------

this.app.use(`/${this.restEndpoint}/oauth2-credential`, oauth2CredentialController);

// Authorize OAuth Data
this.app.get(
`/${this.restEndpoint}/oauth2-credential/auth`,
Expand Down Expand Up @@ -3117,3 +3114,58 @@ async function getExecutionsCount(

return { count, estimated: false };
}

const CUSTOM_API_CALL_NAME = 'Custom API Call';
const CUSTOM_API_CALL_KEY = '__CUSTOM_API_CALL__';

/**
* Inject a `Custom API Call` option into `resource` and `operation`
* parameters in a node that supports proxy auth.
*/
function injectCustomApiCallOption(description: INodeTypeDescription) {
if (!supportsProxyAuth(description)) return description;

description.properties.forEach((p) => {
if (
['resource', 'operation'].includes(p.name) &&
Array.isArray(p.options) &&
p.options[p.options.length - 1].name !== CUSTOM_API_CALL_NAME
) {
p.options.push({
name: CUSTOM_API_CALL_NAME,
value: CUSTOM_API_CALL_KEY,
});
}

return p;
});

return description;
}

const credentialTypes = CredentialTypes();

/**
* Whether any of the node's credential types may be used to
* make a request from a node other than itself.
*/
function supportsProxyAuth(description: INodeTypeDescription) {
if (!description.credentials) return false;

return description.credentials.some(({ name }) => {
const credType = credentialTypes.getByName(name);

if (credType.authenticate !== undefined) return true;

return isOAuth(credType);
});
}

function isOAuth(credType: ICredentialType) {
return (
Array.isArray(credType.extends) &&
credType.extends.some((parentType) =>
['oAuth2Api', 'googleOAuth2Api', 'oAuth1Api'].includes(parentType),
)
);
}
61 changes: 0 additions & 61 deletions packages/cli/src/api/oauth2Credential.api.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { RESPONSE_ERROR_MESSAGES as CORE_RESPONSE_ERROR_MESSAGES } from 'n8n-cor
export const RESPONSE_ERROR_MESSAGES = {
NO_CREDENTIAL: 'Credential not found',
NO_ENCRYPTION_KEY: CORE_RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
NO_CREDENTIAL_TYPE: 'Missing query string param: `credentialType`',
CREDENTIAL_TYPE_NOT_OAUTH2: 'Credential type is not OAuth2 - no scopes can be provided',
};

export const AUTH_COOKIE_NAME = 'n8n-auth';
1 change: 0 additions & 1 deletion packages/cli/src/requests.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export declare namespace OAuthRequest {
namespace OAuth2Credential {
type Auth = OAuth1Credential.Auth;
type Callback = AuthenticatedRequest<{}, {}, {}, { code: string; state: string }>;
type Scopes = AuthenticatedRequest<{}, {}, {}, { credentialType: string }>;
}
}

Expand Down
129 changes: 0 additions & 129 deletions packages/cli/test/integration/oauth2.api.test.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/cli/test/integration/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,3 @@ export const BOOTSTRAP_MYSQL_CONNECTION_NAME: Readonly<string> = 'n8n_bs_mysql';
* Timeout (in milliseconds) to account for fake SMTP service being slow to respond.
*/
export const SMTP_TEST_TIMEOUT = 30_000;

/**
* Timeout (in milliseconds) to account for `LoadNodesAndCredentials()` being slow to run on CI/CD server.
*/
export const LOAD_NODES_AND_CREDS_TEST_TIMEOUT = 30_000;
2 changes: 1 addition & 1 deletion packages/cli/test/integration/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type SmtpTestAccount = {
};
};

type EndpointGroup = 'me' | 'users' | 'auth' | 'owner' | 'passwordReset' | 'credentials' | 'oauth2-credential';
type EndpointGroup = 'me' | 'users' | 'auth' | 'owner' | 'passwordReset' | 'credentials';

export type CredentialPayload = {
name: string;
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/test/integration/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { credentialsController } from '../../../src/api/credentials.api';
import type { User } from '../../../src/databases/entities/User';
import type { EndpointGroup, SmtpTestAccount } from './types';
import type { N8nApp } from '../../../src/UserManagement/Interfaces';
import { oauth2CredentialController } from '../../../src/api/oauth2Credential.api';

/**
* Initialize a test server.
Expand Down Expand Up @@ -64,7 +63,6 @@ export function initTestServer({
if (routerEndpoints.length) {
const map: Record<string, express.Router> = {
credentials: credentialsController,
'oauth2-credential': oauth2CredentialController,
};

for (const group of routerEndpoints) {
Expand Down Expand Up @@ -107,10 +105,7 @@ const classifyEndpointGroups = (endpointGroups: string[]) => {
const functionEndpoints: string[] = [];

endpointGroups.forEach((group) =>
(['credentials', 'oauth2-credential'].includes(group)
? routerEndpoints
: functionEndpoints
).push(group),
(group === 'credentials' ? routerEndpoints : functionEndpoints).push(group),
);

return [routerEndpoints, functionEndpoints];
Expand Down
Loading