@deepmaid/maid-delivery 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/cordis.patch.yml +3 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.js +62 -0
- package/package.json +37 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kenyonxu
|
|
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/cordis.patch.yml
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface DeliveryAddress {
|
|
3
|
+
botId: string;
|
|
4
|
+
targetId: string;
|
|
5
|
+
}
|
|
6
|
+
type DeliveryErrorCode = 'invalid-address' | 'unknown-bot' | 'unknown-target' | 'bot-not-connected' | 'transport' | 'unknown';
|
|
7
|
+
type DeliveryResult = {
|
|
8
|
+
sent: true;
|
|
9
|
+
} | {
|
|
10
|
+
sent: false;
|
|
11
|
+
code: DeliveryErrorCode;
|
|
12
|
+
};
|
|
13
|
+
interface MaidDelivery {
|
|
14
|
+
send(maidId: string, address: DeliveryAddress, text: string, opts?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}): Promise<DeliveryResult>;
|
|
17
|
+
verifyAddress(address: DeliveryAddress): Promise<{
|
|
18
|
+
ok: boolean;
|
|
19
|
+
reason?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface DshImLike {
|
|
23
|
+
send(botId: string, targetId: string, text: string, opts?: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<unknown>;
|
|
26
|
+
listTargets(botId: string): Promise<unknown[]>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/adapter.d.ts
|
|
30
|
+
declare function createDshImDelivery(dshIm: DshImLike): MaidDelivery;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/index.d.ts
|
|
33
|
+
declare const name = "maid-delivery";
|
|
34
|
+
declare const inject: string[];
|
|
35
|
+
declare const apply: (ctx: any, _config: Record<string, never>) => (() => void);
|
|
36
|
+
//#endregion
|
|
37
|
+
export { type DeliveryAddress, type DeliveryErrorCode, type DeliveryResult, type DshImLike, type MaidDelivery, apply, createDshImDelivery, inject, name };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/adapter.ts
|
|
2
|
+
function dshImErrorCodeToDeliveryCode(code) {
|
|
3
|
+
switch (code) {
|
|
4
|
+
case "bad-request":
|
|
5
|
+
case "invalid-target": return "invalid-address";
|
|
6
|
+
case "target-conflict":
|
|
7
|
+
case "unknown-target": return "unknown-target";
|
|
8
|
+
case "unknown-bot": return "unknown-bot";
|
|
9
|
+
case "bot-not-connected": return "bot-not-connected";
|
|
10
|
+
case "ECONNRESET":
|
|
11
|
+
case "ETIMEDOUT":
|
|
12
|
+
case "ECONNREFUSED": return "transport";
|
|
13
|
+
default: return "unknown";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createDshImDelivery(dshIm) {
|
|
17
|
+
return {
|
|
18
|
+
async send(_maidId, address, text, opts) {
|
|
19
|
+
if (address.botId.length === 0 || address.targetId.length === 0) return {
|
|
20
|
+
sent: false,
|
|
21
|
+
code: "invalid-address"
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
const res = await dshIm.send(address.botId, address.targetId, text, opts);
|
|
25
|
+
if (res !== null && typeof res === "object" && "sent" in res && res.sent === true) return { sent: true };
|
|
26
|
+
return {
|
|
27
|
+
sent: false,
|
|
28
|
+
code: "unknown"
|
|
29
|
+
};
|
|
30
|
+
} catch (error) {
|
|
31
|
+
const code = error.code;
|
|
32
|
+
return {
|
|
33
|
+
sent: false,
|
|
34
|
+
code: dshImErrorCodeToDeliveryCode(typeof code === "string" ? code : void 0)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async verifyAddress(address) {
|
|
39
|
+
try {
|
|
40
|
+
return (await dshIm.listTargets(address.botId)).some((t) => typeof t === "object" && t !== null && Object.values(t).includes(address.targetId)) ? { ok: true } : {
|
|
41
|
+
ok: false,
|
|
42
|
+
reason: `targetId '${address.targetId}' not found on bot '${address.botId}'`
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
ok: false,
|
|
47
|
+
reason: `listTargets failed: ${error.message}`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/index.ts
|
|
55
|
+
const name = "maid-delivery";
|
|
56
|
+
const inject = ["dshIm"];
|
|
57
|
+
const apply = (ctx, _config) => {
|
|
58
|
+
const dispose = ctx.provide("maidDelivery", createDshImDelivery(ctx.dshIm));
|
|
59
|
+
return () => dispose();
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { apply, createDshImDelivery, inject, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepmaid/maid-delivery",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"cordis.patch.yml"
|
|
17
|
+
],
|
|
18
|
+
"dsh": {
|
|
19
|
+
"engines": {
|
|
20
|
+
"dsh": ">=0.2.1-rc.2 <0.3"
|
|
21
|
+
},
|
|
22
|
+
"bundle": {
|
|
23
|
+
"patch": "./cordis.patch.yml"
|
|
24
|
+
},
|
|
25
|
+
"meta": {
|
|
26
|
+
"title": "Maid Delivery",
|
|
27
|
+
"description": "cron 产物投递 seam:把晨报等 cron 会话结果送抵 IM 渠道(M1 唯一 provider 是 dsh-im 适配器)。关闭=晨报照常生成但无人投递,主人收不到任何定时消息。"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsdown": "0.22.14",
|
|
32
|
+
"typescript": "6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsdown"
|
|
39
|
+
}
|
|
6
40
|
}
|
package/README.md
DELETED