@frontegg/client
Advanced tools
Comparing version 1.2.20 to 1.2.21
import { AuditsClient } from './src/audits'; | ||
import { FronteggAuthenticator } from './src/authenticator'; | ||
import { IdentityClient } from './src/identity'; | ||
import { FronteggAuthenticator } from './src/authenticator'; | ||
import { contextResolver, withAuthentication } from './src/identity'; | ||
import { frontegg, fronteggNextJs, IFronteggOptions } from './src/middleware'; | ||
import { ContextHolder, frontegg, fronteggNextJs, IFronteggOptions } from './src/middleware'; | ||
import { NotificationsClient } from './src/notifications'; | ||
@@ -12,2 +12,2 @@ import { FronteggPermissions } from './src/permissions'; | ||
export * from './src/events'; | ||
export { AuditsClient, NotificationsClient, TenantsClient, frontegg, fronteggNextJs, FronteggPermissions, IFronteggOptions, FronteggAuthenticator, RbacMiddleware, SsoClient, withAuthentication, contextResolver, IdentityClient }; | ||
export { AuditsClient, ContextHolder, NotificationsClient, TenantsClient, frontegg, fronteggNextJs, FronteggPermissions, IFronteggOptions, FronteggAuthenticator, RbacMiddleware, SsoClient, withAuthentication, contextResolver, IdentityClient, }; |
@@ -8,6 +8,6 @@ "use strict"; | ||
exports.AuditsClient = audits_1.AuditsClient; | ||
var authenticator_1 = require("./src/authenticator"); | ||
exports.FronteggAuthenticator = authenticator_1.FronteggAuthenticator; | ||
var identity_1 = require("./src/identity"); | ||
exports.IdentityClient = identity_1.IdentityClient; | ||
var authenticator_1 = require("./src/authenticator"); | ||
exports.FronteggAuthenticator = authenticator_1.FronteggAuthenticator; | ||
var identity_2 = require("./src/identity"); | ||
@@ -17,2 +17,3 @@ exports.contextResolver = identity_2.contextResolver; | ||
var middleware_1 = require("./src/middleware"); | ||
exports.ContextHolder = middleware_1.ContextHolder; | ||
exports.frontegg = middleware_1.frontegg; | ||
@@ -19,0 +20,0 @@ exports.fronteggNextJs = middleware_1.fronteggNextJs; |
@@ -6,6 +6,9 @@ export declare class FronteggAuthenticator { | ||
private apiKey; | ||
private refreshTimeout; | ||
private shuttingDown; | ||
init(clientId: string, apiKey: string): Promise<void>; | ||
refreshAuthentication(): Promise<void>; | ||
validateAuthentication(): Promise<void>; | ||
shutdown(): Promise<void>; | ||
private authenticate; | ||
} |
@@ -47,2 +47,4 @@ "use strict"; | ||
this.apiKey = ''; | ||
this.refreshTimeout = null; | ||
this.shuttingDown = false; | ||
} | ||
@@ -86,2 +88,13 @@ FronteggAuthenticator.prototype.init = function (clientId, apiKey) { | ||
}; | ||
FronteggAuthenticator.prototype.shutdown = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.shuttingDown = true; | ||
if (this.refreshTimeout !== null) { | ||
clearTimeout(this.refreshTimeout); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
FronteggAuthenticator.prototype.authenticate = function (force) { | ||
@@ -113,3 +126,3 @@ if (force === void 0) { force = false; } | ||
if (e_1.response) { | ||
logger_1.default.error('failed response - '); | ||
logger_1.default.error('failed response: '); | ||
logger_1.default.error(e_1.response.data); | ||
@@ -129,5 +142,7 @@ logger_1.default.error(e_1.response.status); | ||
this.accessTokenExpiry = Date.now() + nextRefresh; | ||
setTimeout(function () { | ||
_this.refreshAuthentication(); | ||
}, nextRefresh); | ||
if (!this.shuttingDown) { | ||
this.refreshTimeout = setTimeout(function () { | ||
_this.refreshAuthentication(); | ||
}, nextRefresh); | ||
} | ||
return [2 /*return*/]; | ||
@@ -134,0 +149,0 @@ } |
@@ -5,2 +5,3 @@ "use strict"; | ||
if (exports.baseUrl.endsWith('/')) { | ||
// Take the base url | ||
exports.baseUrl = exports.baseUrl.slice(0, -1); | ||
@@ -7,0 +8,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export * from './EventsClient'; | ||
export * from './types'; | ||
export * from './events'; |
@@ -6,3 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./EventsClient")); | ||
__export(require("./types")); | ||
__export(require("./events")); | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,4 @@ | ||
export * from './WebpushProperties.interface'; | ||
export * from './BellProperties.interface'; | ||
export * from './AuditProperties.interface'; | ||
export * from './TriggerOptions.interface'; | ||
export * from './BellAction.interface'; | ||
export * from './ChannelsConfiguration.interface'; | ||
export * from './WebhookBody.type'; | ||
export * from './Channels.type'; | ||
export * from './SlackProperties.interface'; | ||
export * from './channel-configuration'; | ||
export * from './errors'; | ||
export * from './event-types'; | ||
export * from './status-types'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./errors")); | ||
//# sourceMappingURL=index.js.map |
@@ -95,2 +95,5 @@ "use strict"; | ||
this.publicKey = publicKey; | ||
return [4 /*yield*/, authenticator.shutdown()]; | ||
case 3: | ||
_b.sent(); | ||
return [2 /*return*/]; | ||
@@ -97,0 +100,0 @@ } |
@@ -45,8 +45,7 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
var proxy = httpProxy.createProxyServer({ secure: false, changeOrigin: true }); | ||
var proxy = httpProxy.createProxyServer({ secure: false, changeOrigin: true, xfwd: true }); | ||
var target = process.env.FRONTEGG_API_GATEWAY_URL || 'https://api.frontegg.com/'; | ||
var pjson = getPackageJSON_1.getPackageJson() || { version: 'unknown' }; | ||
var authenticator = new authenticator_1.FronteggAuthenticator(); | ||
var MAX_RETRIES = 3; | ||
function proxyRequest(req, res, context) { | ||
function proxyRequest(req, res, context, authenticator) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -97,2 +96,3 @@ var headers; | ||
} | ||
var authenticator = new authenticator_1.FronteggAuthenticator(); | ||
ContextHolder_1.ContextHolder.setContext({ | ||
@@ -118,3 +118,3 @@ FRONTEGG_CLIENT_ID: options.clientId, | ||
context = _a.sent(); | ||
return [2 /*return*/, proxyRequest(req, res, context)]; | ||
return [2 /*return*/, proxyRequest(req, res, context, authenticator)]; | ||
} | ||
@@ -190,2 +190,3 @@ }); | ||
// response was already sent from the middleware, we have nothing left to do | ||
logger_1.default.debug('Headers was already sent from authMiddleware'); | ||
return [2 /*return*/]; | ||
@@ -197,2 +198,7 @@ } | ||
logger_1.default.error("Failed to call middleware - ", e_1); | ||
if (res.headersSent) { | ||
// response was already sent from the middleware, we have nothing left to do | ||
logger_1.default.debug('authMiddleware threw error, but headers was already sent'); | ||
return [2 /*return*/]; | ||
} | ||
return [2 /*return*/, res.status(401).send(e_1.message)]; | ||
@@ -229,3 +235,3 @@ case 7: | ||
logger_1.default.debug("going to proxy request"); | ||
return [2 /*return*/, proxyRequest(req, res, context)]; | ||
return [2 /*return*/, proxyRequest(req, res, context, authenticator)]; | ||
} | ||
@@ -232,0 +238,0 @@ }); |
import { AuditsClient } from './src/audits'; | ||
import { FronteggAuthenticator } from './src/authenticator'; | ||
import { IdentityClient } from './src/identity'; | ||
import { FronteggAuthenticator } from './src/authenticator'; | ||
import { contextResolver, withAuthentication } from './src/identity'; | ||
import { frontegg, fronteggNextJs, IFronteggOptions } from './src/middleware'; | ||
import { ContextHolder, frontegg, fronteggNextJs, IFronteggOptions } from './src/middleware'; | ||
import { NotificationsClient } from './src/notifications'; | ||
@@ -16,2 +16,3 @@ import { FronteggPermissions } from './src/permissions'; | ||
AuditsClient, | ||
ContextHolder, | ||
NotificationsClient, | ||
@@ -28,3 +29,3 @@ TenantsClient, | ||
contextResolver, | ||
IdentityClient | ||
IdentityClient, | ||
}; |
{ | ||
"name": "@frontegg/client", | ||
"version": "1.2.20", | ||
"version": "1.2.21", | ||
"description": "Frontegg Javascript Library for backend", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,2 +16,45 @@ # Frontegg Client | ||
## Breaking changes | ||
### v2.0 Events client upgraded to use the v3 Events API | ||
As we grow as a company we also provide new and improved APIs such as the new v3 Events API. | ||
This will allow your to configure more and worry less about channels. It is still not perfect, but we're getting there. | ||
With the new v3 api you'll be able to use the frontegg portal to map events to channels in order to allow your customers to configure their own channels. | ||
The new client will no longer send the channels you wish to trigger, and just use the event's payload. | ||
Please note that email & slack may still require further data (like the email template or slack message format). | ||
Unlike previous clients, the new client requires that you pass a separate authenticator. | ||
Example: | ||
```javascript | ||
const authenticator = new FronteggAuthenticator(); | ||
await authenticator.init('<YOUR_CLIENT_ID>', '<YOUR_API_KEY>') | ||
const eventsClient = new EventsClient(authenticator); | ||
const id = await eventsClient.send( | ||
'my-tenant-id', | ||
{ | ||
eventKey: 'my.event', | ||
data: { | ||
description: 'my description', | ||
title: 'my title' | ||
}, | ||
channelConfiguration: { | ||
email: { | ||
from: 'email@email.com', | ||
html: '<div>{{title}}</div>', // data interpolation using the event data | ||
subject: 'subject' | ||
}, | ||
slack: { | ||
emails: ['email@email.com'], | ||
slackMessageConfig: { | ||
// use https://api.slack.com/methods/chat.postMessage data format to fill this configuration | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
--- | ||
## Usage | ||
@@ -104,5 +147,2 @@ | ||
``` | ||
### Audits | ||
@@ -222,2 +262,2 @@ | ||
})); | ||
``` | ||
``` |
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
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
Sorry, the diff of this file is not supported yet
260
236387
102
3482