@virtocommerce/test-automation-framework 0.0.0-stage → 0.1.0-alpha.1

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 (233) hide show
  1. package/.biome/formatter.json +11 -0
  2. package/.biome/imports.json +52 -0
  3. package/.biome/preset.json +4 -0
  4. package/.biome/rules.json +45 -0
  5. package/.claude/agents/qa-automation-expert.md +119 -0
  6. package/.claude/agents/qa-coverage.md +96 -0
  7. package/.claude/agents/qa-explorer.md +112 -0
  8. package/.claude/agents/qa-healer.md +88 -0
  9. package/.claude/agents/qa-judge.md +102 -0
  10. package/.claude/agents/qa-planner.md +104 -0
  11. package/.claude/agents/qa-reviewer.md +121 -0
  12. package/.claude/checks/browser-secrets.mts +107 -0
  13. package/.claude/checks/contract.mts +469 -0
  14. package/.claude/checks/expectation-guard.mts +665 -0
  15. package/.claude/checks/explore-extractors.mts +4 -0
  16. package/.claude/checks/judge-verdict.mts +165 -0
  17. package/.claude/checks/project-facts.mts +491 -0
  18. package/.claude/checks/prove-fails.mts +770 -0
  19. package/.claude/checks/rank-gaps.mts +177 -0
  20. package/.claude/checks/readonly-shell.mts +740 -0
  21. package/.claude/checks/reconcile-run.mts +270 -0
  22. package/.claude/checks/scan-prompts.mts +351 -0
  23. package/.claude/checks/stand.mts +45 -0
  24. package/.claude/checks/test-duration.mts +134 -0
  25. package/.claude/checks/test-shape.mts +224 -0
  26. package/.claude/checks/ticket-card.mts +195 -0
  27. package/.claude/commands/qa-coverage.md +13 -0
  28. package/.claude/commands/qa-explore.md +17 -0
  29. package/.claude/commands/qa-heal.md +44 -0
  30. package/.claude/commands/qa-implement.md +60 -0
  31. package/.claude/commands/qa-plan.md +55 -0
  32. package/.claude/commands/qa-review.md +90 -0
  33. package/.claude/commands/qa.md +156 -0
  34. package/.claude/hooks/readonly-shell.mts +65 -0
  35. package/.claude/settings.json +15 -0
  36. package/.claude/skills/coverage-analysis/SKILL.md +107 -0
  37. package/.claude/skills/create-graphql-layer/SKILL.md +159 -0
  38. package/.claude/skills/create-ui-layer/SKILL.md +189 -0
  39. package/.claude/skills/explore-api/SKILL.md +74 -0
  40. package/.claude/skills/explore-frontend/SKILL.md +85 -0
  41. package/.claude/skills/framework-rules/SKILL.md +189 -0
  42. package/.claude/skills/heal-tests/SKILL.md +197 -0
  43. package/.claude/skills/heal-tests/guard-recipe.md +53 -0
  44. package/.claude/skills/judge-criteria/SKILL.md +40 -0
  45. package/.claude/skills/judge-criteria/coverage.md +9 -0
  46. package/.claude/skills/judge-criteria/expert.md +23 -0
  47. package/.claude/skills/judge-criteria/explorer.md +9 -0
  48. package/.claude/skills/judge-criteria/healer.md +13 -0
  49. package/.claude/skills/judge-criteria/planner.md +12 -0
  50. package/.claude/skills/plan-implementation/SKILL.md +82 -0
  51. package/.claude/skills/plan-implementation/contract-template.md +72 -0
  52. package/.claude/skills/plan-test-strategy/SKILL.md +100 -0
  53. package/.claude/skills/project-facts/SKILL.md +130 -0
  54. package/.claude/skills/read-change/SKILL.md +64 -0
  55. package/.claude/skills/read-ticket/SKILL.md +63 -0
  56. package/.claude/skills/read-ticket/providers.md +58 -0
  57. package/.claude/skills/review-pr/SKILL.md +152 -0
  58. package/.claude/skills/review-test-code/SKILL.md +208 -0
  59. package/.claude/skills/write-e2e-test/SKILL.md +175 -0
  60. package/.claude/skills/write-graphql-test/SKILL.md +158 -0
  61. package/.claude/skills/write-rest-api-test/SKILL.md +182 -0
  62. package/.claude/skills/write-security-test/SKILL.md +253 -0
  63. package/.qa/project.example.json +71 -0
  64. package/CHANGELOG.md +1 -0
  65. package/LICENSE +12 -0
  66. package/README.md +53 -2
  67. package/bin/install-qa-agents.mjs +94 -0
  68. package/dist/auth/credentials.d.ts +10 -0
  69. package/dist/auth/credentials.js +2 -0
  70. package/dist/auth/credentials.js.map +1 -0
  71. package/dist/auth/frontend-browser-sessions.d.ts +71 -0
  72. package/dist/auth/frontend-browser-sessions.js +130 -0
  73. package/dist/auth/frontend-browser-sessions.js.map +1 -0
  74. package/dist/auth/index.d.ts +9 -0
  75. package/dist/auth/index.js +5 -0
  76. package/dist/auth/index.js.map +1 -0
  77. package/dist/auth/platform-browser-sessions.d.ts +47 -0
  78. package/dist/auth/platform-browser-sessions.js +92 -0
  79. package/dist/auth/platform-browser-sessions.js.map +1 -0
  80. package/dist/auth/sign-in-lock.d.ts +14 -0
  81. package/dist/auth/sign-in-lock.js +70 -0
  82. package/dist/auth/sign-in-lock.js.map +1 -0
  83. package/dist/auth/storage-state.d.ts +3 -0
  84. package/dist/auth/storage-state.js +2 -0
  85. package/dist/auth/storage-state.js.map +1 -0
  86. package/dist/auth/token-client.d.ts +82 -0
  87. package/dist/auth/token-client.js +111 -0
  88. package/dist/auth/token-client.js.map +1 -0
  89. package/dist/auth/token-manager.d.ts +67 -0
  90. package/dist/auth/token-manager.js +138 -0
  91. package/dist/auth/token-manager.js.map +1 -0
  92. package/dist/core/default-reporters.d.ts +31 -0
  93. package/dist/core/default-reporters.js +36 -0
  94. package/dist/core/default-reporters.js.map +1 -0
  95. package/dist/core/default-use.d.ts +28 -0
  96. package/dist/core/default-use.js +25 -0
  97. package/dist/core/default-use.js.map +1 -0
  98. package/dist/core/env.d.ts +24 -0
  99. package/dist/core/env.js +33 -0
  100. package/dist/core/env.js.map +1 -0
  101. package/dist/core/error-message.d.ts +10 -0
  102. package/dist/core/error-message.js +13 -0
  103. package/dist/core/error-message.js.map +1 -0
  104. package/dist/core/index.d.ts +16 -0
  105. package/dist/core/index.js +11 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/is-ci.d.ts +14 -0
  108. package/dist/core/is-ci.js +18 -0
  109. package/dist/core/is-ci.js.map +1 -0
  110. package/dist/core/parse-env.d.ts +13 -0
  111. package/dist/core/parse-env.js +21 -0
  112. package/dist/core/parse-env.js.map +1 -0
  113. package/dist/core/projects.d.ts +24 -0
  114. package/dist/core/projects.js +33 -0
  115. package/dist/core/projects.js.map +1 -0
  116. package/dist/core/run-options.d.ts +31 -0
  117. package/dist/core/run-options.js +43 -0
  118. package/dist/core/run-options.js.map +1 -0
  119. package/dist/core/secret.d.ts +105 -0
  120. package/dist/core/secret.js +167 -0
  121. package/dist/core/secret.js.map +1 -0
  122. package/dist/core/string-schemas.d.ts +39 -0
  123. package/dist/core/string-schemas.js +56 -0
  124. package/dist/core/string-schemas.js.map +1 -0
  125. package/dist/core/url-path.d.ts +7 -0
  126. package/dist/core/url-path.js +2 -0
  127. package/dist/core/url-path.js.map +1 -0
  128. package/dist/dataset/collection.d.ts +44 -0
  129. package/dist/dataset/collection.js +76 -0
  130. package/dist/dataset/collection.js.map +1 -0
  131. package/dist/dataset/index.d.ts +11 -0
  132. package/dist/dataset/index.js +6 -0
  133. package/dist/dataset/index.js.map +1 -0
  134. package/dist/dataset/load-dataset.d.ts +39 -0
  135. package/dist/dataset/load-dataset.js +62 -0
  136. package/dist/dataset/load-dataset.js.map +1 -0
  137. package/dist/dataset/manifest.d.ts +77 -0
  138. package/dist/dataset/manifest.js +10 -0
  139. package/dist/dataset/manifest.js.map +1 -0
  140. package/dist/dataset/placeholders.d.ts +66 -0
  141. package/dist/dataset/placeholders.js +87 -0
  142. package/dist/dataset/placeholders.js.map +1 -0
  143. package/dist/dataset/seed-collection.d.ts +53 -0
  144. package/dist/dataset/seed-collection.js +115 -0
  145. package/dist/dataset/seed-collection.js.map +1 -0
  146. package/dist/dataset/seed-dataset.d.ts +70 -0
  147. package/dist/dataset/seed-dataset.js +138 -0
  148. package/dist/dataset/seed-dataset.js.map +1 -0
  149. package/dist/dataset/seed-events.d.ts +81 -0
  150. package/dist/dataset/seed-events.js +2 -0
  151. package/dist/dataset/seed-events.js.map +1 -0
  152. package/dist/dataset/seed-requests.d.ts +102 -0
  153. package/dist/dataset/seed-requests.js +160 -0
  154. package/dist/dataset/seed-requests.js.map +1 -0
  155. package/dist/dataset/seed-scope.d.ts +39 -0
  156. package/dist/dataset/seed-scope.js +67 -0
  157. package/dist/dataset/seed-scope.js.map +1 -0
  158. package/dist/fixtures/default-fixtures.d.ts +93 -0
  159. package/dist/fixtures/default-fixtures.js +105 -0
  160. package/dist/fixtures/default-fixtures.js.map +1 -0
  161. package/dist/fixtures/index.d.ts +2 -0
  162. package/dist/fixtures/index.js +2 -0
  163. package/dist/fixtures/index.js.map +1 -0
  164. package/dist/graphql/graphql-client.d.ts +78 -0
  165. package/dist/graphql/graphql-client.js +83 -0
  166. package/dist/graphql/graphql-client.js.map +1 -0
  167. package/dist/graphql/graphql-codegen.d.ts +56 -0
  168. package/dist/graphql/graphql-codegen.js +42 -0
  169. package/dist/graphql/graphql-codegen.js.map +1 -0
  170. package/dist/graphql/graphql-error.d.ts +54 -0
  171. package/dist/graphql/graphql-error.js +74 -0
  172. package/dist/graphql/graphql-error.js.map +1 -0
  173. package/dist/graphql/index.d.ts +6 -0
  174. package/dist/graphql/index.js +4 -0
  175. package/dist/graphql/index.js.map +1 -0
  176. package/dist/http/authentication.d.ts +16 -0
  177. package/dist/http/authentication.js +2 -0
  178. package/dist/http/authentication.js.map +1 -0
  179. package/dist/http/http-client.d.ts +110 -0
  180. package/dist/http/http-client.js +237 -0
  181. package/dist/http/http-client.js.map +1 -0
  182. package/dist/http/http-error.d.ts +26 -0
  183. package/dist/http/http-error.js +34 -0
  184. package/dist/http/http-error.js.map +1 -0
  185. package/dist/http/http-method.d.ts +2 -0
  186. package/dist/http/http-method.js +2 -0
  187. package/dist/http/http-method.js.map +1 -0
  188. package/dist/http/http-response.d.ts +137 -0
  189. package/dist/http/http-response.js +166 -0
  190. package/dist/http/http-response.js.map +1 -0
  191. package/dist/http/index.d.ts +7 -0
  192. package/dist/http/index.js +4 -0
  193. package/dist/http/index.js.map +1 -0
  194. package/dist/http/request-options.d.ts +62 -0
  195. package/dist/http/request-options.js +2 -0
  196. package/dist/http/request-options.js.map +1 -0
  197. package/dist/modules/index.d.ts +2 -0
  198. package/dist/modules/index.js +2 -0
  199. package/dist/modules/index.js.map +1 -0
  200. package/dist/modules/installed-modules.d.ts +86 -0
  201. package/dist/modules/installed-modules.js +135 -0
  202. package/dist/modules/installed-modules.js.map +1 -0
  203. package/docs/README.md +43 -0
  204. package/docs/concepts/areas.md +38 -0
  205. package/docs/concepts/auth.md +92 -0
  206. package/docs/concepts/config.md +102 -0
  207. package/docs/concepts/dataset.md +183 -0
  208. package/docs/concepts/environment.md +54 -0
  209. package/docs/concepts/fixtures.md +109 -0
  210. package/docs/concepts/graphql.md +76 -0
  211. package/docs/concepts/http.md +88 -0
  212. package/docs/concepts/modules.md +63 -0
  213. package/docs/concepts/secrets.md +50 -0
  214. package/docs/contributing/architecture.md +67 -0
  215. package/docs/contributing/conventions.md +39 -0
  216. package/docs/contributing/documentation.md +37 -0
  217. package/docs/contributing/releasing.md +76 -0
  218. package/docs/examples/auth.ts +20 -0
  219. package/docs/examples/config.ts +36 -0
  220. package/docs/examples/dataset.ts +70 -0
  221. package/docs/examples/environment.ts +8 -0
  222. package/docs/examples/fixtures.ts +41 -0
  223. package/docs/examples/getting-started.ts +22 -0
  224. package/docs/examples/graphql-codegen.ts +9 -0
  225. package/docs/examples/graphql.ts +32 -0
  226. package/docs/examples/http.ts +18 -0
  227. package/docs/examples/modules.ts +19 -0
  228. package/docs/examples/secrets.ts +11 -0
  229. package/docs/examples/tsconfig.json +10 -0
  230. package/docs/getting-started.md +106 -0
  231. package/docs/guides/generating-types.md +75 -0
  232. package/docs/guides/qa-agents.md +66 -0
  233. package/package.json +156 -4
