@cubicweb/client 3.0.0-alpha.8 → 3.0.0

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 (122) hide show
  1. package/README.md +58 -34
  2. package/lib/Authenticator.d.ts +8 -0
  3. package/lib/Authenticator.d.ts.map +1 -0
  4. package/lib/Authenticator.js +2 -0
  5. package/lib/Authenticator.js.map +1 -0
  6. package/lib/api/Api.d.ts +56 -23
  7. package/lib/api/Api.d.ts.map +1 -1
  8. package/lib/api/Api.js +141 -140
  9. package/lib/api/Api.js.map +1 -1
  10. package/lib/api/Client.d.ts +26 -10
  11. package/lib/api/Client.d.ts.map +1 -1
  12. package/lib/api/Client.js +41 -58
  13. package/lib/api/Client.js.map +1 -1
  14. package/lib/api/ResultSet.d.ts +52 -0
  15. package/lib/api/ResultSet.d.ts.map +1 -0
  16. package/lib/api/ResultSet.js +64 -0
  17. package/lib/api/ResultSet.js.map +1 -0
  18. package/lib/api/authenticators/CookieAuthenticator.d.ts +10 -0
  19. package/lib/api/authenticators/CookieAuthenticator.d.ts.map +1 -0
  20. package/lib/api/authenticators/CookieAuthenticator.js +11 -0
  21. package/lib/api/authenticators/CookieAuthenticator.js.map +1 -0
  22. package/lib/api/authenticators/SignedRequestAuthenticator.d.ts +32 -0
  23. package/lib/api/authenticators/SignedRequestAuthenticator.d.ts.map +1 -0
  24. package/lib/api/authenticators/SignedRequestAuthenticator.js +89 -0
  25. package/lib/api/authenticators/SignedRequestAuthenticator.js.map +1 -0
  26. package/lib/api/binary/RQLBinary.d.ts +6 -0
  27. package/lib/api/binary/RQLBinary.d.ts.map +1 -0
  28. package/lib/api/binary/RQLBinary.js +10 -0
  29. package/lib/api/binary/RQLBinary.js.map +1 -0
  30. package/lib/api/query/RQLQuery.d.ts +40 -0
  31. package/lib/api/query/RQLQuery.d.ts.map +1 -0
  32. package/lib/api/query/RQLQuery.js +48 -0
  33. package/lib/api/query/RQLQuery.js.map +1 -0
  34. package/lib/api/query/references.d.ts +41 -0
  35. package/lib/api/query/references.d.ts.map +1 -0
  36. package/lib/api/query/references.js +50 -0
  37. package/lib/api/query/references.js.map +1 -0
  38. package/lib/api/transaction/Transaction.d.ts +25 -0
  39. package/lib/api/transaction/Transaction.d.ts.map +1 -0
  40. package/lib/api/transaction/Transaction.js +28 -0
  41. package/lib/api/transaction/Transaction.js.map +1 -0
  42. package/lib/api/transaction/TransactionResult.d.ts +41 -0
  43. package/lib/api/transaction/TransactionResult.d.ts.map +1 -0
  44. package/lib/api/transaction/TransactionResult.js +45 -0
  45. package/lib/api/transaction/TransactionResult.js.map +1 -0
  46. package/lib/encodeFormData.d.ts +5 -0
  47. package/lib/encodeFormData.d.ts.map +1 -0
  48. package/lib/encodeFormData.js +94 -0
  49. package/lib/encodeFormData.js.map +1 -0
  50. package/lib/{Errors.d.ts → errors.d.ts} +7 -4
  51. package/lib/errors.d.ts.map +1 -0
  52. package/lib/errors.js +19 -0
  53. package/lib/errors.js.map +1 -0
  54. package/lib/index.d.ts +19 -13
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js +17 -34
  57. package/lib/index.js.map +1 -1
  58. package/lib/schema/classes/EntitySchema.d.ts +5 -5
  59. package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
  60. package/lib/schema/classes/EntitySchema.js +3 -5
  61. package/lib/schema/classes/EntitySchema.js.map +1 -1
  62. package/lib/schema/classes/RelationDefinitionSchema.d.ts +6 -6
  63. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
  64. package/lib/schema/classes/RelationDefinitionSchema.js +8 -10
  65. package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -1
  66. package/lib/schema/classes/Schema.d.ts +7 -7
  67. package/lib/schema/classes/Schema.d.ts.map +1 -1
  68. package/lib/schema/classes/Schema.js +8 -11
  69. package/lib/schema/classes/Schema.js.map +1 -1
  70. package/lib/schema/classes/Utils.d.ts +10 -10
  71. package/lib/schema/classes/Utils.d.ts.map +1 -1
  72. package/lib/schema/classes/Utils.js +19 -35
  73. package/lib/schema/classes/Utils.js.map +1 -1
  74. package/lib/schema/raw/Constraints.d.ts +27 -0
  75. package/lib/schema/raw/Constraints.d.ts.map +1 -1
  76. package/lib/schema/raw/Constraints.js +1 -2
  77. package/lib/schema/raw/Entities.js +1 -2
  78. package/lib/schema/raw/RelationDefinitions.d.ts +3 -3
  79. package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
  80. package/lib/schema/raw/RelationDefinitions.js +1 -2
  81. package/lib/schema/raw/Schema.d.ts +2 -2
  82. package/lib/schema/raw/Schema.d.ts.map +1 -1
  83. package/lib/schema/raw/Schema.js +1 -2
  84. package/lib/schema/raw/Utils.d.ts +1 -1
  85. package/lib/schema/raw/Utils.d.ts.map +1 -1
  86. package/lib/schema/raw/Utils.js +1 -2
  87. package/lib/utils.d.ts +39 -0
  88. package/lib/utils.d.ts.map +1 -0
  89. package/lib/utils.js +58 -0
  90. package/lib/utils.js.map +1 -0
  91. package/package.json +15 -5
  92. package/src/Authenticator.ts +8 -0
  93. package/src/api/Api.ts +148 -122
  94. package/src/api/Client.ts +31 -18
  95. package/src/api/ResultSet.ts +95 -0
  96. package/src/api/authenticators/CookieAuthenticator.ts +17 -0
  97. package/src/api/authenticators/SignedRequestAuthenticator.ts +133 -0
  98. package/src/api/binary/RQLBinary.ts +9 -0
  99. package/src/api/query/RQLQuery.ts +51 -0
  100. package/src/api/query/references.ts +43 -0
  101. package/src/api/transaction/Transaction.ts +31 -0
  102. package/src/api/transaction/TransactionResult.ts +68 -0
  103. package/src/encodeFormData.ts +126 -0
  104. package/src/{Errors.ts → errors.ts} +6 -7
  105. package/src/index.ts +24 -17
  106. package/src/schema/classes/EntitySchema.ts +8 -5
  107. package/src/schema/classes/RelationDefinitionSchema.ts +7 -7
  108. package/src/schema/classes/Schema.ts +10 -7
  109. package/src/schema/classes/Utils.ts +4 -4
  110. package/src/schema/raw/Constraints.ts +28 -0
  111. package/src/schema/raw/RelationDefinitions.ts +3 -3
  112. package/src/schema/raw/Schema.ts +2 -2
  113. package/src/schema/raw/Utils.ts +1 -1
  114. package/src/utils.ts +91 -0
  115. package/lib/Errors.d.ts.map +0 -1
  116. package/lib/Errors.js +0 -25
  117. package/lib/Errors.js.map +0 -1
  118. package/lib/api/Transaction.d.ts +0 -46
  119. package/lib/api/Transaction.d.ts.map +0 -1
  120. package/lib/api/Transaction.js +0 -75
  121. package/lib/api/Transaction.js.map +0 -1
  122. package/src/api/Transaction.ts +0 -94
