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

feat: add isEnterpriseInstall to Context #1511

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,9 @@ export default class App {
error: e,
logger: this.logger,
body: bodyArg,
context: {},
context: {
isEnterpriseInstall,
},
});
}
}
Expand All @@ -854,6 +856,7 @@ export default class App {
const context: Context = {
...authorizeResult,
...event.customProperties,
isEnterpriseInstall,
rockingskier marked this conversation as resolved.
Show resolved Hide resolved
retryNum: event.retryNum,
retryReason: event.retryReason,
};
Expand Down Expand Up @@ -1329,7 +1332,7 @@ function buildSource<IsEnterpriseInstall extends boolean>(
if (type === IncomingEventType.Event) {
const bodyAsEvent = body as SlackEventMiddlewareArgs['body'];
if (Array.isArray(bodyAsEvent.authorizations) && bodyAsEvent.authorizations[0] !== undefined) {
// The enteprise_id here can be null when the workspace is not in an Enterprise Grid
// The enterprise_id here can be null when the workspace is not in an Enterprise Grid
rockingskier marked this conversation as resolved.
Show resolved Hide resolved
const theId = bodyAsEvent.authorizations[0].enterprise_id;
return theId !== null ? theId : undefined;
}
Expand Down
52 changes: 39 additions & 13 deletions src/middleware/builtin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ describe('Built-in global middleware', () => {
const fakeArgs = {
next: () => Promise.resolve(),
message: createFakeMessageEvent(),
context: {},
context: {
isEnterpriseInstall: false,
},
} as unknown as MessageMiddlewareArgs;
const { directMention } = await importBuiltin();

Expand Down Expand Up @@ -510,7 +512,9 @@ describe('Built-in global middleware', () => {
respond: noop,
ack: noop,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
};
await onlyCommands(args);
assert.isTrue(fakeNext.called);
Expand All @@ -530,7 +534,9 @@ describe('Built-in global middleware', () => {
respond: noop,
ack: noop,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
};
await onlyCommands(args);
assert.isTrue(fakeNext.notCalled);
Expand All @@ -553,7 +559,9 @@ describe('Built-in global middleware', () => {
respond: noop,
ack: noop,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
};
}

Expand Down Expand Up @@ -604,7 +612,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
...args,
};
// FIXME: Using any is a workaround for TypeScript 4.7 breaking changes
Expand All @@ -626,7 +636,9 @@ describe('Built-in global middleware', () => {
respond: noop,
ack: noop,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
};
await onlyEvents(args);
assert.isFalse(fakeNext.called);
Expand Down Expand Up @@ -690,7 +702,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await matchEventType('app_mention')(args);
Expand All @@ -706,7 +720,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await matchEventType(/app_mention|app_home_opened/)(args);
Expand All @@ -722,7 +738,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await matchEventType(/app_mention|app_home_opened/)(args);
Expand All @@ -738,7 +756,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await matchEventType('app_home_opened')(args);
Expand All @@ -754,7 +774,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
} as any;
await matchEventType(/foo/)(args);
Expand Down Expand Up @@ -796,7 +818,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await subtype('bot_message')(args);
Expand All @@ -812,7 +836,9 @@ describe('Built-in global middleware', () => {
logger,
client,
next: fakeNext,
context: {},
context: {
isEnterpriseInstall: false,
},
..._args,
};
await subtype('me_message')(args);
Expand Down
4 changes: 4 additions & 0 deletions src/types/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export interface Context extends StringIndexed {
* Enterprise Grid Organization ID.
*/
enterpriseId?: string;
/**
* Is the app installed at an Enterprise level?
*/
isEnterpriseInstall: boolean,

/**
* Retry count of an Events API request (this property does not exist for other requests)
Expand Down