@things-factory/saas 10.1.248 → 10.1.250
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.
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +5 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/entity360/saas-account-360.d.ts +11 -0
- package/dist-client/entity360/saas-account-360.js +178 -0
- package/dist-client/entity360/saas-account-360.js.map +1 -0
- package/dist-client/index.d.ts +1 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/saas-account-list.d.ts +57 -0
- package/dist-client/pages/saas-account-list.js +169 -0
- package/dist-client/pages/saas-account-list.js.map +1 -0
- package/dist-client/pages/saas-account-page.d.ts +52 -0
- package/dist-client/pages/saas-account-page.js +332 -0
- package/dist-client/pages/saas-account-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +13 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-client/words.d.ts +34 -0
- package/dist-client/words.js +22 -0
- package/dist-client/words.js.map +1 -0
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +9 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/role-tasks.d.ts +2 -0
- package/dist-server/role-tasks.js +18 -0
- package/dist-server/role-tasks.js.map +1 -0
- package/dist-server/service/checks.d.ts +27 -0
- package/dist-server/service/checks.js +70 -0
- package/dist-server/service/checks.js.map +1 -0
- package/dist-server/service/index.d.ts +18 -0
- package/dist-server/service/index.js +34 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/saas-access.d.ts +20 -0
- package/dist-server/service/saas-access.js +36 -0
- package/dist-server/service/saas-access.js.map +1 -0
- package/dist-server/service/saas-account.d.ts +39 -0
- package/dist-server/service/saas-account.js +151 -0
- package/dist-server/service/saas-account.js.map +1 -0
- package/dist-server/service/saas-mutation.d.ts +10 -0
- package/dist-server/service/saas-mutation.js +87 -0
- package/dist-server/service/saas-mutation.js.map +1 -0
- package/dist-server/service/saas-query.d.ts +21 -0
- package/dist-server/service/saas-query.js +168 -0
- package/dist-server/service/saas-query.js.map +1 -0
- package/dist-server/service/saas-rules.d.ts +41 -0
- package/dist-server/service/saas-rules.js +62 -0
- package/dist-server/service/saas-rules.js.map +1 -0
- package/dist-server/service/saas-seat.d.ts +26 -0
- package/dist-server/service/saas-seat.js +110 -0
- package/dist-server/service/saas-seat.js.map +1 -0
- package/dist-server/service/saas-service.d.ts +19 -0
- package/dist-server/service/saas-service.js +223 -0
- package/dist-server/service/saas-service.js.map +1 -0
- package/dist-server/service/saas-subscription.d.ts +45 -0
- package/dist-server/service/saas-subscription.js +174 -0
- package/dist-server/service/saas-subscription.js.map +1 -0
- package/dist-server/service/saas-sync.d.ts +34 -0
- package/dist-server/service/saas-sync.js +106 -0
- package/dist-server/service/saas-sync.js.map +1 -0
- package/dist-server/service/saas-type.d.ts +89 -0
- package/dist-server/service/saas-type.js +338 -0
- package/dist-server/service/saas-type.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SAAS_SUBSCRIPTION_FACT = exports.SAAS_ACCOUNT_FACT = void 0;
|
|
4
|
+
exports.saveSaasAccounts = saveSaasAccounts;
|
|
5
|
+
exports.saveSaasSubscriptions = saveSaasSubscriptions;
|
|
6
|
+
exports.saasSubscriptionsOf = saasSubscriptionsOf;
|
|
7
|
+
exports.saveSaasSeats = saveSaasSeats;
|
|
8
|
+
exports.saasSeatsOf = saasSeatsOf;
|
|
9
|
+
exports.saasChangesOf = saasChangesOf;
|
|
10
|
+
const accounting_1 = require("@things-factory/accounting");
|
|
11
|
+
/* The register grids' save, the asset module's - this module saves its grids the same way (one implementation). */
|
|
12
|
+
const asset_1 = require("@things-factory/asset");
|
|
13
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
14
|
+
const fact_change_1 = require("@things-factory/fact-change");
|
|
15
|
+
const organization_1 = require("@things-factory/organization");
|
|
16
|
+
const shell_1 = require("@things-factory/shell");
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const saas_access_1 = require("./saas-access");
|
|
19
|
+
const saas_account_1 = require("./saas-account");
|
|
20
|
+
const saas_rules_1 = require("./saas-rules");
|
|
21
|
+
const saas_seat_1 = require("./saas-seat");
|
|
22
|
+
const saas_subscription_1 = require("./saas-subscription");
|
|
23
|
+
const currencyOf = (value, fallback) => {
|
|
24
|
+
const text = String(value ?? '').trim().toUpperCase();
|
|
25
|
+
if (!text)
|
|
26
|
+
return fallback;
|
|
27
|
+
if (!/^[A-Z]{3}$/.test(text))
|
|
28
|
+
throw new shell_1.Refusal('saas-currency-invalid', { value: text }, `'${text}' is not a currency code (KRW, USD)`);
|
|
29
|
+
return text;
|
|
30
|
+
};
|
|
31
|
+
const intOf = (value, code, min, max) => {
|
|
32
|
+
if (value === null || value === undefined || value === '')
|
|
33
|
+
return null;
|
|
34
|
+
const number = Number(value);
|
|
35
|
+
if (!Number.isInteger(number) || number < min || number > max)
|
|
36
|
+
throw new shell_1.Refusal(code, { min, max }, `Give a whole number from ${min} to ${max}`);
|
|
37
|
+
return number;
|
|
38
|
+
};
|
|
39
|
+
async function oneOf(tx, target, domain, id, code) {
|
|
40
|
+
if (!id)
|
|
41
|
+
return null;
|
|
42
|
+
const found = await tx.getRepository(target).findOne({ where: { domain: { id: domain.id }, id } });
|
|
43
|
+
if (!found)
|
|
44
|
+
throw new shell_1.Refusal(code, {}, 'What it points at was not found');
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
const field = (patch, name, old) => (patch[name] !== undefined ? patch[name] : old?.[name]);
|
|
48
|
+
/*
|
|
49
|
+
* What moved on an account or a subscription, field by field (ADR-0177 decision 11) - the fact-change module keeps it.
|
|
50
|
+
* A row's relations are told by their id; a new row has no history yet.
|
|
51
|
+
*/
|
|
52
|
+
exports.SAAS_ACCOUNT_FACT = 'saas-account';
|
|
53
|
+
exports.SAAS_SUBSCRIPTION_FACT = 'saas-subscription';
|
|
54
|
+
const ACCOUNT_TRACKED = ['name', 'counterpartyId', 'identifier', 'parentId', 'paymentAccountId', 'currency', 'status', 'closedOn'];
|
|
55
|
+
const SUBSCRIPTION_TRACKED = ['name', 'billing', 'vendorKey', 'trial', 'quantity', 'unitPrice', 'startOn', 'renewalOn', 'autoRenew', 'noticeDays', 'departmentId', 'assetId', 'status', 'endedOn'];
|
|
56
|
+
const idsOf = (row) => Object.fromEntries(Object.entries(row).map(([key, value]) => (value && typeof value === 'object' && 'id' in value ? [`${key}Id`, value.id] : value === null && ['counterparty', 'parent', 'paymentAccount', 'department', 'asset'].includes(key) ? [`${key}Id`, null] : [key, value])));
|
|
57
|
+
async function recordChanges(tx, domain, user, factKind, old, row, fields) {
|
|
58
|
+
if (!old)
|
|
59
|
+
return;
|
|
60
|
+
const after = { ...old, ...idsOf(row) };
|
|
61
|
+
await (0, fact_change_1.recordFactChanges)(tx, domain, { factKind, factName: old.id, changes: (0, fact_change_1.fieldChanges)(old, after, fields) }, { user, source: 'saas' });
|
|
62
|
+
}
|
|
63
|
+
/* ----------------------------------------------------------------------------------------------------------------- */
|
|
64
|
+
/* Accounts (decision 2) - kept by `saas` keepers only */
|
|
65
|
+
async function saveSaasAccounts(tx, domain, user, patches) {
|
|
66
|
+
const saved = await (0, asset_1.applyPatches)(tx, saas_account_1.SaasAccount, domain, user, patches, async (patch, old) => {
|
|
67
|
+
const row = {};
|
|
68
|
+
const name = (0, asset_1.touched)(patch, 'name', old) ? (0, asset_1.textOf)(patch.name) : old.name;
|
|
69
|
+
if (!name)
|
|
70
|
+
throw new shell_1.Refusal('saas-account-name-required', {}, 'Name the service');
|
|
71
|
+
row.name = name;
|
|
72
|
+
for (const one of ['identifier', 'purpose', 'billingEmail', 'secretLocation', 'description'])
|
|
73
|
+
if ((0, asset_1.touched)(patch, one, old))
|
|
74
|
+
row[one] = (0, asset_1.textOf)(patch[one]);
|
|
75
|
+
if ((0, asset_1.touched)(patch, 'currency', old))
|
|
76
|
+
row.currency = currencyOf(patch.currency, 'KRW');
|
|
77
|
+
if ((0, asset_1.touched)(patch, 'counterpartyId', old))
|
|
78
|
+
row.counterparty = await oneOf(tx, biz_base_1.Counterparty, domain, patch.counterpartyId, 'saas-counterparty-not-found');
|
|
79
|
+
if ((0, asset_1.touched)(patch, 'paymentAccountId', old))
|
|
80
|
+
row.paymentAccount = await oneOf(tx, accounting_1.BankAccount, domain, patch.paymentAccountId, 'saas-payment-account-not-found');
|
|
81
|
+
if ((0, asset_1.touched)(patch, 'parentId', old)) {
|
|
82
|
+
const parent = await oneOf(tx, saas_account_1.SaasAccount, domain, patch.parentId, 'saas-parent-not-found');
|
|
83
|
+
if (parent && (parent.id === old?.id || (await tx.getRepository(saas_account_1.SaasAccount).findOne({ where: { id: parent.id }, relations: ['parent'] }))?.parent))
|
|
84
|
+
throw new shell_1.Refusal('saas-parent-invalid', {}, 'An account is under a top account only, and not under itself');
|
|
85
|
+
if (parent && old && (await tx.getRepository(saas_subscription_1.SaasSubscription).count({ where: { account: { id: old.id } } })))
|
|
86
|
+
throw new shell_1.Refusal('saas-parent-has-subscriptions', {}, 'An account with subscriptions is billed itself - it cannot go under another');
|
|
87
|
+
row.parent = parent;
|
|
88
|
+
}
|
|
89
|
+
if ((0, asset_1.touched)(patch, 'adminIds', old)) {
|
|
90
|
+
const ids = [...new Set((patch.adminIds ?? []).filter(Boolean))];
|
|
91
|
+
const admins = ids.length ? await tx.getRepository(organization_1.Employee).find({ where: { id: (0, typeorm_1.In)(ids), domain: { id: domain.id } } }) : [];
|
|
92
|
+
if (admins.length !== ids.length)
|
|
93
|
+
throw new shell_1.Refusal('saas-admin-not-found', {}, 'An admin is no employee of this domain');
|
|
94
|
+
row.admins = admins;
|
|
95
|
+
}
|
|
96
|
+
if ((0, asset_1.touched)(patch, 'status', old))
|
|
97
|
+
row.status = patch.status ?? saas_rules_1.SaasAccountStatus.ACTIVE;
|
|
98
|
+
if ((0, asset_1.touched)(patch, 'closedOn', old))
|
|
99
|
+
row.closedOn = (0, asset_1.dayOf)(patch.closedOn, 'saas-day-invalid');
|
|
100
|
+
if ((row.status ?? old?.status) === saas_rules_1.SaasAccountStatus.CLOSED && !(row.closedOn !== undefined ? row.closedOn : old?.closedOn))
|
|
101
|
+
throw new shell_1.Refusal('saas-closed-on-required', {}, 'Give the day it was closed');
|
|
102
|
+
await recordChanges(tx, domain, user, exports.SAAS_ACCOUNT_FACT, old, row, ACCOUNT_TRACKED);
|
|
103
|
+
return row;
|
|
104
|
+
}, 'saas-account-not-found');
|
|
105
|
+
return saved;
|
|
106
|
+
}
|
|
107
|
+
/* ----------------------------------------------------------------------------------------------------------------- */
|
|
108
|
+
/* Subscriptions (decision 3) - by keepers, and by the account's admins */
|
|
109
|
+
async function saveSaasSubscriptions(tx, domain, user, scope, accountId, patches) {
|
|
110
|
+
const account = await (0, saas_access_1.accountIn)(tx, domain, scope, accountId);
|
|
111
|
+
if (account.parentId && patches.some(one => one.cuFlag !== '-'))
|
|
112
|
+
throw new shell_1.Refusal('saas-subscription-on-sub-account', {}, 'An account under another is billed by its parent - subscribe there');
|
|
113
|
+
return (0, asset_1.applyPatches)(tx, saas_subscription_1.SaasSubscription, domain, user, patches, async (patch, old) => {
|
|
114
|
+
const row = old ? {} : { account };
|
|
115
|
+
const name = (0, asset_1.touched)(patch, 'name', old) ? (0, asset_1.textOf)(patch.name) : old.name;
|
|
116
|
+
if (!name)
|
|
117
|
+
throw new shell_1.Refusal('saas-subscription-name-required', {}, 'Name the product or plan');
|
|
118
|
+
row.name = name;
|
|
119
|
+
const billing = (field(patch, 'billing', old) ?? saas_rules_1.SaasBilling.FIXED);
|
|
120
|
+
if (!Object.values(saas_rules_1.SaasBilling).includes(billing))
|
|
121
|
+
throw new shell_1.Refusal('saas-billing-invalid', {}, 'Say how it is paid for');
|
|
122
|
+
row.billing = billing;
|
|
123
|
+
/* Reference only - the money is the recurring item's (개정 7-3). */
|
|
124
|
+
for (const one of ['quantity', 'unitPrice'])
|
|
125
|
+
if ((0, asset_1.touched)(patch, one, old))
|
|
126
|
+
row[one] = (0, asset_1.amountOf)(patch[one], 'saas-amount-invalid');
|
|
127
|
+
/* `vendorKey` and `trial` are a sync's (개정 2) - the GraphQL patch does not carry them. */
|
|
128
|
+
if ((0, asset_1.touched)(patch, 'vendorKey', old))
|
|
129
|
+
row.vendorKey = (0, asset_1.textOf)(patch.vendorKey);
|
|
130
|
+
if ((0, asset_1.touched)(patch, 'trial', old))
|
|
131
|
+
row.trial = patch.trial === true;
|
|
132
|
+
const value = (name) => (row[name] !== undefined ? row[name] : old?.[name]);
|
|
133
|
+
row.startOn = (0, asset_1.touched)(patch, 'startOn', old) ? (0, asset_1.dayOf)(patch.startOn, 'saas-start-on-invalid', true) : old.startOn;
|
|
134
|
+
if ((0, asset_1.touched)(patch, 'renewalOn', old))
|
|
135
|
+
row.renewalOn = (0, asset_1.dayOf)(patch.renewalOn, 'saas-day-invalid');
|
|
136
|
+
if ((0, asset_1.touched)(patch, 'endedOn', old))
|
|
137
|
+
row.endedOn = (0, asset_1.dayOf)(patch.endedOn, 'saas-day-invalid');
|
|
138
|
+
if ((0, asset_1.touched)(patch, 'autoRenew', old))
|
|
139
|
+
row.autoRenew = patch.autoRenew !== false;
|
|
140
|
+
if ((0, asset_1.touched)(patch, 'noticeDays', old))
|
|
141
|
+
row.noticeDays = intOf(patch.noticeDays, 'saas-notice-days-invalid', 0, 365);
|
|
142
|
+
if ((0, asset_1.touched)(patch, 'description', old))
|
|
143
|
+
row.description = (0, asset_1.textOf)(patch.description);
|
|
144
|
+
if ((0, asset_1.touched)(patch, 'departmentId', old))
|
|
145
|
+
row.department = await oneOf(tx, organization_1.Department, domain, patch.departmentId, 'saas-department-not-found');
|
|
146
|
+
if ((0, asset_1.touched)(patch, 'assetId', old))
|
|
147
|
+
row.asset = await oneOf(tx, asset_1.Asset, domain, patch.assetId, 'saas-asset-not-found');
|
|
148
|
+
if (billing === saas_rules_1.SaasBilling.OWNED && !(row.asset !== undefined ? row.asset : old?.assetId))
|
|
149
|
+
throw new shell_1.Refusal('saas-owned-asset-required', {}, 'A license owned points at its asset in the register');
|
|
150
|
+
if (billing === saas_rules_1.SaasBilling.COMMITMENT && !value('renewalOn'))
|
|
151
|
+
throw new shell_1.Refusal('saas-term-end-required', {}, 'A commitment takes the day its term ends');
|
|
152
|
+
if ((0, asset_1.touched)(patch, 'status', old))
|
|
153
|
+
row.status = patch.status ?? saas_rules_1.SaasSubscriptionStatus.ACTIVE;
|
|
154
|
+
const status = row.status ?? old?.status ?? saas_rules_1.SaasSubscriptionStatus.ACTIVE;
|
|
155
|
+
if (status === saas_rules_1.SaasSubscriptionStatus.CANCELLED && !value('endedOn'))
|
|
156
|
+
throw new shell_1.Refusal('saas-ended-on-required', {}, 'Give the day it ended');
|
|
157
|
+
if (status === saas_rules_1.SaasSubscriptionStatus.CANCELLING && !value('renewalOn'))
|
|
158
|
+
throw new shell_1.Refusal('saas-renewal-on-required', {}, 'Not renewing needs the day it would renew');
|
|
159
|
+
if (value('endedOn') && value('endedOn') < row.startOn)
|
|
160
|
+
throw new shell_1.Refusal('saas-ended-before-start', {}, 'It ended before it started');
|
|
161
|
+
await recordChanges(tx, domain, user, exports.SAAS_SUBSCRIPTION_FACT, old, row, SUBSCRIPTION_TRACKED);
|
|
162
|
+
return row;
|
|
163
|
+
}, 'saas-subscription-not-found', { account: { id: account.id } });
|
|
164
|
+
}
|
|
165
|
+
/** The subscriptions of an account, with the seats held today and the reference each makes. */
|
|
166
|
+
async function saasSubscriptionsOf(tx, domain, scope, accountId, today) {
|
|
167
|
+
const account = await (0, saas_access_1.accountIn)(tx, domain, scope, accountId);
|
|
168
|
+
const subs = await tx.getRepository(saas_subscription_1.SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: account.id } }, relations: ['department', 'asset'], order: { name: 'ASC' } });
|
|
169
|
+
const seats = subs.length ? await tx.getRepository(saas_seat_1.SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: (0, typeorm_1.In)(subs.map(one => one.id)) } } }) : [];
|
|
170
|
+
for (const sub of subs) {
|
|
171
|
+
sub.seatsHeld = seats.filter(seat => seat.subscriptionId === sub.id && (0, saas_rules_1.seatHeld)(seat, today)).length;
|
|
172
|
+
sub.referenceAmount = (0, saas_rules_1.referenceAmountOf)(sub);
|
|
173
|
+
}
|
|
174
|
+
return subs;
|
|
175
|
+
}
|
|
176
|
+
/* ----------------------------------------------------------------------------------------------------------------- */
|
|
177
|
+
/* Seats (decision 6) */
|
|
178
|
+
async function subscriptionIn(tx, domain, scope, subscriptionId) {
|
|
179
|
+
const sub = subscriptionId ? await tx.getRepository(saas_subscription_1.SaasSubscription).findOne({ where: { domain: { id: domain.id }, id: subscriptionId } }) : null;
|
|
180
|
+
if (!sub || (scope !== 'all' && !scope.has(sub.accountId)))
|
|
181
|
+
throw new shell_1.Refusal('saas-subscription-not-found', {}, 'The subscription was not found - reload and try again');
|
|
182
|
+
return sub;
|
|
183
|
+
}
|
|
184
|
+
async function saveSaasSeats(tx, domain, user, scope, subscriptionId, patches) {
|
|
185
|
+
const subscription = await subscriptionIn(tx, domain, scope, subscriptionId);
|
|
186
|
+
return (0, asset_1.applyPatches)(tx, saas_seat_1.SaasSeat, domain, user, patches, async (patch, old) => {
|
|
187
|
+
const row = old ? {} : { subscription };
|
|
188
|
+
if ((0, asset_1.touched)(patch, 'employeeId', old))
|
|
189
|
+
row.employee = await oneOf(tx, organization_1.Employee, domain, patch.employeeId, 'saas-seat-employee-not-found');
|
|
190
|
+
/* `login` is a sync's (개정 2) - the GraphQL patch does not carry it. */
|
|
191
|
+
for (const one of ['holder', 'login', 'description'])
|
|
192
|
+
if ((0, asset_1.touched)(patch, one, old))
|
|
193
|
+
row[one] = (0, asset_1.textOf)(patch[one]);
|
|
194
|
+
if (!(row.employee !== undefined ? row.employee : old?.employeeId) && !(row.holder !== undefined ? row.holder : old?.holder))
|
|
195
|
+
throw new shell_1.Refusal('saas-seat-holder-required', {}, 'Say who holds the seat - an employee, or a name');
|
|
196
|
+
if ((0, asset_1.touched)(patch, 'fromOn', old))
|
|
197
|
+
row.fromOn = (0, asset_1.dayOf)(patch.fromOn, 'saas-day-invalid');
|
|
198
|
+
if ((0, asset_1.touched)(patch, 'untilOn', old))
|
|
199
|
+
row.untilOn = (0, asset_1.dayOf)(patch.untilOn, 'saas-day-invalid');
|
|
200
|
+
const from = row.fromOn !== undefined ? row.fromOn : old?.fromOn;
|
|
201
|
+
const until = row.untilOn !== undefined ? row.untilOn : old?.untilOn;
|
|
202
|
+
if (from && until && until < from)
|
|
203
|
+
throw new shell_1.Refusal('saas-seat-until-before-from', {}, 'It was taken back before it was given');
|
|
204
|
+
return row;
|
|
205
|
+
}, 'saas-seat-not-found', { subscription: { id: subscription.id } });
|
|
206
|
+
}
|
|
207
|
+
async function saasSeatsOf(tx, domain, scope, subscriptionId) {
|
|
208
|
+
const sub = await subscriptionIn(tx, domain, scope, subscriptionId);
|
|
209
|
+
return tx.getRepository(saas_seat_1.SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: sub.id } }, relations: ['employee'], order: { fromOn: 'DESC' } });
|
|
210
|
+
}
|
|
211
|
+
/* ----------------------------------------------------------------------------------------------------------------- */
|
|
212
|
+
/* What moved on a row (decision 11) */
|
|
213
|
+
/** What moved on an account and on each of its subscriptions, newest first. */
|
|
214
|
+
async function saasChangesOf(tx, domain, scope, accountId) {
|
|
215
|
+
const account = await (0, saas_access_1.accountIn)(tx, domain, scope, accountId);
|
|
216
|
+
const subs = await tx.getRepository(saas_subscription_1.SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: account.id } }, withDeleted: true });
|
|
217
|
+
const rows = [
|
|
218
|
+
...(await (0, fact_change_1.readFactChanges)(tx, domain, exports.SAAS_ACCOUNT_FACT, account.id)).map(one => Object.assign(one, { subject: account.name })),
|
|
219
|
+
...(await Promise.all(subs.map(async (sub) => (await (0, fact_change_1.readFactChanges)(tx, domain, exports.SAAS_SUBSCRIPTION_FACT, sub.id)).map(one => Object.assign(one, { subject: sub.name }))))).flat()
|
|
220
|
+
];
|
|
221
|
+
return rows.sort((a, b) => new Date(b.at).getTime() - new Date(a.at).getTime());
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=saas-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saas-service.js","sourceRoot":"","sources":["../../server/service/saas-service.ts"],"names":[],"mappings":";;;AA0DA,4CAwCC;AAKD,sDA8CC;AAGD,kDASC;AAWD,sCAyBC;AAED,kCAGC;AAMD,sCAQC;AAxND,2DAAwD;AACxD,mHAAmH;AACnH,iDAAoG;AACpG,uDAAuD;AACvD,6DAA8F;AAC9F,+DAAmE;AACnE,iDAAuD;AACvD,qCAA2C;AAE3C,+CAAoD;AACpD,iDAA4C;AAC5C,6CAAkH;AAClH,2CAAsC;AACtC,2DAAsD;AAEtD,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,QAAuB,EAAE,EAAE;IACzD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACrD,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAA;IAC1B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,eAAO,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,IAAI,qCAAqC,CAAC,CAAA;IACxI,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,KAAU,EAAE,IAAY,EAAE,GAAW,EAAE,GAAW,EAAiB,EAAE;IAClF,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,K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7D,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,oCAAgB,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,EAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3J,MAAM,IAAI,GAAG;QACX,GAAG,CAAC,MAAM,IAAA,6BAAe,EAAC,EAAE,EAAE,MAAM,EAAE,yBAAiB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/H,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAC,GAAG,EAAC,EAAE,CAAC,CAAC,MAAM,IAAA,6BAAe,EAAC,EAAE,EAAE,MAAM,EAAE,8BAAsB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;KAChL,CAAA;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AACjF,CAAC","sourcesContent":["import { BankAccount } from '@things-factory/accounting'\n/* The register grids' save, the asset module's - this module saves its grids the same way (one implementation). */\nimport { amountOf, applyPatches, Asset, dayOf, Patch, textOf, touched } from '@things-factory/asset'\nimport { Counterparty } from '@things-factory/biz-base'\nimport { fieldChanges, readFactChanges, recordFactChanges } from '@things-factory/fact-change'\nimport { Department, Employee } from '@things-factory/organization'\nimport { Domain, Refusal } from '@things-factory/shell'\nimport { EntityManager, In } from 'typeorm'\n\nimport { accountIn, SaasScope } from './saas-access'\nimport { SaasAccount } from './saas-account'\nimport { referenceAmountOf, SaasAccountStatus, SaasBilling, SaasSubscriptionStatus, seatHeld } from './saas-rules'\nimport { SaasSeat } from './saas-seat'\nimport { SaasSubscription } from './saas-subscription'\n\nconst currencyOf = (value: any, fallback: string | null) => {\n const text = String(value ?? '').trim().toUpperCase()\n if (!text) return fallback\n if (!/^[A-Z]{3}$/.test(text)) throw new Refusal('saas-currency-invalid', { value: text }, `'${text}' is not a currency code (KRW, USD)`)\n return text\n}\n\nconst intOf = (value: any, code: string, min: number, max: number): number | null => {\n if (value === null || value === undefined || value === '') return null\n const number = Number(value)\n if (!Number.isInteger(number) || number < min || number > max) throw new Refusal(code, { min, max }, `Give a whole number from ${min} to ${max}`)\n return number\n}\n\nasync function oneOf<T>(tx: EntityManager, target: any, domain: Domain, id: string | null | undefined, code: string): Promise<T | null> {\n if (!id) return null\n const found = await tx.getRepository(target).findOne({ where: { domain: { id: domain.id }, id } as any })\n if (!found) throw new Refusal(code, {}, 'What it points at was not found')\n return found as T\n}\n\nconst field = (patch: Patch, name: string, old?: any) => (patch[name] !== undefined ? patch[name] : old?.[name])\n\n/*\n * What moved on an account or a subscription, field by field (ADR-0177 decision 11) - the fact-change module keeps it.\n * A row's relations are told by their id; a new row has no history yet.\n */\nexport const SAAS_ACCOUNT_FACT = 'saas-account'\nexport const SAAS_SUBSCRIPTION_FACT = 'saas-subscription'\nconst ACCOUNT_TRACKED = ['name', 'counterpartyId', 'identifier', 'parentId', 'paymentAccountId', 'currency', 'status', 'closedOn'] as const\nconst SUBSCRIPTION_TRACKED = ['name', 'billing', 'vendorKey', 'trial', 'quantity', 'unitPrice', 'startOn', 'renewalOn', 'autoRenew', 'noticeDays', 'departmentId', 'assetId', 'status', 'endedOn'] as const\nconst idsOf = (row: Record<string, any>) =>\n Object.fromEntries(Object.entries(row).map(([key, value]) => (value && typeof value === 'object' && 'id' in value ? [`${key}Id`, value.id] : value === null && ['counterparty', 'parent', 'paymentAccount', 'department', 'asset'].includes(key) ? [`${key}Id`, null] : [key, value])))\n\nasync function recordChanges(tx: EntityManager, domain: Domain, user: any, factKind: string, old: any, row: Record<string, any>, fields: readonly string[]) {\n if (!old) return\n const after = { ...old, ...idsOf(row) }\n await recordFactChanges(tx, domain, { factKind, factName: old.id, changes: fieldChanges(old, after, fields as any) }, { user, source: 'saas' })\n}\n\n/* ----------------------------------------------------------------------------------------------------------------- */\n/* Accounts (decision 2) - kept by `saas` keepers only */\n\nexport async function saveSaasAccounts(tx: EntityManager, domain: Domain, user: any, patches: Patch[]) {\n const saved = await applyPatches(\n tx,\n SaasAccount,\n domain,\n user,\n patches,\n async (patch, old) => {\n const row: Record<string, any> = {}\n const name = touched(patch, 'name', old) ? textOf(patch.name) : old!.name\n if (!name) throw new Refusal('saas-account-name-required', {}, 'Name the service')\n row.name = name\n for (const one of ['identifier', 'purpose', 'billingEmail', 'secretLocation', 'description']) if (touched(patch, one, old)) row[one] = textOf(patch[one])\n if (touched(patch, 'currency', old)) row.currency = currencyOf(patch.currency, 'KRW')\n if (touched(patch, 'counterpartyId', old)) row.counterparty = await oneOf(tx, Counterparty, domain, patch.counterpartyId, 'saas-counterparty-not-found')\n if (touched(patch, 'paymentAccountId', old)) row.paymentAccount = await oneOf(tx, BankAccount, domain, patch.paymentAccountId, 'saas-payment-account-not-found')\n if (touched(patch, 'parentId', old)) {\n const parent = await oneOf<SaasAccount>(tx, SaasAccount, domain, patch.parentId, 'saas-parent-not-found')\n if (parent && (parent.id === old?.id || (await tx.getRepository(SaasAccount).findOne({ where: { id: parent.id }, relations: ['parent'] }))?.parent))\n throw new Refusal('saas-parent-invalid', {}, 'An account is under a top account only, and not under itself')\n if (parent && old && (await tx.getRepository(SaasSubscription).count({ where: { account: { id: old.id } } as any })))\n throw new Refusal('saas-parent-has-subscriptions', {}, 'An account with subscriptions is billed itself - it cannot go under another')\n row.parent = parent\n }\n if (touched(patch, 'adminIds', old)) {\n const ids: string[] = [...new Set<string>((patch.adminIds ?? []).filter(Boolean))]\n const admins = ids.length ? await tx.getRepository(Employee).find({ where: { id: In(ids), domain: { id: domain.id } } as any }) : []\n if (admins.length !== ids.length) throw new Refusal('saas-admin-not-found', {}, 'An admin is no employee of this domain')\n row.admins = admins\n }\n if (touched(patch, 'status', old)) row.status = patch.status ?? SaasAccountStatus.ACTIVE\n if (touched(patch, 'closedOn', old)) row.closedOn = dayOf(patch.closedOn, 'saas-day-invalid')\n if ((row.status ?? old?.status) === SaasAccountStatus.CLOSED && !(row.closedOn !== undefined ? row.closedOn : old?.closedOn))\n throw new Refusal('saas-closed-on-required', {}, 'Give the day it was closed')\n await recordChanges(tx, domain, user, SAAS_ACCOUNT_FACT, old, row, ACCOUNT_TRACKED)\n return row\n },\n 'saas-account-not-found'\n )\n return saved\n}\n\n/* ----------------------------------------------------------------------------------------------------------------- */\n/* Subscriptions (decision 3) - by keepers, and by the account's admins */\n\nexport async function saveSaasSubscriptions(tx: EntityManager, domain: Domain, user: any, scope: SaasScope, accountId: string, patches: Patch[]) {\n const account = await accountIn(tx, domain, scope, accountId)\n if (account.parentId && patches.some(one => one.cuFlag !== '-'))\n throw new Refusal('saas-subscription-on-sub-account', {}, 'An account under another is billed by its parent - subscribe there')\n return applyPatches(\n tx,\n SaasSubscription,\n domain,\n user,\n patches,\n async (patch, old) => {\n const row: Record<string, any> = old ? {} : { account }\n const name = touched(patch, 'name', old) ? textOf(patch.name) : old!.name\n if (!name) throw new Refusal('saas-subscription-name-required', {}, 'Name the product or plan')\n row.name = name\n const billing = (field(patch, 'billing', old) ?? SaasBilling.FIXED) as SaasBilling\n if (!Object.values(SaasBilling).includes(billing)) throw new Refusal('saas-billing-invalid', {}, 'Say how it is paid for')\n row.billing = billing\n /* Reference only - the money is the recurring item's (개정 7-3). */\n for (const one of ['quantity', 'unitPrice']) if (touched(patch, one, old)) row[one] = amountOf(patch[one], 'saas-amount-invalid')\n /* `vendorKey` and `trial` are a sync's (개정 2) - the GraphQL patch does not carry them. */\n if (touched(patch, 'vendorKey', old)) row.vendorKey = textOf(patch.vendorKey)\n if (touched(patch, 'trial', old)) row.trial = patch.trial === true\n const value = (name: string) => (row[name] !== undefined ? row[name] : old?.[name])\n row.startOn = touched(patch, 'startOn', old) ? dayOf(patch.startOn, 'saas-start-on-invalid', true) : old!.startOn\n if (touched(patch, 'renewalOn', old)) row.renewalOn = dayOf(patch.renewalOn, 'saas-day-invalid')\n if (touched(patch, 'endedOn', old)) row.endedOn = dayOf(patch.endedOn, 'saas-day-invalid')\n if (touched(patch, 'autoRenew', old)) row.autoRenew = patch.autoRenew !== false\n if (touched(patch, 'noticeDays', old)) row.noticeDays = intOf(patch.noticeDays, 'saas-notice-days-invalid', 0, 365)\n if (touched(patch, 'description', old)) row.description = textOf(patch.description)\n if (touched(patch, 'departmentId', old)) row.department = await oneOf(tx, Department, domain, patch.departmentId, 'saas-department-not-found')\n if (touched(patch, 'assetId', old)) row.asset = await oneOf(tx, Asset, domain, patch.assetId, 'saas-asset-not-found')\n if (billing === SaasBilling.OWNED && !(row.asset !== undefined ? row.asset : old?.assetId))\n throw new Refusal('saas-owned-asset-required', {}, 'A license owned points at its asset in the register')\n if (billing === SaasBilling.COMMITMENT && !value('renewalOn')) throw new Refusal('saas-term-end-required', {}, 'A commitment takes the day its term ends')\n if (touched(patch, 'status', old)) row.status = patch.status ?? SaasSubscriptionStatus.ACTIVE\n const status = row.status ?? old?.status ?? SaasSubscriptionStatus.ACTIVE\n if (status === SaasSubscriptionStatus.CANCELLED && !value('endedOn')) throw new Refusal('saas-ended-on-required', {}, 'Give the day it ended')\n if (status === SaasSubscriptionStatus.CANCELLING && !value('renewalOn')) throw new Refusal('saas-renewal-on-required', {}, 'Not renewing needs the day it would renew')\n if (value('endedOn') && value('endedOn') < row.startOn) throw new Refusal('saas-ended-before-start', {}, 'It ended before it started')\n await recordChanges(tx, domain, user, SAAS_SUBSCRIPTION_FACT, old, row, SUBSCRIPTION_TRACKED)\n return row\n },\n 'saas-subscription-not-found',\n { account: { id: account.id } }\n )\n}\n\n/** The subscriptions of an account, with the seats held today and the reference each makes. */\nexport async function saasSubscriptionsOf(tx: EntityManager, domain: Domain, scope: SaasScope, accountId: string, today: string) {\n const account = await accountIn(tx, domain, scope, accountId)\n const subs = await tx.getRepository(SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: account.id } } as any, relations: ['department', 'asset'], order: { name: 'ASC' } as any })\n const seats = subs.length ? await tx.getRepository(SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: In(subs.map(one => one.id)) } } as any }) : []\n for (const sub of subs) {\n sub.seatsHeld = seats.filter(seat => seat.subscriptionId === sub.id && seatHeld(seat, today)).length\n sub.referenceAmount = referenceAmountOf(sub)\n }\n return subs\n}\n\n/* ----------------------------------------------------------------------------------------------------------------- */\n/* Seats (decision 6) */\n\nasync function subscriptionIn(tx: EntityManager, domain: Domain, scope: SaasScope, subscriptionId: string) {\n const sub = subscriptionId ? await tx.getRepository(SaasSubscription).findOne({ where: { domain: { id: domain.id }, id: subscriptionId } as any }) : null\n if (!sub || (scope !== 'all' && !scope.has(sub.accountId!))) throw new Refusal('saas-subscription-not-found', {}, 'The subscription was not found - reload and try again')\n return sub\n}\n\nexport async function saveSaasSeats(tx: EntityManager, domain: Domain, user: any, scope: SaasScope, subscriptionId: string, patches: Patch[]) {\n const subscription = await subscriptionIn(tx, domain, scope, subscriptionId)\n return applyPatches(\n tx,\n SaasSeat,\n domain,\n user,\n patches,\n async (patch, old) => {\n const row: Record<string, any> = old ? {} : { subscription }\n if (touched(patch, 'employeeId', old)) row.employee = await oneOf(tx, Employee, domain, patch.employeeId, 'saas-seat-employee-not-found')\n /* `login` is a sync's (개정 2) - the GraphQL patch does not carry it. */\n for (const one of ['holder', 'login', 'description']) if (touched(patch, one, old)) row[one] = textOf(patch[one])\n if (!(row.employee !== undefined ? row.employee : old?.employeeId) && !(row.holder !== undefined ? row.holder : old?.holder))\n throw new Refusal('saas-seat-holder-required', {}, 'Say who holds the seat - an employee, or a name')\n if (touched(patch, 'fromOn', old)) row.fromOn = dayOf(patch.fromOn, 'saas-day-invalid')\n if (touched(patch, 'untilOn', old)) row.untilOn = dayOf(patch.untilOn, 'saas-day-invalid')\n const from = row.fromOn !== undefined ? row.fromOn : old?.fromOn\n const until = row.untilOn !== undefined ? row.untilOn : old?.untilOn\n if (from && until && until < from) throw new Refusal('saas-seat-until-before-from', {}, 'It was taken back before it was given')\n return row\n },\n 'saas-seat-not-found',\n { subscription: { id: subscription.id } }\n )\n}\n\nexport async function saasSeatsOf(tx: EntityManager, domain: Domain, scope: SaasScope, subscriptionId: string) {\n const sub = await subscriptionIn(tx, domain, scope, subscriptionId)\n return tx.getRepository(SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: sub.id } } as any, relations: ['employee'], order: { fromOn: 'DESC' } as any })\n}\n\n/* ----------------------------------------------------------------------------------------------------------------- */\n/* What moved on a row (decision 11) */\n\n/** What moved on an account and on each of its subscriptions, newest first. */\nexport async function saasChangesOf(tx: EntityManager, domain: Domain, scope: SaasScope, accountId: string) {\n const account = await accountIn(tx, domain, scope, accountId)\n const subs = await tx.getRepository(SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: account.id } } as any, withDeleted: true })\n const rows = [\n ...(await readFactChanges(tx, domain, SAAS_ACCOUNT_FACT, account.id)).map(one => Object.assign(one, { subject: account.name })),\n ...(await Promise.all(subs.map(async sub => (await readFactChanges(tx, domain, SAAS_SUBSCRIPTION_FACT, sub.id)).map(one => Object.assign(one, { subject: sub.name }))))).flat()\n ]\n return rows.sort((a, b) => new Date(b.at).getTime() - new Date(a.at).getTime())\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Asset } from '@things-factory/asset';
|
|
2
|
+
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { Department } from '@things-factory/organization';
|
|
4
|
+
import { Domain } from '@things-factory/shell';
|
|
5
|
+
import { SaasAccount } from './saas-account';
|
|
6
|
+
import { SaasBilling, SaasSubscriptionStatus } from './saas-rules';
|
|
7
|
+
/**
|
|
8
|
+
* One thing under an account the domain decides on and can cancel (ADR-0177 decisions 1, 3): a plan with seats, a fixed
|
|
9
|
+
* fee, metered usage, a commitment for a term, or a license owned - which points at the asset register. Its quantity and
|
|
10
|
+
* unit price are for reference only: the money is the recurring item's (accounting), which a person compares it with
|
|
11
|
+
* (개정 7).
|
|
12
|
+
*/
|
|
13
|
+
export declare class SaasSubscription {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
domain?: Domain;
|
|
16
|
+
domainId?: string;
|
|
17
|
+
account?: SaasAccount;
|
|
18
|
+
accountId?: string;
|
|
19
|
+
name: string;
|
|
20
|
+
billing: SaasBilling;
|
|
21
|
+
vendorKey?: string;
|
|
22
|
+
trial: boolean;
|
|
23
|
+
quantity?: number;
|
|
24
|
+
unitPrice?: number;
|
|
25
|
+
startOn: string;
|
|
26
|
+
renewalOn?: string;
|
|
27
|
+
autoRenew: boolean;
|
|
28
|
+
noticeDays?: number;
|
|
29
|
+
department?: Department;
|
|
30
|
+
departmentId?: string;
|
|
31
|
+
asset?: Asset;
|
|
32
|
+
assetId?: string;
|
|
33
|
+
status: SaasSubscriptionStatus;
|
|
34
|
+
endedOn?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
seatsHeld?: number;
|
|
37
|
+
referenceAmount?: number | null;
|
|
38
|
+
createdAt?: Date;
|
|
39
|
+
updatedAt?: Date;
|
|
40
|
+
deletedAt?: Date;
|
|
41
|
+
creator?: User;
|
|
42
|
+
creatorId?: string;
|
|
43
|
+
updater?: User;
|
|
44
|
+
updaterId?: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaasSubscription = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const asset_1 = require("@things-factory/asset");
|
|
6
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
7
|
+
const organization_1 = require("@things-factory/organization");
|
|
8
|
+
const shell_1 = require("@things-factory/shell");
|
|
9
|
+
const type_graphql_1 = require("type-graphql");
|
|
10
|
+
const typeorm_1 = require("typeorm");
|
|
11
|
+
const saas_account_1 = require("./saas-account");
|
|
12
|
+
const saas_rules_1 = require("./saas-rules");
|
|
13
|
+
/**
|
|
14
|
+
* One thing under an account the domain decides on and can cancel (ADR-0177 decisions 1, 3): a plan with seats, a fixed
|
|
15
|
+
* fee, metered usage, a commitment for a term, or a license owned - which points at the asset register. Its quantity and
|
|
16
|
+
* unit price are for reference only: the money is the recurring item's (accounting), which a person compares it with
|
|
17
|
+
* (개정 7).
|
|
18
|
+
*/
|
|
19
|
+
let SaasSubscription = class SaasSubscription {
|
|
20
|
+
};
|
|
21
|
+
exports.SaasSubscription = SaasSubscription;
|
|
22
|
+
tslib_1.__decorate([
|
|
23
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
24
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { description: 'Unique identifier of the subscription' }),
|
|
25
|
+
tslib_1.__metadata("design:type", String)
|
|
26
|
+
], SaasSubscription.prototype, "id", void 0);
|
|
27
|
+
tslib_1.__decorate([
|
|
28
|
+
(0, typeorm_1.ManyToOne)(type => shell_1.Domain),
|
|
29
|
+
(0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true, description: 'The domain the subscription belongs to' }),
|
|
30
|
+
tslib_1.__metadata("design:type", shell_1.Domain)
|
|
31
|
+
], SaasSubscription.prototype, "domain", void 0);
|
|
32
|
+
tslib_1.__decorate([
|
|
33
|
+
(0, typeorm_1.RelationId)((sub) => sub.domain),
|
|
34
|
+
tslib_1.__metadata("design:type", String)
|
|
35
|
+
], SaasSubscription.prototype, "domainId", void 0);
|
|
36
|
+
tslib_1.__decorate([
|
|
37
|
+
(0, typeorm_1.ManyToOne)(type => saas_account_1.SaasAccount, { onDelete: 'CASCADE' }),
|
|
38
|
+
(0, type_graphql_1.Field)(type => saas_account_1.SaasAccount, { nullable: true, description: 'The account it is under' }),
|
|
39
|
+
tslib_1.__metadata("design:type", saas_account_1.SaasAccount)
|
|
40
|
+
], SaasSubscription.prototype, "account", void 0);
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, typeorm_1.RelationId)((sub) => sub.account),
|
|
43
|
+
tslib_1.__metadata("design:type", String)
|
|
44
|
+
], SaasSubscription.prototype, "accountId", void 0);
|
|
45
|
+
tslib_1.__decorate([
|
|
46
|
+
(0, typeorm_1.Column)(),
|
|
47
|
+
(0, type_graphql_1.Field)({ description: 'The product and plan - Microsoft 365 Business Standard, AWS usage, Savings Plan 1 year, example.com' }),
|
|
48
|
+
tslib_1.__metadata("design:type", String)
|
|
49
|
+
], SaasSubscription.prototype, "name", void 0);
|
|
50
|
+
tslib_1.__decorate([
|
|
51
|
+
(0, typeorm_1.Column)({ default: saas_rules_1.SaasBilling.FIXED }),
|
|
52
|
+
(0, type_graphql_1.Field)(type => saas_rules_1.SaasBilling, { description: 'How it is paid for' }),
|
|
53
|
+
tslib_1.__metadata("design:type", String)
|
|
54
|
+
], SaasSubscription.prototype, "billing", void 0);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
57
|
+
(0, type_graphql_1.Field)({ nullable: true, description: "The vendor's id for the plan - a Microsoft 365 SKU id; set by a sync, which keeps its seats and quantity" }),
|
|
58
|
+
tslib_1.__metadata("design:type", String)
|
|
59
|
+
], SaasSubscription.prototype, "vendorKey", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, typeorm_1.Column)({ default: false }),
|
|
62
|
+
(0, type_graphql_1.Field)({ description: 'A trial the vendor hands out - it ends on its renewal day unless bought; set by a sync' }),
|
|
63
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
64
|
+
], SaasSubscription.prototype, "trial", void 0);
|
|
65
|
+
tslib_1.__decorate([
|
|
66
|
+
(0, typeorm_1.Column)((0, shell_1.quantityColumn)({ nullable: true })),
|
|
67
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Seats or units' }),
|
|
68
|
+
tslib_1.__metadata("design:type", Number)
|
|
69
|
+
], SaasSubscription.prototype, "quantity", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, typeorm_1.Column)({ ...(0, shell_1.moneyColumn)(), nullable: true }),
|
|
72
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'The price of one seat or unit, or the fee - for reference only' }),
|
|
73
|
+
tslib_1.__metadata("design:type", Number)
|
|
74
|
+
], SaasSubscription.prototype, "unitPrice", void 0);
|
|
75
|
+
tslib_1.__decorate([
|
|
76
|
+
(0, typeorm_1.Column)(),
|
|
77
|
+
(0, type_graphql_1.Field)({ description: 'The day it started - YYYY-MM-DD' }),
|
|
78
|
+
tslib_1.__metadata("design:type", String)
|
|
79
|
+
], SaasSubscription.prototype, "startOn", void 0);
|
|
80
|
+
tslib_1.__decorate([
|
|
81
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
82
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The day it renews or its term ends - YYYY-MM-DD; a domain’s expiry' }),
|
|
83
|
+
tslib_1.__metadata("design:type", String)
|
|
84
|
+
], SaasSubscription.prototype, "renewalOn", void 0);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, typeorm_1.Column)({ default: true }),
|
|
87
|
+
(0, type_graphql_1.Field)({ description: 'Whether the vendor renews it unless cancelled' }),
|
|
88
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
89
|
+
], SaasSubscription.prototype, "autoRenew", void 0);
|
|
90
|
+
tslib_1.__decorate([
|
|
91
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
92
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'How many days before renewal it must be cancelled - told from then' }),
|
|
93
|
+
tslib_1.__metadata("design:type", Number)
|
|
94
|
+
], SaasSubscription.prototype, "noticeDays", void 0);
|
|
95
|
+
tslib_1.__decorate([
|
|
96
|
+
(0, typeorm_1.ManyToOne)(type => organization_1.Department, { nullable: true, onDelete: 'SET NULL' }),
|
|
97
|
+
(0, type_graphql_1.Field)(type => organization_1.Department, { nullable: true, description: 'The department it is for - its cost when no seat says whose' }),
|
|
98
|
+
tslib_1.__metadata("design:type", organization_1.Department)
|
|
99
|
+
], SaasSubscription.prototype, "department", void 0);
|
|
100
|
+
tslib_1.__decorate([
|
|
101
|
+
(0, typeorm_1.RelationId)((sub) => sub.department),
|
|
102
|
+
tslib_1.__metadata("design:type", String)
|
|
103
|
+
], SaasSubscription.prototype, "departmentId", void 0);
|
|
104
|
+
tslib_1.__decorate([
|
|
105
|
+
(0, typeorm_1.ManyToOne)(type => asset_1.Asset, { nullable: true, onDelete: 'SET NULL' }),
|
|
106
|
+
(0, type_graphql_1.Field)(type => asset_1.Asset, { nullable: true, description: 'For a license owned: the asset of the register that carries its cost' }),
|
|
107
|
+
tslib_1.__metadata("design:type", asset_1.Asset)
|
|
108
|
+
], SaasSubscription.prototype, "asset", void 0);
|
|
109
|
+
tslib_1.__decorate([
|
|
110
|
+
(0, typeorm_1.RelationId)((sub) => sub.asset),
|
|
111
|
+
tslib_1.__metadata("design:type", String)
|
|
112
|
+
], SaasSubscription.prototype, "assetId", void 0);
|
|
113
|
+
tslib_1.__decorate([
|
|
114
|
+
(0, typeorm_1.Column)({ default: saas_rules_1.SaasSubscriptionStatus.ACTIVE }),
|
|
115
|
+
(0, type_graphql_1.Field)(type => saas_rules_1.SaasSubscriptionStatus, { description: 'In use, not to be renewed, or ended' }),
|
|
116
|
+
tslib_1.__metadata("design:type", String)
|
|
117
|
+
], SaasSubscription.prototype, "status", void 0);
|
|
118
|
+
tslib_1.__decorate([
|
|
119
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
120
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The day it ended - YYYY-MM-DD' }),
|
|
121
|
+
tslib_1.__metadata("design:type", String)
|
|
122
|
+
], SaasSubscription.prototype, "endedOn", void 0);
|
|
123
|
+
tslib_1.__decorate([
|
|
124
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
125
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
126
|
+
tslib_1.__metadata("design:type", String)
|
|
127
|
+
], SaasSubscription.prototype, "description", void 0);
|
|
128
|
+
tslib_1.__decorate([
|
|
129
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'How many seats are held today - filled by the list query' }),
|
|
130
|
+
tslib_1.__metadata("design:type", Number)
|
|
131
|
+
], SaasSubscription.prototype, "seatsHeld", void 0);
|
|
132
|
+
tslib_1.__decorate([
|
|
133
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'What its quantity and unit price make - for reference against the recurring item; filled by the query' }),
|
|
134
|
+
tslib_1.__metadata("design:type", Number)
|
|
135
|
+
], SaasSubscription.prototype, "referenceAmount", void 0);
|
|
136
|
+
tslib_1.__decorate([
|
|
137
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
138
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When the subscription was registered' }),
|
|
139
|
+
tslib_1.__metadata("design:type", Date)
|
|
140
|
+
], SaasSubscription.prototype, "createdAt", void 0);
|
|
141
|
+
tslib_1.__decorate([
|
|
142
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
143
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When the subscription last changed' }),
|
|
144
|
+
tslib_1.__metadata("design:type", Date)
|
|
145
|
+
], SaasSubscription.prototype, "updatedAt", void 0);
|
|
146
|
+
tslib_1.__decorate([
|
|
147
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
148
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When the subscription was deleted' }),
|
|
149
|
+
tslib_1.__metadata("design:type", Date)
|
|
150
|
+
], SaasSubscription.prototype, "deletedAt", void 0);
|
|
151
|
+
tslib_1.__decorate([
|
|
152
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
153
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who registered it' }),
|
|
154
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
155
|
+
], SaasSubscription.prototype, "creator", void 0);
|
|
156
|
+
tslib_1.__decorate([
|
|
157
|
+
(0, typeorm_1.RelationId)((sub) => sub.creator),
|
|
158
|
+
tslib_1.__metadata("design:type", String)
|
|
159
|
+
], SaasSubscription.prototype, "creatorId", void 0);
|
|
160
|
+
tslib_1.__decorate([
|
|
161
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
162
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who last changed it' }),
|
|
163
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
164
|
+
], SaasSubscription.prototype, "updater", void 0);
|
|
165
|
+
tslib_1.__decorate([
|
|
166
|
+
(0, typeorm_1.RelationId)((sub) => sub.updater),
|
|
167
|
+
tslib_1.__metadata("design:type", String)
|
|
168
|
+
], SaasSubscription.prototype, "updaterId", void 0);
|
|
169
|
+
exports.SaasSubscription = SaasSubscription = tslib_1.__decorate([
|
|
170
|
+
(0, typeorm_1.Entity)(),
|
|
171
|
+
(0, typeorm_1.Index)('ix_saas_subscription_0', (sub) => [sub.domain, sub.account]),
|
|
172
|
+
(0, type_graphql_1.ObjectType)({ description: 'Entity for SaasSubscription — a plan, fee, usage, commitment or owned license under an account' })
|
|
173
|
+
], SaasSubscription);
|
|
174
|
+
//# sourceMappingURL=saas-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saas-subscription.js","sourceRoot":"","sources":["../../server/service/saas-subscription.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,yDAAgD;AAChD,+DAAyD;AACzD,iDAA2E;AAC3E,+CAAgE;AAChE,qCAAoJ;AAEpJ,iDAA4C;AAC5C,6CAAkE;AAElE;;;;;GAKG;AAII,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAoH5B,CAAA;AApHY,4CAAgB;AAGlB;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC;;4CACzD;AAInB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IACzB,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;sCACxF,cAAM;gDAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,GAAqB,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;;kDACjC;AAIjB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,0BAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACvD,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,0BAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;sCAC7E,0BAAW;iDAAA;AAGrB;IADC,IAAA,oBAAU,EAAC,CAAC,GAAqB,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;m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C,EAAE,CAAC;sCAChE,IAAI;mDAAA;AAIhB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;sCAChE,gBAAI;iDAAA;AAGd;IADC,IAAA,oBAAU,EAAC,CAAC,GAAqB,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;mDACjC;AAIlB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;sCAClE,gBAAI;iDAAA;AAGd;IADC,IAAA,oBAAU,EAAC,CAAC,GAAqB,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;mDACjC;2BAnHP,gBAAgB;IAH5B,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,wBAAwB,EAAE,CAAC,GAAqB,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrF,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,gGAAgG,EAAE,CAAC;GACjH,gBAAgB,CAoH5B","sourcesContent":["import { Asset } from '@things-factory/asset'\nimport { User } from '@things-factory/auth-base'\nimport { Department } from '@things-factory/organization'\nimport { Domain, moneyColumn, quantityColumn } from '@things-factory/shell'\nimport { Field, Float, ID, Int, ObjectType } from 'type-graphql'\nimport { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'\n\nimport { SaasAccount } from './saas-account'\nimport { SaasBilling, SaasSubscriptionStatus } from './saas-rules'\n\n/**\n * One thing under an account the domain decides on and can cancel (ADR-0177 decisions 1, 3): a plan with seats, a fixed\n * fee, metered usage, a commitment for a term, or a license owned - which points at the asset register. Its quantity and\n * unit price are for reference only: the money is the recurring item's (accounting), which a person compares it with\n * (개정 7).\n */\n@Entity()\n@Index('ix_saas_subscription_0', (sub: SaasSubscription) => [sub.domain, sub.account])\n@ObjectType({ description: 'Entity for SaasSubscription — a plan, fee, usage, commitment or owned license under an account' })\nexport class SaasSubscription {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier of the subscription' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true, description: 'The domain the subscription belongs to' })\n domain?: Domain\n\n @RelationId((sub: SaasSubscription) => sub.domain)\n domainId?: string\n\n @ManyToOne(type => SaasAccount, { onDelete: 'CASCADE' })\n @Field(type => SaasAccount, { nullable: true, description: 'The account it is under' })\n account?: SaasAccount\n\n @RelationId((sub: SaasSubscription) => sub.account)\n accountId?: string\n\n @Column()\n @Field({ description: 'The product and plan - Microsoft 365 Business Standard, AWS usage, Savings Plan 1 year, example.com' })\n name: string\n\n @Column({ default: SaasBilling.FIXED })\n @Field(type => SaasBilling, { description: 'How it is paid for' })\n billing: SaasBilling\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: \"The vendor's id for the plan - a Microsoft 365 SKU id; set by a sync, which keeps its seats and quantity\" })\n vendorKey?: string\n\n @Column({ default: false })\n @Field({ description: 'A trial the vendor hands out - it ends on its renewal day unless bought; set by a sync' })\n trial: boolean\n\n @Column(quantityColumn({ nullable: true }))\n @Field(type => Float, { nullable: true, description: 'Seats or units' })\n quantity?: number\n\n @Column({ ...moneyColumn(), nullable: true })\n @Field(type => Float, { nullable: true, description: 'The price of one seat or unit, or the fee - for reference only' })\n unitPrice?: number\n\n @Column()\n @Field({ description: 'The day it started - YYYY-MM-DD' })\n startOn: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The day it renews or its term ends - YYYY-MM-DD; a domain’s expiry' })\n renewalOn?: string\n\n @Column({ default: true })\n @Field({ description: 'Whether the vendor renews it unless cancelled' })\n autoRenew: boolean\n\n @Column({ type: 'int', nullable: true })\n @Field(type => Int, { nullable: true, description: 'How many days before renewal it must be cancelled - told from then' })\n noticeDays?: number\n\n @ManyToOne(type => Department, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => Department, { nullable: true, description: 'The department it is for - its cost when no seat says whose' })\n department?: Department\n\n @RelationId((sub: SaasSubscription) => sub.department)\n departmentId?: string\n\n @ManyToOne(type => Asset, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => Asset, { nullable: true, description: 'For a license owned: the asset of the register that carries its cost' })\n asset?: Asset\n\n @RelationId((sub: SaasSubscription) => sub.asset)\n assetId?: string\n\n @Column({ default: SaasSubscriptionStatus.ACTIVE })\n @Field(type => SaasSubscriptionStatus, { description: 'In use, not to be renewed, or ended' })\n status: SaasSubscriptionStatus\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The day it ended - YYYY-MM-DD' })\n endedOn?: string\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'Notes' })\n description?: string\n\n @Field(type => Int, { nullable: true, description: 'How many seats are held today - filled by the list query' })\n seatsHeld?: number\n\n @Field(type => Float, { nullable: true, description: 'What its quantity and unit price make - for reference against the recurring item; filled by the query' })\n referenceAmount?: number | null\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'When the subscription was registered' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'When the subscription last changed' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'When the subscription was deleted' })\n deletedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who registered it' })\n creator?: User\n\n @RelationId((sub: SaasSubscription) => sub.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who last changed it' })\n updater?: User\n\n @RelationId((sub: SaasSubscription) => sub.updater)\n updaterId?: string\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Domain } from '@things-factory/shell';
|
|
2
|
+
import { EntityManager } from 'typeorm';
|
|
3
|
+
export interface LicenseFacts {
|
|
4
|
+
tenantId?: string | null;
|
|
5
|
+
domains?: string[] | null;
|
|
6
|
+
skus: {
|
|
7
|
+
skuId: string;
|
|
8
|
+
name: string;
|
|
9
|
+
enabled: number;
|
|
10
|
+
consumed: number;
|
|
11
|
+
renewalOn?: string | null;
|
|
12
|
+
trial?: boolean | null;
|
|
13
|
+
}[];
|
|
14
|
+
users: {
|
|
15
|
+
login: string;
|
|
16
|
+
mail?: string | null;
|
|
17
|
+
name?: string | null;
|
|
18
|
+
enabled?: boolean | null;
|
|
19
|
+
skuIds: string[];
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
export interface LicenseSyncResult {
|
|
23
|
+
accountId: string;
|
|
24
|
+
accountName: string;
|
|
25
|
+
subscriptions: number;
|
|
26
|
+
created: number;
|
|
27
|
+
opened: number;
|
|
28
|
+
closed: number;
|
|
29
|
+
/** Open seats held as names that took their employee. */
|
|
30
|
+
linked: number;
|
|
31
|
+
/** Logins no employee's mail matched - held as names. */
|
|
32
|
+
unmatched: string[];
|
|
33
|
+
}
|
|
34
|
+
export declare function syncSaasLicenses(tx: EntityManager, domain: Domain, user: any, facts: LicenseFacts, today: string): Promise<LicenseSyncResult>;
|