@sparkvault/sdk-mobile 10.3.0 → 10.5.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/dist/ds-tokens.d.ts +45 -0
- package/dist/ds-tokens.js +59 -0
- package/dist/ds-tokens.js.map +1 -0
- package/dist/identity-dialog.d.ts +8 -1
- package/dist/identity-dialog.js +145 -117
- package/dist/identity-dialog.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sparks.d.ts +70 -14
- package/dist/sparks.js +18 -8
- package/dist/sparks.js.map +1 -1
- package/dist/sparks.test-d.d.ts +17 -3
- package/dist/sparks.test-d.js +6 -2
- package/dist/sparks.test-d.js.map +1 -1
- package/dist/types.d.ts +23 -6
- package/package.json +1 -1
- package/src/ds-tokens.ts +63 -0
- package/src/identity-dialog.tsx +253 -139
- package/src/index.ts +1 -0
- package/src/sparks.test-d.ts +32 -2
- package/src/sparks.ts +76 -15
- package/src/types.ts +25 -6
package/src/sparks.test-d.ts
CHANGED
|
@@ -11,11 +11,16 @@
|
|
|
11
11
|
* and `link_code` beside the spark), apps/api/src/sparks/list.js (each listed
|
|
12
12
|
* spark, a link spark's `link_url` included) and apps/api/src/sparks/readCore.js
|
|
13
13
|
* (`buildReadResponse`: the payload and the name it saves under,
|
|
14
|
-
* `download_filename`).
|
|
15
|
-
*
|
|
14
|
+
* `download_filename`) and apps/api/src/sparks/share.js (`shareSpark`: the
|
|
15
|
+
* link's settings and status, what the share delivered, and whether it
|
|
16
|
+
* changed a link already there; `getShareStatus`: the same link envelope, or
|
|
17
|
+
* `shared: false`). A field the server sends that a type leaves
|
|
18
|
+
* out is one a typed caller cannot reach: a link spark's caller has no link to
|
|
19
|
+
* send.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
import type { CreateSparkResponse, Spark, SparkResponse } from './sparks.js';
|
|
23
|
+
import type { ShareSparkResponse, SparkShareStatus } from './types.js';
|
|
19
24
|
|
|
20
25
|
/** Fails to compile unless `T` resolves to exactly `true`. */
|
|
21
26
|
type Assert<T extends true> = T;
|
|
@@ -85,4 +90,29 @@ export type SparksWireContract = [
|
|
|
85
90
|
Assert<Equals<SparkResponse['download_filename'], string>>,
|
|
86
91
|
Assert<Equals<SparkResponse['status'], 'active' | 'ash'>>,
|
|
87
92
|
Assert<Equals<SparkResponse['burned_at'], number | null>>,
|
|
93
|
+
// Exactly the fields a share answers.
|
|
94
|
+
Assert<
|
|
95
|
+
Equals<
|
|
96
|
+
keyof ShareSparkResponse,
|
|
97
|
+
| 'shared'
|
|
98
|
+
| 'spark_id'
|
|
99
|
+
| 'share_url'
|
|
100
|
+
| 'link_code'
|
|
101
|
+
| 'visibility'
|
|
102
|
+
| 'invites'
|
|
103
|
+
| 'status'
|
|
104
|
+
| 'expires_at'
|
|
105
|
+
| 'created_at'
|
|
106
|
+
| 'already_shared'
|
|
107
|
+
| 'delivered_to'
|
|
108
|
+
>
|
|
109
|
+
>,
|
|
110
|
+
Assert<Equals<ShareSparkResponse['status'], 'active' | 'consumed' | 'expired'>>,
|
|
111
|
+
Assert<Equals<ShareSparkResponse['visibility'], 'public' | 'authenticated' | 'invite_only'>>,
|
|
112
|
+
// A read of a shared spark's sharing answers the share's own envelope.
|
|
113
|
+
Assert<Equals<SharedSparkStatus['status'], ShareSparkResponse['status']>>,
|
|
114
|
+
Assert<Equals<SharedSparkStatus['visibility'], ShareSparkResponse['visibility']>>,
|
|
88
115
|
];
|
|
116
|
+
|
|
117
|
+
/** The read of a shared spark's sharing (`shared: true`). */
|
|
118
|
+
type SharedSparkStatus = Extract<SparkShareStatus, { shared: true }>;
|
package/src/sparks.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
ResendSparkInviteResponse,
|
|
4
4
|
ShareSparkResponse,
|
|
5
5
|
SparkShareStatus,
|
|
6
|
+
SparkShareVisibility,
|
|
6
7
|
UnshareSparkResponse,
|
|
7
8
|
} from './types.js';
|
|
8
9
|
import { apiPath } from './request-path.js';
|
|
@@ -14,17 +15,30 @@ export interface Spark {
|
|
|
14
15
|
account_id: string;
|
|
15
16
|
content_type: string;
|
|
16
17
|
size_bytes: number;
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Its state when the list answers: `active` while its content is live (a
|
|
20
|
+
* Spark a recipient is reading included), `ash` once a recipient read or
|
|
21
|
+
* answered it or its content was recalled (past `expires_at` too),
|
|
22
|
+
* `expired` past `expires_at` and never burned, `deleted` once its owner
|
|
23
|
+
* deleted it (never reported `ash`).
|
|
24
|
+
*/
|
|
18
25
|
status: 'active' | 'ash' | 'expired' | 'deleted';
|
|
19
26
|
created_at: number;
|
|
20
27
|
expires_at: number;
|
|
21
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* When it turned `ash`; null for every other `status`, `deleted` included,
|
|
30
|
+
* though a delete burns the content too.
|
|
31
|
+
*/
|
|
22
32
|
burned_at: number | null;
|
|
23
33
|
/** Seconds left before it expires, 0 once it has. */
|
|
24
34
|
time_remaining: number;
|
|
25
35
|
filename?: string;
|
|
26
36
|
kindling?: string;
|
|
27
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Its x.sv link, while it has one: a link spark (content_type
|
|
39
|
+
* text/uri-list) from its create, any other spark from its share until it
|
|
40
|
+
* is unshared. A deleted Spark keeps the link it had, which opens nothing.
|
|
41
|
+
*/
|
|
28
42
|
link_url?: string;
|
|
29
43
|
}
|
|
30
44
|
|
|
@@ -91,13 +105,49 @@ export interface CreateSparkResponse {
|
|
|
91
105
|
link_code?: string;
|
|
92
106
|
}
|
|
93
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Options for share. A spark already shared keeps its link: the settings are
|
|
110
|
+
* applied to it in place, and its code never changes.
|
|
111
|
+
*/
|
|
94
112
|
export interface ShareSparkOptions {
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Link visibility: public on a spark's first share; an omitted visibility
|
|
115
|
+
* keeps the link's current one.
|
|
116
|
+
*/
|
|
117
|
+
visibility?: SparkShareVisibility;
|
|
118
|
+
/**
|
|
119
|
+
* For invite_only visibility: the one identity (an email address or a phone
|
|
120
|
+
* number) the link is delivered to. Refused with any other visibility; an
|
|
121
|
+
* omitted list keeps the link's current invitee.
|
|
122
|
+
*/
|
|
98
123
|
invites?: string[];
|
|
99
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Link expiration TTL in seconds (server minimum 60, capped at the spark's
|
|
126
|
+
* own expiry). Applies to a spark's first share only: a change to an
|
|
127
|
+
* existing link keeps its lifetime.
|
|
128
|
+
*/
|
|
100
129
|
expiresInSeconds?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The link this change was asked of (its `link_code`, as a share answered
|
|
132
|
+
* it). When it is no longer the spark's link (turned off, or replaced by
|
|
133
|
+
* another share), the change is refused with a 409 CONFLICT and changes
|
|
134
|
+
* nothing. Omitted, the change applies to the spark's link now.
|
|
135
|
+
*/
|
|
136
|
+
linkCode?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Options for resendInvite and unshare, which act on a spark's existing link. */
|
|
140
|
+
export interface SparkLinkActionOptions {
|
|
141
|
+
/**
|
|
142
|
+
* The link this request was asked of (its `link_code`, as a share answered
|
|
143
|
+
* it). A resend asked of a link that is no longer the spark's link (turned
|
|
144
|
+
* off, or replaced by another share) is refused with a 409 CONFLICT,
|
|
145
|
+
* delivering nothing. An unshare is refused only when another share
|
|
146
|
+
* replaced the link, deleting nothing; a link already turned off answers
|
|
147
|
+
* `shared: false`, so a retried unshare is never refused. Omitted, the
|
|
148
|
+
* request acts on the spark's link now.
|
|
149
|
+
*/
|
|
150
|
+
linkCode?: string;
|
|
101
151
|
}
|
|
102
152
|
|
|
103
153
|
export class MobileSparksClient {
|
|
@@ -138,9 +188,10 @@ export class MobileSparksClient {
|
|
|
138
188
|
}
|
|
139
189
|
|
|
140
190
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
191
|
+
* Share a spark via a SparkLink, yielding a shareable `https://x.sv/...` URL:
|
|
192
|
+
* created on the first share; on a spark already shared, the requested
|
|
193
|
+
* settings are applied to the existing link in place (`already_shared`).
|
|
194
|
+
* Only active, non-expired sparks can be shared.
|
|
144
195
|
*/
|
|
145
196
|
async share(sparkId: string, options: ShareSparkOptions = {}): Promise<ShareSparkResponse> {
|
|
146
197
|
validateResourceId(sparkId, 'spark ID', 'sparkId');
|
|
@@ -148,6 +199,7 @@ export class MobileSparksClient {
|
|
|
148
199
|
if (options.visibility) body.visibility = options.visibility;
|
|
149
200
|
if (options.invites) body.invites = options.invites;
|
|
150
201
|
if (options.expiresInSeconds !== undefined) body.expires_in_seconds = options.expiresInSeconds;
|
|
202
|
+
if (options.linkCode !== undefined) body.link_code = options.linkCode;
|
|
151
203
|
|
|
152
204
|
const response = await this.http.patch<ShareSparkResponse>(
|
|
153
205
|
apiPath`/sparks/${sparkId}/share`,
|
|
@@ -161,11 +213,14 @@ export class MobileSparksClient {
|
|
|
161
213
|
* nothing about the link: the way on from an invitation that could not be
|
|
162
214
|
* delivered (a share rejected with 502 INVITATION_DELIVERY_FAILED leaves
|
|
163
215
|
* its link in place, and the same share again delivers nothing).
|
|
216
|
+
* `linkCode` names the link the resend was asked of: a link replaced since
|
|
217
|
+
* is never delivered in its place (409 CONFLICT).
|
|
164
218
|
*/
|
|
165
|
-
async resendInvite(sparkId: string): Promise<ResendSparkInviteResponse> {
|
|
219
|
+
async resendInvite(sparkId: string, options: SparkLinkActionOptions = {}): Promise<ResendSparkInviteResponse> {
|
|
166
220
|
validateResourceId(sparkId, 'spark ID', 'sparkId');
|
|
167
221
|
const response = await this.http.post<ResendSparkInviteResponse>(
|
|
168
|
-
apiPath`/sparks/${sparkId}/share/resend
|
|
222
|
+
apiPath`/sparks/${sparkId}/share/resend`,
|
|
223
|
+
options.linkCode === undefined ? undefined : { link_code: options.linkCode }
|
|
169
224
|
);
|
|
170
225
|
return response.data;
|
|
171
226
|
}
|
|
@@ -179,11 +234,17 @@ export class MobileSparksClient {
|
|
|
179
234
|
return response.data;
|
|
180
235
|
}
|
|
181
236
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Revoke a spark's SparkLink. Resolves whether or not a link existed, the
|
|
239
|
+
* link `linkCode` names included, so a retried unshare is never refused. A
|
|
240
|
+
* `linkCode` naming a link another share replaced since is refused (409
|
|
241
|
+
* CONFLICT), so the link that took its place is never deleted.
|
|
242
|
+
*/
|
|
243
|
+
async unshare(sparkId: string, options: SparkLinkActionOptions = {}): Promise<UnshareSparkResponse> {
|
|
184
244
|
validateResourceId(sparkId, 'spark ID', 'sparkId');
|
|
185
245
|
const response = await this.http.delete<UnshareSparkResponse>(
|
|
186
|
-
apiPath`/sparks/${sparkId}/share
|
|
246
|
+
apiPath`/sparks/${sparkId}/share`,
|
|
247
|
+
{ query: { link_code: options.linkCode } }
|
|
187
248
|
);
|
|
188
249
|
return response.data;
|
|
189
250
|
}
|
package/src/types.ts
CHANGED
|
@@ -1241,17 +1241,37 @@ export interface UploadProgressCallback {
|
|
|
1241
1241
|
(bytesUploaded: number, bytesTotal: number): void;
|
|
1242
1242
|
}
|
|
1243
1243
|
|
|
1244
|
-
/**
|
|
1244
|
+
/** Who may open a spark's SparkLink. */
|
|
1245
|
+
export type SparkShareVisibility = 'public' | 'authenticated' | 'invite_only';
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* A spark's SparkLink status, as every share route answers it: 'active';
|
|
1249
|
+
* 'consumed' once it was opened (it opens once); or 'expired' once a link
|
|
1250
|
+
* never opened opens nothing: from its `expires_at` on, or once its spark is
|
|
1251
|
+
* burned (read by its id) or reaches its own expiry. A change or a resend is
|
|
1252
|
+
* then refused (403 FORBIDDEN).
|
|
1253
|
+
*/
|
|
1254
|
+
export type SparkShareLinkStatus = 'active' | 'consumed' | 'expired';
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Result of sharing a spark: its SparkLink, created on the first share, or the
|
|
1258
|
+
* existing one with the requested settings applied to it in place.
|
|
1259
|
+
*/
|
|
1245
1260
|
export interface ShareSparkResponse {
|
|
1246
1261
|
shared: true;
|
|
1262
|
+
spark_id: string;
|
|
1247
1263
|
/** Public `https://x.sv/{code}` URL for the SparkLink. */
|
|
1248
1264
|
share_url: string;
|
|
1249
1265
|
link_code: string;
|
|
1250
|
-
visibility:
|
|
1266
|
+
visibility: SparkShareVisibility;
|
|
1251
1267
|
invites?: string[];
|
|
1268
|
+
status: SparkShareLinkStatus;
|
|
1252
1269
|
expires_at?: number;
|
|
1253
1270
|
created_at?: number;
|
|
1254
|
-
/**
|
|
1271
|
+
/**
|
|
1272
|
+
* True when a SparkLink already existed: the requested settings were
|
|
1273
|
+
* applied to it in place, and its code is unchanged.
|
|
1274
|
+
*/
|
|
1255
1275
|
already_shared?: boolean;
|
|
1256
1276
|
/**
|
|
1257
1277
|
* The invitees this share delivered the link to: none for a share that
|
|
@@ -1283,10 +1303,9 @@ export type SparkShareStatus =
|
|
|
1283
1303
|
spark_id: string;
|
|
1284
1304
|
share_url: string;
|
|
1285
1305
|
link_code: string;
|
|
1286
|
-
visibility:
|
|
1306
|
+
visibility: SparkShareVisibility;
|
|
1287
1307
|
invites: string[];
|
|
1288
|
-
|
|
1289
|
-
status: string;
|
|
1308
|
+
status: SparkShareLinkStatus;
|
|
1290
1309
|
expires_at?: number;
|
|
1291
1310
|
created_at?: number;
|
|
1292
1311
|
};
|