@comapeo/core-react 10.0.1 → 11.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.
@@ -42,7 +42,7 @@ export declare function useReceivedMapSharesState<T>(selector: (state: Array<Rec
42
42
  * @internal
43
43
  */
44
44
  export declare function useSentMapSharesActions(): {
45
- createAndSend({ projectId, receiverDeviceId, mapId, }: import("../lib/map-shares-stores.js").CreateAndSendMapShareOptions): Promise<import("@comapeo/map-server", { with: { "resolution-mode": "import" } }).MapShareState>;
45
+ createAndSend({ receiverDeviceId, mapId, }: import("../lib/map-shares-stores.js").CreateAndSendMapShareOptions): Promise<import("@comapeo/map-server", { with: { "resolution-mode": "import" } }).MapShareState>;
46
46
  cancel({ shareId }: import("../lib/map-shares-stores.js").CancelMapShareOptions): Promise<void>;
47
47
  };
48
48
  /**
@@ -141,6 +141,9 @@ export declare function useManyReceivedMapShares(): ReceivedMapShareState[];
141
141
  *
142
142
  * @param opts.shareId ID of the map share
143
143
  *
144
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no received share
145
+ * with the given `shareId` exists.
146
+ *
144
147
  * @example
145
148
  * ```tsx
146
149
  * function MapShareDetail({ shareId }: { shareId: string }) {
@@ -156,15 +159,28 @@ export declare function useSingleReceivedMapShare({ shareId }: {
156
159
  /**
157
160
  * Accept and download a map share that has been received. The mutate promise
158
161
  * resolves once the map _starts_ downloading, before it finishes downloading.
159
- * Use `useManyMapShares` or `useSingleMapShare` to track download progress.
160
- *
161
- * Throws if the share is not in `status="pending"` or if the download fails to
162
- * start (e.g. if the shareId if invalid).
162
+ * Use `useManyReceivedMapShares` or `useSingleReceivedMapShare` to track
163
+ * download progress and final status.
164
+ *
165
+ * If the sender canceled the share before the receiver calls this, the
166
+ * mutation will still resolve (the download starts), but the share status will
167
+ * end up as `'canceled'` rather than `'completed'`. This is the only way the
168
+ * receiver discovers that a share has been canceled — check `share.status`
169
+ * after the download settles.
170
+ *
171
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
172
+ * known to be canceled (i.e. `status` is `'canceled'` in the store, e.g.
173
+ * after a previous download attempt discovered the cancellation).
174
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
175
+ * not in a valid state to start downloading (e.g. already downloading,
176
+ * completed, or declined).
177
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
178
+ * given `shareId` exists in the store.
163
179
  *
164
180
  * @example
165
181
  * ```tsx
166
182
  * function AcceptButton({ shareId }: { shareId: string }) {
167
- * const { mutate: accept } = useAcceptMapShare()
183
+ * const { mutate: accept } = useDownloadReceivedMapShare()
168
184
  *
169
185
  * return <button onClick={() => accept({ shareId })}>Accept</button>
170
186
  * }
@@ -189,17 +205,28 @@ export declare function useDownloadReceivedMapShare(): Pick<import("@tanstack/re
189
205
  }, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
190
206
  /**
191
207
  * Decline a map share that has been received. Notifies the sender that the
192
- * share was declined.
193
- *
194
- * Throws if the share is not with `status="pending"`
195
- * Throws if shareId is invalid
196
- * Throws if decline request fails (e.g. network error)
208
+ * share was declined. The share status is only updated to `'declined'` after
209
+ * the server confirms the decline — there is no optimistic update.
210
+ *
211
+ * If the sender canceled the share before the decline reaches the server, the
212
+ * share status will transition to `'canceled'` (not `'error'`) and the
213
+ * mutation will throw a `MapShareCanceledError`.
214
+ *
215
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
216
+ * known to be canceled, or if the server reports that the sender canceled
217
+ * the share while the decline was in flight. In both cases `share.status`
218
+ * will be `'canceled'`.
219
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
220
+ * not in `status='pending'` (e.g. already downloading, completed, or
221
+ * declined).
222
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
223
+ * given `shareId` exists in the store.
197
224
  *
198
225
  * @example
199
226
  * ```tsx
200
227
  * import { DeclineReason } from '@comapeo/core-react'
201
228
  * function DeclineButton({ shareId }: { shareId: string }) {
202
- * const { mutate: decline } = useDeclineMapShare()
229
+ * const { mutate: decline } = useDeclineReceivedMapShare()
203
230
  *
204
231
  * return (
205
232
  * <button onClick={() => decline({ shareId, reason: DeclineReason.user_rejected })}>
@@ -229,13 +256,20 @@ export declare function useDeclineReceivedMapShare(): Pick<import("@tanstack/rea
229
256
  /**
230
257
  * Abort an in-progress map share download.
231
258
  *
232
- * Throws if the share is not in `status="downloading"`
233
- * Throws if shareId is invalid
259
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
260
+ * known to be canceled.
261
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
262
+ * not in `status='downloading'` (e.g. still pending, already completed, or
263
+ * declined).
264
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
265
+ * given `shareId` exists in the store.
266
+ * @throws An error with code `'DOWNLOAD_NOT_FOUND'` if no download is
267
+ * currently tracked for this share (e.g. the download was never started).
234
268
  *
235
269
  * @example
236
270
  * ```tsx
237
271
  * function AbortButton({ shareId }: { shareId: string }) {
238
- * const { mutate: abort } = useAbortMapShareDownload()
272
+ * const { mutate: abort } = useAbortReceivedMapShareDownload()
239
273
  *
240
274
  * return <button onClick={() => abort({ shareId })}>Cancel Download</button>
241
275
  * }
@@ -264,8 +298,6 @@ export declare function useAbortReceivedMapShareDownload(): Pick<import("@tansta
264
298
  * mutation resolves with the created map share object, including its ID, which
265
299
  * can be used to track the share status with `useSingleSentMapShare`.
266
300
  *
267
- * @param opts.projectId Public ID of project for sending the map share: you can only send map shares to users on the same project
268
- *
269
301
  * @example
270
302
  * ```tsx
271
303
  * function SendMapButton({ projectId, deviceId }: { projectId: string; deviceId: string }) {
@@ -274,7 +306,7 @@ export declare function useAbortReceivedMapShareDownload(): Pick<import("@tansta
274
306
  * return (
275
307
  * <button
276
308
  * onClick={() =>
277
- * send({ projectId, receiverDeviceId: deviceId, mapId: 'custom' }, {
309
+ * send({ receiverDeviceId: deviceId, mapId: 'custom' }, {
278
310
  * onSuccess: (mapShare) => {
279
311
  * console.log('Share sent with id', mapShare.shareId)
280
312
  * }
@@ -311,6 +343,12 @@ export declare function useSendMapShare(): Pick<import("@tanstack/react-query").
311
343
  * the share, the download will be canceled before completion. If the download
312
344
  * is already complete, this action will throw an error.
313
345
  *
346
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
347
+ * not in `status='pending'` or `status='downloading'` (e.g. already
348
+ * completed, canceled, aborted, or declined).
349
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
350
+ * given `shareId` exists in the store.
351
+ *
314
352
  * @param opts.projectId Public ID of project to request the map share cancellation for.
315
353
  *
316
354
  * @example
@@ -344,7 +382,8 @@ export declare function useCancelSentMapShare(): Pick<import("@tanstack/react-qu
344
382
  * of the share, updated in real-time. When the recipient starts downloading, or
345
383
  * if they decline the share, then the returned share will update.
346
384
  *
347
- * Throws if no share with the specified ID is found.
385
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no sent share with
386
+ * the given `shareId` exists in the store.
348
387
  *
349
388
  * @param opts.shareId ID of the sent map share
350
389
  *
@@ -163,6 +163,9 @@ function useManyReceivedMapShares() {
163
163
  *
164
164
  * @param opts.shareId ID of the map share
165
165
  *
166
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no received share
167
+ * with the given `shareId` exists.
168
+ *
166
169
  * @example
167
170
  * ```tsx
168
171
  * function MapShareDetail({ shareId }: { shareId: string }) {
@@ -175,22 +178,35 @@ function useManyReceivedMapShares() {
175
178
  function useSingleReceivedMapShare({ shareId }) {
176
179
  const mapShare = (0, MapShares_js_1.useReceivedMapSharesState)((0, react_1.useCallback)((shares) => shares.find((s) => s.shareId === shareId), [shareId]));
177
180
  if (!mapShare) {
178
- throw new Error(`Map share with id ${shareId} not found`);
181
+ throw new errors_js_1.errors.MAP_SHARE_NOT_FOUND(`Received map share with id ${shareId} not found`);
179
182
  }
180
183
  return mapShare;
181
184
  }
182
185
  /**
183
186
  * Accept and download a map share that has been received. The mutate promise
184
187
  * resolves once the map _starts_ downloading, before it finishes downloading.
185
- * Use `useManyMapShares` or `useSingleMapShare` to track download progress.
186
- *
187
- * Throws if the share is not in `status="pending"` or if the download fails to
188
- * start (e.g. if the shareId if invalid).
188
+ * Use `useManyReceivedMapShares` or `useSingleReceivedMapShare` to track
189
+ * download progress and final status.
190
+ *
191
+ * If the sender canceled the share before the receiver calls this, the
192
+ * mutation will still resolve (the download starts), but the share status will
193
+ * end up as `'canceled'` rather than `'completed'`. This is the only way the
194
+ * receiver discovers that a share has been canceled — check `share.status`
195
+ * after the download settles.
196
+ *
197
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
198
+ * known to be canceled (i.e. `status` is `'canceled'` in the store, e.g.
199
+ * after a previous download attempt discovered the cancellation).
200
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
201
+ * not in a valid state to start downloading (e.g. already downloading,
202
+ * completed, or declined).
203
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
204
+ * given `shareId` exists in the store.
189
205
  *
190
206
  * @example
191
207
  * ```tsx
192
208
  * function AcceptButton({ shareId }: { shareId: string }) {
193
- * const { mutate: accept } = useAcceptMapShare()
209
+ * const { mutate: accept } = useDownloadReceivedMapShare()
194
210
  *
195
211
  * return <button onClick={() => accept({ shareId })}>Accept</button>
196
212
  * }
@@ -207,17 +223,28 @@ function useDownloadReceivedMapShare() {
207
223
  }
208
224
  /**
209
225
  * Decline a map share that has been received. Notifies the sender that the
210
- * share was declined.
211
- *
212
- * Throws if the share is not with `status="pending"`
213
- * Throws if shareId is invalid
214
- * Throws if decline request fails (e.g. network error)
226
+ * share was declined. The share status is only updated to `'declined'` after
227
+ * the server confirms the decline — there is no optimistic update.
228
+ *
229
+ * If the sender canceled the share before the decline reaches the server, the
230
+ * share status will transition to `'canceled'` (not `'error'`) and the
231
+ * mutation will throw a `MapShareCanceledError`.
232
+ *
233
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
234
+ * known to be canceled, or if the server reports that the sender canceled
235
+ * the share while the decline was in flight. In both cases `share.status`
236
+ * will be `'canceled'`.
237
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
238
+ * not in `status='pending'` (e.g. already downloading, completed, or
239
+ * declined).
240
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
241
+ * given `shareId` exists in the store.
215
242
  *
216
243
  * @example
217
244
  * ```tsx
218
245
  * import { DeclineReason } from '@comapeo/core-react'
219
246
  * function DeclineButton({ shareId }: { shareId: string }) {
220
- * const { mutate: decline } = useDeclineMapShare()
247
+ * const { mutate: decline } = useDeclineReceivedMapShare()
221
248
  *
222
249
  * return (
223
250
  * <button onClick={() => decline({ shareId, reason: DeclineReason.user_rejected })}>
@@ -239,13 +266,20 @@ function useDeclineReceivedMapShare() {
239
266
  /**
240
267
  * Abort an in-progress map share download.
241
268
  *
242
- * Throws if the share is not in `status="downloading"`
243
- * Throws if shareId is invalid
269
+ * @throws An error with code `'MAP_SHARE_CANCELED'` if the share is already
270
+ * known to be canceled.
271
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
272
+ * not in `status='downloading'` (e.g. still pending, already completed, or
273
+ * declined).
274
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
275
+ * given `shareId` exists in the store.
276
+ * @throws An error with code `'DOWNLOAD_NOT_FOUND'` if no download is
277
+ * currently tracked for this share (e.g. the download was never started).
244
278
  *
245
279
  * @example
246
280
  * ```tsx
247
281
  * function AbortButton({ shareId }: { shareId: string }) {
248
- * const { mutate: abort } = useAbortMapShareDownload()
282
+ * const { mutate: abort } = useAbortReceivedMapShareDownload()
249
283
  *
250
284
  * return <button onClick={() => abort({ shareId })}>Cancel Download</button>
251
285
  * }
@@ -269,8 +303,6 @@ function useAbortReceivedMapShareDownload() {
269
303
  * mutation resolves with the created map share object, including its ID, which
270
304
  * can be used to track the share status with `useSingleSentMapShare`.
271
305
  *
272
- * @param opts.projectId Public ID of project for sending the map share: you can only send map shares to users on the same project
273
- *
274
306
  * @example
275
307
  * ```tsx
276
308
  * function SendMapButton({ projectId, deviceId }: { projectId: string; deviceId: string }) {
@@ -279,7 +311,7 @@ function useAbortReceivedMapShareDownload() {
279
311
  * return (
280
312
  * <button
281
313
  * onClick={() =>
282
- * send({ projectId, receiverDeviceId: deviceId, mapId: 'custom' }, {
314
+ * send({ receiverDeviceId: deviceId, mapId: 'custom' }, {
283
315
  * onSuccess: (mapShare) => {
284
316
  * console.log('Share sent with id', mapShare.shareId)
285
317
  * }
@@ -308,6 +340,12 @@ function useSendMapShare() {
308
340
  * the share, the download will be canceled before completion. If the download
309
341
  * is already complete, this action will throw an error.
310
342
  *
343
+ * @throws An error with code `'INVALID_STATUS_TRANSITION'` if the share is
344
+ * not in `status='pending'` or `status='downloading'` (e.g. already
345
+ * completed, canceled, aborted, or declined).
346
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no share with the
347
+ * given `shareId` exists in the store.
348
+ *
311
349
  * @param opts.projectId Public ID of project to request the map share cancellation for.
312
350
  *
313
351
  * @example
@@ -333,7 +371,8 @@ function useCancelSentMapShare() {
333
371
  * of the share, updated in real-time. When the recipient starts downloading, or
334
372
  * if they decline the share, then the returned share will update.
335
373
  *
336
- * Throws if no share with the specified ID is found.
374
+ * @throws An error with code `'MAP_SHARE_NOT_FOUND'` if no sent share with
375
+ * the given `shareId` exists in the store.
337
376
  *
338
377
  * @param opts.shareId ID of the sent map share
339
378
  *
@@ -4,7 +4,7 @@ export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection,
4
4
  export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSingleInvite, } from './hooks/invites.js';
5
5
  export { useMapStyleUrl, useImportCustomMapFile, useRemoveCustomMapFile, useGetCustomMapInfo, useManyReceivedMapShares, useSingleReceivedMapShare, useDeclineReceivedMapShare, useDownloadReceivedMapShare, useAbortReceivedMapShareDownload, useSendMapShare, useCancelSentMapShare, useSingleSentMapShare, } from './hooks/maps.js';
6
6
  export type { SentMapShareState, ReceivedMapShareState, AbortMapShareOptions, CancelMapShareOptions, DeclineMapShareOptions, DownloadMapShareOptions, CreateAndSendMapShareOptions, } from './lib/map-shares-stores.js';
7
- export { DeclineReason } from './lib/map-shares-stores.js';
7
+ export { DeclineReason, MapShareErrorCode, getErrorCode, MapShareCanceledError, InvalidStatusTransitionError, } from './lib/map-shares-stores.js';
8
8
  export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectOwnRoleChangeListener, useProjectSettings, useRemoveServerPeer, useRemoveMember, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
9
9
  export type { SyncState } from './lib/sync.js';
10
10
  export type { WriteableDocument, WriteableDocumentType, WriteableValue, } from './lib/types.js';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRemoveServerPeer = exports.useProjectSettings = exports.useProjectOwnRoleChangeListener = exports.useOwnRoleInProject = exports.useManyProjects = exports.useManyMembers = exports.useLeaveProject = exports.useImportProjectConfig = exports.useImportProjectCategories = exports.useIconUrl = exports.useDocumentCreatedBy = exports.useDisconnectSyncServers = exports.useDataSyncProgress = exports.useCreateProject = exports.useCreateBlob = exports.useConnectSyncServers = exports.useAttachmentUrl = exports.useAddServerPeer = exports.DeclineReason = exports.useSingleSentMapShare = exports.useCancelSentMapShare = exports.useSendMapShare = exports.useAbortReceivedMapShareDownload = exports.useDownloadReceivedMapShare = exports.useDeclineReceivedMapShare = exports.useSingleReceivedMapShare = exports.useManyReceivedMapShares = exports.useGetCustomMapInfo = exports.useRemoveCustomMapFile = exports.useImportCustomMapFile = exports.useMapStyleUrl = exports.useSingleInvite = exports.useSendInvite = exports.useRequestCancelInvite = exports.useRejectInvite = exports.useManyInvites = exports.useAcceptInvite = exports.useUpdateDocument = exports.useSingleDocByVersionId = exports.useSingleDocByDocId = exports.usePresetsSelection = exports.useManyDocs = exports.useDeleteDocument = exports.useCreateDocument = exports.useSetOwnDeviceInfo = exports.useSetIsArchiveDevice = exports.useOwnDeviceInfo = exports.useIsArchiveDevice = exports.useClientApi = exports.ComapeoCoreProvider = void 0;
4
- exports.isHTTPError = exports.HTTPError = exports.useExportZipFile = exports.useExportGeoJSON = exports.useChangeMemberRole = exports.useUpdateProjectSettings = exports.useSyncState = exports.useStopSync = exports.useStartSync = exports.useSingleProject = exports.useSingleMember = exports.useSetAutostopDataSyncTimeout = exports.useRemoveMember = void 0;
3
+ exports.useManyProjects = exports.useManyMembers = exports.useLeaveProject = exports.useImportProjectConfig = exports.useImportProjectCategories = exports.useIconUrl = exports.useDocumentCreatedBy = exports.useDisconnectSyncServers = exports.useDataSyncProgress = exports.useCreateProject = exports.useCreateBlob = exports.useConnectSyncServers = exports.useAttachmentUrl = exports.useAddServerPeer = exports.InvalidStatusTransitionError = exports.MapShareCanceledError = exports.getErrorCode = exports.MapShareErrorCode = exports.DeclineReason = exports.useSingleSentMapShare = exports.useCancelSentMapShare = exports.useSendMapShare = exports.useAbortReceivedMapShareDownload = exports.useDownloadReceivedMapShare = exports.useDeclineReceivedMapShare = exports.useSingleReceivedMapShare = exports.useManyReceivedMapShares = exports.useGetCustomMapInfo = exports.useRemoveCustomMapFile = exports.useImportCustomMapFile = exports.useMapStyleUrl = exports.useSingleInvite = exports.useSendInvite = exports.useRequestCancelInvite = exports.useRejectInvite = exports.useManyInvites = exports.useAcceptInvite = exports.useUpdateDocument = exports.useSingleDocByVersionId = exports.useSingleDocByDocId = exports.usePresetsSelection = exports.useManyDocs = exports.useDeleteDocument = exports.useCreateDocument = exports.useSetOwnDeviceInfo = exports.useSetIsArchiveDevice = exports.useOwnDeviceInfo = exports.useIsArchiveDevice = exports.useClientApi = exports.ComapeoCoreProvider = void 0;
4
+ exports.isHTTPError = exports.HTTPError = exports.useExportZipFile = exports.useExportGeoJSON = exports.useChangeMemberRole = exports.useUpdateProjectSettings = exports.useSyncState = exports.useStopSync = exports.useStartSync = exports.useSingleProject = exports.useSingleMember = exports.useSetAutostopDataSyncTimeout = exports.useRemoveMember = exports.useRemoveServerPeer = exports.useProjectSettings = exports.useProjectOwnRoleChangeListener = exports.useOwnRoleInProject = void 0;
5
5
  var ComapeoCore_js_1 = require("./contexts/ComapeoCore.js");
6
6
  Object.defineProperty(exports, "ComapeoCoreProvider", { enumerable: true, get: function () { return ComapeoCore_js_1.ComapeoCoreProvider; } });
7
7
  var client_js_1 = require("./hooks/client.js");
@@ -40,6 +40,10 @@ Object.defineProperty(exports, "useCancelSentMapShare", { enumerable: true, get:
40
40
  Object.defineProperty(exports, "useSingleSentMapShare", { enumerable: true, get: function () { return maps_js_1.useSingleSentMapShare; } });
41
41
  var map_shares_stores_js_1 = require("./lib/map-shares-stores.js");
42
42
  Object.defineProperty(exports, "DeclineReason", { enumerable: true, get: function () { return map_shares_stores_js_1.DeclineReason; } });
43
+ Object.defineProperty(exports, "MapShareErrorCode", { enumerable: true, get: function () { return map_shares_stores_js_1.MapShareErrorCode; } });
44
+ Object.defineProperty(exports, "getErrorCode", { enumerable: true, get: function () { return map_shares_stores_js_1.getErrorCode; } });
45
+ Object.defineProperty(exports, "MapShareCanceledError", { enumerable: true, get: function () { return map_shares_stores_js_1.MapShareCanceledError; } });
46
+ Object.defineProperty(exports, "InvalidStatusTransitionError", { enumerable: true, get: function () { return map_shares_stores_js_1.InvalidStatusTransitionError; } });
43
47
  var projects_js_1 = require("./hooks/projects.js");
44
48
  Object.defineProperty(exports, "useAddServerPeer", { enumerable: true, get: function () { return projects_js_1.useAddServerPeer; } });
45
49
  Object.defineProperty(exports, "useAttachmentUrl", { enumerable: true, get: function () { return projects_js_1.useAttachmentUrl; } });
@@ -9,6 +9,107 @@ export type ReceivedMapShareState = DistributedIntersection<Simplify<MapShare>,
9
9
  export type SentMapShareState = ServerMapShareState;
10
10
  export type ReceivedMapSharesStore = ReturnType<typeof createReceivedMapSharesStore>;
11
11
  export type SentMapSharesStore = ReturnType<typeof createSentMapSharesStore>;
12
+ /**
13
+ * Error codes for map share operations. Use with {@link getErrorCode} to safely
14
+ * check the error code of an unknown error thrown by a map share mutation, or
15
+ * to check the `error.code` on a share in `status='error'`.
16
+ *
17
+ * ## Receiver errors
18
+ *
19
+ * **Mutation errors** (thrown by receiver hooks, check via
20
+ * `getErrorCode(mutation.error)`):
21
+ * - `MAP_SHARE_CANCELED` — the sender canceled the share
22
+ * - `INVALID_STATUS_TRANSITION` — the action is not valid for the share's
23
+ * current status (e.g. declining a share that is already downloading)
24
+ * - `MAP_SHARE_NOT_FOUND` — no share with the given `shareId` exists
25
+ * - `DOWNLOAD_NOT_FOUND` — abort was called but no download is tracked for
26
+ * this share
27
+ *
28
+ * **Share state errors** (on received `share.error.code` when
29
+ * `share.status === 'error'`):
30
+ * - `DOWNLOAD_ERROR` — the download failed (network, disk, or server error)
31
+ * - `DECLINE_CANNOT_CONNECT` — the decline was accepted locally but the sender
32
+ * could not be reached to notify them
33
+ *
34
+ * ## Sender errors
35
+ *
36
+ * **Mutation errors** (thrown by sender hooks, check via
37
+ * `getErrorCode(mutation.error)`):
38
+ * - `INVALID_STATUS_TRANSITION` — the action is not valid for the share's
39
+ * current status (e.g. canceling a share that is already canceled)
40
+ * - `MAP_SHARE_NOT_FOUND` — no share with the given `shareId` exists
41
+ *
42
+ * **Share state errors** (on sent `share.error.code` when
43
+ * `share.status === 'error'`):
44
+ * - `CANCEL_SHARE_NOT_CANCELABLE` — the cancel request reached the server but
45
+ * the share is already in a final state (e.g. completed or declined)
46
+ *
47
+ * ## Common
48
+ *
49
+ * - `UNKNOWN_ERROR` — fallback when the original error has no specific code.
50
+ * Can appear as both a mutation error and a share state error for either
51
+ * sender or receiver.
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * import { getErrorCode, MapShareErrorCode } from '@comapeo/core-react'
56
+ *
57
+ * // Receiver: checking a mutation error
58
+ * const decline = useDeclineReceivedMapShare()
59
+ * // ... after mutation fails:
60
+ * if (getErrorCode(decline.error) === MapShareErrorCode.MAP_SHARE_CANCELED) {
61
+ * // Show "this share was canceled by the sender"
62
+ * }
63
+ * ```
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * // Receiver: checking a share state error
68
+ * const share = useSingleReceivedMapShare({ shareId })
69
+ * if (share.status === 'error') {
70
+ * if (share.error.code === MapShareErrorCode.DOWNLOAD_ERROR) {
71
+ * // Show "download failed, try again?"
72
+ * }
73
+ * }
74
+ * ```
75
+ */
76
+ export declare const MapShareErrorCode: {
77
+ /** Receiver: the sender canceled the share before the action could complete */
78
+ readonly MAP_SHARE_CANCELED: "MAP_SHARE_CANCELED";
79
+ /** Receiver/Sender: the action is not valid for the share's current status */
80
+ readonly INVALID_STATUS_TRANSITION: "INVALID_STATUS_TRANSITION";
81
+ /** Receiver/Sender: no map share with the given `shareId` exists in the store */
82
+ readonly MAP_SHARE_NOT_FOUND: "MAP_SHARE_NOT_FOUND";
83
+ /** Receiver: abort was called but no download is tracked for this share */
84
+ readonly DOWNLOAD_NOT_FOUND: "DOWNLOAD_NOT_FOUND";
85
+ /** Receiver: the download failed due to a network, disk, or server error */
86
+ readonly DOWNLOAD_ERROR: "DOWNLOAD_ERROR";
87
+ /** Receiver: could not connect to the sender to notify them of the decline */
88
+ readonly DECLINE_CANNOT_CONNECT: "DECLINE_CANNOT_CONNECT";
89
+ /** Sender: cancel failed because the share is already in a final state on the server */
90
+ readonly CANCEL_SHARE_NOT_CANCELABLE: "CANCEL_SHARE_NOT_CANCELABLE";
91
+ /** Receiver/Sender: fallback code when the original error has no specific code */
92
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
93
+ };
94
+ /**
95
+ * Safely extract the `code` property from an unknown error. Returns `undefined`
96
+ * if the value is not an Error or has no string `code` property.
97
+ *
98
+ * @example
99
+ * ```tsx
100
+ * import { getErrorCode, MapShareErrorCode } from '@comapeo/core-react'
101
+ *
102
+ * try {
103
+ * await decline.mutateAsync({ shareId, reason: 'user_rejected' })
104
+ * } catch (e) {
105
+ * const code = getErrorCode(e)
106
+ * if (code === MapShareErrorCode.MAP_SHARE_CANCELED) {
107
+ * // handle cancellation
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ export declare function getErrorCode(error: unknown): string | undefined;
12
113
  /** Known reasons for declining a map share */
13
114
  export declare const DeclineReason: {
14
115
  /** User explicitly rejected the map share */
@@ -35,8 +136,6 @@ export type AbortMapShareOptions = {
35
136
  };
36
137
  /** Options for creating and sending a map share */
37
138
  export type CreateAndSendMapShareOptions = {
38
- /** Public ID of the project to send the share on behalf of */
39
- projectId: string;
40
139
  /** Device ID of the recipient */
41
140
  receiverDeviceId: string;
42
141
  /** ID of the map to share - not needed until we support multiple maps */
@@ -47,6 +146,24 @@ export type CancelMapShareOptions = {
47
146
  /** ID of the map share to cancel */
48
147
  shareId: string;
49
148
  };
149
+ /**
150
+ * Thrown when a receiver action (download, decline, or abort) is attempted on a
151
+ * map share that has been canceled by the sender. Has `code: 'MAP_SHARE_CANCELED'`.
152
+ */
153
+ export declare class MapShareCanceledError extends Error {
154
+ code: "MAP_SHARE_CANCELED";
155
+ constructor(shareId: string);
156
+ }
157
+ /**
158
+ * Thrown when an action is attempted on a map share whose current status does
159
+ * not allow the requested transition (e.g. declining a share that is already
160
+ * downloading, or aborting a share that is still pending).
161
+ * Has `code: 'INVALID_STATUS_TRANSITION'`.
162
+ */
163
+ export declare class InvalidStatusTransitionError extends Error {
164
+ code: "INVALID_STATUS_TRANSITION";
165
+ constructor(current: string, next: string);
166
+ }
50
167
  /**
51
168
  * Store and actions for received map shares.
52
169
  */
@@ -73,7 +190,7 @@ export declare function createSentMapSharesStore({ clientApi, mapServerApi, }: {
73
190
  subscribe: (listener: () => void) => () => boolean;
74
191
  getSnapshot: () => ServerMapShareState[];
75
192
  actions: {
76
- createAndSend({ projectId, receiverDeviceId, mapId, }: CreateAndSendMapShareOptions): Promise<ServerMapShareState>;
193
+ createAndSend({ receiverDeviceId, mapId, }: CreateAndSendMapShareOptions): Promise<ServerMapShareState>;
77
194
  cancel({ shareId }: CancelMapShareOptions): Promise<void>;
78
195
  };
79
196
  };