@teardown/react-native 2.0.17 → 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
|
@@ -107,35 +107,46 @@ export class IdentityClient {
|
|
|
107
107
|
}
|
|
108
108
|
this.initialized = true;
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
try {
|
|
111
|
+
// Load state from storage first (for fallback if identify fails)
|
|
112
|
+
this.identifyState = this.getIdentifyStateFromStorage();
|
|
113
|
+
this.logger.debug(`Initialized with state: ${this.identifyState.type}`);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Silently fail on errors - we'll re-identify on app boot if needed
|
|
116
|
+
this.logger.debugError("Error initializing IdentityClient", { error });
|
|
117
|
+
this.identifyState = { type: "unidentified" };
|
|
118
|
+
}
|
|
113
119
|
|
|
114
120
|
// Always identify on app boot to refresh version status
|
|
115
121
|
await this.identify();
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
private getIdentifyStateFromStorage(): IdentifyState {
|
|
119
|
-
|
|
125
|
+
try {
|
|
126
|
+
const stored = this.storage.getItem(IDENTIFY_STORAGE_KEY);
|
|
120
127
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
if (stored == null) {
|
|
129
|
+
this.logger.debugInfo("No stored identity state, returning unidentified");
|
|
130
|
+
return UnidentifiedSessionStateSchema.parse({ type: "unidentified" });
|
|
131
|
+
}
|
|
125
132
|
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
const parsed = IdentifyStateSchema.parse(JSON.parse(stored));
|
|
134
|
+
this.logger.debugInfo(`Parsed identity state from storage: ${parsed.type}`);
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
}
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
return parsed;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
this.logger.debugError("Error getting identify state from storage", { error });
|
|
148
|
+
return { type: "unidentified" };
|
|
149
|
+
}
|
|
139
150
|
}
|
|
140
151
|
|
|
141
152
|
private saveIdentifyStateToStorage(identifyState: IdentifyState): void {
|
|
@@ -144,11 +155,11 @@ export class IdentityClient {
|
|
|
144
155
|
|
|
145
156
|
private setIdentifyState(newState: IdentifyState): void {
|
|
146
157
|
if (this.identifyState.type === newState.type) {
|
|
147
|
-
this.logger.
|
|
158
|
+
this.logger.debugInfo(`Identify state already set: ${this.identifyState.type}`);
|
|
148
159
|
return;
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
this.logger.
|
|
162
|
+
this.logger.debugInfo(`Identify state: ${this.identifyState.type} -> ${newState.type}`);
|
|
152
163
|
this.identifyState = newState;
|
|
153
164
|
this.saveIdentifyStateToStorage(newState);
|
|
154
165
|
this.emitter.emit("IDENTIFY_STATE_CHANGED", newState);
|
|
@@ -213,7 +224,7 @@ export class IdentityClient {
|
|
|
213
224
|
}
|
|
214
225
|
|
|
215
226
|
async identify(user?: Persona): AsyncResult<IdentityUser> {
|
|
216
|
-
this.logger.
|
|
227
|
+
this.logger.debugInfo(`Identifying user with persona: ${user?.name ?? "none"}`);
|
|
217
228
|
const previousState = this.identifyState;
|
|
218
229
|
this.setIdentifyState({ type: "identifying" });
|
|
219
230
|
|
|
@@ -244,7 +255,7 @@ export class IdentityClient {
|
|
|
244
255
|
},
|
|
245
256
|
});
|
|
246
257
|
|
|
247
|
-
this.logger.
|
|
258
|
+
this.logger.debugInfo(`Identify API response received`);
|
|
248
259
|
if (response.error != null) {
|
|
249
260
|
this.logger.warn("Identify API error", response.error.status, response.error.value);
|
|
250
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
|
}
|