Skip to content

Commit 2e8ba7c

Browse files
authored
fix(storeurl): support for workflows to storeURL (#406)
* fix(storeurl): support for workflows to storeURL * fix(storeurl): add support workflow to StoreUrl * fix(storeurl): check workflowId exist * fix(storeurl): storeUrl - add workflow * test(storeurl): storeUrl - add test
1 parent 5aa3765 commit 2e8ba7c

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/lib/api/store.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const mockedSession: Session = {
3131
urls: config.urls,
3232
};
3333

34+
const workflowIds = ['123', '321'];
35+
3436
const storeTaskDef = [{ name: 'store', params: {} }];
37+
const storeTaskDefWithWorkflows = [{ name: 'store', params: {} }];
3538
const sourceToStore = 'urlToStore';
3639

3740
describe('StoreURL', () => {
@@ -157,4 +160,18 @@ describe('StoreURL', () => {
157160
})).rejects.toEqual(expect.any(FilestackError));
158161
});
159162

163+
it('should be able to run storeUrl with workflows', async () => {
164+
await storeURL({
165+
session: mockedSession,
166+
url: sourceToStore,
167+
workflowIds,
168+
});
169+
170+
expect(FsRequest.post).toHaveBeenCalledWith(`${mockedSession.urls.processUrl}/process`, {
171+
apikey: mockedSession.apikey,
172+
sources: [ sourceToStore ],
173+
tasks: storeTaskDefWithWorkflows,
174+
}, {});
175+
});
176+
160177
});

src/lib/api/store.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type StoreUrlParams = {
3030
security?: Security;
3131
uploadTags?: UploadTags;
3232
headers?: {[key: string]: string},
33+
workflowIds?: string[]
3334
};
3435

3536
/**
@@ -41,6 +42,7 @@ export type StoreUrlParams = {
4142
* @param token
4243
* @param security
4344
* @param uploadTags
45+
* @param workflowIds
4446
*/
4547
export const storeURL = ({
4648
session,
@@ -50,6 +52,7 @@ export const storeURL = ({
5052
security,
5153
uploadTags,
5254
headers,
55+
workflowIds,
5356
}: StoreUrlParams): Promise<any> => {
5457
if (!url || typeof url !== 'string') {
5558
return Promise.reject(new FilestackError('url is required for storeURL'));
@@ -91,6 +94,10 @@ export const storeURL = ({
9194
}];
9295
}
9396

97+
if (workflowIds && workflowIds.length > 0) {
98+
filelink.addTask('store', { workflows: workflowIds });
99+
}
100+
94101
return FsRequest.post(`${session.urls.processUrl}/process`, {
95102
apikey: session.apikey,
96103
sources,

src/lib/client.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ describe('client', () => {
145145
const options = {};
146146
const token = {};
147147
const uploadTags = { test: '123' };
148-
await client.storeURL(url, options, token, defaultSecurity, uploadTags);
148+
const headers = { 'test': '123' };
149+
const workflowIds = ['123', '321'];
150+
await client.storeURL(url, options, token, defaultSecurity, uploadTags,headers, workflowIds);
149151

150152
expect(storeURL).toHaveBeenCalledWith({
151153
session: defaultSession,
@@ -154,6 +156,8 @@ describe('client', () => {
154156
token,
155157
security: defaultSecurity,
156158
uploadTags,
159+
headers,
160+
workflowIds,
157161
});
158162
});
159163

src/lib/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ export class Client extends EventEmitter {
310310
* @param security Optional security override.
311311
* @param uploadTags Optional tags visible in webhooks.
312312
* @param headers Optional headers to send
313+
* @param workflowIds Optional workflowIds to send
313314
*/
314-
storeURL(url: string, storeParams?: StoreParams, token?: any, security?: Security, uploadTags?: UploadTags, headers?: {[key: string]: string}): Promise<Object> {
315+
storeURL(url: string, storeParams?: StoreParams, token?: any, security?: Security, uploadTags?: UploadTags, headers?: {[key: string]: string}, workflowIds?: string[]): Promise<Object> {
315316
return storeURL({
316317
session: this.session,
317318
url,
@@ -320,6 +321,7 @@ export class Client extends EventEmitter {
320321
security,
321322
uploadTags,
322323
headers,
324+
workflowIds,
323325
});
324326
}
325327

0 commit comments

Comments
 (0)