diff --git a/.husky/pre-commit b/.husky/pre-commit index 76a4c6c..365554b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,3 @@ # update typescript type declarations -npx tsc +npx tsc -p tsconfig.precommit.json git add @types diff --git a/@types/auth.d.ts b/@types/auth.d.ts index 14f87e4..b236d20 100644 --- a/@types/auth.d.ts +++ b/@types/auth.d.ts @@ -1,3 +1,13 @@ +/** + * @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 */ @@ -5,37 +15,20 @@ export default class Auth { /** * Creates an instance of Auth. * - * @param {object} authObject Auth Payload - * @param {string} authObject.client_id Client Id from SFMC config - * @param {string} authObject.client_secret Client Secret from SFMC config - * @param {number} authObject.account_id MID of Business Unit used for API Calls - * @param {string} authObject.auth_url Auth URL from SFMC config - * @param {string[]} [authObject.scope] Array of scopes used for requests + * @param {AuthObject} authObject Auth Payload * @param {object} options options for the SDK as a whole, for example collection of handler functions, or retry settings */ - constructor(authObject: { - client_id: string; - client_secret: string; - account_id: number; - auth_url: string; - scope?: string[]; - }, options: object); - authObject: { - client_id: string; - client_secret: string; - account_id: number; - auth_url: string; - scope?: string[]; - }; + constructor(authObject: AuthObject, options: object); + authObject: AuthObject; options: any; /** * * * @param {boolean} [forceRefresh] used to enforce a refresh of token * @param {number} [remainingAttempts] number of retries in case of issues - * @returns {Promise.} current session information + * @returns {Promise.} current session information */ - getAccessToken(forceRefresh?: boolean, remainingAttempts?: number): Promise; + getAccessToken(forceRefresh?: boolean, remainingAttempts?: number): Promise; /** * Helper to get back list of scopes supported by SDK * @@ -43,4 +36,37 @@ export default class Auth { */ 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 \ No newline at end of file diff --git a/@types/auth.d.ts.map b/@types/auth.d.ts.map index a21185f..f7544d8 100644 --- a/@types/auth.d.ts.map +++ b/@types/auth.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../lib/auth.js"],"names":[],"mappings":"AA0FA;;GAEG;AACH;IACI;;;;;;;;;;OAUG;IACH;QAP8B,SAAS,EAA5B,MAAM;QACa,aAAa,EAAhC,MAAM;QACa,UAAU,EAA7B,MAAM;QACa,QAAQ,EAA3B,MAAM;QACgB,KAAK,GAA3B,MAAM,EAAE;gBACR,MAAM,EA8ChB;IAFG;mBAjDO,MAAM;uBACN,MAAM;oBACN,MAAM;kBACN,MAAM;gBACN,MAAM,EAAE;MA6CmD;IAClE,aAAsB;IAE1B;;;;;;OAMG;IACH,8BAJW,OAAO,sBACP,MAAM,GACJ,QAAS,MAAM,CAAC,CA8B5B;IAED;;;;OAIG;IACH,sBAFa,MAAM,EAAE,CAIpB;CACJ"} \ No newline at end of file +{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../lib/auth.js"],"names":[],"mappings":"AAyFA;;;;;;;;;GASG;AAEH;;GAEG;AACH;IACI;;;;;OAKG;IACH,wBAHW,UAAU,WACV,MAAM,EA8ChB;IAFG,uBAAkE;IAClE,aAAsB;IAE1B;;;;;;OAMG;IACH,8BAJW,OAAO,sBACP,MAAM,GACJ,QAAS,GAAG,CAAC,CA8BzB;IAED;;;;OAIG;IACH,sBAFa,MAAM,EAAE,CAIpB;CACJ;;;;;;;;iBA7Ga,MAAM;;;;kBACN,MAAM;;;;eACN,MAAM;;;;mBACN,MAAM;;;;cACN,MAAM;;;;gBACN,MAAM;;;;YACN,MAAM,EAAE"} \ No newline at end of file diff --git a/@types/rest.d.ts b/@types/rest.d.ts index 3c810d0..de5db3f 100644 --- a/@types/rest.d.ts +++ b/@types/rest.d.ts @@ -17,9 +17,9 @@ export default class Rest { * Method that makes the GET API request * * @param {string} url of the resource to retrieve - * @returns {Promise.} API response + * @returns {Promise.} API response */ - get(url: string): Promise; + get(url: string): Promise; /** * helper for {@link this.getBulk} to determine if the url is a transactional message API * @@ -42,9 +42,9 @@ export default class Rest { * @param {string} url of the resource to retrieve * @param {number} [pageSize] of the response, defaults to 50 * @param {string} [iteratorField] attribute of the response to iterate over (only required if it's not 'items'|'definitions'|'entry') - * @returns {Promise.} API response combined items + * @returns {Promise.} API response combined items */ - getBulk(url: string, pageSize?: number, iteratorField?: string): Promise; + getBulk(url: string, pageSize?: number, iteratorField?: string): Promise; /** * Method that makes a GET API request for each URL (including rate limiting) * @@ -59,42 +59,42 @@ export default class Rest { * @param {string} url of the resource to create * @param {object} payload for the POST request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ - post(url: string, payload: object, headers?: object): Promise; + post(url: string, payload: object, headers?: object): Promise; /** * Method that makes the PUT api request * * @param {string} url of the resource to replace * @param {object} payload for the PUT request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ - put(url: string, payload: object, headers?: object): Promise; + put(url: string, payload: object, headers?: object): Promise; /** * Method that makes the PATCH api request * * @param {string} url of the resource to update * @param {object} payload for the PATCH request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ - patch(url: string, payload: object, headers?: object): Promise; + patch(url: string, payload: object, headers?: object): Promise; /** * Method that makes the DELETE api request * * @param {string} url of the resource to delete - * @returns {Promise.} API response + * @returns {Promise.} API response */ - delete(url: string): Promise; + delete(url: string): Promise; /** * 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.} Results from the Rest request in Object format + * @returns {Promise.} Results from the Rest request in Object format */ - _apiRequest(requestOptions: object, remainingAttempts: number, headers?: object): Promise; + _apiRequest(requestOptions: object, remainingAttempts: number, headers?: object): Promise; } //# sourceMappingURL=rest.d.ts.map \ No newline at end of file diff --git a/@types/rest.d.ts.map b/@types/rest.d.ts.map index aba909b..b937a13 100644 --- a/@types/rest.d.ts.map +++ b/@types/rest.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../lib/rest.js"],"names":[],"mappings":"AAUA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,wBAHW,MAAM,WACN,MAAM,EAUhB;IAPG,UAAsB;IACtB,aAAsB;IACtB,4BAIC;IAGL;;;;;OAKG;IACH,SAHW,MAAM,GACJ,QAAS,MAAM,CAAC,CAU5B;IACD;;;;;;OAMG;IACH,mCAEC;IACD;;;;;;OAMG;IACH,qBAEC;IACD;;;;;;;OAOG;IACH,aALW,MAAM,aACN,MAAM,kBACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAmF5B;IACD;;;;;;OAMG;IACH,wBAJW,MAAM,EAAE,oBACR,MAAM,GACJ,cAAe,CAmB3B;IACD;;;;;;;OAOG;IACH,UALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAU5B;IACD;;;;;;;OAOG;IACH,SALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAU5B;IACD;;;;;;;OAOG;IACH,WALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAU5B;IACD;;;;;OAKG;IACH,YAHW,MAAM,GACJ,QAAS,MAAM,CAAC,CAW5B;IACD;;;;;;;OAOG;IACH,4BALW,MAAM,qBACN,MAAM,YACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAiD5B;CACJ"} \ No newline at end of file +{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../lib/rest.js"],"names":[],"mappings":"AAUA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,wBAHW,MAAM,WACN,MAAM,EAUhB;IAPG,UAAsB;IACtB,aAAsB;IACtB,4BAIC;IAGL;;;;;OAKG;IACH,SAHW,MAAM,GACJ,QAAS,GAAG,CAAC,CAUzB;IACD;;;;;;OAMG;IACH,mCAEC;IACD;;;;;;OAMG;IACH,qBAEC;IACD;;;;;;;OAOG;IACH,aALW,MAAM,aACN,MAAM,kBACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAmFzB;IACD;;;;;;OAMG;IACH,wBAJW,MAAM,EAAE,oBACR,MAAM,GACJ,cAAe,CAmB3B;IACD;;;;;;;OAOG;IACH,UALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAUzB;IACD;;;;;;;OAOG;IACH,SALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAUzB;IACD;;;;;;;OAOG;IACH,WALW,MAAM,WACN,MAAM,YACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAUzB;IACD;;;;;OAKG;IACH,YAHW,MAAM,GACJ,QAAS,GAAG,CAAC,CAWzB;IACD;;;;;;;OAOG;IACH,4BALW,MAAM,qBACN,MAAM,YACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAiDzB;CACJ"} \ No newline at end of file diff --git a/@types/soap.d.ts b/@types/soap.d.ts index 3d05dd1..d7b01ad 100644 --- a/@types/soap.d.ts +++ b/@types/soap.d.ts @@ -18,45 +18,45 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {string[]} propertiesList - Properties which should be retrieved * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - retrieve(type: string, propertiesList: string[], requestParameters?: object): Promise; + retrieve(type: string, propertiesList: string[], requestParameters?: object): Promise; /** * Method used to retrieve all data via SOAP API * * @param {string} type - SOAP Object type * @param {string[]} propertiesList - Properties which should be retrieved * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - retrieveBulk(type: string, propertiesList: string[], requestParameters?: object): Promise; + retrieveBulk(type: string, propertiesList: string[], requestParameters?: object): Promise; /** * Method used to create data via SOAP API * * @param {string} type - SOAP Object type * @param {object} properties - Properties with values which should be created * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - create(type: string, properties: object, requestParameters?: object): Promise; + create(type: string, properties: object, requestParameters?: object): Promise; /** * Method used to update data via SOAP API * * @param {string} type - SOAP Object type * @param {object} properties - Properties with values which should be updated * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - update(type: string, properties: object, requestParameters?: object): Promise; + update(type: string, properties: object, requestParameters?: object): Promise; /** * Method used to delete data via SOAP API * * @param {string} type - SOAP Object type * @param {object} properties - Properties with values * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - delete(type: string, properties: object, requestParameters?: object): Promise; + delete(type: string, properties: object, requestParameters?: object): Promise; /** * Method used to schedule data via SOAP API * @@ -65,48 +65,48 @@ export default class Soap { * @param {Array | object} interactions - Object or array of interactions * @param {string} action - type of schedule * @param {object} [options] - additional options for the request - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - schedule(type: string, schedule: object, interactions: any[] | object, action: string, options?: object): Promise; + schedule(type: string, schedule: object, interactions: any[] | object, action: string, options?: object): Promise; /** * Method used to describe metadata via SOAP API * * @param {string} type - SOAP Object type - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - describe(type: string): Promise; + describe(type: string): Promise; /** * Method used to execute data via SOAP API * * @param {string} type - SOAP Object type * @param {object} properties - Properties with values - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - execute(type: string, properties: object): Promise; + execute(type: string, properties: object): Promise; /** * Method used to execute data via SOAP API * * @param {string} type - SOAP Object type * @param {string} action - type of action, for example 'Start' * @param {object} payload - relevant payload to perform, for example query Definition - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - perform(type: string, action: string, payload: object): Promise; + perform(type: string, action: string, payload: object): Promise; /** * Method used to configure data via SOAP API * * @param {string} type - SOAP Object type * @param {object[]} configArray - Properties which should be updated - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ - configure(type: string, configArray: object[]): Promise; + configure(type: string, configArray: object[]): Promise; /** * 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 - * @returns {Promise.} Results from the SOAP request in Object format + * @returns {Promise.} Results from the SOAP request in Object format */ - _apiRequest(options: object, remainingAttempts: number): Promise; + _apiRequest(options: object, remainingAttempts: number): Promise; } //# sourceMappingURL=soap.d.ts.map \ No newline at end of file diff --git a/@types/soap.d.ts.map b/@types/soap.d.ts.map index 077c34e..0f20b49 100644 --- a/@types/soap.d.ts.map +++ b/@types/soap.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"soap.d.ts","sourceRoot":"","sources":["../lib/soap.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,kBAHW,MAAM,WACN,MAAM,EAKhB;IAFG,UAAgB;IAChB,aAAsB;IAG1B;;;;;;;OAOG;IACH,eALW,MAAM,kBACN,MAAM,EAAE,sBACR,MAAM,GACJ,QAAS,MAAM,CAAC,CAsD5B;IACD;;;;;;;OAOG;IACH,mBALW,MAAM,kBACN,MAAM,EAAE,sBACR,MAAM,GACJ,QAAS,MAAM,CAAC,CAwB5B;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,MAAM,CAAC,CA0B5B;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,MAAM,CAAC,CA2B5B;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,MAAM,CAAC,CA0B5B;IACD;;;;;;;;;OASG;IACH,eAPW,MAAM,YACN,MAAM,gBACN,QAAQ,MAAM,UACd,MAAM,YACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAiC5B;IACD;;;;;OAKG;IACH,eAHW,MAAM,GACJ,QAAS,MAAM,CAAC,CAuB5B;IACD;;;;;;OAMG;IACH,cAJW,MAAM,cACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAsB5B;IACD;;;;;;;OAOG;IACH,cALW,MAAM,UACN,MAAM,WACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAiC5B;IACD;;;;;;OAMG;IACH,gBAJW,MAAM,eACN,MAAM,EAAE,GACN,QAAS,MAAM,CAAC,CA4B5B;IAED;;;;;;OAMG;IACH,qBAJW,MAAM,qBACN,MAAM,GACJ,QAAS,MAAM,CAAC,CAsE5B;CACJ"} \ No newline at end of file +{"version":3,"file":"soap.d.ts","sourceRoot":"","sources":["../lib/soap.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,kBAHW,MAAM,WACN,MAAM,EAKhB;IAFG,UAAgB;IAChB,aAAsB;IAG1B;;;;;;;OAOG;IACH,eALW,MAAM,kBACN,MAAM,EAAE,sBACR,MAAM,GACJ,QAAS,GAAG,CAAC,CAsDzB;IACD;;;;;;;OAOG;IACH,mBALW,MAAM,kBACN,MAAM,EAAE,sBACR,MAAM,GACJ,QAAS,GAAG,CAAC,CAwBzB;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,GAAG,CAAC,CA0BzB;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,GAAG,CAAC,CA2BzB;IACD;;;;;;;OAOG;IACH,aALW,MAAM,cACN,MAAM,sBACN,MAAM,GACJ,QAAS,GAAG,CAAC,CA0BzB;IACD;;;;;;;;;OASG;IACH,eAPW,MAAM,YACN,MAAM,gBACN,QAAQ,MAAM,UACd,MAAM,YACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAiCzB;IACD;;;;;OAKG;IACH,eAHW,MAAM,GACJ,QAAS,GAAG,CAAC,CAuBzB;IACD;;;;;;OAMG;IACH,cAJW,MAAM,cACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAsBzB;IACD;;;;;;;OAOG;IACH,cALW,MAAM,UACN,MAAM,WACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAiCzB;IACD;;;;;;OAMG;IACH,gBAJW,MAAM,eACN,MAAM,EAAE,GACN,QAAS,GAAG,CAAC,CA4BzB;IAED;;;;;;OAMG;IACH,qBAJW,MAAM,qBACN,MAAM,GACJ,QAAS,GAAG,CAAC,CAsEzB;CACJ"} \ No newline at end of file diff --git a/@types/util.d.ts b/@types/util.d.ts index 22416d0..476cd8b 100644 --- a/@types/util.d.ts +++ b/@types/util.d.ts @@ -20,11 +20,11 @@ export function isPayload(object: object): boolean; */ export function isConnectionError(code: string): boolean; /** - * @typedef {object} EnhancedRestError - Error object - * @augments {Error} + * @typedef {object} EnhancedRestErrorHelper - Error object * @property {object} response - * @property {string} code - * @property {string} endpoint - + * @typedef {Error & EnhancedRestErrorHelper} EnhancedRestError - Error object */ /** * CustomError type for handling REST (including Auth) based errors @@ -39,15 +39,15 @@ export class RestError extends Error { */ constructor(ex: EnhancedRestError); code: any; - endpoint: any; + endpoint: string; response: any; } /** - * @typedef {object} EnhancedSoapError - Error object - * @augments {Error} + * @typedef {object} EnhancedSoapErrorHelper - Error object * @property {object} response - * @property {string} code - * @property {string} endpoint - + * @typedef {Error & EnhancedSoapErrorHelper } EnhancedSoapError - Error object */ /** * CustomError type for handling SOAP based errors @@ -71,9 +71,43 @@ export const axiosInstance: import("axios").AxiosInstance; /** * - Error object */ -export type EnhancedRestError = object; +export type EnhancedRestErrorHelper = { + /** + * - + */ + response: object; + /** + * - + */ + code: string; + /** + * - + */ + endpoint: string; +}; +/** + * - Error object + */ +export type EnhancedRestError = Error & EnhancedRestErrorHelper; +/** + * - Error object + */ +export type EnhancedSoapErrorHelper = { + /** + * - + */ + response: object; + /** + * - + */ + code: string; + /** + * - + */ + endpoint: string; +}; /** * - Error object */ -export type EnhancedSoapError = object; +export type EnhancedSoapError = Error & EnhancedSoapErrorHelper; //# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/@types/util.d.ts.map b/@types/util.d.ts.map index 4dd41d8..d2b1ceb 100644 --- a/@types/util.d.ts.map +++ b/@types/util.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../lib/util.js"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,iCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;GAKG;AACH,kCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;GAKG;AACH,wCAHW,MAAM,GACJ,OAAO,CAOnB;AAED;;;;;;GAMG;AACH;;;;;GAKG;AACH;IACI;;;OAGG;IACH,gBAFW,iBAAiB,EAwB3B;IAlBO,UAAiD;IAWjD,cAA2B;IAE/B,cAA2B;CAMlC;AACD;;;;;;GAMG;AACH;;;;;GAKG;AACH;IACI;;;;;OAKG;IACH,gBAJW,iBAAiB,YACjB,MAAM,YACN,MAAM,EAwChB;IAlCO,UAAkC;IA4BtC,cAAwB;IACxB,UAAoB;CAM3B;AAED,0DAA4C;;;;gCAtG/B,MAAM;;;;gCA0CN,MAAM"} \ No newline at end of file +{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../lib/util.js"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,iCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;GAKG;AACH,kCAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;GAKG;AACH,wCAHW,MAAM,GACJ,OAAO,CAOnB;AAED;;;;;;GAMG;AACH;;;;;GAKG;AACH;IACI;;;OAGG;IACH,gBAFW,iBAAiB,EAwB3B;IAlBO,UAAiD;IAWjD,iBAA2B;IAE/B,cAA2B;CAMlC;AACD;;;;;;GAMG;AACH;;;;;GAKG;AACH;IACI;;;;;OAKG;IACH,gBAJW,iBAAiB,YACjB,MAAM,YACN,MAAM,EAwChB;IAlCO,UAAkC;IA4BtC,cAAwB;IACxB,UAAoB;CAM3B;AAED,0DAA4C;;;;;;;;cArG9B,MAAM;;;;UACN,MAAM;;;;cACN,MAAM;;;;;gCACP,KAAK,GAAG,uBAAuB;;;;;;;;cAuC9B,MAAM;;;;UACN,MAAM;;;;cACN,MAAM;;;;;gCACP,KAAK,GAAG,uBAAuB"} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index 1e5d8a2..213dca5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -45,6 +45,7 @@ export default [ 'jsdoc/require-param-type': 'error', 'jsdoc/tag-lines': ['warn', 'any', { startLines: 1 }], 'jsdoc/no-undefined-types': 'error', + 'jsdoc/valid-types': 'off', }, settings: { diff --git a/lib/auth.js b/lib/auth.js index c7ddb5a..734ef6a 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -87,6 +87,16 @@ const AVAIALABLE_SCOPES = [ 'workflows_read', 'workflows_write', ]; +/** + * @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 @@ -95,12 +105,7 @@ export default class Auth { /** * Creates an instance of Auth. * - * @param {object} authObject Auth Payload - * @param {string} authObject.client_id Client Id from SFMC config - * @param {string} authObject.client_secret Client Secret from SFMC config - * @param {number} authObject.account_id MID of Business Unit used for API Calls - * @param {string} authObject.auth_url Auth URL from SFMC config - * @param {string[]} [authObject.scope] Array of scopes used for requests + * @param {AuthObject} authObject Auth Payload * @param {object} options options for the SDK as a whole, for example collection of handler functions, or retry settings */ constructor(authObject, options) { @@ -153,7 +158,7 @@ export default class Auth { * * @param {boolean} [forceRefresh] used to enforce a refresh of token * @param {number} [remainingAttempts] number of retries in case of issues - * @returns {Promise.} current session information + * @returns {Promise.} current session information */ async getAccessToken(forceRefresh, remainingAttempts) { if (remainingAttempts === undefined) { @@ -196,7 +201,7 @@ export default class Auth { } /** - * @param {object} authObject Auth object + * @param {AuthObject} authObject Auth object * @returns {boolean} true if token is expired */ function _isExpired(authObject) { @@ -212,8 +217,8 @@ function _isExpired(authObject) { return expired; } /** - * @param {object} authObject Auth Object for api calls - * @returns {Promise.} updated Auth Object + * @param {AuthObject} authObject Auth Object for api calls + * @returns {Promise.} updated Auth Object */ async function _requestToken(authObject) { // TODO retry logic diff --git a/lib/rest.js b/lib/rest.js index 1e7e364..d813016 100644 --- a/lib/rest.js +++ b/lib/rest.js @@ -33,7 +33,7 @@ export default class Rest { * Method that makes the GET API request * * @param {string} url of the resource to retrieve - * @returns {Promise.} API response + * @returns {Promise.} API response */ get(url) { return this._apiRequest( @@ -70,7 +70,7 @@ export default class Rest { * @param {string} url of the resource to retrieve * @param {number} [pageSize] of the response, defaults to 50 * @param {string} [iteratorField] attribute of the response to iterate over (only required if it's not 'items'|'definitions'|'entry') - * @returns {Promise.} API response combined items + * @returns {Promise.} API response combined items */ async getBulk(url, pageSize = 50, iteratorField) { let page = 1; @@ -185,7 +185,7 @@ export default class Rest { * @param {string} url of the resource to create * @param {object} payload for the POST request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ post(url, payload, headers) { const requestOptions = { @@ -202,7 +202,7 @@ export default class Rest { * @param {string} url of the resource to replace * @param {object} payload for the PUT request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ put(url, payload, headers) { const requestOptions = { @@ -219,7 +219,7 @@ export default class Rest { * @param {string} url of the resource to update * @param {object} payload for the PATCH request body * @param {object} [headers] optional headers to include in the request; note that Authorization-header is always overwritten - * @returns {Promise.} API response + * @returns {Promise.} API response */ patch(url, payload, headers) { const requestOptions = { @@ -234,7 +234,7 @@ export default class Rest { * Method that makes the DELETE api request * * @param {string} url of the resource to delete - * @returns {Promise.} API response + * @returns {Promise.} API response */ delete(url) { return this._apiRequest( @@ -252,7 +252,7 @@ export default class Rest { * @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.} Results from the Rest request in Object format + * @returns {Promise.} Results from the Rest request in Object format */ async _apiRequest(requestOptions, remainingAttempts, headers = {}) { if (!isObject(requestOptions)) { diff --git a/lib/soap.js b/lib/soap.js index d49e692..4a61c2d 100644 --- a/lib/soap.js +++ b/lib/soap.js @@ -24,7 +24,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {string[]} propertiesList - Properties which should be retrieved * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ retrieve(type, propertiesList, requestParameters) { if (!type) { @@ -85,7 +85,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {string[]} propertiesList - Properties which should be retrieved * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ async retrieveBulk(type, propertiesList, requestParameters) { let status; @@ -116,7 +116,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {object} properties - Properties with values which should be created * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ create(type, properties, requestParameters) { if (!type) { @@ -149,7 +149,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {object} properties - Properties with values which should be updated * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ update(type, properties, requestParameters) { if (!type) { @@ -183,7 +183,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {object} properties - Properties with values * @param {object} [requestParameters] - additional RetrieveRequest parameters, for example filter or options - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ delete(type, properties, requestParameters) { if (!type) { @@ -218,7 +218,7 @@ export default class Soap { * @param {Array | object} interactions - Object or array of interactions * @param {string} action - type of schedule * @param {object} [options] - additional options for the request - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ schedule(type, schedule, interactions, action, options) { const body = { @@ -256,7 +256,7 @@ export default class Soap { * Method used to describe metadata via SOAP API * * @param {string} type - SOAP Object type - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ describe(type) { if (!type) { @@ -285,7 +285,7 @@ export default class Soap { * * @param {string} type - SOAP Object type * @param {object} properties - Properties with values - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ execute(type, properties) { if (!type) { @@ -314,7 +314,7 @@ export default class Soap { * @param {string} type - SOAP Object type * @param {string} action - type of action, for example 'Start' * @param {object} payload - relevant payload to perform, for example query Definition - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ perform(type, action, payload) { if (!type) { @@ -353,7 +353,7 @@ export default class Soap { * * @param {string} type - SOAP Object type * @param {object[]} configArray - Properties which should be updated - * @returns {Promise.} SOAP object converted from XML + * @returns {Promise.} SOAP object converted from XML */ configure(type, configArray) { if (!type) { @@ -388,7 +388,7 @@ export default class Soap { * * @param {object} options configuration for the request including body * @param {number} remainingAttempts number of times this request should be reattempted in case of error - * @returns {Promise.} Results from the SOAP request in Object format + * @returns {Promise.} Results from the SOAP request in Object format */ async _apiRequest(options, remainingAttempts) { if (!isObject(options)) { @@ -523,7 +523,7 @@ function _parseFilter(filter) { * * @param {object} response payload including whole SOAP response * @param {string} key key of the expected response body - * @returns {Promise.} Result of request in Object format + * @returns {Promise.} Result of request in Object format */ async function _parseResponse(response, key) { const xmlToJson = new XMLParser({ ignoreAttributes: true }); diff --git a/lib/util.js b/lib/util.js index 2c735e5..b0e4039 100644 --- a/lib/util.js +++ b/lib/util.js @@ -33,11 +33,11 @@ export function isConnectionError(code) { } /** - * @typedef {object} EnhancedRestError - Error object - * @augments {Error} + * @typedef {object} EnhancedRestErrorHelper - Error object * @property {object} response - * @property {string} code - * @property {string} endpoint - + * @typedef {Error & EnhancedRestErrorHelper} EnhancedRestError - Error object */ /** * CustomError type for handling REST (including Auth) based errors @@ -75,11 +75,11 @@ export class RestError extends Error { } } /** - * @typedef {object} EnhancedSoapError - Error object - * @augments {Error} + * @typedef {object} EnhancedSoapErrorHelper - Error object * @property {object} response - * @property {string} code - * @property {string} endpoint - + * @typedef {Error & EnhancedSoapErrorHelper } EnhancedSoapError - Error object */ /** * CustomError type for handling SOAP based errors diff --git a/package-lock.json b/package-lock.json index 21d558c..f9dcf7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sfmc-sdk", - "version": "2.0.1", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "sfmc-sdk", - "version": "2.0.1", + "version": "2.1.1", "license": "BSD-3-Clause", "dependencies": { "axios": "^1.7.2", @@ -14,6 +14,8 @@ "p-limit": "5.0.0" }, "devDependencies": { + "@eslint/js": "9.6.0", + "@types/mocha": "10.0.7", "@types/node": "20.14.9", "assert": "2.1.0", "axios-mock-adapter": "1.22.0", @@ -609,6 +611,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/mocha": { + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", + "dev": true + }, "node_modules/@types/node": { "version": "20.14.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", @@ -5439,6 +5447,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/mocha": { + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", + "dev": true + }, "@types/node": { "version": "20.14.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", diff --git a/package.json b/package.json index cf1e7ea..bc63535 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sfmc-sdk", - "version": "2.1.0", + "version": "2.1.1", "description": "Libarary to simplify SFMC requests with updated dependencies and less overhead", "main": "./lib/index.js", "exports": { @@ -17,8 +17,8 @@ "test": "c8 --reporter=text mocha", "lint": "eslint ./lib ./test", "lint:fix": "eslint ./lib ./test --fix", - "prepare": "husky || true", - "declarations": "tsc" + "lint-ts": "tsc -p tsconfig.precommit.json", + "prepare": "husky || true" }, "repository": { "type": "git", @@ -43,6 +43,8 @@ "sdk" ], "devDependencies": { + "@eslint/js": "9.6.0", + "@types/mocha": "10.0.7", "@types/node": "20.14.9", "assert": "2.1.0", "axios-mock-adapter": "1.22.0", diff --git a/tsconfig.json b/tsconfig.json index 427a15e..ba95dc4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,17 @@ { // Change this to match your project - "include": ["lib/**/*"], + "include": ["lib/**/*.js"], "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "target": "es2022", + "checkJs": true, + "skipLibCheck": true, // Tells TypeScript to read JS files, as // normally they are ignored as source files "allowJs": true, - // Generate d.ts files - "declaration": true, // This compiler run should // only output d.ts files - "emitDeclarationOnly": true, - // Types should go into this directory. - // Removing this would place the .d.ts files - // next to the .js files - "outDir": "@types", - // go to js file when using IDE functions like - // "Go to Definition" in VSCode - "declarationMap": true + "noEmit": true } } diff --git a/tsconfig.npmScripts.json b/tsconfig.npmScripts.json new file mode 100644 index 0000000..ccf8d27 --- /dev/null +++ b/tsconfig.npmScripts.json @@ -0,0 +1,12 @@ +{ + "include": ["lib/**/*.js"], + "exclude": ["node_modules"], + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "target": "es2022", + "checkJs": true, + "skipLibCheck": true, + "noEmit": true + } +} diff --git a/tsconfig.precommit.json b/tsconfig.precommit.json new file mode 100644 index 0000000..9179241 --- /dev/null +++ b/tsconfig.precommit.json @@ -0,0 +1,15 @@ +{ + "include": ["lib/**/*.js"], + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "target": "es2022", + "checkJs": true, + "skipLibCheck": true, + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "@types", + "declarationMap": true + } +}