package/lib/api/Client.js CHANGED
@@ -1,26 +1,14 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Schema_1 = require("../schema/classes/Schema");
16
- const Api_1 = __importDefault(require("./Api"));
17
- const Transaction_1 = require("./Transaction");
1
+ import { Schema } from "../schema/classes/Schema.js";
2
+ import Api from "./Api.js";
3
+ import { RQLQuery } from "./query/RQLQuery.js";
4
+ import { Transaction } from "./transaction/Transaction.js";
18
5
  /**
19
6
  * Class used to communicate with a CubicWeb instance's API.
20
7
  *
21
8
  * @category Api
22
9
  */
23
- class Client {
10
+ export default class Client {
11
+ api;
24
12
  /**
25
13
  * Class used to communicate with a CubicWeb instance's API.
26
14
  *
@@ -28,8 +16,8 @@ class Client {
28
16
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
29
17
  * use https://example.com/api as `apiUrl`.
30
18
  */
31
- constructor(apiUrl) {
32
- this.api = new Api_1.default(apiUrl);
19
+ constructor(apiUrl, options) {
20
+ this.api = new Api(apiUrl, options ?? {});
33
21
  }
34
22
  get apiUrl() {
35
23
  return this.api.apiUrl;
@@ -37,81 +25,76 @@ class Client {
37
25
  /**
38
26
  * Executes the given query and waits for the response.
39
27
  *
40
- * @param query The RQL query to send
28
+ * If binaries are given, the request is automatically
29
+ * sent using `multipart/form-data` to allow uploading binaries.
30
+ *
31
+ * @param rql The RQL query to send
41
32
  * @param params The additional parameters for the request
42
33
  * @returns A promise with the request's result set
43
34
  */
44
- execute(query, params = {}, binaries) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const transaction = new Transaction_1.Transaction();
47
- const transactionQuery = transaction.push(query, params);
48
- transaction.setBinaries(binaries);
49
- const result = yield this.executeTransaction(transaction);
50
- return result.resolveQuery(transactionQuery.ref());
51
- });
35
+ async execute(rql, params = {}) {
36
+ const transaction = new Transaction();
37
+ const query = new RQLQuery(rql, params);
38
+ transaction.push(query);
39
+ const result = await this.executeTransaction(transaction);
40
+ return result.getResultSet(query);
52
41
  }
53
42
  /**
54
43
  * Retrieves the CubicWeb instance's JSON schema.
55
44
  *
56
45
  * @returns The CubicWeb instance's JSON schema.
57
46
  */
58
- schema() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const schema = yield this.api.schema();
61
- return new Schema_1.Schema(schema);
62
- });
47
+ async schema() {
48
+ const schema = await this.api.schema();
49
+ return new Schema(schema);
63
50
  }
64
51
  /**
65
52
  * Tries to log in the user on the configured CubicWeb instance with the given credentials.
66
53
  *
67
54
  * @param login The user login
68
- * @param password THe user password
55
+ * @param password The user password
69
56
  * @returns A promise returning true if the login was successful, false otherwise
70
57
  */
71
- login(login, password) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- return yield this.api.login(login, password);
74
- });
58
+ async login(login, password) {
59
+ return await this.api.login(login, password);
75
60
  }
