@things-factory/saas 10.1.248 → 10.1.249

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 (66) hide show
  1. package/dist-client/bootstrap.d.ts +1 -0
  2. package/dist-client/bootstrap.js +5 -0
  3. package/dist-client/bootstrap.js.map +1 -0
  4. package/dist-client/entity360/saas-account-360.d.ts +11 -0
  5. package/dist-client/entity360/saas-account-360.js +178 -0
  6. package/dist-client/entity360/saas-account-360.js.map +1 -0
  7. package/dist-client/index.d.ts +1 -0
  8. package/dist-client/index.js +2 -0
  9. package/dist-client/index.js.map +1 -0
  10. package/dist-client/pages/saas-account-list.d.ts +57 -0
  11. package/dist-client/pages/saas-account-list.js +169 -0
  12. package/dist-client/pages/saas-account-list.js.map +1 -0
  13. package/dist-client/pages/saas-account-page.d.ts +52 -0
  14. package/dist-client/pages/saas-account-page.js +332 -0
  15. package/dist-client/pages/saas-account-page.js.map +1 -0
  16. package/dist-client/route.d.ts +1 -0
  17. package/dist-client/route.js +13 -0
  18. package/dist-client/route.js.map +1 -0
  19. package/dist-client/tsconfig.tsbuildinfo +1 -0
  20. package/dist-client/words.d.ts +34 -0
  21. package/dist-client/words.js +22 -0
  22. package/dist-client/words.js.map +1 -0
  23. package/dist-server/index.d.ts +1 -0
  24. package/dist-server/index.js +9 -0
  25. package/dist-server/index.js.map +1 -0
  26. package/dist-server/role-tasks.d.ts +2 -0
  27. package/dist-server/role-tasks.js +18 -0
  28. package/dist-server/role-tasks.js.map +1 -0
  29. package/dist-server/service/checks.d.ts +27 -0
  30. package/dist-server/service/checks.js +70 -0
  31. package/dist-server/service/checks.js.map +1 -0
  32. package/dist-server/service/index.d.ts +18 -0
  33. package/dist-server/service/index.js +34 -0
  34. package/dist-server/service/index.js.map +1 -0
  35. package/dist-server/service/saas-access.d.ts +20 -0
  36. package/dist-server/service/saas-access.js +36 -0
  37. package/dist-server/service/saas-access.js.map +1 -0
  38. package/dist-server/service/saas-account.d.ts +39 -0
  39. package/dist-server/service/saas-account.js +151 -0
  40. package/dist-server/service/saas-account.js.map +1 -0
  41. package/dist-server/service/saas-mutation.d.ts +10 -0
  42. package/dist-server/service/saas-mutation.js +87 -0
  43. package/dist-server/service/saas-mutation.js.map +1 -0
  44. package/dist-server/service/saas-query.d.ts +21 -0
  45. package/dist-server/service/saas-query.js +168 -0
  46. package/dist-server/service/saas-query.js.map +1 -0
  47. package/dist-server/service/saas-rules.d.ts +41 -0
  48. package/dist-server/service/saas-rules.js +62 -0
  49. package/dist-server/service/saas-rules.js.map +1 -0
  50. package/dist-server/service/saas-seat.d.ts +26 -0
  51. package/dist-server/service/saas-seat.js +110 -0
  52. package/dist-server/service/saas-seat.js.map +1 -0
  53. package/dist-server/service/saas-service.d.ts +19 -0
  54. package/dist-server/service/saas-service.js +223 -0
  55. package/dist-server/service/saas-service.js.map +1 -0
  56. package/dist-server/service/saas-subscription.d.ts +45 -0
  57. package/dist-server/service/saas-subscription.js +174 -0
  58. package/dist-server/service/saas-subscription.js.map +1 -0
  59. package/dist-server/service/saas-sync.d.ts +34 -0
  60. package/dist-server/service/saas-sync.js +106 -0
  61. package/dist-server/service/saas-sync.js.map +1 -0
  62. package/dist-server/service/saas-type.d.ts +89 -0
  63. package/dist-server/service/saas-type.js +338 -0
  64. package/dist-server/service/saas-type.js.map +1 -0
  65. package/dist-server/tsconfig.tsbuildinfo +1 -0
  66. package/package.json +4 -4
