lumera 0.54.3__tar.gz → 0.54.5.dev1__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.
Files changed (91) hide show
  1. {lumera-0.54.3 → lumera-0.54.5.dev1}/PKG-INFO +1 -1
  2. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/__init__.py +2 -0
  3. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/_utils.py +36 -0
  4. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/storage.py +36 -8
  5. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera.egg-info/PKG-INFO +1 -1
  6. {lumera-0.54.3 → lumera-0.54.5.dev1}/pyproject.toml +1 -1
  7. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_sdk.py +72 -0
  8. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/_live.py +0 -0
  9. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/_log_redaction.py +0 -0
  10. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/agents.py +0 -0
  11. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/automations.py +0 -0
  12. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/documents.py +0 -0
  13. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/email.py +0 -0
  14. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/exceptions.py +0 -0
  15. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/files.py +0 -0
  16. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/flags.py +0 -0
  17. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/function_resources.py +0 -0
  18. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/__init__.py +0 -0
  19. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/__main__.py +0 -0
  20. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_artifacts.py +0 -0
  21. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_config.py +0 -0
  22. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_context.py +0 -0
  23. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_contract.py +0 -0
  24. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_dependencies.py +0 -0
  25. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_errors.py +0 -0
  26. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_execution.py +0 -0
  27. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_jsonschema.py +0 -0
  28. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_registry.py +0 -0
  29. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_remote.py +0 -0
  30. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_runner.py +0 -0
  31. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/_runtime.py +0 -0
  32. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/functions/testing.py +0 -0
  33. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/google.py +0 -0
  34. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/__init__.py +0 -0
  35. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/bill.py +0 -0
  36. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/client.py +0 -0
  37. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/finch.py +0 -0
  38. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/google.py +0 -0
  39. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/kafka.py +0 -0
  40. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/netsuite.py +0 -0
  41. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/personal.py +0 -0
  42. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/salesforce.py +0 -0
  43. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/slack.py +0 -0
  44. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/integrations/snowflake.py +0 -0
  45. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/llm.py +0 -0
  46. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/pb.py +0 -0
  47. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/__init__.py +0 -0
  48. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/__main__.py +0 -0
  49. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_api_child.py +0 -0
  50. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_archive.py +0 -0
  51. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_automation_event.py +0 -0
  52. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_builder.py +0 -0
  53. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_config.py +0 -0
  54. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_contracts.py +0 -0
  55. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_errors.py +0 -0
  56. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_projection.py +0 -0
  57. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_rpc_diagnostics.py +0 -0
  58. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_rpc_event.py +0 -0
  59. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_rpc_process.py +0 -0
  60. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_runtime.py +0 -0
  61. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_runtime_child.py +0 -0
  62. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_schemas.py +0 -0
  63. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_target.py +0 -0
  64. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/releases/_timing.py +0 -0
  65. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/sdk.py +0 -0
  66. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/transactions.py +0 -0
  67. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera/webhooks.py +0 -0
  68. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera.egg-info/SOURCES.txt +0 -0
  69. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera.egg-info/dependency_links.txt +0 -0
  70. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera.egg-info/requires.txt +0 -0
  71. {lumera-0.54.3 → lumera-0.54.5.dev1}/lumera.egg-info/top_level.txt +0 -0
  72. {lumera-0.54.3 → lumera-0.54.5.dev1}/setup.cfg +0 -0
  73. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_agents_live.py +0 -0
  74. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_automations.py +0 -0
  75. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_documents.py +0 -0
  76. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_flags.py +0 -0
  77. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_function_resources.py +0 -0
  78. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integration_client.py +0 -0
  79. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_bill.py +0 -0
  80. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_finch.py +0 -0
  81. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_google.py +0 -0
  82. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_kafka.py +0 -0
  83. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_netsuite.py +0 -0
  84. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_personal.py +0 -0
  85. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_salesforce.py +0 -0
  86. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_slack.py +0 -0
  87. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_integrations_snowflake.py +0 -0
  88. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_lazy_imports.py +0 -0
  89. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_log_redaction.py +0 -0
  90. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_transactions.py +0 -0
  91. {lumera-0.54.3 → lumera-0.54.5.dev1}/tests/test_webhooks.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.54.3
