Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 34ff8db

Browse files
authored
Merge pull request #675 from inplayer-org/ch12080/add-new-get-account-sdk-method
New account methods added
2 parents caa1c1d + 3a9dbc9 commit 34ff8db

File tree

7 files changed

+158
-3
lines changed

7 files changed

+158
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [3.11.0] - 11-03-2021
6+
7+
### Added
8+
9+
- New account methods: Inplayer.Account.signInV2 and Inplayer.Account.signUpV2
10+
511
# [3.10.0] - 24-02-2021
612

713
### Changes

index.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export interface SignUpData {
3434
metadata?: { [key: string]: string };
3535
}
3636

37+
export interface SignUpDataV2 {
38+
fullName: string;
39+
email: string;
40+
password: string;
41+
passwordConfirmation: string;
42+
type: string;
43+
clientId: string;
44+
referrer: string;
45+
metadata: { [key: string]: string };
46+
brandingId: number;
47+
}
48+
3749
export interface RequestPasswordData {
3850
email: string;
3951
merchantUuid: string;
@@ -74,6 +86,13 @@ export declare interface AuthenticateData {
7486
password?: string;
7587
}
7688

89+
export interface AuthenticateDataV2 {
90+
email: string;
91+
clientId: string;
92+
referrer: string;
93+
password: string;
94+
}
95+
7796
export declare interface AccountInformationReturn {
7897
id: number;
7998
email: string;
@@ -148,7 +167,9 @@ export declare class Account {
148167
removeToken<R = void>(): R | void;
149168

150169
signIn(data: AuthenticateData): Promise<AxiosResponse<CreateAccount>>;
170+
signInV2(data: AuthenticateDataV2): Promise<AxiosResponse<CreateAccount>>;
151171
signUp(data: SignUpData): Promise<AxiosResponse<CreateAccount>>;
172+
signUpV2(data: SignUpDataV2): Promise<AxiosResponse<CreateAccount>>;
152173
signOut(): Promise<AxiosResponse<undefined>>;
153174
refreshToken(clientId: string): Promise<AxiosResponse<CreateAccount>>;
154175
reportSSOtoken(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inplayer-org/inplayer.js",
3-
"version": "3.9.0",
3+
"version": "3.11.0",
44
"author": "InPlayer",
55
"license": "MIT",
66
"description": "A Javascript SDK for Inplayer's RESTful API",

src/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
export const API = {
22
// Account
33
signIn: '/accounts/authenticate',
4+
signInV2: '/v2/accounts/authenticate',
45
signOut: '/accounts/logout',
56
signUp: '/accounts',
7+
signUpV2: 'v2/accounts',
68
requestNewPassword: '/accounts/forgot-password',
79
setNewPassword: (token: any) => `/accounts/forgot-password/${token}`,
810
getAccountInfo: '/accounts',

src/endpoints/account.ts

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import qs from 'qs';
22
import {
33
AuthenticateData,
4+
AuthenticateDataV2,
45
SignUpData,
6+
SignUpDataV2,
57
RequestNewPasswordData,
68
SetNewPasswordData,
79
UpdateAccountData,
@@ -116,6 +118,51 @@ class Account extends BaseExtend {
116118
return respData;
117119
}
118120

121+
/**
122+
* Signs in the user v2
123+
* @method signInV2
124+
* @async
125+
* @typedef {Object} AxiosResponse<CreateAccount>
126+
* @param {AuthenticateDataV2} data - Contains {
127+
* email: string,
128+
* password: string,
129+
* clientId: string,
130+
* referrer: string,
131+
* }
132+
* @example
133+
* InPlayer.Account.signInV2({
134+
* email: 'test@test.com',
135+
* password: 'test123',
136+
* clientId: '123-123-hf1hd1-12dhd1',
137+
* referrer: 'http://localhost:3000/',
138+
* })
139+
* .then(data => console.log(data));
140+
* @returns {AxiosResponse<CreateAccount>}
141+
*/
142+
async signInV2(data: AuthenticateDataV2) {
143+
const body = {
144+
client_id: data.clientId,
145+
grant_type: 'password',
146+
referrer: data.referrer,
147+
username: data.email,
148+
password: data.password,
149+
};
150+
151+
const respData = await this.request.post(API.signInV2, qs.stringify(body), {
152+
headers: {
153+
'Content-Type': 'application/x-www-form-urlencoded',
154+
},
155+
});
156+
157+
await this.request.setToken(
158+
respData.data.access_token,
159+
respData.data.refresh_token,
160+
respData.data.expires,
161+
);
162+
163+
return respData;
164+
}
165+
119166
/**
120167
* Signs up/Registers user
121168
* @method signUp
@@ -129,8 +176,7 @@ class Account extends BaseExtend {
129176
* type: string,
130177
* referrer: string,
131178
* brandingId?: number,
132-
* metadata?: { [key: string]: string }\
133-
* dateOfBirth?: string,
179+
* metadata?: { [key: string]: string }
134180
* }
135181
* @example
136182
* InPlayer.Account.signUp({
@@ -174,6 +220,63 @@ class Account extends BaseExtend {
174220
return resp;
175221
}
176222

223+
/**
224+
* Signs up/Registers user v2
225+
* @method signUpV2
226+
* @async
227+
* @param {SignUpDataV2} data - Contains {
228+
* fullName: string,
229+
* email: string
230+
* password: string,
231+
* passwordConfirmation: string,
232+
* clientId: string,
233+
* type: string,
234+
* referrer: string,
235+
* brandingId?: number,
236+
* metadata?: { [key: string]: string }
237+
* }
238+
* @example
239+
* InPlayer.Account.signUpV2({
240+
* fullName: "test",
241+
* email: "test32@test.com",
242+
* password: "12345678",
243+
* passwordConfirmation: "12345678",
244+
* clientId: "528b1b80-5868-4abc-a9b6-4d3455d719c8",
245+
* type: "consumer",
246+
* referrer: "http://localhost:3000/",
247+
* brandingId?: 12345,
248+
* metadata : { country: "Macedonia" },
249+
* })
250+
* .then(data => console.log(data));
251+
* @returns {AxiosResponse<CreateAccount>}
252+
*/
253+
async signUpV2(data: SignUpDataV2) {
254+
const body = {
255+
full_name: data.fullName,
256+
username: data.email,
257+
password: data.password,
258+
password_confirmation: data.passwordConfirmation,
259+
client_id: data.clientId,
260+
type: data.type,
261+
referrer: data.referrer,
262+
grant_type: 'password',
263+
metadata: data.metadata,
264+
branding_id: data.brandingId,
265+
};
266+
267+
const resp = await this.request.post(API.signUpV2, qs.stringify(body), {
268+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
269+
});
270+
271+
await this.request.setToken(
272+
resp.data.access_token,
273+
resp.data.refresh_token,
274+
resp.data.expires,
275+
);
276+
277+
return resp;
278+
}
279+
177280
/**
178281
* Signs out the user and destroys cookies
179282
* @method signOut

src/models/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export interface ApiConfig {
1111

1212
export interface ApiEndpoints {
1313
signIn: string;
14+
signInV2: string;
1415
signOut: string;
1516
signUp: string;
17+
signUpV2: string;
1618
requestNewPassword: string;
1719
setNewPassword: (token: string) => string;
1820
getAccountInfo: string;

src/models/IAccount&Authentication.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ export interface AuthenticateData {
115115
password?: string;
116116
}
117117

118+
export interface AuthenticateDataV2 {
119+
email: string;
120+
clientId: string;
121+
referrer: string;
122+
password: string;
123+
}
124+
118125
export interface SignUpData {
119126
fullName: string;
120127
email: string;
@@ -128,6 +135,18 @@ export interface SignUpData {
128135
brandingId: number;
129136
}
130137

138+
export interface SignUpDataV2 {
139+
fullName: string;
140+
email: string;
141+
password: string;
142+
passwordConfirmation: string;
143+
type: 'consumer';
144+
clientId: string;
145+
referrer: string;
146+
metadata: Record<string, unknown>[];
147+
brandingId: number;
148+
}
149+
131150
export interface RequestNewPasswordData {
132151
merchantUuid: string;
133152
email: string;
@@ -168,7 +187,9 @@ export interface RestrictionSettingsData {
168187

169188
export interface Account extends BaseExtend {
170189
signIn(data: AuthenticateData): Promise<AxiosResponse<CreateAccount>>;
190+
signInV2(data: AuthenticateDataV2): Promise<AxiosResponse<CreateAccountV2>>
171191
signUp(data: SignUpData): Promise<AxiosResponse<CreateAccount>>;
192+
signUpV2(data: SignUpDataV2): Promise<AxiosResponse<CreateAccount>>;
172193
signOut(): Promise<AxiosResponse<undefined>>;
173194
refreshToken(clientId: string): Promise<AxiosResponse<CreateAccount>>;
174195
reportSSOtoken(

0 commit comments

Comments
 (0)