@forge/object-store 1.1.1 → 1.1.2-next.0-experimental-0c74a4b

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.
@@ -87,6 +87,31 @@ describe('ObjectStoreClient', () => {
87
87
  expect(mockResponse.text).toHaveBeenCalled();
88
88
  expect(response).toEqual({ message: 'Blåhaj' });
89
89
  });
90
+ it('should send a POST request with cdn:true option', async () => {
91
+ const mockResponse = {
92
+ ok: true,
93
+ status: 200,
94
+ text: createMockBody(JSON.stringify({ message: 'Blåhaj' }))
95
+ };
96
+ mockFetch.mockResolvedValue(mockResponse);
97
+ const objectId = '1';
98
+ const response = await osClient.get(objectId, { cdn: true });
99
+ expect(mockFetch).toHaveBeenCalledWith('api/v1/metadata', {
100
+ method: 'POST',
101
+ redirect: 'follow',
102
+ headers: {
103
+ Accept: 'application/json',
104
+ 'Content-Type': 'application/json'
105
+ },
106
+ body: JSON.stringify({
107
+ key: objectId,
108
+ cdn: true
109
+ })
110
+ });
111
+ expect(mockResponse.status).toBe(200);
112
+ expect(mockResponse.text).toHaveBeenCalled();
113
+ expect(response).toEqual({ message: 'Blåhaj' });
114
+ });
90
115
  });
91
116
  describe('delete', () => {
92
117
  it('should send a POST request with the correct headers and body', async () => {
@@ -106,6 +131,23 @@ describe('ObjectStoreClient', () => {
106
131
  expect(mockResponse.status).toBe(204);
107
132
  expect(mockResponse.text).toHaveBeenCalled();
108
133
  });
134
+ it('should send a POST request with cdn:true option', async () => {
135
+ const mockResponse = { ok: true, status: 204, text: createMockBody(null) };
136
+ mockFetch.mockResolvedValue(mockResponse);
137
+ const objectId = '1';
138
+ await osClient.delete(objectId, { cdn: true });
139
+ expect(mockFetch).toHaveBeenCalledWith('api/v1/delete', {
140
+ method: 'POST',
141
+ redirect: 'follow',
142
+ headers: {
143
+ Accept: 'application/json',
144
+ 'Content-Type': 'application/json'
145
+ },
146
+ body: JSON.stringify({ key: objectId, cdn: true })
147
+ });
148
+ expect(mockResponse.status).toBe(204);
149
+ expect(mockResponse.text).toHaveBeenCalled();
150
+ });
109
151
  });
110
152
  describe('createUploadUrl', () => {
111
153
  it('should send a POST request with the correct headers and body, and return a URL', async () => {
@@ -162,5 +204,27 @@ describe('ObjectStoreClient', () => {
162
204
  expect(mockResponse.text).toHaveBeenCalled();
163
205
  expect(response).toEqual({ url: 'download-url' });
164
206
  });
207
+ it('should send a POST request with cdn:true option and return a URL', async () => {
208
+ const mockResponse = {
209
+ ok: true,
210
+ status: 200,
211
+ text: createMockBody(JSON.stringify({ url: 'download-url' }))
212
+ };
213
+ mockFetch.mockResolvedValue(mockResponse);
214
+ const objectId = '1';
215
+ const response = await osClient.createDownloadUrl(objectId, { cdn: true });
216
+ expect(mockFetch).toHaveBeenCalledWith('api/v1/download-url', {
217
+ method: 'POST',
218
+ redirect: 'follow',
219
+ headers: {
220
+ Accept: 'application/json',
221
+ 'Content-Type': 'application/json'
222
+ },
223
+ body: JSON.stringify({ key: objectId, cdn: true })
224
+ });
225
+ expect(mockResponse.status).toBe(200);
226
+ expect(mockResponse.text).toHaveBeenCalled();
227
+ expect(response).toEqual({ url: 'download-url' });
228
+ });
165
229
  });
166
230
  });
package/out/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { objectStore } from './object-store';
2
2
  import { errorCodes } from './errorCodes';
3
3
  import { ForgeError } from './errors';
4
- import { ObjectReference, UploadUrlBody, PresignedUrlResponse } from './types';
5
- export { errorCodes, objectStore, ForgeError, ObjectReference, UploadUrlBody, PresignedUrlResponse };
4
+ import { ObjectReference, UploadUrlBody, PresignedUrlResponse, GetOptions, DeleteOptions, CreateDownloadUrlOptions } from './types';
5
+ export { errorCodes, objectStore, ForgeError, ObjectReference, UploadUrlBody, PresignedUrlResponse, GetOptions, DeleteOptions, CreateDownloadUrlOptions };
6
6
  export default objectStore;
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAC;AAErG,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EACL,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,wBAAwB,EACzB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,11 +1,11 @@
1
- import { ObjectReference, PresignedUrlResponse, UploadUrlBody } from './types';
1
+ import { CreateDownloadUrlOptions, DeleteOptions, GetOptions, ObjectReference, PresignedUrlResponse, UploadUrlBody } from './types';
2
2
  export declare class ObjectStoreClient {
3
3
  private sendRequest;
4
4
  private requestJson;
5
- get(key: string): Promise<ObjectReference | undefined>;
6
- delete(key: string): Promise<void>;
5
+ get(key: string, options?: GetOptions): Promise<ObjectReference | undefined>;
6
+ delete(key: string, options?: DeleteOptions): Promise<void>;
7
7
  createUploadUrl(body: UploadUrlBody): Promise<PresignedUrlResponse | undefined>;
8
- createDownloadUrl(key: string): Promise<PresignedUrlResponse | undefined>;
8
+ createDownloadUrl(key: string, options?: CreateDownloadUrlOptions): Promise<PresignedUrlResponse | undefined>;
9
9
  }
10
10
  export declare const objectStore: ObjectStoreClient;
11
11
  //# 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,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS/E,qBAAa,iBAAiB;YAEd,WAAW;YASX,WAAW;IAmCZ,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAgBtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAalC,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAgB/E,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;CAWvF;AAED,eAAO,MAAM,WAAW,mBAA0B,CAAC"}
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;IAmCZ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAiB5E,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;IAgB/E,iBAAiB,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;CAY7C;AAED,eAAO,MAAM,WAAW,mBAA0B,CAAC"}
@@ -40,14 +40,16 @@ class ObjectStoreClient {
40
40
  throw new errors_1.ForgeObjectStoreError(`Unexpected error. Response was not valid JSON: ${responseText}`);
41
41
  }
42
42
  }
43
- async get(key) {
43
+ async get(key, options) {
44
+ const cdn = options?.cdn;
44
45
  return this.requestJson(ValidHttpMethod.POST, `api/v1/metadata`, {
45
46
  Accept: 'application/json',
46
47
  'Content-Type': 'application/json'
47
- }, JSON.stringify({ key }));
48
+ }, JSON.stringify({ key, cdn }));
48
49
  }
