Skip to content

Commit

Permalink
Make HttpRequestOptions accept 'headers' parameter when Axios request.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjiang-cb committed Nov 15, 2024
1 parent a55c551 commit 2eb32c1
Show file tree
Hide file tree
Showing 12 changed files with 5,851 additions and 5,976 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
pre-process:
name: Pre process
runs-on: ubuntu-latest
outputs:
outputs:
were-only-docs-updated: ${{ steps.were-only-docs-updated-action.outputs.were-only-docs-updated }}
steps:
- name: Checkout code
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 2.
fetch-depth: 2.
- name: Get commit range
id: get-commit-range-action
uses: ./.github/actions/get-commit-range-action
Expand Down Expand Up @@ -86,50 +86,50 @@ jobs:
security-events: write
strategy:
matrix:
node-version: [10.x]
node-version: [14.x]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Create cache folder
run: |
mkdir -p /home/runner/.npm
continue-on-error: true
continue-on-error: true
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache: 'npm'
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: javascript
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

codacy-analysis-cli:
name: Codacy Analysis CLI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@master
uses: codacy/codacy-analysis-cli-action@master

Check warning

Code scanning / Semgrep (reported by Codacy)

An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Warning

An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release.
with:
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
# Upload the SARIF file generated in the previous step
max-allowed-issues: 2147483647
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@main
with:
sarif_file: results.sarif

smoke-test:
name: Smoke Test
runs-on: ubuntu-latest
Expand All @@ -141,19 +141,19 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 8
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
java-version: '17'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Smoke Test
run: |
TZ='Asia/Shanghai'; export TZ
TZ='Asia/Shanghai'; export TZ
mkdir -p g11n-js-client
shopt -s extglob
mv !(g11n-js-client) g11n-js-client/
Expand Down
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"json"
],
"testRegex": "/test/*.*\\.spec\\.ts$",
"testEnvironment": "jsdom",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
Expand Down
11,677 changes: 5,762 additions & 5,915 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions package.client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@singleton-i18n/js-core-sdk",
"version": "0.5.7",
"version": "0.5.8",
"publishConfig": {
"registry": ""
},
Expand Down Expand Up @@ -42,18 +42,26 @@
"@types/node": "^10.11.7",
"awesome-typescript-loader": "^5.2.1",
"axios": "^0.21.1",
"jest": "^24.5.0",
"ts-jest": "^24.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^28.1.3",
"ts-jest": "^29.2.5",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-loader": "^3.5.4",
"typescript": "^4.4.4",
"typescript-loader": "^1.1.3",
"typings": "^2.1.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.3.0"
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4"
},
"changelogHistory": [
{
"date": "11/15/24",
"version": "0.5.8",
"notes": [
{
"description": "Make HttpRequestOptions accept 'headers' parameter when Axios request."
}
]
},
{
"date": "06/05/23",
"version": "0.5.7",
Expand Down
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@singleton-i18n/js-core-sdk-server",
"version": "0.5.7",
"version": "0.5.8",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"publishConfig": {
"registry": ""
},
Expand Down Expand Up @@ -42,18 +42,26 @@
"@types/node": "^10.11.7",
"awesome-typescript-loader": "^5.2.1",
"axios": "^0.21.1",
"jest": "^24.5.0",
"ts-jest": "^24.0.0",
"jest": "^29.7.0",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"jest-environment-jsdom": "^28.1.3",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"ts-jest": "^29.2.5",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-loader": "^3.5.4",
"typescript": "^4.4.4",
"typescript-loader": "^1.1.3",
"typings": "^2.1.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.3.0"
"webpack": "^5.96.1",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"webpack-cli": "^5.1.4"

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
},
"changelogHistory": [
{
"date": "11/15/24",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"version": "0.5.8",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"notes": [

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
{
"description": "Make HttpRequestOptions accept 'headers' parameter when Axios request."

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
}
]
},
{
"date": "06/05/23",
"version": "0.5.7",
Expand Down
11 changes: 7 additions & 4 deletions samples/client/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"load-translation": "load-translation --directory `pwd`/src/sources --product CoreSDKClient --component ui --host http://localhost:8091 --version 1.0 --languages zh,en"
},
"dependencies": {
"@singleton-i18n/js-core-sdk": "file:../../../singleton-i18n-js-core-sdk-0.5.7.tgz",
"@singleton-i18n/js-core-sdk": "file:../../../singleton-i18n-js-core-sdk-0.5.8.tgz",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"argparse": "^1.0.10",
"axios": "^0.21.1",
"typescript": "^4.4.4"
Expand All @@ -21,8 +21,11 @@
"copy-webpack-plugin": "^5.0.4",
"express": "^4.17.1",
"express-rate-limit": "^6.7.0",
"jest": "^24.9.0",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6"
"jest": "^29.7.0",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"webpack": "^5.96.1",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"webpack-cli": "^5.1.4"

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
},
"jest": {

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"testEnvironment": "jsdom"

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
}
}
34 changes: 19 additions & 15 deletions samples/client/js/src/i18n.utils.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
* Copyright 2019-2023 VMware, Inc.
* Copyright 2019-2024 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
import * as singletonCore from '@singleton-i18n/js-core-sdk';
import { ENGLISH } from './source.l10n';
import { config as defaultConfig } from './config';

/**
* Should be executed in the html file that needs to be localized.
*
* Should be executed in the html file that needs to be localized.
*
* @param {*} config object that provides the configuration with the following format
* {
* productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
* }
* productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
* }
*/
export function localize(config) {

config = config ? config : {};
// If some properties aren't provided by the given config
// If some properties aren't provided by the given config
// we are getting them from the defaultConfig
config = Object.assign(defaultConfig, config);
const lang = detectLanguage(config);
Expand All @@ -39,16 +39,20 @@ export function localize(config) {
language: lang,
sourceBundle: ENGLISH,
// Uncommend if you don't want to load your translation from singleton but from your sources
//i18nAssets: 'src/translations/',
//i18nAssets: 'src/translations/',
isPseudo: shouldUsePseudoTranslations(),
// It offers the feature to self-custom header for target product
httpOptions: {
headers: {'vrni-header': 'vrni_custom'}
}
}
);
loadAndShowTranslations(i18nClient, config);
}

/**
* Collects all elements from the page that have the l10n attribute.
* Gets the attribute's value which is the key for the message, localizes the message
* Collects all elements from the page that have the l10n attribute.
* Gets the attribute's value which is the key for the message, localizes the message
* and inserts it in the element.
*/
function loadAndShowTranslations(i18nClient, config) {
Expand All @@ -65,12 +69,12 @@ function loadAndShowTranslations(i18nClient, config) {
}

/**
* Function that gets the current language.
* If not set in the cookies it tries to detect the browser's.
* If the browser's language isn't supported by singleton, falls back to english.
* Function that gets the current language.
* If not set in the cookies it tries to detect the browser's.
* If the browser's language isn't supported by singleton, falls back to english.
*/
function detectLanguage(config) {
// First checks for lang in the cookie
// First checks for lang in the cookie
let language = getCookie(config.langCookieName);
if (language) {
return language;
Expand All @@ -81,8 +85,8 @@ function detectLanguage(config) {
return language || undefined;
}

/**
* Gets a cookie by its name.
/**
* Gets a cookie by its name.
*/
function getCookie(name) {
function escape(s) { return s.replace(/([.*+?\^${}()|\[\]\/\\])/g, '\\$1'); };
Expand Down
2 changes: 1 addition & 1 deletion samples/server/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"collect-source-bundle": "collect-source-bundle --source-dir `pwd`/i18n --product NodeSample --component NodeJS --host http://localhost:8091 --version 1.0"
},
"dependencies": {
"@singleton-i18n/js-core-sdk-server": "file:../../../singleton-i18n-js-core-sdk-server-0.5.7.tgz",
"@singleton-i18n/js-core-sdk-server": "file:../../../singleton-i18n-js-core-sdk-server-0.5.8.tgz",

Check notice

Code scanning / Tslint (reported by Codacy)

" should be ' Note

" should be '
"argparse": "^1.0.10",
"axios": "^0.21.1",
"express": "4.15.3",
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/plural/plural.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 VMware, Inc.
* Copyright 2019-2024 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
import { PLURALFUNCS } from './plurals.func';
Expand All @@ -8,7 +8,7 @@ export class Plural {
constructor() { }
private resolveLocale(locale: string): string {
let lang: string = locale;
do {
do {
if (PLURALFUNCS[lang]) {
return lang;
} else if (PLURALFUNCS[lang.toLocaleLowerCase()]) {
Expand Down
7 changes: 6 additions & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 VMware, Inc.
* Copyright 2019-2024 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
import axios from 'axios';
Expand All @@ -8,6 +8,11 @@ import { basedLogger, Logger } from './logger';
export interface HttpRequestOptions {
timeout?: number;
withCredentials?: boolean;
headers?: HttpHeaders;
}

export interface HttpHeaders {
[key: string]: string;
}

export abstract class Loader {
Expand Down
4 changes: 2 additions & 2 deletions src/services/core.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 VMware, Inc.
* Copyright 2019-2024 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
import { Loader, HttpRequestOptions } from '../loader';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class CoreService {
* on which some products might rely to handle .then() method
1. language = 'en-US'
2. language = 'en', region = 'US'
3. language = 'en'
3. language = 'en'
*/
return Promise.resolve({});
}
Expand Down
11 changes: 5 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 VMware, Inc.
* Copyright 2019-2024 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
const helpers = require('./config/helpers');
Expand Down Expand Up @@ -44,21 +44,21 @@ module: {
const nodeConfig = {
mode: 'production',
target: 'node',

resolve: {
extensions: ['.ts', '.js']
},

entry: helpers.root('index.ts'),

output: {
path: helpers.root('bundles'),
publicPath: '/',
filename: 'singleton.core.umd.server.js',
library: 'singletoncore',
libraryTarget: 'umd'
},

module: {
rules: [{
enforce: 'pre',
Expand All @@ -77,4 +77,3 @@ const nodeConfig = {
};

module.exports = [ webConfig, nodeConfig ];

0 comments on commit 2eb32c1

Please sign in to comment.