@api-client/core 0.3.9 → 0.3.12

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 (38) hide show
  1. package/build/browser.d.ts +3 -1
  2. package/build/browser.js +1 -3
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +3 -1
  5. package/build/index.js +1 -3
  6. package/build/index.js.map +1 -1
  7. package/build/src/mocking/ProjectMock.d.ts +6 -0
  8. package/build/src/mocking/ProjectMock.js +6 -0
  9. package/build/src/mocking/ProjectMock.js.map +1 -1
  10. package/build/src/mocking/lib/History.d.ts +70 -0
  11. package/build/src/mocking/lib/History.js +120 -0
  12. package/build/src/mocking/lib/History.js.map +1 -0
  13. package/build/src/mocking/lib/User.d.ts +20 -0
  14. package/build/src/mocking/lib/User.js +51 -0
  15. package/build/src/mocking/lib/User.js.map +1 -0
  16. package/build/src/models/Application.d.ts +19 -0
  17. package/build/src/models/Application.js +2 -0
  18. package/build/src/models/Application.js.map +1 -0
  19. package/build/src/models/Backend.d.ts +85 -0
  20. package/build/src/models/HttpHistory.d.ts +113 -0
  21. package/build/src/models/HttpHistory.js +186 -0
  22. package/build/src/models/HttpHistory.js.map +1 -0
  23. package/build/src/models/HttpProject.js +2 -2
  24. package/build/src/models/HttpProject.js.map +1 -1
  25. package/build/src/models/ProjectFolder.js +2 -2
  26. package/build/src/models/ProjectFolder.js.map +1 -1
  27. package/build/src/models/Workspace.js +2 -2
  28. package/build/src/models/Workspace.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/mocking/ProjectMock.ts +8 -0
  31. package/src/mocking/lib/History.ts +179 -0
  32. package/src/mocking/lib/User.ts +67 -0
  33. package/src/models/Application.ts +19 -0
  34. package/src/models/Backend.ts +93 -0
  35. package/src/models/HttpHistory.ts +229 -0
  36. package/src/models/HttpProject.ts +2 -2
  37. package/src/models/ProjectFolder.ts +2 -2
  38. package/src/models/Workspace.ts +2 -2
