baff.js 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to baff.js are listed here. The project follows [semantic versioning](https://semver.org); before 1.0, minor versions may include breaking changes.
4
4
 
5
+ ## 0.1.1
6
+
7
+ - `ActionRowBuilder` now rejects anything but buttons or one select menu. Before, a text display, separator, container or thumbnail passed `toJSON()`. Thank you to the bug bounty reporter.
8
+ - `PermissionsBitField.has()` and `.any()` now throw `INVALID_PERMISSION` for an unknown permission name even when the bitfield has Administrator. Before, administrators got `true` for a misspelled name.
9
+
5
10
  ## 0.1.0
6
11
 
7
12
  First release.
@@ -4,6 +4,14 @@ exports.ActionRowBuilder = void 0;
4
4
  const constants_js_1 = require("../../util/constants.js");
5
5
  const validate_js_1 = require("../validate.js");
6
6
  const shared_js_1 = require("./shared.js");
7
+ // The only things an action row can hold besides buttons: one select menu.
8
+ const SELECTS = new Set([
9
+ constants_js_1.ComponentType.StringSelect,
10
+ constants_js_1.ComponentType.UserSelect,
11
+ constants_js_1.ComponentType.RoleSelect,
12
+ constants_js_1.ComponentType.MentionableSelect,
13
+ constants_js_1.ComponentType.ChannelSelect
14
+ ]);
7
15
  class ActionRowBuilder extends shared_js_1.ComponentBuilder {
8
16
  components;
9
17
  constructor(data = {}) {
@@ -36,7 +44,7 @@ class ActionRowBuilder extends shared_js_1.ComponentBuilder {
36
44
  if (kinds.length > 5 || kinds.some((k) => k !== constants_js_1.ComponentType.Button))
37
45
  (0, validate_js_1.fail)(code, 'action row', 'can hold up to 5 buttons, all buttons.');
38
46
  }
39
- else if (kinds.length !== 1 || kinds[0] === constants_js_1.ComponentType.TextInput || kinds[0] === undefined) {
47
+ else if (kinds.length !== 1 || !SELECTS.has(kinds[0])) {
40
48
  (0, validate_js_1.fail)(code, 'action row', 'needs 1-5 buttons, or exactly one select menu.');
41
49
  }
42
50
  return { ...this.base(constants_js_1.ComponentType.ActionRow), components: children };
@@ -66,15 +66,17 @@ class PermissionsBitField {
66
66
  throw new BaffError_js_1.BaffError('INVALID_PERMISSION', `Cannot read ${String(bits)} as a permission.`);
67
67
  }
68
68
  has(permission, checkAdmin = true) {
69
+ // Resolve first, so a misspelled name throws for administrators too.
70
+ const bit = PermissionsBitField.resolve(permission);
69
71
  if (checkAdmin && (this.bitfield & exports.PermissionFlagsBits.Administrator) !== 0n)
70
72
  return true;
71
- const bit = PermissionsBitField.resolve(permission);
72
73
  return (this.bitfield & bit) === bit;
73
74
  }
74
75
  any(permission, checkAdmin = true) {
76
+ const bit = PermissionsBitField.resolve(permission);
75
77
  if (checkAdmin && (this.bitfield & exports.PermissionFlagsBits.Administrator) !== 0n)
76
78
  return true;
77
- return (this.bitfield & PermissionsBitField.resolve(permission)) !== 0n;
79
+ return (this.bitfield & bit) !== 0n;
78
80
  }
79
81
  missing(permission, checkAdmin = true) {
80
82
  return PermissionsBitField.names(PermissionsBitField.resolve(permission)).filter((name) => !this.has(name, checkAdmin));
@@ -75,4 +75,4 @@ export declare const PresenceStatus: {
75
75
  };
76
76
  export declare const DEFAULT_API_URL = "https://baff.gg/api";
77
77
  export declare const DEFAULT_GATEWAY_URL = "wss://baff.gg/api/gateway";
78
- export declare const VERSION = "0.1.0";
78
+ export declare const VERSION = "0.1.1";
@@ -78,4 +78,4 @@ exports.PresenceStatus = {
78
78
  };
79
79
  exports.DEFAULT_API_URL = 'https://baff.gg/api';
80
80
  exports.DEFAULT_GATEWAY_URL = 'wss://baff.gg/api/gateway';
81
- exports.VERSION = '0.1.0';
81
+ exports.VERSION = '0.1.1';
@@ -1,6 +1,14 @@
1
1
  import { ComponentType } from '../../util/constants.js';
2
2
  import { fail, resolveJSON } from '../validate.js';
3
3
  import { ComponentBuilder } from './shared.js';
4
+ // The only things an action row can hold besides buttons: one select menu.
5
+ const SELECTS = new Set([
6
+ ComponentType.StringSelect,
7
+ ComponentType.UserSelect,
8
+ ComponentType.RoleSelect,
9
+ ComponentType.MentionableSelect,
10
+ ComponentType.ChannelSelect
11
+ ]);
4
12
  export class ActionRowBuilder extends ComponentBuilder {
5
13
  components;
6
14
  constructor(data = {}) {
@@ -33,7 +41,7 @@ export class ActionRowBuilder extends ComponentBuilder {
33
41
  if (kinds.length > 5 || kinds.some((k) => k !== ComponentType.Button))
34
42
  fail(code, 'action row', 'can hold up to 5 buttons, all buttons.');
35
43
  }
36
- else if (kinds.length !== 1 || kinds[0] === ComponentType.TextInput || kinds[0] === undefined) {
44
+ else if (kinds.length !== 1 || !SELECTS.has(kinds[0])) {
37
45
  fail(code, 'action row', 'needs 1-5 buttons, or exactly one select menu.');
38
46
  }
39
47
  return { ...this.base(ComponentType.ActionRow), components: children };
@@ -63,15 +63,17 @@ export class PermissionsBitField {
63
63
  throw new BaffError('INVALID_PERMISSION', `Cannot read ${String(bits)} as a permission.`);
64
64
  }
65
65
  has(permission, checkAdmin = true) {
66
+ // Resolve first, so a misspelled name throws for administrators too.
67
+ const bit = PermissionsBitField.resolve(permission);
66
68
  if (checkAdmin && (this.bitfield & PermissionFlagsBits.Administrator) !== 0n)
67
69
  return true;
68
- const bit = PermissionsBitField.resolve(permission);
69
70
  return (this.bitfield & bit) === bit;
70
71
  }
71
72
  any(permission, checkAdmin = true) {
73
+ const bit = PermissionsBitField.resolve(permission);
72
74
  if (checkAdmin && (this.bitfield & PermissionFlagsBits.Administrator) !== 0n)
73
75
  return true;
74
- return (this.bitfield & PermissionsBitField.resolve(permission)) !== 0n;
76
+ return (this.bitfield & bit) !== 0n;
75
77
  }
76
78
  missing(permission, checkAdmin = true) {
77
79
  return PermissionsBitField.names(PermissionsBitField.resolve(permission)).filter((name) => !this.has(name, checkAdmin));
@@ -75,4 +75,4 @@ export declare const PresenceStatus: {
75
75
  };
76
76
  export declare const DEFAULT_API_URL = "https://baff.gg/api";
77
77
  export declare const DEFAULT_GATEWAY_URL = "wss://baff.gg/api/gateway";
78
- export declare const VERSION = "0.1.0";
78
+ export declare const VERSION = "0.1.1";
@@ -75,4 +75,4 @@ export const PresenceStatus = {
75
75
  };
76
76
  export const DEFAULT_API_URL = 'https://baff.gg/api';
77
77
  export const DEFAULT_GATEWAY_URL = 'wss://baff.gg/api/gateway';
78
- export const VERSION = '0.1.0';
78
+ export const VERSION = '0.1.1';
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
- {
2
- "name": "baff.js",
3
- "version": "0.1.0",
4
- "description": "The library for building bots on baff.gg: gateway client, REST, slash commands, components and embeds, with no runtime dependencies.",
5
- "license": "SEE LICENSE IN LICENSE",
6
- "type": "module",
7
- "main": "./dist/cjs/index.js",
8
- "module": "./dist/esm/index.js",
9
- "types": "./dist/esm/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "import": {
13
- "types": "./dist/esm/index.d.ts",
14
- "default": "./dist/esm/index.js"
15
- },
16
- "require": {
17
- "types": "./dist/cjs/index.d.ts",
18
- "default": "./dist/cjs/index.js"
19
- }
20
- },
21
- "./package.json": "./package.json"
22
- },
23
- "sideEffects": false,
24
- "files": [
25
- "dist",
26
- "README.md",
27
- "LICENSE",
28
- "CHANGELOG.md"
29
- ],
30
- "engines": {
31
- "node": ">=20"
32
- },
33
- "homepage": "https://docs.baff.gg",
34
- "bugs": {
35
- "url": "https://support.baff.gg/requests/new?topic=bug"
36
- },
37
- "keywords": [
38
- "baff.gg",
39
- "baff",
40
- "bot",
41
- "chat",
42
- "gateway",
43
- "slash-commands",
44
- "api"
45
- ],
46
- "scripts": {
47
- "build": "node scripts/clean.mjs dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/package-markers.mjs",
48
- "typecheck": "tsc --noEmit -p tsconfig.json",
49
- "test": "node scripts/clean.mjs .build-test && tsc -p tsconfig.test.json && node scripts/run-tests.mjs",
50
- "check": "npm run typecheck && npm test",
51
- "smoke": "node scripts/smoke.mjs",
52
- "prepublishOnly": "npm run build && npm test && npm run smoke"
53
- },
54
- "devDependencies": {
55
- "@types/node": "^22.10.0",
56
- "typescript": "^5.7.0"
57
- }
58
- }
1
+ {
2
+ "name": "baff.js",
3
+ "version": "0.1.1",
4
+ "description": "The library for building bots on baff.gg: gateway client, REST, slash commands, components and embeds, with no runtime dependencies.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "type": "module",
7
+ "main": "./dist/cjs/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "types": "./dist/esm/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/esm/index.d.ts",
14
+ "default": "./dist/esm/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/cjs/index.d.ts",
18
+ "default": "./dist/cjs/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "sideEffects": false,
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "homepage": "https://docs.baff.gg",
34
+ "bugs": {
35
+ "url": "https://support.baff.gg/requests/new?topic=bug"
36
+ },
37
+ "keywords": [
38
+ "baff.gg",
39
+ "baff",
40
+ "bot",
41
+ "chat",
42
+ "gateway",
43
+ "slash-commands",
44
+ "api"
45
+ ],
46
+ "scripts": {
47
+ "build": "node scripts/clean.mjs dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/package-markers.mjs",
48
+ "typecheck": "tsc --noEmit -p tsconfig.json",
49
+ "test": "node scripts/clean.mjs .build-test && tsc -p tsconfig.test.json && node scripts/run-tests.mjs",
50
+ "check": "npm run typecheck && npm test",
51
+ "smoke": "node scripts/smoke.mjs",
52
+ "prepublishOnly": "npm run build && npm test && npm run smoke"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^22.10.0",
56
+ "typescript": "^5.7.0"
57
+ }
58
+ }