@credo-ts/question-answer 0.5.0-alpha.101

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 (60) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +65 -0
  3. package/build/QuestionAnswerApi.d.ts +53 -0
  4. package/build/QuestionAnswerApi.js +106 -0
  5. package/build/QuestionAnswerApi.js.map +1 -0
  6. package/build/QuestionAnswerEvents.d.ts +13 -0
  7. package/build/QuestionAnswerEvents.js +8 -0
  8. package/build/QuestionAnswerEvents.js.map +1 -0
  9. package/build/QuestionAnswerModule.d.ts +9 -0
  10. package/build/QuestionAnswerModule.js +31 -0
  11. package/build/QuestionAnswerModule.js.map +1 -0
  12. package/build/QuestionAnswerRole.d.ts +4 -0
  13. package/build/QuestionAnswerRole.js +9 -0
  14. package/build/QuestionAnswerRole.js.map +1 -0
  15. package/build/handlers/AnswerMessageHandler.d.ts +9 -0
  16. package/build/handlers/AnswerMessageHandler.js +15 -0
  17. package/build/handlers/AnswerMessageHandler.js.map +1 -0
  18. package/build/handlers/QuestionMessageHandler.d.ts +9 -0
  19. package/build/handlers/QuestionMessageHandler.js +15 -0
  20. package/build/handlers/QuestionMessageHandler.js.map +1 -0
  21. package/build/handlers/index.d.ts +2 -0
  22. package/build/handlers/index.js +19 -0
  23. package/build/handlers/index.js.map +1 -0
  24. package/build/index.d.ts +8 -0
  25. package/build/index.js +25 -0
  26. package/build/index.js.map +1 -0
  27. package/build/messages/AnswerMessage.d.ts +15 -0
  28. package/build/messages/AnswerMessage.js +42 -0
  29. package/build/messages/AnswerMessage.js.map +1 -0
  30. package/build/messages/QuestionMessage.d.ts +23 -0
  31. package/build/messages/QuestionMessage.js +70 -0
  32. package/build/messages/QuestionMessage.js.map +1 -0
  33. package/build/messages/index.d.ts +2 -0
  34. package/build/messages/index.js +19 -0
  35. package/build/messages/index.js.map +1 -0
  36. package/build/models/QuestionAnswerState.d.ts +11 -0
  37. package/build/models/QuestionAnswerState.js +16 -0
  38. package/build/models/QuestionAnswerState.js.map +1 -0
  39. package/build/models/ValidResponse.d.ts +4 -0
  40. package/build/models/ValidResponse.js +12 -0
  41. package/build/models/ValidResponse.js.map +1 -0
  42. package/build/models/index.d.ts +2 -0
  43. package/build/models/index.js +19 -0
  44. package/build/models/index.js.map +1 -0
  45. package/build/repository/QuestionAnswerRecord.d.ts +48 -0
  46. package/build/repository/QuestionAnswerRecord.js +44 -0
  47. package/build/repository/QuestionAnswerRecord.js.map +1 -0
  48. package/build/repository/QuestionAnswerRepository.d.ts +5 -0
  49. package/build/repository/QuestionAnswerRepository.js +29 -0
  50. package/build/repository/QuestionAnswerRepository.js.map +1 -0
  51. package/build/repository/index.d.ts +2 -0
  52. package/build/repository/index.js +19 -0
  53. package/build/repository/index.js.map +1 -0
  54. package/build/services/QuestionAnswerService.d.ts +107 -0
  55. package/build/services/QuestionAnswerService.js +234 -0
  56. package/build/services/QuestionAnswerService.js.map +1 -0
  57. package/build/services/index.d.ts +1 -0
  58. package/build/services/index.js +18 -0
  59. package/build/services/index.js.map +1 -0
  60. package/package.json +39 -0
