Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sdk release #1658

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8d3a968
feat: add the new auth service to prepare for the new sdk
martin-trajanovski Oct 29, 2024
3b39b75
try to fix some ai-bot review suggestions
martin-trajanovski Oct 31, 2024
b2d524c
add the note for the good review suggestion from ai-bot
martin-trajanovski Oct 31, 2024
a872cf2
remove old sdk and adjust types against the new one
martin-trajanovski Oct 31, 2024
94cb109
fix more types and issues against the new sdk
martin-trajanovski Nov 1, 2024
78de88f
finalize type error fixes
martin-trajanovski Nov 1, 2024
3840cc1
remove prefix
martin-trajanovski Nov 1, 2024
abe2d8e
add the new sdk generation script for local development
martin-trajanovski Nov 1, 2024
0489f0d
Merge pull request #1632 from SciCatProject/SWAP-4278-new-sdk-frotnen…
martin-trajanovski Nov 1, 2024
7947926
Merge branch 'master' of https://github.com/SciCatProject/frontend in…
martin-trajanovski Nov 4, 2024
5863345
resolve merge conflicts
martin-trajanovski Nov 4, 2024
ecd92bb
resolve merge conflicts
martin-trajanovski Nov 4, 2024
0271a43
start fixing TODOs after newly generated sdk
martin-trajanovski Nov 4, 2024
04f5ac1
Merge pull request #1636 from SciCatProject/SWAP-4278-new-sdk-frotnen…
nitrosx Nov 5, 2024
53186ae
Merge pull request #1637 from SciCatProject/SWAP-4278-new-sdk-frotnen…
nitrosx Nov 5, 2024
6ddd5cb
fixed sdk local generation for linux
nitrosx Nov 5, 2024
40e107c
update the sdk package version and fix some more types
martin-trajanovski Nov 6, 2024
0d897af
detect the OS and use the right current directory path
martin-trajanovski Nov 6, 2024
729a735
Merge pull request #1644 from SciCatProject/fix-sdk-local-generation
nitrosx Nov 6, 2024
ef06cc8
Merge branch 'master' of https://github.com/SciCatProject/frontend in…
martin-trajanovski Nov 6, 2024
3597d0d
Merge branch 'new-sdk-release' of https://github.com/SciCatProject/fr…
martin-trajanovski Nov 6, 2024
7c74cc6
improve types and fix more TODOs
martin-trajanovski Nov 6, 2024
9db7588
improve types and fix TODOs after backend improvements
martin-trajanovski Nov 7, 2024
e98f417
finalize TODOs and FIXMEs fixes and type improvements with the new sdk
martin-trajanovski Nov 8, 2024
82c7ba9
fix some sourcery-ai comments
martin-trajanovski Nov 8, 2024
8d0dec8
fix some of the last TODOs
martin-trajanovski Nov 8, 2024
0271c1c
adapted sdk generation to unix environment
nitrosx Nov 11, 2024
f471a23
Merge pull request #1648 from SciCatProject/fix-unix-sdk-generation
nitrosx Nov 12, 2024
f6f2bfb
Merge pull request #1647 from SciCatProject/SWAP-4278-new-sdk-frotnen…
nitrosx Nov 12, 2024
5f12e14
ignore the @scicatproject that is generated with the sdk
martin-trajanovski Nov 12, 2024
8a9f89c
resolve merge conflicts
martin-trajanovski Nov 13, 2024
2ab7a73
resolve merge conflicts
martin-trajanovski Nov 18, 2024
e8f08fd
Merge branch 'master' into new-sdk-release
martin-trajanovski Nov 19, 2024
303e1b7
resolve merge conflicts and fix types after recent changes
martin-trajanovski Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/out-tsc
# Only exists if Bazel was run
/bazel-out
@scicatproject/

