retoolrpc 0.1.1 → 0.1.2

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/src/rpc.spec.ts CHANGED
@@ -10,17 +10,6 @@ import { Arguments } from './types'
10
10
  import { parseFunctionArguments } from './utils/schema'
11
11
  import { RetoolRPCVersion } from './version'
12
12
 
13
- // Expose the protected methods for testing
14
- class TestRetoolRPC extends RetoolRPC {
15
- public testRegisterAgent() {
16
- return this.protectedRegisterAgent()
17
- }
18
-
19
- public testFetchQueryAndExecute() {
20
- return this.protectedFetchQueryAndExecute()
21
- }
22
- }
23
-
24
13
  describe('RetoolRPC', () => {
25
14
  const CURRENT_DATE = new Date(2012, 12, 21)
26
15
  const resourceId = uuidv4()
@@ -47,13 +36,14 @@ describe('RetoolRPC', () => {
47
36
  vi.resetAllMocks()
48
37
  })
49
38
 
50
- const rpcAgent = new TestRetoolRPC({
39
+ const rpcAgent = new RetoolRPC({
51
40
  apiToken: 'secret-api-token',
52
41
  host,
53
42
  resourceId,
54
43
  environmentName,
55
44
  agentUuid,
56
45
  pollingIntervalMs: 1000,
46
+ pollingTimeoutMs: 5000,
57
47
  version: '0.0.1',
58
48
  })
59
49
 
@@ -106,7 +96,8 @@ describe('RetoolRPC', () => {
106
96
  beforeEach(async () => {
107
97
  nock(host).post('/api/v1/retoolrpc/registerAgent').reply(200, { versionHash })
108
98
 
109
- await rpcAgent.testRegisterAgent()
99
+ // @ts-expect-error: private method in test
100
+ await rpcAgent.registerAgent()
110
101
  })
111
102
 
112
103
  test('should "continue" if popQuery has no query', async () => {
@@ -114,7 +105,8 @@ describe('RetoolRPC', () => {
114
105
  .post('/api/v1/retoolrpc/popQuery', JSON.stringify(popQueryRequestBody))
115
106
  .reply(200, { query: null })
116
107
 
117
- const result = await rpcAgent.testFetchQueryAndExecute()
108
+ // @ts-expect-error: private method in test
109
+ const result = await rpcAgent.fetchQueryAndExecute()
118
110
 
119
111
  expect(nockScope.isDone()).toBe(true)
120
112
  expect(result).toEqual('continue')
@@ -168,7 +160,8 @@ describe('RetoolRPC', () => {
168
160
  )
169
161
  .reply(200, { success: true })
170
162
 
171
- const result = await rpcAgent.testFetchQueryAndExecute()
163
+ // @ts-expect-error: private method in test
164
+ const result = await rpcAgent.fetchQueryAndExecute()
172
165
 
173
166
  expect(nockScope1.isDone()).toBe(true)
174
167
  expect(nockScope2.isDone()).toBe(true)
@@ -220,7 +213,8 @@ describe('RetoolRPC', () => {
220
213
  )
221
214
  .reply(200, { success: true })
222
215
 
223
- const result = await rpcAgent.testFetchQueryAndExecute()
216
+ // @ts-expect-error: private method in test
217
+ const result = await rpcAgent.fetchQueryAndExecute()
224
218
 
225
219
  expect(nockScope1.isDone()).toBe(true)
226
220
  expect(nockScope2.isDone()).toBe(true)
package/src/rpc.ts CHANGED
@@ -13,12 +13,13 @@ import { createAgentServerError, FunctionNotFoundError } from './utils/errors'
13
13
  import { parseFunctionArguments } from './utils/schema'
14
14
  import { isClientError } from './utils/helpers'
15
15
  import { loopWithBackoff } from './utils/polling'
16
- import { Logger, LoggerService } from './utils/logger';
16
+ import { Logger, LoggerService } from './utils/logger'
17
17
  import { RetoolAPI } from './utils/api'
18
18
  import { RetoolRPCVersion } from './version'
19
19
 
20
20
  const MINIMUM_POLLING_INTERVAL_MS = 100
21
21
  const DEFAULT_POLLING_INTERVAL_MS = 1000
22
+ const DEFAULT_POLLING_TIMEOUT_MS = 5000
22
23
  const DEFAULT_ENVIRONMENT_NAME = 'production'
23
24
  const DEFAULT_VERSION = '0.0.1'
24
25
 
@@ -31,6 +32,7 @@ export class RetoolRPC {
31
32
  private _resourceId: string
32
33
  private _environmentName: string
33
34
  private _pollingIntervalMs: number
35
+ private _pollingTimeoutMs: number
34
36
  private _version: string
35
37
  private _agentUuid: string
36
38
  private _versionHash: string | undefined
@@ -49,10 +51,15 @@ export class RetoolRPC {
49
51
  this._pollingIntervalMs = config.pollingIntervalMs
50
52
  ? Math.max(config.pollingIntervalMs, MINIMUM_POLLING_INTERVAL_MS)
51
53
  : DEFAULT_POLLING_INTERVAL_MS
54
+ this._pollingTimeoutMs = config.pollingTimeoutMs || DEFAULT_POLLING_TIMEOUT_MS
52
55
  this._version = config.version || DEFAULT_VERSION
53
56
  this._agentUuid = config.agentUuid || uuidv4()
54
57
 
55
- this._retoolApi = new RetoolAPI({ hostUrl: this._hostUrl, apiKey: this._apiKey })
58
+ this._retoolApi = new RetoolAPI({
59
+ hostUrl: this._hostUrl,
60
+ apiKey: this._apiKey,
61
+ pollingTimeoutMs: this._pollingTimeoutMs || DEFAULT_POLLING_TIMEOUT_MS,
62
+ })
56
63
  this._logger = config.logger ?? new Logger({ logLevel: config.logLevel })
57
64
 
58
65
  this._logger.debug('Retool RPC Configuration', {
@@ -245,18 +252,4 @@ export class RetoolRPC {
245
252
 
246
253
  return 'continue'
247
254
  }
248
-
249
- /**
250
- * Export registerAgent as a protected method for testing purpose only. Lookup TestRetoolRPC for usage.
251
- */
252
- protected async protectedRegisterAgent() {
253
- return this.registerAgent()
254
- }
255
-
256
- /**
257
- * Export fetchQueryAndExecute as a protected method for testing purpose only. Lookup TestRetoolRPC for usage.
258
- */
259
- protected async protectedFetchQueryAndExecute() {
260
- return this.fetchQueryAndExecute()
261
- }
262
255
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { LoggerService } from './utils/logger';
1
+ import type { LoggerService } from './utils/logger'
2
2
 
3
3
  /**
4
4
  * Configuration options for the Retool RPC.
@@ -19,6 +19,8 @@ export type RetoolRPCConfig = {
19
19
  version?: string
20
20
  /** The optional polling interval in milliseconds. Defaults to 1000. Minimum is 100. */
21
21
  pollingIntervalMs?: number
22
+ /** The optional polling timeout in milliseconds. Defaults to 5000. */
23
+ pollingTimeoutMs?: number
22
24
  /** The optional UUID of the agent. Will be automatically generated by default */
23
25
  agentUuid?: string
24
26
  /** The optional log level. */
package/src/utils/api.ts CHANGED
@@ -8,8 +8,6 @@ const AbortController = globalThis.AbortController || AbortControllerFallback
8
8
  import { AgentServerError } from '../types'
9
9
  import { RetoolRPCVersion } from '../version'
10
10
 
11
- const POLLING_TIMEOUT_MS = 5 * 1000 // 5 seconds
12
-
13
11
  type PopQueryRequest = {
14
12
  resourceId: string
15
13
  environmentName: string
@@ -46,17 +44,19 @@ type PostQueryResponseRequest = {
46
44
  export class RetoolAPI {
47
45
  private _hostUrl: string
48
46
  private _apiKey: string
47
+ private _pollingTimeoutMs: number
49
48
 
50
- constructor({ hostUrl, apiKey }: { hostUrl: string; apiKey: string }) {
49
+ constructor({ hostUrl, apiKey, pollingTimeoutMs }: { hostUrl: string; apiKey: string; pollingTimeoutMs: number }) {
51
50
  this._hostUrl = hostUrl
52
51
  this._apiKey = apiKey
52
+ this._pollingTimeoutMs = pollingTimeoutMs
53
53
  }
54
54
 
55
55
  async popQuery(options: PopQueryRequest) {
56
56
  const abortController = new AbortController()
57
57
  setTimeout(() => {
58
58
  abortController.abort()
59
- }, POLLING_TIMEOUT_MS)
59
+ }, this._pollingTimeoutMs)
60
60
 
61
61
  try {
62
62
  return await fetch(`${this._hostUrl}/api/v1/retoolrpc/popQuery`, {
@@ -73,7 +73,7 @@ export class RetoolAPI {
73
73
  })
74
74
  } catch (error: any) {
75
75
  if (abortController.signal.aborted) {
76
- throw new Error(`Polling timeout after ${POLLING_TIMEOUT_MS}ms`)
76
+ throw new Error(`Polling timeout after ${this._pollingTimeoutMs}ms`)
77
77
  }
78
78
  throw error
79
79
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const RetoolRPCVersion = '0.1.1'
1
+ export const RetoolRPCVersion = '0.1.2'