skapi-js 2.2.5 → 2.2.6-beta.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.
package/dist/skapi.d.mts CHANGED
@@ -864,43 +864,57 @@ type TicketResponseCondition = Pick<TicketCondition, 'headers' | 'data' | 'user'
864
864
  * | `${user}`, `${user[key]}` | The signed-in user's attributes. Signed requests only. |
865
865
  * | `${ip}`, `${user_agent}`, `${method}` | The caller's IP address, User-Agent and HTTP method. |
866
866
  * | `${record_access}` | The record ID the condition's `record_access` names. Signed requests only. |
867
- * | `${response}`, `${response[key]}` | The parsed body of the enclosing req action's response. Only in that req's nested `actions` and their `err` chains. |
868
- * | `${result}`, `${result[key]}` | The result of the previous action in the same chain. A nested chain and an `err` chain start without one. |
867
+ * | `${response}`, `${response[key]}` | The answer of the enclosing action, in its Then chain (`actions`) and the `err` chains inside it: the record a pstr posted, the parsed body of a req's response, the SUCCESS text of acsg and acsr. |
869
868
  * | `${error}`, `${error[key]}` | In an `err` chain, the failure: `code`, `message`, `detail`, `action` (the act) and `path`. |
870
- * | `${ticket}`, `${ticket[key]}` | This consumption: `id`, `service`, `owner`, `consume_id` and `timestamp`. |
869
+ * | `${ticket}`, `${ticket[key]}` | This consumption: `id`, `service`, `owner`, `consume_id`, `timestamp` and `hash`. |
871
870
  * | `${CLIENT_SECRET}` | Reserved. See `secretName` on the req action. |
872
871
  *