76
61
  /**
77
62
  * Logs out the current user. Will invalidate any authentication cookie active.
78
63
  *
79
64
  * @returns A promise which will resolve when the user is properly logged out
80
65
  */
81
- logout() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return yield this.api.logout();
84
- });
66
+ async logout() {
67
+ return await this.api.logout();
85
68
  }
86
69
  /**
87
70
  * Get the user associated to this client
88
71
  *
89
72
  * @returns A promise resolving to the current user
90
73
  */
91
- currentUser() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return yield this.api.currentUser();
94
- });
74
+ async currentUser() {
75
+ return await this.api.currentUser();
95
76
  }
96
77
  /**
78
+ * Executes the given transaction.
79
+ *
80
+ * If the {@link Transaction} object contains binaries, the request is automatically
81
+ * sent using `multipart/form-data` to allow uploading binaries.
82
+ *
97
83
  * @param transaction Transaction to execute
98
- * @returns A promise fulfilled when the transaction is completed
84
+ * @returns A promise returning the transaction result on success
99
85
  */
100
- executeTransaction(transaction) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- return yield this.api.rql(transaction);
103
- });
86
+ async executeTransaction(transaction) {
87
+ return await this.api.rql(transaction);
104
88
  }
105
89
  /**
106
90
  * Get the binary for the given entity attribute
107
91
  *
108
- * @returns A promise resolving to the binary
92
+ * @param eid Entity eid to fetch the binary from
93
+ * @param attribute Attribute on the entity in which the binary is stored
94
+ * @returns A promise resolving to the binary as a Blob
109
95
  */
110
- getBinary(eid, attribute) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- return yield this.api.binary(eid, attribute);
113
- });
96
+ async getBinary(eid, attribute) {
97
+ return await this.api.binary(eid, attribute);
114
98
  }
115
99
  }
116
- exports.default = Client;
117
100
  //# sourceMappingURL=Client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAAkD;AAClD,gDAA+D;AAC/D,+CAA8E;AAE9E;;;;GAIG;AACH,MAAqB,MAAM;IAGzB;;;;;;OA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C,MAAM,EAAE,CAAC;QACvC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,QAAgB;QACzC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,kBAAkB,CACtB,WAAwB;QAExB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,SAAiB;QAC5C,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Interface representing the json returned by the API for a single result set
3
+ *
4
+ * @category Api
5
+ */
6
+ export interface RawResultSet {
7
+ readonly rows: ResultSetCell[][];
8
+ readonly column_names: string[];
9
+ }
10
+ /**
11
+ * Interface representing the json returned by the API for a single row in a result set
12
+ *
13
+ * @category Api
14
+ */
15
+ export type RawResultSetRow = ResultSetCell[];
16
+ /**
17
+ * Type representing a final value in a result set.
18
+ *
19
+ * Please not this type may not be accurate if you use entity methods,
20
+ * as those methods may return any data structure.
21
+ *
22
+ * @category Api
23
+ */
24
+ export type ResultSetCell = string | number | boolean | null;
25
+ /**
26
+ * Class representing a row returned in a result set.
27
+ *
28
+ * @category Api
29
+ */
30
+ export declare class ResultSetRow implements Iterable<ResultSetCell> {
31
+ readonly columnNames: string[];
32
+ private readonly cells;
33
+ constructor(columnNames: string[], cells: RawResultSetRow);
34
+ [Symbol.iterator](): Generator<ResultSetCell, void, unknown>;
35
+ get length(): number;
36
+ getCell(column: number | string): ResultSetCell;
37
+ }
38
+ /**
39
+ * Class representing a RQL request result.
40
+ *
41
+ * @category Api
42
+ */
43
+ export declare class ResultSet {
44
+ #private;
45
+ readonly columnNames: string[];
46
+ constructor(rawResultSet: RawResultSet);
47
+ [Symbol.iterator](): Generator<ResultSetRow, void, unknown>;
48
+ get length(): number;
49
+ getRow(row: number): ResultSetRow;
50
+ getCell(row: number, column: number | string): ResultSetCell;
51
+ }
52
+ //# sourceMappingURL=ResultSet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResultSet.d.ts","sourceRoot":"","sources":["../../src/api/ResultSet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;CACjC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,EAAE,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,YAAa,YAAW,QAAQ,CAAC,aAAa,CAAC;aAExC,WAAW,EAAE,MAAM,EAAE;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADN,WAAW,EAAE,MAAM,EAAE,EACpB,KAAK,EAAE,eAAe;IAGxC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB,IAAI,MAAM,WAET;IAED,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAQhC;AAED;;;;GAIG;AACH,qBAAa,SAAS;;IACpB,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAG1B,YAAY,EAAE,YAAY;IAKrC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB,IAAI,MAAM,WAET;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAIjC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa;CAQ7D"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Class representing a row returned in a result set.
3
+ *
4
+ * @category Api
5
+ */
6
+ export class ResultSetRow {
7
+ columnNames;
8
+ cells;
9
+ constructor(columnNames, cells) {
10
+ this.columnNames = columnNames;
11
+ this.cells = cells;
12
+ }
13
+ *[Symbol.iterator]() {
14
+ for (const cell of this.cells) {
15
+ yield cell;
16
+ }
17
+ }
18
+ get length() {
19
+ return this.cells.length;
20
+ }
21
+ getCell(column) {
22
+ if (typeof column === "number") {
23
+ return this.cells[column];
24
+ }
25
+ else {
26
+ const columnIndex = this.columnNames.indexOf(column);
27
+ return this.cells[columnIndex];
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * Class representing a RQL request result.
33
+ *
34
+ * @category Api
35
+ */
36
+ export class ResultSet {
37
+ columnNames;
38
+ #rows;
39
+ constructor(rawResultSet) {
40
+ this.columnNames = rawResultSet.column_names;
41
+ this.#rows = rawResultSet.rows;
42
+ }
43
+ *[Symbol.iterator]() {
44
+ for (const r of this.#rows) {
45
+ yield new ResultSetRow(this.columnNames, r);
46
+ }
47
+ }
48
+ get length() {
49
+ return this.#rows.length;
50
+ }
51
+ getRow(row) {
52
+ return new ResultSetRow(this.columnNames, this.#rows[row]);
53
+ }
54
+ getCell(row, column) {
55
+ if (typeof column === "number") {
56
+ return this.#rows[row][column];
57
+ }
58
+ else {
59
+ const columnIndex = this.columnNames.indexOf(column);
60
+ return this.#rows[row][columnIndex];
61
+ }
62
+ }
63
+ }
64
+ //# sourceMappingURL=ResultSet.js.map
@@ -0,0 +1 @@
1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AAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,MAAuB;QAC1C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { AuthenticatedRequest, Authenticator } from "../../Authenticator.js";
2
+ export interface CookieAuthenticatorOptions {
3
+ credentials?: RequestCredentials;
4
+ }
5
+ export declare class CookieAuthenticator implements Authenticator {
6
+ private options?;
7
+ constructor(options?: CookieAuthenticatorOptions | undefined);
8
+ authenticate(url: string, init: RequestInit): Promise<AuthenticatedRequest>;
9
+ }
10
+ //# sourceMappingURL=CookieAuthenticator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieAuthenticator.d.ts","sourceRoot":"","sources":["../../../src/api/authenticators/CookieAuthenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE7E,MAAM,WAAW,0BAA0B;IACzC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,qBAAa,mBAAoB,YAAW,aAAa;IAC3C,OAAO,CAAC,OAAO,CAAC;gBAAR,OAAO,CAAC,wCAA4B;IAElD,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
@@ -0,0 +1,11 @@
1
+ export class CookieAuthenticator {
2
+ options;
3
+ constructor(options) {
4
+ this.options = options;
5
+ }
6
+ async authenticate(url, init) {
7
+ const credentials = this.options?.credentials;
8
+ return { url, init: { ...init, credentials } };
9
+ }
10
+ }
11
+ //# sourceMappingURL=CookieAuthenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieAuthenticator.js","sourceRoot":"","sources":["../../../src/api/authenticators/CookieAuthenticator.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,mBAAmB;IACV;IAApB,YAAoB,OAAoC;QAApC,YAAO,GAAP,OAAO,CAA6B;IAAG,CAAC;IAE5D,KAAK,CAAC,YAAY,CAChB,GAAW,EACX,IAAiB;QAEjB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;QAC9C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import { AuthenticatedRequest, Authenticator } from "../../Authenticator.js";
2
+ export interface SignedRequestAuthToken {
3
+ /**
4
+ * id of the token
5
+ */
6
+ id: string;
7
+ /**
8
+ * secret value of the token
9
+ */
10
+ token: string;
11
+ }
12
+ /**
13
+ * Authenticator allowing to authenticate requests made to a cubicweb instance
14
+ * with the [signedrequest](https://forge.extranet.logilab.fr/cubicweb/cubes/signedrequest) cube (v3.x).
15
+ *
16
+ * @param token A {@link SignedRequestAuthToken}. This token must be enabled.
17
+ */
18
+ export declare class SignedRequestAuthenticator implements Authenticator {
19
+ private token;
20
+ private cachedCryptoKey?;
21
+ constructor(token: SignedRequestAuthToken);
22
+ private digestBody;
23
+ private encodeBody;
24
+ private getCryptoKey;
25
+ /**
26
+ * Compute headers used to sign the request and encode the content as bytes
27
+ */
28
+ private prepareRequest;
29
+ private signContent;
30
+ authenticate(url: string, init: RequestInit): Promise<AuthenticatedRequest>;
31
+ }
32
+ //# sourceMappingURL=SignedRequestAuthenticator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignedRequestAuthenticator.d.ts","sourceRoot":"","sources":["../../../src/api/authenticators/SignedRequestAuthenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAG7E,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAUD;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,aAAa;IAGlD,OAAO,CAAC,KAAK;IAFzB,OAAO,CAAC,eAAe,CAAC,CAAY;gBAEhB,KAAK,EAAE,sBAAsB;YAEnC,UAAU;YAMV,UAAU;YAoBV,YAAY;IAmB1B;;OAEG;YACW,cAAc;YA6Bd,WAAW;IASnB,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,oBAAoB,CAAC;CAUjC"}
@@ -0,0 +1,89 @@
1
+ import { encodeFormData } from "../../encodeFormData.js";
2
+ function bytesToHex(hashBuffer) {
3
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
4
+ const hashHex = hashArray
5
+ .map((b) => b.toString(16).padStart(2, "0"))
6
+ .join(""); // convert bytes to hex string
7
+ return hashHex;
8
+ }
9
+ /**
10
+ * Authenticator allowing to authenticate requests made to a cubicweb instance
11
+ * with the [signedrequest](https://forge.extranet.logilab.fr/cubicweb/cubes/signedrequest) cube (v3.x).
12
+ *
13
+ * @param token A {@link SignedRequestAuthToken}. This token must be enabled.
14
+ */
15
+ export class SignedRequestAuthenticator {
16
+ token;
17
+ cachedCryptoKey;
18
+ constructor(token) {
19
+ this.token = token;
20
+ }
21
+ async digestBody(body) {
22
+ const contentHash = await crypto.subtle.digest("SHA-512", body);
23
+ const hashHex = bytesToHex(contentHash);
24
+ return hashHex;
25
+ }
26
+ async encodeBody(body) {
27
+ if (typeof body === "string") {
28
+ return {
29
+ body: new TextEncoder().encode(body),
30
+ headers: new Headers(),
31
+ };
32
+ }
33
+ else if (body instanceof FormData) {
34
+ return await encodeFormData(body);
35
+ }
36
+ else if (body == null) {
37
+ return {
38
+ body: null,
39
+ headers: new Headers(),
40
+ };
41
+ }
42
+ else {
43
+ throw new Error("Unexpected body type.");
44
+ }
45
+ }
46
+ async getCryptoKey() {
47
+ if (this.cachedCryptoKey) {
48
+ return this.cachedCryptoKey;
49
+ }
50
+ const textEncoder = new TextEncoder();
51
+ this.cachedCryptoKey = await crypto.subtle.importKey("raw", textEncoder.encode(this.token.token), {
52
+ name: "HMAC",
53
+ hash: "SHA-512",
54
+ }, false, ["sign"]);
55
+ return this.cachedCryptoKey;
56
+ }
57
+ /**
58
+ * Compute headers used to sign the request and encode the content as bytes
59
+ */
60
+ async prepareRequest(url, init) {
61
+ const headers = new Headers(init?.headers);
62
+ const { body: encodedBody, headers: encodingHeaders } = await this.encodeBody(init.body || null);
63
+ init.body = encodedBody;
64
+ encodingHeaders.forEach((value, name) => headers.append(name, value));
65
+ const bodyBytes = encodedBody ?? new Uint8Array();
66
+ const bodyHash = await this.digestBody(bodyBytes);
67
+ headers.append("Content-SHA512", bodyHash);
68
+ const date = new Date();
69
+ headers.append("X-Cubicweb-Date", date.toUTCString());
70
+ return {
71
+ contentToSign: (init?.method ?? "GET") +
72
+ url +
73
+ bodyHash +
74
+ (headers.get("Content-Type") ?? "") +
75
+ (headers.get("X-Cubicweb-Date") ?? ""),
76
+ headers,
77
+ };
78
+ }
79
+ async signContent(contentToSign) {
80
+ const textEncoder = new TextEncoder();
81
+ return await crypto.subtle.sign("HMAC", await this.getCryptoKey(), textEncoder.encode(contentToSign));
82
+ }
83
+ async authenticate(url, init) {
84
+ const { contentToSign, headers } = await this.prepareRequest(url, init);
85
+ headers.append("Authorization", `Cubicweb ${this.token.id}:${bytesToHex(await this.signContent(contentToSign))}`);
86
+ return { url, init: { ...init, headers } };
87
+ }
88
+ }
89
+ //# sourceMappingURL=SignedRequestAuthenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignedRequestAuthenticator.js","sourceRoot":"","sources":["../../../src/api/authenticators/SignedRequestAuthenticator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAazD,SAAS,UAAU,CAAC,UAAuB;IACzC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,+BAA+B;IACzF,MAAM,OAAO,GAAG,SAAS;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,8BAA8B;IAC3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAGjB;IAFZ,eAAe,CAAa;IAEpC,YAAoB,KAA6B;QAA7B,UAAK,GAAL,KAAK,CAAwB;IAAG,CAAC;IAE7C,KAAK,CAAC,UAAU,CAAC,IAAgB;QACvC,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,UAAU,CACtB,IAAyB;QAEzB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO;gBACL,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;gBACpC,OAAO,EAAE,IAAI,OAAO,EAAE;aACv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EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export declare class RQLBinary {
2
+ readonly blob: Blob;
3
+ readonly uuid: string;
4
+ constructor(blob: Blob);
5
+ }
6
+ //# sourceMappingURL=RQLBinary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RQLBinary.d.ts","sourceRoot":"","sources":["../../../src/api/binary/RQLBinary.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAS;aAGQ,IAAI,EAAE,IAAI;IAFtC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,IAAI;CAGvC"}
@@ -0,0 +1,10 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ export class RQLBinary {
3
+ blob;
4
+ uuid;
5
+ constructor(blob) {
6
+ this.blob = blob;
7
+ this.uuid = uuidv4();
8
+ }
9
+ }
10
+ //# sourceMappingURL=RQLBinary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RQLBinary.js","sourceRoot":"","sources":["../../../src/api/binary/RQLBinary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,OAAO,SAAS;IAGQ;IAFZ,IAAI,CAAS;IAE7B,YAA4B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QACpC,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,40 @@
1
+ import { RQLQueryCellRef, RQLQueryRowRef } from "./references.js";
2
+ import { RQLQueryParams } from "../Api.js";
3
+ /**
4
+ * Class representing a RQL query to be sent to the API.
5
+ *
6
+ * Queries are identified by a uuid and are independent from transactions.
7
+ *
8
+ * If a query has been used in a transaction, RQLQuery objects can easily retrieve
9
+ * a reference to the query for later resolving the values in a {@link TransactionResult}.
10
+ *
11
+ * @category Api
12
+ */
13
+ export declare class RQLQuery {
14
+ readonly rql: string;
15
+ readonly params: RQLQueryParams;
16
+ readonly queryUUID: string;
17
+ /**
18
+ * Class representing a RQL query to be sent to the API.
19
+ *
20
+ * Queries are identified by a uuid and are independent from transactions.
21
+ *
22
+ * If a query has been used in a transaction, RQLQuery objects can easily retrieve
23
+ * a reference to the query for later resolving the values in a {@link TransactionResult}.
24
+ *
25
+ * @param rql The rql query
26
+ * @param params The parameters for the rql query
27
+ *
28
+ * @category Api
29
+ */
30
+ constructor(rql: string, params?: RQLQueryParams);
31
+ /**
32
+ * @returns A reference to a {@link ResultSetRow} in the result of this query.
33
+ */
34
+ rowRef(row: number): RQLQueryRowRef;
35
+ /**
36
+ * @returns A reference to a {@link ResultSetCell} in the result of this query.
37
+ */
38
+ cellRef(row: number, column: number | string): RQLQueryCellRef;
39
+ }
40
+ //# sourceMappingURL=RQLQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RQLQuery.d.ts","sourceRoot":"","sources":["../../../src/api/query/RQLQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;;;;;;GASG;AACH,qBAAa,QAAQ;aAiBD,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;IAjBxC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC;;;;;;;;;;;;OAYG;gBAEe,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,cAAmB;IAK7C;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc;IAInC;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,eAAe;CAG/D"}
@@ -0,0 +1,48 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ import { RQLQueryCellRef, RQLQueryRowRef } from "./references.js";
3
+ /**
4
+ * Class representing a RQL query to be sent to the API.
5
+ *
6
+ * Queries are identified by a uuid and are independent from transactions.
7
+ *
8
+ * If a query has been used in a transaction, RQLQuery objects can easily retrieve
9
+ * a reference to the query for later resolving the values in a {@link TransactionResult}.
10
+ *
11
+ * @category Api
12
+ */
13
+ export class RQLQuery {
14
+ rql;
15
+ params;
16
+ queryUUID;
17
+ /**
18
+ * Class representing a RQL query to be sent to the API.
19
+ *
20
+ * Queries are identified by a uuid and are independent from transactions.
21
+ *
22
+ * If a query has been used in a transaction, RQLQuery objects can easily retrieve
23
+ * a reference to the query for later resolving the values in a {@link TransactionResult}.
24
+ *
25
+ * @param rql The rql query
26
+ * @param params The parameters for the rql query
27
+ *
28
+ * @category Api
29
+ */
30
+ constructor(rql, params = {}) {
31
+ this.rql = rql;
32
+ this.params = params;
33
+ this.queryUUID = uuidv4();
34
+ }
35
+ /**
36
+ * @returns A reference to a {@link ResultSetRow} in the result of this query.
37
+ */
38
+ rowRef(row) {
39
+ return new RQLQueryRowRef(this.queryUUID, row);
40
+ }
41
+ /**
42
+ * @returns A reference to a {@link ResultSetCell} in the result of this query.
43
+ */
44
+ cellRef(row, column) {
45
+ return new RQLQueryCellRef(this.queryUUID, row, column);
46
+ }
47
+ }
48
+ //# sourceMappingURL=RQLQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RQLQuery.js","sourceRoot":"","sources":["../../../src/api/query/RQLQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGlE;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAQ;IAiBD;IACA;IAjBF,SAAS,CAAS;IAElC;;;;;;;;;;;;OAYG;IACH,YACkB,GAAW,EACX,SAAyB,EAAE;QAD3B,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAqB;QAE3C,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAW,EAAE,MAAuB;QAC1C,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Class representing a reference to a {@link ResultSetRow} in the result of a {@link RQLQuery}.
3
+ *
4
+ * Use this to resolve a {@link ResultSetRow} of the referenced {@link RQLQuery}
5
+ * from a {@link TransactionResult}.
6
+ *
7
+ * @category Api
8
+ */
9
+ export declare class RQLQueryRowRef {
10
+ readonly queryUUID: string;
11
+ readonly row: number;
12
+ constructor(queryUUID: string, row: number);
13
+ /**
14
+ * Retrieve a reference to the given column in this row.
15
+ *
16
+ * @param c The column to get a reference for
17
+ * @returns A reference to the given column in the current row
18
+ *
19
+ * @category Api
20
+ */
21
+ column(c: number | string): RQLQueryCellRef;
22
+ }
23
+ /**
24
+ * Class representing a reference to a {@link ResultSetCell} in the result of a {@link RQLQuery}.
25
+ *
26
+ * Use this to resolve a {@link ResultSetCell} of the referenced {@link RQLQuery}
27
+ * from a {@link TransactionResult}.
28
+ *
29
+ * This reference can also be used in parameters of other {@link RQLQuery}.
30
+ * If both {@link RQLQuery} are used in the same {@link RQLQuery},
31
+ * then the resolved value from the first query will be used in the second.
32
+ *
33
+ * @category Api
34
+ */
35
+ export declare class RQLQueryCellRef {
36
+ readonly queryUUID: string;
37
+ readonly row: number;
38
+ readonly column: number | string;
39
+ constructor(queryUUID: string, row: number, column: number | string);
40
+ }
41
+ //# sourceMappingURL=references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../../src/api/query/references.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,cAAc;aACG,SAAS,EAAE,MAAM;aAAkB,GAAG,EAAE,MAAM;gBAA9C,SAAS,EAAE,MAAM,EAAkB,GAAG,EAAE,MAAM;IAE1E;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,eAAe;CAG5C;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe;aAER,SAAS,EAAE,MAAM;aACjB,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,MAAM,GAAG,MAAM;gBAFvB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GAAG,MAAM;CAE1C"}