@fabriktor/fx 0.0.67 → 0.0.68

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.
@@ -1,4 +1,4 @@
1
- import type { PrivacyOperator } from "@fabriktor/client";
1
+ import { type PrivacyExport, type PrivacyOperator } from "@fabriktor/client";
2
2
  import { type AccountLock, type DeletionRequest } from "@fabriktor/schema";
3
3
  type DeletionRequestInsertOptions = Parameters<PrivacyOperator["insertOneDeletionRequest"]>[0];
4
4
  type DeletionRequestReplaceOptions = Parameters<PrivacyOperator["replaceOneDeletionRequest"]>[0];
@@ -11,8 +11,17 @@ export type ReplaceAccountLockOptions = AccountLockReplaceOptions;
11
11
  export type PrivacyFXOptions = {
12
12
  privacy: PrivacyOperator;
13
13
  };
14
- export type WatchAccountLockOptions = {
14
+ export type GetAccountLockOptions = {
15
15
  owner_id: string;
16
+ };
17
+ export type RequestAccountDeletionOptions = CreateDeletionRequestOptions & {
18
+ owner_id: string;
19
+ };
20
+ export type AccountDeletion = {
21
+ request: DeletionRequest;
22
+ lock: AccountLock;
23
+ };
24
+ export type WatchAccountLockOptions = GetAccountLockOptions & {
16
25
  on_lock: (lock: AccountLock) => void;
17
26
  on_error?: (err: unknown) => void;
18
27
  };
@@ -20,18 +29,25 @@ export type StopAccountLockWatch = () => void;
20
29
  export interface PrivacyFXOperator {
21
30
  createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
22
31
  replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
32
+ requestAccountDeletion(opts: RequestAccountDeletionOptions): Promise<AccountDeletion>;
23
33
  createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
24
34
  replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
35
+ getAccountLock(opts: GetAccountLockOptions): Promise<AccountLock | undefined>;
25
36
  watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
37
+ exportData(): Promise<PrivacyExport>;
26
38
  }
27
39
  export declare class PrivacyFX implements PrivacyFXOperator {
28
40
  private privacy;
29
41
  constructor(opts: PrivacyFXOptions);
30
42
  createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
31
43
  replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
44
+ requestAccountDeletion(opts: RequestAccountDeletionOptions): Promise<AccountDeletion>;
32
45
  createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
33
46
  replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
47
+ getAccountLock(opts: GetAccountLockOptions): Promise<AccountLock | undefined>;
34
48
  watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
49
+ exportData(): Promise<PrivacyExport>;
50
+ private requiredOwnerID;
35
51
  private resolveDeletionRequest;
36
52
  private resolveAccountLock;
37
53
  private findOwnerAccountLock;
@@ -3,8 +3,9 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- import { ZeroID, } from "@fabriktor/schema";
7
- import { errRequired, errResolveFailed, } from "../core/err.js";
6
+ import { queryParam, } from "@fabriktor/client";
7
+ import { OwnerIDKey, ZeroID, } from "@fabriktor/schema";
8
+ import { errRequired, errResolveFailed } from "../core/err.js";
8
9
  import { requiredOperationID } from "../core/id.js";
9
10
  const accountLockIntervalMs = 60 * 60 * 1000;
10
11
  const resourceDeletionRequest = "deletion_request";
@@ -14,6 +15,7 @@ const msgCreatedDeletionRequestIDMissing = "Created deletion request response di
14
15
  const msgDeletionRequestMissing = "Deletion request could not be resolved after the mutation.";
15
16
  const msgCreatedAccountLockIDMissing = "Created account lock response did not contain an ID.";
16
17
  const msgAccountLockMissing = "Account lock could not be resolved after the mutation.";
18
+ const msgDeletionAccountLockMissing = "Account lock could not be resolved after the deletion request.";
17
19
  export class PrivacyFX {
18
20
  privacy;
19
21
  constructor(opts) {
@@ -28,6 +30,18 @@ export class PrivacyFX {
28
30
  await this.privacy.replaceOneDeletionRequest(opts);
29
31
  return await this.resolveDeletionRequest(opts.id);
30
32
  }
33
+ async requestAccountDeletion(opts) {
34
+ const owner_id = this.requiredOwnerID(opts.owner_id);
35
+ const request = await this.createDeletionRequest({ in: opts.in });
36
+ const lock = await this.findOwnerAccountLock(owner_id);
37
+ if (lock === undefined) {
38
+ throw errResolveFailed({
39
+ resource: resourceAccountLock,
40
+ msg: msgDeletionAccountLockMissing,
41
+ });
42
+ }
43
+ return { request, lock };
44
+ }
31
45
  async createAccountLock(opts) {
32
46
  const out = await this.privacy.insertOneAccountLock(opts);
33
47
  const id = requiredOperationID(out, msgCreatedAccountLockIDMissing);
@@ -37,14 +51,11 @@ export class PrivacyFX {
37
51
  await this.privacy.replaceOneAccountLock(opts);
38
52
  return await this.resolveAccountLock(opts.id);
39
53
  }
54
+ async getAccountLock(opts) {
55
+ return await this.findOwnerAccountLock(this.requiredOwnerID(opts.owner_id));
56
+ }
40
57
  async watchAccountLock(opts) {
41
- const owner_id = opts.owner_id.trim();
42
- if (owner_id === "" || owner_id === ZeroID) {
43
- throw errRequired({
44
- field: "owner_id",
45
- msg: msgOwnerIDRequired,
46
- });
47
- }
58
+ const owner_id = this.requiredOwnerID(opts.owner_id);
48
59
  const initial_lock = await this.findOwnerAccountLock(owner_id);
49
60
  if (initial_lock !== undefined) {
50
61
  opts.on_lock(initial_lock);
@@ -89,10 +100,21 @@ export class PrivacyFX {
89
100
  }
90
101
  };
91
102
  }
103
+ async exportData() {
104
+ return await this.privacy.exportData();
105
+ }
106
+ requiredOwnerID(owner_id) {
107
+ const id = owner_id.trim();
108
+ if (id === "" || id === ZeroID) {
109
+ throw errRequired({
110
+ field: "owner_id",
111
+ msg: msgOwnerIDRequired,
112
+ });
113
+ }
114
+ return id;
115
+ }
92
116
  async resolveDeletionRequest(id) {
93
- const out = await this.privacy.findOneDeletionRequest({
94
- id,
95
- });
117
+ const out = await this.privacy.findOneDeletionRequest({ id });
96
118
  const deletion_request = out.value;
97
119
  if (deletion_request === undefined) {
98
120
  throw errResolveFailed({
@@ -103,9 +125,7 @@ export class PrivacyFX {
103
125
  return deletion_request;
104
126
  }
105
127
  async resolveAccountLock(id) {
106
- const out = await this.privacy.findOneAccountLock({
107
- id,
108
- });
128
+ const out = await this.privacy.findOneAccountLock({ id });
109
129
  const account_lock = out.value;
110
130
  if (account_lock === undefined) {
111
131
  throw errResolveFailed({
@@ -117,9 +137,7 @@ export class PrivacyFX {
117
137
  }
118
138
  async findOwnerAccountLock(owner_id) {
119
139
  const out = await this.privacy.queryAccountLocks({
120
- query: {
121
- owner_id,
122
- },
140
+ query: queryParam(OwnerIDKey, owner_id),
123
141
  });
124
142
  return out.value?.[0];
125
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {