@teardown/react-native 2.0.18 → 2.0.19
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
|
@@ -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
|
}
|