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.
@@ -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
- 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
- }
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
- catch (e) {
38
- if (DEBUG) {
39
- console.log(e);
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
- // 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
- });
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
- 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);
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
- 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);
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
- // console.log(up, down, dependencies);
114
- return dependencies;
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
- 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"
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
- 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
- }
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
- // 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);
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
- 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;
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
- return [];
215
- });
168
+ }
169
+ return [];
216
170
  }
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);
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(JSON.stringify(metadata));
197
+ console.log(e);
234
198
  }
235
- return metadata;
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
- 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;
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
- return [];
250
- });
235
+ }
236
+ return [];
251
237
  }
252
238
  export default {
253
239
  connect,
@@ -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: string): string;
111
+ merge(text?: string): string;
112
112
  }
113
113
  declare const context: Context;
114
114
  export declare function initializeContext(): void;