Skip to content

Commit

Permalink
feat: add isEnterpriseInstall to Context (#1511) - fixes #1510
Browse files Browse the repository at this point in the history
  • Loading branch information
rockingskier authored Jul 5, 2022
1 parent 7eec438 commit 9bb3cb0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
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,
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
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

0 comments on commit 9bb3cb0

Please sign in to comment.