Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"js/ts.implicitProjectConfig.checkJs": true,
"javascript.validate.enable": true,
"eslint.useESLintClass": true
"prettier.enable": true
}
57 changes: 7 additions & 50 deletions @types/auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,29 @@
/**
* @typedef {object} AuthObject - Auth object
* @property {number} [expiration] - expiration time of token
* @property {string} access_token - access token
* @property {string} client_id - client id of installed package
* @property {string} client_secret - client secret of installed package
* @property {string} auth_url - auth url for the SFMC instance
* @property {string} account_id - MID of the business unit you want to access
* @property {string[]} [scope] - array of scopes for the request
*/
/**
* Class which handles authentication logic
*/
export default class Auth {
/**
* Creates an instance of Auth.
*
* @param {AuthObject} authObject Auth Payload
* @param {object} options options for the SDK as a whole, for example collection of handler functions, or retry settings
* @param {import('./index.js').AuthObject} authObject Auth Payload
* @param {import('./index.js').SDKOptions} options options for the SDK as a whole, for example collection of handler functions, or retry settings
* eventHandlers
*/
constructor(authObject: AuthObject, options: object);
authObject: AuthObject;
options: any;
constructor(authObject: import("./index.js").AuthObject, options: import("./index.js").SDKOptions);
authObject: import("./index.js").AuthObject;
options: import("./index.js").SDKOptions;
/**
*
*
* @param {boolean} [forceRefresh] used to enforce a refresh of token
* @param {number} [remainingAttempts] number of retries in case of issues
* @returns {Promise.<any>} current session information
*/
getAccessToken(forceRefresh?: boolean, remainingAttempts?: number): Promise<any>;
getAccessToken(forceRefresh?: boolean): Promise<any>;
/**
* Helper to get back list of scopes supported by SDK
*
* @returns {string[]} array of potential scopes
*/
getSupportedScopes(): string[];
}
/**
* - Auth object
*/
export type AuthObject = {
/**
* - expiration time of token
*/
expiration?: number;
/**
* - access token
*/
access_token: string;
/**
* - client id of installed package
*/
client_id: string;
/**
* - client secret of installed package
*/
client_secret: string;
/**
* - auth url for the SFMC instance
*/
auth_url: string;
/**
* - MID of the business unit you want to access
*/
account_id: string;
/**
* - array of scopes for the request
*/
scope?: string[];
};
//# sourceMappingURL=auth.d.ts.map
2 changes: 1 addition & 1 deletion @types/auth.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 80 additions & 11 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,94 @@
/**
* @typedef {object} AuthObject - Auth object
* @property {number} [expiration] - expiration time of token
* @property {string} access_token - access token
* @property {string} client_id - client id of installed package
* @property {string} client_secret - client secret of installed package
* @property {string} auth_url - auth url for the SFMC instance
* @property {string} account_id - MID of the business unit you want to access
* @property {string} [rest_instance_url] - URL for rest requests returned from token request
* @property {string} [soap_instance_url] - URL for soap requests returned from token request
* @property {string[]} [scope] - array of scopes for the request
*/
/**
* @typedef {object} SDKOptions - options for the SDK as a whole, for example collection of handler functions, or retry settings
* @property {number} [requestAttempts] number of retries which should be done, defaulted to 1
* @property {boolean} [retryOnConnectionError] should request be retried in case of connection issues
* @property {object} [eventHandlers] collection of functions which are executed on certain events
*/
/**
* Class main handler for the SDK
*/
export default class SDK {
/**
* Creates an instance of SDK.
*
* @param {object} authObject Auth Object for making requests
* @param {object} [options] options for the SDK as a whole, for example collection of handler functions, or retry settings
* @param {number} [options.requestAttempts] number of retries which should be done, defaulted to 1
* @param {boolean} [options.retryOnConnectionError] should request be retried in case of connection issues
* @param {object} [options.eventHandlers] collection of functions which are executed on certain events
*/
constructor(authObject: object, options?: {
requestAttempts?: number;
retryOnConnectionError?: boolean;
eventHandlers?: object;
});
* @param {AuthObject} authObject Auth Object for making requests
* @param {SDKOptions} [options] options for the SDK as a whole, for example collection of handler functions, or retry settings
*/
constructor(authObject: AuthObject, options?: SDKOptions);
auth: Auth;
rest: Rest;
soap: Soap;
}
/**
* - Auth object
*/
export type AuthObject = {
/**
* - expiration time of token
*/
expiration?: number;
/**
* - access token
*/
access_token: string;
/**
* - client id of installed package
*/
client_id: string;
/**
* - client secret of installed package
*/
client_secret: string;
/**
* - auth url for the SFMC instance
*/
auth_url: string;
/**
* - MID of the business unit you want to access
*/
account_id: string;
/**
* - URL for rest requests returned from token request
*/
rest_instance_url?: string;
/**
* - URL for soap requests returned from token request
*/
soap_instance_url?: string;
/**
* - array of scopes for the request
*/
scope?: string[];
};
/**
* - options for the SDK as a whole, for example collection of handler functions, or retry settings
*/
export type SDKOptions = {
/**
* number of retries which should be done, defaulted to 1
*/
requestAttempts?: number;
/**
* should request be retried in case of connection issues
*/
retryOnConnectionError?: boolean;
/**
* collection of functions which are executed on certain events
*/
eventHandlers?: object;
};
import Auth from './auth.js';
import Rest from './rest.js';
import Soap from './soap.js';
Expand Down
2 changes: 1 addition & 1 deletion @types/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions @types/rest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export default class Rest {
* Constuctor of Rest object
*
* @function Object() { [native code] }
* @param {object} authObject Auth object used for initializing
* @param {object} options options for the SDK as a whole, for example collection of handler functions, or retry settings
* @param {Auth} authObject Auth object used for initializing
* @param {import('./index.js').SDKOptions} options options for the SDK as a whole, for example collection of handler functions, or retry settings
*/
constructor(authObject: object, options: object);
auth: any;
options: any;
constructor(authObject: Auth, options: import("./index.js").SDKOptions);
auth: Auth;
options: import("./index.js").SDKOptions;
transactionalApis: string[];
/**
* Method that makes the GET API request
Expand Down Expand Up @@ -91,10 +91,9 @@ export default class Rest {
* Method that makes the api request
*
* @param {object} requestOptions configuration for the request including body
* @param {number} remainingAttempts number of times this request should be reattempted in case of error
* @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten
* @returns {Promise.<any>} Results from the Rest request in Object format
*/
_apiRequest(requestOptions: object, remainingAttempts: number, headers?: object): Promise<any>;
_apiRequest(requestOptions: object): Promise<any>;
}
import Auth from './auth.js';
//# sourceMappingURL=rest.d.ts.map
2 changes: 1 addition & 1 deletion @types/rest.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions @types/soap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export default class Soap {
* Constuctor of Soap object
*
* @function Object() { [native code] }
* @param {object} auth Auth object used for initializing
* @param {object} options options for the SDK as a whole, for example collection of handler functions, or retry settings
* @param {Auth} auth Auth object used for initializing
* @param {import('./index.js').SDKOptions} options options for the SDK as a whole, for example collection of handler functions, or retry settings
*/
constructor(auth: object, options: object);
auth: any;
options: any;
constructor(auth: Auth, options: import("./index.js").SDKOptions);
auth: Auth;
options: import("./index.js").SDKOptions;
/**
* Method used to retrieve data via SOAP API
*
Expand Down Expand Up @@ -103,10 +103,10 @@ export default class Soap {
/**
* Method that makes the api request
*
* @param {object} options configuration for the request including body
* @param {number} remainingAttempts number of times this request should be reattempted in case of error
* @param {object} requestOptions configuration for the request including body
* @returns {Promise.<any>} Results from the SOAP request in Object format
*/
_apiRequest(options: object, remainingAttempts: number): Promise<any>;
_apiRequest(requestOptions: object): Promise<any>;
}
import Auth from './auth.js';
//# sourceMappingURL=soap.d.ts.map
2 changes: 1 addition & 1 deletion @types/soap.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 30 additions & 35 deletions @types/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export function isPayload(object: object): boolean;
* @returns {boolean} true if a connection error
*/
export function isConnectionError(code: string): boolean;
/**
* Method to check if the repsonse is JSON
*
* @param {object} apiResponse Fetch response before parsing body
* @returns {boolean} true if is simple Object
*/
export function isJSONResponse(apiResponse: object): boolean;
/**
* @typedef {object} EnhancedRestErrorHelper - Error object
* @property {object} response -
Expand All @@ -34,21 +41,31 @@ export function isConnectionError(code: string): boolean;
*/
export class RestError extends Error {
/**
*
* @param {EnhancedRestError} ex Error object
* @param {object} response api respone
* @param {object} responseBody rest body
*/
constructor(ex: EnhancedRestError);
constructor(response: object, responseBody: object);
code: any;
endpoint: string;
response: any;
json: any;
endpoint: any;
}
/**
* @typedef {object} EnhancedSoapErrorHelper - Error object
* @property {object} response -
* @property {string} code -
* @property {string} endpoint -
* @typedef {Error & EnhancedSoapErrorHelper } EnhancedSoapError - Error object
* CustomError type for handling Network based errors
* ie. errors not returning a 400-500 code
*
* @class NetworkError
* @augments {Error}
*/
export class NetworkError extends Error {
/**
* @param {Error} ex Error object
* @param {URL} url url of request, if available
*/
constructor(ex: Error, url: URL);
code: any;
endpoint: URL;
}
/**
* CustomError type for handling SOAP based errors
*
Expand All @@ -58,16 +75,15 @@ export class RestError extends Error {
export class SOAPError extends Error {
/**
*
* @param {EnhancedSoapError} ex Error object
* @param {object} response api respone
* @param {object} soapBody soap body
* @param {object} response api response
* @param {object} responseBody response body (parsed)
*/
constructor(ex: EnhancedSoapError, response: object, soapBody: object);
constructor(response: object, responseBody: object);
code: any;
response: any;
json: any;
endpoint: any;
}
export const axiosInstance: import("axios").AxiosInstance;
/**
* - Error object
*/
Expand All @@ -89,25 +105,4 @@ export type EnhancedRestErrorHelper = {
* - Error object
*/
export type EnhancedRestError = Error & EnhancedRestErrorHelper;
/**
* - Error object
*/
export type EnhancedSoapErrorHelper = {
/**
* -
*/
response: object;
/**
* -
*/
code: string;
/**
* -
*/
endpoint: string;
};
/**
* - Error object
*/
export type EnhancedSoapError = Error & EnhancedSoapErrorHelper;
//# sourceMappingURL=util.d.ts.map
2 changes: 1 addition & 1 deletion @types/util.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading