Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [2.1.0] - 2025-09-30

### Added

- Added `getStudyResearchAssistants` endpoint
- `is_descending` parameters to `getParticipantAccounts` endpoint
- Added `subdomain` optional parameter to `generateAnonymousAccounts` endpoint
- Added optional `activeDeploymentsOnly` parameter to `create` endpoint in Exports service

### Changed

- `addResearcherToStudy` now requires a role
- Updated `parseUser` function to handle `ResearchAssistant` role

## [2.0.7] - 2025-06-11

### Fixed
Expand All @@ -24,7 +38,7 @@
### Fixed

- Fixed serialization of unknown datastream `Data`
- Fixed `ParticipantDataInput.dateOfLastDataUpload` data type
- Fixed `ParticipantDataInput.dateOfLastDataUpload` data type

## [2.0.4] - 2025-03-10

Expand Down Expand Up @@ -57,4 +71,4 @@
### Removed

- Removed `InformedConsent` endpoints. Please use `ParticipantData` instead.
- Removed `DataPoints` endpoints. Please use `DataStreams` instead.
- Removed `DataPoints` endpoints. Please use `DataStreams` instead.
2 changes: 1 addition & 1 deletion LICENCE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 Copenhagen Center for Health Technology (CACHET) at the Technical University of Denmark (DTU).
Copyright (c) 2026 Technical University of Denmark (DTU).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ”Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carp-dk/client",
"type": "module",
"version": "2.0.7",
"version": "2.1.0-dev.8",
"description": "TypeScript API client for the CARP Web Services (CAWS).",
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,37 +35,37 @@
],
"license": "MIT",
"devDependencies": {
"@carp-dk/eslint-config": "^1.1.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.20.0",
"@js-joda/core": "^5.6.4",
"@types/node": "^20.17.19",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-v8": "^3.0.6",
"dotenv": "^16.4.7",
"eslint": "^8.57.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-refresh": "^0.4.19",
"eslint-plugin-unused-imports": "^4.1.4",
"node-jq": "^6.0.1",
"prettier-plugin-organize-imports": "^4.1.0",
"rimraf": "^5.0.10",
"tsc-alias": "^1.8.10",
"tsx": "^4.19.3",
"typescript": "^5.7.3",
"vite": "^6.1.1",
"vitest": "^3.0.6",
"webdriverio": "^8.42.0"
"@carp-dk/eslint-config": "1.1.0",
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.20.0",
"@js-joda/core": "5.6.4",
"@types/node": "20.17.19",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@vitest/browser": "3.0.6",
"@vitest/coverage-v8": "3.0.6",
"dotenv": "16.4.7",
"eslint": "8.57.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsx-a11y": "6.10.2",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-prettier": "5.2.3",
"eslint-plugin-react": "7.37.4",
"eslint-plugin-react-refresh": "0.4.19",
"eslint-plugin-unused-imports": "4.1.4",
"node-jq": "6.0.1",
"prettier-plugin-organize-imports": "4.1.0",
"rimraf": "5.0.10",
"tsc-alias": "1.8.10",
"tsx": "4.19.3",
"typescript": "5.7.3",
"vite": "6.1.1",
"vitest": "3.0.6",
"webdriverio": "8.42.0"
},
"dependencies": {
"axios": "^1.7.9",
"big.js": "^6.2.2",
"jwt-decode": "^4.0.0"
"axios": "1.7.9",
"big.js": "6.2.2",
"jwt-decode": "4.0.0"
},
"pnpm": {
"onlyBuiltDependencies": [
Expand Down
15 changes: 14 additions & 1 deletion src/client/carpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
} from "@/endpoints";
import { CarpServiceError, sanitizeRequestConfig } from "@/shared";
import Protocols from "@/endpoints/protocols";
import { CarpToken } from "@/endpoints/auth";

export default class CarpClient {
private instance: AxiosInstance;
private readonly instance: AxiosInstance;

accounts: Accounts;

Expand All @@ -32,6 +33,18 @@ export default class CarpClient {
return this.instance;
}

private token: CarpToken;

// @internal
public get getInternalToken(): CarpToken {
return this.token;
}

// @internal
public setInternalToken(token: CarpToken): void {
this.token = token;
}

constructor(protected readonly config: Config) {
if (!config.baseUrl) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CarpTestClient from "./carpTestClient";
import CarpClient from "./carpClient";

export { CarpTestClient, CarpClient };
// eslint-disable-next-line import/prefer-default-export
export { CarpClient };
9 changes: 7 additions & 2 deletions src/endpoints/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class Accounts extends Endpoint {
emailAddress: string;
role: string;
}) {
return this.actions.post(`${this.endpoint}/role`, { emailAddress, role });
return this.actions.post<boolean>(`${this.endpoint}/role`, {
emailAddress,
role,
});
}

async getRedirectURIs() {
return this.actions.get<string[]>(`${this.endpoint}/redirect-uris`);
return this.actions.get<{ [key: string]: string[] }>(
`${this.endpoint}/redirect-uris`,
);
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/endpoints/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CarpTestClient } from "..";
import Endpoint from "./endpoint";

export type CarpToken = {
Expand All @@ -10,9 +9,9 @@ export type CarpToken = {
};

class Auth extends Endpoint {
private realm: string = import.meta.env.VITE_AUTH_REALM;
private readonly realm: string = import.meta.env.VITE_AUTH_REALM;

private baseUrl: string = import.meta.env.VITE_AUTH_BASE_URL;
private readonly baseUrl: string = import.meta.env.VITE_AUTH_BASE_URL;

async login(params: {
username: string;
Expand All @@ -33,7 +32,7 @@ class Auth extends Endpoint {
},
);

(this.client as CarpTestClient).setInternalToken(response.data);
this.client.setInternalToken(response.data);

return response.data;
}
Expand Down Expand Up @@ -66,8 +65,7 @@ class Auth extends Endpoint {
client_id: import.meta.env.VITE_AUTH_CLIENT_ID,
client_secret: import.meta.env.VITE_AUTH_CLIENT_SECRET,
grant_type: "refresh_token",
refresh_token: (this.client as CarpTestClient).getInternalToken
.refresh_token,
refresh_token: this.client.getInternalToken.refresh_token,
};
const query = new URLSearchParams(params).toString();
const response = await this.actions.post<CarpToken>(
Expand All @@ -79,8 +77,7 @@ class Auth extends Endpoint {
},
},
);

(this.client as CarpTestClient).setInternalToken(response.data);
this.client.setInternalToken(response.data);
this.client.setAuthToken(response.data.access_token);

return response.data;
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Accounts from "./accounts";
import Auth from "./auth";
import Study from "./study";
import Participation from "./participation";
import Auth from "./auth";
import Studies from "./studies";
import Email from "./email";
import DataStreams from "./dataStreams";

export { Auth, Accounts, Study, Studies, Participation, Email, DataStreams };
export { Accounts, Auth, Study, Studies, Participation, Email, DataStreams };
60 changes: 0 additions & 60 deletions src/endpoints/study/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
serialize,
} from "@/shared";
import Endpoint from "../endpoint";
import { Statistics } from "@/shared/models";

class Deployments extends Endpoint {
coreEndpoint: string = "/api/deployment-service";
Expand Down Expand Up @@ -130,65 +129,6 @@ class Deployments extends Endpoint {

return deviceDeployment;
}

/**
* Get device deployments
* @param studyDeploymentId The ID of the study deployment
*/
async getDeploymentStatistics({
deploymentIds,
}: {
deploymentIds: string[];
}) {
const response = await this.actions.post<{ statistics: any }>(
`${this.coreEndpoint}/statistic`,
{
deploymentIds,
},
); // add deployment ID to URL
const responseData: {
deployments: { deploymentId: string; uploads: any }[];
}[] = [];
const res: { deploymentId: string; uploads: any }[] = [];

const DeploymentIdArray: string[] = [];
const { statistics } = response.data;
Object.keys(statistics).forEach((id) => {
DeploymentIdArray.push(id);
});

DeploymentIdArray.forEach((id) => {
const value = statistics[id];

const dataTypes: string[] = [];
Object.keys(value).forEach((dataType) => {
dataTypes.push(dataType);
});

const uploads: any[] = [];
dataTypes.forEach((element) => {
const obj: {
dataType: string;
uploads: { count: number; uploads: {} };
} = {
dataType: element,
uploads: value[element],
};
uploads.push(obj);
});

const obj: { deploymentId: string; uploads: any[] } = {
deploymentId: id,
uploads,
};
res.push(obj);
responseData.push({
deployments: res,
});
});

return responseData as Statistics[];
}
}

export default Deployments;
11 changes: 7 additions & 4 deletions src/endpoints/study/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ class Exports extends Endpoint {
const regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
const header = response.headers["content-disposition"] as string;
const matches = regex.exec(header);
const filename =
matches != null && matches[1]
? matches[1].replace(/['"]/g, "")
: "download.zip";
const filename = matches?.[1]
? matches[1].replace(/['"]/g, "")
: "download.zip";
const data = response.data as ExportData;

return { data, filename } as ExportToDownload;
Expand All @@ -42,18 +41,22 @@ class Exports extends Endpoint {
* Create a summary
* @param studyId The ID of the study
* @param deploymentIds: The IDs of the deployments to include in the summary
* @param activeDeploymentsOnly: Whether to include only active deployments
*/
async create({
studyId,
deploymentIds,
activeDeploymentsOnly,
}: {
studyId: string;
deploymentIds: string[];
activeDeploymentsOnly?: boolean;
}) {
const response = await this.actions.post<Export>(
`${this.endpoint}/${studyId}/exports/summaries`,
{
deploymentIds,
activeDeploymentsOnly,
},
);

Expand Down
Loading
Loading