-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a client instance to function handler params (#101)
* setting up client as new param passed into all function handlers * adding enrichContext to centralize where it's done across handlers * updating api version for testing * using published version of api * updating types * removing type * new deno version fmt adjustments * updating tests, adding client to unhandledEvent handlers * checking for client in unhandledEvent handler * adding enrichContext tests * updating exported SlackFunctionHandler type to represent runtime context and not enriched SlackFunction() handler context * switching to ts-expect-error * export SlackAPI * adding some api exports
- Loading branch information
1 parent
c25b335
commit c5fa357
Showing
19 changed files
with
519 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { SlackAPI } from "https://deno.land/x/deno_slack_api@1.1.0/mod.ts"; | ||
export type { | ||
SlackAPIClient, | ||
Trigger, | ||
} from "https://deno.land/x/deno_slack_api@1.1.0/types.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SlackAPI } from "../deps.ts"; | ||
import { | ||
BaseRuntimeFunctionContext, | ||
FunctionContextEnrichment, | ||
} from "./types.ts"; | ||
|
||
export const enrichContext = ( | ||
// deno-lint-ignore no-explicit-any | ||
context: BaseRuntimeFunctionContext<any>, | ||
): typeof context & FunctionContextEnrichment => { | ||
const token = context.token; | ||
const slackApiUrl = (context.env || {})["SLACK_API_URL"]; | ||
|
||
const client = SlackAPI(token, { | ||
slackApiUrl: slackApiUrl ? slackApiUrl : undefined, | ||
}); | ||
|
||
return { | ||
...context, | ||
client, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { assertExists } from "../dev_deps.ts"; | ||
import { enrichContext } from "./enrich-context.ts"; | ||
import { BaseRuntimeFunctionContext } from "./types.ts"; | ||
|
||
Deno.test("enrichContext with no env.SLACK_API_URL", () => { | ||
// deno-lint-ignore no-explicit-any | ||
const ctx: BaseRuntimeFunctionContext<any> = { | ||
env: {}, | ||
inputs: {}, | ||
team_id: "team", | ||
token: "token", | ||
}; | ||
|
||
const newContext = enrichContext(ctx); | ||
|
||
assertExists(newContext.client); | ||
}); | ||
|
||
Deno.test("enrichContext with env.SLACK_API_URL", () => { | ||
// deno-lint-ignore no-explicit-any | ||
const ctx: BaseRuntimeFunctionContext<any> = { | ||
env: { | ||
"SLACK_API_URL": "https://something.slack.com/api", | ||
}, | ||
inputs: {}, | ||
team_id: "team", | ||
token: "token", | ||
}; | ||
|
||
const newContext = enrichContext(ctx); | ||
|
||
assertExists(newContext.client); | ||
}); |
Oops, something went wrong.