@@ -0,0 +1,54 @@
1
+ /** An entry of the `errors` array of a GraphQL response. Fields that the server adds are kept. */
2
+ export interface GraphqlErrorEntry {
3
+ /** The description of the error. */
4
+ readonly message: string;
5
+ /** The path of the response field that failed, such as `["cart", "items", 0]`. */
6
+ readonly path?: readonly (string | number)[] | undefined;
7
+ /** Additional data about the error, such as its `code`. */
8
+ readonly extensions?: Readonly<Record<string, unknown>> | undefined;
9
+ /** Other fields that the server adds, such as `locations`. */
10
+ readonly [field: string]: unknown;
11
+ }
12
+ /** The schema of a {@link GraphqlErrorEntry}. Fields that the server adds are kept. */
13
+ export declare const graphqlErrorEntrySchema: import("zod").ZodObject<{
14
+ message: import("zod").ZodString;
15
+ path: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>>>;
16
+ extensions: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
17
+ }, import("zod/v4/core").$loose>;
18
+ /**
19
+ * Represents a GraphQL response that has errors or has no data. The message and the error entries have secrets masked.
20
+ *
21
+ * @remarks
22
+ * The message names the operation and the status, then lists each error with its code and path, such as
23
+ * `- [VALIDATION_ERROR] Quantity must be positive (at addItem)`.
24
+ */
25
+ export declare class GraphqlError extends Error {
26
+ /** The name of the error type, `GraphqlError`. */
27
+ readonly name = "GraphqlError";
28
+ /** The name of the operation, taken from the document, or `(anonymous)` for an operation without a name. */
29
+ readonly operationName: string;
30
+ /** The HTTP status of the response. */
31
+ readonly status: number;
32
+ /**
33
+ * The error entries of the response, with secrets masked. It is empty when the response has no errors and no data.
34
+ */
35
+ readonly errors: readonly GraphqlErrorEntry[];
36
+ /**
37
+ * Creates an error for a GraphQL response.
38
+ *
39
+ * @param operationName - The name of the operation, or `(anonymous)`.
40
+ * @param status - The HTTP status of the response.
41
+ * @param errors - The error entries of the response, or an empty array when the response has no data. Secrets in
42
+ * them are masked.
43
+ */
44
+ constructor(operationName: string, status: number, errors: readonly GraphqlErrorEntry[]);
45
+ /**
46
+ * Determines whether a value is a {@link GraphqlError} with an error entry that has one of the specified codes.
47
+ *
48
+ * @param error - The value to check.
49
+ * @param codes - The codes to match against `extensions.code`.
50
+ * @returns `true` if the value is a {@link GraphqlError} and one of its entries has one of `codes`; otherwise,
51
+ * `false`.
52
+ */
53
+ static hasCode(error: unknown, ...codes: readonly string[]): error is GraphqlError;
54
+ }
@@ -0,0 +1,74 @@
1
+ import { array, looseObject, number, record, string, union, unknown } from "zod";
2
+ import { maskSecrets } from "../core/index.js";
3
+ /** The schema of a {@link GraphqlErrorEntry}. Fields that the server adds are kept. */
4
+ export const graphqlErrorEntrySchema = looseObject({
5
+ message: string(),
6
+ path: array(union([string(), number()])).optional(),
7
+ extensions: record(string(), unknown()).optional(),
8
+ });
9
+ /**
10
+ * Represents a GraphQL response that has errors or has no data. The message and the error entries have secrets masked.
11
+ *
12
+ * @remarks
13
+ * The message names the operation and the status, then lists each error with its code and path, such as
14
+ * `- [VALIDATION_ERROR] Quantity must be positive (at addItem)`.
15
+ */
16
+ export class GraphqlError extends Error {
17
+ /** The name of the error type, `GraphqlError`. */
18
+ name = "GraphqlError";
19
+ /** The name of the operation, taken from the document, or `(anonymous)` for an operation without a name. */
20
+ operationName;
21
+ /** The HTTP status of the response. */
22
+ status;
23
+ /**
24
+ * The error entries of the response, with secrets masked. It is empty when the response has no errors and no data.
25
+ */
26
+ errors;
27
+ /**
28
+ * Creates an error for a GraphQL response.
29
+ *
30
+ * @param operationName - The name of the operation, or `(anonymous)`.
31
+ * @param status - The HTTP status of the response.
32
+ * @param errors - The error entries of the response, or an empty array when the response has no data. Secrets in
33
+ * them are masked.
34
+ */
35
+ constructor(operationName, status, errors) {
36
+ super(maskSecrets([summaryOf(operationName, status, errors), ...errors.map(lineOf)].join("\n")));
37
+ this.operationName = operationName;
38
+ this.status = status;
39
+ this.errors = JSON.parse(maskSecrets(JSON.stringify(errors)));
40
+ }
41
+ /**
42
+ * Determines whether a value is a {@link GraphqlError} with an error entry that has one of the specified codes.
43
+ *
44
+ * @param error - The value to check.
45
+ * @param codes - The codes to match against `extensions.code`.
46
+ * @returns `true` if the value is a {@link GraphqlError} and one of its entries has one of `codes`; otherwise,
47
+ * `false`.
48
+ */
49
+ static hasCode(error, ...codes) {
50
+ return (error instanceof GraphqlError &&
51
+ error.errors.some((entry) => {
52
+ const code = codeOf(entry);
53
+ return code !== undefined && codes.includes(code);
54
+ }));
55
+ }
56
+ }
57
+ function summaryOf(operationName, status, errors) {
58
+ if (errors.length === 0) {
59
+ return `GraphQL operation ${operationName} returned no data with status ${status}`;
60
+ }
61
+ const count = errors.length === 1 ? "1 error" : `${errors.length} errors`;
62
+ return `GraphQL operation ${operationName} returned ${count} with status ${status}:`;
63
+ }
64
+ function lineOf(entry) {
65
+ const code = codeOf(entry);
66
+ const prefix = code === undefined ? "" : `[${code}] `;
67
+ const location = entry.path === undefined ? "" : ` (at ${entry.path.join(".")})`;
68
+ return ` - ${prefix}${entry.message}${location}`;
69
+ }
70
+ function codeOf(entry) {
71
+ const code = entry.extensions?.["code"];
72
+ return typeof code === "string" ? code : undefined;
73
+ }
74
+ //# sourceMappingURL=graphql-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql-error.js","sourceRoot":"","sources":["../../src/graphql/graphql-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAcrC,uFAAuF;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAC;IACjD,OAAO,EAAE,MAAM,EAAE;IACjB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACnD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,kDAAkD;IAChC,IAAI,GAAG,cAAc,CAAC;IAExC,4GAA4G;IACnG,aAAa,CAAS;IAE/B,uCAAuC;IAC9B,MAAM,CAAS;IAExB;;OAEG;IACM,MAAM,CAA+B;IAE9C;;;;;;;OAOG;IACH,YAAY,aA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,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACjF,OAAO,OAAO,MAAM,GAAG,KAAK,CAAC,OAAO,GAAG,QAAQ,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,MAAM,CAAC,KAAwB;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC","sourcesContent":["import { array, looseObject, number, record, string, union, unknown } from \"zod\";\n\nimport { maskSecrets } from \"@/core\";\n\n/** An entry of the `errors` array of a GraphQL response. Fields that the server adds are kept. */\nexport interface GraphqlErrorEntry {\n /** The description of the error. */\n readonly message: string;\n /** The path of the response field that failed, such as `[\"cart\", \"items\", 0]`. */\n readonly path?: readonly (string | number)[] | undefined;\n /** Additional data about the error, such as its `code`. */\n readonly extensions?: Readonly<Record<string, unknown>> | undefined;\n /** Other fields that the server adds, such as `locations`. */\n readonly [field: string]: unknown;\n}\n\n/** The schema of a {@link GraphqlErrorEntry}. Fields that the server adds are kept. */\nexport const graphqlErrorEntrySchema = looseObject({\n message: string(),\n path: array(union([string(), number()])).optional(),\n extensions: record(string(), unknown()).optional(),\n});\n\n/**\n * Represents a GraphQL response that has errors or has no data. The message and the error entries have secrets masked.\n *\n * @remarks\n * The message names the operation and the status, then lists each error with its code and path, such as\n * `- [VALIDATION_ERROR] Quantity must be positive (at addItem)`.\n */\nexport class GraphqlError extends Error {\n /** The name of the error type, `GraphqlError`. */\n override readonly name = \"GraphqlError\";\n\n /** The name of the operation, taken from the document, or `(anonymous)` for an operation without a name. */\n readonly operationName: string;\n\n /** The HTTP status of the response. */\n readonly status: number;\n\n /**\n * The error entries of the response, with secrets masked. It is empty when the response has no errors and no data.\n */\n readonly errors: readonly GraphqlErrorEntry[];\n\n /**\n * Creates an error for a GraphQL response.\n *\n * @param operationName - The name of the operation, or `(anonymous)`.\n * @param status - The HTTP status of the response.\n * @param errors - The error entries of the response, or an empty array when the response has no data. Secrets in\n * them are masked.\n */\n constructor(operationName: string, status: number, errors: readonly GraphqlErrorEntry[]) {\n super(maskSecrets([summaryOf(operationName, status, errors), ...errors.map(lineOf)].join(\"\\n\")));\n this.operationName = operationName;\n this.status = status;\n this.errors = JSON.parse(maskSecrets(JSON.stringify(errors))) as readonly GraphqlErrorEntry[];\n }\n\n /**\n * Determines whether a value is a {@link GraphqlError} with an error entry that has one of the specified codes.\n *\n * @param error - The value to check.\n * @param codes - The codes to match against `extensions.code`.\n * @returns `true` if the value is a {@link GraphqlError} and one of its entries has one of `codes`; otherwise,\n * `false`.\n */\n static hasCode(error: unknown, ...codes: readonly string[]): error is GraphqlError {\n return (\n error instanceof GraphqlError &&\n error.errors.some((entry: GraphqlErrorEntry) => {\n const code = codeOf(entry);\n return code !== undefined && codes.includes(code);\n })\n );\n }\n}\n\nfunction summaryOf(operationName: string, status: number, errors: readonly GraphqlErrorEntry[]): string {\n if (errors.length === 0) {\n return `GraphQL operation ${operationName} returned no data with status ${status}`;\n }\n const count = errors.length === 1 ? \"1 error\" : `${errors.length} errors`;\n return `GraphQL operation ${operationName} returned ${count} with status ${status}:`;\n}\n\nfunction lineOf(entry: GraphqlErrorEntry): string {\n const code = codeOf(entry);\n const prefix = code === undefined ? \"\" : `[${code}] `;\n const location = entry.path === undefined ? \"\" : ` (at ${entry.path.join(\".\")})`;\n return ` - ${prefix}${entry.message}${location}`;\n}\n\nfunction codeOf(entry: GraphqlErrorEntry): string | undefined {\n const code = entry.extensions?.[\"code\"];\n return typeof code === \"string\" ? code : undefined;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export type { GraphqlDocument, GraphqlResult, GraphqlVariablesArgument } from "./graphql-client.ts";
2
+ export type { GraphqlCodegenConfig, GraphqlCodegenOptions } from "./graphql-codegen.ts";
3
+ export type { GraphqlErrorEntry } from "./graphql-error.ts";
4
+ export { GraphqlClient } from "./graphql-client.ts";
5
+ export { graphqlCodegenConfig } from "./graphql-codegen.ts";
6
+ export { GraphqlError } from "./graphql-error.ts";
@@ -0,0 +1,4 @@
1
+ export { GraphqlClient } from "./graphql-client.js";
2
+ export { graphqlCodegenConfig } from "./graphql-codegen.js";
3
+ export { GraphqlError } from "./graphql-error.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type { GraphqlDocument, GraphqlResult, GraphqlVariablesArgument } from \"./graphql-client.ts\";\nexport type { GraphqlCodegenConfig, GraphqlCodegenOptions } from \"./graphql-codegen.ts\";\nexport type { GraphqlErrorEntry } from \"./graphql-error.ts\";\n\nexport { GraphqlClient } from \"./graphql-client.ts\";\nexport { graphqlCodegenConfig } from \"./graphql-codegen.ts\";\nexport { GraphqlError } from \"./graphql-error.ts\";\n"]}
@@ -0,0 +1,16 @@
1
+ import type { HeaderProvider, RequestHeaders } from "./request-options.ts";
2
+ /** Describes how an {@link HttpClient} signs in to requests and renews the sign-in after a 401 status. */
3
+ export interface Authentication {
4
+ /** Returns the sign-in headers. It is called for each request, so a renewed sign-in is picked up. */
5
+ readonly headers: HeaderProvider;
6
+ /**
7
+ * Renews the sign-in after a request receives a 401 status.
8
+ *
9
+ * @remarks
10
+ * Several requests can call this method at the same time. Renew the sign-in only when the rejected headers still
11
+ * hold the current sign-in. After this method completes, the request is sent once more with fresh headers.
12
+ *
13
+ * @param rejected - The headers of the rejected request.
14
+ */
15
+ readonly renew: (rejected: RequestHeaders) => Promise<void>;
16
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/http/authentication.ts"],"names":[],"mappings":"","sourcesContent":["import type { HeaderProvider, RequestHeaders } from \"./request-options.ts\";\n\n/** Describes how an {@link HttpClient} signs in to requests and renews the sign-in after a 401 status. */\nexport interface Authentication {\n /** Returns the sign-in headers. It is called for each request, so a renewed sign-in is picked up. */\n readonly headers: HeaderProvider;\n\n /**\n * Renews the sign-in after a request receives a 401 status.\n *\n * @remarks\n * Several requests can call this method at the same time. Renew the sign-in only when the rejected headers still\n * hold the current sign-in. After this method completes, the request is sent once more with fresh headers.\n *\n * @param rejected - The headers of the rejected request.\n */\n readonly renew: (rejected: RequestHeaders) => Promise<void>;\n}\n"]}
@@ -0,0 +1,110 @@
1
+ import type { APIRequestContext } from "@playwright/test";
2
+ import type { Authentication } from "./authentication.ts";
3
+ import type { HttpMethod } from "./http-method.ts";
4
+ import type { HeaderProvider, RequestHeaders, RequestOptions } from "./request-options.ts";
5
+ import { HttpResponse } from "./http-response.ts";
6
+ /**
7
+ * Represents an immutable HTTP client that sends requests through a request context, so the requests appear in test
8
+ * traces.
9
+ *
10
+ * @remarks
11
+ * - The client sends requests only to its own origin and does not follow redirects, so headers never reach another
12
+ * host.
13
+ * - The client does not throw for a status. Check the status with {@link HttpResponse.expectOk},
14
+ * {@link HttpResponse.json}, {@link HttpResponse.parse} or {@link HttpResponse.errorJson}.
15
+ * - The client throws an error, with secrets masked, when no response arrives. It does not retry.
16
+ * - The client reveals each {@link Secret} in the query, headers or body only when it sends the request, so callers
17
+ * do not call {@link Secret.reveal}.
18
+ *
19
+ * @example
20
+ * const client = new HttpClient(context, baseUrl).withHeaders({ "Accept-Language": "en-US" });
21
+ * const store = (await client.get(`/api/stores/${encodeURIComponent(id)}`)).parse(StoreSchema);
22
+ */
23
+ export declare class HttpClient {
24
+ #private;
25
+ /**
26
+ * Creates a client that sends requests to one origin.
27
+ *
28
+ * @param context - The request context that sends the requests.
29
+ * @param baseUrl - The origin that requests are sent to, such as `http://localhost:8090`.
30
+ * @throws {Error} `baseUrl` is not a canonical origin. The message does not contain the URL.
31
+ */
32
+ constructor(context: APIRequestContext, baseUrl: string);
33
+ /**
34
+ * Returns a client that also sends the specified headers.
35
+ *
36
+ * @remarks
37
+ * The headers replace headers of the same name, except the sign-in headers. A provider is called for each request.
38
+ *
39
+ * @param extra - The headers to send, or a provider that returns them.
40
+ * @returns A new client. This client does not change.
41
+ */
42
+ withHeaders(extra: RequestHeaders | HeaderProvider): HttpClient;
43
+ /**
44
+ * Returns a client that signs in to each request.
45
+ *
46
+ * @remarks
47
+ * The new client adds the sign-in headers to each request. When a response has a 401 status, the client renews the
48
+ * sign-in and sends the request once more; this also happens when a negative test expects the 401 status. The
49
+ * sign-in replaces any sign-in of this client.
50
+ *
51
+ * @param authentication - The sign-in headers and the way to renew them.
52
+ * @returns A new client. This client does not change.
53
+ */
54
+ withAuthentication(authentication: Authentication): HttpClient;
55
+ /**
56
+ * Sends a request and returns the response, whatever its status.
57
+ *
58
+ * @remarks
59
+ * A redirect status (3xx) is returned, not followed. With {@link HttpClient.withAuthentication}, a 401 status
60
+ * renews the sign-in, and the request is sent once more.
61
+ *
62
+ * @param method - The HTTP method.
63
+ * @param path - The path of the request, resolved against the base URL.
64
+ * @param options - The query, headers, body and timeout of the request.
65
+ * @returns The response.
66
+ * @throws {Error} The URL is outside the base origin, in which case nothing is sent, or no response arrives. The
67
+ * message has secrets masked.
68
+ */
69
+ send(method: HttpMethod, path: string, options?: RequestOptions): Promise<HttpResponse>;
70
+ /**
71
+ * Sends a `GET` request. See {@link HttpClient.send}.
72
+ *
73
+ * @param path - The path of the request, resolved against the base URL.
74
+ * @param options - The query, headers, body and timeout of the request.
75
+ * @returns The response, whatever its status.
76
+ */
77
+ get(path: string, options?: RequestOptions): Promise<HttpResponse>;
78
+ /**
79
+ * Sends a `POST` request. See {@link HttpClient.send}.
80
+ *
81
+ * @param path - The path of the request, resolved against the base URL.
82
+ * @param options - The query, headers, body and timeout of the request.
83
+ * @returns The response, whatever its status.
84
+ */
85
+ post(path: string, options?: RequestOptions): Promise<HttpResponse>;
86
+ /**
87
+ * Sends a `PUT` request. See {@link HttpClient.send}.
88
+ *
89
+ * @param path - The path of the request, resolved against the base URL.
90
+ * @param options - The query, headers, body and timeout of the request.
91
+ * @returns The response, whatever its status.
92
+ */
93
+ put(path: string, options?: RequestOptions): Promise<HttpResponse>;
94
+ /**
95
+ * Sends a `PATCH` request. See {@link HttpClient.send}.
96
+ *
97
+ * @param path - The path of the request, resolved against the base URL.
98
+ * @param options - The query, headers, body and timeout of the request.
99
+ * @returns The response, whatever its status.
100
+ */
101
+ patch(path: string, options?: RequestOptions): Promise<HttpResponse>;
102
+ /**
103
+ * Sends a `DELETE` request. See {@link HttpClient.send}.
104
+ *
105
+ * @param path - The path of the request, resolved against the base URL.
106
+ * @param options - The query, headers, body and timeout of the request.
107
+ * @returns The response, whatever its status.
108
+ */
109
+ delete(path: string, options?: RequestOptions): Promise<HttpResponse>;
110
+ }
@@ -0,0 +1,237 @@
1
+ var _a;
2
+ import { errorMessage, maskSecrets, revealedFields, revealedJson, Secret } from "../core/index.js";
3
+ import { HttpResponse } from "./http-response.js";
4
+ const JSON_CONTENT_TYPE = { "content-type": "application/json" };
5
+ /**
6
+ * Represents an immutable HTTP client that sends requests through a request context, so the requests appear in test
7
+ * traces.
8
+ *
9
+ * @remarks
10
+ * - The client sends requests only to its own origin and does not follow redirects, so headers never reach another
11
+ * host.
12
+ * - The client does not throw for a status. Check the status with {@link HttpResponse.expectOk},
13
+ * {@link HttpResponse.json}, {@link HttpResponse.parse} or {@link HttpResponse.errorJson}.
14
+ * - The client throws an error, with secrets masked, when no response arrives. It does not retry.
15
+ * - The client reveals each {@link Secret} in the query, headers or body only when it sends the request, so callers
16
+ * do not call {@link Secret.reveal}.
17
+ *
18
+ * @example
19
+ * const client = new HttpClient(context, baseUrl).withHeaders({ "Accept-Language": "en-US" });
20
+ * const store = (await client.get(`/api/stores/${encodeURIComponent(id)}`)).parse(StoreSchema);
21
+ */
22
+ export class HttpClient {
23
+ #context;
24
+ #baseUrl;
25
+ #headers = noHeaders;
26
+ #authentication;
27
+ /**
28
+ * Creates a client that sends requests to one origin.
29
+ *
30
+ * @param context - The request context that sends the requests.
31
+ * @param baseUrl - The origin that requests are sent to, such as `http://localhost:8090`.
32
+ * @throws {Error} `baseUrl` is not a canonical origin. The message does not contain the URL.
33
+ */
34
+ constructor(context, baseUrl) {
35
+ if (URL.parse(baseUrl)?.origin !== baseUrl) {
36
+ throw new Error("baseUrl must be a canonical origin, such as http://localhost:8090");
37
+ }
38
+ this.#context = context;
39
+ this.#baseUrl = baseUrl;
40
+ }
41
+ /**
42
+ * Returns a client that also sends the specified headers.
43
+ *
44
+ * @remarks
45
+ * The headers replace headers of the same name, except the sign-in headers. A provider is called for each request.
46
+ *
47
+ * @param extra - The headers to send, or a provider that returns them.
48
+ * @returns A new client. This client does not change.
49
+ */
50
+ withHeaders(extra) {
51
+ const provider = typeof extra === "function" ? extra : constantHeaders({ ...extra });
52
+ const parent = this.#headers;
53
+ return this.#derive(async function chained() {
54
+ return mergeHeaders(await parent(), await provider());
55
+ }, this.#authentication);
56
+ }
57
+ /**
58
+ * Returns a client that signs in to each request.
59
+ *
60
+ * @remarks
61
+ * The new client adds the sign-in headers to each request. When a response has a 401 status, the client renews the
62
+ * sign-in and sends the request once more; this also happens when a negative test expects the 401 status. The
63
+ * sign-in replaces any sign-in of this client.
64
+ *
65
+ * @param authentication - The sign-in headers and the way to renew them.
66
+ * @returns A new client. This client does not change.
67
+ */
68
+ withAuthentication(authentication) {
69
+ return this.#derive(this.#headers, authentication);
70
+ }
71
+ /**
72
+ * Sends a request and returns the response, whatever its status.
73
+ *
74
+ * @remarks
75
+ * A redirect status (3xx) is returned, not followed. With {@link HttpClient.withAuthentication}, a 401 status
76
+ * renews the sign-in, and the request is sent once more.
77
+ *
78
+ * @param method - The HTTP method.
79
+ * @param path - The path of the request, resolved against the base URL.
80
+ * @param options - The query, headers, body and timeout of the request.
81
+ * @returns The response.
82
+ * @throws {Error} The URL is outside the base origin, in which case nothing is sent, or no response arrives. The
83
+ * message has secrets masked.
84
+ */
85
+ async send(method, path, options = {}) {
86
+ const url = this.#url(method, path, options.query);
87
+ const headers = await this.#currentHeaders();
88
+ const response = await this.#request(method, url, options, headers);
89
+ if (response.status !== 401 || this.#authentication === undefined) {
90
+ return response;
91
+ }
92
+ await this.#authentication.renew(headers);
93
+ return this.#request(method, url, options, await this.#currentHeaders());
94
+ }
95
+ /**
96
+ * Sends a `GET` request. See {@link HttpClient.send}.
97
+ *
98
+ * @param path - The path of the request, resolved against the base URL.
99
+ * @param options - The query, headers, body and timeout of the request.
100
+ * @returns The response, whatever its status.
101
+ */
102
+ get(path, options) {
103
+ return this.send("GET", path, options);
104
+ }
105
+ /**
106
+ * Sends a `POST` request. See {@link HttpClient.send}.
107
+ *
108
+ * @param path - The path of the request, resolved against the base URL.
109
+ * @param options - The query, headers, body and timeout of the request.
110
+ * @returns The response, whatever its status.
111
+ */
112
+ post(path, options) {
113
+ return this.send("POST", path, options);
114
+ }
115
+ /**
116
+ * Sends a `PUT` request. See {@link HttpClient.send}.
117
+ *
118
+ * @param path - The path of the request, resolved against the base URL.
119
+ * @param options - The query, headers, body and timeout of the request.
120
+ * @returns The response, whatever its status.
121
+ */
122
+ put(path, options) {
123
+ return this.send("PUT", path, options);
124
+ }
125
+ /**
126
+ * Sends a `PATCH` request. See {@link HttpClient.send}.
127
+ *
128
+ * @param path - The path of the request, resolved against the base URL.
129
+ * @param options - The query, headers, body and timeout of the request.
130
+ * @returns The response, whatever its status.
131
+ */
132
+ patch(path, options) {
133
+ return this.send("PATCH", path, options);
134
+ }
135
+ /**
136
+ * Sends a `DELETE` request. See {@link HttpClient.send}.
137
+ *
138
+ * @param path - The path of the request, resolved against the base URL.
139
+ * @param options - The query, headers, body and timeout of the request.
140
+ * @returns The response, whatever its status.
141
+ */
142
+ delete(path, options) {
143
+ return this.send("DELETE", path, options);
144
+ }
145
+ #derive(headers, authentication) {
146
+ const client = new _a(this.#context, this.#baseUrl);
147
+ client.#headers = headers;
148
+ client.#authentication = authentication;
149
+ return client;
150
+ }
151
+ async #currentHeaders() {
152
+ return mergeHeaders(await this.#headers(), (await this.#authentication?.headers()) ?? {});
153
+ }
154
+ #url(method, path, query = {}) {
155
+ const url = new URL(path, this.#baseUrl);
156
+ if (url.origin !== this.#baseUrl) {
157
+ throw new Error(maskSecrets(`${method} ${url.origin}${url.pathname}: a client only sends to ${this.#baseUrl}`));
158
+ }
159
+ for (const [name, value] of Object.entries(query)) {
160
+ for (const item of value === undefined ? [] : [value].flat()) {
161
+ url.searchParams.append(name, item instanceof Secret ? item.reveal() : String(item));
162
+ }
163
+ }
164
+ return url.href;
165
+ }
166
+ async #request(method, url, options, headers) {
167
+ const response = await this.#fetch(url, {
168
+ method,
169
+ headers: revealedFields(mergeHeaders(headersForBody(options, headers), options.headers ?? {})),
170
+ ...bodyOf(options),
171
+ ...(options.timeoutMs === undefined ? {} : { timeout: options.timeoutMs }),
172
+ maxRedirects: 0,
173
+ failOnStatusCode: false,
174
+ });
175
+ try {
176
+ return new HttpResponse({
177
+ method,
178
+ url: maskSecrets(response.url()),
179
+ status: response.status(),
180
+ statusText: response.statusText(),
181
+ headers: response.headers(),
182
+ text: await response.text(),
183
+ });
184
+ }
185
+ finally {
186
+ await response.dispose();
187
+ }
188
+ }
189
+ async #fetch(url, options) {
190
+ try {
191
+ return await this.#context.fetch(url, options);
192
+ }
193
+ catch (error) {
194
+ throw new Error(maskSecrets(errorMessage(error)));
195
+ }
196
+ }
197
+ }
198
+ _a = HttpClient;
199
+ async function noHeaders() {
200
+ return {};
201
+ }
202
+ function constantHeaders(headers) {
203
+ return async function provide() {
204
+ return headers;
205
+ };
206
+ }
207
+ function headersForBody(options, headers) {
208
+ if (options.json !== undefined) {
209
+ return mergeHeaders(headers, JSON_CONTENT_TYPE);
210
+ }
211
+ if (options.form !== undefined || options.multipart !== undefined) {
212
+ return Object.fromEntries(Object.entries(headers).filter(([name]) => name !== "content-type"));
213
+ }
214
+ return headers;
215
+ }
216
+ function bodyOf(options) {
217
+ if (options.json !== undefined) {
218
+ return { data: revealedJson(options.json) };
219
+ }
220
+ if (options.form !== undefined) {
221
+ return { form: revealedFields(options.form) };
222
+ }
223
+ if (options.multipart !== undefined) {
224
+ return { multipart: revealedFields(options.multipart) };
225
+ }
226
+ return {};
227
+ }
228
+ function mergeHeaders(...sources) {
229
+ const merged = {};
230
+ for (const source of sources) {
231
+ for (const [name, value] of Object.entries(source)) {
232
+ merged[name.toLowerCase()] = value;
233
+ }
234
+ }
235
+ return merged;
236
+ }
237
+ //# sourceMappingURL=http-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/http/http-client.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,MAAM,iBAAiB,GAAmB,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAEjF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,UAAU;IACZ,QAAQ,CAAoB;IAC5B,QAAQ,CAAS;IAC1B,QAAQ,GAAmB,SAAS,CAAC;IACrC,eAAe,CAA6B;IAE5C;;;;;;OAMG;IACH,YAAY,OAA0B,EAAE,OAAe;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MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QACrC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { APIRequestContext, APIResponse } from \"@playwright/test\";\nimport type { Authentication } from \"./authentication.ts\";\nimport type { HttpMethod } from \"./http-method.ts\";\nimport type { HeaderProvider, QueryParams, RequestHeaders, RequestOptions } from \"./request-options.ts\";\n\nimport { errorMessage, maskSecrets, revealedFields, revealedJson, Secret } from \"@/core\";\n\nimport { HttpResponse } from \"./http-response.ts\";\n\ntype FetchOptions = NonNullable<Parameters<APIRequestContext[\"fetch\"]>[1]>;\n\nconst JSON_CONTENT_TYPE: RequestHeaders = { \"content-type\": \"application/json\" };\n\n/**\n * Represents an immutable HTTP client that sends requests through a request context, so the requests appear in test\n * traces.\n *\n * @remarks\n * - The client sends requests only to its own origin and does not follow redirects, so headers never reach another\n * host.\n * - The client does not throw for a status. Check the status with {@link HttpResponse.expectOk},\n * {@link HttpResponse.json}, {@link HttpResponse.parse} or {@link HttpResponse.errorJson}.\n * - The client throws an error, with secrets masked, when no response arrives. It does not retry.\n * - The client reveals each {@link Secret} in the query, headers or body only when it sends the request, so callers\n * do not call {@link Secret.reveal}.\n *\n * @example\n * const client = new HttpClient(context, baseUrl).withHeaders({ \"Accept-Language\": \"en-US\" });\n * const store = (await client.get(`/api/stores/${encodeURIComponent(id)}`)).parse(StoreSchema);\n */\nexport class HttpClient {\n readonly #context: APIRequestContext;\n readonly #baseUrl: string;\n #headers: HeaderProvider = noHeaders;\n #authentication: Authentication | undefined;\n\n /**\n * Creates a client that sends requests to one origin.\n *\n * @param context - The request context that sends the requests.\n * @param baseUrl - The origin that requests are sent to, such as `http://localhost:8090`.\n * @throws {Error} `baseUrl` is not a canonical origin. The message does not contain the URL.\n */\n constructor(context: APIRequestContext, baseUrl: string) {\n if (URL.parse(baseUrl)?.origin !== baseUrl) {\n throw new Error(\"baseUrl must be a canonical origin, such as http://localhost:8090\");\n }\n this.#context = context;\n this.#baseUrl = baseUrl;\n }\n\n /**\n * Returns a client that also sends the specified headers.\n *\n * @remarks\n * The headers replace headers of the same name, except the sign-in headers. A provider is called for each request.\n *\n * @param extra - The headers to send, or a provider that returns them.\n * @returns A new client. This client does not change.\n */\n withHeaders(extra: RequestHeaders | HeaderProvider): HttpClient {\n const provider = typeof extra === \"function\" ? extra : constantHeaders({ ...extra });\n const parent = this.#headers;\n return this.#derive(async function chained() {\n return mergeHeaders(await parent(), await provider());\n }, this.#authentication);\n }\n\n /**\n * Returns a client that signs in to each request.\n *\n * @remarks\n * The new client adds the sign-in headers to each request. When a response has a 401 status, the client renews the\n * sign-in and sends the request once more; this also happens when a negative test expects the 401 status. The\n * sign-in replaces any sign-in of this client.\n *\n * @param authentication - The sign-in headers and the way to renew them.\n * @returns A new client. This client does not change.\n */\n withAuthentication(authentication: Authentication): HttpClient {\n return this.#derive(this.#headers, authentication);\n }\n\n /**\n * Sends a request and returns the response, whatever its status.\n *\n * @remarks\n * A redirect status (3xx) is returned, not followed. With {@link HttpClient.withAuthentication}, a 401 status\n * renews the sign-in, and the request is sent once more.\n *\n * @param method - The HTTP method.\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response.\n * @throws {Error} The URL is outside the base origin, in which case nothing is sent, or no response arrives. The\n * message has secrets masked.\n */\n async send(method: HttpMethod, path: string, options: RequestOptions = {}): Promise<HttpResponse> {\n const url = this.#url(method, path, options.query);\n const headers = await this.#currentHeaders();\n const response = await this.#request(method, url, options, headers);\n if (response.status !== 401 || this.#authentication === undefined) {\n return response;\n }\n await this.#authentication.renew(headers);\n return this.#request(method, url, options, await this.#currentHeaders());\n }\n\n /**\n * Sends a `GET` request. See {@link HttpClient.send}.\n *\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response, whatever its status.\n */\n get(path: string, options?: RequestOptions): Promise<HttpResponse> {\n return this.send(\"GET\", path, options);\n }\n\n /**\n * Sends a `POST` request. See {@link HttpClient.send}.\n *\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response, whatever its status.\n */\n post(path: string, options?: RequestOptions): Promise<HttpResponse> {\n return this.send(\"POST\", path, options);\n }\n\n /**\n * Sends a `PUT` request. See {@link HttpClient.send}.\n *\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response, whatever its status.\n */\n put(path: string, options?: RequestOptions): Promise<HttpResponse> {\n return this.send(\"PUT\", path, options);\n }\n\n /**\n * Sends a `PATCH` request. See {@link HttpClient.send}.\n *\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response, whatever its status.\n */\n patch(path: string, options?: RequestOptions): Promise<HttpResponse> {\n return this.send(\"PATCH\", path, options);\n }\n\n /**\n * Sends a `DELETE` request. See {@link HttpClient.send}.\n *\n * @param path - The path of the request, resolved against the base URL.\n * @param options - The query, headers, body and timeout of the request.\n * @returns The response, whatever its status.\n */\n delete(path: string, options?: RequestOptions): Promise<HttpResponse> {\n return this.send(\"DELETE\", path, options);\n }\n\n #derive(headers: HeaderProvider, authentication: Authentication | undefined): HttpClient {\n const client = new HttpClient(this.#context, this.#baseUrl);\n client.#headers = headers;\n client.#authentication = authentication;\n return client;\n }\n\n async #currentHeaders(): Promise<RequestHeaders> {\n return mergeHeaders(await this.#headers(), (await this.#authentication?.headers()) ?? {});\n }\n\n #url(method: HttpMethod, path: string, query: QueryParams = {}): string {\n const url = new URL(path, this.#baseUrl);\n if (url.origin !== this.#baseUrl) {\n throw new Error(maskSecrets(`${method} ${url.origin}${url.pathname}: a client only sends to ${this.#baseUrl}`));\n }\n for (const [name, value] of Object.entries(query)) {\n for (const item of value === undefined ? [] : [value].flat()) {\n url.searchParams.append(name, item instanceof Secret ? item.reveal() : String(item));\n }\n }\n return url.href;\n }\n\n async #request(\n method: HttpMethod,\n url: string,\n options: RequestOptions,\n headers: RequestHeaders,\n ): Promise<HttpResponse> {\n const response = await this.#fetch(url, {\n method,\n headers: revealedFields(mergeHeaders(headersForBody(options, headers), options.headers ?? {})),\n ...bodyOf(options),\n ...(options.timeoutMs === undefined ? {} : { timeout: options.timeoutMs }),\n maxRedirects: 0,\n failOnStatusCode: false,\n });\n\n try {\n return new HttpResponse({\n method,\n url: maskSecrets(response.url()),\n status: response.status(),\n statusText: response.statusText(),\n headers: response.headers(),\n text: await response.text(),\n });\n } finally {\n await response.dispose();\n }\n }\n\n async #fetch(url: string, options: FetchOptions): Promise<APIResponse> {\n try {\n return await this.#context.fetch(url, options);\n } catch (error) {\n throw new Error(maskSecrets(errorMessage(error)));\n }\n }\n}\n\nasync function noHeaders(): Promise<RequestHeaders> {\n return {};\n}\n\nfunction constantHeaders(headers: RequestHeaders): HeaderProvider {\n return async function provide() {\n return headers;\n };\n}\n\nfunction headersForBody(options: RequestOptions, headers: RequestHeaders): RequestHeaders {\n if (options.json !== undefined) {\n return mergeHeaders(headers, JSON_CONTENT_TYPE);\n }\n if (options.form !== undefined || options.multipart !== undefined) {\n return Object.fromEntries(Object.entries(headers).filter(([name]: [string, unknown]) => name !== \"content-type\"));\n }\n return headers;\n}\n\nfunction bodyOf(options: RequestOptions): Pick<FetchOptions, \"data\" | \"form\" | \"multipart\"> {\n if (options.json !== undefined) {\n return { data: revealedJson(options.json) };\n }\n if (options.form !== undefined) {\n return { form: revealedFields(options.form) };\n }\n if (options.multipart !== undefined) {\n return { multipart: revealedFields(options.multipart) };\n }\n return {};\n}\n\nfunction mergeHeaders(...sources: readonly RequestHeaders[]): RequestHeaders {\n const merged: Record<string, string | Secret> = {};\n for (const source of sources) {\n for (const [name, value] of Object.entries(source)) {\n merged[name.toLowerCase()] = value;\n }\n }\n return merged;\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /** Represents a response that is not what the caller expected. The message and body have secrets masked. */
2
+ export declare class HttpError extends Error {
3
+ /** The name of the error type, `HttpError`. */
4
+ readonly name = "HttpError";
5
+ /** The status of the response. */
6
+ readonly status: number;
7
+ /** The body of the response, with secrets masked. */
8
+ readonly body: string;
9
+ /**
10
+ * Creates an error for a response.
11
+ *
12
+ * @param message - The description of the error. Secrets in it are masked.
13
+ * @param status - The status of the response.
14
+ * @param body - The body of the response. Secrets in it are masked.
15
+ * @param options - The options of the error, such as its cause.
16
+ */
17
+ constructor(message: string, status: number, body?: string, options?: ErrorOptions);
18
+ /**
19
+ * Determines whether a value is an {@link HttpError} with one of the specified statuses.
20
+ *
21
+ * @param error - The value to check.
22
+ * @param statuses - The statuses to match.
23
+ * @returns `true` if the value is an {@link HttpError} and its status is one of `statuses`; otherwise, `false`.
24
+ */
25
+ static hasStatus(error: unknown, ...statuses: readonly number[]): error is HttpError;
26
+ }
@@ -0,0 +1,34 @@
1
+ import { maskSecrets } from "../core/index.js";
2
+ /** Represents a response that is not what the caller expected. The message and body have secrets masked. */
3
+ export class HttpError extends Error {
4
+ /** The name of the error type, `HttpError`. */
5
+ name = "HttpError";
6
+ /** The status of the response. */
7
+ status;
8
+ /** The body of the response, with secrets masked. */
9
+ body;
10
+ /**
11
+ * Creates an error for a response.
12
+ *
13
+ * @param message - The description of the error. Secrets in it are masked.
14
+ * @param status - The status of the response.
15
+ * @param body - The body of the response. Secrets in it are masked.
16
+ * @param options - The options of the error, such as its cause.
17
+ */
18
+ constructor(message, status, body = "", options) {
19
+ super(maskSecrets(message), options);
20
+ this.status = status;
21
+ this.body = maskSecrets(body);
22
+ }
23
+ /**
24
+ * Determines whether a value is an {@link HttpError} with one of the specified statuses.
25
+ *
26
+ * @param error - The value to check.
27
+ * @param statuses - The statuses to match.
28
+ * @returns `true` if the value is an {@link HttpError} and its status is one of `statuses`; otherwise, `false`.
29
+ */
30
+ static hasStatus(error, ...statuses) {
31
+ return error instanceof HttpError && statuses.includes(error.status);
32
+ }
33
+ }
34
+ //# sourceMappingURL=http-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../src/http/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,4GAA4G;AAC5G,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,+CAA+C;IAC7B,IAAI,GAAG,WAAW,CAAC;IAErC,kCAAkC;IACzB,MAAM,CAAS;IAExB,qDAAqD;IAC5C,IAAI,CAAS;IAEtB;;;;;;;OAOG;IACH,YAAY,OAAe,EAAE,MAAc,EAAE,IAAI,GAAW,EAAE,EAAE,OAAsB;QACpF,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,KAAc,EAAE,GAAG,QAA2B;QAC7D,OAAO,KAAK,YAAY,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACvE,CAAC;CACF","sourcesContent":["import { maskSecrets } from \"@/core\";\n\n/** Represents a response that is not what the caller expected. The message and body have secrets masked. */\nexport class HttpError extends Error {\n /** The name of the error type, `HttpError`. */\n override readonly name = \"HttpError\";\n\n /** The status of the response. */\n readonly status: number;\n\n /** The body of the response, with secrets masked. */\n readonly body: string;\n\n /**\n * Creates an error for a response.\n *\n * @param message - The description of the error. Secrets in it are masked.\n * @param status - The status of the response.\n * @param body - The body of the response. Secrets in it are masked.\n * @param options - The options of the error, such as its cause.\n */\n constructor(message: string, status: number, body: string = \"\", options?: ErrorOptions) {\n super(maskSecrets(message), options);\n this.status = status;\n this.body = maskSecrets(body);\n }\n\n /**\n * Determines whether a value is an {@link HttpError} with one of the specified statuses.\n *\n * @param error - The value to check.\n * @param statuses - The statuses to match.\n * @returns `true` if the value is an {@link HttpError} and its status is one of `statuses`; otherwise, `false`.\n */\n static hasStatus(error: unknown, ...statuses: readonly number[]): error is HttpError {\n return error instanceof HttpError && statuses.includes(error.status);\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ /** The HTTP methods that an {@link HttpClient} sends. */
2
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http-method.js.map