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

View file

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

View file

@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */ /** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = { module.exports = {
preset: 'ts-jest', preset: "ts-jest",
testEnvironment: 'node', 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", "name": "lhisp-oauth-client-dev",
"version": "1.0.29", "version": "1.0.30",
"main": "src/index", "main": "src/index",
"types": "src/index.d.ts", "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>", "author": "Leandro Costa <contato@leandrocosta.pro.br>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -12,14 +15,14 @@
"test:watch": "jest --watchAll" "test:watch": "jest --watchAll"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.8", "@types/jest": "^30.0.0",
"@types/node": "^20.9.0", "@types/node": "^24.0.4",
"jest": "^29.7.0", "jest": "^30.0.3",
"ts-jest": "^29.1.1", "ts-jest": "^29.4.0",
"typescript": "^5.2.2" "typescript": "^5.8.3"
}, },
"dependencies": { "dependencies": {
"axios": "^1.6.1", "axios": "^1.10.0",
"lhisp-logger": "^1.0.14" "lhisp-logger": "^1.0.16"
} }
} }