@papr/memory 1.9.0 → 1.13.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 (83) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +11 -9
  3. package/client.d.mts +23 -11
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +23 -11
  6. package/client.d.ts.map +1 -1
  7. package/client.js +41 -21
  8. package/client.js.map +1 -1
  9. package/client.mjs +41 -21
  10. package/client.mjs.map +1 -1
  11. package/internal/request-options.d.mts +42 -0
  12. package/internal/request-options.d.mts.map +1 -1
  13. package/internal/request-options.d.ts +42 -0
  14. package/internal/request-options.d.ts.map +1 -1
  15. package/internal/request-options.js.map +1 -1
  16. package/internal/request-options.mjs.map +1 -1
  17. package/internal/uploads.js +1 -1
  18. package/internal/uploads.js.map +1 -1
  19. package/internal/uploads.mjs +1 -1
  20. package/internal/uploads.mjs.map +1 -1
  21. package/internal/utils/log.d.mts.map +1 -1
  22. package/internal/utils/log.d.ts.map +1 -1
  23. package/internal/utils/log.js +4 -3
  24. package/internal/utils/log.js.map +1 -1
  25. package/internal/utils/log.mjs +4 -3
  26. package/internal/utils/log.mjs.map +1 -1
  27. package/internal/utils/path.d.mts.map +1 -1
  28. package/internal/utils/path.d.ts.map +1 -1
  29. package/internal/utils/path.js +26 -5
  30. package/internal/utils/path.js.map +1 -1
  31. package/internal/utils/path.mjs +26 -5
  32. package/internal/utils/path.mjs.map +1 -1
  33. package/package.json +1 -1
  34. package/resources/feedback.d.mts +333 -0
  35. package/resources/feedback.d.mts.map +1 -0
  36. package/resources/feedback.d.ts +333 -0
  37. package/resources/feedback.d.ts.map +1 -0
  38. package/resources/feedback.js +108 -0
  39. package/resources/feedback.js.map +1 -0
  40. package/resources/feedback.mjs +104 -0
  41. package/resources/feedback.mjs.map +1 -0
  42. package/resources/index.d.mts +2 -1
  43. package/resources/index.d.mts.map +1 -1
  44. package/resources/index.d.ts +2 -1
  45. package/resources/index.d.ts.map +1 -1
  46. package/resources/index.js +3 -1
  47. package/resources/index.js.map +1 -1
  48. package/resources/index.mjs +1 -0
  49. package/resources/index.mjs.map +1 -1
  50. package/resources/memory.d.mts +48 -11
  51. package/resources/memory.d.mts.map +1 -1
  52. package/resources/memory.d.ts +48 -11
  53. package/resources/memory.d.ts.map +1 -1
  54. package/resources/memory.js +11 -0
  55. package/resources/memory.js.map +1 -1
  56. package/resources/memory.mjs +11 -0
  57. package/resources/memory.mjs.map +1 -1
  58. package/resources/user.d.mts +24 -88
  59. package/resources/user.d.mts.map +1 -1
  60. package/resources/user.d.ts +24 -88
  61. package/resources/user.d.ts.map +1 -1
  62. package/resources/user.js +17 -56
  63. package/resources/user.js.map +1 -1
  64. package/resources/user.mjs +17 -56
  65. package/resources/user.mjs.map +1 -1
  66. package/src/client.ts +74 -28
  67. package/src/internal/request-options.ts +53 -0
  68. package/src/internal/uploads.ts +1 -1
  69. package/src/internal/utils/log.ts +3 -2
  70. package/src/internal/utils/path.ts +32 -7
  71. package/src/resources/feedback.ts +424 -0
  72. package/src/resources/index.ts +9 -1
  73. package/src/resources/memory.ts +44 -11
  74. package/src/resources/user.ts +29 -130
  75. package/src/version.ts +1 -1
  76. package/version.d.mts +1 -1
  77. package/version.d.mts.map +1 -1
  78. package/version.d.ts +1 -1
  79. package/version.d.ts.map +1 -1
  80. package/version.js +1 -1
  81. package/version.js.map +1 -1
  82. package/version.mjs +1 -1
  83. package/version.mjs.map +1 -1
@@ -1,6 +1,5 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
  import { APIResource } from "../core/resource.mjs";
3
- import { buildHeaders } from "../internal/headers.mjs";
4
3
  import { path } from "../internal/utils/path.mjs";
