@interopio/search-api 2.0.2 → 2.0.4

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 CHANGED
@@ -1,5 +1,233 @@
1
1
  # IO Connect Search API
2
2
 
3
+ Apps can perform searches and provide results for others' searches.
4
+
5
+ For example, let's say an app provides Seinfeld quotes, and wants to make those quotes available to any other app. The Seinfeld app could register itself as a search provider with this:
6
+
7
+ ```js
8
+ // Registering as a provider
9
+ const provider = await glue.search.registerProvider({
10
+ name: "Seinfeld-Quotes"
11
+ });
12
+
13
+ // Registering how the provider will respond to queries
14
+ provider.onQuery(({search, sendResults, done}) => {
15
+ const textOfQuote = doStuffInternally(search);
16
+
17
+ sendResults({
18
+ type: {
19
+ name: "tv-quote",
20
+ displayName: "Seinfeld Quotes"
21
+ },
22
+ id: "quote-123",
23
+ description: textOfQuote
24
+ });
25
+
26
+ done();
27
+ })
28
+ ```
29
+
30
+ Now, let's say an app is interested to see if there are any Seinfeld quotes with the word "architect". It would use the following function:
31
+
32
+ ```js
33
+ const query = await glue.search.query({search: "architect"});
34
+ query.onResults((result) => {
35
+ /*
36
+ // Example value for result -
37
+ {
38
+ provider: {
39
+ id: "INTERNAL_ID",
40
+ interopId: "INTERNAL_INSTANCE_ID",
41
+ name: "Seinfeld-Quotes" // The search provider's name
42
+ appName: "seinfeld-app", // The app that registered the search provider
43
+ },
44
+ result: {
45
+ type: {
46
+ name: "tv-quote",
47
+ displayName: "Seinfeld Quotes"
48
+ },
49
+ id: "quote-123",
50
+ description: "You know I always wanted to pretend I was an architect.
51
+ }
52
+ }
53
+ */
54
+ })
55
+ ```
56
+
57
+ ## Checklists
58
+
59
+ If you're writing a custom search provider, here are things to make sure you implement:
60
+
61
+ Basics
62
+ - [ ] Registering provider
63
+ - [ ] Generate and send results
64
+
65
+ Other considerations:
66
+ - [ ] Call `done()` once you are done (in case queriers are waiting on `onCompleted()`)
67
+ - [ ] Are you checking the `types` property? You don't want to ignore the restrictions the querier placed on their query.
68
+ - [ ] Are you checking the `maxResults` property? You don't want to return more that the querier asked for.
69
+ - [ ] Ditto for `maxResultsByType`
70
+ - [ ] Did you set up error handling, and include the `error()` callback if necessary?
71
+ - [ ] Do your queries take a long enough time that they might get cancelled? If so, are you handling `onQueryCancel`?
72
+
73
+
74
+ If you're querying a search providerm here are things to make sure you implement:
75
+ - [ ] Call the query (eg `const query = await glue.search.query({search: "My search string"})`)
76
+ - [ ] Handle `onResults` (eg `query.onResults(displaySearchResult)`)
77
+ - [ ] Handle `onError`
78
+
79
+ Other considerations:
80
+ - [ ] Is there a situation where you need to `cancel()` your query?
81
+ - [ ] Do you need to limit the quantity of results you receive (using `providerLimits`)?
82
+ - [ ] Do you need `onCompleted`, to see when different search providers have finished? If so, does it also make sense to include a timeout (in case a search provider *doesn't* indicate when they're `done()`?)
83
+ - [ ] Are you interested in only certain **types** of content? Would it make sense to call `listTypes()` to see if the type you're looking is being provided? Would it makse sense to limit your search results to a certain type?
84
+ - [ ] Are you interested in only certain **providers**? Would it make sense to call `listProviders()` to see if the provider you're looking is present? Would it makse sense to limit your search results to certain providers?
85
+ - [ ] Sometimes, search results include `actions`. If that makes sense for your use cases, are you handling incoming actions?
86
+
87
+
88
+ ## API
89
+
90
+ glue.search has the following methods:
91
+ - getDebounceMS
92
+ - listProviders
93
+ - listTypes
94
+ - query
95
+ - registerProvider
96
+ - setDebounceMS
97
+ - version
98
+
99
+ ### registerProvider
100
+
101
+ Config options for `.registerProvider()` are:
102
+ - `name` (required)
103
+ - `types` (optional but recommended). If you register a custom type, it will appear in the `.listTypes` method.
104
+
105
+ ```js
106
+ const provider = await glue.search.registerProvider({name: "test"});
107
+ ```
108
+
109
+ ```js
110
+ const provider = await glue.search.registerProvider({
111
+ name: "test",
112
+ types: [
113
+ {name: "application"}
114
+ ]
115
+ });
116
+ ```
117
+
118
+ `registerProvider` returns a promise that resolves to a `Provider` object. This has the following available methods:
119
+ - `onQuery` - callback when search queries are executed
120
+ - `onQueryCancel` - callback when an app cancels its search query
121
+ - `unregister` - an unregistration method.
122
+
123
+ :::tip
124
+ Search providers are automatically unregistered when windows are closed. Unregistration is a good cleanup action, but may not be required.
125
+ :::
126
+
127
+ The `onQuery` callback provides a `ProviderQuery` object, with the following properties:
128
+ - id - referenced when cancelling the query
129
+ - search - the text being searched for
130
+ - providers - the providers the querier is interested in
131
+ - types - the SearchTypes the querier is interested in
132
+ - providerLimits.maxResults - the maximum number of results the querier wants to receive from each provider
133
+ - providerLimits.maxResultsPerType - the maximum number of results PER TYPE the querier wants to recevie from each provider
134
+ - sendResult - callback for sending an individual result. (The querier receives this with the `query.onResults()` callback)
135
+ - error - callback if there's an error (The querier receives this with the `query.onError()` callback)
136
+ - done - callback once all results have been sent (The querier receives this with the `query.done()` callback)
137
+
138
+ When sending a result, you supply a `QueryResult` object. The properties of that object are:
139
+ - type (required) - a `SearchType` (eg: `{name: "application"}`)
140
+ - id
141
+ - displayName
142
+ - description
143
+ - iconURL
144
+ - metadata
145
+ - action - metadata information about a method you'd want to invoke
146
+ - secondaryActions - more actions
147
+
148
+ ### query
149
+
150
+ You create a query object with the `query()` method:
151
+ ```js
152
+ const query = await glue.search.query({search: "My search query"});
153
+ ```
154
+
155
+ The `query` method takes the following properties:
156
+ - `search` (required) (string) - what you're searching for
157
+ - `providers` (`ProviderData[]`) - providers you want to limit your search to
158
+ - `types` (`SearchType[]`) - the types of results you want to limit your search to
159
+ - `providerLimits.maxResults` (number) - the maximum number of results the querier wants to receive from each provider
160
+ - `providerLimits.maxResultsPerType` (number) - the maximum number of results PER TYPE the querier wants to recevie from each provider
161
+
162
+
163
+ The query object you receive has the following methods:
164
+ - `cancel()` - Cancels the query. (See provider's `onQueryCancel()`)
165
+ - `onResults()` - Callback to receive results (See provider's query handling for `sendResult()`)
166
+ - `onCompleted()` - Callback when provider is done (See provider's query handling for `done()`)
167
+ - `onError()` - Callback when provider has an error (See provider's query handling for `error()`)
168
+
169
+ ### listProviders
170
+
171
+ ```js
172
+ await glue.search.listProviders();
173
+ /*
174
+ Example results: [
175
+ {
176
+ appName: "fsbl-test-butler",
177
+ id: "INTERNAL_ID",
178
+ interopId: "INSTANCE_ID",
179
+ name: "registered-search-provider-custom-name",
180
+ },
181
+ {
182
+ appName: "tester",
183
+ id: "INTERNAL_ID",
184
+ interopId: "INSTANCE_ID",
185
+ name: "my-tester",
186
+ types: [{name: "test-type"}]
187
+ }
188
+ ]
189
+ */
190
+ ```
191
+
192
+ ### listTypes
193
+
194
+ You can see what search types are available. This is especially useful if you are relying on a custom search type from another app, and want to confirm that that app has already been registered.
195
+
196
+ ```js
197
+ await glue.search.listTypes();
198
+ /*
199
+ Example results: [
200
+ {name: "customSearchType"},
201
+ {name: "application"},
202
+ {name: "layout"},
203
+ {name: "workspace"},
204
+ {name: "swimlane"},
205
+ {name: "action"}
206
+ ]
207
+ */
208
+ ```
209
+
210
+ ### getDebounceMS, setDebounceMS
211
+
212
+ **Default debounce: 0ms**
213
+
214
+ Queries can be debounced. If you plan on querying based on individual keystrokes or mouse movements, you can potentially generate an unnecessarily large message flurry. Debouncing the queries will reduce search query traffic.
215
+
216
+ Here are examples of getting/setting the debounce time:
217
+ ```js
218
+ // Get the debounce time:
219
+ glue.search.getDebounceMS(); // returns 0 by default
220
+
221
+ // Set the debounce time to 20ms:
222
+ glue.search.setDebounceMS(20);
223
+ ```
224
+
225
+ ## Actions
226
+ TBD
227
+
228
+
229
+ ## Developer notes
230
+
3
231
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
232
 
5
233
  // package name: @interopio/search-api -> adds the Search API
@@ -13,4 +241,4 @@
13
241
  // lib uses: shared context to providers state management
14
242
  // method used when registered as provider to accept queries
15
243
 
16
- // category = display name for type
244
+ // category = display name for type
package/changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ 2.0.3
2
+ chore: bump due to dependencies update
3
+ 2.0.2
4
+ chore: updated .npmignore
1
5
  2.0.1
2
6
  feat: Introduce the new IO Connect Search API
3
7
  1.3.2
@@ -1799,7 +1799,7 @@ class ProviderController {
1799
1799
  }
1800
1800
  }
1801
1801
 
1802
- var version = "2.0.2";
1802
+ var version = "2.0.4";
1803
1803
 
1804
1804
  class SearchFacade {
1805
1805
  constructor(main) {
@@ -1805,7 +1805,7 @@
1805
1805
  }
1806
1806
  }
1807
1807
 
1808
- var version = "2.0.2";
1808
+ var version = "2.0.4";
1809
1809
 
1810
1810
  class SearchFacade {
1811
1811
  constructor(main) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interopio/search-api",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Glue42 Search API",
5
5
  "main": "./dist/search-api.umd.js",
6
6
  "module": "./dist/search-api.es.js",
@@ -43,10 +43,10 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@interopio/core": "^6.0.2",
46
+ "@interopio/core": "^6.0.4",
47
47
  "callback-registry": "^2.5.2",
48
48
  "decoder-validate": "0.0.2",
49
49
  "nanoid": "^4.0.0"
50
50
  },
51
- "gitHead": "700bd12232dc1d7d0a76e743232fdef0138cfcc9"
51
+ "gitHead": "c2c17d74b0fd1f2bd6de3a7ac5c2fd202912d12a"
52
52
  }