@api-client/core 0.12.10 → 0.12.11

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 (67) hide show
  1. package/build/src/browser.d.ts +0 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +0 -1
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/exceptions/exception.d.ts +29 -1
  6. package/build/src/exceptions/exception.d.ts.map +1 -1
  7. package/build/src/exceptions/exception.js +37 -1
  8. package/build/src/exceptions/exception.js.map +1 -1
  9. package/build/src/index.d.ts +0 -1
  10. package/build/src/index.d.ts.map +1 -1
  11. package/build/src/index.js +0 -1
  12. package/build/src/index.js.map +1 -1
  13. package/build/src/proxy/HttpProjectProxy.d.ts.map +1 -1
  14. package/build/src/proxy/HttpProjectProxy.js +39 -43
  15. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  16. package/build/src/proxy/RequestProxy.d.ts.map +1 -1
  17. package/build/src/proxy/RequestProxy.js +11 -11
  18. package/build/src/proxy/RequestProxy.js.map +1 -1
  19. package/build/src/runtime/store/DataCatalogSdk.d.ts.map +1 -1
  20. package/build/src/runtime/store/DataCatalogSdk.js +49 -109
  21. package/build/src/runtime/store/DataCatalogSdk.js.map +1 -1
  22. package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
  23. package/build/src/runtime/store/FilesSdk.js +51 -115
  24. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  25. package/build/src/runtime/store/HistorySdk.d.ts.map +1 -1
  26. package/build/src/runtime/store/HistorySdk.js +25 -70
  27. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  28. package/build/src/runtime/store/OrganizationsSdk.d.ts.map +1 -1
  29. package/build/src/runtime/store/OrganizationsSdk.js +46 -50
  30. package/build/src/runtime/store/OrganizationsSdk.js.map +1 -1
  31. package/build/src/runtime/store/RevisionsSdk.d.ts.map +1 -1
  32. package/build/src/runtime/store/RevisionsSdk.js +5 -10
  33. package/build/src/runtime/store/RevisionsSdk.js.map +1 -1
  34. package/build/src/runtime/store/SdkBase.d.ts +7 -5
  35. package/build/src/runtime/store/SdkBase.d.ts.map +1 -1
  36. package/build/src/runtime/store/SdkBase.js +45 -63
  37. package/build/src/runtime/store/SdkBase.js.map +1 -1
  38. package/build/src/runtime/store/SharedSdk.d.ts.map +1 -1
  39. package/build/src/runtime/store/SharedSdk.js +5 -14
  40. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  41. package/build/src/runtime/store/TrashSdk.d.ts.map +1 -1
  42. package/build/src/runtime/store/TrashSdk.js +8 -28
  43. package/build/src/runtime/store/TrashSdk.js.map +1 -1
  44. package/build/src/runtime/store/UsersSdk.d.ts.map +1 -1
  45. package/build/src/runtime/store/UsersSdk.js +12 -11
  46. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  47. package/data/models/example-generator-api.json +8 -8
  48. package/package.json +1 -1
  49. package/src/exceptions/exception.ts +51 -4
  50. package/src/proxy/HttpProjectProxy.ts +39 -43
  51. package/src/proxy/RequestProxy.ts +11 -11
  52. package/src/runtime/store/DataCatalogSdk.ts +49 -109
  53. package/src/runtime/store/FilesSdk.ts +51 -115
  54. package/src/runtime/store/HistorySdk.ts +25 -70
  55. package/src/runtime/store/OrganizationsSdk.ts +46 -50
  56. package/src/runtime/store/RevisionsSdk.ts +5 -10
  57. package/src/runtime/store/SdkBase.ts +46 -65
  58. package/src/runtime/store/SharedSdk.ts +5 -14
  59. package/src/runtime/store/TrashSdk.ts +8 -28
  60. package/src/runtime/store/UsersSdk.ts +12 -11
  61. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +42 -40
  62. package/tests/unit/runtime/proxy/RequestProxy.spec.ts +11 -11
  63. package/build/src/runtime/store/Errors.d.ts +0 -51
  64. package/build/src/runtime/store/Errors.d.ts.map +0 -1
  65. package/build/src/runtime/store/Errors.js +0 -61
  66. package/build/src/runtime/store/Errors.js.map +0 -1
  67. package/src/runtime/store/Errors.ts +0 -98
