version: 1.0.30 #1

Merged
leandro merged 18 commits from development into master 2025-06-27 20:36:01 +00:00
6 changed files with 2348 additions and 1459 deletions

View file

@ -0,0 +1,58 @@
name: CI Pipeline
on:
push:
branches:
- master
- development
pull_request:
branches:
- development
workflow_dispatch:
jobs:
build-and-test:
runs-on: docker
container:
image: node:20-alpine
steps:
- name: Git Clone
uses: actions/checkout@v4
- name: Restore Node Modules Cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install
- name: Build Project
run: npm run build
- name: Run Tests
run: npm run test
- name: Prepare Package
run: cp package.json dist
- uses: actions/upload-artifact@v3
name: Upload Artifact
with:
name: dist
path: dist
publish:
runs-on: docker
container:
image: node:20-alpine
needs: [build-and-test]
steps:
- name: Publish Npm Packages
uses: https://git.lhprovedor.com.br/leandro/devops/.forgejo/actions/publish-npm-package@main
with:
npm_token: ${{ secrets.NPM_TOKEN }}
git_token: ${{ secrets.PACKAGE_PUBLISHER_TOKEN }}

View file

@ -1,14 +1,14 @@
import axios from "axios";
import { LhispOauthClient } from "../src/lhisp-oauth-client";
import { ContentType, LhispOauthClientConstructorParams, defaultAuthContentType } from "../src/lhisp-oauth-client.t";
import { ContentType, LhispOauthClientConstructorParams } from "../src/lhisp-oauth-client.t";
// Mock jest and set the type
jest.mock("axios");
const mockedAxios = axios as jest.Mocked<typeof axios>;
const mockedAxios = jest.mocked(axios);
const apiUrl = "https://myapi.com";
const authUrl = "https://auth.myapi.com/oauth/token";
const clientId = "testClientdId";
const clientId = "testClientId";
const clientSecret = "testClientSecret";
const baseClientParams = { apiUrl, authUrl, clientId, clientSecret };
const basicAuth = `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`;
@ -23,19 +23,19 @@ describe("Get Access Token", () => {
mockedAxios.request.mockResolvedValueOnce({ data: mockedAccessToken });
});
it("Shoud Get with Standard Config", async () => {
it("Should Get with Standard Config", async () => {
const cli = getOauthClient();
await accessTokenValidator(cli);
validateDefaultGetAccessToken();
});
it("Shoud Get with Custom Auth Header", async () => {
it("Should Get with Custom Auth Header", async () => {
const cli = getOauthClient({
...baseClientParams,
authHeaderName: "CustomAuthorizationHeader",
});
await accessTokenValidator(cli);
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: authUrl,
method: "POST",
@ -48,13 +48,13 @@ describe("Get Access Token", () => {
);
});
it("Shoud Get with Custom Grant Type", async () => {
it("Should Get with Custom Grant Type", async () => {
const cli = getOauthClient({
...baseClientParams,
grantType: "PermissaoCustom",
});
await accessTokenValidator(cli);
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: authUrl,
method: "POST",
@ -67,13 +67,13 @@ describe("Get Access Token", () => {
);
});
it("Shoud Get with Custom Auth Scope", async () => {
it("Should Get with Custom Auth Scope", async () => {
const cli = getOauthClient({
...baseClientParams,
authScope: "EscopoCustom",
});
await accessTokenValidator(cli);
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: authUrl,
method: "POST",
@ -86,14 +86,14 @@ describe("Get Access Token", () => {
);
});
it("Shoud Get with Credentials on Request body", async () => {
it("Should Get with Credentials on Request body", async () => {
const cli = getOauthClient({
...baseClientParams,
authContentType: contentTypeApplicationJson,
sendAuthCredentialsOnRequestBody: true,
});
await accessTokenValidator(cli);
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: authUrl,
method: "POST",
@ -118,7 +118,7 @@ describe("Request", () => {
const cli = getOauthClient();
const resp = await cli.get({ path: "/my-test-url" });
validateDefaultGetAccessToken();
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: `${apiUrl}/my-test-url`,
method: "GET",
@ -136,7 +136,7 @@ describe("Request", () => {
const cli = getOauthClient();
const resp = await cli.get({ path: "/my-test-url", params: { id: 1 } });
validateDefaultGetAccessToken();
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: `${apiUrl}/my-test-url`,
method: "GET",
@ -155,7 +155,7 @@ describe("Request", () => {
const cli = getOauthClient();
const resp = await cli.post({ path: "/my-test-url-post", data: { id: 1, user: "test" } });
validateDefaultGetAccessToken();
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: `${apiUrl}/my-test-url-post`,
method: "POST",
@ -177,7 +177,7 @@ describe("Request", () => {
contentType: ContentType.APPLICATION_X_WWW_FORM_URLENCODED,
});
validateDefaultGetAccessToken();
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: `${apiUrl}/my-test-url-post`,
method: "POST",
@ -202,7 +202,7 @@ describe("Request", () => {
contentType: ContentType.APPLICATION_X_WWW_FORM_URLENCODED,
});
validateDefaultGetAccessToken();
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: `${apiUrl}/my-test-url-post`,
method: "POST",
@ -218,7 +218,7 @@ describe("Request", () => {
});
function validateDefaultGetAccessToken() {
expect(mockedAxios.request).toBeCalledWith(
expect(mockedAxios.request).toHaveBeenCalledWith(
expect.objectContaining({
url: authUrl,
method: "POST",

View file

@ -15,7 +15,7 @@ pipelines:
branches:
default:
<<: *build-and-test
"{development,realease-no-verify/*}":
"{development,release-no-verify/*}":
- step: *build-and-test
- step:
name: Prepare Package

View file

@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/node_modules/"],
};

3681
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,12 @@
{
"name": "lhisp-oauth-client",
"version": "1.0.29",
"name": "lhisp-oauth-client-dev",
"version": "1.0.30",
"main": "src/index",
"types": "src/index.d.ts",
"repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",
"repository": {
"type": "git",
"url": "https://git.lhprovedor.com.br/leandro/lhisp-oauth-client.git"
},
"author": "Leandro Costa <contato@leandrocosta.pro.br>",
"license": "MIT",
"scripts": {
@ -12,14 +15,14 @@
"test:watch": "jest --watchAll"
},
"devDependencies": {
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"@types/jest": "^30.0.0",
"@types/node": "^24.0.4",
"jest": "^30.0.3",
"ts-jest": "^29.4.0",
"typescript": "^5.8.3"
},
"dependencies": {
"axios": "^1.6.1",
"lhisp-logger": "^1.0.14"
"axios": "^1.10.0",
"lhisp-logger": "^1.0.16"
}
}