@notation/factory-slack 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Notation Labs Ltd
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.
@@ -0,0 +1,57 @@
1
+ import {
2
+ type Channel as ChannelContract,
3
+ OutpostGroup,
4
+ type Selector,
5
+ } from "@notation/factory";
6
+ import * as v from "valibot";
7
+ import type { ConnectionRef } from "./connection-ref.ts";
8
+ import {
9
+ type MentionEvent,
10
+ type MentionOptions,
11
+ mentionOptions,
12
+ } from "./selectors.ts";
13
+
14
+ /** A Slack channel needs naming: there's no default. */
15
+ const channelConfig = v.object({
16
+ scope: v.pipe(v.string(), v.startsWith("#")),
17
+ });
18
+ export type ChannelConfig = v.InferInput<typeof channelConfig>;
19
+
20
+ export type ChannelOptions = { id: string } & ChannelConfig;
21
+
22
+ /**
23
+ * One Slack channel on a Slack connection, made by `connection.channel(...)`.
24
+ * Its grant is the bot's membership: `/invite @<app>` in the channel. A
25
+ * conversation is a thread.
26
+ */
27
+ export class Channel
28
+ extends OutpostGroup<ChannelConfig>
29
+ implements ChannelContract
30
+ {
31
+ readonly scope: string;
32
+ readonly connection: ConnectionRef;
33
+
34
+ constructor(
35
+ id: string,
36
+ { connection, ...config }: ChannelConfig & { connection: ConnectionRef },
37
+ ) {
38
+ const { scope } = v.parse(channelConfig, config);
39
+ super("slack/Channel", id, config);
40
+ this.scope = scope;
41
+ this.connection = connection;
42
+ this.outpost.store.contribute({
43
+ channels: {
44
+ [id]: { provider: "slack", connection: this.connection.name, scope },
45
+ },
46
+ });
47
+ }
48
+
49
+ /** Messages that mention `name`, e.g. `"@claude"`. */
50
+ mention(name: string, opts: MentionOptions): Selector<MentionEvent> {
51
+ return {
52
+ channel: this,
53
+ event: "app_mention",
54
+ match: { mention: name, ...v.parse(mentionOptions, opts) },
55
+ };
56
+ }
57
+ }
@@ -0,0 +1,23 @@
1
+ import { ResourceGroup } from "@notation/resource";
2
+ import type { ConnectionRef as ConnectionRefContract } from "@notation/factory";
3
+ import { Channel, type ChannelOptions } from "./channel.ts";
4
+
5
+ type ConnectionRefConfig = { name: string };
6
+
7
+ /** In an outpost: a Slack connection the infra declares, from `slack.Connection.get(name)`. */
8
+ export class ConnectionRef
9
+ extends ResourceGroup<ConnectionRefConfig>
10
+ implements ConnectionRefContract
11
+ {
12
+ readonly name: string;
13
+
14
+ constructor(id: string, config: ConnectionRefConfig) {
15
+ super("slack/ConnectionRef", id, config);
16
+ this.name = config.name;
17
+ }
18
+
19
+ /** One Slack channel: `scope` is its name, e.g. `"#ops"`. */
20
+ channel({ id, ...config }: ChannelOptions): Channel {
21
+ return new Channel(id, { ...config, connection: this });
22
+ }
23
+ }
@@ -0,0 +1,82 @@
1
+ import { ResourceGroup, text } from "@notation/resource";
2
+ import {
3
+ type Connection as ConnectionContract,
4
+ type Router,
5
+ scopedName,
6
+ } from "@notation/factory";
7
+ import { webhookPath } from "@notation/factory/router";
8
+ import * as v from "valibot";
9
+ import { App, type AppInstance } from "../resources/app.ts";
10
+ import { ConnectionRef } from "./connection-ref.ts";
11
+
12
+ /** Slack app names are at most 35 characters. */
13
+ const SLACK_APP_NAME_MAX_LENGTH = 35;
14
+
15
+ const connectionConfig = v.object({
16
+ /** The Slack workspace the app is installed in. */
17
+ workspace: v.string(),
18
+ });
19
+ export type ConnectionConfig = v.InferInput<typeof connectionConfig>;
20
+
21
+ export type ConnectionOptions = ConnectionConfig & { router: Router };
22
+
23
+ /**
24
+ * `new slack.Connection(...)`: Notation Factory on Slack, as one app whose events go
25
+ * to the router. Its bot token and signing secret go from the app to the
26
+ * router's vault in memory. Slack is a channel only:
27
+ * code still lives on the code host.
28
+ */
29
+ export class Connection
30
+ extends ResourceGroup<ConnectionConfig>
31
+ implements ConnectionContract
32
+ {
33
+ readonly name: string;
34
+ readonly router: Router;
35
+ readonly app: AppInstance;
36
+
37
+ constructor(id: string, { router, ...config }: ConnectionOptions) {
38
+ const { workspace } = v.parse(connectionConfig, config);
39
+ super("slack/Connection", id, config);
40
+ this.name = id;
41
+ this.router = router;
42
+ const key = `slack/${id}`;
43
+ this.app = this.add(
44
+ new App(`${id}-app`, {
45
+ config: {
46
+ name: scopedName(id, SLACK_APP_NAME_MAX_LENGTH),
47
+ workspace,
48
+ requestUrl: text`${router.url}${webhookPath(key)}`,
49
+ },
50
+ }),
51
+ );
52
+ const botToken = this.router.bind(
53
+ this.router.vault.secret({
54
+ id: `${id}-bot-token`,
55
+ value: this.app.credentials.botToken,
56
+ }),
57
+ );
58
+ const signingSecret = this.router.bind(
59
+ this.router.vault.secret({
60
+ id: `${id}-signing-secret`,
61
+ value: this.app.credentials.signingSecret,
62
+ }),
63
+ );
64
+ this.router.store.contribute({
65
+ connections: {
66
+ [key]: {
67
+ provider: "slack",
68
+ source: this.app.outputRef("appId"),
69
+ credentials: {
70
+ botToken,
71
+ signingSecret,
72
+ },
73
+ },
74
+ },
75
+ });
76
+ }
77
+
78
+ /** In an outpost: the connection the infra declares as `name`. */
79
+ static get(name: string): ConnectionRef {
80
+ return new ConnectionRef(name, { name });
81
+ }
82
+ }
@@ -0,0 +1,10 @@
1
+ export type { Channel, ChannelOptions } from "./channel.ts";
2
+ export { Connection, type ConnectionOptions } from "./connection.ts";
3
+ export type { ConnectionRef } from "./connection-ref.ts";
4
+ export {
5
+ type AuthorSet,
6
+ group,
7
+ type MentionEvent,
8
+ type MentionOptions,
9
+ user,
10
+ } from "./selectors.ts";
@@ -0,0 +1,27 @@
1
+ import * as v from "valibot";
2
+
3
+ /** Who may start a run. Data, so the router can check it when an event arrives. */
4
+ const authorSet = v.variant("kind", [
5
+ v.object({ kind: v.literal("group"), handle: v.string() }),
6
+ v.object({ kind: v.literal("user"), email: v.string() }),
7
+ ]);
8
+ export type AuthorSet = v.InferOutput<typeof authorSet>;
9
+
10
+ /** Members of a Slack user group, by handle. */
11
+ export const group = (handle: string): AuthorSet => ({ kind: "group", handle });
12
+ /** One user, by email. */
13
+ export const user = (email: string): AuthorSet => ({ kind: "user", email });
14
+
15
+ export const mentionOptions = v.object({
16
+ from: v.union([authorSet, v.array(authorSet)]),
17
+ });
18
+ export type MentionOptions = v.InferInput<typeof mentionOptions>;
19
+
20
+ /** The parts of Slack's `app_mention` event worktree functions read. */
21
+ export type MentionEvent = {
22
+ channel: string;
23
+ user: string;
24
+ text: string;
25
+ ts: string;
26
+ thread_ts?: string;
27
+ };
package/lib/app.ts ADDED
@@ -0,0 +1,24 @@
1
+ /** The Slack calls an app makes. Stubs. */
2
+
3
+ export const createApp = async (_params: {
4
+ name: string;
5
+ workspace: string;
6
+ requestUrl: string;
7
+ }): Promise<{ appId: string; botToken: string; signingSecret: string }> => {
8
+ throw new Error(
9
+ "not implemented: create the app from a manifest, in the browser, and install it to the workspace",
10
+ );
11
+ };
12
+
13
+ export const readApp = async (_key: {
14
+ appId: string;
15
+ }): Promise<{ appId: string; botToken: string; signingSecret: string }> => {
16
+ throw new Error("not implemented: read the app's manifest");
17
+ };
18
+
19
+ export const setRequestUrl = async (
20
+ _key: { appId: string },
21
+ _requestUrl: string,
22
+ ): Promise<void> => {
23
+ throw new Error("not implemented: set the app's Events API request URL");
24
+ };
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@notation/factory-slack",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "author": "Daniel Grant",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/notationlabs/factory.git",
9
+ "directory": "packages/slack"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./implementations/index.ts"
14
+ },
15
+ "files": [
16
+ "implementations",
17
+ "lib",
18
+ "resources"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "@notation/resource": "0.28.0",
25
+ "valibot": "^1.1.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@notation/factory": "^0.1.1"
29
+ },
30
+ "devDependencies": {
31
+ "@notation/factory": "0.1.1"
32
+ }
6
33
  }
