Skip to content

Commit

Permalink
Merge pull request #355 from platformsh/change-api-url
Browse files Browse the repository at this point in the history
Update config and models to use new api url
  • Loading branch information
shakaman authored Dec 20, 2024
2 parents fe2f43a + 4451155 commit fba6914
Show file tree
Hide file tree
Showing 36 changed files with 261 additions and 327 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "platformsh-client",
"version": "0.2.35",
"version": "0.2.36-beta.1",
"description": "Isomorphic Javascript library for accessing the Platform.sh API",
"type": "module",
"main": "lib/index.js",
Expand Down
6 changes: 1 addition & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const DEFAULT_ACCOUNT_URL = "https://accounts.platform.sh";
const DEFAULT_API_URL = "https://api.platform.sh/api";
const DEFAULT_API_URL = "https://api.platform.sh";

export type ClientConfiguration = {
provider?: string;
client_id?: string;
account_url?: string;
api_url: string;
authentication_url?: string;
scope?: string[];
Expand All @@ -31,7 +30,6 @@ export type DefaultClientConfiguration = ClientConfiguration & {
redirect_uri: string;
provider: string;
client_id: string;
account_url: string;
authentication_url: string;
prompt: string;
response_type: string;
Expand All @@ -43,8 +41,6 @@ const getConfigDefault = (
): DefaultClientConfiguration => ({
provider: "cg",
client_id: "[email protected]",
// On development environment, "baseUrl" already has "/api" appended and this is required.
account_url: `${baseUrl.replace(/(\/api\/?)$/u, "")}/api`,
api_url,
authentication_url: baseUrl,
scope: [],
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export default class Client {
if (project?.endpoint) {
return project.endpoint;
}
const { account_url } = getConfig();
const { api_url } = getConfig();

return request(`${account_url}/platform/projects/${id}`, "GET").then(
return request(`${api_url}/projects/${id}`, "GET").then(
result => result.endpoint || false
);
});
Expand Down Expand Up @@ -646,7 +646,7 @@ export default class Client {
}) {
const { api_url } = getConfig();

return request(`${api_url}/v1/subscriptions/estimate`, "GET", params);
return request(`${api_url}/subscriptions/estimate`, "GET", params);
}

/**
Expand Down Expand Up @@ -983,7 +983,7 @@ export default class Client {
*/
async getCardOnFile() {
const { api_url } = getConfig();
const card = request(`${api_url}/platform/cardonfile`, "GET");
const card = request(`${api_url}/cardonfile`, "GET");
return card;
}

Expand Down Expand Up @@ -1172,7 +1172,7 @@ export default class Client {
async updateUserProfile(id: string, data: APIObject) {
const { api_url } = getConfig();
const updatedProfile = await request(
`${api_url}/platform/profiles/${id}`,
`${api_url}/profiles/${id}`,
"PATCH",
data
);
Expand Down Expand Up @@ -1206,7 +1206,7 @@ export default class Client {
*/
async getSetupRegistry() {
const { api_url } = getConfig();
return request(`${api_url}/platform/setup/registry`, "POST").then(
return request(`${api_url}/setup/registry`, "POST").then(
(data: Record<string, APIObject>) =>
typeof data === "undefined"
? undefined
Expand Down Expand Up @@ -1261,7 +1261,7 @@ export default class Client {
const { api_url } = getConfig();

const user = await request(
`${api_url}/v1/profiles?filter[username]=${username}`
`${api_url}/profiles?filter[username]=${username}`
);

return new entities.AccountsProfile(user.profiles[0]);
Expand Down
14 changes: 7 additions & 7 deletions src/model/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from "../config";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/platform/users/:id";
const url = "/users/:id";
const paramDefaults = {};

export type AccountGetParams = {
Expand All @@ -23,9 +23,9 @@ export class Account extends Ressource {

constructor(account: APIObject) {
const { id } = account;
const { account_url } = getConfig();
const { api_url } = getConfig();

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

static async get(params: AccountGetParams, customUrl?: string) {
const { id, ...queryParams } = params;
const { account_url } = getConfig();
const { api_url } = getConfig();

return super._get<Account>(
customUrl ?? `${account_url}${url}`,
customUrl ?? `${api_url}${url}`,
{ id },
paramDefaults,
queryParams
);
}

static async query(params: AccountGetParams) {
const { account_url } = getConfig();
const { api_url } = getConfig();

return super._query<Account>(
this.getQueryUrl(`${account_url}${url}`),
this.getQueryUrl(`${api_url}${url}`),
{},
paramDefaults,
params
Expand Down
8 changes: 4 additions & 4 deletions src/model/AccountsProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { urlParser } from "../urlParser";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/platform/profiles/:id";
const url = "/profiles/:id";
const paramDefaults = {};
const createableField = [
"id",
Expand Down Expand Up @@ -115,7 +115,7 @@ export class AccountsProfile extends Ressource {
const { api_url } = getConfig();

const user = await authenticatedRequest(
`${api_url}/v1/profiles?filter[username]=${username}`
`${api_url}/profiles?filter[username]=${username}`
);

return new AccountsProfile(user.profiles[0]);
Expand All @@ -124,7 +124,7 @@ export class AccountsProfile extends Ressource {
static async updateProfilePicture(userId: string, picture: FormData) {
const { api_url } = getConfig();
return authenticatedRequest(
`${api_url}/v1/profile/${userId}/picture`,
`${api_url}/profile/${userId}/picture`,
"POST",
picture
);
Expand All @@ -133,7 +133,7 @@ export class AccountsProfile extends Ressource {
static async deleteProfilePicture(userId: string) {
const { api_url } = getConfig();
return authenticatedRequest(
`${api_url}/v1/profile/${userId}/picture`,
`${api_url}/profile/${userId}/picture`,
"DELETE"
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/model/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { urlParser } from "../urlParser";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/v1/profiles/:id/address";
const url = "/profiles/:id/address";
const paramDefaults = {};

export type AddressParams = {
Expand Down Expand Up @@ -40,17 +40,17 @@ export class Address extends Ressource {

constructor(address: APIObject) {
const { id } = address;
const { account_url } = getConfig();
const { api_url } = getConfig();

super(
`${account_url}${url}`,
`${api_url}${url}`,
paramDefaults,
{ id },
address,
[],
_modifiableField
);
this._queryUrl = Address.getQueryUrl(`${account_url}${url}`, id);
this._queryUrl = Address.getQueryUrl(`${api_url}${url}`, id);
this.id = address.id;
this.country = address.country;
this.name_line = address.name_line;
Expand Down
2 changes: 1 addition & 1 deletion src/model/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getConfig } from "../config";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/v1/comments";
const url = "/comments";
const paramDefaults = {};

const createableField = ["body", "ticket_id", "attachments", "author_id"];
Expand Down
4 changes: 2 additions & 2 deletions src/model/Me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { SshKey } from "./SshKey";
import type { Team } from "./Team";
import { User } from "./User";

const url = "/platform/me";
const url = "/me";
const modifiableField = [
"picture",
"mail",
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Me extends User {
async update(data: APIObject) {
const { api_url } = getConfig();

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

return new Result(new Me(result.data)); // Account API does not return a Result
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from "../config";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/v1/orders/:id";
const url = "/orders/:id";
const paramDefaults = {};

export type OrdersGetParams = {
Expand Down
6 changes: 3 additions & 3 deletions src/model/OrganizationAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ export class OrganizationAddress extends Ressource {

constructor(account: APIObject, customUrl?: string) {
const { id } = account;
const { account_url } = getConfig();
const { api_url } = getConfig();

super(
customUrl ?? `${account_url}${url}`,
customUrl ?? `${api_url}${url}`,
paramDefaults,
{ id },
account,
[],
_modifiableField
);
this._queryUrl = Ressource.getQueryUrl(`${account_url}${url}`);
this._queryUrl = Ressource.getQueryUrl(`${api_url}${url}`);
this.id = account.id;
this.country = account.country;
this.name_line = account.name_line;
Expand Down
2 changes: 1 addition & 1 deletion src/model/PaymentSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { urlParser } from "../urlParser";
import type { APIObject, ParamsType } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/platform/payment_source";
const url = "/payment_source";
const paramDefaults = {};
const creatableField = ["type", "token", "email", "chargeable"];

Expand Down
10 changes: 5 additions & 5 deletions src/model/Region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from "../config";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const url = "/platform/regions";
const url = "/regions";
const paramDefaults = {};

export type RegionGetParams = Record<string, any>;
Expand Down Expand Up @@ -41,9 +41,9 @@ export class Region extends Ressource {

constructor(region: APIObject) {
const { id } = region;
const { account_url } = getConfig();
const { api_url } = getConfig();

super(`${account_url}${url}`, paramDefaults, { id }, region);
super(`${api_url}${url}`, paramDefaults, { id }, region);
this._queryUrl = Ressource.getQueryUrl(url);
this.id = region.id;
this.available = region.available;
Expand All @@ -62,10 +62,10 @@ export class Region extends Ressource {
}

static async query(params: RegionGetParams) {
const { account_url } = getConfig();
const { api_url } = getConfig();

return super._query<Region>(
`${account_url}${url}`,
`${api_url}${url}`,
{},
paramDefaults,
params,
Expand Down
2 changes: 1 addition & 1 deletion src/model/SetupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { urlParser } from "../urlParser";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const _url = "/platform/setup/config";
const _url = "/setup/config";
const paramDefaults = {};

export class SetupConfig extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/SetupRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { urlParser } from "../urlParser";
import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const _url = "/platform/setup/registry";
const _url = "/setup/registry";
const paramDefaults = {};

export type SetupRegistryGetParams = {
Expand Down
2 changes: 1 addition & 1 deletion src/model/SshKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { APIObject } from "./Ressource";
import { Ressource } from "./Ressource";

const paramDefaults = {};
const url = "/v1/ssh_keys/:id";
const url = "/ssh_keys/:id";

export type SshKeyGetParams = {
[key: string]: any;
Expand Down
17 changes: 1 addition & 16 deletions src/model/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import isUrl from "is-url";
import { authenticatedRequest } from "../api";
import { getConfig } from "../config";

import { Account } from "./Account";
import type {
MaybeComplexFormattedCost,
MaybeComplexFormattedCostCounter,
Expand Down Expand Up @@ -39,7 +38,7 @@ const modifiableField = [
"continuous_profiling"
];

const url = "/v1/subscriptions/:id";
const url = "/subscriptions/:id";

const availablePlans = ["development", "standard", "medium", "large"];
const availableRegions = ["eu.platform.sh", "us.platform.sh"];
Expand Down Expand Up @@ -465,20 +464,6 @@ export class Subscription extends Ressource {
return this.status;
}

/**
* Get the account for the project's owner.
*
* @return Account|false
*/
async getOwner() {
const id = this.owner;

return Account.get(
{ id },
this.makeAbsoluteUrl("/api/users", this.getLink("project"))
);
}

/**
* Get the project associated with this subscription.
*
Expand Down
2 changes: 1 addition & 1 deletion src/model/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ressource } from "./Ressource";
import { TeamMember } from "./TeamMember";

const paramDefaults = {};
const _url = "/platform/teams";
const _url = "/teams";

const creatableField = ["name", "parent", "id"];
const modifiableField = ["name"];
Expand Down
Loading

0 comments on commit fba6914

Please sign in to comment.