@jsm-mit/rabbit-motoko-package 0.1.33 → 0.1.35
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.
|
@@ -9,7 +9,7 @@ export declare class RabbitMotokoActor {
|
|
|
9
9
|
constructor(canisterId: string, identity?: Secp256k1KeyIdentity);
|
|
10
10
|
private initActor;
|
|
11
11
|
private setupAgent;
|
|
12
|
-
private
|
|
12
|
+
private runFunctionSafely;
|
|
13
13
|
syncTimeAsync(throwError: boolean): Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* Adds a new task to the queue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAAoE,CAAC;
|
|
1
|
+
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAAoE,CAAC;AAGvJ,qBAAa,iBAAiB;IAMd,OAAO,CAAC,QAAQ,CAAC,UAAU;IALvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,YAAY,CAAa;gBAEJ,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,oBAAoB;IAehF,OAAO,CAAC,SAAS;YAOH,UAAU;YAYV,iBAAiB;IAiClB,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAc9D;;OAEG;IACU,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlF;;OAEG;IACU,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAI3F;;OAEG;IACU,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7F;;OAEG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9F;;OAEG;IACU,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAInD,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAMjE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Actor, HttpAgent } from "@icp-sdk/core/agent";
|
|
2
2
|
import { Secp256k1KeyIdentity } from "@icp-sdk/core/identity/secp256k1";
|
|
3
3
|
import { idlFactory } from "../declarations/rabbit-motoko-backend/index.js";
|
|
4
|
+
import { BetterJSON } from "@jsm-mit/utils-package";
|
|
4
5
|
export class RabbitMotokoActor {
|
|
5
6
|
constructor(canisterId, identity) {
|
|
6
7
|
this.canisterId = canisterId;
|
|
@@ -34,11 +35,35 @@ export class RabbitMotokoActor {
|
|
|
34
35
|
console.error("❌ Błąd podczas konfiguracji Agenta:", err);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
async
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
async runFunctionSafely(fn, throwError) {
|
|
39
|
+
try {
|
|
40
|
+
return fn();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const errorMsg = error?.toString() || "";
|
|
44
|
+
if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
|
|
45
|
+
console.warn("⚠️ Wykryto problem z zaufaniem/czasem. Próbuję synchronizacji...");
|
|
46
|
+
await this.syncTimeAsync(false);
|
|
47
|
+
try {
|
|
48
|
+
return fn();
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.error(BetterJSON.stringify(err));
|
|
52
|
+
if (throwError) {
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
console.error(BetterJSON.stringify(error));
|
|
61
|
+
if (throwError) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
42
67
|
}
|
|
43
68
|
}
|
|
44
69
|
async syncTimeAsync(throwError) {
|
|
@@ -58,110 +83,36 @@ export class RabbitMotokoActor {
|
|
|
58
83
|
* Adds a new task to the queue.
|
|
59
84
|
*/
|
|
60
85
|
async addTaskAsync(args, throwError) {
|
|
61
|
-
|
|
62
|
-
return await this.actor.addTask(args);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
await this.checkError(error);
|
|
66
|
-
console.error(`❌ Błąd podczas dodawania zadania:`, error);
|
|
67
|
-
if (throwError) {
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return BigInt(0);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
86
|
+
return this.runFunctionSafely(() => this.actor.addTask(args), throwError);
|
|
74
87
|
}
|
|
75
88
|
/**
|
|
76
89
|
* Claims a task for a specific worker.
|
|
77
90
|
*/
|
|
78
91
|
async claimTaskAsync(args, throwError) {
|
|
79
|
-
|
|
80
|
-
return await this.actor.claimTask(args);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
await this.checkError(error);
|
|
84
|
-
console.error(`❌ Błąd podczas pobierania zadania (claimTask):`, error);
|
|
85
|
-
if (throwError) {
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
+
return this.runFunctionSafely(() => this.actor.claimTask(args), throwError);
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
94
95
|
* Completes a previously claimed task.
|
|
95
96
|
*/
|
|
96
97
|
async completeTaskAsync(args, throwError) {
|
|
97
|
-
|
|
98
|
-
return await this.actor.completeTask(args);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
await this.checkError(error);
|
|
102
|
-
console.error(`❌ Błąd podczas zakończenia zadania:`, error);
|
|
103
|
-
if (throwError) {
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
98
|
+
return this.runFunctionSafely(() => this.actor.completeTask(args), throwError);
|
|
110
99
|
}
|
|
111
100
|
/**
|
|
112
101
|
* Fetches IDs of tasks available in a specific channel.
|
|
113
102
|
*/
|
|
114
103
|
async getAvailableTaskIdsAsync(channel, throwError) {
|
|
115
|
-
|
|
116
|
-
const fifteenMinutes = 15 * 60 * 1000;
|
|
117
|
-
if (Date.now() - this.lastSyncTime > fifteenMinutes) {
|
|
118
|
-
await this.syncTimeAsync(false);
|
|
119
|
-
}
|
|
120
|
-
return await this.actor.getAvailableTaskIds(channel);
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
await this.checkError(error);
|
|
124
|
-
console.error(`❌ Błąd podczas pobierania ID zadań (Kanał: ${channel}):`, error);
|
|
125
|
-
if (throwError) {
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
104
|
+
return this.runFunctionSafely(() => this.actor.getAvailableTaskIds(channel), throwError);
|
|
132
105
|
}
|
|
133
106
|
/**
|
|
134
107
|
* Returns a list of all tasks.
|
|
135
108
|
*/
|
|
136
109
|
async getTasksAsync(throwError) {
|
|
137
|
-
|
|
138
|
-
return await this.actor.getTasks();
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
await this.checkError(error);
|
|
142
|
-
console.error(`❌ Błąd podczas pobierania wszystkich zadań (getTasks):`, error);
|
|
143
|
-
if (throwError) {
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return [];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
110
|
+
return this.runFunctionSafely(() => this.actor.getTasks(), throwError);
|
|
150
111
|
}
|
|
151
112
|
async whoAmIAsync(throwError) {
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
await this.checkError(error);
|
|
158
|
-
console.error(`❌ Błąd podczas pobierania informacji o użytkowniku (whoAmI):`, error);
|
|
159
|
-
if (throwError) {
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return "";
|
|
164
|
-
}
|
|
165
|
-
}
|
|
113
|
+
return this.runFunctionSafely(() => {
|
|
114
|
+
const result = this.actor.whoAmI();
|
|
115
|
+
return Promise.resolve(result.toString());
|
|
116
|
+
}, throwError);
|
|
166
117
|
}
|
|
167
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsm-mit/rabbit-motoko-package",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "Wrapper TypeScript package for Rabbit Motoko Canister.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@jsm-mit/pigeon-package": "0.0
|
|
28
|
+
"@jsm-mit/pigeon-package": "^0.1.0",
|
|
29
29
|
"@jsm-mit/utils-package": "^0.1.0",
|
|
30
30
|
"@icp-sdk/core": "^5.2.0"
|
|
31
31
|
}
|