pyios-firebase 0.2.0__py3-none-any.whl

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 (65) hide show
  1. pyios_firebase/__init__.py +26 -0
  2. pyios_firebase/analytics/__init__.py +434 -0
  3. pyios_firebase/analytics/names.py +251 -0
  4. pyios_firebase/app_check/__init__.py +483 -0
  5. pyios_firebase/auth/__init__.py +131 -0
  6. pyios_firebase/auth/_apple_name_cache.py +97 -0
  7. pyios_firebase/auth/_common.py +121 -0
  8. pyios_firebase/auth/_ui.py +21 -0
  9. pyios_firebase/auth/apple.py +326 -0
  10. pyios_firebase/auth/auth.py +592 -0
  11. pyios_firebase/auth/credentials.py +551 -0
  12. pyios_firebase/auth/errors.py +321 -0
  13. pyios_firebase/auth/facebook.py +240 -0
  14. pyios_firebase/auth/google.py +167 -0
  15. pyios_firebase/auth/multi_factor.py +394 -0
  16. pyios_firebase/auth/results.py +361 -0
  17. pyios_firebase/auth/user.py +457 -0
  18. pyios_firebase/core/__init__.py +32 -0
  19. pyios_firebase/crashlytics/__init__.py +463 -0
  20. pyios_firebase/database/__init__.py +62 -0
  21. pyios_firebase/database/database.py +144 -0
  22. pyios_firebase/database/errors.py +80 -0
  23. pyios_firebase/database/query.py +569 -0
  24. pyios_firebase/database/reference.py +428 -0
  25. pyios_firebase/database/snapshot.py +218 -0
  26. pyios_firebase/database/values.py +271 -0
  27. pyios_firebase/firestore/__init__.py +59 -0
  28. pyios_firebase/firestore/_limits.py +48 -0
  29. pyios_firebase/firestore/_query_state.py +228 -0
  30. pyios_firebase/firestore/_write.py +18 -0
  31. pyios_firebase/firestore/aggregate.py +137 -0
  32. pyios_firebase/firestore/collection_reference.py +100 -0
  33. pyios_firebase/firestore/document_change.py +63 -0
  34. pyios_firebase/firestore/document_reference.py +229 -0
  35. pyios_firebase/firestore/document_snapshot.py +102 -0
  36. pyios_firebase/firestore/enums.py +66 -0
  37. pyios_firebase/firestore/field_value.py +94 -0
  38. pyios_firebase/firestore/filter.py +319 -0
  39. pyios_firebase/firestore/firestore.py +184 -0
  40. pyios_firebase/firestore/listener_registration.py +55 -0
  41. pyios_firebase/firestore/query.py +679 -0
  42. pyios_firebase/firestore/query_snapshot.py +103 -0
  43. pyios_firebase/firestore/snapshot_metadata.py +36 -0
  44. pyios_firebase/firestore/transaction.py +130 -0
  45. pyios_firebase/firestore/write_batch.py +125 -0
  46. pyios_firebase/functions/__init__.py +329 -0
  47. pyios_firebase/messaging/__init__.py +37 -0
  48. pyios_firebase/messaging/messaging.py +435 -0
  49. pyios_firebase/messaging/notifications.py +292 -0
  50. pyios_firebase/performance/__init__.py +486 -0
  51. pyios_firebase/py.typed +0 -0
  52. pyios_firebase/remote_config/__init__.py +660 -0
  53. pyios_firebase/storage/__init__.py +41 -0
  54. pyios_firebase/storage/errors.py +103 -0
  55. pyios_firebase/storage/metadata.py +202 -0
  56. pyios_firebase/storage/reference.py +402 -0
  57. pyios_firebase/storage/storage.py +120 -0
  58. pyios_firebase/storage/task.py +198 -0
  59. pyios_firebase/types.py +93 -0
  60. pyios_firebase/util.py +413 -0
  61. pyios_firebase-0.2.0.dist-info/METADATA +1969 -0
  62. pyios_firebase-0.2.0.dist-info/RECORD +65 -0
  63. pyios_firebase-0.2.0.dist-info/WHEEL +5 -0
  64. pyios_firebase-0.2.0.dist-info/licenses/LICENSE +21 -0
  65. pyios_firebase-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,361 @@
