@api-client/core 0.18.1 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.18.1",
4
+ "version": "0.18.2",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -12,7 +12,40 @@ import type {
12
12
  UsernamePasswordConfiguration,
13
13
  } from './types.js'
14
14
  import { DataDomain } from './DataDomain.js'
15
- import { DependentModel, type DomainDependency, type DependentModelSchema } from './DependentModel.js'
15
+ import { DependentModel, type DependentModelSchema, type DomainDependency } from './DependentModel.js'
16
+ import { observed, toRaw } from './observed.js'
17
+
18
+ /**
19
+ * Contact information for the exposed API.
20
+ */
21
+ export interface ApiContact {
22
+ /**
23
+ * The identifying name of the contact person/organization.
24
+ */
25
+ name?: string
26
+ /**
27
+ * The URL pointing to the contact information. MUST be in the format of a URL.
28
+ */
29
+ url?: string
30
+ /**
31
+ * The email address of the contact person/organization. MUST be in the format of an email address.
32
+ */
33
+ email?: string
34
+ }
35
+
36
+ /**
37
+ * License information for the exposed API.
38
+ */
39
+ export interface ApiLicense {
40
+ /**
41
+ * The license name used for the API. It is recommended to be an SPDX license identifier.
42
+ */
43
+ name: string
44
+ /**
45
+ * A URL to the license used for the API. MUST be in the format of a URL.
46
+ */
47
+ url?: string
48
+ }
16
49
 
17
50
  export interface ApiModelSchema extends DependentModelSchema {
18
51
  /**
@@ -74,6 +107,18 @@ export interface ApiModelSchema extends DependentModelSchema {
74
107
  * Defines rules to protect the API from overuse.
75
108
  */
76
109
  rateLimiting?: RateLimitingConfiguration
110
+ /**
111
+ * A URL to the Terms of Service for the API.
112
+ */
113
+ termsOfService?: string
114
+ /**
115
+ * The contact information for the exposed API.
116
+ */
117
+ contact?: ApiContact
118
+ /**
119
+ * The license information for the API.
120
+ */
121
+ license?: ApiLicense
77
122
  }
78
123
 
