brrr.now 0.1.0
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/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +60 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 uqe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# brrr.now
|
|
2
|
+
|
|
3
|
+
Minimal TypeScript client for the [brrr.now](https://brrr.now/docs/) notification service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add brrr.now
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install brrr.now
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { sendNotification } from "brrr.now";
|
|
19
|
+
|
|
20
|
+
await sendNotification({
|
|
21
|
+
webhook: process.env.BRRR_WEBHOOK!,
|
|
22
|
+
title: "Coffee Machine Offline",
|
|
23
|
+
message: "The coffee machine is currently unreachable.",
|
|
24
|
+
sound: "upbeat_bells",
|
|
25
|
+
openUrl: "https://status.example.com/coffee-machine",
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`webhook` can be either:
|
|
30
|
+
|
|
31
|
+
- the full webhook URL from the brrr.now app
|
|
32
|
+
- only the secret part, for example `br_usr_a1b2c3`
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import type {
|
|
38
|
+
NotificationInterruptionLevel,
|
|
39
|
+
NotificationSound,
|
|
40
|
+
SendNotificationParams,
|
|
41
|
+
} from "brrr.now";
|
|
42
|
+
import { isBrrrNowError, sendNotification } from "brrr.now";
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`sendNotification(params)` sends a `POST` request with a JSON payload and returns the native `Response`.
|
|
46
|
+
|
|
47
|
+
### `SendNotificationParams`
|
|
48
|
+
|
|
49
|
+
- `title`
|
|
50
|
+
- `subtitle`
|
|
51
|
+
- `message`
|
|
52
|
+
- `sound`: `NotificationSound`
|
|
53
|
+
- `openUrl`
|
|
54
|
+
- `imageUrl`
|
|
55
|
+
- `expirationDate`: `string | Date`
|
|
56
|
+
- `filterCriteria`
|
|
57
|
+
- `interruptionLevel`: `NotificationInterruptionLevel`
|
|
58
|
+
|
|
59
|
+
### Error handling
|
|
60
|
+
|
|
61
|
+
On non-`2xx` responses, `sendNotification` throws an `Error` object with extra fields:
|
|
62
|
+
|
|
63
|
+
- `name: "BrrrNowError"`
|
|
64
|
+
- `status`
|
|
65
|
+
- `statusText`
|
|
66
|
+
- `body`
|
|
67
|
+
|
|
68
|
+
Use `isBrrrNowError` to narrow the error type:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { isBrrrNowError, sendNotification } from "brrr.now";
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
await sendNotification({
|
|
75
|
+
webhook: process.env.BRRR_WEBHOOK!,
|
|
76
|
+
message: "Hello world!",
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (isBrrrNowError(error)) {
|
|
80
|
+
console.error(error.status, error.body);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The supported sound values follow the official brrr.now documentation.
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type NotificationSound = "default" | "system" | "brrr" | "bell_ringing" | "bubble_ding" | "bubbly_success_ding" | "cat_meow" | "calm1" | "calm2" | "cha_ching" | "dog_barking" | "door_bell" | "duck_quack" | "short_triple_blink" | "upbeat_bells" | "warm_soft_error";
|
|
2
|
+
type NotificationInterruptionLevel = "passive" | "active" | "time-sensitive";
|
|
3
|
+
interface SendNotificationParams {
|
|
4
|
+
webhook: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
sound?: NotificationSound;
|
|
9
|
+
openUrl?: string;
|
|
10
|
+
imageUrl?: string;
|
|
11
|
+
expirationDate?: string | Date;
|
|
12
|
+
filterCriteria?: string;
|
|
13
|
+
interruptionLevel?: NotificationInterruptionLevel;
|
|
14
|
+
}
|
|
15
|
+
type BrrrNowError = Error & {
|
|
16
|
+
name: "BrrrNowError";
|
|
17
|
+
status: number;
|
|
18
|
+
statusText: string;
|
|
19
|
+
body: string;
|
|
20
|
+
};
|
|
21
|
+
declare const sendNotification: (params: SendNotificationParams) => Promise<Response>;
|
|
22
|
+
declare const isBrrrNowError: (error: unknown) => error is BrrrNowError;
|
|
23
|
+
export { sendNotification, isBrrrNowError, SendNotificationParams, NotificationSound, NotificationInterruptionLevel, BrrrNowError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var API_BASE_URL = "https://api.brrr.now/v1/";
|
|
3
|
+
var sendNotification = async (params) => {
|
|
4
|
+
const response = await fetch(resolveWebhookUrl(params.webhook), {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json"
|
|
8
|
+
},
|
|
9
|
+
body: JSON.stringify(createPayload(params))
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw createBrrrNowError(response, await response.text());
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
};
|
|
16
|
+
var isBrrrNowError = (error) => {
|
|
17
|
+
return error instanceof Error && error.name === "BrrrNowError" && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.body === "string";
|
|
18
|
+
};
|
|
19
|
+
var createPayload = (params) => {
|
|
20
|
+
return {
|
|
21
|
+
title: params.title,
|
|
22
|
+
subtitle: params.subtitle,
|
|
23
|
+
message: params.message,
|
|
24
|
+
sound: params.sound,
|
|
25
|
+
open_url: params.openUrl,
|
|
26
|
+
image_url: params.imageUrl,
|
|
27
|
+
expiration_date: serializeExpirationDate(params.expirationDate),
|
|
28
|
+
"filter-criteria": params.filterCriteria,
|
|
29
|
+
"interruption-level": params.interruptionLevel
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var createBrrrNowError = (response, body) => {
|
|
33
|
+
const error = new Error(`brrr.now request failed with ${response.status} ${response.statusText}${body ? `: ${body}` : ""}`);
|
|
34
|
+
return Object.assign(error, {
|
|
35
|
+
name: "BrrrNowError",
|
|
36
|
+
status: response.status,
|
|
37
|
+
statusText: response.statusText,
|
|
38
|
+
body
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var resolveWebhookUrl = (webhook) => {
|
|
42
|
+
const trimmedWebhook = webhook.trim();
|
|
43
|
+
if (!trimmedWebhook) {
|
|
44
|
+
throw new TypeError("webhook must not be empty");
|
|
45
|
+
}
|
|
46
|
+
if (trimmedWebhook.startsWith("https://") || trimmedWebhook.startsWith("http://")) {
|
|
47
|
+
return trimmedWebhook;
|
|
48
|
+
}
|
|
49
|
+
return new URL(trimmedWebhook, API_BASE_URL).toString();
|
|
50
|
+
};
|
|
51
|
+
var serializeExpirationDate = (expirationDate) => {
|
|
52
|
+
if (expirationDate instanceof Date) {
|
|
53
|
+
return expirationDate.toISOString();
|
|
54
|
+
}
|
|
55
|
+
return expirationDate;
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
sendNotification,
|
|
59
|
+
isBrrrNowError
|
|
60
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brrr.now",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny TypeScript client for sending push notifications with brrr.now webhooks",
|
|
5
|
+
"homepage": "https://github.com/uqe/brrr.now#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/uqe/brrr.now/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"brrr.now",
|
|
12
|
+
"brrr",
|
|
13
|
+
"notification",
|
|
14
|
+
"push-notification",
|
|
15
|
+
"push-notifications",
|
|
16
|
+
"webhook",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/uqe/brrr.now.git"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"type": "module",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bunup",
|
|
41
|
+
"dev": "bunup --watch",
|
|
42
|
+
"format": "oxfmt",
|
|
43
|
+
"lint": "oxlint",
|
|
44
|
+
"prepare": "bun simple-git-hooks",
|
|
45
|
+
"release": "bumpp --commit --push --tag",
|
|
46
|
+
"test": "bun test",
|
|
47
|
+
"test:coverage": "bun test --coverage",
|
|
48
|
+
"test:watch": "bun test --watch",
|
|
49
|
+
"type-check": "tsc --noEmit"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/bun": "^1.3.11",
|
|
53
|
+
"bumpp": "^11.0.1",
|
|
54
|
+
"bunup": "^0.16.31",
|
|
55
|
+
"oxfmt": "^0.42.0",
|
|
56
|
+
"oxlint": "^1.57.0",
|
|
57
|
+
"simple-git-hooks": "^2.13.1",
|
|
58
|
+
"typescript": "^6.0.2"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"typescript": ">=4.5.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"typescript": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"simple-git-hooks": {
|
|
69
|
+
"pre-commit": "bun run lint && bun run type-check"
|
|
70
|
+
}
|
|
71
|
+
}
|