49
- async delete(key) {
50
- return this.requestJson(ValidHttpMethod.POST, `api/v1/delete`, { Accept: 'application/json', 'Content-Type': 'application/json' }, JSON.stringify({ key }));
50
+ async delete(key, options) {
51
+ const cdn = options?.cdn;
52
+ return this.requestJson(ValidHttpMethod.POST, `api/v1/delete`, { Accept: 'application/json', 'Content-Type': 'application/json' }, JSON.stringify({ key, cdn }));
51
53
  }
52
54
  async createUploadUrl(body) {
53
55
  return this.requestJson(ValidHttpMethod.POST, 'api/v1/upload-url', {
@@ -55,11 +57,12 @@ class ObjectStoreClient {
55
57
  'Content-Type': 'application/json'
56
58
  }, JSON.stringify(body));
57
59
  }
58
- async createDownloadUrl(key) {
60
+ async createDownloadUrl(key, options) {
61
+ const cdn = options?.cdn;
59
62
  return this.requestJson(ValidHttpMethod.POST, `api/v1/download-url`, {
60
63
  Accept: 'application/json',
61
64
  'Content-Type': 'application/json'
62
- }, JSON.stringify({ key }));
65
+ }, JSON.stringify({ key, cdn }));
63
66
  }
64
67
  }
65
68
  exports.ObjectStoreClient = ObjectStoreClient;
package/out/types.d.ts CHANGED
@@ -13,8 +13,15 @@ export interface UploadUrlBody {
13
13
  checksumType: 'SHA1' | 'SHA256' | 'CRC32' | 'CRC32C';
14
14
  ttlSeconds?: number;
15
15
  overwrite?: boolean;
16
+ cdn?: boolean;
16
17
  }
17
18
  export interface PresignedUrlResponse {
18
19
  url: string;
19
20
  }
21
+ export interface BaseOptions {
22
+ cdn?: boolean;
23
+ }
24
+ export declare type GetOptions = BaseOptions;
25
+ export declare type DeleteOptions = BaseOptions;
26
+ export declare type CreateDownloadUrlOptions = BaseOptions;
20
27
  //# sourceMappingURL=types.d.ts.map
@@ -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;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;CACb"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/object-store",
3
- "version": "1.1.1",
3
+ "version": "1.1.2-next.0-experimental-0c74a4b",
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.1"
23
+ "@forge/api": "^6.4.2-next.0-experimental-0c74a4b"
24
24
  },
25
25
  "publishConfig": {
26
26
  "registry": "https://packages.atlassian.com/api/npm/npm-public/"