From 323b6bff8e16bc131f2f894c5cc711e3e69351f3 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 12:22:53 -0700 Subject: [PATCH] SDK regeneration (#78) Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> --- core/idempotent_request_option.go | 4 +- core/request_option.go | 2 +- messages.go | 10 +- option/idempotent_request_option.go | 4 +- tenants.go | 6 +- types.go | 706 +++++++++++++++++++++++++--- users/preferences.go | 38 +- users/tenants.go | 39 +- users/types.go | 38 ++ 9 files changed, 725 insertions(+), 122 deletions(-) diff --git a/core/idempotent_request_option.go b/core/idempotent_request_option.go index d396091..1832993 100644 --- a/core/idempotent_request_option.go +++ b/core/idempotent_request_option.go @@ -20,7 +20,7 @@ type IdempotentRequestOptions struct { *RequestOptions IdempotencyKey *string - IdempotencyExpiry *int + IdempotencyExpiry *string } // NewIdempotentRequestOptions returns a new *IdempotentRequestOptions value. @@ -51,7 +51,7 @@ func (i *IdempotencyKeyOption) applyIdempotentRequestOptions(opts *IdempotentReq // IdempotencyExpiryOption implements the RequestOption interface. type IdempotencyExpiryOption struct { - IdempotencyExpiry *int + IdempotencyExpiry *string } func (i *IdempotencyExpiryOption) applyIdempotentRequestOptions(opts *IdempotentRequestOptions) { diff --git a/core/request_option.go b/core/request_option.go index a8f45f1..f2daa6c 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -51,7 +51,7 @@ func (r *RequestOptions) cloneHeader() http.Header { headers := r.HTTPHeader.Clone() headers.Set("X-Fern-Language", "Go") headers.Set("X-Fern-SDK-Name", "github.com/trycourier/courier-go/v3") - headers.Set("X-Fern-SDK-Version", "v3.0.8") + headers.Set("X-Fern-SDK-Version", "v3.0.9") return headers } diff --git a/messages.go b/messages.go index a676209..eb545f4 100644 --- a/messages.go +++ b/messages.go @@ -16,7 +16,7 @@ type GetMessageHistoryRequest struct { type ListMessagesRequest struct { // A boolean value that indicates whether archived messages should be included in the response. Archived *bool `json:"-" url:"archived,omitempty"` - // A unique identifier that allows for fetching the next set of message statuses. + // A unique identifier that allows for fetching the next set of messages. Cursor *string `json:"-" url:"cursor,omitempty"` // A unique identifier representing the event that was used to send the event. Event *string `json:"-" url:"event,omitempty"` @@ -26,12 +26,18 @@ type ListMessagesRequest struct { MessageId *string `json:"-" url:"messageId,omitempty"` // A unique identifier representing the notification that was used to send the event. Notification *string `json:"-" url:"notification,omitempty"` + // The key assocated to the provider you want to filter on. E.g., sendgrid, inbox, twilio, slack, msteams, etc. Allows multiple values to be set in query parameters. + Provider []*string `json:"-" url:"provider,omitempty"` // A unique identifier representing the recipient associated with the requested profile. Recipient *string `json:"-" url:"recipient,omitempty"` - // An indicator of the current status of the message. Multiple status values can be passed in. + // An indicator of the current status of the message. Allows multiple values to be set in query parameters. Status []*string `json:"-" url:"status,omitempty"` + // A tag placed in the metadata.tags during a notification send. Allows multiple values to be set in query parameters. + Tag []*string `json:"-" url:"tag,omitempty"` // A comma delimited list of 'tags'. Messages will be returned if they match any of the tags passed in. Tags *string `json:"-" url:"tags,omitempty"` + // Messages sent with the context of a Tenant + TenantId *string `json:"-" url:"tenant_id,omitempty"` // The enqueued datetime of a message to filter out messages received before. EnqueuedAfter *string `json:"-" url:"enqueued_after,omitempty"` // The unique identifier used to trace the requests diff --git a/option/idempotent_request_option.go b/option/idempotent_request_option.go index 8a21de8..9c56236 100644 --- a/option/idempotent_request_option.go +++ b/option/idempotent_request_option.go @@ -17,7 +17,9 @@ func WithIdempotencyKey(idempotencyKey *string) *core.IdempotencyKeyOption { } // WithIdempotencyExpiry sets the idempotencyExpiry request header. -func WithIdempotencyExpiry(idempotencyExpiry *int) *core.IdempotencyExpiryOption { +// +// The expiry can either be an ISO8601 datetime or a duration like "1 Day". +func WithIdempotencyExpiry(idempotencyExpiry *string) *core.IdempotencyExpiryOption { return &core.IdempotencyExpiryOption{ IdempotencyExpiry: idempotencyExpiry, } diff --git a/tenants.go b/tenants.go index 69a8952..f9a02e4 100644 --- a/tenants.go +++ b/tenants.go @@ -16,7 +16,7 @@ type TenantCreateOrReplaceParams struct { // Defines the preferences used for the tenant when the user hasn't specified their own. DefaultPreferences *DefaultPreferences `json:"default_preferences,omitempty" url:"default_preferences,omitempty"` // Arbitrary properties accessible to a template. - Properties []TemplateProperty `json:"properties,omitempty" url:"properties,omitempty"` + Properties map[string]interface{} `json:"properties,omitempty" url:"properties,omitempty"` // A user profile object merged with user profile on send. UserProfile map[string]interface{} `json:"user_profile,omitempty" url:"user_profile,omitempty"` // Brand to be used for the account when one is not specified by the send call. @@ -130,8 +130,6 @@ func (l *ListUsersForTenantResponse) String() string { return fmt.Sprintf("%#v", l) } -type TemplateProperty = interface{} - type Tenant struct { // Id of the tenant. Id string `json:"id" url:"id"` @@ -142,7 +140,7 @@ type Tenant struct { // Defines the preferences used for the account when the user hasn't specified their own. DefaultPreferences *DefaultPreferences `json:"default_preferences,omitempty" url:"default_preferences,omitempty"` // Arbitrary properties accessible to a template. - Properties *TemplateProperty `json:"properties,omitempty" url:"properties,omitempty"` + Properties map[string]interface{} `json:"properties,omitempty" url:"properties,omitempty"` // A user profile object merged with user profile on send. UserProfile map[string]interface{} `json:"user_profile,omitempty" url:"user_profile,omitempty"` // Brand to be used for the account when one is not specified by the send call. diff --git a/types.go b/types.go index e91415e..5b32df2 100644 --- a/types.go +++ b/types.go @@ -489,6 +489,35 @@ func (t *Target) String() string { return fmt.Sprintf("%#v", t) } +type AccessorType struct { + Ref string `json:"$ref" url:"$ref"` + + _rawJSON json.RawMessage +} + +func (a *AccessorType) UnmarshalJSON(data []byte) error { + type unmarshaler AccessorType + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AccessorType(value) + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AccessorType) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + type Automation struct { CancelationToken *string `json:"cancelation_token,omitempty" url:"cancelation_token,omitempty"` Steps []*AutomationStepOption `json:"steps,omitempty" url:"steps,omitempty"` @@ -519,6 +548,261 @@ func (a *Automation) String() string { return fmt.Sprintf("%#v", a) } +type AutomationAddToBatchMaxItemsType struct { + String string + Integer int +} + +func (a *AutomationAddToBatchMaxItemsType) UnmarshalJSON(data []byte) error { + var valueString string + if err := json.Unmarshal(data, &valueString); err == nil { + a.String = valueString + return nil + } + var valueInteger int + if err := json.Unmarshal(data, &valueInteger); err == nil { + a.Integer = valueInteger + return nil + } + return fmt.Errorf("%s cannot be deserialized as a %T", data, a) +} + +func (a AutomationAddToBatchMaxItemsType) MarshalJSON() ([]byte, error) { + if a.String != "" { + return json.Marshal(a.String) + } + if a.Integer != 0 { + return json.Marshal(a.Integer) + } + return nil, fmt.Errorf("type %T does not include a non-empty union type", a) +} + +type AutomationAddToBatchMaxItemsTypeVisitor interface { + VisitString(string) error + VisitInteger(int) error +} + +func (a *AutomationAddToBatchMaxItemsType) Accept(visitor AutomationAddToBatchMaxItemsTypeVisitor) error { + if a.String != "" { + return visitor.VisitString(a.String) + } + if a.Integer != 0 { + return visitor.VisitInteger(a.Integer) + } + return fmt.Errorf("type %T does not include a non-empty union type", a) +} + +// Defines what items should be retained and passed along to the next steps when the batch is released +type AutomationAddToBatchRetain struct { + // Keep N number of notifications based on the type. First/Last N based on notification received. + // highest/lowest based on a scoring key providing in the data accessed by sort_key + Type AutomationAddToBatchRetainType `json:"type,omitempty" url:"type,omitempty"` + // The number of records to keep in batch. Default is 10 and only configurable by requesting from support. + // When configurable minimum is 2 and maximum is 100. + Count int `json:"count" url:"count"` + // Defines the data value data[sort_key] that is used to sort the stored items. Required when type is set to highest or lowest. + SortKey *string `json:"sort_key,omitempty" url:"sort_key,omitempty"` + + _rawJSON json.RawMessage +} + +func (a *AutomationAddToBatchRetain) UnmarshalJSON(data []byte) error { + type unmarshaler AutomationAddToBatchRetain + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AutomationAddToBatchRetain(value) + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationAddToBatchRetain) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AutomationAddToBatchRetainType string + +const ( + AutomationAddToBatchRetainTypeFirst AutomationAddToBatchRetainType = "first" + AutomationAddToBatchRetainTypeLast AutomationAddToBatchRetainType = "last" + AutomationAddToBatchRetainTypeHighest AutomationAddToBatchRetainType = "highest" + AutomationAddToBatchRetainTypeLowest AutomationAddToBatchRetainType = "lowest" +) + +func NewAutomationAddToBatchRetainTypeFromString(s string) (AutomationAddToBatchRetainType, error) { + switch s { + case "first": + return AutomationAddToBatchRetainTypeFirst, nil + case "last": + return AutomationAddToBatchRetainTypeLast, nil + case "highest": + return AutomationAddToBatchRetainTypeHighest, nil + case "lowest": + return AutomationAddToBatchRetainTypeLowest, nil + } + var t AutomationAddToBatchRetainType + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AutomationAddToBatchRetainType) Ptr() *AutomationAddToBatchRetainType { + return &a +} + +type AutomationAddToBatchScope string + +const ( + AutomationAddToBatchScopeUser AutomationAddToBatchScope = "user" + AutomationAddToBatchScopeGlobal AutomationAddToBatchScope = "global" + AutomationAddToBatchScopeDynamic AutomationAddToBatchScope = "dynamic" +) + +func NewAutomationAddToBatchScopeFromString(s string) (AutomationAddToBatchScope, error) { + switch s { + case "user": + return AutomationAddToBatchScopeUser, nil + case "global": + return AutomationAddToBatchScopeGlobal, nil + case "dynamic": + return AutomationAddToBatchScopeDynamic, nil + } + var t AutomationAddToBatchScope + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AutomationAddToBatchScope) Ptr() *AutomationAddToBatchScope { + return &a +} + +type AutomationAddToBatchStep struct { + If *string `json:"if,omitempty" url:"if,omitempty"` + Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + // Defines the period of inactivity before the batch is released. Specified as an [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) + WaitPeriod string `json:"wait_period" url:"wait_period"` + // Defines the maximum wait time before the batch should be released. Must be less than wait period. Maximum of 60 days. Specified as an [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) + MaxWaitPeriod string `json:"max_wait_period" url:"max_wait_period"` + // If specified, the batch will release as soon as this number is reached + MaxItems *AutomationAddToBatchMaxItemsType `json:"max_items,omitempty" url:"max_items,omitempty"` + Retain *AutomationAddToBatchRetain `json:"retain,omitempty" url:"retain,omitempty"` + // Determine the scope of the batching. If user, chosen in this order: recipient, profile.user_id, data.user_id, data.userId. + // If dynamic, then specify where the batch_key or a reference to the batch_key + Scope *AutomationAddToBatchScope `json:"scope,omitempty" url:"scope,omitempty"` + // If using scope=dynamic, provide the key or a reference (e.g., refs.data.batch_key) + BatchKey *string `json:"batch_key,omitempty" url:"batch_key,omitempty"` + BatchId *string `json:"batch_id,omitempty" url:"batch_id,omitempty"` + // Defines the field of the data object the batch is set to when complete. Defaults to `batch` + CategoryKey *string `json:"category_key,omitempty" url:"category_key,omitempty"` + action string + + _rawJSON json.RawMessage +} + +func (a *AutomationAddToBatchStep) Action() string { + return a.action +} + +func (a *AutomationAddToBatchStep) UnmarshalJSON(data []byte) error { + type embed AutomationAddToBatchStep + var unmarshaler = struct { + embed + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AutomationAddToBatchStep(unmarshaler.embed) + a.action = "add-to-batch" + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationAddToBatchStep) MarshalJSON() ([]byte, error) { + type embed AutomationAddToBatchStep + var marshaler = struct { + embed + Action string `json:"action"` + }{ + embed: embed(*a), + Action: "add-to-batch", + } + return json.Marshal(marshaler) +} + +func (a *AutomationAddToBatchStep) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AutomationAddToDigestStep struct { + If *string `json:"if,omitempty" url:"if,omitempty"` + Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + // The subscription topic that has digests enabled + SubscriptionTopicId string `json:"subscription_topic_id" url:"subscription_topic_id"` + action string + + _rawJSON json.RawMessage +} + +func (a *AutomationAddToDigestStep) Action() string { + return a.action +} + +func (a *AutomationAddToDigestStep) UnmarshalJSON(data []byte) error { + type embed AutomationAddToDigestStep + var unmarshaler = struct { + embed + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AutomationAddToDigestStep(unmarshaler.embed) + a.action = "add-to-digest" + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationAddToDigestStep) MarshalJSON() ([]byte, error) { + type embed AutomationAddToDigestStep + var marshaler = struct { + embed + Action string `json:"action"` + }{ + embed: embed(*a), + Action: "add-to-digest", + } + return json.Marshal(marshaler) +} + +func (a *AutomationAddToDigestStep) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + type AutomationCancelStep struct { If *string `json:"if,omitempty" url:"if,omitempty"` Ref *string `json:"ref,omitempty" url:"ref,omitempty"` @@ -573,8 +857,11 @@ func (a *AutomationCancelStep) String() string { } type AutomationDelayStep struct { - If *string `json:"if,omitempty" url:"if,omitempty"` - Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + If *string `json:"if,omitempty" url:"if,omitempty"` + Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + // The [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) string for how long to delay for + Duration *string `json:"duration,omitempty" url:"duration,omitempty"` + // The ISO 8601 timestamp for when the delay should end Until *string `json:"until,omitempty" url:"until,omitempty"` action string @@ -625,6 +912,117 @@ func (a *AutomationDelayStep) String() string { return fmt.Sprintf("%#v", a) } +type AutomationFetchDataStep struct { + If *string `json:"if,omitempty" url:"if,omitempty"` + Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + Webhook *AutomationFetchDataWebhook `json:"webhook,omitempty" url:"webhook,omitempty"` + MergeStrategy MergeAlgorithm `json:"merge_strategy,omitempty" url:"merge_strategy,omitempty"` + IdempotencyExpiry *string `json:"idempotency_expiry,omitempty" url:"idempotency_expiry,omitempty"` + IdempotencyKey *string `json:"idempotency_key,omitempty" url:"idempotency_key,omitempty"` + action string + + _rawJSON json.RawMessage +} + +func (a *AutomationFetchDataStep) Action() string { + return a.action +} + +func (a *AutomationFetchDataStep) UnmarshalJSON(data []byte) error { + type embed AutomationFetchDataStep + var unmarshaler = struct { + embed + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AutomationFetchDataStep(unmarshaler.embed) + a.action = "fetch-data" + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationFetchDataStep) MarshalJSON() ([]byte, error) { + type embed AutomationFetchDataStep + var marshaler = struct { + embed + Action string `json:"action"` + }{ + embed: embed(*a), + Action: "fetch-data", + } + return json.Marshal(marshaler) +} + +func (a *AutomationFetchDataStep) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AutomationFetchDataWebhook struct { + Body map[string]interface{} `json:"body,omitempty" url:"body,omitempty"` + Headers map[string]interface{} `json:"headers,omitempty" url:"headers,omitempty"` + Params map[string]interface{} `json:"params,omitempty" url:"params,omitempty"` + Method AutomationFetchDataWebhookMethod `json:"method,omitempty" url:"method,omitempty"` + Url string `json:"url" url:"url"` + + _rawJSON json.RawMessage +} + +func (a *AutomationFetchDataWebhook) UnmarshalJSON(data []byte) error { + type unmarshaler AutomationFetchDataWebhook + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AutomationFetchDataWebhook(value) + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationFetchDataWebhook) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AutomationFetchDataWebhookMethod string + +const ( + AutomationFetchDataWebhookMethodGet AutomationFetchDataWebhookMethod = "GET" + AutomationFetchDataWebhookMethodPost AutomationFetchDataWebhookMethod = "POST" +) + +func NewAutomationFetchDataWebhookMethodFromString(s string) (AutomationFetchDataWebhookMethod, error) { + switch s { + case "GET": + return AutomationFetchDataWebhookMethodGet, nil + case "POST": + return AutomationFetchDataWebhookMethodPost, nil + } + var t AutomationFetchDataWebhookMethod + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AutomationFetchDataWebhookMethod) Ptr() *AutomationFetchDataWebhookMethod { + return &a +} + type AutomationInvokeStep struct { If *string `json:"if,omitempty" url:"if,omitempty"` Ref *string `json:"ref,omitempty" url:"ref,omitempty"` @@ -890,43 +1288,13 @@ func (a *AutomationStep) String() string { return fmt.Sprintf("%#v", a) } -type AutomationStepAction string - -const ( - AutomationStepActionCancel AutomationStepAction = "cancel" - AutomationStepActionDelay AutomationStepAction = "delay" - AutomationStepActionInvoke AutomationStepAction = "invoke" - AutomationStepActionSend AutomationStepAction = "send" - AutomationStepActionSendList AutomationStepAction = "send-list" - AutomationStepActionUpdateProfile AutomationStepAction = "update-profile" -) - -func NewAutomationStepActionFromString(s string) (AutomationStepAction, error) { - switch s { - case "cancel": - return AutomationStepActionCancel, nil - case "delay": - return AutomationStepActionDelay, nil - case "invoke": - return AutomationStepActionInvoke, nil - case "send": - return AutomationStepActionSend, nil - case "send-list": - return AutomationStepActionSendList, nil - case "update-profile": - return AutomationStepActionUpdateProfile, nil - } - var t AutomationStepAction - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (a AutomationStepAction) Ptr() *AutomationStepAction { - return &a -} - type AutomationStepOption struct { + AutomationAddToDigestStep *AutomationAddToDigestStep + AutomationAddToBatchStep *AutomationAddToBatchStep + AutomationThrottleStep *AutomationThrottleStep AutomationCancelStep *AutomationCancelStep AutomationDelayStep *AutomationDelayStep + AutomationFetchDataStep *AutomationFetchDataStep AutomationInvokeStep *AutomationInvokeStep AutomationSendStep *AutomationSendStep AutomationV2SendStep *AutomationV2SendStep @@ -935,6 +1303,21 @@ type AutomationStepOption struct { } func (a *AutomationStepOption) UnmarshalJSON(data []byte) error { + valueAutomationAddToDigestStep := new(AutomationAddToDigestStep) + if err := json.Unmarshal(data, &valueAutomationAddToDigestStep); err == nil { + a.AutomationAddToDigestStep = valueAutomationAddToDigestStep + return nil + } + valueAutomationAddToBatchStep := new(AutomationAddToBatchStep) + if err := json.Unmarshal(data, &valueAutomationAddToBatchStep); err == nil { + a.AutomationAddToBatchStep = valueAutomationAddToBatchStep + return nil + } + valueAutomationThrottleStep := new(AutomationThrottleStep) + if err := json.Unmarshal(data, &valueAutomationThrottleStep); err == nil { + a.AutomationThrottleStep = valueAutomationThrottleStep + return nil + } valueAutomationCancelStep := new(AutomationCancelStep) if err := json.Unmarshal(data, &valueAutomationCancelStep); err == nil { a.AutomationCancelStep = valueAutomationCancelStep @@ -945,6 +1328,11 @@ func (a *AutomationStepOption) UnmarshalJSON(data []byte) error { a.AutomationDelayStep = valueAutomationDelayStep return nil } + valueAutomationFetchDataStep := new(AutomationFetchDataStep) + if err := json.Unmarshal(data, &valueAutomationFetchDataStep); err == nil { + a.AutomationFetchDataStep = valueAutomationFetchDataStep + return nil + } valueAutomationInvokeStep := new(AutomationInvokeStep) if err := json.Unmarshal(data, &valueAutomationInvokeStep); err == nil { a.AutomationInvokeStep = valueAutomationInvokeStep @@ -974,12 +1362,24 @@ func (a *AutomationStepOption) UnmarshalJSON(data []byte) error { } func (a AutomationStepOption) MarshalJSON() ([]byte, error) { + if a.AutomationAddToDigestStep != nil { + return json.Marshal(a.AutomationAddToDigestStep) + } + if a.AutomationAddToBatchStep != nil { + return json.Marshal(a.AutomationAddToBatchStep) + } + if a.AutomationThrottleStep != nil { + return json.Marshal(a.AutomationThrottleStep) + } if a.AutomationCancelStep != nil { return json.Marshal(a.AutomationCancelStep) } if a.AutomationDelayStep != nil { return json.Marshal(a.AutomationDelayStep) } + if a.AutomationFetchDataStep != nil { + return json.Marshal(a.AutomationFetchDataStep) + } if a.AutomationInvokeStep != nil { return json.Marshal(a.AutomationInvokeStep) } @@ -999,8 +1399,12 @@ func (a AutomationStepOption) MarshalJSON() ([]byte, error) { } type AutomationStepOptionVisitor interface { + VisitAutomationAddToDigestStep(*AutomationAddToDigestStep) error + VisitAutomationAddToBatchStep(*AutomationAddToBatchStep) error + VisitAutomationThrottleStep(*AutomationThrottleStep) error VisitAutomationCancelStep(*AutomationCancelStep) error VisitAutomationDelayStep(*AutomationDelayStep) error + VisitAutomationFetchDataStep(*AutomationFetchDataStep) error VisitAutomationInvokeStep(*AutomationInvokeStep) error VisitAutomationSendStep(*AutomationSendStep) error VisitAutomationV2SendStep(*AutomationV2SendStep) error @@ -1009,12 +1413,24 @@ type AutomationStepOptionVisitor interface { } func (a *AutomationStepOption) Accept(visitor AutomationStepOptionVisitor) error { + if a.AutomationAddToDigestStep != nil { + return visitor.VisitAutomationAddToDigestStep(a.AutomationAddToDigestStep) + } + if a.AutomationAddToBatchStep != nil { + return visitor.VisitAutomationAddToBatchStep(a.AutomationAddToBatchStep) + } + if a.AutomationThrottleStep != nil { + return visitor.VisitAutomationThrottleStep(a.AutomationThrottleStep) + } if a.AutomationCancelStep != nil { return visitor.VisitAutomationCancelStep(a.AutomationCancelStep) } if a.AutomationDelayStep != nil { return visitor.VisitAutomationDelayStep(a.AutomationDelayStep) } + if a.AutomationFetchDataStep != nil { + return visitor.VisitAutomationFetchDataStep(a.AutomationFetchDataStep) + } if a.AutomationInvokeStep != nil { return visitor.VisitAutomationInvokeStep(a.AutomationInvokeStep) } @@ -1033,6 +1449,130 @@ func (a *AutomationStepOption) Accept(visitor AutomationStepOptionVisitor) error return fmt.Errorf("type %T does not include a non-empty union type", a) } +type AutomationThrottleOnThrottle struct { + // The node to go to if the request is throttled + NodeId string `json:"$node_id" url:"$node_id"` + + _rawJSON json.RawMessage +} + +func (a *AutomationThrottleOnThrottle) UnmarshalJSON(data []byte) error { + type unmarshaler AutomationThrottleOnThrottle + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AutomationThrottleOnThrottle(value) + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationThrottleOnThrottle) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AutomationThrottleScope string + +const ( + AutomationThrottleScopeUser AutomationThrottleScope = "user" + AutomationThrottleScopeGlobal AutomationThrottleScope = "global" + AutomationThrottleScopeDynamic AutomationThrottleScope = "dynamic" +) + +func NewAutomationThrottleScopeFromString(s string) (AutomationThrottleScope, error) { + switch s { + case "user": + return AutomationThrottleScopeUser, nil + case "global": + return AutomationThrottleScopeGlobal, nil + case "dynamic": + return AutomationThrottleScopeDynamic, nil + } + var t AutomationThrottleScope + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AutomationThrottleScope) Ptr() *AutomationThrottleScope { + return &a +} + +type AutomationThrottleStep struct { + If *string `json:"if,omitempty" url:"if,omitempty"` + Ref *string `json:"ref,omitempty" url:"ref,omitempty"` + // Maximum number of allowed notifications in that timeframe + MaxAllowed int `json:"max_allowed" url:"max_allowed"` + // Defines the throttle period which corresponds to the max_allowed. Specified as an ISO 8601 duration, https://en.wikipedia.org/wiki/ISO_8601#Durations + Period string `json:"period" url:"period"` + Scope AutomationThrottleScope `json:"scope,omitempty" url:"scope,omitempty"` + // If using scope=dynamic, provide the reference (e.g., refs.data.throttle_key) to the how the throttle should be identified + ThrottleKey *string `json:"throttle_key,omitempty" url:"throttle_key,omitempty"` + // Value must be true + OnThrottle *AutomationThrottleOnThrottle `json:"on_throttle,omitempty" url:"on_throttle,omitempty"` + action string + shouldAlert bool + + _rawJSON json.RawMessage +} + +func (a *AutomationThrottleStep) Action() string { + return a.action +} + +func (a *AutomationThrottleStep) ShouldAlert() bool { + return a.shouldAlert +} + +func (a *AutomationThrottleStep) UnmarshalJSON(data []byte) error { + type embed AutomationThrottleStep + var unmarshaler = struct { + embed + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AutomationThrottleStep(unmarshaler.embed) + a.action = "throttle" + a.shouldAlert = false + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AutomationThrottleStep) MarshalJSON() ([]byte, error) { + type embed AutomationThrottleStep + var marshaler = struct { + embed + Action string `json:"action"` + ShouldAlert bool `json:"should_alert"` + }{ + embed: embed(*a), + Action: "throttle", + ShouldAlert: false, + } + return json.Marshal(marshaler) +} + +func (a *AutomationThrottleStep) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + type AutomationUpdateProfileStep struct { RecipientId string `json:"recipient_id" url:"recipient_id"` Profile Profile `json:"profile,omitempty" url:"profile,omitempty"` @@ -2303,47 +2843,27 @@ func (r *Rule) String() string { type UserTenantAssociation struct { // User ID for the assocation between tenant and user - UserId string `json:"user_id" url:"user_id"` + UserId *string `json:"user_id,omitempty" url:"user_id,omitempty"` + Type *string `json:"type,omitempty" url:"type,omitempty"` // Tenant ID for the assocation between tenant and user - TenantId string `json:"tenant_id" url:"tenant_id"` - Profile map[string]interface{} `json:"profile,omitempty" url:"profile,omitempty"` - type_ string + TenantId string `json:"tenant_id" url:"tenant_id"` + // Additional metadata to be applied to a user profile when used in a tenant context + Profile map[string]interface{} `json:"profile,omitempty" url:"profile,omitempty"` _rawJSON json.RawMessage } -func (u *UserTenantAssociation) Type() string { - return u.type_ -} - func (u *UserTenantAssociation) UnmarshalJSON(data []byte) error { - type embed UserTenantAssociation - var unmarshaler = struct { - embed - }{ - embed: embed(*u), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { + type unmarshaler UserTenantAssociation + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { return err } - *u = UserTenantAssociation(unmarshaler.embed) - u.type_ = "user" + *u = UserTenantAssociation(value) u._rawJSON = json.RawMessage(data) return nil } -func (u *UserTenantAssociation) MarshalJSON() ([]byte, error) { - type embed UserTenantAssociation - var marshaler = struct { - embed - Type string `json:"type"` - }{ - embed: embed(*u), - Type: "user", - } - return json.Marshal(marshaler) -} - func (u *UserTenantAssociation) String() string { if len(u._rawJSON) > 0 { if value, err := core.StringifyJSON(u._rawJSON); err == nil { @@ -4091,6 +4611,36 @@ func (b *BaseMessage) String() string { return fmt.Sprintf("%#v", b) } +type BaseMessageSendTo struct { + // The recipient or a list of recipients of the message + To *MessageRecipient `json:"to,omitempty" url:"to,omitempty"` + + _rawJSON json.RawMessage +} + +func (b *BaseMessageSendTo) UnmarshalJSON(data []byte) error { + type unmarshaler BaseMessageSendTo + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *b = BaseMessageSendTo(value) + b._rawJSON = json.RawMessage(data) + return nil +} + +func (b *BaseMessageSendTo) String() string { + if len(b._rawJSON) > 0 { + if value, err := core.StringifyJSON(b._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(b); err == nil { + return value + } + return fmt.Sprintf("%#v", b) +} + type BaseSocialPresence struct { Url string `json:"url" url:"url"` @@ -4462,11 +5012,11 @@ type ContentMessage struct { // "Expiry allows you to set an absolute or relative time in which a message expires. // Note: This is only valid for the Courier Inbox channel as of 12-08-2022." Expiry *Expiry `json:"expiry,omitempty" url:"expiry,omitempty"` + // The recipient or a list of recipients of the message + To *MessageRecipient `json:"to,omitempty" url:"to,omitempty"` // Describes the content of the message in a way that will work for email, push, // chat, or any channel. Either this or template must be specified. Content *Content `json:"content,omitempty" url:"content,omitempty"` - // The recipient or a list of recipients of the message - To *MessageRecipient `json:"to,omitempty" url:"to,omitempty"` _rawJSON json.RawMessage } @@ -6205,6 +6755,7 @@ type Recipient struct { UserRecipient *UserRecipient SlackRecipient *SlackRecipient MsTeamsRecipient *MsTeamsRecipient + RecipientData RecipientData } func (r *Recipient) UnmarshalJSON(data []byte) error { @@ -6238,6 +6789,11 @@ func (r *Recipient) UnmarshalJSON(data []byte) error { r.MsTeamsRecipient = valueMsTeamsRecipient return nil } + var valueRecipientData RecipientData + if err := json.Unmarshal(data, &valueRecipientData); err == nil { + r.RecipientData = valueRecipientData + return nil + } return fmt.Errorf("%s cannot be deserialized as a %T", data, r) } @@ -6260,6 +6816,9 @@ func (r Recipient) MarshalJSON() ([]byte, error) { if r.MsTeamsRecipient != nil { return json.Marshal(r.MsTeamsRecipient) } + if r.RecipientData != nil { + return json.Marshal(r.RecipientData) + } return nil, fmt.Errorf("type %T does not include a non-empty union type", r) } @@ -6270,6 +6829,7 @@ type RecipientVisitor interface { VisitUserRecipient(*UserRecipient) error VisitSlackRecipient(*SlackRecipient) error VisitMsTeamsRecipient(*MsTeamsRecipient) error + VisitRecipientData(RecipientData) error } func (r *Recipient) Accept(visitor RecipientVisitor) error { @@ -6291,9 +6851,14 @@ func (r *Recipient) Accept(visitor RecipientVisitor) error { if r.MsTeamsRecipient != nil { return visitor.VisitMsTeamsRecipient(r.MsTeamsRecipient) } + if r.RecipientData != nil { + return visitor.VisitRecipientData(r.RecipientData) + } return fmt.Errorf("type %T does not include a non-empty union type", r) } +type RecipientData = map[string]interface{} + // Allows you to customize which channel(s) Courier will potentially deliver the message. // If no routing key is specified, Courier will use the default routing configuration or // routing defined by the template. @@ -6549,11 +7114,11 @@ type TemplateMessage struct { // "Expiry allows you to set an absolute or relative time in which a message expires. // Note: This is only valid for the Courier Inbox channel as of 12-08-2022." Expiry *Expiry `json:"expiry,omitempty" url:"expiry,omitempty"` + // The recipient or a list of recipients of the message + To *MessageRecipient `json:"to,omitempty" url:"to,omitempty"` // The id of the notification template to be rendered and sent to the recipient(s). // This field or the content field must be supplied. Template string `json:"template" url:"template"` - // The recipient or a list of recipients of the message - To *MessageRecipient `json:"to,omitempty" url:"to,omitempty"` _rawJSON json.RawMessage } @@ -7070,3 +7635,6 @@ func NewSubscriptionTopicStatusFromString(s string) (SubscriptionTopicStatus, er func (s SubscriptionTopicStatus) Ptr() *SubscriptionTopicStatus { return &s } + +// Unused type for tenants +type TemplateProperty = interface{} diff --git a/users/preferences.go b/users/preferences.go index 08b9f8b..5eb26a2 100644 --- a/users/preferences.go +++ b/users/preferences.go @@ -9,6 +9,38 @@ import ( core "github.com/trycourier/courier-go/v3/core" ) +type TopicPreferenceUpdate struct { + Status v3.PreferenceStatus `json:"status,omitempty" url:"status,omitempty"` + // The Channels a user has chosen to receive notifications through for this topic + CustomRouting []v3.ChannelClassification `json:"custom_routing,omitempty" url:"custom_routing,omitempty"` + HasCustomRouting *bool `json:"has_custom_routing,omitempty" url:"has_custom_routing,omitempty"` + + _rawJSON json.RawMessage +} + +func (t *TopicPreferenceUpdate) UnmarshalJSON(data []byte) error { + type unmarshaler TopicPreferenceUpdate + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *t = TopicPreferenceUpdate(value) + t._rawJSON = json.RawMessage(data) + return nil +} + +func (t *TopicPreferenceUpdate) String() string { + if len(t._rawJSON) > 0 { + if value, err := core.StringifyJSON(t._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(t); err == nil { + return value + } + return fmt.Sprintf("%#v", t) +} + type UserPreferencesGetResponse struct { Topic *TopicPreference `json:"topic,omitempty" url:"topic,omitempty"` @@ -99,9 +131,5 @@ func (u *UserPreferencesUpdateResponse) String() string { } type UserPreferencesUpdateParams struct { - Status v3.PreferenceStatus `json:"status,omitempty" url:"status,omitempty"` - // The Channels a user has chosen to receive notifications through for this topic - CustomRouting []v3.ChannelClassification `json:"custom_routing,omitempty" url:"custom_routing,omitempty"` - DefaultStatus v3.PreferenceStatus `json:"default_status,omitempty" url:"default_status,omitempty"` - HasCustomRouting *bool `json:"has_custom_routing,omitempty" url:"has_custom_routing,omitempty"` + Topic *TopicPreferenceUpdate `json:"topic,omitempty" url:"topic,omitempty"` } diff --git a/users/tenants.go b/users/tenants.go index 08bb51c..52d2844 100644 --- a/users/tenants.go +++ b/users/tenants.go @@ -10,7 +10,7 @@ import ( ) type AddUserToSingleTenantsParams struct { - Profile *AddUserToSingleTenantsParamsProfile `json:"profile,omitempty" url:"profile,omitempty"` + Profile map[string]interface{} `json:"profile,omitempty" url:"profile,omitempty"` } type AddUserToMultipleTenantsParams struct { @@ -25,43 +25,6 @@ type ListTenantsForUserParams struct { Cursor *string `json:"-" url:"cursor,omitempty"` } -type AddUserToSingleTenantsParamsProfile struct { - Title string `json:"title" url:"title"` - // Email Address - Email string `json:"email" url:"email"` - // A valid phone number - PhoneNumber string `json:"phone_number" url:"phone_number"` - // The user's preferred ISO 639-1 language code. - Locale string `json:"locale" url:"locale"` - // Additional provider specific fields may be specified. - AdditionalFields map[string]interface{} `json:"additional_fields,omitempty" url:"additional_fields,omitempty"` - - _rawJSON json.RawMessage -} - -func (a *AddUserToSingleTenantsParamsProfile) UnmarshalJSON(data []byte) error { - type unmarshaler AddUserToSingleTenantsParamsProfile - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *a = AddUserToSingleTenantsParamsProfile(value) - a._rawJSON = json.RawMessage(data) - return nil -} - -func (a *AddUserToSingleTenantsParamsProfile) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(a); err == nil { - return value - } - return fmt.Sprintf("%#v", a) -} - type ListTenantsForUserResponse struct { Items []*v3.UserTenantAssociation `json:"items,omitempty" url:"items,omitempty"` // Set to true when there are more pages that can be retrieved. diff --git a/users/types.go b/users/types.go index 1c4af32..65c9069 100644 --- a/users/types.go +++ b/users/types.go @@ -44,6 +44,44 @@ func (t *TopicPreference) String() string { return fmt.Sprintf("%#v", t) } +// AddUserToSingleTenantsParamsProfile is no longer used for Add a User to a Single Tenant +type AddUserToSingleTenantsParamsProfile struct { + Title string `json:"title" url:"title"` + // Email Address + Email string `json:"email" url:"email"` + // A valid phone number + PhoneNumber string `json:"phone_number" url:"phone_number"` + // The user's preferred ISO 639-1 language code. + Locale string `json:"locale" url:"locale"` + // Additional provider specific fields may be specified. + AdditionalFields map[string]interface{} `json:"additional_fields,omitempty" url:"additional_fields,omitempty"` + + _rawJSON json.RawMessage +} + +func (a *AddUserToSingleTenantsParamsProfile) UnmarshalJSON(data []byte) error { + type unmarshaler AddUserToSingleTenantsParamsProfile + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AddUserToSingleTenantsParamsProfile(value) + a._rawJSON = json.RawMessage(data) + return nil +} + +func (a *AddUserToSingleTenantsParamsProfile) String() string { + if len(a._rawJSON) > 0 { + if value, err := core.StringifyJSON(a._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + type DeleteUserTokenOpts struct { UserId string `json:"user_id" url:"user_id"` Token string `json:"token" url:"token"`