@particle-academy/slack-js 0.1.3 → 0.2.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 +58 -0
- package/README.md +41 -2
- package/art/fancified.svg +26 -0
- package/dist/chunk-77FLOHBR.js +276 -0
- package/dist/chunk-77FLOHBR.js.map +1 -0
- package/dist/flow.cjs +228 -2
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.d.cts +4 -1
- package/dist/flow.d.ts +4 -1
- package/dist/flow.js +50 -5
- package/dist/flow.js.map +1 -1
- package/dist/index.cjs +197 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +121 -3
- package/dist/index.d.ts +121 -3
- package/dist/index.js +1 -1
- package/package.json +4 -3
- package/dist/chunk-SWUB2VUX.js +0 -92
- package/dist/chunk-SWUB2VUX.js.map +0 -1
package/dist/chunk-SWUB2VUX.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { callConnector } from '@particle-academy/fancy-connector-core';
|
|
2
|
-
|
|
3
|
-
// src/faker.ts
|
|
4
|
-
function fakeMessagePost({ config, fake }) {
|
|
5
|
-
return {
|
|
6
|
-
"ok": true,
|
|
7
|
-
"channel": "C123ABC456",
|
|
8
|
-
"ts": "1787719200.000100",
|
|
9
|
-
"message": {
|
|
10
|
-
"user": "U012AB3CDE",
|
|
11
|
-
"type": "message",
|
|
12
|
-
"ts": "1787719200.000100",
|
|
13
|
-
"text": "Deployment finished successfully.",
|
|
14
|
-
"app_id": "A012BC3DEF",
|
|
15
|
-
"bot_id": "B012AB3CD"
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
var slackFaker = (operation, request) => {
|
|
20
|
-
switch (operation) {
|
|
21
|
-
case "message_post":
|
|
22
|
-
return fakeMessagePost(request);
|
|
23
|
-
default:
|
|
24
|
-
throw new Error(
|
|
25
|
-
`slack: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// src/service.ts
|
|
31
|
-
var CONNECTOR_API_VERSION = 1;
|
|
32
|
-
var SLACK_BASE_URLS = {
|
|
33
|
-
"live": "https://slack.com",
|
|
34
|
-
"sandbox": "https://slack.com"
|
|
35
|
-
};
|
|
36
|
-
var SLACK_REQUIRES = [
|
|
37
|
-
"accessToken",
|
|
38
|
-
"refreshToken",
|
|
39
|
-
"clientId",
|
|
40
|
-
"clientSecret"
|
|
41
|
-
];
|
|
42
|
-
function slackAuthorize(credentials, request, _mode) {
|
|
43
|
-
request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
|
|
44
|
-
}
|
|
45
|
-
var SLACK = {
|
|
46
|
-
service: "slack",
|
|
47
|
-
title: "Slack",
|
|
48
|
-
sandbox: "separate-account",
|
|
49
|
-
baseUrls: { ...SLACK_BASE_URLS },
|
|
50
|
-
requires: [...SLACK_REQUIRES],
|
|
51
|
-
authorize: slackAuthorize,
|
|
52
|
-
faker: slackFaker
|
|
53
|
-
};
|
|
54
|
-
var MESSAGE_POST_OPERATION = "message_post";
|
|
55
|
-
async function slackMessagePost(options) {
|
|
56
|
-
const config = options.config ?? {};
|
|
57
|
-
if (config.channel === void 0 || config.channel === null || config.channel === "") {
|
|
58
|
-
throw new Error(`message_post: "channel" is required (Channel).`);
|
|
59
|
-
}
|
|
60
|
-
if (config.text === void 0 || config.text === null || config.text === "") {
|
|
61
|
-
throw new Error(`message_post: "text" is required (Message).`);
|
|
62
|
-
}
|
|
63
|
-
const result = await callConnector(SLACK, {
|
|
64
|
-
operation: MESSAGE_POST_OPERATION,
|
|
65
|
-
config,
|
|
66
|
-
input: options.input,
|
|
67
|
-
...options.credentials === void 0 ? {} : { credentials: options.credentials },
|
|
68
|
-
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
69
|
-
...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
|
|
70
|
-
...options.attempts === void 0 ? {} : { attempts: options.attempts },
|
|
71
|
-
...options.transport === void 0 ? {} : { transport: options.transport },
|
|
72
|
-
request: {
|
|
73
|
-
method: "POST",
|
|
74
|
-
path: "/api/chat.postMessage",
|
|
75
|
-
json: {
|
|
76
|
-
"channel": String(config.channel),
|
|
77
|
-
"text": String(config.text)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
const data = result.data;
|
|
82
|
-
if (data?.ok === false) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`message_post: Slack rejected chat.postMessage \u2014 ` + String(data.error ?? "no reason given")
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { CONNECTOR_API_VERSION, MESSAGE_POST_OPERATION, SLACK, SLACK_BASE_URLS, SLACK_REQUIRES, slackAuthorize, slackFaker, slackMessagePost };
|
|
91
|
-
//# sourceMappingURL=chunk-SWUB2VUX.js.map
|
|
92
|
-
//# sourceMappingURL=chunk-SWUB2VUX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/message-post.ts"],"names":[],"mappings":";;;AAyBA,SAAS,eAAA,CAAgB,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AAC/D,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,IAAA;AAAA,IACN,SAAA,EAAW,YAAA;AAAA,IACX,IAAA,EAAM,mBAAA;AAAA,IACN,SAAA,EAAW;AAAA,MACT,MAAA,EAAQ,YAAA;AAAA,MACR,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,mBAAA;AAAA,MACN,MAAA,EAAQ,mCAAA;AAAA,MACR,QAAA,EAAU,YAAA;AAAA,MACV,QAAA,EAAU;AAAA;AACZ,GACF;AACF;AAEO,IAAM,UAAA,GAA6B,CAAC,SAAA,EAA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AAA,KAC1C;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"chunk-SWUB2VUX.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- slack\n */\n\n/**\n * The Slack faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES Slack actually publishes, so an author can wire {{ $json.data.id }}\n * against a fake and have it keep working against the real thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakeMessagePost({ config, fake }: FakeRequest): unknown {\n return {\n \"ok\": true,\n \"channel\": \"C123ABC456\",\n \"ts\": \"1787719200.000100\",\n \"message\": {\n \"user\": \"U012AB3CDE\",\n \"type\": \"message\",\n \"ts\": \"1787719200.000100\",\n \"text\": \"Deployment finished successfully.\",\n \"app_id\": \"A012BC3DEF\",\n \"bot_id\": \"B012AB3CD\",\n },\n };\n}\n\nexport const slackFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"message_post\":\n return fakeMessagePost(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `slack: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- slack\n */\n\n/**\n * Slack, as one service descriptor shared by every Slack operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of Slack: its base URL, its auth\n * scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * Install the app into a dedicated development workspace or Slack developer\n * sandbox. Messages are real inside that workspace, but its users and data are\n * separate from production. Developer sandboxes expire by default and have\n * feature and integration limits.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { slackFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const SLACK_BASE_URLS = {\n \"live\": \"https://slack.com\",\n \"sandbox\": \"https://slack.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const SLACK_REQUIRES = [\n \"accessToken\",\n \"refreshToken\",\n \"clientId\",\n \"clientSecret\"\n] as const;\n\n/**\n * Apply Slack's auth scheme to an outgoing request.\n *\n *\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function slackAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The Slack service, for the TypeScript runtime. */\nexport const SLACK: ServiceDescriptor = {\n service: \"slack\",\n title: \"Slack\",\n sandbox: \"separate-account\",\n baseUrls: { ...SLACK_BASE_URLS },\n requires: [...SLACK_REQUIRES],\n authorize: slackAuthorize,\n faker: slackFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/message-post.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/message-post.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- slack\n */\n\n/**\n * Post a text message to a Slack channel or conversation.\n *\n * POST /api/chat.postMessage —\n * https://docs.slack.dev/reference/methods/chat.postMessage\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls Slack or calls the faker.\n *\n * sideEffects: unsafe-to-replay.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { SLACK } from \"../service.js\";\n\nexport const MESSAGE_POST_OPERATION = \"message_post\";\n\nexport type MessagePostOptions = {\n /** The node's resolved config. Keys: channel, text. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function slackMessagePost(options: MessagePostOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.channel === undefined || config.channel === null || config.channel === \"\") {\n throw new Error(`message_post: \"channel\" is required (Channel).`);\n }\n\n if (config.text === undefined || config.text === null || config.text === \"\") {\n throw new Error(`message_post: \"text\" is required (Message).`);\n }\n\n const result = await callConnector(SLACK, {\n operation: MESSAGE_POST_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: \"/api/chat.postMessage\",\n json: {\n \"channel\": String(config.channel),\n \"text\": String(config.text),\n },\n },\n });\n\n // Slack answers HTTP 200 with `{ok: false}` for an application-level\n // failure. A status check alone reads that as success, so the call is\n // reported as having worked and the next node receives a body that says\n // otherwise.\n const data = result.data as Record<string, unknown> | undefined;\n\n if (data?.ok === false) {\n throw new Error(\n `message_post: Slack rejected chat.postMessage — ` +\n String(data.error ?? \"no reason given\"),\n );\n }\n\n return result;\n}\n"]}
|