@raypx-kit/analytics 0.0.0-alpha.0 → 0.0.0-stage
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/README.md +2 -99
- package/package.json +4 -73
- package/CHANGELOG.md +0 -7
- package/LICENSE +0 -201
- package/dist/browser.d.mts +0 -15
- package/dist/browser.mjs +0 -245
- package/dist/browser.mjs.map +0 -1
- package/dist/index.d.mts +0 -22
- package/dist/index.mjs +0 -62
- package/dist/index.mjs.map +0 -1
- package/dist/react.d.mts +0 -26
- package/dist/react.mjs +0 -30
- package/dist/react.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,100 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Temporary Holding Version
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
ESM; Node 22.14+ for imports and Bun consumers. Browser delivery requires a browser.
|
|
5
|
-
The external `posthog-js` dependency uses its no-external entry, so the SDK never
|
|
6
|
-
loads recorder, survey or other scripts from a CDN. React 19 is an optional peer.
|
|
7
|
-
|
|
8
|
-
## Entries
|
|
9
|
-
|
|
10
|
-
- Root: `AnalyticsClient`, `AnalyticsConsent`, `AnalyticsProperties`, `EventPolicy`,
|
|
11
|
-
`DEFAULT_ANALYTICS_CONSENT`, `createNoopAnalytics`, `sanitizeException`, `applicationFrame`.
|
|
12
|
-
- `/browser`: `createBrowserAnalytics`, `BrowserAnalyticsOptions`.
|
|
13
|
-
- `/react`: `AnalyticsProvider`, `useAnalytics`, `AnalyticsErrorBoundary`.
|
|
14
|
-
|
|
15
|
-
Every entry is safe to import during SSR. Importing does not initialize PostHog.
|
|
16
|
-
Optional static `properties` attach safe application context (such as surface) to all
|
|
17
|
-
events, including exceptions. Never include credentials or business content.
|
|
18
|
-
|
|
19
|
-
Applications own environment parsing, event schemas, identity, preference storage,
|
|
20
|
-
release assets and error UI. No application configuration is read by this package.
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { createBrowserAnalytics } from "@raypx-kit/analytics/browser";
|
|
24
|
-
const analytics = createBrowserAnalytics({
|
|
25
|
-
token: "your-project-token",
|
|
26
|
-
host: "https://us.i.posthog.com",
|
|
27
|
-
environment: "production",
|
|
28
|
-
release: "your-commit",
|
|
29
|
-
assetOrigins: ["https://app.example.com"],
|
|
30
|
-
policy: (event, properties) =>
|
|
31
|
-
event === "view_opened" ? { page: properties.page === "settings" ? "settings" : "home" } : null,
|
|
32
|
-
});
|
|
33
|
-
analytics.setConsent({ usage: true, errors: false }); // only after user action
|
|
34
|
-
analytics.identify("internal-user-id");
|
|
35
|
-
analytics.capture("view_opened", { page: "settings" });
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Both categories start disabled. `capture` and `identify` require usage consent;
|
|
39
|
-
`captureException` and global error/rejection listeners require error consent.
|
|
40
|
-
Errors-only mode remains anonymous. No events are retained before consent or
|
|
41
|
-
replayed when consent is granted later. Unknown events fail closed through the
|
|
42
|
-
application policy. SDK loading and delivery are best effort and never reject a
|
|
43
|
-
product operation. A failed load is retried on a future operation, not in a loop.
|
|
44
|
-
|
|
45
|
-
`identify(null)` / `reset()` clears SDK identity and invalidates in-flight work;
|
|
46
|
-
call before changing accounts. `setConsent` controls each category independently.
|
|
47
|
-
`dispose` permanently stops the client and removes global listeners. SDK state is
|
|
48
|
-
memory-only. Applications persist consent separately; cross-device correlation
|
|
49
|
-
uses the internal user ID, never email or name. The SDK's separate persisted consent
|
|
50
|
-
is synchronized from the application's current choice after initialization.
|
|
51
|
-
Anonymous pre-login IDs are not
|
|
52
|
-
merged into identified profiles, avoiding unbounded alias creation with memory-only
|
|
53
|
-
persistence. Already sent events are not deleted
|
|
54
|
-
when consent is withdrawn.
|
|
55
|
-
|
|
56
|
-
The SDK formats events; the final sanitized payload is handed to this package's
|
|
57
|
-
single-attempt fetch transport. SDK dispatch and retry queues receive no events.
|
|
58
|
-
Requests omit credentials and referrers, disable keepalive, and time out after ten
|
|
59
|
-
seconds. HTTP errors, network failures and timeouts are dropped without retries,
|
|
60
|
-
offline queues or unload beacons. Consent changes, account changes, reset and dispose
|
|
61
|
-
abort pending requests and discard stale work. Delivery is best effort; aborting a
|
|
62
|
-
request cannot retract data that already reached the server.
|
|
63
|
-
|
|
64
|
-
## Errors and data boundaries
|
|
65
|
-
|
|
66
|
-
Error messages become a machine code or `UNEXPECTED_ERROR`. Causes, arbitrary
|
|
67
|
-
thrown objects, function text and local paths are not transmitted. Only frames in
|
|
68
|
-
`/assets/*.js` or `.mjs` on an explicitly permitted HTTP(S) or `views:` origin are
|
|
69
|
-
retained; query strings and fragments are removed. Unknown frames are discarded.
|
|
70
|
-
The final SDK event is rebuilt so default URL, referrer, campaign and person
|
|
71
|
-
properties cannot bypass the application policy. Do not include private content
|
|
72
|
-
in allowed custom properties: the application owns that policy.
|
|
73
|
-
|
|
74
|
-
Automatic clicks, pageviews, console/network capture, heatmaps, surveys, flags and
|
|
75
|
-
session recording are disabled. Manual page events must use application route
|
|
76
|
-
identifiers, never raw URLs. No server or native crash collection is provided.
|
|
77
|
-
|
|
78
|
-
## React
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
import { AnalyticsProvider, AnalyticsErrorBoundary } from "@raypx-kit/analytics/react";
|
|
82
|
-
<AnalyticsProvider client={analytics}>
|
|
83
|
-
<AnalyticsErrorBoundary client={analytics} fallback={<p>Unable to open this view.</p>}>
|
|
84
|
-
<App />
|
|
85
|
-
</AnalyticsErrorBoundary>
|
|
86
|
-
</AnalyticsProvider>;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
The provider borrows its client; the application owns its lifetime. This avoids
|
|
90
|
-
reinitialization in React Strict Mode. `useAnalytics()` is a no-op without a provider.
|
|
91
|
-
|
|
92
|
-
For readable production frames, generate hidden source maps, inject PostHog chunk
|
|
93
|
-
metadata, upload maps and ship those same injected assets. Upload credentials
|
|
94
|
-
belong only in the release environment; maps must not be public app assets.
|
|
95
|
-
See [PostHog source maps](https://posthog.com/docs/error-tracking/upload-source-maps/cli).
|
|
96
|
-
|
|
97
|
-
## Development
|
|
98
|
-
|
|
99
|
-
Run the package tests and check, then the repository `bun run verify`. Packed
|
|
100
|
-
consumer fixtures cover public declarations and SSR imports with and without React.
|
|
3
|
+
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/package.json
CHANGED
|
@@ -1,75 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raypx-kit/analytics",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"author": {
|
|
8
|
-
"name": "Zack",
|
|
9
|
-
"email": "heyloyep@gmail.com"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/raypx/raypx-kit.git",
|
|
14
|
-
"directory": "packages/analytics"
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist",
|
|
18
|
-
"LICENSE",
|
|
19
|
-
"README.md",
|
|
20
|
-
"CHANGELOG.md"
|
|
21
|
-
],
|
|
22
|
-
"type": "module",
|
|
23
|
-
"sideEffects": false,
|
|
24
|
-
"exports": {
|
|
25
|
-
".": {
|
|
26
|
-
"types": "./dist/index.d.mts",
|
|
27
|
-
"import": "./dist/index.mjs"
|
|
28
|
-
},
|
|
29
|
-
"./browser": {
|
|
30
|
-
"types": "./dist/browser.d.mts",
|
|
31
|
-
"import": "./dist/browser.mjs"
|
|
32
|
-
},
|
|
33
|
-
"./react": {
|
|
34
|
-
"types": "./dist/react.d.mts",
|
|
35
|
-
"import": "./dist/react.mjs"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"publishConfig": {
|
|
39
|
-
"access": "public"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"check": "bun --check --tsconfig-override tsconfig.json",
|
|
43
|
-
"test": "bun --bun vp test --run",
|
|
44
|
-
"test:unit": "bun --bun vp test --run --passWithNoTests --exclude '**/component.test.{ts,tsx}' --exclude '**/*.component.test.{ts,tsx}' --exclude '**/*.integration.test.{ts,tsx}'",
|
|
45
|
-
"test:integration": "bun --bun vp test --run --passWithNoTests integration.test",
|
|
46
|
-
"test:component": "bun --bun vp test --run --passWithNoTests component.test",
|
|
47
|
-
"test:coverage": "bun --bun vp test --run --passWithNoTests --coverage --coverage.reporter=text --coverage.reporter=json --coverage.reporter=lcov",
|
|
48
|
-
"build": "tsdown",
|
|
49
|
-
"dev": "tsdown --watch",
|
|
50
|
-
"pack:check": "bun pm pack --dry-run --ignore-scripts"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"posthog-js": "^1.438.13"
|
|
54
|
-
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"@testing-library/react": "^16.3.3",
|
|
57
|
-
"@types/react": "^19.3.0",
|
|
58
|
-
"@types/react-dom": "^19.3.0",
|
|
59
|
-
"@vitest/coverage-v8": "^5.0.5",
|
|
60
|
-
"jsdom": "^30.1.3",
|
|
61
|
-
"react": "^19.3.1",
|
|
62
|
-
"react-dom": "^19.3.1"
|
|
63
|
-
},
|
|
64
|
-
"peerDependencies": {
|
|
65
|
-
"react": "^19.0.0"
|
|
66
|
-
},
|
|
67
|
-
"peerDependenciesMeta": {
|
|
68
|
-
"react": {
|
|
69
|
-
"optional": true
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"engines": {
|
|
73
|
-
"node": ">=22.14"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
3
|
+
"version": "0.0.0-stage",
|
|
4
|
+
"stub": true,
|
|
5
|
+
"description": "Temporary package placeholder for staged publishing"
|
|
6
|
+
}
|
package/CHANGELOG.md
DELETED
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 Zack <heyloyep@gmail.com>
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/dist/browser.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AnalyticsClient, AnalyticsProperties, EventPolicy } from "./index.mjs";
|
|
2
|
-
//#region src/browser.d.ts
|
|
3
|
-
export interface BrowserAnalyticsOptions {
|
|
4
|
-
token: string;
|
|
5
|
-
host: string;
|
|
6
|
-
environment: string;
|
|
7
|
-
release: string;
|
|
8
|
-
assetOrigins: readonly string[];
|
|
9
|
-
policy: EventPolicy;
|
|
10
|
-
properties?: AnalyticsProperties;
|
|
11
|
-
}
|
|
12
|
-
/** No SDK import or network activity until the application explicitly grants consent. */
|
|
13
|
-
export declare function createBrowserAnalytics(options: BrowserAnalyticsOptions): AnalyticsClient;
|
|
14
|
-
//#endregion
|
|
15
|
-
//# sourceMappingURL=browser.d.mts.map
|
package/dist/browser.mjs
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { applicationFrame, sanitizeException } from "./index.mjs";
|
|
2
|
-
//#region src/browser.ts
|
|
3
|
-
/** No SDK import or network activity until the application explicitly grants consent. */
|
|
4
|
-
function createBrowserAnalytics(options) {
|
|
5
|
-
let consent = {
|
|
6
|
-
usage: false,
|
|
7
|
-
errors: false
|
|
8
|
-
};
|
|
9
|
-
let identity = null;
|
|
10
|
-
function safely(run) {
|
|
11
|
-
try {
|
|
12
|
-
run();
|
|
13
|
-
} catch {}
|
|
14
|
-
}
|
|
15
|
-
let sdk;
|
|
16
|
-
let loading;
|
|
17
|
-
let generation = 0;
|
|
18
|
-
let disposed = false;
|
|
19
|
-
const requests = /* @__PURE__ */ new Map();
|
|
20
|
-
function invalidate() {
|
|
21
|
-
generation++;
|
|
22
|
-
for (const [controller, timeout] of requests) {
|
|
23
|
-
clearTimeout(timeout);
|
|
24
|
-
controller.abort();
|
|
25
|
-
}
|
|
26
|
-
requests.clear();
|
|
27
|
-
}
|
|
28
|
-
function syncSdkConsent() {
|
|
29
|
-
safely(() => {
|
|
30
|
-
if (consent.usage || consent.errors) sdk?.opt_in_capturing({ captureEventName: false });
|
|
31
|
-
else sdk?.opt_out_capturing();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async function deliver(event, version) {
|
|
35
|
-
const category = event.event === "$exception" ? "errors" : "usage";
|
|
36
|
-
if (disposed || version !== generation || !consent[category]) return;
|
|
37
|
-
const controller = new AbortController();
|
|
38
|
-
const timeout = setTimeout(() => {
|
|
39
|
-
requests.delete(controller);
|
|
40
|
-
controller.abort();
|
|
41
|
-
}, 1e4);
|
|
42
|
-
requests.set(controller, timeout);
|
|
43
|
-
try {
|
|
44
|
-
await (await fetch(new URL("e/", `${options.host.replace(/\/+$/, "")}/`), {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: { "Content-Type": "application/json" },
|
|
47
|
-
credentials: "omit",
|
|
48
|
-
referrerPolicy: "no-referrer",
|
|
49
|
-
keepalive: false,
|
|
50
|
-
signal: controller.signal,
|
|
51
|
-
body: JSON.stringify({
|
|
52
|
-
api_key: options.token,
|
|
53
|
-
batch: [event],
|
|
54
|
-
sent_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
55
|
-
})
|
|
56
|
-
})).body?.cancel();
|
|
57
|
-
} catch {} finally {
|
|
58
|
-
clearTimeout(timeout);
|
|
59
|
-
requests.delete(controller);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const exceptions = /* @__PURE__ */ new WeakSet();
|
|
63
|
-
const configured = Boolean(options.token && options.host && options.release);
|
|
64
|
-
function beforeSend(event) {
|
|
65
|
-
if (!event || disposed) return null;
|
|
66
|
-
const error = event.event === "$exception";
|
|
67
|
-
const identifying = event.event === "$identify";
|
|
68
|
-
if (error ? !consent.errors : !consent.usage) return null;
|
|
69
|
-
const properties = event.properties;
|
|
70
|
-
const extra = error || identifying ? {} : options.policy(event.event, properties);
|
|
71
|
-
if (!extra) return null;
|
|
72
|
-
const safe = {
|
|
73
|
-
...options.properties,
|
|
74
|
-
...extra,
|
|
75
|
-
environment: options.environment,
|
|
76
|
-
release: options.release,
|
|
77
|
-
$geoip_disable: true
|
|
78
|
-
};
|
|
79
|
-
for (const key of [
|
|
80
|
-
"token",
|
|
81
|
-
"distinct_id",
|
|
82
|
-
"$device_id",
|
|
83
|
-
"$anon_distinct_id",
|
|
84
|
-
"$lib",
|
|
85
|
-
"$lib_version",
|
|
86
|
-
"$process_person_profile"
|
|
87
|
-
]) if (["string", "boolean"].includes(typeof properties[key])) safe[key] = properties[key];
|
|
88
|
-
if (error) {
|
|
89
|
-
const exceptions = properties.$exception_list;
|
|
90
|
-
if (!Array.isArray(exceptions)) return null;
|
|
91
|
-
safe.$exception_list = exceptions.slice(0, 1).map((exception) => ({
|
|
92
|
-
type: exception.type,
|
|
93
|
-
value: /^[A-Z][A-Z0-9_]{0,63}$/.test(exception.value) ? exception.value : "UNEXPECTED_ERROR",
|
|
94
|
-
stacktrace: { frames: (exception.stacktrace?.frames ?? []).flatMap((frame) => {
|
|
95
|
-
const filename = typeof frame.filename === "string" ? applicationFrame(frame.filename, options.assetOrigins) : null;
|
|
96
|
-
if (!filename) return [];
|
|
97
|
-
return [{
|
|
98
|
-
filename,
|
|
99
|
-
...typeof frame.lineno === "number" ? { lineno: frame.lineno } : {},
|
|
100
|
-
...typeof frame.colno === "number" ? { colno: frame.colno } : {},
|
|
101
|
-
...typeof frame.chunk_id === "string" && /^[a-zA-Z0-9-]+$/.test(frame.chunk_id) ? { chunk_id: frame.chunk_id } : {},
|
|
102
|
-
platform: "javascript"
|
|
103
|
-
}];
|
|
104
|
-
}) }
|
|
105
|
-
}));
|
|
106
|
-
safe.$exception_level = "error";
|
|
107
|
-
if (typeof properties.$release_id === "string" && /^[a-f0-9-]{16,128}$/i.test(properties.$release_id)) safe.$release_id = properties.$release_id;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
event: event.event,
|
|
111
|
-
properties: safe,
|
|
112
|
-
...event.timestamp ? { timestamp: event.timestamp } : {},
|
|
113
|
-
uuid: event.uuid
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
async function load() {
|
|
117
|
-
if (disposed || !configured || typeof window === "undefined" || !consent.usage && !consent.errors) return;
|
|
118
|
-
return loading ??= import("posthog-js/no-external").then(({ PostHog }) => {
|
|
119
|
-
if (disposed || !consent.usage && !consent.errors) return;
|
|
120
|
-
sdk = new PostHog();
|
|
121
|
-
sdk.init(options.token, {
|
|
122
|
-
api_host: options.host,
|
|
123
|
-
persistence: "memory",
|
|
124
|
-
reuseAnonymousId: true,
|
|
125
|
-
autocapture: false,
|
|
126
|
-
capture_pageview: false,
|
|
127
|
-
capture_pageleave: false,
|
|
128
|
-
capture_dead_clicks: false,
|
|
129
|
-
capture_exceptions: false,
|
|
130
|
-
disable_session_recording: true,
|
|
131
|
-
disable_surveys: true,
|
|
132
|
-
disable_conversations: true,
|
|
133
|
-
disable_product_tours: true,
|
|
134
|
-
disable_external_dependency_loading: true,
|
|
135
|
-
advanced_disable_flags: true,
|
|
136
|
-
capture_performance: false,
|
|
137
|
-
save_referrer: false,
|
|
138
|
-
save_campaign_params: false,
|
|
139
|
-
enable_heatmaps: false,
|
|
140
|
-
request_batching: false,
|
|
141
|
-
person_profiles: "identified_only",
|
|
142
|
-
ip: false,
|
|
143
|
-
before_send: (event) => {
|
|
144
|
-
try {
|
|
145
|
-
const safe = beforeSend(event);
|
|
146
|
-
if (safe) deliver(safe, generation);
|
|
147
|
-
} catch {}
|
|
148
|
-
return null;
|
|
149
|
-
},
|
|
150
|
-
on_request_error: () => {}
|
|
151
|
-
});
|
|
152
|
-
syncSdkConsent();
|
|
153
|
-
if (consent.usage && identity) sdk.identify(identity);
|
|
154
|
-
return sdk;
|
|
155
|
-
}).catch(() => {
|
|
156
|
-
sdk = void 0;
|
|
157
|
-
loading = void 0;
|
|
158
|
-
}).finally(() => {
|
|
159
|
-
if (!sdk) loading = void 0;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
function send(category, run) {
|
|
163
|
-
if (disposed || !consent[category]) return;
|
|
164
|
-
const version = generation;
|
|
165
|
-
load().then((instance) => {
|
|
166
|
-
if (instance && !disposed && version === generation && consent[category]) run(instance);
|
|
167
|
-
}).catch(() => {});
|
|
168
|
-
}
|
|
169
|
-
const onError = (event) => {
|
|
170
|
-
if (event.error) client.captureException(event.error);
|
|
171
|
-
};
|
|
172
|
-
const onRejection = (event) => client.captureException(event.reason);
|
|
173
|
-
function listen(enabled) {
|
|
174
|
-
if (typeof window === "undefined") return;
|
|
175
|
-
window.removeEventListener("error", onError);
|
|
176
|
-
window.removeEventListener("unhandledrejection", onRejection);
|
|
177
|
-
if (enabled) {
|
|
178
|
-
window.addEventListener("error", onError);
|
|
179
|
-
window.addEventListener("unhandledrejection", onRejection);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const client = {
|
|
183
|
-
capture(event, properties = {}) {
|
|
184
|
-
try {
|
|
185
|
-
const safe = options.policy(event, properties);
|
|
186
|
-
if (safe && !event.startsWith("$")) send("usage", (instance) => instance.capture(event, safe));
|
|
187
|
-
} catch {}
|
|
188
|
-
},
|
|
189
|
-
captureException(error) {
|
|
190
|
-
if (disposed || !consent.errors) return;
|
|
191
|
-
if (error && typeof error === "object") {
|
|
192
|
-
if (exceptions.has(error)) return;
|
|
193
|
-
exceptions.add(error);
|
|
194
|
-
}
|
|
195
|
-
const safe = sanitizeException(error, options.assetOrigins);
|
|
196
|
-
send("errors", (instance) => instance.captureException(safe));
|
|
197
|
-
},
|
|
198
|
-
identify(id) {
|
|
199
|
-
if (disposed || identity === id) return;
|
|
200
|
-
invalidate();
|
|
201
|
-
safely(() => sdk?.reset(true));
|
|
202
|
-
syncSdkConsent();
|
|
203
|
-
identity = id;
|
|
204
|
-
if (id) send("usage", (instance) => instance.identify(id));
|
|
205
|
-
},
|
|
206
|
-
reset() {
|
|
207
|
-
if (disposed) return;
|
|
208
|
-
invalidate();
|
|
209
|
-
identity = null;
|
|
210
|
-
safely(() => sdk?.reset(true));
|
|
211
|
-
syncSdkConsent();
|
|
212
|
-
},
|
|
213
|
-
setConsent(next) {
|
|
214
|
-
if (disposed || consent.usage === next.usage && consent.errors === next.errors) return;
|
|
215
|
-
invalidate();
|
|
216
|
-
const usageChanged = consent.usage !== next.usage;
|
|
217
|
-
consent = {
|
|
218
|
-
usage: next.usage === true,
|
|
219
|
-
errors: next.errors === true
|
|
220
|
-
};
|
|
221
|
-
listen(configured && consent.errors);
|
|
222
|
-
if (usageChanged) safely(() => sdk?.reset(true));
|
|
223
|
-
syncSdkConsent();
|
|
224
|
-
if (!consent.usage && !consent.errors) return;
|
|
225
|
-
load();
|
|
226
|
-
if (consent.usage && identity) send("usage", (instance) => instance.identify(identity));
|
|
227
|
-
},
|
|
228
|
-
dispose() {
|
|
229
|
-
invalidate();
|
|
230
|
-
disposed = true;
|
|
231
|
-
consent = {
|
|
232
|
-
usage: false,
|
|
233
|
-
errors: false
|
|
234
|
-
};
|
|
235
|
-
identity = null;
|
|
236
|
-
listen(false);
|
|
237
|
-
safely(() => sdk?.opt_out_capturing());
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
return client;
|
|
241
|
-
}
|
|
242
|
-
//#endregion
|
|
243
|
-
export { createBrowserAnalytics };
|
|
244
|
-
|
|
245
|
-
//# sourceMappingURL=browser.mjs.map
|
package/dist/browser.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.mjs","names":[],"sources":["../src/browser.ts"],"sourcesContent":["import type { PostHog, CaptureResult } from \"posthog-js\";\nimport {\n applicationFrame,\n sanitizeException,\n type AnalyticsClient,\n type AnalyticsConsent,\n type AnalyticsProperties,\n type EventPolicy,\n} from \"./index.js\";\n\nexport interface BrowserAnalyticsOptions {\n token: string;\n host: string;\n environment: string;\n release: string;\n assetOrigins: readonly string[];\n policy: EventPolicy;\n properties?: AnalyticsProperties;\n}\n/** No SDK import or network activity until the application explicitly grants consent. */\nexport function createBrowserAnalytics(options: BrowserAnalyticsOptions): AnalyticsClient {\n let consent: AnalyticsConsent = { usage: false, errors: false };\n let identity: string | null = null;\n function safely(run: () => void) {\n try {\n run();\n } catch {\n /* Diagnostics never affect product operations. */\n }\n }\n let sdk: PostHog | undefined;\n let loading: Promise<PostHog | undefined> | undefined;\n let generation = 0;\n let disposed = false;\n const requests = new Map<AbortController, ReturnType<typeof setTimeout>>();\n function invalidate() {\n generation++;\n for (const [controller, timeout] of requests) {\n clearTimeout(timeout);\n controller.abort();\n }\n requests.clear();\n }\n function syncSdkConsent() {\n safely(() => {\n if (consent.usage || consent.errors) sdk?.opt_in_capturing({ captureEventName: false });\n else sdk?.opt_out_capturing();\n });\n }\n async function deliver(event: CaptureResult, version: number) {\n const category = event.event === \"$exception\" ? \"errors\" : \"usage\";\n if (disposed || version !== generation || !consent[category]) return;\n const controller = new AbortController();\n const timeout = setTimeout(() => {\n requests.delete(controller);\n controller.abort();\n }, 10_000);\n requests.set(controller, timeout);\n try {\n const response = await fetch(new URL(\"e/\", `${options.host.replace(/\\/+$/, \"\")}/`), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"omit\",\n referrerPolicy: \"no-referrer\",\n keepalive: false,\n signal: controller.signal,\n body: JSON.stringify({\n api_key: options.token,\n batch: [event],\n sent_at: new Date().toISOString(),\n }),\n });\n await response.body?.cancel();\n } catch {\n // One attempt only. Aborts and delivery failures never affect product operations.\n } finally {\n clearTimeout(timeout);\n requests.delete(controller);\n }\n }\n const exceptions = new WeakSet<object>();\n const configured = Boolean(options.token && options.host && options.release);\n function beforeSend(event: CaptureResult | null): CaptureResult | null {\n if (!event || disposed) return null;\n const error = event.event === \"$exception\";\n const identifying = event.event === \"$identify\";\n if (error ? !consent.errors : !consent.usage) return null;\n const properties = event.properties;\n const extra = error || identifying ? {} : options.policy(event.event, properties);\n if (!extra) return null;\n // Rebuild properties instead of forwarding SDK URL/referrer/person enrichment.\n const safe: Record<string, unknown> = {\n ...options.properties,\n ...extra,\n environment: options.environment,\n release: options.release,\n $geoip_disable: true,\n };\n for (const key of [\n \"token\",\n \"distinct_id\",\n \"$device_id\",\n \"$anon_distinct_id\",\n \"$lib\",\n \"$lib_version\",\n \"$process_person_profile\",\n ])\n if ([\"string\", \"boolean\"].includes(typeof properties[key])) safe[key] = properties[key];\n if (error) {\n const exceptions: unknown = properties.$exception_list;\n if (!Array.isArray(exceptions)) return null;\n safe.$exception_list = exceptions.slice(0, 1).map((exception) => ({\n type: exception.type,\n value: /^[A-Z][A-Z0-9_]{0,63}$/.test(exception.value)\n ? exception.value\n : \"UNEXPECTED_ERROR\",\n stacktrace: {\n frames: (exception.stacktrace?.frames ?? []).flatMap((frame: Record<string, unknown>) => {\n const filename =\n typeof frame.filename === \"string\"\n ? applicationFrame(frame.filename, options.assetOrigins)\n : null;\n if (!filename) return [];\n return [\n {\n filename,\n ...(typeof frame.lineno === \"number\" ? { lineno: frame.lineno } : {}),\n ...(typeof frame.colno === \"number\" ? { colno: frame.colno } : {}),\n ...(typeof frame.chunk_id === \"string\" && /^[a-zA-Z0-9-]+$/.test(frame.chunk_id)\n ? { chunk_id: frame.chunk_id }\n : {}),\n platform: \"javascript\",\n },\n ];\n }),\n },\n }));\n safe.$exception_level = \"error\";\n if (\n typeof properties.$release_id === \"string\" &&\n /^[a-f0-9-]{16,128}$/i.test(properties.$release_id)\n )\n safe.$release_id = properties.$release_id;\n }\n return {\n event: event.event,\n properties: safe,\n ...(event.timestamp ? { timestamp: event.timestamp } : {}),\n uuid: event.uuid,\n };\n }\n async function load(): Promise<PostHog | undefined> {\n if (\n disposed ||\n !configured ||\n typeof window === \"undefined\" ||\n (!consent.usage && !consent.errors)\n )\n return;\n return (loading ??= import(\"posthog-js/no-external\")\n .then(({ PostHog }) => {\n if (disposed || (!consent.usage && !consent.errors)) return;\n sdk = new PostHog();\n sdk.init(options.token, {\n api_host: options.host,\n persistence: \"memory\",\n reuseAnonymousId: true,\n autocapture: false,\n capture_pageview: false,\n capture_pageleave: false,\n capture_dead_clicks: false,\n capture_exceptions: false,\n disable_session_recording: true,\n disable_surveys: true,\n disable_conversations: true,\n disable_product_tours: true,\n disable_external_dependency_loading: true,\n advanced_disable_flags: true,\n capture_performance: false,\n save_referrer: false,\n save_campaign_params: false,\n enable_heatmaps: false,\n request_batching: false,\n person_profiles: \"identified_only\",\n ip: false,\n before_send: (event) => {\n try {\n const safe = beforeSend(event);\n if (safe) void deliver(safe, generation);\n } catch {\n /* Invalid SDK payloads fail closed. */\n }\n // The SDK formats events; only our cancellable, single-attempt transport sends them.\n return null;\n },\n on_request_error: () => {},\n });\n // SDK consent has its own persistence even with persistence: \"memory\".\n syncSdkConsent();\n if (consent.usage && identity) sdk.identify(identity);\n return sdk;\n })\n .catch(() => {\n sdk = undefined;\n loading = undefined;\n return undefined;\n })\n .finally(() => {\n if (!sdk) loading = undefined;\n }));\n }\n function send(category: keyof AnalyticsConsent, run: (instance: PostHog) => void) {\n if (disposed || !consent[category]) return;\n const version = generation;\n void load()\n .then((instance) => {\n if (instance && !disposed && version === generation && consent[category]) run(instance);\n })\n .catch(() => {});\n }\n const onError = (event: ErrorEvent) => {\n if (event.error) client.captureException(event.error);\n };\n const onRejection = (event: PromiseRejectionEvent) => client.captureException(event.reason);\n function listen(enabled: boolean) {\n if (typeof window === \"undefined\") return;\n window.removeEventListener(\"error\", onError);\n window.removeEventListener(\"unhandledrejection\", onRejection);\n if (enabled) {\n window.addEventListener(\"error\", onError);\n window.addEventListener(\"unhandledrejection\", onRejection);\n }\n }\n const client: AnalyticsClient = {\n capture(event, properties = {}) {\n try {\n const safe = options.policy(event, properties);\n if (safe && !event.startsWith(\"$\"))\n send(\"usage\", (instance) => instance.capture(event, safe));\n } catch {\n /* Policy failures fail closed. */\n }\n },\n captureException(error) {\n if (disposed || !consent.errors) return;\n if (error && typeof error === \"object\") {\n if (exceptions.has(error)) return;\n exceptions.add(error);\n }\n const safe = sanitizeException(error, options.assetOrigins);\n send(\"errors\", (instance) => instance.captureException(safe));\n },\n identify(id) {\n if (disposed || identity === id) return;\n invalidate();\n safely(() => sdk?.reset(true));\n syncSdkConsent();\n identity = id;\n if (id) send(\"usage\", (instance) => instance.identify(id));\n },\n reset() {\n if (disposed) return;\n invalidate();\n identity = null;\n safely(() => sdk?.reset(true));\n syncSdkConsent();\n },\n setConsent(next) {\n if (disposed || (consent.usage === next.usage && consent.errors === next.errors)) return;\n invalidate();\n const usageChanged = consent.usage !== next.usage;\n consent = { usage: next.usage === true, errors: next.errors === true };\n listen(configured && consent.errors);\n if (usageChanged) safely(() => sdk?.reset(true));\n syncSdkConsent();\n if (!consent.usage && !consent.errors) return;\n void load();\n if (consent.usage && identity) send(\"usage\", (instance) => instance.identify(identity!));\n },\n dispose() {\n invalidate();\n disposed = true;\n consent = { usage: false, errors: false };\n identity = null;\n listen(false);\n safely(() => sdk?.opt_out_capturing());\n },\n };\n return client;\n}\n"],"mappings":";;;AAoBA,SAAgB,uBAAuB,SAAmD;CACxF,IAAI,UAA4B;EAAE,OAAO;EAAO,QAAQ;CAAM;CAC9D,IAAI,WAA0B;CAC9B,SAAS,OAAO,KAAiB;EAC/B,IAAI;GACF,IAAI;EACN,QAAQ,CAER;CACF;CACA,IAAI;CACJ,IAAI;CACJ,IAAI,aAAa;CACjB,IAAI,WAAW;CACf,MAAM,2BAAW,IAAI,IAAoD;CACzE,SAAS,aAAa;EACpB;EACA,KAAK,MAAM,CAAC,YAAY,YAAY,UAAU;GAC5C,aAAa,OAAO;GACpB,WAAW,MAAM;EACnB;EACA,SAAS,MAAM;CACjB;CACA,SAAS,iBAAiB;EACxB,aAAa;GACX,IAAI,QAAQ,SAAS,QAAQ,QAAQ,KAAK,iBAAiB,EAAE,kBAAkB,MAAM,CAAC;QACjF,KAAK,kBAAkB;EAC9B,C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rE,OAAO,cAAc,QAAQ,MAAM;GACnC,IAAI,cAAc,aAAa,KAAK,MAAM,IAAI,CAAC;GAC/C,eAAe;GACf,IAAI,CAAC,QAAQ,SAAS,CAAC,QAAQ,QAAQ;GACvC,KAAU;GACV,IAAI,QAAQ,SAAS,UAAU,KAAK,UAAU,aAAa,SAAS,SAAS,QAAS,CAAC;EACzF;EACA,UAAU;GACR,WAAW;GACX,WAAW;GACX,UAAU;IAAE,OAAO;IAAO,QAAQ;GAAM;GACxC,WAAW;GACX,OAAO,KAAK;GACZ,aAAa,KAAK,kBAAkB,CAAC;EACvC;CACF;CACA,OAAO;AACT"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/index.d.ts
|
|
2
|
-
export type AnalyticsProperties = Readonly<Record<string, string | number | boolean>>;
|
|
3
|
-
export interface AnalyticsConsent {
|
|
4
|
-
usage: boolean;
|
|
5
|
-
errors: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare const DEFAULT_ANALYTICS_CONSENT: Readonly<AnalyticsConsent>;
|
|
8
|
-
export type EventPolicy = (event: string, properties: AnalyticsProperties) => AnalyticsProperties | null;
|
|
9
|
-
export interface AnalyticsClient {
|
|
10
|
-
capture(event: string, properties?: AnalyticsProperties): void;
|
|
11
|
-
captureException(error: unknown): void;
|
|
12
|
-
identify(id: string | null): void;
|
|
13
|
-
reset(): void;
|
|
14
|
-
setConsent(consent: AnalyticsConsent): void;
|
|
15
|
-
dispose(): void;
|
|
16
|
-
}
|
|
17
|
-
export declare function createNoopAnalytics(): AnalyticsClient;
|
|
18
|
-
/** Application assets only. Never retain file paths, query strings or caller text. */
|
|
19
|
-
export declare function applicationFrame(value: string, origins: readonly string[]): string | null;
|
|
20
|
-
export declare function sanitizeException(error: unknown, origins: readonly string[]): Error;
|
|
21
|
-
//#endregion
|
|
22
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//#region src/index.ts
|
|
2
|
-
const DEFAULT_ANALYTICS_CONSENT = Object.freeze({
|
|
3
|
-
usage: false,
|
|
4
|
-
errors: false
|
|
5
|
-
});
|
|
6
|
-
function createNoopAnalytics() {
|
|
7
|
-
const noop = () => {};
|
|
8
|
-
return {
|
|
9
|
-
capture: noop,
|
|
10
|
-
captureException: noop,
|
|
11
|
-
identify: noop,
|
|
12
|
-
reset: noop,
|
|
13
|
-
setConsent: noop,
|
|
14
|
-
dispose: noop
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
/** Application assets only. Never retain file paths, query strings or caller text. */
|
|
18
|
-
function applicationFrame(value, origins) {
|
|
19
|
-
try {
|
|
20
|
-
const url = new URL(value);
|
|
21
|
-
if (!origins.some((origin) => {
|
|
22
|
-
const allowed = new URL(origin);
|
|
23
|
-
return allowed.protocol === url.protocol && allowed.host === url.host;
|
|
24
|
-
})) return null;
|
|
25
|
-
if (!/^(?:https?:|views:)$/.test(url.protocol) || !/^\/assets\/[a-zA-Z0-9_.-]+\.(?:m?js)$/.test(url.pathname)) return null;
|
|
26
|
-
return `${url.protocol}//${url.host}${url.pathname}`;
|
|
27
|
-
} catch {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const errorNames = /* @__PURE__ */ new Set([
|
|
32
|
-
"Error",
|
|
33
|
-
"TypeError",
|
|
34
|
-
"RangeError",
|
|
35
|
-
"ReferenceError",
|
|
36
|
-
"SyntaxError",
|
|
37
|
-
"URIError",
|
|
38
|
-
"EvalError",
|
|
39
|
-
"AggregateError"
|
|
40
|
-
]);
|
|
41
|
-
function sanitizeException(error, origins) {
|
|
42
|
-
const safe = /* @__PURE__ */ new Error("UNEXPECTED_ERROR");
|
|
43
|
-
safe.stack = "";
|
|
44
|
-
try {
|
|
45
|
-
if (!error || typeof error !== "object") return safe;
|
|
46
|
-
const code = Object.getOwnPropertyDescriptor(error, "code")?.value;
|
|
47
|
-
if (typeof code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code)) safe.message = code;
|
|
48
|
-
if (!(error instanceof Error)) return safe;
|
|
49
|
-
if (errorNames.has(error.name)) safe.name = error.name;
|
|
50
|
-
const frames = (error.stack ?? "").split("\n").slice(0, 50).flatMap((line) => {
|
|
51
|
-
const match = line.match(/((?:https?|views):\/\/[^\s()]+):(\d+):(\d+)\)?$/);
|
|
52
|
-
const asset = match ? applicationFrame(match[1], origins) : null;
|
|
53
|
-
return asset && match ? [` at ${asset}:${match[2]}:${match[3]}`] : [];
|
|
54
|
-
});
|
|
55
|
-
if (frames.length) safe.stack = `${safe.name}: ${safe.message}\n${frames.join("\n")}`;
|
|
56
|
-
} catch {}
|
|
57
|
-
return safe;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
export { DEFAULT_ANALYTICS_CONSENT, applicationFrame, createNoopAnalytics, sanitizeException };
|
|
61
|
-
|
|
62
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type AnalyticsProperties = Readonly<Record<string, string | number | boolean>>;\nexport interface AnalyticsConsent {\n usage: boolean;\n errors: boolean;\n}\nexport const DEFAULT_ANALYTICS_CONSENT: Readonly<AnalyticsConsent> = Object.freeze({\n usage: false,\n errors: false,\n});\nexport type EventPolicy = (\n event: string,\n properties: AnalyticsProperties,\n) => AnalyticsProperties | null;\nexport interface AnalyticsClient {\n capture(event: string, properties?: AnalyticsProperties): void;\n captureException(error: unknown): void;\n identify(id: string | null): void;\n reset(): void;\n setConsent(consent: AnalyticsConsent): void;\n dispose(): void;\n}\nexport function createNoopAnalytics(): AnalyticsClient {\n const noop = () => {};\n return {\n capture: noop,\n captureException: noop,\n identify: noop,\n reset: noop,\n setConsent: noop,\n dispose: noop,\n };\n}\n/** Application assets only. Never retain file paths, query strings or caller text. */\nexport function applicationFrame(value: string, origins: readonly string[]): string | null {\n try {\n const url = new URL(value);\n if (\n !origins.some((origin) => {\n const allowed = new URL(origin);\n return allowed.protocol === url.protocol && allowed.host === url.host;\n })\n )\n return null;\n if (\n !/^(?:https?:|views:)$/.test(url.protocol) ||\n !/^\\/assets\\/[a-zA-Z0-9_.-]+\\.(?:m?js)$/.test(url.pathname)\n )\n return null;\n return `${url.protocol}//${url.host}${url.pathname}`;\n } catch {\n return null;\n }\n}\nconst errorNames = new Set([\n \"Error\",\n \"TypeError\",\n \"RangeError\",\n \"ReferenceError\",\n \"SyntaxError\",\n \"URIError\",\n \"EvalError\",\n \"AggregateError\",\n]);\nexport function sanitizeException(error: unknown, origins: readonly string[]): Error {\n const safe = new Error(\"UNEXPECTED_ERROR\");\n safe.stack = \"\";\n try {\n if (!error || typeof error !== \"object\") return safe;\n const code = Object.getOwnPropertyDescriptor(error, \"code\")?.value;\n if (typeof code === \"string\" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code)) safe.message = code;\n if (!(error instanceof Error)) return safe;\n if (errorNames.has(error.name)) safe.name = error.name;\n const frames = (error.stack ?? \"\")\n .split(\"\\n\")\n .slice(0, 50)\n .flatMap((line) => {\n const match = line.match(/((?:https?|views):\\/\\/[^\\s()]+):(\\d+):(\\d+)\\)?$/);\n const asset = match ? applicationFrame(match[1]!, origins) : null;\n return asset && match ? [` at ${asset}:${match[2]}:${match[3]}`] : [];\n });\n if (frames.length) safe.stack = `${safe.name}: ${safe.message}\\n${frames.join(\"\\n\")}`;\n } catch {\n /* An unknown thrown object must not break error reporting. */\n }\n return safe;\n}\n"],"mappings":";AAKA,MAAa,4BAAwD,OAAO,OAAO;CACjF,OAAO;CACP,QAAQ;AACV,CAAC;AAaD,SAAgB,sBAAuC;CACrD,MAAM,aAAa,CAAC;CACpB,OAAO;EACL,SAAS;EACT,kBAAkB;EAClB,UAAU;EACV,OAAO;EACP,YAAY;EACZ,SAAS;CACX;AACF;;AAEA,SAAgB,iBAAiB,O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K,QAAQ,IAAI,OAAO,KAAK,IAAI;CACpF,QAAQ,CAER;CACA,OAAO;AACT"}
|
package/dist/react.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AnalyticsClient } from "./index.mjs";
|
|
2
|
-
import { Component, ErrorInfo, ReactNode } from "react";
|
|
3
|
-
//#region src/react.d.ts
|
|
4
|
-
export declare function AnalyticsProvider({ client, children }: {
|
|
5
|
-
client: AnalyticsClient;
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
}): import("react").JSX.Element;
|
|
8
|
-
export declare function useAnalytics(): AnalyticsClient;
|
|
9
|
-
export declare class AnalyticsErrorBoundary extends Component<{
|
|
10
|
-
client: AnalyticsClient;
|
|
11
|
-
fallback: ReactNode;
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
}, {
|
|
14
|
-
failed: boolean;
|
|
15
|
-
}> {
|
|
16
|
-
state: {
|
|
17
|
-
failed: boolean;
|
|
18
|
-
};
|
|
19
|
-
static getDerivedStateFromError(): {
|
|
20
|
-
failed: boolean;
|
|
21
|
-
};
|
|
22
|
-
componentDidCatch(error: Error, _info: ErrorInfo): void;
|
|
23
|
-
render(): ReactNode;
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//# sourceMappingURL=react.d.mts.map
|
package/dist/react.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createNoopAnalytics } from "./index.mjs";
|
|
2
|
-
import { Component, createContext, useContext } from "react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
//#region src/react.tsx
|
|
5
|
-
const context = createContext(createNoopAnalytics());
|
|
6
|
-
function AnalyticsProvider({ client, children }) {
|
|
7
|
-
return /* @__PURE__ */ jsx(context.Provider, {
|
|
8
|
-
value: client,
|
|
9
|
-
children
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
function useAnalytics() {
|
|
13
|
-
return useContext(context);
|
|
14
|
-
}
|
|
15
|
-
var AnalyticsErrorBoundary = class extends Component {
|
|
16
|
-
state = { failed: false };
|
|
17
|
-
static getDerivedStateFromError() {
|
|
18
|
-
return { failed: true };
|
|
19
|
-
}
|
|
20
|
-
componentDidCatch(error, _info) {
|
|
21
|
-
this.props.client.captureException(error);
|
|
22
|
-
}
|
|
23
|
-
render() {
|
|
24
|
-
return this.state.failed ? this.props.fallback : this.props.children;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
|
-
export { AnalyticsErrorBoundary, AnalyticsProvider, useAnalytics };
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=react.mjs.map
|
package/dist/react.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import { Component, createContext, useContext, type ReactNode, type ErrorInfo } from \"react\";\nimport { createNoopAnalytics, type AnalyticsClient } from \"./index.js\";\nconst context = createContext<AnalyticsClient>(createNoopAnalytics());\nexport function AnalyticsProvider({\n client,\n children,\n}: {\n client: AnalyticsClient;\n children: ReactNode;\n}) {\n return <context.Provider value={client}>{children}</context.Provider>;\n}\nexport function useAnalytics(): AnalyticsClient {\n return useContext(context);\n}\nexport class AnalyticsErrorBoundary extends Component<\n { client: AnalyticsClient; fallback: ReactNode; children: ReactNode },\n { failed: boolean }\n> {\n override state = { failed: false };\n static getDerivedStateFromError() {\n return { failed: true };\n }\n override componentDidCatch(error: Error, _info: ErrorInfo) {\n this.props.client.captureException(error);\n }\n override render() {\n return this.state.failed ? this.props.fallback : this.props.children;\n }\n}\n"],"mappings":";;;;AAEA,MAAM,UAAU,cAA+B,oBAAoB,CAAC;AACpE,SAAgB,kBAAkB,EAChC,QACA,YAIC;CACD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAS;CAA2B,CAAA;AACtE;AACA,SAAgB,eAAgC;CAC9C,OAAO,WAAW,OAAO;AAC3B;AACA,IAAa,yBAAb,cAA4C,UAG1C;CACA,QAAiB,EAAE,QAAQ,MAAM;CACjC,OAAO,2BAA2B;EAChC,OAAO,EAAE,QAAQ,KAAK;CACxB;CACA,kBAA2B,OAAc,OAAkB;EACzD,KAAK,MAAM,OAAO,iBAAiB,KAAK;CAC1C;CACA,SAAkB;EAChB,OAAO,KAAK,MAAM,SAAS,KAAK,MAAM,WAAW,KAAK,MAAM;CAC9D;AACF"}
|