@newfold/huapi-js 2.0.0-alpha.1 → 2.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.babelrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@nrwl/web/babel",
5
+ {
6
+ "useBuiltIns": "usage"
7
+ }
8
+ ]
9
+ ]
10
+ }
package/.eslintrc.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ }
17
+ ]
18
+ }
package/Jenkinsfile ADDED
@@ -0,0 +1,205 @@
1
+ name = "lib-js-nd-mfe-tools"
2
+ dir = "libs/huapi-js"
3
+
4
+ server = "https://api.provo1.endurancemb.com:6443"
5
+
6
+ test_output_file = "/tmp/result"
7
+ exec_bin = "/bin/sh"
8
+
9
+ actions = [
10
+ build: true,
11
+ test: false, // Skip for now, as there is no real testing happening
12
+ test_prod: false,
13
+ test_catalog: false,
14
+ deploy: true,
15
+ deploy_script: true
16
+ ]
17
+
18
+ init = [:]
19
+ init2 = [:]
20
+ fin = [:]
21
+ fin2 = [:]
22
+
23
+ branch_type = ''
24
+
25
+ ns_prod = "${name}-prod"
26
+ ns_beta = "${name}-beta"
27
+
28
+ if (env.BRANCH_NAME == 'main') {
29
+ init = [ ns: "${name}-prod", name: "test-staging" ]
30
+ init2 = [ ns: "${name}-prod", name: "test-prod" ]
31
+ fin = [ ns: "${name}-prod", name: "prod" ]
32
+ fin2 = [ ns: "${name}-prod", name: "staging" ]
33
+
34
+ branch_type = 'main'
35
+ }
36
+ else if (env.BRANCH_NAME == 'beta') {
37
+ init = [ ns: "${name}-beta", name: "beta" ]
38
+
39
+ // needed for credential name
40
+ fin = [ ns: "${name}-beta", name: "beta" ]
41
+ branch_type = 'beta'
42
+ }
43
+ else if (env.BRANCH_NAME == 'huapi-js-version2') {
44
+ init = [ ns: "${name}-alpha", name: branch_name ]
45
+ fin = [ ns: "${name}-alpha", name: branch_name ]
46
+
47
+ branch_type = 'major-prerelease'
48
+ }
49
+
50
+ def kubectl(namespace, cmd) {
51
+ token_name = "\$token_${namespace.replace('-', '_')}"
52
+ sh "kubectl --token $token_name --server $server -n $namespace $cmd"
53
+ }
54
+
55
+ def oc(namespace, cmd) {
56
+ token_name = "\$token_${namespace.replace('-', '_')}"
57
+ sh "oc --token $token_name --server $server -n $namespace $cmd"
58
+ }
59
+
60
+ def exec(namespace, deploy_name, cmd, bin="/bin/bash", action) {
61
+ pod_result_file = "/tmp/${action}-result"
62
+ pod_done_file = "/tmp/${action}-done"
63
+ token_name = "\$token_${namespace.replace('-', '_')}"
64
+
65
+ param_script = ""
66
+ for (item in params) {
67
+ param_script += "export ${item.key}=${item.value}; "
68
+ }
69
+
70
+ sh """
71
+ pod=\$(oc --token $token_name --server $server --namespace ${namespace} get pods -l'app.kubernetes.io/name=${deploy_name}' --sort-by ".metadata.creationTimestamp" | awk '{ print \$1 }' | tail -n1)
72
+ echo "Found pod for ${action}ing: \$pod"
73
+
74
+ kubectl --token $token_name --server $server --namespace ${namespace} exec pod/\$pod -- sh -c 'echo \"Executing ${action} step on \$HOSTNAME / \$OPENSHIFT_BUILD_NAME\"; $param_script ${bin} ${cmd}; echo \$? > ${pod_done_file}; echo DONE_${action.toUpperCase()}ING'
75
+
76
+ result=\$(for i in \$(seq 1000);
77
+ do
78
+ done=\$(kubectl --token $token_name --server $server exec --namespace ${namespace} pod/\$pod -- sh -c "(test -f ${pod_done_file} && echo 1) || true") || true;
79
+ if [[ "\$done" == "1" ]]
80
+ then
81
+ kubectl --token $token_name --server $server exec --namespace ${namespace} pod/\$pod -- cat ${pod_result_file}"";
82
+ break;
83
+ else
84
+ sleep 10; test \$k_verbose == "1" && echo "waiting for pod: \$result";
85
+ fi;
86
+ done)
87
+
88
+ echo "DONE!"
89
+
90
+ echo \$result > cmd_output
91
+
92
+ echo "Checking exit status"
93
+ exit_status=\$( kubectl --token $token_name --server $server exec --namespace ${namespace} pod/\$pod -- cat ${pod_done_file})
94
+ echo \$exit_status > cmd_exit_status
95
+ """
96
+ }
97
+
98
+ node('master') {
99
+ withCredentials([
100
+ string(credentialsId:"${init.ns}-okdtoken", variable: "token_${init.ns.replace('-', '_')}"),
101
+ string(credentialsId:"${fin.ns}-okdtoken", variable: "token_${fin.ns.replace('-', '_')}"),
102
+ ])
103
+ {
104
+ stage('Build') {
105
+ if (!actions['build']) {
106
+ sh "echo Jenkinsfile set to skip build"
107
+ return
108
+ }
109
+
110
+ param_script = ""
111
+ for (item in params) {
112
+ param_script += "--build-arg ${item.key}=${item.value} "
113
+ }
114
+
115
+ if (branch_type == 'main') {
116
+ oc(ns_prod, "start-build --wait --follow prod $param_script")
117
+ }
118
+ else {
119
+ oc(init.ns, "start-build --wait --follow ${init.name} $param_script")
120
+ }
121
+ }
122
+ // stage('Stage') {
123
+ // //kubectl(init.ns, "get pods -l'app.kubernetes.io/name=${init.name}'")
124
+ // //kubectl(init.ns, "get pods -l'app.kubernetes.io/name=${init.name}'")
125
+ // }
126
+ stage('Test') {
127
+ if (!actions['test']) {
128
+ sh "echo Jenkinsfile set to skip tests"
129
+ return
130
+ }
131
+
132
+ action = "test"
133
+
134
+ if (branch_type == "main") {
135
+ kubectl(ns_prod, "rollout restart deployment/test-staging")
136
+ kubectl(ns_prod, "rollout status deployment/test-staging")
137
+ }
138
+ else {
139
+ kubectl(init.ns, "rollout restart deployment/${init.name}")
140
+ kubectl(init.ns, "rollout status deployment/${init.name}")
141
+ }
142
+
143
+ sh "echo Running Primary Tests"
144
+ // Test output from nx does not get captured correctly
145
+ exec(init.ns, init.name, "${dir}/cicd/test.sh", exec_bin, action)
146
+
147
+ if (actions.test_catalog) {
148
+ sh "echo Ensure tests passed"
149
+ junit 'cmd_output'
150
+ sh "test ${currentBuild.currentResult} != UNSTABLE"
151
+ sh "test \$(cat cmd_exit_status) = 0"
152
+ }
153
+
154
+ if (branch_type == 'main' && actions.test_prod) {
155
+ sh "echo Running Prod Tests"
156
+ kubectl(ns_prod, "rollout restart deployment/test-prod")
157
+ kubectl(ns_prod, "rollout status deployment/test-prod")
158
+
159
+ // There is not yet a test-prod.sh for huapi-js
160
+ exec(ns_prod, "test-prod", "${dir}/cicd/test-prod.sh", exec_bin, action)
161
+ }
162
+
163
+ }
164
+ stage('Deploy') {
165
+ if (!actions['deploy']) {
166
+ sh "echo Jenkinsfile set to skip deploy"
167
+ return
168
+ }
169
+
170
+ action = "deploy"
171
+
172
+ if (branch_type == 'main') {
173
+ // STAGING
174
+ sh "echo Deploy Prod and Staging"
175
+ oc(ns_prod, "tag prod:test prod:latest")
176
+
177
+ kubectl(ns_prod, "rollout restart deployment/staging")
178
+ kubectl(ns_prod, "rollout restart deployment/prod")
179
+
180
+ kubectl(ns_prod, "rollout status deployment/staging")
181
+ kubectl(ns_prod, "rollout status deployment/prod")
182
+ }
183
+ else {
184
+ sh "echo Not on Main branch, skipping prod deploy stage"
185
+ }
186
+
187
+ // We could have alpha and/or beta builds deploy a separate npm module for testing changes on HUAPI alpha or feature branches
188
+ if (actions['deploy_script'] && branch_type == 'main') {
189
+ echo "Running deploy script step"
190
+ exec(fin.ns, fin.name, "${dir}/cicd/deploy.sh", exec_bin, action)
191
+ sh "echo check deploy exit status"
192
+ sh "test \$(cat cmd_exit_status) = 0"
193
+ }
194
+
195
+ else if (actions['deploy_script'] && branch_type == 'major-prerelease') {
196
+ echo "Running deploy script step"
197
+ exec(fin.ns, fin.name, "${dir}/cicd/deploy-major-prerelease.sh", exec_bin, action)
198
+ sh "echo check deploy exit status"
199
+ sh "test \$(cat cmd_exit_status) = 0"
200
+ }
201
+
202
+ }
203
+ }
204
+ }
205
+
@@ -0,0 +1,11 @@
1
+ set -o pipefail
2
+ cd dist/libs/huapi-js
3
+ echo "starting deploy script. dir: $(pwd)"
4
+
5
+ npm set //registry.npmjs.org/:_authToken='${NPM_TOKEN}'
6
+ npm version prerelease --preid=beta
7
+ npm publish --cache=/tmp/npmcache --tag=beta 2>&1 | tee /tmp/deploy-result
8
+
9
+ echo "finished deploy script"
10
+
11
+
package/cicd/deploy.sh ADDED
@@ -0,0 +1,10 @@
1
+ set -o pipefail
2
+ cd dist/libs/huapi-js
3
+ echo "starting deploy script. dir: $(pwd)"
4
+
5
+ npm set //registry.npmjs.org/:_authToken='${NPM_TOKEN}'
6
+ npm publish --cache=/tmp/npmcache 2>&1 | tee /tmp/deploy-result
7
+
8
+ echo "finished deploy script"
9
+
10
+
package/cicd/test.sh ADDED
@@ -0,0 +1,5 @@
1
+ echo "starting test script"
2
+
3
+ yarn nx test huapi-js
4
+
5
+ echo "finished testing"
@@ -0,0 +1 @@
1
+ env: alpha
@@ -0,0 +1,14 @@
1
+ git: ndp/vision
2
+ name: lib-js-nd-mfe-tools
3
+ port: '5000'
4
+ health_url: ''
5
+ image:
6
+ prefix: 'image-registry.openshift-image-registry.svc:5000'
7
+ from: 'node:20-alpine'
8
+ build:
9
+ resources:
10
+ limits:
11
+ memory: '4Gi'
12
+ ephemeral-storage: '30Gi'
13
+ # env_vars:
14
+ # name: value
@@ -0,0 +1 @@
1
+ env: beta
@@ -0,0 +1 @@
1
+ env: branch
@@ -0,0 +1,2 @@
1
+ env: prod
2
+ replicaCount: 1
@@ -0,0 +1 @@
1
+ env: staging
@@ -0,0 +1 @@
1
+ env: test-prod
@@ -0,0 +1 @@
1
+ env: test-staging
package/jest.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'huapi-js',
4
+ preset: '../../jest.preset.js',
5
+ globals: {
6
+ 'ts-jest': {
7
+ tsconfig: '<rootDir>/tsconfig.spec.json',
8
+ },
9
+ },
10
+ transform: {
11
+ '^.+\\.[tj]s$': 'ts-jest',
12
+ },
13
+ moduleFileExtensions: ['ts', 'js', 'html'],
14
+ coverageDirectory: '../../coverage/libs/huapi-js',
15
+ };
@@ -0,0 +1,39 @@
1
+ import { defineConfig } from 'orval';
2
+
3
+ export default defineConfig({
4
+ huapi: {
5
+ input: {
6
+ target: './openapi.json',
7
+ // validation: true,
8
+ },
9
+ output: {
10
+ mode: 'split',
11
+ target: './src/index.ts',
12
+ client: 'react-query',
13
+ mock: true,
14
+ clean: false,
15
+ override: {
16
+ mock: {
17
+ delay: 0,
18
+ generateEachHttpStatus: true,
19
+ },
20
+ operations: {
21
+ sites_error_logs: {
22
+ query: {
23
+ useQuery: true,
24
+ useInfinite: true,
25
+ useInfiniteQueryParam: 'page_id',
26
+ },
27
+ },
28
+ sites_access_logs: {
29
+ query: {
30
+ useQuery: true,
31
+ useInfinite: true,
32
+ useInfiniteQueryParam: 'page_id',
33
+ },
34
+ },
35
+ },
36
+ },
37
+ },
38
+ },
39
+ });
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "@newfold/huapi-js",
3
3
  "peerDependencies": {
4
- "@faker-js/faker": "^6.1.2",
4
+ "@faker-js/faker": "^8.0.0",
5
5
  "@tanstack/react-query": "^5.51.1",
6
6
  "axios": "^0.27.2",
7
- "msw": "^0.42.1",
7
+ "msw": "^2.0.0",
8
8
  "react": "^17.0.0 || ^18.0.0",
9
- "react-dom": "^17.0.0 || ^18.0.0",
10
- "tslib": "2.7.0"
9
+ "react-dom": "^17.0.0 || ^18.0.0"
11
10
  },
