@wix/sdk-types 1.5.10 → 1.6.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.
@@ -1,4 +1,4 @@
1
- // src/webhooks.ts
1
+ // src/event-handlers-modules.ts
2
2
  function EventDefinition(type, isDomainEvent = false, _transformations = {}) {
3
3
  return () => ({
4
4
  __type: "event-definition",
package/build/index.d.mts CHANGED
@@ -42,7 +42,9 @@ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctio
42
42
  type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) => AuthenticationStrategy<Host, WithAuth>) | undefined = undefined> = {
43
43
  getAuthHeaders: (host: Host) => Promise<{
44
44
  headers: Record<string, string>;
45
- }>;
45
+ }> | {
46
+ headers: Record<string, string>;
47
+ };
46
48
  decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
47
49
  decoded: {
48
50
  data: string;
@@ -54,7 +56,9 @@ type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) =>
54
56
  type BoundAuthenticationStrategy = {
55
57
  getAuthHeaders: () => Promise<{
56
58
  headers: Record<string, string>;
57
- }>;
59
+ }> | {
60
+ headers: Record<string, string>;
61
+ };
58
62
  };
59
63
 
60
64
  type EventDefinition<Payload = unknown, Type extends string = string> = {
@@ -88,10 +92,13 @@ type DomainEvent<ActionType extends 'create' | 'update' | 'delete' | 'action', P
88
92
  } : ActionType extends 'delete' ? {
89
93
  deletedEvent: Payload;
90
94
  } : never);
95
+ type PayloadOfEventDefinition<T extends EventDefinition<any, any>> = T extends EventDefinition<infer P, any> ? P : never;
96
+ type EventHandler<T extends EventDefinition> = (payload: PayloadOfEventDefinition<T>, metadata: unknown) => void | Promise<void>;
97
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
91
98
 
92
99
  type SPIDefinition<TInput, TResult> = {
93
100
  __input: TInput;
94
101
  __result: TResult;
95
102
  };
96
103
 
97
- export { type APIMetadata, type AuthenticationStrategy, type BoundAuthenticationStrategy, type BuildRESTFunction, type DomainEvent, EventDefinition, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type SPIDefinition };
104
+ export { type APIMetadata, type AuthenticationStrategy, type BoundAuthenticationStrategy, type BuildEventDefinition, type BuildRESTFunction, type DomainEvent, EventDefinition, type EventHandler, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type SPIDefinition };
package/build/index.d.ts CHANGED
@@ -42,7 +42,9 @@ type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctio
42
42
  type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) => AuthenticationStrategy<Host, WithAuth>) | undefined = undefined> = {
43
43
  getAuthHeaders: (host: Host) => Promise<{
44
44
  headers: Record<string, string>;
45
- }>;
45
+ }> | {
46
+ headers: Record<string, string>;
47
+ };
46
48
  decodeJWT?: (token: string, verifyCallerClaims?: boolean) => Promise<{
47
49
  decoded: {
48
50
  data: string;
@@ -54,7 +56,9 @@ type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) =>
54
56
  type BoundAuthenticationStrategy = {
55
57
  getAuthHeaders: () => Promise<{
56
58
  headers: Record<string, string>;
57
- }>;
59
+ }> | {
60
+ headers: Record<string, string>;
61
+ };
58
62
  };
59
63
 
60
64
  type EventDefinition<Payload = unknown, Type extends string = string> = {
@@ -88,10 +92,13 @@ type DomainEvent<ActionType extends 'create' | 'update' | 'delete' | 'action', P
88
92
  } : ActionType extends 'delete' ? {
89
93
  deletedEvent: Payload;
90
94
  } : never);
95
+ type PayloadOfEventDefinition<T extends EventDefinition<any, any>> = T extends EventDefinition<infer P, any> ? P : never;
96
+ type EventHandler<T extends EventDefinition> = (payload: PayloadOfEventDefinition<T>, metadata: unknown) => void | Promise<void>;
97
+ type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
91
98
 
92
99
  type SPIDefinition<TInput, TResult> = {
93
100
  __input: TInput;
94
101
  __result: TResult;
95
102
  };
96
103
 
97
- export { type APIMetadata, type AuthenticationStrategy, type BoundAuthenticationStrategy, type BuildRESTFunction, type DomainEvent, EventDefinition, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type SPIDefinition };
104
+ export { type APIMetadata, type AuthenticationStrategy, type BoundAuthenticationStrategy, type BuildEventDefinition, type BuildRESTFunction, type DomainEvent, EventDefinition, type EventHandler, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type SPIDefinition };
package/build/index.js CHANGED
@@ -24,7 +24,7 @@ __export(src_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
- // src/webhooks.ts
27
+ // src/event-handlers-modules.ts
28
28
  function EventDefinition(type, isDomainEvent = false, _transformations = {}) {
29
29
  return () => ({
30
30
  __type: "event-definition",
package/build/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // src/webhooks.ts
1
+ // src/event-handlers-modules.ts
2
2
  function EventDefinition(type, isDomainEvent = false, _transformations = {}) {
3
3
  return () => ({
4
4
  __type: "event-definition",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-types",
3
- "version": "1.5.10",
3
+ "version": "1.6.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -57,5 +57,5 @@
57
57
  "wallaby": {
58
58
  "autoDetect": true
59
59
  },
60
- "falconPackageHash": "efb91115c561f417a9474bbbb64813644684f0305d8d0ea2a205132c"
60
+ "falconPackageHash": "dfd4b7c02207e404e4c5aef688534e4416df961e3a6b42271666041b"
61
61
  }