@kelpie/schemas 0.10.0 → 0.12.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.
Files changed (81) hide show
  1. package/README.md +16 -0
  2. package/dist/account.d.ts +5 -0
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/account.js +2 -0
  5. package/dist/account.js.map +1 -1
  6. package/dist/apiKey.d.ts +5 -0
  7. package/dist/apiKey.d.ts.map +1 -1
  8. package/dist/apiKey.js +8 -1
  9. package/dist/apiKey.js.map +1 -1
  10. package/dist/apiKeyScopes.d.ts +36 -0
  11. package/dist/apiKeyScopes.d.ts.map +1 -0
  12. package/dist/apiKeyScopes.js +217 -0
  13. package/dist/apiKeyScopes.js.map +1 -0
  14. package/dist/conversion.d.ts +58 -0
  15. package/dist/conversion.d.ts.map +1 -0
  16. package/dist/conversion.js +63 -0
  17. package/dist/conversion.js.map +1 -0
  18. package/dist/deal.d.ts +3 -0
  19. package/dist/deal.d.ts.map +1 -1
  20. package/dist/deal.js +5 -0
  21. package/dist/deal.js.map +1 -1
  22. package/dist/enquiry.d.ts +3 -0
  23. package/dist/enquiry.d.ts.map +1 -1
  24. package/dist/enquiry.js +5 -0
  25. package/dist/enquiry.js.map +1 -1
  26. package/dist/form.d.ts.map +1 -1
  27. package/dist/form.js +2 -2
  28. package/dist/form.js.map +1 -1
  29. package/dist/formMapTargets.d.ts +72 -0
  30. package/dist/formMapTargets.d.ts.map +1 -0
  31. package/dist/formMapTargets.js +385 -0
  32. package/dist/formMapTargets.js.map +1 -0
  33. package/dist/importExport.d.ts +14 -1
  34. package/dist/importExport.d.ts.map +1 -1
  35. package/dist/importExport.js +161 -1
  36. package/dist/importExport.js.map +1 -1
  37. package/dist/index.d.ts +8 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +4 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/list.d.ts +0 -10
  42. package/dist/list.d.ts.map +1 -1
  43. package/dist/list.js +0 -6
  44. package/dist/list.js.map +1 -1
  45. package/dist/opportunity.d.ts +3 -0
  46. package/dist/opportunity.d.ts.map +1 -1
  47. package/dist/opportunity.js +5 -0
  48. package/dist/opportunity.js.map +1 -1
  49. package/dist/partnership.d.ts +3 -0
  50. package/dist/partnership.d.ts.map +1 -1
  51. package/dist/partnership.js +5 -0
  52. package/dist/partnership.js.map +1 -1
  53. package/dist/raise.d.ts +3 -0
  54. package/dist/raise.d.ts.map +1 -1
  55. package/dist/raise.js +5 -0
  56. package/dist/raise.js.map +1 -1
  57. package/dist/session.d.ts +1 -11
  58. package/dist/session.d.ts.map +1 -1
  59. package/dist/session.js +0 -6
  60. package/dist/session.js.map +1 -1
  61. package/dist/values.d.ts +4 -3
  62. package/dist/values.d.ts.map +1 -1
  63. package/dist/values.js +2 -0
  64. package/dist/values.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/account.ts +7 -0
  67. package/src/apiKey.ts +13 -1
  68. package/src/apiKeyScopes.ts +264 -0
  69. package/src/conversion.ts +99 -0
  70. package/src/deal.ts +9 -0
  71. package/src/enquiry.ts +9 -0
  72. package/src/form.ts +1 -2
  73. package/src/formMapTargets.ts +548 -0
  74. package/src/importExport.ts +174 -1
  75. package/src/index.ts +61 -0
  76. package/src/list.ts +0 -16
  77. package/src/opportunity.ts +9 -0
  78. package/src/partnership.ts +9 -0
  79. package/src/raise.ts +9 -0
  80. package/src/session.ts +1 -17
  81. package/src/values.ts +7 -2
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod'
2
+
3
+ import { PIPELINE_KINDS } from './values.ts'
4
+ import type { PipelineKind } from './values.ts'
5
+ import { idSchema } from './wire.ts'
6
+
7
+ /** Where a pipeline record was converted to. Set once; read-only on the wire. */
8
+ export interface ConvertedTo {
9
+ readonly targetType: PipelineKind
10
+ readonly targetId: string
11
+ }
12
+
13
+ export const convertedToSchema: z.ZodType<ConvertedTo, unknown> = z
14
+ .object({
15
+ target_type: z.enum(PIPELINE_KINDS),
16
+ target_id: idSchema,
17
+ })
18
+ .transform(
19
+ (wire): ConvertedTo => ({
20
+ targetType: wire.target_type,
21
+ targetId: wire.target_id,
22
+ }),
23
+ )
24
+
25
+ export const convertedToWireSchema = z
26
+ .object({
27
+ target_type: z.enum(PIPELINE_KINDS),
28
+ target_id: idSchema,
29
+ })
30
+ .nullable()
31
+
32
+ /** Body for `POST /v1/{pipeline}/:id/convert`. */
33
+ export interface ConvertPipelineRecordInput {
34
+ readonly targetType: PipelineKind
35
+ readonly stageId?: string | undefined
36
+ readonly companyId?: string | undefined
37
+ readonly kind?: string | undefined
38
+ readonly name?: string | undefined
39
+ }
40
+
41
+ export const convertPipelineRecordBody = z.strictObject({
42
+ target_type: z.enum(PIPELINE_KINDS),
43
+ stage_id: idSchema.optional(),
44
+ company_id: idSchema.optional(),
45
+ kind: z.string().optional(),
46
+ name: z.string().min(1).optional(),
47
+ })
48
+
49
+ /** Enquiry convert accepts an empty body and defaults the target to a deal. */
50
+ export const convertEnquiryBody = z.strictObject({
51
+ target_type: z.enum(PIPELINE_KINDS).default('deal'),
52
+ stage_id: idSchema.optional(),
53
+ company_id: idSchema.optional(),
54
+ kind: z.string().optional(),
55
+ name: z.string().min(1).optional(),
56
+ })
57
+
58
+ export function convertPipelineRecordRequest(
59
+ input: ConvertPipelineRecordInput,
60
+ ): Record<string, unknown> {
61
+ return {
62
+ target_type: input.targetType,
63
+ ...(input.stageId === undefined ? {} : { stage_id: input.stageId }),
64
+ ...(input.companyId === undefined ? {} : { company_id: input.companyId }),
65
+ ...(input.kind === undefined ? {} : { kind: input.kind }),
66
+ ...(input.name === undefined ? {} : { name: input.name }),
67
+ }
68
+ }
69
+
70
+ /** Builds the wire `converted_to` object from stored columns. */
71
+ export function convertedToForWire(
72
+ convertedTargetType: string | null,
73
+ convertedTargetId: string | null,
74
+ ): ConvertedTo | null {
75
+ if (convertedTargetType === null || convertedTargetId === null) {
76
+ return null
77
+ }
78
+
79
+ return {
80
+ targetType: convertedTargetType as PipelineKind,
81
+ targetId: convertedTargetId,
82
+ }
83
+ }
84
+
85
+ export function convertedToResponse(
86
+ convertedTargetType: string | null,
87
+ convertedTargetId: string | null,
88
+ ): Record<string, unknown> | null {
89
+ const converted = convertedToForWire(convertedTargetType, convertedTargetId)
90
+
91
+ if (converted === null) {
92
+ return null
93
+ }
94
+
95
+ return {
96
+ target_type: converted.targetType,
97
+ target_id: converted.targetId,
98
+ }
99
+ }
package/src/deal.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod'
2
2
 
