@salesforce/packaging 0.0.27 → 0.0.30

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/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.30](https://github.com/forcedotcom/packaging/compare/v0.0.29...v0.0.30) (2022-08-29)
6
+
7
+ ### Bug Fixes
8
+
9
+ - add Package.update method, NUT ([dd77095](https://github.com/forcedotcom/packaging/commit/dd77095f77d2224c347d146810f8d0f883bbd9a3))
10
+
11
+ ### [0.0.29](https://github.com/forcedotcom/packaging/compare/v0.0.28...v0.0.29) (2022-08-26)
12
+
13
+ ### Bug Fixes
14
+
15
+ - add PackageVersion.update, NUTs ([af8a816](https://github.com/forcedotcom/packaging/commit/af8a8167d5fbcf7056f7b72db49e4e9f6ed0363f))
16
+
17
+ ### [0.0.28](https://github.com/forcedotcom/packaging/compare/v0.0.27...v0.0.28) (2022-08-26)
18
+
19
+ ### Bug Fixes
20
+
21
+ - finish pvl, implement a few missing things ([9bb825c](https://github.com/forcedotcom/packaging/commit/9bb825c97b6cb8c8b9522ddcb5e5fb32e5653995))
22
+
5
23
  ### [0.0.27](https://github.com/forcedotcom/packaging/compare/v0.0.26...v0.0.27) (2022-08-26)
6
24
 
7
25
  ### Bug Fixes
@@ -14,7 +14,7 @@ export interface IPackage {
14
14
  getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
15
15
  list(): Promise<QueryResult<PackagingSObjects.Package2>>;
16
16
  uninstall(): Promise<void>;
17
- update(): Promise<void>;
17
+ update(options: PackageUpdateOptions): Promise<PackageSaveResult>;
18
18
  waitForPublish(subscriberPackageVersionKey: string, timeout: number | Duration, installationKey?: string): any;
19
19
  getExternalSites(subscriberPackageVersionKey: string, installationKey?: string): any;
20
20
  }
@@ -39,6 +39,12 @@ export interface IPackageVersion2GP {
39
39
  export declare type PackageOptions = {
40
40
  connection: Connection;
41
41
  };
42
+ export declare type PackageUpdateOptions = {
43
+ Id: string;
44
+ Name?: string;
45
+ Description?: string;
46
+ PackageErrorUsername?: string;
47
+ };
42
48
  export declare type PackageIdType = 'PackageId' | 'SubscriberPackageVersionId' | 'PackageInstallRequestId' | 'PackageUninstallRequestId';
43
49
  export declare type PackageVersionOptions1GP = Record<string, unknown>;
44
50
  export declare type PackageVersionCreateRequestResult = {
@@ -147,17 +153,25 @@ export declare type PackageVersionCreateRequest = {
147
153
  CalculateCodeCoverage: boolean;
148
154
  SkipValidation: boolean;
149
155
  };
150
- export declare type PackageVersionQueryOptions = {
151
- project: SfProject;
156
+ export declare type PackageVersionListOptions = {
152
157
  orderBy: string;
153
158
  modifiedLastDays: number;
154
159
  createdLastDays: number;
155
160
  packages: string[];
156
- connection: Connection;
157
161
  verbose: boolean;
158
162
  concise: boolean;
159
163
  isReleased: boolean;
160
164
  };
165
+ export declare type PackageVersionUpdateOptions = {
166
+ InstallKey?: string;
167
+ VersionName?: string;
168
+ VersionDescription?: string;
169
+ Branch?: string;
170
+ Tag?: string;
171
+ };
172
+ export declare type ListPackageVersionOptions = PackageVersionListOptions & {
173
+ connection: Connection;
174
+ };
161
175
  export declare type PackageSaveResult = SaveResult;
162
176
  export declare type PackageVersionCreateRequestOptions = {
163
177
  path: string;
@@ -1,7 +1,7 @@
1
1
  import { AsyncCreatable, Duration } from '@salesforce/kit';
2
2
  import { QueryResult } from 'jsforce';
3
3
  import { Optional } from '@salesforce/ts-types';
4
- import { IPackage, PackageOptions, PackagingSObjects, PackageInstallOptions, PackageInstallCreateRequest, PackageIdType } from '../interfaces';
4
+ import { IPackage, PackageOptions, PackagingSObjects, PackageInstallOptions, PackageInstallCreateRequest, PackageIdType, PackageSaveResult, PackageUpdateOptions } from '../interfaces';
5
5
  declare type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
6
6
  /**
7
7
  * Package class.
@@ -32,7 +32,7 @@ export declare class Package extends AsyncCreatable<PackageOptions> implements I
32
32
  getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
33
33
  list(): Promise<QueryResult<PackagingSObjects.Package2>>;
34
34
  uninstall(): Promise<void>;
35
- update(): Promise<void>;
35
+ update(options: PackageUpdateOptions): Promise<PackageSaveResult>;
36
36
  getPackage(packageId: string): Promise<PackagingSObjects.Package2>;
37
37
  getExternalSites(subscriberPackageVersionId: string, installationKey?: string): Promise<Optional<string[]>>;
38
38
  waitForPublish(subscriberPackageVersionId: string, timeout: number | Duration, installationKey?: string): Promise<void>;
@@ -72,8 +72,14 @@ class Package extends kit_1.AsyncCreatable {
72
72
  uninstall() {
73
73
  return Promise.resolve(undefined);
74
74
  }
75
- update() {
76
- return Promise.resolve(undefined);
75
+ async update(options) {
76
+ // filter out any undefined values and their keys
77
+ Object.keys(options).forEach((key) => options[key] === undefined && delete options[key]);
78
+ const result = await this.options.connection.tooling.update('Package2', options);
79
+ if (!result.success) {
80
+ throw new core_1.SfError(result.errors.join(', '));
81
+ }
82
+ return result;
77
83
  }
78
84
  async getPackage(packageId) {
79
85
  const package2 = await this.options.connection.tooling.sobject('Package2').retrieve(packageId);
@@ -1,5 +1,5 @@
1
1
  import { Duration } from '@salesforce/kit';
2
- import { PackageSaveResult, PackageVersionCreateOptions, PackageVersionCreateRequestResult, PackageVersionOptions, PackageVersionReportResult } from '../interfaces';
2
+ import { PackageSaveResult, PackageVersionCreateOptions, PackageVersionCreateRequestResult, PackageVersionListOptions, PackageVersionListResult, PackageVersionOptions, PackageVersionReportResult, PackageVersionUpdateOptions } from '../interfaces';
3
3
  export declare class PackageVersion {
4
4
  private options;
5
5
  private readonly project;
@@ -56,10 +56,10 @@ export declare class PackageVersion {
56
56
  }): Promise<PackageVersionCreateRequestResult>;
57
57
  convert(): Promise<void>;
58
58
  install(): Promise<void>;
59
- list(): Promise<void>;
59
+ list(options: PackageVersionListOptions): Promise<PackageVersionListResult[]>;
60
60
  uninstall(): Promise<void>;
61
61
  promote(id: string): Promise<PackageSaveResult>;
62
- update(): Promise<void>;
62
+ update(id: string, options: PackageVersionUpdateOptions): Promise<PackageSaveResult>;
63
63
  private updateDeprecation;
64
64
  private updateProjectWithPackageVersion;
65
65
  }
@@ -13,6 +13,7 @@ const utils_1 = require("../utils");
13
13
  const packageVersionCreate_1 = require("./packageVersionCreate");
14
14
  const packageVersionReport_1 = require("./packageVersionReport");
15
15
  const packageVersionCreateRequestReport_1 = require("./packageVersionCreateRequestReport");
16
+ const packageVersionList_1 = require("./packageVersionList");
16
17
  core_1.Messages.importMessagesDirectory(__dirname);
17
18
  class PackageVersion {
18
19
  constructor(options) {
@@ -153,8 +154,8 @@ class PackageVersion {
153
154
  install() {
154
155
  return Promise.resolve(undefined);
155
156
  }
156
- list() {
157
- return Promise.resolve(undefined);
157
+ async list(options) {
158
+ return (await (0, packageVersionList_1.listPackageVersions)({ ...options, ...{ connection: this.connection } })).records;
158
159
  }
159
160
  uninstall() {
160
161
  return Promise.resolve(undefined);
@@ -166,8 +167,28 @@ class PackageVersion {
166
167
  }
167
168
  return await this.options.connection.tooling.update('Package2Version', { IsReleased: true, Id: id });
168
169
  }
169
- update() {
170
- return Promise.resolve(undefined);
170
+ async update(id, options) {
171
+ // ID can be an 04t or 05i
172
+ (0, utils_1.validateId)([utils_1.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, utils_1.BY_LABEL.PACKAGE_VERSION_ID], id);
173
+ // lookup the 05i ID, if needed
174
+ id = await (0, utils_1.getPackageVersionId)(id, this.connection);
175
+ const request = {
176
+ Id: id,
177
+ InstallKey: options.InstallKey,
178
+ Name: options.VersionName,
179
+ Description: options.VersionDescription,
180
+ Branch: options.Branch,
181
+ Tag: options.Tag,
182
+ };
183
+ // filter out any undefined values and their keys
184
+ Object.keys(request).forEach((key) => request[key] === undefined && delete request[key]);
185
+ const result = await this.connection.tooling.update('Package2Version', request);
186
+ if (!result.success) {
187
+ throw new Error(result.errors.join(', '));
188
+ }
189
+ // Use the 04t ID for the success message
190
+ result.id = await (0, utils_1.getSubscriberPackageVersionId)(id, this.connection);
191
+ return result;
171
192
  }
172
193
  async updateDeprecation(idOrAlias, IsDeprecated) {
173
194
  const packageVersionId = (0, utils_1.getPackageIdFromAlias)(idOrAlias, this.project);
@@ -1,9 +1,7 @@
1
- import { SfProject } from '@salesforce/core';
2
1
  import { QueryResult } from 'jsforce';
3
- import { PackageVersionListResult, PackageVersionQueryOptions } from '../interfaces';
2
+ import { PackageVersionListResult, ListPackageVersionOptions } from '../interfaces';
4
3
  export declare const DEFAULT_ORDER_BY_FIELDS = "Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber";
5
- export declare function listPackageVersions(options: PackageVersionQueryOptions): Promise<QueryResult<PackageVersionListResult>>;
6
- export declare function _constructQuery(options: PackageVersionQueryOptions): string;
7
- export declare function _assembleQueryParts(select: string, where: string[], orderBy?: string): string;
8
- export declare function _constructWhere(idsOrAliases: string[], createdLastDays: number, lastModLastDays: number, project: SfProject): string[];
9
- export declare function _getLastDays(paramName: string, lastDays: number): number;
4
+ export declare function listPackageVersions(options: ListPackageVersionOptions): Promise<QueryResult<PackageVersionListResult>>;
5
+ export declare function assembleQueryParts(select: string, where: string[], orderBy?: string): string;
6
+ export declare function constructWhere(packageIds: string[], createdLastDays: number, lastModLastDays: number, isReleased: boolean): string[];
7
+ export declare function validateDays(paramName: string, lastDays: number): number;
@@ -6,7 +6,7 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports._getLastDays = exports._constructWhere = exports._assembleQueryParts = exports._constructQuery = exports.listPackageVersions = exports.DEFAULT_ORDER_BY_FIELDS = void 0;
9
+ exports.validateDays = exports.constructWhere = exports.assembleQueryParts = exports.listPackageVersions = exports.DEFAULT_ORDER_BY_FIELDS = void 0;
10
10
  const core_1 = require("@salesforce/core");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const utils_1 = require("../utils");
@@ -25,67 +25,60 @@ const VERBOSE_SELECT = 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name,
25
25
  exports.DEFAULT_ORDER_BY_FIELDS = 'Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber';
26
26
  const logger = core_1.Logger.childFromRoot('packageVersionList');
27
27
  async function listPackageVersions(options) {
28
- return options.connection.tooling.query(_constructQuery(options));
28
+ return options.connection.tooling.query(constructQuery(options));
29
29
  }
30
30
  exports.listPackageVersions = listPackageVersions;
31
- function _constructQuery(options) {
31
+ function constructQuery(options) {
32
32
  // construct custom WHERE clause, if applicable
33
- const where = _constructWhere(options.packages, options.createdLastDays, options.modifiedLastDays, options.project);
34
- if (options.isReleased) {
35
- where.push('IsReleased = true');
36
- }
37
- return _assembleQueryParts(options.verbose === true ? VERBOSE_SELECT : DEFAULT_SELECT, where, options.orderBy);
33
+ const where = constructWhere(options.packages, options.createdLastDays, options.modifiedLastDays, options.isReleased);
34
+ return assembleQueryParts(options.verbose === true ? VERBOSE_SELECT : DEFAULT_SELECT, where, options.orderBy);
38
35
  }
39
- exports._constructQuery = _constructQuery;
40
- function _assembleQueryParts(select, where, orderBy = exports.DEFAULT_ORDER_BY_FIELDS) {
36
+ function assembleQueryParts(select, where, orderBy) {
41
37
  // construct ORDER BY clause
42
- // TODO: validate given fields
43
38
  const orderByPart = `ORDER BY ${orderBy ? orderBy : exports.DEFAULT_ORDER_BY_FIELDS}`;
44
39
  const wherePart = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
45
40
  const query = `${select} ${wherePart} ${orderByPart}`;
46
41
  logger.debug(query);
47
42
  return query;
48
43
  }
49
- exports._assembleQueryParts = _assembleQueryParts;
44
+ exports.assembleQueryParts = assembleQueryParts;
50
45
  // construct custom WHERE clause parts
51
- function _constructWhere(idsOrAliases, createdLastDays, lastModLastDays, project) {
46
+ function constructWhere(packageIds, createdLastDays, lastModLastDays, isReleased) {
52
47
  const where = [];
53
48
  // filter on given package ids
54
- if (idsOrAliases?.length > 0) {
49
+ if (packageIds?.length > 0) {
55
50
  // remove dups
56
- const aliasesOrIds = [...new Set(idsOrAliases)];
57
- // resolve any aliases
58
- const packageIds = aliasesOrIds.map((idOrAlias) => (0, utils_1.getPackageIdFromAlias)(idOrAlias, project));
51
+ const uniquePackageIds = [...new Set(packageIds)];
59
52
  // validate ids
60
- packageIds.forEach((packageId) => {
53
+ uniquePackageIds.forEach((packageId) => {
61
54
  (0, utils_1.validateId)(utils_1.BY_LABEL.PACKAGE_ID, packageId);
62
55
  });
63
56
  // stash where part
64
- where.push(`Package2Id IN ('${packageIds.join("','")}')`);
57
+ where.push(`Package2Id IN ('${uniquePackageIds.join("','")}')`);
65
58
  }
66
59
  // filter on created date, days ago: 0 for today, etc
67
60
  if ((0, ts_types_1.isNumber)(createdLastDays)) {
68
- createdLastDays = _getLastDays('createdlastdays', createdLastDays);
61
+ createdLastDays = validateDays('createdlastdays', createdLastDays);
69
62
  where.push(`CreatedDate = LAST_N_DAYS:${createdLastDays}`);
70
63
  }
71
64
  // filter on last mod date, days ago: 0 for today, etc
72
65
  if ((0, ts_types_1.isNumber)(lastModLastDays)) {
73
- lastModLastDays = _getLastDays('modifiedlastdays', lastModLastDays);
66
+ lastModLastDays = validateDays('modifiedlastdays', lastModLastDays);
74
67
  where.push(`LastModifiedDate = LAST_N_DAYS:${lastModLastDays}`);
75
68
  }
69
+ if (isReleased) {
70
+ where.push('IsReleased = true');
71
+ }
76
72
  // exclude deleted
77
73
  where.push('IsDeprecated = false');
78
74
  return where;
79
75
  }
80
- exports._constructWhere = _constructWhere;
81
- function _getLastDays(paramName, lastDays) {
82
- if (isNaN(lastDays)) {
83
- return 0;
84
- }
76
+ exports.constructWhere = constructWhere;
77
+ function validateDays(paramName, lastDays) {
85
78
  if (lastDays < 0) {
86
79
  throw messages.createError('invalidDaysNumber', [paramName, `${lastDays}`]);
87
80
  }
88
81
  return lastDays;
89
82
  }
90
- exports._getLastDays = _getLastDays;
83
+ exports.validateDays = validateDays;
91
84
  //# sourceMappingURL=packageVersionList.js.map
@@ -324,7 +324,9 @@ async function getPackageVersionStrings(subscriberPackageVersionIds, connection)
324
324
  }
325
325
  // remove any duplicate Ids
326
326
  const ids = [...new Set(subscriberPackageVersionIds)];
327
- const query = 'SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN (%IDS%)';
327
+ const query = `SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN (${ids
328
+ .map((id) => `'${id}'`)
329
+ .join(',')})`;
328
330
  const records = await queryWithInConditionChunking(query, ids, '%IDS%', connection);
329
331
  if (records && records.length > 0) {
330
332
  results = new Map(records.map((record) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "0.0.27",
3
+ "version": "0.0.30",
4
4
  "description": "packing libraries to Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",