fix(ajax): become a 0 dependency package
This commit is contained in:
parent
4452d06d44
commit
78df6e7181
8 changed files with 19 additions and 43 deletions
|
|
@ -3,7 +3,7 @@ const path = require('path');
|
|||
|
||||
module.exports = {
|
||||
stories: [
|
||||
'../{packages,packages-node}/*/README.md',
|
||||
'../{packages,packages-node}/!(ajax)*/README.md',
|
||||
'../{packages,packages-node}/*/docs/*.md',
|
||||
'../{packages,packages-node}/*/docs/!(assets)**/*.md',
|
||||
'../packages/helpers/*/README.md',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
export { ajax, setAjax } from './src/ajax.js';
|
||||
export { AjaxClient } from './src/AjaxClient.js';
|
||||
export { AjaxClientFetchError } from './src/AjaxClientFetchError.js';
|
||||
|
||||
export {
|
||||
acceptLanguageRequestInterceptor,
|
||||
createXSRFRequestInterceptor,
|
||||
getCookie,
|
||||
} from './src/interceptors.js';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@lion/ajax",
|
||||
"version": "0.5.15",
|
||||
"description": "Thin wrapper around fetch.",
|
||||
"description": "Thin wrapper around fetch with support for interceptors.",
|
||||
"license": "MIT",
|
||||
"author": "ing-bank",
|
||||
"homepage": "https://github.com/ing-bank/lion/",
|
||||
|
|
@ -29,9 +29,6 @@
|
|||
"prepublishOnly": "../../scripts/npm-prepublish.js",
|
||||
"test": "cd ../../ && npm run test:browser -- --group ajax"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lion/localize": "0.15.5"
|
||||
},
|
||||
"keywords": [
|
||||
"ajax",
|
||||
"fetch",
|
||||
|
|
@ -41,5 +38,8 @@
|
|||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"exports": {
|
||||
".": "./index.js"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { localize } from '@lion/localize';
|
||||
|
||||
/**
|
||||
* @typedef {import('./AjaxClient').RequestInterceptor} RequestInterceptor
|
||||
*/
|
||||
|
|
@ -21,7 +19,11 @@ export function getCookie(name, _document = document) {
|
|||
*/
|
||||
export async function acceptLanguageRequestInterceptor(request) {
|
||||
if (!request.headers.has('accept-language')) {
|
||||
request.headers.set('accept-language', localize.locale);
|
||||
let locale = document.documentElement.lang || 'en';
|
||||
if (document.documentElement.getAttribute('data-localize-lang')) {
|
||||
locale = document.documentElement.getAttribute('data-localize-lang') || 'en';
|
||||
}
|
||||
request.headers.set('accept-language', locale);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { expect } from '@open-wc/testing';
|
||||
import { stub } from 'sinon';
|
||||
import { localize } from '@lion/localize';
|
||||
import { AjaxClient } from '../src/AjaxClient.js';
|
||||
import { AjaxClientFetchError } from '../src/AjaxClientFetchError.js';
|
||||
import { AjaxClient, AjaxClientFetchError } from '@lion/ajax';
|
||||
|
||||
describe('AjaxClient', () => {
|
||||
/** @type {import('sinon').SinonStub} */
|
||||
|
|
@ -154,7 +152,7 @@ describe('AjaxClient', () => {
|
|||
it('is set by default based on localize.locale', async () => {
|
||||
await ajax.request('/foo');
|
||||
const request = fetchStub.getCall(0).args[0];
|
||||
expect(request.headers.get('accept-language')).to.equal(localize.locale);
|
||||
expect(request.headers.get('accept-language')).to.equal('en');
|
||||
});
|
||||
|
||||
it('can be disabled', async () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { expect } from '@open-wc/testing';
|
||||
import { ajax, setAjax } from '../src/ajax.js';
|
||||
import { AjaxClient } from '../src/AjaxClient.js';
|
||||
import { ajax, setAjax, AjaxClient } from '@lion/ajax';
|
||||
|
||||
describe('ajax', () => {
|
||||
it('exports an instance of AjaxClient', () => {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { expect } from '@open-wc/testing';
|
||||
import { localize } from '@lion/localize';
|
||||
import {
|
||||
createXSRFRequestInterceptor,
|
||||
getCookie,
|
||||
acceptLanguageRequestInterceptor,
|
||||
} from '../src/interceptors.js';
|
||||
} from '@lion/ajax';
|
||||
|
||||
describe('interceptors', () => {
|
||||
describe('getCookie()', () => {
|
||||
|
|
@ -31,7 +30,7 @@ describe('interceptors', () => {
|
|||
it('adds the locale as accept-language header', () => {
|
||||
const request = new Request('/foo/');
|
||||
acceptLanguageRequestInterceptor(request);
|
||||
expect(request.headers.get('accept-language')).to.equal(localize.locale);
|
||||
expect(request.headers.get('accept-language')).to.equal('en');
|
||||
});
|
||||
|
||||
it('does not change an existing accept-language header', () => {
|
||||
|
|
@ -51,7 +50,7 @@ describe('interceptors', () => {
|
|||
expect(request.headers.get('X-XSRF-TOKEN')).to.equal('foo');
|
||||
});
|
||||
|
||||
it('doesnt set anything if the cookie is not there', () => {
|
||||
it('does not set anything if the cookie is not there', () => {
|
||||
const interceptor = createXSRFRequestInterceptor('XSRF-TOKEN', 'X-XSRF-TOKEN', {
|
||||
cookie: 'XXSRF-TOKEN=foo',
|
||||
});
|
||||
|
|
|
|||
26
yarn.lock
26
yarn.lock
|
|
@ -1507,25 +1507,6 @@
|
|||
dependencies:
|
||||
vary "^1.1.2"
|
||||
|
||||
"@lion/core@0.13.4":
|
||||
version "0.13.4"
|
||||
resolved "https://registry.yarnpkg.com/@lion/core/-/core-0.13.4.tgz#397f324c56d19f5fc84b9a774fe8169f1c002bb0"
|
||||
integrity sha512-0wcW8WDACxH2LQNZgFG1IoPqrTxyGvusQxY+eXTUzw7rv7a/gYa0t/jh+l45NOlYfKdjyXQLWr121W+NCShqiQ==
|
||||
dependencies:
|
||||
"@open-wc/dedupe-mixin" "^1.2.18"
|
||||
"@open-wc/scoped-elements" "^1.2.2"
|
||||
lit-element "~2.4.0"
|
||||
lit-html "^1.3.0"
|
||||
|
||||
"@lion/localize@0.15.1":
|
||||
version "0.15.1"
|
||||
resolved "https://registry.yarnpkg.com/@lion/localize/-/localize-0.15.1.tgz#0b40f6cb1ecfbb6f56e0efa8c871c9338e5436ea"
|
||||
integrity sha512-cjcE+XQlx4Ehs+rlsJEwD8xvJAki/q0yWtRwH6suuV7hrVpZeMMkOBFjvM07xQEUgzmdjo9FT9TWrsE/keR/RA==
|
||||
dependencies:
|
||||
"@bundled-es-modules/message-format" "6.0.4"
|
||||
"@lion/core" "0.13.4"
|
||||
singleton-manager "1.2.0"
|
||||
|
||||
"@manypkg/find-root@^1.1.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-1.1.0.tgz#a62d8ed1cd7e7d4c11d9d52a8397460b5d4ad29f"
|
||||
|
|
@ -1848,7 +1829,7 @@
|
|||
"@open-wc/rollup-plugin-html" "^1.2.5"
|
||||
polyfills-loader "^1.7.5"
|
||||
|
||||
"@open-wc/scoped-elements@^1.2.2", "@open-wc/scoped-elements@^1.2.4", "@open-wc/scoped-elements@^1.3.3":
|
||||
"@open-wc/scoped-elements@^1.2.4", "@open-wc/scoped-elements@^1.3.3":
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/@open-wc/scoped-elements/-/scoped-elements-1.3.3.tgz#fe008aef4d74fb00c553c900602960638fc1c7b0"
|
||||
integrity sha512-vFIQVYYjFw67odUE4JzZOpctnF7S/2DX+S+clrL3bQPql7HvEnV0wMFwOWUavQTuCJi0rfU8GTcNMiUybio+Yg==
|
||||
|
|
@ -10768,11 +10749,6 @@ simplebar@^4.2.3:
|
|||
lodash.throttle "^4.1.1"
|
||||
resize-observer-polyfill "^1.5.1"
|
||||
|
||||
singleton-manager@1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/singleton-manager/-/singleton-manager-1.2.0.tgz#5f80f89bda3a49b926ce6f721c14abdd8bff067a"
|
||||
integrity sha512-CJvFjCjO6rhAB+N10CJ3nlb6EbuoZv+TEA5y+91oGRHk0egtQJMTbDEUQBg6gw7ksrTgjMhg4RRngE1Km6diAQ==
|
||||
|
||||
sinon-chai@^3.3.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-3.5.0.tgz#c9a78304b0e15befe57ef68e8a85a00553f5c60e"
|
||||
|
|
|
|||
Loading…
Reference in a new issue