Skip to content

Commit fba6914

Browse files
authored
Merge pull request #355 from platformsh/change-api-url
Update config and models to use new api url
2 parents fe2f43a + 4451155 commit fba6914

36 files changed

+261
-327
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "platformsh-client",
3-
"version": "0.2.35",
3+
"version": "0.2.36-beta.1",
44
"description": "Isomorphic Javascript library for accessing the Platform.sh API",
55
"type": "module",
66
"main": "lib/index.js",

src/config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const DEFAULT_ACCOUNT_URL = "https://accounts.platform.sh";
2-
const DEFAULT_API_URL = "https://api.platform.sh/api";
2+
const DEFAULT_API_URL = "https://api.platform.sh";
33

44
export type ClientConfiguration = {
55
provider?: string;
66
client_id?: string;
7-
account_url?: string;
87
api_url: string;
98
authentication_url?: string;
109
scope?: string[];
@@ -31,7 +30,6 @@ export type DefaultClientConfiguration = ClientConfiguration & {
3130
redirect_uri: string;
3231
provider: string;
3332
client_id: string;
34-
account_url: string;
3533
authentication_url: string;
3634
prompt: string;
3735
response_type: string;
@@ -43,8 +41,6 @@ const getConfigDefault = (
4341
): DefaultClientConfiguration => ({
4442
provider: "cg",
4543
client_id: "[email protected]",
46-
// On development environment, "baseUrl" already has "/api" appended and this is required.
47-
account_url: `${baseUrl.replace(/(\/api\/?)$/u, "")}/api`,
4844
api_url,
4945
authentication_url: baseUrl,
5046
scope: [],

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export default class Client {
8686
if (project?.endpoint) {
8787
return project.endpoint;
8888
}
89-
const { account_url } = getConfig();
89+
const { api_url } = getConfig();
9090

91-
return request(`${account_url}/platform/projects/${id}`, "GET").then(
91+
return request(`${api_url}/projects/${id}`, "GET").then(
9292
result => result.endpoint || false
9393
);
9494
});
@@ -646,7 +646,7 @@ export default class Client {
646646
}) {
647647
const { api_url } = getConfig();
648648

649-
return request(`${api_url}/v1/subscriptions/estimate`, "GET", params);
649+
return request(`${api_url}/subscriptions/estimate`, "GET", params);
650650
}
651651

652652
/**
@@ -983,7 +983,7 @@ export default class Client {
983983
*/
984984
async getCardOnFile() {
985985
const { api_url } = getConfig();
986-
const card = request(`${api_url}/platform/cardonfile`, "GET");
986+
const card = request(`${api_url}/cardonfile`, "GET");
987987
return card;
988988
}
989989

@@ -1172,7 +1172,7 @@ export default class Client {
11721172
async updateUserProfile(id: string, data: APIObject) {
11731173
const { api_url } = getConfig();
11741174
const updatedProfile = await request(
1175-
`${api_url}/platform/profiles/${id}`,
1175+
`${api_url}/profiles/${id}`,
11761176
"PATCH",
11771177
data
11781178
);
@@ -1206,7 +1206,7 @@ export default class Client {
12061206
*/
12071207
async getSetupRegistry() {
12081208
const { api_url } = getConfig();
1209-
return request(`${api_url}/platform/setup/registry`, "POST").then(
1209+
return request(`${api_url}/setup/registry`, "POST").then(
12101210
(data: Record<string, APIObject>) =>
12111211
typeof data === "undefined"
12121212
? undefined
@@ -1261,7 +1261,7 @@ export default class Client {
12611261
const { api_url } = getConfig();
12621262

12631263
const user = await request(
1264-
`${api_url}/v1/profiles?filter[username]=${username}`
1264+
`${api_url}/profiles?filter[username]=${username}`
12651265
);
12661266

12671267
return new entities.AccountsProfile(user.profiles[0]);

src/model/Account.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getConfig } from "../config";
33
import type { APIObject } from "./Ressource";
44
import { Ressource } from "./Ressource";
55

6-
const url = "/platform/users/:id";
6+
const url = "/users/:id";
77
const paramDefaults = {};
88

99
export type AccountGetParams = {
@@ -23,9 +23,9 @@ export class Account extends Ressource {
2323

2424
constructor(account: APIObject) {
2525
const { id } = account;
26-
const { account_url } = getConfig();
26+
const { api_url } = getConfig();
2727

28-
super(`${account_url}${url}`, paramDefaults, { id }, account);
28+
super(`${api_url}${url}`, paramDefaults, { id }, account);
2929
this._queryUrl = Ressource.getQueryUrl(url);
3030
this.id = account.id;
3131
this.created_at = account.created_at;
@@ -39,21 +39,21 @@ export class Account extends Ressource {
3939

4040
static async get(params: AccountGetParams, customUrl?: string) {
4141
const { id, ...queryParams } = params;
42-
const { account_url } = getConfig();
42+
const { api_url } = getConfig();
4343

4444
return super._get<Account>(
45-
customUrl ?? `${account_url}${url}`,
45+
customUrl ?? `${api_url}${url}`,
4646
{ id },
4747
paramDefaults,
4848
queryParams
4949
);
5050
}
5151

5252
static async query(params: AccountGetParams) {
53-
const { account_url } = getConfig();
53+
const { api_url } = getConfig();
5454

5555
return super._query<Account>(
56-
this.getQueryUrl(`${account_url}${url}`),
56+
this.getQueryUrl(`${api_url}${url}`),
5757
{},
5858
paramDefaults,
5959
params

src/model/AccountsProfile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { urlParser } from "../urlParser";
55
import type { APIObject } from "./Ressource";
66
import { Ressource } from "./Ressource";
77

8-
const url = "/platform/profiles/:id";
8+
const url = "/profiles/:id";
99
const paramDefaults = {};
1010
const createableField = [
1111
"id",
@@ -115,7 +115,7 @@ export class AccountsProfile extends Ressource {
115115
const { api_url } = getConfig();
116116

117117
const user = await authenticatedRequest(
118-
`${api_url}/v1/profiles?filter[username]=${username}`
118+
`${api_url}/profiles?filter[username]=${username}`
119119
);
120120

121121
return new AccountsProfile(user.profiles[0]);
@@ -124,7 +124,7 @@ export class AccountsProfile extends Ressource {
124124
static async updateProfilePicture(userId: string, picture: FormData) {
125125
const { api_url } = getConfig();
126126
return authenticatedRequest(
127-
`${api_url}/v1/profile/${userId}/picture`,
127+
`${api_url}/profile/${userId}/picture`,
128128
"POST",
129129
picture
130130
);
@@ -133,7 +133,7 @@ export class AccountsProfile extends Ressource {
133133
static async deleteProfilePicture(userId: string) {
134134
const { api_url } = getConfig();
135135
return authenticatedRequest(
136-
`${api_url}/v1/profile/${userId}/picture`,
136+
`${api_url}/profile/${userId}/picture`,
137137
"DELETE"
138138
);
139139
}

src/model/Address.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { urlParser } from "../urlParser";
44
import type { APIObject } from "./Ressource";
55
import { Ressource } from "./Ressource";
66

7-
const url = "/v1/profiles/:id/address";
7+
const url = "/profiles/:id/address";
88
const paramDefaults = {};
99

1010
export type AddressParams = {
@@ -40,17 +40,17 @@ export class Address extends Ressource {
4040

4141
constructor(address: APIObject) {
4242
const { id } = address;
43-
const { account_url } = getConfig();
43+
const { api_url } = getConfig();
4444

4545
super(
46-
`${account_url}${url}`,
46+
`${api_url}${url}`,
4747
paramDefaults,
4848
{ id },
4949
address,
5050
[],
5151
_modifiableField
5252
);
53-
this._queryUrl = Address.getQueryUrl(`${account_url}${url}`, id);
53+
this._queryUrl = Address.getQueryUrl(`${api_url}${url}`, id);
5454
this.id = address.id;
5555
this.country = address.country;
5656
this.name_line = address.name_line;

src/model/Comment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getConfig } from "../config";
44
import type { APIObject } from "./Ressource";
55
import { Ressource } from "./Ressource";
66

7-
const url = "/v1/comments";
7+
const url = "/comments";
88
const paramDefaults = {};
99

1010
const createableField = ["body", "ticket_id", "attachments", "author_id"];

src/model/Me.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { SshKey } from "./SshKey";
99
import type { Team } from "./Team";
1010
import { User } from "./User";
1111

12-
const url = "/platform/me";
12+
const url = "/me";
1313
const modifiableField = [
1414
"picture",
1515
"mail",
@@ -92,7 +92,7 @@ export class Me extends User {
9292
async update(data: APIObject) {
9393
const { api_url } = getConfig();
9494

95-
const result = await super.update(data, `${api_url}/platform/profiles/:id`);
95+
const result = await super.update(data, `${api_url}/profiles/:id`);
9696

9797
return new Result(new Me(result.data)); // Account API does not return a Result
9898
}

src/model/Order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getConfig } from "../config";
33
import type { APIObject } from "./Ressource";
44
import { Ressource } from "./Ressource";
55

6-
const url = "/v1/orders/:id";
6+
const url = "/orders/:id";
77
const paramDefaults = {};
88

99
export type OrdersGetParams = {

0 commit comments

Comments
 (0)