autoforce 0.1.1

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,261 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import context from "./context.js";
11
+ import jsforce from "jsforce";
12
+ const DEBUG = process.env.DEBUG || false;
13
+ const API_VERSION = "60.0";
14
+ let conn;
15
+ function connect() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const orgObject = context.scratch;
18
+ const accessToken = orgObject.accessToken;
19
+ const instanceUrl = orgObject.instanceUrl;
20
+ if (!(accessToken && instanceUrl)) {
21
+ console.error("Para bajar la metadata la herramienta se loguea a Salesforce con la default org. Verifique sf config get target-org");
22
+ throw new Error("Falta configurar ejecute: yarn auto config");
23
+ }
24
+ if (accessToken && instanceUrl) {
25
+ try {
26
+ conn = new jsforce.Connection({
27
+ instanceUrl,
28
+ accessToken,
29
+ version: API_VERSION
30
+ });
31
+ // const identity = await conn.identity();
32
+ // console.log(identity);
33
+ if (DEBUG) {
34
+ console.log(conn);
35
+ }
36
+ }
37
+ catch (e) {
38
+ if (DEBUG) {
39
+ console.log(e);
40
+ }
41
+ throw `Por favor verifique accessToken y instanceUrl ${accessToken} ${instanceUrl}`;
42
+ }
43
+ }
44
+ // if (username && password) {
45
+ // try {
46
+ // conn = new jsforce.Connection({
47
+ // loginUrl: process.env.SF_LOGINURL || "https://test.salesforce.com",
48
+ // version: API_VERSION
49
+ // });
50
+ // const userInfo = await conn.login(username, password);
51
+ //
52
+ // if (DEBUG) {
53
+ // console.log("accessToken", conn.accessToken);
54
+ // }
55
+ // } catch (e) {
56
+ // if (DEBUG) {
57
+ // console.log(e);
58
+ // }
59
+ // throw `Por favor verifique usuario y password ${username} ${password}`;
60
+ // }
61
+ // }
62
+ });
63
+ }
64
+ function check() {
65
+ return conn.accessToken ? true : false;
66
+ }
67
+ // async function getOmni(fullNames: string[]) {}
68
+ //
69
+ // async function getIP(fullNames: string[]) {}
70
+ function getDependencies(listOfIds) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const up = yield conn.tooling
73
+ .sobject("MetadataComponentDependency")
74
+ .find({ RefMetadataComponentId: listOfIds }, [
75
+ "RefMetadataComponentId",
76
+ "MetadataComponentId",
77
+ "MetadataComponentName",
78
+ "MetadataComponentType"
79
+ ]);
80
+ const down = yield conn.tooling
81
+ .sobject("MetadataComponentDependency")
82
+ .find({ MetadataComponentId: listOfIds }, [
83
+ "MetadataComponentId",
84
+ "RefMetadataComponentId",
85
+ "RefMetadataComponentName",
86
+ "RefMetadataComponentType"
87
+ ]);
88
+ const dependencies = {};
89
+ for (const record of up) {
90
+ const entry = {
91
+ Id: record.MetadataComponentId,
92
+ name: record.MetadataComponentName,
93
+ type: record.MetadataComponentType
94
+ };
95
+ let item = dependencies[record.RefMetadataComponentId];
96
+ if (!item) {
97
+ item = { parents: [], childs: [] };
98
+ }
99
+ item.childs.push(entry);
100
+ }
101
+ for (const record of down) {
102
+ const entry = {
103
+ Id: record.RefMetadataComponentId,
104
+ name: record.RefMetadataComponentName,
105
+ type: record.RefMetadataComponentType
106
+ };
107
+ let item = dependencies[record.MetadataComponentId];
108
+ if (!item) {
109
+ item = { parents: [], childs: [] };
110
+ }
111
+ item.parents.push(entry);
112
+ }
113
+ // console.log(up, down, dependencies);
114
+ return dependencies;
115
+ });
116
+ }
117
+ function expiredSession() {
118
+ console.error("El token de la sesion expiro, puede actualizarlo manualmente corriendo sf org display y copiar el Access Token en el .env ");
119
+ process.exit(-1);
120
+ }
121
+ function getLwc(fullNames) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ /**
124
+ Archivos, JS => JSDoc
125
+ */
126
+ //console.log( JSON.stringify(conn.version) );
127
+ try {
128
+ const bundle = yield conn.tooling
129
+ .sobject("LightningComponentBundle")
130
+ .find({ MasterLabel: fullNames }, [
131
+ "MasterLabel",
132
+ "Language",
133
+ "Metadata",
134
+ "NamespacePrefix",
135
+ "Id"
136
+ ]);
137
+ const listOfIds = bundle.map((item) => item.Id);
138
+ if (listOfIds.length > 0) {
139
+ const listOfResources = yield conn.tooling
140
+ .sobject("LightningComponentResource")
141
+ .find({ LightningComponentBundleId: listOfIds }, [
142
+ "LightningComponentBundleId",
143
+ "Format",
144
+ "FilePath",
145
+ "Source"
146
+ ]);
147
+ // Convierte los resources en un mapa con clave el Id y como valor la lista de sus resources
148
+ const resources = {};
149
+ for (const resource of listOfResources) {
150
+ const lwcId = resource.LightningComponentBundleId;
151
+ if (!resources[lwcId]) {
152
+ resources[lwcId] = [resource];
153
+ }
154
+ else {
155
+ resources[lwcId].push(resource);
156
+ }
157
+ }
158
+ // Saca las dependencias
159
+ const dependencies = yield getDependencies(listOfIds);
160
+ const metadata = bundle.map((item) => {
161
+ return Object.assign({ Name: item.MasterLabel, resources: resources[item.Id], dependencies: dependencies[item.Id] }, item.Metadata);
162
+ });
163
+ return metadata;
164
+ }
165
+ }
166
+ catch (e) {
167
+ if (e instanceof Error) {
168
+ if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
169
+ expiredSession();
170
+ }
171
+ if (DEBUG) {
172
+ console.log(e);
173
+ }
174
+ const msg = (e.name == 'ERROR_HTTP_420') ? 'El accesstoken y el instance url en el .env parece que no coinciden, verifique con sf org display' : `Error buscando metadata de los lwc ${fullNames}. ERR-NAME: ${e.name}`;
175
+ throw msg;
176
+ }
177
+ }
178
+ return [];
179
+ });
180
+ }
181
+ function getClasses(fullNames) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ try {
184
+ // > tooling.sobject('ApexClass').find({ Name: "AsistenciasController" })
185
+ const classNames = fullNames.map((clase) => clase.replace(".cls", ""));
186
+ const metadata = yield conn.tooling
187
+ .sobject("ApexClass")
188
+ .find({ Name: classNames }, [
189
+ "Name",
190
+ "Status",
191
+ "IsValid",
192
+ "ApiVersion",
193
+ "CreatedDate",
194
+ "LastModifiedDate",
195
+ "SymbolTable"
196
+ ]);
197
+ if (DEBUG) {
198
+ console.log(JSON.stringify(metadata));
199
+ }
200
+ return metadata;
201
+ }
202
+ catch (e) {
203
+ if (e instanceof Error) {
204
+ if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
205
+ expiredSession();
206
+ }
207
+ if (DEBUG) {
208
+ console.log(e);
209
+ }
210
+ const msg = (e.name == 'ERROR_HTTP_420') ? 'El accesstoken y el instance url en el .env parece que no coinciden, verifique con sf org display' : `Error buscando metadata de las clases ${fullNames}. ERR-NAME: ${e.name}`;
211
+ throw msg;
212
+ }
213
+ }
214
+ return [];
215
+ });
216
+ }
217
+ function customObjects(fullNames) {
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ try {
220
+ let metadata;
221
+ if (fullNames.length <= 10) {
222
+ metadata = (yield conn.metadata.read("CustomObject", fullNames));
223
+ }
224
+ else {
225
+ metadata = [];
226
+ do {
227
+ const items = fullNames.splice(0, 10);
228
+ const result = yield conn.metadata.read("CustomObject", items);
229
+ metadata = metadata.concat(result);
230
+ } while (fullNames.length > 0);
231
+ }
232
+ if (DEBUG) {
233
+ console.log(JSON.stringify(metadata));
234
+ }
235
+ return metadata;
236
+ }
237
+ catch (e) {
238
+ if (e instanceof Error) {
239
+ if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
240
+ expiredSession();
241
+ }
242
+ if (DEBUG) {
243
+ console.log(e);
244
+ }
245
+ const msg = (e.name == 'ERROR_HTTP_420') ? 'El accesstoken y el instance url en el .env parece que no coinciden, verifique con sf org display' : `Error buscando metadata de los objetos ${fullNames}. ERR-NAME: ${e.name}`;
246
+ throw msg;
247
+ }
248
+ }
249
+ return [];
250
+ });
251
+ }
252
+ export default {
253
+ connect,
254
+ check,
255
+ customObjects,
256
+ getDependencies,
257
+ getClasses,
258
+ getLwc
259
+ };
260
+ // getIP
261
+ // getOmni
@@ -0,0 +1,80 @@
1
+ import type { PromptChoices } from "../types/helpers/context.js";
2
+ import type { IProcessHeader, Processes, AnyValue, IProcessInfo, ObjectRecord, IObjectRecord } from "../types/auto.js";
3
+ import type { TaskArguments, TaskArgument, StepArguments } from "../types/helpers/tasks.js";
4
+ export declare function createConfigurationFile(): Promise<boolean>;
5
+ declare class Context implements IObjectRecord {
6
+ [s: string]: AnyValue | undefined;
7
+ isGitApi: boolean;
8
+ gitApi: IGitApi | undefined;
9
+ projectApi: IProjectApi | undefined;
10
+ sfInstalled: boolean;
11
+ sfToken: boolean;
12
+ branchName: string | undefined;
13
+ issueNumber: number | undefined;
14
+ issueType: string | undefined;
15
+ _process: string | undefined;
16
+ _processesHeader: Record<string, IProcessHeader> | undefined;
17
+ _newIssueNumber: number | undefined;
18
+ _newIssueType: string | undefined;
19
+ newBranchName: string | undefined;
20
+ defaultDias: number;
21
+ permissionSet: string | undefined;
22
+ issueTitle: string | undefined;
23
+ isVerbose: boolean;
24
+ projectPath: string;
25
+ _scratch: OrganizationInfo | undefined;
26
+ _branchScratch: OrganizationInfo | undefined;
27
+ existNewBranch: boolean;
28
+ _targetOrg: string | undefined;
29
+ processes: Processes | undefined;
30
+ salida: string;
31
+ repositoryUrl: string | undefined;
32
+ repositoryType: string | undefined;
33
+ repositoryOwner: string | undefined;
34
+ repositoryRepo: string | undefined;
35
+ projectNumber: number | undefined;
36
+ loadGitApi(): void;
37
+ loadPackage(): void;
38
+ loadConfig(): void;
39
+ init(): void;
40
+ get targetOrg(): string;
41
+ get existBranchScratch(): boolean;
42
+ get branchScratch(): OrganizationInfo | undefined;
43
+ getProcessHeader(fullpath: string): {
44
+ [key: string]: any;
45
+ };
46
+ addProcessMetadata(component: string, items: string[]): void;
47
+ get processesHeader(): Record<string, IProcessHeader>;
48
+ getProcessMetadata(): IProcessInfo[];
49
+ getModules(): string[];
50
+ get modules(): PromptChoices;
51
+ get existScratch(): boolean;
52
+ get scratch(): OrganizationInfo;
53
+ validate(guards: string[]): Promise<void>;
54
+ issueFromBranch(branchName: string): void;
55
+ branchNameFromIssue(issueType: string, issueNumber: number, title?: string): string;
56
+ get isDevelopment(): boolean;
57
+ get isNewDevelopment(): boolean;
58
+ get newIssueNumber(): number | undefined;
59
+ set newIssueNumber(value: number | undefined);
60
+ get newIssueType(): string | undefined;
61
+ set newIssueType(value: string | undefined);
62
+ setNewBranchName(): void;
63
+ askFornewBranchName(): Promise<string | undefined>;
64
+ askFornewIssueNumber(): Promise<any>;
65
+ set process(value: string | undefined);
66
+ getProcessFromTitle(title: string): string | undefined;
67
+ get process(): string | undefined;
68
+ askForprocess(): Promise<any>;
69
+ askFornewIssueType(): Promise<any>;
70
+ convertToArrayOfInputs(inputs: TaskArguments): TaskArgument[];
71
+ askForExit(): Promise<void>;
72
+ mergeArgs(args: StepArguments): StepArguments;
73
+ askForArguments(inputs: TaskArguments): Promise<void>;
74
+ setObject(obj: ObjectRecord): void;
75
+ set(key: keyof IObjectRecord, value: AnyValue): void;
76
+ get(key: string): Promise<AnyValue>;
77
+ merge(text: string): string;
78
+ }
79
+ declare const context: Context;
80
+ export default context;