@ondewo/nlu-client-angular
v7.0.0
Published
ONDEWO Natural Language Understanding (NLU) Client library for Angular
Maintainers
Readme
Overview
@ondewo/nlu-client-angular is a compiled version of the ONDEWO NLU API using the ONDEWO PROTO COMPILER. Here you can find the NLU API documentation.
ONDEWO APIs use Protocol Buffers version 3 (proto3) as their Interface Definition Language (IDL) to define the API interface and the structure of the payload messages. The same interface definition is used for gRPC versions of the API in all languages.
Setup
Using NPM:
npm i --save @ondewo/nlu-client-angularUsing GitHub:
git clone https://github.com/ondewo/ondewo-nlu-client-angular.git ## Clone repository
cd ondewo-nlu-client-angular ## Change into repo-directoy
make setup_developer_environment_locally ## Install dependenciesPackage structure
npm
├── api
│ ├── google
│ │ ├── api
│ │ │ ├── annotations.pb.d.ts
│ │ │ └── http.pb.d.ts
│ │ ├── rpc
│ │ │ └── status.pb.d.ts
│ │ └── type
│ │ └── latlng.pb.d.ts
│ └── ondewo
│ ├── nlu
│ │ ├── agent.pbconf.d.ts
│ │ ├── agent.pb.d.ts
│ │ ├── agent.pbsc.d.ts
│ │ ├── aiservices.pbconf.d.ts
│ │ ├── aiservices.pb.d.ts
│ │ ├── aiservices.pbsc.d.ts
│ │ ├── ...
│ └── qa
│ ├── qa.pbconf.d.ts
│ ├── qa.pb.d.ts
│ └── qa.pbsc.d.ts
├── esm2022
│ ├── api
│ │ ├── google
│ │ │ ├── api
│ │ │ │ ├── annotations.pb.mjs
│ │ │ │ └── http.pb.mjs
│ │ │ ├── rpc
│ │ │ │ └── status.pb.mjs
│ │ │ └── type
│ │ │ └── latlng.pb.mjs
│ │ └── ondewo
│ │ ├── nlu
│ │ │ ├── agent.pbconf.mjs
│ │ │ ├── agent.pb.mjs
│ │ │ ├── agent.pbsc.mjs
│ │ │ ├── ...
│ │ └── qa
│ │ ├── qa.pbconf.mjs
│ │ ├── qa.pb.mjs
│ │ └── qa.pbsc.mjs
│ ├── ondewo-nlu-client-angular.mjs
│ └── public-api.mjs
├── fesm2022
│ ├── ondewo-nlu-client-angular.mjs
│ └── ondewo-nlu-client-angular.mjs.map
├── index.d.ts
├── LICENSE.MD
├── package.json
├── public-api.d.ts
└── README.mdAuthentication (Keycloak bearer token)
The hand-written auth surface lives in src/auth/ and attaches the consumer's current
Keycloak access token as an Authorization: Bearer <token> credential to every outgoing gRPC-web and HTTP
request. This library performs no OAuth/OIDC flow itself — it never sees a password and never stores a
token. Acquiring and refreshing the token is the responsibility of keycloak-js / keycloak-angular in the
host application; this client only reads the current token through a TokenProvider and forwards it.
1. Implement a TokenProvider backed by keycloak-js
import { Injectable } from "@angular/core";
import Keycloak from "keycloak-js";
import { TokenProvider, TokenResult } from "@ondewo/nlu-client-angular";
@Injectable({ providedIn: "root" })
export class KeycloakTokenProvider implements TokenProvider {
constructor(private readonly keycloak: Keycloak) {}
// Refresh the token if it expires within 30s, then return the current one.
// Returning a Promise lets the interceptor await the refresh before sending.
getToken(): TokenResult {
return this.keycloak
.updateToken(30)
.then(() => this.keycloak.token ?? null)
.catch(() => null);
}
}getToken() may return a string, null (unauthenticated — the request is sent without an Authorization
header), a Promise<string | null>, or an Observable<string | null>. With keycloak-angular you would
instead inject KeycloakService and call this.keycloakService.getToken().
2. Register the provider and the interceptors
import { bootstrapApplication } from "@angular/platform-browser";
import { provideHttpClient, withInterceptors } from "@angular/common/http";
import { authHttpInterceptor, provideOndewoNluAuth } from "@ondewo/nlu-client-angular";
import { KeycloakTokenProvider } from "./keycloak-token-provider";
bootstrapApplication(AppComponent, {
providers: [
// Binds TOKEN_PROVIDER to your implementation and registers the
// @ngx-grpc AuthGrpcInterceptor for all generated *.pbsc.ts clients.
provideOndewoNluAuth(KeycloakTokenProvider),
// For plain HTTP requests, also register the functional HTTP interceptor.
provideHttpClient(withInterceptors([authHttpInterceptor]))
]
});That is all the wiring required: every NLU service client request now carries authorization: Bearer <token>
whenever a token is available, and is sent unchanged when it is not.
