@metrictrail/react-native 0.1.0 → 0.2.0
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/index.d.ts +0 -1
- package/dist/index.js +8 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
const fallbackId = () => globalThis.crypto?.randomUUID?.() || 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { const r = Math.random() * 16 | 0; return (c === 'x' ? r : r & 3 | 8).toString(16); });
|
|
2
|
+
// The ingest host is fixed, not a caller-configurable option: one SDK
|
|
3
|
+
// version always talks to exactly one API. If the host ever needs to
|
|
4
|
+
// change, that ships as a new SDK version, not a runtime option.
|
|
5
|
+
const ENDPOINT = 'https://api.metrictrail.io';
|
|
2
6
|
export class MetricTrail {
|
|
3
7
|
options;
|
|
4
8
|
queue = [];
|
|
@@ -9,11 +13,11 @@ export class MetricTrail {
|
|
|
9
13
|
id;
|
|
10
14
|
constructor(options) {
|
|
11
15
|
this.options = options;
|
|
12
|
-
if (
|
|
13
|
-
throw Error('
|
|
16
|
+
if (!options.projectId || !options.writeKey)
|
|
17
|
+
throw Error('Project and write key required');
|
|
14
18
|
this.id = options.idFactory || fallbackId;
|
|
15
19
|
this.anonymousId = options.anonymousId || this.id();
|
|
16
|
-
this.key = options.storageKey || `metrictrail:${options.
|
|
20
|
+
this.key = options.storageKey || `metrictrail:${options.projectId}:queue`;
|
|
17
21
|
}
|
|
18
22
|
static async create(options) { const c = new MetricTrail(options); if (options.storage) {
|
|
19
23
|
try {
|
|
@@ -42,7 +46,7 @@ export class MetricTrail {
|
|
|
42
46
|
const retries = Math.min(5, Math.max(0, this.options.maxRetries ?? 2));
|
|
43
47
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
44
48
|
try {
|
|
45
|
-
const response = await fetch(`${
|
|
49
|
+
const response = await fetch(`${ENDPOINT}/v1/projects/${encodeURIComponent(this.options.projectId)}/events`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${this.options.writeKey}` }, body, signal });
|
|
46
50
|
if (response.ok) {
|
|
47
51
|
failure = undefined;
|
|
48
52
|
break;
|