Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

masto

Package Overview
Dependencies
Maintainers
1
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

masto - npm Package Compare versions

Comparing version 6.0.0-alpha.7 to 6.0.0-alpha.8

76

dist/index.js

@@ -186,4 +186,3 @@ import { snakeCase, camelCase } from 'change-case';

this.meta = meta;
const hasMinId = nextParams && typeof nextParams === "object" && "minId" in nextParams;
this.rel = hasMinId ? "prev" : "next";
this.direction = "next";
}

@@ -199,9 +198,6 @@ next() {

this.nextParams = nextUrl === null || nextUrl === void 0 ? void 0 : nextUrl.search.replace(/^\?/, "");
const data = response.data;
const value = this.rel === "prev" && Array.isArray(data)
? data.reverse()
: response.data;
const data = (yield response.data);
return {
done: false,
value: value,
value: data,
};

@@ -232,2 +228,10 @@ });

}
getDirection() {
return this.direction;
}
setDirection(direction) {
const that = this.clone();
that.direction = direction;
return that;
}
[Symbol.asyncIterator]() {

@@ -241,3 +245,3 @@ return this;

}
const parsed = (_b = (_a = parseLinkHeader(value)) === null || _a === void 0 ? void 0 : _a[this.rel]) === null || _b === void 0 ? void 0 : _b.url;
const parsed = (_b = (_a = parseLinkHeader(value)) === null || _a === void 0 ? void 0 : _a[this.direction]) === null || _b === void 0 ? void 0 : _b.url;
if (parsed == undefined) {

@@ -397,7 +401,5 @@ return;

class WebSocketConnectorImpl {
constructor(params, logger, implementation, maxAttempts) {
this.params = params;
constructor(props, logger) {
this.props = props;
this.logger = logger;
this.implementation = implementation;
this.maxAttempts = maxAttempts;
this.queue = [];

@@ -422,4 +424,4 @@ this.disableRetry = false;

{
const ctor = ((_f = this.implementation) !== null && _f !== void 0 ? _f : WebSocket);
const ws = new ctor(...this.params);
const ctor = ((_f = this.props.implementation) !== null && _f !== void 0 ? _f : WebSocket);
const ws = new ctor(...this.props.constructorParameters);
yield waitForOpen(ws);

@@ -453,3 +455,3 @@ this.ws = ws;

for (const { reject } of this.queue) {
reject(new MastoWebSocketError(`Failed to connect to WebSocket after ${this.maxAttempts} attempts`));
reject(new MastoWebSocketError(`Failed to connect to WebSocket after ${this.props.maxAttempts} attempts`));
}

@@ -459,3 +461,3 @@ this.queue = [];

this.backoff = new ExponentialBackoff({
maxAttempts: this.maxAttempts,
maxAttempts: this.props.maxAttempts,
});

@@ -554,3 +556,3 @@ }

try {
for (var _g = true, _h = (e_1 = void 0, __asyncValues(this.mapEvents(messages))), _j; _j = yield __await(_h.next()), _d = _j.done, !_d; _g = true) {
for (var _g = true, _h = (e_1 = void 0, __asyncValues(this.transformIntoEvents(messages))), _j; _j = yield __await(_h.next()), _d = _j.done, !_d; _g = true) {
_f = _j.value;

@@ -582,6 +584,9 @@ _g = false;

}
[Symbol.asyncIterator]() {
return this.values();
}
matches(event) {
var _a;
// subscribe("hashtag", { tag: "foo" }) -> ["hashtag", "foo"]
// subscribe("list", { list: "foo" }) -> ["list", "foo"]
// subscribe("list", { list: "foo" }) -> ["list", "foo"]
const params = (_a = this.params) !== null && _a !== void 0 ? _a : {};

@@ -592,7 +597,4 @@ const extra = Object.values(params);

}
[Symbol.asyncIterator]() {
return this.values();
}
mapEvents(messages) {
return __asyncGenerator(this, arguments, function* mapEvents_1() {
transformIntoEvents(messages) {
return __asyncGenerator(this, arguments, function* transformIntoEvents_1() {
var _a, e_2, _b, _c;

@@ -647,2 +649,5 @@ try {

}
if (action.type === "prepare") {
return this.connector.acquire();
}
if (action.type !== "subscribe") {

@@ -802,3 +807,3 @@ throw new MastoUnexpectedError("Unknown action type");

resolvePath(path, params = {}) {
const url = new URL(path, this.props.url);
const url = new URL(path, this.props.streamingApiUrl);
if (this.props.useInsecureAccessToken) {

@@ -1131,6 +1136,6 @@ params.accessToken = this.props.accessToken;

const createRestClient = (props) => {
const createRestAPIClient = (props) => {
const serializer = new SerializerNativeImpl();
const config = new HttpConfigImpl(props, serializer);
const logger = createLogger(props.logLevel);
const logger = createLogger(props.log);
const http = new HttpNativeImpl(serializer, config, logger);

@@ -1143,6 +1148,6 @@ const actionDispatcher = new HttpActionDispatcher(http);

};
const createOAuthClient = (props) => {
const createOAuthAPIClient = (props) => {
const serializer = new SerializerNativeImpl();
const config = new HttpConfigImpl(props, serializer);
const logger = createLogger(props.logLevel);
const logger = createLogger(props.log);
const http = new HttpNativeImpl(serializer, config, logger);

@@ -1155,7 +1160,14 @@ const actionDispatcher = new HttpActionDispatcher(http);

};
function createStreamingClient(props) {
function createStreamingAPIClient(props) {
const serializer = new SerializerNativeImpl();
const config = new WebSocketConfigImpl(props, serializer);
const logger = createLogger(props.logLevel);
const connector = new WebSocketConnectorImpl([config.resolvePath("/api/v1/streaming"), config.getProtocols()], logger, props.implementation, config.getMaxAttempts());
const logger = createLogger(props.log);
const connector = new WebSocketConnectorImpl({
constructorParameters: [
config.resolvePath("/api/v1/streaming"),
config.getProtocols(),
],
implementation: props.implementation,
maxAttempts: config.getMaxAttempts(),
}, logger);
const actionDispatcher = new WebSocketActionDispatcher(connector, serializer, logger);

@@ -1210,2 +1222,2 @@ const actionProxy = createActionProxy(actionDispatcher);

export { createOAuthClient, createRestClient, createStreamingClient, mastodon };
export { createOAuthAPIClient, createRestAPIClient, createStreamingAPIClient, mastodon };

@@ -5,3 +5,3 @@ {

"private": false,
"version": "6.0.0-alpha.7",
"version": "6.0.0-alpha.8",
"author": "Ryo Igarashi <n33t5hin@gmail.com>",

@@ -8,0 +8,0 @@ "license": "MIT",

@@ -5,3 +5,3 @@ <p align="center">

<p align="center">Mastodon API client for JavaScript, TypeScript, Node.js, browsers</p>
<p align="center">Universal Mastodon API client for JavaScript</p>

@@ -16,20 +16,29 @@ <p align="center">

<p align="center">
<a href="https://github.com/neet/masto.js/discussions">Q&A</a> |
<a href="https://github.com/neet/masto.js/tree/main/examples">Examples</a> |
<a href="https://neet.github.io/masto.js">Read the Docs</a> |
<a href="https://github.com/neet/masto.js/releases">Releases</a> |
<a href="https://github.com/neet/masto.js/issues">Issues</a>
<a href="https://github.com/neet/masto.js/releases">Releases</a>
</p>
> [_Migration Guide From v4_](https://github.com/neet/masto.js/releases/tag/v5.0.0)
## Features
- 🌎 **Isomorphic** which means browsers and Node.js are both supported
- 🌊 **Fetch API** is supported natively
- ⌨️ **TypeScript** powers static typing. And of course there's no `any`!
- 💪 **You don't need to type URLs** because each endpoints have their own function
- 📄 **Detailed docs** and rich hovering menu for IDE, provided by TSDoc
- 🌎 **Universal:** Works in Node.js, browsers, and Deno
- 📦 **Lightweight:** Less runtime codes, [7kB+ minified and gzipped](https://bundlephobia.com/package/masto@6.0.0-alpha.7)
- 📚 **TypeScript:** Written in TypeScript, and provides type definitions
- 🌊 **Latest APIs:** Catches up the latest JS features including `fetch`, `AsyncIterator`.
- 🤓 **Maintained:** Actively maintained by a Fediverse lover [since 2018](https://github.com/neet/masto.js/releases/tag/1.0.0)
## Quick start
## Migration Guides
- [v5.x → v6.0.0](https://github.com/neet/masto.js/releases/tag/v6.0.0)
- [v4.x → v5.0.0](https://github.com/neet/masto.js/releases/tag/v5.0.0)
## Who's using Masto.js?
- [Elk](https://github.com/elk-zone/elk) - A nimble Mastodon web client
- [Phanpy](https://github.com/cheeaun/phanpy) - A minimalistic opinionated Mastodon web client
- [...and a lot more!](https://github.com/neet/masto.js/network/dependents)
## Quick Start
In this quick start, we'll take a look at how to create a simple Mastodon bot that publishes a post using _Masto.js_.

@@ -41,5 +50,5 @@

- **Node.js**: `>= 14.x`
- **npm**: `>= 6.x`
- **TypeScript** (optional peer dependency): `>= 3.6.0`
- **Node.js**: `>= 18.x`
- **npm**: `>= 9.x`
- **TypeScript** (optional peer dependency): `>= 5.0.0`

@@ -62,3 +71,3 @@ If you could successfully installed _Node.js_ and _npm_, create your first _Masto.js_ project with the following command. Assume you're using POSIX-compatible operating system.

Now you could initialise your project for developing a Mastodon bot. Next, you need to create an application to obtain an _[access token](https://docs.joinmastodon.org/client/authorized/)_ required to get access to your account.
Now you successfully initialised your project for developing a Mastodon bot. Next, you need to create an application to obtain an _[access token](https://docs.joinmastodon.org/client/authorized/)_ required to get access to your account.

@@ -76,5 +85,5 @@ Go to your settings page, open **Development**, and click the **New Application** button to earn your personal access token.

```ts
import { login } from 'masto';
import { createRestAPIClient } from "masto";
const masto = await login({
const masto = await createRestAPIClient({
url: process.env.URL,

@@ -85,4 +94,4 @@ accessToken: process.env.TOKEN,

const status = await masto.v1.statuses.create({
status: 'Hello from #mastojs!',
visibility: 'public',
status: "Hello from #mastojs!",
visibility: "public",
});

@@ -101,24 +110,2 @@

## FAQ
### Q. I want to use in Mastodon-compatible servers
Masto.js validates your Mastodon instance's version to provide more helpful error messages, but this may lead to not working with some Mastodon-compatible software. Therefore, we are offering a way to disable this feature.
```diff
await login({
url: "https://example.com",
accessToken: "...",
+ disableVersionCheck: true
});
```
### Q. Do I need polyfills?
Masto.js uses `fetch` and other Web APIs which may not be supported in specific environments such as the legacy version of Node.js, but we also automatically switch to another module that provides the same functionality. For example, if we detected `fetch` API is not available, we switch to `node-fetch` module. Therefore, you don't need to be aware of polyfill / ponyfill in most cases, but you will need to install them manually in some cases.
- `Node.js < 18`: We use `node-fetch`, `abort-controller`, and `form-data` as ponyfill. You don't need to install polyfills. However, if you have installed polyfills of these APIs in global, Masto.js chose them as a priority.
- `Node.js >= 18`: We use native `fetch` API. You don't need to install polyfills.
- Browsers: **We don't include any ponyfill or polyfill** in the bundle. You need to manually install abort-controller, fetch, and form-data to support legacy browsers.
## Contribution

@@ -125,0 +112,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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