@things-factory/survey 0.0.0-stage → 10.1.316

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/dist-client/index.d.ts +1 -0
  2. package/dist-client/index.js +2 -0
  3. package/dist-client/pages/my-surveys.d.ts +24 -0
  4. package/dist-client/pages/my-surveys.js +256 -0
  5. package/dist-client/pages/survey-editor.d.ts +62 -0
  6. package/dist-client/pages/survey-editor.js +668 -0
  7. package/dist-client/pages/survey-list.d.ts +15 -0
  8. package/dist-client/pages/survey-list.js +150 -0
  9. package/dist-client/pages/survey-trustee.d.ts +21 -0
  10. package/dist-client/pages/survey-trustee.js +170 -0
  11. package/dist-client/route.d.ts +1 -0
  12. package/dist-client/route.js +17 -0
  13. package/dist-client/utils/survey-api.d.ts +16 -0
  14. package/dist-client/utils/survey-api.js +46 -0
  15. package/dist-client/utils/survey-result.d.ts +4 -0
  16. package/dist-client/utils/survey-result.js +79 -0
  17. package/dist-client/utils/survey-secret.d.ts +40 -0
  18. package/dist-client/utils/survey-secret.js +154 -0
  19. package/dist-server/index.d.ts +2 -0
  20. package/dist-server/index.js +27 -0
  21. package/dist-server/role-tasks.d.ts +2 -0
  22. package/dist-server/role-tasks.js +16 -0
  23. package/dist-server/service/index.d.ts +16 -0
  24. package/dist-server/service/index.js +30 -0
  25. package/dist-server/service/refusal.d.ts +57 -0
  26. package/dist-server/service/refusal.js +66 -0
  27. package/dist-server/service/survey/ballot-route.d.ts +1 -0
  28. package/dist-server/service/survey/ballot-route.js +30 -0
  29. package/dist-server/service/survey/ballot-worker.d.ts +1 -0
  30. package/dist-server/service/survey/ballot-worker.js +19 -0
  31. package/dist-server/service/survey/index.d.ts +10 -0
  32. package/dist-server/service/survey/index.js +14 -0
  33. package/dist-server/service/survey/survey-answer.d.ts +23 -0
  34. package/dist-server/service/survey/survey-answer.js +99 -0
  35. package/dist-server/service/survey/survey-attributes.d.ts +16 -0
  36. package/dist-server/service/survey/survey-attributes.js +39 -0
  37. package/dist-server/service/survey/survey-ballot.d.ts +14 -0
  38. package/dist-server/service/survey/survey-ballot.js +61 -0
  39. package/dist-server/service/survey/survey-class-key.d.ts +20 -0
  40. package/dist-server/service/survey/survey-class-key.js +92 -0
  41. package/dist-server/service/survey/survey-question.d.ts +27 -0
  42. package/dist-server/service/survey/survey-question.js +113 -0
  43. package/dist-server/service/survey/survey-resolver.d.ts +37 -0
  44. package/dist-server/service/survey/survey-resolver.js +492 -0
  45. package/dist-server/service/survey/survey-respondent.d.ts +17 -0
  46. package/dist-server/service/survey/survey-respondent.js +81 -0
  47. package/dist-server/service/survey/survey-rules.d.ts +169 -0
  48. package/dist-server/service/survey/survey-rules.js +299 -0
  49. package/dist-server/service/survey/survey-secret.d.ts +133 -0
  50. package/dist-server/service/survey/survey-secret.js +347 -0
  51. package/dist-server/service/survey/survey-service.d.ts +83 -0
  52. package/dist-server/service/survey/survey-service.js +384 -0
  53. package/dist-server/service/survey/survey-trustee.d.ts +25 -0
  54. package/dist-server/service/survey/survey-trustee.js +119 -0
  55. package/dist-server/service/survey/survey-types.d.ts +91 -0
  56. package/dist-server/service/survey/survey-types.js +319 -0
  57. package/dist-server/service/survey/survey.d.ts +47 -0
  58. package/dist-server/service/survey/survey.js +214 -0
  59. package/dist-shared/ballot.d.ts +54 -0
  60. package/dist-shared/ballot.js +146 -0
  61. package/dist-shared/blind-rsa.d.ts +18 -0
  62. package/dist-shared/blind-rsa.js +127 -0
  63. package/dist-shared/elgamal.d.ts +20 -0
  64. package/dist-shared/elgamal.js +54 -0
  65. package/dist-shared/group.d.ts +22 -0
  66. package/dist-shared/group.js +112 -0
  67. package/dist-shared/proofs.d.ts +20 -0
  68. package/dist-shared/proofs.js +94 -0
  69. package/dist-shared/threshold.d.ts +39 -0
  70. package/dist-shared/threshold.js +98 -0
  71. package/dist-shared/verify.d.ts +13 -0
  72. package/dist-shared/verify.js +73 -0
  73. package/package.json +63 -4
  74. package/things-factory.config.js +15 -0
  75. package/translations/en.json +202 -0
  76. package/translations/es.json +202 -0
  77. package/translations/ja.json +202 -0
  78. package/translations/ko.json +202 -0
  79. package/translations/ms.json +202 -0
  80. package/translations/zh.json +202 -0
  81. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ export * from './utils/survey-api.js';
