@ganju/utils 0.0.17 → 0.0.18

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 (49) hide show
  1. package/dist/constants.d.ts +6 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +14 -1
  4. package/dist/customCodeToken.d.ts +4 -0
  5. package/dist/customCodeToken.d.ts.map +1 -1
  6. package/dist/customCodeToken.js +9 -1
  7. package/dist/data.d.ts +2 -0
  8. package/dist/data.d.ts.map +1 -1
  9. package/dist/data.js +28 -1
  10. package/dist/dataApi.d.ts +133 -1
  11. package/dist/dataApi.d.ts.map +1 -1
  12. package/dist/dataApi.js +62 -1
  13. package/dist/dataDdl.d.ts.map +1 -1
  14. package/dist/dataDdl.js +3 -1
  15. package/dist/dataEngine.d.ts.map +1 -1
  16. package/dist/dataEngine.js +62 -0
  17. package/dist/dataRpc.d.ts +25 -0
  18. package/dist/dataRpc.d.ts.map +1 -1
  19. package/dist/dataTriggers.d.ts +203 -0
  20. package/dist/dataTriggers.d.ts.map +1 -0
  21. package/dist/dataTriggers.js +760 -0
  22. package/dist/dataTypes.d.ts +1 -0
  23. package/dist/dataTypes.d.ts.map +1 -1
  24. package/dist/index.d.ts +115 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/localizeDataError.d.ts +18 -0
  28. package/dist/localizeDataError.d.ts.map +1 -0
  29. package/dist/localizeDataError.js +359 -0
  30. package/dist/schema.d.ts +110 -0
  31. package/dist/schema.d.ts.map +1 -1
  32. package/dist/schema.js +84 -0
  33. package/dist/sdkConstants.d.ts +2 -0
  34. package/dist/sdkConstants.d.ts.map +1 -1
  35. package/dist/sdkConstants.js +3 -1
  36. package/package.json +1 -1
  37. package/src/constants.ts +17 -1
  38. package/src/customCodeToken.ts +14 -1
  39. package/src/data.ts +40 -0
  40. package/src/dataApi.ts +78 -2
  41. package/src/dataDdl.ts +3 -1
  42. package/src/dataEngine.ts +70 -0
  43. package/src/dataRpc.ts +15 -0
  44. package/src/dataTriggers.ts +1134 -0
  45. package/src/dataTypes.ts +3 -0
  46. package/src/index.ts +2 -0
  47. package/src/localizeDataError.ts +593 -0
  48. package/src/schema.ts +89 -0
  49. package/src/sdkConstants.ts +2 -0
package/src/schema.ts CHANGED
@@ -767,12 +767,75 @@ const DATA_QUERY_RUN_BODY = z.strictObject({
767
767
  timeZone: z.string().max(100).optional()
768
768
  });
769
769
 
770
+ // A trigger, as the dashboard, the API and ganju.json's "triggers" write it:
771
+ // a table, an event, an optional condition and exactly one action. The
772
+ // object checks the rest (columns, fields used in texts) against the schema.
773
+ const DATA_TRIGGER_NAME = z
774
+ .string()
775
+ .regex(
776
+ /^[a-z][a-z0-9_-]{0,62}$/,
777
+ 'Lowercase letters, digits, _ and -, starting with a letter'
778
+ );
779
+ const DATA_TRIGGER_TEMPLATE = z.strictObject({
780
+ name: z.string().min(1).max(512),
781
+ language: z.string().min(1).max(20),
782
+ // Each {{n}} of the template in order: fixed text or a {{field}} of the row.
783
+ params: z.array(z.string().max(1024)).max(20).optional()
784
+ });
785
+ const DATA_TRIGGER_INPUT = z.strictObject({
786
+ name: DATA_TRIGGER_NAME.optional(),
787
+ description: z.string().max(300).nullish(),
788
+ table: DATA_IDENTIFIER,
789
+ on: z.enum(['insert', 'update', 'delete']),
790
+ // { column: { changedTo | changedFrom | equals: value, changed: true } },
791
+ // combined with { all: [...] } or { any: [...] }.
792
+ when: z.record(z.string(), z.unknown()).nullish(),
793
+ enabled: z.boolean().optional(),
794
+ // false: refuse to save over an existing trigger of this name.
795
+ replace: z.boolean().optional(),
796
+ // Runs a minute; past it events wait in the queue. 60 by default.
797
+ rateLimit: z.number().int().min(1).max(600).optional(),
798
+ function: z.string().min(1).max(64).optional(),
799
+ webhook: z.url().max(2000).optional(),
800
+ chat: z
801
+ .strictObject({
802
+ channelId: z.string().min(1).max(100),
803
+ chatId: z.union([z.string().min(1).max(200), z.number().int()]),
804
+ text: z.string().min(1).max(2000)
805
+ })
806
+ .optional(),
807
+ email: z
808
+ .strictObject({
809
+ to: z.union([z.email(), z.array(z.email()).min(1).max(10)]),
810
+ subject: z.string().min(1).max(200).optional(),
811
+ text: z.string().min(1).max(2000)
812
+ })
813
+ .optional(),
814
+ customer: z
815
+ .strictObject({
816
+ text: z.string().min(1).max(2000),
817
+ template: DATA_TRIGGER_TEMPLATE.optional()
818
+ })
819
+ .optional()
820
+ });
821
+ const DATA_TRIGGER_PATCH = z.strictObject({ enabled: z.boolean() });
822
+ const DATA_TRIGGER_DEPLOY_BODY = z.strictObject({
823
+ triggers: z.array(DATA_TRIGGER_INPUT).max(50)
824
+ });
825
+ const DATA_TRIGGER_RUN_LIST_QUERY = z.object({
826
+ limit: z.coerce.number().int().min(1).max(50).optional()
827
+ });
828
+
770
829
  const DATA_TABLE_PARAMS = DATA_DATABASE_GET.extend({ table: DATA_IDENTIFIER });