3
+ import { convertedToWireSchema } from './conversion.ts'
4
+ import type { ConvertedTo } from './conversion.ts'
3
5
  import { customFieldValuesBody, customFieldValuesSchema } from './customField.ts'
4
6
  import type { CustomFieldValue, CustomFieldValues } from './customField.ts'
5
7
  import { definedFields, idSchema, recordTimestamps } from './wire.ts'
@@ -24,6 +26,8 @@ export interface Deal extends RecordTimestamps {
24
26
  readonly summary: string
25
27
  readonly tags: readonly string[]
26
28
  readonly externalId: string | null
29
+ /** Non-null once this record has been converted to another pipeline type. */
30
+ readonly convertedTo: ConvertedTo | null
27
31
  /** Workspace-defined fields, keyed by definition key. Always present (default `{}`). */
28
32
  readonly customFields: CustomFieldValues
29
33
  }
@@ -45,6 +49,7 @@ export const dealSchema: z.ZodType<Deal, unknown> = z
45
49
  summary: z.string(),
46
50
  tags: z.array(z.string()),
47
51
  external_id: z.string().nullable(),
52
+ converted_to: convertedToWireSchema,
48
53
  custom_fields: customFieldValuesSchema,
49
54
  ...recordTimestamps,
50
55
  })
