@salesforce/apex-node
Advanced tools
Comparing version 0.1.1 to 0.1.2
/// <reference types="node" /> | ||
import { CommonOptions } from '../common'; | ||
import { CommonOptions } from '../utils'; | ||
export declare type ApexExecuteOptions = CommonOptions & { | ||
@@ -4,0 +4,0 @@ targetUsername?: string; |
import { Connection } from '@salesforce/core'; | ||
import { ApexLogGetOptions } from './types'; | ||
import { ApexLogGetOptions, LogRecord } from './types'; | ||
import { AnyJson } from '@salesforce/ts-types'; | ||
@@ -7,6 +7,6 @@ export declare class LogService { | ||
constructor(connection: Connection); | ||
getIdList(options: ApexLogGetOptions): Promise<string[]>; | ||
getLogIds(options: ApexLogGetOptions): Promise<string[]>; | ||
getLogs(options: ApexLogGetOptions): Promise<string[]>; | ||
getLogIds(numberOfLogs: number): Promise<string[]>; | ||
getLogRecords(numberOfLogs?: number): Promise<LogRecord[]>; | ||
toolingRequest(url: string): Promise<AnyJson>; | ||
} |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("../common"); | ||
const utils_1 = require("../utils"); | ||
const i18n_1 = require("../i18n"); | ||
@@ -21,3 +21,3 @@ const path = require("path"); | ||
} | ||
getIdList(options) { | ||
getLogIds(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -28,10 +28,7 @@ if (!(typeof options.logId === 'string' || | ||
} | ||
let logIdList = []; | ||
if (typeof options.numberOfLogs === 'number') { | ||
logIdList = yield this.getLogIds(options.numberOfLogs); | ||
const logIdRecordList = yield this.getLogRecords(options.numberOfLogs); | ||
return logIdRecordList.map(logRecord => logRecord.Id); | ||
} | ||
else { | ||
logIdList.push(options.logId); | ||
} | ||
return logIdList; | ||
return [options.logId]; | ||
}); | ||
@@ -42,3 +39,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const logIdList = yield this.getIdList(options); | ||
const logIdList = yield this.getLogIds(options); | ||
const logPaths = []; | ||
@@ -51,3 +48,3 @@ const connectionRequests = logIdList.map((id) => __awaiter(this, void 0, void 0, function* () { | ||
logPaths.push(logPath); | ||
common_1.createFile(logPath, logRecord); | ||
utils_1.createFile(logPath, logRecord); | ||
} | ||
@@ -63,11 +60,16 @@ return String(logRecord); | ||
} | ||
getLogIds(numberOfLogs) { | ||
getLogRecords(numberOfLogs) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (numberOfLogs <= 0) { | ||
throw new Error(i18n_1.nls.localize('num_logs_error')); | ||
let query = 'Select Id, Application, DurationMilliseconds, Location, '; | ||
query += | ||
'LogLength, LogUser.Name, Operation, Request, StartTime, Status from ApexLog Order By StartTime'; | ||
if (typeof numberOfLogs === 'number') { | ||
if (numberOfLogs <= 0) { | ||
throw new Error(i18n_1.nls.localize('num_logs_error')); | ||
} | ||
numberOfLogs = Math.min(numberOfLogs, MAX_NUM_LOGS); | ||
query += `DESC LIMIT ${numberOfLogs}`; | ||
} | ||
numberOfLogs = Math.min(numberOfLogs, MAX_NUM_LOGS); | ||
const query = `Select Id from ApexLog Order By StartTime DESC LIMIT ${numberOfLogs}`; | ||
const response = (yield this.connection.tooling.query(query)); | ||
return response.records.map(record => record.Id); | ||
return response.records; | ||
}); | ||
@@ -74,0 +76,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { CommonOptions } from '../common'; | ||
import { CommonOptions } from '../utils'; | ||
export declare type ApexLogGetOptions = CommonOptions & { | ||
@@ -7,1 +7,46 @@ numberOfLogs?: number; | ||
}; | ||
export interface LogRecord { | ||
Id: string; | ||
/** | ||
* Application type | ||
*/ | ||
Application: 'Unknown' | string; | ||
/** | ||
* Time to generate log | ||
*/ | ||
DurationMilliseconds: number; | ||
/** | ||
* Where the log was stored | ||
*/ | ||
Location: 'SystemLog' | string; | ||
/** | ||
* Length of the debug log | ||
*/ | ||
LogLength: number; | ||
/** | ||
* Name of the user who generated the log | ||
*/ | ||
LogUser: { | ||
attributes: {}; | ||
Name: string; | ||
}; | ||
/** | ||
* Type of operation | ||
*/ | ||
Operation: 'Api' | string; | ||
/** | ||
* Type of request | ||
*/ | ||
Request: 'Api' | string; | ||
/** | ||
* Time the log was generated | ||
*/ | ||
StartTime: string; | ||
/** | ||
* Status of the operation | ||
*/ | ||
Status: string; | ||
} | ||
export declare type LogQueryResult = { | ||
records: LogRecord[]; | ||
}; |
@@ -27,2 +27,68 @@ "use strict"; | ||
const $$ = testSetup_1.testSetup(); | ||
const logRecords = [ | ||
{ | ||
Id: '07L5tgg0005PGdTnEAL', | ||
Application: 'Unknown', | ||
DurationMilliseconds: 75, | ||
Location: 'Unknown', | ||
LogLength: 450, | ||
LogUser: { | ||
Name: 'Test User', | ||
attributes: {} | ||
}, | ||
Operation: 'API', | ||
Request: 'API', | ||
StartTime: '2020-10-13T05:39:43.000+0000', | ||
Status: 'Assertion Failed' | ||
}, | ||
{ | ||
Id: '07L5tgg0005PGdTnFPL', | ||
Application: 'Unknown', | ||
DurationMilliseconds: 75, | ||
Location: 'Unknown', | ||
LogLength: 450, | ||
LogUser: { | ||
Name: 'Test User2', | ||
attributes: {} | ||
}, | ||
Operation: 'API', | ||
Request: 'API', | ||
StartTime: '2020-10-13T05:39:43.000+0000', | ||
Status: 'Successful' | ||
} | ||
]; | ||
const rawLogResult = { | ||
records: [ | ||
{ | ||
Id: '07L5tgg0005PGdTnEAL', | ||
Application: 'Unknown', | ||
DurationMilliseconds: 75, | ||
Location: 'Unknown', | ||
LogLength: 450, | ||
LogUser: { | ||
Name: 'Test User', | ||
attributes: {} | ||
}, | ||
Operation: 'API', | ||
Request: 'API', | ||
StartTime: '2020-10-13T05:39:43.000+0000', | ||
Status: 'Assertion Failed' | ||
}, | ||
{ | ||
Id: '07L5tgg0005PGdTnFPL', | ||
Application: 'Unknown', | ||
DurationMilliseconds: 75, | ||
Location: 'Unknown', | ||
LogLength: 450, | ||
LogUser: { | ||
Name: 'Test User2', | ||
attributes: {} | ||
}, | ||
Operation: 'API', | ||
Request: 'API', | ||
StartTime: '2020-10-13T05:39:43.000+0000', | ||
Status: 'Successful' | ||
} | ||
] | ||
}; | ||
describe('Apex Log Service Tests', () => { | ||
@@ -64,3 +130,3 @@ const testData = new testSetup_1.MockTestOrgData(); | ||
const log = '48.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT..'; | ||
const getLogIdStub = sandboxStub.stub(logService_1.LogService.prototype, 'getLogIds'); | ||
const getLogIdStub = sandboxStub.stub(logService_1.LogService.prototype, 'getLogRecords'); | ||
toolingRequestStub.onFirstCall().resolves(log); | ||
@@ -131,4 +197,5 @@ const response = yield apexLogGet.getLogs({ logId: '07L5w00005PGdTnEAL' }); | ||
const filePath = path.join('testTmp', 'file', 'path', 'logs'); | ||
const logIds = ['07L5tgg0005PGdTnEAL', '07L5tgg0005PGdTnFPL']; | ||
sandboxStub.stub(logService_1.LogService.prototype, 'getLogIds').resolves(logIds); | ||
sandboxStub | ||
.stub(logService_1.LogService.prototype, 'getLogRecords') | ||
.resolves(logRecords); | ||
const createStreamStub = sandboxStub.stub(fs, 'createWriteStream'); | ||
@@ -176,3 +243,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
})); | ||
it('should throw an error if numberOfLogs or logId are not given', () => __awaiter(void 0, void 0, void 0, function* () { | ||
it('should throw an error if numberOfLogs or logId are not given to getLogs', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const apexLogGet = new logService_1.LogService(mockConnection); | ||
@@ -188,3 +255,33 @@ const filePath = path.join('path', 'to', 'logs'); | ||
})); | ||
describe('getLogRecords', () => __awaiter(void 0, void 0, void 0, function* () { | ||
it('should return log records given a specific number of logs', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const numberOfLogs = 2; | ||
let query = 'Select Id, Application, DurationMilliseconds, Location, '; | ||
query += | ||
'LogLength, LogUser.Name, Operation, Request, StartTime, Status from ApexLog Order By StartTime'; | ||
query += `DESC LIMIT ${numberOfLogs}`; | ||
const queryStub = sandboxStub | ||
.stub(mockConnection.tooling, 'query') | ||
//@ts-ignore | ||
.resolves(rawLogResult); | ||
const logService = new logService_1.LogService(mockConnection); | ||
const records = yield logService.getLogRecords(numberOfLogs); | ||
chai_1.expect(records).to.deep.equal(logRecords); | ||
chai_1.expect(queryStub.calledWith(query)).to.be.true; | ||
})); | ||
it('should return all log records', () => __awaiter(void 0, void 0, void 0, function* () { | ||
let query = 'Select Id, Application, DurationMilliseconds, Location, '; | ||
query += | ||
'LogLength, LogUser.Name, Operation, Request, StartTime, Status from ApexLog Order By StartTime'; | ||
const queryStub = sandboxStub | ||
.stub(mockConnection.tooling, 'query') | ||
//@ts-ignore | ||
.resolves(rawLogResult); | ||
const logService = new logService_1.LogService(mockConnection); | ||
const records = yield logService.getLogRecords(); | ||
chai_1.expect(records).to.deep.equal(logRecords); | ||
chai_1.expect(queryStub.calledWith(query)).to.be.true; | ||
})); | ||
})); | ||
}); | ||
//# sourceMappingURL=logService.test.js.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
*/ | ||
const fsUtil = require("../../src/common/fileSystemHandler"); | ||
const fsUtil = require("../../src/utils/fileSystemHandler"); | ||
const sinon_1 = require("sinon"); | ||
@@ -12,0 +12,0 @@ const chai_1 = require("chai"); |
{ | ||
"name": "@salesforce/apex-node", | ||
"description": "Salesforce js library for Apex", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205033
92
3236