@api-client/core 0.12.9 → 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 (81) hide show
  1. package/build/src/browser.d.ts +1 -2
  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 +1 -2
  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/mocking/lib/User.d.ts.map +1 -1
  14. package/build/src/mocking/lib/User.js +1 -0
  15. package/build/src/mocking/lib/User.js.map +1 -1
  16. package/build/src/models/store/User.d.ts +14 -0
  17. package/build/src/models/store/User.d.ts.map +1 -1
  18. package/build/src/models/store/User.js.map +1 -1
  19. package/build/src/proxy/HttpProjectProxy.d.ts.map +1 -1
  20. package/build/src/proxy/HttpProjectProxy.js +39 -43
  21. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  22. package/build/src/proxy/RequestProxy.d.ts.map +1 -1
  23. package/build/src/proxy/RequestProxy.js +11 -11
  24. package/build/src/proxy/RequestProxy.js.map +1 -1
  25. package/build/src/runtime/store/DataCatalogSdk.d.ts.map +1 -1
  26. package/build/src/runtime/store/DataCatalogSdk.js +49 -109
  27. package/build/src/runtime/store/DataCatalogSdk.js.map +1 -1
  28. package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
  29. package/build/src/runtime/store/FilesSdk.js +51 -115
  30. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  31. package/build/src/runtime/store/HistorySdk.d.ts.map +1 -1
  32. package/build/src/runtime/store/HistorySdk.js +25 -70
  33. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  34. package/build/src/runtime/store/OrganizationsSdk.d.ts +20 -1
  35. package/build/src/runtime/store/OrganizationsSdk.d.ts.map +1 -1
  36. package/build/src/runtime/store/OrganizationsSdk.js +103 -43
  37. package/build/src/runtime/store/OrganizationsSdk.js.map +1 -1
  38. package/build/src/runtime/store/RevisionsSdk.d.ts.map +1 -1
  39. package/build/src/runtime/store/RevisionsSdk.js +5 -10
  40. package/build/src/runtime/store/RevisionsSdk.js.map +1 -1
  41. package/build/src/runtime/store/RouteBuilder.d.ts +8 -0
  42. package/build/src/runtime/store/RouteBuilder.d.ts.map +1 -1
  43. package/build/src/runtime/store/RouteBuilder.js +12 -0
  44. package/build/src/runtime/store/RouteBuilder.js.map +1 -1
  45. package/build/src/runtime/store/SdkBase.d.ts +7 -5
  46. package/build/src/runtime/store/SdkBase.d.ts.map +1 -1
  47. package/build/src/runtime/store/SdkBase.js +45 -63
  48. package/build/src/runtime/store/SdkBase.js.map +1 -1
  49. package/build/src/runtime/store/SharedSdk.d.ts.map +1 -1
  50. package/build/src/runtime/store/SharedSdk.js +5 -14
  51. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  52. package/build/src/runtime/store/TrashSdk.d.ts.map +1 -1
  53. package/build/src/runtime/store/TrashSdk.js +8 -28
  54. package/build/src/runtime/store/TrashSdk.js.map +1 -1
  55. package/build/src/runtime/store/UsersSdk.d.ts +2 -0
  56. package/build/src/runtime/store/UsersSdk.d.ts.map +1 -1
  57. package/build/src/runtime/store/UsersSdk.js +18 -11
  58. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/exceptions/exception.ts +51 -4
  61. package/src/mocking/lib/User.ts +1 -0
  62. package/src/models/store/User.ts +16 -0
  63. package/src/proxy/HttpProjectProxy.ts +39 -43
  64. package/src/proxy/RequestProxy.ts +11 -11
  65. package/src/runtime/store/DataCatalogSdk.ts +49 -109
  66. package/src/runtime/store/FilesSdk.ts +51 -115
  67. package/src/runtime/store/HistorySdk.ts +25 -70
  68. package/src/runtime/store/OrganizationsSdk.ts +109 -44
  69. package/src/runtime/store/RevisionsSdk.ts +5 -10
  70. package/src/runtime/store/RouteBuilder.ts +14 -0
  71. package/src/runtime/store/SdkBase.ts +46 -65
  72. package/src/runtime/store/SharedSdk.ts +5 -14
  73. package/src/runtime/store/TrashSdk.ts +8 -28
  74. package/src/runtime/store/UsersSdk.ts +18 -11
  75. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +42 -40
  76. package/tests/unit/runtime/proxy/RequestProxy.spec.ts +11 -11
  77. package/build/src/runtime/store/Errors.d.ts +0 -51
  78. package/build/src/runtime/store/Errors.d.ts.map +0 -1
  79. package/build/src/runtime/store/Errors.js +0 -61
  80. package/build/src/runtime/store/Errors.js.map +0 -1
  81. package/src/runtime/store/Errors.ts +0 -98
@@ -1,6 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { SdkError } from './Errors.js';
3
+ import { Exception } from '../../exceptions/exception.js';
4
4
  export class SharedSdk extends SdkBase {
5
5
  /**
6
6
  * Lists shared with the user files.
@@ -21,29 +21,20 @@ export class SharedSdk extends SdkBase {
21
21
  const E_PREFIX = 'Unable to list organizations. ';
22
22
  if (result.status !== 200) {
23
23
  this.logInvalidResponse(result);
24
- let e = this.createGenericSdkError(result.body);
25
- if (!e) {
26
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
27
- e.response = result.body;
28
- }
29
- throw e;
24
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
30
25
  }
31
26
  if (!result.body) {
32
- throw new SdkError(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, 0);
27
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
33
28
  }
34
29
  let data;
35
30
  try {
36
31
  data = JSON.parse(result.body);
37
32
  }
38
33
  catch {
39
- const err = new SdkError(`${E_PREFIX}${E_INVALID_JSON}.`, 0);
40
- err.response = result.body;
41
- throw err;
34
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
42
35
  }
43
36
  if (!Array.isArray(data.items)) {
44
- const err = new SdkError(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`, 0);
45
- err.response = result.body;
46
- throw err;
37
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
47
38
  }
48
39
  return data;
49
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SharedSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/SharedSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAItC,MAAM,OAAO,SAAU,SAAQ,OAAO;IACpC;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CACR,YAAoB,EACpB,KAAsB,EACtB,OAA4B,EAC5B,UAAsB,EAAE;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;QAC9D,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,YA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ACX,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,GAAG,QAAQ,GAAG,kBAAkB,GAAG,EAAE,CAAC,CAAC,CAAA;YAChE,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;YAC1B,MAAM,GAAG,CAAA;QACX,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IFile } from '../../models/store/File.js'\nimport { SdkError } from './Errors.js'\nimport { ListFileKind } from './FilesSdk.js'\nimport { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\n\nexport class SharedSdk extends SdkBase {\n /**\n * Lists shared with the user files.\n *\n * @param kinds the list of kinds to list.\n * @param options Optional query options.\n * @param request Optional request options.\n */\n async list(\n organization: string,\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IFile>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.shared(organization))\n this.sdk.appendListOptions(url, options)\n if (Array.isArray(kinds)) {\n kinds.forEach((k) => url.searchParams.append('kind', k))\n }\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list organizations. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n if (!result.body) {\n throw new SdkError(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, 0)\n }\n let data: ContextListResult<IFile>\n try {\n data = JSON.parse(result.body)\n } catch {\n const err = new SdkError(`${E_PREFIX}${E_INVALID_JSON}.`, 0)\n err.response = result.body\n throw err\n }\n if (!Array.isArray(data.items)) {\n const err = new SdkError(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`, 0)\n err.response = result.body\n throw err\n }\n return data\n }\n}\n"]}
1
+ {"version":3,"file":"SharedSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/SharedSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIhD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAEzD,MAAM,OAAO,SAAU,SAAQ,OAAO;IACpC;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CACR,YAAoB,EACpB,KAAsB,EACtB,OAA4B,EAC5B,UAAsB,EAAE;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;QAC9D,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;QAC1D,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,wBAAw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.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IFile } from '../../models/store/File.js'\nimport { ListFileKind } from './FilesSdk.js'\nimport { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport class SharedSdk extends SdkBase {\n /**\n * Lists shared with the user files.\n *\n * @param kinds the list of kinds to list.\n * @param options Optional query options.\n * @param request Optional request options.\n */\n async list(\n organization: string,\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IFile>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.shared(organization))\n this.sdk.appendListOptions(url, options)\n if (Array.isArray(kinds)) {\n kinds.forEach((k) => url.searchParams.append('kind', k))\n }\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list organizations. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<IFile>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TrashSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAKP,KAAK,UAAU,EAChB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAEv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,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnF;;;OAGG;IACG,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAW3E"}
@@ -1,6 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { SdkError } from './Errors.js';
3
+ import { Exception } from '../../exceptions/exception.js';
4
4
  export class TrashSdk extends SdkBase {
5
5
  /**
6
6
  * Lists trashed entires.
@@ -15,25 +15,20 @@ export class TrashSdk extends SdkBase {
15
15
  const E_PREFIX = 'Unable to list trash. ';
16
16
  if (result.status !== 200) {
17
17
  this.logInvalidResponse(result);
18
- let e = this.createGenericSdkError(result.body);
19
- if (!e) {
20
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
21
- e.response = result.body;
22
- }
23
- throw e;
18
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
24
19
  }
25
20
  if (!result.body) {
26
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
21
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
27
22
  }
28
23
  let data;
29
24
  try {
30
25
  data = JSON.parse(result.body);
31
26
  }
32
27
  catch {
33
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
28
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
34
29
  }
35
30
  if (!Array.isArray(data.items)) {
36
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
31
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
37
32
  }
38
33
  return data;
39
34
  }
@@ -53,12 +48,7 @@ export class TrashSdk extends SdkBase {
53
48
  const E_PREFIX = 'Unable to delete trash. ';
54
49
  if (result.status !== 204) {
55
50
  this.logInvalidResponse(result);
56
- let e = this.createGenericSdkError(result.body);
57
- if (!e) {
58
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
59
- e.response = result.body;
60
- }
61
- throw e;
51
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
62
52
  }
63
53
  }
64
54
  async restore(oid, keys, request = {}) {
@@ -69,12 +59,7 @@ export class TrashSdk extends SdkBase {
69
59
  const E_PREFIX = 'Unable to restore from trash. ';
70
60
  if (result.status !== 204) {
71
61
  this.logInvalidResponse(result);
72
- let e = this.createGenericSdkError(result.body);
73
- if (!e) {
74
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
75
- e.response = result.body;
76
- }
77
- throw e;
62
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
78
63
  }
79
64
  }
80
65
  /**
@@ -89,12 +74,7 @@ export class TrashSdk extends SdkBase {
89
74
  const E_PREFIX = 'Unable to empty trash. ';
90
75
  if (result.status !== 204) {
91
76
  this.logInvalidResponse(result);
92
- let e = this.createGenericSdkError(result.body);
93
- if (!e) {
94
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
95
- e.response = result.body;
96
- }
97
- throw e;
77
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
98
78
  }
99
79
  }
100
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,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ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\nimport { SdkError } from './Errors.js'\nimport type { TrashEntry } from '../../models/TrashEntry.js'\n\nexport class TrashSdk extends SdkBase {\n /**\n * Lists trashed entires.\n * @param options The list query options.\n */\n async list(\n oid: string,\n options: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<TrashEntry>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trash(oid))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list trash. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: ContextListResult<TrashEntry>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!Array.isArray(data.items)) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Permanently deletes a number of files in a batch operation.\n *\n * @param oid The parent organization\n * @param keys The list of trash entry keys to delete.\n * @param request Optional request options.\n */\n async delete(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const path = RouteBuilder.trashBatchDelete(oid)\n const url = this.sdk.getUrl(path)\n const { token } = request\n const result = await this.sdk.http.delete(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n }\n\n async restore(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const url = this.sdk.getUrl(RouteBuilder.trashBatchRestore(oid))\n const { token } = request\n const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to restore from trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n }\n\n /**\n * Empties the trash for the user in the given organization.\n * @param organization The organization key to remove trash for.\n */\n async empty(organization: string, request: SdkOptions = {}): Promise<void> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trashEmpty(organization))\n const result = await this.sdk.http.delete(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to empty trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n }\n}\n"]}
1
+ {"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAEzD,MAAM,OAAO,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACH,KAAK,CAAC,IAAI,CACR,GAAW,EACX,OAA2B,EAC3B,UAAsB,EAAE;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,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AAM,CAAC,IAAI,CAAC,CAAA;QAC3F,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n type SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\nimport type { TrashEntry } from '../../models/TrashEntry.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport class TrashSdk extends SdkBase {\n /**\n * Lists trashed entires.\n * @param options The list query options.\n */\n async list(\n oid: string,\n options: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<TrashEntry>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trash(oid))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list trash. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<TrashEntry>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Permanently deletes a number of files in a batch operation.\n *\n * @param oid The parent organization\n * @param keys The list of trash entry keys to delete.\n * @param request Optional request options.\n */\n async delete(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const path = RouteBuilder.trashBatchDelete(oid)\n const url = this.sdk.getUrl(path)\n const { token } = request\n const result = await this.sdk.http.delete(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n\n async restore(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const url = this.sdk.getUrl(RouteBuilder.trashBatchRestore(oid))\n const { token } = request\n const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to restore from trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n\n /**\n * Empties the trash for the user in the given organization.\n * @param organization The organization key to remove trash for.\n */\n async empty(organization: string, request: SdkOptions = {}): Promise<void> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trashEmpty(organization))\n const result = await this.sdk.http.delete(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to empty trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n}\n"]}
@@ -78,6 +78,7 @@ export declare class UsersSdk extends SdkBase {
78
78
  * @param organizationId The key of the organization we want to read the user from.
79
79
  * @param options Optional query options.
80
80
  * @param request Optional request options.
81
+ * @deprecated Use `organizations.listUsers()` instead.
81
82
  */
82
83
  list(organizationId: string, options?: ContextListOptions, request?: SdkOptions): Promise<ContextListResult<IUser>>;
83
84
  /**
@@ -87,6 +88,7 @@ export declare class UsersSdk extends SdkBase {
87
88
  * @param key The user key.
88
89
  * @param request Optional request options.
89
90
  * @returns The user object
91
+ * @deprecated Use `organizations.getUser()` instead.
90
92
  */
91
93
  read(organizationId: string, key: string, request?: SdkOptions): Promise<I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AA;CACf;AAED,MAAM,WAAW,6BAA8B,SAAQ,iBAAiB;IACtE,MAAM,EAAE,kBAAkB,CAAA;IAC1B;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;IACjE,MAAM,EAAE,uBAAuB,CAAA;IAC/B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACG,EAAE,CAAC,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,KAAK,CAAC;IAyBlD;;;;;;;OAOG;IACG,IAAI,CACR,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IA4BpC;;;;;;;;OAQG;IACG,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,KAAK,CAAC;CAuB1F"}
@@ -1,5 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
+ import { Exception } from '../../exceptions/exception.js';
3
4
  export class UsersSdk extends SdkBase {
4
5
  /**
5
6
  * Reads the current user.
@@ -13,20 +14,20 @@ export class UsersSdk extends SdkBase {
13
14
  const E_PREFIX = 'Unable to read a user. ';
14
15
  if (result.status !== 200) {
15
16
  this.logInvalidResponse(result);
16
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
17
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
17
18
  }
18
19
  if (!result.body) {
19
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
20
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
20
21
  }
21
22
  let data;
22
23
  try {
23
24
  data = JSON.parse(result.body);
24
25
  }
25
26
  catch {
26
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
27
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
27
28
  }
28
29
  if (!data.key) {
29
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
30
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
30
31
  }
31
32
  return data;
32
33
  }
@@ -36,8 +37,11 @@ export class UsersSdk extends SdkBase {
36
37
  * @param organizationId The key of the organization we want to read the user from.
37
38
  * @param options Optional query options.
38
39
  * @param request Optional request options.
40
+ * @deprecated Use `organizations.listUsers()` instead.
39
41
  */
40
42
  async list(organizationId, options, request = {}) {
43
+ // eslint-disable-next-line no-console
44
+ console.warn('The `users.list` method is deprecated. Use `organizations.listUsers()` instead.');
41
45
  const { token } = request;
42
46
  const url = this.sdk.getUrl(RouteBuilder.users(organizationId));
43
47
  this.sdk.appendListOptions(url, options);
@@ -46,20 +50,20 @@ export class UsersSdk extends SdkBase {
46
50
  const E_PREFIX = 'Unable to list projects. ';
47
51
  if (result.status !== 200) {
48
52
  this.logInvalidResponse(result);
49
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
53
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
50
54
  }
51
55
  if (!result.body) {
52
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
56
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
53
57
  }
54
58
  let data;
55
59
  try {
56
60
  data = JSON.parse(result.body);
57
61
  }
58
62
  catch {
59
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
63
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
60
64
  }
61
65
  if (!Array.isArray(data.items)) {
62
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
66
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
63
67
  }
64
68
  return data;
65
69
  }
@@ -70,8 +74,11 @@ export class UsersSdk extends SdkBase {
70
74
  * @param key The user key.
71
75
  * @param request Optional request options.
72
76
  * @returns The user object
77
+ * @deprecated Use `organizations.getUser()` instead.
73
78
  */
74
79
  async read(organizationId, key, request = {}) {
80
+ // eslint-disable-next-line no-console
81
+ console.warn('The `users.read` method is deprecated. Use `organizations.getUser()` instead.');
75
82
  const { token } = request;
76
83
  const url = this.sdk.getUrl(RouteBuilder.user(organizationId, key));
77
84
  const result = await this.sdk.http.get(url.toString(), { token });
@@ -79,17 +86,17 @@ export class UsersSdk extends SdkBase {
79
86
  const E_PREFIX = 'Unable to read the user info. ';
80
87
  if (result.status !== 200) {
81
88
  this.logInvalidResponse(result);
82
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
89
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
83
90
  }
84
91
  if (!result.body) {
85
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
92
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
86
93
  }
87
94
  let data;
88
95
  try {
89
96
  data = JSON.parse(result.body);
90
97
  }
91
98
  catch {
92
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
99
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });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,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,cAAc,GAAG,CAAC,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IUser } from '../../models/store/User.js'\nimport { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'\n\nexport interface IJwtInfo {\n /**\n * The information about the user that is read from the JWT.\n */\n data: IJwtUser\n /**\n * The name of the provider.\n */\n provider: string\n}\n\nexport interface IJwtUser {\n /**\n * The provider's unique ID.\n */\n id: string\n /**\n * The user's email address.\n */\n email: string\n /**\n * true, if the provider has verified the email address.\n */\n email_verified: boolean\n /**\n * The user's full name.\n */\n name: string\n /**\n * If present, a URL to user's profile picture\n */\n picture?: string\n given_name?: string\n family_name?: string\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hd?: string\n}\n\nexport interface IRegistrationInfo {\n reason: 'new-organization' | 'existing-organization'\n /**\n * The decoded JWT user information.\n * Used to create a user account.\n */\n user: IJwtInfo\n}\n\nexport interface IOrganizationRegistrationInfo extends IRegistrationInfo {\n reason: 'new-organization'\n /**\n * The name of the organization to create for the user.\n */\n organizationName: string\n}\n\nexport interface IOrganizationAddUserInfo extends IRegistrationInfo {\n reason: 'existing-organization'\n /**\n * Set when adding a user to an existing organization.\n */\n organizationId: string\n /**\n * The invitation code used to invite the user.\n */\n invitation: string\n}\n\nexport class UsersSdk extends SdkBase {\n /**\n * Reads the current user.\n * @param request Optional request options.\n */\n async me(request: SdkOptions = {}): Promise<IUser> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.usersMe())\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read a user. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!data.key) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Lists users in the store\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param options Optional query options.\n * @param request Optional request options.\n */\n async list(\n organizationId: string,\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IUser>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.users(organizationId))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list projects. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: ContextListResult<IUser>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!Array.isArray(data.items)) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Reads a user information from the store.\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param key The user key.\n * @param request Optional request options.\n * @returns The user object\n */\n async read(organizationId: string, key: string, request: SdkOptions = {}): Promise<IUser> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.user(organizationId, key))\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read the user info. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n return data\n }\n}\n"]}
1
+ {"version":3,"file":"UsersSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/UsersSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAwEzD,MAAM,OAAO,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,UAAsB,EAAE;QAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAA;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,yBAAyB,CAAA;QAC1C,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,Q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GAAG,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACxG,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IUser } from '../../models/store/User.js'\nimport { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport interface IJwtInfo {\n /**\n * The information about the user that is read from the JWT.\n */\n data: IJwtUser\n /**\n * The name of the provider.\n */\n provider: string\n}\n\nexport interface IJwtUser {\n /**\n * The provider's unique ID.\n */\n id: string\n /**\n * The user's email address.\n */\n email: string\n /**\n * true, if the provider has verified the email address.\n */\n email_verified: boolean\n /**\n * The user's full name.\n */\n name: string\n /**\n * If present, a URL to user's profile picture\n */\n picture?: string\n given_name?: string\n family_name?: string\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hd?: string\n}\n\nexport interface IRegistrationInfo {\n reason: 'new-organization' | 'existing-organization'\n /**\n * The decoded JWT user information.\n * Used to create a user account.\n */\n user: IJwtInfo\n}\n\nexport interface IOrganizationRegistrationInfo extends IRegistrationInfo {\n reason: 'new-organization'\n /**\n * The name of the organization to create for the user.\n */\n organizationName: string\n}\n\nexport interface IOrganizationAddUserInfo extends IRegistrationInfo {\n reason: 'existing-organization'\n /**\n * Set when adding a user to an existing organization.\n */\n organizationId: string\n /**\n * The invitation code used to invite the user.\n */\n invitation: string\n}\n\nexport class UsersSdk extends SdkBase {\n /**\n * Reads the current user.\n * @param request Optional request options.\n */\n async me(request: SdkOptions = {}): Promise<IUser> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.usersMe())\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read a user. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!data.key) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Lists users in the store\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param options Optional query options.\n * @param request Optional request options.\n * @deprecated Use `organizations.listUsers()` instead.\n */\n async list(\n organizationId: string,\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IUser>> {\n // eslint-disable-next-line no-console\n console.warn('The `users.list` method is deprecated. Use `organizations.listUsers()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.users(organizationId))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list projects. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<IUser>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Reads a user information from the store.\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param key The user key.\n * @param request Optional request options.\n * @returns The user object\n * @deprecated Use `organizations.getUser()` instead.\n */\n async read(organizationId: string, key: string, request: SdkOptions = {}): Promise<IUser> {\n // eslint-disable-next-line no-console\n console.warn('The `users.read` method is deprecated. Use `organizations.getUser()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.user(organizationId, key))\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read the user info. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n return data\n }\n}\n"]}
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.9",
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
  }
@@ -29,6 +29,7 @@ export class User {
29
29
  kind: UserKind,
30
30
  key: this.types.string(21),
31
31
  name: this.person.name(),
32
+ status: this.random.pickOne(['active', 'deleted', 'suspended', 'pending']),
32
33
  }
33
34
  if (!init.noEmail) {
34
35
  result.email = [
@@ -1,3 +1,5 @@
1
+ import type { UserOrganizationGrantType } from './Organization.js'
2
+
1
3
  export interface IEmail {
2
4
  /**
3
5
  * When available the email of the user.
@@ -23,6 +25,8 @@ export interface IUserPicture {
23
25
 
24
26
  export const Kind = 'Core#User'
25
27
 
28
+ export type UserStatus = 'active' | 'deleted' | 'suspended' | 'pending'
29
+
26
30
  /**
27
31
  * Represents a user in the system.
28
32
  * This can be embedded in various situations like project's revision history,
@@ -63,6 +67,7 @@ export interface IUser {
63
67
  provider?: unknown
64
68
  /**
65
69
  * Whether the user is deleted from the system.
70
+ * @deprecated Use `status` instead.
66
71
  */
67
72
  deleted?: boolean
68
73
  /**
@@ -73,4 +78,15 @@ export interface IUser {
73
78
  * The id of the user that deleted the user.
74
79
  */
75
80
  deletingUser?: string
81
+ /**
82
+ * The status of the user.
83
+ * May not be populated in all cases.
84
+ * @default 'active'
85
+ */
86
+ status?: UserStatus
87
+ /**
88
+ * Populated when the user object is considered in the context of an organization.
89
+ * This is used to determine the user's role in the organization.
90
+ */
91
+ grantType?: UserOrganizationGrantType
76
92
  }