@teardown/react-native 2.0.18 → 2.0.22
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/package.json
CHANGED
package/src/.DS_Store
ADDED
|
Binary file
|
|
@@ -39,7 +39,7 @@ export const UpdateVersionStatusBodySchema = z.object({
|
|
|
39
39
|
export const SessionSchema = z.object({
|
|
40
40
|
session_id: z.string(),
|
|
41
41
|
device_id: z.string(),
|
|
42
|
-
user_id: z.string(),
|
|
42
|
+
user_id: z.string().or(z.object({ persona_id: z.string() }).transform((val) => val.persona_id)),
|
|
43
43
|
token: z.string(),
|
|
44
44
|
});
|
|
45
45
|
export type Session = z.infer<typeof SessionSchema>;
|
|
@@ -113,7 +113,7 @@ export class IdentityClient {
|
|
|
113
113
|
this.logger.debug(`Initialized with state: ${this.identifyState.type}`);
|
|
114
114
|
} catch (error) {
|
|
115
115
|
// Silently fail on errors - we'll re-identify on app boot if needed
|
|
116
|
-
this.logger.
|
|
116
|
+
this.logger.debugError("Error initializing IdentityClient", { error });
|
|
117
117
|
this.identifyState = { type: "unidentified" };
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -122,26 +122,31 @@ export class IdentityClient {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
private getIdentifyStateFromStorage(): IdentifyState {
|
|
125
|
-
|
|
125
|
+
try {
|
|
126
|
+
const stored = this.storage.getItem(IDENTIFY_STORAGE_KEY);
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
if (stored == null) {
|
|
129
|
+
this.logger.debugInfo("No stored identity state, returning unidentified");
|
|
130
|
+
return UnidentifiedSessionStateSchema.parse({ type: "unidentified" });
|
|
131
|
+
}
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
const parsed = IdentifyStateSchema.parse(JSON.parse(stored));
|
|
134
|
+
this.logger.debugInfo(`Parsed identity state from storage: ${parsed.type}`);
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
// "identifying" is a transient state - if we restore it, treat as unidentified
|
|
137
|
+
// This can happen if the app was killed during an identify call
|
|
138
|
+
if (parsed.type === "identifying") {
|
|
139
|
+
this.logger.debugInfo("Found stale 'identifying' state in storage, resetting to unidentified");
|
|
140
|
+
// Clear the stale state from storage immediately
|
|
141
|
+
this.storage.removeItem(IDENTIFY_STORAGE_KEY);
|
|
142
|
+
return UnidentifiedSessionStateSchema.parse({ type: "unidentified" });
|
|
143
|
+
}
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
return parsed;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
this.logger.debugError("Error getting identify state from storage", { error });
|
|
148
|
+
return { type: "unidentified" };
|
|
149
|
+
}
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
private saveIdentifyStateToStorage(identifyState: IdentifyState): void {
|
|
@@ -150,11 +155,11 @@ export class IdentityClient {
|
|
|
150
155
|
|
|
151
156
|
private setIdentifyState(newState: IdentifyState): void {
|
|
152
157
|
if (this.identifyState.type === newState.type) {
|
|
153
|
-
this.logger.
|
|
158
|
+
this.logger.debugInfo(`Identify state already set: ${this.identifyState.type}`);
|
|
154
159
|
return;
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
this.logger.
|
|
162
|
+
this.logger.debugInfo(`Identify state: ${this.identifyState.type} -> ${newState.type}`);
|
|
158
163
|
this.identifyState = newState;
|
|
159
164
|
this.saveIdentifyStateToStorage(newState);
|
|
160
165
|
this.emitter.emit("IDENTIFY_STATE_CHANGED", newState);
|
|
@@ -219,7 +224,7 @@ export class IdentityClient {
|
|
|
219
224
|
}
|
|
220
225
|
|
|
221
226
|
async identify(user?: Persona): AsyncResult<IdentityUser> {
|
|
222
|
-
this.logger.
|
|
227
|
+
this.logger.debugInfo(`Identifying user with persona: ${user?.name ?? "none"}`);
|
|
223
228
|
const previousState = this.identifyState;
|
|
224
229
|
this.setIdentifyState({ type: "identifying" });
|
|
225
230
|
|
|
@@ -250,7 +255,7 @@ export class IdentityClient {
|
|
|
250
255
|
},
|
|
251
256
|
});
|
|
252
257
|
|
|
253
|
-
this.logger.
|
|
258
|
+
this.logger.debugInfo(`Identify API response received`);
|
|
254
259
|
if (response.error != null) {
|
|
255
260
|
this.logger.warn("Identify API error", response.error.status, response.error.value);
|
|
256
261
|
this.setIdentifyState(previousState);
|
|
@@ -54,12 +54,16 @@ export class Logger {
|
|
|
54
54
|
private boundConsole = {
|
|
55
55
|
log: console.log.bind(console),
|
|
56
56
|
error: console.error.bind(console),
|
|
57
|
-
debug: console.debug.bind(console),
|
|
58
57
|
warn: console.warn.bind(console),
|
|
59
58
|
trace: console.trace.bind(console),
|
|
59
|
+
debug: console.debug.bind(console),
|
|
60
|
+
debugError: console.debug.bind(console, "Error: "),
|
|
61
|
+
debugWarn: console.debug.bind(console, "Warning: "),
|
|
62
|
+
debugInfo: console.debug.bind(console, "Info: "),
|
|
63
|
+
debugVerbose: console.debug.bind(console, "Verbose: "),
|
|
60
64
|
};
|
|
61
65
|
|
|
62
|
-
constructor(private readonly options: LoggerOptions) {
|
|
66
|
+
constructor(private readonly options: LoggerOptions) {}
|
|
63
67
|
|
|
64
68
|
get prefix() {
|
|
65
69
|
return `[Teardown:${this.options.name}]`;
|
|
@@ -75,11 +79,6 @@ export class Logger {
|
|
|
75
79
|
this.boundConsole.error(`${this.prefix} ${message}`, ...args);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
debug(message: string, ...args: unknown[]) {
|
|
79
|
-
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
80
|
-
this.boundConsole.debug(`${this.prefix} ${message}`, ...args);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
82
|
warn(message: string, ...args: unknown[]) {
|
|
84
83
|
if (!this.options.loggingClient.shouldLog("warn")) return;
|
|
85
84
|
this.boundConsole.warn(`${this.prefix} ${message}`, ...args);
|
|
@@ -89,4 +88,29 @@ export class Logger {
|
|
|
89
88
|
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
90
89
|
this.boundConsole.trace(`${this.prefix} ${message}`, ...args);
|
|
91
90
|
}
|
|
91
|
+
|
|
92
|
+
debug(message: string, ...args: unknown[]) {
|
|
93
|
+
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
94
|
+
this.boundConsole.debug(`${this.prefix} ${message}`, ...args);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
debugError(message: string, ...args: unknown[]) {
|
|
98
|
+
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
99
|
+
this.boundConsole.debugError(`${this.prefix} ${message}`, ...args);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
debugWarn(message: string, ...args: unknown[]) {
|
|
103
|
+
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
104
|
+
this.boundConsole.debugWarn(`${this.prefix} ${message}`, ...args);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
debugInfo(message: string, ...args: unknown[]) {
|
|
108
|
+
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
109
|
+
this.boundConsole.debugInfo(`${this.prefix} ${message}`, ...args);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
debugVerbose(message: string, ...args: unknown[]) {
|
|
113
|
+
if (!this.options.loggingClient.shouldLog("verbose")) return;
|
|
114
|
+
this.boundConsole.debugVerbose(`${this.prefix} ${message}`, ...args);
|
|
115
|
+
}
|
|
92
116
|
}
|
|
@@ -1,80 +1,72 @@
|
|
|
1
1
|
import type { Logger, LoggingClient } from "../logging";
|
|
2
2
|
import type { StorageAdapter, SupportedStorage } from "./adapters/storage.adpater-interface";
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
export class StorageClient {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
shutdown(): void {
|
|
75
|
-
this.storage.forEach((storage) => {
|
|
76
|
-
storage.clear();
|
|
77
|
-
});
|
|
78
|
-
this.storage.clear();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
5
|
+
private readonly logger: Logger;
|
|
6
|
+
|
|
7
|
+
private readonly storage: Map<string, SupportedStorage> = new Map();
|
|
8
|
+
|
|
9
|
+
private readonly preloadPromises: Promise<void>[] = [];
|
|
10
|
+
|
|
11
|
+
private _isReady = false;
|
|
12
|
+
|
|
13
|
+
get isReady(): boolean {
|
|
14
|
+
return this._isReady;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
logging: LoggingClient,
|
|
19
|
+
private readonly orgId: string,
|
|
20
|
+
private readonly projectId: string,
|
|
21
|
+
private readonly storageAdapter: StorageAdapter
|
|
22
|
+
) {
|
|
23
|
+
this.logger = logging.createLogger({
|
|
24
|
+
name: "StorageClient",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private createStorageKey(storageKey: string): string {
|
|
29
|
+
return `teardown:v1:${this.orgId}:${this.projectId}:${storageKey}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
createStorage(storageKey: string): SupportedStorage {
|
|
33
|
+
const fullStorageKey = this.createStorageKey(storageKey);
|
|
34
|
+
|
|
35
|
+
this.logger.debug(`Creating storage for ${fullStorageKey}`);
|
|
36
|
+
if (this.storage.has(fullStorageKey)) {
|
|
37
|
+
this.logger.debug(`Storage already exists for ${fullStorageKey}`);
|
|
38
|
+
const existingStorage = this.storage.get(fullStorageKey);
|
|
39
|
+
|
|
40
|
+
if (existingStorage != null) {
|
|
41
|
+
this.logger.debug(`Returning existing storage for ${fullStorageKey}`);
|
|
42
|
+
return existingStorage;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.logger.error(`Existing storage was found for ${fullStorageKey}, but it was null`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.logger.debug(`Creating new storage for ${fullStorageKey}`);
|
|
49
|
+
const newStorage = this.storageAdapter.createStorage(fullStorageKey);
|
|
50
|
+
const preloadResult = newStorage.preload();
|
|
51
|
+
if (preloadResult instanceof Promise) {
|
|
52
|
+
this.preloadPromises.push(preloadResult);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const remappedStorage = {
|
|
56
|
+
...newStorage,
|
|
57
|
+
clear: () => {
|
|
58
|
+
this.storage.delete(fullStorageKey);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
this.storage.set(fullStorageKey, remappedStorage);
|
|
63
|
+
this.logger.debug(`Storage created for ${fullStorageKey}`);
|
|
64
|
+
|
|
65
|
+
return remappedStorage;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async whenReady(): Promise<void> {
|
|
69
|
+
await Promise.all(this.preloadPromises);
|
|
70
|
+
this._isReady = true;
|
|
71
|
+
}
|
|
72
|
+
}
|