79
124
  export class ApiModel extends DependentModel {
@@ -135,6 +180,18 @@ export class ApiModel extends DependentModel {
135
180
  * Defines rules to protect the API from overuse.
136
181
  */
137
182
  rateLimiting?: RateLimitingConfiguration
183
+ /**
184
+ * A URL to the Terms of Service for the API.
185
+ */
186
+ @observed() accessor termsOfService: string | undefined
187
+ /**
188
+ * The contact information for the exposed API.
189
+ */
190
+ @observed({ deep: true }) accessor contact: ApiContact | undefined
191
+ /**
192
+ * The license information for the API.
193
+ */
194
+ @observed({ deep: true }) accessor license: ApiLicense | undefined
138
195
 
139
196
  /**
140
197
  * When the initializing flag is set to true,
@@ -196,6 +253,15 @@ export class ApiModel extends DependentModel {
196
253
  if (input.rateLimiting) {
197
254
  result.rateLimiting = input.rateLimiting
198
255
  }
256
+ if (input.termsOfService) {
257
+ result.termsOfService = input.termsOfService
258
+ }
259
+ if (input.contact) {
260
+ result.contact = structuredClone(input.contact)
261
+ }
262
+ if (input.license) {
263
+ result.license = structuredClone(input.license)
264
+ }
199
265
  return result
200
266
  }
201
267
 
@@ -234,6 +300,15 @@ export class ApiModel extends DependentModel {
234
300
  if (init.rateLimiting) {
235
301
  this.rateLimiting = structuredClone(init.rateLimiting)
236
302
  }
303
+ if (init.termsOfService) {
304
+ this.termsOfService = init.termsOfService
305
+ }
306
+ if (init.contact) {
307
+ this.contact = init.contact
308
+ }
309
+ if (init.license) {
310
+ this.license = init.license
311
+ }
237
312
  this.#initializing = false
238
313
  this.info.addEventListener('change', () => {
239
314
  this.notifyChange()
@@ -268,6 +343,15 @@ export class ApiModel extends DependentModel {
268
343
  if (this.rateLimiting) {
269
344
  result.rateLimiting = structuredClone(this.rateLimiting)
270
345
  }
346
+ if (this.termsOfService) {
347
+ result.termsOfService = this.termsOfService
348
+ }
349
+ if (this.contact) {
350
+ result.contact = structuredClone(toRaw(this, this.contact))
351
+ }
352
+ if (this.license) {
353
+ result.license = structuredClone(toRaw(this, this.license))
354
+ }
271
355
  return result
272
356
  }
273
357
 
@@ -6,6 +6,8 @@ import {
6
6
  type RolesBasedAccessControl,
7
7
  type ApiModelSchema,
8
8
  type ExposedEntity,
9
+ type ApiContact,
10
+ type ApiLicense,
9
11
  } from '../../../src/index.js'
10
12
 
11
13
  test.group('ApiModel.createSchema()', (g) => {
@@ -26,6 +28,9 @@ test.group('ApiModel.createSchema()', (g) => {
26
28
  assert.isUndefined(schema.session)
27
29
  assert.isUndefined(schema.accessRule)
28
30
  assert.isUndefined(schema.rateLimiting)
31
+ assert.isUndefined(schema.termsOfService)
32
+ assert.isUndefined(schema.contact)
33
+ assert.isUndefined(schema.license)
29
34
  })
30
35
 
31
36
  test('creates a schema with provided values', ({ assert }) => {
@@ -40,6 +45,9 @@ test.group('ApiModel.createSchema()', (g) => {
40
45
  session: { secret: 'secret', properties: ['email'] },
41
46
  accessRule: [{ type: 'public' }],
42
47
  rateLimiting: { rules: [] },
48
+ termsOfService: 'https://example.com/terms',
49
+ contact: { name: 'John Doe', email: 'john.doe@example.com' } as ApiContact,
50
+ license: { name: 'MIT', url: 'https://opensource.org/licenses/MIT' } as ApiLicense,
43
51
  }
44
52
  const schema = ApiModel.createSchema(input)
45
53
 
@@ -54,6 +62,9 @@ test.group('ApiModel.createSchema()', (g) => {
54
62
  assert.deepEqual(schema.session, { secret: 'secret', properties: ['email'] })
55
63
  assert.deepEqual(schema.accessRule, [{ type: 'public' }])
56
64
  assert.deepEqual(schema.rateLimiting, { rules: [] })
65
+ assert.equal(schema.termsOfService, 'https://example.com/terms')
66
+ assert.deepEqual(schema.contact, { name: 'John Doe', email: 'john.doe@example.com' })
67
+ assert.deepEqual(schema.license, { name: 'MIT', url: 'https://opensource.org/licenses/MIT' })
57
68
  })
58
69
 
59
70
  test('creates a schema with partial info', ({ assert }) => {
@@ -85,6 +96,9 @@ test.group('ApiModel.constructor()', (g) => {
85
96
  assert.isUndefined(model.session)
86
97
  assert.isUndefined(model.accessRule)
87
98
  assert.isUndefined(model.rateLimiting)
99
+ assert.isUndefined(model.termsOfService)
100
+ assert.isUndefined(model.contact)
101
+ assert.isUndefined(model.license)
88
102
  assert.deepEqual(model.dependencyList, [])
89
103
  })
90
104
 
@@ -101,6 +115,9 @@ test.group('ApiModel.constructor()', (g) => {
101
115
  session: { secret: 'secret', properties: ['email'] },
102
116
  accessRule: [{ type: 'public' }],
103
117
  rateLimiting: { rules: [] },
118
+ termsOfService: 'https://example.com/terms',
119
+ contact: { name: 'John Doe', email: 'john.doe@example.com' },
120
+ license: { name: 'MIT', url: 'https://opensource.org/licenses/MIT' },
104
121
  }
105
122
  const model = new ApiModel(schema)
106
123
 
@@ -114,6 +131,9 @@ test.group('ApiModel.constructor()', (g) => {
114
131
  assert.deepEqual(model.session, { secret: 'secret', properties: ['email'] })
115
132
  assert.deepEqual(model.accessRule, [{ type: 'public' }])
116
133
  assert.deepEqual(model.rateLimiting, { rules: [] })
134
+ assert.equal(model.termsOfService, 'https://example.com/terms')
135
+ assert.deepEqual(model.contact, { name: 'John Doe', email: 'john.doe@example.com' })
136
+ assert.deepEqual(model.license, { name: 'MIT', url: 'https://opensource.org/licenses/MIT' })
117
137
  })
118
138
 
119
139
  test('creates an instance with a DataDomain', ({ assert }) => {
@@ -159,6 +179,9 @@ test.group('ApiModel.toJSON()', (g) => {
159
179
  assert.isUndefined(json.session)
160
180
  assert.isUndefined(json.accessRule)
161
181
  assert.isUndefined(json.rateLimiting)
182
+ assert.isUndefined(json.termsOfService)
183
+ assert.isUndefined(json.contact)
184
+ assert.isUndefined(json.license)
162
185
  })
163
186
 
164
187
  test('serializes all provided values', ({ assert }) => {
@@ -174,6 +197,9 @@ test.group('ApiModel.toJSON()', (g) => {
174
197
  session: { secret: 'secret', properties: ['email'] },
175
198
  accessRule: [{ type: 'public' }],
176
199
  rateLimiting: { rules: [] },
200
+ termsOfService: 'https://example.com/terms',
201
+ contact: { name: 'John Doe', email: 'john.doe@example.com' },
202
+ license: { name: 'MIT', url: 'https://opensource.org/licenses/MIT' },
177
203
  }
178
204
  const model = new ApiModel(schema)
179
205
  const json = model.toJSON()
@@ -188,6 +214,9 @@ test.group('ApiModel.toJSON()', (g) => {
188
214
  assert.deepEqual(json.session, { secret: 'secret', properties: ['email'] })
189
215
  assert.deepEqual(json.accessRule, [{ type: 'public' }])
190
216
  assert.deepEqual(json.rateLimiting, { rules: [] })
217
+ assert.equal(json.termsOfService, 'https://example.com/terms')
218
+ assert.deepEqual(json.contact, { name: 'John Doe', email: 'john.doe@example.com' })
219
+ assert.deepEqual(json.license, { name: 'MIT', url: 'https://opensource.org/licenses/MIT' })
191
220
  })
192
221
  })
193
222