@salesforce/packaging 0.0.2 → 0.0.5

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.
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, 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._getLastDays = exports._constructWhere = exports._assembleQueryParts = exports._constructQuery = exports.listPackageVersions = exports.DEFAULT_ORDER_BY_FIELDS = void 0;
10
+ const _ = require("lodash");
11
+ const core_1 = require("@salesforce/core");
12
+ core_1.Messages.importMessagesDirectory(__dirname);
13
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'messages');
14
+ const ts_types_1 = require("@salesforce/ts-types");
15
+ const utils_1 = require("../utils");
16
+ // Stripping CodeCoverage, HasPassedCodeCoverageCheck as they are causing a perf issue in 47.0+ W-6997762
17
+ const DEFAULT_SELECT = 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name, Package2.Name, Package2.NamespacePrefix, ' +
18
+ 'Description, Tag, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber, IsReleased, ' +
19
+ 'CreatedDate, LastModifiedDate, IsPasswordProtected, AncestorId, ValidationSkipped, CreatedById ' +
20
+ 'FROM Package2Version';
21
+ const VERBOSE_SELECT = 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name, Package2.Name, Package2.NamespacePrefix, ' +
22
+ 'Description, Tag, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber, IsReleased, ' +
23
+ 'CreatedDate, LastModifiedDate, IsPasswordProtected, CodeCoverage, HasPassedCodeCoverageCheck, AncestorId, ValidationSkipped, ' +
24
+ 'ConvertedFromVersionId, Package2.IsOrgDependent, ReleaseVersion, BuildDurationInSeconds, HasMetadataRemoved, CreatedById ' +
25
+ 'FROM Package2Version';
26
+ exports.DEFAULT_ORDER_BY_FIELDS = 'Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber';
27
+ const logger = core_1.Logger.childFromRoot('packageVersionList');
28
+ async function listPackageVersions(options) {
29
+ return options.connection.tooling.query(_constructQuery(options));
30
+ }
31
+ exports.listPackageVersions = listPackageVersions;
32
+ function _constructQuery(options) {
33
+ // construct custom WHERE clause, if applicable
34
+ const where = _constructWhere(options.packages, options.createdLastDays, options.modifiedLastDays, options.project);
35
+ if (options.isReleased) {
36
+ where.push('IsReleased = true');
37
+ }
38
+ return _assembleQueryParts(options.verbose === true ? VERBOSE_SELECT : DEFAULT_SELECT, where, options.orderBy);
39
+ }
40
+ exports._constructQuery = _constructQuery;
41
+ function _assembleQueryParts(select, where, orderBy = exports.DEFAULT_ORDER_BY_FIELDS) {
42
+ // construct ORDER BY clause
43
+ // TODO: validate given fields
44
+ const orderByPart = `ORDER BY ${orderBy ? orderBy : exports.DEFAULT_ORDER_BY_FIELDS}`;
45
+ const wherePart = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
46
+ const query = `${select} ${wherePart} ${orderByPart}`;
47
+ logger.debug(query);
48
+ return query;
49
+ }
50
+ exports._assembleQueryParts = _assembleQueryParts;
51
+ // construct custom WHERE clause parts
52
+ function _constructWhere(idsOrAliases, createdLastDays, lastModLastDays, project) {
53
+ const where = [];
54
+ // filter on given package ids
55
+ if ((idsOrAliases === null || idsOrAliases === void 0 ? void 0 : idsOrAliases.length) > 0) {
56
+ // remove dups
57
+ idsOrAliases = _.uniq(idsOrAliases);
58
+ // resolve any aliases
59
+ const packageIds = idsOrAliases.map((idOrAlias) => (0, utils_1.getPackageIdFromAlias)(idOrAlias, project));
60
+ // validate ids
61
+ packageIds.forEach((packageId) => {
62
+ (0, utils_1.validateId)(utils_1.BY_LABEL.PACKAGE_ID, packageId);
63
+ });
64
+ // stash where part
65
+ where.push(`Package2Id IN ('${packageIds.join("','")}')`);
66
+ }
67
+ // filter on created date, days ago: 0 for today, etc
68
+ if ((0, ts_types_1.isNumber)(createdLastDays)) {
69
+ createdLastDays = _getLastDays('createdlastdays', createdLastDays);
70
+ where.push(`CreatedDate = LAST_N_DAYS:${createdLastDays}`);
71
+ }
72
+ // filter on last mod date, days ago: 0 for today, etc
73
+ if ((0, ts_types_1.isNumber)(lastModLastDays)) {
74
+ lastModLastDays = _getLastDays('modifiedlastdays', lastModLastDays);
75
+ where.push(`LastModifiedDate = LAST_N_DAYS:${lastModLastDays}`);
76
+ }
77
+ // exclude deleted
78
+ where.push('IsDeprecated = false');
79
+ return where;
80
+ }
81
+ exports._constructWhere = _constructWhere;
82
+ function _getLastDays(paramName, lastDays) {
83
+ if (isNaN(lastDays)) {
84
+ return 0;
85
+ }
86
+ if (lastDays < 0) {
87
+ throw messages.createError('invalidDaysNumber', [paramName, `${lastDays}`]);
88
+ }
89
+ return lastDays;
90
+ }
91
+ exports._getLastDays = _getLastDays;
92
+ //# sourceMappingURL=packageVersionList.js.map
@@ -1 +1 @@
1
- export * from './package1Version';
1
+ export * from './packageVersion1GP';
@@ -20,5 +20,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  * Licensed under the BSD 3-Clause license.
21
21
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
22
22
  */
