Updated SDKs
This commit is contained in:
parent
442f857d2b
commit
da1c73d33f
|
@ -5,6 +5,10 @@ sdk
|
|||
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
||||
;
|
||||
|
||||
let result = sdk.account.createOAuth2Session('bitbucket', 'https://example.com', 'https://example.com');
|
||||
let promise = sdk.account.createOAuth2Session('bitbucket');
|
||||
|
||||
console.log(result); // Resource URL
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -286,28 +286,6 @@
|
|||
}
|
||||
}(window.document);
|
||||
|
||||
let iframe = function(method, url, params) {
|
||||
let form = document.createElement('form');
|
||||
|
||||
form.setAttribute('method', method);
|
||||
form.setAttribute('action', config.endpoint + url);
|
||||
|
||||
for(let key in params) {
|
||||
if(params.hasOwnProperty(key)) {
|
||||
let hiddenField = document.createElement("input");
|
||||
hiddenField.setAttribute("type", "hidden");
|
||||
hiddenField.setAttribute("name", key);
|
||||
hiddenField.setAttribute("value", params[key]);
|
||||
|
||||
form.appendChild(hiddenField);
|
||||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(form);
|
||||
|
||||
return form.submit();
|
||||
};
|
||||
|
||||
let account = {
|
||||
|
||||
/**
|
||||
|
@ -768,21 +746,13 @@
|
|||
* @param {string} success
|
||||
* @param {string} failure
|
||||
* @throws {Error}
|
||||
* @return {string}
|
||||
* @return {Promise}
|
||||
*/
|
||||
createOAuth2Session: function(provider, success, failure) {
|
||||
createOAuth2Session: function(provider, success = 'https://localhost:2444/auth/oauth2/success', failure = 'https://localhost:2444/auth/oauth2/failure') {
|
||||
if(provider === undefined) {
|
||||
throw new Error('Missing required parameter: "provider"');
|
||||
}
|
||||
|
||||
if(success === undefined) {
|
||||
throw new Error('Missing required parameter: "success"');
|
||||
}
|
||||
|
||||
if(failure === undefined) {
|
||||
throw new Error('Missing required parameter: "failure"');
|
||||
}
|
||||
|
||||
let path = '/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}', 'g'), provider);
|
||||
|
||||
let payload = {};
|
||||
|
@ -800,8 +770,8 @@
|
|||
payload['key'] = config.key;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
|
||||
window.location = config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -3231,7 +3201,7 @@
|
|||
payload['key'] = config.key;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
|
@ -3286,7 +3256,7 @@
|
|||
payload['key'] = config.key;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
|
@ -3319,7 +3289,7 @@
|
|||
payload['key'] = config.key;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
}
|
||||
};
|
||||
|
|
9
app/sdks/console-javascript/src/sdk.min.js
vendored
9
app/sdks/console-javascript/src/sdk.min.js
vendored
|
@ -12,8 +12,7 @@ request.setRequestHeader(key,headers[key])}}
|
|||
request.onload=function(){if(4===request.readyState&&399>=request.status){let data=request.response;let contentType=this.getResponseHeader('content-type')||'';contentType=contentType.substring(0,contentType.indexOf(';'));switch(contentType){case 'application/json':data=JSON.parse(data);break}
|
||||
let cookieFallback=this.getResponseHeader('X-Fallback-Cookies')||'';if(window.localStorage&&cookieFallback){window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');window.localStorage.setItem('cookieFallback',cookieFallback)}
|
||||
resolve(data)}else{reject(new Error(request.statusText))}};if(progress){request.addEventListener('progress',progress);request.upload.addEventListener('progress',progress,!1)}
|
||||
request.onerror=function(){reject(new Error("Network Error"))};request.send(params)})};return{'get':function(path,headers={},params={}){return call('GET',path+((Object.keys(params).length>0)?'?'+buildQuery(params):''),headers,{})},'post':function(path,headers={},params={},progress=null){return call('POST',path,headers,params,progress)},'put':function(path,headers={},params={},progress=null){return call('PUT',path,headers,params,progress)},'patch':function(path,headers={},params={},progress=null){return call('PATCH',path,headers,params,progress)},'delete':function(path,headers={},params={},progress=null){return call('DELETE',path,headers,params,progress)},'addGlobalParam':addGlobalParam,'addGlobalHeader':addGlobalHeader}}(window.document);let iframe=function(method,url,params){let form=document.createElement('form');form.setAttribute('method',method);form.setAttribute('action',config.endpoint+url);for(let key in params){if(params.hasOwnProperty(key)){let hiddenField=document.createElement("input");hiddenField.setAttribute("type","hidden");hiddenField.setAttribute("name",key);hiddenField.setAttribute("value",params[key]);form.appendChild(hiddenField)}}
|
||||
document.body.appendChild(form);return form.submit()};let account={get:function(){let path='/account';let payload={};return http.get(path,{'content-type':'application/json',},payload)},create:function(email,password,name=''){if(email===undefined){throw new Error('Missing required parameter: "email"')}
|
||||
request.onerror=function(){reject(new Error("Network Error"))};request.send(params)})};return{'get':function(path,headers={},params={}){return call('GET',path+((Object.keys(params).length>0)?'?'+buildQuery(params):''),headers,{})},'post':function(path,headers={},params={},progress=null){return call('POST',path,headers,params,progress)},'put':function(path,headers={},params={},progress=null){return call('PUT',path,headers,params,progress)},'patch':function(path,headers={},params={},progress=null){return call('PATCH',path,headers,params,progress)},'delete':function(path,headers={},params={},progress=null){return call('DELETE',path,headers,params,progress)},'addGlobalParam':addGlobalParam,'addGlobalHeader':addGlobalHeader}}(window.document);let account={get:function(){let path='/account';let payload={};return http.get(path,{'content-type':'application/json',},payload)},create:function(email,password,name=''){if(email===undefined){throw new Error('Missing required parameter: "email"')}
|
||||
if(password===undefined){throw new Error('Missing required parameter: "password"')}
|
||||
let path='/account';let payload={};if(email){payload.email=email}
|
||||
if(password){payload.password=password}
|
||||
|
@ -46,12 +45,10 @@ return http.put(path,{'content-type':'application/json',},payload)},getSessions:
|
|||
if(password===undefined){throw new Error('Missing required parameter: "password"')}
|
||||
let path='/account/sessions';let payload={};if(email){payload.email=email}
|
||||
if(password){payload.password=password}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success,failure){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
|
||||
if(success===undefined){throw new Error('Missing required parameter: "success"')}
|
||||
if(failure===undefined){throw new Error('Missing required parameter: "failure"')}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success='https://localhost:2444/auth/oauth2/success',failure='https://localhost:2444/auth/oauth2/failure'){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
|
||||
let path='/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}','g'),provider);let payload={};if(success){payload.success=success}
|
||||
if(failure){payload.failure=failure}
|
||||
payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
|
||||
payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');window.location=config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
|
||||
let path='/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}','g'),sessionId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"')}
|
||||
let path='/account/verification';let payload={};if(url){payload.url=url}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},updateVerification:function(userId,secret){if(userId===undefined){throw new Error('Missing required parameter: "userId"')}
|
||||
|
|
|
@ -242,7 +242,7 @@
|
|||
"languageVersion": "2.6"
|
||||
}
|
||||
],
|
||||
"generated": "2020-04-10T08:34:20.591152Z",
|
||||
"generated": "2020-04-11T09:32:46.431074Z",
|
||||
"generator": "pub",
|
||||
"generatorVersion": "2.7.2"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by pub on 2020-04-10 11:34:20.573255.
|
||||
# Generated by pub on 2020-04-11 12:32:46.410814.
|
||||
archive:file:///Users/eldadfux/.pub-cache/hosted/pub.dartlang.org/archive-2.0.11/lib/
|
||||
args:file:///Users/eldadfux/.pub-cache/hosted/pub.dartlang.org/args-1.5.2/lib/
|
||||
async:file:///Users/eldadfux/.pub-cache/hosted/pub.dartlang.org/async-2.4.0/lib/
|
||||
|
|
|
@ -10,8 +10,6 @@ client
|
|||
|
||||
Future result = account.createOAuth2Session(
|
||||
provider: 'bitbucket',
|
||||
success: 'https://example.com',
|
||||
failure: 'https://example.com',
|
||||
);
|
||||
|
||||
result
|
||||
|
|
|
@ -10,7 +10,7 @@ client
|
|||
;
|
||||
|
||||
Future result = storage.createFile(
|
||||
file: null,
|
||||
file: new File('./image.jpg'),
|
||||
read: [],
|
||||
write: [],
|
||||
);
|
||||
|
|
|
@ -8,13 +8,8 @@ client
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
Future result = storage.getFileDownload(
|
||||
String result = storage.getFileDownload(
|
||||
fileId: '[FILE_ID]',
|
||||
);
|
||||
|
||||
result
|
||||
.then((response) {
|
||||
print(response);
|
||||
}).catchError((error) {
|
||||
print(error);
|
||||
});
|
||||
print(result); // Resource URL string
|
||||
|
|
|
@ -8,13 +8,8 @@ client
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
Future result = storage.getFilePreview(
|
||||
String result = storage.getFilePreview(
|
||||
fileId: '[FILE_ID]',
|
||||
);
|
||||
|
||||
result
|
||||
.then((response) {
|
||||
print(response);
|
||||
}).catchError((error) {
|
||||
print(error);
|
||||
});
|
||||
print(result); // Resource URL string
|
||||
|
|
|
@ -8,13 +8,8 @@ client
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
Future result = storage.getFileView(
|
||||
String result = storage.getFileView(
|
||||
fileId: '[FILE_ID]',
|
||||
);
|
||||
|
||||
result
|
||||
.then((response) {
|
||||
print(response);
|
||||
}).catchError((error) {
|
||||
print(error);
|
||||
});
|
||||
print(result); // Resource URL string
|
||||
|
|
|
@ -120,6 +120,10 @@ class Client {
|
|||
method: method.name(),
|
||||
);
|
||||
|
||||
if(headers['content-type'] == 'multipart/form-data') {
|
||||
FormData data = FormData.fromMap(params);
|
||||
}
|
||||
|
||||
if (method == HttpMethod.get) {
|
||||
return http.get(path, queryParameters: params, options: options);
|
||||
} else {
|
||||
|
|
|
@ -12,21 +12,32 @@ import "../service.dart";
|
|||
class Account extends Service {
|
||||
Account(Client client): super(client);
|
||||
|
||||
/// Get Account
|
||||
///
|
||||
/// Get currently logged in user data as JSON object.
|
||||
///
|
||||
Future<Response> get() {
|
||||
final String path = '/account';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Account
|
||||
///
|
||||
/// Use this endpoint to allow a new user to register a new account in your
|
||||
/// project. After the user registration completes successfully, you can use
|
||||
/// the [/account/verfication](/docs/account#createVerification) route to start
|
||||
/// verifying the user email address. To allow your new user to login to his
|
||||
/// new account, you need to create a new [account
|
||||
/// session](/docs/account#createSession).
|
||||
///
|
||||
Future<Response> create({@required String email, @required String password, String name = ''}) {
|
||||
final String path = '/account';
|
||||
|
||||
|
@ -36,25 +47,41 @@ class Account extends Service {
|
|||
'name': name,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete Account
|
||||
///
|
||||
/// Delete a currently logged in user account. Behind the scene, the user
|
||||
/// record is not deleted but permanently blocked from any access. This is done
|
||||
/// to avoid deleted accounts being overtaken by new users with the same email
|
||||
/// address. Any user-related resources like documents or storage files should
|
||||
/// be deleted separately.
|
||||
///
|
||||
Future<Response> delete() {
|
||||
final String path = '/account';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Account Email
|
||||
///
|
||||
/// Update currently logged in user account email address. After changing user
|
||||
/// address, user confirmation status is being reset and a new confirmation
|
||||
/// mail is sent. For security measures, user password is required to complete
|
||||
/// this request.
|
||||
///
|
||||
Future<Response> updateEmail({@required String email, @required String password}) {
|
||||
final String path = '/account/email';
|
||||
|
||||
|
@ -63,19 +90,35 @@ class Account extends Service {
|
|||
'password': password,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Account Logs
|
||||
///
|
||||
/// Get currently logged in user list of latest security activity logs. Each
|
||||
/// log returns user IP address, location and date and time of log.
|
||||
///
|
||||
Future<Response> getLogs() {
|
||||
final String path = '/account/logs';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Account Name
|
||||
///
|
||||
/// Update currently logged in user account name.
|
||||
///
|
||||
Future<Response> updateName({@required String name}) {
|
||||
final String path = '/account/name';
|
||||
|
||||
|
@ -83,10 +126,18 @@ class Account extends Service {
|
|||
'name': name,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Account Password
|
||||
///
|
||||
/// Update currently logged in user password. For validation, user is required
|
||||
/// to pass the password twice.
|
||||
///
|
||||
Future<Response> updatePassword({@required String password, @required String oldPassword}) {
|
||||
final String path = '/account/password';
|
||||
|
||||
|
@ -95,19 +146,35 @@ class Account extends Service {
|
|||
'old-password': oldPassword,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Account Preferences
|
||||
///
|
||||
/// Get currently logged in user preferences as a key-value object.
|
||||
///
|
||||
Future<Response> getPrefs() {
|
||||
final String path = '/account/prefs';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Account Preferences
|
||||
///
|
||||
/// Update currently logged in user account preferences. You can pass only the
|
||||
/// specific settings you wish to update.
|
||||
///
|
||||
Future<Response> updatePrefs({@required dynamic prefs}) {
|
||||
final String path = '/account/prefs';
|
||||
|
||||
|
@ -115,14 +182,22 @@ class Account extends Service {
|
|||
'prefs': prefs,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Password Recovery
|
||||
///
|
||||
/// Sends the user an email with a temporary secret key for password reset.
|
||||
/// When the user clicks the confirmation link he is redirected back to your
|
||||
/// app password reset URL with the secret key and email address values
|
||||
/// attached to the URL query string. Use the query string params to submit a
|
||||
/// request to the [PUT /account/recovery](/docs/account#updateRecovery)
|
||||
/// endpoint to complete the process.
|
||||
///
|
||||
Future<Response> createRecovery({@required String email, @required String url}) {
|
||||
final String path = '/account/recovery';
|
||||
|
||||
|
@ -131,8 +206,15 @@ class Account extends Service {
|
|||
'url': url,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Complete Password Recovery
|
||||
///
|
||||
/// Use this endpoint to complete the user account password reset. Both the
|
||||
/// **userId** and **secret** arguments will be passed as query parameters to
|
||||
/// the redirect URL you have provided when sending your request to the [POST
|
||||
|
@ -142,6 +224,7 @@ class Account extends Service {
|
|||
/// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
|
||||
/// the only valid redirect URLs are the ones from domains you have set when
|
||||
/// adding your platforms in the console interface.
|
||||
///
|
||||
Future<Response> updateRecovery({@required String userId, @required String secret, @required String passwordA, @required String passwordB}) {
|
||||
final String path = '/account/recovery';
|
||||
|
||||
|
@ -152,20 +235,36 @@ class Account extends Service {
|
|||
'password-b': passwordB,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Account Sessions
|
||||
///
|
||||
/// Get currently logged in user list of active sessions across different
|
||||
/// devices.
|
||||
///
|
||||
Future<Response> getSessions() {
|
||||
final String path = '/account/sessions';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Account Session
|
||||
///
|
||||
/// Allow the user to login into his account by providing a valid email and
|
||||
/// password combination. This route will create a new session for the user.
|
||||
///
|
||||
Future<Response> createSession({@required String email, @required String password}) {
|
||||
final String path = '/account/sessions';
|
||||
|
||||
|
@ -174,23 +273,39 @@ class Account extends Service {
|
|||
'password': password,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete All Account Sessions
|
||||
///
|
||||
/// Delete all sessions from the user account and remove any sessions cookies
|
||||
/// from the end client.
|
||||
///
|
||||
Future<Response> deleteSessions() {
|
||||
final String path = '/account/sessions';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Account Session with OAuth2
|
||||
///
|
||||
/// Allow the user to login to his account using the OAuth2 provider of his
|
||||
/// choice. Each OAuth2 provider should be enabled from the Appwrite console
|
||||
/// first. Use the success and failure arguments to provide a redirect URL's
|
||||
/// back to your app when login is completed.
|
||||
Future createOAuth2Session({@required String provider, @required String success, @required String failure}) {
|
||||
///
|
||||
Future createOAuth2Session({@required String provider, String success = 'https://localhost:2444/auth/oauth2/success', String failure = 'https://localhost:2444/auth/oauth2/failure'}) {
|
||||
final String path = '/account/sessions/oauth2/{provider}'.replaceAll(RegExp('{provider}'), provider);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
|
@ -214,20 +329,30 @@ class Account extends Service {
|
|||
Uri url = Uri.parse(value);
|
||||
List<Cookie> cookies = [new Cookie(url.queryParameters['key'], url.queryParameters['secret'])];
|
||||
client.cookieJar.saveFromResponse(Uri.parse(client.endPoint), cookies);
|
||||
}).catchError((error) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Delete Account Session
|
||||
///
|
||||
/// Use this endpoint to log out the currently logged in user from all his
|
||||
/// account sessions across all his different devices. When using the option id
|
||||
/// argument, only the session unique ID provider will be deleted.
|
||||
///
|
||||
Future<Response> deleteSession({@required String sessionId}) {
|
||||
final String path = '/account/sessions/{sessionId}'.replaceAll(RegExp('{sessionId}'), sessionId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Email Verification
|
||||
///
|
||||
/// Use this endpoint to send a verification message to your user email address
|
||||
/// to confirm they are the valid owners of that address. Both the **userId**
|
||||
/// and **secret** arguments will be passed as query parameters to the URL you
|
||||
|
@ -241,6 +366,7 @@ class Account extends Service {
|
|||
/// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
|
||||
/// the only valid redirect URLs are the ones from domains you have set when
|
||||
/// adding your platforms in the console interface.
|
||||
///
|
||||
Future<Response> createVerification({@required String url}) {
|
||||
final String path = '/account/verification';
|
||||
|
||||
|
@ -248,12 +374,20 @@ class Account extends Service {
|
|||
'url': url,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Complete Email Verification
|
||||
///
|
||||
/// Use this endpoint to complete the user email verification process. Use both
|
||||
/// the **userId** and **secret** parameters that were attached to your app URL
|
||||
/// to verify the user email ownership. If confirmed this route will return a
|
||||
/// 200 status code.
|
||||
///
|
||||
Future<Response> updateVerification({@required String userId, @required String secret}) {
|
||||
final String path = '/account/verification';
|
||||
|
||||
|
@ -262,6 +396,10 @@ class Account extends Service {
|
|||
'secret': secret,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params, headers: headers);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_web_auth/flutter_web_auth.dart';
|
||||
|
||||
import "../client.dart";
|
||||
import '../enums.dart';
|
||||
|
@ -12,10 +11,13 @@ import "../service.dart";
|
|||
class Avatars extends Service {
|
||||
Avatars(Client client): super(client);
|
||||
|
||||
/// Get Browser Icon
|
||||
///
|
||||
/// You can use this endpoint to show different browser icons to your users.
|
||||
/// The code argument receives the browser code as it appears in your user
|
||||
/// /account/sessions endpoint. Use width, height and quality arguments to
|
||||
/// change the output settings.
|
||||
///
|
||||
Future<Response> getBrowser({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
||||
final String path = '/avatars/browsers/{code}'.replaceAll(RegExp('{code}'), code);
|
||||
|
||||
|
@ -25,12 +27,20 @@ class Avatars extends Service {
|
|||
'quality': quality,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Credit Card Icon
|
||||
///
|
||||
/// Need to display your users with your billing method or their payment
|
||||
/// methods? The credit card endpoint will return you the icon of the credit
|
||||
/// card provider you need. Use width, height and quality arguments to change
|
||||
/// the output settings.
|
||||
///
|
||||
Future<Response> getCreditCard({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
||||
final String path = '/avatars/credit-cards/{code}'.replaceAll(RegExp('{code}'), code);
|
||||
|
||||
|
@ -40,10 +50,18 @@ class Avatars extends Service {
|
|||
'quality': quality,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Favicon
|
||||
///
|
||||
/// Use this endpoint to fetch the favorite icon (AKA favicon) of a any remote
|
||||
/// website URL.
|
||||
///
|
||||
Future<Response> getFavicon({@required String url}) {
|
||||
final String path = '/avatars/favicon';
|
||||
|
||||
|
@ -51,11 +69,19 @@ class Avatars extends Service {
|
|||
'url': url,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Country Flag
|
||||
///
|
||||
/// You can use this endpoint to show different country flags icons to your
|
||||
/// users. The code argument receives the 2 letter country code. Use width,
|
||||
/// height and quality arguments to change the output settings.
|
||||
///
|
||||
Future<Response> getFlag({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
||||
final String path = '/avatars/flags/{code}'.replaceAll(RegExp('{code}'), code);
|
||||
|
||||
|
@ -65,12 +91,20 @@ class Avatars extends Service {
|
|||
'quality': quality,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Image from URL
|
||||
///
|
||||
/// Use this endpoint to fetch a remote image URL and crop it to any image size
|
||||
/// you want. This endpoint is very useful if you need to crop and display
|
||||
/// remote images in your app or in case you want to make sure a 3rd party
|
||||
/// image is properly served using a TLS protocol.
|
||||
///
|
||||
Future<Response> getImage({@required String url, int width = 400, int height = 400}) {
|
||||
final String path = '/avatars/image';
|
||||
|
||||
|
@ -80,10 +114,18 @@ class Avatars extends Service {
|
|||
'height': height,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get QR Code
|
||||
///
|
||||
/// Converts a given plain text to a QR code image. You can use the query
|
||||
/// parameters to change the size and style of the resulting image.
|
||||
///
|
||||
Future<Response> getQR({@required String text, int size = 400, int margin = 1, int download = 0}) {
|
||||
final String path = '/avatars/qr';
|
||||
|
||||
|
@ -94,6 +136,10 @@ class Avatars extends Service {
|
|||
'download': download,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_web_auth/flutter_web_auth.dart';
|
||||
|
||||
import "../client.dart";
|
||||
import '../enums.dart';
|
||||
|
@ -12,10 +11,13 @@ import "../service.dart";
|
|||
class Database extends Service {
|
||||
Database(Client client): super(client);
|
||||
|
||||
/// List Documents
|
||||
///
|
||||
/// Get a list of all the user documents. You can use the query params to
|
||||
/// filter your results. On admin mode, this endpoint will return a list of all
|
||||
/// of the project documents. [Learn more about different API
|
||||
/// modes](/docs/admin).
|
||||
///
|
||||
Future<Response> listDocuments({@required String collectionId, List filters = const [], int offset = 0, int limit = 50, String orderField = '\$id', String orderType = 'ASC', String orderCast = 'string', String search = '', int first = 0, int last = 0}) {
|
||||
final String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
|
||||
|
||||
|
@ -31,9 +33,17 @@ class Database extends Service {
|
|||
'last': last,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Document
|
||||
///
|
||||
/// Create a new Document.
|
||||
///
|
||||
Future<Response> createDocument({@required String collectionId, @required dynamic data, @required List read, @required List write, String parentDocument = '', String parentProperty = '', String parentPropertyType = 'assign'}) {
|
||||
final String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
|
||||
|
||||
|
@ -46,18 +56,32 @@ class Database extends Service {
|
|||
'parentPropertyType': parentPropertyType,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Document
|
||||
///
|
||||
/// Get document by its unique ID. This endpoint response returns a JSON object
|
||||
/// with the document data.
|
||||
///
|
||||
Future<Response> getDocument({@required String collectionId, @required String documentId}) {
|
||||
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Document
|
||||
Future<Response> updateDocument({@required String collectionId, @required String documentId, @required dynamic data, @required List read, @required List write}) {
|
||||
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
||||
|
||||
|
@ -67,17 +91,29 @@ class Database extends Service {
|
|||
'write': write,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete Document
|
||||
///
|
||||
/// Delete document by its unique ID. This endpoint deletes only the parent
|
||||
/// documents, his attributes and relations to other documents. Child documents
|
||||
/// **will not** be deleted.
|
||||
///
|
||||
Future<Response> deleteDocument({@required String collectionId, @required String documentId}) {
|
||||
final String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_web_auth/flutter_web_auth.dart';
|
||||
|
||||
import "../client.dart";
|
||||
import '../enums.dart';
|
||||
|
@ -12,69 +11,116 @@ import "../service.dart";
|
|||
class Locale extends Service {
|
||||
Locale(Client client): super(client);
|
||||
|
||||
/// Get User Locale
|
||||
///
|
||||
/// Get the current user location based on IP. Returns an object with user
|
||||
/// country code, country name, continent name, continent code, ip address and
|
||||
/// suggested currency. You can use the locale header to get the data in a
|
||||
/// supported language.
|
||||
///
|
||||
/// ([IP Geolocation by DB-IP](https://db-ip.com))
|
||||
///
|
||||
Future<Response> get() {
|
||||
final String path = '/locale';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// List Countries
|
||||
///
|
||||
/// List of all continents. You can use the locale header to get the data in a
|
||||
/// supported language.
|
||||
///
|
||||
Future<Response> getContinents() {
|
||||
final String path = '/locale/continents';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// List Countries
|
||||
///
|
||||
/// List of all countries. You can use the locale header to get the data in a
|
||||
/// supported language.
|
||||
///
|
||||
Future<Response> getCountries() {
|
||||
final String path = '/locale/countries';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// List EU Countries
|
||||
///
|
||||
/// List of all countries that are currently members of the EU. You can use the
|
||||
/// locale header to get the data in a supported language.
|
||||
///
|
||||
Future<Response> getCountriesEU() {
|
||||
final String path = '/locale/countries/eu';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// List Countries Phone Codes
|
||||
///
|
||||
/// List of all countries phone codes. You can use the locale header to get the
|
||||
/// data in a supported language.
|
||||
///
|
||||
Future<Response> getCountriesPhones() {
|
||||
final String path = '/locale/countries/phones';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// List Currencies
|
||||
///
|
||||
/// List of all currencies, including currency symol, name, plural, and decimal
|
||||
/// digits for all major and minor currencies. You can use the locale header to
|
||||
/// get the data in a supported language.
|
||||
///
|
||||
Future<Response> getCurrencies() {
|
||||
final String path = '/locale/currencies';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_web_auth/flutter_web_auth.dart';
|
||||
|
||||
import "../client.dart";
|
||||
import '../enums.dart';
|
||||
|
@ -12,9 +11,12 @@ import "../service.dart";
|
|||
class Storage extends Service {
|
||||
Storage(Client client): super(client);
|
||||
|
||||
/// List Files
|
||||
///
|
||||
/// Get a list of all the user files. You can use the query params to filter
|
||||
/// your results. On admin mode, this endpoint will return a list of all of the
|
||||
/// project files. [Learn more about different API modes](/docs/admin).
|
||||
///
|
||||
Future<Response> listFiles({String search = '', int limit = 25, int offset = 0, OrderType orderType = OrderType.asc}) {
|
||||
final String path = '/storage/files';
|
||||
|
||||
|
@ -25,12 +27,20 @@ class Storage extends Service {
|
|||
'orderType': orderType.name(),
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create File
|
||||
///
|
||||
/// Create a new file. The user who creates the file will automatically be
|
||||
/// assigned to read and write access unless he has passed custom values for
|
||||
/// read and write arguments.
|
||||
Future<Response> createFile({@required file, @required List read, @required List write}) {
|
||||
///
|
||||
Future<Response> createFile({@required File file, @required List read, @required List write}) {
|
||||
final String path = '/storage/files';
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
|
@ -39,20 +49,36 @@ class Storage extends Service {
|
|||
'write': write,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'multipart/form-data',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get File
|
||||
///
|
||||
/// Get file by its unique ID. This endpoint response returns a JSON object
|
||||
/// with the file metadata.
|
||||
///
|
||||
Future<Response> getFile({@required String fileId}) {
|
||||
final String path = '/storage/files/{fileId}'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update File
|
||||
///
|
||||
/// Update file by its unique ID. Only users with write permissions have access
|
||||
/// to update this resource.
|
||||
///
|
||||
Future<Response> updateFile({@required String fileId, @required List read, @required List write}) {
|
||||
final String path = '/storage/files/{fileId}'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
|
@ -61,22 +87,38 @@ class Storage extends Service {
|
|||
'write': write,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete File
|
||||
///
|
||||
/// Delete a file by its unique ID. Only users with write permissions have
|
||||
/// access to delete this resource.
|
||||
///
|
||||
Future<Response> deleteFile({@required String fileId}) {
|
||||
final String path = '/storage/files/{fileId}'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get File for Download
|
||||
///
|
||||
/// Get file content by its unique ID. The endpoint response return with a
|
||||
/// 'Content-Disposition: attachment' header that tells the browser to start
|
||||
/// downloading the file to user downloads directory.
|
||||
Future getFileDownload({@required String fileId}) {
|
||||
///
|
||||
String getFileDownload({@required String fileId}) {
|
||||
final String path = '/storage/files/{fileId}/download'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
|
@ -91,21 +133,17 @@ class Storage extends Service {
|
|||
queryParameters:params,
|
||||
);
|
||||
|
||||
return FlutterWebAuth.authenticate(
|
||||
url: url.toString(),
|
||||
callbackUrlScheme: "appwrite-callback"
|
||||
).then((value) {
|
||||
Uri url = Uri.parse(value);
|
||||
List<Cookie> cookies = [new Cookie(url.queryParameters['key'], url.queryParameters['secret'])];
|
||||
client.cookieJar.saveFromResponse(Uri.parse(client.endPoint), cookies);
|
||||
}).catchError((error) {
|
||||
});
|
||||
return Uri.toString();
|
||||
}
|
||||
|
||||
/// Get File Preview
|
||||
///
|
||||
/// Get a file preview image. Currently, this method supports preview for image
|
||||
/// files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
||||
/// and spreadsheets, will return the file icon image. You can also pass query
|
||||
/// string arguments for cutting and resizing your preview image.
|
||||
Future getFilePreview({@required String fileId, int width = 0, int height = 0, int quality = 100, String background = '', String output = ''}) {
|
||||
///
|
||||
String getFilePreview({@required String fileId, int width = 0, int height = 0, int quality = 100, String background = '', String output = ''}) {
|
||||
final String path = '/storage/files/{fileId}/preview'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
|
@ -125,19 +163,15 @@ class Storage extends Service {
|
|||
queryParameters:params,
|
||||
);
|
||||
|
||||
return FlutterWebAuth.authenticate(
|
||||
url: url.toString(),
|
||||
callbackUrlScheme: "appwrite-callback"
|
||||
).then((value) {
|
||||
Uri url = Uri.parse(value);
|
||||
List<Cookie> cookies = [new Cookie(url.queryParameters['key'], url.queryParameters['secret'])];
|
||||
client.cookieJar.saveFromResponse(Uri.parse(client.endPoint), cookies);
|
||||
}).catchError((error) {
|
||||
});
|
||||
return Uri.toString();
|
||||
}
|
||||
|
||||
/// Get File for View
|
||||
///
|
||||
/// Get file content by its unique ID. This endpoint is similar to the download
|
||||
/// method but returns with no 'Content-Disposition: attachment' header.
|
||||
Future getFileView({@required String fileId, String as = ''}) {
|
||||
///
|
||||
String getFileView({@required String fileId, String as = ''}) {
|
||||
final String path = '/storage/files/{fileId}/view'.replaceAll(RegExp('{fileId}'), fileId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
|
@ -153,14 +187,6 @@ class Storage extends Service {
|
|||
queryParameters:params,
|
||||
);
|
||||
|
||||
return FlutterWebAuth.authenticate(
|
||||
url: url.toString(),
|
||||
callbackUrlScheme: "appwrite-callback"
|
||||
).then((value) {
|
||||
Uri url = Uri.parse(value);
|
||||
List<Cookie> cookies = [new Cookie(url.queryParameters['key'], url.queryParameters['secret'])];
|
||||
client.cookieJar.saveFromResponse(Uri.parse(client.endPoint), cookies);
|
||||
}).catchError((error) {
|
||||
});
|
||||
return Uri.toString();
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_web_auth/flutter_web_auth.dart';
|
||||
|
||||
import "../client.dart";
|
||||
import '../enums.dart';
|
||||
|
@ -12,9 +11,12 @@ import "../service.dart";
|
|||
class Teams extends Service {
|
||||
Teams(Client client): super(client);
|
||||
|
||||
/// List Teams
|
||||
///
|
||||
/// Get a list of all the current user teams. You can use the query params to
|
||||
/// filter your results. On admin mode, this endpoint will return a list of all
|
||||
/// of the project teams. [Learn more about different API modes](/docs/admin).
|
||||
///
|
||||
Future<Response> list({String search = '', int limit = 25, int offset = 0, OrderType orderType = OrderType.asc}) {
|
||||
final String path = '/teams';
|
||||
|
||||
|
@ -25,12 +27,20 @@ class Teams extends Service {
|
|||
'orderType': orderType.name(),
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Team
|
||||
///
|
||||
/// Create a new team. The user who creates the team will automatically be
|
||||
/// assigned as the owner of the team. The team owner can invite new members,
|
||||
/// who will be able add new owners and update or delete the team from your
|
||||
/// project.
|
||||
///
|
||||
Future<Response> create({@required String name, List roles = const ["owner"]}) {
|
||||
final String path = '/teams';
|
||||
|
||||
|
@ -39,20 +49,36 @@ class Teams extends Service {
|
|||
'roles': roles,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Team
|
||||
///
|
||||
/// Get team by its unique ID. All team members have read access for this
|
||||
/// resource.
|
||||
///
|
||||
Future<Response> get({@required String teamId}) {
|
||||
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Team
|
||||
///
|
||||
/// Update team by its unique ID. Only team owners have write access for this
|
||||
/// resource.
|
||||
///
|
||||
Future<Response> update({@required String teamId, @required String name}) {
|
||||
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
|
||||
|
||||
|
@ -60,28 +86,51 @@ class Teams extends Service {
|
|||
'name': name,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.put, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete Team
|
||||
///
|
||||
/// Delete team by its unique ID. Only team owners have write access for this
|
||||
/// resource.
|
||||
///
|
||||
Future<Response> delete({@required String teamId}) {
|
||||
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Get Team Memberships
|
||||
///
|
||||
/// Get team members by the team unique ID. All team members have read access
|
||||
/// for this list of resources.
|
||||
///
|
||||
Future<Response> getMemberships({@required String teamId}) {
|
||||
final String path = '/teams/{teamId}/memberships'.replaceAll(RegExp('{teamId}'), teamId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Create Team Membership
|
||||
///
|
||||
/// Use this endpoint to invite a new member to join your team. An email with a
|
||||
/// link to join the team will be sent to the new member email address if the
|
||||
/// member doesn't exist in the project it will be created automatically.
|
||||
|
@ -95,6 +144,7 @@ class Teams extends Service {
|
|||
/// Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
|
||||
/// the only valid redirect URL's are the once from domains you have set when
|
||||
/// added your platforms in the console interface.
|
||||
///
|
||||
Future<Response> createMembership({@required String teamId, @required String email, @required List roles, @required String url, String name = ''}) {
|
||||
final String path = '/teams/{teamId}/memberships'.replaceAll(RegExp('{teamId}'), teamId);
|
||||
|
||||
|
@ -105,22 +155,38 @@ class Teams extends Service {
|
|||
'url': url,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Delete Team Membership
|
||||
///
|
||||
/// This endpoint allows a user to leave a team or for a team owner to delete
|
||||
/// the membership of any other team member. You can also use this endpoint to
|
||||
/// delete a user membership even if he didn't accept it.
|
||||
///
|
||||
Future<Response> deleteMembership({@required String teamId, @required String inviteId}) {
|
||||
final String path = '/teams/{teamId}/memberships/{inviteId}'.replaceAll(RegExp('{teamId}'), teamId).replaceAll(RegExp('{inviteId}'), inviteId);
|
||||
|
||||
final Map<String, dynamic> params = {
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
|
||||
}
|
||||
|
||||
/// Update Team Membership Status
|
||||
///
|
||||
/// Use this endpoint to allow a user to accept an invitation to join a team
|
||||
/// after he is being redirected back to your app from the invitation email he
|
||||
/// was sent.
|
||||
///
|
||||
Future<Response> updateMembershipStatus({@required String teamId, @required String inviteId, @required String userId, @required String secret}) {
|
||||
final String path = '/teams/{teamId}/memberships/{inviteId}/status'.replaceAll(RegExp('{teamId}'), teamId).replaceAll(RegExp('{inviteId}'), inviteId);
|
||||
|
||||
|
@ -129,6 +195,10 @@ class Teams extends Service {
|
|||
'secret': secret,
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params);
|
||||
final Map<String, String> headers = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,10 @@ sdk
|
|||
.setProject('5df5acd0d48c2') // Your project ID
|
||||
;
|
||||
|
||||
let result = sdk.account.createOAuth2Session('bitbucket', 'https://example.com', 'https://example.com');
|
||||
let promise = sdk.account.createOAuth2Session('bitbucket');
|
||||
|
||||
console.log(result); // Resource URL
|
||||
promise.then(function (response) {
|
||||
console.log(response); // Success
|
||||
}, function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
|
@ -286,28 +286,6 @@
|
|||
}
|
||||
}(window.document);
|
||||
|
||||
let iframe = function(method, url, params) {
|
||||
let form = document.createElement('form');
|
||||
|
||||
form.setAttribute('method', method);
|
||||
form.setAttribute('action', config.endpoint + url);
|
||||
|
||||
for(let key in params) {
|
||||
if(params.hasOwnProperty(key)) {
|
||||
let hiddenField = document.createElement("input");
|
||||
hiddenField.setAttribute("type", "hidden");
|
||||
hiddenField.setAttribute("name", key);
|
||||
hiddenField.setAttribute("value", params[key]);
|
||||
|
||||
form.appendChild(hiddenField);
|
||||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(form);
|
||||
|
||||
return form.submit();
|
||||
};
|
||||
|
||||
let account = {
|
||||
|
||||
/**
|
||||
|
@ -768,21 +746,13 @@
|
|||
* @param {string} success
|
||||
* @param {string} failure
|
||||
* @throws {Error}
|
||||
* @return {string}
|
||||
* @return {Promise}
|
||||
*/
|
||||
createOAuth2Session: function(provider, success, failure) {
|
||||
createOAuth2Session: function(provider, success = 'https://localhost:2444/auth/oauth2/success', failure = 'https://localhost:2444/auth/oauth2/failure') {
|
||||
if(provider === undefined) {
|
||||
throw new Error('Missing required parameter: "provider"');
|
||||
}
|
||||
|
||||
if(success === undefined) {
|
||||
throw new Error('Missing required parameter: "success"');
|
||||
}
|
||||
|
||||
if(failure === undefined) {
|
||||
throw new Error('Missing required parameter: "failure"');
|
||||
}
|
||||
|
||||
let path = '/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}', 'g'), provider);
|
||||
|
||||
let payload = {};
|
||||
|
@ -798,8 +768,8 @@
|
|||
payload['project'] = config.project;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
|
||||
window.location = config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1743,7 +1713,7 @@
|
|||
payload['project'] = config.project;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
|
@ -1796,7 +1766,7 @@
|
|||
payload['project'] = config.project;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
},
|
||||
|
||||
|
@ -1827,7 +1797,7 @@
|
|||
payload['project'] = config.project;
|
||||
|
||||
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
|
||||
|
||||
|
||||
return config.endpoint + path + ((query) ? '?' + query : '');
|
||||
}
|
||||
};
|
||||
|
|
9
app/sdks/web-javascript/src/sdk.min.js
vendored
9
app/sdks/web-javascript/src/sdk.min.js
vendored
|
@ -12,8 +12,7 @@ request.setRequestHeader(key,headers[key])}}
|
|||
request.onload=function(){if(4===request.readyState&&399>=request.status){let data=request.response;let contentType=this.getResponseHeader('content-type')||'';contentType=contentType.substring(0,contentType.indexOf(';'));switch(contentType){case 'application/json':data=JSON.parse(data);break}
|
||||
let cookieFallback=this.getResponseHeader('X-Fallback-Cookies')||'';if(window.localStorage&&cookieFallback){window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');window.localStorage.setItem('cookieFallback',cookieFallback)}
|
||||
resolve(data)}else{reject(new Error(request.statusText))}};if(progress){request.addEventListener('progress',progress);request.upload.addEventListener('progress',progress,!1)}
|
||||
request.onerror=function(){reject(new Error("Network Error"))};request.send(params)})};return{'get':function(path,headers={},params={}){return call('GET',path+((Object.keys(params).length>0)?'?'+buildQuery(params):''),headers,{})},'post':function(path,headers={},params={},progress=null){return call('POST',path,headers,params,progress)},'put':function(path,headers={},params={},progress=null){return call('PUT',path,headers,params,progress)},'patch':function(path,headers={},params={},progress=null){return call('PATCH',path,headers,params,progress)},'delete':function(path,headers={},params={},progress=null){return call('DELETE',path,headers,params,progress)},'addGlobalParam':addGlobalParam,'addGlobalHeader':addGlobalHeader}}(window.document);let iframe=function(method,url,params){let form=document.createElement('form');form.setAttribute('method',method);form.setAttribute('action',config.endpoint+url);for(let key in params){if(params.hasOwnProperty(key)){let hiddenField=document.createElement("input");hiddenField.setAttribute("type","hidden");hiddenField.setAttribute("name",key);hiddenField.setAttribute("value",params[key]);form.appendChild(hiddenField)}}
|
||||
document.body.appendChild(form);return form.submit()};let account={get:function(){let path='/account';let payload={};return http.get(path,{'content-type':'application/json',},payload)},create:function(email,password,name=''){if(email===undefined){throw new Error('Missing required parameter: "email"')}
|
||||
request.onerror=function(){reject(new Error("Network Error"))};request.send(params)})};return{'get':function(path,headers={},params={}){return call('GET',path+((Object.keys(params).length>0)?'?'+buildQuery(params):''),headers,{})},'post':function(path,headers={},params={},progress=null){return call('POST',path,headers,params,progress)},'put':function(path,headers={},params={},progress=null){return call('PUT',path,headers,params,progress)},'patch':function(path,headers={},params={},progress=null){return call('PATCH',path,headers,params,progress)},'delete':function(path,headers={},params={},progress=null){return call('DELETE',path,headers,params,progress)},'addGlobalParam':addGlobalParam,'addGlobalHeader':addGlobalHeader}}(window.document);let account={get:function(){let path='/account';let payload={};return http.get(path,{'content-type':'application/json',},payload)},create:function(email,password,name=''){if(email===undefined){throw new Error('Missing required parameter: "email"')}
|
||||
if(password===undefined){throw new Error('Missing required parameter: "password"')}
|
||||
let path='/account';let payload={};if(email){payload.email=email}
|
||||
if(password){payload.password=password}
|
||||
|
@ -46,12 +45,10 @@ return http.put(path,{'content-type':'application/json',},payload)},getSessions:
|
|||
if(password===undefined){throw new Error('Missing required parameter: "password"')}
|
||||
let path='/account/sessions';let payload={};if(email){payload.email=email}
|
||||
if(password){payload.password=password}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success,failure){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
|
||||
if(success===undefined){throw new Error('Missing required parameter: "success"')}
|
||||
if(failure===undefined){throw new Error('Missing required parameter: "failure"')}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success='https://localhost:2444/auth/oauth2/success',failure='https://localhost:2444/auth/oauth2/failure'){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
|
||||
let path='/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}','g'),provider);let payload={};if(success){payload.success=success}
|
||||
if(failure){payload.failure=failure}
|
||||
payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
|
||||
payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');window.location=config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
|
||||
let path='/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}','g'),sessionId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"')}
|
||||
let path='/account/verification';let payload={};if(url){payload.url=url}
|
||||
return http.post(path,{'content-type':'application/json',},payload)},updateVerification:function(userId,secret){if(userId===undefined){throw new Error('Missing required parameter: "userId"')}
|
||||
|
|
12
composer.lock
generated
12
composer.lock
generated
|
@ -1622,7 +1622,7 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/appwrite/sdk-generator",
|
||||
"reference": "3e1012da0fec5559f0859816b4c3fecea23fe808"
|
||||
"reference": "a139044dd98eccf9c909977b8fcfd39faedc876d"
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
|
@ -1652,7 +1652,7 @@
|
|||
}
|
||||
],
|
||||
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
|
||||
"time": "2020-04-10T08:25:22+00:00"
|
||||
"time": "2020-04-11T09:38:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/instantiator",
|
||||
|
@ -1979,12 +1979,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
|
||||
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d"
|
||||
"reference": "74a67151cce1fe4aa5960636ae510ddf1faefdb3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
|
||||
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/74a67151cce1fe4aa5960636ae510ddf1faefdb3",
|
||||
"reference": "74a67151cce1fe4aa5960636ae510ddf1faefdb3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2023,7 +2023,7 @@
|
|||
"reflection",
|
||||
"static analysis"
|
||||
],
|
||||
"time": "2019-12-20T12:45:35+00:00"
|
||||
"time": "2020-04-10T20:41:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-docblock",
|
||||
|
|
Loading…
Reference in a new issue