@forge/object-store 1.1.0-next.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/LICENSE.txt +7 -0
- package/README.md +76 -0
- package/package.json +28 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2025 Atlassian
|
|
2
|
+
Permission is hereby granted to use this software in accordance with the terms
|
|
3
|
+
and conditions outlined in the Atlassian Developer Terms, which can be found
|
|
4
|
+
at the following URL:
|
|
5
|
+
https://developer.atlassian.com/platform/marketplace/atlassian-developer-terms/
|
|
6
|
+
By using this software, you agree to comply with these terms and conditions.
|
|
7
|
+
If you do not agree with these terms, you are not permitted to use this software.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Library for Forge environment.
|
|
2
|
+
|
|
3
|
+
Usage example:
|
|
4
|
+
```typescript
|
|
5
|
+
import fos from "@forge/object-store";
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Types exported:
|
|
9
|
+
```typescript
|
|
10
|
+
export interface ObjectReference {
|
|
11
|
+
key: string;
|
|
12
|
+
checksum: string;
|
|
13
|
+
size: number;
|
|
14
|
+
createdAt?: string;
|
|
15
|
+
currentVersion?: string;
|
|
16
|
+
contentType?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface UploadUrlBody {
|
|
20
|
+
key: string;
|
|
21
|
+
length: number;
|
|
22
|
+
checksum: string;
|
|
23
|
+
checksumType: 'SHA1' | 'SHA256' | 'CRC32' | 'CRC32C';
|
|
24
|
+
ttlSeconds?: number;
|
|
25
|
+
overwrite?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PresignedUrlResponse {
|
|
29
|
+
url: string;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Example upload & download:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Create a buffer from some object and then calculate the SHA256 checksum for it
|
|
37
|
+
const buffer = Buffer.from(object);
|
|
38
|
+
const checksum = crypto.createHash('sha256').update(buffer).digest('base64');
|
|
39
|
+
const key = 'your-object-id';
|
|
40
|
+
|
|
41
|
+
const payload = {
|
|
42
|
+
key,
|
|
43
|
+
checksum,
|
|
44
|
+
checksumType: 'SHA256',
|
|
45
|
+
length: buffer.length,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Create a pre-signed upload url
|
|
49
|
+
const uploadUrlResponse = await fos.createUploadUrl(payload);
|
|
50
|
+
const uploadUrl = uploadUrlResponse.url;
|
|
51
|
+
|
|
52
|
+
// Both standard fetch or api.fetch can be used to upload the buffer
|
|
53
|
+
const response = await fetch(url, {
|
|
54
|
+
method: 'PUT',
|
|
55
|
+
headers: {
|
|
56
|
+
'content-type': 'application/octet-stream', // or the actual content type of your object
|
|
57
|
+
},
|
|
58
|
+
body: buffer,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Check the object metadata
|
|
62
|
+
const metadata = await fos.get(key);
|
|
63
|
+
console.log(metadata);
|
|
64
|
+
|
|
65
|
+
// Download the object by creating a pre-signed link first and then download the object
|
|
66
|
+
const downloadUrlResponse = await fos.createDownloadUrl(key);
|
|
67
|
+
const downloadRes = await fetch(downloadUrlResponse.url);
|
|
68
|
+
|
|
69
|
+
// These buffers should be equal
|
|
70
|
+
const downloaded = Buffer.from(await downloadRes.arrayBuffer());
|
|
71
|
+
const message = buffer.equals(downloaded)
|
|
72
|
+
? "\x1b[32m✅ Files are identical.\x1b[0m"
|
|
73
|
+
: "\x1b[31m❌ Files differ!\x1b[0m"
|
|
74
|
+
|
|
75
|
+
console.log(message);
|
|
76
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forge/object-store",
|
|
3
|
+
"version": "1.1.0-next.1",
|
|
4
|
+
"description": "Forge Object Store SDK",
|
|
5
|
+
"author": "Atlassian",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
|
+
"main": "out/index.js",
|
|
8
|
+
"types": "out/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"out"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "yarn run clean && yarn run compile",
|
|
14
|
+
"clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo",
|
|
15
|
+
"compile": "tsc -b -v"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "20.19.1",
|
|
19
|
+
"expect-type": "^0.17.3",
|
|
20
|
+
"jest-when": "^3.6.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@forge/api": "^6.4.0-next.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://packages.atlassian.com/api/npm/npm-public/"
|
|
27
|
+
}
|
|
28
|
+
}
|