Skip to content

Commit

Permalink
Merge pull request #77 from dxc-technology/upgrade-actions
Browse files Browse the repository at this point in the history
Upgrade GitHub actions to latest versions and Node16.js
  • Loading branch information
Jialecl authored Dec 12, 2023
2 parents 090569e + 0a49e2e commit feaca70
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 221 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Working Version

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: "18"
registry-url: https://registry.npmjs.org/

- name: Install lib dependencies
run: cd lib && npm install

- name: Build library
run: cd lib && npm run build

- name: Test library
run: cd lib && npm run test:coverage
50 changes: 25 additions & 25 deletions .github/workflows/publish-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ name: Publish Next Version

on:
push:
branches: [ master ]
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.x
registry-url: https://registry.npmjs.org/
- name: Install lib dependencies
run: cd lib && npm install
- name: Build library
run: cd lib && npm run build
- name: Test library
run: cd lib && npm run test:coverage
- name: Publish NEXT version to npm
run: |
sed -i "s#\"version\": \"0.0.0\"#\"version\": \"0.0.0-${GITHUB_SHA:0:7}\"#" ./lib/dist/package.json
cd lib/dist
npm publish --tag next --access public
env:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: "18"
registry-url: https://registry.npmjs.org/

- name: Install lib dependencies
run: cd lib && npm install

- name: Build library
run: cd lib && npm run build

- name: Test library
run: cd lib && npm run test:coverage

- name: Publish NEXT version to npm
run: |
sed -i "s#\"version\": \"0.0.0\"#\"version\": \"0.0.0-${GITHUB_SHA:0:7}\"#" ./lib/dist/package.json
cd lib/dist
npm publish --tag next --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
52 changes: 26 additions & 26 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.x
registry-url: https://registry.npmjs.org/
- name: Install lib dependencies
run: cd lib && npm install
- name: Build library
run: cd lib && npm run build
- name: Test library
run: cd lib && npm run test:coverage
- name: Publish RELEASE to npm
run: |
sed -i "s#\"version\": \"0.0.0\"#\"version\": \"${TAG_NAME}\"#" ./lib/dist/package.json
cd lib/dist
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
TAG_NAME: ${{ github.event.release.tag_name }}
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node.js 18
uses: actions/setup-node@v3
with:
node-version: "18"
registry-url: https://registry.npmjs.org/

- name: Install lib dependencies
run: cd lib && npm install

- name: Build library
run: cd lib && npm run build

- name: Test library
run: cd lib && npm run test:coverage

- name: Publish RELEASE to npm
run: |
sed -i "s#\"version\": \"0.0.0\"#\"version\": \"${TAG_NAME}\"#" ./lib/dist/package.json
cd lib/dist
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
TAG_NAME: ${{ github.event.release.tag_name }}
126 changes: 5 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,11 @@ Halstack Client for JavaScript enables developers to easily work with hypermedia

This SDK is released as a client-agnostic library that can be used both in browser applications (such as Vanilla JS, React or Angular applications) or backend applications (NodeJS applications). As such, it is distributed as UMD.

## Installation
## Structure of this repository

```sh
npm install @dxc-technology/halstack-client
```

### Use in Node.js

```js
// require from the dependency the modules you need
const {
HalResource,
HalResponse,
HalApiCaller,
} = require("@dxc-technology/halstack-client");
```

### Use in browsers

```js
// require from the dependency the modules you need
import {
HalResource,
HalResponse,
HalApiCaller,
} from "@dxc-technology/halstack-client";
```

## HalResource Factory

The purpose of this module is facilitating the access to the information of a given resource. This factory function receives a JSON object with the HAL Resource Representation as a parameter.

It returns a [HalResource Object](#halresource-object), encapsulating the original HAL Resource Representation and including a set of functions that will allow you to access the data from the resource in a declarative manner, without having to fully understand the details of how HAL resource representation is structured.

The `HalResource` can also be used to help developers to create a compliant `HalResource` representation to be included in a Hal response, exposing functions to add different sections that typically can be found in a resource.

### HalResource Object

| Name | Type | Description |
| :----------------------- | :------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `resourceRepresentation` | `Object` | The whole resource representation. |
| `getTitle` | `()=>String` | Returns the resource title. Taken from `\_options.title`. |
| `getInteractions` | `()=>HalInteraction[]` | Returns an array of [HalInteraction](#halinteraction-object) objects. Taken from the `\_options.links` array. |
| `getInteraction` | `(String)=>HalInteraction` | Receives a string with the `rel` of the interaction. Returns the [HalInteraction](#halinteraction-object) object. |
| `getItems` | `()=>Object[]` | Returns an array of the original item link objects. Taken from the `\_links.item` array. |
| `getItem` | `(Number)=>Object` | Receives the index of the item. Returns the item object. |
| `getLinks` | `()=>Object[]` | Returns an array of the original link objects (adding the `rel`), ignoring `item` link. Taken from the `\_links` object. |
| `getLink` | `(String)=>Object` | Receives a string with the `rel` of the link. Returns the link object (adding the `rel`). |
| `getProperties` | `()=>Object[]` | Returns an array of [HalProperty](#halproperty-object) objects. Taken from the resource root level properties. |
| `getProperty` | `(String)=>Object` | Receives a string with the key of the property. Returns the [HalProperty](#halproperty-object) object. |
| `getRequiredProperties` | `()=>String[]` | Returns an array with the required properties key. Taken from the `\_options.required` array. |
| `isPropertyRequired` | `(String)=>Bool` | Receives the key of a property. Returns true if it exists within the `\_options.required` array. |
| `getSchemaProperties` | `()=>Object[]` | Returns an array of the original schema objects for properties (adding `key`). Taken from the `\_options.properties` object. |
| `getSchemaProperty` | `(String)=>Object` | Receives the key of a property. Returns the property's schema object (adding `key`) if exists within `\_options.properties` object. |
| `addLink` | `(Object)=>void` | Receives an object as parameter. This object can contain the usual link properties as { `rel`, `name`, `href`, `title` } where `rel` and `href` are required. The `object` will be added to the `\links` section using `rel` as key |
| `addLinks` | `(Object)=>void` | Receives an object as parameter. This object can contain the usual link properties as { `rel`, `name`, `href`, `title` } where `rel` and `href` are required. The object will be added to the `\links` section using `rel` as key |
| `addTitle` | `(String)=>void` | Assign the parameter received to the resource title in `\_options`.title |
| `addItem` | `(Object)=>void` | Add the object received as parameter as a resource `\_link` item |
| `addItems` | `(Object[])=>void` | Add every object in the list received as parameter as a resource `\_link` item. |
| `addProperties` | `(Object)=>void` | Add the key:values found in the object received as parameter as resource properties. |
| `addOptionsProperties` | `(Object)=>void` | Add every property received in parameter as property under the `\_options.properties` section |
| `addOptionsProperty` | `(Object)=>void` | Add the property ({key: schema}) received in parameter as property under the `\_options.properties` section |
| `addInteraction` | `(Object)=>void` | Add the object received as parameter (`{rel: Interaction}`) under the `options.link` section |
| `addOptions` | `(Object)=>void` | It receives an object as parameter and add interactions , properties, required and title if those sections are found as object keys. |

### HalInteraction Object

Includes the existing attributes of the original interaction object. It provides the following additional helper functions:

| Name | Type | Description |
| :---------------------- | :----------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getRequiredProperties` | `()=>String[]` | Returns an array with the required properties key. Taken from the "schema.required" array of the interaction. |
| `isPropertyRequired` | `(String)=>Bool` | Receives the key of a property. Returns true if it exists within the "schema.required" array of the interaction. |
| `getSchemaProperties` | `()=>Object[]` | Returns an array of the original schema objects for properties (adding `key`). Taken from the `\schema.properties` object of the interaction. |
| `getSchemaProperty` | `(String)=>Object` | Receives the key of a property. Returns the property's schema object (adding `key`) if exists within `\schema.properties` object of the interaction. |
| `hasProperty` | `(String)=>Bool` | Receives the key of a property. Returns true if it exists within the `\schema.properties` object of the interaction. |

### HalProperty Object

| Name | Type | Description |
| :-------------------- | :--------------- | :---------------------------------------------------------------------------------------------------------------------------------------------- |
| `isRequired` | `()=>Bool` | Returns true if the property exists within the `\_options.required` array. |
| `existsInInteraction` | `(String)=>Bool` | Receives a string with the `rel` of an interaction. Returns true if the property exists within the "schema.properties" object of the interaction. |
| `getSchema` | `()=>Object` | Returns the property's schema object (adding `key`) if exists within `\_options.properties` object. |

## HalResponse Factory

The purpose of this module is facilitating the access to the information returned inside an API response. This factory function accepts an object with the following attributes as a parameter:

| Name | Type | Description |
| :-------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
| `body` | `Object` | The message-body is the data bytes transmitted associated with a http response. |
| `headers` | `Object` | Contains the http headers which provide information about the server and about further access to the resource identified by the Request-URI. |
| `status` | `Number` | Status codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request for Comments (RFCs). |

It returns [HalResponse Object](#halresponse-object).

### HalResponse Object

| Name | Type | Description |
| :-------------------- | :------------ | :------------------------------------------------------------------------------------------------- |
| `body` | `JSON Object` | Response message-body |
| `headers` | `JSON Object` | Http headers |
| `status` | `Number` | Https response code |
| `type` | `String` | Response format. Example: application/JSON |
| `halResource` | `HalResource` | [HalResource Object](#halresource-object) composed using the information provided inside the body. |
| `containsHalResource` | `Bool` | True if the content of the response is a HAL resource. |

## HalApiCaller Module

This module is a HTTP client which takes care of handing out parsed `HalResponses`. It exports the following functions:

| Name | Type | Description |
| :----------------- | :------------------------------ | :---------------------------------------------------------------------------------------------------------------------------- |
| `setGlobalHeaders` | `function` | Receives a headers object that will be used for all http requests done with this module. |
| `get` | `function:Promise(HalResponse)` | Receives a `{ url, headers }` object as a parameter. Returns a promise and will pass a HalResponse object to the handler. |
| `options` | `function:Promise(HalResponse)` | Receives a `{ url, headers }` object as a parameter. Returns a promise and will pass a HalResponse object to the handler. |
| `patch` | `function:Promise(HalResponse)` | Receives a `{ url, body, headers }` object as a parameter. Returns a promise and will pass a HalResponse object to the handler. |
| `post` | `function:Promise(HalResponse)` | Receives a `{ url, body, headers }` object as a parameter. Returns a promise and will pass a HalResponse object to the handler. |
| `put` | `function:Promise(HalResponse)` | Receives a `{ url, body, headers }` object as a parameter. Returns a promise and will pass a HalResponse object to the handler. |
| `del` | `function:Promise(HalResponse)` | Receives a `{ url, headers }` object as a parameter. Returns a promise and will pass a `HalResponse` object to the handler. |
This repository contains two software assets:
1. The Halstack Client library: [./lib](./lib). Documentation of the npm module is maintained in the [README](./lib/README.md) file in that folder.
2. A example apps that use the local copy of the Halstack Client library: [./example](./example)

## Develop

Expand All @@ -134,7 +18,7 @@ In the first place, clone this repository.
git clone https://github.com/dxc-technology/dxc-halstack-client.git
```

Local development is broken into two parts, related to the `lib/example` folders.
As stated before, local development is broken into two parts.

First, within the `lib` folder, run rollup to watch your `src/` module and automatically recompile it into `dist/` whenever you make changes.

Expand Down
Loading

0 comments on commit feaca70

Please sign in to comment.