@jsm-mit/rabbit-motoko-package 0.2.18 → 0.2.20

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,19 +1,10 @@
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
- private executeFunction;
6
+ constructor(canisterId: string, identity?: Secp256k1KeyIdentity);
7
+ protected initActor(): void;
17
8
  addTaskAsync(args: AddTaskArgs, throwException: boolean): Promise<bigint | null>;
18
9
  claimTaskAsync(args: ClaimTaskArgs, throwException: boolean): Promise<Task | null>;
19
10
  completeTaskAsync(args: CompleteTaskArgs, throwException: boolean): Promise<boolean>;
@@ -1 +1 @@
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,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,QA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E,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,69 +12,6 @@ export class RabbitMotokoActor {
26
12
  canisterId: this.canisterId,
27
13
  });
28
14
  }
29
- async setupAgent() {
30
- try {
31
- await this.agent.syncTime();
32
- console.log("✅ Agent IC zsynchronizowany pomyślnie.");
33
- }
34
- catch (err) {
35
- console.error("❌ Błąd podczas konfiguracji Agenta:", err);
36
- }
37
- }
38
- async runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(fnAsync) {
39
- try {
40
- return await fnAsync();
41
- }
42
- catch (error) {
43
- const errorMsg = BetterJSON.stringify(error);
44
- pigeon.debugEmailAsyncSafe("Problem at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe", "RabbitMotokoActor", [], errorMsg);
45
- if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
46
- console.warn("⚠️ Wykryto problem z czasem. Próbuję synchronizacji...");
47
- await this.syncTimeAsync(false);
48
- try {
49
- return await fnAsync();
50
- }
51
- catch (err) {
52
- console.error(BetterJSON.stringify(err));
53
- throw err;
54
- }
55
- }
56
- else {
57
- throw error;
58
- }
59
- }
60
- }
61
- handleResultErrors(functionName, params, error) {
62
- pigeon.debugEmailAsyncSafe("debug", functionName, params, BetterJSON.stringify(error));
63
- const errorKey = Object.keys(error)[0];
64
- const errorMessage = error[errorKey];
65
- return { errorKey, errorMessage };
66
- }
67
- async syncTimeAsync(throwError) {
68
- try {
69
- await this.agent.syncTime();
70
- }
71
- catch (err) {
72
- if (throwError)
73
- throw err;
74
- }
75
- }
76
- async executeFunction(fnAsync, errorMessage, functionName, params, defaultValue, throwException) {
77
- try {
78
- const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(fnAsync);
79
- if ('ok' in result) {
80
- return result.ok;
81
- }
82
- this.handleResultErrors(functionName, params, result.err);
83
- return defaultValue;
84
- }
85
- catch (err) {
86
- logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
87
- if (throwException)
88
- throw err;
89
- return defaultValue;
90
- }
91
- }
92
15
  // --- Public Actor Methods ---
93
16
  async addTaskAsync(args, throwException) {
94
17
  return await this.executeFunction(() => this.actor.addTask(args), "Network error: add task failed", "addTaskAsync", [args, throwException], null, throwException);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/rabbit-motoko-package",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
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.2",
31
- "@jsm-mit/utils-package": "^0.2.2"
30
+ "@jsm-mit/pigeon-package": "^0.7.0",
31
+ "@jsm-mit/utils-package": "^0.2.2",
32
+ "@jsm-mit/jsm-framework": "^0.0.12"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/node": "^25.5.2",