@harborclient/sdk 1.0.40 → 1.0.41

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.
@@ -27,9 +27,9 @@ interface HcHeaderApi {
27
27
  }
28
28
 
29
29
  /**
30
- * Variable helpers on hc.variables, hc.collection.variables, hc.environment.variables, and hc.globals.
30
+ * Variable bag helpers shared by hc.collection.variables, hc.environment.variables, and hc.globals.
31
31
  */
32
- interface HcVariablesApi {
32
+ interface HcVariableBagApi {
33
33
  /**
34
34
  * Returns a variable value, preferring values set in the current script run.
35
35
  */
@@ -40,12 +40,183 @@ interface HcVariablesApi {
40
40
  */
41
41
  set(key: string, value: unknown): void;
42
42
 
43
+ /**
44
+ * Removes a single key from this scope for the remainder of the script run.
45
+ */
46
+ clear(key: string): void;
47
+ }
48
+
49
+ /**
50
+ * Request-scoped variable helpers on hc.request.variables.
51
+ */
52
+ interface HcRequestVariablesApi extends HcVariableBagApi {
43
53
  /**
44
54
  * Replaces {{variable}} tokens and dynamic $ tokens in a template string.
45
55
  */
46
56
  replaceIn(template: unknown): string;
47
57
  }
48
58
 
59
+ /**
60
+ * Auth type selector for hc.request.auth and hc.collection.auth.
61
+ */
62
+ type HcAuthType = 'none' | 'basic' | 'bearer' | 'oauth2';
63
+
64
+ /**
65
+ * OAuth client credential transport for hc.*.auth when type is oauth2.
66
+ */
67
+ type HcOAuth2ClientAuth = 'header' | 'body';
68
+
69
+ /**
70
+ * Flat auth field names accepted by hc.*.auth.update().
71
+ */
72
+ type HcAuthField =
73
+ | 'type'
74
+ | 'token'
75
+ | 'username'
76
+ | 'password'
77
+ | 'tokenUrl'
78
+ | 'clientId'
79
+ | 'clientSecret'
80
+ | 'scope'
81
+ | 'audience'
82
+ | 'clientAuth';
83
+
84
+ /**
85
+ * Partial flat auth object accepted by hc.request.auth.set() and hc.collection.auth.set().
86
+ *
87
+ * Merges onto the current auth configuration; switching type preserves stored
88
+ * credentials for other types.
89
+ */
90
+ interface HcAuthInput {
91
+ type?: HcAuthType;
92
+ token?: string;
93
+ username?: string;
94
+ password?: string;
95
+ tokenUrl?: string;
96
+ clientId?: string;
97
+ clientSecret?: string;
98
+ scope?: string;
99
+ audience?: string;
100
+ clientAuth?: HcOAuth2ClientAuth;
101
+ }
102
+
103
+ /**
104
+ * Flat auth shape returned by hc.request.auth.get() and hc.collection.auth.get().
105
+ *
106
+ * Includes only fields relevant to the active auth type.
107
+ */
108
+ type HcAuthSnapshot =
109
+ | { type: 'none' }
110
+ | { type: 'basic'; username: string; password: string }
111
+ | { type: 'bearer'; token: string }
112
+ | {
113
+ type: 'oauth2';
114
+ tokenUrl: string;
115
+ clientId: string;
116
+ clientSecret: string;
117
+ scope: string;
118
+ audience: string;
119
+ clientAuth: HcOAuth2ClientAuth;
120
+ };
121
+
122
+ /**
123
+ * Auth helpers on hc.request.auth and hc.collection.auth.
124
+ *
125
+ * Request auth changes apply to the current send only. Collection auth changes
126
+ * persist to the collection when the send completes.
127
+ */
128
+ interface HcAuthApi {
129
+ /**
130
+ * Returns the active auth fields as a flat object for the current auth type.
131
+ */
132
+ get(): HcAuthSnapshot;
133
+
134
+ /**
135
+ * Merges auth configuration from a partial flat auth object.
136
+ */
137
+ set(input: HcAuthInput): void;
138
+
139
+ /**
140
+ * Updates a single flat auth field, such as type or token.
141
+ */
142
+ update(field: HcAuthField, value: unknown): void;
143
+ }
144
+
145
+ /**
146
+ * Cookie bag for the request host resolved at send start.
147
+ * URL changes mid-script do not retarget this bag.
148
+ */
149
+ interface HcCookieApi {
150
+ /**
151
+ * Returns a cookie value by name, preferring values set in the current script run.
152
+ */
153
+ get(name: string): string | undefined;
154
+
155
+ /**
156
+ * Sets a cookie for the request host for the remainder of the script run.
157
+ */
158
+ set(name: string, value: unknown): void;
159
+
160
+ /**
161
+ * Removes a single cookie by name for the remainder of the script run.
162
+ */
163
+ clear(name: string): void;
164
+ }
165
+
166
+ /**
167
+ * Collection runner flow control available in pre/post scripts during a run.
168
+ */
169
+ interface HcExecutionApi {
170
+ /**
171
+ * Jumps to the named request in the active collection run, or stops the run when null.
172
+ */
173
+ setNextRequest(name: string | null): void;
174
+
175
+ /**
176
+ * Skips the HTTP send and post-request scripts for the current request.
177
+ */
178
+ skipRequest(): void;
179
+ }
180
+
181
+ /**
182
+ * Postman-compatible script execution metadata (pm.info equivalent).
183
+ */
184
+ interface HcInfoApi {
185
+ /** `"prerequest"` for pre-request scripts, `"test"` for post-request scripts. */
186
+ readonly eventName: 'prerequest' | 'test';
187
+ /** Display name of the saved request. */
188
+ readonly requestName: string;
189
+ /** Saved request database id as a string, or empty when unsaved. */
190
+ readonly requestId: string;
191
+ /** Collection run iteration index; 0 for manual sends and non-data-driven runs. */
192
+ readonly iteration: number;
193
+ }
194
+
195
+ /**
196
+ * Outbound request payload accepted by hc.sendRequest.
197
+ */
198
+ interface HcSendRequestInput {
199
+ method?: string;
200
+ url: string;
201
+ headers?: Array<{ key: string; value: string; enabled?: boolean }> | Record<string, string>;
202
+ params?: Array<{ key: string; value: string; enabled?: boolean }>;
203
+ body?: string;
204
+ bodyType?: 'none' | 'json' | 'text' | 'multipart' | 'urlencoded';
205
+ body_type?: 'none' | 'json' | 'text' | 'multipart' | 'urlencoded';
206
+ }
207
+
208
+ /**
209
+ * Response snapshot returned by hc.sendRequest.
210
+ */
211
+ interface HcSendRequestResponse {
212
+ readonly code: number;
213
+ readonly status: string;
214
+ readonly headers: Record<string, string>;
215
+ readonly responseTime: number;
216
+ text(): string;
217
+ json(): unknown;
218
+ }
219
+
49
220
  /**
50
221
  * Chai-lite matcher returned by hc.expect(actual).
51
222
  */
@@ -99,22 +270,38 @@ interface HcScriptApi {
99
270
  url: string;
100
271
  body: string;
101
272
  headers: HcHeaderApi;
273
+ auth: HcAuthApi;
274
+ variables: HcRequestVariablesApi;
102
275
  };
103
- variables: HcVariablesApi;
104
276
  collection: {
105
277
  readonly id: number | null;
106
278
  readonly name: string;
107
- variables: HcVariablesApi;
279
+ variables: HcVariableBagApi;
108
280
  headers: HcHeaderApi;
281
+ auth: HcAuthApi;
109
282
  };
110
283
  environment: {
111
284
  readonly name: string;
112
- variables: HcVariablesApi;
285
+ variables: HcVariableBagApi;
113
286
  };
114
- globals: HcVariablesApi;
287
+ globals: HcVariableBagApi;
288
+ cookies: HcCookieApi;
289
+ execution: HcExecutionApi;
290
+ /** Read-only metadata about the current script run (Postman pm.info equivalent). */
291
+ info: HcInfoApi;
292
+ /**
293
+ * Sends an outbound HTTP request from the script sandbox.
294
+ * Requires Settings → General → Allow script network requests.
295
+ *
296
+ * @throws When the setting is disabled or sendRequest is unavailable in this context.
297
+ */
298
+ sendRequest(req: HcSendRequestInput): Promise<HcSendRequestResponse>;
115
299
  test(name: string, fn: () => void): void;
116
300
  expect(actual: unknown): HcExpectMatcher;
117
- response: HcResponseApi;
301
+ /**
302
+ * Available in post-request scripts after the primary request completes.
303
+ */
304
+ response?: HcResponseApi;
118
305
  }
119
306
 
120
307
  /**
package/dist/types.d.ts CHANGED
@@ -1726,7 +1726,7 @@ export interface PluginScriptContextInit {
1726
1726
  */
1727
1727
  response?: PluginScriptResponseInit;
1728
1728
  /**
1729
- * Merged runtime variables for hc.variables, hc.collection.variables,
1729
+ * Merged runtime variables for hc.request.variables, hc.collection.variables,
1730
1730
  * hc.environment.variables, and hc.globals lookups.
1731
1731
  */
1732
1732
  variables?: Record<string, string>;
@@ -1772,7 +1772,7 @@ export interface PluginScriptRunResult {
1772
1772
  */
1773
1773
  request: PluginScriptRequestInit;
1774
1774
  /**
1775
- * Ephemeral variable sets from hc.variables.set.
1775
+ * Ephemeral variable sets from hc.request.variables.set.
1776
1776
  */
1777
1777
  variableSets: Record<string, string>;
1778
1778
  /**
@@ -1836,7 +1836,7 @@ export interface PluginScriptContext {
1836
1836
  * Script sandbox factory available on {@link MainPluginContext.scripts}.
1837
1837
  *
1838
1838
  * Runs user scripts with the same hc object as collection and request pre/post scripts
1839
- * (`hc.request`, `hc.variables`, `hc.collection`, `hc.environment`, `hc.globals`,
1839
+ * (`hc.request`, `hc.collection`, `hc.environment`, `hc.globals`,
1840
1840
  * `hc.test`, `hc.expect`, and `hc.response` when a response is provided).
1841
1841
  */
1842
1842
  export interface PluginScripts {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harborclient/sdk",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "TypeScript SDK for HarborClient development.",
5
5
  "keywords": [
6
6
  "harborclient",