@seamapi/nextlove-sdk-generator 1.15.1 → 1.15.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.
@@ -9,6 +9,11 @@ use Seam\\Utils\\PackageVersion;
9
9
 
10
10
  use GuzzleHttp\\Client as HTTPClient;
11
11
  use \\Exception as Exception;
12
+ use Seam\\HttpApiError;
13
+ use Seam\\HttpUnauthorizedError;
14
+ use Seam\\HttpInvalidInputError;
15
+ use Seam\\ActionAttemptFailedError;
16
+ use Seam\\ActionAttemptTimeoutError;
12
17
 
13
18
  define('LTS_VERSION', '1.0.0');
14
19
 
@@ -57,12 +62,12 @@ class SeamClient
57
62
  "json" => $json,
58
63
  "query" => $query,
59
64
  ];
60
- $options = array_filter($options, fn ($option) => $option !== null);
65
+ $options = array_filter($options, fn($option) => $option !== null);
61
66
 
62
67
  // TODO handle request errors
63
68
  $response = $this->client->request($method, $path, $options);
64
69
  $status_code = $response->getStatusCode();
65
- $request_id = $response->getHeaderLine('seam-request-id');
70
+ $request_id = $response->getHeaderLine("seam-request-id");
66
71
 
67
72
  $res_json = null;
68
73
  try {
@@ -70,44 +75,26 @@ class SeamClient
70
75
  } catch (Exception $ignoreError) {
71
76
  }
72
77
 
73
- if (($res_json->error ?? null) != null) {
74
- throw new Exception(
75
- "Error Calling \\"" .
76
- $method .
77
- " " .
78
- $path .
79
- "\\" : " .
80
- ($res_json->error->type ?? "") .
81
- ": " .
82
- $res_json->error->message .
83
- " [Request ID: " . $request_id . "]"
84
- );
85
- }
86
-
87
78
  if ($status_code >= 400) {
88
- $error_message = $response->getReasonPhrase();
79
+ if ($status_code === 401) {
80
+ throw new HttpUnauthorizedError($request_id);
81
+ }
89
82
 
90
- throw new Exception(
91
- "HTTP Error: " . $error_message . " [" . $status_code . "] " . $method . " " . $path .
92
- " [Request ID: " . $request_id . "]"
93
- );
94
- }
83
+ if (($res_json->error ?? null) != null) {
84
+ if ($res_json->error->type === 'invalid_input') {
85
+ throw new HttpInvalidInputError($res_json->error, $status_code, $request_id);
86
+ }
95
87
 
96
- if ($inner_object) {
97
- if (!is_array($res_json->$inner_object) && ($res_json->$inner_object ?? null) == null) {
98
- throw new Exception(
99
- 'Missing Inner Object "' .
100
- $inner_object .
101
- '" for ' .
102
- $method .
103
- " " .
104
- $path .
105
- " [Request ID: " . $request_id . "]"
106
- );
88
+ throw new HttpApiError($res_json->error, $status_code, $request_id);
107
89
  }
108
- return $res_json->$inner_object;
90
+
91
+ throw \GuzzleHttp\Exception\RequestException::create(
92
+ new \GuzzleHttp\Psr7\Request($method, $path),
93
+ $response
94
+ );
109
95
  }
110
- return $res_json;
96
+
97
+ return $inner_object ? $res_json->$inner_object : $res_json;
111
98
  }
112
99
  }
113
100
 
@@ -1 +1 @@
1
- {"version":3,"file":"generate-seam-client.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/generate-seam-client.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,gBAAgB,EAChB,qBAAqB,GACd,EAAE,EAAE;IACX,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,MAAM,CACrD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAC1B,CAAA;IAED,OAAO;;;;EAIP,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;IAUrE,uBAAuB;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,WAAW,WAAW,CAAC,CAAC,SAAS,GAAG,CAAC;SAC5D,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;MAyBX,uBAAuB;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,WAAW,g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C,IAAI,CAAC,MAAM,CAAC;CACxD,CAAA;AACD,CAAC,CAAA"}
@@ -96,27 +96,26 @@ export class PhpClient {
96
96
  }),
