51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import BaseId360 from "../BaseId360";
|
|
|
|
export interface IConnectionUrlResponse {
|
|
enrollment: {
|
|
franceConnectUrl: string;
|
|
processId: string;
|
|
}
|
|
}
|
|
|
|
export interface ICustomerTokens {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
}
|
|
|
|
export default class Customers extends BaseId360 {
|
|
private static instance: Customers;
|
|
private readonly baseURl = this.namespaceUrl.concat("/customers");
|
|
|
|
private constructor() {
|
|
super();
|
|
}
|
|
|
|
public static getInstance() {
|
|
if (!this.instance) {
|
|
return new this();
|
|
} else {
|
|
return this.instance;
|
|
}
|
|
}
|
|
|
|
public async login(): Promise<IConnectionUrlResponse> {
|
|
const url = new URL(this.baseURl.concat(`/login`));
|
|
try {
|
|
return await this.postRequest<IConnectionUrlResponse>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async loginCallback(callbackToken: string | string[]): Promise<ICustomerTokens> {
|
|
const url = new URL(this.baseURl.concat(`/login-callback/${callbackToken}`));
|
|
try {
|
|
return await this.postRequest<ICustomerTokens>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
}
|