autoforce 0.1.18 → 0.1.20
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/.autoforce.json +1 -1
- package/CHANGELOG.md +10 -0
- package/lib/auto.js +47 -61
- package/lib/helpers/class.d.ts +1 -0
- package/lib/helpers/class.js +65 -78
- package/lib/helpers/connect.js +199 -213
- package/lib/helpers/context.d.ts +1 -1
- package/lib/helpers/context.js +275 -220
- package/lib/helpers/github-graphql.js +90 -113
- package/lib/helpers/github-project-graphql.js +100 -132
- package/lib/helpers/gitlab-graphql.js +68 -104
- package/lib/helpers/lwc.js +33 -46
- package/lib/helpers/object.js +38 -53
- package/lib/helpers/openai.js +10 -22
- package/lib/helpers/taskFunctions.js +328 -384
- package/lib/helpers/tasks.d.ts +1 -1
- package/lib/helpers/tasks.js +99 -119
- package/lib/helpers/template.js +4 -0
- package/lib/helpers/util.d.ts +2 -3
- package/lib/helpers/util.js +109 -162
- package/package.json +15 -10
package/lib/helpers/connect.js
CHANGED
@@ -1,65 +1,54 @@
|
|
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
1
|
import context from "./context.js";
|
11
2
|
import jsforce from "jsforce";
|
12
3
|
const DEBUG = process.env.DEBUG || false;
|
13
4
|
const API_VERSION = "60.0";
|
14
5
|
let conn;
|
15
|
-
function connect() {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
console.log(conn);
|
35
|
-
}
|
6
|
+
async function connect() {
|
7
|
+
const orgObject = context.scratch;
|
8
|
+
const accessToken = orgObject.accessToken;
|
9
|
+
const instanceUrl = orgObject.instanceUrl;
|
10
|
+
if (!(accessToken && instanceUrl)) {
|
11
|
+
console.error("Para bajar la metadata la herramienta se loguea a Salesforce con la default org. Verifique sf config get target-org");
|
12
|
+
throw new Error("Falta configurar ejecute: yarn auto config");
|
13
|
+
}
|
14
|
+
if (accessToken && instanceUrl) {
|
15
|
+
try {
|
16
|
+
conn = new jsforce.Connection({
|
17
|
+
instanceUrl,
|
18
|
+
accessToken,
|
19
|
+
version: API_VERSION
|
20
|
+
});
|
21
|
+
// const identity = await conn.identity();
|
22
|
+
// console.log(identity);
|
23
|
+
if (DEBUG) {
|
24
|
+
console.log(conn);
|
36
25
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
throw `Por favor verifique accessToken y instanceUrl ${accessToken} ${instanceUrl}`;
|
26
|
+
}
|
27
|
+
catch (e) {
|
28
|
+
if (DEBUG) {
|
29
|
+
console.log(e);
|
42
30
|
}
|
31
|
+
throw `Por favor verifique accessToken y instanceUrl ${accessToken} ${instanceUrl}`;
|
43
32
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
}
|
33
|
+
}
|
34
|
+
// if (username && password) {
|
35
|
+
// try {
|
36
|
+
// conn = new jsforce.Connection({
|
37
|
+
// loginUrl: process.env.SF_LOGINURL || "https://test.salesforce.com",
|
38
|
+
// version: API_VERSION
|
39
|
+
// });
|
40
|
+
// const userInfo = await conn.login(username, password);
|
41
|
+
//
|
42
|
+
// if (DEBUG) {
|
43
|
+
// console.log("accessToken", conn.accessToken);
|
44
|
+
// }
|
45
|
+
// } catch (e) {
|
46
|
+
// if (DEBUG) {
|
47
|
+
// console.log(e);
|
48
|
+
// }
|
49
|
+
// throw `Por favor verifique usuario y password ${username} ${password}`;
|
50
|
+
// }
|
51
|
+
// }
|
63
52
|
}
|
64
53
|
function check() {
|
65
54
|
return conn.accessToken ? true : false;
|
@@ -67,187 +56,184 @@ function check() {
|
|
67
56
|
// async function getOmni(fullNames: string[]) {}
|
68
57
|
//
|
69
58
|
// async function getIP(fullNames: string[]) {}
|
70
|
-
function getDependencies(listOfIds) {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
item = { parents: [], childs: [] };
|
98
|
-
}
|
99
|
-
item.childs.push(entry);
|
59
|
+
async function getDependencies(listOfIds) {
|
60
|
+
const up = await conn.tooling
|
61
|
+
.sobject("MetadataComponentDependency")
|
62
|
+
.find({ RefMetadataComponentId: listOfIds }, [
|
63
|
+
"RefMetadataComponentId",
|
64
|
+
"MetadataComponentId",
|
65
|
+
"MetadataComponentName",
|
66
|
+
"MetadataComponentType"
|
67
|
+
]);
|
68
|
+
const down = await conn.tooling
|
69
|
+
.sobject("MetadataComponentDependency")
|
70
|
+
.find({ MetadataComponentId: listOfIds }, [
|
71
|
+
"MetadataComponentId",
|
72
|
+
"RefMetadataComponentId",
|
73
|
+
"RefMetadataComponentName",
|
74
|
+
"RefMetadataComponentType"
|
75
|
+
]);
|
76
|
+
const dependencies = {};
|
77
|
+
for (const record of up) {
|
78
|
+
const entry = {
|
79
|
+
Id: record.MetadataComponentId,
|
80
|
+
name: record.MetadataComponentName,
|
81
|
+
type: record.MetadataComponentType
|
82
|
+
};
|
83
|
+
let item = dependencies[record.RefMetadataComponentId];
|
84
|
+
if (!item) {
|
85
|
+
item = { parents: [], childs: [] };
|
100
86
|
}
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
item
|
87
|
+
item.childs.push(entry);
|
88
|
+
}
|
89
|
+
for (const record of down) {
|
90
|
+
const entry = {
|
91
|
+
Id: record.RefMetadataComponentId,
|
92
|
+
name: record.RefMetadataComponentName,
|
93
|
+
type: record.RefMetadataComponentType
|
94
|
+
};
|
95
|
+
let item = dependencies[record.MetadataComponentId];
|
96
|
+
if (!item) {
|
97
|
+
item = { parents: [], childs: [] };
|
112
98
|
}
|
113
|
-
|
114
|
-
|
115
|
-
|
99
|
+
item.parents.push(entry);
|
100
|
+
}
|
101
|
+
// console.log(up, down, dependencies);
|
102
|
+
return dependencies;
|
116
103
|
}
|
117
104
|
function expiredSession() {
|
118
105
|
console.error("El token de la sesion expiro, puede actualizarlo manualmente corriendo sf org display y copiar el Access Token en el .env ");
|
119
106
|
process.exit(-1);
|
120
107
|
}
|
121
|
-
function getLwc(fullNames) {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
108
|
+
async function getLwc(fullNames) {
|
109
|
+
/**
|
110
|
+
Archivos, JS => JSDoc
|
111
|
+
*/
|
112
|
+
//console.log( JSON.stringify(conn.version) );
|
113
|
+
try {
|
114
|
+
const bundle = await conn.tooling
|
115
|
+
.sobject("LightningComponentBundle")
|
116
|
+
.find({ MasterLabel: fullNames }, [
|
117
|
+
"MasterLabel",
|
118
|
+
"Language",
|
119
|
+
"Metadata",
|
120
|
+
"NamespacePrefix",
|
121
|
+
"Id"
|
122
|
+
]);
|
123
|
+
const listOfIds = bundle.map((item) => item.Id);
|
124
|
+
if (listOfIds.length > 0) {
|
125
|
+
const listOfResources = await conn.tooling
|
126
|
+
.sobject("LightningComponentResource")
|
127
|
+
.find({ LightningComponentBundleId: listOfIds }, [
|
128
|
+
"LightningComponentBundleId",
|
129
|
+
"Format",
|
130
|
+
"FilePath",
|
131
|
+
"Source"
|
136
132
|
]);
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
}
|
133
|
+
// Convierte los resources en un mapa con clave el Id y como valor la lista de sus resources
|
134
|
+
const resources = {};
|
135
|
+
for (const resource of listOfResources) {
|
136
|
+
const lwcId = resource.LightningComponentBundleId;
|
137
|
+
if (!resources[lwcId]) {
|
138
|
+
resources[lwcId] = [resource];
|
157
139
|
}
|
158
|
-
|
159
|
-
|
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);
|
140
|
+
else {
|
141
|
+
resources[lwcId].push(resource);
|
173
142
|
}
|
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
143
|
}
|
144
|
+
// Saca las dependencias
|
145
|
+
const dependencies = await getDependencies(listOfIds);
|
146
|
+
const metadata = bundle.map((item) => {
|
147
|
+
return {
|
148
|
+
Name: item.MasterLabel,
|
149
|
+
resources: resources[item.Id],
|
150
|
+
dependencies: dependencies[item.Id],
|
151
|
+
...item.Metadata
|
152
|
+
};
|
153
|
+
});
|
200
154
|
return metadata;
|
201
155
|
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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;
|
156
|
+
}
|
157
|
+
catch (e) {
|
158
|
+
if (e instanceof Error) {
|
159
|
+
if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
|
160
|
+
expiredSession();
|
212
161
|
}
|
162
|
+
if (DEBUG) {
|
163
|
+
console.log(e);
|
164
|
+
}
|
165
|
+
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}`;
|
166
|
+
throw msg;
|
213
167
|
}
|
214
|
-
|
215
|
-
|
168
|
+
}
|
169
|
+
return [];
|
216
170
|
}
|
217
|
-
function
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
171
|
+
async function getClasses(fullNames) {
|
172
|
+
try {
|
173
|
+
// > tooling.sobject('ApexClass').find({ Name: "AsistenciasController" })
|
174
|
+
const classNames = fullNames.map((clase) => clase.replace(".cls", ""));
|
175
|
+
const metadata = await conn.tooling
|
176
|
+
.sobject("ApexClass")
|
177
|
+
.find({ Name: classNames }, [
|
178
|
+
"Name",
|
179
|
+
"Status",
|
180
|
+
"IsValid",
|
181
|
+
"ApiVersion",
|
182
|
+
"CreatedDate",
|
183
|
+
"LastModifiedDate",
|
184
|
+
"SymbolTable"
|
185
|
+
]);
|
186
|
+
if (DEBUG) {
|
187
|
+
console.log(JSON.stringify(metadata));
|
188
|
+
}
|
189
|
+
return metadata;
|
190
|
+
}
|
191
|
+
catch (e) {
|
192
|
+
if (e instanceof Error) {
|
193
|
+
if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
|
194
|
+
expiredSession();
|
231
195
|
}
|
232
196
|
if (DEBUG) {
|
233
|
-
console.log(
|
197
|
+
console.log(e);
|
234
198
|
}
|
235
|
-
|
199
|
+
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}`;
|
200
|
+
throw msg;
|
236
201
|
}
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
202
|
+
}
|
203
|
+
return [];
|
204
|
+
}
|
205
|
+
async function customObjects(fullNames) {
|
206
|
+
try {
|
207
|
+
let metadata;
|
208
|
+
if (fullNames.length <= 10) {
|
209
|
+
metadata = await conn.metadata.read("CustomObject", fullNames);
|
210
|
+
}
|
211
|
+
else {
|
212
|
+
metadata = [];
|
213
|
+
do {
|
214
|
+
const items = fullNames.splice(0, 10);
|
215
|
+
const result = await conn.metadata.read("CustomObject", items);
|
216
|
+
metadata = metadata.concat(result);
|
217
|
+
} while (fullNames.length > 0);
|
218
|
+
}
|
219
|
+
if (DEBUG) {
|
220
|
+
console.log(JSON.stringify(metadata));
|
221
|
+
}
|
222
|
+
return metadata;
|
223
|
+
}
|
224
|
+
catch (e) {
|
225
|
+
if (e instanceof Error) {
|
226
|
+
if (e.name == "INVALID_SESSION_ID" || e.name == "sf:INVALID_SESSION_ID") {
|
227
|
+
expiredSession();
|
228
|
+
}
|
229
|
+
if (DEBUG) {
|
230
|
+
console.log(e);
|
247
231
|
}
|
232
|
+
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}`;
|
233
|
+
throw msg;
|
248
234
|
}
|
249
|
-
|
250
|
-
|
235
|
+
}
|
236
|
+
return [];
|
251
237
|
}
|
252
238
|
export default {
|
253
239
|
connect,
|
package/lib/helpers/context.d.ts
CHANGED
@@ -108,7 +108,7 @@ declare class Context implements IObjectRecord {
|
|
108
108
|
setObject(obj: ObjectRecord): void;
|
109
109
|
set(key: keyof IObjectRecord, value: AnyValue): void;
|
110
110
|
get(key: string): Promise<AnyValue>;
|
111
|
-
merge(text
|
111
|
+
merge(text?: string): string;
|
112
112
|
}
|
113
113
|
declare const context: Context;
|
114
114
|
export declare function initializeContext(): void;
|