Add Activepieces integration for workflow automation
- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { createPiece, PieceAuth, Property } from '@activepieces/pieces-framework';
|
||||
import { createCouchbaseClient, closeCluster, CouchbaseAuthValue } from './lib/common';
|
||||
import actions from './lib/actions';
|
||||
|
||||
export const couchbaseAuth = PieceAuth.CustomAuth({
|
||||
description: 'Connect to your Couchbase cluster',
|
||||
required: true,
|
||||
props: {
|
||||
connectionString: Property.ShortText({
|
||||
displayName: 'Connection String',
|
||||
description: 'Couchbase connection string (e.g., couchbase://localhost or couchbases://cloud.couchbase.com)',
|
||||
required: true,
|
||||
}),
|
||||
username: Property.ShortText({
|
||||
displayName: 'Username',
|
||||
description: 'Username for authentication',
|
||||
required: true,
|
||||
}),
|
||||
password: PieceAuth.SecretText({
|
||||
displayName: 'Password',
|
||||
description: 'Password for authentication',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
validate: async ({ auth }) => {
|
||||
const authValue = auth as CouchbaseAuthValue;
|
||||
|
||||
if (!authValue.connectionString) {
|
||||
return { valid: false, error: 'Connection string is required' };
|
||||
}
|
||||
if (!authValue.username) {
|
||||
return { valid: false, error: 'Username is required' };
|
||||
}
|
||||
if (!authValue.password) {
|
||||
return { valid: false, error: 'Password is required' };
|
||||
}
|
||||
|
||||
try {
|
||||
const cluster = await createCouchbaseClient(authValue);
|
||||
await cluster.ping();
|
||||
await closeCluster(cluster);
|
||||
return { valid: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Connection failed: ${(error as Error).message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const couchbasePiece = createPiece({
|
||||
displayName: 'Couchbase',
|
||||
description: 'NoSQL document database for modern applications',
|
||||
auth: couchbaseAuth,
|
||||
minimumSupportedRelease: '0.36.1',
|
||||
logoUrl: 'https://cdn.activepieces.com/pieces/couchbase.png',
|
||||
authors: ['chedim', 'onyedikachi-david'],
|
||||
actions,
|
||||
triggers: [],
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import insertDocument from './actions/insert-document';
|
||||
import upsertDocument from './actions/upsert-document';
|
||||
import getDocument from './actions/get-document';
|
||||
import deleteDocument from './actions/delete-document';
|
||||
import query from './actions/query';
|
||||
|
||||
export default [
|
||||
insertDocument,
|
||||
upsertDocument,
|
||||
getDocument,
|
||||
deleteDocument,
|
||||
query,
|
||||
];
|
||||
@@ -0,0 +1,64 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
couchbaseCommonProps,
|
||||
createCouchbaseClient,
|
||||
getCollection,
|
||||
closeCluster,
|
||||
formatMutationResult,
|
||||
CouchbaseAuthValue,
|
||||
} from '../common';
|
||||
import { RemoveOptions, DurabilityLevel } from 'couchbase';
|
||||
|
||||
export default createAction({
|
||||
auth: couchbaseAuth,
|
||||
name: 'delete_document',
|
||||
displayName: 'Delete Document',
|
||||
description: 'Remove a document by its ID',
|
||||
props: {
|
||||
bucket: couchbaseCommonProps.bucket,
|
||||
scope: couchbaseCommonProps.scope,
|
||||
collection: couchbaseCommonProps.collection,
|
||||
documentId: couchbaseCommonProps.documentIdDropdown,
|
||||
durabilityLevel: couchbaseCommonProps.durabilityLevel,
|
||||
timeout: couchbaseCommonProps.timeout,
|
||||
},
|
||||
async run(context) {
|
||||
const auth = (context.auth as { props: CouchbaseAuthValue }).props;
|
||||
const { bucket, scope, collection, documentId, durabilityLevel, timeout } = context.propsValue;
|
||||
|
||||
if (!bucket) {
|
||||
throw new Error('Bucket is required');
|
||||
}
|
||||
|
||||
if (!documentId) {
|
||||
throw new Error('Document ID is required');
|
||||
}
|
||||
|
||||
const cluster = await createCouchbaseClient(auth);
|
||||
|
||||
try {
|
||||
const coll = getCollection(
|
||||
cluster,
|
||||
bucket,
|
||||
scope || undefined,
|
||||
collection || undefined
|
||||
);
|
||||
|
||||
const options: RemoveOptions = {};
|
||||
|
||||
if (durabilityLevel !== undefined && durabilityLevel !== null) {
|
||||
options.durabilityLevel = durabilityLevel as DurabilityLevel;
|
||||
}
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
options.timeout = timeout;
|
||||
}
|
||||
|
||||
const result = await coll.remove(documentId, options);
|
||||
return formatMutationResult(result, documentId);
|
||||
} finally {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
couchbaseCommonProps,
|
||||
createCouchbaseClient,
|
||||
getCollection,
|
||||
closeCluster,
|
||||
formatGetResult,
|
||||
CouchbaseAuthValue,
|
||||
} from '../common';
|
||||
import { GetOptions } from 'couchbase';
|
||||
|
||||
export default createAction({
|
||||
auth: couchbaseAuth,
|
||||
name: 'get_document',
|
||||
displayName: 'Get Document',
|
||||
description: 'Retrieve a document by its ID',
|
||||
props: {
|
||||
bucket: couchbaseCommonProps.bucket,
|
||||
scope: couchbaseCommonProps.scope,
|
||||
collection: couchbaseCommonProps.collection,
|
||||
documentId: couchbaseCommonProps.documentIdDropdown,
|
||||
timeout: couchbaseCommonProps.timeout,
|
||||
},
|
||||
async run(context) {
|
||||
const auth = (context.auth as { props: CouchbaseAuthValue }).props;
|
||||
const { bucket, scope, collection, documentId, timeout } = context.propsValue;
|
||||
|
||||
if (!bucket) {
|
||||
throw new Error('Bucket is required');
|
||||
}
|
||||
|
||||
if (!documentId) {
|
||||
throw new Error('Document ID is required');
|
||||
}
|
||||
|
||||
const cluster = await createCouchbaseClient(auth);
|
||||
|
||||
try {
|
||||
const coll = getCollection(
|
||||
cluster,
|
||||
bucket,
|
||||
scope || undefined,
|
||||
collection || undefined
|
||||
);
|
||||
|
||||
const options: GetOptions = {};
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
options.timeout = timeout;
|
||||
}
|
||||
|
||||
const result = await coll.get(documentId, options);
|
||||
return formatGetResult(result, documentId);
|
||||
} finally {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
couchbaseCommonProps,
|
||||
createCouchbaseClient,
|
||||
getCollection,
|
||||
closeCluster,
|
||||
formatMutationResult,
|
||||
CouchbaseAuthValue,
|
||||
} from '../common';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { InsertOptions, DurabilityLevel } from 'couchbase';
|
||||
|
||||
export default createAction({
|
||||
auth: couchbaseAuth,
|
||||
name: 'insert_document',
|
||||
displayName: 'Insert Document',
|
||||
description: 'Create a new document. Fails if document already exists.',
|
||||
props: {
|
||||
bucket: couchbaseCommonProps.bucket,
|
||||
scope: couchbaseCommonProps.scope,
|
||||
collection: couchbaseCommonProps.collection,
|
||||
documentId: couchbaseCommonProps.documentIdOptional,
|
||||
document: couchbaseCommonProps.document,
|
||||
expiry: couchbaseCommonProps.expiry,
|
||||
durabilityLevel: couchbaseCommonProps.durabilityLevel,
|
||||
timeout: couchbaseCommonProps.timeout,
|
||||
},
|
||||
async run(context) {
|
||||
const auth = (context.auth as { props: CouchbaseAuthValue }).props;
|
||||
const { bucket, scope, collection, documentId, document, expiry, durabilityLevel, timeout } = context.propsValue;
|
||||
|
||||
if (!bucket) {
|
||||
throw new Error('Bucket is required');
|
||||
}
|
||||
|
||||
if (!document) {
|
||||
throw new Error('Document is required');
|
||||
}
|
||||
|
||||
const docId = documentId || randomUUID();
|
||||
const cluster = await createCouchbaseClient(auth);
|
||||
|
||||
try {
|
||||
const coll = getCollection(
|
||||
cluster,
|
||||
bucket,
|
||||
scope || undefined,
|
||||
collection || undefined
|
||||
);
|
||||
|
||||
const options: InsertOptions = {};
|
||||
|
||||
if (expiry && expiry > 0) {
|
||||
options.expiry = expiry;
|
||||
}
|
||||
|
||||
if (durabilityLevel !== undefined && durabilityLevel !== null) {
|
||||
options.durabilityLevel = durabilityLevel as DurabilityLevel;
|
||||
}
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
options.timeout = timeout;
|
||||
}
|
||||
|
||||
const result = await coll.insert(docId, document, options);
|
||||
return formatMutationResult(result, docId);
|
||||
} finally {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
couchbaseCommonProps,
|
||||
createCouchbaseClient,
|
||||
closeCluster,
|
||||
CouchbaseAuthValue,
|
||||
LooseObject,
|
||||
} from '../common';
|
||||
import { QueryOptions, QueryScanConsistency } from 'couchbase';
|
||||
|
||||
export default createAction({
|
||||
auth: couchbaseAuth,
|
||||
name: 'query',
|
||||
displayName: 'Execute SQL++ Query',
|
||||
description: 'Run a SQL++ (N1QL) query with optional vector search filters',
|
||||
props: {
|
||||
bucket: couchbaseCommonProps.bucket,
|
||||
scope: couchbaseCommonProps.scope,
|
||||
query: couchbaseCommonProps.query,
|
||||
arguments: couchbaseCommonProps.arguments,
|
||||
vectorFilters: couchbaseCommonProps.vectorFilters,
|
||||
vectorOrder: couchbaseCommonProps.vectorOrder,
|
||||
limit: couchbaseCommonProps.limit,
|
||||
offset: couchbaseCommonProps.offset,
|
||||
scanConsistency: Property.StaticDropdown({
|
||||
displayName: 'Scan Consistency',
|
||||
description: 'Query consistency level',
|
||||
required: false,
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Not Bounded (Fastest)', value: QueryScanConsistency.NotBounded },
|
||||
{ label: 'Request Plus (Consistent)', value: QueryScanConsistency.RequestPlus },
|
||||
],
|
||||
},
|
||||
}),
|
||||
timeout: couchbaseCommonProps.timeout,
|
||||
},
|
||||
async run(context) {
|
||||
const auth = (context.auth as { props: CouchbaseAuthValue }).props;
|
||||
const {
|
||||
bucket,
|
||||
scope,
|
||||
query,
|
||||
arguments: queryArgs,
|
||||
vectorFilters,
|
||||
vectorOrder,
|
||||
limit,
|
||||
offset,
|
||||
scanConsistency,
|
||||
timeout,
|
||||
} = context.propsValue;
|
||||
|
||||
if (!query) {
|
||||
throw new Error('Query is required');
|
||||
}
|
||||
|
||||
const limitValue = Math.round(limit || 0);
|
||||
const offsetValue = Math.round(offset || 0);
|
||||
|
||||
let userQuery = query;
|
||||
const userQueryUpperCase = userQuery.toUpperCase();
|
||||
const args: string[] = [...((queryArgs as string[]) || [])];
|
||||
|
||||
if (userQueryUpperCase.includes('LIMIT') || userQueryUpperCase.includes('OFFSET')) {
|
||||
throw new Error('Do not include LIMIT or OFFSET in the query. Use the Limit and Offset fields instead.');
|
||||
}
|
||||
|
||||
const whereClauseParts: string[] = [];
|
||||
const orderClauseParts: string[] = [];
|
||||
|
||||
if (vectorFilters && Array.isArray(vectorFilters)) {
|
||||
for (const elem of vectorFilters) {
|
||||
const filter = elem as LooseObject;
|
||||
const funcName = filter['preciseDistance'] ? 'VECTOR_DISTANCE' : 'APPROX_VECTOR_DISTANCE';
|
||||
whereClauseParts.push(
|
||||
`${funcName}(${filter['vectorExpr']}, ${filter['targetVector']}, "${filter['vectorSimilarity']}") < ?`
|
||||
);
|
||||
args.push(String(filter['maxDistance']));
|
||||
}
|
||||
}
|
||||
|
||||
if (vectorOrder && Array.isArray(vectorOrder)) {
|
||||
for (const elem of vectorOrder) {
|
||||
const order = elem as LooseObject;
|
||||
const funcName = order['preciseDistance'] ? 'VECTOR_DISTANCE' : 'APPROX_VECTOR_DISTANCE';
|
||||
orderClauseParts.push(
|
||||
`${funcName}(${order['vectorExpr']}, ${order['targetVector']}, "${order['vectorSimilarity']}")`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (whereClauseParts.length > 0) {
|
||||
const whereClause = whereClauseParts.join(' AND ');
|
||||
const orderByIndex = userQueryUpperCase.indexOf('ORDER BY');
|
||||
|
||||
if (userQueryUpperCase.includes('WHERE')) {
|
||||
userQuery = userQuery.replace(/WHERE/i, `WHERE ${whereClause} AND `);
|
||||
} else if (orderByIndex > -1) {
|
||||
userQuery = userQuery.slice(0, orderByIndex) + `WHERE ${whereClause} ` + userQuery.slice(orderByIndex);
|
||||
} else {
|
||||
userQuery += ` WHERE ${whereClause}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (orderClauseParts.length > 0) {
|
||||
const orderClause = orderClauseParts.join(', ');
|
||||
if (userQueryUpperCase.indexOf('ORDER BY') > -1) {
|
||||
userQuery += `, ${orderClause}`;
|
||||
} else {
|
||||
userQuery += ` ORDER BY ${orderClause}`;
|
||||
}
|
||||
}
|
||||
|
||||
let finalQuery = `SELECT RAW data FROM (${userQuery}) data`;
|
||||
|
||||
if (limitValue > 0) {
|
||||
finalQuery += ` LIMIT ${limitValue}`;
|
||||
}
|
||||
|
||||
if (offsetValue > 0) {
|
||||
finalQuery += ` OFFSET ${offsetValue}`;
|
||||
}
|
||||
|
||||
const cluster = await createCouchbaseClient(auth);
|
||||
|
||||
try {
|
||||
const options: QueryOptions = {};
|
||||
|
||||
if (args.length > 0) {
|
||||
options.parameters = args;
|
||||
}
|
||||
|
||||
if (scanConsistency !== undefined && scanConsistency !== null) {
|
||||
options.scanConsistency = scanConsistency as QueryScanConsistency;
|
||||
}
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
options.timeout = timeout;
|
||||
}
|
||||
|
||||
let result;
|
||||
|
||||
if (bucket && scope) {
|
||||
const bucketObj = cluster.bucket(bucket);
|
||||
const scopeObj = bucketObj.scope(scope);
|
||||
result = await scopeObj.query(finalQuery, options);
|
||||
} else {
|
||||
result = await cluster.query(finalQuery, options);
|
||||
}
|
||||
|
||||
return {
|
||||
rows: result.rows,
|
||||
meta: {
|
||||
requestId: result.meta.requestId,
|
||||
status: result.meta.status,
|
||||
metrics: result.meta.metrics,
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
couchbaseCommonProps,
|
||||
createCouchbaseClient,
|
||||
getCollection,
|
||||
closeCluster,
|
||||
formatMutationResult,
|
||||
CouchbaseAuthValue,
|
||||
} from '../common';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { UpsertOptions, DurabilityLevel } from 'couchbase';
|
||||
|
||||
export default createAction({
|
||||
auth: couchbaseAuth,
|
||||
name: 'upsert_document',
|
||||
displayName: 'Upsert Document',
|
||||
description: 'Create or update a document. Creates if it doesn\'t exist, updates if it does.',
|
||||
props: {
|
||||
bucket: couchbaseCommonProps.bucket,
|
||||
scope: couchbaseCommonProps.scope,
|
||||
collection: couchbaseCommonProps.collection,
|
||||
documentId: couchbaseCommonProps.documentIdOptional,
|
||||
document: couchbaseCommonProps.document,
|
||||
expiry: couchbaseCommonProps.expiry,
|
||||
durabilityLevel: couchbaseCommonProps.durabilityLevel,
|
||||
timeout: couchbaseCommonProps.timeout,
|
||||
},
|
||||
async run(context) {
|
||||
const auth = (context.auth as { props: CouchbaseAuthValue }).props;
|
||||
const { bucket, scope, collection, documentId, document, expiry, durabilityLevel, timeout } = context.propsValue;
|
||||
|
||||
if (!bucket) {
|
||||
throw new Error('Bucket is required');
|
||||
}
|
||||
|
||||
if (!document) {
|
||||
throw new Error('Document is required');
|
||||
}
|
||||
|
||||
const docId = documentId || randomUUID();
|
||||
const cluster = await createCouchbaseClient(auth);
|
||||
|
||||
try {
|
||||
const coll = getCollection(
|
||||
cluster,
|
||||
bucket,
|
||||
scope || undefined,
|
||||
collection || undefined
|
||||
);
|
||||
|
||||
const options: UpsertOptions = {};
|
||||
|
||||
if (expiry && expiry > 0) {
|
||||
options.expiry = expiry;
|
||||
}
|
||||
|
||||
if (durabilityLevel !== undefined && durabilityLevel !== null) {
|
||||
options.durabilityLevel = durabilityLevel as DurabilityLevel;
|
||||
}
|
||||
|
||||
if (timeout && timeout > 0) {
|
||||
options.timeout = timeout;
|
||||
}
|
||||
|
||||
const result = await coll.upsert(docId, document, options);
|
||||
return formatMutationResult(result, docId);
|
||||
} finally {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,471 @@
|
||||
import { Property } from '@activepieces/pieces-framework';
|
||||
import { couchbaseAuth } from '../..';
|
||||
import {
|
||||
Cluster,
|
||||
Collection,
|
||||
connect,
|
||||
Bucket,
|
||||
Scope,
|
||||
DurabilityLevel,
|
||||
GetResult,
|
||||
MutationResult,
|
||||
} from 'couchbase';
|
||||
|
||||
|
||||
export interface CouchbaseAuthValue {
|
||||
connectionString: string;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
|
||||
export interface LooseObject {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
|
||||
export async function createCouchbaseClient(
|
||||
auth: CouchbaseAuthValue
|
||||
): Promise<Cluster> {
|
||||
const isCloudConnection = auth.connectionString.includes('cloud.couchbase.com');
|
||||
|
||||
return await connect(auth.connectionString, {
|
||||
username: auth.username,
|
||||
password: auth.password,
|
||||
configProfile: isCloudConnection ? 'wanDevelopment' : undefined,
|
||||
timeouts: {
|
||||
connectTimeout: 30000,
|
||||
kvTimeout: 15000,
|
||||
managementTimeout: 60000,
|
||||
bootstrapTimeout: 30000,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getCollection(
|
||||
cluster: Cluster,
|
||||
bucketName: string,
|
||||
scopeName?: string,
|
||||
collectionName?: string
|
||||
): Collection {
|
||||
const bucket: Bucket = cluster.bucket(bucketName);
|
||||
const scope: Scope = scopeName ? bucket.scope(scopeName) : bucket.defaultScope();
|
||||
return collectionName ? scope.collection(collectionName) : scope.collection('_default');
|
||||
}
|
||||
|
||||
|
||||
export async function closeCluster(cluster: Cluster): Promise<void> {
|
||||
try {
|
||||
await cluster.close();
|
||||
} catch {
|
||||
// Ignore close errors
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function formatMutationResult(
|
||||
result: MutationResult,
|
||||
documentId: string
|
||||
): { id: string; cas: string; success: boolean } {
|
||||
return {
|
||||
id: documentId,
|
||||
cas: result.cas.toString(),
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function formatGetResult(
|
||||
result: GetResult,
|
||||
documentId: string
|
||||
): { id: string; content: unknown; cas: string } {
|
||||
return {
|
||||
id: documentId,
|
||||
content: result.content,
|
||||
cas: result.cas.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export const bucketDropdown = Property.Dropdown({
|
||||
displayName: 'Bucket',
|
||||
description: 'Select the bucket',
|
||||
required: true,
|
||||
refreshers: ['auth'],
|
||||
auth: couchbaseAuth,
|
||||
options: async ({ auth }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: 'Connect to Couchbase first',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
const authValue = (auth as { props: CouchbaseAuthValue }).props;
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
try {
|
||||
cluster = await createCouchbaseClient(authValue);
|
||||
const bucketManager = cluster.buckets();
|
||||
const buckets = await bucketManager.getAllBuckets();
|
||||
|
||||
if (!buckets || buckets.length === 0) {
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: 'No buckets found in cluster',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options: buckets.map((bucket) => ({
|
||||
label: bucket.name,
|
||||
value: bucket.name,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: `Failed to load buckets: ${errorMessage}`,
|
||||
options: [],
|
||||
};
|
||||
} finally {
|
||||
if (cluster) {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const scopeDropdown = Property.Dropdown({
|
||||
displayName: 'Scope',
|
||||
description: 'Select the scope (leave empty for default)',
|
||||
required: false,
|
||||
refreshers: ['auth', 'bucket'],
|
||||
auth: couchbaseAuth,
|
||||
options: async ({ auth, bucket }) => {
|
||||
if (!auth || !bucket) {
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: 'Select a bucket first',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
const authValue = (auth as { props: CouchbaseAuthValue }).props;
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
try {
|
||||
cluster = await createCouchbaseClient(authValue);
|
||||
const bucketObj = cluster.bucket(bucket as string);
|
||||
const collectionManager = bucketObj.collections();
|
||||
const scopes = await collectionManager.getAllScopes();
|
||||
|
||||
if (!scopes || scopes.length === 0) {
|
||||
return {
|
||||
disabled: false,
|
||||
options: [{ label: '_default (Default)', value: '_default' }],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options: scopes.map((scope) => ({
|
||||
label: scope.name === '_default' ? '_default (Default)' : scope.name,
|
||||
value: scope.name,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: `Failed to load scopes: ${errorMessage}`,
|
||||
options: [],
|
||||
};
|
||||
} finally {
|
||||
if (cluster) {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const collectionDropdown = Property.Dropdown({
|
||||
displayName: 'Collection',
|
||||
description: 'Select the collection (leave empty for default)',
|
||||
required: false,
|
||||
refreshers: ['auth', 'bucket', 'scope'],
|
||||
auth: couchbaseAuth,
|
||||
options: async ({ auth, bucket, scope }) => {
|
||||
if (!auth || !bucket) {
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: 'Select a bucket first',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
const authValue = (auth as { props: CouchbaseAuthValue }).props;
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
try {
|
||||
cluster = await createCouchbaseClient(authValue);
|
||||
const bucketObj = cluster.bucket(bucket as string);
|
||||
const collectionManager = bucketObj.collections();
|
||||
const scopes = await collectionManager.getAllScopes();
|
||||
|
||||
const selectedScope = scopes?.find(
|
||||
(s) => s.name === (scope || '_default')
|
||||
);
|
||||
|
||||
if (!selectedScope || !selectedScope.collections) {
|
||||
return {
|
||||
disabled: false,
|
||||
options: [{ label: '_default (Default)', value: '_default' }],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options: selectedScope.collections.map((coll) => ({
|
||||
label: coll.name === '_default' ? '_default (Default)' : coll.name,
|
||||
value: coll.name,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: `Failed to load collections: ${errorMessage}`,
|
||||
options: [],
|
||||
};
|
||||
} finally {
|
||||
if (cluster) {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const documentIdDropdown = Property.Dropdown({
|
||||
displayName: 'Document ID',
|
||||
description: 'Select an existing document or type a custom ID',
|
||||
required: true,
|
||||
refreshers: ['auth', 'bucket', 'scope', 'collection'],
|
||||
auth: couchbaseAuth,
|
||||
options: async ({ auth, bucket, scope, collection }) => {
|
||||
if (!auth || !bucket) {
|
||||
return {
|
||||
disabled: true,
|
||||
placeholder: 'Select a bucket first',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
const authValue = (auth as { props: CouchbaseAuthValue }).props;
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
try {
|
||||
cluster = await createCouchbaseClient(authValue);
|
||||
|
||||
const scopeName = (scope as string) || '_default';
|
||||
const collectionName = (collection as string) || '_default';
|
||||
const keyspace = `\`${bucket}\`.\`${scopeName}\`.\`${collectionName}\``;
|
||||
|
||||
const query = `SELECT META().id AS docId FROM ${keyspace} LIMIT 100`;
|
||||
const result = await cluster.query(query);
|
||||
|
||||
if (!result.rows || result.rows.length === 0) {
|
||||
return {
|
||||
disabled: false,
|
||||
placeholder: 'No documents found - type a document ID',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options: result.rows.map((row: { docId: string }) => ({
|
||||
label: row.docId,
|
||||
value: row.docId,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
disabled: false,
|
||||
placeholder: `Could not load documents: ${errorMessage}`,
|
||||
options: [],
|
||||
};
|
||||
} finally {
|
||||
if (cluster) {
|
||||
await closeCluster(cluster);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const durabilityLevelDropdown = Property.StaticDropdown({
|
||||
displayName: 'Durability Level',
|
||||
description: 'How durable the write should be before returning success',
|
||||
required: false,
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'None (Fastest)', value: DurabilityLevel.None },
|
||||
{ label: 'Majority', value: DurabilityLevel.Majority },
|
||||
{ label: 'Majority and Persist on Master', value: DurabilityLevel.MajorityAndPersistOnMaster },
|
||||
{ label: 'Persist to Majority (Safest)', value: DurabilityLevel.PersistToMajority },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export const couchbaseCommonProps = {
|
||||
bucket: bucketDropdown,
|
||||
scope: scopeDropdown,
|
||||
collection: collectionDropdown,
|
||||
|
||||
documentIdDropdown: documentIdDropdown,
|
||||
|
||||
documentId: Property.ShortText({
|
||||
displayName: 'Document ID',
|
||||
description: 'Unique identifier for the document',
|
||||
required: true,
|
||||
}),
|
||||
|
||||
documentIdOptional: Property.ShortText({
|
||||
displayName: 'Document ID',
|
||||
description: 'Unique identifier for the document. Leave empty to auto-generate.',
|
||||
required: false,
|
||||
}),
|
||||
|
||||
document: Property.Json({
|
||||
displayName: 'Document',
|
||||
description: 'The JSON document to store',
|
||||
required: true,
|
||||
}),
|
||||
|
||||
expiry: Property.Number({
|
||||
displayName: 'Expiry (seconds)',
|
||||
description: 'Document expiration time in seconds. Leave empty for no expiry.',
|
||||
required: false,
|
||||
}),
|
||||
|
||||
durabilityLevel: durabilityLevelDropdown,
|
||||
|
||||
timeout: Property.Number({
|
||||
displayName: 'Timeout (ms)',
|
||||
description: 'Operation timeout in milliseconds',
|
||||
required: false,
|
||||
defaultValue: 10000,
|
||||
}),
|
||||
|
||||
query: Property.LongText({
|
||||
displayName: 'SQL++ Query',
|
||||
description: 'SELECT statement with optional positional parameters ($1, $2, etc.). Do not include LIMIT or OFFSET.',
|
||||
required: true,
|
||||
}),
|
||||
|
||||
arguments: Property.Array({
|
||||
displayName: 'Query Arguments',
|
||||
description: 'Values for positional parameters ($1, $2, etc.) in the query',
|
||||
required: false,
|
||||
}),
|
||||
|
||||
limit: Property.Number({
|
||||
displayName: 'Limit',
|
||||
description: 'Maximum number of results to return',
|
||||
required: false,
|
||||
}),
|
||||
|
||||
offset: Property.Number({
|
||||
displayName: 'Offset',
|
||||
description: 'Number of results to skip',
|
||||
required: false,
|
||||
}),
|
||||
|
||||
vectorFilters: Property.Array({
|
||||
displayName: 'Vector Filters',
|
||||
description: 'Filter results by vector similarity (requires vector index)',
|
||||
required: false,
|
||||
properties: {
|
||||
vectorExpr: Property.ShortText({
|
||||
displayName: 'Vector Expression',
|
||||
description: 'Field path returning a vector (e.g., data.embedding)',
|
||||
required: true,
|
||||
}),
|
||||
targetVector: Property.LongText({
|
||||
displayName: 'Target Vector',
|
||||
description: 'Array of numbers to compare against (e.g., [0.1, 0.2, ...])',
|
||||
required: true,
|
||||
}),
|
||||
vectorSimilarity: Property.StaticDropdown({
|
||||
displayName: 'Similarity Metric',
|
||||
required: true,
|
||||
defaultValue: 'L2_SQUARED',
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Cosine', value: 'COSINE' },
|
||||
{ label: 'Dot Product', value: 'DOT' },
|
||||
{ label: 'Euclidean (L2)', value: 'L2' },
|
||||
{ label: 'Squared Euclidean', value: 'L2_SQUARED' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
maxDistance: Property.Number({
|
||||
displayName: 'Max Distance',
|
||||
description: 'Maximum distance threshold',
|
||||
required: true,
|
||||
}),
|
||||
preciseDistance: Property.Checkbox({
|
||||
displayName: 'Use Precise Distance',
|
||||
description: 'Use VECTOR_DISTANCE instead of APPROX_VECTOR_DISTANCE (slower but more accurate)',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
}),
|
||||
|
||||
vectorOrder: Property.Array({
|
||||
displayName: 'Vector Ordering',
|
||||
description: 'Order results by vector similarity (requires vector index)',
|
||||
required: false,
|
||||
properties: {
|
||||
vectorExpr: Property.ShortText({
|
||||
displayName: 'Vector Expression',
|
||||
description: 'Field path returning a vector (e.g., data.embedding)',
|
||||
required: true,
|
||||
}),
|
||||
targetVector: Property.LongText({
|
||||
displayName: 'Target Vector',
|
||||
description: 'Array of numbers to compare against (e.g., [0.1, 0.2, ...])',
|
||||
required: true,
|
||||
}),
|
||||
vectorSimilarity: Property.StaticDropdown({
|
||||
displayName: 'Similarity Metric',
|
||||
required: true,
|
||||
defaultValue: 'L2_SQUARED',
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Cosine', value: 'COSINE' },
|
||||
{ label: 'Dot Product', value: 'DOT' },
|
||||
{ label: 'Euclidean (L2)', value: 'L2' },
|
||||
{ label: 'Squared Euclidean', value: 'L2_SQUARED' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
preciseDistance: Property.Checkbox({
|
||||
displayName: 'Use Precise Distance',
|
||||
description: 'Use VECTOR_DISTANCE instead of APPROX_VECTOR_DISTANCE (slower but more accurate)',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
}),
|
||||
};
|
||||
Reference in New Issue
Block a user