@forge/os 1.1.0 → 1.1.2-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/out/__test__/os.test.js +22 -29
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/os.d.ts +5 -5
- package/out/os.d.ts.map +1 -1
- package/out/os.js +36 -35
- package/out/types.d.ts +11 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +2 -0
- package/package.json +2 -2
package/out/__test__/os.test.js
CHANGED
|
@@ -42,14 +42,11 @@ describe('ObjectStoreClient', () => {
|
|
|
42
42
|
const path = 'api/v1/objects/1';
|
|
43
43
|
const response = await osClient['sendRequest'](path);
|
|
44
44
|
expect(mockFetch).toHaveBeenCalledWith(path, {
|
|
45
|
-
redirect: 'follow'
|
|
46
|
-
headers: {
|
|
47
|
-
...DEFAULT_HEADERS
|
|
48
|
-
}
|
|
45
|
+
redirect: 'follow'
|
|
49
46
|
});
|
|
50
47
|
expect(response).toBe(mockResponse);
|
|
51
48
|
});
|
|
52
|
-
it('should handle requests that
|
|
49
|
+
it('should handle requests that set headers', async () => {
|
|
53
50
|
const mockResponse = { ok: true, status: 200 };
|
|
54
51
|
mockFetch.mockResolvedValue(mockResponse);
|
|
55
52
|
const path = 'api/v1/objects/1';
|
|
@@ -59,47 +56,44 @@ describe('ObjectStoreClient', () => {
|
|
|
59
56
|
redirect: 'follow',
|
|
60
57
|
method: 'GET',
|
|
61
58
|
headers: {
|
|
62
|
-
...DEFAULT_HEADERS,
|
|
63
59
|
'Content-Type': 'application/octet-stream'
|
|
64
60
|
}
|
|
65
61
|
});
|
|
66
62
|
expect(response).toBe(mockResponse);
|
|
67
63
|
});
|
|
68
64
|
});
|
|
69
|
-
describe('
|
|
70
|
-
it('should send a
|
|
71
|
-
const mockResponse = {
|
|
72
|
-
ok: true,
|
|
73
|
-
status: 200,
|
|
74
|
-
text: createMockBody(JSON.stringify({ message: 'Blåhaj' }))
|
|
75
|
-
};
|
|
65
|
+
describe('put', () => {
|
|
66
|
+
it('should send a PUT request with the correct headers and body', async () => {
|
|
67
|
+
const mockResponse = { ok: true, status: 201, text: createMockBody(null) };
|
|
76
68
|
mockFetch.mockResolvedValue(mockResponse);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
const objectId = '1';
|
|
70
|
+
const buffer = Buffer.from('hello world');
|
|
71
|
+
await osClient.put(objectId, buffer);
|
|
72
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/objects/1', {
|
|
73
|
+
method: 'PUT',
|
|
80
74
|
redirect: 'follow',
|
|
81
75
|
headers: {
|
|
82
|
-
...DEFAULT_HEADERS
|
|
83
|
-
|
|
76
|
+
...DEFAULT_HEADERS,
|
|
77
|
+
'Content-Type': 'application/octet-stream'
|
|
78
|
+
},
|
|
79
|
+
body: buffer
|
|
84
80
|
});
|
|
85
|
-
expect(mockResponse.status).toBe(
|
|
81
|
+
expect(mockResponse.status).toBe(201);
|
|
86
82
|
expect(mockResponse.text).toHaveBeenCalled();
|
|
87
|
-
expect(response).toEqual({ message: 'Blåhaj' });
|
|
88
83
|
});
|
|
89
|
-
|
|
90
|
-
describe('put', () => {
|
|
91
|
-
it('should send a PUT request with the correct headers and body', async () => {
|
|
84
|
+
it('should send a PUT request with the ttl headers and body', async () => {
|
|
92
85
|
const mockResponse = { ok: true, status: 201, text: createMockBody(null) };
|
|
93
86
|
mockFetch.mockResolvedValue(mockResponse);
|
|
94
87
|
const objectId = '1';
|
|
95
88
|
const buffer = Buffer.from('hello world');
|
|
96
|
-
await osClient.put(objectId, buffer);
|
|
89
|
+
await osClient.put(objectId, buffer, 100);
|
|
97
90
|
expect(mockFetch).toHaveBeenCalledWith('api/v1/objects/1', {
|
|
98
91
|
method: 'PUT',
|
|
99
92
|
redirect: 'follow',
|
|
100
93
|
headers: {
|
|
101
94
|
...DEFAULT_HEADERS,
|
|
102
|
-
'Content-Type': 'application/octet-stream'
|
|
95
|
+
'Content-Type': 'application/octet-stream',
|
|
96
|
+
'ttl-seconds': '100'
|
|
103
97
|
},
|
|
104
98
|
body: buffer
|
|
105
99
|
});
|
|
@@ -121,7 +115,7 @@ describe('ObjectStoreClient', () => {
|
|
|
121
115
|
method: 'GET',
|
|
122
116
|
redirect: 'follow',
|
|
123
117
|
headers: {
|
|
124
|
-
|
|
118
|
+
Accept: 'application/json'
|
|
125
119
|
}
|
|
126
120
|
});
|
|
127
121
|
expect(mockResponse.status).toBe(200);
|
|
@@ -139,7 +133,7 @@ describe('ObjectStoreClient', () => {
|
|
|
139
133
|
method: 'DELETE',
|
|
140
134
|
redirect: 'follow',
|
|
141
135
|
headers: {
|
|
142
|
-
|
|
136
|
+
Accept: 'application/json'
|
|
143
137
|
}
|
|
144
138
|
});
|
|
145
139
|
expect(mockResponse.status).toBe(204);
|
|
@@ -156,11 +150,10 @@ describe('ObjectStoreClient', () => {
|
|
|
156
150
|
mockFetch.mockResolvedValue(mockResponse);
|
|
157
151
|
const objectId = '1';
|
|
158
152
|
const response = await osClient.download(objectId);
|
|
159
|
-
expect(mockFetch).toHaveBeenCalledWith('api/v1/objects/1', {
|
|
153
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/objects/1/download', {
|
|
160
154
|
method: 'GET',
|
|
161
155
|
redirect: 'follow',
|
|
162
156
|
headers: {
|
|
163
|
-
...DEFAULT_HEADERS,
|
|
164
157
|
Accept: 'application/octet-stream'
|
|
165
158
|
}
|
|
166
159
|
});
|
package/out/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { os } from './os';
|
|
2
2
|
import { errorCodes } from './errorCodes';
|
|
3
3
|
import { ForgeError } from './errors';
|
|
4
|
-
|
|
4
|
+
import { ObjectReference, VersionsList } from './types';
|
|
5
|
+
export { errorCodes, os, ForgeError, ObjectReference, VersionsList };
|
|
5
6
|
export default os;
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AAErE,eAAe,EAAE,CAAC"}
|
package/out/os.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { ObjectReference, VersionsList } from './types';
|
|
2
3
|
export declare class ObjectStoreClient {
|
|
3
4
|
private sendRequest;
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get<DataType>(objectId: string): Promise<DataType | null>;
|
|
5
|
+
private requestJson;
|
|
6
|
+
put(objectId: string, buffer: Buffer, ttlSeconds?: number): Promise<ObjectReference | null>;
|
|
7
|
+
get(objectId: string): Promise<ObjectReference | null>;
|
|
8
8
|
delete(objectId: string): Promise<void>;
|
|
9
|
-
listVersions(objectId: string): Promise<
|
|
9
|
+
listVersions(objectId: string): Promise<VersionsList | null>;
|
|
10
10
|
download(objectId: string): Promise<Buffer | null>;
|
|
11
11
|
}
|
|
12
12
|
export declare const os: ObjectStoreClient;
|
package/out/os.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQxD,qBAAa,iBAAiB;YAEd,WAAW;YASX,WAAW;IAqCZ,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAa3F,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAUtD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAU5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAehE;AAED,eAAO,MAAM,EAAE,mBAA0B,CAAC"}
|
package/out/os.js
CHANGED
|
@@ -10,67 +10,68 @@ var ValidHttpMethod;
|
|
|
10
10
|
ValidHttpMethod["GET"] = "GET";
|
|
11
11
|
ValidHttpMethod["DELETE"] = "DELETE";
|
|
12
12
|
})(ValidHttpMethod || (ValidHttpMethod = {}));
|
|
13
|
-
const DEFAULT_HEADERS = {
|
|
14
|
-
Accept: 'application/json',
|
|
15
|
-
'Content-Type': 'application/json'
|
|
16
|
-
};
|
|
17
13
|
class ObjectStoreClient {
|
|
18
14
|
async sendRequest(path, options) {
|
|
19
15
|
return await (0, api_1.__fetchProduct)({ provider: 'app', remote: 'os' })(path, {
|
|
20
16
|
...options,
|
|
21
17
|
redirect: 'follow',
|
|
22
|
-
headers:
|
|
23
|
-
...DEFAULT_HEADERS,
|
|
24
|
-
...options?.headers
|
|
25
|
-
}
|
|
18
|
+
headers: options?.headers
|
|
26
19
|
});
|
|
27
20
|
}
|
|
28
|
-
async
|
|
21
|
+
async requestJson(method, path, headers, body) {
|
|
29
22
|
const response = await this.sendRequest(path, {
|
|
30
23
|
method,
|
|
31
24
|
headers,
|
|
32
25
|
body
|
|
33
26
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return response.arrayBuffer().then((buffer) => Buffer.from(buffer));
|
|
27
|
+
if (response.status === 404) {
|
|
28
|
+
return null;
|
|
37
29
|
}
|
|
30
|
+
await (0, error_handling_1.checkResponseError)(response);
|
|
38
31
|
const responseText = await response.text();
|
|
39
|
-
if (responseText) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
if (!responseText || responseText.trim().length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(responseText);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new errors_1.ForgeObjectStoreError(`Unexpected error. Response was not valid JSON: ${responseText}`);
|
|
46
40
|
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
async echo() {
|
|
50
|
-
return this.storageApi(ValidHttpMethod.GET, `api/v1/echo`, { 'Content-Type': 'application/json' });
|
|
51
41
|
}
|
|
52
|
-
async put(objectId, buffer) {
|
|
42
|
+
async put(objectId, buffer, ttlSeconds) {
|
|
53
43
|
const headers = {
|
|
54
|
-
|
|
55
|
-
'Content-Type': 'application/octet-stream'
|
|
44
|
+
Accept: 'application/json',
|
|
45
|
+
'Content-Type': 'application/octet-stream',
|
|
46
|
+
...(ttlSeconds ? { 'ttl-seconds': ttlSeconds.toString() } : {})
|
|
56
47
|
};
|
|
57
|
-
|
|
48
|
+
return this.requestJson(ValidHttpMethod.PUT, `api/v1/objects/${objectId}`, headers, buffer);
|
|
58
49
|
}
|
|
59
50
|
async get(objectId) {
|
|
60
|
-
return this.
|
|
51
|
+
return this.requestJson(ValidHttpMethod.GET, `api/v1/objects/${objectId}`, {
|
|
52
|
+
Accept: 'application/json'
|
|
53
|
+
});
|
|
61
54
|
}
|
|
62
55
|
async delete(objectId) {
|
|
63
|
-
await this.
|
|
56
|
+
await this.requestJson(ValidHttpMethod.DELETE, `api/v1/objects/${objectId}`, { Accept: 'application/json' });
|
|
64
57
|
}
|
|
65
58
|
async listVersions(objectId) {
|
|
66
|
-
return this.
|
|
59
|
+
return this.requestJson(ValidHttpMethod.GET, `api/v1/objects/${objectId}/versions`, {
|
|
60
|
+
Accept: 'application/json'
|
|
61
|
+
});
|
|
67
62
|
}
|
|
68
63
|
async download(objectId) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
const response = await this.sendRequest(`api/v1/objects/${objectId}/download`, {
|
|
65
|
+
method: ValidHttpMethod.GET,
|
|
66
|
+
headers: {
|
|
67
|
+
Accept: 'application/octet-stream'
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (response.status === 404) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
await (0, error_handling_1.checkResponseError)(response);
|
|
74
|
+
return await response.arrayBuffer().then((buffer) => Buffer.from(buffer));
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
exports.ObjectStoreClient = ObjectStoreClient;
|
package/out/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B"}
|
package/out/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/os",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2-next.1",
|
|
4
4
|
"description": "Forge Object Store SDK",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"jest-when": "^3.6.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@forge/api": "^4.
|
|
25
|
+
"@forge/api": "^4.2.0-next.0"
|
|
26
26
|
}
|
|
27
27
|
}
|