@clicktap/state 0.11.5 → 0.12.1

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.
@@ -1,145 +1,163 @@
1
1
  import { ReactNode } from 'react';
2
- import { Actor, InspectionEvent, Observer, StateMachine } from 'xstate';
3
- import { AuthMachineContext, authMachine } from './auth';
2
+ import { Actor, InspectionEvent, Observer } from 'xstate';
3
+ import { authMachine } from './auth';
4
4
  export interface AuthContextType {
5
5
  authActor?: Actor<typeof authMachine>;
6
6
  isLoggedIn: boolean;
7
7
  }
8
- export declare const AuthContext: import("react").Context<Actor<StateMachine<AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
8
+ export declare const AuthContext: import("react").Context<Actor<import("xstate").StateMachine<import("./auth").AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
9
9
  [x: string]: import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
10
10
  type: string;
11
11
  accessToken: string;
12
12
  }, {
13
- context: AuthMachineContext;
13
+ context: import("./auth").AuthMachineContext;
14
14
  }>, {
15
15
  [k: string]: unknown;
16
16
  type: string;
17
- }> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
17
+ }, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
18
18
  type: string;
19
19
  accessToken: string;
20
20
  }, {
21
- context: AuthMachineContext;
21
+ context: import("./auth").AuthMachineContext;
22
22
  username: string;
23
23
  password: string;
24
24
  }>, {
25
25
  [k: string]: unknown;
26
26
  type: string;
27
- }> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
27
+ }, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
28
28
  type: string;
29
29
  }, {
30
- context: AuthMachineContext;
30
+ context: import("./auth").AuthMachineContext;
31
31
  }>, {
32
32
  [k: string]: unknown;
33
33
  type: string;
34
- }> | undefined;
35
- }, {
36
- src: "refreshAccessToken";
37
- logic: import("xstate").PromiseActorLogic<{
38
- type: string;
39
- accessToken: string;
40
- }, {
41
- context: AuthMachineContext;
42
- }>;
43
- id: string | undefined;
44
- } | {
45
- src: "authenticate";
46
- logic: import("xstate").PromiseActorLogic<{
47
- type: string;
48
- accessToken: string;
49
- }, {
50
- context: AuthMachineContext;
51
- username: string;
52
- password: string;
53
- }>;
54
- id: string | undefined;
55
- } | {
56
- src: "unauthenticate";
57
- logic: import("xstate").PromiseActorLogic<{
58
- type: string;
59
- }, {
60
- context: AuthMachineContext;
61
- }>;
62
- id: string | undefined;
63
- }, {
64
- type: "setUserContext";
65
- params: import("xstate").NonReducibleUnknown;
66
- } | {
67
- type: "unsetUserContext";
68
- params: import("xstate").NonReducibleUnknown;
69
- } | {
70
- type: "setAccessToken";
71
- params: import("xstate").NonReducibleUnknown;
72
- } | {
73
- type: "unsetRefreshToken";
74
- params: import("xstate").NonReducibleUnknown;
75
- } | {
76
- type: "setIgnoreRefreshToken";
77
- params: import("xstate").NonReducibleUnknown;
78
- } | {
79
- type: "addError";
80
- params: import("xstate").NonReducibleUnknown;
81
- } | {
82
- type: "clearErrors";
83
- params: import("xstate").NonReducibleUnknown;
84
- }, {
85
- type: string;
86
- params: import("xstate").NonReducibleUnknown;
87
- }, string, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
88
- initialContext: Partial<AuthMachineContext>;
34
+ }, import("xstate").EventObject> | undefined;
35
+ }, import("xstate").Values<{
36
+ refreshAccessToken: {
37
+ src: "refreshAccessToken";
38
+ logic: import("xstate").PromiseActorLogic<{
39
+ type: string;
40
+ accessToken: string;
41
+ }, {
42
+ context: import("./auth").AuthMachineContext;
43
+ }>;
44
+ id: string | undefined;
45
+ };
46
+ authenticate: {
47
+ src: "authenticate";
48
+ logic: import("xstate").PromiseActorLogic<{
49
+ type: string;
50
+ accessToken: string;
51
+ }, {
52
+ context: import("./auth").AuthMachineContext;
53
+ username: string;
54
+ password: string;
55
+ }>;
56
+ id: string | undefined;
57
+ };
58
+ unauthenticate: {
59
+ src: "unauthenticate";
60
+ logic: import("xstate").PromiseActorLogic<{
61
+ type: string;
62
+ }, {
63
+ context: import("./auth").AuthMachineContext;
64
+ }>;
65
+ id: string | undefined;
66
+ };
67
+ }>, import("xstate").Values<{
68
+ setUserContext: {
69
+ type: "setUserContext";
70
+ params: import("xstate").NonReducibleUnknown;
71
+ };
72
+ unsetUserContext: {
73
+ type: "unsetUserContext";
74
+ params: import("xstate").NonReducibleUnknown;
75
+ };
76
+ setAccessToken: {
77
+ type: "setAccessToken";
78
+ params: import("xstate").NonReducibleUnknown;
79
+ };
80
+ unsetRefreshToken: {
81
+ type: "unsetRefreshToken";
82
+ params: import("xstate").NonReducibleUnknown;
83
+ };
84
+ setIgnoreRefreshToken: {
85
+ type: "setIgnoreRefreshToken";
86
+ params: import("xstate").NonReducibleUnknown;
87
+ };
88
+ addError: {
89
+ type: "addError";
90
+ params: import("xstate").NonReducibleUnknown;
91
+ };
92
+ clearErrors: {
93
+ type: "clearErrors";
94
+ params: import("xstate").NonReducibleUnknown;
95
+ };
96
+ }>, never, never, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
97
+ initialContext: Partial<import("./auth").AuthMachineContext>;
89
98
  initialState?: string | undefined;
90
- }, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
91
- src: "refreshAccessToken";
92
- logic: import("xstate").PromiseActorLogic<{
93
- type: string;
94
- accessToken: string;
95
- }, {
96
- context: AuthMachineContext;
97
- }>;
98
- id: string | undefined;
99
- } | {
100
- src: "authenticate";
101
- logic: import("xstate").PromiseActorLogic<{
102
- type: string;
103
- accessToken: string;
104
- }, {
105
- context: AuthMachineContext;
106
- username: string;
107
- password: string;
108
- }>;
109
- id: string | undefined;
110
- } | {
111
- src: "unauthenticate";
112
- logic: import("xstate").PromiseActorLogic<{
113
- type: string;
114
- }, {
115
- context: AuthMachineContext;
116
- }>;
117
- id: string | undefined;
118
- }, {
119
- type: "setUserContext";
120
- params: import("xstate").NonReducibleUnknown;
121
- } | {
122
- type: "unsetUserContext";
123
- params: import("xstate").NonReducibleUnknown;
124
- } | {
125
- type: "setAccessToken";
126
- params: import("xstate").NonReducibleUnknown;
127
- } | {
128
- type: "unsetRefreshToken";
129
- params: import("xstate").NonReducibleUnknown;
130
- } | {
131
- type: "setIgnoreRefreshToken";
132
- params: import("xstate").NonReducibleUnknown;
133
- } | {
134
- type: "addError";
135
- params: import("xstate").NonReducibleUnknown;
136
- } | {
137
- type: "clearErrors";
138
- params: import("xstate").NonReducibleUnknown;
139
- }, {
140
- type: string;
141
- params: import("xstate").NonReducibleUnknown;
142
- }, string, string>>> | undefined>;
99
+ }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
100
+ refreshAccessToken: {
101
+ src: "refreshAccessToken";
102
+ logic: import("xstate").PromiseActorLogic<{
103
+ type: string;
104
+ accessToken: string;
105
+ }, {
106
+ context: import("./auth").AuthMachineContext;
107
+ }>;
108
+ id: string | undefined;
109
+ };
110
+ authenticate: {
111
+ src: "authenticate";
112
+ logic: import("xstate").PromiseActorLogic<{
113
+ type: string;
114
+ accessToken: string;
115
+ }, {
116
+ context: import("./auth").AuthMachineContext;
117
+ username: string;
118
+ password: string;
119
+ }>;
120
+ id: string | undefined;
121
+ };
122
+ unauthenticate: {
123
+ src: "unauthenticate";
124
+ logic: import("xstate").PromiseActorLogic<{
125
+ type: string;
126
+ }, {
127
+ context: import("./auth").AuthMachineContext;
128
+ }>;
129
+ id: string | undefined;
130
+ };
131
+ }>, import("xstate").Values<{
132
+ setUserContext: {
133
+ type: "setUserContext";
134
+ params: import("xstate").NonReducibleUnknown;
135
+ };
136
+ unsetUserContext: {
137
+ type: "unsetUserContext";
138
+ params: import("xstate").NonReducibleUnknown;
139
+ };
140
+ setAccessToken: {
141
+ type: "setAccessToken";
142
+ params: import("xstate").NonReducibleUnknown;
143
+ };
144
+ unsetRefreshToken: {
145
+ type: "unsetRefreshToken";
146
+ params: import("xstate").NonReducibleUnknown;
147
+ };
148
+ setIgnoreRefreshToken: {
149
+ type: "setIgnoreRefreshToken";
150
+ params: import("xstate").NonReducibleUnknown;
151
+ };
152
+ addError: {
153
+ type: "addError";
154
+ params: import("xstate").NonReducibleUnknown;
155
+ };
156
+ clearErrors: {
157
+ type: "clearErrors";
158
+ params: import("xstate").NonReducibleUnknown;
159
+ };
160
+ }>, never, never, string, import("xstate").EventObject>>> | undefined>;
143
161
  export declare const useAuth: () => AuthContextType;
144
162
  type AuthOptions = {
145
163
  inspect: Observer<InspectionEvent> | undefined;
@@ -156,141 +174,159 @@ type AuthOptions = {
156
174
  * @todo should probably update signature to pass Partial<AuthContext> and
157
175
  * Options, endpoints should probably be moved into context
158
176
  */
159
- export declare const getAuth: (refreshToken?: string, options?: AuthOptions) => Promise<Actor<StateMachine<AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
177
+ export declare const getAuth: (refreshToken?: string, options?: AuthOptions) => Promise<Actor<import("xstate").StateMachine<import("./auth").AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
160
178
  [x: string]: import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
161
179
  type: string;
162
180
  accessToken: string;
163
181
  }, {
164
- context: AuthMachineContext;
182
+ context: import("./auth").AuthMachineContext;
165
183
  }>, {
166
184
  [k: string]: unknown;
167
185
  type: string;
168
- }> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
186
+ }, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
169
187
  type: string;
170
188
  accessToken: string;
171
189
  }, {
172
- context: AuthMachineContext;
190
+ context: import("./auth").AuthMachineContext;
173
191
  username: string;
174
192
  password: string;
175
193
  }>, {
176
194
  [k: string]: unknown;
177
195
  type: string;
178
- }> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
196
+ }, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
179
197
  type: string;