@@ -0,0 +1,64 @@
1
+ import { defineResource } from "@notation/resource";
2
+ import * as v from "valibot";
3
+ import { createApp, readApp, setRequestUrl } from "../lib/app.ts";
4
+
5
+ /** One Slack app, which backs a connection. Its Events API request URL is the connection's webhook path on the router. */
6
+ type AppApi = {
7
+ Key: { appId: string };
8
+ CreateParams: { name: string; workspace: string; requestUrl: string };
9
+ UpdateParams: { requestUrl: string };
10
+ ReadResult: { appId: string };
11
+ };
12
+
13
+ export const App = defineResource<AppApi>({
14
+ type: "slack/apps/App",
15
+ provider: "@notation/factory-slack",
16
+ })
17
+ .defineSchema({
18
+ name: {
19
+ propertyType: "param",
20
+ presence: "required",
21
+ immutable: true,
22
+ value: v.string(),
23
+ },
24
+ workspace: {
25
+ propertyType: "param",
26
+ presence: "required",
27
+ immutable: true,
28
+ value: v.string(),
29
+ },
30
+ requestUrl: {
31
+ propertyType: "param",
32
+ presence: "required",
33
+ value: v.string(),
34
+ },
35
+ appId: {
36
+ propertyType: "computed",
37
+ presence: "required",
38
+ primaryKey: true,
39
+ value: v.string(),
40
+ },
41
+ /** The bot token, which installing the app to the workspace issues. */
42
+ botToken: { propertyType: "credential", value: v.string() },
43
+ /** The secret that Slack signs the app's requests with. */
44
+ signingSecret: { propertyType: "credential", value: v.string() },
45
+ } as const)
46
+ .defineOperations({
47
+ create: async (params) => createApp(params),
48
+ rotateManually: {
49
+ botToken:
50
+ "Copy the Bot User OAuth Token from the app's OAuth & Permissions page.",
51
+ signingSecret:
52
+ "Regenerate the Signing Secret on the app's Basic Information page.",
53
+ },
54
+ read: async (key) => readApp(key),
55
+ update: async (key, _patch, params) =>
56
+ setRequestUrl(key, params.requestUrl),
57
+ delete: async () => {
58
+ throw new Error(
59
+ "The Slack app is protected: delete it on its settings page",
60
+ );
61
+ },
62
+ });
63
+
64
+ export type AppInstance = InstanceType<typeof App>;
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.