Skip to content

The open alternative to Salesforce, designed for AI.

604 B
Raw Blame
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';

import { Buffer } from 'buffer';
import { base64UrlEncode, isDefined } from 'twenty-shared/utils';
import { doNotTranslate } from 'twenty-shared/i18n';

export const encodeCursor = (record: ObjectRecord) => {
  if (!('id' in record) || !isDefined(record.id)) {
    throw new Error(doNotTranslate('Record does not have an id'));
  }

  const payload: {
    id: string;
    position?: number;
  } = {
    position: record.position,
    id: record.id,
  };

  return base64UrlEncode(Buffer.from(JSON.stringify(payload), 'utf-8'));
};