u2auth 0.2.2__tar.gz → 0.3.0__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u2auth
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers
5
5
  Author-email: DollarMates Dev <dev@dollarmates.com>
6
6
  License-Expression: MIT
@@ -215,6 +215,28 @@ while True:
215
215
  cursor = page["next_cursor"]
216
216
  ```
217
217
 
218
+ ### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
219
+
220
+ Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
221
+
222
+ #### Export the sign-in log
223
+
224
+ Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
225
+
226
+ ```python
227
+ cursor = load_cursor() # "" on the first run
228
+ while True:
229
+ page = client.list_sign_in_log(limit=1000, cursor=cursor)
230
+ for ev in page["items"]:
231
+ store(ev)
232
+ cursor = page["next_cursor"]
233
+ save_cursor(cursor)
234
+ if not page["has_more"]:
235
+ break
236
+ ```
237
+
238
+ Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
239
+
218
240
  ### Helpers (no API call)
219
241
 
220
242
  ```python
@@ -192,6 +192,28 @@ while True:
192
192
  cursor = page["next_cursor"]
193
193
  ```
194
194
 
195
+ ### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
196
+
197
+ Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
198
+
199
+ #### Export the sign-in log
200
+
201
+ Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
202
+
203
+ ```python
204
+ cursor = load_cursor() # "" on the first run
205
+ while True:
206
+ page = client.list_sign_in_log(limit=1000, cursor=cursor)
207
+ for ev in page["items"]:
208
+ store(ev)
209
+ cursor = page["next_cursor"]
210
+ save_cursor(cursor)
211
+ if not page["has_more"]:
212
+ break
213
+ ```
214
+
215
+ Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
216
+
195
217
  ### Helpers (no API call)
196
218
 
197
219
  ```python
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "u2auth"
7
- version = "0.2.2"
7
+ version = "0.3.0"
8
8
  description = "U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers"
9
9
  authors = [{ name = "DollarMates Dev", email = "dev@dollarmates.com" }]
10
10
  requires-python = ">=3.9"
@@ -605,6 +605,104 @@ class TestListEnrolmentEvents:
605
605
  srv.stop()
606
606
 
607
607
 
608
+ class TestListSignInLog:
609
+ PATH = "/api/v1/sdk/sign-in-log"
610
+
611
+ def _srv(self, body=None, status=200, **kw):
612
+ return MockServer(
613
+ make_handler(
614
+ status,
615
+ body if body is not None else {"items": [], "next_cursor": "", "has_more": False},
616
+ assert_method="GET",
617
+ assert_path=self.PATH,
618
+ **kw,
619
+ )
620
+ )
621
+
622
+ def test_default_call_sends_auth_and_no_query(self):
623
+ srv = self._srv(assert_query={}, assert_auth="Bearer rka_test")
624
+ Client("rka_test", base_url=srv.url).list_sign_in_log()
625
+ srv.stop()
626
+
627
+ def test_limit_and_cursor_included_when_given(self):
628
+ srv = self._srv(assert_query={"limit": "1000", "cursor": "abc"})
629
+ Client("rka_test", base_url=srv.url).list_sign_in_log(limit=1000, cursor="abc")
630
+ srv.stop()
631
+
632
+ def test_zero_limit_is_omitted(self):
633
+ srv = self._srv(assert_query={})
634
+ Client("rka_test", base_url=srv.url).list_sign_in_log(limit=0)
635
+ srv.stop()
636
+
637
+ def test_negative_limit_is_omitted(self):
638
+ srv = self._srv(assert_query={})
639
+ Client("rka_test", base_url=srv.url).list_sign_in_log(limit=-1)
640
+ srv.stop()
641
+
642
+ def test_empty_cursor_is_omitted(self):
643
+ srv = self._srv(assert_query={"limit": "5"})
644
+ Client("rka_test", base_url=srv.url).list_sign_in_log(limit=5, cursor="")
645
+ srv.stop()
646
+
647
+ def test_cursor_is_url_encoded(self):
648
+ raw = "a+b/c=d e&f"
649
+ srv = self._srv(assert_query={"cursor": raw})
650
+ Client("rka_test", base_url=srv.url).list_sign_in_log(cursor=raw)
651
+ srv.stop()
652
+
653
+ def test_decodes_fleet_and_push_rows_preserving_nulls(self):
654
+ fleet = {
655
+ "id": "e1", "occurred_at": "2026-11-10T00:00:00Z",
656
+ "received_at": "2026-11-10T00:00:05Z", "user_identifier": "alice",
657
+ "local_login": "alice", "kind": "machine", "origin": "ssh",
658
+ "method": "push", "outcome": "approved", "reason": "ok",
659
+ "city": "Berlin", "region": "", "country": "DE", "new_country": True,
660
+ "source_ip": "203.0.113.9", "machine_id": "m1", "machine_name": "web-1",
661
+ "service": "sshd", "context": "login", "approval_id": "ap1",
662
+ "seq": 7, "gap_count": 0, "clock_skew_seconds": 2,
663
+ }
664
+ push = {
665
+ "id": "e2", "occurred_at": "2026-11-10T00:01:00Z",
666
+ "received_at": "2026-11-10T00:01:01Z", "user_identifier": "bob",
667
+ "local_login": None, "kind": "push", "origin": "app",
668
+ "method": "push", "outcome": "approved", "reason": None,
669
+ "city": None, "region": None, "country": None, "new_country": False,
670
+ "source_ip": None, "machine_id": None, "machine_name": None,
671
+ "service": None, "context": None, "approval_id": "ap2",
672
+ "seq": None, "gap_count": None, "clock_skew_seconds": None,
673
+ }
674
+ srv = self._srv({"items": [fleet, push], "next_cursor": "c2", "has_more": True})
675
+ result = Client("rka_test", base_url=srv.url).list_sign_in_log()
676
+ srv.stop()
677
+ assert result == {"items": [fleet, push], "next_cursor": "c2", "has_more": True}
678
+ assert result["items"][0]["machine_id"] == "m1"
679
+ assert result["items"][0]["region"] == ""
680
+ assert result["items"][1]["city"] is None
681
+ assert result["items"][1]["machine_id"] is None
682
+ assert result["has_more"] is True
683
+
684
+ def test_invalid_cursor_surfaces_code(self):
685
+ srv = self._srv(
686
+ {"error": {"code": "INVALID_CURSOR", "message": "bad cursor"}}, status=400
687
+ )
688
+ with pytest.raises(U2AuthError) as exc:
689
+ Client("rka_test", base_url=srv.url).list_sign_in_log(cursor="zzz")
690
+ srv.stop()
691
+ assert exc.value.code == "INVALID_CURSOR"
692
+ assert exc.value.status_code == 400
693
+
694
+ def test_machine_key_not_allowed_surfaces_code(self):
695
+ srv = self._srv(
696
+ {"error": {"code": "MACHINE_KEY_NOT_ALLOWED", "message": "use an app key"}},
697
+ status=403,
698
+ )
699
+ with pytest.raises(U2AuthError) as exc:
700
+ Client("rka_test", base_url=srv.url).list_sign_in_log()
701
+ srv.stop()
702
+ assert exc.value.code == "MACHINE_KEY_NOT_ALLOWED"
703
+ assert exc.value.status_code == 403
704
+
705
+
608
706
  class TestListEnrolmentsUserIdentifier:
