Skip to content

Commit dd6e9a4

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat-react-native-sdk
2 parents ea10075 + 8828819 commit dd6e9a4

34 files changed

+812
-1193
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getSSLPage($url) {
4242
$platform = 'console';
4343
// $platform = 'server';
4444

45-
$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/feat-rc-sdks/app/config/specs/swagger2-latest-{$platform}.json");
45+
$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.5.x/app/config/specs/swagger2-latest-{$platform}.json");
4646

4747
if(empty($spec)) {
4848
throw new Exception('Failed to fetch spec from Appwrite server');

src/SDK/Language/Node.php

Lines changed: 157 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Appwrite\SDK\Language;
44

5-
class Node extends JS
5+
class Node extends Web
66
{
77
/**
88
* @return string
@@ -12,31 +12,138 @@ public function getName(): string
1212
return 'NodeJS';
1313
}
1414

15-
/**
16-
* @param array $parameter
17-
* @param array $spec
18-
* @return string
19-
*/
20-
public function getTypeName(array $parameter, array $spec = []): string
15+
public function getTypeName(array $parameter, array $method = []): string
2116
{
2217
if (isset($parameter['enumName'])) {
2318
return \ucfirst($parameter['enumName']);
2419
}
2520
if (!empty($parameter['enumValues'])) {
2621
return \ucfirst($parameter['name']);
2722
}
28-
return match ($parameter['type']) {
29-
self::TYPE_INTEGER,
30-
self::TYPE_NUMBER => 'number',
31-
self::TYPE_STRING => 'string',
32-
self::TYPE_FILE => 'InputFile',
33-
self::TYPE_BOOLEAN => 'boolean',
34-
self::TYPE_OBJECT => 'object',
35-
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
36-
? $this->getTypeName($parameter['array']) . '[]'
37-
: 'string[]',
38-
default => $parameter['type'],
39-
};
23+
switch ($parameter['type']) {
24+
case self::TYPE_INTEGER:
25+
case self::TYPE_NUMBER:
26+
return 'number';
27+
case self::TYPE_ARRAY:
28+
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) {
29+
return $this->getTypeName($parameter['array']) . '[]';
30+
}
31+
return 'string[]';
32+
case self::TYPE_FILE:
33+
return "File";
34+
case self::TYPE_OBJECT:
35+
if (empty($method)) {
36+
return $parameter['type'];
37+
}
38+
switch ($method['responseModel']) {
39+
case 'user':
40+
return "Partial<Preferences>";
41+
case 'document':
42+
if ($method['method'] === 'post') {
43+
return "Omit<Document, keyof Models.Document>";
44+
}
45+
if ($method['method'] === 'patch') {
46+
return "Partial<Omit<Document, keyof Models.Document>>";
47+
}
48+
}
49+
break;
50+
}
51+
return $parameter['type'];
52+
}
53+
54+
public function getReturn(array $method, array $spec): string
55+
{
56+
if ($method['type'] === 'webAuth') {
57+
return 'Promise<string>';
58+
}
59+
60+
if ($method['type'] === 'location') {
61+
return 'Promise<ArrayBuffer>';
62+
}
63+
64+
if (array_key_exists('responseModel', $method) && !empty($method['responseModel']) && $method['responseModel'] !== 'any') {
65+
$ret = 'Promise<';
66+
67+
if (
68+
array_key_exists($method['responseModel'], $spec['definitions']) &&
69+
array_key_exists('additionalProperties', $spec['definitions'][$method['responseModel']]) &&
70+
!$spec['definitions'][$method['responseModel']]['additionalProperties']
71+
) {
72+
$ret .= 'Models.';
73+
}
74+
75+
$ret .= $this->toPascalCase($method['responseModel']);
76+
77+
$models = [];
78+
79+
$this->populateGenerics($method['responseModel'], $spec, $models);
80+
81+
$models = array_unique($models);
82+
$models = array_filter($models, fn ($model) => $model != $this->toPascalCase($method['responseModel']));
83+
84+
if (!empty($models)) {
85+
$ret .= '<' . implode(', ', $models) . '>';
86+
}
87+
88+
$ret .= '>';
89+
90+
return $ret;
91+
}
92+
return 'Promise<{}>';
93+
}
94+
95+
/**
96+
* @param array $param
97+
* @return string
98+
*/
99+
public function getParamExample(array $param): string
100+
{
101+
$type = $param['type'] ?? '';
102+
$example = $param['example'] ?? '';
103+
104+
$output = '';
105+
106+
if (empty($example) && $example !== 0 && $example !== false) {
107+
switch ($type) {
108+
case self::TYPE_NUMBER:
109+
case self::TYPE_INTEGER:
110+
case self::TYPE_BOOLEAN:
111+
$output .= 'null';
112+
break;
113+
case self::TYPE_STRING:
114+
$output .= "''";
115+
break;
116+
case self::TYPE_ARRAY:
117+
$output .= '[]';
118+
break;
119+
case self::TYPE_OBJECT:
120+
$output .= '{}';
121+
break;
122+
case self::TYPE_FILE:
123+
$output .= "InputFile.fromPath('/path/to/file', 'filename')";
124+
break;
125+
}
126+
} else {
127+
switch ($type) {
128+
case self::TYPE_NUMBER:
129+
case self::TYPE_INTEGER:
130+
case self::TYPE_ARRAY:
131+
case self::TYPE_OBJECT:
132+
$output .= $example;
133+
break;
134+
case self::TYPE_BOOLEAN:
135+
$output .= ($example) ? 'true' : 'false';
136+
break;
137+
case self::TYPE_STRING:
138+
$output .= "'{$example}'";
139+
break;
140+
case self::TYPE_FILE:
141+
$output .= "InputFile.fromPath('/path/to/file', 'filename')";
142+
break;
143+
}
144+
}
145+
146+
return $output;
40147
}
41148

42149
/**
@@ -47,53 +154,48 @@ public function getFiles(): array
47154
return [
48155
[
49156
'scope' => 'default',
50-
'destination' => 'index.js',
51-
'template' => 'node/index.js.twig',
157+
'destination' => 'src/index.ts',
158+
'template' => 'node/src/index.ts.twig',
52159
],
53160
[
54161
'scope' => 'default',
55-
'destination' => 'index.d.ts',
56-
'template' => 'node/index.d.ts.twig',
162+
'destination' => 'src/client.ts',
163+
'template' => 'node/src/client.ts.twig',
57164
],
58165
[
59166
'scope' => 'default',
60-
'destination' => 'lib/client.js',
61-
'template' => 'node/lib/client.js.twig',
167+
'destination' => 'src/inputFile.ts',
168+
'template' => 'node/src/inputFile.ts.twig',
62169
],
63170
[
64-
'scope' => 'default',
65-
'destination' => 'lib/permission.js',
66-
'template' => 'node/lib/permission.js.twig',
171+
'scope' => 'service',
172+
'destination' => 'src/services/{{service.name | caseDash}}.ts',
173+
'template' => 'node/src/services/template.ts.twig',
67174
],
68175
[
69176
'scope' => 'default',
70-
'destination' => 'lib/role.js',
71-
'template' => 'node/lib/role.js.twig',
177+
'destination' => 'src/models.ts',
178+
'template' => 'web/src/models.ts.twig',
72179
],
73180
[
74181
'scope' => 'default',
75-
'destination' => 'lib/id.js',
76-
'template' => 'node/lib/id.js.twig',
182+
'destination' => 'src/permission.ts',
183+
'template' => 'web/src/permission.ts.twig',
77184
],
78185
[
79186
'scope' => 'default',
80-
'destination' => 'lib/query.js',
81-
'template' => 'node/lib/query.js.twig',
187+
'destination' => 'src/role.ts',
188+
'template' => 'web/src/role.ts.twig',
82189
],
83190
[
84191
'scope' => 'default',
85-
'destination' => 'lib/inputFile.js',
86-
'template' => 'node/lib/inputFile.js.twig',
192+
'destination' => 'src/id.ts',
193+
'template' => 'web/src/id.ts.twig',
87194
],
88195
[
89196
'scope' => 'default',
90-
'destination' => '/lib/service.js',
91-
'template' => 'node/lib/service.js.twig',
92-
],
93-
[
94-
'scope' => 'service',
95-
'destination' => '/lib/services/{{service.name | caseDash}}.js',
96-
'template' => 'node/lib/services/service.js.twig',
197+
'destination' => 'src/query.ts',
198+
'template' => 'web/src/query.ts.twig',
97199
],
98200
[
99201
'scope' => 'default',
@@ -115,80 +217,31 @@ public function getFiles(): array
115217
'destination' => 'package.json',
116218
'template' => 'node/package.json.twig',
117219
],
118-
[
119-
'scope' => 'default',
120-
'destination' => 'lib/exception.js',
121-
'template' => 'node/lib/exception.js.twig',
122-
],
123220
[
124221
'scope' => 'method',
125222
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
126223
'template' => 'node/docs/example.md.twig',
127224
],
225+
[
226+
'scope' => 'default',
227+
'destination' => 'tsconfig.json',
228+
'template' => '/node/tsconfig.json.twig',
229+
],
230+
[
231+
'scope' => 'default',
232+
'destination' => 'tsup.config.js',
233+
'template' => 'node/tsup.config.js.twig',
234+
],
128235
[
129236
'scope' => 'default',
130237
'destination' => '.travis.yml',
131238
'template' => 'node/.travis.yml.twig',
132239
],
133240
[
134241
'scope' => 'enum',
135-
'destination' => 'lib/enums/{{ enum.name | caseDash }}.js',
136-
'template' => 'node/lib/enums/enum.js.twig',
242+
'destination' => 'src/enums/{{ enum.name | caseDash }}.ts',
243+
'template' => 'web/src/enums/enum.ts.twig',
137244
],
138245
];
139246
}
140-
141-
/**
142-
* @param array $param
143-
* @return string
144-
*/
145-
public function getParamExample(array $param): string
146-
{
147-
$type = $param['type'] ?? '';
148-
$example = $param['example'] ?? '';
149-
150-
$output = '';
151-
152-
if (empty($example) && $example !== 0 && $example !== false) {
153-
switch ($type) {
154-
case self::TYPE_NUMBER:
155-
case self::TYPE_INTEGER:
156-
case self::TYPE_BOOLEAN:
157-
$output .= 'null';
158-
break;
159-
case self::TYPE_STRING:
160-
$output .= "''";
161-
break;
162-
case self::TYPE_ARRAY:
163-
$output .= '[]';
164-
break;
165-
case self::TYPE_OBJECT:
166-
$output .= '{}';
167-
break;
168-
case self::TYPE_FILE:
169-
$output .= "InputFile.fromPath('/path/to/file.png', 'file.png')";
170-
break;
171-
}
172-
} else {
173-
switch ($type) {
174-
case self::TYPE_NUMBER:
175-
case self::TYPE_INTEGER:
176-
case self::TYPE_ARRAY:
177-
case self::TYPE_OBJECT:
178-
$output .= $example;
179-
break;
180-
case self::TYPE_BOOLEAN:
181-
$output .= ($example) ? 'true' : 'false';
182-
break;
183-
case self::TYPE_STRING:
184-
$output .= "'{$example}'";
185-
break;
186-
case self::TYPE_FILE:
187-
$output .= "InputFile.fromPath('/path/to/file.png', 'file.png')";
188-
break;
189-
}
190-
}
191-
192-
return $output;
193-
}
194247
}

templates/cli/lib/commands/generic.js.twig

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const { sdkForConsole } = require("../sdks");
55
const { globalConfig, localConfig } = require("../config");
66
const { actionRunner, success, parseBool, commandDescriptions, log, parse } = require("../parser");
77
{% if sdk.test != "true" %}
8-
const { questionsLogin } = require("../questions");
9-
const { accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
8+
const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
9+
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
1010

1111
const login = new Command("login")
1212
.description(commandDescriptions['login'])
@@ -25,7 +25,44 @@ const login = new Command("login")
2525
sdk: client
2626
})
2727

28-
success()
28+
client.setCookie(globalConfig.getCookie());
29+
30+
let account;
31+
32+
try {
33+
account = await accountGet({
34+
sdk: client,
35+
parseOutput: false
36+
});
37+
} catch(error) {
38+
if (error.response === 'user_more_factors_required') {
39+
const { factor } = await inquirer.prompt(questionsListFactors);
40+
41+
const challenge = await accountCreateMfaChallenge({
42+
factor,
43+
parseOutput: false,
44+
sdk: client
45+
});
46+
47+
const { otp } = await inquirer.prompt(questionsMfaChallenge);
48+
49+
await accountUpdateMfaChallenge({
50+
challengeId: challenge.$id,
51+
otp,
52+
parseOutput: false,
53+
sdk: client
54+
});
55+
56+
account = await accountGet({
57+
sdk: client,
58+
parseOutput: false
59+
});
60+
} else {
61+
throw error;
62+
}
63+
}
64+
65+
success("Signed in as user with ID: " + account.$id);
2966
}));
3067

3168
const logout = new Command("logout")

0 commit comments

Comments
 (0)