Bot releases are hidden (Show)
Mainly a fix for m3api-oauth2 after changes in MediaWiki.
Published by lucaswerkmeister 6 months ago
MediaWiki-API-Error
response header is present to indicate that the response represents a regular error and not an internal error. (The status code is ignored; the response body is expected to contain a response with one or more regular errors.)Published by lucaswerkmeister 11 months ago
Published by lucaswerkmeister over 1 year ago
More modern Node requirement, file upload support.
add-performance-global.js
has been removed, as it is no longer needed.axios.js
has been removed, as axios is no longer used. Its role has been taken over by fetch-node.js
.fetch.js
is no longer suitable for use in Chrome-like browsers. The functionality of renaming the user-agent
request header to api-user-agent
has been moved to fetch-browser.js
.fetch()
on all supported platforms. The public interface, browser.js
and node.js
, can be used as before. The internal interface has been rearranged, with fetch.js
now used for both backends, augmented by fetch-browser.js
and fetch-node.js
.Blob
and File
parameters in POST requests. This can be used to upload files.README.md
formatting for npmjs.com.Published by lucaswerkmeister over 1 year ago
Custom error handler support for m3api-oauth2.
errorHandlers
option can be used to customize error handling. It is only part of the internal interface, not of the stable, public interface. Using this options, extension packages or end users can register handlers for certain API error codes; the handlers can e.g. perform necessary cleanup actions and/or retry the request. The existing support for retrying after maxlag
, readonly
or badtoken
errors is now also internally implemented in terms of this new option.Published by lucaswerkmeister almost 2 years ago
internalGet()
and internalPost()
methods has changed; an apiUrl
string has been addded as the first parameter, and the last parameter is now a headers
object instead of a userAgent
string. The apiUrl
should always be used instead of this.apiUrl
. In headers
, the header names are always in all-lowercase, so you can safely get the userAgent
value as headers['user-agent']
.authorization
request option can be used to set an Authorization:
request header. This will be used by the upcoming m3api-oauth2 package to support OAuth 2.0; you can also use it directly using the access token of an owner-only client.apiUrl
member of a Session
is now public. This will be used by m3api-oauth2.getUserAgent()
, can be used to get the user agent for a request. This will be used by m3api-oauth2.dropTruncatedResultWarning
didn’t work properly when using the default errorformat
on current MediaWiki versions; this has been fixed. (It’s still a good idea to set a non-bc
error format in general.)Published by lucaswerkmeister almost 2 years ago
Documentation-only release.
@typedef
for Options
, the request options; this may help if you are using m3api with TypeScript or in an IDE.Published by lucaswerkmeister almost 2 years ago
maxRetriesSeconds
, limits the total duration of retried requests, replacing the previousmaxRetries
option that limited the number of retried requests. It defaults to 65 seconds, which should be enough to cover a typicalmaxRetries
option should no longer be used.tokenType
and tokenName
. The most common case, e.g. for action=edit
, is to use tokenType: 'csrf'
with the default tokenName
('token'
). m3api will automatically fetch and cache the token (and this internal request can be automatically combined with other action=query
requests), discarding stale tokens and retrying upon encountering a badtoken
error. Tokens are cached in the public Session.tokens
Map, which users and extension packages are encouraged to clear()
after changing the session state (e.g. login), to avoid the overhead of a badtoken
error. (Note that the m3api-botpassword extension package does this for you.)Session.defaultParams
, Session.defaultOptions
and DEFAULT_OPTIONS
have been declared public, and extension packages are encouraged to use the latter two for their own options as well. Guidelines for extension packages have also been added to the README.maxlag
or readonly
errors are now automatically retried, even if the response did not include a Retry-After
response header. (Currently, MediaWiki only sends this header for maxlag
errors.) Two new request options, retryAfterMaxlagSeconds
and retryAfterReadonlySeconds
, control the default retry delay (in seconds) for these errors. The defaults of 5 and 30 seconds respectively are intended to be useful for Wikimedia wikis. If you increase these values, don’t forget to increase maxRetriesSeconds
as well.axios.js
) now keeps the network connection alive (using Node’s default Keep-Alive settings), which can speed up consecutive API requests (e.g. to get and then use a token). Requests with technically different options can be combined in some more situations. Specifically, a request explicitly specifying a default option is compatible with one not specifying the option at all (both will use the default), and the dropTruncatedResultWarning
option does not affect compatibility at all (the option is handled while combining requests, so that truncated result warnings are only sent to the correct requests).Published by lucaswerkmeister over 2 years ago
Add dropTruncatedResultWarning
option for m3api-query.
dropTruncatedResultWarning
, is available. Previously, this behavior was hard-coded in requestAndContinueReducingBatch()
; now, it can be optionally enabled in request()
and requestAndContinue()
, or disabled in requestAndContinueReducingBatch()
. By default, the option is enabled in the latter function and disbled in the former two, so there is no change in behavior unless you set the option with a request.Published by lucaswerkmeister over 2 years ago
warn
handler (using the second constructor argument, next to the userAgent
option), so that warnings are not shown to end users. You should make sure that the warnings still reach the developers, though.continue
member; continuation now always proceeds according to the original continue
contents. The fact that this previously worked was not intended, and if any code actually behaves differently due to this change, it is assumed that the previous behavior was a bug rather than intended. If you really want to modify continuation, implement it yourself instead of using requestAndContinue
.requestAndContinueReducingBatch
, is available to work with continuation. It is useful in cases where data for a batchbatchcomplete
. (An example isaxios.js
) now requests gzip compression of the response from the server, which should reducePublished by lucaswerkmeister almost 3 years ago
Abbreviate api.php
URL as domain, warn on requests without user agent.
BREAKING CHANGE (internal): The Session
constructor now requires the default request options to include warn
, which must be a function. The fetch.js
and axios.js
backends already add a default for this option, so this is only relevant for you if you wrote a custom network implementation; if you just import browser.js
or node.js
, it doesn’t matter.
The first constructor argument can now be a domain name instead of a full api.php
URL, e.g. en.wikipedia.org
instead of
https://en.wikipedia.org/w/api.php
.
Requests that do not specify a user agent will now trigger a warning, limited to once per session. If you see this warning, you should add a
user agent to your requests – see the User-Agent policy. Usually you would add it to the default options at construction time:
const session = new Session( 'en.wikipedia.org', {
formatversion: 2,
// other default params...
}, {
userAgent: 'my-cool-tool',
// other default options...
} );
But it can also be specified for an individual request:
const response = await session.request( {
action: 'query',
// other params...
}, {
userAgent: 'my-cool-tool',
// other options...
} );
Recall that the default warning handler is console.warn
in the browser, and also in Node.js if NODE_ENV = “development” is set, but otherwise the Node.js backend ignores warnings.
Published by lucaswerkmeister almost 3 years ago
More consistent constructor signature, support for API warnings.
userAgent
key. Convert constructor calls like new Session( ..., {}, 'user-agent' )
to new Session( ..., {}, { userAgent: 'user-agent' } )
instead.internalGet
and internalPost
methods now receive an additional parameter, the user agent string,browser.js
or node.js
, it doesn’t matter.userAgent
request option can now specified for an individual request if you want to, and conversely other options like maxRetries
can be defaulted in the constructor.warn
request option, which can be used to handle warnings from a request. In the browser, and with NODE_ENV = “development” in Node.js, warnings are sent to the console by default. If you use the Node.js backend, but not for a CLI application, consider logging warnings regardless of environment by adding warn: console.warn
to the default request options (or use a custom warning handler).responseBoolean
utility function, to get a boolean out of a response value regardless of formatversion
.Published by lucaswerkmeister about 3 years ago
set()
helper as a namedset( ... )
instead of [ ... ]
for list-like parameters where additional values from other requests can be safely added, such as action=query
’s prop
, list
and meta
parameters. For more information, see the updated README, especially the new “automatically combining requests” section.Published by lucaswerkmeister about 3 years ago
Security update.
Published by lucaswerkmeister about 3 years ago
First proper update over a previous release.
internalGet
and internalPost
methods now return additional data. This is only relevant for you if you wrote a custom network implementation; if you just import browser.js
or node.js
, it doesn’t matter.maxRetries
request option.Published by lucaswerkmeister about 3 years ago
No change from v0.1.1 apart from the version number.
Published by lucaswerkmeister about 3 years ago
This is the initial release of the library, as presented at the 2021 Wikimania Hackathon Showcase. It supports basic API requests, continuation, error detection, cookie jars in axios, and more.