entropic-bond 1.50.0 → 1.50.2

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.
Files changed (111) hide show
  1. package/lib/auth/auth-mock.d.ts +22 -0
  2. package/lib/auth/auth-mock.spec.d.ts +1 -0
  3. package/lib/auth/auth.d.ts +131 -0
  4. package/lib/auth/user-auth-types.d.ts +19 -0
  5. package/lib/cloud-functions/cloud-functions-mock.d.ts +11 -0
  6. package/lib/cloud-functions/cloud-functions-mock.spec.d.ts +1 -0
  7. package/lib/cloud-functions/cloud-functions.d.ts +19 -0
  8. package/lib/cloud-storage/cloud-storage.d.ts +24 -0
  9. package/lib/cloud-storage/cloud-storage.spec.d.ts +1 -0
  10. package/lib/cloud-storage/mock-cloud-storage.d.ts +20 -0
  11. package/lib/cloud-storage/stored-file.d.ts +39 -0
  12. package/lib/entropic-bond.js +1667 -0
  13. package/lib/entropic-bond.umd.cjs +7 -0
  14. package/lib/index.d.ts +19 -0
  15. package/lib/observable/observable.d.ts +52 -0
  16. package/lib/observable/observable.spec.d.ts +1 -0
  17. package/lib/persistent/entropic-component.d.ts +76 -0
  18. package/lib/persistent/entropic-component.spec.d.ts +1 -0
  19. package/lib/persistent/persistent.d.ts +281 -0
  20. package/lib/persistent/persistent.spec.d.ts +67 -0
  21. package/lib/server-auth/server-auth-mock.d.ts +12 -0
  22. package/lib/server-auth/server-auth-mock.spec.d.ts +1 -0
  23. package/lib/server-auth/server-auth.d.ts +24 -0
  24. package/lib/store/data-source.d.ts +137 -0
  25. package/lib/store/json-data-source.d.ts +68 -0
  26. package/lib/store/json-data-source.spec.d.ts +1 -0
  27. package/lib/store/mocks/test-user.d.ts +49 -0
  28. package/lib/store/model.d.ts +238 -0
  29. package/lib/store/model.spec.d.ts +1 -0
  30. package/lib/store/store.d.ts +62 -0
  31. package/lib/store/store.spec.d.ts +1 -0
  32. package/lib/types/utility-types.d.ts +45 -0
  33. package/lib/types/utility-types.spec.d.ts +1 -0
  34. package/lib/utils/test-utils/test-person.d.ts +33 -0
  35. package/{src/utils/utils.ts → lib/utils/utils.d.ts} +10 -34
  36. package/lib/utils/utils.spec.d.ts +1 -0
  37. package/package.json +7 -4
  38. package/.github/workflows/release.yml +0 -26
  39. package/CHANGELOG.md +0 -1151
  40. package/docs/.nojekyll +0 -1
  41. package/docs/README.md +0 -94
  42. package/docs/classes/Auth.md +0 -391
  43. package/docs/classes/AuthMock.md +0 -278
  44. package/docs/classes/AuthService.md +0 -188
  45. package/docs/classes/CloudFunctions.md +0 -123
  46. package/docs/classes/CloudFunctionsMock.md +0 -97
  47. package/docs/classes/CloudStorage.md +0 -215
  48. package/docs/classes/DataSource.md +0 -248
  49. package/docs/classes/EntropicComponent.md +0 -666
  50. package/docs/classes/JsonDataSource.md +0 -328
  51. package/docs/classes/MockCloudStorage.md +0 -279
  52. package/docs/classes/Model.md +0 -274
  53. package/docs/classes/Observable.md +0 -120
  54. package/docs/classes/Persistent.md +0 -420
  55. package/docs/classes/ServerAuth.md +0 -211
  56. package/docs/classes/ServerAuthMock.md +0 -176
  57. package/docs/classes/ServerAuthService.md +0 -130
  58. package/docs/classes/Store.md +0 -218
  59. package/docs/classes/StoredFile.md +0 -636
  60. package/docs/enums/StoredFileEvent.md +0 -41
  61. package/docs/interfaces/AuthError.md +0 -30
  62. package/docs/interfaces/CloudFunctionsService.md +0 -69
  63. package/docs/interfaces/Collection.md +0 -13
  64. package/docs/interfaces/CustomCredentials.md +0 -7
  65. package/docs/interfaces/DocumentReference.md +0 -49
  66. package/docs/interfaces/JsonRawData.md +0 -7
  67. package/docs/interfaces/SignData.md +0 -63
  68. package/docs/interfaces/StoreParams.md +0 -52
  69. package/docs/interfaces/StoredFileChange.md +0 -41
  70. package/docs/interfaces/UploadControl.md +0 -90
  71. package/docs/interfaces/UserCredentials.md +0 -113
  72. package/docs/interfaces/Values.md +0 -17
  73. package/docs/modules.md +0 -1273
  74. package/src/auth/auth-mock.spec.ts +0 -168
  75. package/src/auth/auth-mock.ts +0 -129
  76. package/src/auth/auth.ts +0 -185
  77. package/src/auth/user-auth-types.ts +0 -21
  78. package/src/cloud-functions/cloud-functions-mock.spec.ts +0 -136
  79. package/src/cloud-functions/cloud-functions-mock.ts +0 -23
  80. package/src/cloud-functions/cloud-functions.ts +0 -83
  81. package/src/cloud-storage/cloud-storage.spec.ts +0 -207
  82. package/src/cloud-storage/cloud-storage.ts +0 -60
  83. package/src/cloud-storage/mock-cloud-storage.ts +0 -72
  84. package/src/cloud-storage/stored-file.ts +0 -102
  85. package/src/index.ts +0 -19
  86. package/src/observable/observable.spec.ts +0 -105
  87. package/src/observable/observable.ts +0 -67
  88. package/src/persistent/entropic-component.spec.ts +0 -143
  89. package/src/persistent/entropic-component.ts +0 -135
  90. package/src/persistent/persistent.spec.ts +0 -828
  91. package/src/persistent/persistent.ts +0 -650
  92. package/src/server-auth/server-auth-mock.spec.ts +0 -53
  93. package/src/server-auth/server-auth-mock.ts +0 -45
  94. package/src/server-auth/server-auth.ts +0 -49
  95. package/src/store/data-source.ts +0 -186
  96. package/src/store/json-data-source.spec.ts +0 -100
  97. package/src/store/json-data-source.ts +0 -256
  98. package/src/store/mocks/mock-data.json +0 -155
  99. package/src/store/mocks/test-user.ts +0 -122
  100. package/src/store/model.spec.ts +0 -659
  101. package/src/store/model.ts +0 -462
  102. package/src/store/store.spec.ts +0 -30
  103. package/src/store/store.ts +0 -113
  104. package/src/types/utility-types.spec.ts +0 -117
  105. package/src/types/utility-types.ts +0 -116
  106. package/src/utils/test-utils/test-person.ts +0 -44
  107. package/src/utils/utils.spec.ts +0 -95
  108. package/tsconfig-build.json +0 -7
  109. package/tsconfig-cjs.json +0 -9
  110. package/tsconfig.json +0 -33
  111. package/vite.config.ts +0 -22