@@ -65,6 +70,10 @@ export const dealSchema: z.ZodType<Deal, unknown> = z
65
70
  summary: wire.summary,
66
71
  tags: wire.tags,
67
72
  externalId: wire.external_id,
73
+ convertedTo:
74
+ wire.converted_to === null
75
+ ? null
76
+ : { targetType: wire.converted_to.target_type, targetId: wire.converted_to.target_id },
68
77
  customFields: wire.custom_fields,
69
78
  createdAt: wire.created_at,
70
79
  updatedAt: wire.updated_at,
package/src/enquiry.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod'
2
2
 
3
+ import { convertedToWireSchema } from './conversion.ts'
4
+ import type { ConvertedTo } from './conversion.ts'
3
5
  import { customFieldValuesBody, customFieldValuesSchema } from './customField.ts'
4
6
  import type { CustomFieldValue, CustomFieldValues } from './customField.ts'
5
7
  import { definedFields, idSchema, recordTimestamps } from './wire.ts'
@@ -18,6 +20,8 @@ export interface Enquiry extends RecordTimestamps {
18
20
  readonly ownerId: string | null
19
21
  /** Non-null once the enquiry has been converted to a Deal; nulled if that deal is deleted. */
20
22
  readonly convertedDealId: string | null
23
+ /** Non-null once this record has been converted to another pipeline type. */
24
+ readonly convertedTo: ConvertedTo | null
21
25
  readonly personIds: readonly string[]
22
26
  readonly summary: string
23
27
  readonly tags: readonly string[]
@@ -34,6 +38,7 @@ export const enquirySchema: z.ZodType<Enquiry, unknown> = z
34
38
  company_id: idSchema.nullable(),
35
39
  owner_id: idSchema.nullable(),
36
40
  converted_deal_id: idSchema.nullable(),
41
+ converted_to: convertedToWireSchema,
37
42
  person_ids: z.array(idSchema),
38
43
  summary: z.string(),
39
44
  tags: z.array(z.string()),
@@ -49,6 +54,10 @@ export const enquirySchema: z.ZodType<Enquiry, unknown> = z
49
54
  companyId: wire.company_id,
50
55
  ownerId: wire.owner_id,
51
56
  convertedDealId: wire.converted_deal_id,
57
+ convertedTo:
58
+ wire.converted_to === null
59
+ ? null
60
+ : { targetType: wire.converted_to.target_type, targetId: wire.converted_to.target_id },
52
61
  personIds: wire.person_ids,
53
62
  summary: wire.summary,
54
63
  tags: wire.tags,
package/src/form.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod'
2
2
 
3
3
  import {
4
- FORM_FIELD_MAP_TARGETS,
5
4
  FORM_FIELD_TYPES,
6
5
  FORM_OPTION_VALUE_TYPES,
7
6
  FORM_STATUSES,
@@ -156,7 +155,7 @@ const formFieldSchema = z
156
155
  label: z.string(),
157
156
  type: z.enum(FORM_FIELD_TYPES),
158
157
  required: z.boolean(),
159
- map_to: z.enum(FORM_FIELD_MAP_TARGETS),
158
+ map_to: z.string().min(1),
160
159
  options: z.array(formFieldOptionSchema),
161
160
  placeholder: z.string().nullable(),
162
161
  statement: z.string().nullable(),