package/build/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./messages"), exports);
18
+ __exportStar(require("./models"), exports);
19
+ __exportStar(require("./services"), exports);
20
+ __exportStar(require("./repository"), exports);
21
+ __exportStar(require("./QuestionAnswerEvents"), exports);
22
+ __exportStar(require("./QuestionAnswerApi"), exports);
23
+ __exportStar(require("./QuestionAnswerRole"), exports);
24
+ __exportStar(require("./QuestionAnswerModule"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,2CAAwB;AACxB,6CAA0B;AAC1B,+CAA4B;AAC5B,yDAAsC;AACtC,sDAAmC;AACnC,uDAAoC;AACpC,yDAAsC"}
@@ -0,0 +1,15 @@
1
+ import { AgentMessage } from '@credo-ts/core';
2
+ export declare class AnswerMessage extends AgentMessage {
3
+ /**
4
+ * Create new AnswerMessage instance.
5
+ * @param options
6
+ */
7
+ constructor(options: {
8
+ id?: string;
9
+ response: string;
10
+ threadId: string;
11
+ });
12
+ readonly type: string;
13
+ static readonly type: import("@credo-ts/core/build/utils/messageType").ParsedMessageType;
14
+ response: string;
15
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AnswerMessage = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ const class_transformer_1 = require("class-transformer");
15
+ const class_validator_1 = require("class-validator");
16
+ class AnswerMessage extends core_1.AgentMessage {
17
+ /**
18
+ * Create new AnswerMessage instance.
19
+ * @param options
20
+ */
21
+ constructor(options) {
22
+ super();
23
+ this.type = AnswerMessage.type.messageTypeUri;
24
+ if (options) {
25
+ this.id = options.id || this.generateId();
26
+ this.setThread({ threadId: options.threadId });
27
+ this.response = options.response;
28
+ }
29
+ }
30
+ }
31
+ AnswerMessage.type = (0, core_1.parseMessageType)('https://didcomm.org/questionanswer/1.0/answer');
32
+ __decorate([
33
+ (0, core_1.IsValidMessageType)(AnswerMessage.type),
34
+ __metadata("design:type", Object)
35
+ ], AnswerMessage.prototype, "type", void 0);
36
+ __decorate([
37
+ (0, class_transformer_1.Expose)({ name: 'response' }),
38
+ (0, class_validator_1.IsString)(),
39
+ __metadata("design:type", String)
40
+ ], AnswerMessage.prototype, "response", void 0);
41
+ exports.AnswerMessage = AnswerMessage;
42
+ //# sourceMappingURL=AnswerMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnswerMessage.js","sourceRoot":"","sources":["../../src/messages/AnswerMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmF;AACnF,yDAA0C;AAC1C,qDAA0C;AAE1C,MAAa,aAAc,SAAQ,mBAAY;IAC7C;;;OAGG;IACH,YAAmB,OAA4D;QAC7E,KAAK,EAAE,CAAA;QAUO,SAAI,GAAG,aAAa,CAAC,IAAI,CAAC,cAAc,CAAA;QARtD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;YACzC,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SACjC;IACH,CAAC;;AAIsB,kBAAI,GAAG,IAAA,uBAAgB,EAAC,+CAA+C,CAAC,CAAA;AAF/F;IAAC,IAAA,yBAAkB,EAAC,aAAa,CAAC,IAAI,CAAC;;2CACiB;AAGxD;IAAC,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC5B,IAAA,0BAAQ,GAAE;;+CACa;AArB1B,sCAsBC"}
@@ -0,0 +1,23 @@
1
+ import { AgentMessage } from '@credo-ts/core';
2
+ import { ValidResponse } from '../models';
3
+ export declare class QuestionMessage extends AgentMessage {
4
+ /**
5
+ * Create new QuestionMessage instance.
6
+ * @param options
7
+ */
8
+ constructor(options: {
9
+ questionText: string;
10
+ questionDetail?: string;
11
+ validResponses: ValidResponse[];
12
+ signatureRequired?: boolean;
13
+ id?: string;
14
+ nonce?: string;
15
+ });
16
+ readonly type: string;
17
+ static readonly type: import("@credo-ts/core/build/utils/messageType").ParsedMessageType;
18
+ nonce?: string;
19
+ signatureRequired?: boolean;
20
+ validResponses: ValidResponse[];
21
+ questionText: string;
22
+ questionDetail?: string;
23
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.QuestionMessage = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ const class_transformer_1 = require("class-transformer");
15
+ const class_validator_1 = require("class-validator");
16
+ const models_1 = require("../models");
17
+ class QuestionMessage extends core_1.AgentMessage {
18
+ /**
19
+ * Create new QuestionMessage instance.
20
+ * @param options
21
+ */
22
+ constructor(options) {
23
+ super();
24
+ this.type = QuestionMessage.type.messageTypeUri;
25
+ if (options) {
26
+ this.id = options.id || this.generateId();
27
+ this.nonce = options.nonce;
28
+ this.questionText = options.questionText;
29
+ this.questionDetail = options.questionDetail;
30
+ this.signatureRequired = options.signatureRequired;
31
+ this.validResponses = options.validResponses;
32
+ }
33
+ }
34
+ }
35
+ QuestionMessage.type = (0, core_1.parseMessageType)('https://didcomm.org/questionanswer/1.0/question');
36
+ __decorate([
37
+ (0, core_1.IsValidMessageType)(QuestionMessage.type),
38
+ __metadata("design:type", Object)
39
+ ], QuestionMessage.prototype, "type", void 0);
40
+ __decorate([
41
+ (0, class_validator_1.IsOptional)(),
42
+ (0, class_validator_1.IsString)(),
43
+ __metadata("design:type", String)
44
+ ], QuestionMessage.prototype, "nonce", void 0);
45
+ __decorate([
46
+ (0, class_validator_1.IsOptional)(),
47
+ (0, class_validator_1.IsBoolean)(),
48
+ (0, class_transformer_1.Expose)({ name: 'signature_required' }),
49
+ __metadata("design:type", Boolean)
50
+ ], QuestionMessage.prototype, "signatureRequired", void 0);
51
+ __decorate([
52
+ (0, class_transformer_1.Expose)({ name: 'valid_responses' }),
53
+ (0, class_transformer_1.Type)(() => models_1.ValidResponse),
54
+ (0, class_validator_1.ValidateNested)({ each: true }),
55
+ (0, class_validator_1.IsInstance)(models_1.ValidResponse, { each: true }),
56
+ __metadata("design:type", Array)
57
+ ], QuestionMessage.prototype, "validResponses", void 0);
58
+ __decorate([
59
+ (0, class_transformer_1.Expose)({ name: 'question_text' }),
60
+ (0, class_validator_1.IsString)(),
61
+ __metadata("design:type", String)
62
+ ], QuestionMessage.prototype, "questionText", void 0);
63
+ __decorate([
64
+ (0, class_validator_1.IsOptional)(),
65
+ (0, class_transformer_1.Expose)({ name: 'question_detail' }),
66
+ (0, class_validator_1.IsString)(),
67
+ __metadata("design:type", String)
68
+ ], QuestionMessage.prototype, "questionDetail", void 0);
69
+ exports.QuestionMessage = QuestionMessage;
70
+ //# sourceMappingURL=QuestionMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionMessage.js","sourceRoot":"","sources":["../../src/messages/QuestionMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmF;AACnF,yDAAgD;AAChD,qDAA6F;AAE7F,sCAAyC;AAEzC,MAAa,eAAgB,SAAQ,mBAAY;IAC/C;;;OAGG;IACH,YAAmB,OAOlB;QACC,KAAK,EAAE,CAAA;QAaO,SAAI,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,CAAA;QAXxD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;YACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;YAC1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;YACxC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;YAC5C,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;YAClD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;SAC7C;IACH,CAAC;;AAIsB,oBAAI,GAAG,IAAA,uBAAgB,EAAC,iDAAiD,CAAC,CAAA;AAFjG;IAAC,IAAA,yBAAkB,EAAC,eAAe,CAAC,IAAI,CAAC;;6CACiB;AAG1D;IAAC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;8CACU;AAErB;IAAC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;IACX,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;;0DACL;AAElC;IAAC,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IACnC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,sBAAa,CAAC;IACzB,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,4BAAU,EAAC,sBAAa,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;uDACH;AAEvC;IAAC,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IACjC,IAAA,0BAAQ,GAAE;;qDACiB;AAE5B;IAAC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IACnC,IAAA,0BAAQ,GAAE;;uDACmB;AAnDhC,0CAoDC"}
@@ -0,0 +1,2 @@
1
+ export * from './QuestionMessage';
2
+ export * from './AnswerMessage';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./QuestionMessage"), exports);
18
+ __exportStar(require("./AnswerMessage"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,kDAA+B"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * QuestionAnswer states inferred from RFC 0113.
3
+ *
4
+ * @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0113-question-answer/README.md
5
+ */
6
+ export declare enum QuestionAnswerState {
7
+ QuestionSent = "question-sent",
8
+ QuestionReceived = "question-received",
9
+ AnswerReceived = "answer-received",
10
+ AnswerSent = "answer-sent"
11
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionAnswerState = void 0;
4
+ /**
5
+ * QuestionAnswer states inferred from RFC 0113.
6
+ *
7
+ * @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0113-question-answer/README.md
8
+ */
9
+ var QuestionAnswerState;
10
+ (function (QuestionAnswerState) {
11
+ QuestionAnswerState["QuestionSent"] = "question-sent";
12
+ QuestionAnswerState["QuestionReceived"] = "question-received";
13
+ QuestionAnswerState["AnswerReceived"] = "answer-received";
14
+ QuestionAnswerState["AnswerSent"] = "answer-sent";
15
+ })(QuestionAnswerState = exports.QuestionAnswerState || (exports.QuestionAnswerState = {}));
16
+ //# sourceMappingURL=QuestionAnswerState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerState.js","sourceRoot":"","sources":["../../src/models/QuestionAnswerState.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,qDAA8B,CAAA;IAC9B,6DAAsC,CAAA;IACtC,yDAAkC,CAAA;IAClC,iDAA0B,CAAA;AAC5B,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B"}
@@ -0,0 +1,4 @@
1
+ export declare class ValidResponse {
2
+ constructor(options: ValidResponse);
3
+ text: string;
4
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidResponse = void 0;
4
+ class ValidResponse {
5
+ constructor(options) {
6
+ if (options) {
7
+ this.text = options.text;
8
+ }
9
+ }
10
+ }
11
+ exports.ValidResponse = ValidResponse;
12
+ //# sourceMappingURL=ValidResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidResponse.js","sourceRoot":"","sources":["../../src/models/ValidResponse.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAa;IACxB,YAAmB,OAAsB;QACvC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;SACzB;IACH,CAAC;CAGF;AARD,sCAQC"}
@@ -0,0 +1,2 @@
1
+ export * from './QuestionAnswerState';
2
+ export * from './ValidResponse';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./QuestionAnswerState"), exports);
18
+ __exportStar(require("./ValidResponse"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC;AACrC,kDAA+B"}
@@ -0,0 +1,48 @@
1
+ import type { QuestionAnswerRole } from '../QuestionAnswerRole';
2
+ import type { QuestionAnswerState, ValidResponse } from '../models';
3
+ import type { RecordTags, TagsBase } from '@credo-ts/core';
4
+ import { BaseRecord } from '@credo-ts/core';
5
+ export type CustomQuestionAnswerTags = TagsBase;
6
+ export type DefaultQuestionAnswerTags = {
7
+ connectionId: string;
8
+ role: QuestionAnswerRole;
9
+ state: QuestionAnswerState;
10
+ threadId: string;
11
+ };
12
+ export type QuestionAnswerTags = RecordTags<QuestionAnswerRecord>;
13
+ export interface QuestionAnswerStorageProps {
14
+ id?: string;
15
+ createdAt?: Date;
16
+ connectionId: string;
17
+ role: QuestionAnswerRole;
18
+ signatureRequired: boolean;
19
+ state: QuestionAnswerState;
20
+ tags?: CustomQuestionAnswerTags;
21
+ threadId: string;
22
+ questionText: string;
23
+ questionDetail?: string;
24
+ validResponses: ValidResponse[];
25
+ response?: string;
26
+ }
27
+ export declare class QuestionAnswerRecord extends BaseRecord<DefaultQuestionAnswerTags, CustomQuestionAnswerTags> {
28
+ questionText: string;
29
+ questionDetail?: string;
30
+ validResponses: ValidResponse[];
31
+ connectionId: string;
32
+ role: QuestionAnswerRole;
33
+ signatureRequired: boolean;
34
+ state: QuestionAnswerState;
35
+ threadId: string;
36
+ response?: string;
37
+ static readonly type = "QuestionAnswerRecord";
38
+ readonly type = "QuestionAnswerRecord";
39
+ constructor(props: QuestionAnswerStorageProps);
40
+ getTags(): {
41
+ connectionId: string;
42
+ role: QuestionAnswerRole;
43
+ state: QuestionAnswerState;
44
+ threadId: string;
45
+ };
46
+ assertRole(expectedRole: QuestionAnswerRole): void;
47
+ assertState(expectedStates: QuestionAnswerState | QuestionAnswerState[]): void;
48
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionAnswerRecord = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ class QuestionAnswerRecord extends core_1.BaseRecord {
6
+ constructor(props) {
7
+ var _a, _b, _c;
8
+ super();
9
+ this.type = QuestionAnswerRecord.type;
10
+ if (props) {
11
+ this.id = (_a = props.id) !== null && _a !== void 0 ? _a : core_1.utils.uuid();
12
+ this.createdAt = (_b = props.createdAt) !== null && _b !== void 0 ? _b : new Date();
13
+ this.questionText = props.questionText;
14
+ this.questionDetail = props.questionDetail;
15
+ this.validResponses = props.validResponses;
16
+ this.connectionId = props.connectionId;
17
+ this._tags = (_c = props.tags) !== null && _c !== void 0 ? _c : {};
18
+ this.role = props.role;
19
+ this.signatureRequired = props.signatureRequired;
20
+ this.state = props.state;
21
+ this.threadId = props.threadId;
22
+ this.response = props.response;
23
+ }
24
+ }
25
+ getTags() {
26
+ return Object.assign(Object.assign({}, this._tags), { connectionId: this.connectionId, role: this.role, state: this.state, threadId: this.threadId });
27
+ }
28
+ assertRole(expectedRole) {
29
+ if (this.role !== expectedRole) {
30
+ throw new core_1.AriesFrameworkError(`Invalid question answer record role ${this.role}, expected is ${expectedRole}.`);
31
+ }
32
+ }
33
+ assertState(expectedStates) {
34
+ if (!Array.isArray(expectedStates)) {
35
+ expectedStates = [expectedStates];
36
+ }
37
+ if (!expectedStates.includes(this.state)) {
38
+ throw new core_1.AriesFrameworkError(`Question answer record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(', ')}.`);
39
+ }
40
+ }
41
+ }
42
+ exports.QuestionAnswerRecord = QuestionAnswerRecord;
43
+ QuestionAnswerRecord.type = 'QuestionAnswerRecord';
44
+ //# sourceMappingURL=QuestionAnswerRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRecord.js","sourceRoot":"","sources":["../../src/repository/QuestionAnswerRecord.ts"],"names":[],"mappings":";;;AAIA,yCAAuE;AA6BvE,MAAa,oBAAqB,SAAQ,iBAA+D;IAcvG,YAAmB,KAAiC;;QAClD,KAAK,EAAE,CAAA;QAHO,SAAI,GAAG,oBAAoB,CAAC,IAAI,CAAA;QAK9C,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,YAAK,CAAC,IAAI,EAAE,CAAA;YAClC,IAAI,CAAC,SAAS,GAAG,MAAA,KAAK,CAAC,SAAS,mCAAI,IAAI,IAAI,EAAE,CAAA;YAC9C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAA;YACtC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;YAC1C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;YAC1C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAA;YACtC,IAAI,CAAC,KAAK,GAAG,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAA;YAC7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;YACtB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAA;YAChD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;YAC9B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;SAC/B;IACH,CAAC;IAEM,OAAO;QACZ,uCACK,IAAI,CAAC,KAAK,KACb,YAAY,EAAE,IAAI,CAAC,YAAY,EAC/B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ,IACxB;IACH,CAAC;IAEM,UAAU,CAAC,YAAgC;QAChD,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE;YAC9B,MAAM,IAAI,0BAAmB,CAAC,uCAAuC,IAAI,CAAC,IAAI,iBAAiB,YAAY,GAAG,CAAC,CAAA;SAChH;IACH,CAAC;IAEM,WAAW,CAAC,cAA2D;QAC5E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;YAClC,cAAc,GAAG,CAAC,cAAc,CAAC,CAAA;SAClC;QAED,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACxC,MAAM,IAAI,0BAAmB,CAC3B,8CAA8C,IAAI,CAAC,KAAK,uBAAuB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC5G,CAAA;SACF;IACH,CAAC;;AA3DH,oDA4DC;AAjDwB,yBAAI,GAAG,sBAAsB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { EventEmitter, Repository, StorageService } from '@credo-ts/core';
2
+ import { QuestionAnswerRecord } from './QuestionAnswerRecord';
3
+ export declare class QuestionAnswerRepository extends Repository<QuestionAnswerRecord> {
4
+ constructor(storageService: StorageService<QuestionAnswerRecord>, eventEmitter: EventEmitter);
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.QuestionAnswerRepository = void 0;
16
+ const core_1 = require("@credo-ts/core");
17
+ const QuestionAnswerRecord_1 = require("./QuestionAnswerRecord");
18
+ let QuestionAnswerRepository = class QuestionAnswerRepository extends core_1.Repository {
19
+ constructor(storageService, eventEmitter) {
20
+ super(QuestionAnswerRecord_1.QuestionAnswerRecord, storageService, eventEmitter);
21
+ }
22
+ };
23
+ QuestionAnswerRepository = __decorate([
24
+ (0, core_1.injectable)(),
25
+ __param(0, (0, core_1.inject)(core_1.InjectionSymbols.StorageService)),
26
+ __metadata("design:paramtypes", [Object, core_1.EventEmitter])
27
+ ], QuestionAnswerRepository);
28
+ exports.QuestionAnswerRepository = QuestionAnswerRepository;
29
+ //# sourceMappingURL=QuestionAnswerRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRepository.js","sourceRoot":"","sources":["../../src/repository/QuestionAnswerRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAA+G;AAE/G,iEAA6D;AAGtD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,iBAAgC;IAC5E,YAC2C,cAAoD,EAC7F,YAA0B;QAE1B,KAAK,CAAC,2CAAoB,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IAC3D,CAAC;CACF,CAAA;AAPY,wBAAwB;IADpC,IAAA,iBAAU,GAAE;IAGR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,cAAc,CAAC,CAAA;6CAC1B,mBAAY;GAHjB,wBAAwB,CAOpC;AAPY,4DAAwB"}
@@ -0,0 +1,2 @@
1
+ export * from './QuestionAnswerRecord';
2
+ export * from './QuestionAnswerRepository';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./QuestionAnswerRecord"), exports);
18
+ __exportStar(require("./QuestionAnswerRepository"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,6DAA0C"}
@@ -0,0 +1,107 @@
1
+ import type { ValidResponse } from '../models';
2
+ import type { AgentContext, InboundMessageContext, Query } from '@credo-ts/core';
3
+ import { EventEmitter, Logger } from '@credo-ts/core';
4
+ import { AnswerMessage, QuestionMessage } from '../messages';
5
+ import { QuestionAnswerRepository, QuestionAnswerRecord } from '../repository';
6
+ export declare class QuestionAnswerService {
7
+ private questionAnswerRepository;
8
+ private eventEmitter;
9
+ private logger;
10
+ constructor(questionAnswerRepository: QuestionAnswerRepository, eventEmitter: EventEmitter, logger: Logger);
11
+ /**
12
+ * Create a question message and a new QuestionAnswer record for the questioner role
13
+ *
14
+ * @param question text for question message
15
+ * @param details optional details for question message
16
+ * @param connectionId connection for QuestionAnswer record
17
+ * @param validResponses array of valid responses for question
18
+ * @returns question message and QuestionAnswer record
19
+ */
20
+ createQuestion(agentContext: AgentContext, connectionId: string, config: {
21
+ question: string;
22
+ validResponses: ValidResponse[];
23
+ detail?: string;
24
+ }): Promise<{
25
+ questionMessage: QuestionMessage;
26
+ questionAnswerRecord: QuestionAnswerRecord;
27
+ }>;
28
+ /**
29
+ * receive question message and create record for responder role
30
+ *
31
+ * @param messageContext the message context containing a question message
32
+ * @returns QuestionAnswer record
33
+ */
34
+ processReceiveQuestion(messageContext: InboundMessageContext<QuestionMessage>): Promise<QuestionAnswerRecord>;
35
+ /**
36
+ * create answer message, check that response is valid
37
+ *
38
+ * @param questionAnswerRecord record containing question and valid responses
39
+ * @param response response used in answer message
40
+ * @returns answer message and QuestionAnswer record
41
+ */
42
+ createAnswer(agentContext: AgentContext, questionAnswerRecord: QuestionAnswerRecord, response: string): Promise<{
43
+ answerMessage: AnswerMessage;
44
+ questionAnswerRecord: QuestionAnswerRecord;
45
+ }>;
46
+ /**
47
+ * receive answer as questioner
48
+ *
49
+ * @param messageContext the message context containing an answer message message
50
+ * @returns QuestionAnswer record
51
+ */
52
+ receiveAnswer(messageContext: InboundMessageContext<AnswerMessage>): Promise<QuestionAnswerRecord>;
53
+ /**
54
+ * Update the record to a new state and emit an state changed event. Also updates the record
55
+ * in storage.
56
+ *
57
+ * @param questionAnswerRecord The question answer record to update the state for
58
+ * @param newState The state to update to
59
+ *
60
+ */
61
+ private updateState;
62
+ private createRecord;
63
+ /**
64
+ * Retrieve a question answer record by connection id and thread id
65
+ *
66
+ * @param connectionId The connection id
67
+ * @param threadId The thread id
68
+ * @throws {RecordNotFoundError} If no record is found
69
+ * @throws {RecordDuplicateError} If multiple records are found
70
+ * @returns The question answer record
71
+ */
72
+ getByThreadAndConnectionId(agentContext: AgentContext, connectionId: string, threadId: string): Promise<QuestionAnswerRecord>;
73
+ /**
74
+ * Retrieve a question answer record by thread id
75
+ *
76
+ * @param connectionId The connection id
77
+ * @param threadId The thread id
78
+ * @returns The question answer record or null if not found
79
+ */
80
+ findByThreadAndConnectionId(agentContext: AgentContext, connectionId: string, threadId: string): Promise<QuestionAnswerRecord | null>;
81
+ /**
82
+ * Retrieve a question answer record by id
83
+ *
84
+ * @param questionAnswerId The questionAnswer record id
85
+ * @throws {RecordNotFoundError} If no record is found
86
+ * @return The question answer record
87
+ *
88
+ */
89
+ getById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord>;
90
+ /**
91
+ * Retrieve a question answer record by id
92
+ *
93
+ * @param questionAnswerId The questionAnswer record id
94
+ * @return The question answer record or null if not found
95
+ *
96
+ */
97
+ findById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord | null>;
98
+ /**
99
+ * Retrieve a question answer record by id
100
+ *
101
+ * @param questionAnswerId The questionAnswer record id
102
+ * @return The question answer record or null if not found
103
+ *
104
+ */
105
+ getAll(agentContext: AgentContext): Promise<QuestionAnswerRecord[]>;
106
+ findAllByQuery(agentContext: AgentContext, query: Query<QuestionAnswerRecord>): Promise<QuestionAnswerRecord[]>;
107
+ }