first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.bitwarden",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Data & Storage"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/bitwarden/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.bitwarden/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import partialRight from 'lodash/partialRight';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import type { CollectionUpdateFields } from './descriptions/CollectionDescription';
|
||||
import { collectionFields, collectionOperations } from './descriptions/CollectionDescription';
|
||||
import { eventFields, eventOperations } from './descriptions/EventDescription';
|
||||
import type {
|
||||
GroupCreationAdditionalFields,
|
||||
GroupUpdateFields,
|
||||
} from './descriptions/GroupDescription';
|
||||
import { groupFields, groupOperations } from './descriptions/GroupDescription';
|
||||
import type {
|
||||
MemberCreationAdditionalFields,
|
||||
MemberUpdateFields,
|
||||
} from './descriptions/MemberDescription';
|
||||
import { memberFields, memberOperations } from './descriptions/MemberDescription';
|
||||
import {
|
||||
bitwardenApiRequest as tokenlessBitwardenApiRequest,
|
||||
getAccessToken,
|
||||
handleGetAll as tokenlessHandleGetAll,
|
||||
loadResource,
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class Bitwarden implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Bitwarden',
|
||||
name: 'bitwarden',
|
||||
icon: 'file:bitwarden.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the Bitwarden API',
|
||||
defaults: {
|
||||
name: 'Bitwarden',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'bitwardenApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Collection',
|
||||
value: 'collection',
|
||||
},
|
||||
{
|
||||
name: 'Event',
|
||||
value: 'event',
|
||||
},
|
||||
{
|
||||
name: 'Group',
|
||||
value: 'group',
|
||||
},
|
||||
{
|
||||
name: 'Member',
|
||||
value: 'member',
|
||||
},
|
||||
],
|
||||
default: 'collection',
|
||||
},
|
||||
...collectionOperations,
|
||||
...collectionFields,
|
||||
...eventOperations,
|
||||
...eventFields,
|
||||
...groupOperations,
|
||||
...groupFields,
|
||||
...memberOperations,
|
||||
...memberFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getGroups(this: ILoadOptionsFunctions) {
|
||||
return await loadResource.call(this, 'groups');
|
||||
},
|
||||
|
||||
async getCollections(this: ILoadOptionsFunctions) {
|
||||
return await loadResource.call(this, 'collections');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
let responseData;
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
const token = await getAccessToken.call(this);
|
||||
const bitwardenApiRequest = partialRight(tokenlessBitwardenApiRequest, token);
|
||||
const handleGetAll = partialRight(tokenlessHandleGetAll, token);
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (resource === 'collection') {
|
||||
// *********************************************************************
|
||||
// collection
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// collection: delete
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('collectionId', i);
|
||||
const endpoint = `/public/collections/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'DELETE', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// collection: get
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('collectionId', i);
|
||||
const endpoint = `/public/collections/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// collection: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = '/public/collections';
|
||||
responseData = await handleGetAll.call(this, i, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------
|
||||
// collection: update
|
||||
// ----------------------------------
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as CollectionUpdateFields;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const { groups, externalId } = updateFields;
|
||||
|
||||
const body = {} as IDataObject;
|
||||
|
||||
if (groups) {
|
||||
body.groups = groups.map((groupId) => ({
|
||||
id: groupId,
|
||||
ReadOnly: false,
|
||||
}));
|
||||
}
|
||||
|
||||
if (externalId) {
|
||||
body.externalId = externalId;
|
||||
}
|
||||
|
||||
const id = this.getNodeParameter('collectionId', i);
|
||||
const endpoint = `/public/collections/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
} else if (resource === 'event') {
|
||||
// *********************************************************************
|
||||
// event
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// event: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const filters = this.getNodeParameter('filters', i);
|
||||
const qs = isEmpty(filters) ? {} : filters;
|
||||
const endpoint = '/public/events';
|
||||
responseData = await handleGetAll.call(this, i, 'GET', endpoint, qs, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
} else if (resource === 'group') {
|
||||
// *********************************************************************
|
||||
// group
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------
|
||||
// group: create
|
||||
// ----------------------------------
|
||||
|
||||
const body = {
|
||||
name: this.getNodeParameter('name', i),
|
||||
AccessAll: this.getNodeParameter('accessAll', i),
|
||||
} as IDataObject;
|
||||
|
||||
const { collections, externalId } = this.getNodeParameter(
|
||||
'additionalFields',
|
||||
i,
|
||||
) as GroupCreationAdditionalFields;
|
||||
|
||||
if (collections) {
|
||||
body.collections = collections.map((collectionId) => ({
|
||||
id: collectionId,
|
||||
ReadOnly: false,
|
||||
}));
|
||||
}
|
||||
|
||||
if (externalId) {
|
||||
body.externalId = externalId;
|
||||
}
|
||||
|
||||
const endpoint = '/public/groups';
|
||||
responseData = await bitwardenApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// group: delete
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('groupId', i);
|
||||
const endpoint = `/public/groups/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'DELETE', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// group: get
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('groupId', i);
|
||||
const endpoint = `/public/groups/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// group: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = '/public/groups';
|
||||
responseData = await handleGetAll.call(this, i, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'getMembers') {
|
||||
// ----------------------------------
|
||||
// group: getMembers
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('groupId', i);
|
||||
const endpoint = `/public/groups/${id}/member-ids`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData.map((memberId: string) => ({ memberId }));
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------
|
||||
// group: update
|
||||
// ----------------------------------
|
||||
|
||||
const groupId = this.getNodeParameter('groupId', i);
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as GroupUpdateFields;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
// set defaults for `name` and `accessAll`, required by Bitwarden but optional in n8n
|
||||
|
||||
let { name, accessAll } = updateFields;
|
||||
|
||||
if (name === undefined) {
|
||||
responseData = (await bitwardenApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/public/groups/${groupId}`,
|
||||
{},
|
||||
{},
|
||||
)) as { name: string };
|
||||
name = responseData.name;
|
||||
}
|
||||
|
||||
if (accessAll === undefined) {
|
||||
accessAll = false;
|
||||
}
|
||||
|
||||
const body = {
|
||||
name,
|
||||
AccessAll: accessAll,
|
||||
} as IDataObject;
|
||||
|
||||
const { collections, externalId } = updateFields;
|
||||
|
||||
if (collections) {
|
||||
body.collections = collections.map((collectionId) => ({
|
||||
id: collectionId,
|
||||
ReadOnly: false,
|
||||
}));
|
||||
}
|
||||
|
||||
if (externalId) {
|
||||
body.externalId = externalId;
|
||||
}
|
||||
|
||||
const endpoint = `/public/groups/${groupId}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'updateMembers') {
|
||||
// ----------------------------------
|
||||
// group: updateMembers
|
||||
// ----------------------------------
|
||||
|
||||
const memberIds = this.getNodeParameter('memberIds', i) as string;
|
||||
|
||||
const body = {
|
||||
memberIds: memberIds.includes(',') ? memberIds.split(',') : [memberIds],
|
||||
};
|
||||
|
||||
const groupId = this.getNodeParameter('groupId', i);
|
||||
const endpoint = `/public/groups/${groupId}/member-ids`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
} else if (resource === 'member') {
|
||||
// *********************************************************************
|
||||
// member
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------
|
||||
// member: create
|
||||
// ----------------------------------
|
||||
|
||||
const body = {
|
||||
email: this.getNodeParameter('email', i),
|
||||
type: this.getNodeParameter('type', i),
|
||||
AccessAll: this.getNodeParameter('accessAll', i),
|
||||
} as IDataObject;
|
||||
|
||||
const { collections, externalId } = this.getNodeParameter(
|
||||
'additionalFields',
|
||||
i,
|
||||
) as MemberCreationAdditionalFields;
|
||||
|
||||
if (collections) {
|
||||
body.collections = collections.map((collectionId) => ({
|
||||
id: collectionId,
|
||||
ReadOnly: false,
|
||||
}));
|
||||
}
|
||||
|
||||
if (externalId) {
|
||||
body.externalId = externalId;
|
||||
}
|
||||
|
||||
const endpoint = '/public/members/';
|
||||
responseData = await bitwardenApiRequest.call(this, 'POST', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// member: delete
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('memberId', i);
|
||||
const endpoint = `/public/members/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'DELETE', endpoint, {}, {});
|
||||
responseData = { success: true };
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// member: get
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('memberId', i);
|
||||
const endpoint = `/public/members/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// member: getAll
|
||||
// ----------------------------------
|
||||
|
||||
const endpoint = '/public/members';
|
||||
responseData = await handleGetAll.call(this, i, 'GET', endpoint, {}, {});
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'getGroups') {
|
||||
// ----------------------------------
|
||||
// member: getGroups
|
||||
// ----------------------------------
|
||||
|
||||
const id = this.getNodeParameter('memberId', i);
|
||||
const endpoint = `/public/members/${id}/group-ids`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
responseData = responseData.map((groupId: string) => ({ groupId }));
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------
|
||||
// member: update
|
||||
// ----------------------------------
|
||||
|
||||
const body = {} as IDataObject;
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as MemberUpdateFields;
|
||||
|
||||
if (isEmpty(updateFields)) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const { accessAll, collections, externalId, type } = updateFields;
|
||||
|
||||
if (accessAll !== undefined) {
|
||||
body.AccessAll = accessAll;
|
||||
}
|
||||
|
||||
if (collections) {
|
||||
body.collections = collections.map((collectionId) => ({
|
||||
id: collectionId,
|
||||
ReadOnly: false,
|
||||
}));
|
||||
}
|
||||
|
||||
if (externalId) {
|
||||
body.externalId = externalId;
|
||||
}
|
||||
|
||||
if (type !== undefined) {
|
||||
body.Type = type;
|
||||
}
|
||||
|
||||
const id = this.getNodeParameter('memberId', i);
|
||||
const endpoint = `/public/members/${id}`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} else if (operation === 'updateGroups') {
|
||||
// ----------------------------------
|
||||
// member: updateGroups
|
||||
// ----------------------------------
|
||||
|
||||
const groupIds = this.getNodeParameter('groupIds', i) as string;
|
||||
|
||||
const body = {
|
||||
groupIds: groupIds.includes(',') ? groupIds.split(',') : [groupIds],
|
||||
};
|
||||
|
||||
const memberId = this.getNodeParameter('memberId', i);
|
||||
const endpoint = `/public/members/${memberId}/group-ids`;
|
||||
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
INodePropertyOptions,
|
||||
IRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Return the access token URL based on the user's environment.
|
||||
*/
|
||||
async function getTokenUrl(this: IExecuteFunctions | ILoadOptionsFunctions) {
|
||||
const { environment, domain } = await this.getCredentials('bitwardenApi');
|
||||
|
||||
return environment === 'cloudHosted'
|
||||
? 'https://identity.bitwarden.com/connect/token'
|
||||
: `${domain}/identity/connect/token`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base API URL based on the user's environment.
|
||||
*/
|
||||
async function getBaseUrl(this: IExecuteFunctions | ILoadOptionsFunctions) {
|
||||
const { environment, domain } = await this.getCredentials('bitwardenApi');
|
||||
|
||||
return environment === 'cloudHosted' ? 'https://api.bitwarden.com' : `${domain}/api`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an authenticated API request to Bitwarden.
|
||||
*/
|
||||
export async function bitwardenApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
qs: IDataObject,
|
||||
body: IDataObject,
|
||||
token: string,
|
||||
): Promise<any> {
|
||||
const baseUrl = await getBaseUrl.call(this);
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
'user-agent': 'n8n',
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
uri: `${baseUrl}${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (!Object.keys(qs).length) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the access token needed for every API request to Bitwarden.
|
||||
*/
|
||||
export async function getAccessToken(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('bitwardenApi');
|
||||
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
method: 'POST',
|
||||
form: {
|
||||
client_id: credentials.clientId,
|
||||
client_secret: credentials.clientSecret,
|
||||
grant_type: 'client_credentials',
|
||||
scope: 'api.organization',
|
||||
deviceName: 'n8n',
|
||||
deviceType: 2, // https://github.com/bitwarden/server/blob/master/src/Core/Enums/DeviceType.cs
|
||||
deviceIdentifier: 'n8n',
|
||||
},
|
||||
uri: await getTokenUrl.call(this),
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
const { access_token } = await this.helpers.request(options);
|
||||
return access_token;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplement a `getAll` operation with `returnAll` and `limit` parameters.
|
||||
*/
|
||||
export async function handleGetAll(
|
||||
this: IExecuteFunctions,
|
||||
i: number,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
qs: IDataObject,
|
||||
body: IDataObject,
|
||||
token: string,
|
||||
) {
|
||||
const responseData = await bitwardenApiRequest.call(this, method, endpoint, qs, body, token);
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (returnAll) {
|
||||
return responseData.data;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
return responseData.data.slice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a resource so that it can be selected by name from a dropdown.
|
||||
*/
|
||||
export async function loadResource(this: ILoadOptionsFunctions, resource: string) {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const token = await getAccessToken.call(this);
|
||||
const endpoint = `/public/${resource}`;
|
||||
|
||||
const { data } = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {}, token as string);
|
||||
|
||||
data.forEach(({ id, name, externalId }: { id: string; name: string; externalId?: string }) => {
|
||||
returnData.push({
|
||||
name: externalId || name || id,
|
||||
value: id,
|
||||
});
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"collections": {
|
||||
"type": "null"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"object": {
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"type": "null"
|
||||
},
|
||||
"resetPasswordEnrolled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"ssoExternalId": {
|
||||
"type": "null"
|
||||
},
|
||||
"status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"twoFactorEnabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="#fff" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 55 66"><use xlink:href="#a" x=".5" y=".5"/><symbol id="a" overflow="visible"><path fill="#3c8dbc" fill-rule="nonzero" stroke="none" d="M53.333 2.667v32q0 3.582-1.396 7.103c-1.396 3.521-2.084 4.43-3.458 6.25s-3.015 3.59-4.917 5.312-3.66 3.153-5.272 4.292l-5.04 3.23-3.73 2.062-1.77.834q-.5.25-1.083.25a2.4 2.4 0 0 1-1.083-.25l-1.77-.834-3.73-2.062-5.042-3.23q-2.416-1.71-5.27-4.292c-2.854-2.582-3.54-3.492-4.916-5.312s-2.528-3.903-3.46-6.25S0 37.055 0 34.667v-32A2.56 2.56 0 0 1 .791.792 2.56 2.56 0 0 1 2.666 0h48q1.081 0 1.874.792a2.56 2.56 0 0 1 .792 1.875m-8 32V8H26.666v47.375q4.958-2.625 8.875-5.708 9.79-7.665 9.79-15"/></symbol></svg>
|
||||
|
After Width: | Height: | Size: 830 B |
@@ -0,0 +1,136 @@
|
||||
import type { IDataObject, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const collectionOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete a collection',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get a collection',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many collections',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update a collection',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const collectionFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// collection: shared
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Collection ID',
|
||||
name: 'collectionId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The identifier of the collection',
|
||||
default: '',
|
||||
placeholder: '5e59c8c7-e05a-4d17-8e85-acc301343926',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['delete', 'get', 'update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// collection: getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 10,
|
||||
description: 'Max number of results to return',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// collection: update
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
displayName: 'Group Names or IDs',
|
||||
name: 'groups',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'The group to assign this collection to. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
description: 'The external identifier to set to this collection',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export type CollectionUpdateFields = IDataObject & {
|
||||
groups: string[];
|
||||
externalId: string;
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const eventOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many events',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const eventFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// event: getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 10,
|
||||
description: 'Max number of results to return',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Filters',
|
||||
name: 'filters',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Filter',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Acting User ID',
|
||||
name: 'actingUserId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The unique identifier of the acting user',
|
||||
placeholder: '4a59c8c7-e05a-4d17-8e85-acc301343926',
|
||||
},
|
||||
{
|
||||
displayName: 'End Date',
|
||||
name: 'end',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'The end date for the search',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemID',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The unique identifier of the item that the event describes',
|
||||
placeholder: '5e59c8c7-e05a-4d17-8e85-acc301343926',
|
||||
},
|
||||
{
|
||||
displayName: 'Start Date',
|
||||
name: 'start',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'The start date for the search',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['event'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,253 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const groupOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create a group',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete a group',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get a group',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many groups',
|
||||
},
|
||||
{
|
||||
name: 'Get Members',
|
||||
value: 'getMembers',
|
||||
action: 'Get group members',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update a group',
|
||||
},
|
||||
{
|
||||
name: 'Update Members',
|
||||
value: 'updateMembers',
|
||||
action: 'Update group members',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const groupFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// group: shared
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Group ID',
|
||||
name: 'groupId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The identifier of the group',
|
||||
default: '',
|
||||
placeholder: '5e59c8c7-e05a-4d17-8e85-acc301343926',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['delete', 'get', 'getMembers', 'update', 'updateMembers'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// group: getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 10,
|
||||
description: 'Max number of results to return',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// group: create
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'The name of the group to create',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Access All',
|
||||
name: 'accessAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to allow this group to access all collections within the organization, instead of only its associated collections. If set to true, this option overrides any collection assignments.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Collection Names or IDs',
|
||||
name: 'collections',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'The collections to assign to this group. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
description: 'The external identifier to set to this group',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// group: update
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Access All',
|
||||
name: 'accessAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to allow this group to access all collections within the organization, instead of only its associated collections. If set to true, this option overrides any collection assignments.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Names or IDs',
|
||||
name: 'collections',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'The collections to assign to this group. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
description: 'The external identifier to set to this group',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The name of the group to update',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// group: updateMembers
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Member IDs',
|
||||
name: 'memberIds',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Comma-separated list of IDs of members to set in a group',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['updateMembers'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
type GroupSchema = {
|
||||
name: string;
|
||||
collections: string[];
|
||||
accessAll: boolean;
|
||||
externalId: string;
|
||||
};
|
||||
|
||||
export type GroupUpdateFields = GroupSchema;
|
||||
|
||||
export type GroupCreationAdditionalFields = Omit<GroupSchema, 'name'>;
|
||||
@@ -0,0 +1,294 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const memberOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create a member',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete a member',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get a member',
|
||||
},
|
||||
{
|
||||
name: 'Get Groups',
|
||||
value: 'getGroups',
|
||||
action: 'Get groups for a member',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many members',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update a member',
|
||||
},
|
||||
{
|
||||
name: 'Update Groups',
|
||||
value: 'updateGroups',
|
||||
action: 'Update groups for a member',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const memberFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// member: shared
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Member ID',
|
||||
name: 'memberId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The identifier of the member',
|
||||
default: '',
|
||||
placeholder: '5e59c8c7-e05a-4d17-8e85-acc301343926',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['delete', 'get', 'getGroups', 'update', 'updateGroups'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
default: 2,
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Owner',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
name: 'Admin',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: 'Manager',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
// ----------------------------------
|
||||
// member: getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 10,
|
||||
description: 'Max number of results to return',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
// ----------------------------------
|
||||
// member: create
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
placeholder: 'name@email.com',
|
||||
default: '',
|
||||
description: 'The email of the member to update',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Access All',
|
||||
name: 'accessAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Collection Names or IDs',
|
||||
name: 'collections',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'The collections to assign to this member. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
description: 'The external identifier to set to this member',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
// ----------------------------------
|
||||
// member: update
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'Owner',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
name: 'Admin',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: 'Manager',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Names or IDs',
|
||||
name: 'collections',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'The collections to assign to this member. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
description: 'The external identifier to set to this member',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Access All',
|
||||
name: 'accessAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
// ----------------------------------
|
||||
// member: updateGroups
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Group IDs',
|
||||
name: 'groupIds',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Comma-separated list of IDs of groups to set for a member',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['member'],
|
||||
operation: ['updateGroups'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
type MemberSchema = {
|
||||
email: string;
|
||||
collections: string[];
|
||||
type: number;
|
||||
accessAll: boolean;
|
||||
externalId: string;
|
||||
};
|
||||
|
||||
export type MemberUpdateFields = Omit<MemberSchema, 'email'>;
|
||||
|
||||
export type MemberCreationAdditionalFields = Omit<MemberSchema, 'email'>;
|
||||
Reference in New Issue
Block a user