@seamapi/nextlove-sdk-generator 1.8.5 → 1.10.0

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 (45) hide show
  1. package/lib/generate-python-sdk/class-file.js +2 -2
  2. package/lib/generate-python-sdk/class-file.js.map +1 -1
  3. package/lib/generate-python-sdk/generate-python-sdk.js +11 -2
  4. package/lib/generate-python-sdk/generate-python-sdk.js.map +1 -1
  5. package/lib/generate-python-sdk/templates/__init__.py.template.js +8 -2
  6. package/lib/generate-python-sdk/templates/__init__.py.template.js.map +1 -1
  7. package/lib/generate-python-sdk/templates/auth.py.template.d.ts +2 -0
  8. package/lib/generate-python-sdk/templates/auth.py.template.js +103 -0
  9. package/lib/generate-python-sdk/templates/auth.py.template.js.map +1 -0
  10. package/lib/generate-python-sdk/templates/conftest.py.template.js +8 -17
  11. package/lib/generate-python-sdk/templates/conftest.py.template.js.map +1 -1
  12. package/lib/generate-python-sdk/templates/parse_options.py.template.d.ts +2 -0
  13. package/lib/generate-python-sdk/templates/parse_options.py.template.js +91 -0
  14. package/lib/generate-python-sdk/templates/parse_options.py.template.js.map +1 -0
  15. package/lib/generate-python-sdk/templates/routes.py.template.js +0 -3
  16. package/lib/generate-python-sdk/templates/routes.py.template.js.map +1 -1
  17. package/lib/generate-python-sdk/templates/seam.py.template.js +55 -36
  18. package/lib/generate-python-sdk/templates/seam.py.template.js.map +1 -1
  19. package/lib/generate-python-sdk/templates/snippets/abstract-routes.template.js +1 -4
  20. package/lib/generate-python-sdk/templates/snippets/abstract-routes.template.js.map +1 -1
  21. package/lib/generate-python-sdk/templates/snippets/abstract-seam.template.js +34 -9
  22. package/lib/generate-python-sdk/templates/snippets/abstract-seam.template.js.map +1 -1
  23. package/lib/generate-python-sdk/templates/token.py.template.d.ts +2 -0
  24. package/lib/generate-python-sdk/templates/token.py.template.js +49 -0
  25. package/lib/generate-python-sdk/templates/token.py.template.js.map +1 -0
  26. package/lib/generate-python-sdk/templates/utils/action-attempt.d.ts +1 -0
  27. package/lib/generate-python-sdk/templates/utils/action-attempt.js +9 -2
  28. package/lib/generate-python-sdk/templates/utils/action-attempt.js.map +1 -1
  29. package/lib/generate-python-sdk/templates/utils/action_attempt_errors.py.template.d.ts +2 -0
  30. package/lib/generate-python-sdk/templates/utils/action_attempt_errors.py.template.js +24 -0
  31. package/lib/generate-python-sdk/templates/utils/action_attempt_errors.py.template.js.map +1 -0
  32. package/package.json +1 -1
  33. package/src/lib/generate-python-sdk/class-file.ts +2 -1
  34. package/src/lib/generate-python-sdk/generate-python-sdk.ts +11 -2
  35. package/src/lib/generate-python-sdk/templates/__init__.py.template.ts +8 -2
  36. package/src/lib/generate-python-sdk/templates/auth.py.template.ts +102 -0
  37. package/src/lib/generate-python-sdk/templates/conftest.py.template.ts +8 -17
  38. package/src/lib/generate-python-sdk/templates/parse_options.py.template.ts +90 -0
  39. package/src/lib/generate-python-sdk/templates/routes.py.template.ts +0 -3
  40. package/src/lib/generate-python-sdk/templates/seam.py.template.ts +55 -36
  41. package/src/lib/generate-python-sdk/templates/snippets/abstract-routes.template.ts +1 -4
  42. package/src/lib/generate-python-sdk/templates/snippets/abstract-seam.template.ts +34 -9
  43. package/src/lib/generate-python-sdk/templates/token.py.template.ts +48 -0
  44. package/src/lib/generate-python-sdk/templates/utils/action-attempt.ts +10 -2
  45. package/src/lib/generate-python-sdk/templates/utils/action_attempt_errors.py.template.ts +23 -0