@@ -0,0 +1,2 @@
1
+ export * from './utils/survey-api.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,24 @@
1
+ import { PageView } from '@operato/shell';
2
+ import { type Row } from '../utils/survey-api.js';
3
+ declare const MySurveysPage_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
4
+ export declare class MySurveysPage extends MySurveysPage_base {
5
+ static styles: import("lit").CSSResult[];
6
+ surveys: Row[];
7
+ drafts: Record<string, Record<string, Row>>;
8
+ sealing: string;
9
+ checked: Record<string, boolean>;
10
+ get context(): {
11
+ title: string;
12
+ };
13
+ render(): import("lit-html").TemplateResult<1>;
14
+ private renderOne;
15
+ private renderForm;
16
+ private renderTaken;
17
+ private say;
18
+ resend(id: string): Promise<void>;
19
+ checkReceipt(id: string, receipt: string): Promise<void>;
20
+ pageUpdated(_changes: any, _lifecycle: any, before: any): Promise<void>;
21
+ load(): Promise<void>;
22
+ send(mine: Row): Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,256 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import gql from 'graphql-tag';
3
+ import { css, html, nothing } from 'lit';
4
+ import { customElement, state } from 'lit/decorators.js';
5
+ import { client } from '@operato/graphql';
6
+ import { i18next, localize } from '@operato/i18n';
7
+ import { PageView } from '@operato/shell';
8
+ import { ButtonStyles, FormFieldStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
9
+ import { notify } from '@operato/layout';
10
+ import { levelLabel, mutate, statusLabel, sure } from '../utils/survey-api.js';
11
+ import { BallotRefusal, castSecretBallot, pendingBallotOf, receiptOf, resendPending } from '../utils/survey-secret.js';
12
+ import { SurveyResultStyles, surveyResultView } from '../utils/survey-result.js';
13
+ /*
14
+ * **내 설문** - the surveys that ask me (operato-survey design §9): answer an open one - every question, once - and read a
15
+ * result once it is published to me.
16
+ */
17
+ let MySurveysPage = class MySurveysPage extends localize(i18next)(PageView) {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.surveys = [];
21
+ this.drafts = {};
22
+ this.sealing = '';
23
+ this.checked = {};
24
+ }
25
+ static { this.styles = [
26
+ WorkSurfacePageStyles,
27
+ ScrollbarStyles,
28
+ ButtonStyles,
29
+ FormFieldStyles,
30
+ SurveyResultStyles,
31
+ css `
32
+ main {
33
+ overflow-y: auto;
34
+ padding: 16px;
35
+ display: flex;
36
+ flex-direction: column;
37
+ gap: 16px;
38
+ max-width: 880px;
39
+ }
40
+ article {
41
+ border: 1px solid var(--md-sys-color-outline-variant);
42
+ border-radius: 10px;
43
+ padding: 16px;
44
+ display: flex;
45
+ flex-direction: column;
46
+ gap: 12px;
47
+ }
48
+ article h3 {
49
+ margin: 0;
50
+ }
51
+ .note {
52
+ color: var(--md-sys-color-on-surface-variant);
53
+ font-size: 13px;
54
+ margin: 0;
55
+ }
56
+ fieldset {
57
+ border: none;
58
+ padding: 0;
59
+ margin: 0;
60
+ display: flex;
61
+ flex-direction: column;
62
+ gap: 6px;
63
+ }
64
+ legend {
65
+ font-weight: 600;
66
+ margin-bottom: 4px;
67
+ }
68
+ .choices {
69
+ display: flex;
70
+ flex-wrap: wrap;
71
+ gap: 12px;
72
+ }
73
+ .shares {
74
+ display: grid;
75
+ grid-template-columns: minmax(80px, 40%) 120px;
76
+ gap: 6px;
77
+ align-items: center;
78
+ }
79
+ `
80
+ ]; }
81
+ get context() {
82
+ return { title: i18next.t('title.my-surveys') };
83
+ }
84
+ render() {
85
+ return html `<main>
86
+ ${this.surveys.map(one => this.renderOne(one))}
87
+ ${this.surveys.length ? nothing : html `<p class="note">${i18next.t('text.my-surveys-none')}</p>`}
88
+ </main>`;
89
+ }
90
+ renderOne(mine) {
91
+ const survey = mine.survey;
92
+ const open = survey.status === 'OPEN' && !mine.taken;
93
+ return html `<article>
94
+ <h3>${survey.name}</h3>
95
+ <p class="note">
96
+ ${levelLabel(survey.level)} · ${statusLabel(survey.status)}
97
+ ${survey.closesAt ? html ` · ${i18next.t('label.survey-closes-at')} ${new Date(survey.closesAt).toLocaleString()}` : nothing}
98
+ </p>
99
+ ${survey.description ? html `<p>${survey.description}</p>` : nothing}
100
+ ${survey.level === 'NAMED' && open ? html `<p class="note">${i18next.t('text.survey-named-notice')}</p>` : nothing}
101
+ ${survey.level === 'SECRET' && open ? html `<p class="note">${i18next.t('text.survey-secret-notice')}</p>` : nothing}
102
+ ${open ? this.renderForm(mine) : mine.taken ? this.renderTaken(mine) : nothing}
103
+ ${mine.published ? surveyResultView(mine.questions, mine.published) : nothing}
104
+ </article>`;
105
+ }
106
+ renderForm(mine) {
107
+ const id = mine.survey.id;
108
+ const draft = this.drafts[id] ?? {};
109
+ const set = (questionId, value) => (this.drafts = { ...this.drafts, [id]: { ...draft, [questionId]: value } });
110
+ return html `
111
+ ${mine.questions.map((question) => {
112
+ const value = draft[question.id] ?? {};
113
+ return html `<fieldset>
114
+ <legend>${question.seq}. ${question.prompt}</legend>
115
+ ${question.kind === 'SINGLE'
116
+ ? html `<div class="choices">
117
+ ${question.options.map((one) => html `<label><input type="radio" name=${`${id}-${question.id}`} .checked=${value.pick === one.key} @change=${() => set(question.id, { pick: one.key })} /> ${one.label}</label>`)}
118
+ </div>`
119
+ : question.kind === 'MULTI'
120
+ ? html `<p class="note">${i18next.t('text.survey-pick-up-to', { count: question.maxPicks })}</p>
121
+ <div class="choices">
122
+ ${question.options.map((one) => {
123
+ const picks = value.picks ?? [];
124
+ return html `<label
125
+ ><input
126
+ type="checkbox"
127
+ .checked=${picks.includes(one.key)}
128
+ ?disabled=${!picks.includes(one.key) && picks.length >= question.maxPicks}
129
+ @change=${(e) => set(question.id, { picks: e.target.checked ? [...picks, one.key] : picks.filter(key => key !== one.key) })}
130
+ />
131
+ ${one.label}</label
132
+ >`;
133
+ })}
134
+ </div>`
135
+ : question.kind === 'SCALE'
136
+ ? html `<div class="choices">
137
+ ${Array.from({ length: question.scaleMax - question.scaleMin + 1 }, (_, index) => question.scaleMin + index).map(score => html `<label><input type="radio" name=${`${id}-${question.id}`} .checked=${value.value === score} @change=${() => set(question.id, { value: score })} /> ${score}</label>`)}
138
+ </div>`
139
+ : html `<p class="note">${i18next.t('text.survey-allocate-total', { total: question.allocateTotal, sum: Object.values(value.shares ?? {}).reduce((t, n) => t + n, 0) })}</p>
140
+ <div class="shares">
141
+ ${question.options.map((one) => html `<span>${one.label}</span>
142
+ <input type="number" min="0" .value=${String(value.shares?.[one.key] ?? 0)} @change=${(e) => set(question.id, { shares: { ...(value.shares ?? {}), [one.key]: Number(e.target.value) } })} />`)}
143
+ </div>`}
144
+ </fieldset>`;
145
+ })}
146
+ <div>
147
+ <button raised ?disabled=${this.sealing === id} @click=${() => this.send(mine)}>${i18next.t('button.survey-submit')}</button>
148
+ ${this.sealing === id ? html `<span class="note">${i18next.t('text.survey-sealing')}</span>` : nothing}
149
+ </div>
150
+ `;
151
+ }
152
+ renderTaken(mine) {
153
+ const id = mine.survey.id;
154
+ if (mine.survey.level !== 'SECRET')
155
+ return html `<p class="note">${i18next.t('text.survey-answered')}</p>`;
156
+ const receipt = receiptOf(id);
157
+ const pending = pendingBallotOf(id);
158
+ return html `
159
+ ${receipt
160
+ ? html `<p class="note">${i18next.t('text.survey-receipt', { receipt: receipt.slice(0, 16) })}</p>
161
+ ${['DECRYPTING', 'COUNTED', 'PUBLISHED', 'CLOSED'].includes(mine.survey.status)
162
+ ? html `<div><button @click=${() => this.checkReceipt(id, receipt)}>${i18next.t('button.survey-check-receipt')}</button>
163
+ ${id in this.checked ? html `<span class="note">${i18next.t(this.checked[id] ? 'text.survey-receipt-listed' : 'text.survey-receipt-missing')}</span>` : nothing}</div>`
164
+ : nothing}`
165
+ : pending && mine.survey.status === 'OPEN'
166
+ ? html `<p class="note">${i18next.t('text.survey-ballot-pending')}</p>
167
+ <div><button raised @click=${() => this.resend(id)}>${i18next.t('button.survey-resend')}</button></div>`
168
+ : html `<p class="note">${i18next.t('text.survey-token-taken')}</p>`}
169
+ `;
170
+ }
171
+ say(error) {
172
+ const code = error instanceof BallotRefusal ? error.code : undefined;
173
+ notify({ level: 'error', message: code ? i18next.t(`error.${code}`) : error?.graphQLErrors?.[0]?.message ?? error?.message ?? i18next.t('text.error') });
174
+ }
175
+ async resend(id) {
176
+ try {
177
+ await resendPending(id);
178
+ await this.load();
179
+ }
180
+ catch (error) {
181
+ this.say(error);
182
+ }
183
+ }
184
+ async checkReceipt(id, receipt) {
185
+ const response = await client.query({ query: gql `query ($id: String!, $receipt: String!) { surveyReceiptListed(id: $id, receipt: $receipt) }`, variables: { id, receipt }, fetchPolicy: 'network-only' });
186
+ this.checked = { ...this.checked, [id]: !!response.data?.surveyReceiptListed };
187
+ }
188
+ async pageUpdated(_changes, _lifecycle, before) {
189
+ if (this.active && !before?.active)
190
+ await this.load();
191
+ }
192
+ async load() {
193
+ const response = await client.query({
194
+ query: gql `
195
+ query {
196
+ mySurveys {
197
+ survey { id name description level status closesAt }
198
+ taken
199
+ questions { id seq kind prompt options maxPicks scaleMin scaleMax allocateTotal }
200
+ published
201
+ }
202
+ }
203
+ `,
204
+ fetchPolicy: 'network-only'
205
+ });
206
+ this.surveys = response.data?.mySurveys ?? [];
207
+ }
208
+ async send(mine) {
209
+ const draft = this.drafts[mine.survey.id] ?? {};
210
+ const answers = mine.questions.filter((one) => draft[one.id]).map((one) => ({ questionId: one.id, value: draft[one.id] }));
211
+ if (!(await sure(i18next.t('text.survey-confirm-submit'), i18next.t('button.survey-submit'))))
212
+ return;
213
+ if (mine.survey.level === 'SECRET') {
214
+ if (answers.length !== mine.questions.length)
215
+ return notify({ level: 'error', message: i18next.t('text.survey-answer-every-question') });
216
+ this.sealing = mine.survey.id;
217
+ /* let the page say it is sealing before the arithmetic holds the thread */
218
+ await new Promise(resolve => setTimeout(resolve, 30));
219
+ try {
220
+ await castSecretBallot(mine.survey.id, mine.questions, Object.fromEntries(answers.map((one) => [one.questionId, one.value])));
221
+ notify({ level: 'info', message: i18next.t('text.survey-ballot-received') });
222
+ }
223
+ catch (error) {
224
+ this.say(error);
225
+ }
226
+ finally {
227
+ this.sealing = '';
228
+ await this.load();
229
+ }
230
+ return;
231
+ }
232
+ if (await mutate(gql `mutation ($id: String!, $answers: [SurveyAnswerInput!]!) { answerSurvey(id: $id, answers: $answers) }`, { id: mine.survey.id, answers }))
233
+ await this.load();
234
+ }
235
+ };
236
+ __decorate([
237
+ state(),
238
+ __metadata("design:type", Array)
239
+ ], MySurveysPage.prototype, "surveys", void 0);
240
+ __decorate([
241
+ state(),
242
+ __metadata("design:type", Object)
243
+ ], MySurveysPage.prototype, "drafts", void 0);
244
+ __decorate([
245
+ state(),
246
+ __metadata("design:type", Object)
247
+ ], MySurveysPage.prototype, "sealing", void 0);
248
+ __decorate([
249
+ state(),
250
+ __metadata("design:type", Object)
251
+ ], MySurveysPage.prototype, "checked", void 0);
252
+ MySurveysPage = __decorate([
253
+ customElement('my-surveys')
254
+ ], MySurveysPage);
255
+ export { MySurveysPage };
256
+ //# sourceMappingURL=my-surveys.js.map
@@ -0,0 +1,62 @@
1
+ import '@operato/input/ox-select.js';
2
+ import '@operato/popup/ox-popup-list.js';
3
+ import { PageView } from '@operato/shell';
4
+ import { type Row } from '../utils/survey-api.js';
5
+ type Question = {
6
+ kind: string;
7
+ prompt: string;
8
+ options: {
9
+ key: string;
10
+ label: string;
11
+ }[];
12
+ maxPicks?: number;
13
+ scaleMin?: number;
14
+ scaleMax?: number;
15
+ allocateTotal?: number;
16
+ };
17
+ declare const SurveyEditorPage_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
18
+ export declare class SurveyEditorPage extends SurveyEditorPage_base {
19
+ static styles: import("lit").CSSResult[];
20
+ surveyId?: string;
21
+ survey: Row;
22
+ questions: Question[];
23
+ detail?: Row;
24
+ sheets: Row[];
25
+ choices?: Row;
26
+ weightAttributes: Row[];
27
+ preview?: Record<string, number>;
28
+ bulletin?: Row;
29
+ check?: Row;
30
+ rounds: Row[];
31
+ previous: Row[];
32
+ get context(): {
33
+ title: string;
34
+ };
35
+ private get editable();
36
+ render(): import("lit-html").TemplateResult<1>;
37
+ private renderDraft;
38
+ private get classes();
39
+ private setClasses;
40
+ private renderWeighting;
41
+ private renderClass;
42
+ private renderRounds;
43
+ private renderTrustees;
44
+ private renderQuestion;
45
+ private renderPast;
46
+ private answerText;
47
+ private choice;
48
+ private chip;
49
+ private targetChoices;
50
+ private targetName;
51
+ private personName;
52
+ private addTarget;
53
+ private dropTarget;
54
+ private dropExcluded;
55
+ pageUpdated(changes: any, lifecycle: any): Promise<void>;
56
+ load(): Promise<void>;
57
+ save(): Promise<void>;
58
+ loadPreview(): Promise<void>;
59
+ checkCount(): Promise<void>;
60
+ carry(): Promise<void>;
61
+ }
62
+ export {};