@forge/object-store 1.2.1-next.0 → 1.3.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/LICENSE.txt +1 -1
- package/out/__test__/object-store.test.js +66 -0
- package/out/object-store.d.ts +2 -1
- package/out/object-store.d.ts.map +1 -1
- package/out/object-store.js +8 -1
- package/out/types.d.ts +3 -0
- package/out/types.d.ts.map +1 -1
- package/package.json +2 -2
package/LICENSE.txt
CHANGED
|
@@ -227,4 +227,70 @@ describe('ObjectStoreClient', () => {
|
|
|
227
227
|
expect(response).toEqual({ url: 'download-url' });
|
|
228
228
|
});
|
|
229
229
|
});
|
|
230
|
+
describe('createCDNUrl', () => {
|
|
231
|
+
it('should send a POST request with the correct headers and body, and return a URL', async () => {
|
|
232
|
+
const mockResponse = {
|
|
233
|
+
ok: true,
|
|
234
|
+
status: 200,
|
|
235
|
+
text: createMockBody(JSON.stringify({ url: 'cdn-url' }))
|
|
236
|
+
};
|
|
237
|
+
mockFetch.mockResolvedValue(mockResponse);
|
|
238
|
+
const objectId = '1';
|
|
239
|
+
const response = await osClient.createCDNUrl(objectId);
|
|
240
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/cdn-url', {
|
|
241
|
+
method: 'POST',
|
|
242
|
+
redirect: 'follow',
|
|
243
|
+
headers: {
|
|
244
|
+
Accept: 'application/json',
|
|
245
|
+
'Content-Type': 'application/json'
|
|
246
|
+
},
|
|
247
|
+
body: JSON.stringify({ key: objectId })
|
|
248
|
+
});
|
|
249
|
+
expect(mockResponse.status).toBe(200);
|
|
250
|
+
expect(mockResponse.text).toHaveBeenCalled();
|
|
251
|
+
expect(response).toEqual({ url: 'cdn-url' });
|
|
252
|
+
});
|
|
253
|
+
it('should send a POST request with ttlSeconds option and return a URL', async () => {
|
|
254
|
+
const mockResponse = {
|
|
255
|
+
ok: true,
|
|
256
|
+
status: 200,
|
|
257
|
+
text: createMockBody(JSON.stringify({ url: 'cdn-url' }))
|
|
258
|
+
};
|
|
259
|
+
mockFetch.mockResolvedValue(mockResponse);
|
|
260
|
+
const objectId = '1';
|
|
261
|
+
const ttlSeconds = 3600;
|
|
262
|
+
const response = await osClient.createCDNUrl(objectId, { ttlSeconds });
|
|
263
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/cdn-url', {
|
|
264
|
+
method: 'POST',
|
|
265
|
+
redirect: 'follow',
|
|
266
|
+
headers: {
|
|
267
|
+
Accept: 'application/json',
|
|
268
|
+
'Content-Type': 'application/json'
|
|
269
|
+
},
|
|
270
|
+
body: JSON.stringify({ key: objectId, ttlSeconds })
|
|
271
|
+
});
|
|
272
|
+
expect(mockResponse.status).toBe(200);
|
|
273
|
+
expect(mockResponse.text).toHaveBeenCalled();
|
|
274
|
+
expect(response).toEqual({ url: 'cdn-url' });
|
|
275
|
+
});
|
|
276
|
+
it('should return undefined when server returns 404', async () => {
|
|
277
|
+
const mockResponse = {
|
|
278
|
+
ok: false,
|
|
279
|
+
status: 404
|
|
280
|
+
};
|
|
281
|
+
mockFetch.mockResolvedValue(mockResponse);
|
|
282
|
+
const objectId = '1';
|
|
283
|
+
const response = await osClient.createCDNUrl(objectId);
|
|
284
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/cdn-url', {
|
|
285
|
+
method: 'POST',
|
|
286
|
+
redirect: 'follow',
|
|
287
|
+
headers: {
|
|
288
|
+
Accept: 'application/json',
|
|
289
|
+
'Content-Type': 'application/json'
|
|
290
|
+
},
|
|
291
|
+
body: JSON.stringify({ key: objectId })
|
|
292
|
+
});
|
|
293
|
+
expect(response).toBeUndefined();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
230
296
|
});
|
package/out/object-store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateDownloadUrlOptions, DeleteOptions, GetOptions, ObjectReference, PresignedUrlResponse, UploadUrlBody } from './types';
|
|
1
|
+
import { CDNOptions, CreateDownloadUrlOptions, DeleteOptions, GetOptions, ObjectReference, PresignedUrlResponse, UploadUrlBody } from './types';
|
|
2
2
|
export declare class ObjectStoreClient {
|
|
3
3
|
private sendRequest;
|
|
4
4
|
private requestJson;
|
|
@@ -6,6 +6,7 @@ export declare class ObjectStoreClient {
|
|
|
6
6
|
delete(key: string, options?: DeleteOptions): Promise<void>;
|
|
7
7
|
createUploadUrl(body: UploadUrlBody): Promise<PresignedUrlResponse | undefined>;
|
|
8
8
|
createDownloadUrl(key: string, options?: CreateDownloadUrlOptions): Promise<PresignedUrlResponse | undefined>;
|
|
9
|
+
createCDNUrl(key: string, options?: CDNOptions): Promise<PresignedUrlResponse | undefined>;
|
|
9
10
|
}
|
|
10
11
|
export declare const objectStore: ObjectStoreClient;
|
|
11
12
|
//# sourceMappingURL=object-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-store.d.ts","sourceRoot":"","sources":["../src/object-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,aAAa,EACd,MAAM,SAAS,CAAC;AASjB,qBAAa,iBAAiB;YAEd,WAAW;YASX,WAAW;
|
|
1
|
+
{"version":3,"file":"object-store.d.ts","sourceRoot":"","sources":["../src/object-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,aAAa,EACd,MAAM,SAAS,CAAC;AASjB,qBAAa,iBAAiB;YAEd,WAAW;YASX,WAAW;IAoCZ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAkB5E,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAc3D,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAiB/E,iBAAiB,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAkB/B,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;CAYxG;AAED,eAAO,MAAM,WAAW,mBAA0B,CAAC"}
|
package/out/object-store.js
CHANGED
|
@@ -59,11 +59,18 @@ class ObjectStoreClient {
|
|
|
59
59
|
}
|
|
60
60
|
async createDownloadUrl(key, options) {
|
|
61
61
|
const cdn = options?.cdn;
|
|
62
|
-
return this.requestJson(ValidHttpMethod.POST,
|
|
62
|
+
return this.requestJson(ValidHttpMethod.POST, 'api/v1/download-url', {
|
|
63
63
|
Accept: 'application/json',
|
|
64
64
|
'Content-Type': 'application/json'
|
|
65
65
|
}, JSON.stringify({ key, cdn }));
|
|
66
66
|
}
|
|
67
|
+
async createCDNUrl(key, options) {
|
|
68
|
+
const ttlSeconds = options?.ttlSeconds;
|
|
69
|
+
return this.requestJson(ValidHttpMethod.POST, 'api/v1/cdn-url', {
|
|
70
|
+
Accept: 'application/json',
|
|
71
|
+
'Content-Type': 'application/json'
|
|
72
|
+
}, JSON.stringify({ key, ttlSeconds }));
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
exports.ObjectStoreClient = ObjectStoreClient;
|
|
69
76
|
exports.objectStore = new ObjectStoreClient();
|
package/out/types.d.ts
CHANGED
|
@@ -24,4 +24,7 @@ export interface BaseOptions {
|
|
|
24
24
|
export declare type GetOptions = BaseOptions;
|
|
25
25
|
export declare type DeleteOptions = BaseOptions;
|
|
26
26
|
export declare type CreateDownloadUrlOptions = BaseOptions;
|
|
27
|
+
export interface CDNOptions {
|
|
28
|
+
ttlSeconds?: number;
|
|
29
|
+
}
|
|
27
30
|
//# sourceMappingURL=types.d.ts.map
|
package/out/types.d.ts.map
CHANGED
|
@@ -1 +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;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,oBAAY,UAAU,GAAG,WAAW,CAAC;AACrC,oBAAY,aAAa,GAAG,WAAW,CAAC;AACxC,oBAAY,wBAAwB,GAAG,WAAW,CAAC"}
|
|
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;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,oBAAY,UAAU,GAAG,WAAW,CAAC;AACrC,oBAAY,aAAa,GAAG,WAAW,CAAC;AACxC,oBAAY,wBAAwB,GAAG,WAAW,CAAC;AAEnD,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/object-store",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Forge Object Store SDK",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"jest-when": "^3.6.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@forge/api": "^6.4.3
|
|
23
|
+
"@forge/api": "^6.4.3"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"registry": "https://packages.atlassian.com/api/npm/npm-public/"
|