Skip to content

Commit 68bea6a

Browse files
committed
wip
1 parent 59a3475 commit 68bea6a

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

packages/signals/signals-integration-tests/src/tests/signals-vanilla/network-signals-fetch.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ test.describe('network signals - fetch', () => {
5454
(el) => el.properties!.data.action === 'request'
5555
)
5656
expect(requests).toHaveLength(1)
57-
expect(requests[0].properties!.data).toMatchObject({
57+
expect(requests[0].properties!.data).toEqual({
5858
action: 'request',
5959
url: 'http://localhost/test',
60+
method: 'POST',
6061
data: { key: 'value' },
6162
})
6263

6364
const responses = networkEvents.filter(
6465
(el) => el.properties!.data.action === 'response'
6566
)
6667
expect(responses).toHaveLength(1)
67-
expect(responses[0].properties!.data).toMatchObject({
68+
expect(responses[0].properties!.data).toEqual({
6869
action: 'response',
6970
url: 'http://localhost/test',
7071
data: { foo: 'test' },
72+
statusCode: 200,
73+
ok: true,
7174
})
7275
})
7376

@@ -176,6 +179,8 @@ test.describe('network signals - fetch', () => {
176179
action: 'response',
177180
url: 'http://localhost/test',
178181
data: { errorMsg: 'foo' },
182+
statusCode: 400,
183+
ok: false,
179184
})
180185
expect(responses).toHaveLength(1)
181186
})
@@ -213,6 +218,8 @@ test.describe('network signals - fetch', () => {
213218
action: 'response',
214219
url: 'http://localhost/test',
215220
data: 'foo',
221+
statusCode: 400,
222+
ok: false,
216223
})
217224
expect(responses).toHaveLength(1)
218225
})

packages/signals/signals-runtime/editor/mobile-editor.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ type JSONObject = {
1818
};
1919
type JSONArray = JSONValue[];
2020
interface SegmentEvent {
21-
type: EventType;
22-
[key: string]: any;
21+
/**
22+
* @example 'track' | 'page' | 'screen' | 'identify' | 'group' | 'alias'
23+
*/
24+
type: string;
25+
[key: string]: unknown;
2326
}
24-
type EventType = "track" | "page" | "screen" | "identify" | "group" | "alias";
2527
type SignalTypes = Signal["type"];
2628
type NavigationAction = "forward" | "backward" | "modal" | "entering" | "leaving" | "page" | "popup";
2729
type NetworkAction = "request" | "response";
@@ -57,7 +59,6 @@ interface NetworkData {
5759
}
5860
interface NetworkSignal extends RawSignal<"network"> {
5961
data: NetworkData;
60-
[key: string]: unknown;
6162
}
6263
interface LocalData {
6364
action: LocalDataAction;
@@ -77,6 +78,8 @@ interface InstrumentationData {
7778
interface InstrumentationSignal extends RawSignal<"instrumentation"> {
7879
data: InstrumentationData;
7980
}
81+
interface MobileSignalsRuntime extends ISignalsRuntime<Signal> {
82+
}
8083

8184

8285

packages/signals/signals-runtime/editor/web-editor.d.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ type JSONObject = {
1818
};
1919
type JSONArray = JSONValue[];
2020
interface SegmentEvent {
21-
type: EventType;
22-
[key: string]: any;
21+
/**
22+
* @example 'track' | 'page' | 'screen' | 'identify' | 'group' | 'alias'
23+
*/
24+
type: string;
25+
[key: string]: unknown;
2326
}
24-
type EventType = "track" | "page" | "screen" | "identify" | "group" | "alias";
2527
type SignalTypes = Signal["type"];
2628
interface RawSignal<T extends SignalTypes, Data> extends BaseSignal {
2729
type: T;
@@ -80,6 +82,8 @@ interface NetworkRequestData extends BaseNetworkData {
8082
interface NetworkResponseData extends BaseNetworkData {
8183
action: "response";
8284
url: string;
85+
statusCode: number;
86+
ok: boolean;
8387
}
8488
type NetworkData = NetworkRequestData | NetworkResponseData;
8589
type NetworkSignal = RawSignal<"network", NetworkData>;
@@ -88,10 +92,12 @@ interface UserDefinedSignalData {
8892
}
8993
type UserDefinedSignal = RawSignal<"userDefined", UserDefinedSignalData>;
9094
type Signal = InteractionSignal | NavigationSignal | InstrumentationSignal | NetworkSignal | UserDefinedSignal;
95+
interface WebSignalsRuntime extends ISignalsRuntime<Signal> {
96+
}
9197

9298

9399

94-
declare const signals: ISignalsRuntime<Signal>
100+
declare const signals: WebSignalsRuntime
95101
declare const SignalType: {
96102
Interaction: 'interaction'
97103
Navigation: 'navigation'

packages/signals/signals-runtime/src/shared/shared-types.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@ export type JSONObject = { [member: string]: JSONValue }
2121
export type JSONArray = JSONValue[]
2222

2323
export interface SegmentEvent {
24-
type: EventType // e.g 'track'
25-
[key: string]: any
24+
/**
25+
* @example 'track' | 'page' | 'screen' | 'identify' | 'group' | 'alias'
26+
*/
27+
type: string
28+
[key: string]: unknown
2629
}
27-
28-
export type EventType =
29-
| 'track'
30-
| 'page'
31-
| 'screen'
32-
| 'identify'
33-
| 'group'
34-
| 'alias'

packages/signals/signals/src/core/emitter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Emitter } from '@segment/analytics-generic-utils'
22
import { logger } from '../../lib/logger'
3-
import { Signal } from '../../types'
3+
import { Signal } from '@segment/analytics-signals-runtime'
44

55
export interface EmitSignal {
66
emit: (signal: Signal) => void

packages/signals/signals/src/core/processor/sandbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { logger } from '../../lib/logger'
22
import { createWorkerBox, WorkerBoxAPI } from '../../lib/workerbox'
33
import { resolvers } from './arg-resolvers'
4-
import { AnalyticsRuntimePublicApi, Signal, AnalyticsEnums } from '../../types'
4+
import { AnalyticsRuntimePublicApi, AnalyticsEnums } from '../../types'
55
import { replaceBaseUrl } from '../../lib/replace-base-url'
6-
import { SignalsRuntime } from '@segment/analytics-signals-runtime'
6+
import { SignalsRuntime, Signal } from '@segment/analytics-signals-runtime'
77

88
export type MethodName =
99
| 'page'

packages/signals/signals/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
*/
55
export { SignalsPlugin } from './plugin/signals-plugin'
66
export { Signals } from './core/signals'
7-
7+
export type { Signal } from '@segment/analytics-signals-runtime'
88
export type {
99
ProcessSignal,
1010
AnalyticsRuntimePublicApi,
1111
SignalsPluginSettingsConfig,
12-
Signal,
1312
} from './types'

0 commit comments

Comments
 (0)