5
4
  export class User extends APIResource {
6
5
  /**
@@ -10,53 +9,33 @@ export class User extends APIResource {
10
9
  * ```ts
11
10
  * const userResponse = await client.user.create({
12
11
  * external_id: 'user123',
13
- * 'X-API-Key': 'X-API-Key',
14
12
  * });
15
13
  * ```
16
14
  */
17
- create(params, options) {
18
- const { 'X-API-Key': xAPIKey, ...body } = params;
19
- return this._client.post('/v1/user', {
20
- body,
21
- ...options,
22
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
23
- });
15
+ create(body, options) {
16
+ return this._client.post('/v1/user', { body, ...options });
24
17
  }
25
18
  /**
26
19
  * Update user details by user_id (\_User.objectId) and developer association
27
20
  *
28
21
  * @example
29
22
  * ```ts
30
- * const userResponse = await client.user.update('user_id', {
31
- * 'X-API-Key': 'X-API-Key',
32
- * });
23
+ * const userResponse = await client.user.update('user_id');
33
24
  * ```
34
25
  */
35
- update(userID, params, options) {
36
- const { 'X-API-Key': xAPIKey, ...body } = params;
37
- return this._client.put(path `/v1/user/${userID}`, {
38
- body,
39
- ...options,
40
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
41
- });
26
+ update(userID, body, options) {
27
+ return this._client.put(path `/v1/user/${userID}`, { body, ...options });
42
28
  }
43
29
  /**
44
30
  * List users for a developer
45
31
  *
46
32
  * @example
47
33
  * ```ts
48
- * const users = await client.user.list({
49
- * 'X-API-Key': 'X-API-Key',
50
- * });
34
+ * const users = await client.user.list();
51
35
  * ```
52
36
  */
53
- list(params, options) {
54
- const { 'X-API-Key': xAPIKey, ...query } = params;
55
- return this._client.get('/v1/user', {
56
- query,
57
- ...options,
58
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
59
- });
37
+ list(query = {}, options) {
38
+ return this._client.get('/v1/user', { query, ...options });
60
39
  }
61
40
  /**
62
41
  * Delete user association with developer and the user itself by , assume external
@@ -64,18 +43,12 @@ export class User extends APIResource {
64
43
  *
65
44
  * @example
66
45
  * ```ts
67
- * const user = await client.user.delete('user_id', {
68
- * 'X-API-Key': 'X-API-Key',
69
- * });
46
+ * const user = await client.user.delete('user_id');
70
47
  * ```
71
48
  */
72
- delete(userID, params, options) {
73
- const { 'X-API-Key': xAPIKey, is_external } = params;
74
- return this._client.delete(path `/v1/user/${userID}`, {
75
- query: { is_external },
76
- ...options,
77
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
78
- });
49
+ delete(userID, params = {}, options) {
50
+ const { is_external } = params ?? {};
51
+ return this._client.delete(path `/v1/user/${userID}`, { query: { is_external }, ...options });
79
52
  }
80
53
  /**
81
54
  * Create multiple users or link existing users to developer, and add each to the
@@ -85,34 +58,22 @@ export class User extends APIResource {
85
58
  * ```ts
86
59
  * const response = await client.user.createBatch({
87
60
  * users: [{ external_id: 'user123' }],
88
- * 'X-API-Key': 'X-API-Key',
89
61
  * });
90
62
  * ```
91
63
  */
92
- createBatch(params, options) {
93
- const { 'X-API-Key': xAPIKey, ...body } = params;
94
- return this._client.post('/v1/user/batch', {
95
- body,
96
- ...options,
97
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
98
- });
64
+ createBatch(body, options) {
65
+ return this._client.post('/v1/user/batch', { body, ...options });
99
66
  }
100
67
  /**
101
68
  * Get user details by user_id (\_User.objectId) and developer association
102
69
  *
103
70
  * @example
104
71
  * ```ts
105
- * const userResponse = await client.user.get('user_id', {
106
- * 'X-API-Key': 'X-API-Key',
107
- * });
72
+ * const userResponse = await client.user.get('user_id');
108
73
  * ```
109
74
  */
110
- get(userID, params, options) {
111
- const { 'X-API-Key': xAPIKey } = params;
112
- return this._client.get(path `/v1/user/${userID}`, {
113
- ...options,
114
- headers: buildHeaders([{ 'X-API-Key': xAPIKey }, options?.headers]),
115
- });
75
+ get(userID, options) {
76
+ return this._client.get(path `/v1/user/${userID}`, options);
116
77
  }
117
78
  }
118
79
  //# sourceMappingURL=user.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.mjs","sourceRoot":"","sources":["../src/resources/user.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAGf,EAAE,YAAY,EAAE;OAEhB,EAAE,IAAI,EAAE;AAEf,MAAM,OAAO,IAAK,SAA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 import * as Errors from './core/error';
16
16
  import * as Uploads from './core/uploads';
17
17
  import * as API from './resources/index';
18
18
  import { APIPromise } from './core/api-promise';
19
+ import {
20
+ BatchRequest,
21
+ BatchResponse,
22
+ Feedback,
23
+ FeedbackRequest,
24
+ FeedbackResponse,
25
+ FeedbackSubmitBatchParams,
26
+ FeedbackSubmitParams,
27
+ } from './resources/feedback';
19
28
  import {
20
29
  AddMemory,
21
30
  AddMemoryResponse,
@@ -41,7 +50,6 @@ import {
41
50
  UserCreateParams,
42
51
  UserDeleteParams,
43
52
  UserDeleteResponse,
44
- UserGetParams,
45
53
  UserListParams,
46
54
  UserListResponse,
47
55
  UserResponse,
@@ -65,7 +73,12 @@ export interface ClientOptions {
65
73
  /**
66
74
  * Defaults to process.env['PAPR_MEMORY_API_KEY'].
67
75
  */
68
- apiKey?: string | undefined;
76
+ xAPIKey?: string | undefined;
77
+
78
+ /**
79
+ * Defaults to process.env['PAPR_MEMORY_Session_Token'].
80
+ */
81
+ xSessionToken?: string | null | undefined;
69
82
 
70
83
  /**
71
84
  * Defaults to process.env['PAPR_MEMORY_BEARER_TOKEN'].
@@ -85,6 +98,8 @@ export interface ClientOptions {
85
98
  *
86
99
  * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
87
100
  * much longer than this timeout before the promise succeeds or fails.
101
+ *
102
+ * @unit milliseconds
88
103
  */
89
104
  timeout?: number | undefined;
90
105
  /**
@@ -143,7 +158,8 @@ export interface ClientOptions {
143
158
  * API Client for interfacing with the Papr API.
144
159
  */
145
160
  export class Papr {
146
- apiKey: string;
161
+ xAPIKey: string;
162
+ xSessionToken: string | null;
147
163
  bearerToken: string | null;
148
164
 
149
165
  baseURL: string;
@@ -161,7 +177,8 @@ export class Papr {
161
177
  /**
162
178
  * API Client for interfacing with the Papr API.
163
179
  *
164
- * @param {string | undefined} [opts.apiKey=process.env['PAPR_MEMORY_API_KEY'] ?? undefined]
180
+ * @param {string | undefined} [opts.xAPIKey=process.env['PAPR_MEMORY_API_KEY'] ?? undefined]
181
+ * @param {string | null | undefined} [opts.xSessionToken=process.env['PAPR_MEMORY_Session_Token'] ?? null]
165
182
  * @param {string | null | undefined} [opts.bearerToken=process.env['PAPR_MEMORY_BEARER_TOKEN'] ?? null]
166
183
  * @param {string} [opts.baseURL=process.env['PAPR_BASE_URL'] ?? https://memory.papr.ai] - Override the default base URL for the API.
167
184
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
@@ -173,18 +190,20 @@ export class Papr {
173
190
  */
174
191
  constructor({
175
192
  baseURL = readEnv('PAPR_BASE_URL'),
176
- apiKey = readEnv('PAPR_MEMORY_API_KEY'),
193
+ xAPIKey = readEnv('PAPR_MEMORY_API_KEY'),
194
+ xSessionToken = readEnv('PAPR_MEMORY_Session_Token') ?? null,
177
195
  bearerToken = readEnv('PAPR_MEMORY_BEARER_TOKEN') ?? null,
178
196
  ...opts
179
197
  }: ClientOptions = {}) {
180
- if (apiKey === undefined) {
198
+ if (xAPIKey === undefined) {
181
199
  throw new Errors.PaprError(
182
- "The PAPR_MEMORY_API_KEY environment variable is missing or empty; either provide it, or instantiate the Papr client with an apiKey option, like new Papr({ apiKey: 'My API Key' }).",
200
+ "The PAPR_MEMORY_API_KEY environment variable is missing or empty; either provide it, or instantiate the Papr client with an xAPIKey option, like new Papr({ xAPIKey: 'My X API Key' }).",
183
201
  );
184
202
  }
185
203
 
186
204
  const options: ClientOptions = {
187
- apiKey,
205
+ xAPIKey,
206
+ xSessionToken,
188
207
  bearerToken,
189
208
  ...opts,
190
209
  baseURL: baseURL || `https://memory.papr.ai`,
@@ -207,7 +226,8 @@ export class Papr {
207
226
 
208
227
  this._options = options;
209
228
 
210
- this.apiKey = apiKey;
229
+ this.xAPIKey = xAPIKey;
230
+ this.xSessionToken = xSessionToken;
211
231
  this.bearerToken = bearerToken;
212
232
  }
213
233
 
@@ -215,7 +235,7 @@ export class Papr {
215
235
  * Create a new client instance re-using the same options given to the current client with optional overriding.
216
236
  */
217
237
  withOptions(options: Partial<ClientOptions>): this {
218
- return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
238
+ const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
219
239
  ...this._options,
220
240
  baseURL: this.baseURL,
221
241
  maxRetries: this.maxRetries,
@@ -224,10 +244,12 @@ export class Papr {
224
244
  logLevel: this.logLevel,
225
245
  fetch: this.fetch,
226
246
  fetchOptions: this.fetchOptions,
227
- apiKey: this.apiKey,
247
+ xAPIKey: this.xAPIKey,
248
+ xSessionToken: this.xSessionToken,
228
249
  bearerToken: this.bearerToken,
229
250
  ...options,
230
251
  });
252
+ return client;
231
253
  }
232
254
 
233
255
  /**
@@ -245,21 +267,32 @@ export class Papr {
245
267
  return;
246
268
  }
247
269
 
248
- protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
249
- return buildHeaders([this.apiKeyHeaderAuth(opts), this.bearerAuth(opts)]);
250
- }
251
-
252
- protected apiKeyHeaderAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
253
- return buildHeaders([{ 'X-Session-Token': this.apiKey }]);
270
+ protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
271
+ return buildHeaders([
272
+ await this.bearerAuth(opts),
273
+ await this.xSessionTokenAuth(opts),
274
+ await this.xAPIKeyAuth(opts),
275
+ ]);
254
276
  }
255
277
 
256
- protected bearerAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
278
+ protected async bearerAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
257
279
  if (this.bearerToken == null) {
258
280
  return undefined;
259
281
  }
260
282
  return buildHeaders([{ Authorization: `Bearer ${this.bearerToken}` }]);
261
283
  }
262
284
 
285
+ protected async xSessionTokenAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
286
+ if (this.xSessionToken == null) {
287
+ return undefined;
288
+ }
289
+ return buildHeaders([{ 'X-Session-Token': this.xSessionToken }]);
290
+ }
291
+
292
+ protected async xAPIKeyAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
293
+ return buildHeaders([{ 'X-API-Key': this.xAPIKey }]);
294
+ }
295
+
263
296
  /**
264
297
  * Basic re-implementation of `qs.stringify` for primitive types.
265
298
  */
@@ -388,7 +421,9 @@ export class Papr {
388
421
 
389
422
  await this.prepareOptions(options);
390
423
 
391
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
424
+ const { req, url, timeout } = await this.buildRequest(options, {
425
+ retryCount: maxRetries - retriesRemaining,
426
+ });
392
427
 
393
428
  await this.prepareRequest(req, { url, options });
394
429
 
@@ -466,7 +501,7 @@ export class Papr {
466
501
  } with status ${response.status} in ${headersTime - startTime}ms`;
467
502
 
468
503
  if (!response.ok) {
469
- const shouldRetry = this.shouldRetry(response);
504
+ const shouldRetry = await this.shouldRetry(response);
470
505
  if (retriesRemaining && shouldRetry) {
471
506
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
472
507
 
@@ -565,7 +600,7 @@ export class Papr {
565
600
  }
566
601
  }
567
602
 
568
- private shouldRetry(response: Response): boolean {
603
+ private async shouldRetry(response: Response): Promise<boolean> {
569
604
  // Note this is not a standard header.
570
605
  const shouldRetryHeader = response.headers.get('x-should-retry');
571
606
 
@@ -642,10 +677,10 @@ export class Papr {
642
677
  return sleepSeconds * jitter * 1000;
643
678
  }
644
679
 
645
- buildRequest(
680
+ async buildRequest(
646
681
  inputOptions: FinalRequestOptions,
647
682
  { retryCount = 0 }: { retryCount?: number } = {},
648
- ): { req: FinalizedRequestInit; url: string; timeout: number } {
683
+ ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
649
684
  const options = { ...inputOptions };
650
685
  const { method, path, query, defaultBaseURL } = options;
651
686
 
@@ -653,7 +688,7 @@ export class Papr {
653
688
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
654
689
  options.timeout = options.timeout ?? this.timeout;
655
690
  const { bodyHeaders, body } = this.buildBody({ options });
656
- const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
691
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
657
692
 
658
693
  const req: FinalizedRequestInit = {
659
694
  method,
@@ -669,7 +704,7 @@ export class Papr {
669
704
  return { req, url, timeout: options.timeout };
670
705
  }
671
706
 
672
- private buildHeaders({
707
+ private async buildHeaders({
673
708
  options,
674
709
  method,
675
710
  bodyHeaders,
@@ -679,7 +714,7 @@ export class Papr {
679
714
  method: HTTPMethod;
680
715
  bodyHeaders: HeadersLike;
681
716
  retryCount: number;
682
- }): Headers {
717
+ }): Promise<Headers> {
683
718
  let idempotencyHeaders: HeadersLike = {};
684
719
  if (this.idempotencyHeader && method !== 'get') {
685
720
  if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
@@ -695,7 +730,7 @@ export class Papr {
695
730
  ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
696
731
  ...getPlatformHeaders(),
697
732
  },
698
- this.authHeaders(options),
733
+ await this.authHeaders(options),
699
734
  this._options.defaultHeaders,
700
735
  bodyHeaders,
701
736
  options.headers,
@@ -764,9 +799,11 @@ export class Papr {
764
799
 
765
800
  user: API.User = new API.User(this);
766
801
  memory: API.Memory = new API.Memory(this);
802
+ feedback: API.Feedback = new API.Feedback(this);
767
803
  }
768
804
  Papr.User = User;
769
805
  Papr.Memory = Memory;
806
+ Papr.Feedback = Feedback;
770
807
  export declare namespace Papr {
771
808
  export type RequestOptions = Opts.RequestOptions;
772
809
 
@@ -782,7 +819,6 @@ export declare namespace Papr {
782
819
  type UserListParams as UserListParams,
783
820
  type UserDeleteParams as UserDeleteParams,
784
821
  type UserCreateBatchParams as UserCreateBatchParams,
785
- type UserGetParams as UserGetParams,
786
822
  };
787
823
 
788
824
  export {
@@ -803,4 +839,14 @@ export declare namespace Papr {
803
839
  type MemoryAddBatchParams as MemoryAddBatchParams,
804
840
  type MemorySearchParams as MemorySearchParams,
805
841
  };
842
+
843
+ export {
844
+ Feedback as Feedback,
845
+ type BatchRequest as BatchRequest,
846
+ type BatchResponse as BatchResponse,
847
+ type FeedbackRequest as FeedbackRequest,
848
+ type FeedbackResponse as FeedbackResponse,
849
+ type FeedbackSubmitParams as FeedbackSubmitParams,
850
+ type FeedbackSubmitBatchParams as FeedbackSubmitBatchParams,
851
+ };
806
852
  }
@@ -9,17 +9,70 @@ import { type HeadersLike } from './headers';
9
9
  export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
10
10
 
11
11
  export type RequestOptions = {
12
+ /**
13
+ * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
14
+ */
12
15
  method?: HTTPMethod;
16
+
17
+ /**
18
+ * The URL path for the request.
19
+ *
20
+ * @example "/v1/foo"
21
+ */
13
22
  path?: string;
23
+
24
+ /**
25
+ * Query parameters to include in the request URL.
26
+ */
14
27
  query?: object | undefined | null;
28
+
29
+ /**
30
+ * The request body. Can be a string, JSON object, FormData, or other supported types.
31
+ */
15
32
  body?: unknown;
33
+
34
+ /**
35
+ * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
36
+ */
16
37
  headers?: HeadersLike;
38
+
39
+ /**
40
+ * The maximum number of times that the client will retry a request in case of a
41
+ * temporary failure, like a network error or a 5XX error from the server.
42
+ *
43
+ * @default 2
44
+ */
17
45
  maxRetries?: number;
46
+
18
47
  stream?: boolean | undefined;
48
+
49
+ /**
50
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
51
+ * from the server before timing out a single request.
52
+ *
53
+ * @unit milliseconds
54
+ */
19
55
  timeout?: number;
56
+
57
+ /**
58
+ * Additional `RequestInit` options to be passed to the underlying `fetch` call.
59
+ * These options will be merged with the client's default fetch options.
60
+ */
20
61
  fetchOptions?: MergedRequestInit;
62
+
63
+ /**
64
+ * An AbortSignal that can be used to cancel the request.
65
+ */
21
66
  signal?: AbortSignal | undefined | null;
67
+
68
+ /**
69
+ * A unique key for this request to enable idempotency.
70
+ */
22
71
  idempotencyKey?: string;
72
+
73
+ /**
74
+ * Override the default base URL for this specific request.
75
+ */
23
76
  defaultBaseURL?: string | undefined;
24
77
 
25
78
  __binaryResponse?: boolean | undefined;
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
90
90
  return { ...opts, body: await createForm(opts.body, fetch) };
91
91
  };
92
92
 
93
- const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
93
+ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
94
94
 
95
95
  /**
96
96
  * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
@@ -58,7 +58,7 @@ const noopLogger = {
58
58
  debug: noop,
59
59
  };
60
60
 
61
- let cachedLoggers = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
61
+ let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
62
62
 
63
63
  export function loggerFor(client: Papr): Logger {
64
64
  const logger = client.logger;
@@ -106,8 +106,9 @@ export const formatRequestDetails = (details: {
106
106
  ([name, value]) => [
107
107
  name,
108
108
  (
109
- name.toLowerCase() === 'x-session-token' ||
110
109
  name.toLowerCase() === 'authorization' ||
110
+ name.toLowerCase() === 'x-session-token' ||
111
+ name.toLowerCase() === 'x-api-key' ||
111
112
  name.toLowerCase() === 'cookie' ||
112
113
  name.toLowerCase() === 'set-cookie'
113
114
  ) ?
@@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
12
12
  return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
13
13
  }
14
14
 
15
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
16
+
15
17
  export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
16
18
  function path(statics: readonly string[], ...params: readonly unknown[]): string {
17
19
  // If there are no params, no processing is needed.
18
20
  if (statics.length === 1) return statics[0]!;
19
21
 
20
22
  let postPath = false;
23
+ const invalidSegments = [];
21
24
  const path = statics.reduce((previousValue, currentValue, index) => {
22
25
  if (/[?#]/.test(currentValue)) {
23
26
  postPath = true;
24
27
  }
25
- return (
26
- previousValue +
27
- currentValue +
28
- (index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
29
- );
28
+ const value = params[index];
29
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
30
+ if (
31
+ index !== params.length &&
32
+ (value == null ||
33
+ (typeof value === 'object' &&
34
+ // handle values from other realms
35
+ value.toString ===
36
+ Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
37
+ ?.toString))
38
+ ) {
39
+ encoded = value + '';
40
+ invalidSegments.push({
41
+ start: previousValue.length + currentValue.length,
42
+ length: encoded.length,
43
+ error: `Value of type ${Object.prototype.toString
44
+ .call(value)
45
+ .slice(8, -1)} is not a valid path parameter`,
46
+ });
47
+ }
48
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
30
49
  }, '');
31
50
 
32
51
  const pathOnly = path.split(/[?#]/, 1)[0]!;
33
- const invalidSegments = [];
34
52
  const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
35
53
  let match;
36
54
 
@@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
39
57
  invalidSegments.push({
40
58
  start: match.index,
41
59
  length: match[0].length,
60
+ error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
42
61
  });
43
62
  }
44
63
 
64
+ invalidSegments.sort((a, b) => a.start - b.start);
65
+
45
66
  if (invalidSegments.length > 0) {
46
67
  let lastEnd = 0;
47
68
  const underline = invalidSegments.reduce((acc, segment) => {
@@ -51,7 +72,11 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
51
72
  return acc + spaces + arrows;
52
73
  }, '');
53
74
 
54
- throw new PaprError(`Path parameters result in path with invalid segments:\n${path}\n${underline}`);
75
+ throw new PaprError(
76
+ `Path parameters result in path with invalid segments:\n${invalidSegments
77
+ .map((e) => e.error)
78
+ .join('\n')}\n${path}\n${underline}`,
79
+ );
55
80
  }
56
81
 
57
82
  return path;