@@ -0,0 +1,48 @@
1
+ export default () => `token_prefix = "seam_"
2
+
3
+ access_token_prefix = "seam_at"
4
+
5
+ jwt_prefix = "ey"
6
+
7
+ client_session_token_prefix = "seam_cst"
8
+
9
+ publishable_key_token_prefix = "seam_pk"
10
+
11
+
12
+ def is_access_token(token: str) -> bool:
13
+ return token.startswith(access_token_prefix)
14
+
15
+
16
+ def is_jwt(token: str) -> bool:
17
+ return token.startswith(jwt_prefix)
18
+
19
+
20
+ def is_seam_token(token: str) -> bool:
21
+ return token.startswith(token_prefix)
22
+
23
+
24
+ def is_api_key(token: str) -> bool:
25
+ return (
26
+ not is_client_session_token(token)
27
+ and not is_jwt(token)
28
+ and not is_access_token(token)
29
+ and not is_publishable_key(token)
30
+ and is_seam_token(token)
31
+ )
32
+
33
+
34
+ def is_client_session_token(token: str) -> bool:
35
+ return token.startswith(client_session_token_prefix)
36
+
37
+
38
+ def is_publishable_key(token: str) -> bool:
39
+ return token.startswith(publishable_key_token_prefix)
40
+
41
+
42
+ def is_console_session_token(token: str) -> bool:
43
+ return is_jwt(token)
44
+
45
+
46
+ def is_personal_access_token(token: str) -> bool:
47
+ return is_access_token(token)
48
+ `
@@ -47,14 +47,14 @@ export const action_attempt_utils_definitions = [
47
47
  " time_waiting += polling_interval",
48
48
  "",
49
49
  " if time_waiting > timeout:",
50
- " raise Exception('Timed out waiting for action attempt to be ready')",
50
+ " raise SeamActionAttemptTimeoutError(action_attempt, timeout)",
51
51
  "",
52
52
  " action_attempt = seam.action_attempts.get(",
53
53
  " action_attempt_id=action_attempt.action_attempt_id, wait_for_action_attempt=False",
54
54
  " )",
55
55
  "",
56
56
  " if action_attempt.status == 'failed':",
57
- " raise Exception(f'Action Attempt failed: {action_attempt.error.message}')",
57
+ " raise SeamActionAttemptFailedError(action_attempt)",
58
58
  "",
59
59
  " return action_attempt",
60
60
  "",
@@ -68,3 +68,11 @@ export const action_attempt_utils_definitions = [
68
68
  "",
69
69
  " return action_attempt",
70
70
  ].join("\n")
71
+
72
+ export const action_attempt_imports = `import time
73
+
74
+ from seam.utils.action_attempt_errors import (
75
+ SeamActionAttemptFailedError,
76
+ SeamActionAttemptTimeoutError,
77
+ )
78
+ `
@@ -0,0 +1,23 @@
1
+ export default () => `from seam.types import ActionAttempt
2
+
3
+
4
+ class SeamActionAttemptError(Exception):
5
+ def __init__(self, message: str, action_attempt: ActionAttempt):
6
+ super().__init__(message)
7
+ self.name = self.__class__.__name__
8
+ self.action_attempt = action_attempt
9
+
10
+
11
+ class SeamActionAttemptFailedError(SeamActionAttemptError):
12
+ def __init__(self, action_attempt: ActionAttempt):
13
+ super().__init__(action_attempt.error.message, action_attempt)
14
+ self.name = self.__class__.__name__
15
+ self.code = action_attempt.error.type
16
+
17
+
18
+ class SeamActionAttemptTimeoutError(SeamActionAttemptError):
19
+ def __init__(self, action_attempt: ActionAttempt, timeout: str):
20
+ message = f"Timed out waiting for action attempt after {timeout}s"
21
+ super().__init__(message, action_attempt)
22
+ self.name = self.__class__.__name__
23
+ `