fsm-sdk
Version:
Node.JS sdk to interface with SAP Field Service Management APIs.
265 lines (264 loc) • 9.7 kB
TypeScript
import { DTOName, DTOModels } from './core/dto-name.model';
import { ClientConfig } from './core/client-config.model';
import { OauthTokenResponse } from './core/oauth-token-response.model';
import { ClientResponse } from './core/client-response.model';
import { BatchAction } from './core/batch-action.model';
import { BatchResponseJson } from './core/batch-response';
export declare class CoreAPIClient {
private _client;
private _config_default;
/**
* The CoreAPIClient
*
* ```typescript
*{
* // [mandatory] your client configuration
* clientIdentifier: '<your-clientIdentifier>',
* clientSecret: '<your-clientSecret>',
* clientVersion: '<your-clientVersion>',
*
* // [optional] oauth grant type, default=password
* authGrantType: 'password' | 'client_credentials' | undefined
*
* // [optional] | [mandatory] if oauth grant type password
* authAccountName: '<your-authAccountName>',
*
* // [optional] | [mandatory] if oauth grant type password
* authUserName: '<your-authUserName>',
*
* // [optional] | [mandatory] if oauth grant type password
* authPassword: '<your-authPassword>',
*
* // [optional] or default=FIRST
* authCompany: '<your-authCompany>',
*
* // [optional] provide verbose logs
* debug: false,
*
* // [optional] enable using custom oauth endpoints
* oauthEndpoint: 'https://ds.coresuite.com/api/oauth2/v1',
*
* // [optional] client will cache token (helpful for writing integration tests)
* tokenCacheFilePath: './.myToken.json'
*
*}
* ```
* @param _config ClientConfig
* @returns CoreAPIClient
*/
constructor(config: ClientConfig);
/**
* Creates UUID
* @returns a uuid that can be used as an FSM object id
*/
static createUUID(): string;
/**
* Here, you can input and execute the CoreSQL query.
*
* related api docs:
* https://help.sap.com/viewer/fsm_query_api/Cloud/en-US/query-api-intro.html
*
* @param coreSQL valid CoreSQL
* @param dtoNames DTOName[]
* @returns Promise<{ data: DTO[] }>
*/
query<T extends {
[projection: string]: DTOModels;
}>(coreSQL: string, dtoNames: DTOName[]): Promise<{
data: T[];
}>;
/**
* Retrieving Lists of Objects by Id
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param resourceId uuid as string
* @returns Promise<ClientResponse<DTO>>
*/
getById<T extends DTOModels>(resourceName: DTOName, resourceId: string): Promise<ClientResponse<T>>;
/**
* Retrieving Lists of Objects by ExternalId
*
* Note: [useExternalIds=true] option will be used
* referenced resources will not be a uid-string or null but of object or null
* containing id and externalId if present
* ```typescript
* [referenced-resource] : { id: string, externalId? : string } | null
* ```
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param externalId externalId as string
* @returns Promise<ClientResponse<DTO>>
*/
getByExternalId<T extends DTOModels>(resourceName: DTOName, externalId: string): Promise<ClientResponse<T>>;
/**
* Deletes Existing Object by Id
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param resource { id: string, lastChanged: number }
* @returns
*/
deleteById<T extends Partial<DTOModels> & {
id: string;
lastChanged: number;
}>(resourceName: DTOName, resource: T): Promise<undefined>;
/**
* Deletes Existing Object by ExternalId
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param resource { id: string, lastChanged: number }
* @returns
*/
deleteByExternalId<T extends Partial<DTOModels> & {
externalId: string;
lastChanged: number;
}>(resourceName: DTOName, resource: T): Promise<undefined>;
/**
* Creating Objects by Id
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param resource should contain in the body the ENTIRE updated resource
* @returns Promise<ClientResponse<DTO>>
*/
post<T extends DTOModels>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Creating Objects by ExternalId
*
* Note: [useExternalIds=true] option will be used
* referenced resources will not be a uid-string or null but of object or null
* containing id and externalId if present
* ```typescript
* [referenced-resource] : { id: string, externalId? : string } | null
* ```
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName DTOName
* @param resource should contain in the body the ENTIRE updated resource
* @returns Promise<ClientResponse<DTO>>
*/
postByExternalId<T extends DTOModels>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Updating Existing Objects by Id
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName resourceName
* @param resource should contain in the body the ENTIRE updated resource
* @returns Promise<ClientResponse<DTO>>
*/
put<T extends DTOModels>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Updating Existing Objects by ExternalId
*
* Note: [useExternalIds=true] option will be used
* referenced resources will not be a uid-string or null but of object or null
* containing id and externalId if present
* ```typescript
* [referenced-resource] : { id: string, externalId? : string } | null
* ```
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName resourceName
* @param resource should contain in the resource the ENTIRE updated resource
* @returns Promise<ClientResponse<DTO>>
*/
putByExternalId<T extends DTOModels & {
externalId: string;
}>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Updating Existing Objects by Id
* should contain [id] in the body the entire updated resource
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName resourceName
* @param resource should contain in the body the [id] & [FIELDS THAT YOU WANT TO UPDATE]
* @returns Promise<ClientResponse<DTO>>
*/
patch<T extends DTOModels>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Updating Existing Objects by ExternalId
* should contain [ExternalId] in the resource the entire updated resource
*
* Note: [useExternalIds=true] option will be used
* referenced resources will not be a uid-string or null but of object or null
* containing id and externalId if present
* ```typescript
* [referenced-resource] : { id: string, externalId? : string } | null
* ```
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US
*
* @param resourceName resourceName
* @param resource should contain in the resource the [externalId] & [FIELDS THAT YOU WANT TO UPDATE]
* @returns Promise<ClientResponse<DTO>>
*/
patchByExternalId<T extends DTOModels & {
externalId: string;
}>(resourceName: DTOName, resource: T): Promise<ClientResponse<T>>;
/**
* Batch request with transational support
* requests will be executed in oder of the actions array.
*
* Example:
* ```typescript
* const actions = [
* new CreateAction('ServiceCall', { ... }),
* new UpdateAction('ServiceCall', { id, lastChanged ... }),
* new DeleteAction('ServiceCall', { id, lastChanged ... })
* ];
* await client.batch(actions)
* ```
*
* related api docs:
* https://help.sap.com/viewer/fsm_data_api/Cloud/en-US/batch-api-intro.html
*
* @param actions BatchAction | CreateAction | UpdateAction | DeleteAction
* @returns Promise<BatchResponseJson<T>[]>
*/
batch<T extends DTOModels>(actions: BatchAction[]): Promise<BatchResponseJson<T>[]>;
/**
* Will use provided ClientConfig and perform a Login.
*
* Note: that it is **not required** to explicitly call client.login()
* before each client action. The CoreAPIClient will login and **keep a internally token copy**
* and will use this **up to its expiration** and **will auto refresh** when needed.
* Calling client.login() will NOT result in mutiple http calls to the oauth api.
*
* related api docs:
* https://help.sap.com/viewer/fsm_access_api/Cloud/en-US/oauth-intro.html
*
* @returns Promise<OauthTokenResponse>
*/
login(): Promise<OauthTokenResponse>;
/**
* get OauthTokenResponse
* @returns Readonly<OauthTokenResponse> | undefined
*/
getToken(): Readonly<OauthTokenResponse> | undefined;
/**
* set OauthTokenResponse
* @param token OauthTokenResponse
* @returns CoreAPIClient
*/
setToken(token: OauthTokenResponse): CoreAPIClient;
}