Socket
Socket
Sign inDemoInstall

@octokit/rest

Package Overview
Dependencies
Maintainers
3
Versions
297
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/rest - npm Package Compare versions

Comparing version 14.0.9 to 15.0.1

lib/.DS_Store

4

lib/endpoint/extract-url-variable-names.js
module.exports = extractUrlVariableName
const _ = require('lodash')
const flatten = require('lodash/flatten')

@@ -13,3 +13,3 @@ const urlVariableRegex = /\{[^}]+\}/g

return _.flatten(matches.map(removeNonChars))
return flatten(matches.map(removeNonChars))
}

@@ -16,0 +16,0 @@

@@ -5,3 +5,6 @@ 'use strict'

const _ = require('lodash')
const defaultsDeep = require('lodash/defaultsDeep')
const intersection = require('lodash/intersection')
const mapKeys = require('lodash/mapKeys')
const omit = require('lodash/omit')
const urlTemplate = require('url-template')

@@ -19,3 +22,3 @@

function restEndpoint (options) {
options = _.defaultsDeep({}, options, DEFAULTS)
options = defaultsDeep({}, options, DEFAULTS)
let method = options.method

@@ -26,9 +29,9 @@ let baseUrl = options.baseUrl

let headers = options.headers
let remainingOptions = _.omit(options, ['method', 'baseUrl', 'url', 'headers'])
let remainingOptions = omit(options, ['method', 'baseUrl', 'url', 'headers'])
method = method.toLowerCase()
headers = _.mapKeys(headers, (value, key) => key.toLowerCase())
headers = mapKeys(headers, (value, key) => key.toLowerCase())
// replace :varname with {varname} to make it RFC 6570 compatible
url = url.replace(/:(\w+)/g, '{+$1}')
url = url.replace(/:([a-z]\w+)/g, '{+$1}')

@@ -45,3 +48,3 @@ // extract variable names from URL to calculate remaining variables later

const requestOptions = remainingOptions.request
remainingOptions = _.omit(remainingOptions, _.intersection(Object.keys(options), urlVariableNames).concat(NON_PARAMETERS))
remainingOptions = omit(remainingOptions, intersection(Object.keys(options), urlVariableNames).concat(NON_PARAMETERS))

@@ -48,0 +51,0 @@ if (method === 'get' || method === 'head') {

module.exports = parseOptions
const _ = require('lodash')
const defaults = require('lodash/defaults')
const pick = require('lodash/pick')

@@ -33,5 +34,5 @@ const DEFAULTS = require('./defaults')

options = _.defaults(_.pick(options, OPTION_NAMES), DEFAULTS)
options = defaults(pick(options, OPTION_NAMES), DEFAULTS)
const defaults = {
const clientDefaults = {
headers: options.headers,

@@ -47,6 +48,6 @@ request: {

defaults.baseUrl = `${options.protocol}://${options.host}`
clientDefaults.baseUrl = `${options.protocol}://${options.host}`
if (options.port) {
defaults.baseUrl += `:${options.port}`
clientDefaults.baseUrl += `:${options.port}`
}

@@ -56,6 +57,6 @@

if (options.pathPrefix) {
defaults.baseUrl += '/' + options.pathPrefix.replace(/(^[/]+|[/]+$)/g, '')
clientDefaults.baseUrl += '/' + options.pathPrefix.replace(/(^[/]+|[/]+$)/g, '')
}
return defaults
return clientDefaults
}
module.exports = authenticationBeforeRequest
const btoa = require('btoa-lite')
function authenticationBeforeRequest (state, options) {

@@ -9,5 +11,3 @@ if (!state.auth.type) {

if (state.auth.type === 'basic') {
const hash = Buffer.from(
`${state.auth.username}:${state.auth.password}`, 'ascii'
).toString('base64')
const hash = btoa(`${state.auth.username}:${state.auth.password}`)
options.headers['authorization'] = `Basic ${hash}`

@@ -14,0 +14,0 @@ return

module.exports = apiPlugin
const _ = require('lodash')
const pick = require('lodash/pick')

@@ -16,3 +16,3 @@ const method = require('./method')

const apiOptions = ENDPOINT_DEFAULTS[namespaceName][apiName]
const endpointDefaults = _.pick(apiOptions, ['method', 'url', 'headers', 'request'])
const endpointDefaults = pick(apiOptions, ['method', 'url', 'headers', 'request'])

@@ -19,0 +19,0 @@ octokit[namespaceName][apiName] = method.bind(null, octokit, endpointDefaults, apiOptions.params)

@@ -9,13 +9,14 @@ 'use strict'

const _ = require('lodash')
const debug = require('debug')('octokit:rest')
const defaults = require('lodash/defaults')
const isArrayBuffer = require('is-array-buffer')
const isStream = require('is-stream')
const pick = require('lodash/pick')
const HttpError = require('./http-error')
function httpRequest (requestOptions) {
requestOptions = Object.assign(
url.parse(requestOptions.url),
_.pick(requestOptions, 'method', 'body', 'headers', 'ca', 'family', 'proxy', 'rejectUnauthorized', 'timeout')
function httpRequest (origRequestOptions) {
const requestOptions = Object.assign(
url.parse(origRequestOptions.url),
pick(origRequestOptions, 'method', 'body', 'headers', 'ca', 'family', 'proxy', 'rejectUnauthorized', 'timeout')
)

@@ -32,3 +33,3 @@ debug('REQUEST:', requestOptions)

_.defaults(requestOptions.headers, {
defaults(requestOptions.headers, {
'content-type': 'application/json; charset=utf-8',

@@ -58,4 +59,8 @@ 'content-length': Buffer.byteLength(requestOptions.body, 'utf8')

response.setEncoding('utf8')
let data = ''
let data
response.on('data', (chunk) => {
/* istanbul ignore else */
if (!data) {
data = ''
}
data += chunk

@@ -70,4 +75,5 @@ })

if (response.statusCode !== 304 && response.statusCode >= 301 && response.statusCode <= 307) {
requestOptions.url = response.headers.location
httpRequest(requestOptions).then(resolve, reject)
// requestOptions.url = response.headers.location
origRequestOptions.url = JSON.parse(data).url
httpRequest(origRequestOptions).then(resolve, reject)
return

@@ -74,0 +80,0 @@ }

{
"name": "@octokit/rest",
"version": "14.0.9",
"version": "15.0.1",
"publishConfig": {
"access": "public"
"access": "public",
"tag": "next"
},

@@ -39,2 +40,3 @@ "description": "GitHub REST API client for Node.js",

"before-after-hook": "^1.1.0",
"btoa-lite": "^1.0.0",
"debug": "^3.1.0",

@@ -47,6 +49,9 @@ "is-array-buffer": "^1.0.0",

"devDependencies": {
"@octokit/fixtures": "^6.0.0",
"@octokit/fixtures-server": "^2.0.1",
"apidoc": "^0.17.6",
"bundlesize": "^0.16.0",
"chai": "^4.1.2",
"compression-webpack-plugin": "^1.1.6",
"coveralls": "^3.0.0",
"cypress": "^1.4.2",
"dotenv": "^5.0.0",

@@ -59,12 +64,20 @@ "gh-pages-with-token": "^1.0.0",

"nock": "^9.1.0",
"npm-run-all": "^4.1.1",
"node-fetch": "^2.0.0",
"npm-run-all": "^4.1.2",
"nyc": "^11.2.1",
"proxyquire": "^1.8.0",
"semantic-release": "^12.2.2",
"simple-mock": "^0.8.0",
"semantic-release": "^14.0.3",
"sinon": "^4.2.2",
"sinon-chai": "^2.14.0",
"standard": "^10.0.3",
"standard-markdown": "^4.0.2",
"string-to-arraybuffer": "^1.0.0",
"typescript": "^2.6.2"
"typescript": "^2.6.2",
"webpack": "^4.0.0-beta.1",
"webpack-bundle-analyzer": "^2.10.0",
"webpack-cli": "^2.0.4"
},
"browser": {
"./lib/request/request.js": "./lib/request/request-browser.js"
},
"types": "index.d.ts",

@@ -75,3 +88,4 @@ "scripts": {

"pretest": "standard && standard-markdown",
"test": "nyc mocha 'test/**/*-test.js'",
"test": "nyc mocha test/mocha-node-setup.js 'test/**/*-test.js'",
"test:browser": "cypress run --browser chrome",
"test:examples": "node test/examples.js",

@@ -84,6 +98,12 @@ "build": "npm-run-all build:*",

"build:ts": "node scripts/generate-typescript-types",
"prebuild:browser": "mkdirp dist/",
"build:browser": "npm-run-all build:browser:*",
"build:browser:development": "webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json",
"build:browser:production": "webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map",
"generate-bundle-report": "webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html",
"prevalidate:ts": "npm run -s build:ts",
"validate:ts": "tsc --target es6 index.d.ts",
"deploy-docs": "gh-pages-with-token -d doc",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"start-fixtures-server": "octokit-fixtures-server"
},

@@ -107,3 +127,30 @@ "license": "MIT",

]
}
},
"release": {
"publish": [
"@semantic-release/npm",
{
"path": "@semantic-release/github",
"assets": [
"dist/*.js"
]
}
]
},
"standard": {
"globals": [
"describe",
"beforeEach",
"afterEach",
"it",
"expect",
"cy"
]
},
"bundlesize": [
{
"path": "./dist/octokit-rest.min.js.gz",
"maxSize": "33 kB"
}
]
}

@@ -12,6 +12,6 @@ # rest.js

### Node
Install with `npm install @octokit/rest`.
<!-- HEADS UP: when changing the options for the constructor, make sure to also
update the type definition templates in scripts/templates/* -->
```js

@@ -29,4 +29,32 @@ const octokit = require('@octokit/rest')()

### Browser
1. Download `octokit-rest.min.js` from the latest release: https://github.com/octokit/rest.js/releases
2. Load it as script into your web application:
```html
<script scr="octokit-rest.min.js"></script>
```
3. Initialize `octokit`
```js
const octokit = new Octokit()
// Compare: https://developer.github.com/v3/repos/#list-organization-repositories
octokit.repos.getForOrg({
org: 'octokit',
type: 'public'
}).then(({data}) => {
// handle data
})
```
### Options
All available client options with default values
<!-- HEADS UP: when changing the options for the constructor, make sure to also
update the type definition templates in scripts/templates/* -->
```js

@@ -134,3 +162,3 @@ const octokit = require('@octokit/rest')({

## DEBUG
## Debug

@@ -141,4 +169,10 @@ Set `DEBUG=octokit:rest*` for additional debug logs.

Run all tests
Before running any tests you have to start the [fixtures server](https://github.com/octokit/fixtures-server)
```
$ npm run start-fixtures-server
```
In a second terminal, run the tests
```bash

@@ -151,5 +185,14 @@ $ npm test

```bash
$ ./node_modules/.bin/mocha test/test/integration/get-repository-test.js
$ ./node_modules/.bin/mocha test/scenarios/get-repository-test.js
```
Run browser tests
```bash
$ npm run test:browser
```
**Note**: In order to run the same [scenario tests](test/scenarios) in both Node
and browser, we simulate the Cypress environment in Node, see [test/mocha-node-setup.js](test/mocha-node-setup.js).
The examples are run as part of the tests. You can set an `EXAMPLES_GITHUB_TOKEN` environment

@@ -156,0 +199,0 @@ variable (or set it in a `.env` file) to avoid running against GitHub's rate limit.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc