Skip to content

Commit a05d192

Browse files
authored
Merge pull request #228 from Scalingo/feat/contract-agreements
feat: support for contracts and agreements
2 parents 7673c84 + 529b09a commit a05d192

File tree

7 files changed

+176
-1
lines changed

7 files changed

+176
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Unreleased
22

3-
* nothing yet
3+
## 0.6.1
4+
5+
* feature: support for contracts and agreements
46

57
## 0.6.0
68

src/Contracts/index.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Client } from "..";
2+
import { Contract, ContractAgreement } from "../models/auth/contracts";
3+
import { CreateAgreementParams } from "../params/auth/contracts";
4+
import { unpackData } from "../utils";
5+
6+
/**
7+
* Contract and Agreements API Client
8+
*/
9+
export default class Contracts {
10+
/** Scalingo API Client */
11+
_client: Client;
12+
13+
/**
14+
* Create a new "thematic" client
15+
* @param client Scalingo API Client
16+
*/
17+
constructor(client: Client) {
18+
this._client = client;
19+
}
20+
21+
/**
22+
* Get all existing contracts
23+
*/
24+
all(): Promise<Contract[]> {
25+
return unpackData(
26+
this._client.authApiClient().get("/contracts"),
27+
"contracts"
28+
);
29+
}
30+
31+
/**
32+
* Get all existing contract agreements
33+
*/
34+
allAgreements(): Promise<ContractAgreement[]> {
35+
return unpackData(
36+
this._client.authApiClient().get("/contract_agreements"),
37+
"contract_agreements"
38+
);
39+
}
40+
41+
/**
42+
* Show a given contract
43+
*/
44+
show(id: string): Promise<Contract> {
45+
return unpackData(
46+
this._client.authApiClient().get(`/contracts/${id}`),
47+
"contract"
48+
);
49+
}
50+
51+
/**
52+
* Show a given contract agreement
53+
*/
54+
showAgreement(id: string): Promise<ContractAgreement> {
55+
return unpackData(
56+
this._client.authApiClient().get(`/contract_agreements/${id}`),
57+
"contract_agreement"
58+
);
59+
}
60+
61+
/** Create an agreement for the given contract */
62+
createAgreement(params: CreateAgreementParams): Promise<ContractAgreement> {
63+
return unpackData(
64+
this._client
65+
.authApiClient()
66+
.post(`/contract_agreements`, { contract_agreement: params }),
67+
"contract_agreement"
68+
);
69+
}
70+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Autoscalers from "./Autoscalers";
88
import Billing from "./Billing";
99
import Collaborators from "./Collaborators";
1010
import Containers from "./Containers";
11+
import Contracts from "./Contracts";
1112
import CronTasks from "./CronTasks";
1213
import Deployments from "./Deployments";
1314
import Domains from "./Domains";
@@ -88,6 +89,7 @@ export class Client {
8889
Billing = new Billing(this);
8990
Collaborators = new Collaborators(this);
9091
Containers = new Containers(this);
92+
Contracts = new Contracts(this);
9193
CronTasks = new CronTasks(this);
9294
Deployments = new Deployments(this);
9395
Domains = new Domains(this);

src/models/auth/contracts.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export type ContractLangs = "en" | "fr";
2+
3+
export interface Contract {
4+
/** Unique key ID */
5+
id: string;
6+
/** Contract kind */
7+
kind: string;
8+
/** Version of the contract */
9+
version: string;
10+
/** Date at which the contract starts applying */
11+
start_date: string;
12+
/** Date at which the contract stops applying, if relevant */
13+
end_date: string | null;
14+
/** Map of locale => url of the pdf of the contract in locale */
15+
pdf_urls: Record<ContractLangs, string>;
16+
/** Map of locale => url of a web page of the contract in locale */
17+
web_urls: Record<ContractLangs, string>;
18+
}
19+
20+
export interface ContractAgreement {
21+
/** Unique key ID */
22+
id: string;
23+
/** ID of the user who accepted the contract */
24+
user_id: string;
25+
/** The date when the contract was accepted */
26+
date: string;
27+
/** The locale in which the contract was accepted */
28+
locale: ContractLangs;
29+
}

src/models/auth/user.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export interface User {
3434
suspension_reason: string | null;
3535

3636
preferences: UserPreferences;
37+
38+
contracts: Record<string, boolean>;
39+
new_contracts: Record<string, boolean>;
3740
}
3841

3942
export interface GithubProfile {

src/params/auth/contracts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ContractLangs } from "../../models/auth/contracts";
2+
3+
export interface CreateAgreementParams {
4+
/** ID of the contract to agree to */
5+
contract_id: string;
6+
/** Locale of the contract to agree to */
7+
locale: ContractLangs;
8+
}

test/Contracts/index.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import Contracts from "../../src/Contracts";
2+
import { testGetter, testPost } from "../utils/http";
3+
4+
describe("Contracts#all", () => {
5+
testGetter(
6+
"https://auth.scalingo.com/v1/contracts",
7+
null,
8+
"contracts",
9+
(client) => {
10+
return new Contracts(client).all();
11+
}
12+
);
13+
});
14+
15+
describe("Contracts#allAgreements", () => {
16+
testGetter(
17+
"https://auth.scalingo.com/v1/contract_agreements",
18+
null,
19+
"contract_agreements",
20+
(client) => {
21+
return new Contracts(client).allAgreements();
22+
}
23+
);
24+
});
25+
26+
describe("Contracts#show", () => {
27+
testGetter(
28+
"https://auth.scalingo.com/v1/contracts/contract-id",
29+
null,
30+
"contract",
31+
(client) => {
32+
return new Contracts(client).show("contract-id");
33+
}
34+
);
35+
});
36+
37+
describe("Contracts#showAgreement", () => {
38+
testGetter(
39+
"https://auth.scalingo.com/v1/contract_agreements/contract-id",
40+
null,
41+
"contract_agreement",
42+
(client) => {
43+
return new Contracts(client).showAgreement("contract-id");
44+
}
45+
);
46+
});
47+
48+
describe("Contracts#createAgreement", () => {
49+
testPost(
50+
"https://auth.scalingo.com/v1/contract_agreements",
51+
null,
52+
{ contract_agreement: { contract_id: "my-id", locale: "es" } },
53+
"contract_agreement",
54+
(client) => {
55+
return new Contracts(client).createAgreement({
56+
contract_id: "my-id",
57+
locale: "es",
58+
});
59+
}
60+
);
61+
});

0 commit comments

Comments
 (0)