/
jobs-manager.ts
172 lines (149 loc) · 4.65 KB
/
jobs-manager.ts
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
import * as runtime from '../../../lib/runtime.js';
import type { InitOverride, ApiResponse } from '../../../lib/runtime.js';
import type {
GetErrors200Response,
Job,
PostUsersExportsRequest,
PostVerificationEmailRequest,
GetErrorsRequest,
GetJobsByIdRequest,
PostUsersImportsData,
} from '../models/index.js';
const { BaseAPI } = runtime;
/**
*
*/
export class JobsManager extends BaseAPI {
/**
* Retrieve error details of a failed job.
* Get job error details
*
* @throws {RequiredError}
*/
async getErrors(
requestParameters: GetErrorsRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<GetErrors200Response | void>> {
runtime.validateRequiredRequestParams(requestParameters, ['id']);
const response = await this.request(
{
path: `/jobs/{id}/errors`.replace('{id}', encodeURIComponent(String(requestParameters.id))),
method: 'GET',
},
initOverrides
);
return response.status === 204
? runtime.VoidApiResponse.fromResponse(response)
: runtime.JSONApiResponse.fromResponse(response);
}
/**
* Retrieves a job. Useful to check its status.
* Get a job
*
* @throws {RequiredError}
*/
async get(
requestParameters: GetJobsByIdRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<Job>> {
runtime.validateRequiredRequestParams(requestParameters, ['id']);
const response = await this.request(
{
path: `/jobs/{id}`.replace('{id}', encodeURIComponent(String(requestParameters.id))),
method: 'GET',
},
initOverrides
);
return runtime.JSONApiResponse.fromResponse(response);
}
/**
* Export all users to a file via a long-running job.
* Create export users job
*
* @throws {RequiredError}
*/
async exportUsers(
bodyParameters: PostUsersExportsRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<Job>> {
const headerParameters: runtime.HTTPHeaders = {};
headerParameters['Content-Type'] = 'application/json';
const response = await this.request(
{
path: `/jobs/users-exports`,
method: 'POST',
headers: headerParameters,
body: bodyParameters,
},
initOverrides
);
return runtime.JSONApiResponse.fromResponse(response);
}
/**
* Import users from a <a href="https://manage.local.dev.auth0.com/docs/users/references/bulk-import-database-schema-examples">formatted file</a> into a connection via a long-running job.
* Create import users job
*
* @throws {RequiredError}
*/
async importUsers(
bodyParameters: PostUsersImportsData,
initOverrides?: InitOverride
): Promise<ApiResponse<Job>> {
const formParams = new FormData();
if (bodyParameters.users !== undefined) {
formParams.append('users', await runtime.parseFormParam(bodyParameters.users));
}
if (bodyParameters.connection_id !== undefined) {
formParams.append(
'connection_id',
await runtime.parseFormParam(bodyParameters.connection_id)
);
}
if (bodyParameters.upsert !== undefined) {
formParams.append('upsert', await runtime.parseFormParam(bodyParameters.upsert));
}
if (bodyParameters.external_id !== undefined) {
formParams.append('external_id', await runtime.parseFormParam(bodyParameters.external_id));
}
if (bodyParameters.send_completion_email !== undefined) {
formParams.append(
'send_completion_email',
await runtime.parseFormParam(bodyParameters.send_completion_email)
);
}
const response = await this.request(
{
path: `/jobs/users-imports`,
method: 'POST',
body: formParams,
},
initOverrides
);
return runtime.JSONApiResponse.fromResponse(response);
}
/**
* Send an email to the specified user that asks them to click a link to <a href="https://auth0.com/docs/email/custom#verification-email">verify their email address</a>.
*
* Note: You must have the `Status` toggle enabled for the verification email template for the email to be sent.
* Send an email address verification email
*
* @throws {RequiredError}
*/
async verifyEmail(
bodyParameters: PostVerificationEmailRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<Job>> {
const headerParameters: runtime.HTTPHeaders = {};
headerParameters['Content-Type'] = 'application/json';
const response = await this.request(
{
path: `/jobs/verification-email`,
method: 'POST',
headers: headerParameters,
body: bodyParameters,
},
initOverrides
);
return runtime.JSONApiResponse.fromResponse(response);
}
}