/**
 * Transforms Nacelle v2 `sourceEntryId`s into formats used in Nacelle v1.
 * @param sourceEntryId A `sourceEntryId` associated with a product, variant, etc.
 * @returns A `sourceEntryId` that matches the Nacelle v1 format for `pimSyncSourceProductId` / equivalent properties that represent an ID from an upstream system.
 */
export function transformSourceEntryId(sourceEntryId: string): string {
  if (!sourceEntryId.startsWith('gid://shopify/')) {
    return sourceEntryId;
  }

  if (typeof window !== 'undefined') {
    return self.btoa(sourceEntryId);
  }

  return Buffer.from(sourceEntryId).toString('base64');
}
