Skip to content

Commit c930208

Browse files
fix: Update typings for interaction API to reflect waitForEnd (#1591)
Co-authored-by: Chunwai Li <cli@newrelic.com>
1 parent cefd898 commit c930208

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export FORCE_COLOR=1
66

77
npm run lint
88
npm run test -- --onlyChanged
9+
npm run test:types

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"test": " NODE_OPTIONS=--max-old-space-size=8192 jest",
188188
"test:unit": "jest --selectProjects unit",
189189
"test:component": "jest --selectProjects component",
190-
"test:types": "tsd -f ./tests/dts/**/*.ts",
190+
"test:types": "npm run npm:build:types && tsd -f ./tests/dts/**/*.ts",
191191
"wdio": "node --max-old-space-size=8192 tools/wdio/bin/cli.js",
192192
"wdio:smoke": "node --max-old-space-size=8192 tools/wdio/bin/cli.js -T --concurrent=30",
193193
"build:all": "npm run cdn:build:local && npm run build:npm && npm run tools:test-builds",

src/loaders/api-base.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ export class ApiBase {
197197
/**
198198
* Returns a new API object that is bound to the current SPA interaction.
199199
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction/}
200+
* @param {Object} [opts] Options to configure the new or existing interaction with
201+
* @param {boolean} [opts.waitForEnd=false] To forcibly keep the interaction open until the `.end` method is called on its handle, set to true. Defaults to false. After an interaction is earmarked with this, it cannot be undone.
200202
* @returns {InteractionInstance} An API object that is bound to a specific BrowserInteraction event. Each time this method is called for the same BrowserInteraction, a new object is created, but it still references the same interaction.
201203
* - Note: Does not apply to MicroAgent
202204
* - Deprecation Notice: interaction.createTracer is deprecated. See https://docs.newrelic.com/eol/2024/04/eol-04-24-24-createtracer/ for more information.
203205
*/
204-
interaction () {
205-
return this.#callMethod(INTERACTION)
206+
interaction (opts) {
207+
return this.#callMethod(INTERACTION, opts)
206208
}
207209

208210
/**

tests/dts/agentoptions.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const validOptions: AgentOptions = {
5656
enabled: true,
5757
autoStart: false
5858
},
59-
obfuscate: [{ pattern: /sensitive/, replacement: '****' }],
59+
obfuscate: [{ regex: /sensitive/, replacement: '****' }],
6060
page_action: {
6161
enabled: true
6262
},

tests/dts/api.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ expectType<MicroAgent>(microAgent)
2525
type?: string;
2626
}) => any>(agent.addToTrace)
2727
expectType<(name: string) => any>(agent.setCurrentRouteName)
28-
expectType<() => InteractionInstance>(agent.interaction)
28+
expectType<(opts?: { waitForEnd?: boolean }) => InteractionInstance>(agent.interaction)
2929

3030
// Base Agent APIs
3131
expectType<(name: string, attributes?: object) => any>(agent.addPageAction)
@@ -45,7 +45,7 @@ expectType<MicroAgent>(microAgent)
4545
expectType<(parent: object, functionName: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => any>(agent.wrapLogger)
4646

4747
// SPA APIs
48-
expectType<() => InteractionInstance>(agent.interaction)
48+
expectType<(opts?: { waitForEnd?: boolean }) => InteractionInstance>(agent.interaction)
4949
expectType<(value: string) => InteractionInstance>(agent.interaction().actionText)
5050
expectType<(name: string, callback?: ((...args: any[]) => any)) => (...args: any) => any>(agent.interaction().createTracer)
5151
expectType<() => InteractionInstance>(agent.interaction().end)

0 commit comments

Comments
 (0)