@jsm-mit/tigi-sharded-package 0.1.0 → 0.3.0
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/README.md +85 -2
- package/declarations/coordinator/coordinator.did +68 -31
- package/declarations/coordinator/coordinator.did.d.ts +90 -30
- package/declarations/coordinator/coordinator.did.js +55 -31
- package/declarations/core/core.did +146 -40
- package/declarations/core/core.did.d.ts +137 -41
- package/declarations/core/core.did.js +93 -34
- package/dist/actors/driver-canisters-actor.d.ts +77 -0
- package/dist/actors/driver-canisters-actor.d.ts.map +1 -0
- package/dist/actors/driver-canisters-actor.js +147 -0
- package/dist/actors/profiles-actor.d.ts +9 -1
- package/dist/actors/profiles-actor.d.ts.map +1 -1
- package/dist/actors/profiles-actor.js +16 -0
- package/dist/actors/rides-actor.d.ts +12 -1
- package/dist/actors/rides-actor.d.ts.map +1 -1
- package/dist/actors/rides-actor.js +17 -0
- package/dist/chat.d.ts +51 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +87 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/interfaces.d.ts +47 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The driver canister of the signed-in person in the core's factory (fabryka.md F-5 … F-8,
|
|
2
|
+
// F-20; U-45): the demo lease, its extension, "mine", and the one-time claim code that hands
|
|
3
|
+
// a demo canister over to the driver's principal on the canister's own front.
|
|
4
|
+
//
|
|
5
|
+
// Internet Identity gives one person a different principal on every origin: the lease is
|
|
6
|
+
// taken on the rider's site, the driver signs in on `https://<canister>.icp0.io`. The
|
|
7
|
+
// rider's site shows the link `claimLinkOf(canisterId, code)`; the driver's front reads the
|
|
8
|
+
// code with `claimCodeOfHash(location.hash)` and calls `claimAsyncUnsafe` as the driver.
|
|
9
|
+
//
|
|
10
|
+
// The driver canister's id is the driver's own address (the link of his front), so these
|
|
11
|
+
// views carry it — unlike the rider's views of other drivers (U-14).
|
|
12
|
+
import { Principal } from "@icp-sdk/core/principal";
|
|
13
|
+
import { errorKeyOf, executeAsyncUnsafe } from "../group/canister-actor.js";
|
|
14
|
+
import { TigiGroup } from "../group/group.js";
|
|
15
|
+
import { msOf } from "../mappers.js";
|
|
16
|
+
/** The fragment key of a claim link: `https://<canister>.icp0.io/#claim=<code>`. */
|
|
17
|
+
export const CLAIM_FRAGMENT_KEY = "claim";
|
|
18
|
+
/** F-20a: a code is 32 characters of base64url; the core refuses more than this. */
|
|
19
|
+
export const MAX_CLAIM_CODE_CHARS = 64;
|
|
20
|
+
/**
|
|
21
|
+
* F-20: the link the rider's site shows after a lease ("Otwórz swój kanister"). The code
|
|
22
|
+
* rides in the fragment, which the browser never sends to a server.
|
|
23
|
+
* @param frontOrigin the origin of the driver canister's front; default `https://<canister>.icp0.io`
|
|
24
|
+
*/
|
|
25
|
+
export function claimLinkOf(canisterId, code, frontOrigin = `https://${canisterId}.icp0.io`) {
|
|
26
|
+
return `${frontOrigin}/#${CLAIM_FRAGMENT_KEY}=${encodeURIComponent(code)}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* F-20: the claim code in a location hash (`#claim=<code>`, also among other `&` parts), or
|
|
30
|
+
* undefined. The driver's front clears the fragment after the claim.
|
|
31
|
+
*/
|
|
32
|
+
export function claimCodeOfHash(hash) {
|
|
33
|
+
const text = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
34
|
+
for (const part of text.split("&")) {
|
|
35
|
+
const [key, ...rest] = part.split("=");
|
|
36
|
+
if (key !== CLAIM_FRAGMENT_KEY)
|
|
37
|
+
continue;
|
|
38
|
+
let code;
|
|
39
|
+
try {
|
|
40
|
+
code = decodeURIComponent(rest.join("="));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return code.length > 0 && code.length <= MAX_CLAIM_CODE_CHARS && /^[A-Za-z0-9_-]+$/.test(code) ? code : undefined;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/** @internal */
|
|
50
|
+
export function driverCanisterOf(record) {
|
|
51
|
+
const until = record.leaseUntilNs[0];
|
|
52
|
+
return {
|
|
53
|
+
canisterId: record.canister.toText(),
|
|
54
|
+
kind: "pool" in record.kind ? "pool" : "own",
|
|
55
|
+
ownerPrincipal: record.owner.toText(),
|
|
56
|
+
leaseUntilMs: until === undefined ? undefined : msOf(BigInt(until)),
|
|
57
|
+
blocked: record.blocked,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** @internal */
|
|
61
|
+
export function claimCodeOf(claim) {
|
|
62
|
+
return { canisterId: claim.canister.toText(), code: claim.code, expiresAtMs: msOf(BigInt(claim.expiresAtNs)) };
|
|
63
|
+
}
|
|
64
|
+
export class DriverCanistersActor {
|
|
65
|
+
group;
|
|
66
|
+
constructor(coordinatorId, identity, options = {}) {
|
|
67
|
+
this.group = TigiGroup.of(coordinatorId, identity, options);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* F-5 … F-7, F-20a: a demo canister for 15 minutes, reinstalled with the caller as its
|
|
71
|
+
* owner — or the caller's lease already (no reinstall, no code: `newClaimCodeAsyncUnsafe`).
|
|
72
|
+
* @returns `leased` with `claim` after a fresh lease (undefined when the core could make
|
|
73
|
+
* no code — ask `newClaimCodeAsyncUnsafe`); `busy` with the time the pool frees up
|
|
74
|
+
* @throws Error with message `CanisterError` — `NotAuthorized` (prod), `NotFound` (no pool),
|
|
75
|
+
* `InvalidData` (no driver wasm), `RemoteCanisterError` (the install failed)
|
|
76
|
+
* @throws Error with message `CallRefusedAtInspectionStage` — anonymous, or the daily limit (30)
|
|
77
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
78
|
+
*/
|
|
79
|
+
async leaseDemoAsyncUnsafe() {
|
|
80
|
+
const answer = await executeAsyncUnsafe(async () => (await this.group.coreAsync()).leaseDemoDriverCanister());
|
|
81
|
+
if ("busy" in answer)
|
|
82
|
+
return { kind: "busy", untilMs: msOf(BigInt(answer.busy.untilNs)) };
|
|
83
|
+
const leased = answer.leased;
|
|
84
|
+
const claim = leased.claim[0];
|
|
85
|
+
return { kind: "leased", canister: driverCanisterOf(leased), claim: claim === undefined ? undefined : claimCodeOf(claim) };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* F-8: 15 minutes more for the holder of the demo canister (at most 30 ahead), also after
|
|
89
|
+
* the end while nobody took it over. The owner stays (F-20f).
|
|
90
|
+
* @throws Error with message `CanisterError` — `NotFound` (no lease of the caller), `InvalidData` (being installed)
|
|
91
|
+
* @throws Error with message `CallRefusedAtInspectionStage` — anonymous, or the daily limit (30)
|
|
92
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
93
|
+
*/
|
|
94
|
+
async extendDemoAsyncUnsafe() {
|
|
95
|
+
return driverCanisterOf(await executeAsyncUnsafe(async () => (await this.group.coreAsync()).extendDemoLease()));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The caller's own driver canister, or the demo canister the caller holds now (as the
|
|
99
|
+
* lease holder — after a claim the canister's owner is the driver, `ownerPrincipal`).
|
|
100
|
+
* @returns undefined when the caller has none
|
|
101
|
+
* @throws Error with message `CanisterError` — `NotAuthorized` (anonymous)
|
|
102
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
103
|
+
*/
|
|
104
|
+
async getMineAsyncUnsafe() {
|
|
105
|
+
try {
|
|
106
|
+
return driverCanisterOf(await executeAsyncUnsafe(async () => (await this.group.coreAsync()).getMyDriverCanister()));
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
if (errorKeyOf(err) === "NotFound")
|
|
110
|
+
return undefined;
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* F-20c: a new claim code for the caller's running demo lease ("Nowy link"); the code
|
|
116
|
+
* before it stops working. Good for 15 minutes, once.
|
|
117
|
+
* @throws Error with message `CanisterError` — `NotFound` (no running lease of the caller),
|
|
118
|
+
* `InvalidData` (being installed), `RemoteCanisterError` (no randomness — try again)
|
|
119
|
+
* @throws Error with message `CallRefusedAtInspectionStage` — anonymous, or the daily limit (30)
|
|
120
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
121
|
+
*/
|
|
122
|
+
async newClaimCodeAsyncUnsafe() {
|
|
123
|
+
return claimCodeOf(await executeAsyncUnsafe(async () => (await this.group.coreAsync()).newClaimCode()));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* F-20d, F-20e: the caller — the driver signed in on the canister's own front — takes
|
|
127
|
+
* over the demo canister with the code of the link. The canister's owner becomes the
|
|
128
|
+
* caller, and so does the recipient of its chat room; the lease stays with its holder.
|
|
129
|
+
* @returns the canister with the caller as `ownerPrincipal`
|
|
130
|
+
* @throws Error with message `CanisterError` — `NotAuthorized` (the code is wrong, expired,
|
|
131
|
+
* used, or not for this canister — one answer for all), `InvalidData` (the canister
|
|
132
|
+
* is busy — try again), `RemoteCanisterError` (the driver canister did not take it;
|
|
133
|
+
* the code stays good)
|
|
134
|
+
* @throws Error with message `CallRefusedAtInspectionStage` — anonymous, or the daily limit (30)
|
|
135
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
136
|
+
*/
|
|
137
|
+
async claimAsyncUnsafe(canisterId, code) {
|
|
138
|
+
let canister;
|
|
139
|
+
try {
|
|
140
|
+
canister = Principal.fromText(canisterId);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
throw new Error("CanisterError", { cause: { errorKey: "InvalidData", errorMessage: "not a canister id", logs: [] } });
|
|
144
|
+
}
|
|
145
|
+
return driverCanisterOf(await executeAsyncUnsafe(async () => (await this.group.coreAsync()).claimDriverCanister({ canister, code })));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Identity } from "@icp-sdk/core/agent";
|
|
2
2
|
import { type GroupOptions } from "../group/canister-actor.js";
|
|
3
|
-
import type { Profile, RideHistoryPage } from "../interfaces.js";
|
|
3
|
+
import type { MyRatingView, Profile, RideHistoryPage } from "../interfaces.js";
|
|
4
4
|
/** KU-1: a page of the rider's history. */
|
|
5
5
|
export declare const RIDES_PAGE = 20;
|
|
6
6
|
export declare class ProfilesActor {
|
|
@@ -21,6 +21,14 @@ export declare class ProfilesActor {
|
|
|
21
21
|
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
22
22
|
*/
|
|
23
23
|
setMyProfileAsyncUnsafe(name: string): Promise<Profile>;
|
|
24
|
+
/**
|
|
25
|
+
* C-16, PF-4: the signed-in user's rating as a rider ("★ 4,87"). Ratings reach the core
|
|
26
|
+
* in the workers' batches, up to a minute after the driver rated (K-9).
|
|
27
|
+
* @returns undefined while nobody rated the user ("Brak ocen")
|
|
28
|
+
* @throws Error with message `CanisterError` — `NotAuthorized` (anonymous)
|
|
29
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
30
|
+
*/
|
|
31
|
+
getMyRatingAsyncUnsafe(): Promise<MyRatingView | undefined>;
|
|
24
32
|
/**
|
|
25
33
|
* C-8, KU-1: the rider's rides, newest first, `RIDES_PAGE` a page. A ride reaches the core
|
|
26
34
|
* up to a minute after its end (K-9, KU-2).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles-actor.d.ts","sourceRoot":"","sources":["../../src/actors/profiles-actor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAkC,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/F,OAAO,KAAK,EAAE,OAAO,EAA6B,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"profiles-actor.d.ts","sourceRoot":"","sources":["../../src/actors/profiles-actor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAkC,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/F,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAA6B,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAG1G,2CAA2C;AAC3C,eAAO,MAAM,UAAU,KAAK,CAAC;AAkB7B,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;gBAEtB,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,YAAiB;IAIjF;;;;;;OAMG;IACU,uBAAuB,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IASpE;;;;;OAKG;IACU,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpE;;;;;;OAMG;IACU,sBAAsB,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAUxE;;;;;;OAMG;IACU,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,MAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;CAS5G"}
|
|
@@ -49,6 +49,22 @@ export class ProfilesActor {
|
|
|
49
49
|
async setMyProfileAsyncUnsafe(name) {
|
|
50
50
|
return profileOf(await executeAsyncUnsafe(async () => (await this.group.coreAsync()).setMyProfile({ name })));
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* C-16, PF-4: the signed-in user's rating as a rider ("★ 4,87"). Ratings reach the core
|
|
54
|
+
* in the workers' batches, up to a minute after the driver rated (K-9).
|
|
55
|
+
* @returns undefined while nobody rated the user ("Brak ocen")
|
|
56
|
+
* @throws Error with message `CanisterError` — `NotAuthorized` (anonymous)
|
|
57
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
58
|
+
*/
|
|
59
|
+
async getMyRatingAsyncUnsafe() {
|
|
60
|
+
const answer = await executeAsyncUnsafe(async () => (await this.group.coreAsync()).getMyRating());
|
|
61
|
+
const rating = answer[0];
|
|
62
|
+
if (rating === undefined || rating.count === 0n)
|
|
63
|
+
return undefined;
|
|
64
|
+
const sum = Number(rating.sum);
|
|
65
|
+
const count = Number(rating.count);
|
|
66
|
+
return { average: Math.round((sum / count) * 100) / 100, count, sum };
|
|
67
|
+
}
|
|
52
68
|
/**
|
|
53
69
|
* C-8, KU-1: the rider's rides, newest first, `RIDES_PAGE` a page. A ride reaches the core
|
|
54
70
|
* up to a minute after its end (K-9, KU-2).
|
|
@@ -2,7 +2,7 @@ import type { Identity } from "@icp-sdk/core/agent";
|
|
|
2
2
|
import { type GroupOptions } from "../group/canister-actor.js";
|
|
3
3
|
import { TigiGroup } from "../group/group.js";
|
|
4
4
|
import { type Geo } from "../geo.js";
|
|
5
|
-
import type { ChooseOutcome, LicenceView, RequestSnapshot, RideView } from "../interfaces.js";
|
|
5
|
+
import type { ChatPlace, ChooseOutcome, LicenceView, RequestSnapshot, RideView } from "../interfaces.js";
|
|
6
6
|
/** U-29: the rider's radius, and the radius after `WIDEN_AFTER_MS` without offers. */
|
|
7
7
|
export declare const SEARCH_RADIUS_METERS = 3000;
|
|
8
8
|
export declare const WIDE_RADIUS_METERS = 6000;
|
|
@@ -192,6 +192,17 @@ export declare class RideRequest {
|
|
|
192
192
|
* @throws Error with message `CriticalCanisterError` — the driver canister does not answer
|
|
193
193
|
*/
|
|
194
194
|
getLicenceAsyncUnsafe(): Promise<LicenceView>;
|
|
195
|
+
/**
|
|
196
|
+
* U-43, K-12, PR-25: where the chat with the driver of the accepted ride is — give it to
|
|
197
|
+
* `@jsm-mit/chat-sharded-package` (`ChatsActor.openChatAsyncUnsafe({ projectId, roomId })`
|
|
198
|
+
* on `chatCoordinatorId`). The room is the driver's (one per driver, not per ride): the
|
|
199
|
+
* rider has one chat with that driver over all their rides. Show "Napisz do kierowcy"
|
|
200
|
+
* from `accepted` to the end of the ride only.
|
|
201
|
+
* @returns undefined when the environment has no chat, or the driver is simulated (no chat in MVP)
|
|
202
|
+
* @throws Error with message `CanisterError` — `NOT_ACCEPTED` (no driver accepted yet)
|
|
203
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
204
|
+
*/
|
|
205
|
+
getChatPlaceAsyncUnsafe(): Promise<ChatPlace | undefined>;
|
|
195
206
|
/**
|
|
196
207
|
* K-8: the rider rates the driver 1–5 after `completed`, once, within 24 h.
|
|
197
208
|
* @returns false when the rider rated this ride already
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rides-actor.d.ts","sourceRoot":"","sources":["../../src/actors/rides-actor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAA0H,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvL,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAA2B,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAa,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"rides-actor.d.ts","sourceRoot":"","sources":["../../src/actors/rides-actor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAA0H,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvL,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAA2B,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAa,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIpH,sFAAsF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-10,6 +10,7 @@ import { canisterError, errorKeyOf, executeAsyncUnsafe, executeProtocolAsyncUnsa
|
|
|
10
10
|
import { TigiGroup } from "../group/group.js";
|
|
11
11
|
import { geohashesByWorker } from "../group/prefixes.js";
|
|
12
12
|
import { cellsWithin, isValidGeo } from "../geo.js";
|
|
13
|
+
import { driverChatPlaceAsyncUnsafe } from "../chat.js";
|
|
13
14
|
import { cardOf, closeReasonOf, decodeToken, driverOfOfferId, encodeToken, mergedPhase, mergeOffers, moneyOf, msOf, offerIdOf, offerOf, phaseOf, placeOffers, rideStatusOf } from "../mappers.js";
|
|
14
15
|
/** U-29: the rider's radius, and the radius after `WIDEN_AFTER_MS` without offers. */
|
|
15
16
|
export const SEARCH_RADIUS_METERS = 3_000;
|
|
@@ -391,6 +392,22 @@ export class RideRequest {
|
|
|
391
392
|
const licence = await executeProtocolAsyncUnsafe(async () => (await this.driverAsync(accepted.canister)).getLicence({ requestId: this.state.requestId, driverKey: accepted.driverKey }));
|
|
392
393
|
return { image: Uint8Array.from(licence.image), mimeType: licence.mimeType, documentNumber: licence.documentNumber };
|
|
393
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* U-43, K-12, PR-25: where the chat with the driver of the accepted ride is — give it to
|
|
397
|
+
* `@jsm-mit/chat-sharded-package` (`ChatsActor.openChatAsyncUnsafe({ projectId, roomId })`
|
|
398
|
+
* on `chatCoordinatorId`). The room is the driver's (one per driver, not per ride): the
|
|
399
|
+
* rider has one chat with that driver over all their rides. Show "Napisz do kierowcy"
|
|
400
|
+
* from `accepted` to the end of the ride only.
|
|
401
|
+
* @returns undefined when the environment has no chat, or the driver is simulated (no chat in MVP)
|
|
402
|
+
* @throws Error with message `CanisterError` — `NOT_ACCEPTED` (no driver accepted yet)
|
|
403
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
404
|
+
*/
|
|
405
|
+
async getChatPlaceAsyncUnsafe() {
|
|
406
|
+
const accepted = await this.acceptedAsyncUnsafe();
|
|
407
|
+
if (accepted.canister === (await this.simulatorIdAsync()))
|
|
408
|
+
return undefined;
|
|
409
|
+
return driverChatPlaceAsyncUnsafe(this.group, accepted.canister, accepted.driverKey);
|
|
410
|
+
}
|
|
394
411
|
/**
|
|
395
412
|
* K-8: the rider rates the driver 1–5 after `completed`, once, within 24 h.
|
|
396
413
|
* @returns false when the rider rated this ride already
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Identity } from "@icp-sdk/core/agent";
|
|
2
|
+
import { type GroupOptions } from "./group/canister-actor.js";
|
|
3
|
+
import { TigiGroup } from "./group/group.js";
|
|
4
|
+
import type { ChatPlace } from "./interfaces.js";
|
|
5
|
+
/** A room id of chat-sharded: at most 50 characters, never '/' or '|'. */
|
|
6
|
+
export declare const MAX_ROOM_ID_CHARS = 50;
|
|
7
|
+
export declare const DRIVER_ROOM_PREFIX = "drv-";
|
|
8
|
+
/** The chat config of the core is asked again after this long. */
|
|
9
|
+
export declare const CHAT_CONFIG_TTL_MS = 60000;
|
|
10
|
+
/**
|
|
11
|
+
* C-15: the room of a driver — the core's `ChatRoomFunctions.driverRoomId`, the same rule:
|
|
12
|
+
* "drv-<canister>" for a canister with one driver (`driverKey` = ""),
|
|
13
|
+
* "drv-<canister>-<driverKey>" otherwise; undefined when longer than 50 characters or
|
|
14
|
+
* holding '/' or '|'. The core makes rooms for the canisters of its registry only (one
|
|
15
|
+
* driver each), so a simulated driver has no room (MVP).
|
|
16
|
+
*/
|
|
17
|
+
export declare function driverRoomId(driverCanisterId: string, driverKey?: string): string | undefined;
|
|
18
|
+
/** @internal */
|
|
19
|
+
export declare function chatConfigOfAsyncUnsafe(group: TigiGroup): Promise<{
|
|
20
|
+
chatCoordinatorId: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
/** @internal — the place of a driver's room, or undefined (no chat here, no room for this driver). */
|
|
24
|
+
export declare function driverChatPlaceAsyncUnsafe(group: TigiGroup, driverCanisterId: string, driverKey: string): Promise<ChatPlace | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* The chat places of the group, for the fronts — the driver's front (its own room: the
|
|
27
|
+
* chats of its riders) and anybody that knows a driver canister. The rider's front takes
|
|
28
|
+
* the place of its ride from `RideRequest.getChatPlaceAsyncUnsafe` instead.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ChatPlacesActor {
|
|
31
|
+
private readonly group;
|
|
32
|
+
constructor(coordinatorId: string, identity?: Identity, options?: GroupOptions);
|
|
33
|
+
/**
|
|
34
|
+
* The chat of this environment: the chat group's coordinator and the project.
|
|
35
|
+
* @returns undefined when the environment has no chat yet
|
|
36
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
37
|
+
*/
|
|
38
|
+
getChatConfigAsyncUnsafe(): Promise<{
|
|
39
|
+
chatCoordinatorId: string;
|
|
40
|
+
projectId: string;
|
|
41
|
+
} | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* FK-20: the room of a driver canister (one driver, `driverKey` = ""). The driver's front
|
|
44
|
+
* lists the chats of this room as their recipient and shows only the current rider's.
|
|
45
|
+
* @returns undefined when the environment has no chat yet or the driver has no room
|
|
46
|
+
* @throws Error with message `CanisterError` (errorKey `InvalidData`) — not a principal
|
|
47
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
48
|
+
*/
|
|
49
|
+
getDriverChatPlaceAsyncUnsafe(driverCanisterId: string, driverKey?: string): Promise<ChatPlace | undefined>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAEzC;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,GAAG,SAAS,CAKjG;AAQD,gBAAgB;AAChB,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CASrI;AAED,sGAAsG;AACtG,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAQ9I;AAED;;;;GAIG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;gBAEtB,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAE,YAAiB;IAIlF;;;;OAIG;IACU,wBAAwB,IAAI,OAAO,CAAC;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAI9G;;;;;;OAMG;IACU,6BAA6B,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAQ/H"}
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// The chat with a driver (U-43, core.md C-15): one room per driver in chat-sharded, made by
|
|
2
|
+
// the core through the group's coordinator; the recipient is the owner of the driver
|
|
3
|
+
// canister, and every Tigi account may open a chat there. The fronts talk to the chat
|
|
4
|
+
// themselves with `@jsm-mit/chat-sharded-package` — this package only says WHERE.
|
|
5
|
+
import { Principal } from "@icp-sdk/core/principal";
|
|
6
|
+
import { transportAsync } from "./group/canister-actor.js";
|
|
7
|
+
import { TigiGroup } from "./group/group.js";
|
|
8
|
+
/** A room id of chat-sharded: at most 50 characters, never '/' or '|'. */
|
|
9
|
+
export const MAX_ROOM_ID_CHARS = 50;
|
|
10
|
+
export const DRIVER_ROOM_PREFIX = "drv-";
|
|
11
|
+
/** The chat config of the core is asked again after this long. */
|
|
12
|
+
export const CHAT_CONFIG_TTL_MS = 60_000;
|
|
13
|
+
/**
|
|
14
|
+
* C-15: the room of a driver — the core's `ChatRoomFunctions.driverRoomId`, the same rule:
|
|
15
|
+
* "drv-<canister>" for a canister with one driver (`driverKey` = ""),
|
|
16
|
+
* "drv-<canister>-<driverKey>" otherwise; undefined when longer than 50 characters or
|
|
17
|
+
* holding '/' or '|'. The core makes rooms for the canisters of its registry only (one
|
|
18
|
+
* driver each), so a simulated driver has no room (MVP).
|
|
19
|
+
*/
|
|
20
|
+
export function driverRoomId(driverCanisterId, driverKey = "") {
|
|
21
|
+
const base = DRIVER_ROOM_PREFIX + driverCanisterId;
|
|
22
|
+
const id = driverKey === "" ? base : `${base}-${driverKey}`;
|
|
23
|
+
if (id.length > MAX_ROOM_ID_CHARS || id.includes("/") || id.includes("|"))
|
|
24
|
+
return undefined;
|
|
25
|
+
return id;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The chat of the environment as the core names it (`getChatConfig`), kept for
|
|
29
|
+
* `CHAT_CONFIG_TTL_MS` per group.
|
|
30
|
+
*/
|
|
31
|
+
const configs = new WeakMap();
|
|
32
|
+
/** @internal */
|
|
33
|
+
export async function chatConfigOfAsyncUnsafe(group) {
|
|
34
|
+
const known = configs.get(group);
|
|
35
|
+
if (known && Date.now() - known.atMs < CHAT_CONFIG_TTL_MS)
|
|
36
|
+
return known.value;
|
|
37
|
+
const answer = await transportAsync(async () => (await group.coreAsync()).getChatConfig());
|
|
38
|
+
const config = answer[0];
|
|
39
|
+
const value = config === undefined ? undefined : { chatCoordinatorId: config.chatCoordinatorId.toText(), projectId: config.projectId };
|
|
40
|
+
configs.set(group, { atMs: Date.now(), value });
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
/** @internal — the place of a driver's room, or undefined (no chat here, no room for this driver). */
|
|
44
|
+
export async function driverChatPlaceAsyncUnsafe(group, driverCanisterId, driverKey) {
|
|
45
|
+
const roomId = driverRoomId(driverCanisterId, driverKey);
|
|
46
|
+
if (roomId === undefined || driverKey !== "")
|
|
47
|
+
return undefined;
|
|
48
|
+
const config = await chatConfigOfAsyncUnsafe(group);
|
|
49
|
+
if (config === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
return { chatCoordinatorId: config.chatCoordinatorId, projectId: config.projectId, roomId };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The chat places of the group, for the fronts — the driver's front (its own room: the
|
|
55
|
+
* chats of its riders) and anybody that knows a driver canister. The rider's front takes
|
|
56
|
+
* the place of its ride from `RideRequest.getChatPlaceAsyncUnsafe` instead.
|
|
57
|
+
*/
|
|
58
|
+
export class ChatPlacesActor {
|
|
59
|
+
group;
|
|
60
|
+
constructor(coordinatorId, identity, options = {}) {
|
|
61
|
+
this.group = TigiGroup.of(coordinatorId, identity, options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The chat of this environment: the chat group's coordinator and the project.
|
|
65
|
+
* @returns undefined when the environment has no chat yet
|
|
66
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
67
|
+
*/
|
|
68
|
+
async getChatConfigAsyncUnsafe() {
|
|
69
|
+
return chatConfigOfAsyncUnsafe(this.group);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* FK-20: the room of a driver canister (one driver, `driverKey` = ""). The driver's front
|
|
73
|
+
* lists the chats of this room as their recipient and shows only the current rider's.
|
|
74
|
+
* @returns undefined when the environment has no chat yet or the driver has no room
|
|
75
|
+
* @throws Error with message `CanisterError` (errorKey `InvalidData`) — not a principal
|
|
76
|
+
* @throws Error with message `CriticalCanisterError` — the core could not be reached
|
|
77
|
+
*/
|
|
78
|
+
async getDriverChatPlaceAsyncUnsafe(driverCanisterId, driverKey = "") {
|
|
79
|
+
try {
|
|
80
|
+
Principal.fromText(driverCanisterId);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
throw new Error("CanisterError", { cause: { errorKey: "InvalidData", errorMessage: "not a canister id", logs: [] } });
|
|
84
|
+
}
|
|
85
|
+
return driverChatPlaceAsyncUnsafe(this.group, driverCanisterId, driverKey);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { MAINNET_HOST, STOPPED_RETRY_ATTEMPTS, canisterError, errorKeyOf, isCani
|
|
|
2
2
|
export { RidesActor, RideRequest, refusalKeyOf, REFRESH_WAIT_MS, REQUEST_POLL_MS, RIDE_POLL_MS, RIDE_POLL_NEAR_MS, SEARCH_RADIUS_METERS, WIDE_RADIUS_METERS, WIDEN_AFTER_MS, type RequestRideArgs, } from "./actors/rides-actor.js";
|
|
3
3
|
export { ProfilesActor, RIDES_PAGE } from "./actors/profiles-actor.js";
|
|
4
4
|
export { TestManagerActor, SIMULATED_DRIVERS } from "./actors/test-manager-actor.js";
|
|
5
|
+
export { DriverCanistersActor, CLAIM_FRAGMENT_KEY, MAX_CLAIM_CODE_CHARS, claimCodeOfHash, claimLinkOf } from "./actors/driver-canisters-actor.js";
|
|
6
|
+
export { ChatPlacesActor, CHAT_CONFIG_TTL_MS, DRIVER_ROOM_PREFIX, MAX_ROOM_ID_CHARS, driverRoomId } from "./chat.js";
|
|
5
7
|
export { cellsWithin, decodeGeohashCenter, distanceMeters, encodeGeohash } from "./geo.js";
|
|
6
8
|
export type * from "./interfaces.js";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACH,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,sBAAsB,EACtB,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,QAAQ,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACH,UAAU,EACV,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,KAAK,eAAe,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAClJ,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3F,mBAAmB,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,15 @@
|
|
|
4
4
|
//
|
|
5
5
|
// The rider (night 1, step 7): `RidesActor` (a request in every worker in range, merged
|
|
6
6
|
// offers, one choice at a time, the ride in the driver canister), `ProfilesActor` (the
|
|
7
|
-
// account and the history in the core), `TestManagerActor` (simulated drivers,
|
|
7
|
+
// account, the rating and the history in the core), `TestManagerActor` (simulated drivers,
|
|
8
|
+
// ×10). The chat (U-43): `ChatPlacesActor` and `RideRequest.getChatPlaceAsyncUnsafe` say
|
|
9
|
+
// WHERE a driver's room is; the fronts use `@jsm-mit/chat-sharded-package` for the messages.
|
|
10
|
+
// The driver's own canister (U-45): `DriverCanistersActor` (the demo lease, its extension,
|
|
11
|
+
// "mine", the one-time claim code and the claim from the canister's own front).
|
|
8
12
|
export { MAINNET_HOST, STOPPED_RETRY_ATTEMPTS, canisterError, errorKeyOf, isCanisterStoppedError, retrySettings, } from "./group/canister-actor.js";
|
|
9
13
|
export { RidesActor, RideRequest, refusalKeyOf, REFRESH_WAIT_MS, REQUEST_POLL_MS, RIDE_POLL_MS, RIDE_POLL_NEAR_MS, SEARCH_RADIUS_METERS, WIDE_RADIUS_METERS, WIDEN_AFTER_MS, } from "./actors/rides-actor.js";
|
|
10
14
|
export { ProfilesActor, RIDES_PAGE } from "./actors/profiles-actor.js";
|
|
11
15
|
export { TestManagerActor, SIMULATED_DRIVERS } from "./actors/test-manager-actor.js";
|
|
16
|
+
export { DriverCanistersActor, CLAIM_FRAGMENT_KEY, MAX_CLAIM_CODE_CHARS, claimCodeOfHash, claimLinkOf } from "./actors/driver-canisters-actor.js";
|
|
17
|
+
export { ChatPlacesActor, CHAT_CONFIG_TTL_MS, DRIVER_ROOM_PREFIX, MAX_ROOM_ID_CHARS, driverRoomId } from "./chat.js";
|
|
12
18
|
export { cellsWithin, decodeGeohashCenter, distanceMeters, encodeGeohash } from "./geo.js";
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -146,4 +146,51 @@ export interface SpawnResult {
|
|
|
146
146
|
registered: number;
|
|
147
147
|
problems: string[];
|
|
148
148
|
}
|
|
149
|
+
/** PF-4: the signed-in user's rating as a rider (C-16), from the core. */
|
|
150
|
+
export interface MyRatingView {
|
|
151
|
+
/** The average of the stars, e.g. 4.87 (show "★ 4,87"). */
|
|
152
|
+
average: number;
|
|
153
|
+
/** How many ratings. */
|
|
154
|
+
count: number;
|
|
155
|
+
sum: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* U-43, C-15: where the chat with a driver is — what `@jsm-mit/chat-sharded-package` needs:
|
|
159
|
+
* `new ChatsActor(chatCoordinatorId, identity).openChatAsyncUnsafe({ projectId, roomId })`.
|
|
160
|
+
* One room per driver; its recipient is the driver (the owner of the driver canister).
|
|
161
|
+
*/
|
|
162
|
+
export interface ChatPlace {
|
|
163
|
+
/** The chat group's coordinator (its address). */
|
|
164
|
+
chatCoordinatorId: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
roomId: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A driver canister of the signed-in person: their own (`own`) or a demo canister they
|
|
170
|
+
* hold (`pool`). Its id is the driver's own address (`https://<canisterId>.icp0.io`).
|
|
171
|
+
*/
|
|
172
|
+
export interface DriverCanisterView {
|
|
173
|
+
canisterId: string;
|
|
174
|
+
kind: "own" | "pool";
|
|
175
|
+
/** The admin of the canister: after a claim (F-20) the driver, not the lease holder. */
|
|
176
|
+
ownerPrincipal: string;
|
|
177
|
+
/** A demo lease ends then (pool canisters). */
|
|
178
|
+
leaseUntilMs?: number;
|
|
179
|
+
blocked: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** F-20: a one-time code that hands the demo canister to whoever claims it, until `expiresAtMs`. */
|
|
182
|
+
export interface ClaimCodeView {
|
|
183
|
+
canisterId: string;
|
|
184
|
+
code: string;
|
|
185
|
+
expiresAtMs: number;
|
|
186
|
+
}
|
|
187
|
+
/** F-6, F-20a: a lease (with a claim code after a fresh one), or busy until then. */
|
|
188
|
+
export type DemoLeaseView = {
|
|
189
|
+
kind: "leased";
|
|
190
|
+
canister: DriverCanisterView;
|
|
191
|
+
claim?: ClaimCodeView;
|
|
192
|
+
} | {
|
|
193
|
+
kind: "busy";
|
|
194
|
+
untilMs: number;
|
|
195
|
+
};
|
|
149
196
|
//# sourceMappingURL=interfaces.d.ts.map
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,YAAY,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,wEAAwE;AACxE,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC;AAE7E,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhF;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACtB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,GAAG,EAAE,GAAG,CAAC;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,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name": "@jsm-mit/tigi-sharded-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The one package of the Tigi network group: takes the coordinator's id and hides the coordinator, the core and the workers — for a consumer the group is one canister; plus the rider's few driver-canister endpoints (U-14).",
|
|
5
5
|
"homepage": "https://github.com/JSM-Tigi/tigi-sharded/tree/master/package#readme",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
"test-simulator": "bash scripts/run-tests-local.sh tests/test-simulator.ts",
|
|
39
39
|
"test-drivers": "bash scripts/run-tests-local.sh tests/test-drivers.ts",
|
|
40
40
|
"test-split": "bash scripts/run-tests-local.sh tests/test-split.ts",
|
|
41
|
-
"test-
|
|
41
|
+
"test-claim": "bash scripts/run-tests-local.sh tests/test-claim.ts",
|
|
42
|
+
"load-local": "bash scripts/run-load-local.sh",
|
|
43
|
+
"test-e2e": "npm run test-drivers && npm run test-simulator && npm run test-split && npm run test-claim"
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
46
|
"@icp-sdk/core": "^6.1.0"
|
|
@@ -54,11 +56,11 @@
|
|
|
54
56
|
"tigiSharded": {
|
|
55
57
|
"repo": "tigi-sharded",
|
|
56
58
|
"repoUrl": "https://github.com/JSM-Tigi/tigi-sharded",
|
|
57
|
-
"commit": "
|
|
59
|
+
"commit": "8b9fac7d28569db8ee2633e5e40364528bd5aaa1"
|
|
58
60
|
},
|
|
59
61
|
"tigiDriverRust": {
|
|
60
62
|
"repo": "tigi-driver-rust",
|
|
61
63
|
"repoUrl": "https://github.com/JSM-Tigi/tigi-driver-rust",
|
|
62
|
-
"commit": "
|
|
64
|
+
"commit": "6870f40829f8532baa7209832e1c553d2c270f94"
|
|
63
65
|
}
|
|
64
66
|
}
|