From 860874cec46886ce7ff08a03c678a2209a41b562 Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Sat, 14 Oct 2023 21:06:24 +0300 Subject: [PATCH] avatar api updates --- examples/package-lock.json | 25 ++++++++++++------- examples/package.json | 2 +- src/version2/avatars.ts | 33 +++++++++++++++++++------- src/version2/parameters/storeAvatar.ts | 1 + src/version3/avatars.ts | 33 +++++++++++++++++++------- src/version3/parameters/storeAvatar.ts | 1 + 6 files changed, 70 insertions(+), 25 deletions(-) diff --git a/examples/package-lock.json b/examples/package-lock.json index 6adf38abaa..5acff2fb39 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -12,7 +12,7 @@ "jira.js": "latest" }, "devDependencies": { - "@types/node": "^20.8.2", + "@types/node": "^20.8.6", "ts-node": "^10.9.1", "typescript": "^5.2.2" } @@ -79,10 +79,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", - "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", - "dev": true + "version": "20.8.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.6.tgz", + "integrity": "sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.25.1" + } }, "node_modules/acorn": { "version": "8.10.0", @@ -205,9 +208,9 @@ } }, "node_modules/jira.js": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/jira.js/-/jira.js-2.20.0.tgz", - "integrity": "sha512-CjfmK7TJVf/ZKN+dXQPZzNxvrWsTzBrQ6ALAVtEV2+sJGANkkA3OWPmAgg4Pwq9Xi88PhKz1fNXemNRm8lGH9w==", + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/jira.js/-/jira.js-2.20.1.tgz", + "integrity": "sha512-ZFlFAVTEaw86OemQ8BVyVSV0YDZqMI6WVc08Th5GgqVEODW4gmhXLOxqSmCasRJMMVAtI1LrFlFFTf9GnFaUhg==", "dependencies": { "atlassian-jwt": "^2.0.2", "axios": "^1.5.1", @@ -325,6 +328,12 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "dev": true + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/examples/package.json b/examples/package.json index 77c882adb7..01fa1c0f29 100644 --- a/examples/package.json +++ b/examples/package.json @@ -12,7 +12,7 @@ }, "license": "MIT", "devDependencies": { - "@types/node": "^20.8.2", + "@types/node": "^20.8.6", "ts-node": "^10.9.1", "typescript": "^5.2.2" }, diff --git a/src/version2/avatars.ts b/src/version2/avatars.ts index d705d7a35f..aa60e006f7 100644 --- a/src/version2/avatars.ts +++ b/src/version2/avatars.ts @@ -137,6 +137,7 @@ export class Avatars { y: parameters.y, size: parameters.size, }, + data: parameters.avatar, }; return this.client.sendRequest(config, callback); @@ -172,7 +173,7 @@ export class Avatars { * * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None. */ - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback: Callback, ): Promise; @@ -183,11 +184,11 @@ export class Avatars { * * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None. */ - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback?: never, ): Promise; - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback?: Callback, ): Promise { @@ -196,13 +197,21 @@ export class Avatars { const config: RequestConfig = { url: `/rest/api/2/universal_avatar/view/type/${type}`, method: 'GET', + responseType: 'arraybuffer', params: { size: typeof parameters !== 'string' && parameters.size, format: typeof parameters !== 'string' && parameters.format, }, }; - return this.client.sendRequest(config, callback); + const { + data: avatar, + headers: { 'content-type': contentTypeWithEncoding }, + } = await this.client.sendRequestFullResponse(config); + + const contentType = contentTypeWithEncoding.split(';')[0].trim(); + + return this.client.handleSuccessResponse({ contentType, avatar }, callback); } /** @@ -276,7 +285,7 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByOwner( + async getAvatarImageByOwner( parameters: Parameters.GetAvatarImageByOwner, callback: Callback, ): Promise; @@ -293,20 +302,28 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByOwner(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise; - async getAvatarImageByOwner( + async getAvatarImageByOwner(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise; + async getAvatarImageByOwner( parameters: Parameters.GetAvatarImageByOwner, callback?: Callback, ): Promise { const config: RequestConfig = { url: `/rest/api/2/universal_avatar/view/type/${parameters.type}/owner/${parameters.entityId}`, method: 'GET', + responseType: 'arraybuffer', params: { size: parameters.size, format: parameters.format, }, }; - return this.client.sendRequest(config, callback); + const { + data: avatar, + headers: { 'content-type': contentTypeWithEncoding }, + } = await this.client.sendRequestFullResponse(config); + + const contentType = contentTypeWithEncoding.split(';')[0].trim(); + + return this.client.handleSuccessResponse({ contentType, avatar }, callback); } } diff --git a/src/version2/parameters/storeAvatar.ts b/src/version2/parameters/storeAvatar.ts index 7bbf800cef..1e730f3604 100644 --- a/src/version2/parameters/storeAvatar.ts +++ b/src/version2/parameters/storeAvatar.ts @@ -9,4 +9,5 @@ export interface StoreAvatar { y?: number; /** The length of each side of the crop region. */ size: number; + avatar: any; } diff --git a/src/version3/avatars.ts b/src/version3/avatars.ts index ef06946733..96e10018c9 100644 --- a/src/version3/avatars.ts +++ b/src/version3/avatars.ts @@ -137,6 +137,7 @@ export class Avatars { y: parameters.y, size: parameters.size, }, + data: parameters.avatar, }; return this.client.sendRequest(config, callback); @@ -172,7 +173,7 @@ export class Avatars { * * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) required:** None. */ - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback: Callback, ): Promise; @@ -183,11 +184,11 @@ export class Avatars { * * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) required:** None. */ - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback?: never, ): Promise; - async getAvatarImageByType( + async getAvatarImageByType( parameters: Parameters.GetAvatarImageByType | string, callback?: Callback, ): Promise { @@ -196,13 +197,21 @@ export class Avatars { const config: RequestConfig = { url: `/rest/api/3/universal_avatar/view/type/${type}`, method: 'GET', + responseType: 'arraybuffer', params: { size: typeof parameters !== 'string' && parameters.size, format: typeof parameters !== 'string' && parameters.format, }, }; - return this.client.sendRequest(config, callback); + const { + data: avatar, + headers: { 'content-type': contentTypeWithEncoding }, + } = await this.client.sendRequestFullResponse(config); + + const contentType = contentTypeWithEncoding.split(';')[0].trim(); + + return this.client.handleSuccessResponse({ contentType, avatar }, callback); } /** @@ -276,7 +285,7 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByOwner( + async getAvatarImageByOwner( parameters: Parameters.GetAvatarImageByOwner, callback: Callback, ): Promise; @@ -293,20 +302,28 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByOwner(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise; - async getAvatarImageByOwner( + async getAvatarImageByOwner(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise; + async getAvatarImageByOwner( parameters: Parameters.GetAvatarImageByOwner, callback?: Callback, ): Promise { const config: RequestConfig = { url: `/rest/api/3/universal_avatar/view/type/${parameters.type}/owner/${parameters.entityId}`, method: 'GET', + responseType: 'arraybuffer', params: { size: parameters.size, format: parameters.format, }, }; - return this.client.sendRequest(config, callback); + const { + data: avatar, + headers: { 'content-type': contentTypeWithEncoding }, + } = await this.client.sendRequestFullResponse(config); + + const contentType = contentTypeWithEncoding.split(';')[0].trim(); + + return this.client.handleSuccessResponse({ contentType, avatar }, callback); } } diff --git a/src/version3/parameters/storeAvatar.ts b/src/version3/parameters/storeAvatar.ts index 7bbf800cef..1e730f3604 100644 --- a/src/version3/parameters/storeAvatar.ts +++ b/src/version3/parameters/storeAvatar.ts @@ -9,4 +9,5 @@ export interface StoreAvatar { y?: number; /** The length of each side of the crop region. */ size: number; + avatar: any; }