180
198
  }, {
181
- context: AuthMachineContext;
199
+ context: import("./auth").AuthMachineContext;
182
200
  }>, {
183
201
  [k: string]: unknown;
184
202
  type: string;
185
- }> | undefined;
186
- }, {
187
- src: "refreshAccessToken";
188
- logic: import("xstate").PromiseActorLogic<{
189
- type: string;
190
- accessToken: string;
191
- }, {
192
- context: AuthMachineContext;
193
- }>;
194
- id: string | undefined;
195
- } | {
196
- src: "authenticate";
197
- logic: import("xstate").PromiseActorLogic<{
198
- type: string;
199
- accessToken: string;
200
- }, {
201
- context: AuthMachineContext;
202
- username: string;
203
- password: string;
204
- }>;
205
- id: string | undefined;
206
- } | {
207
- src: "unauthenticate";
208
- logic: import("xstate").PromiseActorLogic<{
209
- type: string;
210
- }, {
211
- context: AuthMachineContext;
212
- }>;
213
- id: string | undefined;
214
- }, {
215
- type: "setUserContext";
216
- params: import("xstate").NonReducibleUnknown;
217
- } | {
218
- type: "unsetUserContext";
219
- params: import("xstate").NonReducibleUnknown;
220
- } | {
221
- type: "setAccessToken";
222
- params: import("xstate").NonReducibleUnknown;
223
- } | {
224
- type: "unsetRefreshToken";
225
- params: import("xstate").NonReducibleUnknown;
226
- } | {
227
- type: "setIgnoreRefreshToken";
228
- params: import("xstate").NonReducibleUnknown;
229
- } | {
230
- type: "addError";
231
- params: import("xstate").NonReducibleUnknown;
232
- } | {
233
- type: "clearErrors";
234
- params: import("xstate").NonReducibleUnknown;
235
- }, {
236
- type: string;
237
- params: import("xstate").NonReducibleUnknown;
238
- }, string, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
239
- initialContext: Partial<AuthMachineContext>;
203
+ }, import("xstate").EventObject> | undefined;
204
+ }, import("xstate").Values<{
205
+ refreshAccessToken: {
206
+ src: "refreshAccessToken";
207
+ logic: import("xstate").PromiseActorLogic<{
208
+ type: string;
209
+ accessToken: string;
210
+ }, {
211
+ context: import("./auth").AuthMachineContext;
212
+ }>;
213
+ id: string | undefined;
214
+ };
215
+ authenticate: {
216
+ src: "authenticate";
217
+ logic: import("xstate").PromiseActorLogic<{
218
+ type: string;
219
+ accessToken: string;
220
+ }, {
221
+ context: import("./auth").AuthMachineContext;
222
+ username: string;
223
+ password: string;
224
+ }>;
225
+ id: string | undefined;
226
+ };
227
+ unauthenticate: {
228
+ src: "unauthenticate";
229
+ logic: import("xstate").PromiseActorLogic<{
230
+ type: string;
231
+ }, {
232
+ context: import("./auth").AuthMachineContext;
233
+ }>;
234
+ id: string | undefined;
235
+ };
236
+ }>, import("xstate").Values<{
237
+ setUserContext: {
238
+ type: "setUserContext";
239
+ params: import("xstate").NonReducibleUnknown;
240
+ };
241
+ unsetUserContext: {
242
+ type: "unsetUserContext";
243
+ params: import("xstate").NonReducibleUnknown;
244
+ };
245
+ setAccessToken: {
246
+ type: "setAccessToken";
247
+ params: import("xstate").NonReducibleUnknown;
248
+ };
249
+ unsetRefreshToken: {
250
+ type: "unsetRefreshToken";
251
+ params: import("xstate").NonReducibleUnknown;
252
+ };
253
+ setIgnoreRefreshToken: {
254
+ type: "setIgnoreRefreshToken";
255
+ params: import("xstate").NonReducibleUnknown;
256
+ };
257
+ addError: {
258
+ type: "addError";
259
+ params: import("xstate").NonReducibleUnknown;
260
+ };
261
+ clearErrors: {
262
+ type: "clearErrors";
263
+ params: import("xstate").NonReducibleUnknown;
264
+ };
265
+ }>, never, never, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
266
+ initialContext: Partial<import("./auth").AuthMachineContext>;
240
267
  initialState?: string | undefined;
241
- }, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
242
- src: "refreshAccessToken";
243
- logic: import("xstate").PromiseActorLogic<{
244
- type: string;
245
- accessToken: string;
246
- }, {
247
- context: AuthMachineContext;
248
- }>;
249
- id: string | undefined;
250
- } | {
251
- src: "authenticate";
252
- logic: import("xstate").PromiseActorLogic<{
253
- type: string;
254
- accessToken: string;
255
- }, {
256
- context: AuthMachineContext;
257
- username: string;
258
- password: string;
259
- }>;
260
- id: string | undefined;
261
- } | {
262
- src: "unauthenticate";
263
- logic: import("xstate").PromiseActorLogic<{
264
- type: string;
265
- }, {
266
- context: AuthMachineContext;
267
- }>;
268
- id: string | undefined;
269
- }, {
270
- type: "setUserContext";
271
- params: import("xstate").NonReducibleUnknown;
272
- } | {
273
- type: "unsetUserContext";
274
- params: import("xstate").NonReducibleUnknown;
275
- } | {
276
- type: "setAccessToken";
277
- params: import("xstate").NonReducibleUnknown;
278
- } | {
279
- type: "unsetRefreshToken";
280
- params: import("xstate").NonReducibleUnknown;
281
- } | {
282
- type: "setIgnoreRefreshToken";
283
- params: import("xstate").NonReducibleUnknown;
284
- } | {
285
- type: "addError";
286
- params: import("xstate").NonReducibleUnknown;
287
- } | {
288
- type: "clearErrors";
289
- params: import("xstate").NonReducibleUnknown;
290
- }, {
291
- type: string;
292
- params: import("xstate").NonReducibleUnknown;
293
- }, string, string>>>>;
268
+ }, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
269
+ refreshAccessToken: {
270
+ src: "refreshAccessToken";
271
+ logic: import("xstate").PromiseActorLogic<{
272
+ type: string;
273
+ accessToken: string;
274
+ }, {
275
+ context: import("./auth").AuthMachineContext;
276
+ }>;
277
+ id: string | undefined;
278
+ };
279
+ authenticate: {
280
+ src: "authenticate";
281
+ logic: import("xstate").PromiseActorLogic<{
282
+ type: string;
283
+ accessToken: string;
284
+ }, {
285
+ context: import("./auth").AuthMachineContext;
286
+ username: string;
287
+ password: string;
288
+ }>;
289
+ id: string | undefined;
290
+ };
291
+ unauthenticate: {
292
+ src: "unauthenticate";
293
+ logic: import("xstate").PromiseActorLogic<{
294
+ type: string;
295
+ }, {
296
+ context: import("./auth").AuthMachineContext;
297
+ }>;
298
+ id: string | undefined;
299
+ };
300
+ }>, import("xstate").Values<{
301
+ setUserContext: {
302
+ type: "setUserContext";
303
+ params: import("xstate").NonReducibleUnknown;
304
+ };
305
+ unsetUserContext: {
306
+ type: "unsetUserContext";
307
+ params: import("xstate").NonReducibleUnknown;
308
+ };
309
+ setAccessToken: {
310
+ type: "setAccessToken";
311
+ params: import("xstate").NonReducibleUnknown;
312
+ };
313
+ unsetRefreshToken: {
314
+ type: "unsetRefreshToken";
315
+ params: import("xstate").NonReducibleUnknown;
316
+ };
317
+ setIgnoreRefreshToken: {
318
+ type: "setIgnoreRefreshToken";
319
+ params: import("xstate").NonReducibleUnknown;
320
+ };
321
+ addError: {
322
+ type: "addError";
323
+ params: import("xstate").NonReducibleUnknown;
324
+ };
325
+ clearErrors: {
326
+ type: "clearErrors";
327
+ params: import("xstate").NonReducibleUnknown;
328
+ };
329
+ }>, never, never, string, import("xstate").EventObject>>>>;
294
330
  type Props = {
295
331
  children: ReactNode;
296
332
  actor: Actor<typeof authMachine>;