@jsm-mit/rabbit-motoko-package 0.2.17 → 0.2.19

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,35 +1,13 @@
1
1
  import { Secp256k1KeyIdentity } from "@icp-sdk/core/identity/secp256k1";
2
2
  import type { AddTaskArgs, ClaimTaskArgs, CompleteTaskArgs, Task } from "../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js";
3
- export declare class RabbitMotokoActor {
4
- private readonly canisterId;
5
- private readonly identity?;
6
- private readonly host;
3
+ import { ActorBase } from "@jsm-mit/jsm-framework";
4
+ export declare class RabbitMotokoActor extends ActorBase {
7
5
  private actor;
8
- private agent;
9
- constructor(canisterId: string, identity?: Secp256k1KeyIdentity | undefined);
10
- reinitializeAgent(): void;
11
- private initActor;
12
- private setupAgent;
13
- private runFunctionAndSyncTimeIfNecessaryAsyncUnsafe;
14
- private handleResultErrors;
15
- syncTimeAsync(throwError: boolean): Promise<void>;
16
- testErrWithText(): Promise<import("../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js").Result>;
17
- testError(): Promise<import("../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js").Result>;
18
- /**
19
- * Adds a new task to the queue.
20
- */
6
+ constructor(canisterId: string, identity?: Secp256k1KeyIdentity);
7
+ protected initActor(): void;
21
8
  addTaskAsync(args: AddTaskArgs, throwException: boolean): Promise<bigint | null>;
22
- /**
23
- * Claims a task for a specific worker.
24
- */
25
9
  claimTaskAsync(args: ClaimTaskArgs, throwException: boolean): Promise<Task | null>;
26
- /**
27
- * Completes a previously claimed task.
28
- */
29
10
  completeTaskAsync(args: CompleteTaskArgs, throwException: boolean): Promise<boolean>;
30
- /**
31
- * Fetches IDs of tasks available in a specific channel.
32
- */
33
11
  getAvailableTaskIdsAsync(channel: string, throwException: boolean): Promise<bigint[]>;
34
12
  }
35
13
  //# sourceMappingURL=rabbit-motoko-actor.d.ts.map
@@ -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,EAAS,IAAI,EAAE,MAAM,oEAAoE,CAAC;AAI9J,qBAAa,iBAAiB;IAKd,OAAO,CAAC,QAAQ,CAAC,UAAU;IAAU,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAJ3E,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAa;gBAEG,UAAU,EAAE,MAAM,EAAmB,QAAQ,CAAC,EAAE,oBAAoB,YAAA;IAK1F,iBAAiB;IAYxB,OAAO,CAAC,SAAS;YAOH,UAAU;YAWV,4CAA4C;IA4B1D,OAAO,CAAC,kBAAkB;IAWb,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAajD,eAAe;IAIf,SAAS;IAItB;;OAEG;IACU,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAwB7F;;OAEG;IACU,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAwB/F;;OAEG;IACU,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAwBjG;;OAEG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAwBrG"}
1
+ {"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAAoE,CAAC;AACvJ,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,qBAAa,iBAAkB,SAAQ,SAAS;IAC5C,OAAO,CAAC,KAAK,CAA2B;gBAE5B,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,oBAAoB;IAI/D,SAAS,CAAC,SAAS;IASN,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAWhF,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAWlF,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAWpF,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAUrG"}
@@ -1,24 +1,10 @@
1
- import { Actor, HttpAgent } from "@icp-sdk/core/agent";
1
+ import { Actor } 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, logErrorLocallyAndPublishOnErrorSubject } from "@jsm-mit/utils-package";
5
- import { pigeon } from "@jsm-mit/pigeon-package";
6
- export class RabbitMotokoActor {
4
+ import { ActorBase } from "@jsm-mit/jsm-framework";
5
+ export class RabbitMotokoActor extends ActorBase {
7
6
  constructor(canisterId, identity) {
8
- this.canisterId = canisterId;
9
- this.identity = identity;
10
- this.host = "https://icp0.io";
11
- this.reinitializeAgent();
12
- this.setupAgent();
13
- }
14
- reinitializeAgent() {
15
- console.log("Agent reinitialization");
16
- this.agent = HttpAgent.createSync({
17
- host: this.host,
18
- ingressExpiryInMinutes: 1,
19
- identity: this.identity
20
- });
21
- this.initActor();
7
+ super(canisterId, identity);
22
8
  }
23
9
  initActor() {
24
10
  this.actor = Actor.createActor(idlFactory, {
@@ -26,166 +12,17 @@ export class RabbitMotokoActor {
26
12
  canisterId: this.canisterId,
27
13
  });
28
14
  }
29
- async setupAgent() {
30
- try {
31
- // Synchronizacja czasu z siecią IC - rozwiązuje błąd "certificate is still too far in the future"
32
- await this.agent.syncTime();
33
- console.log("✅ Agent IC zsynchronizowany pomyślnie.");
34
- }
35
- catch (err) {
36
- console.error("❌ Błąd podczas konfiguracji Agenta:", err);
37
- }
38
- }
39
- async runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(fnAsync) {
40
- try {
41
- return await fnAsync();
42
- }
43
- catch (error) {
44
- const errorMsg = BetterJSON.stringify(error);
45
- pigeon.debugEmailAsyncSafe("Problem at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe", "runFunctionAndSyncTimeIfNecessaryAsyncUnsafe", [], errorMsg);
46
- if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
47
- console.warn("⚠️ Wykryto problem z zaufaniem/czasem. Próbuję synchronizacji...");
48
- await this.syncTimeAsync(false);
49
- try {
50
- return await fnAsync();
51
- }
52
- catch (err) {
53
- console.error(BetterJSON.stringify(err));
54
- throw err;
55
- }
56
- }
57
- else {
58
- console.error(`Error at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe: ${errorMsg}`);
59
- throw error;
60
- }
61
- }
62
- }
63
- handleResultErrors(functionName, params, error) {
64
- pigeon.debugEmailAsyncSafe("debug", functionName, params, BetterJSON.stringify(error));
65
- const errorKey = Object.keys(error)[0];
66
- const errorMessage = error[errorKey];
67
- return {
68
- errorKey,
69
- errorMessage
70
- };
71
- }
72
- async syncTimeAsync(throwError) {
73
- try {
74
- await this.agent.syncTime();
75
- console.log("🔄 Czas agenta został zsynchronizowany ponownie.");
76
- }
77
- catch (err) {
78
- console.error("❌ Nie udało się zsynchronizować czasu:", err);
79
- if (throwError) {
80
- throw err;
81
- }
82
- }
83
- }
84
- async testErrWithText() {
85
- return this.actor.testErrWithText();
86
- }
87
- async testError() {
88
- return this.actor.testError();
89
- }
90
- /**
91
- * Adds a new task to the queue.
92
- */
15
+ // --- Public Actor Methods ---
93
16
  async addTaskAsync(args, throwException) {
94
- const errorMessage = "Network error: add task failed";
95
- try {
96
- const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.addTask(args));
97
- if ('ok' in result) {
98
- return result.ok;
99
- }
100
- else {
101
- this.handleResultErrors("addTaskAsync", [args, throwException], result.err);
102
- return null;
103
- }
104
- }
105
- catch (err) {
106
- logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
107
- if (throwException) {
108
- throw err;
109
- }
110
- else {
111
- return null;
112
- }
113
- }
17
+ return await this.executeFunction(() => this.actor.addTask(args), "Network error: add task failed", "addTaskAsync", [args, throwException], null, throwException);
114
18
  }
115
- /**
116
- * Claims a task for a specific worker.
117
- */
118
19
  async claimTaskAsync(args, throwException) {
119
- const errorMessage = "Network error: claim task failed";
120
- try {
121
- const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.claimTask(args));
122
- if ('ok' in result) {
123
- return result.ok;
124
- }
125
- else {
126
- this.handleResultErrors("claimTaskAsync", [args, throwException], result.err);
127
- return null;
128
- }
129
- }
130
- catch (err) {
131
- logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
132
- if (throwException) {
133
- throw err;
134
- }
135
- else {
136
- return null;
137
- }
138
- }
20
+ return await this.executeFunction(() => this.actor.claimTask(args), "Network error: claim task failed", "claimTaskAsync", [args, throwException], null, throwException);
139
21
  }