771
830
  const DATA_COLUMN_PARAMS = DATA_TABLE_PARAMS.extend({
772
831
  column: DATA_IDENTIFIER
773
832
  });
774
833
  const DATA_ROW_PARAMS = DATA_TABLE_PARAMS.extend({ id: DATA_ROW_ID });
775
834
  const DATA_QUERY_PATH_PARAMS = DATA_DATABASE_GET.extend({ name: DATA_IDENTIFIER });
835
+ const DATA_TRIGGER_PATH_PARAMS = DATA_DATABASE_GET.extend({ name: DATA_TRIGGER_NAME });
836
+ const DATA_TRIGGER_RUN_PARAMS = DATA_TRIGGER_PATH_PARAMS.extend({
837
+ runId: z.string().min(1).max(64)
838
+ });
776
839
 
777
840
  const ARTIFACT_UPLOAD_RESOURCE_FILE = z.object({
778
841
  resourceId: z.uuid(),
@@ -1409,6 +1472,9 @@ const CUSTOM_CODE_TOOL = z.object({
1409
1472
  // is the owner's code. Narrowing matters most for a function a channel bot
1410
1473
  // calls after reading customer text, and the broker enforces it, since
1411
1474
  // anything in the script can be edited.
1475
+ // false: deployed and run by triggers, but never offered to the assistant
1476
+ // (left out of tools/list, and not counted toward its tools).
1477
+ expose: z.boolean().optional(),
1412
1478
  data: z
1413
1479
  .strictObject({
1414
1480
  access: z.enum(['read', 'write']).optional(),
@@ -1673,6 +1739,21 @@ const CUSTOM_CODE_BROKER_DATA = z.object({
1673
1739
  args: z.record(z.string(), z.unknown()).default({})
1674
1740
  });
1675
1741
 
1742
+ // ctx.channels: a message to a customer the bot has spoken with, or a post
1743
+ // to a chat the bot is in. `call` names the function, as for ctx.data.
1744
+ const CUSTOM_CODE_BROKER_CHANNELS_SEND = z.object({
1745
+ call: z.string().min(1).max(4000),
1746
+ participantId: z.string().min(1).max(100),
1747
+ text: z.string().min(1).max(4000).optional(),
1748
+ template: DATA_TRIGGER_TEMPLATE.optional()
1749
+ });
1750
+ const CUSTOM_CODE_BROKER_CHANNELS_POST = z.object({
1751
+ call: z.string().min(1).max(4000),
1752
+ channelId: z.string().min(1).max(100),
1753
+ chatId: z.union([z.string().min(1).max(200), z.number().int()]),
1754
+ text: z.string().min(1).max(4000)
1755
+ });
1756
+
1676
1757
  const CUSTOM_CODE_BROKER_RESOURCE_SEARCH = z.object({
1677
1758
  query: z.string().min(1).max(2000),
1678
1759
  limit: z.number().int().positive().max(20).default(5)
@@ -2038,6 +2119,12 @@ export const Schema = {
2038
2119
  DATA_QUERY_INPUT,
2039
2120
  DATA_QUERY_RUN_BODY,
2040
2121
  DATA_QUERY_PATH_PARAMS,
2122
+ DATA_TRIGGER_INPUT,
2123
+ DATA_TRIGGER_PATCH,
2124
+ DATA_TRIGGER_DEPLOY_BODY,
2125
+ DATA_TRIGGER_RUN_LIST_QUERY,
2126
+ DATA_TRIGGER_PATH_PARAMS,
2127
+ DATA_TRIGGER_RUN_PARAMS,
2041
2128
  DATA_COLUMN_PARAMS,
2042
2129
  DATA_ROW_PARAMS,
2043
2130
  ARTIFACT_REMOVE_RESOURCE,
@@ -2102,6 +2189,8 @@ export const Schema = {
2102
2189
  CUSTOM_CODE_BROKER_CONNECTION,
2103
2190
  CUSTOM_CODE_BROKER_SECRET,
2104
2191
  CUSTOM_CODE_BROKER_DATA,
2192
+ CUSTOM_CODE_BROKER_CHANNELS_SEND,
2193
+ CUSTOM_CODE_BROKER_CHANNELS_POST,
2105
2194
  CUSTOM_CODE_BROKER_RESOURCE_SEARCH,
2106
2195
  CUSTOM_CODE_BROKER_RESOURCE_READ,
2107
2196
  CUSTOM_CODE_BROKER_RESOURCE_CREATE,
@@ -30,6 +30,8 @@ export const CUSTOM_CODE_BROKER_PATH_RESOURCES_CREATE = '/resources/create';
30
30
  export const CUSTOM_CODE_BROKER_PATH_RESOURCES_DELETE = '/resources/delete';
31
31
  export const CUSTOM_CODE_BROKER_PATH_SEND_FILE = '/send-file';
32
32
  export const CUSTOM_CODE_BROKER_PATH_DATA = '/data';
33
+ export const CUSTOM_CODE_BROKER_PATH_CHANNELS_SEND = '/channels/send';
34
+ export const CUSTOM_CODE_BROKER_PATH_CHANNELS_POST = '/channels/post';
33
35
 
34
36
  // Injected at upload time and echoed back by the health probe below. Uploading a
35
37
  // script into the dispatch namespace is not read-your-writes: dispatching to the