@@ -0,0 +1,179 @@
1
+ import { Internet, Types, DataMockInit, Person, Random, TypeDateTimeInit } from '@pawel-up/data-mock';
2
+ // import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
3
+ import { IHttpHistory, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
4
+ import { Request, IRequestLogInit } from './Request.js';
5
+
6
+
7
+ export interface IHttpHistoryInit {
8
+ /**
9
+ * Either space id, list of spaces to pick one or whether to generate a space.
10
+ */
11
+ space?: boolean | string | string[];
12
+ /**
13
+ * User is always generated per store requirements.
14
+ */
15
+ user?: string | string[];
16
+ /**
17
+ * Either project id, list of projects to pick one or whether to generate a project.
18
+ */
19
+ project?: boolean | string | string[];
20
+ /**
21
+ * Either request id, list of requests to pick one or whether to generate a request.
22
+ */
23
+ request?: boolean | string | string[];
24
+ /**
25
+ * Either app id, list of apps to pick one or whether to generate an app.
26
+ */
27
+ app?: boolean | string | string[];
28
+ /**
29
+ * The log init options
30
+ */
31
+ log?: IRequestLogInit;
32
+ /**
33
+ * The created time init options.
34
+ */
35
+ created?: TypeDateTimeInit;
36
+ }
37
+
38
+ export interface IHttpHistoryListInit extends IHttpHistoryInit {
39
+ /**
40
+ * When set it generates as many user IDs.
41
+ * Ignored when the `user` is set.
42
+ */
43
+ usersSize?: number;
44
+ /**
45
+ * When set it generates as many space ids.
46
+ * Ignored when the `space` is set.
47
+ */
48
+ spacesSize?: number;
49
+ /**
50
+ * When set it generates as many project ids.
51
+ * Ignored when the `project` is set.
52
+ */
53
+ projectsSize?: number;
54
+ /**
55
+ * When set it generates as many request ids.
56
+ * Ignored when the `request` is set.
57
+ */
58
+ requestsSize?: number;
59
+ /**
60
+ * When set it generates as many app ids.
61
+ * Ignored when the `app` is set.
62
+ */
63
+ appsSize?: number;
64
+ }
65
+
66
+ export class History {
67
+ person: Person;
68
+ types: Types;
69
+ internet: Internet;
70
+ random: Random;
71
+ request: Request;
72
+
73
+ constructor(init: DataMockInit={}) {
74
+ this.person = new Person(init);
75
+ this.types = new Types(init.seed);
76
+ this.internet = new Internet(init);
77
+ this.random = new Random(init.seed);
78
+ this.request = new Request(init);
79
+ }
80
+
81
+ httpHistory(init: IHttpHistoryInit = {}): IHttpHistory {
82
+ const date = this.types.datetime(init.created);
83
+ const result: IHttpHistory = {
84
+ kind: HttpHistoryKind,
85
+ created: date.getTime(),
86
+ log: this.request.log(init.log),
87
+ user: '',
88
+ }
89
+ date.setHours(0, 0, 0, 0);
90
+ result.midnight = date.getTime();
91
+
92
+ if (typeof init.space === 'string') {
93
+ result.space = init.space;
94
+ } else if (Array.isArray(init.space)) {
95
+ result.space = this.random.pickOne(init.space);
96
+ } else if (init.space) {
97
+ result.space = this.types.string(10);
98
+ }
99
+
100
+ if (typeof init.user === 'string') {
101
+ result.user = init.user;
102
+ } else if (Array.isArray(init.user)) {
103
+ result.user = this.random.pickOne(init.user);
104
+ } else {
105
+ result.user = this.types.uuid();
106
+ }
107
+
108
+ if (typeof init.project === 'string') {
109
+ result.project = init.project;
110
+ } else if (Array.isArray(init.project)) {
111
+ result.project = this.random.pickOne(init.project);
112
+ } else if (init.project) {
113
+ result.project = this.types.uuid();
114
+ }
115
+
116
+ if (typeof init.request === 'string') {
117
+ result.request = init.request;
118
+ } else if (Array.isArray(init.request)) {
119
+ result.request = this.random.pickOne(init.request);
120
+ } else if (init.request) {
121
+ result.request = this.types.uuid();
122
+ }
123
+
124
+ if (typeof init.app === 'string') {
125
+ result.app = init.app;
126
+ } else if (Array.isArray(init.app)) {
127
+ result.app = this.random.pickOne(init.app);
128
+ } else if (init.app) {
129
+ result.app = this.types.uuid();
130
+ }
131
+ return result;
132
+ }
133
+
134
+ httpHistoryList(size=25, init: IHttpHistoryListInit = {}): IHttpHistory[] {
135
+ const { usersSize, spacesSize, projectsSize, requestsSize, appsSize } = init;
136
+ const copy = { ...init };
137
+ if (usersSize && typeof init.user === 'undefined') {
138
+ const users: string[] = [];
139
+ for (let i = 0; i < usersSize; i++) {
140
+ users.push(this.types.uuid());
141
+ }
142
+ copy.user = users;
143
+ }
144
+ if (spacesSize && typeof init.space === 'undefined') {
145
+ const space: string[] = [];
146
+ for (let i = 0; i < spacesSize; i++) {
147
+ space.push(this.types.string(10));
148
+ }
149
+ copy.space = space;
150
+ }
151
+ if (projectsSize && typeof init.project === 'undefined') {
152
+ const project: string[] = [];
153
+ for (let i = 0; i < projectsSize; i++) {
154
+ project.push(this.types.uuid());
155
+ }
156
+ copy.project = project;
157
+ }
158
+ if (requestsSize && typeof init.request === 'undefined') {
159
+ const requests: string[] = [];
160
+ for (let i = 0; i < requestsSize; i++) {
161
+ requests.push(this.types.uuid());
162
+ }
163
+ copy.request = requests;
164
+ }
165
+ if (appsSize && typeof init.app === 'undefined') {
166
+ const apps: string[] = [];
167
+ for (let i = 0; i < appsSize; i++) {
168
+ apps.push(this.types.uuid());
169
+ }
170
+ copy.app = apps;
171
+ }
172
+
173
+ const result: IHttpHistory[] = [];
174
+ for (let i = 0; i < size; i++) {
175
+ result.push(this.httpHistory(copy));
176
+ }
177
+ return result;
178
+ }
179
+ }
@@ -0,0 +1,67 @@
1
+ import { Internet, Types, DataMockInit, Person, Random } from '@pawel-up/data-mock';
2
+ // import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
3
+ import { IUser, ISpaceUser, AccessControlLevel } from '../../models/User.js';
4
+
5
+
6
+ export interface IUserInit {
7
+ noEmail?: boolean;
8
+ noPicture?: boolean;
9
+ noProvider?: boolean;
10
+ }
11
+
12
+ export interface ISpaceUserInit extends IUserInit {
13
+ level?: AccessControlLevel;
14
+ levelPool?: AccessControlLevel[];
15
+ }
16
+
17
+ const accessPool: AccessControlLevel[] = ['read', 'comment', 'write', 'admin', 'owner'];
18
+
19
+ export class User {
20
+ person: Person;
21
+ types: Types;
22
+ internet: Internet;
23
+ random: Random;
24
+
25
+ constructor(init: DataMockInit={}) {
26
+ this.person = new Person(init);
27
+ this.types = new Types(init.seed);
28
+ this.internet = new Internet(init);
29
+ this.random = new Random(init.seed);
30
+ }
31
+
32
+ user(init: IUserInit = {}): IUser {
33
+ const result: IUser = {
34
+ key: this.types.uuid(),
35
+ name: this.person.name(),
36
+ }
37
+ if (!init.noEmail) {
38
+ result.email = [{
39
+ email: this.internet.email(),
40
+ verified: this.types.boolean(),
41
+ }];
42
+ }
43
+ if (!init.noPicture) {
44
+ result.picture = {
45
+ url: this.internet.avatar(),
46
+ };
47
+ }
48
+ if (!init.noProvider) {
49
+ result.provider = {
50
+ refreshToken: this.types.uuid(),
51
+ };
52
+ }
53
+ return result;
54
+ }
55
+
56
+ spaceUser(init: ISpaceUserInit = {}): ISpaceUser {
57
+ const user = this.user(init) as ISpaceUser;
58
+ if (init.level) {
59
+ user.level = init.level;
60
+ } else if (Array.isArray(init.levelPool)) {
61
+ user.level = this.random.pickOne(init.levelPool);
62
+ } else {
63
+ user.level = this.random.pickOne(accessPool);
64
+ }
65
+ return user;
66
+ }
67
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A definition if an application.
3
+ */
4
+ export interface IApplication {
5
+ /**
6
+ * The unique code identifying the application in the ecosystem.
7
+ * For example, `api-client` application has its own code reported through this property.
8
+ * This is not generated per instance but per application.
9
+ */
10
+ code: string;
11
+ /**
12
+ * Application display name.
13
+ */
14
+ name: string;
15
+ /**
16
+ * The current version of the application.
17
+ */
18
+ version: string;
19
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/export */
1
2
  export type BackendMode = 'single-user' | 'multi-user';
2
3
 
3
4
  export interface IBackendInfo {
@@ -104,4 +105,96 @@ export interface IListOptions {
104
105
  * Only with the `query` property. Tells the system in which fields to search for the query term.
105
106
  */
106
107
  queryField?: string[];
108
+ type?: string;
109
+ }
110
+
111
+ export interface ICursorOptions {
112
+ /**
113
+ * Page cursor to use with the query.
114
+ */
115
+ cursor?: string;
116
+ }
117
+
118
+ /**
119
+ * Listing options for the HTTP history.
120
+ */
121
+ export type HistoryListOptions = IHistorySpaceListOptions | IHistoryProjectListOptions | IHistoryRequestListOptions | IHistoryUserListOptions | IHistoryAppListOptions;
122
+
123
+ /**
124
+ * Query options to list history for a user space.
125
+ * The user has to have access to the user space to read / create / delete the history.
126
+ */
127
+ export interface IHistorySpaceListOptions extends IListOptions {
128
+ type: 'space';
129
+ /**
130
+ * The id of the space.
131
+ */
132
+ id: string;
133
+ /**
134
+ * Whether to limit the list of results to the history that belongs to the current user.
135
+ */
136
+ user?: boolean;
137
+ }
138
+
139
+ /**
140
+ * Query options to list history for an HTTP project.
141
+ * The user has to have access to the parent user space to read / create / delete the history.
142
+ */
143
+ export interface IHistoryProjectListOptions extends IListOptions {
144
+ type: 'project';
145
+ /**
146
+ * The id of the space containing the project.
147
+ * The access to the history records for the project is tested against the user space.
148
+ */
149
+ space: string;
150
+ /**
151
+ * The id of the project.
152
+ */
153
+ id: string;
154
+ /**
155
+ * Whether to limit the list of results to the history that belongs to the current user.
156
+ */
157
+ user?: boolean;
158
+ }
159
+
160
+ /**
161
+ * Query options to list history for a request in a project.
162
+ * The user has to have access to the parent user space to read / create / delete the history.
163
+ */
164
+ export interface IHistoryRequestListOptions extends IListOptions {
165
+ type: 'request';
166
+ /**
167
+ * The id of the space containing the project that contains the request.
168
+ * The access to the history records for the request is tested against the user space.
169
+ */
170
+ space: string;
171
+ /**
172
+ * The id of the request.
173
+ */
174
+ id: string;
175
+ /**
176
+ * Whether to limit the list of results to the history that belongs to the current user.
177
+ */
178
+ user?: boolean;
179
+ }
180
+
181
+ /**
182
+ * Query options to list history for a user. This targets lists all user history. If you need to
183
+ * filter the user history use other interfaces with the `user` flag set.
184
+ */
185
+ export interface IHistoryUserListOptions extends IListOptions {
186
+ type: 'user';
187
+ }
188
+
189
+ /**
190
+ * Query options to list history for a history object that was created by an application that has no concept
191
+ * of user spaces. In this case the queries are always made against the current user.
192
+ */
193
+ export interface IHistoryAppListOptions extends IListOptions {
194
+ type: 'app';
195
+ /**
196
+ * The id of the application.
197
+ * These queries are always made for a user.
198
+ */
199
+ id: string;
107
200
  }
@@ -0,0 +1,229 @@
1
+ import { IRequestLog, RequestLog, Kind as RequestLogKind } from './RequestLog.js';
2
+
3
+ export const Kind = 'ARC#HttpHistory';
4
+ export const createdSymbol = Symbol('created');
5
+ export const midnightSymbol = Symbol('midnight');
6
+
7
+ export interface IHttpHistory {
8
+ kind: typeof Kind;
9
+ /**
10
+ * The data store key. Only present when the object was already inserted into the data store.
11
+ * In majority of cases this value is set. It is not set when generating the history object before sending it to the store.
12
+ *
13
+ * Note for data store implementations. This must be a URL-safe value so the id should be encoded if needed.
14
+ */
15
+ key?: string;
16
+ /**
17
+ * Optional user space id. Must be set when the originating request belongs to a user space.
18
+ */
19
+ space?: string;
20
+ /**
21
+ * Optional project id. Must be set when the originating request belongs to a user space.
22
+ */
23
+ project?: string;
24
+ /**
25
+ * Optional application id. Must be set when the application that created this record does not use the concept of a user space.
26
+ */
27
+ app?: string;
28
+ /**
29
+ * The user id that made that request.
30
+ * Note, the default API Client's store automatically adds the user information to the record overriding any pre-set user id.
31
+ */
32
+ user: string;
33
+ /**
34
+ * The optional request id in the project that generated this log.
35
+ */
36
+ request?: string;
37
+ /**
38
+ * The request log.
39
+ */
40
+ log: IRequestLog;
41
+ /**
42
+ * The timestamp when this history request has been created.
43
+ */
44
+ created: number;
45
+ /**
46
+ * A timestamp of the midnight when the object was created
47
+ */
48
+ midnight?: number;
49
+ }
50
+
51
+ /**
52
+ * An HTTP history is an object containing an information of a request and response
53
+ * made with the application.
54
+ *
55
+ * Note, history object are not mutable. Can only be created or deleted.
56
+ */
57
+ export class HttpHistory {
58
+ [createdSymbol]: number;
59
+ [midnightSymbol]: number;
60
+ kind = Kind;
61
+ /**
62
+ * The data store key. Only present when the object was already inserted into the data store.
63
+ * In majority of cases this value is set. It is not set when generating the history object before sending it to the store.
64
+ *
65
+ * Note for data store implementations. This must be a URL-safe value so the id should be encoded if needed.
66
+ */
67
+ key?: string;
68
+ /**
69
+ * Optional user space id. Must be set when the originating request belongs to a user space.
70
+ */
71
+ space?: string;
72
+ /**
73
+ * Optional project id. Must be set when the originating request belongs to a user space.
74
+ */
75
+ project?: string;
76
+ /**
77
+ * Optional application id. Must be set when the application that created this record does not use the concept of a user space.
78
+ */
79
+ app?: string;
80
+ /**
81
+ * The user id that made that request.
82
+ * Note, the default API Client's store automatically adds the user information to the record overriding any pre-set user id.
83
+ */
84
+ user = '';
85
+ /**
86
+ * The optional request id in the project that generated this log.
87
+ */
88
+ request?: string;
89
+ /**
90
+ * The execution log of the HTTP request with a response.
91
+ */
92
+ log: RequestLog = new RequestLog();
93
+
94
+ /**
95
+ * @param value The timestamp when the request was created.
96
+ */
97
+ set created(value: number | undefined) {
98
+ if (!value) {
99
+ this[createdSymbol] = Date.now();
100
+ } else {
101
+ this[createdSymbol] = value;
102
+ }
103
+ const d = new Date(this[createdSymbol]);
104
+ d.setHours(0, 0, 0, 0);
105
+ this[midnightSymbol] = d.getTime();
106
+ }
107
+
108
+ /**
109
+ * @returns The timestamp when the request was created.
110
+ */
111
+ get created(): number {
112
+ return this[createdSymbol] || Date.now();
113
+ }
114
+
115
+ /**
116
+ * @param value The timestamp of the midnight when the request object was updated
117
+ */
118
+ set midnight(value: number | undefined) {
119
+ if (!value) {
120
+ this[midnightSymbol] = this.defaultMidnight();
121
+ } else {
122
+ this[midnightSymbol] = value;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @returns The timestamp of the midnight when the request object was updated
128
+ */
129
+ get midnight(): number {
130
+ if (this[midnightSymbol]) {
131
+ return this[midnightSymbol];
132
+ }
133
+ return this.defaultMidnight();
134
+ }
135
+
136
+ constructor(input?: string|IHttpHistory) {
137
+ let init: IHttpHistory;
138
+ if (typeof input === 'string') {
139
+ init = JSON.parse(input);
140
+ } else if (typeof input === 'object') {
141
+ init = input;
142
+ } else {
143
+ const now:number = Date.now();
144
+ init = {
145
+ kind: Kind,
146
+ created: now,
147
+ user: '',
148
+ log: {
149
+ kind: RequestLogKind,
150
+ },
151
+ };
152
+ }
153
+ this.new(init);
154
+ }
155
+
156
+ new(init: IHttpHistory): void {
157
+ const { log, created = Date.now(), midnight, space, project, request, user, key, app } = init;
158
+ this.log = new RequestLog(log);
159
+ this.created = created;
160
+ if (key) {
161
+ this.key = key;
162
+ } else {
163
+ this.key = undefined;
164
+ }
165
+ if (app) {
166
+ this.app = app;
167
+ } else {
168
+ this.app = undefined;
169
+ }
170
+ if (midnight) {
171
+ this.midnight = midnight;
172
+ }
173
+ if (space) {
174
+ this.space = space;
175
+ } else {
176
+ this.space = undefined;
177
+ }
178
+ if (project) {
179
+ this.project = project;
180
+ } else {
181
+ this.project = undefined;
182
+ }
183
+ if (request) {
184
+ this.request = request;
185
+ } else {
186
+ this.request = undefined;
187
+ }
188
+ if (user) {
189
+ this.user = user;
190
+ } else {
191
+ this.user = '';
192
+ }
193
+ }
194
+
195
+ toJSON(): IHttpHistory {
196
+ const result: IHttpHistory = {
197
+ kind: Kind,
198
+ created: this.created,
199
+ midnight: this.midnight,
200
+ log: this.log.toJSON(),
201
+ user: this.user,
202
+ };
203
+ if (this.key) {
204
+ result.key = this.key;
205
+ }
206
+ if (this.space) {
207
+ result.space = this.space;
208
+ }
209
+ if (this.project) {
210
+ result.project = this.project;
211
+ }
212
+ if (this.request) {
213
+ result.request = this.request;
214
+ }
215
+ if (this.app) {
216
+ result.app = this.app;
217
+ }
218
+ return result;
219
+ }
220
+
221
+ /**
222
+ * @returns The default value for the midnight when the request was last updated.
223
+ */
224
+ defaultMidnight(): number {
225
+ const d = new Date(this.created);
226
+ d.setHours(0, 0, 0, 0);
227
+ return d.getTime();
228
+ }
229
+ }
@@ -350,7 +350,7 @@ export class HttpProject extends ProjectParent {
350
350
  this.key = key;
351
351
  this.environments = [];
352
352
  if (Array.isArray(environments)) {
353
- this.environments = environments;
353
+ this.environments = [...environments];
354
354
  }
355
355
  if (license) {
356
356
  this.license = new License(license);
@@ -416,7 +416,7 @@ export class HttpProject extends ProjectParent {
416
416
  result.definitions.schemas = this.definitions.schemas.map(i => i.toJSON());
417
417
  }
418
418
  if (Array.isArray(this.environments) && this.environments.length) {
419
- result.environments = this.environments;
419
+ result.environments = [...this.environments];
420
420
  }
421
421
  if (Array.isArray(this.items) && this.items.length) {
422
422
  result.items = this.items.map(i => i.toJSON());
@@ -148,7 +148,7 @@ export class ProjectFolder extends ProjectParent {
148
148
  this.info = new Thing({ kind: ThingKind, name: DefaultFolderName });
149
149
  }
150
150
  if (Array.isArray(environments)) {
151
- this.environments = environments;
151
+ this.environments = [...environments];
152
152
  } else {
153
153
  this.environments = [];
154
154
  }
@@ -179,7 +179,7 @@ export class ProjectFolder extends ProjectParent {
179
179
  result.items = this.items.map(i => i.toJSON());
180
180
  }
181
181
  if (Array.isArray(this.environments)) {
182
- result.environments = this.environments;
182
+ result.environments = [...this.environments];
183
183
  }
184
184
  return result;
185
185
  }
@@ -144,7 +144,7 @@ export class Workspace {
144
144
  this.info = new Thing({ kind: ThingKind, name: '' });
145
145
  }
146
146
  if (Array.isArray(users)) {
147
- this.users = users;
147
+ this.users = [...users];
148
148
  } else {
149
149
  this.users = [];
150
150
  }
@@ -175,7 +175,7 @@ export class Workspace {
175
175
  owner,
176
176
  };
177
177
  if (Array.isArray(users) && users.length) {
178
- result.users = users;
178
+ result.users = [...users];
179
179
  }
180
180
  return result;
181
181
  }