@retter/sdk 0.1.15 → 0.2.3

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 CHANGED
@@ -1,222 +1,42 @@
1
- import { LogLevelDesc } from 'loglevel';
2
- import { Observable } from 'rxjs';
3
- import { AxiosResponse } from 'axios';
4
- import { createResponse, ActionEvent, RESPONSE_TYPE, parseClassValidatorErrors, ValidationError } from './helpers';
5
- export { ActionEvent, createResponse, RESPONSE_TYPE, parseClassValidatorErrors, ValidationError };
6
- declare enum LogLevel {
7
- VERBOSE = 1,
8
- DEBUG = 2,
9
- ERROR = 3
10
- }
11
- interface LogMessage {
12
- level: LogLevel;
13
- message: string;
14
- }
15
- export interface ServiceResponse {
16
- errorCode: string;
17
- serviceId: string;
18
- status: number;
19
- errors: string[];
20
- response: any;
21
- durationInMilliseconds: number;
22
- executionDurationInMilliseconds: number;
23
- headers: {
24
- [key: string]: string;
25
- };
26
- }
27
- export interface RbsJwtPayload {
28
- serviceId?: string;
29
- projectId?: string;
30
- clientId?: string;
31
- userId?: string;
32
- anonymous?: boolean;
33
- identity?: string;
34
- iat?: number;
35
- exp?: number;
36
- }
37
- export interface RBSTokenData {
38
- accessToken: string;
39
- refreshToken: string;
40
- firebaseToken?: string;
41
- accessTokenExpiresAt: number;
42
- refreshTokenExpiresAt: number;
43
- isServiceToken: boolean;
44
- firebase?: FirebaseConfig;
45
- }
46
- declare type SuccessCallBack = (resp: any) => any;
47
- declare type ErrorCallBack = (e: any) => any;
48
- export interface RBSAction {
49
- action?: string;
50
- targetServiceId?: string;
51
- relatedUserId?: string;
52
- data?: any;
53
- culture?: string;
54
- headers?: {
55
- [key: string]: string;
56
- };
57
- pop?: boolean;
58
- token?: string;
59
- generateGetUrl?: boolean;
60
- onSuccess?: SuccessCallBack;
61
- onError?: ErrorCallBack;
62
- }
63
- interface FirebaseConfig {
64
- apiKey: string;
65
- projectId: string;
66
- customToken: string;
67
- }
68
- interface RBSActionWrapper {
69
- action?: RBSAction;
70
- tokenData?: RBSTokenData;
71
- response?: any;
72
- responseError?: Error;
73
- url?: string;
74
- }
75
- export interface RbsRegionConfiguration {
76
- regionId?: RbsRegion;
77
- getUrl: string;
78
- url: string;
79
- apiUrl: string;
80
- }
81
- export declare enum RbsRegion {
82
- euWest1 = 0,
83
- euWest1Beta = 1
84
- }
85
- interface RBSClientConfig {
86
- projectId: string;
87
- secretKey?: string;
88
- developerId?: string;
89
- serviceId?: string;
90
- region?: RbsRegion;
91
- regionConfiguration?: RbsRegionConfiguration;
92
- anonymTokenTTL?: number;
93
- logLevel?: LogLevelDesc;
94
- platform?: string;
95
- }
96
- export declare enum RBSAuthStatus {
97
- SIGNED_IN = "SIGNED_IN",
98
- SIGNED_IN_ANONYM = "SIGNED_IN_ANONYM",
99
- SIGNED_OUT = "SIGNED_OUT",
100
- AUTH_FAILED = "AUTH_FAILED"
101
- }
102
- export interface RBSAuthChangedEvent {
103
- authStatus: RBSAuthStatus;
104
- identity?: string;
105
- uid?: string;
106
- message?: string;
107
- }
108
- interface RBSCloudObjectStates {
109
- role: Observable<any> | null;
110
- user: Observable<any> | null;
111
- public: Observable<any> | null;
112
- }
113
- interface RBSCloudObjectMethod {
114
- tag?: string;
115
- name: string;
116
- sync?: boolean;
117
- readonly?: boolean;
118
- }
119
- export interface RBSCloudObjectState {
120
- role: {
121
- [key: string]: any;
122
- };
123
- user: {
124
- [key: string]: any;
125
- };
126
- public: {
127
- [key: string]: any;
128
- };
129
- private: {
130
- [key: string]: any;
131
- };
132
- }
133
- export declare type RBSCallResponse<T> = Omit<AxiosResponse<T>, 'config' | 'request'>;
134
- export interface RBSCloudObject<T> {
135
- instanceId: string;
136
- isNewInstance: boolean;
137
- methods: RBSCloudObjectMethod[];
138
- response?: any;
139
- call(params: RBSCloudObjectCallData): Promise<RBSCallResponse<T>>;
140
- getState(params?: RBSCloudObjectRequest): Promise<RBSCallResponse<RBSCloudObjectState>>;
141
- state?: RBSCloudObjectStates;
142
- }
143
- export interface RBSCloudObjectData {
144
- classId: string;
145
- key?: {
146
- name: string;
147
- value: string;
148
- };
149
- instanceId?: string;
150
- method?: string;
151
- headers?: {
152
- [key: string]: string;
153
- };
154
- queryStringParams?: {
155
- [key: string]: string;
156
- };
157
- httpMethod?: 'get' | 'delete' | 'post' | 'put';
158
- body?: {
159
- [key: string]: any;
160
- };
161
- useLocal?: boolean;
162
- token?: string;
163
- }
164
- export declare type RBSCloudObjectRequest = Omit<RBSCloudObjectData, 'classId' | 'useLocal'>;
165
- export interface RBSCloudObjectCallData extends RBSCloudObjectRequest {
166
- method: string;
167
- }
168
- export default class RBS {
1
+ import { Unsubscribe } from '@firebase/util';
2
+ import { Notification, Observable, ReplaySubject } from 'rxjs';
3
+ import { RetterAction, RetterActionWrapper, RetterAuthChangedEvent, RetterClientConfig, RetterCloudObject, RetterCloudObjectConfig } from './types';
4
+ export * from './types';
5
+ export default class Retter {
169
6
  private static instances;
170
- private firebaseApp;
171
- private firestore;
172
- private firebaseAuth;
173
- private cloudObjects;
174
- private commandQueue;
175
- private customAuthQueue;
176
- private clientConfig;
177
- private axiosInstance;
178
- private latestTokenData?;
179
7
  private initialized;
180
- isNode(): boolean;
8
+ private clientConfig?;
9
+ private auth?;
10
+ private http?;
11
+ private authQueue;
12
+ private actionQueue;
181
13
  private authStatusSubject;
182
- get authStatus(): Observable<RBSAuthChangedEvent>;
183
- private getServiceEndpoint;
184
- private getRegion;
185
- private getApiUrl;
186
- private getBaseUrl;
14
+ private firebase?;
15
+ private firestore?;
16
+ private firebaseAuth?;
17
+ private cloudObjects;
187
18
  private constructor();
188
- static clearTokens(): void;
189
- static getInstance(config?: RBSClientConfig | null): RBS;
190
- static dispose(): void;
191
- init(config: RBSClientConfig): void;
192
- getAuthChangedEvent: (tokenData: RBSTokenData | undefined) => RBSAuthChangedEvent;
193
- fireAuthStatus: (tokenData: RBSTokenData | undefined) => void;
194
- _getStoredTokenData: () => Promise<RBSTokenData | undefined>;
195
- logMessage: (logMessage: LogMessage) => void;
196
- getActionWithTokenData: (actionWrapper: RBSActionWrapper) => Promise<RBSActionWrapper>;
197
- getP: <T>(url: string, queryParams?: object | undefined) => Promise<T>;
198
- getPlatform: () => string;
199
- request: (url: string, actionWrapper: RBSActionWrapper) => Promise<RBSActionWrapper>;
200
- post: (url: string, actionWrapper: RBSActionWrapper) => Promise<RBSActionWrapper>;
201
- getParams: (actionWrapper: RBSActionWrapper) => any;
202
- get: (url: string, actionWrapper: RBSActionWrapper) => Promise<RBSActionWrapper>;
203
- getPlain: (url: string, params: any, actionWrapper: RBSActionWrapper) => Promise<RBSActionWrapper>;
204
- getSafeNow: () => number;
205
- getTokenDataKey: () => string;
206
- setTokenData: (tokenData: RBSTokenData) => Promise<void>;
207
- getStoredTokenData: () => Promise<RBSTokenData | undefined>;
208
- getUser: () => Promise<RbsJwtPayload | null>;
209
- generatePublicGetActionUrl: (action: RBSAction) => string;
210
- generateGetActionUrl: (action: RBSAction) => Promise<string>;
211
- send: (action: RBSAction) => Promise<ServiceResponse[] | any>;
212
- authenticateWithCustomToken: (token: string) => Promise<RBSAuthChangedEvent>;
213
- signInAnonymously: () => Promise<void>;
214
- signOut: () => Promise<boolean>;
215
- protected logoutUser: () => Promise<boolean>;
216
- protected initFirebase: () => Promise<void>;
217
- private getFirebaseListeners;
218
- private cleanFirebase;
219
- private isCosAction;
220
- private getCosEndpoint;
221
- getCloudObject: (data: RBSCloudObjectData) => Promise<RBSCloudObject<any>>;
19
+ static getInstance(config: RetterClientConfig): Retter;
20
+ protected init(config: RetterClientConfig): void;
21
+ protected processAuthQueue(): void;
22
+ protected processActionQueue(): void;
23
+ protected sendToAuthQueue<T>(action: RetterAction): Promise<T>;
24
+ protected sendToActionQueue<T>(action: RetterAction): Promise<T>;
25
+ protected getActionWithTokenData(action: RetterAction): Promise<RetterActionWrapper>;
26
+ protected fireAuthStatus(actionWrapper: RetterActionWrapper): void;
27
+ protected storeTokenData(actionWrapper: RetterActionWrapper): Promise<void>;
28
+ protected processAction(actionWrapper: RetterActionWrapper): Observable<Notification<RetterActionWrapper>>;
29
+ protected initFirebase(actionWrapper: RetterActionWrapper): Promise<RetterActionWrapper>;
30
+ protected clearFirebase(): void;
31
+ protected getCosEndpoint(ev: RetterActionWrapper): {
32
+ path: string;
33
+ params: any;
34
+ };
35
+ protected getFirebaseListener(queue: ReplaySubject<any>, collection: string, documentId: string): Unsubscribe;
36
+ protected clearCloudObjects(): Promise<void>;
37
+ signInAnonymously(): Promise<RetterAuthChangedEvent>;
38
+ authenticateWithCustomToken(token: string): Promise<RetterAuthChangedEvent>;
39
+ signOut(): Promise<void>;
40
+ getCloudObject(config: RetterCloudObjectConfig): Promise<RetterCloudObject>;
41
+ get authStatus(): Observable<RetterAuthChangedEvent>;
222
42
  }