@opendoor/partner-sdk-client-js-core 0.0.1-alpha.40.1 → 0.0.1-alpha.42.1

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/dist/client.d.ts CHANGED
@@ -20,16 +20,19 @@
20
20
  * @packageDocumentation
21
21
  */
22
22
  import type { AddressSuggestionsResponse, CreateOfferRequest, CreateOfferResponse, UpdateOfferRequest, UpdateOfferResponse, GetOfferResponse, GetOfferWithPricingResponse, AddressUnitCheckResponse, GetAssessmentSlotsRequest, GetAssessmentSlotsResponse, GetHomeDetailRequest, GetHomeDetailResponse } from './types.js';
23
+ export type OpendoorEnvironment = 'staging' | 'production';
23
24
  /**
24
25
  * Configuration for the browser OpendoorClient.
25
26
  *
26
27
  * @param baseURL - Base URL of the partner's BFF server (e.g., '/api/opendoor')
27
28
  * @param timeout - Request timeout in milliseconds. Defaults to 30000.
29
+ * @param environment - Target environment. Defaults to 'production'.
28
30
  * @param endpoints - Override default endpoint paths.
29
31
  */
30
32
  export interface OpendoorClientConfig {
31
33
  baseURL: string;
32
34
  timeout?: number;
35
+ environment?: OpendoorEnvironment;
33
36
  endpoints?: Partial<{
34
37
  addressSuggestions: string;
35
38
  createOffer: string;
@@ -42,6 +45,7 @@ export declare class OpendoorClient {
42
45
  private readonly baseURL;
43
46
  private readonly timeout;
44
47
  private readonly endpoints;
48
+ readonly environment: OpendoorEnvironment;
45
49
  constructor(config: OpendoorClientConfig);
46
50
  /**
47
51
  * Search for addresses matching a query string.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B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AK,EAAE,MAAM,GACZ,OAAO,CAAC,0BAA0B,CAAC;IActC;;;;;OAKG;IACG,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IASzE;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,mBAAmB,CAAC;IAS/B;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAW1D;;;;OAIG;IACG,6BAA6B,CACjC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,2BAA2B,CAAC;IAcvC;;;;;OAKG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAC9B,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAcrC;;;;;OAKG;IACG,kBAAkB,CACtB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,0BAA0B,CAAC;IActC;;;OAGG;IACG,aAAa,CACjB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,qBAAqB,CAAC;YAkBnB,OAAO;CA8CtB"}
package/dist/client.js CHANGED
@@ -44,6 +44,7 @@ export class OpendoorClient {
44
44
  // Strip trailing slash from baseURL
45
45
  this.baseURL = config.baseURL.replace(/\/+$/, '');
46
46
  this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
47
+ this.environment = config.environment ?? 'production';
47
48
  this.endpoints = {
48
49
  ...DEFAULT_ENDPOINTS,
49
50
  ...config.endpoints,
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export declare const VERSION = "0.2.0";
10
10
  export { OpendoorClient } from './client.js';
11
- export type { OpendoorClientConfig } from './client.js';
11
+ export type { OpendoorClientConfig, OpendoorEnvironment } from './client.js';
12
12
  export type { Address, AddressSuggestionsResponse, CreateOfferRequest, CreateOfferResponse, UpdateOfferRequest, UpdateOfferResponse, GetOfferResponse, GetOfferWithPricingResponse, OfferData, OfferDataWithPricing, DenialInfo, OfferStatus, ExperimentalQuestionAnswer, AddressUnitCheckResponse, GetAssessmentSlotsRequest, GetAssessmentSlotsResponse, GetHomeDetailRequest, GetHomeDetailResponse, } from './types.js';
13
13
  export { resolveAppearance, THEMES } from './appearance.js';
14
14
  export type { OpendoorAppearance, OpendoorThemeVariables, } from './appearance.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD,YAAY,EACV,OAAO,EACP,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,2BAA2B,EAC3B,SAAS,EACT,oBAAoB,EACpB,UAAU,EACV,WAAW,EACX,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EACV,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,YAAY,EACV,OAAO,EACP,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,2BAA2B,EAC3B,SAAS,EACT,oBAAoB,EACpB,UAAU,EACV,WAAW,EACX,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EACV,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Internal types matching the Journey API proto3 JSON format.
3
+ * These are NOT exported from the package — they are used only by the
4
+ * internal TrackingClient.
5
+ *
6
+ * Field names use camelCase (proto3 JSON mapping).
7
+ * google.protobuf.StringValue → string | undefined
8
+ * google.protobuf.Timestamp → ISO 8601 string
9
+ * oneof → only the selected field is present
10
+ */
11
+ export interface Screen {
12
+ width: number;
13
+ height: number;
14
+ density: number;
15
+ }
16
+ export interface WebsiteSource {
17
+ url: string;
18
+ userAgent?: string;
19
+ referrer?: string;
20
+ pathname?: string;
21
+ host?: string;
22
+ eventOrigin: 'CLIENT';
23
+ screen?: Screen;
24
+ language?: string[];
25
+ }
26
+ export interface PageViewEvent {
27
+ }
28
+ export interface ButtonClickEvent {
29
+ targetName: string;
30
+ }
31
+ export interface InputViewEvent {
32
+ targetName: string;
33
+ }
34
+ export interface LinkClickEvent {
35
+ targetName: string;
36
+ }
37
+ export interface CheckboxClickEvent {
38
+ targetName: string;
39
+ optionName: string;
40
+ }
41
+ export interface RadioClickEvent {
42
+ targetName: string;
43
+ optionName: string;
44
+ }
45
+ export type PlatformEvent = {
46
+ pageViewEvent: PageViewEvent;
47
+ } | {
48
+ buttonClickEvent: ButtonClickEvent;
49
+ } | {
50
+ inputViewEvent: InputViewEvent;
51
+ } | {
52
+ linkClickEvent: LinkClickEvent;
53
+ } | {
54
+ checkboxClickEvent: CheckboxClickEvent;
55
+ } | {
56
+ radioClickEvent: RadioClickEvent;
57
+ };
58
+ export interface PlatformCategory {
59
+ platform: PlatformEvent;
60
+ }
61
+ export interface AddressEntryV2Event {
62
+ street1?: string;
63
+ city?: string;
64
+ state?: string;
65
+ postalCode?: string;
66
+ unit?: string;
67
+ sourcePage?: string;
68
+ }
69
+ export type SellEvent = {
70
+ addressEntryV2: AddressEntryV2Event;
71
+ };
72
+ export interface SellCategory {
73
+ sell: SellEvent;
74
+ }
75
+ export type EventCategory = PlatformCategory | SellCategory;
76
+ export interface EventWrapper {
77
+ timestamp: string;
78
+ websiteSource: WebsiteSource;
79
+ anonymousId?: string;
80
+ customerUuid?: string;
81
+ platform?: PlatformEvent;
82
+ sell?: SellEvent;
83
+ }
84
+ export interface EventWrapperList {
85
+ eventWrappers: EventWrapper[];
86
+ }
87
+ //# sourceMappingURL=tracking-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracking-types.d.ts","sourceRoot":"","sources":["../src/tracking-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAA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ACjB;AAMD,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,YAAY,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Internal types matching the Journey API proto3 JSON format.
3
+ * These are NOT exported from the package — they are used only by the
4
+ * internal TrackingClient.
5
+ *
6
+ * Field names use camelCase (proto3 JSON mapping).
7
+ * google.protobuf.StringValue → string | undefined
8
+ * google.protobuf.Timestamp → ISO 8601 string
9
+ * oneof → only the selected field is present
10
+ */
11
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Internal Journey event tracking client.
3
+ * NOT exported from the package — used only by client-react components.
4
+ *
5
+ * Modeled after the observability JourneyClientImpl in opendoor-labs/code,
6
+ * adapted for cross-origin partner domains.
7
+ */
8
+ import type { PlatformEvent, SellEvent } from './tracking-types.js';
9
+ import type { OpendoorEnvironment } from './client.js';
10
+ export interface Tracker {
11
+ trackPlatform(event: PlatformEvent): void;
12
+ trackSell(event: SellEvent): void;
13
+ flush(keepalive?: boolean): void;
14
+ destroy(): void;
15
+ }
16
+ export declare class TrackingClient implements Tracker {
17
+ private buffer;
18
+ private timer;
19
+ private readonly endpoint;
20
+ private readonly anonymousId;
21
+ private destroyed;
22
+ private readonly onVisibilityChange;
23
+ private readonly onBeforeUnload;
24
+ constructor(environment: OpendoorEnvironment);
25
+ trackPlatform(event: PlatformEvent): void;
26
+ trackSell(event: SellEvent): void;
27
+ flush(keepalive?: boolean): void;
28
+ destroy(): void;
29
+ private enqueue;
30
+ }
31
+ export declare const NOOP_TRACKING: Tracker;
32
+ //# sourceMappingURL=tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../src/tracking.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAGV,aAAa,EACb,SAAS,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA0BvD,MAAM,WAAW,OAAO;IACtB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC1C,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAClC,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC,OAAO,IAAI,IAAI,CAAC;CACjB;AA8ED,qBAAa,cAAe,YAAW,OAAO;IAC5C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAA6C;IAC1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAEjC;IACF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAE7B;gBAEU,WAAW,EAAE,mBAAmB;IAa5C,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAIzC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAOjC,KAAK,CAAC,SAAS,UAAQ,GAAG,IAAI;IAmB9B,OAAO,IAAI,IAAI;IAef,OAAO,CAAC,OAAO;CAqBhB;AAMD,eAAO,MAAM,aAAa,EAAE,OAK3B,CAAC"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Internal Journey event tracking client.
3
+ * NOT exported from the package — used only by client-react components.
4
+ *
5
+ * Modeled after the observability JourneyClientImpl in opendoor-labs/code,
6
+ * adapted for cross-origin partner domains.
7
+ */
8
+ // ---------------------------------------------------------------------------
9
+ // Constants
10
+ // ---------------------------------------------------------------------------
11
+ const JOURNEY_ENDPOINTS = {
12
+ production: 'https://journey.apps.opendoor.com/_journey/api/v1/events',
13
+ staging: 'https://journey.apps-staging.opendoor.com/_journey/api/v1/events',
14
+ };
15
+ const CLIENT_NAME = 'partner-sdk';
16
+ const CLIENT_VERSION = '1.0';
17
+ const FLUSH_INTERVAL_MS = 5000;
18
+ const MAX_BATCH_SIZE = 20;
19
+ const MAX_PAYLOAD_KB = 512;
20
+ const RETRY_COUNT = 5;
21
+ const RETRY_DELAY_MS = 500;
22
+ const ANONYMOUS_ID_KEY = 'od_sdk_aid';
23
+ // ---------------------------------------------------------------------------
24
+ // Helpers
25
+ // ---------------------------------------------------------------------------
26
+ function getOrCreateAnonymousId() {
27
+ try {
28
+ const existing = localStorage.getItem(ANONYMOUS_ID_KEY);
29
+ if (existing)
30
+ return existing;
31
+ const id = crypto.randomUUID();
32
+ localStorage.setItem(ANONYMOUS_ID_KEY, id);
33
+ return id;
34
+ }
35
+ catch {
36
+ // localStorage unavailable (SSR, privacy mode, etc.)
37
+ return undefined;
38
+ }
39
+ }
40
+ function buildWebsiteSource() {
41
+ if (typeof window === 'undefined') {
42
+ return { url: '', eventOrigin: 'CLIENT' };
43
+ }
44
+ return {
45
+ url: window.location.href,
46
+ userAgent: navigator.userAgent,
47
+ referrer: document.referrer || undefined,
48
+ pathname: window.location.pathname,
49
+ host: window.location.host,
50
+ eventOrigin: 'CLIENT',
51
+ screen: {
52
+ width: Math.round(window.innerWidth),
53
+ height: Math.round(window.innerHeight),
54
+ density: Math.round(window.devicePixelRatio ?? 1),
55
+ },
56
+ language: Array.from(navigator.languages ?? []),
57
+ };
58
+ }
59
+ function computeSizeKB(buffer) {
60
+ let total = 0;
61
+ for (const s of buffer)
62
+ total += s.length;
63
+ return total / 1024;
64
+ }
65
+ function isApproachingLimit(buffer) {
66
+ return computeSizeKB(buffer) >= MAX_PAYLOAD_KB - 50;
67
+ }
68
+ async function fetchWithRetry(url, init) {
69
+ let retries = RETRY_COUNT;
70
+ while (retries > 0) {
71
+ try {
72
+ const response = await fetch(url, init);
73
+ if (response.status === 202)
74
+ return;
75
+ if (response.status >= 500 && retries >= 1) {
76
+ await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
77
+ retries--;
78
+ }
79
+ else {
80
+ break;
81
+ }
82
+ }
83
+ catch {
84
+ if (retries >= 1) {
85
+ await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
86
+ retries--;
87
+ }
88
+ else {
89
+ break;
90
+ }
91
+ }
92
+ }
93
+ // Silent fail — no Sentry in partner SDK
94
+ }
95
+ // ---------------------------------------------------------------------------
96
+ // TrackingClient
97
+ // ---------------------------------------------------------------------------
98
+ export class TrackingClient {
99
+ constructor(environment) {
100
+ this.buffer = [];
101
+ this.destroyed = false;
102
+ this.onVisibilityChange = () => {
103
+ if (document.visibilityState === 'hidden')
104
+ this.flush(true);
105
+ };
106
+ this.onBeforeUnload = () => {
107
+ this.flush(true);
108
+ };
109
+ this.endpoint = JOURNEY_ENDPOINTS[environment];
110
+ this.anonymousId = getOrCreateAnonymousId();
111
+ this.timer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
112
+ if (typeof document !== 'undefined') {
113
+ document.addEventListener('visibilitychange', this.onVisibilityChange);
114
+ }
115
+ if (typeof window !== 'undefined') {
116
+ window.addEventListener('beforeunload', this.onBeforeUnload);
117
+ }
118
+ }
119
+ trackPlatform(event) {
120
+ this.enqueue({ platform: event });
121
+ }
122
+ trackSell(event) {
123
+ this.enqueue({ sell: event });
124
+ }
125
+ // keepalive=true is only used on page unload (visibilitychange/beforeunload)
126
+ // to survive navigation. Timer-based flushes use regular fetch because
127
+ // keepalive requests have a 64KB cumulative body size limit per origin.
128
+ flush(keepalive = false) {
129
+ if (this.buffer.length === 0)
130
+ return;
131
+ const body = `{"eventWrappers":[${this.buffer.join(',')}]}`;
132
+ this.buffer = [];
133
+ fetchWithRetry(this.endpoint, {
134
+ method: 'POST',
135
+ credentials: 'omit',
136
+ keepalive,
137
+ headers: {
138
+ 'Content-Type': 'application/json',
139
+ 'X-Journey-Client-Name': CLIENT_NAME,
140
+ 'X-Journey-Client-Version': CLIENT_VERSION,
141
+ },
142
+ body,
143
+ });
144
+ }
145
+ destroy() {
146
+ this.destroyed = true;
147
+ this.flush(true);
148
+ if (this.timer) {
149
+ clearInterval(this.timer);
150
+ this.timer = undefined;
151
+ }
152
+ if (typeof document !== 'undefined') {
153
+ document.removeEventListener('visibilitychange', this.onVisibilityChange);
154
+ }
155
+ if (typeof window !== 'undefined') {
156
+ window.removeEventListener('beforeunload', this.onBeforeUnload);
157
+ }
158
+ }
159
+ enqueue(category) {
160
+ if (this.destroyed)
161
+ return;
162
+ const wrapper = {
163
+ timestamp: new Date().toISOString(),
164
+ websiteSource: buildWebsiteSource(),
165
+ anonymousId: this.anonymousId,
166
+ ...category,
167
+ };
168
+ this.buffer.push(JSON.stringify(wrapper));
169
+ if (this.buffer.length >= MAX_BATCH_SIZE ||
170
+ isApproachingLimit(this.buffer)) {
171
+ this.flush();
172
+ }
173
+ }
174
+ }
175
+ // ---------------------------------------------------------------------------
176
+ // No-op stub for when tracking is unavailable
177
+ // ---------------------------------------------------------------------------
178
+ export const NOOP_TRACKING = {
179
+ trackPlatform() { },
180
+ trackSell() { },
181
+ flush() { },
182
+ destroy() { },
183
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendoor/partner-sdk-client-js-core",
3
- "version": "0.0.1-alpha.40.1",
3
+ "version": "0.0.1-alpha.42.1",
4
4
  "description": "Framework-agnostic client SDK for Opendoor partner integrations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "import": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts"
12
+ },
13
+ "./internal/tracking": {
14
+ "import": "./dist/tracking.js",
15
+ "types": "./dist/tracking.d.ts"
12
16
  }
13
17
  },
14
18
  "files": [