@boxxy/notifier-atc 0.0.1 → 0.1.4
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/README.md +33 -5
- package/dist/create-atc-notifier.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/types.d.ts +12 -0
- package/package.json +23 -4
- package/src/create-atc-notifier.ts +47 -0
- package/src/index.ts +2 -0
- package/src/types.ts +17 -0
package/README.md
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>@boxxy/notifier-atc</h1>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
boxxy
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@boxxy/notifier-atc"><img src="https://img.shields.io/npm/v/@boxxy/notifier-atc" alt="npm version"></a>
|
|
6
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
|
|
7
|
+
</p>
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
<p>
|
|
10
|
+
<a href="../../docs/design/boxxy/README.md">Documentation</a>
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
boxxy's `Notifier` port on atc: a hold notice arrives as one atc message in one named session.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
Install the package from [npm](https://www.npmjs.com/package/@boxxy/notifier-atc) with Bun:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bun add @boxxy/notifier-atc
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The package runs on [Bun](https://bun.sh) 1.3 or newer.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- `createAtcNotifier({ client, session })` returns a `Notifier`. The message names the item and the
|
|
29
|
+
reason, and says the owner next runs `boxxy item note` and `boxxy item retry`.
|
|
30
|
+
- The client is one call, `sendMessage`. The app builds it from its atc connection.
|
|
31
|
+
- A send that fails, or that atc refuses, returns the failed outcome and never throws.
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
[Notices in v1](../../docs/design/boxxy/v1.md#notices) describes when a notice is written and sent.
|
package/dist/index.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AtcSendRequest {
|
|
2
|
+
readonly session: string;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
readonly idempotencyKey: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AtcMessageClient {
|
|
7
|
+
sendMessage: (request: AtcSendRequest) => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface AtcNotifierOptions {
|
|
10
|
+
readonly client: AtcMessageClient;
|
|
11
|
+
readonly session: string;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boxxy/notifier-atc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "boxxy's hold notice sent as an atc message to one named session",
|
|
5
5
|
"homepage": "https://github.com/zgeoff/boxxy/tree/main/adapters/notifier-atc#readme",
|
|
6
6
|
"bugs": "https://github.com/zgeoff/boxxy/issues",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,10 +11,29 @@
|
|
|
11
11
|
"directory": "adapters/notifier-atc"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"src",
|
|
15
|
+
"!src/**/*.test.ts",
|
|
16
|
+
"dist"
|
|
16
17
|
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./src/index.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"publishConfig": {
|
|
18
26
|
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && tsrs -p tsconfig.build.json",
|
|
30
|
+
"typecheck": "tsrs --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@boxxy/model": "0.1.4"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"bun": ">=1.3",
|
|
37
|
+
"node": ">=24"
|
|
19
38
|
}
|
|
20
39
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { HoldNotice, Notifier } from '@boxxy/model';
|
|
2
|
+
import type { AtcNotifierOptions } from './types.ts';
|
|
3
|
+
|
|
4
|
+
export function createAtcNotifier(options: AtcNotifierOptions): Notifier {
|
|
5
|
+
return {
|
|
6
|
+
async tellHold(notice) {
|
|
7
|
+
try {
|
|
8
|
+
await options.client.sendMessage({
|
|
9
|
+
session: options.session,
|
|
10
|
+
text: formatHoldMessage(notice),
|
|
11
|
+
idempotencyKey: buildIdempotencyKey(notice),
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return { kind: 'failed', reason: toFailureReason(error) };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return { kind: 'sent' };
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatHoldMessage(notice: HoldNotice): string {
|
|
23
|
+
return [
|
|
24
|
+
`boxxy put ${notice.item} on hold: ${notice.reason}.`,
|
|
25
|
+
`Add a note with \`boxxy item note ${notice.item}\`, then run \`boxxy item retry ${notice.item}\`.`,
|
|
26
|
+
].join('\n');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The port's notice has no id or try count; the item, the reason and the time name the notice,
|
|
30
|
+
// so a later try of the same notice repeats the key.
|
|
31
|
+
function buildIdempotencyKey(notice: HoldNotice): string {
|
|
32
|
+
return `boxxy-hold:${notice.item}:${notice.reason}:${notice.at}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Only a string `code` is kept: an error message may carry text that must not reach the log.
|
|
36
|
+
function toFailureReason(error: unknown): string {
|
|
37
|
+
if (
|
|
38
|
+
typeof error === 'object' &&
|
|
39
|
+
error !== null &&
|
|
40
|
+
'code' in error &&
|
|
41
|
+
typeof error.code === 'string'
|
|
42
|
+
) {
|
|
43
|
+
return error.code;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 'atc send failed';
|
|
47
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AtcSendRequest {
|
|
2
|
+
// the name or the id of the session that gets the message
|
|
3
|
+
readonly session: string;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly idempotencyKey: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// The one call the adapter needs. It resolves when atc takes the message and rejects when atc
|
|
9
|
+
// refuses it or cannot be reached; a rejection may carry a string `code`, such as `no_such_session`.
|
|
10
|
+
export interface AtcMessageClient {
|
|
11
|
+
sendMessage: (request: AtcSendRequest) => Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AtcNotifierOptions {
|
|
15
|
+
readonly client: AtcMessageClient;
|
|
16
|
+
readonly session: string;
|
|
17
|
+
}
|