Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(persist): Add support for activityLogId to get records endpoint #3476

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ApiError, Endpoint, GetRecordsSuccess } from '@nangohq/types';
import type { EndpointRequest, EndpointResponse, RouteHandler, Route } from '@nangohq/utils';
import { records } from '@nangohq/records';
import { validateGetRecords } from './validate.js';
import type { LogContextStateless } from '@nangohq/logs';
import { logContextGetter } from '@nangohq/logs';

type GetRecords = Endpoint<{
Method: typeof method;
Expand All @@ -13,8 +15,9 @@ type GetRecords = Endpoint<{
Querystring: {
model: string;
externalIds: string[];
cursor: string;
cursor: string | undefined;
limit: number;
activityLogId: string | undefined;
};
Error: ApiError<'get_records_failed'>;
Success: GetRecordsSuccess;
Expand All @@ -28,17 +31,28 @@ const validate = validateGetRecords<GetRecords>();
const handler = async (req: EndpointRequest<GetRecords>, res: EndpointResponse<GetRecords>) => {
const {
params: { nangoConnectionId },
query: { model, externalIds, cursor }
query: { model, externalIds, cursor, limit, activityLogId }
} = req;

let logCtx: LogContextStateless | undefined = undefined;
if (activityLogId) {
logCtx = logContextGetter.getStateLess({ id: String(activityLogId) });
}

const result = await records.getRecords({
connectionId: nangoConnectionId,
model,
cursor,
externalIds,
limit: 100
limit
});

if (result.isOk()) {
await logCtx?.info(`Successfully found ${result.value.records.length} records`, {
model,
externalIds,
limit
});
res.json(result.value);
} else {
res.status(500).json({ error: { code: 'get_records_failed', message: `Failed to get records: ${result.error.message}` } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const validateGetRecords = <E extends Endpoint<any>>() =>
model: z.string(),
cursor: z.string().optional(),
limit: z.coerce.number().int().positive().default(100),
activityLogId: z.string().optional(),
externalIds: z
.union([
z.string().min(1).max(256), // There is no diff between a normal query param and an array with one item
Expand Down
Loading