@stackoverflow/backstage-stack-overflow-teams-collator 1.4.0

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.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+
2
+ # Stack Overflow for Teams Search Backend Module
3
+
4
+ This module for the search plugin is an enhanced version of the original [Stack Overflow collator](https://github.com/backstage/backstage/tree/master/plugins/search-backend-module-stack-overflow-collator). It provides additional information while coded to work specifically with Stack Overflow for Teams API Version 3.
5
+
6
+ ## Getting started
7
+
8
+ Before we begin, make sure:
9
+
10
+ - You have created your own standalone Backstage app using @backstage/create-app and not using a fork of the backstage repository. If you haven't setup Backstage already, start [here](https://backstage.io/docs/getting-started/).
11
+
12
+ To use any of the functionality this plugin provides, you need to start by configuring your App with the following config:
13
+
14
+ ```yaml
15
+ stackoverflow:
16
+ baseUrl: https://api.stackoverflowteams.com # alternative: your Stack Overflow Enterprise site
17
+ teamName: $STACK_OVERFLOW_TEAM_NAME # optional if you are on Enterprise
18
+ apiAccessToken: $STACK_OVERFLOW_API_ACCESS_TOKEN
19
+ ```
20
+
21
+ ### Stack Overflow for Teams
22
+
23
+ If you have a private Stack Overflow instance and/or a private Stack Overflow Team you will need to supply a Personal Access Token. You can read more about how to set this up by going to [Stack Overflow's Help Page](https://stackoverflowteams.help/en/articles/7913768-stack-overflow-for-teams-api-v3).
24
+
25
+ ## Areas of Responsibility
26
+
27
+ This stack overflow backend plugin is primarily responsible for the following:
28
+
29
+ - Provides a `StackOverflowQuestionsCollatorFactory`, which can be used in the search backend to index stack overflow questions to your Backstage Search.
30
+
31
+ ### Index Stack Overflow Questions to search
32
+
33
+ Before you are able to start index stack overflow questions to search, you need to go through the [search getting started guide](https://backstage.io/docs/features/search/getting-started).
34
+
35
+ When you have your `packages/backend/src/plugins/search.ts` file ready to make modifications, add the following code snippet to add the `StackOverflowQuestionsCollatorFactory`. Note that you can optionally modify the `requestParams`, otherwise it will defaults to `{ order: 'desc', sort: 'activity' }`.
36
+
37
+ ```ts
38
+ indexBuilder.addCollator({
39
+ schedule,
40
+ factory: StackOverflowQuestionsCollatorFactory.fromConfig(env.config, {
41
+ logger: env.logger,
42
+ requestParams: {
43
+ tagged: ['backstage'],
44
+ pagesize: 100,
45
+ },
46
+ }),
47
+ });
48
+ ```
49
+
50
+ ## New Backend System
51
+
52
+ This package exports a module that extends the search backend to also indexing the questions exposed by the [`Stack Overflow for Teams API version 3`](https://stackoverflowteams.help/en/articles/7913768-stack-overflow-for-teams-api-v3).
53
+
54
+ ### Installation
55
+
56
+ Add the module package as a dependency:
57
+
58
+ ```bash
59
+ # From your Backstage root directory
60
+ yarn --cwd packages/backend add backstage-stack-overflow-teams-collator
61
+ ```
62
+
63
+ Add the collator to your backend instance, along with the search plugin itself:
64
+
65
+ ```tsx
66
+ // packages/backend/src/index.ts
67
+ import { createBackend } from '@backstage/backend-defaults';
68
+
69
+ const backend = createBackend();
70
+ backend.add(import('@backstage/plugin-search-backend'));
71
+ backend.add(
72
+ import('backstage-stack-overflow-teams-collator'),
73
+ );
74
+ backend.start();
75
+ ```
76
+
77
+ You may also want to add configuration parameters to your app-config, for example for controlling the scheduled indexing interval. These parameters should be placed under the `stackoverflow` key. See [the config definition file](https://github.com/estoesmoises/backstage-stackoverflow/blob/main/plugins/search-backend-module-stack-overflow-teams-collator/config.d.ts) for more details.
package/config.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright 2023 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface Config {
18
+ /**
19
+ * Configuration options for the stack overflow plugin
20
+ */
21
+ stackoverflow?: {
22
+ /**
23
+ * The base url of the Stack Overflow API used for the plugin, if no BaseUrl is provided it will default to https://api.stackoverflowteams.com
24
+ */
25
+ baseUrl?: string;
26
+
27
+ /**
28
+ * The API Access Token to authenticate to Stack Overflow API Version 3
29
+ * @visibility secret
30
+ */
31
+ apiAccessToken: string;
32
+
33
+ /**
34
+ * The name of the team for a Stack Overflow for Teams account. When teamName is provided baseUrl will always be https://api.stackoverflowteams.com
35
+ */
36
+ teamName?: string;
37
+
38
+ /**
39
+ * Type representing the request parameters.
40
+ */
41
+ requestParams?: {
42
+ [key: string]: string | string[] | number;
43
+ };
44
+ /**
45
+ * Type representing the schedule options.
46
+ */
47
+ schedule?: {
48
+ frequency?: TimeUnit;
49
+ timeout?: TimeUnit;
50
+ initialDelay?: TimeUnit;
51
+ };
52
+
53
+
54
+ };
55
+ }
56
+
57
+ type TimeUnit = { minutes?: number; hours?: number; seconds?: number }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@stackoverflow/backstage-stack-overflow-teams-collator",
3
+ "version": "1.4.0",
4
+ "description": "A module for the search backend that exports stack overflow for teams modules",
5
+ "backstage": {
6
+ "role": "backend-plugin-module",
7
+ "pluginId": "search",
8
+ "pluginPackage": "@backstage/plugin-search-backend"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/StackExchange/backstage-stackoverflow"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/StackExchange/backstage-stackoverflow/issues"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "main": "src/index.ts",
22
+ "types": "src/index.ts",
23
+ "files": [
24
+ "dist",
25
+ "config.d.ts"
26
+ ],
27
+ "scripts": {
28
+ "build": "backstage-cli package build",
29
+ "clean": "backstage-cli package clean",
30
+ "lint": "backstage-cli package lint",
31
+ "prepack": "backstage-cli package prepack",
32
+ "postpack": "backstage-cli package postpack",
33
+ "start": "backstage-cli package start",
34
+ "test": "backstage-cli package test"
35
+ },
36
+ "dependencies": {
37
+ "@backstage/backend-plugin-api": "latest",
38
+ "@backstage/config": "latest",
39
+ "@backstage/plugin-search-backend-node": "latest",
40
+ "@backstage/plugin-search-common": "latest",
41
+ "qs": "^6.9.4"
42
+ },
43
+ "devDependencies": {
44
+ "@backstage/backend-test-utils": "latest",
45
+ "@backstage/cli": "latest",
46
+ "msw": "^1.2.1",
47
+ "typescript": "^5.8.2"
48
+ }
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright 2023 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * @packageDocumentation
19
+ * A module for the search backend that exports Stack Overflow modules.
20
+ */
21
+
22
+ export * from './collators';
23
+ export { searchStackOverflowCollatorModule as default } from './module';