Skip to content

Commit 6e1c366

Browse files
committed
wip
1 parent 25a34da commit 6e1c366

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
export type ID = string | null | undefined
2+
13
export interface BaseSignal {
24
type: string
3-
anonymousId: string
5+
anonymousId: ID
46
timestamp: string
57
}
68

packages/signals/signals/src/core/middleware/user-info/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { Signal } from '@segment/analytics-signals-runtime'
2-
import { User } from '../../../types'
2+
import { UserInfo } from '../../../types'
33
import { SignalsMiddleware, SignalsMiddlewareContext } from '../../emitter'
44

55
export class UserInfoMiddleware implements SignalsMiddleware {
6-
user!: User
6+
user!: UserInfo
77

88
async load(ctx: SignalsMiddlewareContext) {
99
this.user = await ctx.analyticsInstance.user()
1010
}
1111

1212
process(signal: Signal): Signal {
13+
// anonymousId should always exist here unless the user is explicitly setting it to null
1314
signal.anonymousId = this.user.anonymousId()
1415
return signal
1516
}

packages/signals/signals/src/types/__tests__/create-network-signal.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe(createNetworkSignal, () => {
1616
disallowed: ['disallowed1', 'disallowed2'],
1717
},
1818
}
19-
2019
it('should create a network signal for a request', () => {
2120
const data: NetworkData = {
2221
action: 'request',

packages/signals/signals/src/types/analytics-api.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ export interface DestinationMiddlewareParams {
5050
integration: string
5151
}
5252

53-
export interface User {
54-
id(): string
55-
anonymousId(): string
53+
export type ID = string | null | undefined
54+
55+
export interface UserInfo {
56+
id(): ID
57+
anonymousId(): ID
5658
}
5759

5860
export interface AnyAnalytics {
@@ -72,7 +74,7 @@ export interface AnyAnalytics {
7274
alias(...args: any[]): void
7375
screen(...args: any[]): void
7476
reset(): void
75-
user(): User | Promise<User>
77+
user(): UserInfo | Promise<UserInfo> // works for
7678
on(name: 'reset', fn: (...args: any[]) => void): void
7779
}
7880

0 commit comments

Comments
 (0)