@anvilco/anvil
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -8,2 +8,6 @@ # Changelog | ||
## [v3.1.0] | ||
- Update `node-fetch` to latest and drop `form-data`. https://github.com/anvilco/node-anvil/issues/239 | ||
- Update various dependencies | ||
## [v3.0.1] | ||
@@ -10,0 +14,0 @@ - Fix "double-default" ESM exports, but also leave for backwards compatibility. https://github.com/anvilco/node-anvil/issues/354 |
@@ -5,5 +5,3 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _fs = _interopRequireDefault(require("fs")); | ||
var _formData = _interopRequireDefault(require("form-data")); | ||
var _abortController = _interopRequireDefault(require("abort-controller")); | ||
var _extractFiles = require("extract-files"); | ||
var _limiter = require("limiter"); | ||
@@ -20,2 +18,6 @@ | ||
class Warning extends Error {} | ||
let extractFiles; | ||
let FormDataModule; | ||
let Fetch; | ||
@@ -72,2 +74,6 @@ let fetch; | ||
const { | ||
@@ -214,3 +220,4 @@ mutations: { | ||
pathOrStreamLikeThing = _fs.default.createReadStream(pathOrStreamLikeThing); | ||
} else if ( | ||
@@ -221,2 +228,3 @@ !formDataAppendOptions || | ||
formDataAppendOptions.filename || ignoreFilenameValidation)) | ||
@@ -230,4 +238,10 @@ | ||
pathOrStreamLikeThing instanceof Buffer || | ||
!( | ||
!pathOrStreamLikeThing.path) | ||
pathOrStreamLikeThing.path && typeof pathOrStreamLikeThing.path === 'string' || | ||
pathOrStreamLikeThing.name && typeof pathOrStreamLikeThing.name === 'string')) | ||
{ | ||
@@ -442,6 +456,8 @@ let message = 'For this type of input, `options.filename` must be provided to prepareGraphQLFile.' + ' ' + FILENAME_IGNORE_MESSAGE; | ||
extractFiles ?? (extractFiles = (await import('extract-files/extractFiles.mjs')).default); | ||
const { | ||
clone: augmentedOperation, | ||
files: filesMap | ||
} = (0, _extractFiles.extractFiles)(originalOperation, '', _validation.isFile); | ||
} = extractFiles(originalOperation, _validation.isFile); | ||
@@ -458,4 +474,7 @@ const operationJSON = JSON.stringify(augmentedOperation); | ||
const abortController = new _abortController.default(); | ||
const form = new _formData.default(); | ||
Fetch ?? (Fetch = await import('node-fetch')); | ||
FormDataModule ?? (FormDataModule = await import('formdata-polyfill/esm.min.js')); | ||
const form = new FormDataModule.FormData(); | ||
form.append('operations', operationJSON); | ||
@@ -472,9 +491,16 @@ | ||
filesMap.forEach((paths, file) => { | ||
let appendOptions = {}; | ||
if (file instanceof _UploadWithOptions.default) { | ||
appendOptions = file.options; | ||
file = file.file; | ||
if (file instanceof _UploadWithOptions.default === false) { | ||
file = Anvil.prepareGraphQLFile(file); | ||
} | ||
let { filename, mimetype, ignoreFilenameValidation } = file.options || {}; | ||
file = file.file; | ||
if (!file) { | ||
throw new Error('No file provided. Options were: ' + JSON.stringify(options)); | ||
} | ||
if (typeof file.on === 'function') { | ||
@@ -488,4 +514,43 @@ file.on('error', (err) => { | ||
if (typeof file === 'string') { | ||
file = Fetch.fileFromSync(file, mimetype); | ||
} else if (file instanceof Buffer) { | ||
const buffer = file; | ||
form.append(`${++i}`, file, appendOptions); | ||
file = new Fetch.File( | ||
[buffer], | ||
filename, | ||
{ | ||
type: mimetype | ||
} | ||
); | ||
} else if (file instanceof _stream.Stream) { | ||
const stream = file; | ||
file = { | ||
[Symbol.toStringTag]: 'File', | ||
size: _fs.default.statSync(stream.path).size, | ||
stream: () => stream, | ||
type: mimetype | ||
}; | ||
filename ?? (filename = stream.path.split('/').pop()); | ||
} else if (file.constructor.name !== 'File') { | ||
if (!filename) { | ||
const name = file.name || file.path; | ||
if (name) { | ||
filename = name.split('/').pop(); | ||
} | ||
if (!filename && !ignoreFilenameValidation) { | ||
console.warn(new Warning('No filename provided. Please provide a filename to the file options.')); | ||
} | ||
} | ||
} | ||
form.append(`${++i}`, file, filename); | ||
}); | ||
@@ -492,0 +557,0 @@ |
{ | ||
"name": "@anvilco/anvil", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Anvil API Client", | ||
@@ -43,3 +43,3 @@ "author": "Anvil Foundry Inc.", | ||
"clean": "yarn rimraf ./dist", | ||
"prepare": "yarn clean && yarn build", | ||
"prepare": "yarn tsc && yarn clean && yarn build", | ||
"test": "yarn prepare && mocha --config ./test/mocha.js", | ||
@@ -55,6 +55,5 @@ "lint": "eslint src/**/*.js test/**/*.js", | ||
"abort-controller": "^3.0.0", | ||
"extract-files": "^11", | ||
"form-data": "^4.0.0", | ||
"extract-files": "^13", | ||
"limiter": "^2.1.0", | ||
"node-fetch": "3.0.x" | ||
"node-fetch": "^3.3.2" | ||
}, | ||
@@ -85,3 +84,3 @@ "devDependencies": { | ||
"rimraf": "^5.0.0", | ||
"sinon": "^15.0.1", | ||
"sinon": "^16.0.0", | ||
"sinon-chai": "^3.5.0", | ||
@@ -88,0 +87,0 @@ "typescript": "^5.0.4", |
@@ -364,8 +364,15 @@ ![Horizontal Lockupblack](https://user-images.githubusercontent.com/293079/169453889-ae211c6c-7634-4ccd-8ca9-8970c2621b6f.png#gh-light-mode-only) | ||
A nice helper to prepare a Stream-backed or Buffer-backed file upload for use with our GraphQL API. By default, this will upload your files as multipart uploads over the [jaydenseric / GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec). NOTE: Please see below about certain scenarios where you may need to manually provide a `filename`. | ||
A nice helper to prepare a [File](https://developer.mozilla.org/en-US/docs/Web/API/File) upload for use with our GraphQL API. By default, this will upload your files as multipart uploads over the [jaydenseric / GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec). We use `node-fetch` under the hood, and you can see [this example](https://github.com/node-fetch/node-fetch#post-data-using-a-file) to get a bit of an understanding of what's happening behind the scenes. NOTE: Please see below about certain scenarios where you may need to manually provide a `filename`. | ||
* `pathOrStreamLikeThing` (String | Stream | Buffer) - An existing `Stream`, `Buffer` or other Stream-like thing supported by [FormData.append](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-) OR a string representing a fully resolved path to a file to be read into a new `Stream`. | ||
* `options` (Object) - Anything supported by [FormData.append](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-). Required when providing a vanilla ReadStream or Buffer. From the `form-data` docs: | ||
> Form-Data can recognize and fetch all the required information from common types of streams (fs.readStream, http.response and mikeal's request), for some other types of streams you'd need to provide "file"-related information manually | ||
* `pathOrSupportedInstance` (String | File | Blob | Stream | Buffer) - Can be one of several things. Here's a list of what's supported, in order of preference: | ||
1. A `File` instance. | ||
1. A `Blob` instance. | ||
1. A `string` that is a path to a file to be used. | ||
1. A `ReadStream` instance that must either have either: | ||
1. A `path` property (this will usually be present when the stream was loaded from the local file system) | ||
1. A `filename` provided in the `options` parameter. | ||
1. A `Buffer` instance with a `filename` provided in the `options` parameter. | ||
* `options` (Object) - Options that may be required when providing certain types of values as the first parameter. For example, `Blob`s, `Buffer`s and certain kinds of `ReadStream`s will not have any notion of what the name of the file is or should be when uploaded. | ||
* `filename` (String) - Override the filename of the uploaded file here. If providing a generic ReadStream or Buffer, you will be required to provide a filename here | ||
* `mimetype` (String) - Optional mimetype to specify with the resulting file that can be used when a `string` path, `Buffer` or `ReadStream` are provided as the first parameter. | ||
* Returns an `Object` that is properly formatted to be coerced by the client for use against our GraphQL API wherever an `Upload` type is required. | ||
@@ -372,0 +379,0 @@ |
@@ -5,12 +5,12 @@ const path = require('path') | ||
const Anvil = require('../src/index') | ||
const Anvil = require('../dist/index').default | ||
// Local Dev | ||
// const apiKey = 'AXZj09jvHRPNBFRHMnAF2jpwOx9J5Rb6' | ||
const apiKey = '7R3ElJ1sGusHS3eQAiRUKG6QjhSQ1IHE' | ||
// Prod Mango Dev | ||
const apiKey = 'oBU3hec1pdBRGB5NmSJaj7QQzhiME1u8' | ||
// const apiKey = 'oBU3hec1pdBRGB5NmSJaj7QQzhiME1u8' | ||
// | ||
// const [eid, apiKey, jsonPath] = argv._ | ||
let baseURL | ||
// baseURL = 'http://localhost:3000' | ||
baseURL = 'http://localhost:3000' | ||
// baseURL = 'https://outlook.office.com/webhook/' | ||
@@ -21,3 +21,3 @@ | ||
// cookie: 'koa:sess=c2a23c802c7c9e09016378f74ef1ee1d; koa:sess.sig=PO0AfdOUgUcsLFhFLbaz7QgGncU', | ||
// baseURL, | ||
baseURL, | ||
// userAgent, | ||
@@ -24,0 +24,0 @@ debug: true, |
@@ -5,3 +5,3 @@ const { client } = require('./base') | ||
const path = require('path') | ||
const Anvil = require('../src/index') | ||
const Anvil = require('../dist/index').default | ||
@@ -45,5 +45,9 @@ // const argv = require('yargs') | ||
msg: 'Complain about filename.split, please', | ||
filePath: fs.readFileSync(pdfFile), | ||
filePath: pdfFile, | ||
// filePath: fs.readFileSync(pdfFile), | ||
// filePath: fs.createReadStream(pdfFile), | ||
formDataAppendOptions: { | ||
filename: 'foo.pdf', | ||
// filename: 'foof.pdf', | ||
// mimetype: 'image/png', | ||
mimetype: 'application/pdf', | ||
}, | ||
@@ -135,6 +139,6 @@ }, | ||
console.log({ | ||
filePath, | ||
formDataAppendOptions, | ||
}) | ||
// console.log({ | ||
// filePath, | ||
// formDataAppendOptions, | ||
// }) | ||
@@ -149,2 +153,4 @@ const file = Anvil.prepareGraphQLFile(filePath, formDataAppendOptions) | ||
eid | ||
name | ||
title | ||
} | ||
@@ -154,3 +160,3 @@ }`, | ||
organizationEid, | ||
title: 'foo bar', | ||
title: 'fooey bar', | ||
file, | ||
@@ -157,0 +163,0 @@ isTemplate: true, |
@@ -5,5 +5,3 @@ import fs from 'fs' | ||
import FormData from 'form-data' | ||
import AbortController from 'abort-controller' | ||
import { extractFiles } from 'extract-files' | ||
import { RateLimiter } from 'limiter' | ||
@@ -20,2 +18,6 @@ | ||
class Warning extends Error {} | ||
let extractFiles | ||
let FormDataModule | ||
let Fetch | ||
@@ -70,2 +72,6 @@ let fetch | ||
/** @typedef {{ | ||
path: string | ||
}} Readable */ | ||
// Ignoring the below since they are dynamically created depepending on what's | ||
@@ -202,3 +208,3 @@ // inside the `src/graphql` directory. | ||
* | ||
* @param {string|Buffer} pathOrStreamLikeThing - Either a string path to a file, | ||
* @param {string|Buffer|Readable|File|Blob} pathOrStreamLikeThing - Either a string path to a file, | ||
* a Buffer, or a Stream-like thing that is compatible with form-data as an append. | ||
@@ -215,3 +221,4 @@ * @param {Object} [formDataAppendOptions] - User can specify options to be passed to the form-data.append | ||
// @ts-ignore | ||
pathOrStreamLikeThing = fs.createReadStream(pathOrStreamLikeThing) | ||
// no-op for this logic path. It's a path and we will load it later and it will at least | ||
// have the file's name as a filename to possibly use. | ||
} else if ( | ||
@@ -221,3 +228,4 @@ !formDataAppendOptions || | ||
formDataAppendOptions && !( | ||
// Require the filename or the ignoreFilenameValidation option. | ||
// Require the filename or the ignoreFilenameValidation option. This is an escape hatch | ||
// for things we didn't anticipate to cause problems | ||
formDataAppendOptions.filename || ignoreFilenameValidation | ||
@@ -231,4 +239,10 @@ ) | ||
pathOrStreamLikeThing instanceof Buffer || | ||
// Some stream things have the path in them | ||
!pathOrStreamLikeThing.path | ||
!( | ||
// Some stream things have a string path in them (can also be a buffer, but we want/need string) | ||
// @ts-ignore | ||
(pathOrStreamLikeThing.path && typeof pathOrStreamLikeThing.path === 'string') || | ||
// A File might look like this | ||
// @ts-ignore | ||
(pathOrStreamLikeThing.name && typeof pathOrStreamLikeThing.name === 'string') | ||
) | ||
) { | ||
@@ -443,6 +457,8 @@ let message = 'For this type of input, `options.filename` must be provided to prepareGraphQLFile.' + ' ' + FILENAME_IGNORE_MESSAGE | ||
extractFiles ??= (await import('extract-files/extractFiles.mjs')).default | ||
const { | ||
clone: augmentedOperation, | ||
files: filesMap, | ||
} = extractFiles(originalOperation, '', isFile) | ||
} = extractFiles(originalOperation, isFile) | ||
@@ -459,3 +475,6 @@ const operationJSON = JSON.stringify(augmentedOperation) | ||
const abortController = new AbortController() | ||
const form = new FormData() | ||
Fetch ??= await import('node-fetch') | ||
// This is a dependency of 'node-fetch'` | ||
FormDataModule ??= await import('formdata-polyfill/esm.min.js') | ||
const form = new FormDataModule.FormData() | ||
@@ -473,7 +492,14 @@ form.append('operations', operationJSON) | ||
filesMap.forEach((paths, file) => { | ||
let appendOptions = {} | ||
if (file instanceof UploadWithOptions) { | ||
appendOptions = file.options | ||
file = file.file | ||
// Ensure that the file has been run through the prepareGraphQLFile process | ||
// and checks | ||
if (file instanceof UploadWithOptions === false) { | ||
file = Anvil.prepareGraphQLFile(file) | ||
} | ||
let { filename, mimetype, ignoreFilenameValidation } = file.options || {} | ||
file = file.file | ||
if (!file) { | ||
throw new Error('No file provided. Options were: ' + JSON.stringify(options)) | ||
} | ||
// If this is a stream-like thing, attach a listener to the 'error' event so that we | ||
@@ -488,5 +514,44 @@ // can cancel the API call if something goes wrong | ||
// Pass in some things explicitly to the form.append so that we get the | ||
// desired/expected filename and mimetype, etc | ||
form.append(`${++i}`, file, appendOptions) | ||
// If file a path to a file? | ||
if (typeof file === 'string') { | ||
file = Fetch.fileFromSync(file, mimetype) | ||
} else if (file instanceof Buffer) { | ||
const buffer = file | ||
// https://developer.mozilla.org/en-US/docs/Web/API/File/File | ||
file = new Fetch.File( | ||
[buffer], | ||
filename, | ||
{ | ||
type: mimetype, | ||
}, | ||
) | ||
} else if (file instanceof Stream) { | ||
// https://github.com/node-fetch/node-fetch#post-data-using-a-file | ||
const stream = file | ||
file = { | ||
[Symbol.toStringTag]: 'File', | ||
// @ts-ignore | ||
size: fs.statSync(stream.path).size, | ||
stream: () => stream, | ||
type: mimetype, | ||
} | ||
// @ts-ignore | ||
filename ??= stream.path.split('/').pop() | ||
} else if (file.constructor.name !== 'File') { | ||
// Like a Blob or something | ||
if (!filename) { | ||
const name = file.name || file.path | ||
if (name) { | ||
filename = name.split('/').pop() | ||
} | ||
if (!filename && !ignoreFilenameValidation) { | ||
console.warn(new Warning('No filename provided. Please provide a filename to the file options.')) | ||
} | ||
} | ||
} | ||
// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append | ||
form.append(`${++i}`, file, filename) | ||
}) | ||
@@ -493,0 +558,0 @@ |
@@ -5,3 +5,2 @@ import fs from 'fs' | ||
import { RateLimiter } from 'limiter' | ||
import FormData from 'form-data' | ||
import { AbortSignal } from 'abort-controller' | ||
@@ -53,3 +52,9 @@ | ||
let FormDataModule | ||
describe('Anvil API Client', function () { | ||
before(async function () { | ||
FormDataModule ??= await import('formdata-polyfill/esm.min.js') | ||
}) | ||
beforeEach(function () { | ||
@@ -516,3 +521,3 @@ sinon.stub(Anvil.prototype, '_throttle').callsFake(fakeThrottle) | ||
describe('without files', function () { | ||
it('stringifies query and variables', function () { | ||
it('stringifies query and variables', async function () { | ||
const query = { foo: 'bar' } | ||
@@ -522,3 +527,3 @@ const variables = { baz: 'bop' } | ||
client.requestGraphQL({ query, variables }, clientOptions) | ||
await client.requestGraphQL({ query, variables }, clientOptions) | ||
@@ -548,3 +553,3 @@ expect(client._wrapRequest).to.have.been.calledOnce | ||
beforeEach(function () { | ||
sinon.spy(FormData.prototype, 'append') | ||
sinon.spy(FormDataModule.FormData.prototype, 'append') | ||
}) | ||
@@ -557,2 +562,7 @@ | ||
afterEach(function () { | ||
if ($.willFail) { | ||
expect(client._wrapRequest).to.not.have.been.called | ||
return | ||
} | ||
expect(client._wrapRequest).to.have.been.calledOnce | ||
@@ -584,6 +594,6 @@ | ||
expect(headers).to.eql({}) // node-fetch will add appropriate header | ||
expect(body).to.be.an.instanceof(FormData) | ||
expect(body).to.be.an.instanceof(FormDataModule.FormData) | ||
expect(signal).to.be.an.instanceof(AbortSignal) | ||
expect( | ||
FormData.prototype.append.withArgs( | ||
FormDataModule.FormData.prototype.append.withArgs( | ||
'map', | ||
@@ -596,12 +606,26 @@ JSON.stringify({ 1: ['variables.aNested.file'] }), | ||
context('file is a Buffer', function () { | ||
context('using a Buffer', function () { | ||
def('variables', () => ({ | ||
aNested: { | ||
file: Buffer.from(''), | ||
file: Anvil.prepareGraphQLFile(Buffer.from(''), { filename: 'test.pdf' }), | ||
}, | ||
})) | ||
it('creates a FormData and appends the files map', function () { | ||
client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
it('creates a FormData and appends the files map when prepareGraphQLFile was used', async function () { | ||
await client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
}) | ||
context('file is a Buffer', function () { | ||
def('willFail', () => true) | ||
def('variables', () => ({ | ||
aNested: { | ||
file: Buffer.from(''), | ||
}, | ||
})) | ||
it('throws an error creating a FormData and appending to the files map when a raw Buffer is used', async function () { | ||
await expect(client.requestGraphQL({ query, variables: $.variables }, clientOptions)) | ||
.to.eventually.be.rejectedWith('When passing a Buffer to prepareGraphQLFile, `options.filename` must be provided') | ||
}) | ||
}) | ||
}) | ||
@@ -619,4 +643,4 @@ | ||
it('creates a FormData and appends the files map', function () { | ||
client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
it('creates a FormData and appends the files map', async function () { | ||
await client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
}) | ||
@@ -639,4 +663,4 @@ }) | ||
it('does not touch the variables at all', function () { | ||
client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
it('does not touch the variables at all', async function () { | ||
await client.requestGraphQL({ query, variables: $.variables }, clientOptions) | ||
}) | ||
@@ -667,7 +691,7 @@ }) | ||
context('mutation is specified', function () { | ||
it('calls requestGraphQL with overridden mutation', function () { | ||
it('calls requestGraphQL with overridden mutation', async function () { | ||
const variables = { foo: 'bar' } | ||
const mutationOverride = 'createEtchPacketOverride()' | ||
client.createEtchPacket({ variables, mutation: mutationOverride }) | ||
await client.createEtchPacket({ variables, mutation: mutationOverride }) | ||
@@ -689,6 +713,6 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
context('no responseQuery specified', function () { | ||
it('calls requestGraphQL with default responseQuery', function () { | ||
it('calls requestGraphQL with default responseQuery', async function () { | ||
const variables = { foo: 'bar' } | ||
client.createEtchPacket({ variables }) | ||
await client.createEtchPacket({ variables }) | ||
@@ -710,7 +734,7 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
context('responseQuery specified', function () { | ||
it('calls requestGraphQL with overridden responseQuery', function () { | ||
it('calls requestGraphQL with overridden responseQuery', async function () { | ||
const variables = { foo: 'bar' } | ||
const responseQuery = 'onlyInATest {}' | ||
client.createEtchPacket({ variables, responseQuery }) | ||
await client.createEtchPacket({ variables, responseQuery }) | ||
@@ -788,3 +812,3 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
it('calls requestGraphQL with default responseQuery', async function () { | ||
client.getEtchPacket({ variables: $.variables }) | ||
await client.getEtchPacket({ variables: $.variables }) | ||
@@ -808,3 +832,3 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
const responseQuery = 'myCustomResponseQuery' | ||
client.getEtchPacket({ variables: $.variables, responseQuery }) | ||
await client.getEtchPacket({ variables: $.variables, responseQuery }) | ||
@@ -831,7 +855,7 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
it('calls requestGraphQL with overridden mutation', function () { | ||
it('calls requestGraphQL with overridden mutation', async function () { | ||
const variables = { foo: 'bar' } | ||
const mutationOverride = 'forgeSubmitOverride()' | ||
client.forgeSubmit({ variables, mutation: mutationOverride }) | ||
await client.forgeSubmit({ variables, mutation: mutationOverride }) | ||
@@ -853,3 +877,3 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
const variables = { foo: 'bar' } | ||
client.forgeSubmit({ variables }) | ||
await client.forgeSubmit({ variables }) | ||
@@ -872,3 +896,3 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
const customResponseQuery = 'myCustomResponseQuery' | ||
client.forgeSubmit({ variables, responseQuery: customResponseQuery }) | ||
await client.forgeSubmit({ variables, responseQuery: customResponseQuery }) | ||
@@ -894,7 +918,7 @@ expect(client.requestGraphQL).to.have.been.calledOnce | ||
it('calls requestGraphQL with overridden mutation', function () { | ||
it('calls requestGraphQL with overridden mutation', async function () { | ||
const variables = { foo: 'bar' } | ||
const mutationOverride = 'removeWeldDataOverride()' | ||
client.removeWeldData({ variables, mutation: mutationOverride }) | ||
await client.removeWeldData({ variables, mutation: mutationOverride }) | ||
@@ -901,0 +925,0 @@ expect(client.requestGraphQL).to.have.been.calledOnce |
@@ -7,6 +7,4 @@ { | ||
"compilerOptions": { | ||
"target": "es2021", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"lib": ["es2017", "dom"], | ||
"module": "node16", | ||
"moduleResolution": "node16", | ||
"noImplicitThis": true, | ||
@@ -13,0 +11,0 @@ "alwaysStrict": true, |
@@ -1,4 +0,3 @@ | ||
import mutations = require("./mutations"); | ||
import queries = require("./queries"); | ||
export { mutations, queries }; | ||
export * as queries from "./queries"; | ||
export * as mutations from "./mutations"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,5 @@ | ||
declare const _exports: {}; | ||
export = _exports; | ||
export * as createEtchPacket from "./createEtchPacket"; | ||
export * as forgeSubmit from "./forgeSubmit"; | ||
export * as generateEtchSignUrl from "./generateEtchSignUrl"; | ||
export * as removeWeldData from "./removeWeldData"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,2 @@ | ||
declare const _exports: {}; | ||
export = _exports; | ||
export * as etchPacket from "./etchPacket"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,44 @@ | ||
export = Anvil; | ||
export default Anvil; | ||
export type AnvilOptions = { | ||
apiKey?: string; | ||
accessToken?: string; | ||
baseURL?: string; | ||
userAgent?: string; | ||
requestLimit?: number; | ||
requestLimitMS?: number; | ||
}; | ||
export type GraphQLResponse = { | ||
statusCode: number; | ||
data?: GraphQLResponseData; | ||
errors?: Array<ResponseError>; | ||
}; | ||
export type GraphQLResponseData = { | ||
data: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
export type RESTResponse = { | ||
statusCode: number; | ||
data?: Buffer | Stream | any; | ||
errors?: Array<ResponseError>; | ||
/** | ||
* node-fetch Response | ||
*/ | ||
response?: any; | ||
}; | ||
export type ResponseError = { | ||
[key: string]: any; | ||
message: string; | ||
status?: number; | ||
name?: string; | ||
fields?: Array<ResponseErrorField>; | ||
}; | ||
export type ResponseErrorField = { | ||
[key: string]: any; | ||
message: string; | ||
property?: string; | ||
}; | ||
export type Readable = { | ||
path: string; | ||
}; | ||
declare class Anvil { | ||
@@ -7,3 +49,3 @@ /** | ||
* | ||
* @param {string|Buffer} pathOrStreamLikeThing - Either a string path to a file, | ||
* @param {string|Buffer|Readable|File|Blob} pathOrStreamLikeThing - Either a string path to a file, | ||
* a Buffer, or a Stream-like thing that is compatible with form-data as an append. | ||
@@ -17,3 +59,3 @@ * @param {Object} [formDataAppendOptions] - User can specify options to be passed to the form-data.append | ||
*/ | ||
static prepareGraphQLFile(pathOrStreamLikeThing: string | Buffer, formDataAppendOptions?: any): UploadWithOptions; | ||
static prepareGraphQLFile(pathOrStreamLikeThing: string | Buffer | Readable | File | Blob, { ignoreFilenameValidation, ...formDataAppendOptions }?: any): UploadWithOptions; | ||
/** | ||
@@ -140,2 +182,3 @@ * @param {AnvilOptions?} options | ||
requestREST(url: string, fetchOptions: any, clientOptions?: any): Promise<RESTResponse>; | ||
_request(...args: any[]): any; | ||
/** | ||
@@ -147,3 +190,3 @@ * @param {string} url | ||
*/ | ||
private _request; | ||
private __request; | ||
/** | ||
@@ -185,48 +228,11 @@ * @param {CallableFunction} retryableRequestFn | ||
declare namespace Anvil { | ||
export { UploadWithOptions, VERSION_LATEST, VERSION_LATEST_PUBLISHED, AnvilOptions, GraphQLResponse, GraphQLResponseData, RESTResponse, ResponseError, ResponseErrorField }; | ||
export { UploadWithOptions }; | ||
export { VERSION_LATEST }; | ||
export { VERSION_LATEST_PUBLISHED }; | ||
} | ||
import { RateLimiter } from "limiter/dist/cjs/RateLimiter"; | ||
type GraphQLResponse = { | ||
statusCode: number; | ||
data?: GraphQLResponseData; | ||
errors?: Array<ResponseError>; | ||
}; | ||
type RESTResponse = { | ||
statusCode: number; | ||
data?: Buffer | Stream | any; | ||
errors?: Array<ResponseError>; | ||
/** | ||
* node-fetch Response | ||
*/ | ||
response?: any; | ||
}; | ||
type ResponseError = { | ||
[key: string]: any; | ||
message: string; | ||
status?: number; | ||
name?: string; | ||
fields?: Array<ResponseErrorField>; | ||
}; | ||
import UploadWithOptions = require("./UploadWithOptions"); | ||
type AnvilOptions = { | ||
apiKey?: string; | ||
accessToken?: string; | ||
baseURL?: string; | ||
userAgent?: string; | ||
requestLimit?: number; | ||
requestLimitMS?: number; | ||
}; | ||
import { Stream } from 'stream'; | ||
import { RateLimiter } from 'limiter'; | ||
import UploadWithOptions from './UploadWithOptions'; | ||
declare const VERSION_LATEST: -1; | ||
declare const VERSION_LATEST_PUBLISHED: -2; | ||
type GraphQLResponseData = { | ||
data: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
type ResponseErrorField = { | ||
[key: string]: any; | ||
message: string; | ||
property?: string; | ||
}; | ||
import { Stream } from "stream"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,2 @@ | ||
export = UploadWithOptions; | ||
declare class UploadWithOptions { | ||
export default class UploadWithOptions { | ||
constructor(streamLikeThing: any, formDataAppendOptions: any); | ||
@@ -4,0 +3,0 @@ streamLikeThing: any; |
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
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
Sorry, the diff of this file is not supported yet
3554921
4
4627
432
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedextract-files@13.0.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
- Removedform-data@^4.0.0
- Removedasynckit@0.4.0(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddata-uri-to-buffer@3.0.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedextract-files@11.0.0(transitive)
- Removedform-data@4.0.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednode-fetch@3.0.0(transitive)
Updatedextract-files@^13
Updatednode-fetch@^3.3.2