File size: 8,514 Bytes
61d39e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Share Endpoints

Share endpoints allow sharing files with other users.

## POST `/share` (auth required)

### Description

The `/share` endpoint shares 1 or more filesystem items
with one or more recipients. The recipients will receive
some notification about the shared item, making this
different from calling `/grant-user-user` with a permission.

When users are **specified by email** they will receive
a [share link](./concepts/share-link.md).

Each item specified in the `shares` property is a tag-typed
object of type `fs-share` or `app-share`.

#### File Shares (`fs-share`)

File shares grant permission to a file or directory. By default
this is read permission. If `access` is specified as `"write"`,
then write permission will be granted.

#### App Shares (`app-share`)

App shares grant permission to read a protected app.

##### subdomain permission
If there is a subdomain associated with the app, and the owner
of the subdomain is the same as the owner of the app, then
permission to access the subdomain will be granted.
Note that the subdomain is only associated if the subdomain
entry has `associated_app_id` set according to the app's id,
and will not be considered "associated" if only the index_url

happens to match the subdomain url.



##### appdata permission

If the app has `shared_appdata` set to `true` in its metadata
object, the recipient of the share will also get write permission
to the app owner's corresponding appdata directory. The appdata
directory must exist for this to work as expected
(otherwise the permission rewrite rule fails since the uuid
can't be determined).

### Example

```json

{

    "recipients": [

        "user_that_gets_shared_to",

        "another@example.com"

    ],

    "shares": [

        {

            "$": "app-share",

            "name": "some-app-name"

        },

        {

            "$": "app-share",

            "uid": "app-SOME-APP-UID"

        },

        {

            "$": "fs-share",

            "path": "/some/file/or/directory"

        },

        {

            "$": "fs-share",

            "path": "SOME-FILE-UUID"

        }

    ]

}

```

### Parameters

- **recipients** _- required_
  - **accepts:** `string | Array<string>`
  - **description:**
    recipients for the filesystem entries being shared.

  - **notes:**

    - validation on `string`: email or username

    - requirement of at least one value

- **shares:** _- required_

  - **accepts:** `object | Array<object>`

    - object is [type-tagged](./type-tagged.md)

    - type is either [file-share](./types/file-share.md)

      or [app-share](./types/app-share.md)

  - **notes:**

    - requirement that file/directory or app exists

    - requirement of at least one entry

- **dry_run:** _- optional_

  - **accepts:** `bool`

  - **description:**

    when true, only validation will occur

    

### Response


- **$:** `api:share`
- **$version:** `v0.0.0`
- **status:** one of: `"success"`, `"mixed"`, `"aborted"`
- **recipients:** array of: `api:status-report` or
  `heyputer:api/APIError`
- **paths:** array of: `api:status-report` or
  `heyputer:api/APIError`
- **dry_run:** `true` if present



### Request Example



```javascript

await fetch("http://puter.localhost:4100/share", {

  headers: {

    "Content-Type": "application/json",

    "Authorization": `Bearer ${puter.authToken}`,

  },

  body: JSON.stringify({

    recipients: [

        "user_that_gets_shared_to",

        "another@example.com"

    ],

    shares: [

        {

            $: "app-share",

            name: "some-app-name"

        },

        {

            $: "app-share",

            uid: "app-SOME-APP-UID"

        },

        {

            $: "fs-share",

            path: "/some/file/or/directory"

        },

        {

            $: "fs-share",

            path: "SOME-FILE-UUID"

        }

    ]

  }),

  method: "POST",

});

```



### Success Response



```json

{

    "$": "api:share",

    "$version": "v0.0.0",

    "status": "success",

    "recipients": [

        {

            "$": "api:status-report",

            "status": "success"

        }

    ],

    "paths": [

        {

            "$": "api:status-report",

            "status": "success"

        }

    ],

    "dry_run": true

}

```



### Error response (missing file)



```json

{

    "$": "api:share",

    "$version": "v0.0.0",

    "status": "mixed",

    "recipients": [

        {

            "$": "api:status-report",

            "status": "success"

        }

    ],

    "paths": [

        {

            "$": "heyputer:api/APIError",

            "code": "subject_does_not_exist",

            "message": "File or directory not found.",

            "status": 404

        }

    ],

    "dry_run": true

}

```



### Error response (missing user)



```json

{

    "$": "api:share",

    "$version": "v0.0.0",

    "status": "mixed",

    "recipients": [

        {

            "$": "heyputer:api/APIError",

            "code": "user_does_not_exist",

            "message": "The user `non_existing_user` does not exist.",

            "username": "non_existing_user",

            "status": 422

        }

    ],

    "paths": [

        {

            "$": "api:status-report",

            "status": "success"

        }

    ],

    "dry_run": true

}

```



## POST `/sharelink/check` (no auth)



### Description



The `/sharelink/check` endpoint verifies that a token provided

by a share link is valid.



### Example



```javascript

await fetch(`${config.api_origin}/sharelink/check`, {

  "headers": {

    "Content-Type": "application/json",

    "Authorization": `Bearer ${puter.authToken}`,

  },

  "body": JSON.stringify({

      token: '...',

  }),

  "method": "POST",

});

```



### Parameters



- **token:** _- required_

  - **accepts:** `string`
    The token from the querystring parameter


### Response

A type-tagged object, either of type `api:share` or `api:error`

### Success Response

```json

{

    "$": "api:share",

    "uid": "836671d4-ac5d-4bd3-bc0a-ec357e0d8f02",

    "email": "asdf@example.com"

}

```

### Error Response

```json

{

    "$": "api:error",

    "message":"Field `token` is required.",

    "key":"token",

    "code":"field_missing"

}

```

## POST `/sharelink/apply` (no auth)

### Description

The `/sharelink/apply` endpoint applies a share to the current
user **if and only if** that user's email is confirmed and matches
the email associated with the share.

### Example

```javascript

await fetch(`${config.api_origin}/sharelink/apply`, {

  "headers": {

    "Content-Type": "application/json",

    "Authorization": `Bearer ${puter.authToken}`,

  },

  "body": JSON.stringify({

      uid: '836671d4-ac5d-4bd3-bc0a-ec357e0d8f02',

  }),

  "method": "POST",

});

```

### Parameters

- **uid:** _- required_
  - **accepts:** `string`
    The uid of an existing share, received using `/sharelink/check`


### Response

A type-tagged object, either of type `api:status-report` or `api:error`

### Success Response

```json

{"$":"api:status-report","status":"success"}

```

### Error Response

```json

{

    "message": "This share can not be applied to this user.",

    "code": "can_not_apply_to_this_user"

}

```

## POST `/sharelink/request` (no auth)

### Description

The `/sharelink/request` endpoint requests the permissions associated
with a share link to the issuer of the share (user that sent the share).
This can be used when a user is logged in, but that user's email does
not match the email associated with the share.

### Example

```javascript

await fetch(`${config.api_origin}/sharelink/request`, {

  "headers": {

    "Content-Type": "application/json",

    "Authorization": `Bearer ${puter.authToken}`,

  },

  "body": JSON.stringify({

      uid: '836671d4-ac5d-4bd3-bc0a-ec357e0d8f02',

  }),

  "method": "POST",

});

```

### Parameters

- **uid:** _- required_
  - **accepts:** `string`
    The uid of an existing share, received using `/sharelink/check`


### Response

A type-tagged object, either of type `api:status-report` or `api:error`

### Success Response

```json

{"$":"api:status-report","status":"success"}

```

### Error Response

```json

{

    "message": "This share is already valid for this user; POST to /apply for access",

    "code": "no_need_to_request"

}

```