@seamapi/http 2.23.2 → 2.23.4

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.
package/README.md CHANGED
@@ -538,6 +538,12 @@ console.log(`${request.method} ${request.url}`, JSON.stringify(request.body))
538
538
  const devices = await request.execute()
539
539
  ```
540
540
 
541
+ A `SeamHttpRequest` is sent at most once.
542
+ Awaiting the same request again,
543
+ or calling `execute`, `then`, `catch`, or `finally` more than once,
544
+ always returns the result of the first execution
545
+ and never repeats the HTTP request.
546
+
541
547
  #### Serializing URL search params
542
548
 
543
549
  The Seam API parses URL search params as complex types.
@@ -26,6 +26,11 @@ interface SeamHttpRequestConfig<TResponseKey> {
26
26
  * The request is sent once `execute` is called,
27
27
  * or when the request is awaited like a Promise,
28
28
  * e.g., with `await`, `then`, `catch`, or `finally`.
29
+ * The request is sent at most once:
30
+ * awaiting the same SeamHttpRequest again,
31
+ * or calling `execute`, `then`, `catch`, or `finally` more than once,
32
+ * always returns the result of the first execution
33
+ * and never repeats the HTTP request.
29
34
  * When the response contains an action attempt,
30
35
  * awaiting the request also waits for the action attempt to resolve
31
36
  * according to the `waitForActionAttempt` option.
@@ -56,11 +61,17 @@ export declare class SeamHttpRequest<const TResponse, const TResponseKey extends
56
61
  * If the response contains an action attempt,
57
62
  * waits for the action attempt to resolve
58
63
  * according to the `waitForActionAttempt` option.
64
+ * The request is sent at most once:
65
+ * calling this method again returns the result of the first call
66
+ * and never repeats the HTTP request.
59
67
  */
60
68
  execute(): Promise<TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined>;
61
69
  /**
62
70
  * Sends the request and returns the entire response body
63
71
  * without waiting for any action attempt to resolve.
72
+ * The request is sent at most once:
73
+ * calling this method again returns the result of the first call
74
+ * and never repeats the HTTP request.
64
75
  */
65
76
  fetchResponse(): Promise<TResponse>;
66
77
  then<TResult1 = TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined, TResult2 = never>(onfulfilled?: ((value: TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
@@ -9,6 +9,11 @@ import { serializeUrlSearchParams } from './url-search-params-serializer.js';
9
9
  * The request is sent once `execute` is called,
10
10
  * or when the request is awaited like a Promise,
11
11
  * e.g., with `await`, `then`, `catch`, or `finally`.
12
+ * The request is sent at most once:
13
+ * awaiting the same SeamHttpRequest again,
14
+ * or calling `execute`, `then`, `catch`, or `finally` more than once,
15
+ * always returns the result of the first execution
16
+ * and never repeats the HTTP request.
12
17
  * When the response contains an action attempt,
13
18
  * awaiting the request also waits for the action attempt to resolve
14
19
  * according to the `waitForActionAttempt` option.
@@ -20,6 +25,8 @@ export class SeamHttpRequest {
20
25
  [Symbol.toStringTag] = 'SeamHttpRequest';
21
26
  #parent;
22
27
  #config;
28
+ #executePromise = null;
29
+ #fetchResponsePromise = null;
23
30
  constructor(parent, config) {
24
31
  this.#parent = parent;
25
32
  this.#config = config;
@@ -67,8 +74,15 @@ export class SeamHttpRequest {
67
74
  * If the response contains an action attempt,
68
75
  * waits for the action attempt to resolve
69
76
  * according to the `waitForActionAttempt` option.
77
+ * The request is sent at most once:
78
+ * calling this method again returns the result of the first call
79
+ * and never repeats the HTTP request.
70
80
  */
71
81
  async execute() {
82
+ this.#executePromise ??= this.#execute();
83
+ return await this.#executePromise;
84
+ }
85
+ async #execute() {
72
86
  const response = await this.fetchResponse();
73
87
  if (this.responseKey === undefined) {
74
88
  return undefined;
@@ -90,8 +104,15 @@ export class SeamHttpRequest {
90
104
  /**
91
105
  * Sends the request and returns the entire response body
92
106
  * without waiting for any action attempt to resolve.
107
+ * The request is sent at most once:
108
+ * calling this method again returns the result of the first call
109
+ * and never repeats the HTTP request.
93
110
  */
94
111
  async fetchResponse() {
112
+ this.#fetchResponsePromise ??= this.#fetchResponse();
113
+ return await this.#fetchResponsePromise;
114
+ }
115
+ async #fetchResponse() {
95
116
  assertValidRequestParameters(this.#config.parameters, this.pathname, this.#config.hasRequiredParameters ?? false, this.#config.requiredParameterNames ?? []);
96
117
  const { client } = this.#parent;
97
118
  const response = await client.request({
@@ -1 +1 @@
1
- {"version":3,"file":"seam-http-request.js","sourceRoot":"","sources":["../src/lib/seam-http-request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AACtE,OAAO,EAEL,oBAAoB,GACrB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAqB5E;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,eAAe;IAMjB,CAAC,MAAM,CAAC,WAAW,CAAC,GAAW,iBAAiB,CAAA;IAEhD,OAAO,CAAuB;IAC9B,OAAO,CAAqC;IAErD,YACE,MAA6B,EAC7B,MAA2C;QAE3C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAED;;;OAGG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAA;IACjC,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,KAAK,CAAA;IAC5C,CAAC;IAED;;OAEG;IACH,IAAW,GAAG;QACZ,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAE/B,MAAM,UAAU,GACd,OAAO,MAAM,CAAC,QAAQ,CAAC,gBAAgB,KAAK,UAAU;YACpD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB;YAClC,CAAC,CAAC,wBAAwB,CAAA;QAE9B,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,OAA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C,KAAa,EAAW,EAAE;IACnD,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QACnC,OAAO,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,QAAQ,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const seamapiJavascriptHttpVersion = "2.23.2";
1
+ declare const seamapiJavascriptHttpVersion = "2.23.4";
2
2
  export default seamapiJavascriptHttpVersion;
package/lib/version.js CHANGED
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '2.23.2';
1
+ const seamapiJavascriptHttpVersion = '2.23.4';
2
2
  export default seamapiJavascriptHttpVersion;
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamapi/http",
3
- "version": "2.23.2",
3
+ "version": "2.23.4",
4
4
  "description": "JavaScript HTTP client for the Seam API written in TypeScript.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -8,7 +8,7 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./index.d.ts",
11
- "import": "./index.js"
11
+ "default": "./index.js"
12
12
  },
13
13
  "./connect": {
14
14
  "types": "./index.d.ts",
@@ -37,6 +37,11 @@ interface SeamHttpRequestConfig<TResponseKey> {
37
37
  * The request is sent once `execute` is called,
38
38
  * or when the request is awaited like a Promise,
39
39
  * e.g., with `await`, `then`, `catch`, or `finally`.
40
+ * The request is sent at most once:
41
+ * awaiting the same SeamHttpRequest again,
42
+ * or calling `execute`, `then`, `catch`, or `finally` more than once,
43
+ * always returns the result of the first execution
44
+ * and never repeats the HTTP request.
40
45
  * When the response contains an action attempt,
41
46
  * awaiting the request also waits for the action attempt to resolve
42
47
  * according to the `waitForActionAttempt` option.
@@ -55,6 +60,12 @@ export class SeamHttpRequest<
55
60
  readonly #parent: SeamHttpRequestParent
56
61
  readonly #config: SeamHttpRequestConfig<TResponseKey>
57
62
 
63
+ #executePromise: Promise<
64
+ TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
65
+ > | null = null
66
+
67
+ #fetchResponsePromise: Promise<TResponse> | null = null
68
+
58
69
  constructor(
59
70
  parent: SeamHttpRequestParent,
60
71
  config: SeamHttpRequestConfig<TResponseKey>,
@@ -119,9 +130,19 @@ export class SeamHttpRequest<
119
130
  * If the response contains an action attempt,
120
131
  * waits for the action attempt to resolve
121
132
  * according to the `waitForActionAttempt` option.
133
+ * The request is sent at most once:
134
+ * calling this method again returns the result of the first call
135
+ * and never repeats the HTTP request.
122
136
  */
123
137
  async execute(): Promise<
124
138
  TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
139
+ > {
140
+ this.#executePromise ??= this.#execute()
141
+ return await this.#executePromise
142
+ }
143
+
144
+ async #execute(): Promise<
145
+ TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
125
146
  > {
126
147
  const response = await this.fetchResponse()
127
148
 
@@ -165,8 +186,16 @@ export class SeamHttpRequest<
165
186
  /**
166
187
  * Sends the request and returns the entire response body
167
188
  * without waiting for any action attempt to resolve.
189
+ * The request is sent at most once:
190
+ * calling this method again returns the result of the first call
191
+ * and never repeats the HTTP request.
168
192
  */
169
193
  async fetchResponse(): Promise<TResponse> {
194
+ this.#fetchResponsePromise ??= this.#fetchResponse()
195
+ return await this.#fetchResponsePromise
196
+ }
197
+
198
+ async #fetchResponse(): Promise<TResponse> {
170
199
  assertValidRequestParameters(
171
200
  this.#config.parameters,
172
201
  this.pathname,
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '2.23.2'
1
+ const seamapiJavascriptHttpVersion = '2.23.4'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion