Skip to content

Commit

Permalink
Revert "chore: init adding version param"
Browse files Browse the repository at this point in the history
This reverts commit 25fba47.
  • Loading branch information
einaralex committed Aug 8, 2024
1 parent 25fba47 commit 9fb6bea
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 302 deletions.
75 changes: 14 additions & 61 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export class MoneriumClient {
#env: Environment;

#authorizationHeader?: string;

#version?: string;
/**
* The PKCE code verifier
* @deprecated, use localStorage, will be removed in v3
Expand Down Expand Up @@ -93,7 +91,6 @@ export class MoneriumClient {
// No arguments, default to sandbox
if (!envOrOptions) {
this.#env = MONERIUM_CONFIG.environments['sandbox'];
this.#version = 'v2';
return;
}
// String argument
Expand All @@ -102,7 +99,6 @@ export class MoneriumClient {
} else {
this.#env =
MONERIUM_CONFIG.environments[envOrOptions.environment || 'sandbox'];
this.#version = envOrOptions?.version || 'v2';

if (!isServer) {
const { clientId, redirectUri } =
Expand Down Expand Up @@ -352,42 +348,15 @@ export class MoneriumClient {
* {@link https://monerium.dev/api-docs#operation/profile-addresses}
* @category Accounts
*/
linkAddress(
body: Omit<LinkAddress, 'accounts'> & { profile: string }
): Promise<LinkedAddress>;
/** @deprecated this function should only take one parameter, body with profile id included */
linkAddress(profileId: string, body: LinkAddress): Promise<LinkedAddress>;

linkAddress(
profileIdOrBody:
| string
| (Omit<LinkAddress, 'accounts'> & { profile: string }),
/** @deprecated this function should only take one parameter, body with profile id included */
body?: LinkAddress
): Promise<LinkedAddress> {
if (typeof profileIdOrBody === 'string' && body && this.#version === 'v1') {
body = mapChainIdToChain(body);
if (body?.accounts) {
body.accounts = body?.accounts.map((account) =>
mapChainIdToChain(account)
);
}
linkAddress(profileId: string, body: LinkAddress): Promise<LinkedAddress> {
body = mapChainIdToChain(body);
body.accounts = body.accounts.map((account) => mapChainIdToChain(account));

return this.#api<LinkedAddress>(
'post',
`profiles/${profileIdOrBody}/addresses`,
JSON.stringify(body)
);
} else if (typeof profileIdOrBody === 'object' && this.#version === 'v2') {
profileIdOrBody = mapChainIdToChain(profileIdOrBody);
return this.#api<LinkedAddress>(
'post',
`addresses`,
JSON.stringify(profileIdOrBody)
);
} else {
throw new Error('Invalid arguments');
}
return this.#api(
'post',
`profiles/${profileId}/addresses`,
JSON.stringify(body)
);
}

/**
Expand Down Expand Up @@ -428,32 +397,16 @@ export class MoneriumClient {
body?: BodyInit | Record<string, string>,
isFormEncoded?: boolean
): Promise<T> {
const headers: Record<string, string> = {
Authorization: this.#authorizationHeader || '',
'Content-Type': `application/${
isFormEncoded ? 'x-www-form-urlencoded' : 'json'
}`,
};
if (this.#version === 'v2') {
headers['Accept'] = 'application/vnd.monerium.api-v2+json';
}
console.log(
'%c headers',
'color:white; padding: 30px; background-color: darkgreen',
headers
);

console.log(
'%c ${this.#env.api}/${resource}',
'color:white; padding: 30px; background-color: darkgreen',
`${this.#env.api}/${resource}`
);

return rest<T>(
`${this.#env.api}/${resource}`,
method,
isFormEncoded ? urlEncoded(body as Record<string, string>) : body,
headers
{
Authorization: this.#authorizationHeader || '',
'Content-Type': `application/${
isFormEncoded ? 'x-www-form-urlencoded' : 'json'
}`,
}
);
}

Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ export type MoneriumEventListener = (notification: OrderNotification) => void;

export type ClassOptions = {
environment?: ENV;
version?: 'v1' | 'v2';
} & BearerTokenCredentials;

export interface AuthFlowOptions {
Expand Down
232 changes: 0 additions & 232 deletions packages/sdk/test/client-server-v2.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/sdk/test/client-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ process.env.CI !== 'true' &&
client = new MoneriumClient({
clientId: APP_ONE_CREDENTIALS_CLIENT_ID,
clientSecret: APP_ONE_CREDENTIALS_SECRET,
version: 'v1',
});
try {
await client.getAccess();
Expand Down
Loading

0 comments on commit 9fb6bea

Please sign in to comment.