Repository URL to install this package:
|
Version:
0.9.2-rc0 ▾
|
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
'use strict';
const { superbrain } = require('@supertenant/superbrain');
const consts = require('@supertenant/superconsts');
const { getOrCreateTask } = require('./tracing/taskManager');
const { instrumentFastify } = require('./tracing/instrumentation/frameworks/fastify');
class SuperTenantSDK {
/**
* Sets the tenant identifier for the current run context.
* @param {string} tenantId
* @returns {boolean}
*/
setTenantId(tenantId) {
try {
const taskId = getOrCreateTask();
return superbrain.setLabelOnSharedData(taskId, consts.Label.SupertenantTenantId, tenantId);
} catch (e) {
return false;
}
}
/**
* Instruments Fastify, with optional tenant getter function which should return string
* @param {object} app
* @param {string} hook
* @param {(object) => string | Promise<string>} tenantGetter
*/
instrumentFastify(app, hook, tenantGetter) {
instrumentFastify(app, hook, tenantGetter);
}
}
/**
* Returns a new instance of the SuperTenant SDK
*
* @returns {SuperTenantSDK}
*/
function getSuperTenantSDK() {
return new SuperTenantSDK();
}
module.exports = getSuperTenantSDK;