@zapier/zapier-sdk 0.13.6 → 0.13.8

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 (155) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +5 -5
  4. package/dist/api/client.test.d.ts +2 -0
  5. package/dist/api/client.test.d.ts.map +1 -0
  6. package/dist/api/client.test.js +80 -0
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/index.js +3 -1
  10. package/dist/api/schemas.d.ts +20 -20
  11. package/dist/api/types.d.ts +2 -0
  12. package/dist/api/types.d.ts.map +1 -1
  13. package/dist/auth.d.ts +3 -0
  14. package/dist/auth.d.ts.map +1 -1
  15. package/dist/auth.test.d.ts +2 -0
  16. package/dist/auth.test.d.ts.map +1 -0
  17. package/dist/auth.test.js +102 -0
  18. package/dist/constants.d.ts +4 -4
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +4 -4
  21. package/dist/index.cjs +89 -21
  22. package/dist/index.d.mts +21 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/index.mjs +88 -22
  27. package/dist/plugins/api/index.d.ts.map +1 -1
  28. package/dist/plugins/api/index.js +4 -1
  29. package/dist/plugins/eventEmission/index.d.ts +2 -0
  30. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  31. package/dist/plugins/eventEmission/index.js +35 -9
  32. package/dist/plugins/eventEmission/index.test.js +100 -0
  33. package/dist/schemas/Action.d.ts +2 -2
  34. package/dist/schemas/Auth.d.ts +4 -4
  35. package/dist/schemas/Field.d.ts +10 -10
  36. package/dist/sdk.test.js +121 -1
  37. package/dist/types/sdk.d.ts +3 -0
  38. package/dist/types/sdk.d.ts.map +1 -1
  39. package/dist/utils/url-utils.d.ts +19 -0
  40. package/dist/utils/url-utils.d.ts.map +1 -0
  41. package/dist/utils/url-utils.js +62 -0
  42. package/dist/utils/url-utils.test.d.ts +2 -0
  43. package/dist/utils/url-utils.test.d.ts.map +1 -0
  44. package/dist/utils/url-utils.test.js +103 -0
  45. package/package.json +8 -3
  46. package/src/api/auth.ts +0 -28
  47. package/src/api/client.ts +0 -491
  48. package/src/api/debug.test.ts +0 -76
  49. package/src/api/debug.ts +0 -154
  50. package/src/api/index.ts +0 -90
  51. package/src/api/polling.test.ts +0 -405
  52. package/src/api/polling.ts +0 -253
  53. package/src/api/schemas.ts +0 -465
  54. package/src/api/types.ts +0 -152
  55. package/src/auth.ts +0 -72
  56. package/src/constants.ts +0 -16
  57. package/src/index.ts +0 -111
  58. package/src/plugins/api/index.ts +0 -43
  59. package/src/plugins/apps/index.ts +0 -203
  60. package/src/plugins/apps/schemas.ts +0 -64
  61. package/src/plugins/eventEmission/builders.ts +0 -115
  62. package/src/plugins/eventEmission/index.test.ts +0 -169
  63. package/src/plugins/eventEmission/index.ts +0 -294
  64. package/src/plugins/eventEmission/transport.test.ts +0 -214
  65. package/src/plugins/eventEmission/transport.ts +0 -135
  66. package/src/plugins/eventEmission/types.ts +0 -58
  67. package/src/plugins/eventEmission/utils.ts +0 -121
  68. package/src/plugins/fetch/index.ts +0 -83
  69. package/src/plugins/fetch/schemas.ts +0 -37
  70. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  71. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  72. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  73. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  74. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  75. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  76. package/src/plugins/getAction/index.test.ts +0 -239
  77. package/src/plugins/getAction/index.ts +0 -75
  78. package/src/plugins/getAction/schemas.ts +0 -41
  79. package/src/plugins/getApp/index.test.ts +0 -181
  80. package/src/plugins/getApp/index.ts +0 -60
  81. package/src/plugins/getApp/schemas.ts +0 -33
  82. package/src/plugins/getAuthentication/index.test.ts +0 -294
  83. package/src/plugins/getAuthentication/index.ts +0 -95
  84. package/src/plugins/getAuthentication/schemas.ts +0 -38
  85. package/src/plugins/getProfile/index.ts +0 -60
  86. package/src/plugins/getProfile/schemas.ts +0 -24
  87. package/src/plugins/listActions/index.test.ts +0 -526
  88. package/src/plugins/listActions/index.ts +0 -132
  89. package/src/plugins/listActions/schemas.ts +0 -55
  90. package/src/plugins/listApps/index.test.ts +0 -378
  91. package/src/plugins/listApps/index.ts +0 -159
  92. package/src/plugins/listApps/schemas.ts +0 -41
  93. package/src/plugins/listAuthentications/index.test.ts +0 -739
  94. package/src/plugins/listAuthentications/index.ts +0 -152
  95. package/src/plugins/listAuthentications/schemas.ts +0 -77
  96. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  97. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  98. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  99. package/src/plugins/listInputFields/index.test.ts +0 -439
  100. package/src/plugins/listInputFields/index.ts +0 -294
  101. package/src/plugins/listInputFields/schemas.ts +0 -68
  102. package/src/plugins/manifest/index.test.ts +0 -776
  103. package/src/plugins/manifest/index.ts +0 -461
  104. package/src/plugins/manifest/schemas.ts +0 -60
  105. package/src/plugins/registry/index.ts +0 -160
  106. package/src/plugins/request/index.test.ts +0 -333
  107. package/src/plugins/request/index.ts +0 -105
  108. package/src/plugins/request/schemas.ts +0 -69
  109. package/src/plugins/runAction/index.test.ts +0 -388
  110. package/src/plugins/runAction/index.ts +0 -215
  111. package/src/plugins/runAction/schemas.ts +0 -60
  112. package/src/resolvers/actionKey.ts +0 -37
  113. package/src/resolvers/actionType.ts +0 -34
  114. package/src/resolvers/appKey.ts +0 -7
  115. package/src/resolvers/authenticationId.ts +0 -54
  116. package/src/resolvers/index.ts +0 -11
  117. package/src/resolvers/inputFieldKey.ts +0 -70
  118. package/src/resolvers/inputs.ts +0 -69
  119. package/src/schemas/Action.ts +0 -52
  120. package/src/schemas/App.ts +0 -45
  121. package/src/schemas/Auth.ts +0 -59
  122. package/src/schemas/Field.ts +0 -169
  123. package/src/schemas/Run.ts +0 -40
  124. package/src/schemas/UserProfile.ts +0 -60
  125. package/src/sdk.test.ts +0 -212
  126. package/src/sdk.ts +0 -178
  127. package/src/types/domain.test.ts +0 -50
  128. package/src/types/domain.ts +0 -66
  129. package/src/types/errors.ts +0 -278
  130. package/src/types/events.ts +0 -43
  131. package/src/types/functions.ts +0 -28
  132. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  133. package/src/types/plugin.ts +0 -125
  134. package/src/types/properties.ts +0 -80
  135. package/src/types/sdk.ts +0 -111
  136. package/src/types/telemetry-events.ts +0 -85
  137. package/src/utils/array-utils.test.ts +0 -131
  138. package/src/utils/array-utils.ts +0 -41
  139. package/src/utils/domain-utils.test.ts +0 -433
  140. package/src/utils/domain-utils.ts +0 -267
  141. package/src/utils/file-utils.test.ts +0 -73
  142. package/src/utils/file-utils.ts +0 -94
  143. package/src/utils/function-utils.test.ts +0 -141
  144. package/src/utils/function-utils.ts +0 -245
  145. package/src/utils/pagination-utils.test.ts +0 -620
  146. package/src/utils/pagination-utils.ts +0 -242
  147. package/src/utils/schema-utils.ts +0 -207
  148. package/src/utils/string-utils.test.ts +0 -45
  149. package/src/utils/string-utils.ts +0 -54
  150. package/src/utils/validation.test.ts +0 -51
  151. package/src/utils/validation.ts +0 -44
  152. package/tsconfig.build.json +0 -18
  153. package/tsconfig.json +0 -20
  154. package/tsconfig.tsbuildinfo +0 -1
  155. package/tsup.config.ts +0 -23
