@magda/auth-api-client 2.0.0-alpha.0 → 2.0.0-alpha.3

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/dist/index.d.ts CHANGED
@@ -14,15 +14,6 @@ declare class ApiClient {
14
14
  * @memberof ApiClient
15
15
  */
16
16
  getUser(userId: string): Promise<Maybe<RequiredKeys<User, "id">>>;
17
- /**
18
- * Get the data of a user.
19
- * (Deprecated) This is the public facing API and will return less fields.
20
- *
21
- * @param {string} userId
22
- * @returns {Promise<Maybe<User>>}
23
- * @memberof ApiClient
24
- */
25
- getUserPublic(userId: string): Promise<Maybe<RequiredKeys<User, "id">>>;
26
17
  /**
27
18
  * Lookup user by source (identity provider) & sourceId (identity ID)
28
19
  *
@@ -35,11 +26,11 @@ declare class ApiClient {
35
26
  /**
36
27
  * create a user
37
28
  *
38
- * @param {User} user
39
- * @returns {Promise<User>}
29
+ * @param {CreateUserData} user
30
+ * @returns {Promise<UserRecord>}
40
31
  * @memberof ApiClient
41
32
  */
42
- createUser(user: User): Promise<RequiredKeys<User, "id">>;
33
+ createUser(user: CreateUserData): Promise<UserRecord>;
43
34
  /**
44
35
  * Add Roles to a user.
45
36
  * Returns a list of current role ids of the user.
@@ -135,10 +126,21 @@ declare class ApiClient {
135
126
  * @memberof ApiClient
136
127
  */
137
128
  getAllOrgUnitChildren(nodeId: string): Promise<OrgUnit[]>;
129
+ createOrgNode(parentNodeId: string, node: Partial<Omit<OrgUnitRecord, "id" | "createBy" | "createTime" | "editBy" | "editTime" | "left" | "right">>): Promise<OrgUnit>;
130
+ createRole(name: string, desc?: string): Promise<Role>;
131
+ createRolePermission(roleId: string, permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>;
132
+ getOperationByUri(opUri: string): Promise<OperationRecord>;
133
+ getResourceByUri(resUri: string): Promise<ResourceRecord>;
138
134
  private handleGetResult;
139
135
  }
140
136
  export default ApiClient;
141
137
 
138
+ declare interface CreateRolePermissionInputData extends Omit<PermissionRecord, "id" | "owner_id" | "create_by" | "create_time" | "edit_by" | "edit_time"> {
139
+ operationIds: string[];
140
+ }
141
+
142
+ declare type CreateUserData = Partial<Omit<UserRecord, "email" | "displayName" | "id">> & Pick<UserRecord, "displayName" | "email">;
143
+
142
144
  declare interface Eq<T> {
143
145
  equals(t: T): boolean;
144
146
  }
@@ -206,22 +208,33 @@ export declare interface Operation {
206
208
  description?: string;
207
209
  }
208
210
 
211
+ declare type OperationRecord = {
212
+ id: string;
213
+ uri: string;
214
+ name: string;
215
+ description: string;
216
+ resource_id: string;
217
+ };
218
+
209
219
  declare interface OptionalMaybePatterns<T, U> {
210
220
  just?: (t: T) => U;
211
221
  nothing?: () => U;
212
222
  }
213
223
 
214
- export declare interface OrgUnit {
215
- id?: string;
216
- name?: string;
217
- description?: string;
224
+ export declare type OrgUnit = Partial<OrgUnitRecord> & {
218
225
  relationship?: OrgUnitRelationshipType;
219
- left?: number;
220
- right?: number;
221
- createBy?: string;
222
- createTime?: Date;
223
- editBy?: string;
224
- editTime?: Date;
226
+ };
227
+
228
+ declare interface OrgUnitRecord {
229
+ id: string;
230
+ name: string;
231
+ description: string;
232
+ left: number;
233
+ right: number;
234
+ createBy: string;
235
+ createTime: Date;
236
+ editBy: string;
237
+ editTime: Date;
225
238
  }
226
239
 
227
240
  export declare type OrgUnitRelationshipType = "ancestor" | "descendant" | "equal" | "unrelated";
@@ -242,20 +255,37 @@ export declare interface Permission {
242
255
  editTime?: Date;
243
256
  }
244
257
 
245
- export declare interface PublicUser {
246
- id?: string;
247
- displayName: string;
248
- photoURL?: string;
249
- isAdmin: boolean;
258
+ declare interface PermissionRecord {
259
+ id: string;
260
+ name: string;
261
+ description: string;
262
+ resource_id: string;
263
+ user_ownership_constraint: boolean;
264
+ org_unit_ownership_constraint: boolean;
265
+ pre_authorised_constraint: boolean;
266
+ owner_id: string;
267
+ create_time: string;
268
+ create_by: string;
269
+ edit_time: string;
270
+ edit_by: string;
271
+ }
272
+
273
+ export declare type PublicUser = Partial<Pick<UserRecord, "id" | "photoURL" | "orgUnitId">> & Omit<UserRecord, "id" | "photoURL" | "orgUnitId" | "email" | "source" | "sourceId"> & {
250
274
  roles?: Role[];
251
275
  permissions?: Permission[];
252
276
  managingOrgUnitIds?: string[];
253
- orgUnitId?: string;
254
277
  orgUnit?: OrgUnit;
255
- }
278
+ };
256
279
 
257
280
  declare type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
258
281
 
282
+ declare type ResourceRecord = {
283
+ id: string;
284
+ uri: string;
285
+ name: string;
286
+ description: string;
287
+ };
288
+
259
289
  export declare interface Role {
260
290
  id: string;
261
291
  name: string;
@@ -267,7 +297,14 @@ export declare interface Role {
267
297
  editTime?: Date;
268
298
  }
269
299
 
270
- export declare interface User extends PublicUser {
300
+ export declare type User = PublicUser & Pick<UserRecord, "email" | "source" | "sourceId">;
301
+
302
+ declare interface UserRecord {
303
+ id: string;
304
+ displayName: string;
305
+ photoURL: string;
306
+ isAdmin: boolean;
307
+ orgUnitId: string;
271
308
  email: string;
272
309
  source: string;
273
310
  sourceId: string;
package/dist/index.js CHANGED
@@ -1806,7 +1806,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
1806
1806
  * URI.js - Mutating URLs
1807
1807
  * IPv6 Support
1808
1808
  *
1809
- * Version: 1.19.5
1809
+ * Version: 1.19.11
1810
1810
  *
1811
1811
  * Author: Rodney Rehm
1812
1812
  * Web: http://medialize.github.io/URI.js/
@@ -1998,7 +1998,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
1998
1998
  * URI.js - Mutating URLs
1999
1999
  * Second Level Domain (SLD) Support
2000
2000
  *
2001
- * Version: 1.19.5
2001
+ * Version: 1.19.11
2002
2002
  *
2003
2003
  * Author: Rodney Rehm
2004
2004
  * Web: http://medialize.github.io/URI.js/
@@ -2281,9 +2281,10 @@ const isomorphic_fetch_1 = __importDefault(__webpack_require__(30));
2281
2281
  const tsmonad_1 = __webpack_require__(15);
2282
2282
  const lodash_1 = __importDefault(__webpack_require__(59));
2283
2283
  const buildJwt_1 = __importDefault(__webpack_require__(60));
2284
- const GenericError_1 = __importDefault(__webpack_require__(79));
2285
- const addTrailingSlash_1 = __importDefault(__webpack_require__(80));
2286
- const urijs_1 = __importDefault(__webpack_require__(81));
2284
+ const addTrailingSlash_1 = __importDefault(__webpack_require__(79));
2285
+ const urijs_1 = __importDefault(__webpack_require__(80));
2286
+ const ServerError_1 = __importDefault(__webpack_require__(81));
2287
+ const isUuid_1 = __importDefault(__webpack_require__(82));
2287
2288
  class ApiClient {
2288
2289
  constructor(
2289
2290
  // e.g. http://authorization-api/v0
@@ -2295,14 +2296,29 @@ class ApiClient {
2295
2296
  if (jwtSecret && userId) {
2296
2297
  this.jwt = buildJwt_1.default(jwtSecret, userId);
2297
2298
  }
2298
- this.requestInitOption = {
2299
- headers: {
2300
- "X-Magda-Session": this.jwt
2301
- }
2302
- };
2299
+ if (this.jwt) {
2300
+ this.requestInitOption = {
2301
+ headers: {
2302
+ "X-Magda-Session": this.jwt
2303
+ }
2304
+ };
2305
+ }
2303
2306
  }
2304
2307
  getMergeRequestInitOption(extraOptions = null) {
2305
- return lodash_1.default.merge({}, this.requestInitOption, extraOptions);
2308
+ let defaultContentTypeCfg = {};
2309
+ if ((extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.body) &&
2310
+ (!(extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.headers) ||
2311
+ (typeof extraOptions.headers === "object" &&
2312
+ Object.keys(extraOptions.headers)
2313
+ .map((key) => key.toLowerCase())
2314
+ .indexOf("content-type") == -1))) {
2315
+ defaultContentTypeCfg = {
2316
+ headers: {
2317
+ "Content-Type": "application/json"
2318
+ }
2319
+ };
2320
+ }
2321
+ return lodash_1.default.merge({}, this.requestInitOption, extraOptions, defaultContentTypeCfg);
2306
2322
  }
2307
2323
  processJsonResponse(res) {
2308
2324
  return __awaiter(this, void 0, void 0, function* () {
@@ -2310,8 +2326,8 @@ class ApiClient {
2310
2326
  return (yield res.json());
2311
2327
  }
2312
2328
  else {
2313
- const responseText = (yield res.text()).replace(/<(.|\n)*?>/g, "");
2314
- throw new GenericError_1.default(responseText, res.status);
2329
+ const responseText = yield res.text();
2330
+ throw new ServerError_1.default(`Error: ${res.statusText}. ${responseText.replace(/<(.|\n)*?>/g, "")}`, res.status);
2315
2331
  }
2316
2332
  });
2317
2333
  }
@@ -2323,19 +2339,6 @@ class ApiClient {
2323
2339
  * @memberof ApiClient
2324
2340
  */
2325
2341
  getUser(userId) {
2326
- return __awaiter(this, void 0, void 0, function* () {
2327
- return yield this.handleGetResult(isomorphic_fetch_1.default(`${this.baseUrl}private/users/${userId}`, this.getMergeRequestInitOption()));
2328
- });
2329
- }
2330
- /**
2331
- * Get the data of a user.
2332
- * (Deprecated) This is the public facing API and will return less fields.
2333
- *
2334
- * @param {string} userId
2335
- * @returns {Promise<Maybe<User>>}
2336
- * @memberof ApiClient
2337
- */
2338
- getUserPublic(userId) {
2339
2342
  return __awaiter(this, void 0, void 0, function* () {
2340
2343
  return yield this.handleGetResult(isomorphic_fetch_1.default(`${this.baseUrl}public/users/${userId}`, this.getMergeRequestInitOption()));
2341
2344
  });
@@ -2356,14 +2359,14 @@ class ApiClient {
2356
2359
  /**
2357
2360
  * create a user
2358
2361
  *
2359
- * @param {User} user
2360
- * @returns {Promise<User>}
2362
+ * @param {CreateUserData} user
2363
+ * @returns {Promise<UserRecord>}
2361
2364
  * @memberof ApiClient
2362
2365
  */
2363
2366
  createUser(user) {
2364
2367
  return __awaiter(this, void 0, void 0, function* () {
2365
2368
  try {
2366
- const res = yield isomorphic_fetch_1.default(`${this.baseUrl}private/users`, this.getMergeRequestInitOption({
2369
+ const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/users`, this.getMergeRequestInitOption({
2367
2370
  method: "POST",
2368
2371
  headers: {
2369
2372
  "Content-Type": "application/json"
@@ -2371,10 +2374,10 @@ class ApiClient {
2371
2374
  body: JSON.stringify(user)
2372
2375
  }));
2373
2376
  if (res.status >= 400) {
2374
- throw new Error(`Encountered error ${res.status} when POSTing new user to ${this.baseUrl}/private/users`);
2377
+ throw new Error(`Encountered error ${res.status}: ${yield res.text()} when creating new user to ${this.baseUrl}public/users`);
2375
2378
  }
2376
2379
  const resData = yield res.json();
2377
- return Object.assign(Object.assign({}, user), resData);
2380
+ return resData;
2378
2381
  }
2379
2382
  catch (e) {
2380
2383
  console.error(e);
@@ -2393,7 +2396,7 @@ class ApiClient {
2393
2396
  */
2394
2397
  addUserRoles(userId, roleIds) {
2395
2398
  return __awaiter(this, void 0, void 0, function* () {
2396
- const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/user/${userId}/roles`, this.getMergeRequestInitOption({
2399
+ const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/users/${userId}/roles`, this.getMergeRequestInitOption({
2397
2400
  method: "POST",
2398
2401
  headers: {
2399
2402
  "Content-Type": "application/json"
@@ -2432,7 +2435,7 @@ class ApiClient {
2432
2435
  */
2433
2436
  getUserRoles(userId) {
2434
2437
  return __awaiter(this, void 0, void 0, function* () {
2435
- const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/user/${userId}/roles`, this.getMergeRequestInitOption());
2438
+ const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/users/${userId}/roles`, this.getMergeRequestInitOption());
2436
2439
  return yield this.processJsonResponse(res);
2437
2440
  });
2438
2441
  }
@@ -2445,7 +2448,7 @@ class ApiClient {
2445
2448
  */
2446
2449
  getUserPermissions(userId) {
2447
2450
  return __awaiter(this, void 0, void 0, function* () {
2448
- const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/user/${userId}/permissions`, this.getMergeRequestInitOption());
2451
+ const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/users/${userId}/permissions`, this.getMergeRequestInitOption());
2449
2452
  return yield this.processJsonResponse(res);
2450
2453
  });
2451
2454
  }
@@ -2458,7 +2461,7 @@ class ApiClient {
2458
2461
  */
2459
2462
  getRolePermissions(roleId) {
2460
2463
  return __awaiter(this, void 0, void 0, function* () {
2461
- const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/role/${roleId}/permissions`, this.getMergeRequestInitOption());
2464
+ const res = yield isomorphic_fetch_1.default(`${this.baseUrl}public/roles/${roleId}/permissions`, this.getMergeRequestInitOption());
2462
2465
  return yield this.processJsonResponse(res);
2463
2466
  });
2464
2467
  }
@@ -2568,6 +2571,60 @@ class ApiClient {
2568
2571
  return yield this.processJsonResponse(res);
2569
2572
  });
2570
2573
  }
2574
+ createOrgNode(parentNodeId, node) {
2575
+ return __awaiter(this, void 0, void 0, function* () {
2576
+ const uri = urijs_1.default(`${this.baseUrl}public/orgunits`)
2577
+ .segmentCoded(parentNodeId)
2578
+ .segmentCoded("insert");
2579
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption({
2580
+ method: "post",
2581
+ body: JSON.stringify(node)
2582
+ }));
2583
+ return yield this.processJsonResponse(res);
2584
+ });
2585
+ }
2586
+ createRole(name, desc) {
2587
+ return __awaiter(this, void 0, void 0, function* () {
2588
+ const uri = urijs_1.default(`${this.baseUrl}public/roles`);
2589
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption({
2590
+ method: "post",
2591
+ body: JSON.stringify({
2592
+ name,
2593
+ description: desc ? desc : ""
2594
+ })
2595
+ }));
2596
+ return yield this.processJsonResponse(res);
2597
+ });
2598
+ }
2599
+ createRolePermission(roleId, permissionData) {
2600
+ return __awaiter(this, void 0, void 0, function* () {
2601
+ if (!isUuid_1.default(roleId)) {
2602
+ throw new ServerError_1.default(`roleId: ${roleId} is not a valid UUID.`);
2603
+ }
2604
+ const uri = urijs_1.default(`${this.baseUrl}public/roles`)
2605
+ .segmentCoded(roleId)
2606
+ .segmentCoded("permissions");
2607
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption({
2608
+ method: "post",
2609
+ body: JSON.stringify(permissionData)
2610
+ }));
2611
+ return yield this.processJsonResponse(res);
2612
+ });
2613
+ }
2614
+ getOperationByUri(opUri) {
2615
+ return __awaiter(this, void 0, void 0, function* () {
2616
+ const uri = urijs_1.default(`${this.baseUrl}public/operations/byUri/${opUri}`);
2617
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption());
2618
+ return yield this.processJsonResponse(res);
2619
+ });
2620
+ }
2621
+ getResourceByUri(resUri) {
2622
+ return __awaiter(this, void 0, void 0, function* () {
2623
+ const uri = urijs_1.default(`${this.baseUrl}public/resources/byUri/${resUri}`);
2624
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption());
2625
+ return yield this.processJsonResponse(res);
2626
+ });
2627
+ }
2571
2628
  handleGetResult(promise) {
2572
2629
  return __awaiter(this, void 0, void 0, function* () {
2573
2630
  return promise
@@ -6021,14 +6078,15 @@ Request.prototype.clone = function() {
6021
6078
  var undefined;
6022
6079
 
6023
6080
  /** Used as the semantic version number. */
6024
- var VERSION = '4.17.15';
6081
+ var VERSION = '4.17.21';
6025
6082
 
6026
6083
  /** Used as the size to enable large array optimizations. */
6027
6084
  var LARGE_ARRAY_SIZE = 200;
6028
6085
 
6029
6086
  /** Error message constants. */
6030
6087
  var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
6031
- FUNC_ERROR_TEXT = 'Expected a function';
6088
+ FUNC_ERROR_TEXT = 'Expected a function',
6089
+ INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
6032
6090
 
6033
6091
  /** Used to stand-in for `undefined` hash values. */
6034
6092
  var HASH_UNDEFINED = '__lodash_hash_undefined__';
@@ -6161,10 +6219,11 @@ Request.prototype.clone = function() {
6161
6219
  var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
6162
6220
  reHasRegExpChar = RegExp(reRegExpChar.source);
6163
6221
 
6164
- /** Used to match leading and trailing whitespace. */
6165
- var reTrim = /^\s+|\s+$/g,
6166
- reTrimStart = /^\s+/,
6167
- reTrimEnd = /\s+$/;
6222
+ /** Used to match leading whitespace. */
6223
+ var reTrimStart = /^\s+/;
6224
+
6225
+ /** Used to match a single whitespace character. */
6226
+ var reWhitespace = /\s/;
6168
6227
 
6169
6228
  /** Used to match wrap detail comments. */
6170
6229
  var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
@@ -6174,6 +6233,18 @@ Request.prototype.clone = function() {
6174
6233
  /** Used to match words composed of alphanumeric characters. */
6175
6234
  var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
6176
6235
 
6236
+ /**
6237
+ * Used to validate the `validate` option in `_.template` variable.
6238
+ *
6239
+ * Forbids characters which could potentially change the meaning of the function argument definition:
6240
+ * - "()," (modification of function parameters)
6241
+ * - "=" (default value)
6242
+ * - "[]{}" (destructuring of function parameters)
6243
+ * - "/" (beginning of a comment)
6244
+ * - whitespace
6245
+ */
6246
+ var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
6247
+
6177
6248
  /** Used to match backslashes in property paths. */
6178
6249
  var reEscapeChar = /\\(\\)?/g;
6179
6250
 
@@ -7002,6 +7073,19 @@ Request.prototype.clone = function() {
7002
7073
  });
7003
7074
  }
7004
7075
 
7076
+ /**
7077
+ * The base implementation of `_.trim`.
7078
+ *
7079
+ * @private
7080
+ * @param {string} string The string to trim.
7081
+ * @returns {string} Returns the trimmed string.
7082
+ */
7083
+ function baseTrim(string) {
7084
+ return string
7085
+ ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
7086
+ : string;
7087
+ }
7088
+
7005
7089
  /**
7006
7090
  * The base implementation of `_.unary` without support for storing metadata.
7007
7091
  *
@@ -7335,6 +7419,21 @@ Request.prototype.clone = function() {
7335
7419
  : asciiToArray(string);
7336
7420
  }
7337
7421
 
7422
+ /**
7423
+ * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
7424
+ * character of `string`.
7425
+ *
7426
+ * @private
7427
+ * @param {string} string The string to inspect.
7428
+ * @returns {number} Returns the index of the last non-whitespace character.
7429
+ */
7430
+ function trimmedEndIndex(string) {
7431
+ var index = string.length;
7432
+
7433
+ while (index-- && reWhitespace.test(string.charAt(index))) {}
7434
+ return index;
7435
+ }
7436
+
7338
7437
  /**
7339
7438
  * Used by `_.unescape` to convert HTML entities to characters.
7340
7439
  *
@@ -9728,8 +9827,21 @@ Request.prototype.clone = function() {
9728
9827
  * @returns {Array} Returns the new sorted array.
9729
9828
  */
9730
9829
  function baseOrderBy(collection, iteratees, orders) {
9830
+ if (iteratees.length) {
9831
+ iteratees = arrayMap(iteratees, function(iteratee) {
9832
+ if (isArray(iteratee)) {
9833
+ return function(value) {
9834
+ return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
9835
+ }
9836
+ }
9837
+ return iteratee;
9838
+ });
9839
+ } else {
9840
+ iteratees = [identity];
9841
+ }
9842
+
9731
9843
  var index = -1;
9732
- iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
9844
+ iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
9733
9845
 
9734
9846
  var result = baseMap(collection, function(value, key, collection) {
9735
9847
  var criteria = arrayMap(iteratees, function(iteratee) {
@@ -9986,6 +10098,10 @@ Request.prototype.clone = function() {
9986
10098
  var key = toKey(path[index]),
9987
10099
  newValue = value;
9988
10100
 
10101
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
10102
+ return object;
10103
+ }
10104
+
9989
10105
  if (index != lastIndex) {
9990
10106
  var objValue = nested[key];
9991
10107
  newValue = customizer ? customizer(objValue, key, nested) : undefined;
@@ -10138,11 +10254,14 @@ Request.prototype.clone = function() {
10138
10254
  * into `array`.
10139
10255
  */
10140
10256
  function baseSortedIndexBy(array, value, iteratee, retHighest) {
10141
- value = iteratee(value);
10142
-
10143
10257
  var low = 0,
10144
- high = array == null ? 0 : array.length,
10145
- valIsNaN = value !== value,
10258
+ high = array == null ? 0 : array.length;
10259
+ if (high === 0) {
10260
+ return 0;
10261
+ }
10262
+
10263
+ value = iteratee(value);
10264
+ var valIsNaN = value !== value,
10146
10265
  valIsNull = value === null,
10147
10266
  valIsSymbol = isSymbol(value),
10148
10267
  valIsUndefined = value === undefined;
@@ -11627,10 +11746,11 @@ Request.prototype.clone = function() {
11627
11746
  if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
11628
11747
  return false;
11629
11748
  }
11630
- // Assume cyclic values are equal.
11631
- var stacked = stack.get(array);
11632
- if (stacked && stack.get(other)) {
11633
- return stacked == other;
11749
+ // Check that cyclic values are equal.
11750
+ var arrStacked = stack.get(array);
11751
+ var othStacked = stack.get(other);
11752
+ if (arrStacked && othStacked) {
11753
+ return arrStacked == other && othStacked == array;
11634
11754
  }
11635
11755
  var index = -1,
11636
11756
  result = true,
@@ -11792,10 +11912,11 @@ Request.prototype.clone = function() {
11792
11912
  return false;
11793
11913
  }
11794
11914
  }
11795
- // Assume cyclic values are equal.
11796
- var stacked = stack.get(object);
11797
- if (stacked && stack.get(other)) {
11798
- return stacked == other;
11915
+ // Check that cyclic values are equal.
11916
+ var objStacked = stack.get(object);
11917
+ var othStacked = stack.get(other);
11918
+ if (objStacked && othStacked) {
11919
+ return objStacked == other && othStacked == object;
11799
11920
  }
11800
11921
  var result = true;
11801
11922
  stack.set(object, other);
@@ -15176,6 +15297,10 @@ Request.prototype.clone = function() {
15176
15297
  * // The `_.property` iteratee shorthand.
15177
15298
  * _.filter(users, 'active');
15178
15299
  * // => objects for ['barney']
15300
+ *
15301
+ * // Combining several predicates using `_.overEvery` or `_.overSome`.
15302
+ * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
15303
+ * // => objects for ['fred', 'barney']
15179
15304
  */
15180
15305
  function filter(collection, predicate) {
15181
15306
  var func = isArray(collection) ? arrayFilter : baseFilter;
@@ -15925,15 +16050,15 @@ Request.prototype.clone = function() {
15925
16050
  * var users = [
15926
16051
  * { 'user': 'fred', 'age': 48 },
15927
16052
  * { 'user': 'barney', 'age': 36 },
15928
- * { 'user': 'fred', 'age': 40 },
16053
+ * { 'user': 'fred', 'age': 30 },
15929
16054
  * { 'user': 'barney', 'age': 34 }
15930
16055
  * ];
15931
16056
  *
15932
16057
  * _.sortBy(users, [function(o) { return o.user; }]);
15933
- * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
16058
+ * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
15934
16059
  *
15935
16060
  * _.sortBy(users, ['user', 'age']);
15936
- * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
16061
+ * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
15937
16062
  */
15938
16063
  var sortBy = baseRest(function(collection, iteratees) {
15939
16064
  if (collection == null) {
@@ -18477,7 +18602,7 @@ Request.prototype.clone = function() {
18477
18602
  if (typeof value != 'string') {
18478
18603
  return value === 0 ? value : +value;
18479
18604
  }
18480
- value = value.replace(reTrim, '');
18605
+ value = baseTrim(value);
18481
18606
  var isBinary = reIsBinary.test(value);
18482
18607
  return (isBinary || reIsOctal.test(value))
18483
18608
  ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
@@ -20808,11 +20933,11 @@ Request.prototype.clone = function() {
20808
20933
 
20809
20934
  // Use a sourceURL for easier debugging.
20810
20935
  // The sourceURL gets injected into the source that's eval-ed, so be careful
20811
- // with lookup (in case of e.g. prototype pollution), and strip newlines if any.
20812
- // A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
20936
+ // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
20937
+ // and escape the comment, thus injecting code that gets evaled.
20813
20938
  var sourceURL = '//# sourceURL=' +
20814
20939
  (hasOwnProperty.call(options, 'sourceURL')
20815
- ? (options.sourceURL + '').replace(/[\r\n]/g, ' ')
20940
+ ? (options.sourceURL + '').replace(/\s/g, ' ')
20816
20941
  : ('lodash.templateSources[' + (++templateCounter) + ']')
20817
20942
  ) + '\n';
20818
20943
 
@@ -20845,12 +20970,16 @@ Request.prototype.clone = function() {
20845
20970
 
20846
20971
  // If `variable` is not specified wrap a with-statement around the generated
20847
20972
  // code to add the data object to the top of the scope chain.
20848
- // Like with sourceURL, we take care to not check the option's prototype,
20849
- // as this configuration is a code injection vector.
20850
20973
  var variable = hasOwnProperty.call(options, 'variable') && options.variable;
20851
20974
  if (!variable) {
20852
20975
  source = 'with (obj) {\n' + source + '\n}\n';
20853
20976
  }
20977
+ // Throw an error if a forbidden character was found in `variable`, to prevent
20978
+ // potential command injection attacks.
20979
+ else if (reForbiddenIdentifierChars.test(variable)) {
20980
+ throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
20981
+ }
20982
+
20854
20983
  // Cleanup code by stripping empty strings.
20855
20984
  source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
20856
20985
  .replace(reEmptyStringMiddle, '$1')
@@ -20964,7 +21093,7 @@ Request.prototype.clone = function() {
20964
21093
  function trim(string, chars, guard) {
20965
21094
  string = toString(string);
20966
21095
  if (string && (guard || chars === undefined)) {
20967
- return string.replace(reTrim, '');
21096
+ return baseTrim(string);
20968
21097
  }
20969
21098
  if (!string || !(chars = baseToString(chars))) {
20970
21099
  return string;
@@ -20999,7 +21128,7 @@ Request.prototype.clone = function() {
20999
21128
  function trimEnd(string, chars, guard) {
21000
21129
  string = toString(string);
21001
21130
  if (string && (guard || chars === undefined)) {
21002
- return string.replace(reTrimEnd, '');
21131
+ return string.slice(0, trimmedEndIndex(string) + 1);
21003
21132
  }
21004
21133
  if (!string || !(chars = baseToString(chars))) {
21005
21134
  return string;
@@ -21553,6 +21682,9 @@ Request.prototype.clone = function() {
21553
21682
  * values against any array or object value, respectively. See `_.isEqual`
21554
21683
  * for a list of supported value comparisons.
21555
21684
  *
21685
+ * **Note:** Multiple values can be checked by combining several matchers
21686
+ * using `_.overSome`
21687
+ *
21556
21688
  * @static
21557
21689
  * @memberOf _
21558
21690
  * @since 3.0.0
@@ -21568,6 +21700,10 @@ Request.prototype.clone = function() {
21568
21700
  *
21569
21701
  * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
21570
21702
  * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
21703
+ *
21704
+ * // Checking for several possible values
21705
+ * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
21706
+ * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
21571
21707
  */
21572
21708
  function matches(source) {
21573
21709
  return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
@@ -21582,6 +21718,9 @@ Request.prototype.clone = function() {
21582
21718
  * `srcValue` values against any array or object value, respectively. See
21583
21719
  * `_.isEqual` for a list of supported value comparisons.
21584
21720
  *
21721
+ * **Note:** Multiple values can be checked by combining several matchers
21722
+ * using `_.overSome`
21723
+ *
21585
21724
  * @static
21586
21725
  * @memberOf _
21587
21726
  * @since 3.2.0
@@ -21598,6 +21737,10 @@ Request.prototype.clone = function() {
21598
21737
  *
21599
21738
  * _.find(objects, _.matchesProperty('a', 4));
21600
21739
  * // => { 'a': 4, 'b': 5, 'c': 6 }
21740
+ *
21741
+ * // Checking for several possible values
21742
+ * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
21743
+ * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
21601
21744
  */
21602
21745
  function matchesProperty(path, srcValue) {
21603
21746
  return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
@@ -21821,6 +21964,10 @@ Request.prototype.clone = function() {
21821
21964
  * Creates a function that checks if **all** of the `predicates` return
21822
21965
  * truthy when invoked with the arguments it receives.
21823
21966
  *
21967
+ * Following shorthands are possible for providing predicates.
21968
+ * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
21969
+ * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
21970
+ *
21824
21971
  * @static
21825
21972
  * @memberOf _
21826
21973
  * @since 4.0.0
@@ -21847,6 +21994,10 @@ Request.prototype.clone = function() {
21847
21994
  * Creates a function that checks if **any** of the `predicates` return
21848
21995
  * truthy when invoked with the arguments it receives.
21849
21996
  *
21997
+ * Following shorthands are possible for providing predicates.
21998
+ * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
21999
+ * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
22000
+ *
21850
22001
  * @static
21851
22002
  * @memberOf _
21852
22003
  * @since 4.0.0
@@ -21866,6 +22017,9 @@ Request.prototype.clone = function() {
21866
22017
  *
21867
22018
  * func(NaN);
21868
22019
  * // => false
22020
+ *
22021
+ * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
22022
+ * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
21869
22023
  */
21870
22024
  var overSome = createOver(arraySome);
21871
22025
 
@@ -27465,29 +27619,6 @@ module.exports = once;
27465
27619
 
27466
27620
  "use strict";
27467
27621
 
27468
- Object.defineProperty(exports, "__esModule", { value: true });
27469
- class GenericError extends Error {
27470
- constructor(message = "Unknown Error", statusCode = 500) {
27471
- super(message);
27472
- this.statusCode = statusCode;
27473
- }
27474
- toData() {
27475
- return {
27476
- isError: true,
27477
- errorCode: this.statusCode,
27478
- errorMessage: this.message
27479
- };
27480
- }
27481
- }
27482
- exports.default = GenericError;
27483
- //# sourceMappingURL=GenericError.js.map
27484
-
27485
- /***/ }),
27486
- /* 80 */
27487
- /***/ (function(module, exports, __webpack_require__) {
27488
-
27489
- "use strict";
27490
-
27491
27622
  Object.defineProperty(exports, "__esModule", { value: true });
27492
27623
  function addTrailingSlash(url) {
27493
27624
  if (!url) {
@@ -27504,13 +27635,13 @@ exports.default = addTrailingSlash;
27504
27635
  //# sourceMappingURL=addTrailingSlash.js.map
27505
27636
 
27506
27637
  /***/ }),
27507
- /* 81 */
27638
+ /* 80 */
27508
27639
  /***/ (function(module, exports, __webpack_require__) {
27509
27640
 
27510
27641
  var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
27511
27642
  * URI.js - Mutating URLs
27512
27643
  *
27513
- * Version: 1.19.5
27644
+ * Version: 1.19.11
27514
27645
  *
27515
27646
  * Author: Rodney Rehm
27516
27647
  * Web: http://medialize.github.io/URI.js/
@@ -27590,7 +27721,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
27590
27721
  return /^[0-9]+$/.test(value);
27591
27722
  }
27592
27723
 
27593
- URI.version = '1.19.5';
27724
+ URI.version = '1.19.11';
27594
27725
 
27595
27726
  var p = URI.prototype;
27596
27727
  var hasOwn = Object.prototype.hasOwnProperty;
@@ -27748,6 +27879,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
27748
27879
  // balanced parens inclusion (), [], {}, <>
27749
27880
  parens: /(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g,
27750
27881
  };
27882
+ URI.leading_whitespace_expression = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
27883
+ // https://infra.spec.whatwg.org/#ascii-tab-or-newline
27884
+ URI.ascii_tab_whitespace = /[\u0009\u000A\u000D]+/g
27751
27885
  // http://www.iana.org/assignments/uri-schemes.html
27752
27886
  // http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
27753
27887
  URI.defaultPorts = {
@@ -28003,6 +28137,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28003
28137
  preventInvalidHostname: URI.preventInvalidHostname
28004
28138
  };
28005
28139
  }
28140
+
28141
+ string = string.replace(URI.leading_whitespace_expression, '')
28142
+ // https://infra.spec.whatwg.org/#ascii-tab-or-newline
28143
+ string = string.replace(URI.ascii_tab_whitespace, '')
28144
+
28006
28145
  // [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
28007
28146
 
28008
28147
  // extract fragment
@@ -28021,6 +28160,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28021
28160
  string = string.substring(0, pos);
28022
28161
  }
28023
28162
 
28163
+ // slashes and backslashes have lost all meaning for the web protocols (https, http, wss, ws)
28164
+ string = string.replace(/^(https?|ftp|wss?)?:+[/\\]*/i, '$1://');
28165
+ // slashes and backslashes have lost all meaning for scheme relative URLs
28166
+ string = string.replace(/^[/\\]{2,}/i, '//');
28167
+
28024
28168
  // extract protocol
28025
28169
  if (string.substring(0, 2) === '//') {
28026
28170
  // relative-scheme
@@ -28035,7 +28179,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28035
28179
  if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
28036
28180
  // : may be within the path
28037
28181
  parts.protocol = undefined;
28038
- } else if (string.substring(pos + 1, pos + 3) === '//') {
28182
+ } else if (string.substring(pos + 1, pos + 3).replace(/\\/g, '/') === '//') {
28039
28183
  string = string.substring(pos + 3);
28040
28184
 
28041
28185
  // extract "user:pass@host:port"
@@ -28167,7 +28311,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28167
28311
  // no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
28168
28312
  value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;
28169
28313
 
28170
- if (hasOwn.call(items, name)) {
28314
+ if (name === '__proto__') {
28315
+ // ignore attempt at exploiting JavaScript internals
28316
+ continue;
28317
+ } else if (hasOwn.call(items, name)) {
28171
28318
  if (typeof items[name] === 'string' || items[name] === null) {
28172
28319
  items[name] = [items[name]];
28173
28320
  }
@@ -28260,7 +28407,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28260
28407
  var t = '';
28261
28408
  var unique, key, i, length;
28262
28409
  for (key in data) {
28263
- if (hasOwn.call(data, key)) {
28410
+ if (key === '__proto__') {
28411
+ // ignore attempt at exploiting JavaScript internals
28412
+ continue;
28413
+ } else if (hasOwn.call(data, key)) {
28264
28414
  if (isArray(data[key])) {
28265
28415
  unique = {};
28266
28416
  for (i = 0, length = data[key].length; i < length; i++) {
@@ -29854,6 +30004,41 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
29854
30004
  }));
29855
30005
 
29856
30006
 
30007
+ /***/ }),
30008
+ /* 81 */
30009
+ /***/ (function(module, exports, __webpack_require__) {
30010
+
30011
+ "use strict";
30012
+
30013
+ Object.defineProperty(exports, "__esModule", { value: true });
30014
+ class ServerError extends Error {
30015
+ constructor(message = "Unknown Error", statusCode = 500) {
30016
+ super(message);
30017
+ this.statusCode = statusCode;
30018
+ }
30019
+ toData() {
30020
+ return {
30021
+ isError: true,
30022
+ errorCode: this.statusCode,
30023
+ errorMessage: this.message
30024
+ };
30025
+ }
30026
+ }
30027
+ exports.default = ServerError;
30028
+ //# sourceMappingURL=ServerError.js.map
30029
+
30030
+ /***/ }),
30031
+ /* 82 */
30032
+ /***/ (function(module, exports, __webpack_require__) {
30033
+
30034
+ "use strict";
30035
+
30036
+ Object.defineProperty(exports, "__esModule", { value: true });
30037
+ const uuidRegEx = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
30038
+ const isUuid = (id) => typeof id === "string" && uuidRegEx.test(id);
30039
+ exports.default = isUuid;
30040
+ //# sourceMappingURL=isUuid.js.map
30041
+
29857
30042
  /***/ })
29858
30043
  /******/ ]);
29859
30044
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/auth-api-client",
3
3
  "description": "MAGDA Auth API Client",
4
- "version": "2.0.0-alpha.0",
4
+ "version": "2.0.0-alpha.3",
5
5
  "scripts": {
6
6
  "prebuild": "rimraf dist tsconfig.tsbuildinfo",
7
7
  "build": "webpack && api-extractor run -l",
@@ -12,7 +12,7 @@
12
12
  "main": "dist/index.js",
13
13
  "types": "dist/index.d.ts",
14
14
  "devDependencies": {
15
- "@magda/typescript-common": "^2.0.0-alpha.0",
15
+ "@magda/typescript-common": "^2.0.0-alpha.3",
16
16
  "@microsoft/api-extractor": "^7.7.8",
17
17
  "ts-loader": "^6.2.1",
18
18
  "typescript": "^3.7.2",