slack.ts 0.0.1 → 0.0.2

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.
@@ -1,26 +1,26 @@
1
- import type { AuthTestParams, AuthTestResponse } from './web/auth';
2
- import type { ChatPostMessageParams, ChatPostMessageResponse } from './web/chat';
3
- import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from './web/conversations';
1
+ import type { AuthTestParams, AuthTestResponse } from "./web/auth.js";
2
+ import type { ChatPostMessageParams, ChatPostMessageResponse } from "./web/chat.js";
3
+ import type { ConversationsInfoParams, ConversationsInfoResponse, ConversationsRepliesParams, ConversationsRepliesResponse } from "./web/conversations.js";
4
4
  export interface SlackWebAPIMap {
5
- 'auth.test': {
5
+ "auth.test": {
6
6
  params: AuthTestParams;
7
7
  response: AuthTestResponse;
8
8
  };
9
- 'chat.postMessage': {
9
+ "chat.postMessage": {
10
10
  params: ChatPostMessageParams;
11
11
  response: ChatPostMessageResponse;
12
12
  };
13
- 'conversations.info': {
13
+ "conversations.info": {
14
14
  params: ConversationsInfoParams;
15
15
  response: ConversationsInfoResponse;
16
16
  };
17
- 'conversations.replies': {
17
+ "conversations.replies": {
18
18
  params: ConversationsRepliesParams;
19
19
  response: ConversationsRepliesResponse;
20
20
  };
21
21
  }
22
22
  export type SlackAPIMethod = keyof SlackWebAPIMap;
23
- export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]['params'] & {
23
+ export type SlackAPIParams<Method extends SlackAPIMethod> = SlackWebAPIMap[Method]["params"] & {
24
24
  token?: string;
25
25
  };
26
26
  export type SlackAPIResponse<Method extends SlackAPIMethod> = {
@@ -28,5 +28,5 @@ export type SlackAPIResponse<Method extends SlackAPIMethod> = {
28
28
  error: string;
29
29
  } | ({
30
30
  ok: true;
31
- } & SlackWebAPIMap[Method]['response']);
32
- //# sourceMappingURL=index.d.ts.map
31
+ } & SlackWebAPIMap[Method]["response"]);
32
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { NormalMessage } from '../types/message';
1
+ import type { NormalMessage } from "../types/message.js";
2
2
  interface MarkdownMessage {
3
3
  markdown_text: string;
4
4
  blocks?: never;
@@ -21,7 +21,7 @@ export type ChatPostMessageParams = {
21
21
  link_names?: boolean;
22
22
  metadata?: unknown;
23
23
  mrkdwn?: boolean;
24
- parse?: 'none' | 'full';
24
+ parse?: "none" | "full";
25
25
  reply_broadcast?: boolean;
26
26
  thread_ts?: string;
27
27
  unfurl_links?: boolean;
@@ -34,4 +34,4 @@ export interface ChatPostMessageResponse {
34
34
  message: NormalMessage;
35
35
  }
36
36
  export {};
37
- //# sourceMappingURL=chat.d.ts.map
37
+ //# sourceMappingURL=chat.d.ts.map
@@ -1,6 +1,6 @@
1
- import type { CursorPaginationParams, CursorPaginationResponse, TimestampPaginationParams } from '../types/api';
2
- import type { Conversation } from '../types/conversation';
3
- import type { AnyMessage } from '../types/message';
1
+ import type { CursorPaginationParams, CursorPaginationResponse, TimestampPaginationParams } from "../types/api.js";
2
+ import type { Conversation } from "../types/conversation.js";
3
+ import type { AnyMessage } from "../types/message.js";
4
4
  export interface ConversationsInfoParams {
5
5
  /** Conversation ID to learn more about */
6
6
  channel: string;
@@ -36,4 +36,4 @@ export interface ConversationsRepliesParams extends CursorPaginationParams, Time
36
36
  export interface ConversationsRepliesResponse extends CursorPaginationResponse {
37
37
  messages: AnyMessage[];
38
38
  }
39
- //# sourceMappingURL=conversations.d.ts.map
39
+ //# sourceMappingURL=conversations.d.ts.map
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ChannelRef } from './resources/channel';
2
- import type { SlackAPIMethod, SlackAPIParams, SlackAPIResponse } from './api';
1
+ import { ChannelRef } from "./resources/channel.js";
2
+ import type { SlackAPIMethod, SlackAPIParams, SlackAPIResponse } from "./api/index.js";
3
3
  interface AppOptions {
4
4
  token?: string;
5
5
  }
@@ -27,4 +27,4 @@ export declare class App {
27
27
  }>;
28
28
  }
29
29
  export {};
30
- //# sourceMappingURL=client.d.ts.map
30
+ //# sourceMappingURL=client.d.ts.map
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
- import { sleep } from './utils';
2
- import { ChannelRef } from './resources/channel';
3
- import { SlackWebAPIError, SlackWebAPIPlatformError } from './error';
1
+ import { sleep } from "./utils/index.js";
2
+ import { ChannelRef } from "./resources/channel.js";
3
+ import { SlackWebAPIError, SlackWebAPIPlatformError } from "./error.js";
4
4
  export class App {
5
5
  #token;
6
6
  constructor({ token }) {
@@ -24,10 +24,10 @@ export class App {
24
24
  * @param [method='GET'] The HTTP method for the request. Default is `'GET'`
25
25
  * @returns The response from the API call
26
26
  */
27
- async request(endpoint, params, method = 'GET') {
28
- const body = method !== 'GET' ? JSON.stringify(params) : undefined;
27
+ async request(endpoint, params, method = "GET") {
28
+ const body = method !== "GET" ? JSON.stringify(params) : undefined;
29
29
  const url = new URL(`https://slack.com/api/${endpoint}`);
30
- if (method === 'GET' && params) {
30
+ if (method === "GET" && params) {
31
31
  for (const [key, value] of Object.entries(params)) {
32
32
  if (value instanceof Array) {
33
33
  for (const item of value) {
@@ -41,10 +41,10 @@ export class App {
41
41
  }
42
42
  const headers = new Headers();
43
43
  if (body) {
44
- headers.append('Content-Type', 'application/json; charset=utf-8');
44
+ headers.append("Content-Type", "application/json; charset=utf-8");
45
45
  }
46
46
  if (params.token || this.#token) {
47
- headers.set('Authorization', `Bearer ${params.token || this.#token}`);
47
+ headers.set("Authorization", `Bearer ${params.token || this.#token}`);
48
48
  }
49
49
  const res = await request(url.toString(), { method, body, headers });
50
50
  if (!res.ok) {
@@ -56,7 +56,7 @@ export class App {
56
56
  async function request(url, options) {
57
57
  const res = await fetch(url, options);
58
58
  if (res.status === 429) {
59
- const retryAfter = Number(res.headers.get('Retry-After') ?? 2);
59
+ const retryAfter = Number(res.headers.get("Retry-After") ?? 2);
60
60
  await sleep(retryAfter * 1000);
61
61
  return request(url, options);
62
62
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './client';
2
- export * from './error';
3
- //# sourceMappingURL=index.d.ts.map
1
+ export * from "./client.js";
2
+ export * from "./error.js";
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './client';
2
- export * from './error';
1
+ export * from "./client.js";
2
+ export * from "./error.js";
@@ -1,7 +1,7 @@
1
- import type { Conversation } from '../api/types/conversation';
2
- import type { NormalMessage } from '../api/types/message';
3
- import type { App } from '../client';
4
- import { MessageRef, type MessageInstance } from './message';
1
+ import type { Conversation } from "../api/types/conversation.js";
2
+ import type { NormalMessage } from "../api/types/message.js";
3
+ import type { App } from "../client.js";
4
+ import { MessageRef, type MessageInstance } from "./message.js";
5
5
  declare class ChannelMixin {
6
6
  #private;
7
7
  protected client: App;
@@ -23,7 +23,7 @@ declare class ChannelMixin {
23
23
  * @param ts The timestamp of the message
24
24
  * @returns A message reference object
25
25
  */
26
- message(ts: string): MessageRef<import("../api/types/message").AnyMessage>;
26
+ message(ts: string): MessageRef<import("../api/types/message.js").AnyMessage>;
27
27
  }
28
28
  export declare class ChannelRef extends ChannelMixin implements PromiseLike<ChannelInstance> {
29
29
  #private;
@@ -35,4 +35,4 @@ export declare class Channel extends ChannelMixin {
35
35
  }
36
36
  export type ChannelInstance = Channel & Conversation;
37
37
  export {};
38
- //# sourceMappingURL=channel.d.ts.map
38
+ //# sourceMappingURL=channel.d.ts.map
@@ -1,4 +1,4 @@
1
- import { Message, MessageRef } from './message';
1
+ import { Message, MessageRef } from "./message.js";
2
2
  class ChannelMixin {
3
3
  client;
4
4
  #id;
@@ -18,7 +18,7 @@ class ChannelMixin {
18
18
  * @returns The sent message
19
19
  */
20
20
  async send(message) {
21
- const data = await this.client.request('chat.postMessage', { ...message, channel: this.id });
21
+ const data = await this.client.request("chat.postMessage", { ...message, channel: this.id });
22
22
  return new Message(this.client, this.#id, data.ts, data.message);
23
23
  }
24
24
  /**
@@ -37,7 +37,7 @@ export class ChannelRef extends ChannelMixin {
37
37
  return this.#fetch().then(onfulfilled, onrejected);
38
38
  }
39
39
  async #fetch() {
40
- const data = await this.client.request('conversations.info', { channel: this.id });
40
+ const data = await this.client.request("conversations.info", { channel: this.id });
41
41
  return new Channel(this.client, this.id, data.channel);
42
42
  }
43
43
  }
@@ -1,6 +1,6 @@
1
- import type { AnyMessage, NormalMessage } from '../api/types/message';
2
- import type { App } from '../client';
3
- import { ChannelRef } from './channel';
1
+ import type { AnyMessage, NormalMessage } from "../api/types/message.js";
2
+ import type { App } from "../client.js";
3
+ import { ChannelRef } from "./channel.js";
4
4
  declare class MessageMixin {
5
5
  #private;
6
6
  protected client: App;
@@ -25,4 +25,4 @@ export declare class Message<Subtype extends AnyMessage = AnyMessage> extends Me
25
25
  }
26
26
  export type MessageInstance<Subtype extends AnyMessage = AnyMessage> = Message<Subtype> & Subtype;
27
27
  export {};
28
- //# sourceMappingURL=message.d.ts.map
28
+ //# sourceMappingURL=message.d.ts.map
@@ -1,5 +1,5 @@
1
- import { SlackError } from '../error';
2
- import { ChannelRef } from './channel';
1
+ import { SlackError } from "../error.js";
2
+ import { ChannelRef } from "./channel.js";
3
3
  class MessageMixin {
4
4
  client;
5
5
  #channel;
@@ -26,7 +26,7 @@ export class MessageRef extends MessageMixin {
26
26
  return this.#fetch().then(onfulfilled, onrejected);
27
27
  }
28
28
  async #fetch() {
29
- const data = await this.client.request('conversations.replies', {
29
+ const data = await this.client.request("conversations.replies", {
30
30
  channel: this._channelId,
31
31
  ts: this.ts,
32
32
  latest: this.ts,
@@ -34,7 +34,7 @@ export class MessageRef extends MessageMixin {
34
34
  inclusive: true,
35
35
  });
36
36
  if (!data.messages.length) {
37
- throw new SlackError('Message is not found');
37
+ throw new SlackError("Message is not found");
38
38
  }
39
39
  return new Message(this.client, this._channelId, this.ts, data.messages[0]);
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slack.ts",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A fully-typed, opinionated Slack API library",
5
5
  "author": "@jollyroger182",
6
6
  "license": "MIT",
@@ -37,6 +37,7 @@
37
37
  "@types/node": "^25.5.0",
38
38
  "prettier": "^3.8.1",
39
39
  "prettier-plugin-jsdoc": "^1.8.0",
40
+ "ts-add-js-extension": "^1.6.6",
40
41
  "typescript": "^5"
41
42
  },
42
43
  "engines": {