@things-factory/saas 0.0.0-stage → 10.1.234

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 (83) hide show
  1. package/README.md +19 -2
  2. package/dist-client/bootstrap.d.ts +1 -0
  3. package/dist-client/bootstrap.js +5 -0
  4. package/dist-client/bootstrap.js.map +1 -0
  5. package/dist-client/components/saas-bill-editor.d.ts +59 -0
  6. package/dist-client/components/saas-bill-editor.js +211 -0
  7. package/dist-client/components/saas-bill-editor.js.map +1 -0
  8. package/dist-client/entity360/saas-account-360.d.ts +12 -0
  9. package/dist-client/entity360/saas-account-360.js +231 -0
  10. package/dist-client/entity360/saas-account-360.js.map +1 -0
  11. package/dist-client/index.d.ts +3 -0
  12. package/dist-client/index.js +4 -0
  13. package/dist-client/index.js.map +1 -0
  14. package/dist-client/pages/saas-account-list.d.ts +57 -0
  15. package/dist-client/pages/saas-account-list.js +175 -0
  16. package/dist-client/pages/saas-account-list.js.map +1 -0
  17. package/dist-client/pages/saas-account-page.d.ts +54 -0
  18. package/dist-client/pages/saas-account-page.js +352 -0
  19. package/dist-client/pages/saas-account-page.js.map +1 -0
  20. package/dist-client/pages/saas-cost-trend.d.ts +23 -0
  21. package/dist-client/pages/saas-cost-trend.js +219 -0
  22. package/dist-client/pages/saas-cost-trend.js.map +1 -0
  23. package/dist-client/route.d.ts +1 -0
  24. package/dist-client/route.js +16 -0
  25. package/dist-client/route.js.map +1 -0
  26. package/dist-client/tsconfig.tsbuildinfo +1 -0
  27. package/dist-client/words.d.ts +47 -0
  28. package/dist-client/words.js +39 -0
  29. package/dist-client/words.js.map +1 -0
  30. package/dist-server/index.d.ts +1 -0
  31. package/dist-server/index.js +9 -0
  32. package/dist-server/index.js.map +1 -0
  33. package/dist-server/role-tasks.d.ts +2 -0
  34. package/dist-server/role-tasks.js +16 -0
  35. package/dist-server/role-tasks.js.map +1 -0
  36. package/dist-server/service/checks.d.ts +32 -0
  37. package/dist-server/service/checks.js +83 -0
  38. package/dist-server/service/checks.js.map +1 -0
  39. package/dist-server/service/index.d.ts +20 -0
  40. package/dist-server/service/index.js +38 -0
  41. package/dist-server/service/index.js.map +1 -0
  42. package/dist-server/service/saas-access.d.ts +20 -0
  43. package/dist-server/service/saas-access.js +36 -0
  44. package/dist-server/service/saas-access.js.map +1 -0
  45. package/dist-server/service/saas-account.d.ts +43 -0
  46. package/dist-server/service/saas-account.js +166 -0
  47. package/dist-server/service/saas-account.js.map +1 -0
  48. package/dist-server/service/saas-bill.d.ts +41 -0
  49. package/dist-server/service/saas-bill.js +160 -0
  50. package/dist-server/service/saas-bill.js.map +1 -0
  51. package/dist-server/service/saas-mutation.d.ts +12 -0
  52. package/dist-server/service/saas-mutation.js +103 -0
  53. package/dist-server/service/saas-mutation.js.map +1 -0
  54. package/dist-server/service/saas-query.d.ts +69 -0
  55. package/dist-server/service/saas-query.js +215 -0
  56. package/dist-server/service/saas-query.js.map +1 -0
  57. package/dist-server/service/saas-rules.d.ts +138 -0
  58. package/dist-server/service/saas-rules.js +217 -0
  59. package/dist-server/service/saas-rules.js.map +1 -0
  60. package/dist-server/service/saas-seat.d.ts +25 -0
  61. package/dist-server/service/saas-seat.js +105 -0
  62. package/dist-server/service/saas-seat.js.map +1 -0
  63. package/dist-server/service/saas-service.d.ts +119 -0
  64. package/dist-server/service/saas-service.js +492 -0
  65. package/dist-server/service/saas-service.js.map +1 -0
  66. package/dist-server/service/saas-subscription.d.ts +44 -0
  67. package/dist-server/service/saas-subscription.js +174 -0
  68. package/dist-server/service/saas-subscription.js.map +1 -0
  69. package/dist-server/service/saas-trend-type.d.ts +9 -0
  70. package/dist-server/service/saas-trend-type.js +37 -0
  71. package/dist-server/service/saas-trend-type.js.map +1 -0
  72. package/dist-server/service/saas-type.d.ts +113 -0
  73. package/dist-server/service/saas-type.js +430 -0
  74. package/dist-server/service/saas-type.js.map +1 -0
  75. package/dist-server/tsconfig.tsbuildinfo +1 -0
  76. package/package.json +49 -4
  77. package/things-factory.config.js +13 -0
  78. package/translations/en.json +185 -0
  79. package/translations/es.json +185 -0
  80. package/translations/ja.json +185 -0
  81. package/translations/ko.json +185 -0
  82. package/translations/ms.json +185 -0
  83. package/translations/zh.json +185 -0