97
97
  this.client_name === "ActionAttempts"
98
98
  ? [
99
- " public function poll_until_ready(string $action_attempt_id): ActionAttempt",
99
+ " public function poll_until_ready(string $action_attempt_id, float $timeout = 20.0): ActionAttempt",
100
100
  " {",
101
101
  " $seam = $this->seam;",
102
102
  " $time_waiting = 0.0;",
103
+ " $polling_interval = 0.4;",
103
104
  " $action_attempt = $seam->action_attempts->get($action_attempt_id);",
104
105
  "",
105
- ' while ($action_attempt->status == "pending") {',
106
+ " while ($action_attempt->status == 'pending') {",
106
107
  " $action_attempt = $seam->action_attempts->get(",
107
108
  " $action_attempt->action_attempt_id",
108
109
  " );",
109
- " if ($time_waiting > 20.0) {",
110
- ' throw new Exception("Timed out waiting for action attempt to be ready");',
110
+ " if ($time_waiting > $timeout) {",
111
+ " throw new ActionAttemptTimeoutError($action_attempt, $timeout);",
111
112
  " }",
112
- " $time_waiting += 0.4;",
113
- " usleep(400000); // sleep for 0.4 seconds",
113
+ " $time_waiting += $polling_interval;",
114
+ " usleep($polling_interval * 1000000);",
114
115
  " }",
115
116
  "",
116
- ' if ($action_attempt->status == "failed") {',
117
- " throw new Exception(",
118
- ' "Action Attempt failed: " . $action_attempt->error->message',
119
- " );",
117
+ " if ($action_attempt->status == 'error') {",
118
+ " throw new ActionAttemptFailedError($action_attempt);",
120
119
  " }",
121
120
  "",
122
121
  " return $action_attempt;",
@@ -1 +1 @@
1
- {"version":3,"file":"php-client.js","sourceRoot":"","sources":["../../../src/lib/generate-php-sdk/utils/php-client.ts"],"names":[],"mappings":"AAuBA,MAAM,OAAO,SAAS;IAGpB,YACS,WAAuB,EACvB,SAAoB,EACpB,gBAAyB,EACzB,wBAA+C;QAH/C,gBAAW,GAAX,WAAW,CAAY;QACvB,cAAS,GAAT,SAAS,CAAW;QACpB,qBAAgB,GAAhB,gBAAgB,CAAS;QACzB,6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C/C,4DAA4D;oBAC5D,OAAO;oBACP,EAAE;oBACF,6BAA6B;oBAC7B,KAAK;iBACN,CAAC,IAAI,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,EAAE;YACN,GAAG;SACJ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACd,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamapi/nextlove-sdk-generator",
3
- "version": "1.15.1",
3
+ "version": "1.15.2",
4
4
  "description": "Utilities for building NextLove SDK Generators",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -22,6 +22,11 @@ use Seam\\Utils\\PackageVersion;
22
22
 
23
23
  use GuzzleHttp\\Client as HTTPClient;
24
24
  use \\Exception as Exception;
25
+ use Seam\\HttpApiError;
26
+ use Seam\\HttpUnauthorizedError;
27
+ use Seam\\HttpInvalidInputError;
28
+ use Seam\\ActionAttemptFailedError;
29
+ use Seam\\ActionAttemptTimeoutError;
25
30
 
26
31
  define('LTS_VERSION', '1.0.0');
27
32
 
@@ -70,12 +75,12 @@ class SeamClient
70
75
  "json" => $json,
71
76
  "query" => $query,
72
77
  ];
73
- $options = array_filter($options, fn ($option) => $option !== null);
78
+ $options = array_filter($options, fn($option) => $option !== null);
74
79
 
75
80
  // TODO handle request errors
76
81
  $response = $this->client->request($method, $path, $options);
77
82
  $status_code = $response->getStatusCode();
78
- $request_id = $response->getHeaderLine('seam-request-id');
83
+ $request_id = $response->getHeaderLine("seam-request-id");
79
84
 
80
85
  $res_json = null;
81
86
  try {
@@ -83,44 +88,26 @@ class SeamClient
83
88
  } catch (Exception $ignoreError) {
84
89
  }
85
90
 
86
- if (($res_json->error ?? null) != null) {
87
- throw new Exception(
88
- "Error Calling \\"" .
89
- $method .
90
- " " .
91
- $path .
92
- "\\" : " .
93
- ($res_json->error->type ?? "") .
94
- ": " .
95
- $res_json->error->message .
96
- " [Request ID: " . $request_id . "]"
97
- );
98
- }
99
-
100
91
  if ($status_code >= 400) {
101
- $error_message = $response->getReasonPhrase();
92
+ if ($status_code === 401) {
93
+ throw new HttpUnauthorizedError($request_id);
94
+ }
102
95
 
103
- throw new Exception(
104
- "HTTP Error: " . $error_message . " [" . $status_code . "] " . $method . " " . $path .
105
- " [Request ID: " . $request_id . "]"
106
- );
107
- }
96
+ if (($res_json->error ?? null) != null) {
97
+ if ($res_json->error->type === 'invalid_input') {
98
+ throw new HttpInvalidInputError($res_json->error, $status_code, $request_id);
99
+ }
108
100
 
109
- if ($inner_object) {
110
- if (!is_array($res_json->$inner_object) && ($res_json->$inner_object ?? null) == null) {
111
- throw new Exception(
112
- 'Missing Inner Object "' .
113
- $inner_object .
114
- '" for ' .
115
- $method .
116
- " " .
117
- $path .
118
- " [Request ID: " . $request_id . "]"
119
- );
101
+ throw new HttpApiError($res_json->error, $status_code, $request_id);
120
102
  }
121
- return $res_json->$inner_object;
103
+
104
+ throw \GuzzleHttp\Exception\RequestException::create(
105
+ new \GuzzleHttp\Psr7\Request($method, $path),
106
+ $response
107
+ );
122
108
  }
123
- return $res_json;
109
+
110
+ return $inner_object ? $res_json->$inner_object : $res_json;
124
111
  }
125
112
  }