@@ -42470,13 +42470,13 @@
42470
42470
  "@id": "#219"
42471
42471
  },
42472
42472
  {
42473
- "@id": "#210"
42473
+ "@id": "#216"
42474
42474
  },
42475
42475
  {
42476
- "@id": "#213"
42476
+ "@id": "#210"
42477
42477
  },
42478
42478
  {
42479
- "@id": "#216"
42479
+ "@id": "#213"
42480
42480
  },
42481
42481
  {
42482
42482
  "@id": "#219"
@@ -43892,7 +43892,7 @@
43892
43892
  "doc:ExternalDomainElement",
43893
43893
  "doc:DomainElement"
43894
43894
  ],
43895
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
43895
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
43896
43896
  "core:mediaType": "application/yaml",
43897
43897
  "sourcemaps:sources": [
43898
43898
  {
@@ -43913,7 +43913,7 @@
43913
43913
  "doc:ExternalDomainElement",
43914
43914
  "doc:DomainElement"
43915
43915
  ],
43916
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
43916
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
43917
43917
  "core:mediaType": "application/yaml",
43918
43918
  "sourcemaps:sources": [
43919
43919
  {
@@ -43934,7 +43934,7 @@
43934
43934
  "doc:ExternalDomainElement",
43935
43935
  "doc:DomainElement"
43936
43936
  ],
43937
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
43937
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
43938
43938
  "core:mediaType": "application/yaml",
43939
43939
  "sourcemaps:sources": [
43940
43940
  {
@@ -44781,12 +44781,12 @@
44781
44781
  {
44782
44782
  "@id": "#215/source-map/lexical/element_0",
44783
44783
  "sourcemaps:element": "amf://id#215",
44784
- "sourcemaps:value": "[(1,0)-(6,0)]"
44784
+ "sourcemaps:value": "[(1,0)-(7,0)]"
44785
44785
  },
44786
44786
  {
44787
44787
  "@id": "#218/source-map/lexical/element_0",
44788
44788
  "sourcemaps:element": "amf://id#218",
44789
- "sourcemaps:value": "[(1,0)-(7,0)]"
44789
+ "sourcemaps:value": "[(1,0)-(6,0)]"
44790
44790
  },
44791
44791
  {
44792
44792
  "@id": "#221/source-map/lexical/element_0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.12.10",
4
+ "version": "0.12.11",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -1,3 +1,13 @@
1
+ export interface ExceptionSchema {
2
+ name: string
3
+ message: string
4
+ status?: number
5
+ code?: string
6
+ help?: string
7
+ stack?: string
8
+ [key: string]: string | number | undefined
9
+ }
10
+
1
11
  /**
2
12
  * Create a custom error class with the ability to define the error
3
13
  * code, status, and the help text.
@@ -46,7 +56,44 @@ export class Exception extends Error {
46
56
  */
47
57
  status: number
48
58
 
49
- constructor(message?: string, options?: ErrorOptions & { code?: string; status?: number }) {
59
+ /**
60
+ * Create a new exception instance.
61
+ * It tries to extract the error code and status from the
62
+ * `init` object. If not found, it uses the default message.
63
+ * @param init - An object containing error details
64
+ * @param defaultMessage - A default message to use if `init.message` is not provided
65
+ * @returns An instance of the Exception class
66
+ * @example
67
+ * ```js
68
+ * const error = Exception.fromApiError({
69
+ * code: 'E_FILE_NOT_FOUND',
70
+ * status: 404,
71
+ * message: 'File not found',
72
+ * help: 'Please check the file path and try again'
73
+ * }, 'An error occurred while processing your request')
74
+ * ```
75
+ */
76
+ static fromRawException(init: object, defaultMessage: string): Exception {
77
+ const typed = init as Record<string, string | number>
78
+ const options: ErrorOptions & { code?: string; status?: number } = {}
79
+ if (typed.code) {
80
+ options.code = typed.code as string
81
+ }
82
+ if (typed.status) {
83
+ options.status = Number(typed.status)
84
+ }
85
+ const message = typed.message ?? defaultMessage
86
+ const result = new this(message as string, options)
87
+ if (typed.help) {
88
+ result.setHelp(typed.help as string)
89
+ }
90
+ if (typed.name) {
91
+ result.name = typed.name as string
92
+ }
93
+ return result
94
+ }
95
+
96
+ constructor(message?: string, options?: ErrorOptions & { code?: string; status?: number; help?: string }) {
50
97
  super(message, options)
51
98
 
52
99
  const ErrorConstructor = this.constructor as typeof Exception
@@ -60,7 +107,7 @@ export class Exception extends Error {
60
107
  this.code = code
61
108
  }
62
109
 
63
- const help = ErrorConstructor.help
110
+ const help = options?.help || ErrorConstructor.help
64
111
  if (help !== undefined) {
65
112
  this.help = help
66
113
  }
@@ -94,8 +141,8 @@ export class Exception extends Error {
94
141
  return `${this.name}: ${this.message}`
95
142
  }
96
143
 
97
- toJSON() {
98
- const result: Record<string, string | number> = {
144
+ toJSON(): ExceptionSchema {
145
+ const result: ExceptionSchema = {
99
146
  name: this.name,
100
147
  message: this.message,
101
148
  }
@@ -1,11 +1,11 @@
1
1
  import { IProjectRunnerOptions } from '../runtime/node/InteropInterfaces.js'
2
2
  import { Kind as HttpProjectKind, HttpProject, IHttpProject } from '../models/HttpProject.js'
3
- import { ApiError } from '../runtime/store/Errors.js'
4
3
  import { StoreSdk } from '../runtime/store/StoreSdkNode.js'
5
4
  import { ProjectSerialRunner } from '../runtime/node/ProjectSerialRunner.js'
6
5
  import { ProjectParallelRunner } from '../runtime/node/ProjectParallelRunner.js'
7
6
  import Proxy, { IProxyResult } from './Proxy.js'
8
7
  import { IProjectExecutionLog } from '../models/ProjectExecution.js'
8
+ import { Exception } from '../exceptions/exception.js'
9
9
 
10
10
  interface ProxyInit {
11
11
  kind: typeof HttpProjectKind
@@ -44,52 +44,48 @@ export default class HttpProjectProxy extends Proxy {
44
44
 
45
45
  protected async configureStore(init: IHttpProjectStoreProxyInit, token: string, baseUri: string): Promise<void> {
46
46
  const { pid, options, organization } = init
47
+ const INVALID_REQUEST = 'Invalid request'
48
+ const code = 'E_INVALID_REQUEST'
47
49
  if (!pid) {
48
- throw new ApiError({
49
- error: true,
50
- message: 'Invalid request',
51
- detail: 'The "pid" parameter is required.',
52
- code: 400,
50
+ throw new Exception(INVALID_REQUEST, {
51
+ help: 'The "pid" parameter is required.',
52
+ status: 400,
53
+ code,
53
54
  })
54
55
  }
55
56
  if (!organization) {
56
- throw new ApiError({
57
- error: true,
58
- message: 'Invalid request',
59
- detail: 'The "organization" parameter is required.',
60
- code: 400,
57
+ throw new Exception(INVALID_REQUEST, {
58
+ help: 'The "organization" parameter is required.',
59
+ status: 400,
60
+ code,
61
61
  })
62
62
  }
63
63
  if (!options) {
64
- throw new ApiError({
65
- error: true,
66
- message: 'Invalid request',
67
- detail: 'The "options" parameter is required.',
68
- code: 400,
64
+ throw new Exception(INVALID_REQUEST, {
65
+ help: 'The "options" parameter is required.',
66
+ status: 400,
67
+ code,
69
68
  })
70
69
  }
71
70
  if (!token) {
72
- throw new ApiError({
73
- error: true,
74
- message: 'Invalid request',
75
- detail: 'Set the authentication credentials.',
76
- code: 400,
71
+ throw new Exception(INVALID_REQUEST, {
72
+ help: 'Set the authentication credentials.',
73
+ status: 400,
74
+ code,
77
75
  })
78
76
  }
79
77
  if (!baseUri) {
80
- throw new ApiError({
81
- error: true,
82
- message: 'Invalid request',
83
- detail: 'The store uri is missing.',
84
- code: 400,
78
+ throw new Exception(INVALID_REQUEST, {
79
+ help: 'The store uri is missing.',
80
+ status: 400,
81
+ code,
85
82
  })
86
83
  }
87
84
  if (!baseUri.startsWith('http')) {
88
- throw new ApiError({
89
- error: true,
90
- message: 'Invalid request',
91
- detail: 'The store uri is invalid.',
92
- code: 400,
85
+ throw new Exception(INVALID_REQUEST, {
86
+ help: 'The store uri is invalid.',
87
+ status: 400,
88
+ code,
93
89
  })
94
90
  }
95
91
  const sdk = new StoreSdk(baseUri)
@@ -100,10 +96,10 @@ export default class HttpProjectProxy extends Proxy {
100
96
  project = data.media as IHttpProject
101
97
  } catch (cause) {
102
98
  const e = cause as Error
103
- throw new ApiError(e.message, 400)
99
+ throw new Exception(e.message, { status: 400 })
104
100
  }
105
101
  if (project.key !== pid) {
106
- throw new ApiError(`Unable to read the project.`, 500)
102
+ throw new Exception(`Unable to read the project.`, { status: 500 })
107
103
  }
108
104
  this.options = options
109
105
  this.project = new HttpProject(project)
@@ -111,20 +107,20 @@ export default class HttpProjectProxy extends Proxy {
111
107
 
112
108
  protected async configureProject(init: IHttpProjectProxyInit): Promise<void> {
113
109
  const { project, options } = init
110
+ const INVALID_REQUEST = 'Invalid request'
111
+ const code = 'E_INVALID_REQUEST'
114
112
  if (!options) {
115
- throw new ApiError({
116
- error: true,
117
- message: 'Invalid request',
118
- detail: 'The "options" parameter is required.',
119
- code: 400,
113
+ throw new Exception(INVALID_REQUEST, {
114
+ help: 'The "options" parameter is required.',
115
+ status: 400,
116
+ code,
120
117
  })
121
118
  }
122
119
  if (!project) {
123
- throw new ApiError({
124
- error: true,
125
- message: 'Invalid request',
126
- detail: 'The "project" parameter is required.',
127
- code: 400,
120
+ throw new Exception(INVALID_REQUEST, {
121
+ help: 'The "project" parameter is required.',
122
+ status: 400,
123
+ code,
128
124
  })
129
125
  }
130
126
  this.options = options
@@ -3,12 +3,12 @@ import { IRequestAuthorization } from '../models/RequestAuthorization.js'
3
3
  import { IRequestConfig } from '../models/RequestConfig.js'
4
4
  import Proxy, { IProxyResult } from './Proxy.js'
5
5
  import { HttpCertificate } from '../models/ClientCertificate.js'
6
- import { ApiError } from '../runtime/store/Errors.js'
7
6
  import { DummyLogger } from '../lib/logging/DummyLogger.js'
8
7
  import { HttpRequestRunner } from '../runtime/http-runner/HttpRequestRunner.js'
9
8
  import { IRequestLog } from '../models/RequestLog.js'
10
9
  import { IHttpFlow } from '../models/http-flows/HttpFlows.js'
11
10
  import { IHttpAssertion } from '../models/http-flows/HttpAssertion.js'
11
+ import { Exception } from '../exceptions/exception.js'
12
12
 
13
13
  export interface IRequestProxyInit {
14
14
  kind: typeof HttpRequestKind
@@ -54,20 +54,20 @@ export default class RequestProxy extends Proxy {
54
54
 
55
55
  async configure(init: IRequestProxyInit): Promise<void> {
56
56
  const { request } = init
57
+ const INVALID_REQUEST = 'Invalid request'
58
+ const code = 'E_INVALID_REQUEST'
57
59
  if (!request) {
58
- throw new ApiError({
59
- error: true,
60
- message: 'Invalid request',
61
- detail: 'The "request" parameter is required.',
62
- code: 400,
60
+ throw new Exception(INVALID_REQUEST, {
61
+ help: 'The "request" parameter is required.',
62
+ status: 400,
63
+ code,
63
64
  })
64
65
  }
65
66
  if (!request.url) {
66
- throw new ApiError({
67
- error: true,
68
- message: 'Invalid request',
69
- detail: 'The "request.url" parameter is required.',
70
- code: 400,
67
+ throw new Exception(INVALID_REQUEST, {
68
+ help: 'The "request.url" parameter is required.',
69
+ status: 400,
70
+ code,
71
71
  })
72
72
  }
73
73
  this.init = init