23
- __exportStar(require("./package1Version"), exports);
23
+ __exportStar(require("./packageVersion1GP"), exports);
24
24
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,11 @@
1
1
  import { AsyncCreatable } from '@salesforce/kit';
2
- import { IPackage1Version, PackageVersion1Options } from '../interfaces';
2
+ import { IPackageVersion1GP, PackageVersionOptions1GP } from '../interfaces';
3
3
  /**
4
4
  * Package1Version class - Class to be used with 1st generation package versions
5
5
  */
6
- export declare class Package1Version extends AsyncCreatable<PackageVersion1Options> implements IPackage1Version {
6
+ export declare class PackageVersion1GP extends AsyncCreatable<PackageVersionOptions1GP> implements IPackageVersion1GP {
7
7
  private options;
8
- constructor(options: PackageVersion1Options);
8
+ constructor(options: PackageVersionOptions1GP);
9
9
  convert(): Promise<void>;
10
10
  create(): Promise<void>;
11
11
  delete(): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Package1Version = void 0;
3
+ exports.PackageVersion1GP = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
11
11
  /**
12
12
  * Package1Version class - Class to be used with 1st generation package versions
13
13
  */
14
- class Package1Version extends kit_1.AsyncCreatable {
14
+ class PackageVersion1GP extends kit_1.AsyncCreatable {
15
15
  // @ts-ignore
16
16
  constructor(options) {
17
17
  super(options);
@@ -42,5 +42,5 @@ class Package1Version extends kit_1.AsyncCreatable {
42
42
  return Promise.resolve(undefined);
43
43
  }
44
44
  }
45
- exports.Package1Version = Package1Version;
46
- //# sourceMappingURL=package1Version.js.map
45
+ exports.PackageVersion1GP = PackageVersion1GP;
46
+ //# sourceMappingURL=packageVersion1GP.js.map
@@ -0,0 +1 @@
1
+ export * from './packageUtils';
@@ -0,0 +1,24 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (c) 2022, salesforce.com, inc.
19
+ * All rights reserved.
20
+ * Licensed under the BSD 3-Clause license.
21
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
22
+ */
23
+ __exportStar(require("./packageUtils"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,152 @@
1
+ import { Connection, NamedPackageDir, PackageDir, SfProject } from '@salesforce/core';
2
+ import { Duration } from '@salesforce/kit';
3
+ import { Many } from '@salesforce/ts-types';
4
+ import { PackagingSObjects, Package2VersionCreateRequestResult } from '../interfaces';
5
+ import { PackageVersionCreateRequestApi } from '../package/packageVersionCreateRequestApi';
6
+ export declare const VERSION_NUMBER_SEP = ".";
7
+ export declare type IdRegistryValue = {
8
+ prefix: string;
9
+ label: string;
10
+ };
11
+ export declare type IdRegistry = {
12
+ [key: string]: IdRegistryValue;
13
+ };
14
+ export declare const INSTALL_URL_BASE = "https://login.salesforce.com/packaging/installPackage.apexp?p0=";
15
+ export declare const SOQL_WHERE_CLAUSE_MAX_LENGTH = 4000;
16
+ export declare const POLL_INTERVAL_SECONDS = 30;
17
+ export declare const DEFAULT_PACKAGE_DIR: {
18
+ path: string;
19
+ package: string;
20
+ versionName: string;
21
+ versionNumber: string;
22
+ default: boolean;
23
+ };
24
+ export declare const BY_PREFIX: IdRegistry;
25
+ export declare const BY_LABEL: IdRegistry;
26
+ export declare function validateId(idObj: Many<IdRegistryValue>, value: string): void;
27
+ export declare function validateIdNoThrow(idObj: Many<IdRegistryValue>, value: any): any;
28
+ export declare function validateVersionNumber(versionNumberString: string, supportedBuildNumberToken: string, supportedBuildNumberToken2: string): string;
29
+ export declare function validatePatchVersion(connection: Connection, versionNumberString: string, packageId: string): Promise<void>;
30
+ export declare function validUrl(url: string): boolean;
31
+ export declare function isErrorFromSPVQueryRestriction(err: Error): boolean;
32
+ export declare function isErrorPackageNotAvailable(err: Error): boolean;
33
+ export declare function massageErrorMessage(err: Error): Error;
34
+ export declare function applyErrorAction(err: Error): Error;
35
+ /**
36
+ * Given a subscriber package version ID (04t) or package version ID (05i), return the package version ID (05i)
37
+ *
38
+ * @param versionId The subscriber package version ID
39
+ * @param connection For tooling query
40
+ */
41
+ export declare function getPackageVersionId(versionId: string, connection: Connection): Promise<string>;
42
+ /**
43
+ * Given 0Ho the package type type (Managed, Unlocked, Locked(deprecated?))
44
+ *
45
+ * @param package2Id the 0Ho
46
+ * @param connection For tooling query
47
+ * @throws Error with message when package2 cannot be found
48
+ */
49
+ export declare function getPackage2Type(package2Id: string, connection: Connection): Promise<string>;
50
+ /**
51
+ * Given 04t the package type type (Managed, Unlocked, Locked(deprecated?))
52
+ *
53
+ * @param package2VersionId the 04t
54
+ * @param connection For tooling query
55
+ * @param installKey For tooling query, if an installation key is applicable to the package version it must be passed in the queries
56
+ * @throws Error with message when package2 cannot be found
57
+ */
58
+ export declare function getPackage2TypeBy04t(package2VersionId: string, connection: Connection, installKey: string): Promise<string>;
59
+ /**
60
+ * Given a package version ID (05i) or subscriber package version ID (04t), return the subscriber package version ID (04t)
61
+ *
62
+ * @param versionId The suscriber package version ID
63
+ * @param connection For tooling query
64
+ */
65
+ export declare function getSubscriberPackageVersionId(versionId: string, connection: Connection): Promise<string>;
66
+ /**
67
+ * Get the ContainerOptions for the specified Package2 (0Ho) IDs.
68
+ *
69
+ * @return Map of 0Ho id to container option api value
70
+ * @param package2Ids The list of package IDs
71
+ * @param connection For tooling query
72
+ */
73
+ export declare function getContainerOptions(package2Ids: string[], connection: Connection): Promise<Map<string, string>>;
74
+ /**
75
+ * Return the Package2Version.HasMetadataRemoved field value for the given Id (05i)
76
+ *
77
+ * @param packageVersionId package version ID (05i)
78
+ * @param connection For tooling query
79
+ */
80
+ export declare function getHasMetadataRemoved(packageVersionId: string, connection: Connection): Promise<boolean>;
81
+ /**
82
+ * Given a list of subscriber package version IDs (04t), return the associated version strings (e.g., Major.Minor.Patch.Build)
83
+ *
84
+ * @return Map of subscriberPackageVersionId to versionString
85
+ * @param subscriberPackageVersionIds
86
+ * @param connection For tooling query
87
+ */
88
+ export declare function getPackageVersionStrings(subscriberPackageVersionIds: string[], connection: Connection): Promise<Map<string, string>>;
89
+ /**
90
+ * For queries with an IN condition, determine if the WHERE clause will exceed
91
+ * SOQL's 4000 character limit. Perform multiple queries as needed to stay below the limit.
92
+ *
93
+ * @return concatenated array of records returned from the resulting query(ies)
94
+ * @param query The full query to execute containing the replaceToken param in its IN clause
95
+ * @param items The IN clause items. A length-appropriate single-quoted comma-separated string chunk will be made from the items.
96
+ * @param replaceToken A placeholder in the query's IN condition that will be replaced with the chunked items
97
+ * @param connection For tooling query
98
+ */
99
+ export declare function queryWithInConditionChunking<T = Record<string, unknown>>(query: string, items: string[], replaceToken: string, connection: Connection): Promise<T[]>;
100
+ /**
101
+ * Returns the number of items that can be included in a quoted comma-separated string (e.g., "'item1','item2'") not exceeding maxLength
102
+ */
103
+ export declare function getInClauseItemsCount(items: string[], startIndex: number, maxLength: number): number;
104
+ /**
105
+ * Given a package descriptor, return the ancestor ID. This code was duplicated to scratchOrgInfoGenerator.getAncestorIds,
106
+ * changes here may need to be duplicated there until that code, and/or this code is moved to a separate plugin.
107
+ *
108
+ * @param packageDescriptorJson JSON for packageDirectories element in sfdx-project.json
109
+ * @param connection For tooling query
110
+ * @param project The project to use for looking up the ancestor ID
111
+ * @param versionNumberString The version number string to use for looking up the ancestor ID
112
+ * @param skipAncestorCheck If true, skip the check for the ancestor ID
113
+ */
114
+ export declare function getAncestorId(packageDescriptorJson: PackageDir, connection: Connection, project: SfProject, versionNumberString: string, skipAncestorCheck: boolean): Promise<string>;
115
+ export declare function validateAncestorId(ancestorId: string, highestReleasedVersion: PackagingSObjects.Package2Version, explicitUseNoAncestor: boolean, isPatch: boolean, skipAncestorCheck: boolean, origSpecifiedAncestor: string): string;
116
+ export declare function getAncestorIdHighestRelease(connection: Connection, packageId: string, versionNumberString: string, explicitUseHighestRelease: boolean, skipAncestorCheck: boolean): Promise<{
117
+ finalAncestorId: string;
118
+ highestReleasedVersion: PackagingSObjects.Package2Version;
119
+ }>;
120
+ /**
121
+ * Return a version string in Major.Minor.Patch.Build format, using 0 for any empty part
122
+ */
123
+ export declare function concatVersion(major: string | number, minor: string | number, patch: string | number, build: string | number): string;
124
+ export declare function getPackage2VersionNumber(package2VersionObj: PackagingSObjects.Package2Version): string;
125
+ export declare function getConfigPackageDirectories(project: SfProject): PackageDir[];
126
+ export declare function getConfigPackageDirectory(packageDirs: NamedPackageDir[], lookupProperty: string, lookupValue: unknown): NamedPackageDir | undefined;
127
+ /**
128
+ * Given a packageAlias, attempt to return the associated id from the config
129
+ *
130
+ * @param packageAlias string representing a package alias
131
+ * @param project for obtaining the project config
132
+ * @returns the associated id or the arg given.
133
+ */
134
+ export declare function getPackageIdFromAlias(packageAlias: string, project: SfProject): string;
135
+ /**
136
+ * @param stringIn pascal or camel case string
137
+ * @returns space delimited and lower-cased (except for 1st char) string (e.g. in "AbcdEfghIj" => "Abcd efgh ij")
138
+ */
139
+ export declare function convertCamelCaseStringToSentence(stringIn: string): string;
140
+ /**
141
+ * Given a package id, attempt to return the associated aliases from the config
142
+ *
143
+ * @param packageId string representing a package id
144
+ * @param project for obtaining the project config
145
+ * @returns an array of alias for the given id.
146
+ */
147
+ export declare function getPackageAliasesFromId(packageId: string, project: SfProject): string[];
148
+ export declare function findOrCreatePackage2(seedPackage: string, connection: Connection): Promise<string>;
149
+ export declare function _getPackageVersionCreateRequestApi(connection: Connection): PackageVersionCreateRequestApi;
150
+ export declare function pollForStatusWithInterval(context: any, id: string, retries: number, packageId: string, branch: string, withProject: SfProject, connection: Connection, interval: Duration): Promise<Package2VersionCreateRequestResult>;
151
+ export declare function getSoqlWhereClauseMaxLength(): number;
152
+ export declare function formatDate(date: Date): string;