@jsm-mit/sultana-core-motoko-package 0.0.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ # Sultana Core Motoko Package
2
+
3
+ A TypeScript library for interacting with the Sultana Core Motoko actor on the Internet Computer (IC) platform.
@@ -0,0 +1,50 @@
1
+ import type {
2
+ ActorSubclass,
3
+ HttpAgentOptions,
4
+ ActorConfig,
5
+ Agent,
6
+ } from "@icp-sdk/core/agent";
7
+ import type { Principal } from "@icp-sdk/core/principal";
8
+ import type { IDL } from "@icp-sdk/core/candid";
9
+
10
+ import { _SERVICE } from './sultana-core-motoko.did';
11
+
12
+ export declare const idlFactory: IDL.InterfaceFactory;
13
+ export declare const canisterId: string;
14
+
15
+ export declare interface CreateActorOptions {
16
+ /**
17
+ * @see {@link Agent}
18
+ */
19
+ agent?: Agent;
20
+ /**
21
+ * @see {@link HttpAgentOptions}
22
+ */
23
+ agentOptions?: HttpAgentOptions;
24
+ /**
25
+ * @see {@link ActorConfig}
26
+ */
27
+ actorOptions?: ActorConfig;
28
+ }
29
+
30
+ /**
31
+ * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
32
+ * @constructs {@link ActorSubClass}
33
+ * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
34
+ * @param {CreateActorOptions} options - see {@link CreateActorOptions}
35
+ * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
36
+ * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
37
+ * @see {@link HttpAgentOptions}
38
+ * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
39
+ * @see {@link ActorConfig}
40
+ */
41
+ export declare const createActor: (
42
+ canisterId: string | Principal,
43
+ options?: CreateActorOptions
44
+ ) => ActorSubclass<_SERVICE>;
45
+
46
+ /**
47
+ * Intialized Actor using default settings, ready to talk to a canister using its candid interface
48
+ * @constructs {@link ActorSubClass}
49
+ */
50
+ export declare const sultana_core_motoko: ActorSubclass<_SERVICE>;
@@ -0,0 +1,42 @@
1
+ import { Actor, HttpAgent } from "@icp-sdk/core/agent";
2
+
3
+ // Imports and re-exports candid interface
4
+ import { idlFactory } from "./sultana-core-motoko.did.js";
5
+ export { idlFactory } from "./sultana-core-motoko.did.js";
6
+
7
+ /* CANISTER_ID is replaced by webpack based on node environment
8
+ * Note: canister environment variable will be standardized as
9
+ * process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
10
+ * beginning in dfx 0.15.0
11
+ */
12
+ export const canisterId =
13
+ process.env.CANISTER_ID_SULTANA_CORE_MOTOKO;
14
+
15
+ export const createActor = (canisterId, options = {}) => {
16
+ const agent = options.agent || new HttpAgent({ ...options.agentOptions });
17
+
18
+ if (options.agent && options.agentOptions) {
19
+ console.warn(
20
+ "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
21
+ );
22
+ }
23
+
24
+ // Fetch root key for certificate validation during development
25
+ if (process.env.DFX_NETWORK !== "ic") {
26
+ agent.fetchRootKey().catch((err) => {
27
+ console.warn(
28
+ "Unable to fetch root key. Check to ensure that your local replica is running"
29
+ );
30
+ console.error(err);
31
+ });
32
+ }
33
+
34
+ // Creates an actor with using the candid interface and the HttpAgent
35
+ return Actor.createActor(idlFactory, {
36
+ agent,
37
+ canisterId,
38
+ ...options.actorOptions,
39
+ });
40
+ };
41
+
42
+ export const sultana_core_motoko = canisterId ? createActor(canisterId) : undefined;
@@ -0,0 +1,246 @@
1
+ type UserProfile =
2
+ record {
3
+ avatarUrl: opt text;
4
+ id: principal;
5
+ name: text;
6
+ };
7
+ type UpdateSalonServiceArgs =
8
+ record {
9
+ active: bool;
10
+ duration: nat;
11
+ name: text;
12
+ price: nat;
13
+ serviceId: SalonServiceId;
14
+ serviceTypeIds: vec ServiceTypeId;
15
+ workerIds: vec principal;
16
+ };
17
+ type UpdateProfileArgs =
18
+ record {
19
+ avatarUrl: opt text;
20
+ name: text;
21
+ };
22
+ type ToggleWorkerCapabilityArgs =
23
+ record {
24
+ canPerform: bool;
25
+ salonId: SalonId;
26
+ salonServiceId: SalonServiceId;
27
+ workerId: principal;
28
+ };
29
+ type TimeMask = vec nat64;
30
+ type SetWeeklyTemplateArgs =
31
+ record {
32
+ day: nat;
33
+ mask: TimeMask;
34
+ salonId: SalonId;
35
+ workerId: principal;
36
+ };
37
+ type SetDailyScheduleArgs =
38
+ record {
39
+ date: nat64;
40
+ mask: TimeMask;
41
+ workerId: principal;
42
+ };
43
+ type ServiceTypeId = text;
44
+ type SalonServiceId = text;
45
+ type SalonService =
46
+ record {
47
+ active: bool;
48
+ address: text;
49
+ duration: nat;
50
+ geohash6: Geohash;
51
+ id: SalonServiceId;
52
+ location: Coordinate;
53
+ name: text;
54
+ price: nat;
55
+ salonId: SalonId;
56
+ serviceTypeIds: vec ServiceTypeId;
57
+ workerIds: vec principal;
58
+ };
59
+ type SalonId = text;
60
+ type Salon =
61
+ record {
62
+ active: bool;
63
+ address: text;
64
+ geohash6: Geohash;
65
+ id: SalonId;
66
+ location: Coordinate;
67
+ name: text;
68
+ ownerId: principal;
69
+ };
70
+ type Result_9 =
71
+ variant {
72
+ err: Error;
73
+ ok: SalonId;
74
+ };
75
+ type Result_8 =
76
+ variant {
77
+ err: Error;
78
+ ok: TimeMask;
79
+ };
80
+ type Result_7 =
81
+ variant {
82
+ err: Error;
83
+ ok: vec nat64;
84
+ };
85
+ type Result_6 =
86
+ variant {
87
+ err: Error;
88
+ ok: vec Salon;
89
+ };
90
+ type Result_5 =
91
+ variant {
92
+ err: Error;
93
+ ok: vec SalonService;
94
+ };
95
+ type Result_4 =
96
+ variant {
97
+ err: Error;
98
+ ok: vec UserProfile;
99
+ };
100
+ type Result_3 =
101
+ variant {
102
+ err: Error;
103
+ ok: vec ServiceTypeId;
104
+ };
105
+ type Result_2 =
106
+ variant {
107
+ err: Error;
108
+ ok: principal;
109
+ };
110
+ type Result_11 =
111
+ variant {
112
+ err: Error;
113
+ ok: SalonServiceId;
114
+ };
115
+ type Result_10 =
116
+ variant {
117
+ err: Error;
118
+ ok: AppointmentId;
119
+ };
120
+ type Result_1 =
121
+ variant {
122
+ err: Error;
123
+ ok: UserProfile;
124
+ };
125
+ type Result =
126
+ variant {
127
+ err: Error;
128
+ ok;
129
+ };
130
+ type RequestToJoinArgs = record {salonId: SalonId;};
131
+ type RemoveDailyScheduleArgs =
132
+ record {
133
+ date: nat64;
134
+ workerId: principal;
135
+ };
136
+ type RejectCandidateArgs =
137
+ record {
138
+ salonId: SalonId;
139
+ workerId: principal;
140
+ };
141
+ type GetDayFromWeeklyTemplateArgs =
142
+ record {
143
+ day: DayOfWeek;
144
+ salonId: SalonId;
145
+ workerId: principal;
146
+ };
147
+ type GetDailyScheduleArgs =
148
+ record {
149
+ date: nat64;
150
+ workerId: principal;
151
+ };
152
+ type Geohash = text;
153
+ type Error =
154
+ variant {
155
+ AlreadyExists;
156
+ InvalidData: text;
157
+ NotAuthorized: text;
158
+ NotFound;
159
+ ReturnsNull;
160
+ };
161
+ type DayOfWeek = nat;
162
+ type CreateSalonArgs =
163
+ record {
164
+ address: text;
165
+ geohash6: Geohash;
166
+ location: Coordinate;
167
+ name: text;
168
+ };
169
+ type Coordinate =
170
+ record {
171
+ lat: float64;
172
+ lng: float64;
173
+ };
174
+ type BookAppointmentArgs =
175
+ record {
176
+ dateMidnight: nat64;
177
+ dayOfWeek: DayOfWeek;
178
+ notes: opt text;
179
+ salonId: SalonId;
180
+ salonServiceId: SalonServiceId;
181
+ startTime: nat64;
182
+ workerId: principal;
183
+ };
184
+ type AppointmentId = text;
185
+ type AddSalonServiceArgs =
186
+ record {
187
+ active: bool;
188
+ duration: nat;
189
+ name: text;
190
+ price: nat;
191
+ salonId: SalonId;
192
+ serviceTypeIds: vec ServiceTypeId;
193
+ workerIds: vec principal;
194
+ };
195
+ type AcceptWorkerArgs =
196
+ record {
197
+ salonId: SalonId;
198
+ workerId: principal;
199
+ };
200
+ service : {
201
+ /// Owner accepts a candidate into the team
202
+ acceptWorker: (args: AcceptWorkerArgs) -> (Result);
203
+ /// Adds a new service to a specific salon
204
+ addSalonService: (args: AddSalonServiceArgs) -> (Result_11);
205
+ addServiceType: (id: ServiceTypeId) -> (Result);
206
+ bookAppointment: (args: BookAppointmentArgs) -> (Result_10);
207
+ /// Creates a new salon and links it to the caller
208
+ createSalon: (args: CreateSalonArgs) -> (Result_9);
209
+ getAllProfiles: () -> (Result_4) query;
210
+ /// Returns a specific daily override if it exists
211
+ getDailySchedule: (args: GetDailyScheduleArgs) -> (Result_8) query;
212
+ getDayFromWeeklyTemplate: (args: GetDayFromWeeklyTemplateArgs) ->
213
+ (Result_7) query;
214
+ getMyProfile: () -> (Result_1) query;
215
+ /// Pobiera listę salonów aktualnie zalogowanego właściciela (używa indeksu)
216
+ getMySalons: () -> (Result_6) query;
217
+ /// Returns the list of profiles waiting for approval (Owner only)
218
+ getSalonCandidates: (salonId: SalonId) -> (Result_4) query;
219
+ /// Pobiera listę usług salonu na podstawie jego ID (widok dla właściciela)
220
+ getSalonServicesBySalonId: (salonId: SalonId) -> (Result_5) query;
221
+ /// Pobiera listę profili wszystkich pracowników zatrudnionych w danym salonie
222
+ getSalonWorkers: (salonId: SalonId) -> (Result_4) query;
223
+ getServiceTypes: () -> (Result_3) query;
224
+ getSystemAdmin: () -> (Result_2) query;
225
+ /// Właściciel odrzuca prośbę kandydata o dołączenie do zespołu
226
+ rejectCandidate: (args: RejectCandidateArgs) -> (Result);
227
+ removeDailySchedule: (args: RemoveDailyScheduleArgs) -> (Result);
228
+ /// Permanently removes a salon service and cleans up search indexes
229
+ removeSalonService: (serviceId: SalonServiceId) -> (Result);
230
+ removeServiceType: (id: ServiceTypeId) -> (Result);
231
+ /// Owner removes a worker from the salon team
232
+ removeWorkerFromSalon: (salonId: SalonId, workerId: principal) -> (Result);
233
+ /// Worker sends a request to join a specific salon
234
+ requestToJoinSalon: (args: RequestToJoinArgs) -> (Result);
235
+ setDailySchedule: (args: SetDailyScheduleArgs) -> (Result);
236
+ /// Ustawia lub zmienia administratora systemu.
237
+ /// Jeśli admin nie jest ustawiony, pierwszy wywołujący staje się adminem.
238
+ /// Jeśli jest ustawiony, tylko obecny admin może przekazać uprawnienia komuś innemu.
239
+ setSystemAdmin: (newAdmin: opt principal) -> (Result_2);
240
+ setWeeklyTemplate: (args: SetWeeklyTemplateArgs) -> (Result);
241
+ /// Umożliwia właścicielowi salonu przypisanie lub odebranie uprawnień pracownikowi do wykonywania konkretnej usługi.
242
+ toggleWorkerCapability: (args: ToggleWorkerCapabilityArgs) -> (Result);
243
+ updateMyProfile: (args: UpdateProfileArgs) -> (Result_1);
244
+ /// Updates an existing service with new details and synchronizes the index
245
+ updateSalonService: (args: UpdateSalonServiceArgs) -> (Result);
246
+ }
@@ -0,0 +1,225 @@
1
+ import type { Principal } from '@icp-sdk/core/principal';
2
+ import type { ActorMethod } from '@icp-sdk/core/agent';
3
+ import type { IDL } from '@icp-sdk/core/candid';
4
+
5
+ export interface AcceptWorkerArgs {
6
+ 'workerId' : Principal,
7
+ 'salonId' : SalonId,
8
+ }
9
+ export interface AddSalonServiceArgs {
10
+ 'duration' : bigint,
11
+ 'active' : boolean,
12
+ 'name' : string,
13
+ 'serviceTypeIds' : Array<ServiceTypeId>,
14
+ 'workerIds' : Array<Principal>,
15
+ 'price' : bigint,
16
+ 'salonId' : SalonId,
17
+ }
18
+ export type AppointmentId = string;
19
+ export interface BookAppointmentArgs {
20
+ 'startTime' : bigint,
21
+ 'workerId' : Principal,
22
+ 'dayOfWeek' : DayOfWeek,
23
+ 'salonServiceId' : SalonServiceId,
24
+ 'notes' : [] | [string],
25
+ 'dateMidnight' : bigint,
26
+ 'salonId' : SalonId,
27
+ }
28
+ export interface Coordinate { 'lat' : number, 'lng' : number }
29
+ export interface CreateSalonArgs {
30
+ 'name' : string,
31
+ 'address' : string,
32
+ 'location' : Coordinate,
33
+ 'geohash6' : Geohash,
34
+ }
35
+ export type DayOfWeek = bigint;
36
+ export type Error = { 'NotFound' : null } |
37
+ { 'NotAuthorized' : string } |
38
+ { 'InvalidData' : string } |
39
+ { 'AlreadyExists' : null } |
40
+ { 'ReturnsNull' : null };
41
+ export type Geohash = string;
42
+ export interface GetDailyScheduleArgs {
43
+ 'workerId' : Principal,
44
+ 'date' : bigint,
45
+ }
46
+ export interface GetDayFromWeeklyTemplateArgs {
47
+ 'day' : DayOfWeek,
48
+ 'workerId' : Principal,
49
+ 'salonId' : SalonId,
50
+ }
51
+ export interface RejectCandidateArgs {
52
+ 'workerId' : Principal,
53
+ 'salonId' : SalonId,
54
+ }
55
+ export interface RemoveDailyScheduleArgs {
56
+ 'workerId' : Principal,
57
+ 'date' : bigint,
58
+ }
59
+ export interface RequestToJoinArgs { 'salonId' : SalonId }
60
+ export type Result = { 'ok' : null } |
61
+ { 'err' : Error };
62
+ export type Result_1 = { 'ok' : UserProfile } |
63
+ { 'err' : Error };
64
+ export type Result_10 = { 'ok' : AppointmentId } |
65
+ { 'err' : Error };
66
+ export type Result_11 = { 'ok' : SalonServiceId } |
67
+ { 'err' : Error };
68
+ export type Result_2 = { 'ok' : Principal } |
69
+ { 'err' : Error };
70
+ export type Result_3 = { 'ok' : Array<ServiceTypeId> } |
71
+ { 'err' : Error };
72
+ export type Result_4 = { 'ok' : Array<UserProfile> } |
73
+ { 'err' : Error };
74
+ export type Result_5 = { 'ok' : Array<SalonService> } |
75
+ { 'err' : Error };
76
+ export type Result_6 = { 'ok' : Array<Salon> } |
77
+ { 'err' : Error };
78
+ export type Result_7 = { 'ok' : BigUint64Array | bigint[] } |
79
+ { 'err' : Error };
80
+ export type Result_8 = { 'ok' : TimeMask } |
81
+ { 'err' : Error };
82
+ export type Result_9 = { 'ok' : SalonId } |
83
+ { 'err' : Error };
84
+ export interface Salon {
85
+ 'id' : SalonId,
86
+ 'active' : boolean,
87
+ 'ownerId' : Principal,
88
+ 'name' : string,
89
+ 'address' : string,
90
+ 'location' : Coordinate,
91
+ 'geohash6' : Geohash,
92
+ }
93
+ export type SalonId = string;
94
+ export interface SalonService {
95
+ 'id' : SalonServiceId,
96
+ 'duration' : bigint,
97
+ 'active' : boolean,
98
+ 'name' : string,
99
+ 'serviceTypeIds' : Array<ServiceTypeId>,
100
+ 'workerIds' : Array<Principal>,
101
+ 'address' : string,
102
+ 'price' : bigint,
103
+ 'location' : Coordinate,
104
+ 'geohash6' : Geohash,
105
+ 'salonId' : SalonId,
106
+ }
107
+ export type SalonServiceId = string;
108
+ export type ServiceTypeId = string;
109
+ export interface SetDailyScheduleArgs {
110
+ 'workerId' : Principal,
111
+ 'date' : bigint,
112
+ 'mask' : TimeMask,
113
+ }
114
+ export interface SetWeeklyTemplateArgs {
115
+ 'day' : bigint,
116
+ 'workerId' : Principal,
117
+ 'mask' : TimeMask,
118
+ 'salonId' : SalonId,
119
+ }
120
+ export type TimeMask = BigUint64Array | bigint[];
121
+ export interface ToggleWorkerCapabilityArgs {
122
+ 'workerId' : Principal,
123
+ 'canPerform' : boolean,
124
+ 'salonServiceId' : SalonServiceId,
125
+ 'salonId' : SalonId,
126
+ }
127
+ export interface UpdateProfileArgs {
128
+ 'name' : string,
129
+ 'avatarUrl' : [] | [string],
130
+ }
131
+ export interface UpdateSalonServiceArgs {
132
+ 'duration' : bigint,
133
+ 'active' : boolean,
134
+ 'name' : string,
135
+ 'serviceTypeIds' : Array<ServiceTypeId>,
136
+ 'workerIds' : Array<Principal>,
137
+ 'serviceId' : SalonServiceId,
138
+ 'price' : bigint,
139
+ }
140
+ export interface UserProfile {
141
+ 'id' : Principal,
142
+ 'name' : string,
143
+ 'avatarUrl' : [] | [string],
144
+ }
145
+ export interface _SERVICE {
146
+ /**
147
+ * / Owner accepts a candidate into the team
148
+ */
149
+ 'acceptWorker' : ActorMethod<[AcceptWorkerArgs], Result>,
150
+ /**
151
+ * / Adds a new service to a specific salon
152
+ */
153
+ 'addSalonService' : ActorMethod<[AddSalonServiceArgs], Result_11>,
154
+ 'addServiceType' : ActorMethod<[ServiceTypeId], Result>,
155
+ 'bookAppointment' : ActorMethod<[BookAppointmentArgs], Result_10>,
156
+ /**
157
+ * / Creates a new salon and links it to the caller
158
+ */
159
+ 'createSalon' : ActorMethod<[CreateSalonArgs], Result_9>,
160
+ 'getAllProfiles' : ActorMethod<[], Result_4>,
161
+ /**
162
+ * / Returns a specific daily override if it exists
163
+ */
164
+ 'getDailySchedule' : ActorMethod<[GetDailyScheduleArgs], Result_8>,
165
+ 'getDayFromWeeklyTemplate' : ActorMethod<
166
+ [GetDayFromWeeklyTemplateArgs],
167
+ Result_7
168
+ >,
169
+ 'getMyProfile' : ActorMethod<[], Result_1>,
170
+ /**
171
+ * / Pobiera listę salonów aktualnie zalogowanego właściciela (używa indeksu)
172
+ */
173
+ 'getMySalons' : ActorMethod<[], Result_6>,
174
+ /**
175
+ * / Returns the list of profiles waiting for approval (Owner only)
176
+ */
177
+ 'getSalonCandidates' : ActorMethod<[SalonId], Result_4>,
178
+ /**
179
+ * / Pobiera listę usług salonu na podstawie jego ID (widok dla właściciela)
180
+ */
181
+ 'getSalonServicesBySalonId' : ActorMethod<[SalonId], Result_5>,
182
+ /**
183
+ * / Pobiera listę profili wszystkich pracowników zatrudnionych w danym salonie
184
+ */
185
+ 'getSalonWorkers' : ActorMethod<[SalonId], Result_4>,
186
+ 'getServiceTypes' : ActorMethod<[], Result_3>,
187
+ 'getSystemAdmin' : ActorMethod<[], Result_2>,
188
+ /**
189
+ * / Właściciel odrzuca prośbę kandydata o dołączenie do zespołu
190
+ */
191
+ 'rejectCandidate' : ActorMethod<[RejectCandidateArgs], Result>,
192
+ 'removeDailySchedule' : ActorMethod<[RemoveDailyScheduleArgs], Result>,
193
+ /**
194
+ * / Permanently removes a salon service and cleans up search indexes
195
+ */
196
+ 'removeSalonService' : ActorMethod<[SalonServiceId], Result>,
197
+ 'removeServiceType' : ActorMethod<[ServiceTypeId], Result>,
198
+ /**
199
+ * / Owner removes a worker from the salon team
200
+ */
201
+ 'removeWorkerFromSalon' : ActorMethod<[SalonId, Principal], Result>,
202
+ /**
203
+ * / Worker sends a request to join a specific salon
204
+ */
205
+ 'requestToJoinSalon' : ActorMethod<[RequestToJoinArgs], Result>,
206
+ 'setDailySchedule' : ActorMethod<[SetDailyScheduleArgs], Result>,
207
+ /**
208
+ * / Ustawia lub zmienia administratora systemu.
209
+ * / Jeśli admin nie jest ustawiony, pierwszy wywołujący staje się adminem.
210
+ * / Jeśli jest ustawiony, tylko obecny admin może przekazać uprawnienia komuś innemu.
211
+ */
212
+ 'setSystemAdmin' : ActorMethod<[[] | [Principal]], Result_2>,
213
+ 'setWeeklyTemplate' : ActorMethod<[SetWeeklyTemplateArgs], Result>,
214
+ /**
215
+ * / Umożliwia właścicielowi salonu przypisanie lub odebranie uprawnień pracownikowi do wykonywania konkretnej usługi.
216
+ */
217
+ 'toggleWorkerCapability' : ActorMethod<[ToggleWorkerCapabilityArgs], Result>,
218
+ 'updateMyProfile' : ActorMethod<[UpdateProfileArgs], Result_1>,
219
+ /**
220
+ * / Updates an existing service with new details and synchronizes the index
221
+ */
222
+ 'updateSalonService' : ActorMethod<[UpdateSalonServiceArgs], Result>,
223
+ }
224
+ export declare const idlFactory: IDL.InterfaceFactory;
225
+ export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
@@ -0,0 +1,177 @@
1
+ export const idlFactory = ({ IDL }) => {
2
+ const SalonId = IDL.Text;
3
+ const AcceptWorkerArgs = IDL.Record({
4
+ 'workerId' : IDL.Principal,
5
+ 'salonId' : SalonId,
6
+ });
7
+ const Error = IDL.Variant({
8
+ 'NotFound' : IDL.Null,
9
+ 'NotAuthorized' : IDL.Text,
10
+ 'InvalidData' : IDL.Text,
11
+ 'AlreadyExists' : IDL.Null,
12
+ 'ReturnsNull' : IDL.Null,
13
+ });
14
+ const Result = IDL.Variant({ 'ok' : IDL.Null, 'err' : Error });
15
+ const ServiceTypeId = IDL.Text;
16
+ const AddSalonServiceArgs = IDL.Record({
17
+ 'duration' : IDL.Nat,
18
+ 'active' : IDL.Bool,
19
+ 'name' : IDL.Text,
20
+ 'serviceTypeIds' : IDL.Vec(ServiceTypeId),
21
+ 'workerIds' : IDL.Vec(IDL.Principal),
22
+ 'price' : IDL.Nat,
23
+ 'salonId' : SalonId,
24
+ });
25
+ const SalonServiceId = IDL.Text;
26
+ const Result_11 = IDL.Variant({ 'ok' : SalonServiceId, 'err' : Error });
27
+ const DayOfWeek = IDL.Nat;
28
+ const BookAppointmentArgs = IDL.Record({
29
+ 'startTime' : IDL.Nat64,
30
+ 'workerId' : IDL.Principal,
31
+ 'dayOfWeek' : DayOfWeek,
32
+ 'salonServiceId' : SalonServiceId,
33
+ 'notes' : IDL.Opt(IDL.Text),
34
+ 'dateMidnight' : IDL.Nat64,
35
+ 'salonId' : SalonId,
36
+ });
37
+ const AppointmentId = IDL.Text;
38
+ const Result_10 = IDL.Variant({ 'ok' : AppointmentId, 'err' : Error });
39
+ const Coordinate = IDL.Record({ 'lat' : IDL.Float64, 'lng' : IDL.Float64 });
40
+ const Geohash = IDL.Text;
41
+ const CreateSalonArgs = IDL.Record({
42
+ 'name' : IDL.Text,
43
+ 'address' : IDL.Text,
44
+ 'location' : Coordinate,
45
+ 'geohash6' : Geohash,
46
+ });
47
+ const Result_9 = IDL.Variant({ 'ok' : SalonId, 'err' : Error });
48
+ const UserProfile = IDL.Record({
49
+ 'id' : IDL.Principal,
50
+ 'name' : IDL.Text,
51
+ 'avatarUrl' : IDL.Opt(IDL.Text),
52
+ });
53
+ const Result_4 = IDL.Variant({ 'ok' : IDL.Vec(UserProfile), 'err' : Error });
54
+ const GetDailyScheduleArgs = IDL.Record({
55
+ 'workerId' : IDL.Principal,
56
+ 'date' : IDL.Nat64,
57
+ });
58
+ const TimeMask = IDL.Vec(IDL.Nat64);
59
+ const Result_8 = IDL.Variant({ 'ok' : TimeMask, 'err' : Error });
60
+ const GetDayFromWeeklyTemplateArgs = IDL.Record({
61
+ 'day' : DayOfWeek,
62
+ 'workerId' : IDL.Principal,
63
+ 'salonId' : SalonId,
64
+ });
65
+ const Result_7 = IDL.Variant({ 'ok' : IDL.Vec(IDL.Nat64), 'err' : Error });
66
+ const Result_1 = IDL.Variant({ 'ok' : UserProfile, 'err' : Error });
67
+ const Salon = IDL.Record({
68
+ 'id' : SalonId,
69
+ 'active' : IDL.Bool,
70
+ 'ownerId' : IDL.Principal,
71
+ 'name' : IDL.Text,
72
+ 'address' : IDL.Text,
73
+ 'location' : Coordinate,
74
+ 'geohash6' : Geohash,
75
+ });
76
+ const Result_6 = IDL.Variant({ 'ok' : IDL.Vec(Salon), 'err' : Error });
77
+ const SalonService = IDL.Record({
78
+ 'id' : SalonServiceId,
79
+ 'duration' : IDL.Nat,
80
+ 'active' : IDL.Bool,
81
+ 'name' : IDL.Text,
82
+ 'serviceTypeIds' : IDL.Vec(ServiceTypeId),
83
+ 'workerIds' : IDL.Vec(IDL.Principal),
84
+ 'address' : IDL.Text,
85
+ 'price' : IDL.Nat,
86
+ 'location' : Coordinate,
87
+ 'geohash6' : Geohash,
88
+ 'salonId' : SalonId,
89
+ });
90
+ const Result_5 = IDL.Variant({ 'ok' : IDL.Vec(SalonService), 'err' : Error });
91
+ const Result_3 = IDL.Variant({
92
+ 'ok' : IDL.Vec(ServiceTypeId),
93
+ 'err' : Error,
94
+ });
95
+ const Result_2 = IDL.Variant({ 'ok' : IDL.Principal, 'err' : Error });
96
+ const RejectCandidateArgs = IDL.Record({
97
+ 'workerId' : IDL.Principal,
98
+ 'salonId' : SalonId,
99
+ });
100
+ const RemoveDailyScheduleArgs = IDL.Record({
101
+ 'workerId' : IDL.Principal,
102
+ 'date' : IDL.Nat64,
103
+ });
104
+ const RequestToJoinArgs = IDL.Record({ 'salonId' : SalonId });
105
+ const SetDailyScheduleArgs = IDL.Record({
106
+ 'workerId' : IDL.Principal,
107
+ 'date' : IDL.Nat64,
108
+ 'mask' : TimeMask,
109
+ });
110
+ const SetWeeklyTemplateArgs = IDL.Record({
111
+ 'day' : IDL.Nat,
112
+ 'workerId' : IDL.Principal,
113
+ 'mask' : TimeMask,
114
+ 'salonId' : SalonId,
115
+ });
116
+ const ToggleWorkerCapabilityArgs = IDL.Record({
117
+ 'workerId' : IDL.Principal,
118
+ 'canPerform' : IDL.Bool,
119
+ 'salonServiceId' : SalonServiceId,
120
+ 'salonId' : SalonId,
121
+ });
122
+ const UpdateProfileArgs = IDL.Record({
123
+ 'name' : IDL.Text,
124
+ 'avatarUrl' : IDL.Opt(IDL.Text),
125
+ });
126
+ const UpdateSalonServiceArgs = IDL.Record({
127
+ 'duration' : IDL.Nat,
128
+ 'active' : IDL.Bool,
129
+ 'name' : IDL.Text,
130
+ 'serviceTypeIds' : IDL.Vec(ServiceTypeId),
131
+ 'workerIds' : IDL.Vec(IDL.Principal),
132
+ 'serviceId' : SalonServiceId,
133
+ 'price' : IDL.Nat,
134
+ });
135
+ return IDL.Service({
136
+ 'acceptWorker' : IDL.Func([AcceptWorkerArgs], [Result], []),
137
+ 'addSalonService' : IDL.Func([AddSalonServiceArgs], [Result_11], []),
138
+ 'addServiceType' : IDL.Func([ServiceTypeId], [Result], []),
139
+ 'bookAppointment' : IDL.Func([BookAppointmentArgs], [Result_10], []),
140
+ 'createSalon' : IDL.Func([CreateSalonArgs], [Result_9], []),
141
+ 'getAllProfiles' : IDL.Func([], [Result_4], ['query']),
142
+ 'getDailySchedule' : IDL.Func(
143
+ [GetDailyScheduleArgs],
144
+ [Result_8],
145
+ ['query'],
146
+ ),
147
+ 'getDayFromWeeklyTemplate' : IDL.Func(
148
+ [GetDayFromWeeklyTemplateArgs],
149
+ [Result_7],
150
+ ['query'],
151
+ ),
152
+ 'getMyProfile' : IDL.Func([], [Result_1], ['query']),
153
+ 'getMySalons' : IDL.Func([], [Result_6], ['query']),
154
+ 'getSalonCandidates' : IDL.Func([SalonId], [Result_4], ['query']),
155
+ 'getSalonServicesBySalonId' : IDL.Func([SalonId], [Result_5], ['query']),
156
+ 'getSalonWorkers' : IDL.Func([SalonId], [Result_4], ['query']),
157
+ 'getServiceTypes' : IDL.Func([], [Result_3], ['query']),
158
+ 'getSystemAdmin' : IDL.Func([], [Result_2], ['query']),
159
+ 'rejectCandidate' : IDL.Func([RejectCandidateArgs], [Result], []),
160
+ 'removeDailySchedule' : IDL.Func([RemoveDailyScheduleArgs], [Result], []),
161
+ 'removeSalonService' : IDL.Func([SalonServiceId], [Result], []),
162
+ 'removeServiceType' : IDL.Func([ServiceTypeId], [Result], []),
163
+ 'removeWorkerFromSalon' : IDL.Func([SalonId, IDL.Principal], [Result], []),
164
+ 'requestToJoinSalon' : IDL.Func([RequestToJoinArgs], [Result], []),
165
+ 'setDailySchedule' : IDL.Func([SetDailyScheduleArgs], [Result], []),
166
+ 'setSystemAdmin' : IDL.Func([IDL.Opt(IDL.Principal)], [Result_2], []),
167
+ 'setWeeklyTemplate' : IDL.Func([SetWeeklyTemplateArgs], [Result], []),
168
+ 'toggleWorkerCapability' : IDL.Func(
169
+ [ToggleWorkerCapabilityArgs],
170
+ [Result],
171
+ [],
172
+ ),
173
+ 'updateMyProfile' : IDL.Func([UpdateProfileArgs], [Result_1], []),
174
+ 'updateSalonService' : IDL.Func([UpdateSalonServiceArgs], [Result], []),
175
+ });
176
+ };
177
+ export const init = ({ IDL }) => { return []; };
@@ -0,0 +1,3 @@
1
+ export { SultanaCoreMotokoActor } from "./sultana-core-motoko-actor.js";
2
+ export type { AcceptWorkerArgs, AddSalonServiceArgs, BookAppointmentArgs, GetDailyScheduleArgs, CreateSalonArgs, GetDayFromWeeklyTemplateArgs, RejectCandidateArgs, RemoveDailyScheduleArgs, RequestToJoinArgs, SetDailyScheduleArgs, SetWeeklyTemplateArgs, ToggleWorkerCapabilityArgs, UpdateProfileArgs, UpdateSalonServiceArgs } from '../declarations/sultana-core-motoko/sultana-core-motoko.did.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,YAAY,EACR,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,4BAA4B,EAC5B,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,EACjB,sBAAsB,EACzB,MAAM,gEAAgE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { SultanaCoreMotokoActor } from "./sultana-core-motoko-actor.js";
@@ -0,0 +1,21 @@
1
+ import { type Identity } from "@icp-sdk/core/agent";
2
+ import type { Principal } from "@icp-sdk/core/principal";
3
+ export declare class SultanaCoreMotokoActor {
4
+ private canisterId;
5
+ private actor;
6
+ private agent;
7
+ constructor(canisterId: string, identity?: Identity);
8
+ private initActor;
9
+ protected executeFunctionAsyncUnsafe<T>(fnAsync: () => Promise<{
10
+ ok: T;
11
+ } | {
12
+ err: any;
13
+ }>): Promise<T>;
14
+ protected handleResultErrors(error: any): {
15
+ errorKey: string;
16
+ errorMessage: any;
17
+ };
18
+ setMyselfAsAdminAsyncUnsafe(): Promise<Principal>;
19
+ getAdminAsyncUnsafe(): Promise<Principal>;
20
+ }
21
+ //# sourceMappingURL=sultana-core-motoko-actor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sultana-core-motoko-actor.d.ts","sourceRoot":"","sources":["../src/sultana-core-motoko-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,qBAAa,sBAAsB;IAInB,OAAO,CAAC,UAAU;IAH9B,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAa;gBAEN,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAU3D,OAAO,CAAC,SAAS;cAOD,0BAA0B,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,CAAC,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,GAAG,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAwB3G,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,GAAG;;;;IAY1B,2BAA2B,IAAI,OAAO,CAAC,SAAS,CAAC;IAMjD,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;CAKzD"}
@@ -0,0 +1,55 @@
1
+ import { Actor, HttpAgent } from "@icp-sdk/core/agent";
2
+ import { Secp256k1KeyIdentity } from "@icp-sdk/core/identity/secp256k1";
3
+ import { idlFactory } from "../declarations/sultana-core-motoko/index.js";
4
+ export class SultanaCoreMotokoActor {
5
+ constructor(canisterId, identity) {
6
+ this.canisterId = canisterId;
7
+ this.agent = HttpAgent.createSync({
8
+ host: "https://icp0.io",
9
+ identity: identity
10
+ });
11
+ // 2. Inicjalizacja Aktora
12
+ this.initActor();
13
+ }
14
+ initActor() {
15
+ this.actor = Actor.createActor(idlFactory, {
16
+ agent: this.agent,
17
+ canisterId: this.canisterId,
18
+ });
19
+ }
20
+ async executeFunctionAsyncUnsafe(fnAsync) {
21
+ let errorObj;
22
+ try {
23
+ const result = await fnAsync();
24
+ if ('ok' in result) {
25
+ return result.ok;
26
+ }
27
+ errorObj = this.handleResultErrors(result.err);
28
+ const fullError = errorObj.errorKey + ': ' + errorObj.errorMessage;
29
+ }
30
+ catch (err) {
31
+ throw new Error("CriticalErrorCanister");
32
+ }
33
+ if (errorObj) {
34
+ throw new Error(errorObj.errorKey);
35
+ }
36
+ else {
37
+ throw new Error("Unreachable code reached OPDIZ");
38
+ }
39
+ }
40
+ handleResultErrors(error) {
41
+ const errorKey = Object.keys(error)[0];
42
+ const errorMessage = error[errorKey];
43
+ return {
44
+ errorKey: errorKey.toString(),
45
+ errorMessage
46
+ };
47
+ }
48
+ // --- Public Actor Methods ---
49
+ async setMyselfAsAdminAsyncUnsafe() {
50
+ return this.executeFunctionAsyncUnsafe(() => this.actor.setSystemAdmin([]));
51
+ }
52
+ async getAdminAsyncUnsafe() {
53
+ return this.executeFunctionAsyncUnsafe(() => this.actor.getSystemAdmin());
54
+ }
55
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@jsm-mit/sultana-core-motoko-package",
3
+ "version": "0.0.1",
4
+ "description": "A TypeScript library for interacting with the Sultana Core Motoko actor on the Internet Computer (IC) platform.",
5
+ "homepage": "https://github.com/JSM-Sultana/sultana-core-motoko-package#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/JSM-Sultana/sultana-core-motoko-package/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/JSM-Sultana/sultana-core-motoko-package.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "",
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist/",
26
+ "declarations/"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "clean": "rm -rf dist",
31
+ "prepare": "npm run build",
32
+ "publish-public": "npm run build && npm login && npm publish --access public",
33
+ "test": "vitest",
34
+ "sandbox": "npx tsx sandbox/main.ts"
35
+ },
36
+ "dependencies": {
37
+ "@icp-sdk/core": "^5.2.0"
38
+ },
39
+ "peerDependencies": {
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.5.2",
43
+ "@jsm-mit/utils-package": "0.4.1",
44
+ "dotenv": "^16.3.1",
45
+ "tsx": "^4.18.0",
46
+ "vitest": "^1.0.0",
47
+ "typescript": "^5.9.3"
48
+ }
49
+ }