Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 20 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
# Change Log


## 28.2.0-rc.7

* Added: `Analytics` service and the `Tracking` auto-tracking helper, which were missing from `28.2.0-rc.5` and `rc.6`
* Changed: `Tracking` takes `new Analytics(client)` and a property id instead of an emitter callback; the adapter to `createEvent` now lives inside the SDK
* Changed: `enableAllAutoTracking()` is now `start()`
* Removed: `AnalyticsEventEmitter`; the option types are now `TrackingEventOptions` and `TrackingOptions`

## 28.2.0-rc.6

* Added: `Push.onNotificationOpened()` fires when a user taps a shown notification
* Added: `Push.getInitialNotification()` (returns `null` on web) and the `PushNotificationOpened` type
* Added: tapping a push notification focuses then closes the page
* Fixed: `subscribe()` resolves the signed-in user from `cookieFallback`, not just an explicit session
* Fixed: background notifications de-duplicate by title, so each distinct title posts once
* Updated: clearer error messages for missing credentials in push

## 28.2.0-rc.5

* Updated: regenerated with sdk-generator 5.5.0; no SDK code changes

## 28.2.0-rc.3

* Added: background push notifications render the server `notification` title, body, and image
* Added: notification `data` now carries `topic` and `payload`
* Fixed: a server-sent title dedupes to one notification per topic instead of one per subscription
* Fixed: malformed push payloads no longer break notification rendering

## 28.2.0-rc.2

* Added: `Push` service for MQTT realtime push messages
* Added: `Topic` and `ResolvedTopic` builders for push topic filters
## 29.0.0

* Breaking: `Oauth2` `resource` parameter is now `string[]` instead of `string`
* Breaking: `Teams.createMembership` takes `membershipId` after `roles`; positional callers must update
* Added: `Account.listPasskeys`, `createPasskey`, `getPasskey`, `updatePasskey` and `deletePasskey`
* Added: `Account.updatePasskeyVerification` to finish registering a passkey
* Added: `Account.createPasskeyToken` and `Account.updatePasskeyToken` for passkey sign-in
* Added: `Passkey`, `PasskeyList`, `PasskeyChallenge` and `TokenSecret` models
* Added: `Push` service for MQTT realtime push, with `Topic` and `ResolvedTopic` builders
* Added: `Client.setPushEndpoint()` and `Client.setPushClientId()`
* Added: `Avatars.deletePhoto()` method
* Added: `Models.Account` type
* Added: background push notifications render the server `notification` title, body, and image
* Added: `Push.onNotificationOpened()`, `Push.getInitialNotification()` and the `PushNotificationOpened` type
* Added: `Analytics` service with `createEvent`
* Added: `Tracking` helper for automatic pageviews, outbound links, downloads, scroll depth and engagement
* Added: `Avatars.updatePhoto()` and `Avatars.deletePhoto()` methods, and the `Models.Account` type
* Added: `state` parameter to `Account.createOAuth2Session` and `Account.createOAuth2Token`
* Added: `duration` parameter to `Account.createEmailPasswordSession`
* Added: `current` parameter to `Account.deleteSessions`
* Added: `total` parameter to `Account.listSessions`, `Locale` list methods and `listTransactions`
* Added: `Webflow` to the `OAuthProvider` enum
* Fixed: response models fill missing fields from spec defaults instead of throwing
* Updated: `Client.chunkedUpload()` accepts a `responseType`, supports `text`, and falls back without a file
* Updated: SDK now targets Appwrite 2.4 (`X-Appwrite-Response-Format: 2.4.0`)

## 28.1.0

Expand Down Expand Up @@ -250,4 +236,3 @@
* Fix pong response & chunked upload
* Add `ping` support to `Realtime` service


6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Appwrite Web SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.3.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.4.0-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK targets Appwrite server version 2.3.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-web/releases) when APIs differ.
**This SDK targets Appwrite server version 2.4.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-web/releases) when APIs differ.

Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Web SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

Expand All @@ -33,7 +33,7 @@ import { Client, Account } from 'appwrite';
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:

```html
<script src="https://cdn.jsdelivr.net/npm/appwrite@28.2.0-rc.7"></script>
<script src="https://cdn.jsdelivr.net/npm/appwrite@29.0.0"></script>
```

## Getting Started
Expand Down
13 changes: 13 additions & 0 deletions docs/examples/account/create-passkey-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.createPasskeyToken();

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/account/create-passkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.createPasskey({
passkeyId: '<PASSKEY_ID>', // optional
name: '<NAME>', // optional
});

