Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
root=true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.js]
|
||||
indent_style = tab
|
||||
|
||||
[*.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"node": true,
|
||||
"browser": true,
|
||||
"predef": ["describe", "it", "before"]
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- 14
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Matt Andrews
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
isomorphic-fetch [](https://travis-ci.org/matthew-andrews/isomorphic-fetch)
|
||||
================
|
||||
|
||||
Fetch for node and Browserify. Built on top of [GitHub's WHATWG Fetch polyfill](https://github.com/github/fetch).
|
||||
|
||||
## Warnings
|
||||
|
||||
- This adds `fetch` as a global so that its API is consistent between client and server.
|
||||
|
||||
For [ease-of-maintenance and backward-compatibility reasons][why polyfill], this library will always be a polyfill. As a "safe" alternative, which does not modify the global, consider [fetch-ponyfill][].
|
||||
|
||||
[why polyfill]: https://github.com/matthew-andrews/isomorphic-fetch/issues/31#issuecomment-149668361
|
||||
[fetch-ponyfill]: https://github.com/qubyte/fetch-ponyfill
|
||||
|
||||
## Why Use Isomorphic Fetch
|
||||
|
||||
The Fetch API is currently [not implemented consistently](http://caniuse.com/#search=fetch) across browsers. This module will enable you to use `fetch` in your Node code in a cross-browser compliant fashion. The Fetch API is part of the Web platform API defined by the standards bodies WHATWG and W3C.
|
||||
|
||||
## Installation
|
||||
|
||||
### NPM
|
||||
|
||||
```sh
|
||||
npm install --save isomorphic-fetch
|
||||
```
|
||||
|
||||
### Bower
|
||||
|
||||
```sh
|
||||
bower install --save isomorphic-fetch
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
require('isomorphic-fetch');
|
||||
|
||||
fetch('//offline-news-api.herokuapp.com/stories')
|
||||
.then(function(response) {
|
||||
if (response.status >= 400) {
|
||||
throw new Error("Bad response from server");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(function(stories) {
|
||||
console.log(stories);
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
All open source code released by FT Labs is licenced under the MIT licence. Based on [the fine work by](https://github.com/github/fetch/pull/31) **[jxck](https://github.com/Jxck)**.
|
||||
|
||||
## Alternatives
|
||||
|
||||
- [cross-fetch](https://github.com/lquixada/cross-fetch#why-not-isomorphic-fetch)
|
||||
- Using [node-fetch](https://github.com/node-fetch/node-fetch) and the [Fetch polyfill](https://github.com/github/fetch) directly (or from [polyfill.io](https://polyfill.io), or relying on [the browser's implementation of the Fetch API](https://caniuse.com/fetch)).
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "isomorphic-fetch",
|
||||
"main": ["fetch-bower.js"],
|
||||
"dependencies": {
|
||||
"fetch": "github/fetch#^3.4.1"
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('fetch');
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// the whatwg-fetch polyfill installs the fetch() function
|
||||
// on the global object (window or self)
|
||||
//
|
||||
// Return that as the export for use in Webpack, Browserify etc.
|
||||
require('whatwg-fetch');
|
||||
module.exports = self.fetch.bind(self);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var realFetch = require('node-fetch');
|
||||
module.exports = function(url, options) {
|
||||
if (/^\/\//.test(url)) {
|
||||
url = 'https:' + url;
|
||||
}
|
||||
return realFetch.call(this, url, options);
|
||||
};
|
||||
|
||||
if (!global.fetch) {
|
||||
global.fetch = module.exports;
|
||||
global.Response = realFetch.Response;
|
||||
global.Headers = realFetch.Headers;
|
||||
global.Request = realFetch.Request;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "isomorphic-fetch",
|
||||
"version": "3.0.0",
|
||||
"description": "Isomorphic WHATWG Fetch API, for Node & Browserify",
|
||||
"browser": "fetch-npm-browserify.js",
|
||||
"main": "fetch-npm-node.js",
|
||||
"scripts": {
|
||||
"files": "find . -name '*.js' ! -path './node_modules/*' ! -path './bower_components/*'",
|
||||
"test": "jshint `npm run -s files` && lintspaces -i js-comments -e .editorconfig `npm run -s files` && mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/matthew-andrews/isomorphic-fetch.git"
|
||||
},
|
||||
"author": "Matt Andrews <matt@mattandre.ws>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/matthew-andrews/isomorphic-fetch/issues"
|
||||
},
|
||||
"homepage": "https://github.com/matthew-andrews/isomorphic-fetch/issues",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.1",
|
||||
"whatwg-fetch": "^3.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"jshint": "^2.5.11",
|
||||
"lintspaces-cli": "^0.7.1",
|
||||
"mocha": "^8.1.3",
|
||||
"nock": "^13.0.4"
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*global fetch*/
|
||||
"use strict";
|
||||
|
||||
require('../fetch-npm-node');
|
||||
var expect = require('chai').expect;
|
||||
var nock = require('nock');
|
||||
var good = 'hello world. 你好世界。';
|
||||
var bad = 'good bye cruel world. 再见残酷的世界。';
|
||||
|
||||
function responseToText(response) {
|
||||
if (response.status >= 400) throw new Error("Bad server response");
|
||||
return response.text();
|
||||
}
|
||||
|
||||
describe('fetch', function() {
|
||||
|
||||
before(function() {
|
||||
nock('https://mattandre.ws')
|
||||
.get('/succeed.txt')
|
||||
.reply(200, good);
|
||||
nock('https://mattandre.ws')
|
||||
.get('/fail.txt')
|
||||
.reply(404, bad);
|
||||
});
|
||||
|
||||
it('should be defined', function() {
|
||||
expect(fetch).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should facilitate the making of requests', function(done) {
|
||||
fetch('//mattandre.ws/succeed.txt')
|
||||
.then(responseToText)
|
||||
.then(function(data) {
|
||||
expect(data).to.equal(good);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('should do the right thing with bad requests', function(done) {
|
||||
fetch('//mattandre.ws/fail.txt')
|
||||
.then(responseToText)
|
||||
.catch(function(err) {
|
||||
expect(err.toString()).to.equal("Error: Bad server response");
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user