126
113
 
@@ -156,27 +156,26 @@ export class PhpClient {
156
156
  ),
157
157
  this.client_name === "ActionAttempts"
158
158
  ? [
159
- " public function poll_until_ready(string $action_attempt_id): ActionAttempt",
159
+ " public function poll_until_ready(string $action_attempt_id, float $timeout = 20.0): ActionAttempt",
160
160
  " {",
161
161
  " $seam = $this->seam;",
162
162
  " $time_waiting = 0.0;",
163
+ " $polling_interval = 0.4;",
163
164
  " $action_attempt = $seam->action_attempts->get($action_attempt_id);",
164
165
  "",
165
- ' while ($action_attempt->status == "pending") {',
166
+ " while ($action_attempt->status == 'pending') {",
166
167
  " $action_attempt = $seam->action_attempts->get(",
167
168
  " $action_attempt->action_attempt_id",
168
169
  " );",
169
- " if ($time_waiting > 20.0) {",
170
- ' throw new Exception("Timed out waiting for action attempt to be ready");',
170
+ " if ($time_waiting > $timeout) {",
171
+ " throw new ActionAttemptTimeoutError($action_attempt, $timeout);",
171
172
  " }",
172
- " $time_waiting += 0.4;",
173
- " usleep(400000); // sleep for 0.4 seconds",
173
+ " $time_waiting += $polling_interval;",
174
+ " usleep($polling_interval * 1000000);",
174
175
  " }",
175
176
  "",
176
- ' if ($action_attempt->status == "failed") {',
177
- " throw new Exception(",
178
- ' "Action Attempt failed: " . $action_attempt->error->message',
179
- " );",
177
+ " if ($action_attempt->status == 'error') {",
178
+ " throw new ActionAttemptFailedError($action_attempt);",
180
179
  " }",
181
180
  "",
182
181
  " return $action_attempt;",