@salesforce/packaging 4.12.0 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/exported.d.ts CHANGED
@@ -2,3 +2,6 @@ export * from './interfaces';
2
2
  export * from './package';
3
3
  export * from './package1';
4
4
  export * from './utils';
5
+ export * from './package/packageBundle';
6
+ export * from './package/packageBundleVersionCreate';
7
+ export * from './package/packageBundleInstall';
package/lib/exported.js CHANGED
@@ -24,4 +24,7 @@ __exportStar(require("./interfaces"), exports);
24
24
  __exportStar(require("./package"), exports);
25
25
  __exportStar(require("./package1"), exports);
26
26
  __exportStar(require("./utils"), exports);
27
+ __exportStar(require("./package/packageBundle"), exports);
28
+ __exportStar(require("./package/packageBundleVersionCreate"), exports);
29
+ __exportStar(require("./package/packageBundleInstall"), exports);
27
30
  //# sourceMappingURL=exported.js.map
@@ -0,0 +1,33 @@
1
+ import { Nullable } from '@salesforce/ts-types';
2
+ import { Connection, SfProject } from '@salesforce/core';
3
+ import { Duration } from '@salesforce/kit';
4
+ import { SaveResult } from '@jsforce/jsforce-node';
5
+ export type BundleCreateOptions = {
6
+ BundleName: string;
7
+ Description: string;
8
+ };
9
+ export type BundleVersionCreateOptions = {
10
+ connection: Connection;
11
+ project: SfProject;
12
+ PackageBundle: string;
13
+ MajorVersion: string;
14
+ MinorVersion: string;
15
+ Ancestor: Nullable<string>;
16
+ BundleVersionComponentsPath: string;
17
+ Description?: string;
18
+ polling?: {
19
+ timeout: Duration;
20
+ frequency: Duration;
21
+ };
22
+ };
23
+ export type BundleInstallOptions = {
24
+ connection: Connection;
25
+ project: SfProject;
26
+ PackageBundleVersion: string;
27
+ DevelopmentOrganization: string;
28
+ polling?: {
29
+ timeout: Duration;
30
+ frequency: Duration;
31
+ };
32
+ };
33
+ export type BundleSaveResult = SaveResult;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=bundleInterfacesAndType.js.map
@@ -0,0 +1,146 @@
1
+ import { Nullable } from '@salesforce/ts-types';
2
+ import { BundleEntry } from '@salesforce/schemas';
3
+ import type { Schema } from '@jsforce/jsforce-node';
4
+ export { BundleEntry };
5
+ export type QueryRecord = Schema & {
6
+ Id: string;
7
+ PackageBundle?: {
8
+ Id: string;
9
+ BundleName: string;
10
+ Description?: string;
11
+ IsDeleted: boolean;
12
+ CreatedDate: string;
13
+ CreatedById: string;
14
+ LastModifiedDate: string;
15
+ LastModifiedById: string;
16
+ SystemModstamp: string;
17
+ };
18
+ VersionName: string;
19
+ MajorVersion: string;
20
+ MinorVersion: string;
21
+ IsReleased: boolean;
22
+ Ancestor?: {
23
+ Id: string;
24
+ PackageBundle?: {
25
+ Id: string;
26
+ BundleName: string;
27
+ Description?: string;
28
+ IsDeleted: boolean;
29
+ CreatedDate: string;
30
+ CreatedById: string;
31
+ LastModifiedDate: string;
32
+ LastModifiedById: string;
33
+ SystemModstamp: string;
34
+ };
35
+ VersionName: string;
36
+ MajorVersion: string;
37
+ MinorVersion: string;
38
+ IsReleased: boolean;
39
+ };
40
+ };
41
+ export type AncestorRecord = {
42
+ Id: string;
43
+ PackageBundle?: {
44
+ Id: string;
45
+ BundleName: string;
46
+ Description?: string;
47
+ IsDeleted: boolean;
48
+ CreatedDate: string;
49
+ CreatedById: string;
50
+ LastModifiedDate: string;
51
+ LastModifiedById: string;
52
+ SystemModstamp: string;
53
+ };
54
+ VersionName: string;
55
+ MajorVersion: string;
56
+ MinorVersion: string;
57
+ IsReleased: boolean;
58
+ };
59
+ export declare namespace BundleSObjects {
60
+ type Bundle = {
61
+ BundleName: string;
62
+ Description?: string;
63
+ Id: string;
64
+ IsDeleted: boolean;
65
+ CreatedDate: string;
66
+ CreatedById: string;
67
+ LastModifiedDate: string;
68
+ LastModifiedById: string;
69
+ SystemModstamp: string;
70
+ };
71
+ type BundleVersion = {
72
+ Id: string;
73
+ PackageBundle: Bundle;
74
+ VersionName: string;
75
+ MajorVersion: string;
76
+ MinorVersion: string;
77
+ Ancestor: Nullable<BundleVersion>;
78
+ IsReleased: boolean;
79
+ CreatedDate: string;
80
+ CreatedById: string;
81
+ LastModifiedDate: string;
82
+ LastModifiedById: string;
83
+ };
84
+ type PkgBundleVersionCreateReq = {
85
+ PackageBundleId: string;
86
+ VersionName: string;
87
+ MajorVersion: string;
88
+ MinorVersion: string;
89
+ BundleVersionComponents: string;
90
+ Ancestor?: string | null;
91
+ };
92
+ type PackageBundleVersionCreateRequestResult = PkgBundleVersionCreateReq & {
93
+ Id: string;
94
+ PackageBundleVersionId: string;
95
+ RequestStatus: PkgBundleVersionCreateReqStatus;
96
+ CreatedDate: string;
97
+ CreatedById: string;
98
+ Error?: string[];
99
+ };
100
+ enum PkgBundleVersionCreateReqStatus {
101
+ queued = "Queued",
102
+ success = "Success",
103
+ error = "Error"
104
+ }
105
+ enum PkgBundleVersionInstallReqStatus {
106
+ queued = "Queued",
107
+ success = "Success",
108
+ error = "Error"
109
+ }
110
+ type PkgBundleVersionQueryRecord = {
111
+ Id: string;
112
+ RequestStatus: BundleSObjects.PkgBundleVersionCreateReqStatus;
113
+ PackageBundle: Bundle;
114
+ PackageBundleVersion: BundleVersion;
115
+ VersionName: string;
116
+ MajorVersion: string;
117
+ MinorVersion: string;
118
+ Ancestor: BundleVersion;
119
+ BundleVersionComponents: string;
120
+ CreatedDate: string;
121
+ CreatedById: string;
122
+ Error?: string[];
123
+ } & Schema;
124
+ type PkgBundleVersionInstallReq = {
125
+ PackageBundleVersionID: string;
126
+ DevelopmentOrganization: string;
127
+ };
128
+ type PkgBundleVersionInstallReqResult = PkgBundleVersionInstallReq & {
129
+ Id: string;
130
+ InstallStatus: PkgBundleVersionInstallReqStatus;
131
+ ValidationError: string;
132
+ CreatedDate: string;
133
+ CreatedById: string;
134
+ Error?: string[];
135
+ };
136
+ type PkgBundleVersionInstallQueryRecord = {
137
+ Id: string;
138
+ InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus;
139
+ PackageBundleVersionID: string;
140
+ DevelopmentOrganization: string;
141
+ ValidationError: string;
142
+ CreatedDate: string;
143
+ CreatedById: string;
144
+ Error?: string[];
145
+ } & Schema;
146
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BundleSObjects = void 0;
4
+ var BundleSObjects;
5
+ (function (BundleSObjects) {
6
+ let PkgBundleVersionCreateReqStatus;
7
+ (function (PkgBundleVersionCreateReqStatus) {
8
+ PkgBundleVersionCreateReqStatus["queued"] = "Queued";
9
+ PkgBundleVersionCreateReqStatus["success"] = "Success";
10
+ PkgBundleVersionCreateReqStatus["error"] = "Error";
11
+ })(PkgBundleVersionCreateReqStatus = BundleSObjects.PkgBundleVersionCreateReqStatus || (BundleSObjects.PkgBundleVersionCreateReqStatus = {}));
12
+ let PkgBundleVersionInstallReqStatus;
13
+ (function (PkgBundleVersionInstallReqStatus) {
14
+ PkgBundleVersionInstallReqStatus["queued"] = "Queued";
15
+ PkgBundleVersionInstallReqStatus["success"] = "Success";
16
+ PkgBundleVersionInstallReqStatus["error"] = "Error";
17
+ })(PkgBundleVersionInstallReqStatus = BundleSObjects.PkgBundleVersionInstallReqStatus || (BundleSObjects.PkgBundleVersionInstallReqStatus = {}));
18
+ })(BundleSObjects || (exports.BundleSObjects = BundleSObjects = {}));
19
+ //# sourceMappingURL=bundleSObjects.js.map
@@ -1,2 +1,4 @@
1
1
  export * from './packagingInterfacesAndType';
2
2
  export * from './packagingSObjects';
3
+ export * from './bundleInterfacesAndType';
4
+ export * from './bundleSObjects';
@@ -22,4 +22,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  */
23
23
  __exportStar(require("./packagingInterfacesAndType"), exports);
24
24
  __exportStar(require("./packagingSObjects"), exports);
25
+ __exportStar(require("./bundleInterfacesAndType"), exports);
26
+ __exportStar(require("./bundleSObjects"), exports);
25
27
  //# sourceMappingURL=index.js.map
@@ -3,3 +3,6 @@ export * from './packageVersion';
3
3
  export * from './subscriberPackageVersion';
4
4
  export * from './packagePushUpgrade';
5
5
  export { VersionNumber } from './versionNumber';
6
+ export * from './packageBundle';
7
+ export * from './packageBundleVersion';
8
+ export * from './packageBundleInstall';
@@ -27,4 +27,7 @@ __exportStar(require("./subscriberPackageVersion"), exports);
27
27
  __exportStar(require("./packagePushUpgrade"), exports);
28
28
  var versionNumber_1 = require("./versionNumber");
29
29
  Object.defineProperty(exports, "VersionNumber", { enumerable: true, get: function () { return versionNumber_1.VersionNumber; } });
30
+ __exportStar(require("./packageBundle"), exports);
31
+ __exportStar(require("./packageBundleVersion"), exports);
32
+ __exportStar(require("./packageBundleInstall"), exports);
30
33
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,37 @@
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { SaveResult } from '@jsforce/jsforce-node';
3
+ import { Duration } from '@salesforce/kit';
4
+ import { BundleCreateOptions, BundleSObjects, BundleVersionCreateOptions } from '../interfaces';
5
+ export declare class PackageBundle {
6
+ /**
7
+ * Create a new package bundle.
8
+ *
9
+ * @param connection - instance of Connection
10
+ * @param project - instance of SfProject
11
+ * @param options - options for creating a bundle - see BundleCreateOptions
12
+ * @returns PackageBundle
13
+ */
14
+ static create(connection: Connection, project: SfProject, options: BundleCreateOptions): Promise<{
15
+ Id: string;
16
+ }>;
17
+ /**
18
+ * Create a new package bundle version.
19
+ *
20
+ * @param connection - instance of Connection
21
+ * @param project - instance of SfProject
22
+ * @param options - options for creating a bundle version - see BundleVersionCreateOptions
23
+ * @returns PackageBundle
24
+ */
25
+ static createVersion(options: BundleVersionCreateOptions, polling?: {
26
+ frequency: Duration;
27
+ timeout: Duration;
28
+ }): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult>;
29
+ static delete(connection: Connection, project: SfProject, idOrAlias: string): Promise<SaveResult>;
30
+ /**
31
+ * Returns all the package bundles that are available in the org, up to 10,000. If more records are
32
+ * needed use the `SF_ORG_MAX_QUERY_LIMIT` env var.
33
+ *
34
+ * @param connection
35
+ */
36
+ static list(connection: Connection): Promise<BundleSObjects.Bundle[]>;
37
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PackageBundle = void 0;
10
+ const core_1 = require("@salesforce/core");
11
+ const kit_1 = require("@salesforce/kit");
12
+ const packageBundleCreate_1 = require("./packageBundleCreate");
13
+ const packageBundleVersion_1 = require("./packageBundleVersion");
14
+ const BundleFields = [
15
+ 'BundleName',
16
+ 'Description',
17
+ 'Id',
18
+ 'IsDeleted',
19
+ 'CreatedDate',
20
+ 'CreatedById',
21
+ 'LastModifiedDate',
22
+ 'LastModifiedById',
23
+ 'SystemModstamp',
24
+ ];
25
+ class PackageBundle {
26
+ /**
27
+ * Create a new package bundle.
28
+ *
29
+ * @param connection - instance of Connection
30
+ * @param project - instance of SfProject
31
+ * @param options - options for creating a bundle - see BundleCreateOptions
32
+ * @returns PackageBundle
33
+ */
34
+ static async create(connection, project, options) {
35
+ return (0, packageBundleCreate_1.createBundle)(connection, project, options);
36
+ }
37
+ /**
38
+ * Create a new package bundle version.
39
+ *
40
+ * @param connection - instance of Connection
41
+ * @param project - instance of SfProject
42
+ * @param options - options for creating a bundle version - see BundleVersionCreateOptions
43
+ * @returns PackageBundle
44
+ */
45
+ static async createVersion(options, polling = {
46
+ frequency: kit_1.Duration.seconds(0),
47
+ timeout: kit_1.Duration.seconds(0),
48
+ }) {
49
+ return packageBundleVersion_1.PackageBundleVersion.create(options, polling);
50
+ }
51
+ static async delete(connection, project, idOrAlias) {
52
+ // Check if it's already an ID (1Fl followed by 15 characters)
53
+ if (/^1Fl.{15}$/.test(idOrAlias)) {
54
+ return connection.tooling.sobject('PackageBundle').delete(idOrAlias);
55
+ }
56
+ // Validate that project is provided when using aliases
57
+ if (!project) {
58
+ throw new core_1.SfError('Project instance is required when deleting package bundle by alias');
59
+ }
60
+ // eslint-disable-next-line no-param-reassign
61
+ idOrAlias = project.getPackageBundleIdFromAlias(idOrAlias) ?? idOrAlias;
62
+ return connection.tooling.sobject('PackageBundle').delete(idOrAlias);
63
+ }
64
+ /**
65
+ * Returns all the package bundles that are available in the org, up to 10,000. If more records are
66
+ * needed use the `SF_ORG_MAX_QUERY_LIMIT` env var.
67
+ *
68
+ * @param connection
69
+ */
70
+ static async list(connection) {
71
+ const query = `select ${BundleFields.join(', ')} from PackageBundle ORDER BY BundleName`;
72
+ return (await connection.autoFetchQuery(query, { tooling: true }))?.records;
73
+ }
74
+ }
75
+ exports.PackageBundle = PackageBundle;
76
+ //# sourceMappingURL=packageBundle.js.map
@@ -0,0 +1,7 @@
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { BundleEntry } from '@salesforce/schemas';
3
+ import { BundleCreateOptions } from '../interfaces';
4
+ export declare function createPackageDirEntry(project: SfProject, options: BundleCreateOptions): BundleEntry;
5
+ export declare function createBundle(connection: Connection, project: SfProject, options: BundleCreateOptions): Promise<{
6
+ Id: string;
7
+ }>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPackageDirEntry = createPackageDirEntry;
4
+ exports.createBundle = createBundle;
5
+ /*
6
+ * Copyright (c) 2025, salesforce.com, inc.
7
+ * All rights reserved.
8
+ * Licensed under the BSD 3-Clause license.
9
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
10
+ */
11
+ const core_1 = require("@salesforce/core");
12
+ const bundleUtils_1 = require("../utils/bundleUtils");
13
+ core_1.Messages.importMessagesDirectory(__dirname);
14
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_create');
15
+ function createPackageDirEntry(project, options) {
16
+ return {
17
+ versionName: 'ver 0.1',
18
+ versionNumber: '0.1',
19
+ name: options.BundleName,
20
+ versionDescription: options.Description,
21
+ };
22
+ }
23
+ async function createBundle(connection, project, options) {
24
+ const request = { BundleName: options.BundleName, Description: options.Description };
25
+ let createResult;
26
+ try {
27
+ createResult = await connection.tooling.sobject('PackageBundle').create(request);
28
+ }
29
+ catch (err) {
30
+ const error = err instanceof Error
31
+ ? err
32
+ : new Error(typeof err === 'string' ? err : messages.getMessage('failedToCreatePackageBundle'));
33
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
34
+ }
35
+ if (!createResult?.success) {
36
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(new Error(messages.getMessage('failedToCreatePackageBundle'))));
37
+ }
38
+ const bundleEntry = createPackageDirEntry(project, options);
39
+ project.getSfProjectJson().addPackageBundle(bundleEntry);
40
+ project.getSfProjectJson().addPackageBundleAlias(bundleEntry.name, createResult.id);
41
+ await project.getSfProjectJson().write();
42
+ return { Id: createResult.id };
43
+ }
44
+ //# sourceMappingURL=packageBundleCreate.js.map
@@ -0,0 +1,9 @@
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { BundleSObjects, BundleInstallOptions } from '../interfaces';
3
+ export declare class PackageBundleInstall {
4
+ static getInstallStatus(installRequestId: string, connection: Connection): Promise<BundleSObjects.PkgBundleVersionInstallReqResult>;
5
+ static getInstallStatuses(connection: Connection, status?: BundleSObjects.PkgBundleVersionInstallReqStatus, createdLastDays?: number): Promise<BundleSObjects.PkgBundleVersionInstallReqResult[]>;
6
+ static installBundle(connection: Connection, project: SfProject, options: BundleInstallOptions): Promise<BundleSObjects.PkgBundleVersionInstallReqResult>;
7
+ private static parsePackageBundleVersionId;
8
+ private static pollInstallStatus;
9
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageBundleInstall = void 0;
4
+ /*
5
+ * Copyright (c) 2025, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const core_1 = require("@salesforce/core");
11
+ const interfaces_1 = require("../interfaces");
12
+ const bundleUtils_1 = require("../utils/bundleUtils");
13
+ core_1.Messages.importMessagesDirectory(__dirname);
14
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_install');
15
+ class PackageBundleInstall {
16
+ static async getInstallStatus(installRequestId, connection) {
17
+ try {
18
+ const result = await connection.tooling.sobject('PkgBundleVersionInstallReq').retrieve(installRequestId);
19
+ return result;
20
+ }
21
+ catch (err) {
22
+ const error = err instanceof Error ? err : new Error(messages.getMessage('failedToGetPackageBundleInstallStatus'));
23
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
24
+ }
25
+ }
26
+ static async getInstallStatuses(connection, status, createdLastDays) {
27
+ let query = 'SELECT Id, InstallStatus, PackageBundleVersionID, DevelopmentOrganization, ValidationError, ' +
28
+ 'CreatedDate, CreatedById ' +
29
+ 'FROM PkgBundleVersionInstallReq';
30
+ if (status && createdLastDays) {
31
+ query += ` WHERE InstallStatus = '${status}' AND CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
32
+ }
33
+ else if (status) {
34
+ query += ` WHERE InstallStatus = '${status}'`;
35
+ }
36
+ else if (createdLastDays) {
37
+ query += ` WHERE CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
38
+ }
39
+ const queryResult = await connection.autoFetchQuery(query, {
40
+ tooling: true,
41
+ });
42
+ return queryResult.records.map((record) => ({
43
+ Id: record.Id,
44
+ InstallStatus: record.InstallStatus,
45
+ PackageBundleVersionID: record.PackageBundleVersionID ?? '',
46
+ DevelopmentOrganization: record.DevelopmentOrganization ?? '',
47
+ ValidationError: record.ValidationError ?? '',
48
+ CreatedDate: record.CreatedDate ?? '',
49
+ CreatedById: record.CreatedById ?? '',
50
+ }));
51
+ }
52
+ static async installBundle(connection, project, options) {
53
+ const packageBundleVersionId = PackageBundleInstall.parsePackageBundleVersionId(options.PackageBundleVersion, project);
54
+ const request = {
55
+ PackageBundleVersionID: packageBundleVersionId,
56
+ DevelopmentOrganization: options.DevelopmentOrganization,
57
+ };
58
+ let installResult;
59
+ try {
60
+ installResult = await connection.tooling.sobject('PkgBundleVersionInstallReq').create(request);
61
+ }
62
+ catch (err) {
63
+ const error = err instanceof Error
64
+ ? err
65
+ : new Error(typeof err === 'string' ? err : messages.getMessage('failedToInstallPackageBundle'));
66
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
67
+ }
68
+ if (!installResult?.success) {
69
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(new Error(messages.getMessage('failedToInstallPackageBundle'))));
70
+ }
71
+ if (options.polling) {
72
+ return PackageBundleInstall.pollInstallStatus(installResult.id, connection, options.polling);
73
+ }
74
+ return {
75
+ Id: installResult.id,
76
+ PackageBundleVersionID: packageBundleVersionId,
77
+ DevelopmentOrganization: options.DevelopmentOrganization,
78
+ InstallStatus: interfaces_1.BundleSObjects.PkgBundleVersionInstallReqStatus.queued,
79
+ ValidationError: '',
80
+ CreatedDate: new Date().toISOString(),
81
+ CreatedById: connection.getUsername() ?? 'unknown',
82
+ };
83
+ }
84
+ static parsePackageBundleVersionId(packageBundleVersion, project) {
85
+ // Check if it's already an ID (starts with appropriate prefix)
86
+ if (/^1Q8.{15}$/.test(packageBundleVersion)) {
87
+ return packageBundleVersion;
88
+ }
89
+ // Otherwise, treat it as an alias and resolve it from sfdx-project.json
90
+ const packageBundleVersionId = project.getPackageBundleIdFromAlias(packageBundleVersion);
91
+ if (!packageBundleVersionId) {
92
+ throw new core_1.SfError(messages.getMessage('noPackageBundleVersionFoundWithAlias', [packageBundleVersion]));
93
+ }
94
+ return packageBundleVersionId;
95
+ }
96
+ static async pollInstallStatus(installRequestId, connection, polling) {
97
+ if (polling.timeout?.milliseconds <= 0) {
98
+ return PackageBundleInstall.getInstallStatus(installRequestId, connection);
99
+ }
100
+ const pollingClient = await core_1.PollingClient.create({
101
+ poll: async () => {
102
+ const status = await PackageBundleInstall.getInstallStatus(installRequestId, connection);
103
+ if (status.InstallStatus === interfaces_1.BundleSObjects.PkgBundleVersionInstallReqStatus.success) {
104
+ return { completed: true, payload: status };
105
+ }
106
+ return { completed: false, payload: status };
107
+ },
108
+ frequency: polling.frequency,
109
+ timeout: polling.timeout,
110
+ });
111
+ try {
112
+ return await pollingClient.subscribe();
113
+ }
114
+ catch (err) {
115
+ if (err instanceof Error) {
116
+ throw new Error('Install request timed out');
117
+ }
118
+ throw err;
119
+ }
120
+ }
121
+ }
122
+ exports.PackageBundleInstall = PackageBundleInstall;
123
+ //# sourceMappingURL=packageBundleInstall.js.map
@@ -0,0 +1,21 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { SfProject } from '@salesforce/core';
3
+ import { Duration } from '@salesforce/kit';
4
+ import { BundleVersionCreateOptions, BundleSObjects, PackagingSObjects } from '../interfaces';
5
+ export declare class PackageBundleVersion {
6
+ static create(options: BundleVersionCreateOptions, polling?: {
7
+ frequency: Duration;
8
+ timeout: Duration;
9
+ }): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult>;
10
+ static pollCreateStatus(createPackageVersionRequestId: string, connection: Connection, project: SfProject, polling: {
11
+ frequency: Duration;
12
+ timeout: Duration;
13
+ }): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult>;
14
+ static report(connection: Connection, id: string): Promise<BundleSObjects.BundleVersion | null>;
15
+ static list(connection: Connection): Promise<BundleSObjects.BundleVersion[]>;
16
+ static getComponentPackages(connection: Connection, id: string): Promise<PackagingSObjects.SubscriberPackageVersion[]>;
17
+ private static mapRecordToBundleVersion;
18
+ private static mapPackageBundle;
19
+ private static mapAncestor;
20
+ private static mapAncestorPackageBundle;
21
+ }
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PackageBundleVersion = void 0;
10
+ const core_1 = require("@salesforce/core");
11
+ const kit_1 = require("@salesforce/kit");
12
+ const interfaces_1 = require("../interfaces");
13
+ const bundleUtils_1 = require("../utils/bundleUtils");
14
+ const packageUtils_1 = require("../utils/packageUtils");
15
+ const packageBundleVersionCreate_1 = require("./packageBundleVersionCreate");
16
+ core_1.Messages.importMessagesDirectory(__dirname);
17
+ const bundleVersionMessages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_version');
18
+ class PackageBundleVersion {
19
+ static async create(options, polling) {
20
+ const createResult = await packageBundleVersionCreate_1.PackageBundleVersionCreate.createBundleVersion(options.connection, options.project, options);
21
+ if (polling) {
22
+ return PackageBundleVersion.pollCreateStatus(createResult.Id, options.connection, options.project, polling).catch((error) => {
23
+ if (error.name === 'PollingClientTimeout') {
24
+ const modifiedError = new core_1.SfError(error.message);
25
+ modifiedError.setData({ VersionCreateRequestId: createResult.Id });
26
+ modifiedError.message += ` Run 'sf package bundle version create report -i ${createResult.Id}' to check the status.`;
27
+ throw (0, packageUtils_1.applyErrorAction)((0, bundleUtils_1.massageErrorMessage)(modifiedError));
28
+ }
29
+ throw (0, packageUtils_1.applyErrorAction)((0, bundleUtils_1.massageErrorMessage)(error));
30
+ });
31
+ }
32
+ return createResult;
33
+ }
34
+ static async pollCreateStatus(createPackageVersionRequestId, connection, project, polling) {
35
+ if (polling.timeout?.milliseconds <= 0) {
36
+ return packageBundleVersionCreate_1.PackageBundleVersionCreate.getCreateStatus(createPackageVersionRequestId, connection);
37
+ }
38
+ let remainingWaitTime = polling.timeout;
39
+ const pollingClient = await core_1.PollingClient.create({
40
+ poll: async () => {
41
+ const report = await packageBundleVersionCreate_1.PackageBundleVersionCreate.getCreateStatus(createPackageVersionRequestId, connection);
42
+ switch (report.RequestStatus) {
43
+ case interfaces_1.BundleSObjects.PkgBundleVersionCreateReqStatus.queued:
44
+ await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageVersionEvents.create.enqueued, { ...report, remainingWaitTime });
45
+ remainingWaitTime = kit_1.Duration.seconds(remainingWaitTime.seconds - polling.frequency.seconds);
46
+ return {
47
+ completed: false,
48
+ payload: report,
49
+ };
50
+ case interfaces_1.BundleSObjects.PkgBundleVersionCreateReqStatus.success: {
51
+ await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageVersionEvents.create.success, report);
52
+ return { completed: true, payload: report };
53
+ }
54
+ case interfaces_1.BundleSObjects.PkgBundleVersionCreateReqStatus.error:
55
+ await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageVersionEvents.create.error, report);
56
+ return { completed: true, payload: report };
57
+ }
58
+ },
59
+ frequency: polling.frequency,
60
+ timeout: polling.timeout,
61
+ });
62
+ try {
63
+ return await pollingClient.subscribe();
64
+ }
65
+ catch (err) {
66
+ const report = await packageBundleVersionCreate_1.PackageBundleVersionCreate.getCreateStatus(createPackageVersionRequestId, connection);
67
+ await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageVersionEvents.create['timed-out'], report);
68
+ if (err instanceof Error) {
69
+ throw (0, packageUtils_1.applyErrorAction)(err);
70
+ }
71
+ throw err;
72
+ }
73
+ }
74
+ static async report(connection, id) {
75
+ const query = `SELECT Id, PackageBundle.Id, PackageBundle.BundleName, VersionName, MajorVersion, MinorVersion, IsReleased, PackageBundle.Description, PackageBundle.IsDeleted, PackageBundle.CreatedDate, PackageBundle.CreatedById, PackageBundle.LastModifiedDate, PackageBundle.LastModifiedById, PackageBundle.SystemModstamp, Ancestor.Id, Ancestor.PackageBundle.Id, Ancestor.PackageBundle.BundleName, Ancestor.VersionName, Ancestor.MajorVersion, Ancestor.MinorVersion, Ancestor.IsReleased, Ancestor.PackageBundle.Description, Ancestor.PackageBundle.IsDeleted, Ancestor.PackageBundle.CreatedDate, Ancestor.PackageBundle.CreatedById, Ancestor.PackageBundle.LastModifiedDate, Ancestor.PackageBundle.LastModifiedById, Ancestor.PackageBundle.SystemModstamp FROM PackageBundleVersion WHERE Id = '${id}'`;
76
+ const queryResult = await connection.autoFetchQuery(query, { tooling: true });
77
+ return queryResult.records.length > 0
78
+ ? PackageBundleVersion.mapRecordToBundleVersion(queryResult.records[0])
79
+ : null;
80
+ }
81
+ static async list(connection) {
82
+ const query = 'SELECT Id, PackageBundle.Id, PackageBundle.BundleName, VersionName, MajorVersion, MinorVersion, IsReleased, PackageBundle.Description, PackageBundle.IsDeleted, PackageBundle.CreatedDate, PackageBundle.CreatedById, PackageBundle.LastModifiedDate, PackageBundle.LastModifiedById, PackageBundle.SystemModstamp, Ancestor.Id, Ancestor.PackageBundle.Id, Ancestor.PackageBundle.BundleName, Ancestor.VersionName, Ancestor.MajorVersion, Ancestor.MinorVersion, Ancestor.IsReleased, Ancestor.PackageBundle.Description, Ancestor.PackageBundle.IsDeleted, Ancestor.PackageBundle.CreatedDate, Ancestor.PackageBundle.CreatedById, Ancestor.PackageBundle.LastModifiedDate, Ancestor.PackageBundle.LastModifiedById, Ancestor.PackageBundle.SystemModstamp FROM PackageBundleVersion';
83
+ const queryResult = await connection.autoFetchQuery(query, { tooling: true });
84
+ return queryResult.records.map((record) => PackageBundleVersion.mapRecordToBundleVersion(record));
85
+ }
86
+ static async getComponentPackages(connection, id) {
87
+ const query = `SELECT Component.Id, Component.Description, Component.PublisherName, Component.MajorVersion, Component.MinorVersion, Component.PatchVersion, Component.BuildNumber, Component.ReleaseState, Component.IsManaged, Component.IsDeprecated, Component.IsPasswordProtected, Component.IsBeta, Component.Package2ContainerOptions, Component.IsSecurityReviewed, Component.IsOrgDependent, Component.AppExchangePackageName, Component.AppExchangeDescription, Component.AppExchangePublisherName, Component.AppExchangeLogoUrl, Component.ReleaseNotesUrl, Component.PostInstallUrl, Component.RemoteSiteSettings, Component.CspTrustedSites, Component.Profiles, Component.Dependencies, Component.InstallValidationStatus, Component.SubscriberPackageId FROM PkgBundleVersionComponent WHERE PackageBundleVersion.Id = '${id}' ORDER BY CreatedDate`;
88
+ const queryResult = await connection.autoFetchQuery(query, { tooling: true });
89
+ // Get unique SubscriberPackageIds to query for Names
90
+ const subscriberPackageIds = [
91
+ ...new Set(queryResult.records
92
+ .map((record) => record.Component?.SubscriberPackageId)
93
+ .filter((packageId) => !!packageId)),
94
+ ];
95
+ // Query SubscriberPackage to get Names (one by one due to implementation restriction)
96
+ const subscriberPackageNames = new Map();
97
+ const packageQueries = subscriberPackageIds.map(async (packageId) => {
98
+ try {
99
+ const packageQuery = `SELECT Id, Name FROM SubscriberPackage WHERE Id='${packageId}'`;
100
+ const packageQueryResult = await connection.autoFetchQuery(packageQuery, { tooling: true });
101
+ return {
102
+ packageId,
103
+ name: packageQueryResult.records.length > 0 ? packageQueryResult.records[0].Name : '',
104
+ };
105
+ }
106
+ catch (error) {
107
+ // If individual query fails, return empty name for this package
108
+ return {
109
+ packageId,
110
+ name: '',
111
+ };
112
+ }
113
+ });
114
+ const packageResults = await Promise.allSettled(packageQueries);
115
+ packageResults.forEach((result) => {
116
+ if (result.status === 'fulfilled') {
117
+ subscriberPackageNames.set(result.value.packageId, result.value.name);
118
+ }
119
+ });
120
+ return queryResult.records.map((record) => {
121
+ const component = record.Component;
122
+ if (!component) {
123
+ throw new core_1.SfError(bundleVersionMessages.getMessage('componentRecordMissing'));
124
+ }
125
+ const packageName = subscriberPackageNames.get(component.SubscriberPackageId) ?? '';
126
+ return {
127
+ Id: component.Id,
128
+ SubscriberPackageId: component.SubscriberPackageId,
129
+ Name: packageName,
130
+ Description: component.Description,
131
+ PublisherName: component.PublisherName,
132
+ MajorVersion: component.MajorVersion,
133
+ MinorVersion: component.MinorVersion,
134
+ PatchVersion: component.PatchVersion,
135
+ BuildNumber: component.BuildNumber,
136
+ ReleaseState: component.ReleaseState,
137
+ IsManaged: component.IsManaged,
138
+ IsDeprecated: component.IsDeprecated,
139
+ IsPasswordProtected: component.IsPasswordProtected,
140
+ IsBeta: component.IsBeta,
141
+ Package2ContainerOptions: component.Package2ContainerOptions,
142
+ IsSecurityReviewed: component.IsSecurityReviewed,
143
+ IsOrgDependent: component.IsOrgDependent,
144
+ AppExchangePackageName: component.AppExchangePackageName,
145
+ AppExchangeDescription: component.AppExchangeDescription,
146
+ AppExchangePublisherName: component.AppExchangePublisherName,
147
+ AppExchangeLogoUrl: component.AppExchangeLogoUrl,
148
+ ReleaseNotesUrl: component.ReleaseNotesUrl,
149
+ PostInstallUrl: component.PostInstallUrl,
150
+ RemoteSiteSettings: component.RemoteSiteSettings,
151
+ CspTrustedSites: component.CspTrustedSites,
152
+ Profiles: component.Profiles,
153
+ Dependencies: component.Dependencies,
154
+ InstallValidationStatus: component.InstallValidationStatus,
155
+ };
156
+ });
157
+ }
158
+ static mapRecordToBundleVersion(record) {
159
+ return {
160
+ Id: record.Id,
161
+ PackageBundle: PackageBundleVersion.mapPackageBundle(record.PackageBundle),
162
+ VersionName: record.VersionName ?? '',
163
+ MajorVersion: record.MajorVersion ?? '',
164
+ MinorVersion: record.MinorVersion ?? '',
165
+ CreatedDate: record.PackageBundle?.CreatedDate ?? '',
166
+ CreatedById: record.PackageBundle?.CreatedById ?? '',
167
+ LastModifiedDate: record.PackageBundle?.LastModifiedDate ?? '',
168
+ LastModifiedById: record.PackageBundle?.LastModifiedById ?? '',
169
+ Ancestor: record.Ancestor?.Id ? PackageBundleVersion.mapAncestor(record.Ancestor) : null,
170
+ IsReleased: record.IsReleased ?? false,
171
+ };
172
+ }
173
+ static mapPackageBundle(packageBundle) {
174
+ return {
175
+ Id: packageBundle?.Id ?? '',
176
+ BundleName: packageBundle?.BundleName ?? '',
177
+ Description: packageBundle?.Description,
178
+ IsDeleted: packageBundle?.IsDeleted ?? false,
179
+ CreatedDate: packageBundle?.CreatedDate ?? '',
180
+ CreatedById: packageBundle?.CreatedById ?? '',
181
+ LastModifiedDate: packageBundle?.LastModifiedDate ?? '',
182
+ LastModifiedById: packageBundle?.LastModifiedById ?? '',
183
+ SystemModstamp: packageBundle?.SystemModstamp ?? '',
184
+ };
185
+ }
186
+ static mapAncestor(ancestor) {
187
+ return {
188
+ Id: ancestor.Id,
189
+ PackageBundle: PackageBundleVersion.mapAncestorPackageBundle(ancestor.PackageBundle),
190
+ VersionName: ancestor?.VersionName ?? '',
191
+ MajorVersion: ancestor?.MajorVersion ?? '',
192
+ MinorVersion: ancestor?.MinorVersion ?? '',
193
+ CreatedDate: ancestor.PackageBundle?.CreatedDate ?? '',
194
+ CreatedById: ancestor.PackageBundle?.CreatedById ?? '',
195
+ LastModifiedDate: ancestor.PackageBundle?.LastModifiedDate ?? '',
196
+ LastModifiedById: ancestor.PackageBundle?.LastModifiedById ?? '',
197
+ Ancestor: null,
198
+ IsReleased: ancestor.IsReleased ?? false,
199
+ };
200
+ }
201
+ static mapAncestorPackageBundle(packageBundle) {
202
+ return {
203
+ Id: packageBundle?.Id ?? '',
204
+ BundleName: packageBundle?.BundleName ?? '',
205
+ Description: packageBundle?.Description,
206
+ IsDeleted: packageBundle?.IsDeleted ?? false,
207
+ CreatedDate: packageBundle?.CreatedDate ?? '',
208
+ CreatedById: packageBundle?.CreatedById ?? '',
209
+ LastModifiedDate: packageBundle?.LastModifiedDate ?? '',
210
+ LastModifiedById: packageBundle?.LastModifiedById ?? '',
211
+ SystemModstamp: packageBundle?.SystemModstamp ?? '',
212
+ };
213
+ }
214
+ }
215
+ exports.PackageBundleVersion = PackageBundleVersion;
216
+ //# sourceMappingURL=packageBundleVersion.js.map
@@ -0,0 +1,11 @@
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { BundleSObjects, BundleVersionCreateOptions } from '../interfaces';
3
+ export declare class PackageBundleVersionCreate {
4
+ static getCreateStatus(createPackageVersionRequestId: string, connection: Connection): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult>;
5
+ static getCreateStatuses(connection: Connection, status?: BundleSObjects.PkgBundleVersionCreateReqStatus, createdLastDays?: number): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult[]>;
6
+ static createBundleVersion(connection: Connection, project: SfProject, options: BundleVersionCreateOptions): Promise<BundleSObjects.PackageBundleVersionCreateRequestResult>;
7
+ private static readBundleVersionComponents;
8
+ private static getVersionName;
9
+ private static parsePackageBundleId;
10
+ private static getPackageVersion;
11
+ }
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PackageBundleVersionCreate = void 0;
37
+ /*
38
+ * Copyright (c) 2025, salesforce.com, inc.
39
+ * All rights reserved.
40
+ * Licensed under the BSD 3-Clause license.
41
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
42
+ */
43
+ const fs = __importStar(require("node:fs"));
44
+ const core_1 = require("@salesforce/core");
45
+ const interfaces_1 = require("../interfaces");
46
+ const bundleUtils_1 = require("../utils/bundleUtils");
47
+ const packageBundleVersion_1 = require("./packageBundleVersion");
48
+ core_1.Messages.importMessagesDirectory(__dirname);
49
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_version_create');
50
+ class PackageBundleVersionCreate {
51
+ static async getCreateStatus(createPackageVersionRequestId, connection) {
52
+ try {
53
+ const result = await connection.tooling
54
+ .sobject('PkgBundleVersionCreateReq')
55
+ .retrieve(createPackageVersionRequestId);
56
+ return result;
57
+ }
58
+ catch (err) {
59
+ const error = err instanceof Error ? err : new Error(messages.getMessage('failedToGetPackageBundleVersionCreateStatus'));
60
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
61
+ }
62
+ }
63
+ static async getCreateStatuses(connection, status, createdLastDays) {
64
+ let query = 'SELECT Id, RequestStatus, PackageBundle.Id, PackageBundle.BundleName, PackageBundleVersion.Id, ' +
65
+ 'VersionName, MajorVersion, MinorVersion, Ancestor.Id, BundleVersionComponents, ' +
66
+ 'CreatedDate, CreatedById ' +
67
+ 'FROM PkgBundleVersionCreateReq';
68
+ if (status && createdLastDays) {
69
+ query += ` WHERE RequestStatus = '${status}' AND CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
70
+ }
71
+ else if (status) {
72
+ query += ` WHERE RequestStatus = '${status}'`;
73
+ }
74
+ else if (createdLastDays) {
75
+ query += ` WHERE CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
76
+ }
77
+ const queryResult = await connection.autoFetchQuery(query, {
78
+ tooling: true,
79
+ });
80
+ return queryResult.records.map((record) => ({
81
+ Id: record.Id,
82
+ RequestStatus: record.RequestStatus,
83
+ PackageBundleId: record.PackageBundle?.Id ?? '',
84
+ PackageBundleVersionId: record.PackageBundleVersion?.Id ?? '',
85
+ VersionName: record.VersionName ?? '',
86
+ MajorVersion: record.MajorVersion ?? '',
87
+ MinorVersion: record.MinorVersion ?? '',
88
+ Ancestor: record.Ancestor?.Id ?? '',
89
+ BundleVersionComponents: record.BundleVersionComponents ?? '',
90
+ CreatedDate: record.CreatedDate ?? '',
91
+ CreatedById: record.CreatedById ?? '',
92
+ }));
93
+ }
94
+ static async createBundleVersion(connection, project, options) {
95
+ const bundleVersionComponents = PackageBundleVersionCreate.readBundleVersionComponents(options.BundleVersionComponentsPath, project);
96
+ const packageBundleId = PackageBundleVersionCreate.parsePackageBundleId(options.PackageBundle, project);
97
+ // Use provided MajorVersion and MinorVersion if they are not empty strings, otherwise get from bundle configuration
98
+ const version = options.MajorVersion && options.MinorVersion
99
+ ? { MajorVersion: options.MajorVersion, MinorVersion: options.MinorVersion }
100
+ : await PackageBundleVersionCreate.getPackageVersion(options, project, connection);
101
+ const request = {
102
+ PackageBundleId: packageBundleId,
103
+ VersionName: PackageBundleVersionCreate.getVersionName(options.PackageBundle, version.MajorVersion, version.MinorVersion),
104
+ MajorVersion: version.MajorVersion,
105
+ MinorVersion: version.MinorVersion,
106
+ BundleVersionComponents: JSON.stringify(bundleVersionComponents),
107
+ ...(options.Ancestor ? { Ancestor: options.Ancestor } : {}),
108
+ };
109
+ let createResult;
110
+ try {
111
+ createResult = await connection.tooling.sobject('PkgBundleVersionCreateReq').create(request);
112
+ }
113
+ catch (err) {
114
+ const error = err instanceof Error
115
+ ? err
116
+ : new Error(typeof err === 'string' ? err : messages.getMessage('failedToCreatePackageBundleVersion'));
117
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
118
+ }
119
+ if (!createResult?.success) {
120
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(new Error(messages.getMessage('failedToCreatePackageBundleVersion'))));
121
+ }
122
+ if (options.polling) {
123
+ return packageBundleVersion_1.PackageBundleVersion.pollCreateStatus(createResult.id, connection, project, options.polling);
124
+ }
125
+ return {
126
+ Id: createResult.id,
127
+ PackageBundleVersionId: createResult.id,
128
+ PackageBundleId: packageBundleId,
129
+ VersionName: PackageBundleVersionCreate.getVersionName(options.PackageBundle, version.MajorVersion, version.MinorVersion),
130
+ MajorVersion: version.MajorVersion,
131
+ MinorVersion: version.MinorVersion,
132
+ BundleVersionComponents: JSON.stringify(bundleVersionComponents),
133
+ RequestStatus: interfaces_1.BundleSObjects.PkgBundleVersionCreateReqStatus.success,
134
+ CreatedDate: new Date().toISOString(),
135
+ CreatedById: connection.getUsername() ?? 'unknown',
136
+ };
137
+ }
138
+ static readBundleVersionComponents(filePath, project) {
139
+ try {
140
+ const fileContent = fs.readFileSync(filePath, 'utf8');
141
+ const bundleVersionComponents = JSON.parse(fileContent);
142
+ if (!Array.isArray(bundleVersionComponents)) {
143
+ throw new core_1.SfError(messages.getMessage('bundleVersionComponentsMustBeArray'));
144
+ }
145
+ // Validate that each item has the required packageVersion property
146
+ for (const component of bundleVersionComponents) {
147
+ if (!component || typeof component !== 'object' || !component.packageVersion) {
148
+ throw new core_1.SfError(messages.getMessage('bundleVersionComponentMustBeObject'));
149
+ }
150
+ }
151
+ // Process each component to get the package version ID
152
+ return bundleVersionComponents.map((component) => {
153
+ const packageVersion = component.packageVersion;
154
+ // Check if it's already an ID (04t followed by 15 characters)
155
+ if (/^04t[a-zA-Z0-9]{15}$/.test(packageVersion)) {
156
+ return packageVersion;
157
+ }
158
+ // Otherwise, treat it as an alias and resolve it from sfdx-project.json
159
+ const packageVersionId = project.getPackageIdFromAlias(packageVersion);
160
+ if (!packageVersionId) {
161
+ throw new core_1.SfError(messages.getMessage('noPackageVersionFoundWithAlias', [packageVersion]));
162
+ }
163
+ return packageVersionId;
164
+ });
165
+ }
166
+ catch (err) {
167
+ const error = err instanceof Error ? err : new Error(messages.getMessage('failedToReadBundleVersionComponentsFile'));
168
+ throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
169
+ }
170
+ }
171
+ static getVersionName(packageBundle, majorVersion, minorVersion) {
172
+ return `${packageBundle}@${majorVersion}.${minorVersion}`;
173
+ }
174
+ static parsePackageBundleId(packageBundle, project) {
175
+ if (/^1Fl.{15}$/.test(packageBundle)) {
176
+ return packageBundle;
177
+ }
178
+ const bundleId = project.getPackageBundleIdFromAlias(packageBundle);
179
+ if (!bundleId) {
180
+ throw new core_1.SfError(messages.getMessage('noPackageBundleFoundWithAlias', [packageBundle]));
181
+ }
182
+ return bundleId;
183
+ }
184
+ static async getPackageVersion(options, project, connection) {
185
+ const packageBundleId = PackageBundleVersionCreate.parsePackageBundleId(options.PackageBundle, project);
186
+ const query = `SELECT BundleName FROM PackageBundle WHERE Id = '${packageBundleId}'`;
187
+ const result = await connection.tooling.query(query);
188
+ if (!result.records || result.records.length === 0) {
189
+ throw new core_1.SfError(messages.getMessage('noBundleFoundWithId', [packageBundleId]));
190
+ }
191
+ const bundleName = result.records[0].BundleName;
192
+ const bundles = project.getSfProjectJson().getPackageBundles();
193
+ const bundle = bundles.find((b) => b.name === bundleName);
194
+ if (!bundle) {
195
+ throw new core_1.SfError(messages.getMessage('noBundleFoundWithName', [bundleName]));
196
+ }
197
+ const [major, minor] = bundle.versionNumber.split('.');
198
+ if (!major || !minor) {
199
+ throw new core_1.SfError(messages.getMessage('invalidVersionNumberFormat', [bundle.versionNumber]));
200
+ }
201
+ // Check if major is an integer
202
+ const majorInt = parseInt(major, 10);
203
+ if (isNaN(majorInt) || majorInt.toString() !== major) {
204
+ throw new core_1.SfError(messages.getMessage('invalidVersionNumberFormat', [bundle.versionNumber]));
205
+ }
206
+ // Check if minor is either an integer or "next"
207
+ if (minor === 'NEXT') {
208
+ // Query existing bundle versions to find the highest minor version for this major version
209
+ const bundleVersionQuery = 'SELECT Id, PackageBundle.Id, PackageBundle.BundleName, VersionName, MajorVersion, MinorVersion, IsReleased ' +
210
+ 'FROM PackageBundleVersion ' +
211
+ `WHERE PackageBundle.BundleName = '${bundleName}' AND MajorVersion = ${major} ` +
212
+ 'ORDER BY MinorVersion DESC LIMIT 1';
213
+ const queryResult = await connection.tooling.query(bundleVersionQuery);
214
+ if (queryResult.records && queryResult.records.length > 0) {
215
+ const highestRecord = queryResult.records[0];
216
+ // Get the highest minor version and add 1
217
+ const highestMinorVersion = parseInt(highestRecord.MinorVersion, 10);
218
+ if (isNaN(highestMinorVersion)) {
219
+ throw new core_1.SfError(messages.getMessage('invalidMinorVersionInExisting', [highestRecord.MinorVersion]));
220
+ }
221
+ const nextMinorVersion = (highestMinorVersion + 1).toString();
222
+ return { MajorVersion: major, MinorVersion: nextMinorVersion };
223
+ }
224
+ else {
225
+ // No existing versions found for this major version, start with .0
226
+ return { MajorVersion: major, MinorVersion: '0' };
227
+ }
228
+ }
229
+ else {
230
+ const minorInt = parseInt(minor, 10);
231
+ if (isNaN(minorInt) || minorInt.toString() !== minor) {
232
+ throw new core_1.SfError(messages.getMessage('invalidVersionNumberFormat', [bundle.versionNumber]));
233
+ }
234
+ }
235
+ return { MajorVersion: major, MinorVersion: minor };
236
+ }
237
+ }
238
+ exports.PackageBundleVersionCreate = PackageBundleVersionCreate;
239
+ //# sourceMappingURL=packageBundleVersionCreate.js.map
@@ -0,0 +1 @@
1
+ export declare function massageErrorMessage(err: Error): Error;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.massageErrorMessage = massageErrorMessage;
10
+ const core_1 = require("@salesforce/core");
11
+ core_1.Messages.importMessagesDirectory(__dirname);
12
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_utils');
13
+ function massageErrorMessage(err) {
14
+ if (err.name === 'STRING_TOO_LONG') {
15
+ err['message'] = messages.getMessage('STRING_TOO_LONG');
16
+ }
17
+ return err;
18
+ }
19
+ //# sourceMappingURL=bundleUtils.js.map
@@ -1 +1,2 @@
1
1
  export { INSTALL_URL_BASE, getContainerOptions, getPackageVersionStrings, getPackageVersionNumber, } from './packageUtils';
2
+ export { massageErrorMessage } from './bundleUtils';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageVersionNumber = exports.getPackageVersionStrings = exports.getContainerOptions = exports.INSTALL_URL_BASE = void 0;
3
+ exports.massageErrorMessage = exports.getPackageVersionNumber = exports.getPackageVersionStrings = exports.getContainerOptions = exports.INSTALL_URL_BASE = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -12,4 +12,6 @@ Object.defineProperty(exports, "INSTALL_URL_BASE", { enumerable: true, get: func
12
12
  Object.defineProperty(exports, "getContainerOptions", { enumerable: true, get: function () { return packageUtils_1.getContainerOptions; } });
13
13
  Object.defineProperty(exports, "getPackageVersionStrings", { enumerable: true, get: function () { return packageUtils_1.getPackageVersionStrings; } });
14
14
  Object.defineProperty(exports, "getPackageVersionNumber", { enumerable: true, get: function () { return packageUtils_1.getPackageVersionNumber; } });
15
+ var bundleUtils_1 = require("./bundleUtils");
16
+ Object.defineProperty(exports, "massageErrorMessage", { enumerable: true, get: function () { return bundleUtils_1.massageErrorMessage; } });
15
17
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ # failedToCreatePackageBundle
2
+
3
+ Failed to create package bundle
@@ -0,0 +1,11 @@
1
+ # failedToGetPackageBundleInstallStatus
2
+
3
+ Failed to get package bundle install status
4
+
5
+ # failedToInstallPackageBundle
6
+
7
+ Failed to install package bundle
8
+
9
+ # noPackageBundleVersionFoundWithAlias
10
+
11
+ No package bundle version found with alias: %s
@@ -0,0 +1,7 @@
1
+ # STRING_TOO_LONG
2
+
3
+ Either name or description has exceeded the 255 charector limit.
4
+
5
+ # invalidIdOrAlias
6
+
7
+ The %s : %s isn't defined in the sfdx-project.json. Add it to the packageBundles section and add the alias to packageBundleAliases with its %s ID.
@@ -0,0 +1,3 @@
1
+ # componentRecordMissing
2
+
3
+ Component record is missing
@@ -0,0 +1,47 @@
1
+ # failedToGetPackageBundleVersionCreateStatus
2
+
3
+ Failed to get package bundle version create status
4
+
5
+ # failedToCreatePackageBundleVersion
6
+
7
+ Failed to create package bundle version
8
+
9
+ # bundleVersionComponentsMustBeArray
10
+
11
+ Bundle version components must be an array of objects with packageVersion property
12
+
13
+ # bundleVersionComponentMustBeObject
14
+
15
+ Each bundle version component must be an object with a packageVersion property
16
+
17
+ # noPackageVersionFoundWithAlias
18
+
19
+ No package version found with alias: %s
20
+
21
+ # failedToReadBundleVersionComponentsFile
22
+
23
+ Failed to read or parse bundle version components file
24
+
25
+ # noPackageBundleFoundWithAlias
26
+
27
+ No package bundle found with alias: %s
28
+
29
+ # noBundleFoundWithId
30
+
31
+ No bundle found with id: %s
32
+
33
+ # noBundleFoundWithName
34
+
35
+ No bundle found with name: %s
36
+
37
+ # invalidVersionNumberFormat
38
+
39
+ Invalid version number format: %s
40
+
41
+ # majorVersionMismatch
42
+
43
+ Major version mismatch: expected %s, found %s
44
+
45
+ # invalidMinorVersionInExisting
46
+
47
+ Invalid minor version in existing record: %s
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "Packaging library for the Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -42,10 +42,10 @@
42
42
  "!lib/**/*.map"
43
43
  ],
44
44
  "dependencies": {
45
- "@jsforce/jsforce-node": "^3.6.5",
46
- "@salesforce/core": "^8.18.5",
45
+ "@jsforce/jsforce-node": "^3.10.4",
46
+ "@salesforce/core": "^8.23.0",
47
47
  "@salesforce/kit": "^3.2.3",
48
- "@salesforce/schemas": "^1.9.1",
48
+ "@salesforce/schemas": "^1.10.3",
49
49
  "@salesforce/source-deploy-retrieve": "^12.16.9",
50
50
  "@salesforce/ts-types": "^2.0.11",
51
51
  "@salesforce/types": "^1.2.0",