@@ -1,168 +0,0 @@
1
- import { Auth } from './auth'
2
- import { AuthMock } from './auth-mock'
3
- import { UserCredentials } from './user-auth-types'
4
-
5
- interface CustomCredentials {
6
- role: string
7
- customer: string
8
- }
9
-
10
- describe( 'Auth Mock', ()=>{
11
- let authChangeSpy = vi.fn()
12
- let mockAuthService: AuthMock
13
- const fakeUseCredentials = {
14
- email: 'fakeUser@test.com',
15
- emailVerified: true,
16
- creationDate: new Date( '2017-01-01' ).getDate(),
17
- lastLogin: new Date( '2017-01-03' ).getDate(),
18
- customData: {
19
- role: 'testRole',
20
- customer: 'testCustomer'
21
- },
22
- id: 'fakeUser',
23
- } as UserCredentials<CustomCredentials>
24
-
25
- beforeEach(()=>{
26
- Auth.useAuthService( mockAuthService = new AuthMock() )
27
- Auth.instance.onAuthStateChange( authChangeSpy )
28
-
29
- mockAuthService.fakeRegisteredUser( fakeUseCredentials )
30
-
31
- })
32
-
33
- it( 'should throw if AuthService not set', ()=>{
34
- Auth.useAuthService( undefined! )
35
- expect(
36
- ()=>Auth.instance
37
- ).toThrow( Auth.error.shouldBeRegistered )
38
- })
39
-
40
-
41
- it( 'should emulate sign-up', async ()=>{
42
- const userCredentials = await Auth.instance.signUp({
43
- authProvider: 'google',
44
- email: 'test@test.com',
45
- password: 'password'
46
- })
47
-
48
- expect( userCredentials.email ).toEqual( 'test@test.com' )
49
- expect( authChangeSpy ).toHaveBeenCalledWith( userCredentials )
50
- })
51
-
52
- it( 'should emulate failed sign-up', async ()=>{
53
- try {
54
- var userCredentials = await Auth.instance.signUp({
55
- authProvider: 'email',
56
- email: 'test@test.com',
57
- password: 'fail'
58
- })
59
- }
60
- catch {}
61
-
62
- expect( userCredentials! ).toBeUndefined()
63
- expect( authChangeSpy ).toHaveBeenCalledWith( undefined )
64
- })
65
-
66
- it( 'should login with fake registered user', async ()=>{
67
- const userCredentials = await Auth.instance.login({
68
- email: 'fakeUser@test.com',
69
- password: 'password',
70
- authProvider: 'google'
71
- })
72
-
73
- const modUserCredentials = {
74
- ...fakeUseCredentials,
75
- id: fakeUseCredentials.id
76
- }
77
-
78
- expect( userCredentials ).toEqual( modUserCredentials )
79
- expect( authChangeSpy ).toHaveBeenCalledWith( modUserCredentials )
80
- })
81
-
82
- it( 'should fail login with email auth provider if does not match fake user credentials', async ()=>{
83
- try {
84
- var userCredentials = await Auth.instance.login({
85
- email: 'test@test.com',
86
- password: 'password',
87
- authProvider: 'email'
88
- })
89
- } catch {}
90
-
91
- expect( userCredentials! ).toEqual( undefined )
92
- expect( authChangeSpy ).toHaveBeenCalledWith( undefined )
93
- })
94
-
95
- it( 'should NOT fail login with non email auth provider even if does not match fake user credentials', async ()=>{
96
- const userCredentials = await Auth.instance.login({
97
- email: 'test@test.com',
98
- password: 'password',
99
- authProvider: 'google'
100
- })
101
-
102
- expect( userCredentials.email ).toEqual( 'test@test.com' )
103
- expect( authChangeSpy ).toHaveBeenCalledWith( undefined )
104
- })
105
-
106
- it( 'should logout', async ()=>{
107
- await Auth.instance.logout()
108
-
109
- expect( authChangeSpy ).toHaveBeenCalledWith( undefined )
110
- })
111
-
112
- it( 'should throw if email does not exists in resetEmailPassword', async ()=>{
113
- return expect(
114
- Auth.instance.resetEmailPassword( 'non-existing-email@test.com' )
115
- ).rejects.toEqual( expect.objectContaining({ code: 'userNotFound' }) )
116
- })
117
-
118
- it( 'should retrieve custom credentials', async ()=>{
119
- const userCredentials = await Auth.instance.login<CustomCredentials>({
120
- email: 'fakeUser@test.com',
121
- password: 'password',
122
- authProvider: 'google'
123
- })
124
-
125
- expect( userCredentials.customData?.role ).toEqual( 'testRole' )
126
- })
127
-
128
- it( 'should throw if login and not email in email auth provider', ()=>{
129
- return expect(
130
- Auth.instance.login({
131
- authProvider: 'email',
132
- email: '',
133
- password: '****'
134
- })
135
- ).rejects.toEqual( expect.objectContaining({ code: 'missingEmail' }))
136
- })
137
-
138
- it( 'should throw if login and not password in email auth provider', ()=>{
139
- return expect(
140
- Auth.instance.login({
141
- authProvider: 'email',
142
- email: 'test@test.com',
143
- password: ''
144
- })
145
- ).rejects.toEqual( expect.objectContaining({ code: 'missingPassword' }))
146
- })
147
-
148
- it( 'should throw if signup and not email in email auth provider', ()=>{
149
- return expect(
150
- Auth.instance.signUp({
151
- authProvider: 'email',
152
- email: '',
153
- password: '****'
154
- })
155
- ).rejects.toEqual( expect.objectContaining({ code: 'missingEmail' }))
156
- })
157
-
158
- it( 'should throw if signup and not password in email auth provider', ()=>{
159
- return expect(
160
- Auth.instance.signUp({
161
- authProvider: 'email',
162
- email: 'test@test.com',
163
- password: ''
164
- })
165
- ).rejects.toEqual( expect.objectContaining({ code: 'missingPassword' }))
166
- })
167
-
168
- })
@@ -1,129 +0,0 @@
1
- import { Collection } from '../types/utility-types'
2
- import { AuthService, RejectedCallback, ResovedCallback } from "./auth"
3
- import { UserCredentials, SignData, AuthProvider } from "./user-auth-types"
4
-
5
- export class AuthMock extends AuthService {
6
-
7
- signUp<T extends {}>( signData: SignData ): Promise<UserCredentials<T>> {
8
- const { verificationLink, email, password, authProvider } = signData
9
-
10
- const promise = new Promise<UserCredentials<T>>( async ( resolve: ResovedCallback<T>, reject: RejectedCallback ) => {
11
- if ( authProvider === 'email' ) {
12
- if ( !email ) reject({ code: 'missingEmail', message: 'missingEmail' })
13
- if ( !password ) reject({ code: 'missingPassword', message: 'missingPassword' })
14
- }
15
- if ( password !== 'fail' && email !== 'fail' ) {
16
- this._loggedUser = this.userCredentials<T>( signData )
17
- this._fakeRegisteredUsers[ this._loggedUser.id ] = this._loggedUser
18
- resolve( this._loggedUser as UserCredentials<T> )
19
- this.notifyChange?.( this._loggedUser )
20
- }
21
- else {
22
- reject({ code: 'userNotFound', message: verificationLink || 'Test auth error' })
23
- this.notifyChange?.( undefined )
24
- }
25
- })
26
- this.pendingPromises.push( promise )
27
- return promise
28
- }
29
-
30
- login<T extends {}>( signData: SignData ): Promise<UserCredentials<T>> {
31
- const fakeUser = Object.values( this._fakeRegisteredUsers ).find(
32
- user => user.email === signData.email
33
- )
34
-
35
- if ( signData.authProvider === 'email' && !fakeUser && signData.email) {
36
- signData.email = 'fail'
37
- }
38
-
39
- return this.signUp( signData )
40
- }
41
-
42
- onAuthStateChange<T extends {}>( onChange: ( userCredentials: UserCredentials<T> )=>void ) {
43
- this.notifyChange = onChange
44
- this.notifyChange( this._loggedUser )
45
- }
46
-
47
- async logout(): Promise<void> {
48
- const promise = new Promise<void>( resolve => {
49
- this._loggedUser = undefined
50
- resolve()
51
- this.notifyChange?.( undefined )
52
- })
53
- this.pendingPromises.push( promise )
54
- return promise
55
- }
56
-
57
- resetEmailPassword( email: string ) {
58
- const fakeUserExists = Object.values( this._fakeRegisteredUsers ).find(
59
- user => user.email === email
60
- )
61
-
62
- if ( fakeUserExists ) return Promise.resolve()
63
- else return Promise.reject({ code: 'userNotFound', message: 'Test auth error' })
64
- }
65
-
66
- resendVerificationEmail( email: string, _password: string, _verificationLink: string ) {
67
- const fakeUserExists = Object.values( this._fakeRegisteredUsers ).find(
68
- user => user.email === email
69
- )
70
-
71
- if ( fakeUserExists ) return Promise.resolve()
72
- else return Promise.reject({ code: 'userNotFound', message: 'Test auth error' })
73
- }
74
-
75
- override refreshToken(): Promise<void> {
76
- return Promise.resolve()
77
- }
78
-
79
- linkAdditionalProvider( provider: AuthProvider ): Promise<unknown> {
80
- throw new Error('Not implemented.')
81
- }
82
-
83
- unlinkProvider( provider: AuthProvider ): Promise<unknown> {
84
- throw new Error('Not implemented.')
85
- }
86
-
87
- async flush() {
88
- await Promise.all(this.pendingPromises)
89
- this.pendingPromises = []
90
- }
91
-
92
- fakeRegisteredUser<T extends {}>( userCredentials: UserCredentials<T> ) {
93
- if ( this._fakeRegisteredUsers[ userCredentials.id ] ) throw new Error( `User with id ${ userCredentials.id } already exists in fake user list`)
94
- this._fakeRegisteredUsers[ userCredentials.id ] = userCredentials
95
- return this
96
- }
97
-
98
- get fakeRegisteredUsers() {
99
- return this._fakeRegisteredUsers
100
- }
101
-
102
- private userCredentials<T extends {}>( signData: SignData ): UserCredentials<T> {
103
- const fakeUser = Object.values( this._fakeRegisteredUsers ).find(
104
- user => user.email === signData.email
105
- )
106
-
107
- if ( fakeUser ) {
108
- return { ...fakeUser as UserCredentials<T> }
109
- }
110
- else {
111
- return ({
112
- id: signData.authProvider || `testUID${ signData.email? '-' + signData.email : '' }`,
113
- email: signData.email || 'testEmail',
114
- name: signData.authProvider || `testName${ signData.email? ' ' + signData.email : '' }` ,
115
- phoneNumber: 'testPhone',
116
- customData: {
117
- role: 'test'
118
- } as unknown as T,
119
- lastLogin: 0,
120
- creationDate: 0
121
- } as UserCredentials<T>)
122
- }
123
- }
124
-
125
- private pendingPromises: Promise<any>[] = []
126
- private _loggedUser: UserCredentials<{}> | undefined
127
- private notifyChange: (( userCredentials: UserCredentials<{}> | undefined ) => void ) | undefined
128
- private _fakeRegisteredUsers: Collection<UserCredentials<{}>> = {}
129
- }
package/src/auth/auth.ts DELETED
@@ -1,185 +0,0 @@
1
- import { Observable } from '../observable/observable'
2
- import { AuthProvider, SignData, UserCredentials } from "./user-auth-types"
3
-
4
- /**
5
- * The AuthService class is an abstract class that defines the interface of an authentication service.
6
- * You should derive from this class to implement your own authentication service.
7
- */
8
- export abstract class AuthService {
9
- abstract signUp<T extends {}>( signData: SignData ): Promise<UserCredentials<T>>
10
- abstract login<T extends {}>( signData: SignData ): Promise<UserCredentials<T>>
11
- abstract logout(): Promise<void>
12
- abstract resetEmailPassword( email: string ): Promise<void>
13
- abstract refreshToken(): Promise<void>
14
- abstract linkAdditionalProvider( provider: AuthProvider ): Promise<unknown>
15
- abstract unlinkProvider( provider: AuthProvider ): Promise<unknown>
16
- abstract onAuthStateChange<T extends {}>( onChange: (userCredentials: UserCredentials<T> | undefined) => void ): void
17
- abstract resendVerificationEmail( email: string, password: string, verificationLink: string ): Promise<void>
18
- }
19
-
20
- export type AuthErrorCode = 'wrongPassword' | 'popupClosedByUser' | 'userNotFound' | 'invalidEmail' | 'missingPassword' | 'missingEmail'
21
-
22
- export interface AuthError {
23
- code: AuthErrorCode
24
- message: string
25
- }
26
-
27
- /**
28
- * Types the callback to accept a user credentials object
29
- */
30
- export type ResovedCallback<T extends {}> = ( credentials: UserCredentials<T> ) => void
31
- export type RejectedCallback = ( reason: AuthError ) => void
32
-
33
- /**
34
- * The Auth class is a singleton that provides a unified interface to the authentication service.
35
- * You should register an authentication service by using `Auth.useAuthService`
36
- * method before using the Auth class.
37
- */
38
- export class Auth extends AuthService {
39
- static error = { shouldBeRegistered: 'You should register an auth service before using Auth.' }
40
-
41
- protected constructor() {
42
- super()
43
- if (!Auth._authService ) throw ( new Error( Auth.error.shouldBeRegistered ) )
44
- Auth._authService.onAuthStateChange(
45
- userCredentials => this.authStateChanged( userCredentials )
46
- )
47
- }
48
-
49
- /**
50
- * Registers an authentication service to be used by the Auth class.
51
- * You need to register an authentication service before using the Auth class.
52
- * @param authService the authentication service to be used by the Auth class
53
- */
54
- static useAuthService( authService: AuthService ) {
55
- if ( Auth._authService != authService ) {
56
- Auth._authService = authService
57
- this._instance = undefined
58
- }
59
- }
60
-
61
- /**
62
- * The instance of the Auth class
63
- * @returns the authentication service
64
- */
65
- static get instance() {
66
- return this._instance || (this._instance = new this() )
67
- }
68
-
69
- /**
70
- * Signs up a new user
71
- * @param singData the data to be used to sign up the user
72
- * @returns a promise that resolves to the user credentials
73
- * @example
74
- * // Sign up a new user with email and password
75
- * Auth.instance.signUp({ authProvider: 'email', email: 'john@test.com', password: '123456' })
76
- * // Sign up a new user with a Google account
77
- * Auth.instance.signUp({ authProvider: 'google'})
78
- */
79
- signUp<T extends {}>( singData: SignData ): Promise<UserCredentials<T>> {
80
- return Auth._authService.signUp( singData )
81
- }
82
-
83
- /**
84
- * Logs in an existing user
85
- * @param singData the data to be used to log in the user
86
- * @returns a promise that resolves to the user credentials
87
- * @example
88
- * // Log in an existing user with email and password
89
- * Auth.instance.login({ authProvider: 'email', email: 'john@test.com', password: '123456' })
90
- * // Log in an existing user with a Google account
91
- * Auth.instance.login({ authProvider: 'google'})
92
- */
93
- login<T extends {}>( singData: SignData ): Promise<UserCredentials<T>> {
94
- return Auth._authService.login( singData )
95
- }
96
-
97
- /**
98
- * Logs out the current user
99
- * @returns a promise that resolves when the user is logged out
100
- */
101
- logout(): Promise<void> {
102
- return Auth._authService.logout()
103
- }
104
-
105
- /**
106
- * Resets the password associated with the email.
107
- * @param email the email address of the user to reset the password
108
- * @returns a promise that resolves when the process is done
109
- */
110
- resetEmailPassword( email: string ) {
111
- return Auth._authService.resetEmailPassword( email )
112
- }
113
-
114
- /**
115
- * Resends the email verification to the user.
116
- * @returns a promise that resolves when the process is done
117
- */
118
- override resendVerificationEmail( email: string, password: string, verificationLink: string ): Promise<void> {
119
- return Auth._authService.resendVerificationEmail( email, password, verificationLink )
120
- }
121
-
122
- override refreshToken(): Promise<void> {
123
- return Auth._authService.refreshToken()
124
- }
125
-
126
- /**
127
- * Adds a listener to be called when the authentication state changes.
128
- * @param onChange the listener to be called when the authentication state changes.
129
- * The listener is called with the user credentials as a parameter.
130
- * If the user is logged out, the listener is called with `undefined` as a parameter.
131
- * @returns a function to remove the listener
132
- * @example
133
- * // Add a listener to be called when the authentication state changes
134
- * const removeListener = Auth.instance.onAuthStateChange( userCredentials => {
135
- * if ( userCredentials ) {
136
- * // The user is logged in
137
- * } else {
138
- * // The user is logged out
139
- * }
140
- * })
141
- */
142
- onAuthStateChange<T extends {}>( onChange: ( userCredentials: UserCredentials<T> )=>void ) {
143
- return this._onAuthStateChange.subscribe( onChange )
144
- }
145
-
146
- /**
147
- * Removes a listener that was added by `onAuthStateChange` method.
148
- * @param onChange the listener to be removed
149
- */
150
- removeAuthStateChange<T extends {}>( onChange: ( userCredentials: UserCredentials<T> )=>void ) {
151
- this._onAuthStateChange.unsubscribe( onChange )
152
- }
153
-
154
- /**
155
- * Links an additional authentication provider to the authenticated user.
156
- * @param provider the provider to be linked
157
- * @returns a promise that resolves when the process is done
158
- * @example
159
- * // Link a Google account to the auth service
160
- * Auth.instance.linkAdditionalProvider({ authProvider: 'google' })
161
- */
162
- linkAdditionalProvider( provider: AuthProvider ): Promise<unknown> {
163
- return Auth._authService.linkAdditionalProvider( provider )
164
- }
165
-
166
- /**
167
- * Unlinks an authentication provider from the authenticated user.
168
- * @param provider the provider to be unlinked
169
- * @returns a promise that resolves when the process is done
170
- * @example
171
- * // Unlink the Google account from the auth service
172
- * Auth.instance.unlinkProvider({ authProvider: 'google' })
173
- */
174
- unlinkProvider( provider: AuthProvider ): Promise<unknown> {
175
- return Auth._authService.unlinkProvider( provider )
176
- }
177
-
178
- private authStateChanged( userCredentials: UserCredentials<{}> | undefined ) {
179
- this._onAuthStateChange.notify( userCredentials )
180
- }
181
-
182
- private static _instance: Auth | undefined = undefined
183
- private static _authService: AuthService
184
- private _onAuthStateChange: Observable<UserCredentials<{}>> = new Observable<UserCredentials<{}>>()
185
- }
@@ -1,21 +0,0 @@
1
- export interface UserCredentials<T extends {} = {}> {
2
- id: string
3
- email: string
4
- name?: string
5
- pictureUrl?: string
6
- phoneNumber?: string
7
- emailVerified?: boolean
8
- customData?: T
9
- lastLogin?: number
10
- creationDate?: number
11
- }
12
-
13
- export type AuthProvider = 'email' | 'facebook' | 'google' | 'twitter'
14
-
15
- export interface SignData {
16
- authProvider: AuthProvider
17
- email?: string
18
- password?: string
19
- name?: string
20
- verificationLink?: string
21
- }
@@ -1,136 +0,0 @@
1
- import { PersistentObject } from '../persistent/persistent'
2
- import { TestUser } from '../store/mocks/test-user'
3
- import { CloudFunctions } from './cloud-functions'
4
- import { CloudFunctionsMock } from './cloud-functions-mock'
5
-
6
- describe( 'Cloud functions', ()=>{
7
-
8
- beforeEach(()=>{
9
- CloudFunctions.useCloudFunctionsService( new CloudFunctionsMock({
10
- testNoParam: ():Promise<string> => Promise.resolve( 'test' ),
11
- testArbitraryParamAndReturn: ( data: any ): Promise<any> => Promise.resolve( data.length ),
12
- testPersistentParamAndReturn: ( data: PersistentObject<TestUser> ): Promise<PersistentObject<TestUser>> => {
13
- return Promise.resolve( JSON.parse( JSON.stringify( data ) ) )
14
- },
15
- testPersistentParamAndPlainReturn: ( data: PersistentObject<TestUser> ): Promise<number> => {
16
- return Promise.resolve( data.age! )
17
- },
18
- testPlainParamAndPersistentReturn: ( data: number ): Promise<PersistentObject<TestUser>> => {
19
- const user = new TestUser()
20
- user.age = data
21
- return Promise.resolve( user.toObject() )
22
- },
23
- testWithoutParam: (): Promise<string> => Promise.resolve( 'Hello from the other side' ),
24
- testWithoutReturn: ( _data: string ): Promise<void> => Promise.resolve(),
25
- testArrayParam: ( data: PersistentObject<TestUser>[] ) => Promise.resolve( data.map( d => d.id ) ),
26
- testObjectParam: ( data: {[key:string]:PersistentObject<TestUser>} ) => Promise.resolve(
27
- Object.entries( data ).reduce(( obj, [k,v] ) => {
28
- obj[k] = v.id
29
- return obj
30
- }, {})
31
- ),
32
- testArrayResult: () => Promise.resolve([ new TestUser('userA').toObject(), new TestUser('userB').toObject() ]),
33
- testObjectResult: () => Promise.resolve({ user1: new TestUser('userA').toObject(), user2: new TestUser('userB').toObject() })
34
- }))
35
-
36
- })
37
-
38
- it( 'should execute cloud function without params', async ()=>{
39
- const testNoParam = CloudFunctions.instance.getRawFunction<never, string>( 'testNoParam' )
40
- const result = await testNoParam()
41
- expect( result ).toEqual( 'test' )
42
- })
43
-
44
- it( 'should execute cloud function with params', async ()=>{
45
- const testArbitraryParamAndReturn = CloudFunctions.instance.getFunction<string, number>( 'testArbitraryParamAndReturn' )
46
-
47
- const result = await testArbitraryParamAndReturn( 'Hello' )
48
- expect( result ).toEqual( 5 )
49
- })
50
-
51
- it( 'should execute cloud function without params', async ()=>{
52
- const testWithoutReturn = CloudFunctions.instance.getFunction<string>( 'testWithoutReturn' )
53
-
54
- expect( testWithoutReturn( '' ) ).resolves.toBeUndefined()
55
- })
56
-
57
- it( 'should execute cloud function with void return', async ()=>{
58
- const testWithoutParam = CloudFunctions.instance.getFunction<string>( 'testWithoutParam' )
59
-
60
- const result = await testWithoutParam()
61
- expect( result ).toEqual( 'Hello from the other side' )
62
- })
63
-
64
- it( 'should execute cloud function with params and return as Persistent', async ()=>{
65
- const testPersistentParamAndReturn = CloudFunctions.instance.getFunction<TestUser, TestUser>( 'testPersistentParamAndReturn' )
66
-
67
- const user = new TestUser()
68
- user.age = 35
69
- user.name = { firstName: 'Test User', lastName: 'as a user', ancestorName: {} }
70
-
71
- const result = await testPersistentParamAndReturn( user )
72
- expect( result.age ).toBe( 35 )
73
- expect( result.name ).toEqual({ firstName: 'Test User', lastName: 'as a user', ancestorName: {} })
74
- })
75
-
76
- it( 'should execute cloud function with params as Persistent and return as plain', async ()=>{
77
- const testPersistentParamAndPlainReturn = CloudFunctions.instance.getFunction<TestUser, number>( 'testPersistentParamAndPlainReturn' )
78
-
79
- const user = new TestUser()
80
- user.age = 35
81
-
82
- const result = await testPersistentParamAndPlainReturn( user )
83
- expect( result ).toBe( 35 )
84
- })
85
-
86
- it( 'should execute cloud function with params as plain and return as Persistent', async ()=>{
87
- const testPlainParamAndPersistentReturn = CloudFunctions.instance.getFunction<number, TestUser>( 'testPlainParamAndPersistentReturn' )
88
-
89
- const result = await testPlainParamAndPersistentReturn( 35 )
90
- expect( result.age ).toEqual( 35 )
91
- })
92
-
93
- it( 'should execute cloud function with params as an array of Persistents', async ()=>{
94
- const testArrayParam = CloudFunctions.instance.getFunction<TestUser[], string[]>( 'testArrayParam' )
95
-
96
- const result = await testArrayParam([
97
- new TestUser('userA'),
98
- new TestUser('userB')
99
- ])
100
-
101
- expect( result ).toEqual([ 'userA', 'userB' ])
102
- })
103
-
104
- it( 'should execute cloud functions that return array of Persistent', async ()=>{
105
- const testArrayResult = CloudFunctions.instance.getFunction<void, TestUser[]>( 'testArrayResult' )
106
-
107
- const result = await testArrayResult()
108
-
109
- expect( result[0] ).toBeInstanceOf( TestUser )
110
- expect( result[0]?.id ).toEqual( 'userA' )
111
- expect( result[1]?.id ).toEqual( 'userB' )
112
- })
113
-
114
- it( 'should execute cloud function with params as an object containing Persistents', async ()=>{
115
- const testObjectParam = CloudFunctions.instance.getFunction<{[key: string]:TestUser}, {[key: string]:string}>( 'testObjectParam' )
116
-
117
- const result = await testObjectParam({
118
- user1: new TestUser('userA'),
119
- user2: new TestUser('userB')
120
- })
121
-
122
- expect( result ).toEqual({ user1: 'userA', user2: 'userB' })
123
- })
124
-
125
- it( 'should execute cloud functions that return an object with Persistent', async ()=>{
126
- const testObjectResult = CloudFunctions.instance.getFunction<void, {[key: string]:TestUser}>( 'testObjectResult' )
127
-
128
- const result = await testObjectResult()
129
-
130
- expect( result.user1 ).toBeInstanceOf( TestUser )
131
- expect( result.user1?.id ).toEqual( 'userA' )
132
- expect( result.user2?.id ).toEqual( 'userB' )
133
- })
134
-
135
-
136
- })
@@ -1,23 +0,0 @@
1
- import { CloudFunction, CloudFunctionsService } from './cloud-functions'
2
-
3
- interface FunctionCollection {
4
- [key: string]: CloudFunction<any,any>
5
- }
6
-
7
- export class CloudFunctionsMock implements CloudFunctionsService {
8
- constructor( registeredFunctions: FunctionCollection ) {
9
- this._registeredFunctions = registeredFunctions
10
- }
11
-
12
- retrieveFunction<P, R>( cloudFunction: string ): CloudFunction<P,R> {
13
- const func = this._registeredFunctions[ cloudFunction ]
14
- if ( !func ) throw new Error( `Cloud function ${ cloudFunction } is not registered.` )
15
- return func
16
- }
17
-
18
- callFunction<P, R>( func: CloudFunction<P, R>, params: P ): Promise<R> {
19
- return func( params )
20
- }
21
-
22
- private _registeredFunctions: FunctionCollection
23
- }