1
+ """What Firebase Authentication calls give back, as plain Python values."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = (
6
+ "ActionCodeInfo",
7
+ "ActionCodeOperation",
8
+ "ActionCodeSettings",
9
+ "ActionCodeURL",
10
+ "AdditionalUserInfo",
11
+ "AuthDataResult",
12
+ "IDTokenResult",
13
+ "UserInfo",
14
+ "UserMetadata",
15
+ )
16
+
17
+ import urllib.parse
18
+ from dataclasses import dataclass
19
+ from datetime import datetime
20
+ from typing import Any, Final
21
+
22
+ from ..types import ObjCObject
23
+ from ..util import nsdate_to_datetime, objc_class, to_python
24
+ from . import user as user_module # module import: user imports us back
25
+ from ._common import flag, text, url_text
26
+ from .credentials import OAuthCredential
27
+
28
+
29
+ def _required_date(value: ObjCObject) -> datetime:
30
+ """An ``NSDate`` the SDK always provides, as a ``datetime``."""
31
+ result = nsdate_to_datetime(value)
32
+ if result is None:
33
+ raise ValueError("Firebase gave no date where one is required")
34
+ return result
35
+
36
+
37
+ class UserInfo:
38
+ """A user's profile at one provider (an entry of ``User.provider_data``).
39
+
40
+ Args:
41
+ native: the native ``FIRUserInfo``.
42
+ """
43
+
44
+ def __init__(self, native: ObjCObject) -> None:
45
+ self._native = native
46
+
47
+ @property
48
+ def provider_id(self) -> str:
49
+ """The provider ID, for example ``"password"`` or ``"google.com"``."""
50
+ return str(self._native.providerID)
51
+
52
+ @property
53
+ def uid(self) -> str:
54
+ """The user's ID at that provider (not the Firebase uid)."""
55
+ return str(self._native.uid)
56
+
57
+ @property
58
+ def display_name(self) -> str | None:
59
+ """The name at that provider, or ``None``."""
60
+ return text(self._native.displayName)
61
+
62
+ @property
63
+ def email(self) -> str | None:
64
+ """The email address at that provider, or ``None``."""
65
+ return text(self._native.email)
66
+
67
+ @property
68
+ def phone_number(self) -> str | None:
69
+ """The phone number at that provider, or ``None``."""
70
+ return text(self._native.phoneNumber)
71
+
72
+ @property
73
+ def photo_url(self) -> str | None:
74
+ """The profile photo URL at that provider, or ``None``."""
75
+ return url_text(self._native.photoURL)
76
+
77
+ def __repr__(self) -> str:
78
+ return f"UserInfo(provider_id={self.provider_id!r}, uid={self.uid!r})"
79
+
80
+
81
+ @dataclass(frozen=True)
82
+ class UserMetadata:
83
+ """When the user was created and last signed in."""
84
+
85
+ creation_date: datetime | None
86
+ """When the account was created (UTC)."""
87
+ last_sign_in_date: datetime | None
88
+ """When the user last signed in (UTC)."""
89
+
90
+ @classmethod
91
+ def from_native(cls, native: ObjCObject) -> UserMetadata:
92
+ """Copy a native ``FIRUserMetadata``.
93
+
94
+ Args:
95
+ native: the ``FIRUserMetadata``.
96
+ """
97
+ return cls(
98
+ nsdate_to_datetime(native.creationDate),
99
+ nsdate_to_datetime(native.lastSignInDate),
100
+ )
101
+
102
+
103
+ @dataclass(frozen=True)
104
+ class AdditionalUserInfo:
105
+ """Provider details from one sign-in."""
106
+
107
+ provider_id: str
108
+ """The provider used for this sign-in."""
109
+ is_new_user: bool
110
+ """True if this sign-in created the account."""
111
+ username: str | None
112
+ """The username at the provider (GitHub, Twitter), or ``None``."""
113
+ profile: dict[str, Any]
114
+ """The provider's profile data (for example Google's ``given_name``)."""
115
+
116
+ @classmethod
117
+ def from_native(cls, native: ObjCObject) -> AdditionalUserInfo:
118
+ """Copy a native ``FIRAdditionalUserInfo``.
119
+
120
+ Args:
121
+ native: the ``FIRAdditionalUserInfo``.
122
+ """
123
+ profile = native.profile
124
+ return cls(
125
+ provider_id=str(native.providerID),
126
+ is_new_user=flag(native, "isNewUser"),
127
+ username=text(native.username),
128
+ profile={} if profile is None else to_python(profile),
129
+ )
130
+
131
+
132
+ class AuthDataResult:
133
+ """The result of a sign-in, link or re-authentication.
134
+
135
+ Args:
136
+ native: the native ``FIRAuthDataResult``.
137
+ """
138
+
139
+ def __init__(self, native: ObjCObject) -> None:
140
+ self._native = native
141
+
142
+ @property
143
+ def user(self) -> user_module.User:
144
+ """The signed-in (or linked) user."""
145
+ return user_module.User(self._native.user)
146
+
147
+ @property
148
+ def additional_user_info(self) -> AdditionalUserInfo | None:
149
+ """Provider details from this sign-in, or ``None``."""
150
+ info = self._native.additionalUserInfo
151
+ return None if info is None else AdditionalUserInfo.from_native(info)
152
+
153
+ @property
154
+ def credential(self) -> OAuthCredential | None:
155
+ """The OAuth credential the provider gave (OAuth providers only), or
156
+ ``None``. Holds the provider's own access / ID tokens."""
157
+ credential = self._native.credential
158
+ return None if credential is None else OAuthCredential(credential)
159
+
160
+ def __repr__(self) -> str:
161
+ return f"AuthDataResult(user={self.user!r})"
162
+
163
+
164
+ @dataclass(frozen=True)
165
+ class IDTokenResult:
166
+ """A Firebase ID token and what it says."""
167
+
168
+ token: str
169
+ """The ID token (a JWT). Send it to your backend to prove who the user is."""
170
+ claims: dict[str, Any]
171
+ """All the token's claims, including custom claims set by your backend."""
172
+ expiration_date: datetime
173
+ """When the token expires (UTC)."""
174
+ issued_at_date: datetime
175
+ """When the token was issued (UTC)."""
176
+ auth_date: datetime
177
+ """When the user signed in (UTC)."""
178
+ sign_in_provider: str
179
+ """The provider used to sign in, for example ``"password"`` or ``"anonymous"``."""
180
+ sign_in_second_factor: str | None
181
+ """The second factor used, for multi-factor sign-in, or ``None``."""
182
+
183
+ @classmethod
184
+ def from_native(cls, native: ObjCObject) -> IDTokenResult:
185
+ """Copy a native ``FIRAuthTokenResult``.
186
+
187
+ Args:
188
+ native: the ``FIRAuthTokenResult``.
189
+ """
190
+ second = text(native.signInSecondFactor)
191
+ return cls(
192
+ token=str(native.token),
193
+ claims=to_python(native.claims),
194
+ expiration_date=_required_date(native.expirationDate),
195
+ issued_at_date=_required_date(native.issuedAtDate),
196
+ auth_date=_required_date(native.authDate),
197
+ sign_in_provider=str(native.signInProvider),
198
+ sign_in_second_factor=second or None,
199
+ )
200
+
201
+
202
+ class ActionCodeOperation:
203
+ """What an email action code (link) is for. The values of
204
+ ``ActionCodeInfo.operation``."""
205
+
206
+ UNKNOWN: Final = 0
207
+ PASSWORD_RESET: Final = 1
208
+ VERIFY_EMAIL: Final = 2
209
+ RECOVER_EMAIL: Final = 3
210
+ EMAIL_LINK: Final = 4
211
+ VERIFY_AND_CHANGE_EMAIL: Final = 5
212
+ REVERT_SECOND_FACTOR_ADDITION: Final = 6
213
+
214
+
215
+ @dataclass(frozen=True)
216
+ class ActionCodeInfo:
217
+ """What ``Auth.check_action_code`` learned about an email action code."""
218
+
219
+ operation: int
220
+ """An ``ActionCodeOperation`` value.
221
+
222
+ Firebase iOS SDK 13.1.1 only recognises request types in camel case
223
+ (``"resetPassword"``); a server that sends ``"PASSWORD_RESET"``, as the
224
+ Auth emulator does, gives ``UNKNOWN``. Do not rely on it alone."""
225
+ email: str
226
+ """The email address the code is for."""
227
+ previous_email: str | None
228
+ """For ``RECOVER_EMAIL`` / ``VERIFY_AND_CHANGE_EMAIL``: the old address."""
229
+
230
+ @classmethod
231
+ def from_native(cls, native: ObjCObject) -> ActionCodeInfo:
232
+ """Copy a native ``FIRActionCodeInfo``.
233
+
234
+ Args:
235
+ native: the ``FIRActionCodeInfo``.
236
+ """
237
+ return cls(int(native.operation), str(native.email), text(native.previousEmail))
238
+
239
+
240
+ @dataclass
241
+ class ActionCodeSettings:
242
+ """Where email links (password reset, verification, sign-in) lead.
243
+
244
+ ::
245
+
246
+ ActionCodeSettings(
247
+ url="https://example.com/finish-sign-in",
248
+ handle_code_in_app=True,
249
+ ios_bundle_id="com.example.app",
250
+ )
251
+ """
252
+
253
+ url: str | None = None
254
+ """The continue URL: where the user lands after the action. Its domain must
255
+ be authorized in the Firebase console."""
256
+ handle_code_in_app: bool = False
257
+ """True to open the link in the app (required for email link sign-in)."""
258
+ ios_bundle_id: str | None = None
259
+ """The iOS app to open the link in."""
260
+ android_package_name: str | None = None
261
+ """The Android app to open the link in."""
262
+ android_install_if_not_available: bool = False
263
+ """Offer to install the Android app if it is missing."""
264
+ android_minimum_version: str | None = None
265
+ """The minimum Android app version that can handle the link."""
266
+ link_domain: str | None = None
267
+ """A custom Firebase Hosting domain for the link."""
268
+
269
+ def to_native(self) -> ObjCObject:
270
+ """Make the native ``FIRActionCodeSettings``."""
271
+ native = objc_class("FIRActionCodeSettings").alloc().init()
272
+ if self.url is not None:
273
+ native.URL = objc_class("NSURL").URLWithString_(self.url)
274
+ native.handleCodeInApp = bool(self.handle_code_in_app)
275
+ if self.ios_bundle_id is not None:
276
+ native.iOSBundleID = self.ios_bundle_id
277
+ if self.android_package_name is not None:
278
+ native.setAndroidPackageName_installIfNotAvailable_minimumVersion_(
279
+ self.android_package_name,
280
+ bool(self.android_install_if_not_available),
281
+ self.android_minimum_version,
282
+ )
283
+ if self.link_domain is not None:
284
+ native.linkDomain = self.link_domain
285
+ return native
286
+
287
+
288
+ _LINK_MODES: Final = {
289
+ "resetPassword": 1,
290
+ "verifyEmail": 2,
291
+ "recoverEmail": 3,
292
+ "signIn": 4,
293
+ "verifyAndChangeEmail": 5,
294
+ "revertSecondFactorAddition": 6,
295
+ }
296
+
297
+
298
+ def _query_params(url: str) -> dict[str, str]:
299
+ """The first value of each query parameter, percent-decoded once."""
300
+ query = urllib.parse.urlsplit(url).query
301
+ return {
302
+ k: v[0] for k, v in urllib.parse.parse_qs(query, keep_blank_values=True).items()
303
+ }
304
+
305
+
306
+ @dataclass(frozen=True)
307
+ class ActionCodeURL:
308
+ """The parts of an email action link (password reset, verification,
309
+ sign-in), read without calling the server.
310
+
311
+ Use it to get the ``continue_url`` back, with the state you put in it
312
+ ("Passing State in Email Actions")::
313
+
314
+ info = ActionCodeURL.from_link(link)
315
+ if info is not None and info.continue_url:
316
+ state = urllib.parse.parse_qs(urllib.parse.urlsplit(info.continue_url).query)
317
+
318
+ Parsed in Python: Firebase iOS SDK 13.1.1 decodes the link's query before
319
+ splitting it, which cuts a continue URL at its own ``&`` and loses state.
320
+ """
321
+
322
+ operation: int
323
+ """An ``ActionCodeOperation`` value, from the link's ``mode``."""
324
+ code: str | None
325
+ """The action code (``oobCode``): pass it to ``apply_action_code``,
326
+ ``confirm_password_reset``, ..."""
327
+ continue_url: str | None
328
+ """The continue URL given in ``ActionCodeSettings.url``, with its state."""
329
+ api_key: str | None
330
+ """The Firebase API key in the link."""
331
+ language_code: str | None
332
+ """The language of the email, or ``None``."""
333
+
334
+ @classmethod
335
+ def from_link(cls, link: str) -> ActionCodeURL | None:
336
+ """Parse an action link.
337
+
338
+ Links wrapped in another link's ``link`` parameter (as Firebase Hosting
339
+ and Dynamic Links deliver them) are unwrapped.
340
+
341
+ Args:
342
+ link: the full link from the email (or the URL the app was opened with).
343
+
344
+ Returns:
345
+ An ``ActionCodeURL``, or ``None`` if ``link`` has no ``mode`` or
346
+ ``oobCode`` (it is not an action link).
347
+ """
348
+ params = _query_params(link)
349
+ if "oobCode" not in params and "mode" not in params and "link" in params:
350
+ params = _query_params(params["link"])
351
+ if "oobCode" not in params and "mode" not in params:
352
+ return None
353
+ return cls(
354
+ operation=_LINK_MODES.get(
355
+ params.get("mode", ""), ActionCodeOperation.UNKNOWN
356
+ ),
357
+ code=params.get("oobCode"),
358
+ continue_url=params.get("continueUrl"),
359
+ api_key=params.get("apiKey"),
360
+ language_code=params.get("lang"),
361
+ )