873
872
  * Registration refuses anything else inside `${ }` (an unknown root such as `${id}`, keys under
874
873
  * a root that takes none such as `${ip[x]}`, `${placeholder}` or `${headers}` without a key,
875
- * broken brackets) with a message listing these forms, and a reference written where it can
876
- * never resolve (`${response}` outside a req's nested actions, `${error}` outside an `err`
874
+ * broken brackets) with a message listing these forms, `${result}` (gone: an answer is read as
875
+ * `${response}` in the action's Then chain, or captured by its Check), and a reference written
876
+ * where it can never resolve (`${response}` outside a Then chain, `${error}` outside an `err`
877
877
  * chain, `${record_access}` when the condition names no record). When the action runs, a
878
878
  * reference that does not resolve fails it before it does anything: PATH_NOT_FOUND,
879
879
  * PLACEHOLDER_MISSING for a placeholder that was never captured, or AUTH_REQUIRED for `${user}`
880
880
  * on a request that is not signed in. Its `err` chain runs and the consumption stops.
881
+ *
882
+ * Every action but resp and cond answers something (the record, the response body, a SUCCESS
883
+ * text) and may carry a Check (`condition`: rows on that answer, a key "" the whole text; a miss
884
+ * fails the action) and a Then chain (`actions`, reading the answer as `${response}`). `retry:
885
+ * true` on acsg, acsr, pstr and req tries a failure again, up to 3 more times, 1, 2 and 4
886
+ * seconds apart, while the time budget holds them; never for a failure inside Then.
881
887
  */
882
888
  type TicketAction = {
883
- /** Set the access group of a user. */
889
+ /** Set the access group of a user. Answers the SUCCESS text the grant returns. */
884
890
  act: 'acsg';
885
891
  exe: {
886
892
  /** 1 ~ 99, or "admin", or a reference that gives one when the action runs, such as "${placeholder[GROUP]}". */
887
893
  group: number | 'admin' | `${string}\${${string}}${string}`;
888
894
  /** Blank = the consumer (signed-in consumption only). The project owner cannot be a target. */
889
895
  user_id?: string;
896
+ /** The Check: rows on the answer. */
897
+ condition?: TicketAnswerCondition;
898
+ /** The Then chain, reading the answer as `${response}`. */
899
+ actions?: TicketAction[];
890
900
  };
891
901
  err?: TicketAction[];
902
+ retry?: boolean;
892
903
  } | {
893
- /** Grant private access to a record. */
904
+ /** Grant private access to a record. Answers the SUCCESS text the grant returns. */
894
905
  act: 'acsr';
895
906
  exe: {
896
907
  /** A record ID, not a unique ID. */
897
908
  record_id: string;
898
909
  /** Blank = the consumer. */
899
910
  user_id?: string | string[];
911
+ condition?: TicketAnswerCondition;
912
+ actions?: TicketAction[];
900
913
  };
901
914
  err?: TicketAction[];
915
+ retry?: boolean;
902
916
  } | {
903
- /** Post a record. Everything but `user_id` is the payload postRecord() sends, so the same rules apply. A `unique_id` makes a retried webhook update the same record instead of adding one. */
917
+ /** Post a record. Everything but `user_id` is the payload postRecord() sends, so the same rules apply. A `unique_id` makes a retried webhook update the same record instead of adding one. Answers the record (RecordData). */
904
918
  act: 'pstr';
905
919
  exe: {
906
920
  table: string | {
@@ -922,10 +936,15 @@ type TicketAction = {
922
936
  source?: PostRecordConfig['source'];
923
937
  /** Post as this user instead of the project owner. */
924
938
  user_id?: string;
939
+ /** The Check: rows on the record posted, such as `record_id`. */
940
+ condition?: TicketAnswerCondition;
941
+ /** The Then chain, reading the record as `${response}` (`${response[record_id]}`). */
942
+ actions?: TicketAction[];
925
943
  };
926
944
  err?: TicketAction[];
945
+ retry?: boolean;
927
946
  } | {
928
- /** HTTP request with its own response condition and nested chain. Result: the parsed response body. */
947
+ /** HTTP request with its own response condition and nested chain. Answers the parsed response body. */
929
948
  act: 'req';
930
949
  exe: {
931
950
  /**
@@ -1000,6 +1019,73 @@ type TicketAction = {
1000
1019
  actions?: TicketAction[];
1001
1020
  };
1002
1021
  err?: TicketAction[];
1022
+ retry?: boolean;
1023
+ } | {
1024
+ /**
1025
+ * Respond: answers the consumer now, then stops or goes on. One per run: a second Respond
1026
+ * on a path that already answered is refused at registration, and ALREADY_RESPONDED when
1027
+ * it runs. consumeTicket() resolves with the body (or the receipt), whatever the status.
1028
+ */
1029
+ act: 'resp';
1030
+ exe: {
1031
+ /** The HTTP status, 100 to 599, or a reference. Default 200. An error status is still an answer, not a failure. */
1032
+ status?: number | string;
1033
+ /** Any JSON, templated; absent: the receipt { tkid, hash }. A `stage` key is refused (that is how an error is told apart). */
1034
+ body?: any;
1035
+ /**
1036
+ * What happens after the answer. Absent or "stop": the rest of the chain does not run.
1037
+ * "0m": goes on at once, in the background. "<n>m" | "<n>h" | "<n>d" (n >= 1): goes on
1038
+ * after that delay, to the minute. A number: a time in ms since the epoch, to the second
1039
+ * (a literal in the past is refused at registration; a templated one goes on at once).
1040
+ * A run that goes on counts toward the plan's queued ticket runs for the month; Free and
1041
+ * Standard stop at theirs (QUOTA_EXCEEDED), Premium is billed past it.
1042
+ */
1043
+ resume?: 'stop' | '0m' | `${number}m` | `${number}h` | `${number}d` | number | string;
1044
+ };
1045
+ err?: TicketAction[];
1046
+ } | {
1047
+ /**
1048
+ * Condition: rows inside a chain, under the rules of the ticket's own condition. A part
1049
+ * that fails fails the chain here with CONDITION_FAILED (the action's `err` chain runs).
1050
+ * Answers nothing. `response` rows only inside a Then chain, `error` rows only inside an
1051
+ * `err` chain, `placeholder` rows name placeholders (and may compare with null).
1052
+ */
1053
+ act: 'cond';
1054
+ exe: {
1055
+ data?: TicketConditionRow[];
1056
+ params?: TicketConditionRow[];
1057
+ headers?: TicketCondition['headers'];
1058
+ ip?: TicketCondition['ip'];
1059
+ user_agent?: TicketCondition['user_agent'];
1060
+ user?: TicketCondition['user'];
1061
+ record_access?: string;
1062
+ placeholder?: {
1063
+ key: string;
1064
+ operator: TicketConditionOperator;
1065
+ value: any;
1066
+ }[];
1067
+ response?: TicketConditionRow[];
1068
+ error?: TicketConditionRow[];
1069
+ };
1070
+ err?: TicketAction[];
1071
+ };
1072
+ /** The Check of an action: rows on its answer (TicketConditionRow, keys paths in the answer; "" is the whole answer as text). */
1073
+ type TicketAnswerCondition = {
1074
+ data?: TicketConditionRow[];
1075
+ };
1076
+ /** What a consumption answers when no Respond action composes the answer. */
1077
+ type TicketReceipt = {
1078
+ ticket_id: string;
1079
+ /** Id of this consumption: base62 of the timestamp in milliseconds, followed by 4 random characters. */
1080
+ consume_id: string;
1081
+ /** The consumer. The user id on the signed-in endpoint, else "<ip>(<user agent>)". */
1082
+ user_id: string;
1083
+ /** Always false here: dry runs go through the check URL, which consumeTicket() never calls. */
1084
+ is_test: boolean;
1085
+ /** When the consumption happened, in milliseconds. Decoded from consume_id. */
1086
+ timestamp: number;
1087
+ /** Proof string of the consumption. */
1088
+ hash: string;
1003
1089
  };
1004
1090
  /** An issued ticket as getTickets() and registerTicket() return it. */
1005
1091
  type Ticket = {
@@ -1026,7 +1112,7 @@ type Ticket = {
1026
1112
  */
1027
1113
  legacy?: boolean;
1028
1114
  };
1029
- type TicketErrorCode = 'INVALID_SERVICE' | 'SERVICE_DISABLED' | 'TICKET_NOT_FOUND' | 'TICKET_EXPIRED' | 'TICKET_EXHAUSTED' | 'USER_LIMIT_REACHED' | 'ISSUER_CANNOT_CONSUME' | 'AUTH_REQUIRED' | 'METHOD_NOT_ALLOWED' | 'CONDITION_FAILED' | 'PATH_NOT_FOUND' | 'PLACEHOLDER_MISSING' | 'REQUEST_FAILED' | 'TIMEOUT' | 'ACTION_FAILED' | 'ACTION_FORBIDDEN' | 'INTERNAL_ERROR';
1115
+ type TicketErrorCode = 'INVALID_SERVICE' | 'SERVICE_DISABLED' | 'TICKET_NOT_FOUND' | 'TICKET_EXPIRED' | 'TICKET_EXHAUSTED' | 'USER_LIMIT_REACHED' | 'ISSUER_CANNOT_CONSUME' | 'AUTH_REQUIRED' | 'METHOD_NOT_ALLOWED' | 'CONDITION_FAILED' | 'PATH_NOT_FOUND' | 'PLACEHOLDER_MISSING' | 'REQUEST_FAILED' | 'TIMEOUT' | 'ACTION_FAILED' | 'ACTION_FORBIDDEN' | 'QUOTA_EXCEEDED' | 'ALREADY_RESPONDED' | 'INTERNAL_ERROR';
1030
1116
  /**
1031
1117
  * The body a consume endpoint answers with when the consumption fails, and the `cause` of the
1032
1118
  * SkapiError consumeTicket() rejects with. A success body never has `stage`; an error body
@@ -1090,11 +1176,13 @@ type Types_Table = Table;
1090
1176
  type Types_Tag = Tag;
1091
1177
  type Types_Ticket = Ticket;
1092
1178
  type Types_TicketAction = TicketAction;
1179
+ type Types_TicketAnswerCondition = TicketAnswerCondition;
1093
1180
  type Types_TicketCondition = TicketCondition;
1094
1181
  type Types_TicketConditionOperator = TicketConditionOperator;
1095
1182
  type Types_TicketConditionRow = TicketConditionRow;
1096
1183
  type Types_TicketError = TicketError;
1097
1184
  type Types_TicketErrorCode = TicketErrorCode;
1185
+ type Types_TicketReceipt = TicketReceipt;
1098
1186
  type Types_TicketResponseCondition = TicketResponseCondition;
1099
1187
  type Types_TicketSignatureCondition = TicketSignatureCondition;
1100
1188
  type Types_UniqueId = UniqueId;
@@ -1103,7 +1191,7 @@ type Types_UserProfile = UserProfile;
1103
1191
  type Types_UserPublic = UserPublic;
1104
1192
  type Types_WebSocketMessage = WebSocketMessage;
1105
1193
  declare namespace Types {
1106
- export type { Types_BinaryFile as BinaryFile, Types_Condition as Condition, Types_Connection as Connection, Types_ConnectionInfo as ConnectionInfo, Types_DatabaseResponse as DatabaseResponse, Types_DelRecordQuery as DelRecordQuery, Types_EncryptionOptions as EncryptionOptions, Types_FetchOptions as FetchOptions, Types_FileInfo as FileInfo, Types_Form as Form, Types_GetRecordQuery as GetRecordQuery, Types_Index as Index, Types_Newsletter as Newsletter, Types_NewsletterGroup as NewsletterGroup, Types_PostRecordConfig as PostRecordConfig, Types_ProgressCallback as ProgressCallback, Types_RTCConnector as RTCConnector, Types_RTCConnectorParams as RTCConnectorParams, Types_RTCEvent as RTCEvent, Types_RTCReceiverParams as RTCReceiverParams, Types_RTCResolved as RTCResolved, Types_RealtimeCallback as RealtimeCallback, Types_RecordData as RecordData, Types_RecordEncryptionInfo as RecordEncryptionInfo, Types_RequestHistory as RequestHistory, Types_Subscription as Subscription, Types_Table as Table, Types_Tag as Tag, Types_Ticket as Ticket, Types_TicketAction as TicketAction, Types_TicketCondition as TicketCondition, Types_TicketConditionOperator as TicketConditionOperator, Types_TicketConditionRow as TicketConditionRow, Types_TicketError as TicketError, Types_TicketErrorCode as TicketErrorCode, Types_TicketResponseCondition as TicketResponseCondition, Types_TicketSignatureCondition as TicketSignatureCondition, Types_UniqueId as UniqueId, Types_UserAttributes as UserAttributes, Types_UserProfile as UserProfile, Types_UserPublic as UserPublic, Types_WebSocketMessage as WebSocketMessage };
1194
+ export type { Types_BinaryFile as BinaryFile, Types_Condition as Condition, Types_Connection as Connection, Types_ConnectionInfo as ConnectionInfo, Types_DatabaseResponse as DatabaseResponse, Types_DelRecordQuery as DelRecordQuery, Types_EncryptionOptions as EncryptionOptions, Types_FetchOptions as FetchOptions, Types_FileInfo as FileInfo, Types_Form as Form, Types_GetRecordQuery as GetRecordQuery, Types_Index as Index, Types_Newsletter as Newsletter, Types_NewsletterGroup as NewsletterGroup, Types_PostRecordConfig as PostRecordConfig, Types_ProgressCallback as ProgressCallback, Types_RTCConnector as RTCConnector, Types_RTCConnectorParams as RTCConnectorParams, Types_RTCEvent as RTCEvent, Types_RTCReceiverParams as RTCReceiverParams, Types_RTCResolved as RTCResolved, Types_RealtimeCallback as RealtimeCallback, Types_RecordData as RecordData, Types_RecordEncryptionInfo as RecordEncryptionInfo, Types_RequestHistory as RequestHistory, Types_Subscription as Subscription, Types_Table as Table, Types_Tag as Tag, Types_Ticket as Ticket, Types_TicketAction as TicketAction, Types_TicketAnswerCondition as TicketAnswerCondition, Types_TicketCondition as TicketCondition, Types_TicketConditionOperator as TicketConditionOperator, Types_TicketConditionRow as TicketConditionRow, Types_TicketError as TicketError, Types_TicketErrorCode as TicketErrorCode, Types_TicketReceipt as TicketReceipt, Types_TicketResponseCondition as TicketResponseCondition, Types_TicketSignatureCondition as TicketSignatureCondition, Types_UniqueId as UniqueId, Types_UserAttributes as UserAttributes, Types_UserProfile as UserProfile, Types_UserPublic as UserPublic, Types_WebSocketMessage as WebSocketMessage };
1107
1195
  }
1108
1196
 
1109
1197
  declare function terminatePendingRequests(): void;
@@ -1818,13 +1906,16 @@ declare class Skapi {
1818
1906
  * its actions run. An anonymous POST goes to `/tp/`, an anonymous GET to `/tg/` with `data`
1819
1907
  * as the query string, and a signed-in consumption (`auth: true`) to `/tpa/`, which is POST only.
1820
1908
  *
1909
+ * Resolves with the receipt (TicketReceipt: ticket_id, consume_id, user_id, is_test, timestamp, hash),
1910
+ * or with the body a Respond action of the ticket answered, as sent and whatever its status. `T` names that body.
1911
+ *
1821
1912
  * A failed consumption rejects with a SkapiError: `err.code` is the ticket error code and
1822
1913
  * `err.cause` the flat TicketError body (`err.cause.stage`, `err.cause.action`, `err.cause.detail`).
1823
1914
  * This holds when the ticket answers HTTP 200 as well (`return200`): the body is inspected, not the status.
1824
1915
  * @param params Request parameters.
1825
- * @returns A promise that resolves to Promise<{ ticket_id: string; consume_id: string; user_id: string; is_test: boolean; timestamp: number; hash: string; }>.
1916
+ * @returns A promise that resolves to Promise<T>, the receipt or the Respond body.
1826
1917
  */
1827
- consumeTicket(params: {
1918
+ consumeTicket<T = TicketReceipt>(params: {
1828
1919
  /** ID of the ticket to consume. */
1829
1920
  ticket_id: string;
1830
1921
  /** "GET" or "POST". */
@@ -1835,14 +1926,7 @@ declare class Skapi {
1835
1926
  data?: {
1836
1927
  [key: string]: any;
1837
1928
  };
1838
- }): Promise<{
1839
- ticket_id: string;
1840
- consume_id: string;
1841
- user_id: string;
1842
- is_test: boolean;
1843
- timestamp: number;
1844
- hash: string;
1845
- }>;
1929
+ }): Promise<T>;
1846
1930
  /**
1847
1931
  * Lists the tickets the signed-in user has consumed, with optional filters and pagination.
1848
1932
  * @param params Request parameters.
@@ -1861,9 +1945,29 @@ declare class Skapi {
1861
1945
  * @returns A promise that resolves to Promise<DatabaseResponse<any>>.
1862
1946
  */
1863
1947
  getTickets(params: {
1864
- /** Absent = every ticket. "<id>" = that ticket. "#<id>#" = the consumption log of that ticket (project owner only). */
1948
+ /** Absent = every ticket. "<id>" = that ticket. "#<id>#" = the consumption log of that ticket, "@<id>#<consume id>#" the action rows of one consumption (project owner only). */
1865
1949
  ticket_id?: string;
1950
+ /** A log listing only: rows from this time on, in milliseconds since the epoch. */
1951
+ from?: number;
1952
+ /** A log listing only: rows up to this time, in milliseconds since the epoch. */
1953
+ to?: number;
1866
1954
  }, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any>>;
1955
+ /**
1956
+ * Deletes a ticket's log rows before a time, in the background over the next minutes. The ticket's
1957
+ * remaining count and its per-user limits are unchanged. Project owner only.
1958
+ * @param params Request parameters.
1959
+ * @returns A promise that resolves to Promise<{ message: string; ticket_id: string; before: number }>, `before` being the time applied (later than now is clipped to now).
1960
+ */
1961
+ clearTicketLog(params: {
1962
+ /** The ticket whose log rows go. */
1963
+ ticket_id: string;
1964
+ /** Rows before this time, in milliseconds since the epoch. Default: now. */
1965
+ before?: number;
1966
+ }): Promise<{
1967
+ message: string;
1968
+ ticket_id: string;
1969
+ before: number;
1970
+ }>;
1867
1971
  /**
1868
1972
  * Closes the active realtime WebSocket connection.
1869
1973
  * @returns A promise that resolves to Promise<void>.
@@ -3010,4 +3114,4 @@ declare class SkapiError extends Error {
3010
3114
  });
3011
3115
  }
3012
3116
 
3013
- export { type BinaryFile, type Condition, type Connection, type ConnectionInfo, type DatabaseResponse, type DelRecordQuery, type FetchOptions, type FileInfo, type Form, type GetRecordQuery, type Index, type Newsletter, type NewsletterGroup, type PostRecordConfig, type ProgressCallback, type RTCConnector, type RTCConnectorParams, type RTCEvent, type RTCReceiverParams, type RTCResolved, type RealtimeCallback, type RecordData, Skapi, SkapiError, type Subscription, type Table, type Tag, type Ticket, type TicketAction, type TicketCondition, type TicketConditionOperator, type TicketConditionRow, type TicketError, type TicketErrorCode, type TicketResponseCondition, type TicketSignatureCondition, Types, type UniqueId, type UserAttributes, type UserProfile, type UserPublic, type WebSocketMessage };
3117
+ export { type BinaryFile, type Condition, type Connection, type ConnectionInfo, type DatabaseResponse, type DelRecordQuery, type FetchOptions, type FileInfo, type Form, type GetRecordQuery, type Index, type Newsletter, type NewsletterGroup, type PostRecordConfig, type ProgressCallback, type RTCConnector, type RTCConnectorParams, type RTCEvent, type RTCReceiverParams, type RTCResolved, type RealtimeCallback, type RecordData, Skapi, SkapiError, type Subscription, type Table, type Tag, type Ticket, type TicketAction, type TicketAnswerCondition, type TicketCondition, type TicketConditionOperator, type TicketConditionRow, type TicketError, type TicketErrorCode, type TicketReceipt, type TicketResponseCondition, type TicketSignatureCondition, Types, type UniqueId, type UserAttributes, type UserProfile, type UserPublic, type WebSocketMessage };
package/dist/skapi.d.ts CHANGED
@@ -864,43 +864,57 @@ type TicketResponseCondition = Pick<TicketCondition, 'headers' | 'data' | 'user'
864
864
  * | `${user}`, `${user[key]}` | The signed-in user's attributes. Signed requests only. |
865
865
  * | `${ip}`, `${user_agent}`, `${method}` | The caller's IP address, User-Agent and HTTP method. |
866
866
  * | `${record_access}` | The record ID the condition's `record_access` names. Signed requests only. |
867
- * | `${response}`, `${response[key]}` | The parsed body of the enclosing req action's response. Only in that req's nested `actions` and their `err` chains. |
868
- * | `${result}`, `${result[key]}` | The result of the previous action in the same chain. A nested chain and an `err` chain start without one. |
867
+ * | `${response}`, `${response[key]}` | The answer of the enclosing action, in its Then chain (`actions`) and the `err` chains inside it: the record a pstr posted, the parsed body of a req's response, the SUCCESS text of acsg and acsr. |
869
868
  * | `${error}`, `${error[key]}` | In an `err` chain, the failure: `code`, `message`, `detail`, `action` (the act) and `path`. |
870
- * | `${ticket}`, `${ticket[key]}` | This consumption: `id`, `service`, `owner`, `consume_id` and `timestamp`. |
869
+ * | `${ticket}`, `${ticket[key]}` | This consumption: `id`, `service`, `owner`, `consume_id`, `timestamp` and `hash`. |
871
870
  * | `${CLIENT_SECRET}` | Reserved. See `secretName` on the req action. |
872
871
  *
873
872
  * Registration refuses anything else inside `${ }` (an unknown root such as `${id}`, keys under
874
873
  * a root that takes none such as `${ip[x]}`, `${placeholder}` or `${headers}` without a key,
875
- * broken brackets) with a message listing these forms, and a reference written where it can
876
- * never resolve (`${response}` outside a req's nested actions, `${error}` outside an `err`
874
+ * broken brackets) with a message listing these forms, `${result}` (gone: an answer is read as
875
+ * `${response}` in the action's Then chain, or captured by its Check), and a reference written
876
+ * where it can never resolve (`${response}` outside a Then chain, `${error}` outside an `err`
877
877
  * chain, `${record_access}` when the condition names no record). When the action runs, a
878
878
  * reference that does not resolve fails it before it does anything: PATH_NOT_FOUND,
879
879
  * PLACEHOLDER_MISSING for a placeholder that was never captured, or AUTH_REQUIRED for `${user}`
880
880
  * on a request that is not signed in. Its `err` chain runs and the consumption stops.
881
+ *
882
+ * Every action but resp and cond answers something (the record, the response body, a SUCCESS
883
+ * text) and may carry a Check (`condition`: rows on that answer, a key "" the whole text; a miss
884
+ * fails the action) and a Then chain (`actions`, reading the answer as `${response}`). `retry:
885
+ * true` on acsg, acsr, pstr and req tries a failure again, up to 3 more times, 1, 2 and 4
886
+ * seconds apart, while the time budget holds them; never for a failure inside Then.
881
887
  */
882
888
  type TicketAction = {
883
- /** Set the access group of a user. */
889
+ /** Set the access group of a user. Answers the SUCCESS text the grant returns. */
884
890
  act: 'acsg';
885
891
  exe: {
886
892
  /** 1 ~ 99, or "admin", or a reference that gives one when the action runs, such as "${placeholder[GROUP]}". */
887
893
  group: number | 'admin' | `${string}\${${string}}${string}`;
888
894
  /** Blank = the consumer (signed-in consumption only). The project owner cannot be a target. */
889
895
  user_id?: string;
896
+ /** The Check: rows on the answer. */
897
+ condition?: TicketAnswerCondition;
898
+ /** The Then chain, reading the answer as `${response}`. */
899
+ actions?: TicketAction[];
890
900
  };
891
901
  err?: TicketAction[];
902
+ retry?: boolean;
892
903
  } | {
893
- /** Grant private access to a record. */
904
+ /** Grant private access to a record. Answers the SUCCESS text the grant returns. */
894
905
  act: 'acsr';
895
906
  exe: {
896
907
  /** A record ID, not a unique ID. */
897
908
  record_id: string;
898
909
  /** Blank = the consumer. */
899
910
  user_id?: string | string[];
911
+ condition?: TicketAnswerCondition;
912
+ actions?: TicketAction[];
900
913
  };
901
914
  err?: TicketAction[];
915
+ retry?: boolean;
902
916
  } | {
903
- /** Post a record. Everything but `user_id` is the payload postRecord() sends, so the same rules apply. A `unique_id` makes a retried webhook update the same record instead of adding one. */
917
+ /** Post a record. Everything but `user_id` is the payload postRecord() sends, so the same rules apply. A `unique_id` makes a retried webhook update the same record instead of adding one. Answers the record (RecordData). */
904
918
  act: 'pstr';
905
919
  exe: {
906
920
  table: string | {
@@ -922,10 +936,15 @@ type TicketAction = {
922
936
  source?: PostRecordConfig['source'];
923
937
  /** Post as this user instead of the project owner. */
924
938
  user_id?: string;
939
+ /** The Check: rows on the record posted, such as `record_id`. */
940
+ condition?: TicketAnswerCondition;
941
+ /** The Then chain, reading the record as `${response}` (`${response[record_id]}`). */
942
+ actions?: TicketAction[];
925
943
  };
926
944
  err?: TicketAction[];
945
+ retry?: boolean;
927
946
  } | {
928
- /** HTTP request with its own response condition and nested chain. Result: the parsed response body. */
947
+ /** HTTP request with its own response condition and nested chain. Answers the parsed response body. */
929
948
  act: 'req';
930
949
  exe: {
931
950
  /**
@@ -1000,6 +1019,73 @@ type TicketAction = {
1000
1019
  actions?: TicketAction[];
1001
1020
  };
1002
1021
  err?: TicketAction[];
1022
+ retry?: boolean;
1023
+ } | {
1024
+ /**
1025
+ * Respond: answers the consumer now, then stops or goes on. One per run: a second Respond
1026
+ * on a path that already answered is refused at registration, and ALREADY_RESPONDED when
1027
+ * it runs. consumeTicket() resolves with the body (or the receipt), whatever the status.
1028
+ */
1029
+ act: 'resp';
1030
+ exe: {
1031
+ /** The HTTP status, 100 to 599, or a reference. Default 200. An error status is still an answer, not a failure. */
1032
+ status?: number | string;
1033
+ /** Any JSON, templated; absent: the receipt { tkid, hash }. A `stage` key is refused (that is how an error is told apart). */
1034
+ body?: any;
1035
+ /**
1036
+ * What happens after the answer. Absent or "stop": the rest of the chain does not run.
1037
+ * "0m": goes on at once, in the background. "<n>m" | "<n>h" | "<n>d" (n >= 1): goes on
1038
+ * after that delay, to the minute. A number: a time in ms since the epoch, to the second
1039
+ * (a literal in the past is refused at registration; a templated one goes on at once).
1040
+ * A run that goes on counts toward the plan's queued ticket runs for the month; Free and
1041
+ * Standard stop at theirs (QUOTA_EXCEEDED), Premium is billed past it.
1042
+ */
1043
+ resume?: 'stop' | '0m' | `${number}m` | `${number}h` | `${number}d` | number | string;
1044
+ };
1045
+ err?: TicketAction[];
1046
+ } | {
1047
+ /**
1048
+ * Condition: rows inside a chain, under the rules of the ticket's own condition. A part
1049
+ * that fails fails the chain here with CONDITION_FAILED (the action's `err` chain runs).
1050
+ * Answers nothing. `response` rows only inside a Then chain, `error` rows only inside an
1051
+ * `err` chain, `placeholder` rows name placeholders (and may compare with null).
1052
+ */
1053
+ act: 'cond';
1054
+ exe: {
1055
+ data?: TicketConditionRow[];
1056
+ params?: TicketConditionRow[];
1057
+ headers?: TicketCondition['headers'];
1058
+ ip?: TicketCondition['ip'];
1059
+ user_agent?: TicketCondition['user_agent'];
1060
+ user?: TicketCondition['user'];
1061
+ record_access?: string;
1062
+ placeholder?: {
1063
+ key: string;
1064
+ operator: TicketConditionOperator;
1065
+ value: any;
1066
+ }[];
1067
+ response?: TicketConditionRow[];
1068
+ error?: TicketConditionRow[];
1069
+ };
1070
+ err?: TicketAction[];
1071
+ };
1072
+ /** The Check of an action: rows on its answer (TicketConditionRow, keys paths in the answer; "" is the whole answer as text). */
1073
+ type TicketAnswerCondition = {
1074
+ data?: TicketConditionRow[];
1075
+ };
1076
+ /** What a consumption answers when no Respond action composes the answer. */
1077
+ type TicketReceipt = {
1078
+ ticket_id: string;
1079
+ /** Id of this consumption: base62 of the timestamp in milliseconds, followed by 4 random characters. */
1080
+ consume_id: string;
1081
+ /** The consumer. The user id on the signed-in endpoint, else "<ip>(<user agent>)". */
1082
+ user_id: string;
1083
+ /** Always false here: dry runs go through the check URL, which consumeTicket() never calls. */
1084
+ is_test: boolean;
1085
+ /** When the consumption happened, in milliseconds. Decoded from consume_id. */
1086
+ timestamp: number;
1087
+ /** Proof string of the consumption. */
1088
+ hash: string;
1003
1089
  };
1004
1090
  /** An issued ticket as getTickets() and registerTicket() return it. */
1005
1091
  type Ticket = {
@@ -1026,7 +1112,7 @@ type Ticket = {
1026
1112
  */
1027
1113
  legacy?: boolean;
1028
1114
  };
1029
- type TicketErrorCode = 'INVALID_SERVICE' | 'SERVICE_DISABLED' | 'TICKET_NOT_FOUND' | 'TICKET_EXPIRED' | 'TICKET_EXHAUSTED' | 'USER_LIMIT_REACHED' | 'ISSUER_CANNOT_CONSUME' | 'AUTH_REQUIRED' | 'METHOD_NOT_ALLOWED' | 'CONDITION_FAILED' | 'PATH_NOT_FOUND' | 'PLACEHOLDER_MISSING' | 'REQUEST_FAILED' | 'TIMEOUT' | 'ACTION_FAILED' | 'ACTION_FORBIDDEN' | 'INTERNAL_ERROR';
1115
+ type TicketErrorCode = 'INVALID_SERVICE' | 'SERVICE_DISABLED' | 'TICKET_NOT_FOUND' | 'TICKET_EXPIRED' | 'TICKET_EXHAUSTED' | 'USER_LIMIT_REACHED' | 'ISSUER_CANNOT_CONSUME' | 'AUTH_REQUIRED' | 'METHOD_NOT_ALLOWED' | 'CONDITION_FAILED' | 'PATH_NOT_FOUND' | 'PLACEHOLDER_MISSING' | 'REQUEST_FAILED' | 'TIMEOUT' | 'ACTION_FAILED' | 'ACTION_FORBIDDEN' | 'QUOTA_EXCEEDED' | 'ALREADY_RESPONDED' | 'INTERNAL_ERROR';
1030
1116
  /**
1031
1117
  * The body a consume endpoint answers with when the consumption fails, and the `cause` of the
1032
1118
  * SkapiError consumeTicket() rejects with. A success body never has `stage`; an error body
@@ -1090,11 +1176,13 @@ type Types_Table = Table;
1090
1176
  type Types_Tag = Tag;
1091
1177
  type Types_Ticket = Ticket;
1092
1178
  type Types_TicketAction = TicketAction;
1179
+ type Types_TicketAnswerCondition = TicketAnswerCondition;
1093
1180
  type Types_TicketCondition = TicketCondition;
1094
1181
  type Types_TicketConditionOperator = TicketConditionOperator;
1095
1182
  type Types_TicketConditionRow = TicketConditionRow;
1096
1183
  type Types_TicketError = TicketError;
1097
1184
  type Types_TicketErrorCode = TicketErrorCode;
1185
+ type Types_TicketReceipt = TicketReceipt;
1098
1186
  type Types_TicketResponseCondition = TicketResponseCondition;
1099
1187
  type Types_TicketSignatureCondition = TicketSignatureCondition;
1100
1188
  type Types_UniqueId = UniqueId;
@@ -1103,7 +1191,7 @@ type Types_UserProfile = UserProfile;
1103
1191
  type Types_UserPublic = UserPublic;
1104
1192
  type Types_WebSocketMessage = WebSocketMessage;
1105
1193
  declare namespace Types {
1106
- export type { Types_BinaryFile as BinaryFile, Types_Condition as Condition, Types_Connection as Connection, Types_ConnectionInfo as ConnectionInfo, Types_DatabaseResponse as DatabaseResponse, Types_DelRecordQuery as DelRecordQuery, Types_EncryptionOptions as EncryptionOptions, Types_FetchOptions as FetchOptions, Types_FileInfo as FileInfo, Types_Form as Form, Types_GetRecordQuery as GetRecordQuery, Types_Index as Index, Types_Newsletter as Newsletter, Types_NewsletterGroup as NewsletterGroup, Types_PostRecordConfig as PostRecordConfig, Types_ProgressCallback as ProgressCallback, Types_RTCConnector as RTCConnector, Types_RTCConnectorParams as RTCConnectorParams, Types_RTCEvent as RTCEvent, Types_RTCReceiverParams as RTCReceiverParams, Types_RTCResolved as RTCResolved, Types_RealtimeCallback as RealtimeCallback, Types_RecordData as RecordData, Types_RecordEncryptionInfo as RecordEncryptionInfo, Types_RequestHistory as RequestHistory, Types_Subscription as Subscription, Types_Table as Table, Types_Tag as Tag, Types_Ticket as Ticket, Types_TicketAction as TicketAction, Types_TicketCondition as TicketCondition, Types_TicketConditionOperator as TicketConditionOperator, Types_TicketConditionRow as TicketConditionRow, Types_TicketError as TicketError, Types_TicketErrorCode as TicketErrorCode, Types_TicketResponseCondition as TicketResponseCondition, Types_TicketSignatureCondition as TicketSignatureCondition, Types_UniqueId as UniqueId, Types_UserAttributes as UserAttributes, Types_UserProfile as UserProfile, Types_UserPublic as UserPublic, Types_WebSocketMessage as WebSocketMessage };
1194
+ export type { Types_BinaryFile as BinaryFile, Types_Condition as Condition, Types_Connection as Connection, Types_ConnectionInfo as ConnectionInfo, Types_DatabaseResponse as DatabaseResponse, Types_DelRecordQuery as DelRecordQuery, Types_EncryptionOptions as EncryptionOptions, Types_FetchOptions as FetchOptions, Types_FileInfo as FileInfo, Types_Form as Form, Types_GetRecordQuery as GetRecordQuery, Types_Index as Index, Types_Newsletter as Newsletter, Types_NewsletterGroup as NewsletterGroup, Types_PostRecordConfig as PostRecordConfig, Types_ProgressCallback as ProgressCallback, Types_RTCConnector as RTCConnector, Types_RTCConnectorParams as RTCConnectorParams, Types_RTCEvent as RTCEvent, Types_RTCReceiverParams as RTCReceiverParams, Types_RTCResolved as RTCResolved, Types_RealtimeCallback as RealtimeCallback, Types_RecordData as RecordData, Types_RecordEncryptionInfo as RecordEncryptionInfo, Types_RequestHistory as RequestHistory, Types_Subscription as Subscription, Types_Table as Table, Types_Tag as Tag, Types_Ticket as Ticket, Types_TicketAction as TicketAction, Types_TicketAnswerCondition as TicketAnswerCondition, Types_TicketCondition as TicketCondition, Types_TicketConditionOperator as TicketConditionOperator, Types_TicketConditionRow as TicketConditionRow, Types_TicketError as TicketError, Types_TicketErrorCode as TicketErrorCode, Types_TicketReceipt as TicketReceipt, Types_TicketResponseCondition as TicketResponseCondition, Types_TicketSignatureCondition as TicketSignatureCondition, Types_UniqueId as UniqueId, Types_UserAttributes as UserAttributes, Types_UserProfile as UserProfile, Types_UserPublic as UserPublic, Types_WebSocketMessage as WebSocketMessage };
1107
1195
  }
1108
1196
 
1109
1197
  declare function terminatePendingRequests(): void;
@@ -1818,13 +1906,16 @@ declare class Skapi {
1818
1906
  * its actions run. An anonymous POST goes to `/tp/`, an anonymous GET to `/tg/` with `data`
1819
1907
  * as the query string, and a signed-in consumption (`auth: true`) to `/tpa/`, which is POST only.
1820
1908
  *
1909
+ * Resolves with the receipt (TicketReceipt: ticket_id, consume_id, user_id, is_test, timestamp, hash),
1910
+ * or with the body a Respond action of the ticket answered, as sent and whatever its status. `T` names that body.
1911
+ *
1821
1912
  * A failed consumption rejects with a SkapiError: `err.code` is the ticket error code and
1822
1913
  * `err.cause` the flat TicketError body (`err.cause.stage`, `err.cause.action`, `err.cause.detail`).
1823
1914
  * This holds when the ticket answers HTTP 200 as well (`return200`): the body is inspected, not the status.
1824
1915
  * @param params Request parameters.
1825
- * @returns A promise that resolves to Promise<{ ticket_id: string; consume_id: string; user_id: string; is_test: boolean; timestamp: number; hash: string; }>.
1916
+ * @returns A promise that resolves to Promise<T>, the receipt or the Respond body.
1826
1917
  */
1827
- consumeTicket(params: {
1918
+ consumeTicket<T = TicketReceipt>(params: {
1828
1919
  /** ID of the ticket to consume. */
1829
1920
  ticket_id: string;
1830
1921
  /** "GET" or "POST". */
@@ -1835,14 +1926,7 @@ declare class Skapi {
1835
1926
  data?: {
1836
1927
  [key: string]: any;
1837
1928
  };
1838
- }): Promise<{
1839
- ticket_id: string;
1840
- consume_id: string;
1841
- user_id: string;
1842
- is_test: boolean;
1843
- timestamp: number;
1844
- hash: string;
1845
- }>;
1929
+ }): Promise<T>;
1846
1930
  /**
1847
1931
  * Lists the tickets the signed-in user has consumed, with optional filters and pagination.
1848
1932
  * @param params Request parameters.
@@ -1861,9 +1945,29 @@ declare class Skapi {
1861
1945
  * @returns A promise that resolves to Promise<DatabaseResponse<any>>.
1862
1946
  */
1863
1947
  getTickets(params: {
1864
- /** Absent = every ticket. "<id>" = that ticket. "#<id>#" = the consumption log of that ticket (project owner only). */
1948
+ /** Absent = every ticket. "<id>" = that ticket. "#<id>#" = the consumption log of that ticket, "@<id>#<consume id>#" the action rows of one consumption (project owner only). */
1865
1949
  ticket_id?: string;
1950
+ /** A log listing only: rows from this time on, in milliseconds since the epoch. */
1951
+ from?: number;
1952
+ /** A log listing only: rows up to this time, in milliseconds since the epoch. */
1953
+ to?: number;
1866
1954
  }, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any>>;
1955
+ /**
1956
+ * Deletes a ticket's log rows before a time, in the background over the next minutes. The ticket's
1957
+ * remaining count and its per-user limits are unchanged. Project owner only.
1958
+ * @param params Request parameters.
1959
+ * @returns A promise that resolves to Promise<{ message: string; ticket_id: string; before: number }>, `before` being the time applied (later than now is clipped to now).
1960
+ */
1961
+ clearTicketLog(params: {
1962
+ /** The ticket whose log rows go. */
1963
+ ticket_id: string;
1964
+ /** Rows before this time, in milliseconds since the epoch. Default: now. */
1965
+ before?: number;
1966
+ }): Promise<{
1967
+ message: string;
1968
+ ticket_id: string;
1969
+ before: number;
1970
+ }>;
1867
1971
  /**
1868
1972
  * Closes the active realtime WebSocket connection.
1869
1973
  * @returns A promise that resolves to Promise<void>.
@@ -3010,4 +3114,4 @@ declare class SkapiError extends Error {
3010
3114
  });
3011
3115
  }
3012
3116
 
3013
- export { type BinaryFile, type Condition, type Connection, type ConnectionInfo, type DatabaseResponse, type DelRecordQuery, type FetchOptions, type FileInfo, type Form, type GetRecordQuery, type Index, type Newsletter, type NewsletterGroup, type PostRecordConfig, type ProgressCallback, type RTCConnector, type RTCConnectorParams, type RTCEvent, type RTCReceiverParams, type RTCResolved, type RealtimeCallback, type RecordData, Skapi, SkapiError, type Subscription, type Table, type Tag, type Ticket, type TicketAction, type TicketCondition, type TicketConditionOperator, type TicketConditionRow, type TicketError, type TicketErrorCode, type TicketResponseCondition, type TicketSignatureCondition, Types, type UniqueId, type UserAttributes, type UserProfile, type UserPublic, type WebSocketMessage };
3117
+ export { type BinaryFile, type Condition, type Connection, type ConnectionInfo, type DatabaseResponse, type DelRecordQuery, type FetchOptions, type FileInfo, type Form, type GetRecordQuery, type Index, type Newsletter, type NewsletterGroup, type PostRecordConfig, type ProgressCallback, type RTCConnector, type RTCConnectorParams, type RTCEvent, type RTCReceiverParams, type RTCResolved, type RealtimeCallback, type RecordData, Skapi, SkapiError, type Subscription, type Table, type Tag, type Ticket, type TicketAction, type TicketAnswerCondition, type TicketCondition, type TicketConditionOperator, type TicketConditionRow, type TicketError, type TicketErrorCode, type TicketReceipt, type TicketResponseCondition, type TicketSignatureCondition, Types, type UniqueId, type UserAttributes, type UserProfile, type UserPublic, type WebSocketMessage };