@atlaskit/util-service-support
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -1,56 +0,30 @@ | ||
<a name="2.0.4"></a> | ||
## 2.0.4 (2018-02-06) | ||
# @atlaskit/util-service-support | ||
## 2.0.5 | ||
- [patch] FS-1698 migrated util-service-support to mk-2 [e0bcb61](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/e0bcb61) | ||
<a name="2.0.4"></a> | ||
## 2.0.4 (2018-02-06) | ||
* bug fix; added omitCredentials to SecurityOptions ([88cb203](https://bitbucket.org/atlassian/atlaskit/commits/88cb203)) | ||
### Bug Fixes | ||
* **component:** added omitCredentials to SecurityOptions ([88cb203](https://bitbucket.org/atlassian/atlaskit/commits/88cb203)) | ||
<a name="2.0.3"></a> | ||
## 2.0.3 (2017-12-26) | ||
### Bug Fixes | ||
* **package:** add url-search-params as a dependency ([b33cdcf](https://bitbucket.org/atlassian/atlaskit/commits/b33cdcf)) | ||
* **package:** remove [@atlaskit](https://github.com/atlaskit)/util-common-test from devDependencies ([e9faeab](https://bitbucket.org/atlassian/atlaskit/commits/e9faeab)) | ||
<a name="2.0.2"></a> | ||
* bug fix; remove @atlaskit/util-common-test from devDependencies ([e9faeab](https://bitbucket.org/atlassian/atlaskit/commits/e9faeab)) | ||
* bug fix; add url-search-params as a dependency (issues closed: fs-1091) ([b33cdcf](https://bitbucket.org/atlassian/atlaskit/commits/b33cdcf)) | ||
## 2.0.2 (2017-09-12) | ||
* bug fix; requestService can handle 204 responses with no content ([edf13d5](https://bitbucket.org/atlassian/atlaskit/commits/edf13d5)) | ||
### Bug Fixes | ||
* **component:** requestService can handle 204 responses with no content ([edf13d5](https://bitbucket.org/atlassian/atlaskit/commits/edf13d5)) | ||
<a name="2.0.1"></a> | ||
## 2.0.1 (2017-07-24) | ||
### Bug Fixes | ||
* fix; make sure types from utils are exports (extracted types to separate file) ([ebde291](https://bitbucket.org/atlassian/atlaskit/commits/ebde291)) | ||
* **component:** make sure types from utils are exports (extracted types to separate file) ([ebde291](https://bitbucket.org/atlassian/atlaskit/commits/ebde291)) | ||
## 1.0.0 (2017-07-24) | ||
<a name="1.0.0"></a> | ||
# 1.0.0 (2017-07-24) | ||
### Features | ||
* **component:** extract common service integration code into a shared library ([5714832](https://bitbucket.org/atlassian/atlaskit/commits/5714832)) | ||
* feature; extract common service integration code into a shared library ([5714832](https://bitbucket.org/atlassian/atlaskit/commits/5714832)) |
export * from './types'; | ||
export * from './serviceResources'; | ||
import * as serviceUtils from './serviceUtils'; | ||
export const utils = serviceUtils; | ||
export var utils = serviceUtils; | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,6 @@ | ||
export class AbstractResource { | ||
constructor() { | ||
var AbstractResource = /** @class */ (function () { | ||
function AbstractResource() { | ||
this.listeners = new Set(); | ||
} | ||
subscribe(onChange) { | ||
AbstractResource.prototype.subscribe = function (onChange) { | ||
this.listeners.add(onChange); | ||
@@ -11,13 +11,13 @@ if (this.lastResult) { | ||
} | ||
} | ||
unsubscribe(onChange) { | ||
}; | ||
AbstractResource.prototype.unsubscribe = function (onChange) { | ||
this.listeners.delete(onChange); | ||
} | ||
notifyResult(result) { | ||
this.listeners.forEach((onChange) => { | ||
}; | ||
AbstractResource.prototype.notifyResult = function (result) { | ||
this.listeners.forEach(function (onChange) { | ||
onChange.result(result); | ||
}); | ||
} | ||
notifyError(error) { | ||
this.listeners.forEach((onChange) => { | ||
}; | ||
AbstractResource.prototype.notifyError = function (error) { | ||
this.listeners.forEach(function (onChange) { | ||
if (onChange.error) { | ||
@@ -27,5 +27,5 @@ onChange.error(error); | ||
}); | ||
} | ||
notifyInfo(info) { | ||
this.listeners.forEach((onChange) => { | ||
}; | ||
AbstractResource.prototype.notifyInfo = function (info) { | ||
this.listeners.forEach(function (onChange) { | ||
if (onChange.info) { | ||
@@ -35,5 +35,5 @@ onChange.info(info); | ||
}); | ||
} | ||
notifyNotReady() { | ||
this.listeners.forEach((onChange) => { | ||
}; | ||
AbstractResource.prototype.notifyNotReady = function () { | ||
this.listeners.forEach(function (onChange) { | ||
if (onChange.notReady) { | ||
@@ -43,4 +43,6 @@ onChange.notReady(); | ||
}); | ||
} | ||
} | ||
}; | ||
return AbstractResource; | ||
}()); | ||
export { AbstractResource }; | ||
//# sourceMappingURL=serviceResources.js.map |
@@ -0,10 +1,12 @@ | ||
import * as tslib_1 from "tslib"; | ||
import * as URL from 'url'; | ||
import * as URLSearchParams from 'url-search-params'; // IE, Safari, Mobile Chrome, Mobile Safari | ||
import { buildCredentials } from './types'; | ||
const defaultRequestServiceOptions = {}; | ||
const buildUrl = (baseUrl, path = '', queryParams, secOptions) => { | ||
const searchParam = new URLSearchParams(URL.parse(baseUrl).search || undefined); | ||
import { buildCredentials, } from './types'; | ||
var defaultRequestServiceOptions = {}; | ||
var buildUrl = function (baseUrl, path, queryParams, secOptions) { | ||
if (path === void 0) { path = ''; } | ||
var searchParam = new URLSearchParams(URL.parse(baseUrl).search || undefined); | ||
baseUrl = baseUrl.split('?')[0]; | ||
if (queryParams) { | ||
for (const key in queryParams) { | ||
for (var key in queryParams) { | ||
if ({}.hasOwnProperty.call(queryParams, key)) { | ||
@@ -16,7 +18,7 @@ searchParam.append(key, queryParams[key]); | ||
if (secOptions && secOptions.params) { | ||
for (const key in secOptions.params) { | ||
for (var key in secOptions.params) { | ||
if ({}.hasOwnProperty.call(secOptions.params, key)) { | ||
const values = secOptions.params[key]; | ||
var values = secOptions.params[key]; | ||
if (Array.isArray(values)) { | ||
for (let i = 0; i < values.length; i++) { | ||
for (var i = 0; i < values.length; i++) { | ||
searchParam.append(key, values[i]); | ||
@@ -31,19 +33,19 @@ } | ||
} | ||
let seperator = ''; | ||
var seperator = ''; | ||
if (path && baseUrl.substr(-1) !== '/') { | ||
seperator = '/'; | ||
} | ||
let params = searchParam.toString(); | ||
var params = searchParam.toString(); | ||
if (params) { | ||
params = '?' + params; | ||
} | ||
return `${baseUrl}${seperator}${path}${params}`; | ||
return "" + baseUrl + seperator + path + params; | ||
}; | ||
const addToHeaders = (headers, keyValues) => { | ||
var addToHeaders = function (headers, keyValues) { | ||
if (keyValues) { | ||
for (const key in keyValues) { | ||
for (var key in keyValues) { | ||
if ({}.hasOwnProperty.call(keyValues, key)) { | ||
const values = keyValues[key]; | ||
var values = keyValues[key]; | ||
if (Array.isArray(values)) { | ||
for (let i = 0; i < values.length; i++) { | ||
for (var i = 0; i < values.length; i++) { | ||
headers.append(key, values[i]); | ||
@@ -59,4 +61,4 @@ } | ||
}; | ||
const buildHeaders = (secOptions, extraHeaders) => { | ||
const headers = new Headers(); | ||
var buildHeaders = function (secOptions, extraHeaders) { | ||
var headers = new Headers(); | ||
addToHeaders(headers, extraHeaders); | ||
@@ -71,13 +73,12 @@ if (secOptions) { | ||
*/ | ||
export const requestService = (serviceConfig, options) => { | ||
const { url, securityProvider, refreshedSecurityProvider } = serviceConfig; | ||
const { path, queryParams, requestInit } = options || defaultRequestServiceOptions; | ||
const secOptions = securityProvider && securityProvider(); | ||
const requestUrl = buildUrl(url, path, queryParams, secOptions); | ||
const headers = buildHeaders(secOptions, requestInit && requestInit.headers); | ||
const credentials = buildCredentials(secOptions); | ||
const requestOptions = Object.assign({}, requestInit, { headers, | ||
credentials }); | ||
return fetch(new Request(requestUrl, requestOptions)) | ||
.then((response) => { | ||
export var requestService = function (serviceConfig, options) { | ||
var url = serviceConfig.url, securityProvider = serviceConfig.securityProvider, refreshedSecurityProvider = serviceConfig.refreshedSecurityProvider; | ||
var _a = options || defaultRequestServiceOptions, path = _a.path, queryParams = _a.queryParams, requestInit = _a.requestInit; | ||
var secOptions = securityProvider && securityProvider(); | ||
var requestUrl = buildUrl(url, path, queryParams, secOptions); | ||
var headers = buildHeaders(secOptions, requestInit && requestInit.headers); | ||
var credentials = buildCredentials(secOptions); | ||
var requestOptions = tslib_1.__assign({}, requestInit, { headers: headers, | ||
credentials: credentials }); | ||
return fetch(new Request(requestUrl, requestOptions)).then(function (response) { | ||
if (response.status === 204) { | ||
@@ -91,6 +92,6 @@ return Promise.resolve(); | ||
// auth issue - try once | ||
return refreshedSecurityProvider().then(newSecOptions => { | ||
const retryServiceConfig = { | ||
url, | ||
securityProvider: () => newSecOptions, | ||
return refreshedSecurityProvider().then(function (newSecOptions) { | ||
var retryServiceConfig = { | ||
url: url, | ||
securityProvider: function () { return newSecOptions; }, | ||
}; | ||
@@ -97,0 +98,0 @@ return requestService(retryServiceConfig, options); |
@@ -1,4 +0,6 @@ | ||
export const buildCredentials = (secOptions) => { | ||
return secOptions && secOptions.omitCredentials ? 'omit' : 'include'; | ||
export var buildCredentials = function (secOptions) { | ||
return secOptions && secOptions.omitCredentials | ||
? 'omit' | ||
: 'include'; | ||
}; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@atlaskit/util-service-support", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "A library of support classes for integrating React components with REST HTTP services", | ||
"config": { | ||
"access": "public" | ||
}, | ||
"description": "A library of support classes for integrating React components with REST HTTP services", | ||
"main": "dist/es5/index.js", | ||
"atlaskit:src": "src/index.ts", | ||
"jsnext:main": "dist/es2015/index.js", | ||
"module": "dist/es2015/index.js", | ||
"types": "dist/es5/index.d.ts", | ||
"scripts": { | ||
"prepublish": "../../node_modules/.bin/in-publish && npm run build || ../../node_modules/.bin/not-in-publish", | ||
"build": "npm run build/es5 && npm run build/es2015", | ||
"build/es5": "../../node_modules/.bin/tsc -p build/es5", | ||
"build/es2015": "../../node_modules/.bin/tsc -p build/es2015", | ||
"lint": "../../node_modules/.bin/tslint --project . '*.{ts,tsx,d.ts}' '{src,test,stories}/**/*.{ts,tsx,d.ts}'", | ||
"validate/typescript": "../../build/bin/validate.typescript.sh", | ||
"test:unit": "../../node_modules/.bin/jest -c ../../build/config/jest.config.js", | ||
"jest": "echo 'yarn run jest is deprecated and removed. please run yarn run test:unit instead.'" | ||
}, | ||
"files": [ | ||
@@ -26,3 +18,3 @@ "dist", | ||
"dependencies": { | ||
"tslib": "^1.2.0", | ||
"tslib": "^1.8.0", | ||
"url": "^0.11.0", | ||
@@ -39,3 +31,4 @@ "url-search-params": "^0.10.0" | ||
"devDependencies": { | ||
"fetch-mock": "^5.8.0" | ||
"@atlaskit/docs": "^3.0.0", | ||
"fetch-mock": "^5.12.1" | ||
}, | ||
@@ -42,0 +35,0 @@ "keywords": [ |
import { OnProviderChange, Provider } from './types'; | ||
export abstract class AbstractResource<Q, R, E, I, O> implements Provider<Q, R, E, I, O> { | ||
export abstract class AbstractResource<Q, R, E, I, O> | ||
implements Provider<Q, R, E, I, O> { | ||
private lastResult: R; | ||
@@ -22,3 +23,3 @@ private listeners = new Set<OnProviderChange<R, E, I>>(); | ||
protected notifyResult(result: R): void { | ||
this.listeners.forEach((onChange) => { | ||
this.listeners.forEach(onChange => { | ||
onChange.result(result); | ||
@@ -29,3 +30,3 @@ }); | ||
protected notifyError(error: E): void { | ||
this.listeners.forEach((onChange) => { | ||
this.listeners.forEach(onChange => { | ||
if (onChange.error) { | ||
@@ -38,3 +39,3 @@ onChange.error(error); | ||
protected notifyInfo(info: I): void { | ||
this.listeners.forEach((onChange) => { | ||
this.listeners.forEach(onChange => { | ||
if (onChange.info) { | ||
@@ -47,3 +48,3 @@ onChange.info(info); | ||
protected notifyNotReady(): void { | ||
this.listeners.forEach((onChange) => { | ||
this.listeners.forEach(onChange => { | ||
if (onChange.notReady) { | ||
@@ -55,2 +56,1 @@ onChange.notReady(); | ||
} | ||
import * as URL from 'url'; | ||
import * as URLSearchParams from 'url-search-params'; // IE, Safari, Mobile Chrome, Mobile Safari | ||
import { KeyValues, RequestServiceOptions, ServiceConfig, SecurityOptions, buildCredentials } from './types'; | ||
import { | ||
KeyValues, | ||
RequestServiceOptions, | ||
ServiceConfig, | ||
SecurityOptions, | ||
buildCredentials, | ||
} from './types'; | ||
const defaultRequestServiceOptions: RequestServiceOptions = {}; | ||
const buildUrl = (baseUrl: string, path: string = '', queryParams?: KeyValues, secOptions?: SecurityOptions): string => { | ||
const searchParam = new URLSearchParams(URL.parse(baseUrl).search || undefined); | ||
const buildUrl = ( | ||
baseUrl: string, | ||
path: string = '', | ||
queryParams?: KeyValues, | ||
secOptions?: SecurityOptions, | ||
): string => { | ||
const searchParam = new URLSearchParams( | ||
URL.parse(baseUrl).search || undefined, | ||
); | ||
baseUrl = baseUrl.split('?')[0]; | ||
@@ -60,3 +73,6 @@ if (queryParams) { | ||
const buildHeaders = (secOptions?: SecurityOptions, extraHeaders?: KeyValues): Headers => { | ||
const buildHeaders = ( | ||
secOptions?: SecurityOptions, | ||
extraHeaders?: KeyValues, | ||
): Headers => { | ||
const headers = new Headers(); | ||
@@ -73,5 +89,9 @@ addToHeaders(headers, extraHeaders); | ||
*/ | ||
export const requestService = <T>(serviceConfig: ServiceConfig, options?: RequestServiceOptions): Promise<T> => { | ||
export const requestService = <T>( | ||
serviceConfig: ServiceConfig, | ||
options?: RequestServiceOptions, | ||
): Promise<T> => { | ||
const { url, securityProvider, refreshedSecurityProvider } = serviceConfig; | ||
const { path, queryParams, requestInit } = options || defaultRequestServiceOptions; | ||
const { path, queryParams, requestInit } = | ||
options || defaultRequestServiceOptions; | ||
const secOptions = securityProvider && securityProvider(); | ||
@@ -87,4 +107,4 @@ const requestUrl = buildUrl(url, path, queryParams, secOptions); | ||
return fetch(new Request(requestUrl, requestOptions)) | ||
.then((response: Response) => { | ||
return fetch(new Request(requestUrl, requestOptions)).then( | ||
(response: Response) => { | ||
if (response.status === 204) { | ||
@@ -108,3 +128,4 @@ return Promise.resolve(); | ||
}); | ||
}); | ||
}, | ||
); | ||
}; |
@@ -65,3 +65,5 @@ export interface OnProviderChange<R, E, I> { | ||
export const buildCredentials = (secOptions?: SecurityOptions) => { | ||
return secOptions && secOptions.omitCredentials ? 'omit' as 'omit' : 'include' as 'include'; | ||
return secOptions && secOptions.omitCredentials | ||
? ('omit' as 'omit') | ||
: ('include' as 'include'); | ||
}; | ||
@@ -68,0 +70,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
24809
2
20
503
1
0
Updatedtslib@^1.8.0