@automate.ax/integration-contracts 0.112.6 → 0.112.7

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.
@@ -2,6 +2,7 @@ import * as z from "zod"
2
2
  import {
3
3
  ASANA_PROVIDER_RESOURCE_SCHEMA,
4
4
  ASANA_RESOURCE_SCHEMA,
5
+ omitAsanaUndefined,
5
6
  toAsanaResource,
6
7
  } from "./base"
7
8
 
@@ -255,16 +256,18 @@ export const ASANA_PROVIDER_JOB_SCHEMA = ASANA_PROVIDER_RESOURCE_SCHEMA.extend({
255
256
  export function toAsanaAttachment(
256
257
  value: z.output<typeof ASANA_PROVIDER_ATTACHMENT_SCHEMA>,
257
258
  ) {
258
- return {
259
- ...toAsanaResource(value),
260
- createdAt: value.created_at,
261
- downloadUrl: value.download_url ?? undefined,
262
- host: value.host,
263
- parent: value.parent ? toAsanaResource(value.parent) : undefined,
264
- permanentUrl: value.permanent_url ?? undefined,
265
- size: value.size ?? undefined,
266
- viewUrl: value.view_url ?? undefined,
267
- }
259
+ return ASANA_ATTACHMENT_SCHEMA.parse(
260
+ omitAsanaUndefined({
261
+ ...toAsanaResource(value),
262
+ createdAt: value.created_at,
263
+ downloadUrl: value.download_url ?? undefined,
264
+ host: value.host,
265
+ parent: value.parent ? toAsanaResource(value.parent) : undefined,
266
+ permanentUrl: value.permanent_url ?? undefined,
267
+ size: value.size ?? undefined,
268
+ viewUrl: value.view_url ?? undefined,
269
+ }),
270
+ )
268
271
  }
269
272
 
270
273
  /**
@@ -273,14 +276,16 @@ export function toAsanaAttachment(
273
276
  * @param value - Provider tag.
274
277
  */
275
278
  export function toAsanaTag(value: z.output<typeof ASANA_PROVIDER_TAG_SCHEMA>) {
276
- return {
277
- ...toAsanaResource(value),
278
- color: value.color ?? undefined,
279
- createdAt: value.created_at,
280
- followers: (value.followers ?? []).map(toAsanaResource),
281
- notes: value.notes,
282
- workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
283
- }
279
+ return ASANA_TAG_SCHEMA.parse(
280
+ omitAsanaUndefined({
281
+ ...toAsanaResource(value),
282
+ color: value.color ?? undefined,
283
+ createdAt: value.created_at,
284
+ followers: (value.followers ?? []).map(toAsanaResource),
285
+ notes: value.notes,
286
+ workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
287
+ }),
288
+ )
284
289
  }
285
290
 
286
291
  /**
@@ -291,15 +296,17 @@ export function toAsanaTag(value: z.output<typeof ASANA_PROVIDER_TAG_SCHEMA>) {
291
296
  export function toAsanaTeam(
292
297
  value: z.output<typeof ASANA_PROVIDER_TEAM_SCHEMA>,
293
298
  ) {
294
- return {
295
- ...toAsanaResource(value),
296
- description: value.description,
297
- htmlDescription: value.html_description,
298
- organization: value.organization
299
- ? toAsanaResource(value.organization)
300
- : undefined,
301
- permalinkUrl: value.permalink_url,
302
- }
299
+ return ASANA_TEAM_SCHEMA.parse(
300
+ omitAsanaUndefined({
301
+ ...toAsanaResource(value),
302
+ description: value.description,
303
+ htmlDescription: value.html_description,
304
+ organization: value.organization
305
+ ? toAsanaResource(value.organization)
306
+ : undefined,
307
+ permalinkUrl: value.permalink_url,
308
+ }),
309
+ )
303
310
  }
304
311
 
305
312
  /**
@@ -310,11 +317,13 @@ export function toAsanaTeam(
310
317
  export function toAsanaEnumOption(
311
318
  value: z.output<typeof ASANA_PROVIDER_ENUM_OPTION_SCHEMA>,
312
319
  ) {
313
- return {
314
- ...toAsanaResource(value),
315
- color: value.color ?? undefined,
316
- enabled: value.enabled,
317
- }
320
+ return ASANA_ENUM_OPTION_SCHEMA.parse(
321
+ omitAsanaUndefined({
322
+ ...toAsanaResource(value),
323
+ color: value.color ?? undefined,
324
+ enabled: value.enabled,
325
+ }),
326
+ )
318
327
  }
319
328
 
320
329
  /**
@@ -325,16 +334,18 @@ export function toAsanaEnumOption(
325
334
  export function toAsanaCustomField(
326
335
  value: z.output<typeof ASANA_PROVIDER_CUSTOM_FIELD_SCHEMA>,
327
336
  ) {
328
- return {
329
- ...toAsanaResource(value),
330
- customLabel: value.custom_label ?? undefined,
331
- currencyCode: value.currency_code ?? undefined,
332
- description: value.description,
333
- enumOptions: (value.enum_options ?? []).map(toAsanaEnumOption),
334
- format: value.format ?? undefined,
335
- precision: value.precision ?? undefined,
336
- subtype: value.resource_subtype,
337
- }
337
+ return ASANA_CUSTOM_FIELD_SCHEMA.parse(
338
+ omitAsanaUndefined({
339
+ ...toAsanaResource(value),
340
+ customLabel: value.custom_label ?? undefined,
341
+ currencyCode: value.currency_code ?? undefined,
342
+ description: value.description,
343
+ enumOptions: (value.enum_options ?? []).map(toAsanaEnumOption),
344
+ format: value.format ?? undefined,
345
+ precision: value.precision ?? undefined,
346
+ subtype: value.resource_subtype,
347
+ }),
348
+ )
338
349
  }
339
350
 
340
351
  /**
@@ -345,24 +356,26 @@ export function toAsanaCustomField(
345
356
  export function toAsanaCustomFieldValue(
346
357
  value: z.output<typeof ASANA_PROVIDER_CUSTOM_FIELD_VALUE_SCHEMA>,
347
358
  ) {
348
- return {
349
- ...toAsanaCustomField(value),
350
- dateValue: value.date_value
351
- ? {
352
- date: value.date_value.date,
353
- dateTime: value.date_value.date_time ?? undefined,
354
- }
355
- : undefined,
356
- displayValue: value.display_value ?? undefined,
357
- enumValue: value.enum_value
358
- ? toAsanaEnumOption(value.enum_value)
359
- : undefined,
360
- multiEnumValues: (value.multi_enum_values ?? []).map(toAsanaEnumOption),
361
- numberValue: value.number_value ?? undefined,
362
- peopleValue: (value.people_value ?? []).map(toAsanaResource),
363
- referenceValue: (value.reference_value ?? []).map(toAsanaResource),
364
- textValue: value.text_value ?? undefined,
365
- }
359
+ return ASANA_CUSTOM_FIELD_VALUE_SCHEMA.parse(
360
+ omitAsanaUndefined({
361
+ ...toAsanaCustomField(value),
362
+ dateValue: value.date_value
363
+ ? {
364
+ date: value.date_value.date,
365
+ dateTime: value.date_value.date_time ?? undefined,
366
+ }
367
+ : undefined,
368
+ displayValue: value.display_value ?? undefined,
369
+ enumValue: value.enum_value
370
+ ? toAsanaEnumOption(value.enum_value)
371
+ : undefined,
372
+ multiEnumValues: (value.multi_enum_values ?? []).map(toAsanaEnumOption),
373
+ numberValue: value.number_value ?? undefined,
374
+ peopleValue: (value.people_value ?? []).map(toAsanaResource),
375
+ referenceValue: (value.reference_value ?? []).map(toAsanaResource),
376
+ textValue: value.text_value ?? undefined,
377
+ }),
378
+ )
366
379
  }
367
380
 
368
381
  /**
@@ -373,14 +386,16 @@ export function toAsanaCustomFieldValue(
373
386
  export function toAsanaProjectTaskCounts(
374
387
  value: z.output<typeof ASANA_PROVIDER_PROJECT_TASK_COUNTS_SCHEMA>,
375
388
  ) {
376
- return {
377
- numCompletedMilestones: value.num_completed_milestones,
378
- numCompletedTasks: value.num_completed_tasks,
379
- numIncompleteMilestones: value.num_incomplete_milestones,
380
- numIncompleteTasks: value.num_incomplete_tasks,
381
- numMilestones: value.num_milestones,
382
- numTasks: value.num_tasks,
383
- }
389
+ return ASANA_PROJECT_TASK_COUNTS_SCHEMA.parse(
390
+ omitAsanaUndefined({
391
+ numCompletedMilestones: value.num_completed_milestones,
392
+ numCompletedTasks: value.num_completed_tasks,
393
+ numIncompleteMilestones: value.num_incomplete_milestones,
394
+ numIncompleteTasks: value.num_incomplete_tasks,
395
+ numMilestones: value.num_milestones,
396
+ numTasks: value.num_tasks,
397
+ }),
398
+ )
384
399
  }
385
400
 
386
401
  /**
@@ -389,13 +404,15 @@ export function toAsanaProjectTaskCounts(
389
404
  * @param value - Provider job.
390
405
  */
391
406
  export function toAsanaJob(value: z.output<typeof ASANA_PROVIDER_JOB_SCHEMA>) {
392
- return {
393
- ...toAsanaResource(value),
394
- newProject: value.new_project
395
- ? toAsanaResource(value.new_project)
396
- : undefined,
397
- newTask: value.new_task ? toAsanaResource(value.new_task) : undefined,
398
- status: value.status,
399
- subtype: value.resource_subtype,
400
- }
407
+ return ASANA_JOB_SCHEMA.parse(
408
+ omitAsanaUndefined({
409
+ ...toAsanaResource(value),
410
+ newProject: value.new_project
411
+ ? toAsanaResource(value.new_project)
412
+ : undefined,
413
+ newTask: value.new_task ? toAsanaResource(value.new_task) : undefined,
414
+ status: value.status,
415
+ subtype: value.resource_subtype,
416
+ }),
417
+ )
401
418
  }
@@ -2,6 +2,7 @@ import * as z from "zod"
2
2
  import {
3
3
  ASANA_PROVIDER_RESOURCE_SCHEMA,
4
4
  ASANA_RESOURCE_SCHEMA,
5
+ omitAsanaUndefined,
5
6
  toAsanaResource,
6
7
  } from "./base"
7
8
  import {
@@ -430,15 +431,17 @@ export const ASANA_PROVIDER_EVENT_SCHEMA = z.looseObject({
430
431
  export function toAsanaWorkspace(
431
432
  value: z.output<typeof ASANA_PROVIDER_WORKSPACE_SCHEMA>,
432
433
  ) {
433
- return {
434
- ...toAsanaResource(value),
435
- ...(value.email_domains !== undefined && {
436
- emailDomains: value.email_domains,
434
+ return ASANA_WORKSPACE_SCHEMA.parse(
435
+ omitAsanaUndefined({
436
+ ...toAsanaResource(value),
437
+ ...(value.email_domains !== undefined && {
438
+ emailDomains: value.email_domains,
439
+ }),
440
+ ...(value.is_organization !== undefined && {
441
+ isOrganization: value.is_organization,
442
+ }),
437
443
  }),
438
- ...(value.is_organization !== undefined && {
439
- isOrganization: value.is_organization,
440
- }),
441
- }
444
+ )
442
445
  }
443
446
 
444
447
  /**
@@ -449,12 +452,14 @@ export function toAsanaWorkspace(
449
452
  export function toAsanaUser(
450
453
  value: z.output<typeof ASANA_PROVIDER_USER_SCHEMA>,
451
454
  ) {
452
- return {
453
- ...toAsanaResource(value),
454
- email: value.email,
455
- photoUrl: value.photo?.image_128x128,
456
- workspaces: value.workspaces.map(toAsanaResource),
457
- }
455
+ return ASANA_USER_SCHEMA.parse(
456
+ omitAsanaUndefined({
457
+ ...toAsanaResource(value),
458
+ email: value.email,
459
+ photoUrl: value.photo?.image_128x128,
460
+ workspaces: value.workspaces.map(toAsanaResource),
461
+ }),
462
+ )
458
463
  }
459
464
 
460
465
  /**
@@ -465,22 +470,24 @@ export function toAsanaUser(
465
470
  export function toAsanaProject(
466
471
  value: z.output<typeof ASANA_PROVIDER_PROJECT_SCHEMA>,
467
472
  ) {
468
- return {
469
- ...toAsanaResource(value),
470
- archived: value.archived,
471
- color: value.color ?? undefined,
472
- createdAt: value.created_at,
473
- defaultView: value.default_view,
474
- dueOn: value.due_on ?? undefined,
475
- htmlNotes: value.html_notes,
476
- modifiedAt: value.modified_at,
477
- notes: value.notes,
478
- permalinkUrl: value.permalink_url,
479
- public: value.public,
480
- startOn: value.start_on ?? undefined,
481
- team: value.team ? toAsanaResource(value.team) : undefined,
482
- workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
483
- }
473
+ return ASANA_PROJECT_SCHEMA.parse(
474
+ omitAsanaUndefined({
475
+ ...toAsanaResource(value),
476
+ archived: value.archived,
477
+ color: value.color ?? undefined,
478
+ createdAt: value.created_at,
479
+ defaultView: value.default_view,
480
+ dueOn: value.due_on ?? undefined,
481
+ htmlNotes: value.html_notes,
482
+ modifiedAt: value.modified_at,
483
+ notes: value.notes,
484
+ permalinkUrl: value.permalink_url,
485
+ public: value.public,
486
+ startOn: value.start_on ?? undefined,
487
+ team: value.team ? toAsanaResource(value.team) : undefined,
488
+ workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
489
+ }),
490
+ )
484
491
  }
485
492
 
486
493
  /**
@@ -491,11 +498,13 @@ export function toAsanaProject(
491
498
  export function toAsanaSection(
492
499
  value: z.output<typeof ASANA_PROVIDER_SECTION_SCHEMA>,
493
500
  ) {
494
- return {
495
- ...toAsanaResource(value),
496
- createdAt: value.created_at,
497
- project: value.project ? toAsanaResource(value.project) : undefined,
498
- }
501
+ return ASANA_SECTION_SCHEMA.parse(
502
+ omitAsanaUndefined({
503
+ ...toAsanaResource(value),
504
+ createdAt: value.created_at,
505
+ project: value.project ? toAsanaResource(value.project) : undefined,
506
+ }),
507
+ )
499
508
  }
500
509
 
501
510
  /**
@@ -506,37 +515,41 @@ export function toAsanaSection(
506
515
  export function toAsanaTask(
507
516
  value: z.output<typeof ASANA_PROVIDER_TASK_SCHEMA>,
508
517
  ) {
509
- return {
510
- ...toAsanaResource(value),
511
- assignee: value.assignee ? toAsanaResource(value.assignee) : undefined,
512
- assigneeStatus: value.assignee_status,
513
- completed: value.completed,
514
- completedAt: value.completed_at ?? undefined,
515
- completedBy: value.completed_by
516
- ? toAsanaResource(value.completed_by)
517
- : undefined,
518
- createdAt: value.created_at,
519
- createdBy: value.created_by ? toAsanaResource(value.created_by) : undefined,
520
- customFields: (value.custom_fields ?? []).map(toAsanaCustomFieldValue),
521
- dueAt: value.due_at ?? undefined,
522
- dueOn: value.due_on ?? undefined,
523
- followers: value.followers.map(toAsanaResource),
524
- htmlNotes: value.html_notes,
525
- memberships: value.memberships.map(({ project, section }) => ({
526
- project: toAsanaResource(project),
527
- section: section ? toAsanaResource(section) : undefined,
528
- })),
529
- modifiedAt: value.modified_at,
530
- notes: value.notes,
531
- parent: value.parent ? toAsanaResource(value.parent) : undefined,
532
- permalinkUrl: value.permalink_url,
533
- projects: value.projects.map(toAsanaResource),
534
- startAt: value.start_at ?? undefined,
535
- startOn: value.start_on ?? undefined,
536
- subtype: value.resource_subtype,
537
- tags: value.tags.map(toAsanaResource),
538
- workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
539
- }
518
+ return ASANA_TASK_SCHEMA.parse(
519
+ omitAsanaUndefined({
520
+ ...toAsanaResource(value),
521
+ assignee: value.assignee ? toAsanaResource(value.assignee) : undefined,
522
+ assigneeStatus: value.assignee_status,
523
+ completed: value.completed,
524
+ completedAt: value.completed_at ?? undefined,
525
+ completedBy: value.completed_by
526
+ ? toAsanaResource(value.completed_by)
527
+ : undefined,
528
+ createdAt: value.created_at,
529
+ createdBy: value.created_by
530
+ ? toAsanaResource(value.created_by)
531
+ : undefined,
532
+ customFields: (value.custom_fields ?? []).map(toAsanaCustomFieldValue),
533
+ dueAt: value.due_at ?? undefined,
534
+ dueOn: value.due_on ?? undefined,
535
+ followers: value.followers.map(toAsanaResource),
536
+ htmlNotes: value.html_notes,
537
+ memberships: value.memberships.map(({ project, section }) => ({
538
+ project: toAsanaResource(project),
539
+ section: section ? toAsanaResource(section) : undefined,
540
+ })),
541
+ modifiedAt: value.modified_at,
542
+ notes: value.notes,
543
+ parent: value.parent ? toAsanaResource(value.parent) : undefined,
544
+ permalinkUrl: value.permalink_url,
545
+ projects: value.projects.map(toAsanaResource),
546
+ startAt: value.start_at ?? undefined,
547
+ startOn: value.start_on ?? undefined,
548
+ subtype: value.resource_subtype,
549
+ tags: value.tags.map(toAsanaResource),
550
+ workspace: value.workspace ? toAsanaResource(value.workspace) : undefined,
551
+ }),
552
+ )
540
553
  }
541
554
 
542
555
  /**
@@ -547,16 +560,20 @@ export function toAsanaTask(
547
560
  export function toAsanaStory(
548
561
  value: z.output<typeof ASANA_PROVIDER_STORY_SCHEMA>,
549
562
  ) {
550
- return {
551
- ...toAsanaResource(value),
552
- createdAt: value.created_at,
553
- createdBy: value.created_by ? toAsanaResource(value.created_by) : undefined,
554
- htmlText: value.html_text,
555
- isEdited: value.is_edited,
556
- isPinned: value.is_pinned,
557
- subtype: value.resource_subtype,
558
- text: value.text,
559
- }
563
+ return ASANA_STORY_SCHEMA.parse(
564
+ omitAsanaUndefined({
565
+ ...toAsanaResource(value),
566
+ createdAt: value.created_at,
567
+ createdBy: value.created_by
568
+ ? toAsanaResource(value.created_by)
569
+ : undefined,
570
+ htmlText: value.html_text,
571
+ isEdited: value.is_edited,
572
+ isPinned: value.is_pinned,
573
+ subtype: value.resource_subtype,
574
+ text: value.text,
575
+ }),
576
+ )
560
577
  }
561
578
 
562
579
  /**
@@ -567,25 +584,27 @@ export function toAsanaStory(
567
584
  */
568
585
  export function normalizeAsanaEvent(value: unknown, watchedResourceId: string) {
569
586
  const event = ASANA_PROVIDER_EVENT_SCHEMA.parse(value)
570
- return ASANA_EVENT_SCHEMA.parse({
571
- action: event.action,
572
- change: event.change
573
- ? {
574
- action: event.change.action,
575
- addedValue: camelCaseAsanaValue(event.change.added_value),
576
- field: camelCaseAsanaKey(event.change.field),
577
- newValue: camelCaseAsanaValue(event.change.new_value),
578
- removedValue: camelCaseAsanaValue(event.change.removed_value),
579
- }
580
- : undefined,
581
- createdAt: event.created_at,
582
- parent: event.parent ? toAsanaResource(event.parent) : undefined,
583
- resource: toAsanaResource(event.resource),
584
- resourceSubtype: event.resource.resource_subtype,
585
- resourceType: event.resource.resource_type ?? event.type,
586
- user: event.user ? toAsanaResource(event.user) : undefined,
587
- watchedResourceId,
588
- })
587
+ return ASANA_EVENT_SCHEMA.parse(
588
+ omitAsanaUndefined({
589
+ action: event.action,
590
+ change: event.change
591
+ ? {
592
+ action: event.change.action,
593
+ addedValue: camelCaseAsanaValue(event.change.added_value),
594
+ field: camelCaseAsanaKey(event.change.field),
595
+ newValue: camelCaseAsanaValue(event.change.new_value),
596
+ removedValue: camelCaseAsanaValue(event.change.removed_value),
597
+ }
598
+ : undefined,
599
+ createdAt: event.created_at,
600
+ parent: event.parent ? toAsanaResource(event.parent) : undefined,
601
+ resource: toAsanaResource(event.resource),
602
+ resourceSubtype: event.resource.resource_subtype,
603
+ resourceType: event.resource.resource_type ?? event.type,
604
+ user: event.user ? toAsanaResource(event.user) : undefined,
605
+ watchedResourceId,
606
+ }),
607
+ )
589
608
  }
590
609
 
591
610
  /**