@mojaloop/event-sdk
Version:
Shared code for Event Logging
93 lines (87 loc) • 4.07 kB
JavaScript
;
/*****
License
--------------
Copyright © 2020-2025 Mojaloop Foundation
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Mojaloop Foundation for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Mojaloop Foundation
- Name Surname <name.surname@mojaloop.io>
- Ramiro González Maciel <ramiro@modusbox.com>
- Valentin Genev <valentin.genev@modusbox.com>
--------------
******/
/**
* Example showing how to use EventLogger from TypeScript
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
const Tracer_1 = require("../Tracer");
const EventMessage_1 = require("../model/EventMessage");
const now = new Date();
const event = {
from: "noresponsepayeefsp",
to: "payerfsp",
id: "aa398930-f210-4dcd-8af0-7c769cea1660",
content: {
headers: {
"content-type": "application/vnd.interoperability.transfers+json;version=1.0",
date: "2019-05-28T16:34:41.000Z",
"fspiop-source": "noresponsepayeefsp",
"fspiop-destination": "payerfsp",
priority: 100,
blocking: false
},
payload: "data:application/vnd.interoperability.transfers+json;version=1.0;base64,ewogICJmdWxmaWxtZW50IjogIlVObEo5OGhaVFlfZHN3MGNBcXc0aV9VTjN2NHV0dDdDWkZCNHlmTGJWRkEiLAogICJjb21wbGV0ZWRUaW1lc3RhbXAiOiAiMjAxOS0wNS0yOVQyMzoxODozMi44NTZaIiwKICAidHJhbnNmZXJTdGF0ZSI6ICJDT01NSVRURUQiCn0",
data: {
str1: 'Hi world',
number1: 12345,
date1: now,
bool1: true,
nil1: null,
undef1: undefined,
array1: ["Hello", 1234, now, true, null, undefined],
child: {
str2: 'Hi world',
number2: 12345,
date2: now,
bool2: true,
nil2: null,
undef2: undefined,
array2: ["Hello", 1234, now, true, null, undefined],
}
}
},
type: "application/json",
metadata: {
event: EventMessage_1.EventMetadata.log({
id: "3920382d-f78c-4023-adf9-0d7a4a2a3a2f",
action: (new EventMessage_1.LogEventTypeAction(EventMessage_1.LogEventAction.debug)).action, // Actions which are available can be generated by the respective methods
createdAt: "2019-05-29T23:18:32.935Z",
state: {
status: EventMessage_1.EventStatusType.success,
code: 0,
description: "action successful"
},
responseTo: "1a396c07-47ab-4d68-a7a0-7a1ea36f0012"
})
} // metadata with specific type definition
};
const tracer = Tracer_1.Tracer.createSpan('new-span'); // Creates new trace with its first span.
console.log('app: sending message', JSON.stringify(event, null, 2));
tracer.info(event) // Logs event message with log level info. For the rest of the methods and usecases you can see the js_app.js
.then(result => {
console.log('app: received back:', JSON.stringify(result, null, 2));
});
//# sourceMappingURL=ts_app.js.map