140
- /**
141
- * Completes a previously claimed task.
142
- */
143
22
  async completeTaskAsync(args, throwException) {
144
- const errorMessage = "Network error: complete task failed";
145
- try {
146
- const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.completeTask(args));
147
- if ('ok' in result) {
148
- return result.ok;
149
- }
150
- else {
151
- this.handleResultErrors("completeTaskAsync", [args, throwException], result.err);
152
- return false;
153
- }
154
- }
155
- catch (err) {
156
- logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
157
- if (throwException) {
158
- throw err;
159
- }
160
- else {
161
- return false;
162
- }
163
- }
23
+ return await this.executeFunction(() => this.actor.completeTask(args), "Network error: complete task failed", "completeTaskAsync", [args, throwException], false, throwException);
164
24
  }
165
- /**
166
- * Fetches IDs of tasks available in a specific channel.
167
- */
168
25
  async getAvailableTaskIdsAsync(channel, throwException) {
169
- const errorMessage = "Network error: get available task IDs failed";
170
- try {
171
- const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.getAvailableTaskIds(channel));
172
- if ('ok' in result) {
173
- return result.ok;
174
- }
175
- else {
176
- this.handleResultErrors("getAvailableTaskIdsAsync", [channel, throwException], result.err);
177
- return [];
178
- }
179
- }
180
- catch (err) {
181
- console.log("catch getAvailableTaskIdsAsync catch");
182
- logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
183
- if (throwException) {
184
- throw err;
185
- }
186
- else {
187
- return [];
188
- }
189
- }
26
+ return await this.executeFunction(() => this.actor.getAvailableTaskIds(channel), "Network error: get available task IDs failed", "getAvailableTaskIdsAsync", [channel, throwException], [], throwException);
190
27
  }
191
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/rabbit-motoko-package",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "Wrapper TypeScript package for Rabbit Motoko Canister.",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -27,8 +27,9 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@icp-sdk/core": "^5.2.0",
30
- "@jsm-mit/pigeon-package": "^0.6.1",
31
- "@jsm-mit/utils-package": "^0.2.2"
30
+ "@jsm-mit/pigeon-package": "^0.6.4",
31
+ "@jsm-mit/utils-package": "^0.2.2",
32
+ "@jsm-mit/jsm-framework": "^0.0.6"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/node": "^25.5.2",