12
11
  "module": "dist/index.ts",
13
- "version": "2.0.0-alpha.1",
14
- "sideEffects": false,
15
- "main": "./src/index.js",
16
- "types": "./src/index.d.ts",
17
- "dependencies": {}
12
+ "version": "2.1.0-beta.1",
13
+ "sideEffects": false
18
14
  }
package/project.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "huapi-js",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/huapi-js/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "prepare": {
8
+ "executor": "nx:run-commands",
9
+ "options": {
10
+ "parallel": false,
11
+ "commands": [
12
+ {
13
+ "command": "echo NX_API_URL=${NX_API_URL:=https://huapi.beta.bh2.hosting.newfold.com/openapi.json}; curl -o libs/huapi-js/openapi.json $NX_API_URL"
14
+ },
15
+ {
16
+ "command": "orval --config libs/huapi-js/orval.config.ts"
17
+ },
18
+ {
19
+ "command": "node libs/huapi-js/scripts/update-version.js"
20
+ }
21
+ ]
22
+ }
23
+ },
24
+ "build": {
25
+ "executor": "@nrwl/js:tsc",
26
+ "outputs": ["{options.outputPath}"],
27
+ "options": {
28
+ "outputPath": "dist/libs/huapi-js",
29
+ "main": "libs/huapi-js/src/index.ts",
30
+ "tsConfig": "libs/huapi-js/tsconfig.lib.json",
31
+ "assets": ["libs/huapi-js/*.md"]
32
+ },
33
+ "dependsOn": [
34
+ {
35
+ "target": "prepare",
36
+ "projects": "self"
37
+ }
38
+ ]
39
+ },
40
+ "publish": {
41
+ "executor": "nx:run-commands",
42
+ "options": {
43
+ "command": "node tools/scripts/publish.mjs huapi-js {args.ver} {args.tag}"
44
+ },
45
+ "dependsOn": [
46
+ {
47
+ "projects": "self",
48
+ "target": "build"
49
+ }
50
+ ]
51
+ },
52
+ "lint": {
53
+ "executor": "@nrwl/linter:eslint",
54
+ "outputs": ["{options.outputFile}"],
55
+ "options": {
56
+ "lintFilePatterns": ["libs/huapi-js/**/*.ts"]
57
+ }
58
+ },
59
+ "test": {
60
+ "executor": "@nrwl/jest:jest",
61
+ "outputs": ["{workspaceRoot}/coverage/libs/huapi-js"],
62
+ "options": {
63
+ "jestConfig": "libs/huapi-js/jest.config.ts",
64
+ "passWithNoTests": true
65
+ }
66
+ }
67
+ },
68
+ "tags": []
69
+ }
@@ -0,0 +1,43 @@
1
+ const fs = require('fs');
2
+
3
+ // get version from openapi spec
4
+ const openapi = require('../openapi.json');
5
+ const openAPIVersion = openapi?.info?.version || 'unknown-version';
6
+
7
+ // The MINOR and PATCH versions represent huapi's openapi version
8
+ // The MAJOR version can manually change to reflect breaking changes in haupi-js
9
+ const versionParts = openAPIVersion.split('.');
10
+ versionParts[0] = '2'; // Bumping the major version to 2 via the React Query v4 to v5 upgrade
11
+ const version = versionParts.join('.');
12
+
13
+ // print cli alert
14
+ console.log(
15
+ `[update-version.js] updating package.json version to ${version}...`
16
+ );
17
+
18
+ // path to packge.json file
19
+ // TODO: update to be more robust when run from different directories
20
+ const filePath = 'libs/huapi-js/package.json';
21
+
22
+ // read the file
23
+ fs.readFile(filePath, 'utf-8', (err, data) => {
24
+ if (err) throw err;
25
+
26
+ // print to the file
27
+ fs.writeFile(
28
+ filePath,
29
+ // replace the version and re-stringify into json format
30
+ // use two spaces and a tab at the end of the file for `pretty` formatting
31
+ `${JSON.stringify({ ...JSON.parse(data), version }, null, ' ')}\n`,
32
+ 'utf-8',
33
+
34
+ (err) => {
35
+ if (err) throw err;
36
+
37
+ // notify the user the operation is complete
38
+ console.log(
39
+ `[update-version.js] package.json update to ${version} > DONE <`
40
+ );
41
+ }
42
+ );
43
+ });
@@ -0,0 +1,7 @@
1
+ import { useSitesInfo } from '..';
2
+
3
+ describe('huapiJs', () => {
4
+ it('should have a function useSitesInfo', () => {
5
+ expect(typeof useSitesInfo).toBe('function');
6
+ });
7
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "noImplicitOverride": true,
9
+ "noPropertyAccessFromIndexSignature": true,
10
+ "noImplicitReturns": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "sourceMap": false
13
+ },
14
+ "files": [],
15
+ "include": [],
16
+ "references": [
17
+ {
18
+ "path": "./tsconfig.lib.json"
19
+ },
20
+ {
21
+ "path": "./tsconfig.spec.json"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": []
7
+ },
8
+ "include": ["**/*.ts"],
9
+ "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts", "node_modules"]
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
9
+ }
package/orval.config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const _default: import("@orval/core").ConfigExternal;
2
- export default _default;
package/orval.config.js DELETED
@@ -1,33 +0,0 @@
1
- import { defineConfig } from 'orval';
2
- export default defineConfig({
3
- huapi: {
4
- input: {
5
- target: './openapi.json',
6
- // validation: true,
7
- },
8
- output: {
9
- mode: 'split',
10
- target: './src/index.ts',
11
- client: 'react-query',
12
- mock: true,
13
- prettier: true,
14
- clean: false,
15
- override: {
16
- operations: {
17
- sites_error_logs: {
18
- query: {
19
- useQuery: true,
20
- useInfinite: true,
21
- },
22
- },
23
- sites_access_logs: {
24
- query: {
25
- useQuery: true,
26
- useInfinite: true,
27
- },
28
- },
29
- },
30
- },
31
- },
32
- },
33
- });