Skip to content

Commit

Permalink
New types and IDX namespace - 2.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthovestadt committed Feb 16, 2017
1 parent 172cc1a commit 9abe6b2
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 13 deletions.
43 changes: 42 additions & 1 deletion lib/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ export class Accounts {
return this.gigya.request<AccountsGetScreenSetsResponse>('accounts.getScreenSets', params);
}

/**
* This method imports user account data into the Accounts Storage.
*
* @see http://developers.gigya.com/display/GD/accounts.importAccount+REST
*/
public importAccount(params: BaseParams & AccountsImportAccountParams) {
return this.gigya.request<AccountsImportAccountResponse>('accounts.importAccount', params);
}

/**
* This method imports a user's profile photo to Gigya's server.
*
Expand Down Expand Up @@ -215,7 +224,7 @@ export class Accounts {
*
* @see http://developers.gigya.com/display/GD/accounts.notifyLogin+REST
*/
public notifyLogin(params: BaseParams & AccountsNotifyLoginParamsSiteUID | AccountsNotifyLoginParamsProviderSessions) {
public notifyLogin(params: BaseParams & (AccountsNotifyLoginParamsSiteUID | AccountsNotifyLoginParamsProviderSessions)) {
return this.gigya.request<Account & SessionInfo>('accounts.notifyLogin', params);
}

Expand Down Expand Up @@ -607,6 +616,37 @@ export interface AccountsSetAccountInfoParams {
regSource?: string;
}

export interface AccountsImportAccountParams {
UID: string;
username?: string;
email?: string;
secretQuestion?: string;
secretAnswer?: string;
profile?: Profile;
data?: any;
lang?: string;
skipVerification?: boolean;
finalizeRegistration?: boolean;
created?: string;
lastUpdated?: string;
isActive?: boolean;
regSource?: string;
lastLogin?: string;
compoundHashedPassword?: string;
hashedPassword?: string;
pwHashAlgorithm?: string;
pwHashFormat?: string;
pwHashBinaryFormat?: string;
pwHashSalt?: string;
pwHashRounds?: string;
url?: string;
}

export interface AccountsImportAccountResponse {
identityConflicts: Array<any>;
isImported: boolean;
}

export interface AccountsImportProfilePhotoParams {
url: string;
UID?: string;
Expand Down Expand Up @@ -738,6 +778,7 @@ export interface AccountsNotifyLoginParams {
cid?: string;
targetEnv?: TargetEnv;
regSource?: string;
sessionExpiration?: SessionExpiration;
}
export interface AccountsNotifyLoginParamsSiteUID extends AccountsNotifyLoginParams {
siteUID: string;
Expand Down
35 changes: 30 additions & 5 deletions lib/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export class Admin {
constructor(protected gigya: Gigya) {
}

/**
* This method creates a new site.
*
* @see http://developers.gigya.com/display/GD/admin.createSite+REST
*/
public createSite(params: BaseParamsSite & AdminCreateSiteParams) {
return this.gigya.request<AdminCreateSiteResponse>('admin.createSite', params);
}

/**
* This API retrieves a partner's previously-saved ACL and its description, or a built-in ACL.
*
Expand Down Expand Up @@ -55,22 +64,32 @@ export class Admin {
}

/**
* This API retrieves a partner's previously-saved ACL and its description, or a built-in ACL.
* This method sets the configuration for existing sites.
*
* @see http://developers.gigya.com/display/GD/admin.getACL+REST
* @see http://developers.gigya.com/display/GD/admin.setSiteConfig+REST
*/
public setSiteConfig(params: BaseParamsSite & AdminSetSiteConfigParams) {
return this.gigya.request('admin.setSiteConfig', params);
}
}

export interface AdminCreateSiteParams {
partnerID: number | string;
baseDomain: string;
description?: string;
dataCenter?: string;
}
export interface AdminCreateSiteResponse {
apiKey: string;
}

export interface AdminGetEffectiveACLTargetUserKeyParams {
partnerID: string;
partnerID: number | string;
targetUserKey: string;
apiKey?: string;
}
export interface AdminGetEffectiveACLGroupIDsParams {
partnerID: string;
partnerID: number | string;
groupIds: string;
apiKey?: string;
}
Expand Down Expand Up @@ -123,13 +142,19 @@ export interface AdminServices {
secretKey: string;
};
export interface AdminGetPartnerParams {
partnerID: string;
partnerID: number | string;
}
export interface AdminGetPartnerResponse {
partnerID: number;
isTrial: boolean;
isEnabled: boolean;
services: AdminServices;
defaultDataCenter: string;
customData: {
websiteURL: string;
companyName: string;
};
secretKey: string;
}

export interface AdminUserSite {
Expand Down
20 changes: 17 additions & 3 deletions lib/gigya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DS from './ds';
import GM from './gm';
import Fidm from './fidm';
import Reports from './reports';
import IDX from './idx';
import GigyaError from './gigya-error';
import GigyaResponse from './interfaces/gigya-response';
import ErrorCode from './interfaces/error-code';
Expand All @@ -22,6 +23,7 @@ export * from './ds';
export * from './gm';
export * from './fidm';
export * from './reports';
export * from './idx';
export * from './gigya-error';
export * from './interfaces/gigya-response';
export * from './interfaces/error-code';
Expand All @@ -45,6 +47,7 @@ export class Gigya {
public readonly gm: GM;
public readonly fidm: Fidm;
public readonly reports: Reports;
public readonly idx: IDX;

/**
* Initialize new instance of Gigya.
Expand Down Expand Up @@ -87,6 +90,7 @@ export class Gigya {
this.gm = new GM(this);
this.fidm = new Fidm(this);
this.reports = new Reports(this);
this.idx = new IDX(this);
}

/**
Expand All @@ -102,15 +106,18 @@ export class Gigya {
* Internal handler for requests.
*/
protected async _request<R>(endpoint: string, userParams: BaseParams & { [key: string]: any; }, retries = 0): Promise<GigyaResponse & R> {
// Data center can be passed as a "param" but shouldn't be sent to the server.
const dataCenter = userParams.dataCenter || this.dataCenter || 'us1';
delete userParams.dataCenter;

// Create final set of params with defaults, credentials, and params.
const requestParams: { [key: string]: string | null | number | boolean; } = _.assignIn(
_.mapValues(userParams, (value: any) => {
// Gigya wants arrays and objects stringified into JSON, eg Account profile and data objects.
if (value && (_.isObject(value) || _.isArray(value))) {
// Gigya wants arrays and objects stringified into JSON, eg Account profile and data objects.
return JSON.stringify(value);
} else if (value === null) {
// Null is meaningful in some contexts. Ensure it is passed.
return 'null';
} else {
return value;
Expand Down Expand Up @@ -145,15 +152,22 @@ export class Gigya {
// Fire request.
let response;
try {
response = await this.httpRequest<R>(endpoint, dataCenter, requestParams);
// Host is constructed from the endpoint namespace and data center.
// Endpoint "accounts.getAccountInfo" and data center "us1" become "accounts.us1.gigya.com".
const namespace = endpoint.substring(0, endpoint.indexOf('.'));
const host = `${namespace}.${dataCenter}.gigya.com`;

response = await this.httpRequest<R>(endpoint, host, requestParams);

// Non-zero error code means failure.
if (response.errorCode !== 0) {
throw this.createErrorFromResponse(response, endpoint, userParams);
}
} catch (e) {
// Check for error codes that signal need to retry.
if (e.errorCode === ErrorCode.GENERAL_SERVER_ERROR || e.errorCode === ErrorCode.SEARCH_TIMED_OUT || e.errorCode === ErrorCode.CONCURRENT_UPDATES_NOT_ALLOWED) {
if (e.errorCode === ErrorCode.GENERAL_SERVER_ERROR
|| e.errorCode === ErrorCode.SEARCH_TIMED_OUT
|| e.errorCode === ErrorCode.CONCURRENT_UPDATES_NOT_ALLOWED) {
retries++;
if (retries < Gigya.RETRY_LIMIT) {
if (Gigya.RETRY_DELAY) {
Expand Down
8 changes: 5 additions & 3 deletions lib/helpers/default-http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ function getCertificate(): string {
return certificate;
}

export const httpRequest: ProxyHttpRequest = <R>(endpoint: string, dataCenter: any, requestParams: any) => {
/**
* Make HTTP request to Gigya.
*/
export const httpRequest: ProxyHttpRequest = <R>(endpoint: string, host: string, requestParams: any) => {
return new Promise<GigyaResponse & R>((resolve, reject) => {
const namespace = endpoint.substring(0, endpoint.indexOf('.'));
const uri = `https://${namespace}.${dataCenter}.gigya.com/${endpoint}`;
const uri = `https://${host}/${endpoint}`;
request.post(uri, {
method: 'post',
form: requestParams,
Expand Down
113 changes: 113 additions & 0 deletions lib/idx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Gigya from './gigya';
import GigyaResponse from './interfaces/gigya-response';
import BaseParams from './interfaces/base-params';

export * from './interfaces/gigya-response';
export * from './interfaces/base-params';

export class IDX {
constructor(protected gigya: Gigya) {
}

/**
* The method creates a single dataflow and saves it in the system.
*
* @see http://developers.gigya.com/display/GD/idx.createDataflow+REST
*/
public createDataflow(params: BaseParams & any) {
return this.gigya.request<any>('idx.createDataflow', params);
}

/**
* The method retrieves a dataflow by ID.
*
* @see http://developers.gigya.com/display/GD/idx.getDataflow+REST
*/
public getDataflow(params: BaseParams & any) {
return this.gigya.request<any>('idx.getDataflow', params);
}

/**
* This method modifies an existing dataflow.
*
* @see http://developers.gigya.com/display/GD/idx.setDataflow+REST
*/
public setDataflow(params: BaseParams & any) {
return this.gigya.request<any>('idx.setDataflow', params);
}

/**
* The method deletes a Dataflow by ID.
*
* @see http://developers.gigya.com/display/GD/idx.deleteDataflow+REST
*/
public deleteDataflow(params: BaseParams & IDXDeleteDataflowParams) {
return this.gigya.request('idx.deleteDataflow', params);
}

/**
* The method schedules a dataflow to execute.
*
* @see http://developers.gigya.com/display/GD/idx.createScheduling+REST
*/
public createScheduling(params: BaseParams & any) {
return this.gigya.request<any>('idx.createScheduling', params);
}

/**
* The method retrieves a scheduling.
*
* @see http://developers.gigya.com/display/GD/idx.getScheduling+REST
*/
public getScheduling(params: BaseParams & any) {
return this.gigya.request<any>('idx.getScheduling', params);
}

/**
* The method modifies an existing scheduling.
*
* @see http://developers.gigya.com/display/GD/idx.setScheduling+REST
*/
public setScheduling(params: BaseParams & any) {
return this.gigya.request<any>('idx.setScheduling', params);
}

/**
* The method deletes a scheduling.
*
* @see http://developers.gigya.com/display/GD/idx.deleteScheduling+REST
*/
public deleteScheduling(params: BaseParams & IDXDeleteSchedulingParams) {
return this.gigya.request('idx.deleteScheduling', params);
}

/**
* Searches and retrieves data from the ETL service using an SQL-like query.
*
* @see http://developers.gigya.com/display/GD/idx.search+REST
*/
public search(params: BaseParams & IDXSearchParams) {
return this.gigya.request<any>('idx.search', params);
}
}

export interface IDXDeleteDataflowParams {
id: string;
}

export interface IDXDeleteSchedulingParams {
id: string;
}

export interface IDXSearchParams {
query: string;
openCursor?: boolean;
cursorId?: string;
}
export interface IDXSearchResponse {
resultCount: number;
totalCount: number;
result: Array<any>;
}

export default IDX;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": [
"gigya"
],
"version": "2.0.10",
"version": "2.0.11",
"author": {
"name": "Scott Hovestadt",
"email": "scott.hovestadt@gmail.com"
Expand Down

0 comments on commit 9abe6b2

Please sign in to comment.