YAAS TypeScript API (for Angular2, Ionic2, ...)
Updated 343 Days AgoPublic

Especially if you plan to develop modern web or standalone applications, BrainBoutique highly encourages you to evaluate Angular2 (Hybris YAAS also uses Angular(1) - an older version - for some of the tools) and Ionic2 - awesome technology boosting your implementation significantly! To ease access to YAAS REST APIs, convenience libraries are provided.

RAML

Hybris SAP leverages RAML to specify external APIs - this seems to be a pretty good choice - but it comes with some *buts*:

  • Still uses RAML 0.8, latest is 1.0
  • Mid-term the specification language may merge into OpenAPI (formerly Swagger)
  • Tool support is far from optimal

Biggest limitation for effective development seems to be that RAML client for JavaScript only at runtime assembles required REST URLs, schemas and signatures. At development time, very little support on syntax highlighting, parameter validation etc is used.

Typescript

With TypeScript, however, a lot of validation can already happen at compile time, reducing the risk of "unexpected behaviour", runtime glitches or version issues.

To fully leverage those advantages, BrainBoutique compiled a tool raml-typescript-generator to convert Hybris provided RAML files into directly usable Node modules - which can then be used at compile time to help with auto complete, validation etc:

Result documents are automatically mapped to a matching "type" (aka JSon Schema in RAML), allowing the developer to directly assess promised values:

Installation

To install client API, use npm like

npm install --save yaas-api-schema-v1

Check readme files for detailed usage examples.

Currently following encapsulation modules are provided:

BrainBoutique will publish additional clients as soon as possible and as required by current projects. If, however, you would need specific RAML encapsulations for your setup, please get in contact with NOSPAM_info@brainboutique.de to check (and potentially align) release schedule.

Usage example

import {YaasApiSchemaV1 as YaasApiSchema, SchemasData} from 'yaas-api-schema-v1';

@Injectable()
export class YaasIntegrationService {
  schemaService: YaasApiSchema;

  constructor() {
    this.schemaService = new YaasApiSchema({
      getHeaders: () => {
        return (authService.getHybrisAuthHeaders())
      }
    });


  getSchemas(): Observable<YaasSchemaDictionary> {
    return Observable.create((observer) => {
      this.authService.authenticate().subscribe(() => {
        this.schemaService.tenant(this.authService.getTenant()).GET(null, 1, 100)
          .subscribe(s => {
            if (s._400) {
              console.error(s._400.message)
            } else if (s._200) {
              s._200.forEach(schema => {
                console.log("Schema ", schema); // "schema" is SchemasData.SchemaMetadata
           ...
  }

Limitations

  • Unfortunately YAAS OAuth2 does not seem to be fully aligned with RAML auto-processing so OAuth2 token must be fetched manually upfront and provided via getHeaders() callback.
  • Result documents are not validated against schema (not a priority as this should just be a "safeguard")
  • Provided Hybris YAAS RAML files unfortunately are not overly accurate. Files have been fixed "best effort", see YAAS API.
Last Author
whein
Projects
None
Subscribers
None