repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
javavscode
github_2023
oracle
typescript
URI.file
static file(path: string): URI { let authority = _empty; // normalize to fwd-slashes on windows, // on other systems bwd-slashes are valid // filename character, eg /f\oo/ba\r.txt if (isWindows) { path = path.replace(/\\/g, _slash); } // check for au...
/** * Creates a new URI from a file system path, e.g. `c:\my\files`, * `/usr/home`, or `\\server\share\some\path`. * * The *difference* between `URI#parse` and `URI#file` is that the latter treats the argument * as path, not as stringified-uri. E.g. `URI.file(path)` is **not...
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/test/unit/mocks/vscode/uri.ts#L379-L404
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
URI.toString
toString(skipEncoding = false): string { return _asFormatted(this, skipEncoding); }
/** * Creates a string representation for this URI. It's guaranteed that calling * `URI.parse` with the result of this function creates an URI which is equal * to this URI. * * * The result shall *not* be used for display purposes but for externalization or transport. * * The result will b...
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/test/unit/mocks/vscode/uri.ts#L436-L438
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
_makeFsPath
function _makeFsPath(uri: URI): string { let value: string; if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') { // unc path: file://shares/c$/far/boo value = `//${uri.authority}${uri.path}`; } else if ( uri.path.charCodeAt(0) === CharCode.Slash && ((uri.path....
/** * Compute `fsPath` for the given uri */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/test/unit/mocks/vscode/uri.ts#L666-L687
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
_asFormatted
function _asFormatted(uri: URI, skipEncoding: boolean): string { const encoder = !skipEncoding ? encodeURIComponentFast : encodeURIComponentMinimal; let res = ''; let { authority, path } = uri; const { scheme, query, fragment } = uri; if (scheme) { res += scheme; res += ':'; } ...
/** * Create the external version of a uri */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/test/unit/mocks/vscode/uri.ts#L692-L758
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
TreeViewService.fetchImageUri
async fetchImageUri(nodeData: NodeInfoRequest.Data): Promise<vscode.Uri | string | ThemeIcon | undefined> { let res: vscode.Uri | string | ThemeIcon | undefined = this.imageUri(nodeData); if (res) { return res; } if (!nodeData?.iconDescriptor) { return undefined; } let ci: CachedIma...
/** * Requests an image data from the LSP server. * @param nodeData * @returns icon specification or undefined */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/views/projects.ts#L242-L268
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
VisualizerProvider.wrap
async wrap<X>(fn: (pending: Visualizer[]) => Thenable<X>): Promise<X> { let arr: Visualizer[] = []; try { return await fn(arr); } finally { this.releaseVisualizersAndFire(arr); } }
/** * Wraps code that queries individual Visualizers so that blocked changes are fired after * the code terminated. * * Usage: * wrap(() => { ... code ... ; queryVisualizer(vis, () => { ... })}); * @param fn the code to execute * @returns value of the code function */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/views/projects.ts#L568-L575
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
VisualizerProvider.visualizerList
private visualizerList(arr: Visualizer[]): string { let s = ""; for (let v of arr) { s += v.idstring() + " "; } return s; }
/** * Just creates a string list from visualizer IDs. Diagnostics only. */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/views/projects.ts#L580-L586
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
VisualizerProvider.releaseVisualizersAndFire
private releaseVisualizersAndFire(list: Visualizer[] | undefined) { if (!list) { list = Array.from(this.delayedFire); } if (doLog) { this.log.appendLine(`Done with ${this.visualizerList(list)}`); } // v can be in list several times, each push increased its counter, so we need to decrease...
/** * Do not use directly, use wrap(). Fires delayed events for visualizers that have no pending queries. */
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/views/projects.ts#L591-L621
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
javavscode
github_2023
oracle
typescript
VisualizerProvider.queryVisualizer
async queryVisualizer<X>(element: Visualizer | undefined, pending: Visualizer[], fn: () => Promise<X>): Promise<X> { if (!element) { return fn(); } this.delayedFire.add(element); pending.push(element); element.pendingQueries++; if (doLog) { this.log.appendLine(`Delaying visualizer ${...
/** * Should wrap calls to NBLS for individual visualizers (info, children). Puts visualizer on the delayed fire list. * Must be itself wrapped in wrap() -- wrap(... queryVisualizer()). * @param element visualizer to be queried, possibly undefined (new item is expected) * @param fn code to execute * @ret...
https://github.com/oracle/javavscode/blob/40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9/vscode/src/views/projects.ts#L630-L641
40d9fe288a4f2a3117be5be3ef2b53fc8f53c4e9
wanderlust
github_2023
krishnaacharyaa
typescript
isRedisEnabled
function isRedisEnabled() { return getRedisClient() !== null; }
// Helper function to check if Redis is available
https://github.com/krishnaacharyaa/wanderlust/blob/778bec3cf698538839d39c6eb4c5643c3aa7d60d/backend/utils/cache-posts.ts#L5-L7
778bec3cf698538839d39c6eb4c5643c3aa7d60d
text-to-cad-ui
github_2023
KittyCAD
typescript
fromLocalStorage
function fromLocalStorage<T = unknown>(storageKey: string, fallbackValue: T) { if (browser) { const storedValue = window.localStorage.getItem(storageKey) if (storedValue !== 'undefined' && storedValue !== null) { return typeof fallbackValue === 'object' ? JSON.parse(storedValue) : storedValue } } return f...
// Get value from localStorage if in browser and the value is stored, otherwise fallback
https://github.com/KittyCAD/text-to-cad-ui/blob/d9aeac11f79fbb8332fdfddc82bff5509190827b/src/lib/stores.ts#L90-L100
d9aeac11f79fbb8332fdfddc82bff5509190827b
text-to-cad-ui
github_2023
KittyCAD
typescript
signOut
function signOut() { cookies.delete(AUTH_COOKIE_NAME, { domain: DOMAIN, path: '/' }) throw redirect(303, '/') }
/** * Shared sign out function */
https://github.com/KittyCAD/text-to-cad-ui/blob/d9aeac11f79fbb8332fdfddc82bff5509190827b/src/routes/(sidebarLayout)/+layout.server.ts#L58-L61
d9aeac11f79fbb8332fdfddc82bff5509190827b
wxlivespy
github_2023
fire4nt
typescript
WXDataDecoder.decodeDataFromResponse
static decodeDataFromResponse( requestHeaders: Record<string, string>, requestData: any, responseData: any, ): DecodedData | null { const decodedMessages = {} as DecodedData; decodedMessages.host_info = {} as HostInfo; decodedMessages.host_info.wechat_uin = requestHeaders['x-wechat-uin']; ...
// }
https://github.com/fire4nt/wxlivespy/blob/10351334a5dd48f7e9cd06482cf91fde066176a6/src/main/WXDataDecoder.ts#L126-L163
10351334a5dd48f7e9cd06482cf91fde066176a6
wxlivespy
github_2023
fire4nt
typescript
SpyConfig.getProp
public getProp<K extends keyof ConfigProps>(key: K): ConfigProps[K] { return this.config[key]; }
// Step 2: Implement generic getProp and setProp methods
https://github.com/fire4nt/wxlivespy/blob/10351334a5dd48f7e9cd06482cf91fde066176a6/src/main/config.ts#L51-L53
10351334a5dd48f7e9cd06482cf91fde066176a6
wxlivespy
github_2023
fire4nt
typescript
getForwardURL
const getForwardURL = async () => { const url = await window.electron.ipcRenderer.getForwardUrl(); // setFormData(configFromMain); setForwardURL(url); };
// Fetch config from main process when component is mounted
https://github.com/fire4nt/wxlivespy/blob/10351334a5dd48f7e9cd06482cf91fde066176a6/src/renderer/EventPanel.tsx#L24-L28
10351334a5dd48f7e9cd06482cf91fde066176a6
wxlivespy
github_2023
fire4nt
typescript
getLiveStatusURL
const getLiveStatusURL = async () => { const httpServerPort = await window.electron.ipcRenderer.getConfig('http_server_port'); liveStatusUrl = `http://localhost:${httpServerPort}/getLiveStatus`; log.info(liveStatusUrl); };
// window.electron.ipcRenderer.once('wxlive-status', (arg) => {
https://github.com/fire4nt/wxlivespy/blob/10351334a5dd48f7e9cd06482cf91fde066176a6/src/renderer/StatusPanel.tsx#L42-L46
10351334a5dd48f7e9cd06482cf91fde066176a6
citrineos-core
github_2023
citrineos
typescript
findCaseInsensitiveMatch
function findCaseInsensitiveMatch<T>( obj: Record<string, T>, targetKey: string, ): string | undefined { const lowerTargetKey = targetKey.toLowerCase(); return Object.keys(obj).find((key) => key.toLowerCase() === lowerTargetKey); }
/** * Finds a case-insensitive match for a key in an object. * @param obj The object to search. * @param targetKey The target key. * @returns The matching key or undefined. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/config/defineConfig.ts#L21-L27
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
mergeConfigFromEnvVars
function mergeConfigFromEnvVars<T extends Record<string, any>>( defaultConfig: T, envVars: NodeJS.ProcessEnv, configKeyMap: Record<string, any>, ): T { const config: T = { ...defaultConfig }; for (const [fullEnvKey, value] of Object.entries(envVars)) { if (!value) { continue; } const lowerc...
/** * Merges configuration from environment variables into the default configuration. Allows any to keep it as generic as possible. * @param defaultConfig The default configuration. * @param envVars The environment variables. * @returns The merged configuration. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/config/defineConfig.ts#L70-L120
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
validateFinalConfig
function validateFinalConfig(finalConfig: SystemConfigInput) { if (!finalConfig.data.sequelize.username) { throw new Error( 'CITRINEOS_DATA_SEQUELIZE_USERNAME must be set if username not provided in config', ); } if (!finalConfig.data.sequelize.password) { throw new Error( 'CITRINEOS_DATA_...
/** * Validates the system configuration to ensure required properties are set. * @param finalConfig The final system configuration. * @throws Error if required properties are not set. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/config/defineConfig.ts#L127-L138
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
_handler
const _handler = async ( request: FastifyRequest<{ Body: OcppRequest; Querystring: Record<string, any>; }>, ): Promise<IMessageConfirmation> => { const { identifier, tenantId, callbackUrl, ...extraQueries } = request.query; return method.call( this, id...
/** * Executes the handler function for the given request. * * @param {FastifyRequest<{ Body: OcppRequest, Querystring: IMessageQuerystring }>} request - The request object containing the body and querystring. * @return {Promise<IMessageConfirmation>} The promise that resolves to the message confirm...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/interfaces/api/AbstractModuleApi.ts#L132-L148
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
_handler
const _handler = async ( request: FastifyRequest<{ Body: object; Querystring: object; }>, reply: FastifyReply, ): Promise<unknown> => ( method.call(this, request, reply) as Promise< undefined | string | object > ).catch((err) => { // TO...
/** * Handles the request and returns a Promise resolving to an object. * * @param {FastifyRequest<{ Body: object, Querystring: object }>} request - the request object * @param {FastifyReply} reply - the reply object * @return {Promise<any>} - a Promise resolving to an object */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/interfaces/api/AbstractModuleApi.ts#L242-L258
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
cleanSchema
const cleanSchema = (obj: any) => { if (typeof obj !== 'object' || obj === null) return; // Remove specific unknown keys for (const unknownKey of ['comment', 'javaType', 'tsEnumNames']) { if (unknownKey in obj) { delete obj[unknownKey]; } } // Remove `additional...
// Use structuredClone for a true deep copy
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/interfaces/api/AbstractModuleApi.ts#L394-L424
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Message.constructor
constructor( origin: MessageOrigin, eventGroup: EventGroup, action: CallAction, state: MessageState, context: IMessageContext, payload: T, ) { this._origin = origin; this._eventGroup = eventGroup; this._action = action; this._state = state; this._context = context; this...
/** * Constructs a new instance of Message. * * @param {MessageOrigin} origin - The origin of the message. * @param {EventGroup} eventGroup - The event group of the message. * @param {CallAction} action - The action of the message. * @param {MessageState} state - The state of the message. * @param ...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/interfaces/messages/Message.ts#L68-L82
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Message.origin
get origin(): MessageOrigin { return this._origin; }
/** * Getter & Setter */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/interfaces/messages/Message.ts#L87-L89
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Money.roundToCurrencyScale
roundToCurrencyScale(): Money { const newAmount = this._amount.round( this.currency.scale, 0, // RoundDown ); return this.withAmount(newAmount); }
/** * Rounds the amount down to match the currency's defined scale. * This method could be used when converting an amount to its final monetary value. * * @returns {Money} A new Money instance with the amount rounded down to the currency's scale. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/money/Money.ts#L50-L56
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
MeterValueUtils.getTotalKwh
public static getTotalKwh(meterValues: MeterValueType[]): number { const filteredValues = this.filterValidMeterValues(meterValues); const timestampToKwhMap = this.getTimestampToKwhMap(filteredValues); const sortedValues = this.getSortedKwhByTimestampAscending(timestampToKwhMap); return this.calcul...
/** * Calculate the total Kwh * * @param {array} meterValues - meterValues of a transaction. * @return {number} total Kwh based on the overall values (i.e., without phase) in the simpledValues. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/00_Base/src/util/MeterValueUtils.ts#L21-L27
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
TlsCertificatesRequest.constructor
constructor(certificateChain: string[], privateKey: string, rootCA?: string, subCAKey?: string) { this.certificateChain = certificateChain; this.privateKey = privateKey; this.rootCA = rootCA; this.subCAKey = subCAKey; }
// file id for the private key of sub CA for signing charging station certificate
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/interfaces/dtos/TlsCertificatesRequest.ts#L12-L17
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeAuthorizationRepository._updateIdToken
private async _updateIdToken(value: IdTokenType, transaction?: Transaction): Promise<IdToken> { const [savedIdTokenModel] = await IdToken.findOrCreate({ where: { idToken: value.idToken, type: value.type }, transaction, }); const additionalInfoIds: number[] = []; // Create any additionalInf...
/** * Private Methods */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/Authorization.ts#L138-L179
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeBootRepository.manageSetVariables
private async manageSetVariables(setVariableIds: number[], stationId: string, bootConfigId: string): Promise<VariableAttribute[]> { const managedSetVariables: VariableAttribute[] = []; // Unassigns variables await this.variableAttributes.updateAllByQuery( { bootConfigId: null }, { where:...
/** * Private Methods */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/Boot.ts#L68-L92
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeDeviceModelRepository.createSetVariableDataType
private createSetVariableDataType(input: VariableAttribute): SetVariableDataType { if (!input.value) { throw new Error('Value must be present to generate SetVariableDataType from VariableAttribute'); } else { return { attributeType: input.type, attributeValue: input.value, co...
/** * Private Methods */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/DeviceModel.ts#L419-L434
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeSecurityEventRepository.generateTimestampQuery
private generateTimestampQuery(from?: string, to?: string): any { if (!from && !to) { return {}; } if (!from && to) { return { timestamp: { [Op.lte]: to } }; } if (from && !to) { return { timestamp: { [Op.gte]: from } }; } return { timestamp: { [Op.between]: [from, to] } };...
/** * Private Methods */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/SecurityEvent.ts#L45-L56
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeSubscriptionRepository.create
create(value: Subscription): Promise<Subscription> { const { ...rawSubscription } = value; rawSubscription.id = null; return super.create(Subscription.build({ ...rawSubscription })); }
/** * Creates a new {@link Subscription} in the database. * Input is assumed to not have an id, and id will be removed if present. * Object is rebuilt to ensure access to essential {@link Model} function {@link Model.save()} (Model is extended by Subscription). * * @param value {@link Subscription} objec...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/Subscription.ts#L25-L29
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeTransactionEventRepository.createOrUpdateTransactionByTransactionEventAndStationId
async createOrUpdateTransactionByTransactionEventAndStationId(value: TransactionEventRequest, stationId: string): Promise<Transaction> { let evse: Evse | undefined; if (value.evse) { [evse] = await this.evse.readOrCreateByQuery({ where: { id: value.evse.id, connectorId: value.e...
/** * @param value TransactionEventRequest received from charging station. Will be used to create TransactionEvent, * MeterValues, and either create or update Transaction. IdTokens (and associated AdditionalInfo) and EVSEs are * assumed to already exist and will not be created as part of this call. * * @...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/TransactionEvent.ts#L48-L155
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SequelizeTransactionEventRepository.readAllTransactionsByStationIdAndEvseAndChargingStates
async readAllTransactionsByStationIdAndEvseAndChargingStates(stationId: string, evse?: EVSEType, chargingStates?: ChargingStateEnumType[] | undefined): Promise<Transaction[]> { const includeObj = evse ? [ { model: Evse, where: { id: evse.id, connectorId: evse.connectorId ? ev...
/** * @param stationId StationId of the charging station where the transaction took place. * @param evse Evse where the transaction took place. * @param chargingStates Optional list of {@link ChargingStateEnumType}s the transactions must be in. * If not present, will grab transactions regardless of charging...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/01_Data/src/layers/sequelize/repository/TransactionEvent.ts#L186-L201
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificateAuthorityService.getCertificateChain
async getCertificateChain( csrString: string, stationId: string, certificateType?: CertificateSigningUseEnumType | null, ): Promise<string> { this._logger.info( `Getting certificate chain for certificateType: ${certificateType} and stationId: ${stationId}`, ); switch (certificateType) {...
/** * Retrieves the certificate chain for V2G- and Charging Station certificates. * * @param {string} csrString - The Certificate Signing Request string. * @param {string} stationId - The station identifier. * @param {CertificateSigningUseEnumType} [certificateType] - The type of certificate to retrieve....
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/CertificateAuthority.ts#L69-L93
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificateAuthorityService.validateCertificateChainPem
public async validateCertificateChainPem( certificateChainPem: string, ): Promise<AuthorizeCertificateStatusEnumType> { const certificatePems: string[] = parseCertificateChainPem(certificateChainPem); this._logger.debug( `Found ${certificatePems.length} certificates in chain.`, ); if (...
/* * Validate the certificate chain using real time OCSP check. * * @param certificateChainPem - certificate chain pem * @return AuthorizeCertificateStatusEnumType */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/CertificateAuthority.ts#L155-L239
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificateAuthorityService._createCertificateChainWithoutRootCA
private _createCertificateChainWithoutRootCA( signedCert: string, caCerts: string, ): string { let certificateChain = ''; // Add Cert const leafRaw = extractCertificateArrayFromEncodedString(signedCert)[0]; if (leafRaw) { certificateChain += createPemBlock( 'CERTIFICATE', ...
/** * Create a certificate chain including leaf and sub CA certificates except for the root certificate. * * @param {string} signedCert - The leaf certificate. * @param {string} caCerts - CA certificates. * @return {string} The certificate chain pem. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/CertificateAuthority.ts#L281-L312
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Acme.getRootCACertificate
async getRootCACertificate(): Promise<string> { const response = await fetch( `https://letsencrypt.org/certs/${this._preferredChain.file}.pem`, ); if (!response.ok && response.status !== 304) { throw new Error( `Failed to fetch certificate: ${response.status}: ${await response.text()}`,...
/** * Get LetsEncrypt Root CA certificate, ISRG Root X1. * @return {Promise<string>} The CA certificate pem. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/acme.ts#L82-L94
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Acme.signCertificateByExternalCA
async signCertificateByExternalCA(csrString: string): Promise<string> { const folderPath = '/usr/local/apps/citrineos/Server/src/assets/.well-known/acme-challenge'; const cert = await this._client?.auto({ csr: csrString, email: this._email, termsOfServiceAgreed: true, preferredCha...
/** * Retrieves a signed certificate based on the provided CSR. * The returned certificate will be signed by Let's Encrypt, ISRG Root X1. * which is listed in https://ccadb.my.salesforce-sites.com/mozilla/CAAIdentifiersReport * * @param {string} csrString - The certificate signing request. * @return {...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/acme.ts#L104-L143
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Acme.getCertificateChain
async getCertificateChain(csrString: string): Promise<string> { const [serverId, [certChain, subCAPrivateKey]] = this._securityCertChainKeyMap.entries().next().value; this._logger.debug( `Found certificate chain in server ${serverId}: ${certChain}`, ); const certChainArray: string[] = parse...
/** * Get sub CA from the certificate chain. * Use it to sign certificate based on the CSR string. * * @param {string} csrString - The Certificate Signing Request (CSR) string. * @return {Promise<string>} - The signed certificate followed by sub CA in PEM format. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/acme.ts#L152-L176
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Hubject.getSignedCertificate
async getSignedCertificate(csrString: string): Promise<string> { const url = `${this._baseUrl}/cpo/simpleenroll/${this._isoVersion}`; const response = await fetch(url, { method: 'POST', headers: { Accept: 'application/pkcs10', Authorization: await this._getAuthorizationToken(this._to...
/** * Retrieves a signed certificate based on the provided CSR. * DOC: https://hubject.stoplight.io/docs/open-plugncharge/486f0b8b3ded4-simple-enroll-iso-15118-2-and-iso-15118-20 * * @param {string} csrString - The certificate signing request from SignCertificateRequest. * @return {Promise<string>} The s...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/hubject.ts#L38-L57
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Hubject.getCACertificates
async getCACertificates(): Promise<string> { const url = `${this._baseUrl}/cpo/cacerts/${this._isoVersion}`; const response = await fetch(url, { method: 'GET', headers: { Accept: 'application/pkcs10, application/pkcs7', Authorization: await this._getAuthorizationToken(this._tokenUrl)...
/** * Retrieves the CA certificates including sub CAs and root CA. * DOC: https://hubject.stoplight.io/docs/open-plugncharge/e246aa213bc22-obtaining-ca-certificates-iso-15118-2-and-iso-15118-20 * * @return {Promise<string>} The CA certificates. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/hubject.ts#L65-L83
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Hubject.getRootCertificates
async getRootCertificates(): Promise<string[]> { const url = `${this._baseUrl}/v1/root/rootCerts`; const response = await fetch(url, { method: 'GET', headers: { Accept: 'application/json', Authorization: await this._getAuthorizationToken(this._tokenUrl), }, }); if (res...
/** * Retrieves all root certificates from Hubject. * Refer to https://hubject.stoplight.io/docs/open-plugncharge/fdc9bdfdd4fb2-get-all-root-certificates * * @return {Promise<string[]>} Array of root certificate. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/hubject.ts#L146-L172
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Hubject._parseBearerToken
private _parseBearerToken(token: string): string { let tokenValue: string = token.split('Bearer ')[1]; tokenValue = tokenValue.split('\n')[0]; return 'Bearer ' + tokenValue; }
/** * Parses the Bearer token from the input token * which is expected to be in the format of "XXXXBearer <token>\nXXXXX" * * @param {string} token - The input token string to parse. * @return {string} The parsed Bearer token string. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/certificate/client/hubject.ts#L191-L195
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection.sendMessage
sendMessage(identifier: string, message: string): Promise<boolean> { return new Promise<boolean>((resolve, reject) => { this._cache .get(identifier, CacheNamespace.Connections) .then((clientConnection) => { if (clientConnection) { const websocketConnection = ...
/** * Send a message to the charging station specified by the identifier. * * @param {string} identifier - The identifier of the client. * @param {string} message - The message to send. * @return {boolean} True if the method sends the message successfully, false otherwise. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L124-L168
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection.updateTlsCertificates
updateTlsCertificates( serverId: string, tlsKey: string, tlsCertificateChain: string, rootCA?: string, ): void { let httpsServer = this._httpServersMap.get(serverId); if (httpsServer && httpsServer instanceof https.Server) { const secureContextOptions: SecureContextOptions = { k...
/** * Updates certificates for a specific server with the provided TLS key, certificate chain, and optional * root CA. * * @param {string} serverId - The ID of the server to update. * @param {string} tlsKey - The TLS key to set. * @param {string} tlsCertificateChain - The TLS certificate chain to set....
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L185-L208
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._upgradeRequest
private async _upgradeRequest( req: http.IncomingMessage, socket: Duplex, head: Buffer, wss: WebSocketServer, websocketServerConfig: WebsocketServerConfig, ) { // Failed mTLS and TLS requests are rejected by the server before getting this far this._logger.debug('On upgrade request', req.me...
/** * Method to validate websocket upgrade requests and pass them to the socket server. * * @param {IncomingMessage} req - The request object. * @param {Duplex} socket - Websocket duplex stream. * @param {Buffer} head - Websocket buffer. * @param {WebSocketServer} wss - Websocket server. * @param {...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L235-L275
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._rejectUpgradeUnauthorized
private _rejectUpgradeUnauthorized(socket: Duplex) { socket.write('HTTP/1.1 401 Unauthorized\r\n'); socket.write( 'WWW-Authenticate: Basic realm="Access to the WebSocket", charset="UTF-8"\r\n', ); socket.write('\r\n'); socket.end(); socket.destroy(); }
/** * Utility function to reject websocket upgrade requests with 401 status code. * @param socket - Websocket duplex stream. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L281-L289
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._handleProtocols
private _handleProtocols( protocols: Set<string>, req: http.IncomingMessage, wsServerProtocol: string, ) { // Only supports configured protocol version if (protocols.has(wsServerProtocol)) { return wsServerProtocol; } this._logger.error( `Protocol mismatch. Supported protocols:...
/** * Internal method to handle new client connection and ensures supported protocols are used. * * @param {Set<string>} protocols - The set of protocols to handle. * @param {IncomingMessage} req - The request object. * @param {string} wsServerProtocol - The websocket server protocol. * @return {boole...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L299-L313
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._onConnection
private async _onConnection( ws: WebSocket, pingInterval: number, req: http.IncomingMessage, ): Promise<void> { // Pause the WebSocket event emitter until broker is established ws.pause(); const identifier = this._getClientIdFromUrl(req.url as string); this._identifierConnections.set(iden...
/** * Internal method to handle the connection event when a WebSocket connection is established. * This happens after successful protocol exchange with client. * * @param {WebSocket} ws - The WebSocket object representing the connection. * @param {number} pingInterval - The ping interval in seconds. *...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L324-L363
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._registerWebsocketEvents
private _registerWebsocketEvents( identifier: string, ws: WebSocket, pingInterval: number, ): void { ws.onerror = (event: ErrorEvent) => { this._logger.error( 'Connection error encountered for', identifier, event.error, event.message, event.type, ); ...
/** * Internal method to register event listeners for the WebSocket connection. * * @param {string} identifier - The unique identifier for the connection. * @param {WebSocket} ws - The WebSocket object representing the connection. * @param {number} pingInterval - The ping interval in seconds. * @retur...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L373-L433
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._onMessage
private _onMessage(identifier: string, message: string): void { this._router.onMessage(identifier, message, new Date()); }
/** * Internal method to handle the incoming message from the websocket client. * * @param {string} identifier - The client identifier. * @param {string} message - The incoming message from the client. * @return {void} This function does not return anything. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L442-L444
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._onError
private _onError(wss: WebSocketServer, error: Error): void { this._logger.error(error); // TODO: Try to recover the Websocket server }
/** * Internal method to handle the error event for the WebSocket server. * * @param {WebSocketServer} wss - The WebSocket server instance. * @param {Error} error - The error object. * @return {void} This function does not return anything. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L453-L456
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._onClose
private _onClose(wss: WebSocketServer): void { this._logger.debug('Websocket Server closed'); // TODO: Try to recover the Websocket server }
/** * Internal method to handle the event when the WebSocketServer is closed. * * @param {WebSocketServer} wss - The WebSocketServer instance. * @return {void} This function does not return anything. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L464-L467
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._ping
private async _ping( identifier: string, ws: WebSocket, pingInterval: number, ): Promise<void> { setTimeout(async () => { const clientConnection: string | null = await this._cache.get( identifier, CacheNamespace.Connections, ); if (clientConnection) { this._lo...
/** * Internal method to execute a ping operation on a WebSocket connection after a delay of 60 seconds. * * @param {string} identifier - The identifier of the client connection. * @param {WebSocket} ws - The WebSocket connection to ping. * @param {number} pingInterval - The ping interval in milliseconds...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L477-L501
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
WebsocketNetworkConnection._getClientIdFromUrl
private _getClientIdFromUrl(url: string): string { return url.split('/').pop() as string; }
/** * * @param url Http upgrade request url used by charger * @returns Charger identifier */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/networkconnection/WebsocketNetworkConnection.ts#L507-L509
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubReceiver.constructor
constructor( config: SystemConfig, logger?: Logger<ILogObj>, module?: IModule, cache?: ICache, ) { super(config, logger, module); this._cache = cache || new MemoryCache(); this._client = new PubSub({ servicePath: this._config.util.messageBroker.pubsub?.servicePath, }); }
/** * Constructor * * @param topicPrefix Custom topic prefix, defaults to "ocpp" */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/receiver.ts#L50-L61
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubReceiver.subscribe
subscribe( identifier: string, actions?: CallAction[], filter?: { [k: string]: string }, ): Promise<boolean> { const topicName = `${this._config.util.messageBroker.pubsub?.topicPrefix}-${this._config.util.messageBroker.pubsub?.topicName}`; // Check if topic exists, if not create it return thi...
/** * The init method will create a subscription for each action in the {@link CallAction} array. * * @param actions All actions to subscribe to * @param stateFilter Optional filter for the subscription via {@link MessageState}, must be used to prevent looping of messages in Google PubSub * @returns *...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/receiver.ts#L70-L106
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubReceiver.shutdown
shutdown() { this._subscriptions.forEach((subscription) => { subscription.close().then(() => { subscription.delete().then(() => { this._logger.debug(`Subscription ${subscription.name} deleted.`); }); }); }); }
/** * Shutdown the receiver by closing all subscriptions and deleting them. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/receiver.ts#L137-L145
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubReceiver._onMessage
protected async _onMessage(message: PubSubMessage): Promise<void> { try { const parsed = plainToInstance( Message<OcppRequest | OcppResponse | OcppError>, <Message<OcppRequest | OcppResponse | OcppError>>( JSON.parse(message.data.toString()) ), ); await this.handl...
/** * Underlying PubSub message handler. * * @param message The PubSubMessage to process */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/receiver.ts#L152-L172
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubReceiver._subscribe
private _subscribe( identifier: string, topic: Topic, actions?: CallAction[], filter?: { [k: string]: string }, ): Promise<string> { // Generate topic name const subscriptionName = `${topic.name.split('/').pop()}-${identifier}-${Date.now()}`; // Create message filter based on actions ...
/** * * @param action * @param stateFilter * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/receiver.ts#L184-L235
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubSender.constructor
constructor(config: SystemConfig, logger?: Logger<ILogObj>) { super(config, logger); this._client = new PubSub({ servicePath: this._config.util.messageBroker.pubsub?.servicePath, }); }
/** * Constructor * * @param topicPrefix Custom topic prefix, defaults to "ocpp" */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/sender.ts#L38-L44
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubSender.sendRequest
sendRequest( message: IMessage<OcppRequest>, payload?: OcppRequest, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Request); }
/** * Convenience method to send a request message. * * @param message The {@link IMessage} to send * @param payload The payload to send * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/sender.ts#L53-L58
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubSender.sendResponse
sendResponse( message: IMessage<OcppResponse | OcppError>, payload?: OcppResponse | OcppError, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Response); }
/** * Convenience method to send a confirmation message. * @param message The {@link IMessage} to send * @param payload The payload to send * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/sender.ts#L66-L71
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubSender.send
send( message: IMessage<OcppRequest | OcppResponse | OcppError>, payload?: OcppRequest | OcppResponse | OcppError, state?: MessageState, ): Promise<IMessageConfirmation> { if (payload) { message.payload = payload; } if (state) { message.state = state; } if (!message.state...
/** * Publishes the given message to Google PubSub. * * @param message The {@link IMessage} to publish * @param payload The payload to within the {@link IMessage} * @param state The {@link MessageState} of the {@link IMessage} * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/sender.ts#L81-L123
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
PubSubSender.shutdown
shutdown(): void { // Nothing to do }
/** * Interface implementation */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/google-pubsub/sender.ts#L128-L130
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaReceiver._onMessage
private async _onMessage( { topic, partition, message }: EachMessagePayload, consumer: Consumer, ): Promise<void> { this._logger.debug( `Received message ${message.value?.toString()} on topic ${topic} partition ${partition}`, ); try { const messageValue = message.value; if (messa...
/** * Underlying Kafka message handler. * * @param message The PubSub message to process */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/receiver.ts#L143-L171
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaSender.constructor
constructor(config: SystemConfig, logger?: Logger<ILogObj>) { super(config, logger); this._client = new Kafka({ brokers: config.util.messageBroker.kafka?.brokers || [], ssl: true, sasl: { mechanism: 'plain', username: config.util.messageBroker.kafka?.sasl.username || '', ...
/** * Constructor * * @param topicPrefix Custom topic prefix, defaults to "ocpp" */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/sender.ts#L39-L72
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaSender.sendRequest
sendRequest( message: IMessage<OcppRequest>, payload?: OcppRequest, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Request); }
/** * Convenience method to send a request message. * * @param message The {@link IMessage} to send * @param payload The payload to send * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/sender.ts#L81-L86
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaSender.sendResponse
sendResponse( message: IMessage<OcppResponse | OcppError>, payload?: OcppResponse | OcppError, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Response); }
/** * Convenience method to send a confirmation message. * @param message The {@link IMessage} to send * @param payload The payload to send * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/sender.ts#L94-L99
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaSender.send
send( message: IMessage<OcppRequest | OcppResponse | OcppError>, payload?: OcppRequest | OcppResponse | OcppError, state?: MessageState, ): Promise<IMessageConfirmation> { if (payload) { message.payload = payload; } if (state) { message.state = state; } if (!message.state...
/** * Publishes the given message to Google PubSub. * * @param message The {@link IMessage} to publish * @param payload The payload to within the {@link IMessage} * @param state The {@link MessageState} of the {@link IMessage} * @returns */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/sender.ts#L109-L155
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
KafkaSender.shutdown
shutdown(): void { this._producers.forEach((producer) => { producer.disconnect(); }); }
/** * Interface implementation */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/kafka/sender.ts#L160-L164
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqReceiver.subscribe
async subscribe( identifier: string, actions?: CallAction[], filter?: { [k: string]: string }, ): Promise<boolean> { // If actions are a defined but empty list, it is likely a module // with no available actions and should not have a queue. // // If actions are undefined, it is likely a ch...
/** * Binds queue to an exchange given identifier and optional actions and filter. * Note: Due to the nature of AMQP 0-9-1 model, if you need to filter for the identifier, you **MUST** provide it in the filter object. * * @param {string} identifier - The identifier of the channel to subscribe to. * @para...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/receiver.ts#L68-L148
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqReceiver._connect
protected _connect(): Promise<amqplib.Channel> { return amqplib .connect(this._config.util.messageBroker.amqp?.url || '') .then((connection) => { this._connection = connection; return connection.createChannel(); }) .then((channel) => { // Add listener for channel erro...
/** * Connect to RabbitMQ */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/receiver.ts#L193-L208
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqReceiver._onMessage
protected async _onMessage( message: amqplib.ConsumeMessage | null, channel: amqplib.Channel, ): Promise<void> { if (message) { try { this._logger.debug( '_onMessage:Received message:', message.properties, message.content.toString(), ); const par...
/** * Underlying RabbitMQ message handler. * * @param message The AMQPMessage to process */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/receiver.ts#L215-L245
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender.constructor
constructor(config: SystemConfig, logger?: Logger<ILogObj>) { super(config, logger); this._connect().then((channel) => { this._channel = channel; }); }
/** * Constructor for the class. * * @param {SystemConfig} config - The system configuration. * @param {Logger<ILogObj>} [logger] - The logger object. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L45-L51
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender.sendRequest
sendRequest( message: IMessage<OcppRequest>, payload?: OcppRequest | undefined, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Request); }
/** * Sends a request message with an optional payload and returns a promise that resolves to the confirmation message. * * @param {IMessage<OcppRequest>} message - The message to be sent. * @param {OcppRequest | undefined} payload - The optional payload to be sent with the message. * @return {Promise<IM...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L64-L69
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender.sendResponse
sendResponse( message: IMessage<OcppResponse | OcppError>, payload?: OcppResponse | OcppError, ): Promise<IMessageConfirmation> { return this.send(message, payload, MessageState.Response); }
/** * Sends a response message and returns a promise of the message confirmation. * * @param {IMessage<OcppResponse | OcppError>} message - The message to send. * @param {OcppResponse | OcppError} payload - The payload to include in the response. * @return {Promise<IMessageConfirmation>} - A promise that...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L78-L83
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender.send
async send( message: IMessage<OcppRequest | OcppResponse | OcppError>, payload?: OcppRequest | OcppResponse | OcppError, state?: MessageState, ): Promise<IMessageConfirmation> { if (payload) { message.payload = payload; } if (state) { message.state = state; } if (!message...
/** * Sends a message and returns a promise that resolves to a message confirmation. * * @param {IMessage<OcppRequest | OcppResponse | OcppError>} message - The message to be sent. * @param {OcppRequest | OcppResponse | OcppError} [payload] - The payload to be included in the message. * @param {MessageSt...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L93-L137
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender.shutdown
shutdown(): Promise<void> { return Promise.resolve(); }
/** * Shuts down the sender by closing the client. * * @return {Promise<void>} A promise that resolves when the client is closed. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L144-L146
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
RabbitMqSender._connect
protected _connect(): Promise<amqplib.Channel> { return amqplib .connect(this._config.util.messageBroker.amqp?.url || '') .then(async (connection) => { this._connection = connection; return connection.createChannel(); }) .then((channel) => { // Add listener for channe...
/** * Connect to RabbitMQ */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/queue/rabbit-mq/sender.ts#L155-L170
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SignedMeterValuesUtil.constructor
constructor( fileAccess: IFileAccess, config: SystemConfig, logger: Logger<ILogObj>, ) { this._fileAccess = fileAccess; this._logger = logger; this._chargingStationSecurityInfoRepository = new sequelize.SequelizeChargingStationSecurityInfoRepository( config, logger, ...
/** * @param {IFileAccess} [fileAccess] - The `fileAccess` allows access to the configured file storage. * * @param {SystemConfig} config - The `config` contains the current system configuration settings. * * @param {Logger<ILogObj>} [logger] - The `logger` represents an instance of {@link Logger<ILogObj...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/security/SignedMeterValuesUtil.ts#L36-L51
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
SignedMeterValuesUtil.validateMeterValues
public async validateMeterValues( stationId: string, meterValues: [MeterValueType, ...MeterValueType[]], ): Promise<boolean> { for (const meterValue of meterValues) { for (const sampledValue of meterValue.sampledValue) { if (sampledValue.signedMeterValue) { const validMeterValues =...
/** * Checks the validity of a meter value. * * If a meter value is unsigned, it is valid. * * If a meter value is signed, it is valid if: * - SignedMeterValuesConfig is configured * AND * - The incoming signed meter value's signing method matches the configured signing method * AND * - Th...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/security/SignedMeterValuesUtil.ts#L70-L89
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
OcppTransformObject
function OcppTransformObject({ swaggerObject, openapiObject, }: { swaggerObject: Partial<OpenAPIV2.Document>; openapiObject: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>; }) { console.log('OcppTransformObject: Transforming OpenAPI object...'); if (openapiObject.paths && openapiObject.components) { ...
/** * This transformation is used to set default tags * * @param {object} swaggerObject - The original Swagger object to be transformed. * @param {object} openapiObject - The original OpenAPI object to be transformed. * @return {object} The transformed OpenAPI object. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/util/swagger.ts#L28-L60
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Timer.difference
get difference(): bigint | null { return this.timerEnd ? this.timerEnd - this.timerStart : null; }
/** * Calculates and returns the difference between the timer end and start values. * * @return {bigint | null} The difference between the timer end and start values, or null if either value is missing. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/util/timer.ts#L34-L36
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
Timer.end
end(): bigint | null { this.timerEnd = BigInt(new Date().getTime()); return this.difference; }
/** * Ends the timer and returns the time difference. * * @returns The time difference between the start and end of the timer. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/02_Util/src/util/timer.ts#L43-L46
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModuleApi.constructor
constructor( certificatesModule: CertificatesModule, server: FastifyInstance, fileAccess: IFileAccess, networkConnection: WebsocketNetworkConnection, websocketServersConfig: WebsocketServerConfig[], logger?: Logger<ILogObj>, ) { super(certificatesModule, server, logger); this._fileAcce...
/** * Constructs a new instance of the class. * * @param {CertificatesModule} certificatesModule - The Certificates module. * @param {FastifyInstance} server - The Fastify server instance. * @param {Logger<ILogObj>} [logger] - The logger instance. * @param {IFileAccess} fileAccess - The FileAccess ...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/api.ts#L77-L89
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModuleApi._toMessagePath
protected _toMessagePath(input: CallAction): string { const endpointPrefix = this._module.config.modules.certificates?.endpointPrefix; return super._toMessagePath(input, endpointPrefix); }
/** * Overrides superclass method to generate the URL path based on the input {@link CallAction} and the module's endpoint prefix configuration. * * @param {CallAction} input - The input {@link CallAction}. * @return {string} - The generated URL path. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/api.ts#L447-L451
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModuleApi._toDataPath
protected _toDataPath(input: Namespace): string { const endpointPrefix = this._module.config.modules.certificates?.endpointPrefix; return super._toDataPath(input, endpointPrefix); }
/** * Overrides superclass method to generate the URL path based on the input {@link Namespace} and the module's endpoint prefix configuration. * * @param {CallAction} input - The input {@link Namespace}. * @return {string} - The generated URL path. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/api.ts#L459-L463
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModuleApi._generateSubCACertificateSignedByCAServer
private async _generateSubCACertificateSignedByCAServer( certificate: Certificate, ): Promise<[string, string]> { const [csrPem, privateKeyPem] = generateCSR(certificate); const signedCertificate = await this._module.certificateAuthorityService.signedSubCaCertificateByExternalCA( csrPem, ...
/** * Generates a sub CA certificate signed by a CA server. * * @param {Certificate} certificate - The certificate information used for generating the root certificate. * @return {Promise<[string, string]>} An array containing the signed certificate and the private key. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/api.ts#L566-L575
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModuleApi._storeCertificateAndKey
private async _storeCertificateAndKey( certificateEntity: Certificate, certPem: string, keyPem: string, filePrefix: PemType, filePath?: string, ): Promise<Certificate> { // Store certificate and private key in file storage certificateEntity.privateKeyFileId = await this._fileAccess.uploadF...
/** * Store certificate in file storage and db. * @param certificateEntity certificate to be stored in db * @param certPem certificate pem to be stored in file storage * @param keyPem private key pem to be stored in file storage * @param filePrefix prefix for file name to be stored in file storage * @...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/api.ts#L586-L611
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
CertificatesModule.constructor
constructor( config: SystemConfig, cache: ICache, sender: IMessageSender, handler: IMessageHandler, logger?: Logger<ILogObj>, deviceModelRepository?: IDeviceModelRepository, certificateRepository?: ICertificateRepository, locationRepository?: ILocationRepository, certificateAuthority...
/** * This is the constructor function that initializes the {@link CertificatesModule}. * * @param {SystemConfig} config - The `config` contains configuration settings for the module. * * @param {ICache} [cache] - The cache instance which is shared among the modules & Central System to pass information s...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Certificates/src/module/module.ts#L127-L173
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
BootNotificationService.cacheChargerActionsPermissions
async cacheChargerActionsPermissions( stationId: string, cachedBootStatus: RegistrationStatusEnumType | null, bootNotificationResponseStatus: RegistrationStatusEnumType, ): Promise<void> { // New boot status is Accepted and cachedBootStatus exists (meaning there was a previous Rejected or Pending boot...
/** * Determines whether to blacklist or whitelist charger actions based on its boot status. * * If the new boot is accepted and the charger actions were previously blacklisted, then whitelist the charger actions. * If the new boot is not accepted and charger actions were previously whitelisted, then blackl...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/BootNotificationService.ts#L128-L162
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
BootNotificationService.confirmGetBaseReportSuccess
async confirmGetBaseReportSuccess( stationId: string, requestId: string, getBaseReportMessageConfirmation: IMessageConfirmation, maxCachingSeconds: number, ): Promise<void> { if (getBaseReportMessageConfirmation.success) { this._logger.debug( `GetBaseReport successfully sent to charg...
/** * Based on the GetBaseReportMessageConfirmation, checks the cache to ensure GetBaseReport truly succeeded. * If GetBaseReport did not succeed, this method will throw. Otherwise, it will finish without throwing. * * @param stationId * @param requestId * @param getBaseReportMessageConfirmation * ...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/BootNotificationService.ts#L194-L232
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
DeviceModelService.getItemsPerMessageSetVariablesByStationId
async getItemsPerMessageSetVariablesByStationId( stationId: string, ): Promise<number | null> { const itemsPerMessageSetVariablesAttributes: VariableAttribute[] = await this._deviceModelRepository.readAllByQuerystring({ stationId: stationId, component_name: 'DeviceDataCtrlr', var...
/** * Fetches the ItemsPerMessageSetVariables attribute from the device model. * Returns null if no such attribute exists. * It is possible for there to be multiple ItemsPerMessageSetVariables attributes if component instances or evses * are associated with alternate options. That structure is not supported...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/DeviceModelService.ts#L25-L44
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
DeviceModelService.getItemsPerMessageGetVariablesByStationId
async getItemsPerMessageGetVariablesByStationId( stationId: string, ): Promise<number | null> { const itemsPerMessageGetVariablesAttributes: VariableAttribute[] = await this._deviceModelRepository.readAllByQuerystring({ stationId: stationId, component_name: 'DeviceDataCtrlr', var...
/** * Fetches the ItemsPerMessageGetVariables attribute from the device model. * Returns null if no such attribute exists. * It is possible for there to be multiple ItemsPerMessageGetVariables attributes if component instances or evses * are associated with alternate options. That structure is not supported...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/DeviceModelService.ts#L56-L75
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
ConfigurationModuleApi.constructor
constructor( ConfigurationComponent: ConfigurationModule, server: FastifyInstance, logger?: Logger<ILogObj>, ) { super(ConfigurationComponent, server, logger); }
/** * Constructor for the class. * * @param {ConfigurationModule} ConfigurationComponent - The Configuration component. * @param {FastifyInstance} server - The server instance. * @param {Logger<ILogObj>} [logger] - Optional logger instance. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/api.ts#L95-L101
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
ConfigurationModuleApi._toMessagePath
protected _toMessagePath(input: CallAction): string { const endpointPrefix = this._module.config.modules.configuration.endpointPrefix; return super._toMessagePath(input, endpointPrefix); }
/** * Overrides superclass method to generate the URL path based on the input {@link CallAction} and the module's endpoint prefix configuration. * * @param {CallAction} input - The input {@link CallAction}. * @return {string} - The generated URL path. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/api.ts#L454-L458
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
ConfigurationModuleApi._toDataPath
protected _toDataPath(input: Namespace): string { const endpointPrefix = this._module.config.modules.configuration.endpointPrefix; return super._toDataPath(input, endpointPrefix); }
/** * Overrides superclass method to generate the URL path based on the input {@link Namespace} and the module's endpoint prefix configuration. * * @param {CallAction} input - The input {@link Namespace}. * @return {string} - The generated URL path. */
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/api.ts#L466-L470
462a009d9b7a2dabb8e9a55442654cdb39e672eb
citrineos-core
github_2023
citrineos
typescript
ConfigurationModule.constructor
constructor( config: SystemConfig, cache: ICache, sender?: IMessageSender, handler?: IMessageHandler, logger?: Logger<ILogObj>, bootRepository?: IBootRepository, deviceModelRepository?: IDeviceModelRepository, messageInfoRepository?: IMessageInfoRepository, idGenerator?: IdGenerator,...
/** * This is the constructor function that initializes the {@link ConfigurationModule}. * * @param {SystemConfig} config - The `config` contains configuration settings for the module. * * @param {ICache} [cache] - The cache instance which is shared among the modules & Central System to pass information ...
https://github.com/citrineos/citrineos-core/blob/462a009d9b7a2dabb8e9a55442654cdb39e672eb/03_Modules/Configuration/src/module/module.ts#L148-L205
462a009d9b7a2dabb8e9a55442654cdb39e672eb