package/README.md CHANGED
@@ -1,3 +1,20 @@
1
- # Temporary Holding Version
1
+ # @things-factory/saas
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What the company subscribes to online and pays for again and again — not only SaaS: cloud (AWS, Azure, GCP), domains and
4
+ certificates too — and the software licenses it owns (ADR-0177 in operato-application).
5
+
6
+ - **Account** — one account we hold with a vendor, the unit a bill comes from (an AWS organization's payer account, a
7
+ Microsoft 365 tenant, an Adobe Admin Console, a registrar). An account under another (an AWS member account) names its
8
+ purpose and admins only; the money is the parent's. No password, key or recovery code is kept — only where it is kept.
9
+ - **Subscription** — one thing under an account we decide on and can cancel: a plan with seats, a fixed fee, metered
10
+ usage with a monthly budget, a commitment, or a license we own (which points at the asset register and carries no
11
+ amount). What metered usage is made of (EC2, tokens) is the vendor's bill, not a row here.
12
+ - **Seat** — who holds one place of a subscription.
13
+ - **Bill** — what an account was actually billed for a month, one line per subscription. The cost trend is computed from
14
+ the bills, never stored.
15
+
16
+ A subscription's money still to come is read by the application from these rows (`saasExpected`), on the day rule the
17
+ recurring cash items use (`@things-factory/accounting` `recurring-schedule`).
18
+
19
+ Who may do what: `saas.keeping` keeps everything, `saas.reading` reads it, and an account's admins — whatever their
20
+ seat — keep their own accounts' subscriptions, seats and bills (`saas.administering`).
@@ -0,0 +1 @@
1
+ export default function bootstrap(): void;
@@ -0,0 +1,5 @@
1
+ import { registerSaasAccount360 } from './entity360/saas-account-360.js';
2
+ export default function bootstrap() {
3
+ registerSaasAccount360();
4
+ }
5
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../client/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AAExE,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,sBAAsB,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["import { registerSaasAccount360 } from './entity360/saas-account-360.js'\n\nexport default function bootstrap() {\n registerSaasAccount360()\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import '@material/web/button/filled-button.js';
2
+ import '@material/web/button/text-button.js';
3
+ import '@operato/data-grist/ox-grist.js';
4
+ import '@operato/popup/ox-popup-actions.js';
5
+ import { LitElement } from 'lit';
6
+ type Subscription = {
7
+ id: string;
8
+ name: string;
9
+ billing: string;
10
+ status: string;
11
+ };
12
+ type Bill = {
13
+ id?: string;
14
+ month: string;
15
+ billedOn?: string | null;
16
+ description?: string | null;
17
+ lines: {
18
+ subscription?: {
19
+ id: string;
20
+ } | null;
21
+ label?: string | null;
22
+ amount: number;
23
+ }[];
24
+ };
25
+ declare const SaasBillEditor_base: (new (...args: any[]) => LitElement) & typeof LitElement;
26
+ /**
27
+ * One bill of an account for a month (ADR-0177 decisions 5, 9): a line a subscription - a new bill starts with one for each
28
+ * in use - and lines on none for tax and credits. Saved whole; the cost trend is read from these.
29
+ */
30
+ export declare class SaasBillEditor extends SaasBillEditor_base {
31
+ static styles: import("lit").CSSResult[];
32
+ accountId: string;
33
+ currency: string;
34
+ subscriptions: Subscription[];
35
+ bill?: Bill;
36
+ saved?: () => void;
37
+ month: string;
38
+ billedOn: string;
39
+ description: string;
40
+ total: number;
41
+ gristConfig: any;
42
+ private initial;
43
+ private grist;
44
+ static open(options: {
45
+ accountId: string;
46
+ currency: string;
47
+ subscriptions: Subscription[];
48
+ bill?: Bill;
49
+ saved?: () => void;
50
+ }): import("@operato/layout").PopupHandle<unknown>;
51
+ connectedCallback(): void;
52
+ private get lines();
53
+ render(): import("lit-html").TemplateResult<1>;
54
+ firstUpdated(): void;
55
+ private records;
56
+ private sum;
57
+ private save;
58
+ }
59
+ export {};
@@ -0,0 +1,211 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/button/filled-button.js';
3
+ import '@material/web/button/text-button.js';
4
+ import '@operato/data-grist/ox-grist.js';
5
+ import '@operato/popup/ox-popup-actions.js';
6
+ import gql from 'graphql-tag';
7
+ import { css, html, LitElement } from 'lit';
8
+ import { customElement, property, query, state } from 'lit/decorators.js';
9
+ import { DataGrist } from '@operato/data-grist';
10
+ import { client } from '@operato/graphql';
11
+ import { i18next, localize } from '@operato/i18n';
12
+ import { notify, openPopup } from '@operato/layout';
13
+ import { closePopup } from '@operato/popup';
14
+ import { CommonPopupStyles } from '@operato/styles';
15
+ import { failureOf } from '@things-factory/asset/dist-client/grid.js';
16
+ import { amountText, fieldWord, shiftMonth, thisMonth } from '../words.js';
17
+ /**
18
+ * One bill of an account for a month (ADR-0177 decisions 5, 9): a line a subscription - a new bill starts with one for each
19
+ * in use - and lines on none for tax and credits. Saved whole; the cost trend is read from these.
20
+ */
21
+ let SaasBillEditor = class SaasBillEditor extends localize(i18next)(LitElement) {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.accountId = '';
25
+ this.currency = '';
26
+ this.subscriptions = [];
27
+ this.month = shiftMonth(thisMonth(), -1);
28
+ this.billedOn = '';
29
+ this.description = '';
30
+ this.total = 0;
31
+ /* The lines it opens with - set once, so a re-render does not put them back over what was typed. */
32
+ this.initial = { records: [], total: 0 };
33
+ }
34
+ static { this.styles = [
35
+ CommonPopupStyles,
36
+ css `
37
+ :host {
38
+ display: flex;
39
+ flex-direction: column;
40
+ background-color: var(--md-sys-color-surface);
41
+ min-height: 420px;
42
+ }
43
+ .fields {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: var(--spacing-medium, 8px) var(--spacing-large, 12px);
47
+ padding: var(--spacing-large, 12px);
48
+ }
49
+ label {
50
+ display: flex;
51
+ flex-direction: column;
52
+ gap: 4px;
53
+ font-size: var(--ui-t-caption, 12px);
54
+ color: var(--md-sys-color-on-surface-variant);
55
+ }
56
+ label.wide {
57
+ flex: 1;
58
+ min-width: 200px;
59
+ }
60
+ input {
61
+ height: 32px;
62
+ padding: 0 8px;
63
+ border: 1px solid var(--ui-line-soft, var(--md-sys-color-outline-variant));
64
+ border-radius: var(--md-sys-shape-corner-small, 4px);
65
+ background: var(--md-sys-color-surface);
66
+ color: var(--md-sys-color-on-surface);
67
+ font: inherit;
68
+ font-size: var(--ui-t-body, 14px);
69
+ }
70
+ .total {
71
+ padding: 0 var(--spacing-large, 12px) var(--spacing-medium, 8px);
72
+ text-align: right;
73
+ font-size: var(--ui-t-body, 14px);
74
+ }
75
+ ox-grist {
76
+ flex: 1;
77
+ overflow-y: auto;
78
+ }
79
+ `
80
+ ]; }
81
+ static open(options) {
82
+ const title = options.bill ? i18next.t('title.saas-bill-edit', { month: options.bill.month }) : i18next.t('title.saas-bill-new');
83
+ return openPopup(html `<saas-bill-editor .accountId=${options.accountId} .currency=${options.currency} .subscriptions=${options.subscriptions} .bill=${options.bill} .saved=${options.saved}></saas-bill-editor>`, { backdrop: true, size: 'large', title });
84
+ }
85
+ connectedCallback() {
86
+ super.connectedCallback();
87
+ if (this.bill) {
88
+ this.month = this.bill.month;
89
+ this.billedOn = this.bill.billedOn ?? '';
90
+ this.description = this.bill.description ?? '';
91
+ }
92
+ const records = this.lines;
93
+ this.initial = { records, total: records.length };
94
+ const options = [{ value: '', display: i18next.t('text.saas-bill-line-none') }, ...this.subscriptions.map(one => ({ value: one.id, display: one.name }))];
95
+ this.gristConfig = {
96
+ rows: { appendable: true, selectable: { multiple: true } },
97
+ pagination: { infinite: true },
98
+ columns: [
99
+ { type: 'gutter', gutterName: 'sequence' },
100
+ { type: 'gutter', gutterName: 'row-selector', multiple: true },
101
+ { type: 'select', name: 'subscriptionId', header: fieldWord('saas-bill-line', 'subscription'), width: 240, record: { editable: true, options } },
102
+ { type: 'string', name: 'label', header: fieldWord('saas-bill-line', 'label'), width: 160, record: { editable: true } },
103
+ { type: 'float', name: 'amount', header: fieldWord('saas-bill-line', 'amount') + ` (${this.currency})`, width: 140, record: { editable: true, align: 'right', renderer: (value) => amountText(value) } }
104
+ ]
105
+ };
106
+ }
107
+ get lines() {
108
+ return this.bill
109
+ ? this.bill.lines.map(line => ({ subscriptionId: line.subscription?.id ?? '', label: line.label ?? '', amount: line.amount }))
110
+ : this.subscriptions.filter(one => one.status !== 'CANCELLED' && one.billing !== 'OWNED').map(one => ({ subscriptionId: one.id, label: '', amount: null }));
111
+ }
112
+ render() {
113
+ return html `
114
+ <div class="fields">
115
+ <label>${fieldWord('saas-bill', 'month')} (YYYY-MM)<input type="month" .value=${this.month} @change=${(e) => (this.month = e.target.value)} /></label>
116
+ <label>${fieldWord('saas-bill', 'billedOn')}<input type="date" .value=${this.billedOn} @change=${(e) => (this.billedOn = e.target.value)} /></label>
117
+ <label class="wide">${fieldWord('saas-bill', 'description')}<input .value=${this.description} @change=${(e) => (this.description = e.target.value)} /></label>
118
+ </div>
119
+ <ox-grist .mode=${'GRID'} .config=${this.gristConfig} .data=${this.initial} @field-change=${() => this.sum()}></ox-grist>
120
+ <div class="total">${i18next.t('text.saas-bill-total', { total: amountText(this.total), currency: this.currency })}</div>
121
+ <ox-popup-actions>
122
+ <md-text-button slot="start" @click=${() => this.grist.addRecord({ subscriptionId: '', label: '', amount: null })}>${i18next.t('button.saas-bill-add-line')}</md-text-button>
123
+ <md-text-button slot="cancel" @click=${() => closePopup(this)}>${i18next.t('button.cancel')}</md-text-button>
124
+ <md-filled-button slot="confirm" @click=${() => this.save()}>${i18next.t('button.save')}</md-filled-button>
125
+ </ox-popup-actions>
126
+ `;
127
+ }
128
+ firstUpdated() {
129
+ this.sum();
130
+ }
131
+ records() {
132
+ return (this.grist?.dirtyData?.records ?? this.grist?.data?.records ?? []);
133
+ }
134
+ sum() {
135
+ this.total = this.records()
136
+ .filter(one => one.__dirty__ !== '-')
137
+ .reduce((sum, one) => sum + (Number(one.amount) || 0), 0);
138
+ }
139
+ async save() {
140
+ const lines = this.records()
141
+ .filter(one => one.__dirty__ !== '-' && (one.subscriptionId || one.label || Number(one.amount)))
142
+ .map(one => ({ subscriptionId: one.subscriptionId || null, label: one.label || null, amount: Number(one.amount) || 0 }));
143
+ try {
144
+ const response = await client.mutate({
145
+ mutation: gql `
146
+ mutation ($accountId: String!, $bill: SaasBillInput!) {
147
+ saveSaasBill(accountId: $accountId, bill: $bill) { id }
148
+ }
149
+ `,
150
+ variables: { accountId: this.accountId, bill: { id: this.bill?.id, month: this.month, billedOn: this.billedOn || null, description: this.description || null, lines } }
151
+ });
152
+ if (response.errors?.length)
153
+ throw response;
154
+ notify({ level: 'info', message: i18next.t('text.saas-bill-saved', { month: this.month }) });
155
+ this.saved?.();
156
+ closePopup(this);
157
+ }
158
+ catch (error) {
159
+ notify({ level: 'error', message: failureOf(error) });
160
+ }
161
+ }
162
+ };
163
+ __decorate([
164
+ property(),
165
+ __metadata("design:type", Object)
166
+ ], SaasBillEditor.prototype, "accountId", void 0);
167
+ __decorate([
168
+ property(),
169
+ __metadata("design:type", Object)
170
+ ], SaasBillEditor.prototype, "currency", void 0);
171
+ __decorate([
172
+ property({ type: Array }),
173
+ __metadata("design:type", Array)
174
+ ], SaasBillEditor.prototype, "subscriptions", void 0);
175
+ __decorate([
176
+ property({ type: Object }),
177
+ __metadata("design:type", Object)
178
+ ], SaasBillEditor.prototype, "bill", void 0);
179
+ __decorate([
180
+ property({ type: Object }),
181
+ __metadata("design:type", Function)
182
+ ], SaasBillEditor.prototype, "saved", void 0);
183
+ __decorate([
184
+ state(),
185
+ __metadata("design:type", Object)
186
+ ], SaasBillEditor.prototype, "month", void 0);
187
+ __decorate([
188
+ state(),
189
+ __metadata("design:type", Object)
190
+ ], SaasBillEditor.prototype, "billedOn", void 0);
191
+ __decorate([
192
+ state(),
193
+ __metadata("design:type", Object)
194
+ ], SaasBillEditor.prototype, "description", void 0);
195
+ __decorate([
196
+ state(),
197
+ __metadata("design:type", Object)
198
+ ], SaasBillEditor.prototype, "total", void 0);
199
+ __decorate([
200
+ state(),
201
+ __metadata("design:type", Object)
202
+ ], SaasBillEditor.prototype, "gristConfig", void 0);
203
+ __decorate([
204
+ query('ox-grist'),
205
+ __metadata("design:type", DataGrist)
206
+ ], SaasBillEditor.prototype, "grist", void 0);
207
+ SaasBillEditor = __decorate([
208
+ customElement('saas-bill-editor')
209
+ ], SaasBillEditor);
210
+ export { SaasBillEditor };
211
+ //# sourceMappingURL=saas-bill-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saas-bill-editor.js","sourceRoot":"","sources":["../../client/components/saas-bill-editor.ts"],"names":[],"mappings":";AAAA,OAAO,uCAAuC,CAAA;AAC9C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,iCAAiC,CAAA;AACxC,OAAO,oCAAoC,CAAA;AAE3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAErE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAK1E;;;GAGG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,QAAQ,CAAC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,IAAI,EAAE,KAAK,EAAE,EAAE;aACxK,CAAC,CAAA;YACF,IAAK,QAAgB,CAAC,MAAM,EAAE,MAAM;gBAAE,MAAM,QAAQ,CAAA;YACpD,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;YAC5F,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;YACd,UAAU,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;;AAvGW;IAAX,QAAQ,EAAE;;iDAAe;AACd;IAAX,QAAQ,EAAE;;gDAAc;AACE;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;qDAAmC;AACjC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;4CAAY;AACX;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;6CAAmB;AAErC;IAAR,KAAK,EAAE;;6CAAoC;AACnC;IAAR,KAAK,EAAE;;gDAAc;AACb;IAAR,KAAK,EAAE;;mDAAiB;AAChB;IAAR,KAAK,EAAE;;6CAAU;AACT;IAAR,KAAK,EAAE;;mDAAiB;AAGE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;6CAAA;AA9DjC,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CAyJ1B","sourcesContent":["import '@material/web/button/filled-button.js'\nimport '@material/web/button/text-button.js'\nimport '@operato/data-grist/ox-grist.js'\nimport '@operato/popup/ox-popup-actions.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { DataGrist } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { closePopup } from '@operato/popup'\nimport { CommonPopupStyles } from '@operato/styles'\nimport { failureOf } from '@things-factory/asset/dist-client/grid.js'\n\nimport { amountText, fieldWord, shiftMonth, thisMonth } from '../words.js'\n\ntype Subscription = { id: string; name: string; billing: string; status: string }\ntype Bill = { id?: string; month: string; billedOn?: string | null; description?: string | null; lines: { subscription?: { id: string } | null; label?: string | null; amount: number }[] }\n\n/**\n * One bill of an account for a month (ADR-0177 decisions 5, 9): a line a subscription - a new bill starts with one for each\n * in use - and lines on none for tax and credits. Saved whole; the cost trend is read from these.\n */\n@customElement('saas-bill-editor')\nexport class SaasBillEditor extends localize(i18next)(LitElement) {\n static styles = [\n CommonPopupStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n background-color: var(--md-sys-color-surface);\n min-height: 420px;\n }\n .fields {\n display: flex;\n flex-wrap: wrap;\n gap: var(--spacing-medium, 8px) var(--spacing-large, 12px);\n padding: var(--spacing-large, 12px);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: 4px;\n font-size: var(--ui-t-caption, 12px);\n color: var(--md-sys-color-on-surface-variant);\n }\n label.wide {\n flex: 1;\n min-width: 200px;\n }\n input {\n height: 32px;\n padding: 0 8px;\n border: 1px solid var(--ui-line-soft, var(--md-sys-color-outline-variant));\n border-radius: var(--md-sys-shape-corner-small, 4px);\n background: var(--md-sys-color-surface);\n color: var(--md-sys-color-on-surface);\n font: inherit;\n font-size: var(--ui-t-body, 14px);\n }\n .total {\n padding: 0 var(--spacing-large, 12px) var(--spacing-medium, 8px);\n text-align: right;\n font-size: var(--ui-t-body, 14px);\n }\n ox-grist {\n flex: 1;\n overflow-y: auto;\n }\n `\n ]\n\n @property() accountId = ''\n @property() currency = ''\n @property({ type: Array }) subscriptions: Subscription[] = []\n @property({ type: Object }) bill?: Bill\n @property({ type: Object }) saved?: () => void\n\n @state() month = shiftMonth(thisMonth(), -1)\n @state() billedOn = ''\n @state() description = ''\n @state() total = 0\n @state() gristConfig: any\n /* The lines it opens with - set once, so a re-render does not put them back over what was typed. */\n private initial: any = { records: [], total: 0 }\n @query('ox-grist') private grist!: DataGrist\n\n static open(options: { accountId: string; currency: string; subscriptions: Subscription[]; bill?: Bill; saved?: () => void }) {\n const title = options.bill ? i18next.t('title.saas-bill-edit', { month: options.bill.month }) : i18next.t('title.saas-bill-new')\n return openPopup(\n html`<saas-bill-editor .accountId=${options.accountId} .currency=${options.currency} .subscriptions=${options.subscriptions} .bill=${options.bill} .saved=${options.saved}></saas-bill-editor>`,\n { backdrop: true, size: 'large', title }\n )\n }\n\n connectedCallback() {\n super.connectedCallback()\n if (this.bill) {\n this.month = this.bill.month\n this.billedOn = this.bill.billedOn ?? ''\n this.description = this.bill.description ?? ''\n }\n const records = this.lines\n this.initial = { records, total: records.length }\n const options = [{ value: '', display: i18next.t('text.saas-bill-line-none') }, ...this.subscriptions.map(one => ({ value: one.id, display: one.name }))]\n this.gristConfig = {\n rows: { appendable: true, selectable: { multiple: true } },\n pagination: { infinite: true },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n { type: 'select', name: 'subscriptionId', header: fieldWord('saas-bill-line', 'subscription'), width: 240, record: { editable: true, options } },\n { type: 'string', name: 'label', header: fieldWord('saas-bill-line', 'label'), width: 160, record: { editable: true } },\n { type: 'float', name: 'amount', header: fieldWord('saas-bill-line', 'amount') + ` (${this.currency})`, width: 140, record: { editable: true, align: 'right', renderer: (value: number) => amountText(value) } }\n ]\n }\n }\n\n private get lines() {\n return this.bill\n ? this.bill.lines.map(line => ({ subscriptionId: line.subscription?.id ?? '', label: line.label ?? '', amount: line.amount }))\n : this.subscriptions.filter(one => one.status !== 'CANCELLED' && one.billing !== 'OWNED').map(one => ({ subscriptionId: one.id, label: '', amount: null }))\n }\n\n render() {\n return html`\n <div class=\"fields\">\n <label>${fieldWord('saas-bill', 'month')} (YYYY-MM)<input type=\"month\" .value=${this.month} @change=${(e: any) => (this.month = e.target.value)} /></label>\n <label>${fieldWord('saas-bill', 'billedOn')}<input type=\"date\" .value=${this.billedOn} @change=${(e: any) => (this.billedOn = e.target.value)} /></label>\n <label class=\"wide\">${fieldWord('saas-bill', 'description')}<input .value=${this.description} @change=${(e: any) => (this.description = e.target.value)} /></label>\n </div>\n <ox-grist .mode=${'GRID'} .config=${this.gristConfig} .data=${this.initial} @field-change=${() => this.sum()}></ox-grist>\n <div class=\"total\">${i18next.t('text.saas-bill-total', { total: amountText(this.total), currency: this.currency })}</div>\n <ox-popup-actions>\n <md-text-button slot=\"start\" @click=${() => this.grist.addRecord({ subscriptionId: '', label: '', amount: null })}>${i18next.t('button.saas-bill-add-line')}</md-text-button>\n <md-text-button slot=\"cancel\" @click=${() => closePopup(this)}>${i18next.t('button.cancel')}</md-text-button>\n <md-filled-button slot=\"confirm\" @click=${() => this.save()}>${i18next.t('button.save')}</md-filled-button>\n </ox-popup-actions>\n `\n }\n\n firstUpdated() {\n this.sum()\n }\n\n private records(): any[] {\n return (this.grist?.dirtyData?.records ?? this.grist?.data?.records ?? []) as any[]\n }\n\n private sum() {\n this.total = this.records()\n .filter(one => one.__dirty__ !== '-')\n .reduce((sum, one) => sum + (Number(one.amount) || 0), 0)\n }\n\n private async save() {\n const lines = this.records()\n .filter(one => one.__dirty__ !== '-' && (one.subscriptionId || one.label || Number(one.amount)))\n .map(one => ({ subscriptionId: one.subscriptionId || null, label: one.label || null, amount: Number(one.amount) || 0 }))\n try {\n const response = await client.mutate({\n mutation: gql`\n mutation ($accountId: String!, $bill: SaasBillInput!) {\n saveSaasBill(accountId: $accountId, bill: $bill) { id }\n }\n `,\n variables: { accountId: this.accountId, bill: { id: this.bill?.id, month: this.month, billedOn: this.billedOn || null, description: this.description || null, lines } }\n })\n if ((response as any).errors?.length) throw response\n notify({ level: 'info', message: i18next.t('text.saas-bill-saved', { month: this.month }) })\n this.saved?.()\n closePopup(this)\n } catch (error) {\n notify({ level: 'error', message: failureOf(error) })\n }\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { LitElement } from 'lit';
2
+ import { type Entity360DoorAnswer, type Entity360Subject } from '@operato/layout';
3
+ export declare function registerSaasAccount360(): void;
4
+ export declare class SaasAccount360 extends LitElement {
5
+ static styles: import("lit").CSSResult;
6
+ subject?: Entity360Subject;
7
+ answer?: Entity360DoorAnswer<any>;
8
+ payments?: any[] | null;
9
+ updated(changed: Map<string, unknown>): void;
10
+ private read;
11
+ render(): import("lit-html").TemplateResult<1>;
12
+ }
@@ -0,0 +1,231 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import gql from 'graphql-tag';
3
+ import { css, html, LitElement, nothing } from 'lit';
4
+ import { customElement, property, state } from 'lit/decorators.js';
5
+ import { client } from '@operato/graphql';
6
+ import { i18next } from '@operato/i18n';
7
+ import { entity360Name, readEntity360Door, registerEntity360Kind, registerEntity360Section } from '@operato/layout';
8
+ import { navigate } from '@operato/shell';
9
+ import { amountText, wordOf } from '../words.js';
10
+ /*
11
+ * A subscription account's 360 (ADR-0177 decision 11) - one account read deep: what it is and how it is paid, its last
12
+ * twelve months against the next three expected, its bills month by month, what is subscribed under it and what moved on
13
+ * it. Reading first; the account's screen opens from a quiet button beside the heading.
14
+ */
15
+ export function registerSaasAccount360() {
16
+ registerEntity360Kind({
17
+ kind: 'saas-account',
18
+ typenames: ['SaasAccount'],
19
+ /* Not yet a record the assistant's conversation follows - the module registers no subject describer for it. */
20
+ assistantSubject: false,
21
+ title: ({ value }) => `${i18next.t('title.saas-account-page')} · ${value.name || ''}`,
22
+ context: ({ value }) => [value.identifier, value.currency].filter(Boolean).join(' · ')
23
+ });
24
+ registerEntity360Section('saas-account', { name: 'overview', order: 10, render: subject => html `<saas-account-360 .subject=${subject}></saas-account-360>` });
25
+ }
26
+ const ACCOUNT = gql `
27
+ query ($id: String!) {
28
+ saasAccount(id: $id) {
29
+ id name identifier purpose currency billingDay status closedOn
30
+ counterparty { id name } paymentAccount { id name } parent { id name } admins { id name }
31
+ trend { months values sources nextMonths expected currency }
32
+ }
33
+ saasSubscriptions(accountId: $id) { id name billing quantity unitPrice amount budget everyMonths renewalOn autoRenew status seatsHeld }
34
+ saasBills(accountId: $id) { id month billedOn total lines { subscription { id name } label amount } }
35
+ saasChanges(accountId: $id) { subject field fromValue toValue at changedBy }
36
+ }
37
+ `;
38
+ let SaasAccount360 = class SaasAccount360 extends LitElement {
39
+ static { this.styles = css `
40
+ :host {
41
+ display: flex;
42
+ flex-direction: column;
43
+ gap: var(--spacing-large, 12px);
44
+ font-size: var(--ui-t-body, 13px);
45
+ line-height: 1.5;
46
+ }
47
+ dl {
48
+ margin: 0;
49
+ display: grid;
50
+ grid-template-columns: max-content 1fr;
51
+ gap: var(--spacing-small, 4px) var(--spacing-large, 12px);
52
+ }
53
+ dt,
54
+ th,
55
+ .muted {
56
+ color: var(--ui-muted);
57
+ }
58
+ dd {
59
+ margin: 0;
60
+ overflow-wrap: anywhere;
61
+ }
62
+ table {
63
+ width: 100%;
64
+ border-collapse: collapse;
65
+ font-variant-numeric: tabular-nums;
66
+ }
67
+ th,
68
+ td {
69
+ padding: 4px 6px;
70
+ border-bottom: 1px solid var(--ui-line, var(--md-sys-color-outline-variant));
71
+ text-align: right;
72
+ font-weight: normal;
73
+ }
74
+ th:first-child,
75
+ td:first-child {
76
+ text-align: left;
77
+ }
78
+ td.expected {
79
+ color: var(--ui-muted);
80
+ font-style: italic;
81
+ }
82
+ ox-grist-sparkline-renderer {
83
+ height: 48px;
84
+ }
85
+ .quiet {
86
+ border: none;
87
+ background: none;
88
+ padding: 0;
89
+ color: var(--md-sys-color-primary);
90
+ font: inherit;
91
+ cursor: pointer;
92
+ }
93
+ `; }
94
+ updated(changed) {
95
+ if (changed.has('subject'))
96
+ this.read();
97
+ }
98
+ async read() {
99
+ const id = this.subject?.id;
100
+ this.answer = undefined;
101
+ if (!id)
102
+ return;
103
+ let response;
104
+ try {
105
+ response = await client.query({ query: ACCOUNT, variables: { id }, fetchPolicy: 'no-cache', errorPolicy: 'all' });
106
+ }
107
+ catch (e) {
108
+ response = { data: null, errors: e?.graphQLErrors?.length ? e.graphQLErrors : [{ message: e?.message ?? String(e) }] };
109
+ }
110
+ if (this.subject?.id !== id)
111
+ return;
112
+ this.answer = readEntity360Door(response, data => (data?.saasAccount ? data : null));
113
+ this.payments = undefined;
114
+ try {
115
+ const paid = await client.query({
116
+ query: gql `query ($id: String!) { saasPayments(accountId: $id) { id transactionDate amount currency description } }`,
117
+ variables: { id },
118
+ fetchPolicy: 'no-cache',
119
+ errorPolicy: 'all'
120
+ });
121
+ if (this.subject?.id === id)
122
+ this.payments = paid.errors?.length ? null : paid.data?.saasPayments ?? [];
123
+ }
124
+ catch {
125
+ if (this.subject?.id === id)
126
+ this.payments = null;
127
+ }
128
+ }
129
+ render() {
130
+ const state = this.answer?.state ?? 'loading';
131
+ const data = this.answer?.data;
132
+ const one = data?.saasAccount;
133
+ const section = (heading, body, action) => html `<ox-entity360-section .heading=${heading} .state=${state} .message=${this.answer?.message ?? ''}>${action ? html `<span slot="actions">${action}</span>` : nothing}${one ? body : nothing}</ox-entity360-section>`;
134
+ if (!one)
135
+ return section(i18next.t('title.saas-account-page'), nothing);
136
+ const trend = one.trend;
137
+ const subs = data.saasSubscriptions ?? [];
138
+ const bills = data.saasBills ?? [];
139
+ const changes = data.saasChanges ?? [];
140
+ const nextRenewal = subs
141
+ .filter(sub => sub.status === 'ACTIVE' && sub.renewalOn)
142
+ .map(sub => sub.renewalOn)
143
+ .sort()[0];
144
+ const open = html `<button class="quiet" @click=${() => navigate(`saas-account-page?id=${one.id}`)}>${i18next.t('button.saas-open-account')}</button>`;
145
+ const party = (value) => (value ? entity360Name({ __typename: 'Counterparty', ...value }, value.name) : '—');
146
+ return html `
147
+ ${section(one.name, html `<dl>
148
+ <dt>${i18next.t('field.saas-account-counterparty')}</dt>
149
+ <dd>${party(one.counterparty)}</dd>
150
+ <dt>${i18next.t('field.saas-account-payment-account')}</dt>
151
+ <dd>${one.paymentAccount?.name ?? '—'}</dd>
152
+ <dt>${i18next.t('field.saas-account-currency')}</dt>
153
+ <dd>${one.currency}${one.billingDay ? ` · ${i18next.t('text.saas-account-billing-day', { day: one.billingDay })}` : ''}</dd>
154
+ <dt>${i18next.t('text.saas-360-next-renewal')}</dt>
155
+ <dd>${nextRenewal ?? '—'}</dd>
156
+ <dt>${i18next.t('field.saas-account-admins')}</dt>
157
+ <dd>${(one.admins ?? []).map((admin) => admin.name).join(', ') || '—'}</dd>
158
+ <dt>${i18next.t('field.saas-account-status')}</dt>
159
+ <dd>${wordOf('saas-account-status', one.status)}${one.closedOn ? ` · ${one.closedOn}` : ''}</dd>
160
+ </dl>`, open)}
161
+ ${trend
162
+ ? section(i18next.t('text.saas-360-months'), html `${[...trend.values, ...trend.expected].some((value) => value !== null)
163
+ ? html `<ox-grist-sparkline-renderer .value=${trend} .column=${{ type: 'sparkline', name: 'trend', record: {} }}></ox-grist-sparkline-renderer>`
164
+ : nothing}
165
+ <table>
166
+ <tr><th>${i18next.t('field.saas-bill-month')}</th><th>${trend.currency}</th></tr>
167
+ ${trend.months.map((month, i) => html `<tr>
168
+ <td>${month} ${trend.sources?.[i] ? html `<span class="muted">${i18next.t(`text.saas-360-source-${trend.sources[i]}`)}</span>` : nothing}</td>
169
+ <td>${trend.values[i] === null ? '—' : amountText(trend.values[i])}</td>
170
+ </tr>`)}
171
+ ${trend.nextMonths.map((month, i) => html `<tr><td>${month}</td><td class="expected">${trend.expected[i] === null ? '' : amountText(trend.expected[i])}</td></tr>`)}
172
+ </table>`)
173
+ : nothing}
174
+ ${this.payments
175
+ ? section(i18next.t('text.saas-360-payments', { vendor: one.counterparty?.name ?? '' }), this.payments.length
176
+ ? html `<table>
177
+ ${this.payments.map(line => html `<tr>
178
+ <td>${entity360Name({ __typename: 'Transaction', id: line.id, transactionDate: line.transactionDate, direction: 'EXPENSE' }, line.transactionDate)}</td>
179
+ <td class="muted">${line.description ?? ''}</td>
180
+ <td>${amountText(line.amount)} ${line.currency !== one.currency ? line.currency : ''}</td>
181
+ </tr>`)}
182
+ </table>`
183
+ : html `<div class="muted">${i18next.t(one.counterparty ? 'text.saas-360-payments-empty' : 'text.saas-360-payments-no-vendor')}</div>`)
184
+ : nothing}
185
+ ${section(i18next.t('text.saas-tab-bills'), bills.length
186
+ ? html `<table>
187
+ ${bills.map(bill => html `<tr>
188
+ <td>${bill.month}${bill.billedOn ? html ` <span class="muted">${bill.billedOn}</span>` : nothing}</td>
189
+ <td class="muted">${(bill.lines ?? []).map((line) => `${line.subscription?.name ?? line.label ?? ''} ${amountText(line.amount)}`).join(' · ')}</td>
190
+ <td>${amountText(bill.total)}</td>
191
+ </tr>`)}
192
+ </table>`
193
+ : html `<div class="muted">${i18next.t('text.saas-bills-empty')}</div>`)}
194
+ ${section(i18next.t('text.saas-tab-subscriptions'), subs.length
195
+ ? html `<table>
196
+ ${subs.map(sub => html `<tr>
197
+ <td>${sub.name} <span class="muted">${wordOf('saas-billing', sub.billing)} · ${wordOf('saas-subscription-status', sub.status)}</span></td>
198
+ <td class="muted">${sub.billing === 'SEAT' ? i18next.t('text.saas-360-seats', { held: sub.seatsHeld ?? 0, quantity: sub.quantity ?? 0 }) : sub.billing === 'USAGE' ? i18next.t('text.saas-360-budget', { budget: amountText(sub.budget) }) : ''}</td>
199
+ <td>${sub.billing === 'SEAT' ? amountText((sub.quantity ?? 0) * (sub.unitPrice ?? 0)) : amountText(sub.amount)}</td>
200
+ </tr>`)}
201
+ </table>`
202
+ : html `<div class="muted">${i18next.t('text.saas-subscriptions-empty')}</div>`)}
203
+ ${section(i18next.t('text.saas-360-changes'), changes.length
204
+ ? html `<table>
205
+ ${changes.map(change => html `<tr>
206
+ <td>${String(change.at).slice(0, 10)} <span class="muted">${change.changedBy ?? ''}</span></td>
207
+ <td>${change.subject} · ${i18next.t(`text.saas-change-field-${change.field}`, { defaultValue: change.field })}</td>
208
+ <td>${change.fromValue ?? '—'} → ${change.toValue ?? '—'}</td>
209
+ </tr>`)}
210
+ </table>`
211
+ : html `<div class="muted">${i18next.t('text.saas-360-changes-empty')}</div>`)}
212
+ `;
213
+ }
214
+ };
215
+ __decorate([
216
+ property({ attribute: false }),
217
+ __metadata("design:type", Object)
218
+ ], SaasAccount360.prototype, "subject", void 0);
219
+ __decorate([
220
+ state(),
221
+ __metadata("design:type", Object)
222
+ ], SaasAccount360.prototype, "answer", void 0);
223
+ __decorate([
224
+ state(),
225
+ __metadata("design:type", Object)
226
+ ], SaasAccount360.prototype, "payments", void 0);
227
+ SaasAccount360 = __decorate([
228
+ customElement('saas-account-360')
229
+ ], SaasAccount360);
230
+ export { SaasAccount360 };
231
+ //# sourceMappingURL=saas-account-360.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saas-account-360.js","sourceRoot":"","sources":["../../client/entity360/saas-account-360.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,wBAAwB,EAAmD,MAAM,iBAAiB,CAAA;AACpK,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEhD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACpC,qBAAqB,CA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CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC;sBAC1G,CACP;qBACM;YACX,CAAC,CAAC,IAAI,CAAA,sBAAsB,OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC,QAAQ,CACjF;QACC,OAAO,CACP,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,EAClC,OAAO,CAAC,MAAM;YACZ,CAAC,CAAC,IAAI,CAAA;gBACA,OAAO,CAAC,GAAG,CACX,MAAM,CAAC,EAAE,CAAC,IAAI,CAAA;wBACN,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,wBAAwB,MAAM,CAAC,SAAS,IAAI,EAAE;wBAC5E,MAAM,CAAC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,0BAA0B,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;wBACvG,MAAM,CAAC,SAAS,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,IAAI,GAAG;sBACpD,CACP;qBACM;YACX,CAAC,CAAC,IAAI,CAAA,sBAAsB,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,QAAQ,CAC/E;KACF,CAAA;IACH,CAAC;;AAvJ+B;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;+CAA2B;AACjD;IAAR,KAAK,EAAE;;8CAAkC;AAEjC;IAAR,KAAK,EAAE;;gDAAwB;AA5DrB,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CAiN1B","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next } from '@operato/i18n'\nimport { entity360Name, readEntity360Door, registerEntity360Kind, registerEntity360Section, type Entity360DoorAnswer, type Entity360Subject } from '@operato/layout'\nimport { navigate } from '@operato/shell'\n\nimport { amountText, wordOf } from '../words.js'\n\n/*\n * A subscription account's 360 (ADR-0177 decision 11) - one account read deep: what it is and how it is paid, its last\n * twelve months against the next three expected, its bills month by month, what is subscribed under it and what moved on\n * it. Reading first; the account's screen opens from a quiet button beside the heading.\n */\nexport function registerSaasAccount360() {\n registerEntity360Kind({\n kind: 'saas-account',\n typenames: ['SaasAccount'],\n /* Not yet a record the assistant's conversation follows - the module registers no subject describer for it. */\n assistantSubject: false,\n title: ({ value }) => `${i18next.t('title.saas-account-page')} · ${value.name || ''}`,\n context: ({ value }) => [value.identifier, value.currency].filter(Boolean).join(' · ')\n })\n registerEntity360Section('saas-account', { name: 'overview', order: 10, render: subject => html`<saas-account-360 .subject=${subject}></saas-account-360>` })\n}\n\nconst ACCOUNT = gql`\n query ($id: String!) {\n saasAccount(id: $id) {\n id name identifier purpose currency billingDay status closedOn\n counterparty { id name } paymentAccount { id name } parent { id name } admins { id name }\n trend { months values sources nextMonths expected currency }\n }\n saasSubscriptions(accountId: $id) { id name billing quantity unitPrice amount budget everyMonths renewalOn autoRenew status seatsHeld }\n saasBills(accountId: $id) { id month billedOn total lines { subscription { id name } label amount } }\n saasChanges(accountId: $id) { subject field fromValue toValue at changedBy }\n }\n`\n\n@customElement('saas-account-360')\nexport class SaasAccount360 extends LitElement {\n static styles = css`\n :host {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-large, 12px);\n font-size: var(--ui-t-body, 13px);\n line-height: 1.5;\n }\n dl {\n margin: 0;\n display: grid;\n grid-template-columns: max-content 1fr;\n gap: var(--spacing-small, 4px) var(--spacing-large, 12px);\n }\n dt,\n th,\n .muted {\n color: var(--ui-muted);\n }\n dd {\n margin: 0;\n overflow-wrap: anywhere;\n }\n table {\n width: 100%;\n border-collapse: collapse;\n font-variant-numeric: tabular-nums;\n }\n th,\n td {\n padding: 4px 6px;\n border-bottom: 1px solid var(--ui-line, var(--md-sys-color-outline-variant));\n text-align: right;\n font-weight: normal;\n }\n th:first-child,\n td:first-child {\n text-align: left;\n }\n td.expected {\n color: var(--ui-muted);\n font-style: italic;\n }\n ox-grist-sparkline-renderer {\n height: 48px;\n }\n .quiet {\n border: none;\n background: none;\n padding: 0;\n color: var(--md-sys-color-primary);\n font: inherit;\n cursor: pointer;\n }\n `\n\n @property({ attribute: false }) subject?: Entity360Subject\n @state() answer?: Entity360DoorAnswer<any>\n /* What left the bank for the vendor - the bank's door, read apart so a reader without it still sees the rest. */\n @state() payments?: any[] | null\n\n updated(changed: Map<string, unknown>) {\n if (changed.has('subject')) this.read()\n }\n\n private async read() {\n const id = this.subject?.id\n this.answer = undefined\n if (!id) return\n let response: any\n try {\n response = await client.query({ query: ACCOUNT, variables: { id }, fetchPolicy: 'no-cache', errorPolicy: 'all' } as any)\n } catch (e: any) {\n response = { data: null, errors: e?.graphQLErrors?.length ? e.graphQLErrors : [{ message: e?.message ?? String(e) }] }\n }\n if (this.subject?.id !== id) return\n this.answer = readEntity360Door(response, data => (data?.saasAccount ? data : null))\n this.payments = undefined\n try {\n const paid: any = await client.query({\n query: gql`query ($id: String!) { saasPayments(accountId: $id) { id transactionDate amount currency description } }`,\n variables: { id },\n fetchPolicy: 'no-cache',\n errorPolicy: 'all'\n } as any)\n if (this.subject?.id === id) this.payments = paid.errors?.length ? null : paid.data?.saasPayments ?? []\n } catch {\n if (this.subject?.id === id) this.payments = null\n }\n }\n\n render() {\n const state = this.answer?.state ?? 'loading'\n const data = this.answer?.data\n const one = data?.saasAccount\n const section = (heading: string, body: unknown, action?: unknown) =>\n html`<ox-entity360-section .heading=${heading} .state=${state} .message=${this.answer?.message ?? ''}>${action ? html`<span slot=\"actions\">${action}</span>` : nothing}${one ? body : nothing}</ox-entity360-section>`\n if (!one) return section(i18next.t('title.saas-account-page'), nothing)\n\n const trend = one.trend\n const subs: any[] = data.saasSubscriptions ?? []\n const bills: any[] = data.saasBills ?? []\n const changes: any[] = data.saasChanges ?? []\n const nextRenewal = subs\n .filter(sub => sub.status === 'ACTIVE' && sub.renewalOn)\n .map(sub => sub.renewalOn)\n .sort()[0]\n const open = html`<button class=\"quiet\" @click=${() => navigate(`saas-account-page?id=${one.id}`)}>${i18next.t('button.saas-open-account')}</button>`\n const party = (value?: { id: string; name: string }) => (value ? entity360Name({ __typename: 'Counterparty', ...value }, value.name) : '—')\n\n return html`\n ${section(\n one.name,\n html`<dl>\n <dt>${i18next.t('field.saas-account-counterparty')}</dt>\n <dd>${party(one.counterparty)}</dd>\n <dt>${i18next.t('field.saas-account-payment-account')}</dt>\n <dd>${one.paymentAccount?.name ?? '—'}</dd>\n <dt>${i18next.t('field.saas-account-currency')}</dt>\n <dd>${one.currency}${one.billingDay ? ` · ${i18next.t('text.saas-account-billing-day', { day: one.billingDay })}` : ''}</dd>\n <dt>${i18next.t('text.saas-360-next-renewal')}</dt>\n <dd>${nextRenewal ?? '—'}</dd>\n <dt>${i18next.t('field.saas-account-admins')}</dt>\n <dd>${(one.admins ?? []).map((admin: any) => admin.name).join(', ') || '—'}</dd>\n <dt>${i18next.t('field.saas-account-status')}</dt>\n <dd>${wordOf('saas-account-status', one.status)}${one.closedOn ? ` · ${one.closedOn}` : ''}</dd>\n </dl>`,\n open\n )}\n ${trend\n ? section(\n i18next.t('text.saas-360-months'),\n html`${[...trend.values, ...trend.expected].some((value: number | null) => value !== null)\n ? html`<ox-grist-sparkline-renderer .value=${trend} .column=${{ type: 'sparkline', name: 'trend', record: {} }}></ox-grist-sparkline-renderer>`\n : nothing}\n <table>\n <tr><th>${i18next.t('field.saas-bill-month')}</th><th>${trend.currency}</th></tr>\n ${trend.months.map(\n (month: string, i: number) =>\n html`<tr>\n <td>${month} ${trend.sources?.[i] ? html`<span class=\"muted\">${i18next.t(`text.saas-360-source-${trend.sources[i]}`)}</span>` : nothing}</td>\n <td>${trend.values[i] === null ? '—' : amountText(trend.values[i])}</td>\n </tr>`\n )}\n ${trend.nextMonths.map((month: string, i: number) => html`<tr><td>${month}</td><td class=\"expected\">${trend.expected[i] === null ? '' : amountText(trend.expected[i])}</td></tr>`)}\n </table>`\n )\n : nothing}\n ${this.payments\n ? section(\n i18next.t('text.saas-360-payments', { vendor: one.counterparty?.name ?? '' }),\n this.payments.length\n ? html`<table>\n ${this.payments.map(\n line => html`<tr>\n <td>${entity360Name({ __typename: 'Transaction', id: line.id, transactionDate: line.transactionDate, direction: 'EXPENSE' }, line.transactionDate)}</td>\n <td class=\"muted\">${line.description ?? ''}</td>\n <td>${amountText(line.amount)} ${line.currency !== one.currency ? line.currency : ''}</td>\n </tr>`\n )}\n </table>`\n : html`<div class=\"muted\">${i18next.t(one.counterparty ? 'text.saas-360-payments-empty' : 'text.saas-360-payments-no-vendor')}</div>`\n )\n : nothing}\n ${section(\n i18next.t('text.saas-tab-bills'),\n bills.length\n ? html`<table>\n ${bills.map(\n bill => html`<tr>\n <td>${bill.month}${bill.billedOn ? html` <span class=\"muted\">${bill.billedOn}</span>` : nothing}</td>\n <td class=\"muted\">${(bill.lines ?? []).map((line: any) => `${line.subscription?.name ?? line.label ?? ''} ${amountText(line.amount)}`).join(' · ')}</td>\n <td>${amountText(bill.total)}</td>\n </tr>`\n )}\n </table>`\n : html`<div class=\"muted\">${i18next.t('text.saas-bills-empty')}</div>`\n )}\n ${section(\n i18next.t('text.saas-tab-subscriptions'),\n subs.length\n ? html`<table>\n ${subs.map(\n sub => html`<tr>\n <td>${sub.name} <span class=\"muted\">${wordOf('saas-billing', sub.billing)} · ${wordOf('saas-subscription-status', sub.status)}</span></td>\n <td class=\"muted\">${sub.billing === 'SEAT' ? i18next.t('text.saas-360-seats', { held: sub.seatsHeld ?? 0, quantity: sub.quantity ?? 0 }) : sub.billing === 'USAGE' ? i18next.t('text.saas-360-budget', { budget: amountText(sub.budget) }) : ''}</td>\n <td>${sub.billing === 'SEAT' ? amountText((sub.quantity ?? 0) * (sub.unitPrice ?? 0)) : amountText(sub.amount)}</td>\n </tr>`\n )}\n </table>`\n : html`<div class=\"muted\">${i18next.t('text.saas-subscriptions-empty')}</div>`\n )}\n ${section(\n i18next.t('text.saas-360-changes'),\n changes.length\n ? html`<table>\n ${changes.map(\n change => html`<tr>\n <td>${String(change.at).slice(0, 10)} <span class=\"muted\">${change.changedBy ?? ''}</span></td>\n <td>${change.subject} · ${i18next.t(`text.saas-change-field-${change.field}`, { defaultValue: change.field })}</td>\n <td>${change.fromValue ?? '—'} → ${change.toValue ?? '—'}</td>\n </tr>`\n )}\n </table>`\n : html`<div class=\"muted\">${i18next.t('text.saas-360-changes-empty')}</div>`\n )}\n `\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { SaasBillEditor } from './components/saas-bill-editor.js';
2
+ export { registerSaasAccount360 } from './entity360/saas-account-360.js';
3
+ export { trendTitle } from './words.js';