@magda/auth-api-client 2.0.0-alpha.2 → 2.0.0-alpha.5

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
@@ -129,6 +129,7 @@ declare class ApiClient {
129
129
  createOrgNode(parentNodeId: string, node: Partial<Omit<OrgUnitRecord, "id" | "createBy" | "createTime" | "editBy" | "editTime" | "left" | "right">>): Promise<OrgUnit>;
130
130
  createRole(name: string, desc?: string): Promise<Role>;
131
131
  createRolePermission(roleId: string, permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>;
132
+ createPermission(permissionData: CreateRolePermissionInputData): Promise<PermissionRecord>;
132
133
  getOperationByUri(opUri: string): Promise<OperationRecord>;
133
134
  getResourceByUri(resUri: string): Promise<ResourceRecord>;
134
135
  private handleGetResult;
package/dist/index.js CHANGED
@@ -2353,7 +2353,26 @@ class ApiClient {
2353
2353
  */
2354
2354
  lookupUser(source, sourceId) {
2355
2355
  return __awaiter(this, void 0, void 0, function* () {
2356
- return this.handleGetResult(isomorphic_fetch_1.default(`${this.baseUrl}private/users/lookup?source=${source}&sourceId=${sourceId}`, this.getMergeRequestInitOption()));
2356
+ if (!source) {
2357
+ throw new ServerError_1.default("source cannot be empty!", 400);
2358
+ }
2359
+ if (!sourceId) {
2360
+ throw new ServerError_1.default("sourceId cannot be empty!", 400);
2361
+ }
2362
+ const uri = urijs_1.default(`${this.baseUrl}public/users`).search({
2363
+ source,
2364
+ sourceId,
2365
+ limit: 1
2366
+ });
2367
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption());
2368
+ if (!res.ok) {
2369
+ throw new ServerError_1.default(yield res.text(), res.status);
2370
+ }
2371
+ const data = yield res.json();
2372
+ if (!(data === null || data === void 0 ? void 0 : data.length)) {
2373
+ return tsmonad_1.Maybe.nothing();
2374
+ }
2375
+ return tsmonad_1.Maybe.just(data[0]);
2357
2376
  });
2358
2377
  }
2359
2378
  /**
@@ -2611,6 +2630,16 @@ class ApiClient {
2611
2630
  return yield this.processJsonResponse(res);
2612
2631
  });
2613
2632
  }
2633
+ createPermission(permissionData) {
2634
+ return __awaiter(this, void 0, void 0, function* () {
2635
+ const uri = urijs_1.default(`${this.baseUrl}public/permissions`);
2636
+ const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption({
2637
+ method: "post",
2638
+ body: JSON.stringify(permissionData)
2639
+ }));
2640
+ return yield this.processJsonResponse(res);
2641
+ });
2642
+ }
2614
2643
  getOperationByUri(opUri) {
2615
2644
  return __awaiter(this, void 0, void 0, function* () {
2616
2645
  const uri = urijs_1.default(`${this.baseUrl}public/operations/byUri/${opUri}`);
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.2",
4
+ "version": "2.0.0-alpha.5",
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.2",
15
+ "@magda/typescript-common": "^2.0.0-alpha.5",
16
16
  "@microsoft/api-extractor": "^7.7.8",
17
17
  "ts-loader": "^6.2.1",
18
18
  "typescript": "^3.7.2",