# dependencies
/node_modules
Expand Down
40 changes: 39 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint:fix": "ng lint --fix",
"betterer": "betterer",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
"cypress:run": "cypress run",
"generate:sdk:local": "node scripts/generate-nestjs-sdk"
},
"private": true,
"dependencies": {
Expand All @@ -33,6 +34,7 @@
"@ngrx/effects": "^16",
"@ngrx/router-store": "^16",
"@ngrx/store": "^16",
"@scicatproject/scicat-sdk-ts": "^4.6.5",
"autolinker": "^4.0.0",
"deep-equal": "^2.0.5",
"exceljs": "^4.3.0",
Expand All @@ -41,6 +43,7 @@
"lodash-es": "^4.17.21",
"luxon": "^3.3.0",
"mathjs": "^13.0.0",
"ngx-cookie-service": "^16.1.0",
"ngx-json-viewer": "^3",
"ngx-linky": "^4.0.0",
"ngx-material-luxon": "^1.1.1",
Expand All @@ -67,7 +70,7 @@
"@types/deep-equal": "^1.0.1",
"@types/file-saver": "^2.0.2",
"@types/jasmine": "^5.1.0",
"@types/lodash": "^4.14.172",
"@types/lodash-es": "^4.17.12",
"@types/luxon": "^3.3.0",
"@types/node": "^22.0.0",
"@types/shortid": "2.2.0",
Expand Down
62 changes: 62 additions & 0 deletions scripts/generate-nestjs-sdk.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#
#

USER=`who am i | cut -d\ -f1`
echo -e "\nUser running the script: ${USER}"

echo -e "\nCleanup old files..."
rm -rf node_modules/@scicatproject/scicat-sdk-ts
rm -rf @scicatproject/scicat-sdk-ts

echo -e "\nGenerating the new sdk..."
docker run \
--rm \
--add-host host.docker.internal:host-gateway \
-v "`pwd`:/local" \
openapitools/openapi-generator-cli:v7.9.0 generate \
-i http://host.docker.internal:3000/explorer-json \
-g typescript-angular \
-o local/@scicatproject/scicat-sdk-ts \
--additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true

REMOVE_NPM_LINK=0
if ! command -v npm 2>&1 1>/dev/null
then
if [ "--`env | grep NVM_BIN`--" != "----" ]
then
echo -e "\nCreating links to npm and node versions"
ln -s "$NVM_BIN/npm" "/usr/local/bin/npm"
whereis npm
ln -s "$NVM_BIN/node" "/usr/local/bin/node"
whereis node
REMOVE_NPM_LINK=1
else
echo -e "\nNo npm found!!!"
exit 1
fi
fi

echo -e "\nInstalling dependencies and building the sdk..."
cd @scicatproject/scicat-sdk-ts
npm install
npm run build

echo -e "\nCopying the build files in node_modules..."
cd ../..
cp -rv @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts

echo -e "\nAdjusting ownership to user ${USER}"
chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts

echo -e "\nFinal cleanup..."
echo -e "Removing sdk folder"
rm -rfv @scicatproject

if [ $REMOVE_NPM_LINK -eq 1 ];
then
echo -e "\nRemoving links to npm and node"
rm -fv "/usr/local/bin/npm"
rm -fv "/usr/local/bin/node"
fi

68 changes: 68 additions & 0 deletions scripts/generate-nestjs-sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* NOTE: This file contains commands that generate new typescript-angular sdk against the running scicat backend
* which overwrites the node_modules/@scicatproject/scicat-sdk-ts for development purpose
* It should NOT be used in production because the real (@scicatproject/scicat-sdk-ts) npm package will be installed and used.
*/

const execSync = require("child_process").execSync;
const os = require("os");

function isWindows() {
return os.platform() === "win32";
}

function getCurrentDirectory() {
if (isWindows()) {
return "%cd%";
}

return "$(pwd)";
}

if (isWindows()) {

// NOTE: First do some cleanup before starting the generation
console.log("Cleanup old files...");
execSync(
"rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts",
{ encoding: "utf-8" },
);

console.log("Generating the new sdk...");
const generationOutput = execSync(
`docker run --rm --add-host host.docker.internal:host-gateway -v "${getCurrentDirectory()}:/local" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/@scicatproject/scicat-sdk-ts --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true`,
{ encoding: "utf-8" },
);
console.log(generationOutput);

console.log("Installing dependencies and building the sdk...");
const installBuildOutput = execSync(
"cd @scicatproject/scicat-sdk-ts && npm install && npm run build",
{ encoding: "utf-8" },
);
console.log(installBuildOutput);

console.log("Copying the build files in node_modules...");
const copyToNodeModulesOutput = execSync(
"cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts",
{ encoding: "utf-8" },
);
console.log(copyToNodeModulesOutput);

console.log("Final cleanup...");
execSync("rm -rf @scicatproject", {
encoding: "utf-8",
});

console.log("Local SDK generation completed");

} else {
console.log("Your environment is a linux/unix");
console.log("Please run the following command on your terminal:");
console.log("> sudo -E ./scripts/generate-nestjs-sdk.bash");
console.log("");
console.log("IMPORTANT: the script runs under sudo. You will be asked your password.");
console.log("");

}

6 changes: 4 additions & 2 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
datasetReduceEnabled: boolean;
datasetDetailsShowMissingProposalId: boolean;
datafilesActionsEnabled: boolean;
datafilesActions: any[];

Check warning on line 45 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
editDatasetSampleEnabled: boolean;
editMetadataEnabled: boolean;
editPublishedData: boolean;
Expand Down Expand Up @@ -109,14 +109,16 @@

async loadAppConfig(): Promise<void> {
try {
this.appConfig = await this.http
const config = await this.http
.get("/api/v3/admin/config")
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.log("No config available in backend, trying with local config.");
try {
this.appConfig = await this.http.get("/assets/config.json").toPromise();
const config = await this.http.get("/assets/config.json").toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.error("No config provided.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/app-routing/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ActivatedRouteSnapshot,
RouterStateSnapshot,
} from "@angular/router";
import { UserApi } from "shared/sdk/services";
import { UsersService } from "@scicatproject/scicat-sdk-ts";

/**
* Ensure that the current user is logged in
Expand All @@ -19,7 +19,7 @@ import { UserApi } from "shared/sdk/services";
})
export class AuthGuard implements CanActivate {
constructor(
private us: UserApi,
private us: UsersService,
private router: Router,
) {}

Expand All @@ -31,7 +31,7 @@ export class AuthGuard implements CanActivate {
state: RouterStateSnapshot,
): Promise<boolean> {
return this.us
.getCurrent()
.usersControllerGetMyUser()
.toPromise()
.catch(() => {
this.router.navigate(["/login"], {
Expand Down
7 changes: 4 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
ChangeDetectorRef,
} from "@angular/core";
import { Store } from "@ngrx/store";
import { LoopBackConfig } from "shared/sdk";
import {
clearMessageAction,
fetchCurrentUserAction,
Expand All @@ -25,6 +24,7 @@
} from "state-management/selectors/user.selectors";
import { MessageType } from "state-management/models";
import { AppConfigService, AppConfig as Config } from "app-config.service";
import { Configuration } from "@scicatproject/scicat-sdk-ts";

@Component({
selector: "app-root",
Expand All @@ -45,6 +45,7 @@
constructor(
@Inject(APP_CONFIG) public appConfig: AppConfig,
private appConfigService: AppConfigService,
private apiConfigService: Configuration,
private cdRef: ChangeDetectorRef,
private metaService: Meta,
public snackBar: MatSnackBar,
Expand All @@ -68,19 +69,19 @@
* @memberof AppComponent
*/
ngOnInit() {
LoopBackConfig.setBaseURL(this.config.lbBaseURL);
console.log(LoopBackConfig.getPath());
this.apiConfigService.basePath = this.config.lbBaseURL;
console.log(this.apiConfigService.basePath);

this.store.dispatch(loadDefaultSettings({ config: this.config }));

Check warning on line 75 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / eslint

Avoid dispatching many actions in a row to accomplish a larger conceptual "transaction"

this.store.dispatch(fetchCurrentUserAction());

Check warning on line 77 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / eslint

Avoid dispatching many actions in a row to accomplish a larger conceptual "transaction"
if (window.location.pathname.indexOf("logout") !== -1) {
this.logout();
}

this.userMessageSubscription = this.store
.select(selectUserMessage)
.subscribe((current) => {

Check warning on line 84 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / eslint

`Store` subscription is forbidden. Use the `async` pipe instead
if (current && current.content !== undefined) {
let panelClass = "";
switch (current.type) {
Expand Down
Loading
Loading