@temboplus/afloat 0.1.10 → 0.1.12
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/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/almost_equals.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/assert/1.0.11 → esm/deps/jsr.io/@std/assert/1.0.10}/array_includes.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/assert/1.0.11 → esm/deps/jsr.io/@std/assert/1.0.10}/assert.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/assert/1.0.11 → esm/deps/jsr.io/@std/assert/1.0.10}/assertion_error.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/equal.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/equals.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/exists.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/fail.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/false.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/greater.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/greater_or_equal.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/instance_of.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/is_error.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/less.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/less_or_equal.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/match.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/mod.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_equals.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_instance_of.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_match.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_strict_equals.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/object_match.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/rejects.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/strict_equals.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/string_includes.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/throws.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/unimplemented.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/unreachable.d.ts.map +1 -1
- package/esm/src/features/auth/manager.d.ts +9 -1
- package/esm/src/features/auth/manager.d.ts.map +1 -1
- package/esm/src/features/auth/manager.js +21 -3
- package/esm/src/features/contact/repository.d.ts +12 -1
- package/esm/src/features/contact/repository.d.ts.map +1 -1
- package/esm/src/features/contact/repository.js +25 -11
- package/esm/src/features/files-gen/repository.d.ts +4 -1
- package/esm/src/features/files-gen/repository.d.ts.map +1 -1
- package/esm/src/features/files-gen/repository.js +9 -1
- package/esm/src/features/payout/repository.d.ts +6 -1
- package/esm/src/features/payout/repository.d.ts.map +1 -1
- package/esm/src/features/payout/repository.js +12 -7
- package/esm/src/features/wallet/repository.d.ts +8 -1
- package/esm/src/features/wallet/repository.d.ts.map +1 -1
- package/esm/src/features/wallet/repository.js +17 -8
- package/esm/src/shared/base_repository.d.ts +25 -1
- package/esm/src/shared/base_repository.d.ts.map +1 -1
- package/esm/src/shared/base_repository.js +61 -3
- package/package.json +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/almost_equals.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/assert/1.0.11 → script/deps/jsr.io/@std/assert/1.0.10}/array_includes.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/assert/1.0.11 → script/deps/jsr.io/@std/assert/1.0.10}/assert.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/assert/1.0.11 → script/deps/jsr.io/@std/assert/1.0.10}/assertion_error.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/equal.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/equals.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/exists.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/fail.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/false.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/greater.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/greater_or_equal.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/instance_of.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/is_error.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/less.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/less_or_equal.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/match.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/mod.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_equals.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_instance_of.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_match.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/not_strict_equals.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/object_match.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/rejects.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/strict_equals.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/string_includes.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/throws.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/unimplemented.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/assert/{1.0.11 → 1.0.10}/unreachable.d.ts.map +1 -1
- package/script/src/features/auth/manager.d.ts +9 -1
- package/script/src/features/auth/manager.d.ts.map +1 -1
- package/script/src/features/auth/manager.js +22 -4
- package/script/src/features/contact/repository.d.ts +12 -1
- package/script/src/features/contact/repository.d.ts.map +1 -1
- package/script/src/features/contact/repository.js +31 -17
- package/script/src/features/files-gen/repository.d.ts +4 -1
- package/script/src/features/files-gen/repository.d.ts.map +1 -1
- package/script/src/features/files-gen/repository.js +9 -1
- package/script/src/features/payout/repository.d.ts +6 -1
- package/script/src/features/payout/repository.d.ts.map +1 -1
- package/script/src/features/payout/repository.js +12 -7
- package/script/src/features/wallet/repository.d.ts +8 -1
- package/script/src/features/wallet/repository.d.ts.map +1 -1
- package/script/src/features/wallet/repository.js +17 -8
- package/script/src/shared/base_repository.d.ts +25 -1
- package/script/src/shared/base_repository.d.ts.map +1 -1
- package/script/src/shared/base_repository.js +61 -3
|
@@ -4,9 +4,8 @@ exports.ContactRepository = void 0;
|
|
|
4
4
|
const base_repository_js_1 = require("../../shared/base_repository.js");
|
|
5
5
|
const contract_js_1 = require("./contract.js");
|
|
6
6
|
const index_js_1 = require("../../models/contact/index.js");
|
|
7
|
-
const index_js_2 = require("
|
|
8
|
-
const index_js_3 = require("../../
|
|
9
|
-
const index_js_4 = require("../../errors/index.js");
|
|
7
|
+
const index_js_2 = require("../../models/index.js");
|
|
8
|
+
const index_js_3 = require("../../errors/index.js");
|
|
10
9
|
/**
|
|
11
10
|
* Repository class for managing `Contact` data through API interactions.
|
|
12
11
|
* Extends the `BaseRepository` to leverage shared functionality.
|
|
@@ -14,21 +13,27 @@ const index_js_4 = require("../../errors/index.js");
|
|
|
14
13
|
class ContactRepository extends base_repository_js_1.BaseRepository {
|
|
15
14
|
/**
|
|
16
15
|
* Creates an instance of `ContactRepository` using the contact contract.
|
|
16
|
+
* @param {Object} [props] - Optional constructor properties
|
|
17
|
+
* @param {AfloatAuth} [props.auth] - Optional auth instance to use
|
|
18
|
+
* @param {string} [props.root] - Optional API root URL
|
|
17
19
|
*/
|
|
18
|
-
constructor() {
|
|
19
|
-
super("contact", contract_js_1.contract);
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super("contact", contract_js_1.contract, props);
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Creates a new contact record.
|
|
23
25
|
* @param {ContactInput} input - The data required to create a new contact.
|
|
24
26
|
* @returns {Promise<Contact>} A promise that resolves to the newly created contact.
|
|
27
|
+
* @throws {PermissionError} If the user lacks required permissions
|
|
25
28
|
* @throws {APIError} If the response status code is not 201.
|
|
26
29
|
*/
|
|
27
30
|
async create(input) {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
const auth = this.getAuthForPermissionCheck();
|
|
32
|
+
const requiredPerm = index_js_2.Permissions.Contact.Create;
|
|
33
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
34
|
+
throw new index_js_3.PermissionError({
|
|
30
35
|
message: "You are not authorized to add contacts.",
|
|
31
|
-
requiredPermissions: [
|
|
36
|
+
requiredPermissions: [requiredPerm],
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
const result = await this.client.postContact({ body: input });
|
|
@@ -40,13 +45,16 @@ class ContactRepository extends base_repository_js_1.BaseRepository {
|
|
|
40
45
|
* @param {string} id - The unique identifier of the contact to edit.
|
|
41
46
|
* @param {ContactInput} input - The data to update the contact with.
|
|
42
47
|
* @returns {Promise<Contact>} A promise that resolves to the updated contact.
|
|
48
|
+
* @throws {PermissionError} If the user lacks required permissions
|
|
43
49
|
* @throws {APIError} If the response status code is not 200.
|
|
44
50
|
*/
|
|
45
51
|
async edit(id, input) {
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
const auth = this.getAuthForPermissionCheck();
|
|
53
|
+
const requiredPerm = index_js_2.Permissions.Contact.Update;
|
|
54
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
55
|
+
throw new index_js_3.PermissionError({
|
|
48
56
|
message: "You are not authorized to update contacts.",
|
|
49
|
-
requiredPermissions: [
|
|
57
|
+
requiredPermissions: [requiredPerm],
|
|
50
58
|
});
|
|
51
59
|
}
|
|
52
60
|
const result = await this.client.editContact({
|
|
@@ -60,13 +68,16 @@ class ContactRepository extends base_repository_js_1.BaseRepository {
|
|
|
60
68
|
* Deletes a contact record by ID.
|
|
61
69
|
* @param {string} id - The unique identifier of the contact to remove.
|
|
62
70
|
* @returns {Promise<void>} A promise that resolves when the deletion is complete.
|
|
71
|
+
* @throws {PermissionError} If the user lacks required permissions
|
|
63
72
|
* @throws {APIError} If the response status code is not 200.
|
|
64
73
|
*/
|
|
65
74
|
async remove(id) {
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
const auth = this.getAuthForPermissionCheck();
|
|
76
|
+
const requiredPerm = index_js_2.Permissions.Contact.Delete;
|
|
77
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
78
|
+
throw new index_js_3.PermissionError({
|
|
68
79
|
message: "You are not authorized to delete contacts.",
|
|
69
|
-
requiredPermissions: [
|
|
80
|
+
requiredPermissions: [requiredPerm],
|
|
70
81
|
});
|
|
71
82
|
}
|
|
72
83
|
const result = await this.client.deleteContact({ params: { id } });
|
|
@@ -77,16 +88,19 @@ class ContactRepository extends base_repository_js_1.BaseRepository {
|
|
|
77
88
|
* Results are ordered in descending order by default.
|
|
78
89
|
*
|
|
79
90
|
* @returns {Promise<Contact[]>} A promise that resolves to an array of contacts.
|
|
91
|
+
* @throws {PermissionError} If the user lacks required permissions
|
|
80
92
|
* @throws {APIError} If the response status code is not 200 or the range is invalid.
|
|
81
93
|
* @example
|
|
82
94
|
* const repository = new ContactRepository();
|
|
83
95
|
* repository.getAll().then(contacts => console.log(contacts));
|
|
84
96
|
*/
|
|
85
97
|
async getAll() {
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
const auth = this.getAuthForPermissionCheck();
|
|
99
|
+
const requiredPerm = index_js_2.Permissions.Contact.List;
|
|
100
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
101
|
+
throw new index_js_3.PermissionError({
|
|
88
102
|
message: "You are not authorized to view contacts.",
|
|
89
|
-
requiredPermissions: [
|
|
103
|
+
requiredPermissions: [requiredPerm],
|
|
90
104
|
});
|
|
91
105
|
}
|
|
92
106
|
const query = { orderByDesc: "createdAt" };
|
|
@@ -2,6 +2,7 @@ import { contract } from "./contract.js";
|
|
|
2
2
|
import { BaseRepository } from "../../shared/index.js";
|
|
3
3
|
import type { ClientInferRequest, ClientInferResponseBody } from "@ts-rest/core";
|
|
4
4
|
import type { StatementFile } from "../../models/wallet/index.js";
|
|
5
|
+
import type { AfloatAuth } from "../auth/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* Type definition for statement generation input parameters.
|
|
7
8
|
* Inferred from the contract's genStatementPDF endpoint request body.
|
|
@@ -24,7 +25,9 @@ export declare class AfloatFilesRepo extends BaseRepository<typeof contract> {
|
|
|
24
25
|
* Creates an instance of AfloatFilesRepo initialized with the files generation contract.
|
|
25
26
|
* Configures the repository with the PDF maker service endpoint.
|
|
26
27
|
*/
|
|
27
|
-
constructor(
|
|
28
|
+
constructor(props?: {
|
|
29
|
+
auth?: AfloatAuth;
|
|
30
|
+
});
|
|
28
31
|
/**
|
|
29
32
|
* Generates and downloads a statement PDF based on the provided parameters.
|
|
30
33
|
* @param {GenStatementInput} body - The statement generation parameters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/files-gen/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/files-gen/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,KAAK,iBAAiB,GAAG,kBAAkB,CACzC,OAAO,QAAQ,CAAC,eAAe,CAChC,CAAC,MAAM,CAAC,CAAC;AAEV;;;;GAIG;AACH,KAAK,yBAAyB,GAAG,uBAAuB,CACtD,OAAO,QAAQ,CAAC,oBAAoB,CACrC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAClE;;;OAGG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAQzC;;;;;;;;;OASG;IACG,iBAAiB,CACrB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAWjE"}
|
|
@@ -14,9 +14,11 @@ class AfloatFilesRepo extends index_js_1.BaseRepository {
|
|
|
14
14
|
* Creates an instance of AfloatFilesRepo initialized with the files generation contract.
|
|
15
15
|
* Configures the repository with the PDF maker service endpoint.
|
|
16
16
|
*/
|
|
17
|
-
constructor() {
|
|
17
|
+
constructor(props) {
|
|
18
18
|
super("wallet", contract_js_1.contract, {
|
|
19
19
|
root: "https://api.afloat.money/pdf-maker/afloat",
|
|
20
|
+
// root: "http://localhost:3000/afloat",
|
|
21
|
+
auth: props?.auth,
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
@@ -34,6 +36,12 @@ class AfloatFilesRepo extends index_js_1.BaseRepository {
|
|
|
34
36
|
if (result.status === 201) {
|
|
35
37
|
return result.body;
|
|
36
38
|
}
|
|
39
|
+
if (result.status === 202) {
|
|
40
|
+
throw new api_error_js_1.APIError({
|
|
41
|
+
message: result.body.message,
|
|
42
|
+
statusCode: 202,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
37
45
|
throw api_error_js_1.APIError.unknown("An error occurred while generating statement PDF");
|
|
38
46
|
}
|
|
39
47
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseRepository } from "../../shared/index.js";
|
|
2
2
|
import { type PayoutAPI } from "./contract.js";
|
|
3
3
|
import { type GetPayoutsAPIArgs, type PayoutInput } from "../../models/payout/index.js";
|
|
4
|
+
import type { AfloatAuth } from "../auth/manager.js";
|
|
4
5
|
import { Payout } from "../../models/payout/derivatives/payout.js";
|
|
5
6
|
/**
|
|
6
7
|
* Repository class for managing payout operations including creation, approval,
|
|
@@ -10,8 +11,12 @@ import { Payout } from "../../models/payout/derivatives/payout.js";
|
|
|
10
11
|
export declare class PayoutRepository extends BaseRepository<PayoutAPI> {
|
|
11
12
|
/**
|
|
12
13
|
* Creates an instance of PayoutRepository initialized with the payout contract.
|
|
14
|
+
* @param {Object} [props] - Optional constructor properties
|
|
15
|
+
* @param {AfloatAuth} [props.auth] - Optional auth instance to use
|
|
13
16
|
*/
|
|
14
|
-
constructor(
|
|
17
|
+
constructor(props?: {
|
|
18
|
+
auth?: AfloatAuth;
|
|
19
|
+
});
|
|
15
20
|
/**
|
|
16
21
|
* Retrieves a paginated list of payouts with optional filtering for pending status.
|
|
17
22
|
* @param {GetPayoutsAPIArgs} [args] - Optional arguments for filtering and pagination
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/payout/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/payout/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAAC,SAAS,CAAC;IAC7D;;;;OAIG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAIzC;;;;;;;;;OASG;IACG,MAAM,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAC9C,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IA6CF;;;;;;OAMG;IACG,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB9C;;;;;;;;OAQG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgCrE;;;;;;;;OAQG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CA+BrE"}
|
|
@@ -4,7 +4,6 @@ exports.PayoutRepository = void 0;
|
|
|
4
4
|
const index_js_1 = require("../../shared/index.js");
|
|
5
5
|
const contract_js_1 = require("./contract.js");
|
|
6
6
|
const index_js_2 = require("../../models/payout/index.js");
|
|
7
|
-
const manager_js_1 = require("../auth/manager.js");
|
|
8
7
|
const permission_js_1 = require("../../models/permission.js");
|
|
9
8
|
const index_js_3 = require("../../errors/index.js");
|
|
10
9
|
const payout_js_1 = require("../../models/payout/derivatives/payout.js");
|
|
@@ -16,9 +15,11 @@ const payout_js_1 = require("../../models/payout/derivatives/payout.js");
|
|
|
16
15
|
class PayoutRepository extends index_js_1.BaseRepository {
|
|
17
16
|
/**
|
|
18
17
|
* Creates an instance of PayoutRepository initialized with the payout contract.
|
|
18
|
+
* @param {Object} [props] - Optional constructor properties
|
|
19
|
+
* @param {AfloatAuth} [props.auth] - Optional auth instance to use
|
|
19
20
|
*/
|
|
20
|
-
constructor() {
|
|
21
|
-
super("payout", contract_js_1.contract);
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super("payout", contract_js_1.contract, { auth: props?.auth });
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Retrieves a paginated list of payouts with optional filtering for pending status.
|
|
@@ -31,8 +32,9 @@ class PayoutRepository extends index_js_1.BaseRepository {
|
|
|
31
32
|
* @returns {Promise<{results: Payout[]; total: number}>} Paginated payout results and total count
|
|
32
33
|
*/
|
|
33
34
|
async getAll(args) {
|
|
35
|
+
const auth = this.getAuthForPermissionCheck();
|
|
34
36
|
const requiredPerm = permission_js_1.Permissions.Payout.List;
|
|
35
|
-
if (!
|
|
37
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
36
38
|
throw new index_js_3.PermissionError({
|
|
37
39
|
message: "You are not authorized to view payouts.",
|
|
38
40
|
requiredPermissions: [requiredPerm],
|
|
@@ -73,8 +75,9 @@ class PayoutRepository extends index_js_1.BaseRepository {
|
|
|
73
75
|
* @returns {Promise<Payout>} The created payout
|
|
74
76
|
*/
|
|
75
77
|
async pay(input) {
|
|
78
|
+
const auth = this.getAuthForPermissionCheck();
|
|
76
79
|
const requiredPerm = permission_js_1.Permissions.Payout.Create;
|
|
77
|
-
if (!
|
|
80
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
78
81
|
throw new index_js_3.PermissionError({
|
|
79
82
|
message: "You are not authorized to create payouts.",
|
|
80
83
|
requiredPermissions: [requiredPerm],
|
|
@@ -98,8 +101,9 @@ class PayoutRepository extends index_js_1.BaseRepository {
|
|
|
98
101
|
* @returns {Promise<Payout>} The approved payout
|
|
99
102
|
*/
|
|
100
103
|
async approve(id, args) {
|
|
104
|
+
const auth = this.getAuthForPermissionCheck();
|
|
101
105
|
const requiredPerm = permission_js_1.Permissions.Payout.Approve;
|
|
102
|
-
if (!
|
|
106
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
103
107
|
throw new index_js_3.PermissionError({
|
|
104
108
|
message: "You are not authorized to approve or reject payouts.",
|
|
105
109
|
requiredPermissions: [requiredPerm],
|
|
@@ -133,8 +137,9 @@ class PayoutRepository extends index_js_1.BaseRepository {
|
|
|
133
137
|
* @returns {Promise<Payout>} The rejected payout
|
|
134
138
|
*/
|
|
135
139
|
async reject(id, args) {
|
|
140
|
+
const auth = this.getAuthForPermissionCheck();
|
|
136
141
|
const requiredPerm = permission_js_1.Permissions.Payout.Approve;
|
|
137
|
-
if (!
|
|
142
|
+
if (!auth.checkPermission(requiredPerm)) {
|
|
138
143
|
throw new index_js_3.PermissionError({
|
|
139
144
|
message: "You are not authorized to approve or reject payouts.",
|
|
140
145
|
requiredPermissions: [requiredPerm],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseRepository } from "../../shared/base_repository.js";
|
|
2
2
|
import { contract } from "./contract.js";
|
|
3
3
|
import type { STATEMENT_OUTPUT_TYPE, StatementFile, Wallet, WalletStatementItem } from "../../models/wallet/index.js";
|
|
4
|
+
import type { AfloatAuth } from "../auth/manager.js";
|
|
4
5
|
/**
|
|
5
6
|
* Repository class for managing wallet operations including balance checking,
|
|
6
7
|
* statement generation, and wallet information retrieval.
|
|
@@ -9,8 +10,14 @@ import type { STATEMENT_OUTPUT_TYPE, StatementFile, Wallet, WalletStatementItem
|
|
|
9
10
|
export declare class WalletRepo extends BaseRepository<typeof contract> {
|
|
10
11
|
/**
|
|
11
12
|
* Creates an instance of WalletRepo initialized with the wallet contract.
|
|
13
|
+
* @param {Object} [options] - Optional configuration
|
|
14
|
+
* @param {string} [options.root] - Custom API root URL
|
|
15
|
+
* @param {AfloatAuth} [options.auth] - Auth instance to use
|
|
12
16
|
*/
|
|
13
|
-
constructor(
|
|
17
|
+
constructor(props?: {
|
|
18
|
+
root?: string;
|
|
19
|
+
auth?: AfloatAuth;
|
|
20
|
+
});
|
|
14
21
|
/**
|
|
15
22
|
* Gets an instance of the file generation repository.
|
|
16
23
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,MAAM,EACN,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,MAAM,EACN,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAC7D;;;;;OAKG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAOxD;;;;OAIG;IACH,OAAO,KAAK,WAAW,GAEtB;IAED;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBnC;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAUrC;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE;YAAE,SAAS,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,IAAI,CAAA;SAAE,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,mBAAmB,EAAE,CAAC;IA4BjC;;;;;;;;;OASG;IACG,YAAY,CAChB,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE;QACL,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC;IAmBzB;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC;CAapD"}
|
|
@@ -4,7 +4,6 @@ exports.WalletRepo = void 0;
|
|
|
4
4
|
const base_repository_js_1 = require("../../shared/base_repository.js");
|
|
5
5
|
const contract_js_1 = require("./contract.js");
|
|
6
6
|
const repository_js_1 = require("../files-gen/repository.js");
|
|
7
|
-
const manager_js_1 = require("../auth/manager.js");
|
|
8
7
|
const permission_js_1 = require("../../models/permission.js");
|
|
9
8
|
const index_js_1 = require("../../errors/index.js");
|
|
10
9
|
/**
|
|
@@ -15,9 +14,15 @@ const index_js_1 = require("../../errors/index.js");
|
|
|
15
14
|
class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
16
15
|
/**
|
|
17
16
|
* Creates an instance of WalletRepo initialized with the wallet contract.
|
|
17
|
+
* @param {Object} [options] - Optional configuration
|
|
18
|
+
* @param {string} [options.root] - Custom API root URL
|
|
19
|
+
* @param {AfloatAuth} [options.auth] - Auth instance to use
|
|
18
20
|
*/
|
|
19
|
-
constructor() {
|
|
20
|
-
super("wallet", contract_js_1.contract
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super("wallet", contract_js_1.contract, {
|
|
23
|
+
root: props?.root,
|
|
24
|
+
auth: props?.auth,
|
|
25
|
+
});
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Gets an instance of the file generation repository.
|
|
@@ -25,7 +30,7 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
25
30
|
* @returns {AfloatFilesRepo} A new instance of AfloatFilesRepo
|
|
26
31
|
*/
|
|
27
32
|
get fileGenRepo() {
|
|
28
|
-
return new repository_js_1.AfloatFilesRepo();
|
|
33
|
+
return new repository_js_1.AfloatFilesRepo({ auth: this.auth });
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* Retrieves the current available balance for the wallet.
|
|
@@ -34,8 +39,9 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
34
39
|
* @returns {Promise<number>} The available balance amount
|
|
35
40
|
*/
|
|
36
41
|
async getBalance() {
|
|
42
|
+
const auth = this.getAuthForPermissionCheck();
|
|
37
43
|
const requirePerm = permission_js_1.Permissions.Wallet.ViewBalance;
|
|
38
|
-
if (!
|
|
44
|
+
if (!auth.checkPermission(requirePerm)) {
|
|
39
45
|
throw new index_js_1.PermissionError({
|
|
40
46
|
message: "You are not authorized to view the account balance.",
|
|
41
47
|
requiredPermissions: [requirePerm],
|
|
@@ -72,8 +78,9 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
72
78
|
* @returns {Promise<WalletStatementItem[]>} Array of statement items for the specified period
|
|
73
79
|
*/
|
|
74
80
|
async getStatement(props) {
|
|
81
|
+
const auth = this.getAuthForPermissionCheck();
|
|
75
82
|
const requirePerm = permission_js_1.Permissions.Wallet.ViewStatement;
|
|
76
|
-
if (!
|
|
83
|
+
if (!auth.checkPermission(requirePerm)) {
|
|
77
84
|
throw new index_js_1.PermissionError({
|
|
78
85
|
message: "You are not authorized to view the statement.",
|
|
79
86
|
requiredPermissions: [requirePerm],
|
|
@@ -103,8 +110,9 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
103
110
|
* @returns {Promise<StatementFile>} The generated statement file
|
|
104
111
|
*/
|
|
105
112
|
async genStatement(fileType, props) {
|
|
113
|
+
const auth = this.getAuthForPermissionCheck();
|
|
106
114
|
const requirePerm = permission_js_1.Permissions.Wallet.ViewStatement;
|
|
107
|
-
if (!
|
|
115
|
+
if (!auth.checkPermission(requirePerm)) {
|
|
108
116
|
throw new index_js_1.PermissionError({
|
|
109
117
|
message: "You are not authorized to view the statement.",
|
|
110
118
|
requiredPermissions: [requirePerm],
|
|
@@ -123,8 +131,9 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
123
131
|
* @returns {Promise<StatementFile>} The generated PDF file containing wallet details
|
|
124
132
|
*/
|
|
125
133
|
async genWalletDetailsPDF() {
|
|
134
|
+
const auth = this.getAuthForPermissionCheck();
|
|
126
135
|
const requirePerm = permission_js_1.Permissions.Wallet.ViewBalance;
|
|
127
|
-
if (!
|
|
136
|
+
if (!auth.checkPermission(requirePerm)) {
|
|
128
137
|
throw new index_js_1.PermissionError({
|
|
129
138
|
message: "You are not authorized to view the account details.",
|
|
130
139
|
requiredPermissions: [requirePerm],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AppRouter } from "@ts-rest/core";
|
|
2
2
|
import type { InitClientArgs } from "@ts-rest/core";
|
|
3
|
+
import { AfloatAuth } from "../features/auth/manager.js";
|
|
3
4
|
/**
|
|
4
5
|
* BaseRepository
|
|
5
6
|
*
|
|
@@ -28,15 +29,38 @@ export declare class BaseRepository<TContract extends AppRouter> {
|
|
|
28
29
|
* @protected
|
|
29
30
|
*/
|
|
30
31
|
protected root: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The auth instance to use for authentication
|
|
34
|
+
*
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
protected auth: AfloatAuth | undefined;
|
|
31
38
|
/**
|
|
32
39
|
* Constructs a new instance of `BaseRepository`.
|
|
33
40
|
*
|
|
34
|
-
* @param contract - The "ts-rest" contract
|
|
35
41
|
* @param endpoint - API endpoint
|
|
42
|
+
* @param contract - The "ts-rest" contract
|
|
43
|
+
* @param args - Optional constructor arguments
|
|
44
|
+
* @param args.root - Optional API root URL
|
|
45
|
+
* @param args.auth - Optional auth instance to use
|
|
36
46
|
*/
|
|
37
47
|
constructor(endpoint: string, contract: TContract, args?: {
|
|
38
48
|
root?: string;
|
|
49
|
+
auth?: AfloatAuth;
|
|
39
50
|
});
|
|
51
|
+
/**
|
|
52
|
+
* Gets an auth instance that can be used for permission checks.
|
|
53
|
+
* Follows a fallback strategy to find a valid auth instance.
|
|
54
|
+
*
|
|
55
|
+
* @protected
|
|
56
|
+
* @returns {AfloatAuth} A valid auth instance
|
|
57
|
+
* @throws {Error} If no valid auth instance is available
|
|
58
|
+
*/
|
|
59
|
+
protected getAuthForPermissionCheck(): AfloatAuth;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the initialized client for making API requests.
|
|
62
|
+
* Uses authentication token if available.
|
|
63
|
+
*/
|
|
40
64
|
get client(): { [TKey in keyof TContract]: TContract[TKey] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey], InitClientArgs>> : TContract[TKey] extends AppRouter ? TContract[TKey] extends infer T extends AppRouter ? { [TKey_1 in keyof T]: TContract[TKey][TKey_1] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1], InitClientArgs>> : TContract[TKey][TKey_1] extends AppRouter ? TContract[TKey][TKey_1] extends infer T_1 extends AppRouter ? { [TKey_2 in keyof T_1]: TContract[TKey][TKey_1][TKey_2] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2] extends AppRouter ? TContract[TKey][TKey_1][TKey_2] extends infer T_2 extends AppRouter ? { [TKey_3 in keyof T_2]: TContract[TKey][TKey_1][TKey_2][TKey_3] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3] extends infer T_3 extends AppRouter ? { [TKey_4 in keyof T_3]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends infer T_4 extends AppRouter ? { [TKey_5 in keyof T_4]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends infer T_5 extends AppRouter ? { [TKey_6 in keyof T_5]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends infer T_6 extends AppRouter ? { [TKey_7 in keyof T_6]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends infer T_7 extends AppRouter ? { [TKey_8 in keyof T_7]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends infer T_8 extends AppRouter ? { [TKey_9 in keyof T_8]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends infer T_9 extends AppRouter ? { [TKey_10 in keyof T_9]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10] extends AppRouter ? any : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; };
|
|
41
65
|
/**
|
|
42
66
|
* Handles the API response by checking the HTTP status code and returning the response body
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_repository.d.ts","sourceRoot":"","sources":["../../../src/src/shared/base_repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"base_repository.d.ts","sourceRoot":"","sources":["../../../src/src/shared/base_repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAe,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;GAQG;AACH,qBAAa,cAAc,CAAC,SAAS,SAAS,SAAS;IACrD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE9B;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAEvC;;;;;;;;OAQG;gBACS,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE;QACxD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB;IASD;;;;;;;OAOG;IACH,SAAS,CAAC,yBAAyB,IAAI,UAAU;IAgBjD;;;OAGG;IACH,IAAI,MAAM,k0LA+BT;IAED;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,EACd,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,EACzC,iBAAiB,EAAE,MAAM,GACxB,CAAC;CAgBL"}
|
|
@@ -4,7 +4,7 @@ exports.BaseRepository = void 0;
|
|
|
4
4
|
const core_1 = require("@ts-rest/core");
|
|
5
5
|
const api_error_js_1 = require("../errors/api_error.js");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
|
-
const
|
|
7
|
+
const manager_js_1 = require("../features/auth/manager.js");
|
|
8
8
|
/**
|
|
9
9
|
* BaseRepository
|
|
10
10
|
*
|
|
@@ -18,8 +18,11 @@ class BaseRepository {
|
|
|
18
18
|
/**
|
|
19
19
|
* Constructs a new instance of `BaseRepository`.
|
|
20
20
|
*
|
|
21
|
-
* @param contract - The "ts-rest" contract
|
|
22
21
|
* @param endpoint - API endpoint
|
|
22
|
+
* @param contract - The "ts-rest" contract
|
|
23
|
+
* @param args - Optional constructor arguments
|
|
24
|
+
* @param args.root - Optional API root URL
|
|
25
|
+
* @param args.auth - Optional auth instance to use
|
|
23
26
|
*/
|
|
24
27
|
constructor(endpoint, contract, args) {
|
|
25
28
|
/**
|
|
@@ -55,18 +58,73 @@ class BaseRepository {
|
|
|
55
58
|
writable: true,
|
|
56
59
|
value: void 0
|
|
57
60
|
});
|
|
61
|
+
/**
|
|
62
|
+
* The auth instance to use for authentication
|
|
63
|
+
*
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
Object.defineProperty(this, "auth", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
58
72
|
this.contract = contract;
|
|
59
73
|
this.endpoint = endpoint;
|
|
60
74
|
this.root = args?.root;
|
|
75
|
+
// Use provided auth or try to get the current context
|
|
76
|
+
this.auth = args?.auth || manager_js_1.AuthContext.current;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets an auth instance that can be used for permission checks.
|
|
80
|
+
* Follows a fallback strategy to find a valid auth instance.
|
|
81
|
+
*
|
|
82
|
+
* @protected
|
|
83
|
+
* @returns {AfloatAuth} A valid auth instance
|
|
84
|
+
* @throws {Error} If no valid auth instance is available
|
|
85
|
+
*/
|
|
86
|
+
getAuthForPermissionCheck() {
|
|
87
|
+
// Use the instance provided in constructor, or fallback to context
|
|
88
|
+
const auth = this.auth || manager_js_1.AuthContext.current;
|
|
89
|
+
if (!auth) {
|
|
90
|
+
try {
|
|
91
|
+
// Last resort: try to get the client singleton
|
|
92
|
+
return manager_js_1.AfloatAuth.instance;
|
|
93
|
+
}
|
|
94
|
+
catch (_) {
|
|
95
|
+
throw new Error(`No valid auth instance available for ${this.endpoint} repository`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return auth;
|
|
61
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the initialized client for making API requests.
|
|
102
|
+
* Uses authentication token if available.
|
|
103
|
+
*/
|
|
62
104
|
get client() {
|
|
63
105
|
const baseUrl = this.root
|
|
64
106
|
? `${this.root}/${this.endpoint}`
|
|
65
107
|
: `https://api.afloat.money/v1/${this.endpoint}`;
|
|
108
|
+
let token = "";
|
|
109
|
+
// Try to get token from the provided auth instance
|
|
110
|
+
if (this.auth) {
|
|
111
|
+
token = this.auth.getUserToken() ?? "";
|
|
112
|
+
}
|
|
113
|
+
// Fall back to singleton if no auth was provided, but handle exceptions
|
|
114
|
+
// that occur in server environments
|
|
115
|
+
else {
|
|
116
|
+
try {
|
|
117
|
+
token = manager_js_1.AfloatAuth.instance.getUserToken() ?? "";
|
|
118
|
+
}
|
|
119
|
+
catch (_) {
|
|
120
|
+
// This will fail when called within the server without initialization
|
|
121
|
+
// We'll proceed with an empty token
|
|
122
|
+
}
|
|
123
|
+
}
|
|
66
124
|
const args = {
|
|
67
125
|
baseUrl,
|
|
68
126
|
baseHeaders: {
|
|
69
|
-
"token":
|
|
127
|
+
"token": token,
|
|
70
128
|
"x-request-id": (0, uuid_1.v4)(),
|
|
71
129
|
},
|
|
72
130
|
};
|