Repository navigation
Expand file tree
/
Copy pathorganizationinvitation.go
More file actions
251 lines (229 loc) · 10.6 KB
/
Copy pathorganizationinvitation.go
File metadata and controls
251 lines (229 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package keycard
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/keycardai/keycard-go/internal/apijson"
"github.com/keycardai/keycard-go/internal/apiquery"
"github.com/keycardai/keycard-go/internal/requestconfig"
"github.com/keycardai/keycard-go/option"
"github.com/keycardai/keycard-go/packages/param"
"github.com/keycardai/keycard-go/packages/respjson"
)
// OrganizationInvitationService contains methods and other services that help with
// interacting with the keycard-api API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewOrganizationInvitationService] method instead.
type OrganizationInvitationService struct {
Options []option.RequestOption
}
// NewOrganizationInvitationService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewOrganizationInvitationService(opts ...option.RequestOption) (r OrganizationInvitationService) {
r = OrganizationInvitationService{}
r.Options = opts
return
}
// Create an invitation to join an organization
func (r *OrganizationInvitationService) New(ctx context.Context, organizationID string, params OrganizationInvitationNewParams, opts ...option.RequestOption) (res *Invitation, err error) {
if !param.IsOmitted(params.XClientRequestID) {
opts = append(opts, option.WithHeader("X-Client-Request-ID", fmt.Sprintf("%v", params.XClientRequestID.Value)))
}
opts = slices.Concat(r.Options, opts)
if organizationID == "" {
err = errors.New("missing required organization_id parameter")
return nil, err
}
path := fmt.Sprintf("organizations/%s/invitations", url.PathEscape(organizationID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// List invitations for an organization
func (r *OrganizationInvitationService) List(ctx context.Context, organizationID string, params OrganizationInvitationListParams, opts ...option.RequestOption) (res *OrganizationInvitationListResponse, err error) {
if !param.IsOmitted(params.XClientRequestID) {
opts = append(opts, option.WithHeader("X-Client-Request-ID", fmt.Sprintf("%v", params.XClientRequestID.Value)))
}
opts = slices.Concat(r.Options, opts)
if organizationID == "" {
err = errors.New("missing required organization_id parameter")
return nil, err
}
path := fmt.Sprintf("organizations/%s/invitations", url.PathEscape(organizationID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &res, opts...)
return res, err
}
// Delete an invitation
func (r *OrganizationInvitationService) Delete(ctx context.Context, invitationID string, params OrganizationInvitationDeleteParams, opts ...option.RequestOption) (err error) {
if !param.IsOmitted(params.XClientRequestID) {
opts = append(opts, option.WithHeader("X-Client-Request-ID", fmt.Sprintf("%v", params.XClientRequestID.Value)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if params.OrganizationID == "" {
err = errors.New("missing required organization_id parameter")
return err
}
if invitationID == "" {
err = errors.New("missing required invitation_id parameter")
return err
}
path := fmt.Sprintf("organizations/%s/invitations/%s", url.PathEscape(params.OrganizationID), url.PathEscape(invitationID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return err
}
type Invitation struct {
// Identifier for API resources. A 26-char nanoid (URL/DNS safe).
ID string `json:"id" api:"required"`
// The time the entity was created in utc
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// ID of the user who created the invitation
CreatedBy string `json:"created_by" api:"required"`
// Email address for the invitation
Email string `json:"email" api:"required" format:"email"`
// When the invitation expires
ExpiresAt time.Time `json:"expires_at" api:"required" format:"date-time"`
// Identifier for API resources. A 26-char nanoid (URL/DNS safe).
OrganizationID string `json:"organization_id" api:"required"`
// Role that will be assigned when invitation is accepted
//
// Any of "org_admin", "org_member", "org_viewer".
Role OrganizationRole `json:"role" api:"required"`
// Status of an invitation
//
// Any of "pending", "accepted", "expired", "revoked".
Status InvitationStatus `json:"status" api:"required"`
// The time the entity was mostly recently updated in utc
UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
// Permissions granted to the authenticated principal for this resource. Only
// populated when the 'expand[]=permissions' query parameter is provided. Keys are
// resource types (e.g., "organizations"), values are objects mapping permission
// names to boolean values indicating if the permission is granted.
Permissions map[string]map[string]bool `json:"permissions"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
CreatedBy respjson.Field
Email respjson.Field
ExpiresAt respjson.Field
OrganizationID respjson.Field
Role respjson.Field
Status respjson.Field
UpdatedAt respjson.Field
Permissions respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r Invitation) RawJSON() string { return r.JSON.raw }
func (r *Invitation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of an invitation
type InvitationStatus string
const (
InvitationStatusPending InvitationStatus = "pending"
InvitationStatusAccepted InvitationStatus = "accepted"
InvitationStatusExpired InvitationStatus = "expired"
InvitationStatusRevoked InvitationStatus = "revoked"
)
type OrganizationInvitationListResponse struct {
Items []Invitation `json:"items" api:"required"`
// Pagination information using cursor-based pagination
PageInfo PageInfoCursor `json:"page_info" api:"required"`
// Permissions granted to the authenticated principal for this resource. Only
// populated when the 'expand[]=permissions' query parameter is provided. Keys are
// resource types (e.g., "organizations"), values are objects mapping permission
// names to boolean values indicating if the permission is granted.
Permissions map[string]map[string]bool `json:"permissions"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Items respjson.Field
PageInfo respjson.Field
Permissions respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r OrganizationInvitationListResponse) RawJSON() string { return r.JSON.raw }
func (r *OrganizationInvitationListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type OrganizationInvitationNewParams struct {
// Email address to invite
Email string `json:"email" api:"required" format:"email"`
// Role to assign when invitation is accepted
//
// Any of "org_admin", "org_member", "org_viewer".
Role OrganizationRole `json:"role,omitzero" api:"required"`
XClientRequestID param.Opt[string] `header:"X-Client-Request-ID,omitzero" format:"uuid" json:"-"`
paramObj
}
func (r OrganizationInvitationNewParams) MarshalJSON() (data []byte, err error) {
type shadow OrganizationInvitationNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *OrganizationInvitationNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type OrganizationInvitationListParams struct {
// Cursor for forward pagination
After param.Opt[string] `query:"after,omitzero" json:"-"`
// Cursor for backward pagination
Before param.Opt[string] `query:"before,omitzero" json:"-"`
// Maximum number of invitations to return
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
XClientRequestID param.Opt[string] `header:"X-Client-Request-ID,omitzero" format:"uuid" json:"-"`
// Fields to expand in the response. Supports "permissions" to include the
// permissions field with the caller's permissions for the resource. For the
// service account and service account credential list operations, "total_count"
// populates pagination.total_count with the number of items matching the same
// filters as the list (excluding cursor and limit). Other operations ignore expand
// values they do not use.
Expand OrganizationInvitationListParamsExpandUnion `query:"expand[],omitzero" json:"-"`
// Return only invitations with these statuses. Repeat the parameter to match any
// of several statuses (`?filter[status]=pending&filter[status]=accepted`). Expired
// invitations are never listed, so `expired` matches nothing. When absent, no
// status filter is applied.
FilterStatus []InvitationStatus `query:"filter[status],omitzero" json:"-"`
paramObj
}
// URLQuery serializes [OrganizationInvitationListParams]'s query parameters as
// `url.Values`.
func (r OrganizationInvitationListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type OrganizationInvitationListParamsExpandUnion struct {
// Check if union is this variant with
// !param.IsOmitted(union.OfOrganizationInvitationListsExpandString)
OfOrganizationInvitationListsExpandString param.Opt[string] `query:",omitzero,inline"`
OfOrganizationInvitationListsExpandArrayItemArray []string `query:",omitzero,inline"`
paramUnion
}
type OrganizationInvitationListParamsExpandString string
const (
OrganizationInvitationListParamsExpandStringPermissions OrganizationInvitationListParamsExpandString = "permissions"
OrganizationInvitationListParamsExpandStringTotalCount OrganizationInvitationListParamsExpandString = "total_count"
)
type OrganizationInvitationDeleteParams struct {
// Organization ID or label identifier
OrganizationID string `path:"organization_id" api:"required" json:"-"`
XClientRequestID param.Opt[string] `header:"X-Client-Request-ID,omitzero" format:"uuid" json:"-"`
paramObj
}