3
+ Version: 0.54.5.dev1
4
4
  Summary: SDK for building on Lumera platform
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: requests>=2.33.0
@@ -39,6 +39,7 @@ except PackageNotFoundError:
39
39
  __all__ = [
40
40
  # Authentication & utilities
41
41
  "Credentials",
42
+ "as_app_user",
42
43
  "get_access_token",
43
44
  "get_credentials",
44
45
  "get_google_access_token", # Kept for backwards compatibility
@@ -133,6 +134,7 @@ _LAZY_ATTRIBUTES = {
133
134
  "LumeraAPIError": ("._utils", "LumeraAPIError"),
134
135
  "RecordNotUniqueError": ("._utils", "RecordNotUniqueError"),
135
136
  "get_access_token": ("._utils", "get_access_token"),
137
+ "as_app_user": ("._utils", "as_app_user"),
136
138
  "get_credentials": ("._utils", "get_credentials"),
137
139
  "get_google_access_token": ("._utils", "get_google_access_token"),
138
140
  "list_integration_connections": ("._utils", "list_integration_connections"),
@@ -68,6 +68,37 @@ def _reset_runtime_lumera_token(token: Token[str]) -> None:
68
68
  _runtime_lumera_token.reset(token)
69
69
 
70
70
 
71
+ APP_USER_ASSERTION_HEADER = "X-Lumera-App-User-Assertion"
72
+ _app_user_assertion: ContextVar[str] = ContextVar("lumera_app_user_assertion", default="")
73
+
74
+
75
+ @contextlib.contextmanager
76
+ def as_app_user(assertion: str | None) -> Iterator[None]:
77
+ """Attribute the SDK calls made inside the block to an external app user.
78
+
79
+ An App API route receives the signed ``X-Lumera-App-User-Assertion`` header
80
+ for a signed-in external user. Pass that value here and every SDK call in
81
+ the block forwards it, so the platform records the app user as the actor
82
+ instead of the project runtime. The platform verifies the assertion; an
83
+ invalid one is ignored. ``None`` or an empty value forwards nothing, which
84
+ is the case in dev, for organization members, and for anonymous visitors.
85
+
86
+ The binding is local to the current request (a context variable), so
87
+ concurrent requests do not see each other's assertion.
88
+
89
+ Example::
90
+
91
+ with as_app_user(request.headers.get("X-Lumera-App-User-Assertion")):
92
+ pb.update("invoices", invoice_id, {"status": "approved"})
93
+ """
94
+
95
+ token = _app_user_assertion.set((assertion or "").strip())
96
+ try:
97
+ yield
98
+ finally:
99
+ _app_user_assertion.reset(token)
100
+
101
+
71
102
  def _credentials_paths() -> tuple[str, ...]:
72
103
  explicit = os.getenv(CREDENTIALS_PATH_ENV, "").strip()
73
104
  return tuple(
@@ -865,6 +896,11 @@ def _api_headers(
865
896
  if _user_id:
866
897
  headers["X-Lumera-User-Id"] = _user_id
867
898
 
899
+ # App user context: set by as_app_user() for the current request only.
900
+ _assertion = _app_user_assertion.get()
901
+ if _assertion:
902
+ headers[APP_USER_ASSERTION_HEADER] = _assertion
903
+
868
904
  return headers
869
905
 
870
906
 
@@ -37,6 +37,7 @@ import mimetypes
37
37
  import os
38
38
  import pathlib
39
39
  from typing import Any, Required, TypedDict
40
+ from urllib.parse import quote
40
41
 
41
42
  import requests
42
43
 
@@ -276,10 +277,23 @@ def list_files(prefix: str | None = None) -> list[dict[str, Any]]:
276
277
  return files
277
278
 
278
279
 
280
+ def _run_file_ref(object_key: str) -> tuple[str, str] | None:
281
+ """Split a run file key (agent_runs/<run_id>/<name>, with or without the
282
+ storage prefix in front) into its run id and file name."""
283
+ parts = object_key.strip().strip("/").split("/")
284
+ if parts[0] in ("pb", "mailboxes") or "agent_runs" not in parts[:2]:
285
+ return None
286
+ rest = parts[parts.index("agent_runs") + 1 :]
287
+ if len(rest) < 2 or not rest[0] or not rest[-1]:
288
+ return None
289
+ return rest[0], "/".join(rest[1:])
290
+
291
+
279
292
  def get_download_url(object_key: str) -> str:
280
293
  """Get a presigned download URL for a file by its object_key.
281
294
 
282
- Use this to get download URLs for files stored in file fields on records.
295
+ Use this to get download URLs for files stored in file fields on records,
296
+ or for a run's file from the object_key that storage.upload() returned.
283
297
  The object_key is in each file descriptor; a lumera_file_v2 field holds a
284
298
  list of them (e.g., record["files"][0]["object_key"]).
285
299
 
@@ -301,12 +315,25 @@ def get_download_url(object_key: str) -> str:
301
315
  if not object_key or not object_key.strip():
302
316
  raise ValueError("object_key is required and cannot be empty")
303
317
 
304
- resp = _get_session().post(
305
- f"{API_BASE}/pb/uploads/download",
306
- json={"object_key": object_key.strip()},
307
- headers=_api_headers(content_type="application/json"),
308
- timeout=30,
309
- )
318
+ # A file uploaded for a run (storage.upload(), or a run's file input) is
319
+ # signed by that run's files route. /pb/uploads/download signs only record
320
+ # files and mailbox attachments.
321
+ run_file = _run_file_ref(object_key)
322
+ if run_file:
323
+ run_id, name = run_file
324
+ resp = _get_session().get(
325
+ f"{API_BASE}/automation-runs/{quote(run_id, safe='')}/files/download-url",
326
+ params={"name": name},
327
+ headers=_api_headers(),
328
+ timeout=30,
329
+ )
330
+ else:
331
+ resp = _get_session().post(
332
+ f"{API_BASE}/pb/uploads/download",
333
+ json={"object_key": object_key.strip()},
334
+ headers=_api_headers(content_type="application/json"),
335
+ timeout=30,
336
+ )
310
337
  resp.raise_for_status()
311
338
 
312
339
  data = resp.json()
@@ -320,7 +347,8 @@ def get_download_url(object_key: str) -> str:
320
347
  def download(object_key: str) -> bytes:
321
348
  """Download file content by its object_key.
322
349
 
323
- Use this to download files stored in file fields on records.
350
+ Use this to download files stored in file fields on records, or a run's
351
+ file from the object_key that storage.upload() returned.
324
352
  The object_key is in each file descriptor; a lumera_file_v2 field holds a
325
353
  list of them (e.g., record["files"][0]["object_key"]).
326
354
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.54.3
3
+ Version: 0.54.5.dev1
4
4
  Summary: SDK for building on Lumera platform
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: requests>=2.33.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lumera"
3
- version = "0.54.3"
3
+ version = "0.54.5.dev1"
4
4
  description = "SDK for building on Lumera platform"
5
5
  requires-python = ">=3.11"
6
6
  dependencies = [
@@ -213,6 +213,21 @@ def test_api_headers_uses_request_local_runtime_actor(monkeypatch: pytest.Monkey
213
213
  assert _utils._api_headers()["X-Lumera-User-Id"] == "fallback-member"
214
214
 
215
215
 
216
+ def test_as_app_user_forwards_the_assertion_only_inside_the_block(
217
+ monkeypatch: pytest.MonkeyPatch,
218
+ ) -> None:
219
+ monkeypatch.setenv(sdk.TOKEN_ENV, "tok")
220
+ header = _utils.APP_USER_ASSERTION_HEADER
221
+
222
+ with _utils.as_app_user(" signed-assertion "):
223
+ assert _utils._api_headers()[header] == "signed-assertion"
224
+ with _utils.as_app_user(None):
225
+ assert header not in _utils._api_headers()
226
+ assert _utils._api_headers()[header] == "signed-assertion"
227
+
228
+ assert header not in _utils._api_headers()
229
+
230
+
216
231
  def test_api_headers_forwards_execution_correlation(monkeypatch: pytest.MonkeyPatch) -> None:
217
232
  monkeypatch.setenv(sdk.TOKEN_ENV, "tok")
218
233
  monkeypatch.setenv("LUMERA_REQUEST_ID", " request_1 ")
@@ -993,6 +1008,63 @@ PRESIGNED_URL = (
993
1008
  )
994
1009
 
995
1010
 
1011
+ @pytest.mark.parametrize(
1012
+ ("object_key", "method", "path", "sent"),
1013
+ [
1014
+ (
1015
+ "uploaded-documents/agent_runs/run42/report.csv",
1016
+ "GET",
1017
+ "/automation-runs/run42/files/download-url",
1018
+ {"name": "report.csv"},
1019
+ ),
1020
+ (
1021
+ "agent_runs/run42/report.csv",
1022
+ "GET",
1023
+ "/automation-runs/run42/files/download-url",
1024
+ {"name": "report.csv"},
1025
+ ),
1026
+ (
1027
+ "pb/docs/rec1/agent_runs/f.txt",
1028
+ "POST",
1029
+ "/pb/uploads/download",
1030
+ {"object_key": "pb/docs/rec1/agent_runs/f.txt"},
1031
+ ),
1032
+ ],
1033
+ )
1034
+ def test_storage_get_download_url_routes_by_key(
1035
+ monkeypatch: pytest.MonkeyPatch,
1036
+ object_key: str,
1037
+ method: str,
1038
+ path: str,
1039
+ sent: dict[str, str],
1040
+ ) -> None:
1041
+ import lumera.storage as storage
1042
+
1043
+ calls: list[tuple[str, str, object]] = []
1044
+
1045
+ class _Resp:
1046
+ def raise_for_status(self) -> None:
1047
+ pass
1048
+
1049
+ def json(self) -> dict[str, str]:
1050
+ return {"download_url": "https://bucket.test/signed"}
1051
+
1052
+ class _Session:
1053
+ def get(self, url: str, **kwargs: object) -> _Resp:
1054
+ calls.append(("GET", url, kwargs.get("params")))
1055
+ return _Resp()
1056
+
1057
+ def post(self, url: str, **kwargs: object) -> _Resp:
1058
+ calls.append(("POST", url, kwargs.get("json")))
1059
+ return _Resp()
1060
+
1061
+ monkeypatch.setenv(sdk.TOKEN_ENV, "tok")
1062
+ monkeypatch.setattr(storage, "_get_session", lambda: _Session())
1063
+
1064
+ assert storage.get_download_url(object_key) == "https://bucket.test/signed"
1065
+ assert calls == [(method, storage.API_BASE + path, sent)]
1066
+
1067
+
996
1068
  def test_storage_download_error_hides_presigned_url(monkeypatch: pytest.MonkeyPatch) -> None:
997
1069
  import lumera.storage as storage
998
1070
 
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
File without changes
File without changes