Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web API Type Safety #1673

Merged
merged 125 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
ec34ce6
Remove WebAPICallOptions, replace where it is used with `Record<strin…
Oct 4, 2023
79aaf6e
@slack/web-api: Remove inclusion of arbitrary properties from WebAPIC…
Oct 4, 2023
62ffc7f
Remove optionality on abstract generic Method interface options arg, …
Oct 4, 2023
3cb6c62
adjust return type for fileuploadv2 based on recent change.
Oct 5, 2023
16464e5
adding notes on future type improvements to getFile API args
Oct 5, 2023
b4837a4
Remove note about getFile response type being generated. Tweak some m…
Oct 5, 2023
e2d2faa
Tweaking web-api arguments as I audit them, adding TODOs for future b…
Oct 5, 2023
bc25c1f
Audit of `admin.*` methods complete, added TODOs and updating argumen…
Oct 6, 2023
41a0d79
audited api.test and apps.* method arguments.
Oct 6, 2023
931c06f
bots and auth
Oct 6, 2023
2e9f906
audit bookmarks.*
Oct 6, 2023
3a4a7a2
remove deprecated channels methods, audit chat.* methods.
Oct 18, 2023
7e7b16c
conversations and dialogs methods
Oct 18, 2023
4e0a739
dnd methods
Oct 18, 2023
a3cfd8b
files methods
Oct 18, 2023
124e5f6
remove deprecated groups.* methods.
Oct 18, 2023
2bf4dc9
remove deprecated im.* methods.
Oct 18, 2023
b9c63c8
removed deprecated mpim.* methods.
Oct 18, 2023
daed47d
oauth methods
Oct 18, 2023
202a321
pin methods
Oct 18, 2023
4fca944
reaction methods
Oct 18, 2023
d64c44d
audit reminders methods and factor out optional team id into own mixin.
Oct 18, 2023
fd17314
rtm methods
Oct 18, 2023
6813605
search methods
Oct 18, 2023
6d26fda
stars methods
Oct 18, 2023
a526bec
team methods
Oct 18, 2023
6afd88a
usergroups methods
Oct 18, 2023
0a2692d
users methods
Oct 18, 2023
75ef263
views methods
Oct 18, 2023
9dea3ab
workflows methods
Oct 18, 2023
6ce56f3
Remove unnecessary comment.
Oct 19, 2023
f172551
Address a comment.
Oct 19, 2023
8766ead
move web-api response types to a types subdir, so we can reach into t…
Oct 20, 2023
5864f31
module refs post types reorg
Oct 20, 2023
822496f
Update deprecation warning to remove old deprecated methods, and star…
Oct 20, 2023
9f8df3c
update type tests after moving response/request objects around
Oct 20, 2023
5345456
Start splitting out request interfaces into src/types/request and sep…
Oct 20, 2023
fe414b3
Fix import
Oct 20, 2023
6860612
Move request arguments for users.* apis to own file. Removed the warn…
Oct 24, 2023
206078c
do not apply naming convention linter rules to imports; those might c…
Oct 24, 2023
64950e5
remove tests related to cursorPagination warning, which was removed.
Oct 24, 2023
82b82f6
Describe `users.*` API calls with JSDoc. Document cursor pagination p…
Oct 26, 2023
539ee1d
Document and deprecate workflows.* API methods.
Oct 26, 2023
e6adeb0
Document views.* API methods.
Oct 26, 2023
4a97841
Document search.* API methods.
Oct 26, 2023
98f22c2
Split out usergroups.* API arguments into own file. Document usergrou…
Oct 26, 2023
ac6ca14
Split out team.* API arguments into own file. Document team.* API met…
Oct 26, 2023
fa547db
Split out stars.* API arguments into own file and refactor. Document …
Oct 30, 2023
08b4d0f
Split out rtm.* API arguments into own file and refactor. Document rt…
Oct 30, 2023
b7749a5
Split out reminders.* API arguments into own file. Document reminder …
Oct 31, 2023
896edd4
Bump `@slack/types` dev dependencies to fix the build.
Oct 31, 2023
7a0724f
Factor message/file/file-comment arguments into common.ts for easy re…
Oct 31, 2023
a52a5ce
Bump `@slack/rtm-api` dev dependencies to fix the build and fix eslin…
Oct 31, 2023
753d15d
Bump `@slack/socket-mode` dev dependencies to fix the build and fix e…
Oct 31, 2023
53c0034
Bump `@slack/oauth` dev dependencies to fix the build and fix eslint …
Oct 31, 2023
5a5cdb1
Split out pins.* API arguments into own file. Document pin API methods.
Oct 31, 2023
11c69d2
Split out openid.* API arguments into own file. Document openid API m…
Oct 31, 2023
0e24e84
Factor out common OAuth/OpenID arguments into common.ts. Add descript…
Oct 31, 2023
352f985
Document migration.* methods and split out their arguments into own f…
Oct 31, 2023
336c62d
halfway through file uploads refactor
Nov 2, 2023
3c8d14a
Fix up the build related to reworked file upload arguments.
Nov 2, 2023
9446539
Document files.* APIs and finish rework of files API argument shapes.
Nov 2, 2023
f35fb45
Playing around with the type tests for files.
Nov 2, 2023
59026ca
lint tweaks for type tests, first stab at type tests.
Nov 3, 2023
3eaf51b
merge main branch in
Nov 3, 2023
2996db8
Add special import rules for type tests: allow reaching into src/ dir…
Nov 3, 2023
e9ac27a
tweaking some files.* API type tests.
Nov 14, 2023
7065af8
merging in latest `main`
Nov 15, 2023
7efacf7
fixes post-merge
Nov 15, 2023
d2a7882
small refactor of files.* API arguments and finished types tests for …
Nov 15, 2023
bb042dc
add type tests for views.* API arguments
Nov 16, 2023
13f0b0e
add type tests for users.* methods
Nov 16, 2023
a8c8dc5
usergroups.update only requires `usergroup` parameter, all other are …
Nov 16, 2023
524493d
new file for tooling.* API argument types, test types for it too. JSD…
Nov 16, 2023
3f5a661
team.* API argument type tests.
Nov 16, 2023
0bdd2af
search sort and sort dir args are optional, actually (thank you, test…
Nov 16, 2023
75a1e95
type tests for rtm.* APIs
Nov 16, 2023
1db4e03
added reminders.* API type tests.
Nov 17, 2023
4bea006
added reactions.* API type tests.
Nov 17, 2023
c3af002
added pins.* API type tests.
Nov 17, 2023
5a1a354
added openid.* API type tests.
Nov 17, 2023
cd81272
added oauth.* API type tests.
Nov 17, 2023
2ae4033
added migration.* API type tests.
Nov 17, 2023
a50ae8e
JSdoc, test types and separate request argument type file for emoji.l…
Nov 20, 2023
d887ef1
JSdoc, test types and separate request argument type file for dnd.* APIs
Nov 20, 2023
4d83293
JSdoc, test types and separate request argument type file for dialog.…
Nov 20, 2023
2ffa1bd
JSdoc, test types and separate request argument type file for convers…
Nov 20, 2023
587b71c
forgot one jsdoc
Nov 20, 2023
658cf45
JSdoc chat.* API methods
Nov 22, 2023
a29e77a
first pass at chat.* API method arg refactor and initial type tests.
Nov 22, 2023
6cc5f84
OK back in action: extensive postEphemeral type tests and tweaks to t…
Nov 22, 2023
4956cc8
extensive postMessage type tests and tweaks to types to make them pass
Nov 22, 2023
efec9ea
Factor out unfurl_* props into Unfurls interface for chat.* method ar…
Nov 22, 2023
71fd621
When assembling composite types, re-order them so that required prope…
Nov 23, 2023
38b1a4e
rejigging types around to get type tests passing - TS is weird.
Nov 23, 2023
40f706c
finished arg refactor and type tests for chat.* APIs.
Nov 23, 2023
c3aaac4
Refactor arguments and type tests for calls.* APIs.
Nov 23, 2023
73e1a9e
Refactor arguments and type tests for bots.* and bookmarks.* APIs.
Nov 23, 2023
64529a0
Refactor arguments and type tests for auth.* APIs.
Nov 23, 2023
6323f6e
jsdoc and some type tests for apps.* API, but manifest APIs needs som…
Nov 24, 2023
f453f2e
Refactor arguments and type tests for api.test API.
Nov 24, 2023
a3db517
stubbing out bits for admin.analytics.getFile API but need access to …
Nov 24, 2023
80c3d5e
Refactor arguments and type tests for admin.apps.* APIs.
Nov 24, 2023
d548bff
Refactor arguments and type tests for admin.auth.* APIs.
Nov 24, 2023
1d94a70
start of admin.barrier api rework
Nov 27, 2023
3687c89
Refactor arguments and type tests for admin.barriers.* APIs.
Nov 27, 2023
94c7c57
Refactor arguments and type tests for admin.analytics.getFile API.
Nov 28, 2023
08d1413
part of the way there for admin.conversations APIs
Nov 30, 2023
7d03359
Finishing up admin.conversations.* APIs.
Dec 5, 2023
38dfcde
Refactor arguments and type tests for admin.emoji.* APIs.
Dec 5, 2023
692792f
Refactor arguments and type tests for admin.functions.* APIs.
Dec 7, 2023
456c49b
merge in latest main (support for functions.* APIs)
Dec 7, 2023
2f1f9da
Refactor arguments and type tests for functions.* APIs.
Dec 7, 2023
22efb5a
fix bad reference
Dec 7, 2023
0bec7f6
Refactor arguments and type tests for admin.inviteRequests.* APIs.
Dec 7, 2023
0f59b96
Refactor arguments and type tests for admin.roles.* APIs.
Dec 7, 2023
fcebf0e
Refactor arguments and type tests for admin.teams.* APIs.
Dec 7, 2023
b6f1a88
users.profile.set should accept an object for the `profile` argument.
Dec 11, 2023
d0526bf
Refactor arguments and type tests for admin.usergroups.* APIs.
Dec 12, 2023
260e242
Refactor arguments and type tests for admin.users.* APIs.
Dec 12, 2023
a193b6e
Refactor arguments and type tests for admin.workflows.* APIs.
Dec 12, 2023
f01e0e6
Refactor arguments and type tests for apps.manifest.* APIs. Add first…
Dec 13, 2023
920c3fb
Update packages/web-api/src/types/request/bots.ts
Dec 14, 2023
6e2d515
7.0.0-rc.0 (#1704)
Dec 14, 2023
f340482
Tweaks to some JSDocs and being extra careful to allow for `text` wit…
Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion lint-configs/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
node_modules
20 changes: 18 additions & 2 deletions lint-configs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ module.exports = {
format: ['camelCase'],
leadingUnderscore: 'allow',
},
{
selector: 'import',
format: null, // do not force conventions on imports
},
{
selector: 'variable',
// PascalCase for variables is added to allow exporting a singleton, function library, or bare object as in
Expand Down Expand Up @@ -246,8 +250,7 @@ module.exports = {
allow: [
'**/middleware/*', // the src/middleware directory doesn't export a module, it's just a namespace.
'**/receivers/*', // the src/receivers directory doesn't export a module, it's just a namespace.
'**/types/**/*',
'**/types/*', // type heirarchies should be used however one wants
'**/types/**/*', // type heirarchies should be used however one wants
],
}],

Expand Down Expand Up @@ -296,6 +299,19 @@ module.exports = {
'symbol-description': 'off',
},
},
{
files: ['test/types/**/*.test-d.ts'],
extends: ['plugin:@typescript-eslint/disable-type-checked'],
rules: {
'import/no-internal-modules': ['error', {
// Use the following option to set a list of allowable globs in this project.
allow: [
'**/src/**/*', // allow type tests to reach into src/
'**/types/**/*', // type heirarchies should be used however one wants
],
}],
}
},
],
};

Expand Down
34 changes: 16 additions & 18 deletions packages/oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"lint": "eslint --fix --ext .ts src",
"test": "npm run lint && npm run test:mocha",
"test:mocha": "nyc mocha --config .mocharc.json src/*.spec.js src/**/*.spec.js src/*.spec.ts src/**/*.spec.ts",
"coverage": "codecov -F oauthhelper --root=$PWD",
"ref-docs:model": "api-extractor run",
"watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm run build"
},
Expand All @@ -47,29 +46,28 @@
"lodash.isstring": "^4.0.1"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.19.4",
"@types/chai": "^4.2.11",
"@types/mocha": "^9.1.0",
"@types/sinon": "^10.0.11",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.0",
"chai": "^4.2.0",
"codecov": "^3.0.4",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.6.1",
"@microsoft/api-extractor": "^7.38.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.20",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"chai": "^4.3.8",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^9.2.1",
"mocha": "^10.2.0",
"nop": "^1.0.0",
"nyc": "^15.1.0",
"rewiremock": "^3.13.9",
"shx": "^0.3.2",
"sinon": "^9.0.2",
"source-map-support": "^0.5.12",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"superagent": "^3.3.1",
"ts-node": "^8.2.0",
"ts-node": "^10.8.1",
"typescript": "^4.1",
"uncaughtException": "^1.0.0"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/oauth/src/callback-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function defaultCallbackSuccess(
<p>Redirecting to the Slack App... click <a href="${escapeHtml(redirectUrl)}">here</a>. If you use the browser version of Slack, click <a href="${escapeHtml(browserUrl)}" target="_blank">this link</a> instead.</p>
</body>
</html>`;
// eslint-disable-next-line @typescript-eslint/naming-convention
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(htmlResponse);
}
Expand All @@ -139,6 +140,7 @@ export function defaultCallbackFailure(
default:
httpStatus = 500;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
res.writeHead(httpStatus, { 'Content-Type': 'text/html; charset=utf-8' });
const html = `<html>
<head>
Expand Down
4 changes: 1 addition & 3 deletions packages/oauth/src/install-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,7 @@ export class InstallProvider {
// End: Build the installation object

if (options?.afterInstallation !== undefined) {
shouldProceed = await options.afterInstallation(
installation, installOptions, req, res,
);
shouldProceed = await options.afterInstallation(installation, installOptions, req, res);
}
if (!shouldProceed) {
// When options.beforeInstallation returns false,
Expand Down
16 changes: 8 additions & 8 deletions packages/rtm-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
"ws": "^7.5.3"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.6.1",
"@microsoft/api-extractor": "^7.38.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"shx": "^0.3.2",
"typescript": "^4.1.0"
Expand Down
1 change: 1 addition & 0 deletions packages/rtm-api/src/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class KeepAlive extends EventEmitter {
.catch((error) => {
this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rtm-api/src/RTMClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ export class RTMClient extends EventEmitter {
*
* If the awaitReply parameter is set to false, then the returned Promise is resolved as soon as the message is sent
* from the websocket.
*
* @param awaitReply - whether to wait for an acknowledgement response from the platform before resolving the returned
* Promise.
* @param type - the message type
Expand Down Expand Up @@ -629,6 +628,7 @@ export class RTMClient extends EventEmitter {
let event;
try {
event = JSON.parse(data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (parseError: any) {
// prevent application from crashing on a bad message, but log an error to bring attention
this.logger.error(
Expand Down
30 changes: 15 additions & 15 deletions packages/socket-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@
"ws": "^7.5.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.0",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.6",
"chai": "^4.2.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.6.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"chai": "^4.3.8",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^9.1.0",
"nyc": "^14.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"shx": "^0.3.2",
"ts-node": "^8.2.0",
"sinon": "^7.3.2",
"source-map-support": "^0.5.12",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.8.1",
"typescript": "^4.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/socket-mode/src/SocketModeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export class SocketModeClient extends EventEmitter {
private numOfConsecutiveReconnectionFailures: number = 0;

/* eslint-disable @typescript-eslint/indent, newline-per-chained-call */
private connectingStateMachineConfig: Configuration<ConnectingState, Event>
= Finity.configure<ConnectingState, Event>()
private connectingStateMachineConfig: Configuration<ConnectingState, Event> = Finity
.configure<ConnectingState, Event>()
.global()
.onStateEnter((state) => {
this.logger.debug(`Transitioning to state: ${State.Connecting}:${state}`);
Expand Down
16 changes: 8 additions & 8 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"ref-docs:model": "api-extractor run"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.6.1",
"@microsoft/api-extractor": "^7.38.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-node": "^11.1.0",
"shx": "^0.3.2",
"typescript": "^4.1.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/web-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slack/web-api",
"version": "6.9.0",
"version": "7.0.0-rc.0",
"description": "Official library for using the Slack Platform's Web API",
"author": "Slack Technologies, LLC",
"license": "MIT",
Expand Down Expand Up @@ -62,6 +62,7 @@
"@microsoft/api-extractor": "^7.38.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.20",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.0",
"busboy": "^1.6.0",
Expand Down
20 changes: 0 additions & 20 deletions packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,26 +797,6 @@ describe('WebClient', function () {
this.method = 'conversations.list';
});

describe('logging', function () {
beforeEach(function () {
this.capture = new CaptureConsole();
this.capture.startCapture();
});
it('should log a warning when called with a method not known to be cursor pagination enabled', function () {
this.client.paginate('method');
const output = this.capture.getCapturedText();
assert.isNotEmpty(output);
});
it('should not log a warning when called with a known cursor pagination enabled', function () {
this.client.paginate(this.method);
const output = this.capture.getCapturedText();
assert.isEmpty(output);
});
afterEach(function () {
this.capture.stopCapture();
});
});

describe('when not given shouldStop predicate', function () {
it('should return an AsyncIterator', function () {
const iterator = this.client.paginate(this.method);
Expand Down
Loading