@@ -1,34 +0,0 @@
1
- import type { DynamicResolver } from "../utils/schema-utils";
2
-
3
- interface ActionTypeItem {
4
- key: string;
5
- name: string;
6
- }
7
-
8
- export const actionTypeResolver: DynamicResolver<
9
- ActionTypeItem,
10
- { appKey: string }
11
- > = {
12
- type: "dynamic",
13
- depends: ["appKey"] as const,
14
- fetch: async (sdk, resolvedParams) => {
15
- const actionsResponse = await sdk.listActions({
16
- appKey: resolvedParams.appKey,
17
- });
18
-
19
- const actionTypes = actionsResponse.data.map(
20
- (action) => action.action_type,
21
- );
22
- const types: string[] = [...new Set(actionTypes)];
23
- return types.map((type) => ({ key: type, name: type }));
24
- },
25
- prompt: (types) => ({
26
- type: "list",
27
- name: "actionType",
28
- message: "Select action type:",
29
- choices: types.map((type) => ({
30
- name: type.name,
31
- value: type.key,
32
- })),
33
- }),
34
- };
@@ -1,7 +0,0 @@
1
- import type { StaticResolver } from "../utils/schema-utils";
2
-
3
- export const appKeyResolver: StaticResolver = {
4
- type: "static",
5
- inputType: "text",
6
- placeholder: "Enter app key (e.g., 'SlackCLIAPI' or slug like 'github')",
7
- };
@@ -1,54 +0,0 @@
1
- import type { DynamicResolver } from "../utils/schema-utils";
2
- import type { AuthItem } from "../schemas/Auth";
3
-
4
- type AuthenticationIdResolver = DynamicResolver<AuthItem, { appKey?: string }>;
5
-
6
- export const authenticationIdResolver: AuthenticationIdResolver = {
7
- type: "dynamic",
8
- depends: ["appKey"] as const,
9
- fetch: async (sdk, resolvedParams) => {
10
- const listOptions: { maxItems: number; appKey?: string } = {
11
- maxItems: 1000,
12
- };
13
-
14
- if (resolvedParams.appKey) {
15
- listOptions.appKey = resolvedParams.appKey;
16
- }
17
-
18
- const myAuths = await sdk.listAuthentications({
19
- ...listOptions,
20
- owner: "me",
21
- });
22
- const allAuths = await sdk.listAuthentications(listOptions);
23
-
24
- // Filter out myAuths from allAuths
25
- const otherAuths = allAuths.data.filter(
26
- (auth: { id: number }) =>
27
- !myAuths.data.some((myAuth: { id: number }) => myAuth.id === auth.id),
28
- );
29
- return [...myAuths.data, ...otherAuths];
30
- },
31
- prompt: (auths, params) => ({
32
- type: "list",
33
- name: "authenticationId",
34
- message: params.appKey
35
- ? `Select authentication for ${params.appKey}:`
36
- : "Select authentication:",
37
- choices: [
38
- ...auths.map((auth) => ({
39
- name: `${auth.title || auth.label || "Authentication"} (ID: ${auth.id})`,
40
- value: auth.id,
41
- })),
42
- {
43
- name: "↗ Skip authentication (may fail)",
44
- value: null,
45
- },
46
- ],
47
- }),
48
- };
49
-
50
- // Generic version without appKey dependency
51
- export const authenticationIdGenericResolver: AuthenticationIdResolver = {
52
- ...authenticationIdResolver,
53
- depends: [] as const,
54
- };
@@ -1,11 +0,0 @@
1
- // Re-export individual resolvers for plugin use
2
- export { appKeyResolver } from "./appKey";
3
- export { actionTypeResolver } from "./actionType";
4
- export { actionKeyResolver } from "./actionKey";
5
- export {
6
- authenticationIdResolver,
7
- authenticationIdGenericResolver,
8
- } from "./authenticationId";
9
- export { inputsResolver } from "./inputs";
10
- export { inputFieldKeyResolver } from "./inputFieldKey";
11
- export { inputsAllOptionalResolver } from "./inputs";
@@ -1,70 +0,0 @@
1
- import type { DynamicResolver } from "../utils/schema-utils";
2
- import type { InputFieldItem } from "../schemas/Field";
3
- import type { ActionTypeProperty } from "../types/properties";
4
- import type {
5
- RootFieldItem,
6
- InfoFieldItem,
7
- FieldsetItem,
8
- } from "../types/domain";
9
-
10
- /**
11
- * Helper function to flatten fieldsets into a flat array of input fields.
12
- * Used to extract all input fields from nested fieldset structure for field selection.
13
- */
14
- function flattenRootFieldset(rootFieldset: RootFieldItem[]): InputFieldItem[] {
15
- const result: InputFieldItem[] = [];
16
-
17
- function processItem(item: InputFieldItem | InfoFieldItem | FieldsetItem) {
18
- if (item.type === "input_field") {
19
- result.push(item);
20
- } else if (item.type === "fieldset") {
21
- // Recursively process fields in the fieldset
22
- for (const field of item.fields) {
23
- processItem(field);
24
- }
25
- }
26
- // Skip info fields as they're not input fields
27
- }
28
-
29
- for (const item of rootFieldset) {
30
- processItem(item);
31
- }
32
-
33
- return result;
34
- }
35
-
36
- export const inputFieldKeyResolver: DynamicResolver<
37
- InputFieldItem,
38
- {
39
- appKey: string;
40
- actionKey: string;
41
- actionType: ActionTypeProperty;
42
- authenticationId: number;
43
- inputs?: Record<string, unknown>;
44
- }
45
- > = {
46
- type: "dynamic",
47
- depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
48
- fetch: async (sdk, resolvedParams) => {
49
- const fieldsResponse = await sdk.listInputFields({
50
- appKey: resolvedParams.appKey,
51
- actionKey: resolvedParams.actionKey,
52
- actionType: resolvedParams.actionType,
53
- authenticationId: resolvedParams.authenticationId,
54
- inputs: resolvedParams.inputs, // Pass along currently resolved inputs
55
- });
56
- // Flatten the fieldset structure for field selection
57
- return flattenRootFieldset(fieldsResponse.data);
58
- },
59
- prompt: (fields) => ({
60
- type: "list",
61
- name: "inputFieldKey",
62
- message: "Select input field:",
63
- choices: fields.map((field) => ({
64
- name: `${field.title || field.key} - ${
65
- field.value_type || "No type"
66
- } ${field.is_required ? "(required)" : "(optional)"}`,
67
- value: field.key,
68
- })),
69
- }),
70
- };
@@ -1,69 +0,0 @@
1
- import type { ActionTypeProperty } from "../types/properties";
2
- import type { RootFieldItem } from "../types/domain";
3
-
4
- // Helper function to recursively make all input fields optional while preserving structure
5
- function makeFieldsOptional(fields: RootFieldItem[]): RootFieldItem[] {
6
- return fields.map((field) => {
7
- if (field.type === "input_field") {
8
- return {
9
- ...field,
10
- is_required: false,
11
- };
12
- } else if (field.type === "fieldset") {
13
- return {
14
- ...field,
15
- fields: makeFieldsOptional(field.fields),
16
- };
17
- } else {
18
- // Info fields remain unchanged
19
- return field;
20
- }
21
- });
22
- }
23
-
24
- // Custom resolver type for fieldsets - returns the nested structure
25
- type InputsResolver = {
26
- type: "fields";
27
- depends: readonly string[];
28
- fetch: (
29
- sdk: any,
30
- resolvedParams: {
31
- appKey: string;
32
- actionKey: string;
33
- actionType: ActionTypeProperty;
34
- authenticationId: number;
35
- inputs?: Record<string, unknown>;
36
- },
37
- ) => Promise<RootFieldItem[]>;
38
- };
39
-
40
- export const inputsResolver: InputsResolver = {
41
- type: "fields",
42
- depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
43
- fetch: async (sdk, resolvedParams) => {
44
- const fieldsResponse = await sdk.listInputFields({
45
- appKey: resolvedParams.appKey,
46
- actionKey: resolvedParams.actionKey,
47
- actionType: resolvedParams.actionType,
48
- authenticationId: resolvedParams.authenticationId,
49
- inputs: resolvedParams.inputs, // Pass along currently resolved inputs
50
- });
51
- return fieldsResponse.data;
52
- },
53
- };
54
-
55
- export const inputsAllOptionalResolver: InputsResolver = {
56
- type: "fields",
57
- depends: ["appKey", "actionKey", "actionType", "authenticationId"] as const,
58
- fetch: async (sdk, resolvedParams) => {
59
- const fieldsResponse = await sdk.listInputFields({
60
- appKey: resolvedParams.appKey,
61
- actionKey: resolvedParams.actionKey,
62
- actionType: resolvedParams.actionType,
63
- authenticationId: resolvedParams.authenticationId,
64
- inputs: resolvedParams.inputs, // Pass along currently resolved inputs
65
- });
66
- // Return nested structure with all fields marked as optional.
67
- return makeFieldsOptional(fieldsResponse.data);
68
- },
69
- };
@@ -1,52 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter } from "../utils/schema-utils";
3
- import { ActionSchema } from "../api/schemas";
4
-
5
- // ============================================================================
6
- // Action Item Schema (extends API schema with computed fields and formatting)
7
- // ============================================================================
8
-
9
- export const ActionItemSchema = withFormatter(
10
- ActionSchema.omit({ type: true, name: true, selected_api: true }).extend({
11
- app_key: z.string(), // App key without version (extracted from selected_api)
12
- app_version: z.string().optional(), // Version extracted from selected_api
13
- action_type: ActionSchema.shape.type, // Mapped from original 'type' field
14
- title: z.string(), // Mapped from original 'name' field
15
- type: z.literal("action"), // Fixed type identifier
16
- }),
17
- {
18
- format: (item) => {
19
- const details = [];
20
- details.push({
21
- text: `Type: ${item.action_type}`,
22
- style: "accent" as const,
23
- });
24
- if (item.app_key) {
25
- details.push({
26
- text: `App: ${item.app_key}`,
27
- style: "normal" as const,
28
- });
29
- }
30
- if (item.description) {
31
- details.push({
32
- text: item.description,
33
- style: "dim" as const,
34
- });
35
- }
36
-
37
- return {
38
- title: item.title || item.key,
39
- id: item.id,
40
- key: item.key,
41
- description: item.description,
42
- details,
43
- };
44
- },
45
- },
46
- );
47
-
48
- // ============================================================================
49
- // Type Exports
50
- // ============================================================================
51
-
52
- export type ActionItem = z.infer<typeof ActionItemSchema>;
@@ -1,45 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter } from "../utils/schema-utils";
3
- import { ImplementationMetaSchema } from "../api/schemas";
4
- import { toSnakeCase } from "../utils/string-utils";
5
-
6
- export { FormattedItem, FormatMetadata } from "../utils/schema-utils";
7
-
8
- // ============================================================================
9
- // App Item Schema (extends ImplementationMetaSchema with transformed fields)
10
- // ============================================================================
11
-
12
- export const AppItemSchema = withFormatter(
13
- ImplementationMetaSchema.omit({ name: true, id: true }).extend({
14
- title: z.string(), // Mapped from name
15
- key: z.string(), // Extracted from id (base part without version)
16
- implementation_id: z.string(), // Mapped from id (full versioned ID)
17
- }),
18
- {
19
- format: (item) => {
20
- // Create additional keys if slug exists
21
- const additionalKeys = [];
22
- if (item.slug && item.slug !== item.key) {
23
- additionalKeys.push(item.slug);
24
- const snakeCaseSlug = toSnakeCase(item.slug);
25
- if (snakeCaseSlug !== item.slug && snakeCaseSlug !== item.key) {
26
- additionalKeys.push(snakeCaseSlug);
27
- }
28
- }
29
-
30
- return {
31
- title: item.title,
32
- key: item.key,
33
- keys: [item.key, ...additionalKeys],
34
- description: item.description,
35
- details: [],
36
- };
37
- },
38
- },
39
- );
40
-
41
- // ============================================================================
42
- // Type Exports
43
- // ============================================================================
44
-
45
- export type AppItem = z.infer<typeof AppItemSchema>;
@@ -1,59 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter } from "../utils/schema-utils";
3
- import { AuthenticationSchema } from "../api/schemas";
4
-
5
- // ============================================================================
6
- // Authentication Item Schema (extends API schema with computed fields and formatting)
7
- // ============================================================================
8
-
9
- export const AuthenticationItemSchema = withFormatter(
10
- AuthenticationSchema.omit({ selected_api: true, customuser_id: true }).extend(
11
- {
12
- implementation_id: z.string().optional(), // Renamed from selected_api
13
- is_expired: z.string().optional(), // Mapped from is_stale
14
- expired_at: z.string().nullable().optional(), // Mapped from marked_stale_at
15
- app_key: z.string().optional(), // App key from implementations endpoint
16
- app_version: z.string().optional(), // Version extracted from implementation_id
17
- user_id: z.number().optional(),
18
- },
19
- ),
20
- {
21
- format: (item) => {
22
- const details = [];
23
-
24
- if (item.identifier) {
25
- details.push({
26
- text: `Identifier: ${item.identifier}`,
27
- style: "accent" as const,
28
- });
29
- }
30
-
31
- details.push({
32
- text: `Account: ${item.account_id} | Private: ${item.is_private} | Shared: ${item.shared_with_all}`,
33
- style: "dim" as const,
34
- });
35
-
36
- if (item.marked_stale_at) {
37
- details.push({
38
- text: `⚠️ Marked stale: ${new Date(item.marked_stale_at).toLocaleDateString()}`,
39
- style: "warning" as const,
40
- });
41
- }
42
-
43
- return {
44
- title: item.title || `Authentication ${item.id}`,
45
- id: item.id?.toString(),
46
- details,
47
- };
48
- },
49
- },
50
- );
51
-
52
- // Legacy alias for backward compatibility
53
- export const AuthItemSchema = AuthenticationItemSchema;
54
-
55
- // ============================================================================
56
- // Type Exports
57
- // ============================================================================
58
-
59
- export type AuthItem = z.infer<typeof AuthItemSchema>;
@@ -1,169 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter } from "../utils/schema-utils";
3
-
4
- // ============================================================================
5
- // Base Field Schema
6
- // ============================================================================
7
-
8
- export const BaseFieldItemSchema = z.object({
9
- type: z.string(), // "input_field", "info_field", or "fieldset"
10
- key: z.string(), // From need.key
11
- });
12
-
13
- // ============================================================================
14
- // Input Field Item Schema (extends API Need schema with computed fields and formatting)
15
- // ============================================================================
16
-
17
- export const InputFieldItemSchema = withFormatter(
18
- BaseFieldItemSchema.extend({
19
- type: z.literal("input_field"),
20
- default_value: z.string(), // Mapped from 'default' with fallback to ""
21
- depends_on: z.array(z.string()), // Mapped from 'depends_on' with fallback to []
22
- description: z.string(), // Mapped from 'help_text' with fallback to ""
23
- invalidates_input_fields: z.boolean(), // Mapped from 'alters_custom_fields' with fallback to false
24
- is_required: z.boolean(), // Mapped from 'required' with fallback to false
25
- placeholder: z.string(), // Mapped from 'placeholder' with fallback to ""
26
- title: z.string(), // Mapped from 'label' with fallback to ""
27
- value_type: z.string(), // Computed from InputFieldType enum
28
- format: z.string().optional(), // Computed from InputFieldFormat enum (optional)
29
- items: z.object({ type: z.string() }).optional(), // Computed from ItemsType enum (optional, only for arrays)
30
- }),
31
- {
32
- format: (item) => {
33
- const details = [];
34
-
35
- // Type and required status
36
- const typeInfo = [
37
- item.value_type && `Type: ${item.value_type}`,
38
- `Required: ${item.is_required ? "Yes" : "No"}`,
39
- ]
40
- .filter(Boolean)
41
- .join(" | ");
42
- if (typeInfo) {
43
- details.push({ text: typeInfo, style: "dim" as const });
44
- }
45
-
46
- // Description
47
- if (item.description) {
48
- details.push({
49
- text: item.description,
50
- style: "normal" as const,
51
- });
52
- }
53
-
54
- // Default value
55
- if (item.default_value) {
56
- details.push({
57
- text: `Default: ${item.default_value}`,
58
- style: "accent" as const,
59
- });
60
- }
61
-
62
- // Placeholder
63
- if (item.placeholder) {
64
- details.push({
65
- text: `Placeholder: ${item.placeholder}`,
66
- style: "dim" as const,
67
- });
68
- }
69
-
70
- // Dependencies
71
- if (item.depends_on && item.depends_on.length > 0) {
72
- details.push({
73
- text: `Depends on: ${item.depends_on.join(", ")}`,
74
- style: "warning" as const,
75
- });
76
- }
77
-
78
- // Format information
79
- if (item.format) {
80
- details.push({ text: `Format: ${item.format}`, style: "dim" as const });
81
- }
82
-
83
- // Items type for arrays
84
- if (item.items) {
85
- details.push({
86
- text: `Items type: ${item.items.type}`,
87
- style: "dim" as const,
88
- });
89
- }
90
-
91
- return {
92
- title: item.title || item.key,
93
- key: item.key,
94
- description: item.description,
95
- details,
96
- };
97
- },
98
- },
99
- );
100
-
101
- // ============================================================================
102
- // Info Field Item Schema (for help text and copy fields)
103
- // ============================================================================
104
-
105
- export const InfoFieldItemSchema = withFormatter(
106
- BaseFieldItemSchema.extend({
107
- type: z.literal("info_field"),
108
- description: z.string(), // From need.help_text
109
- title: z.string().optional(), // Optional title
110
- }),
111
- {
112
- format: (item) => ({
113
- title: item.title || "Info",
114
- key: item.key,
115
- description: item.description,
116
- details: [{ text: item.description, style: "normal" as const }],
117
- }),
118
- },
119
- );
120
-
121
- // ============================================================================
122
- // Fieldset Schema (for grouping fields)
123
- // ============================================================================
124
-
125
- // Forward reference for recursive type
126
- type FieldsetItemType =
127
- | z.infer<typeof InputFieldItemSchema>
128
- | z.infer<typeof InfoFieldItemSchema>
129
- | FieldsetItem;
130
-
131
- export interface FieldsetItem {
132
- type: "fieldset";
133
- key: string;
134
- title: string;
135
- fields: FieldsetItemType[];
136
- }
137
-
138
- export const FieldsetItemSchema: z.ZodType<FieldsetItem> =
139
- BaseFieldItemSchema.extend({
140
- type: z.literal("fieldset"),
141
- title: z.string(),
142
- fields: z.lazy(() =>
143
- z.array(
144
- z.union([
145
- InputFieldItemSchema,
146
- InfoFieldItemSchema,
147
- FieldsetItemSchema,
148
- ]),
149
- ),
150
- ),
151
- });
152
-
153
- // ============================================================================
154
- // Root Field Item Schema (union of all possible field types)
155
- // ============================================================================
156
-
157
- export const RootFieldItemSchema = z.union([
158
- InputFieldItemSchema,
159
- InfoFieldItemSchema,
160
- FieldsetItemSchema,
161
- ]);
162
-
163
- // ============================================================================
164
- // Type Exports
165
- // ============================================================================
166
-
167
- export type InputFieldItem = z.infer<typeof InputFieldItemSchema>;
168
- export type InfoFieldItem = z.infer<typeof InfoFieldItemSchema>;
169
- export type RootFieldItem = z.infer<typeof RootFieldItemSchema>;
@@ -1,40 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter, type FormattedItem } from "../utils/schema-utils";
3
-
4
- // Type guard to safely access object properties
5
- function getStringProperty(obj: unknown, key: string): string | undefined {
6
- if (typeof obj === "object" && obj !== null && key in obj) {
7
- const value = (obj as Record<string, unknown>)[key];
8
- return typeof value === "string" ? value : undefined;
9
- }
10
- return undefined;
11
- }
12
-
13
- // Formatter for action results - handles any data structure
14
- function formatActionResult(item: unknown): FormattedItem {
15
- // Try to extract common fields for structured display
16
- const obj = typeof item === "object" && item !== null ? item : {};
17
-
18
- // Try common title fields
19
- const title =
20
- getStringProperty(obj, "title") ||
21
- getStringProperty(obj, "name") ||
22
- getStringProperty(obj, "label") ||
23
- getStringProperty(obj, "subject") ||
24
- "Action Result";
25
-
26
- return {
27
- title,
28
- id: getStringProperty(obj, "id"),
29
- key: getStringProperty(obj, "key"),
30
- description: getStringProperty(obj, "description"),
31
- data: item, // Let formatJsonOutput handle the JSON rendering
32
- details: [], // Not used when data is provided
33
- };
34
- }
35
-
36
- // Flexible schema for action results - can be any object
37
- export const ActionResultItemSchema = withFormatter(
38
- z.unknown().describe("Action execution result"),
39
- { format: formatActionResult },
40
- );
@@ -1,60 +0,0 @@
1
- import { z } from "zod";
2
- import { withFormatter } from "../utils/schema-utils";
3
- import { UserProfileSchema } from "../api/schemas";
4
-
5
- export { FormattedItem, FormatMetadata } from "../utils/schema-utils";
6
-
7
- // ============================================================================
8
- // User Profile Item Schema (extends API schema with computed fields and formatting)
9
- // ============================================================================
10
-
11
- export const UserProfileItemSchema = withFormatter(
12
- UserProfileSchema.omit({ user_id: true }).extend({
13
- full_name: z.string(), // Computed field: first_name + " " + last_name
14
- }),
15
- {
16
- format: (item) => {
17
- const details = [];
18
- if (
19
- item == null ||
20
- typeof item !== "object" ||
21
- !("full_name" in item) ||
22
- !("username" in item)
23
- ) {
24
- return {
25
- title: "User Profile",
26
- subtitle: "Malformatted result item",
27
- details: [],
28
- };
29
- }
30
-
31
- if ("email" in item) {
32
- details.push({ text: item.email, style: "dim" as const });
33
- }
34
- if ("timezone" in item && item.timezone) {
35
- details.push({
36
- text: `Timezone: ${item.timezone}`,
37
- style: "accent" as const,
38
- });
39
- }
40
- if ("since_signup" in item && item.since_signup) {
41
- details.push({
42
- text: `Member since: ${item.since_signup}`,
43
- style: "dim" as const,
44
- });
45
- }
46
-
47
- return {
48
- title: item.full_name,
49
- id: item.id.toString(),
50
- details,
51
- };
52
- },
53
- },
54
- );
55
-
56
- // ============================================================================
57
- // Type Exports
58
- // ============================================================================
59
-
60
- export type UserProfileItem = z.infer<typeof UserProfileItemSchema>;