@@ -0,0 +1,27 @@
1
+ import { Domain } from '@things-factory/shell';
2
+ import { EntityManager } from 'typeorm';
3
+ import { SaasAccount } from './saas-account';
4
+ import { SaasSeat } from './saas-seat';
5
+ import { SaasSubscription } from './saas-subscription';
6
+ /** Subscriptions in use whose renewal is near - from their notice days before it to the day (decision 7). */
7
+ export declare function saasRenewalsDue(tx: EntityManager, domain: Domain, today: string): Promise<{
8
+ subscription: SaasSubscription;
9
+ account: SaasAccount;
10
+ }[]>;
11
+ /** Seats still held by people who have retired. */
12
+ export declare function saasSeatsOfLeavers(tx: EntityManager, domain: Domain, today: string): Promise<{
13
+ seat: SaasSeat;
14
+ subscription: SaasSubscription;
15
+ account: SaasAccount;
16
+ }[]>;
17
+ /** Accounts in use with nobody left to administer them - no admin named, or every admin retired. */
18
+ export declare function saasAccountsWithoutAdmin(tx: EntityManager, domain: Domain, today: string): Promise<SaasAccount[]>;
19
+ /**
20
+ * Seat plans in use whose seats held today are not as many as bought. A plan with no price is left out - a
21
+ * free or trial plan a tenant hands out (1,000,000 Power BI Free) costs nothing unused (ADR-0177 개정 2, the user 10-31).
22
+ */
23
+ export declare function saasSeatCountsDiffer(tx: EntityManager, domain: Domain, today: string): Promise<{
24
+ subscription: SaasSubscription;
25
+ account: SaasAccount;
26
+ held: number;
27
+ }[]>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.saasRenewalsDue = saasRenewalsDue;
4
+ exports.saasSeatsOfLeavers = saasSeatsOfLeavers;
5
+ exports.saasAccountsWithoutAdmin = saasAccountsWithoutAdmin;
6
+ exports.saasSeatCountsDiffer = saasSeatCountsDiffer;
7
+ const organization_1 = require("@things-factory/organization");
8
+ const typeorm_1 = require("typeorm");
9
+ const saas_account_1 = require("./saas-account");
10
+ const saas_rules_1 = require("./saas-rules");
11
+ const saas_seat_1 = require("./saas-seat");
12
+ const saas_subscription_1 = require("./saas-subscription");
13
+ /*
14
+ * The subscriptions' part of an application's management check (ADR-0177 decisions 6, 7): judged here, counted there.
15
+ * Each takes the day it judges on.
16
+ */
17
+ /** The employees who have retired by a day. */
18
+ async function retiredOf(tx, domain, ids, today) {
19
+ if (!ids.length)
20
+ return new Set();
21
+ const employees = await tx.getRepository(organization_1.Employee).find({ where: { domain: { id: domain.id }, id: (0, typeorm_1.In)(ids) } });
22
+ return new Set(employees.filter(one => one.retiredOn && one.retiredOn <= today).map(one => one.id));
23
+ }
24
+ async function inUse(tx, domain) {
25
+ const accounts = await tx.getRepository(saas_account_1.SaasAccount).find({ where: { domain: { id: domain.id }, status: saas_rules_1.SaasAccountStatus.ACTIVE }, relations: ['admins'] });
26
+ const subs = accounts.length
27
+ ? await tx.getRepository(saas_subscription_1.SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: (0, typeorm_1.In)(accounts.map(one => one.id)) }, status: (0, typeorm_1.In)([saas_rules_1.SaasSubscriptionStatus.ACTIVE, saas_rules_1.SaasSubscriptionStatus.CANCELLING]) } })
28
+ : [];
29
+ return { accounts, subs };
30
+ }
31
+ /** Subscriptions in use whose renewal is near - from their notice days before it to the day (decision 7). */
32
+ async function saasRenewalsDue(tx, domain, today) {
33
+ const { accounts, subs } = await inUse(tx, domain);
34
+ return subs.filter(sub => (0, saas_rules_1.renewalDue)(sub, today)).map(sub => ({ subscription: sub, account: accounts.find(one => one.id === sub.accountId) }));
35
+ }
36
+ /** Seats still held by people who have retired. */
37
+ async function saasSeatsOfLeavers(tx, domain, today) {
38
+ const { accounts, subs } = await inUse(tx, domain);
39
+ if (!subs.length)
40
+ return [];
41
+ const seats = (await tx.getRepository(saas_seat_1.SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: (0, typeorm_1.In)(subs.map(one => one.id)) } }, relations: ['employee'] })).filter(seat => seat.employeeId && (0, saas_rules_1.seatHeld)(seat, today));
42
+ const retired = await retiredOf(tx, domain, [...new Set(seats.map(one => one.employeeId))], today);
43
+ return seats
44
+ .filter(seat => retired.has(seat.employeeId))
45
+ .map(seat => {
46
+ const subscription = subs.find(one => one.id === seat.subscriptionId);
47
+ return { seat, subscription, account: accounts.find(one => one.id === subscription.accountId) };
48
+ });
49
+ }
50
+ /** Accounts in use with nobody left to administer them - no admin named, or every admin retired. */
51
+ async function saasAccountsWithoutAdmin(tx, domain, today) {
52
+ const { accounts } = await inUse(tx, domain);
53
+ const retired = await retiredOf(tx, domain, [...new Set(accounts.flatMap(one => (one.admins ?? []).map(admin => admin.id)))], today);
54
+ return accounts.filter(account => !(account.admins ?? []).some(admin => !retired.has(admin.id)));
55
+ }
56
+ /**
57
+ * Seat plans in use whose seats held today are not as many as bought. A plan with no price is left out - a
58
+ * free or trial plan a tenant hands out (1,000,000 Power BI Free) costs nothing unused (ADR-0177 개정 2, the user 10-31).
59
+ */
60
+ async function saasSeatCountsDiffer(tx, domain, today) {
61
+ const { accounts, subs } = await inUse(tx, domain);
62
+ const plans = subs.filter(one => one.billing === saas_rules_1.SaasBilling.SEAT && one.startOn <= today && one.unitPrice !== null && one.unitPrice !== undefined);
63
+ if (!plans.length)
64
+ return [];
65
+ const seats = await tx.getRepository(saas_seat_1.SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: (0, typeorm_1.In)(plans.map(one => one.id)) } } });
66
+ return plans
67
+ .map(sub => ({ subscription: sub, account: accounts.find(one => one.id === sub.accountId), held: seats.filter(seat => seat.subscriptionId === sub.id && (0, saas_rules_1.seatHeld)(seat, today)).length }))
68
+ .filter(one => one.held !== Number(one.subscription.quantity ?? 0));
69
+ }
70
+ //# sourceMappingURL=checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.js","sourceRoot":"","sources":["../../server/service/checks.ts"],"names":[],"mappings":";;AA8BA,0CAGC;AAGD,gDAaC;AAGD,4DAIC;AAMD,oDAQC;AAtED,+DAAuD;AAEvD,qCAA2C;AAE3C,iDAA4C;AAC5C,6CAA2G;AAC3G,2CAAsC;AACtC,2DAAsD;AAEtD;;;GAGG;AAEH,+CAA+C;AAC/C,KAAK,UAAU,SAAS,CAAC,EAAiB,EAAE,MAAc,EAAE,GAAa,EAAE,KAAa;IACtF,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,IAAI,GAAG,EAAE,CAAA;IACjC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uBAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAA,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,MAAM,EAAE,CAAC,CAAC;SACzL,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAA;AACvE,CAAC","sourcesContent":["import { Employee } from '@things-factory/organization'\nimport { Domain } from '@things-factory/shell'\nimport { EntityManager, In } from 'typeorm'\n\nimport { SaasAccount } from './saas-account'\nimport { renewalDue, SaasAccountStatus, SaasBilling, SaasSubscriptionStatus, seatHeld } from './saas-rules'\nimport { SaasSeat } from './saas-seat'\nimport { SaasSubscription } from './saas-subscription'\n\n/*\n * The subscriptions' part of an application's management check (ADR-0177 decisions 6, 7): judged here, counted there.\n * Each takes the day it judges on.\n */\n\n/** The employees who have retired by a day. */\nasync function retiredOf(tx: EntityManager, domain: Domain, ids: string[], today: string): Promise<Set<string>> {\n if (!ids.length) return new Set()\n const employees = await tx.getRepository(Employee).find({ where: { domain: { id: domain.id }, id: In(ids) } as any })\n return new Set(employees.filter(one => one.retiredOn && one.retiredOn <= today).map(one => one.id))\n}\n\nasync function inUse(tx: EntityManager, domain: Domain) {\n const accounts = await tx.getRepository(SaasAccount).find({ where: { domain: { id: domain.id }, status: SaasAccountStatus.ACTIVE } as any, relations: ['admins'] })\n const subs = accounts.length\n ? await tx.getRepository(SaasSubscription).find({ where: { domain: { id: domain.id }, account: { id: In(accounts.map(one => one.id)) }, status: In([SaasSubscriptionStatus.ACTIVE, SaasSubscriptionStatus.CANCELLING]) } as any })\n : []\n return { accounts, subs }\n}\n\n/** Subscriptions in use whose renewal is near - from their notice days before it to the day (decision 7). */\nexport async function saasRenewalsDue(tx: EntityManager, domain: Domain, today: string) {\n const { accounts, subs } = await inUse(tx, domain)\n return subs.filter(sub => renewalDue(sub, today)).map(sub => ({ subscription: sub, account: accounts.find(one => one.id === sub.accountId)! }))\n}\n\n/** Seats still held by people who have retired. */\nexport async function saasSeatsOfLeavers(tx: EntityManager, domain: Domain, today: string) {\n const { accounts, subs } = await inUse(tx, domain)\n if (!subs.length) return []\n const seats = (await tx.getRepository(SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: In(subs.map(one => one.id)) } } as any, relations: ['employee'] })).filter(\n seat => seat.employeeId && seatHeld(seat, today)\n )\n const retired = await retiredOf(tx, domain, [...new Set(seats.map(one => one.employeeId!))], today)\n return seats\n .filter(seat => retired.has(seat.employeeId!))\n .map(seat => {\n const subscription = subs.find(one => one.id === seat.subscriptionId)!\n return { seat, subscription, account: accounts.find(one => one.id === subscription.accountId)! }\n })\n}\n\n/** Accounts in use with nobody left to administer them - no admin named, or every admin retired. */\nexport async function saasAccountsWithoutAdmin(tx: EntityManager, domain: Domain, today: string) {\n const { accounts } = await inUse(tx, domain)\n const retired = await retiredOf(tx, domain, [...new Set(accounts.flatMap(one => (one.admins ?? []).map(admin => admin.id)))], today)\n return accounts.filter(account => !(account.admins ?? []).some(admin => !retired.has(admin.id)))\n}\n\n/**\n * Seat plans in use whose seats held today are not as many as bought. A plan with no price is left out - a\n * free or trial plan a tenant hands out (1,000,000 Power BI Free) costs nothing unused (ADR-0177 개정 2, the user 10-31).\n */\nexport async function saasSeatCountsDiffer(tx: EntityManager, domain: Domain, today: string) {\n const { accounts, subs } = await inUse(tx, domain)\n const plans = subs.filter(one => one.billing === SaasBilling.SEAT && one.startOn <= today && one.unitPrice !== null && one.unitPrice !== undefined)\n if (!plans.length) return []\n const seats = await tx.getRepository(SaasSeat).find({ where: { domain: { id: domain.id }, subscription: { id: In(plans.map(one => one.id)) } } as any })\n return plans\n .map(sub => ({ subscription: sub, account: accounts.find(one => one.id === sub.accountId)!, held: seats.filter(seat => seat.subscriptionId === sub.id && seatHeld(seat, today)).length }))\n .filter(one => one.held !== Number(one.subscription.quantity ?? 0))\n}\n"]}
@@ -0,0 +1,18 @@
1
+ export * from './saas-rules';
2
+ export * from './saas-account';
3
+ export * from './saas-subscription';
4
+ export * from './saas-seat';
5
+ export * from './saas-type';
6
+ export * from './saas-access';
7
+ export * from './saas-service';
8
+ export * from './saas-sync';
9
+ export * from './checks';
10
+ import { SaasAccount } from './saas-account';
11
+ import { SaasMutation } from './saas-mutation';
12
+ import { SaasAccountQuery } from './saas-query';
13
+ import { SaasSeat } from './saas-seat';
14
+ import { SaasSubscription } from './saas-subscription';
15
+ export declare const entities: (typeof SaasAccount | typeof SaasSubscription | typeof SaasSeat)[];
16
+ export declare const schema: {
17
+ resolverClasses: (typeof SaasMutation | typeof SaasAccountQuery)[];
18
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = exports.entities = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* EXPORT ENTITY TYPES */
6
+ tslib_1.__exportStar(require("./saas-rules"), exports);
7
+ tslib_1.__exportStar(require("./saas-account"), exports);
8
+ tslib_1.__exportStar(require("./saas-subscription"), exports);
9
+ tslib_1.__exportStar(require("./saas-seat"), exports);
10
+ tslib_1.__exportStar(require("./saas-type"), exports);
11
+ tslib_1.__exportStar(require("./saas-access"), exports);
12
+ tslib_1.__exportStar(require("./saas-service"), exports);
13
+ tslib_1.__exportStar(require("./saas-sync"), exports);
14
+ tslib_1.__exportStar(require("./checks"), exports);
15
+ /* IMPORT ENTITIES AND RESOLVERS */
16
+ const saas_account_1 = require("./saas-account");
17
+ const saas_mutation_1 = require("./saas-mutation");
18
+ const saas_query_1 = require("./saas-query");
19
+ const saas_seat_1 = require("./saas-seat");
20
+ const saas_subscription_1 = require("./saas-subscription");
21
+ exports.entities = [
22
+ /* ENTITIES */
23
+ saas_account_1.SaasAccount,
24
+ saas_subscription_1.SaasSubscription,
25
+ saas_seat_1.SaasSeat
26
+ ];
27
+ exports.schema = {
28
+ resolverClasses: [
29
+ /* RESOLVER CLASSES */
30
+ saas_query_1.SaasAccountQuery,
31
+ saas_mutation_1.SaasMutation
32
+ ]
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,uDAA4B;AAC5B,yDAA8B;AAC9B,8DAAmC;AACnC,sDAA2B;AAC3B,sDAA2B;AAC3B,wDAA6B;AAC7B,yDAA8B;AAC9B,sDAA2B;AAC3B,mDAAwB;AAExB,mCAAmC;AACnC,iDAA4C;AAC5C,mDAA8C;AAC9C,6CAA+C;AAC/C,2CAAsC;AACtC,2DAAsD;AAEzC,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,0BAAW;IACX,oCAAgB;IAChB,oBAAQ;CACT,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACtB,6BAAgB;QAChB,4BAAY;KACb;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\nexport * from './saas-rules'\nexport * from './saas-account'\nexport * from './saas-subscription'\nexport * from './saas-seat'\nexport * from './saas-type'\nexport * from './saas-access'\nexport * from './saas-service'\nexport * from './saas-sync'\nexport * from './checks'\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport { SaasAccount } from './saas-account'\nimport { SaasMutation } from './saas-mutation'\nimport { SaasAccountQuery } from './saas-query'\nimport { SaasSeat } from './saas-seat'\nimport { SaasSubscription } from './saas-subscription'\n\nexport const entities = [\n /* ENTITIES */\n SaasAccount,\n SaasSubscription,\n SaasSeat\n]\n\nexport const schema = {\n resolverClasses: [\n /* RESOLVER CLASSES */\n SaasAccountQuery,\n SaasMutation\n ]\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { Domain } from '@things-factory/shell';
2
+ import { EntityManager } from 'typeorm';
3
+ import { SaasAccount } from './saas-account';
4
+ /**
5
+ * Whose accounts a person reaches (ADR-0177 Q4): every account with `saas` on the axis (or as the domain owner), else
6
+ * only the accounts they are named an admin of - whatever their seat. The doors that admins pass ask `saas-self`; this
7
+ * says how far it reaches.
8
+ */
9
+ export type SaasScope = 'all' | Set<string>;
10
+ export declare function scopeOf(state: {
11
+ domain: Domain;
12
+ user: any;
13
+ unsafeIP?: boolean;
14
+ prohibitedPrivileges?: any[];
15
+ tx?: EntityManager;
16
+ }, axis: 'query' | 'mutation', tx: EntityManager): Promise<SaasScope>;
17
+ /** The accounts a person is named an admin of - by their employee record of the domain, while not retired. */
18
+ export declare function administeredBy(tx: EntityManager, domain: Domain, userId?: string): Promise<string[]>;
19
+ /** The account, when it is of the domain and within the scope; refused otherwise - as not found, so nothing is told. */
20
+ export declare function accountIn(tx: EntityManager, domain: Domain, scope: SaasScope, accountId: string): Promise<SaasAccount>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scopeOf = scopeOf;
4
+ exports.administeredBy = administeredBy;
5
+ exports.accountIn = accountIn;
6
+ const auth_base_1 = require("@things-factory/auth-base");
7
+ const shell_1 = require("@things-factory/shell");
8
+ const organization_1 = require("@things-factory/organization");
9
+ const typeorm_1 = require("typeorm");
10
+ const saas_account_1 = require("./saas-account");
11
+ async function scopeOf(state, axis, tx) {
12
+ const { domain, user, unsafeIP, prohibitedPrivileges } = state;
13
+ if (await (0, auth_base_1.checkPermission)({ category: 'saas', privilege: axis, owner: true }, user, domain, unsafeIP, prohibitedPrivileges))
14
+ return 'all';
15
+ return new Set(await administeredBy(tx, domain, user?.id));
16
+ }
17
+ /** The accounts a person is named an admin of - by their employee record of the domain, while not retired. */
18
+ async function administeredBy(tx, domain, userId) {
19
+ if (!userId)
20
+ return [];
21
+ const today = new Date().toISOString().slice(0, 10);
22
+ /* A retired employee administers nothing any more. */
23
+ const employees = (await tx.getRepository(organization_1.Employee).find({ where: { domain: { id: domain.id }, user: { id: userId } } })).filter(one => !one.retiredOn || one.retiredOn > today);
24
+ if (!employees.length)
25
+ return [];
26
+ const rows = await tx.getRepository(saas_account_1.SaasAccount).find({ where: { domain: { id: domain.id }, admins: { id: (0, typeorm_1.In)(employees.map(one => one.id)) } }, relations: ['admins'] });
27
+ return [...new Set(rows.map(one => one.id))];
28
+ }
29
+ /** The account, when it is of the domain and within the scope; refused otherwise - as not found, so nothing is told. */
30
+ async function accountIn(tx, domain, scope, accountId) {
31
+ const account = accountId && (scope === 'all' || scope.has(accountId)) ? await tx.getRepository(saas_account_1.SaasAccount).findOne({ where: { domain: { id: domain.id }, id: accountId } }) : null;
32
+ if (!account)
33
+ throw new shell_1.Refusal('saas-account-not-found', {}, 'The account was not found - reload and try again');
34
+ return account;
35
+ }
36
+ //# sourceMappingURL=saas-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saas-access.js","sourceRoot":"","sources":["../../server/service/saas-access.ts"],"names":[],"mappings":";;AAcA,0BAIC;AAGD,wCAQC;AAGD,8BAIC;AApCD,yDAA2D;AAC3D,iDAAuD;AACvD,+DAAuD;AACvD,qCAA2C;AAE3C,iDAA4C;AASrC,KAAK,UAAU,OAAO,CAAC,KAA0G,EAAE,IAA0B,EAAE,EAAiB;IACrL,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAA;IAC9D,IAAI,MAAM,IAAA,2BAAe,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,CAAC;QAAE,OAAO,KAAK,CAAA;IAChJ,OAAO,IAAI,GAAG,CAAC,MAAM,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED,8GAA8G;AACvG,KAAK,UAAU,cAAc,CAAC,EAAiB,EAAE,MAAc,EAAE,MAAe;IACrF,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAA;IACtB,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,C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AC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,EAAS,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3L,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,eAAO,CAAC,wBAAwB,EAAE,EAAE,EAAE,kDAAkD,CAAC,CAAA;IACjH,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { checkPermission } from '@things-factory/auth-base'\nimport { Domain, Refusal } from '@things-factory/shell'\nimport { Employee } from '@things-factory/organization'\nimport { EntityManager, In } from 'typeorm'\n\nimport { SaasAccount } from './saas-account'\n\n/**\n * Whose accounts a person reaches (ADR-0177 Q4): every account with `saas` on the axis (or as the domain owner), else\n * only the accounts they are named an admin of - whatever their seat. The doors that admins pass ask `saas-self`; this\n * says how far it reaches.\n */\nexport type SaasScope = 'all' | Set<string>\n\nexport async function scopeOf(state: { domain: Domain; user: any; unsafeIP?: boolean; prohibitedPrivileges?: any[]; tx?: EntityManager }, axis: 'query' | 'mutation', tx: EntityManager): Promise<SaasScope> {\n const { domain, user, unsafeIP, prohibitedPrivileges } = state\n if (await checkPermission({ category: 'saas', privilege: axis, owner: true } as any, user, domain, unsafeIP, prohibitedPrivileges)) return 'all'\n return new Set(await administeredBy(tx, domain, user?.id))\n}\n\n/** The accounts a person is named an admin of - by their employee record of the domain, while not retired. */\nexport async function administeredBy(tx: EntityManager, domain: Domain, userId?: string): Promise<string[]> {\n if (!userId) return []\n const today = new Date().toISOString().slice(0, 10)\n /* A retired employee administers nothing any more. */\n const employees = (await tx.getRepository(Employee).find({ where: { domain: { id: domain.id }, user: { id: userId } } as any })).filter(one => !one.retiredOn || one.retiredOn > today)\n if (!employees.length) return []\n const rows = await tx.getRepository(SaasAccount).find({ where: { domain: { id: domain.id }, admins: { id: In(employees.map(one => one.id)) } } as any, relations: ['admins'] })\n return [...new Set(rows.map(one => one.id))]\n}\n\n/** The account, when it is of the domain and within the scope; refused otherwise - as not found, so nothing is told. */\nexport async function accountIn(tx: EntityManager, domain: Domain, scope: SaasScope, accountId: string): Promise<SaasAccount> {\n const account = accountId && (scope === 'all' || scope.has(accountId)) ? await tx.getRepository(SaasAccount).findOne({ where: { domain: { id: domain.id }, id: accountId } as any }) : null\n if (!account) throw new Refusal('saas-account-not-found', {}, 'The account was not found - reload and try again')\n return account\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { BankAccount } from '@things-factory/accounting';
2
+ import { User } from '@things-factory/auth-base';
3
+ import { Counterparty } from '@things-factory/biz-base';
4
+ import { Employee } from '@things-factory/organization';
5
+ import { Domain } from '@things-factory/shell';
6
+ import { SaasAccountStatus } from './saas-rules';
7
+ /**
8
+ * One account the domain holds with a vendor - the unit a bill comes from (ADR-0177 decision 2): an AWS organization's
9
+ * payer account, a Microsoft 365 tenant, a registrar. An account under another (an AWS member account) names its purpose
10
+ * and admins only; the money is the parent's. No password, key or recovery code is kept - only where it is kept.
11
+ */
12
+ export declare class SaasAccount {
13
+ readonly id: string;
14
+ domain?: Domain;
15
+ domainId?: string;
16
+ name: string;
17
+ counterparty?: Counterparty;
18
+ counterpartyId?: string;
19
+ identifier?: string;
20
+ parent?: SaasAccount;
21
+ parentId?: string;
22
+ purpose?: string;
23
+ admins?: Employee[];
24
+ billingEmail?: string;
25
+ paymentAccount?: BankAccount;
26
+ paymentAccountId?: string;
27
+ currency: string;
28
+ secretLocation?: string;
29
+ status: SaasAccountStatus;
30
+ closedOn?: string;
31
+ description?: string;
32
+ createdAt?: Date;
33
+ updatedAt?: Date;
34
+ deletedAt?: Date;
35
+ creator?: User;
36
+ creatorId?: string;
37
+ updater?: User;
38
+ updaterId?: string;
39
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SaasAccount = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const accounting_1 = require("@things-factory/accounting");
6
+ const auth_base_1 = require("@things-factory/auth-base");
7
+ const biz_base_1 = require("@things-factory/biz-base");
8
+ const organization_1 = require("@things-factory/organization");
9
+ const shell_1 = require("@things-factory/shell");
10
+ const type_graphql_1 = require("type-graphql");
11
+ const typeorm_1 = require("typeorm");
12
+ const saas_rules_1 = require("./saas-rules");
13
+ /**
14
+ * One account the domain holds with a vendor - the unit a bill comes from (ADR-0177 decision 2): an AWS organization's
15
+ * payer account, a Microsoft 365 tenant, a registrar. An account under another (an AWS member account) names its purpose
16
+ * and admins only; the money is the parent's. No password, key or recovery code is kept - only where it is kept.
17
+ */
18
+ let SaasAccount = class SaasAccount {
19
+ };
20
+ exports.SaasAccount = SaasAccount;
21
+ tslib_1.__decorate([
22
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
23
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID, { description: 'Unique identifier of the account' }),
24
+ tslib_1.__metadata("design:type", String)
25
+ ], SaasAccount.prototype, "id", void 0);
26
+ tslib_1.__decorate([
27
+ (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
28
+ (0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true, description: 'The domain the account belongs to' }),
29
+ tslib_1.__metadata("design:type", shell_1.Domain)
30
+ ], SaasAccount.prototype, "domain", void 0);
31
+ tslib_1.__decorate([
32
+ (0, typeorm_1.RelationId)((account) => account.domain),
33
+ tslib_1.__metadata("design:type", String)
34
+ ], SaasAccount.prototype, "domainId", void 0);
35
+ tslib_1.__decorate([
36
+ (0, typeorm_1.Column)(),
37
+ (0, type_graphql_1.Field)({ description: 'The service - AWS, Microsoft 365, Adobe Creative Cloud, a registrar' }),
38
+ tslib_1.__metadata("design:type", String)
39
+ ], SaasAccount.prototype, "name", void 0);
40
+ tslib_1.__decorate([
41
+ (0, typeorm_1.ManyToOne)(type => biz_base_1.Counterparty, { nullable: true, onDelete: 'SET NULL' }),
42
+ (0, type_graphql_1.Field)(type => biz_base_1.Counterparty, { nullable: true, description: 'The vendor it is paid to' }),
43
+ tslib_1.__metadata("design:type", biz_base_1.Counterparty)
44
+ ], SaasAccount.prototype, "counterparty", void 0);
45
+ tslib_1.__decorate([
46
+ (0, typeorm_1.RelationId)((account) => account.counterparty),
47
+ tslib_1.__metadata("design:type", String)
48
+ ], SaasAccount.prototype, "counterpartyId", void 0);
49
+ tslib_1.__decorate([
50
+ (0, typeorm_1.Column)({ nullable: true }),
51
+ (0, type_graphql_1.Field)({ nullable: true, description: "The vendor's name for the account - an AWS account number, a tenant domain, an organization id" }),
52
+ tslib_1.__metadata("design:type", String)
53
+ ], SaasAccount.prototype, "identifier", void 0);
54
+ tslib_1.__decorate([
55
+ (0, typeorm_1.ManyToOne)(type => SaasAccount, { nullable: true, onDelete: 'SET NULL' }),
56
+ (0, type_graphql_1.Field)(type => SaasAccount, { nullable: true, description: 'The account it is under - an AWS member account under its payer; the money is the parent’s' }),
57
+ tslib_1.__metadata("design:type", SaasAccount)
58
+ ], SaasAccount.prototype, "parent", void 0);
59
+ tslib_1.__decorate([
60
+ (0, typeorm_1.RelationId)((account) => account.parent),
61
+ tslib_1.__metadata("design:type", String)
62
+ ], SaasAccount.prototype, "parentId", void 0);
63
+ tslib_1.__decorate([
64
+ (0, typeorm_1.Column)({ nullable: true }),
65
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What it is used for - production, development, a customer' }),
66
+ tslib_1.__metadata("design:type", String)
67
+ ], SaasAccount.prototype, "purpose", void 0);
68
+ tslib_1.__decorate([
69
+ (0, typeorm_1.ManyToMany)(type => organization_1.Employee),
70
+ (0, typeorm_1.JoinTable)({ name: 'saas_account_admins' }),
71
+ (0, type_graphql_1.Field)(type => [organization_1.Employee], { nullable: true, description: 'Who administers it at the vendor - they keep its subscriptions, seats and bills' }),
72
+ tslib_1.__metadata("design:type", Array)
73
+ ], SaasAccount.prototype, "admins", void 0);
74
+ tslib_1.__decorate([
75
+ (0, typeorm_1.Column)({ nullable: true }),
76
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Where the vendor sends the bills' }),
77
+ tslib_1.__metadata("design:type", String)
78
+ ], SaasAccount.prototype, "billingEmail", void 0);
79
+ tslib_1.__decorate([
80
+ (0, typeorm_1.ManyToOne)(type => accounting_1.BankAccount, { nullable: true, onDelete: 'SET NULL' }),
81
+ (0, type_graphql_1.Field)(type => accounting_1.BankAccount, { nullable: true, description: 'What it is paid from - a bank account or a card (accounting, ADR-0178)' }),
82
+ tslib_1.__metadata("design:type", accounting_1.BankAccount)
83
+ ], SaasAccount.prototype, "paymentAccount", void 0);
84
+ tslib_1.__decorate([
85
+ (0, typeorm_1.RelationId)((account) => account.paymentAccount),
86
+ tslib_1.__metadata("design:type", String)
87
+ ], SaasAccount.prototype, "paymentAccountId", void 0);
88
+ tslib_1.__decorate([
89
+ (0, typeorm_1.Column)({ default: 'KRW' }),
90
+ (0, type_graphql_1.Field)({ description: 'The currency its prices are in - ISO 4217' }),
91
+ tslib_1.__metadata("design:type", String)
92
+ ], SaasAccount.prototype, "currency", void 0);
93
+ tslib_1.__decorate([
94
+ (0, typeorm_1.Column)({ nullable: true }),
95
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Where its password, keys and recovery codes are kept - never the secrets themselves' }),
96
+ tslib_1.__metadata("design:type", String)
97
+ ], SaasAccount.prototype, "secretLocation", void 0);
98
+ tslib_1.__decorate([
99
+ (0, typeorm_1.Column)({ default: saas_rules_1.SaasAccountStatus.ACTIVE }),
100
+ (0, type_graphql_1.Field)(type => saas_rules_1.SaasAccountStatus, { description: 'In use or closed' }),
101
+ tslib_1.__metadata("design:type", String)
102
+ ], SaasAccount.prototype, "status", void 0);
103
+ tslib_1.__decorate([
104
+ (0, typeorm_1.Column)({ nullable: true }),
105
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The day it was closed - YYYY-MM-DD' }),
106
+ tslib_1.__metadata("design:type", String)
107
+ ], SaasAccount.prototype, "closedOn", void 0);
108
+ tslib_1.__decorate([
109
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
110
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
111
+ tslib_1.__metadata("design:type", String)
112
+ ], SaasAccount.prototype, "description", void 0);
113
+ tslib_1.__decorate([
114
+ (0, typeorm_1.CreateDateColumn)(),
115
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When the account was registered' }),
116
+ tslib_1.__metadata("design:type", Date)
117
+ ], SaasAccount.prototype, "createdAt", void 0);
118
+ tslib_1.__decorate([
119
+ (0, typeorm_1.UpdateDateColumn)(),
120
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When the account last changed' }),
121
+ tslib_1.__metadata("design:type", Date)
122
+ ], SaasAccount.prototype, "updatedAt", void 0);
123
+ tslib_1.__decorate([
124
+ (0, typeorm_1.DeleteDateColumn)(),
125
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When the account was deleted' }),
126
+ tslib_1.__metadata("design:type", Date)
127
+ ], SaasAccount.prototype, "deletedAt", void 0);
128
+ tslib_1.__decorate([
129
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
130
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who registered it' }),
131
+ tslib_1.__metadata("design:type", auth_base_1.User)
132
+ ], SaasAccount.prototype, "creator", void 0);
133
+ tslib_1.__decorate([
134
+ (0, typeorm_1.RelationId)((account) => account.creator),
135
+ tslib_1.__metadata("design:type", String)
136
+ ], SaasAccount.prototype, "creatorId", void 0);
137
+ tslib_1.__decorate([
138
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
139
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who last changed it' }),
140
+ tslib_1.__metadata("design:type", auth_base_1.User)
141
+ ], SaasAccount.prototype, "updater", void 0);
142
+ tslib_1.__decorate([
143
+ (0, typeorm_1.RelationId)((account) => account.updater),
144
+ tslib_1.__metadata("design:type", String)
145
+ ], SaasAccount.prototype, "updaterId", void 0);
146
+ exports.SaasAccount = SaasAccount = tslib_1.__decorate([
147
+ (0, typeorm_1.Entity)(),
148
+ (0, typeorm_1.Index)('ix_saas_account_0', (account) => [account.domain, account.status]),
149
+ (0, type_graphql_1.ObjectType)({ description: 'Entity for SaasAccount — an account the domain holds with a vendor of something it subscribes to' })
150
+ ], SaasAccount);
151
+ //# sourceMappingURL=saas-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saas-account.js","sourceRoot":"","sources":["../../server/service/saas-account.ts"],"names":[],"mappings":";;;;AAAA,2DAAwD;AACxD,yDAAgD;AAChD,uDAAuD;AACvD,+DAAuD;AACvD,iDAA8C;AAC9C,+CAAgE;AAChE,qCAYgB;AAEhB,6CAAgD;AAEhD;;;;GAIG;AAII,IAAM,WAAW,GAAjB,MAAM,WAAW;CAmGvB,CAAA;AAnGY,kCAAW;AAGb;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;;uCACpD;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,mCAAmC,EAAE,CAAC;sCACnF,cAAM;2CAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,OAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;;6CACpC;AAIjB;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,qEAAqE,EAAE,CAAC;;yCAClF;AAIZ;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,uBAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;IACzE,IAAA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AAU,EAAC,CAAC,OAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;;8CACpC;sBAlGP,WAAW;IAHvB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,mBAAmB,EAAE,CAAC,OAAoB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtF,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,kGAAkG,EAAE,CAAC;GACnH,WAAW,CAmGvB","sourcesContent":["import { BankAccount } from '@things-factory/accounting'\nimport { User } from '@things-factory/auth-base'\nimport { Counterparty } from '@things-factory/biz-base'\nimport { Employee } from '@things-factory/organization'\nimport { Domain } from '@things-factory/shell'\nimport { Field, Float, ID, Int, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n DeleteDateColumn,\n Entity,\n Index,\n JoinTable,\n ManyToMany,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { SaasAccountStatus } from './saas-rules'\n\n/**\n * One account the domain holds with a vendor - the unit a bill comes from (ADR-0177 decision 2): an AWS organization's\n * payer account, a Microsoft 365 tenant, a registrar. An account under another (an AWS member account) names its purpose\n * and admins only; the money is the parent's. No password, key or recovery code is kept - only where it is kept.\n */\n@Entity()\n@Index('ix_saas_account_0', (account: SaasAccount) => [account.domain, account.status])\n@ObjectType({ description: 'Entity for SaasAccount — an account the domain holds with a vendor of something it subscribes to' })\nexport class SaasAccount {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier of the account' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true, description: 'The domain the account belongs to' })\n domain?: Domain\n\n @RelationId((account: SaasAccount) => account.domain)\n domainId?: string\n\n @Column()\n @Field({ description: 'The service - AWS, Microsoft 365, Adobe Creative Cloud, a registrar' })\n name: string\n\n @ManyToOne(type => Counterparty, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => Counterparty, { nullable: true, description: 'The vendor it is paid to' })\n counterparty?: Counterparty\n\n @RelationId((account: SaasAccount) => account.counterparty)\n counterpartyId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: \"The vendor's name for the account - an AWS account number, a tenant domain, an organization id\" })\n identifier?: string\n\n @ManyToOne(type => SaasAccount, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => SaasAccount, { nullable: true, description: 'The account it is under - an AWS member account under its payer; the money is the parent’s' })\n parent?: SaasAccount\n\n @RelationId((account: SaasAccount) => account.parent)\n parentId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'What it is used for - production, development, a customer' })\n purpose?: string\n\n @ManyToMany(type => Employee)\n @JoinTable({ name: 'saas_account_admins' })\n @Field(type => [Employee], { nullable: true, description: 'Who administers it at the vendor - they keep its subscriptions, seats and bills' })\n admins?: Employee[]\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Where the vendor sends the bills' })\n billingEmail?: string\n\n @ManyToOne(type => BankAccount, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => BankAccount, { nullable: true, description: 'What it is paid from - a bank account or a card (accounting, ADR-0178)' })\n paymentAccount?: BankAccount\n\n @RelationId((account: SaasAccount) => account.paymentAccount)\n paymentAccountId?: string\n\n @Column({ default: 'KRW' })\n @Field({ description: 'The currency its prices are in - ISO 4217' })\n currency: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Where its password, keys and recovery codes are kept - never the secrets themselves' })\n secretLocation?: string\n\n @Column({ default: SaasAccountStatus.ACTIVE })\n @Field(type => SaasAccountStatus, { description: 'In use or closed' })\n status: SaasAccountStatus\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The day it was closed - YYYY-MM-DD' })\n closedOn?: string\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'Notes' })\n description?: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'When the account was registered' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'When the account last changed' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'When the account 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((account: SaasAccount) => account.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((account: SaasAccount) => account.updater)\n updaterId?: string\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { SaasAccount } from './saas-account';
2
+ import { SaasSeat } from './saas-seat';
3
+ import { SaasSubscription } from './saas-subscription';
4
+ import { SaasAccountPatch, SaasLicensesInput, SaasSeatPatch, SaasSubscriptionPatch } from './saas-type';
5
+ export declare class SaasMutation {
6
+ syncSaasLicenses(licenses: SaasLicensesInput, context: ResolverContext): Promise<import("./saas-sync").LicenseSyncResult>;
7
+ updateMultipleSaasAccount(patches: SaasAccountPatch[], context: ResolverContext): Promise<SaasAccount[]>;
8
+ updateMultipleSaasSubscription(accountId: string, patches: SaasSubscriptionPatch[], context: ResolverContext): Promise<SaasSubscription[]>;
9
+ updateMultipleSaasSeat(subscriptionId: string, patches: SaasSeatPatch[], context: ResolverContext): Promise<SaasSeat[]>;
10
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SaasMutation = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const shell_1 = require("@things-factory/shell");
6
+ const type_graphql_1 = require("type-graphql");
7
+ const saas_access_1 = require("./saas-access");
8
+ const saas_account_1 = require("./saas-account");
9
+ const saas_service_1 = require("./saas-service");
10
+ const saas_seat_1 = require("./saas-seat");
11
+ const saas_subscription_1 = require("./saas-subscription");
12
+ const saas_sync_1 = require("./saas-sync");
13
+ const saas_type_1 = require("./saas-type");
14
+ /*
15
+ * The accounts are the keepers'. What is under an account - its subscriptions and their seats - is also its
16
+ * admins', whatever their seat (ADR-0177 Q4): those doors ask `saas-self`, and the service keeps an admin to their own.
17
+ */
18
+ let SaasMutation = class SaasMutation {
19
+ /* A scenario's step (ADR-0177 개정 2): seats and quantities only, so its own category - the system admin runs it. */
20
+ syncSaasLicenses(licenses, context) {
21
+ const { tx, domain, user } = context.state;
22
+ return (0, saas_sync_1.syncSaasLicenses)(tx, domain, user, licenses, new Date().toISOString().slice(0, 10));
23
+ }
24
+ updateMultipleSaasAccount(patches, context) {
25
+ const { tx, domain, user } = context.state;
26
+ return (0, saas_service_1.saveSaasAccounts)(tx, domain, user, patches);
27
+ }
28
+ async updateMultipleSaasSubscription(accountId, patches, context) {
29
+ const { tx, domain, user } = context.state;
30
+ return (0, saas_service_1.saveSaasSubscriptions)(tx, domain, user, await (0, saas_access_1.scopeOf)(context.state, 'mutation', tx), accountId, patches);
31
+ }
32
+ async updateMultipleSaasSeat(subscriptionId, patches, context) {
33
+ const { tx, domain, user } = context.state;
34
+ return (0, saas_service_1.saveSaasSeats)(tx, domain, user, await (0, saas_access_1.scopeOf)(context.state, 'mutation', tx), subscriptionId, patches);
35
+ }
36
+ };
37
+ exports.SaasMutation = SaasMutation;
38
+ tslib_1.__decorate([
39
+ (0, type_graphql_1.Directive)('@transaction'),
40
+ (0, type_graphql_1.Directive)('@privilege(category: "saas-sync", privilege: "mutation", domainOwnerGranted: true)'),
41
+ (0, type_graphql_1.Mutation)(type => saas_type_1.SaasLicenseSync, { description: "To keep an account's seats and quantities as its vendor tenant says - what it bought and who holds each" }),
42
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('licenses', type => saas_type_1.SaasLicensesInput)),
43
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
44
+ tslib_1.__metadata("design:type", Function),
45
+ tslib_1.__metadata("design:paramtypes", [saas_type_1.SaasLicensesInput, Object]),
46
+ tslib_1.__metadata("design:returntype", void 0)
47
+ ], SaasMutation.prototype, "syncSaasLicenses", null);
48
+ tslib_1.__decorate([
49
+ (0, type_graphql_1.Directive)('@transaction'),
50
+ (0, type_graphql_1.Directive)('@privilege(category: "saas", privilege: "mutation", domainOwnerGranted: true)'),
51
+ (0, type_graphql_1.Directive)('@auditTarget(kind: "SaasAccount", arg: "patches")'),
52
+ (0, type_graphql_1.Mutation)(type => [saas_account_1.SaasAccount], { description: 'To save the accounts grid - new, changed and deleted rows together' }),
53
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [saas_type_1.SaasAccountPatch])),
54
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
55
+ tslib_1.__metadata("design:type", Function),
56
+ tslib_1.__metadata("design:paramtypes", [Array, Object]),
57
+ tslib_1.__metadata("design:returntype", void 0)
58
+ ], SaasMutation.prototype, "updateMultipleSaasAccount", null);
59
+ tslib_1.__decorate([
60
+ (0, type_graphql_1.Directive)('@transaction'),
61
+ (0, type_graphql_1.Directive)('@privilege(category: "saas-self", privilege: "mutation", domainOwnerGranted: true)'),
62
+ (0, type_graphql_1.Directive)('@auditTarget(kind: "SaasAccount", arg: "accountId")'),
63
+ (0, type_graphql_1.Mutation)(type => [saas_subscription_1.SaasSubscription], { description: "To save an account's subscriptions grid" }),
64
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('accountId')),
65
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('patches', type => [saas_type_1.SaasSubscriptionPatch])),
66
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
67
+ tslib_1.__metadata("design:type", Function),
68
+ tslib_1.__metadata("design:paramtypes", [String, Array, Object]),
69
+ tslib_1.__metadata("design:returntype", Promise)
70
+ ], SaasMutation.prototype, "updateMultipleSaasSubscription", null);
71
+ tslib_1.__decorate([
72
+ (0, type_graphql_1.Directive)('@transaction'),
73
+ (0, type_graphql_1.Directive)('@privilege(category: "saas-self", privilege: "mutation", domainOwnerGranted: true)'),
74
+ (0, type_graphql_1.Directive)('@auditTarget(kind: "SaasSubscription", arg: "subscriptionId")'),
75
+ (0, type_graphql_1.Mutation)(type => [saas_seat_1.SaasSeat], { description: "To save a subscription's seats grid" }),
76
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('subscriptionId')),
77
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('patches', type => [saas_type_1.SaasSeatPatch])),
78
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
79
+ tslib_1.__metadata("design:type", Function),
80
+ tslib_1.__metadata("design:paramtypes", [String, Array, Object]),
81
+ tslib_1.__metadata("design:returntype", Promise)
82
+ ], SaasMutation.prototype, "updateMultipleSaasSeat", null);
83
+ exports.SaasMutation = SaasMutation = tslib_1.__decorate([
84
+ (0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
85
+ (0, type_graphql_1.Resolver)(saas_account_1.SaasAccount)
86
+ ], SaasMutation);
87
+ //# sourceMappingURL=saas-mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saas-mutation.js","sourceRoot":"","sources":["../../server/service/saas-mutation.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AACrD,+CAAqF;AAErF,+CAAuC;AACvC,iDAA4C;AAC5C,iDAAuF;AACvF,2CAAsC;AACtC,2DAAsD;AACtD,2CAA8C;AAC9C,2CAAwH;AAExH;;;GAGG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,mHAAmH;IAInH,gBAAgB,CAA6C,QAA2B,EAAS,OAAwB;QACvH,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,IAAA,4BAAgB,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5F,CAAC;IAMD,yBAAyB,CAA6C,OAA2B,EAAS,OAAwB;QAChI,MAAM,E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CAAC,CAAA;IAA4B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DAGpJ;uBAnCU,YAAY;IAFxB,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,0BAAW,CAAC;GACT,YAAY,CAoCxB","sourcesContent":["import { SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\n\nimport { scopeOf } from './saas-access'\nimport { SaasAccount } from './saas-account'\nimport { saveSaasAccounts, saveSaasSeats, saveSaasSubscriptions } from './saas-service'\nimport { SaasSeat } from './saas-seat'\nimport { SaasSubscription } from './saas-subscription'\nimport { syncSaasLicenses } from './saas-sync'\nimport { SaasAccountPatch, SaasLicenseSync, SaasLicensesInput, SaasSeatPatch, SaasSubscriptionPatch } from './saas-type'\n\n/*\n * The accounts are the keepers'. What is under an account - its subscriptions and their seats - is also its\n * admins', whatever their seat (ADR-0177 Q4): those doors ask `saas-self`, and the service keeps an admin to their own.\n */\n@UseMiddleware(SpeakRefusals)\n@Resolver(SaasAccount)\nexport class SaasMutation {\n /* A scenario's step (ADR-0177 개정 2): seats and quantities only, so its own category - the system admin runs it. */\n @Directive('@transaction')\n @Directive('@privilege(category: \"saas-sync\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => SaasLicenseSync, { description: \"To keep an account's seats and quantities as its vendor tenant says - what it bought and who holds each\" })\n syncSaasLicenses(@Arg('licenses', type => SaasLicensesInput) licenses: SaasLicensesInput, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return syncSaasLicenses(tx, domain, user, licenses, new Date().toISOString().slice(0, 10))\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"saas\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@auditTarget(kind: \"SaasAccount\", arg: \"patches\")')\n @Mutation(type => [SaasAccount], { description: 'To save the accounts grid - new, changed and deleted rows together' })\n updateMultipleSaasAccount(@Arg('patches', type => [SaasAccountPatch]) patches: SaasAccountPatch[], @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveSaasAccounts(tx, domain, user, patches)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"saas-self\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@auditTarget(kind: \"SaasAccount\", arg: \"accountId\")')\n @Mutation(type => [SaasSubscription], { description: \"To save an account's subscriptions grid\" })\n async updateMultipleSaasSubscription(@Arg('accountId') accountId: string, @Arg('patches', type => [SaasSubscriptionPatch]) patches: SaasSubscriptionPatch[], @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveSaasSubscriptions(tx, domain, user, await scopeOf(context.state, 'mutation', tx), accountId, patches)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"saas-self\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@auditTarget(kind: \"SaasSubscription\", arg: \"subscriptionId\")')\n @Mutation(type => [SaasSeat], { description: \"To save a subscription's seats grid\" })\n async updateMultipleSaasSeat(@Arg('subscriptionId') subscriptionId: string, @Arg('patches', type => [SaasSeatPatch]) patches: SaasSeatPatch[], @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveSaasSeats(tx, domain, user, await scopeOf(context.state, 'mutation', tx), subscriptionId, patches)\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { BankAccount } from '@things-factory/accounting';
2
+ import { User } from '@things-factory/auth-base';
3
+ import { Counterparty } from '@things-factory/biz-base';
4
+ import { Domain, ListParam } from '@things-factory/shell';
5
+ import { SaasAccount } from './saas-account';
6
+ import { SaasSeat } from './saas-seat';
7
+ import { SaasSubscription } from './saas-subscription';
8
+ import { SaasAccountList, SaasChange } from './saas-type';
9
+ export declare class SaasAccountQuery {
10
+ saasAccounts(params: ListParam, context: ResolverContext): Promise<SaasAccountList>;
11
+ mySaasAccounts(context: ResolverContext): Promise<SaasAccount[]>;
12
+ saasAccount(id: string, context: ResolverContext): Promise<SaasAccount>;
13
+ saasSubscriptions(accountId: string, context: ResolverContext): Promise<SaasSubscription[]>;
14
+ saasSeats(subscriptionId: string, context: ResolverContext): Promise<SaasSeat[]>;
15
+ saasChanges(accountId: string, context: ResolverContext): Promise<SaasChange[]>;
16
+ counterparty(row: SaasAccount): Counterparty | Promise<Counterparty>;
17
+ parent(row: SaasAccount): SaasAccount | Promise<SaasAccount>;
18
+ paymentAccount(row: SaasAccount): BankAccount | Promise<BankAccount>;
19
+ domain(row: SaasAccount): Domain | Promise<Domain>;
20
+ updater(row: SaasAccount): User | Promise<User>;
21
+ }