diff --git a/src/package/packageBundleVersionCreate.ts b/src/package/packageBundleVersionCreate.ts index 3c32d6626..215027fcc 100644 --- a/src/package/packageBundleVersionCreate.ts +++ b/src/package/packageBundleVersionCreate.ts @@ -174,8 +174,8 @@ export class PackageBundleVersionCreate { return bundleVersionComponents.map((component) => { const packageVersion = component.packageVersion; - // Check if it's already an ID (04t followed by 15 characters) - if (/^04t[a-zA-Z0-9]{15}$/.test(packageVersion)) { + // Check if it's a package version ID (04t prefix, 15 or 18 characters) + if (/^04t[a-zA-Z0-9]{12,15}$/.test(packageVersion)) { return packageVersion; } diff --git a/test/package/bundleVersionCreate.test.ts b/test/package/bundleVersionCreate.test.ts index af7ddf260..d8f980e3a 100644 --- a/test/package/bundleVersionCreate.test.ts +++ b/test/package/bundleVersionCreate.test.ts @@ -585,6 +585,75 @@ describe('PackageBundleVersion.create', () => { fs.unlinkSync(componentsPath); }); + it('should accept 15-char package version IDs', async () => { + const componentsPath = path.join(project.getPath(), 'bundle-components.json'); + const components = [ + { packageVersion: '04t5f000000WM9y' }, // 15-char ID + { packageVersion: '04t000000000000003' }, // 18-char ID + ]; + fs.writeFileSync(componentsPath, JSON.stringify(components)); + + let capturedRequest: { BundleVersionComponents: string } | undefined; + Object.assign(connection.tooling, { + sobject: () => ({ + create: (req: { BundleVersionComponents: string }) => { + capturedRequest = req; + return Promise.resolve({ + success: true, + id: '0Ho000000000000', + }); + }, + }), + query: () => + Promise.resolve({ + records: [{ BundleName: 'testBundle' }], + }), + }); + + Object.assign(connection, { + autoFetchQuery: () => + Promise.resolve({ + records: [ + { + Id: '0Ho000000000000', + RequestStatus: BundleSObjects.PkgBundleVersionCreateReqStatus.success, + PackageBundle: { Id: '0Ho123456789012' }, + PackageBundleVersion: { Id: '1Q8000000000001' }, + VersionName: 'ver 1.0', + MajorVersion: '1', + MinorVersion: '0', + Ancestor: null, + BundleVersionComponents: JSON.stringify(components), + CreatedDate: '2025-01-01T00:00:00.000Z', + CreatedById: '005000000000000', + ValidationError: '', + }, + ], + }), + }); + + const options: BundleVersionCreateOptions = { + connection, + project, + PackageBundle: 'testBundle', + MajorVersion: '1', + MinorVersion: '0', + Ancestor: null, + BundleVersionComponentsPath: componentsPath, + }; + + const result = await PackageBundleVersion.create(options); + expect(result).to.have.property('RequestStatus', BundleSObjects.PkgBundleVersionCreateReqStatus.success); + + // Verify both 15-char and 18-char IDs are passed through to the API + expect(capturedRequest).to.not.be.undefined; + const sentComponents = JSON.parse(capturedRequest!.BundleVersionComponents) as string[]; + expect(sentComponents[0]).to.equal('04t5f000000WM9y'); // 15-char passed through + expect(sentComponents[1]).to.equal('04t000000000000003'); // 18-char passed through + + fs.unlinkSync(componentsPath); + }); + it('should handle invalid bundle components format', async () => { const componentsPath = path.join(project.getPath(), 'bundle-components.json');