@nacelle/compatibility-connector
Version:
Connect @nacelle/client-js-sdk to Nacelle's v2 back end with minimal code changes
17 lines (14 loc) • 625 B
text/typescript
/**
* 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');
}