console.log(result);
```
15 changes: 15 additions & 0 deletions docs/examples/account/delete-passkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.deletePasskey({
passkeyId: '<PASSKEY_ID>',
});

console.log(result);
```
15 changes: 15 additions & 0 deletions docs/examples/account/get-passkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.getPasskey({
passkeyId: '<PASSKEY_ID>',
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/account/list-passkeys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.listPasskeys({
queries: [], // optional
total: false, // optional
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/account/update-passkey-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.updatePasskeyToken({
challengeId: '<CHALLENGE_ID>',
credential: {},
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/account/update-passkey-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.updatePasskeyVerification({
passkeyId: '<PASSKEY_ID>',
credential: {},
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/account/update-passkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Account } from 'appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.updatePasskey({
passkeyId: '<PASSKEY_ID>',
name: '<NAME>',
});

console.log(result);
```
2 changes: 1 addition & 1 deletion docs/examples/oauth2/authorize-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const result = await oauth2.authorizePost({
prompt: '<PROMPT>', // optional
maxAge: 0, // optional
authorizationDetails: '<AUTHORIZATION_DETAILS>', // optional
resource: '', // optional
resource: [], // optional
audience: '<AUDIENCE>', // optional
requestUri: '<REQUEST_URI>', // optional
});
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/oauth2/authorize.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const result = await oauth2.authorize({
prompt: '<PROMPT>', // optional
maxAge: 0, // optional
authorizationDetails: '<AUTHORIZATION_DETAILS>', // optional
resource: '', // optional
resource: [], // optional
audience: '<AUDIENCE>', // optional
requestUri: '<REQUEST_URI>', // optional
});
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/oauth2/create-device-authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const result = await oauth2.createDeviceAuthorization({
clientId: '<CLIENT_ID>', // optional
scope: '<SCOPE>', // optional
authorizationDetails: '<AUTHORIZATION_DETAILS>', // optional
resource: '', // optional
resource: [], // optional
audience: '<AUDIENCE>', // optional
});

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/oauth2/create-par.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const result = await oauth2.createPAR({
prompt: '<PROMPT>', // optional
maxAge: 0, // optional
authorizationDetails: '<AUTHORIZATION_DETAILS>', // optional
resource: '', // optional
resource: [], // optional
audience: '<AUDIENCE>', // optional
});

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/oauth2/create-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const result = await oauth2.createToken({
clientSecret: '<CLIENT_SECRET>', // optional
codeVerifier: '<CODE_VERIFIER>', // optional
redirectUri: 'https://example.com', // optional
resource: '', // optional
resource: [], // optional
audience: '<AUDIENCE>', // optional
});

Expand Down
1 change: 1 addition & 0 deletions docs/examples/teams/create-membership.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const teams = new Teams(client);
const result = await teams.createMembership({
teamId: '<TEAM_ID>',
roles: ['editor'],
membershipId: '<MEMBERSHIP_ID>', // optional
email: 'email@example.com', // optional
userId: '<USER_ID>', // optional
phone: '+12065550100', // optional
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
"version": "28.2.0-rc.7",
"version": "29.0.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
48 changes: 46 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,50 @@ export const JSONbig = {
stringify: JSONbigSerializer.stringify,
};

type DefaultsShape = string | { items: DefaultsShape };

type DefaultsModel = {
defaults?: Record<string, unknown>;
properties?: Record<string, DefaultsShape>;
};

type Defaults = {
root: DefaultsShape;
models: Record<string, DefaultsModel>;
};

export function applyDefaults<T>(value: T, tree: Defaults): T {
return fillDefaults(value, tree.root, tree.models) as T;
}

function fillDefaults(
value: unknown,
shape: DefaultsShape,
models: Record<string, DefaultsModel>,
): unknown {
if (typeof shape !== 'string') {
if (!Array.isArray(value)) {
return value;
}
const items = shape.items;
return value.map((item) => fillDefaults(item, items, models));
}
const model = models[shape];
if (!model || typeof value !== 'object' || value === null) {
return value;
}
if (Array.isArray(value)) {
return value;
}
const result: Record<string, unknown> = { ...model.defaults, ...value };
for (const [key, child] of Object.entries(model.properties ?? {})) {
if (key in result) {
result[key] = fillDefaults(result[key], child, models);
}
}
return result;
}

/**
* Payload type representing a key-value pair with string keys and any values.
*/
Expand Down Expand Up @@ -401,8 +445,8 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
'x-sdk-version': '28.2.0-rc.7',
'X-Appwrite-Response-Format': '2.3.0',
'x-sdk-version': '29.0.0',
'X-Appwrite-Response-Format': '2.4.0',
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Appwrite Web SDK
*
* This SDK targets Appwrite server version 2.3.x as shipped on Appwrite Cloud.
* This SDK targets Appwrite server version 2.4.x as shipped on Appwrite Cloud.
* Self-hosted releases can lag behind Cloud — if you run an older self-hosted
* build, use a matching older SDK from
* [previous releases](https://github.com/appwrite/sdk-for-web/releases)
Expand Down
Loading
Loading