609
707
  def test_user_identifier_included_when_given(self):
610
708
  srv = MockServer(
@@ -239,6 +239,30 @@ class Client:
239
239
  path = f"/api/v1/sdk/enrolments/{enrolment_path}/events"
240
240
  return self._get(f"{path}?{query}" if query else path)
241
241
 
242
+ def list_sign_in_log(self, *, limit: int = 0, cursor: str = "") -> Dict[str, Any]:
243
+ """Pull the app's sign-in log, oldest first.
244
+
245
+ limit <= 0 is treated as unset and omitted from the query (the server
246
+ default is 500, max 1000), same as an empty cursor.
247
+
248
+ cursor is opaque; pass back the previous page's next_cursor verbatim.
249
+ Rows are served about 30 seconds after they are recorded.
250
+
251
+ Raises U2AuthError with code 'INVALID_CURSOR' if cursor is malformed,
252
+ or 'MACHINE_KEY_NOT_ALLOWED' if called with a machine key (use an app
253
+ key).
254
+
255
+ Returns {'items': [...], 'next_cursor': '...', 'has_more': bool}.
256
+ """
257
+ params: Dict[str, Any] = {}
258
+ if limit > 0:
259
+ params["limit"] = limit
260
+ if cursor:
261
+ params["cursor"] = cursor
262
+ query = urllib.parse.urlencode(params)
263
+ path = "/api/v1/sdk/sign-in-log"
264
+ return self._get(f"{path}?{query}" if query else path)
265
+
242
266
  def _post(
243
267
  self, path: str, body: Dict[str, Any], headers: Optional[Dict[str, str]] = None
244
268
  ) -> Dict[str, Any]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u2auth
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers
5
5
  Author-email: DollarMates Dev <dev@dollarmates.com>
6
6
  License-Expression: MIT
@@ -215,6 +215,28 @@ while True:
215
215
  cursor = page["next_cursor"]
216
216
  ```
217
217
 
218
+ ### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
219
+
220
+ Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
221
+
222
+ #### Export the sign-in log
223
+
224
+ Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
225
+
226
+ ```python
227
+ cursor = load_cursor() # "" on the first run
228
+ while True:
229
+ page = client.list_sign_in_log(limit=1000, cursor=cursor)
230
+ for ev in page["items"]:
231
+ store(ev)
232
+ cursor = page["next_cursor"]
233
+ save_cursor(cursor)
234
+ if not page["has_more"]:
235
+ break
236
+ ```
237
+
238
+ Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
239
+
218
240
  ### Helpers (no API call)
219
241
 
220
242
  ```python
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes