-
Notifications
You must be signed in to change notification settings - Fork 41
/
objectinfo.ts
49 lines (39 loc) · 1.7 KB
/
objectinfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { flags, SfdxCommand } from '@salesforce/command';
import fs = require('fs-extra');
import request = require('request-promise-native');
export default class ObjectInfo extends SfdxCommand {
public static description =
'get a ui api response from the objectinfo endpoint: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_object_info.htm';
public static examples = [
`sfdx shane:uiapi:objectinfo -o Account --json
// returns ui-api objectinfo for Account
`,
`sfdx shane:uiapi:objectinfo -o Account --json --outputfile accountObjectInfo.json
// returns ui-api objectinfo for Account and saves it to a local file
`
];
protected static flagsConfig = {
object: flags.string({ char: 'o', description: 'object api name', required: true }),
outputfile: flags.filepath({ description: 'local path to save the output to' })
};
protected static requiresUsername = true;
public async run(): Promise<any> {
const conn = this.org.getConnection();
this.flags.apiversion = this.flags.apiversion ?? (await conn.retrieveMaxApiVersion());
const result = await request({
method: 'get',
uri: `${conn.instanceUrl}/services/data/v${this.flags.apiversion}/ui-api/object-info/${this.flags.object}`,
headers: {
Authorization: `Bearer ${conn.accessToken}`
},
json: true
});
this.ux.log(result);
if (this.flags.outputfile) {
await fs.outputJSON(this.flags.outputfile, result);
} else {
this.ux.warn('did you forget the outputfile');
}
return result;
}
}