diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e6ea266..47ba248 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Use Node.js - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version: '24.14.1' registry-url: 'https://registry.npmjs.org' diff --git a/CHANGELOG.md b/CHANGELOG.md index 2adc7bb..6c0f0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## 12.1.0 + +* Added: `setSession` method on `Client` for `X-Appwrite-Session` authentication +* Added: `setDevKey` method on `Client` for `X-Appwrite-Dev-Key` authentication +* Added: `suggestQueries` method on `Console` service +* Added: `QuerySuggestionResource` enum for supported list resource types +* Added: `project.policies.read`, `project.policies.write`, `backups.policies.read`, `backups.policies.write` scopes +* Updated: `setCookie` documentation clarified for server-side runtimes + ## 12.0.0 * Breaking: Renamed `AuthMethod` enum to `MethodId` diff --git a/README.md b/README.md index 61a3c80..5fe2f0f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ import { Client, Account } from "@appwrite.io/console"; To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services: ```html - + ``` diff --git a/docs/examples/console/create-program-membership.md b/docs/examples/console/create-program-membership.md index fa19b0c..23ed45d 100644 --- a/docs/examples/console/create-program-membership.md +++ b/docs/examples/console/create-program-membership.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.createProgramMembership({ +const result = await xconsole.createProgramMembership({ programId: '' }); diff --git a/docs/examples/console/create-source.md b/docs/examples/console/create-source.md index a5283da..b6307b1 100644 --- a/docs/examples/console/create-source.md +++ b/docs/examples/console/create-source.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.createSource({ +const result = await xconsole.createSource({ ref: '', // optional referrer: 'https://example.com', // optional utmSource: '', // optional diff --git a/docs/examples/console/get-campaign.md b/docs/examples/console/get-campaign.md index 703c6e3..e9d41ae 100644 --- a/docs/examples/console/get-campaign.md +++ b/docs/examples/console/get-campaign.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getCampaign({ +const result = await xconsole.getCampaign({ campaignId: '' }); diff --git a/docs/examples/console/get-coupon.md b/docs/examples/console/get-coupon.md index 74c7a57..716d26a 100644 --- a/docs/examples/console/get-coupon.md +++ b/docs/examples/console/get-coupon.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getCoupon({ +const result = await xconsole.getCoupon({ couponId: '' }); diff --git a/docs/examples/console/get-plan.md b/docs/examples/console/get-plan.md index 4c86072..7171de6 100644 --- a/docs/examples/console/get-plan.md +++ b/docs/examples/console/get-plan.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getPlan({ +const result = await xconsole.getPlan({ planId: '' }); diff --git a/docs/examples/console/get-plans.md b/docs/examples/console/get-plans.md index 546c728..c5d846a 100644 --- a/docs/examples/console/get-plans.md +++ b/docs/examples/console/get-plans.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getPlans({ +const result = await xconsole.getPlans({ platform: Platform.Appwrite // optional }); diff --git a/docs/examples/console/get-program.md b/docs/examples/console/get-program.md index 038cf5f..5e19bcf 100644 --- a/docs/examples/console/get-program.md +++ b/docs/examples/console/get-program.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getProgram({ +const result = await xconsole.getProgram({ programId: '' }); diff --git a/docs/examples/console/get-resource.md b/docs/examples/console/get-resource.md index 706d96e..699a83d 100644 --- a/docs/examples/console/get-resource.md +++ b/docs/examples/console/get-resource.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.getResource({ +const result = await xconsole.getResource({ value: '', type: ConsoleResourceType.Rules }); diff --git a/docs/examples/console/list-o-auth-2-providers.md b/docs/examples/console/list-o-auth-2-providers.md index d26800b..278d16d 100644 --- a/docs/examples/console/list-o-auth-2-providers.md +++ b/docs/examples/console/list-o-auth-2-providers.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.listOAuth2Providers(); +const result = await xconsole.listOAuth2Providers(); console.log(result); ``` diff --git a/docs/examples/console/list-project-scopes.md b/docs/examples/console/list-project-scopes.md index b1cb803..f59300a 100644 --- a/docs/examples/console/list-project-scopes.md +++ b/docs/examples/console/list-project-scopes.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.listProjectScopes(); +const result = await xconsole.listProjectScopes(); console.log(result); ``` diff --git a/docs/examples/console/list-regions.md b/docs/examples/console/list-regions.md index 5d49fee..ef750a8 100644 --- a/docs/examples/console/list-regions.md +++ b/docs/examples/console/list-regions.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.listRegions(); +const result = await xconsole.listRegions(); console.log(result); ``` diff --git a/docs/examples/console/suggest-columns.md b/docs/examples/console/suggest-columns.md index 32daa10..50e866e 100644 --- a/docs/examples/console/suggest-columns.md +++ b/docs/examples/console/suggest-columns.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.suggestColumns({ +const result = await xconsole.suggestColumns({ databaseId: '', tableId: '', context: '', // optional diff --git a/docs/examples/console/suggest-indexes.md b/docs/examples/console/suggest-indexes.md index e59e337..3014fc3 100644 --- a/docs/examples/console/suggest-indexes.md +++ b/docs/examples/console/suggest-indexes.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.suggestIndexes({ +const result = await xconsole.suggestIndexes({ databaseId: '', tableId: '', min: 1, // optional diff --git a/docs/examples/console/suggest-queries.md b/docs/examples/console/suggest-queries.md new file mode 100644 index 0000000..cbffccc --- /dev/null +++ b/docs/examples/console/suggest-queries.md @@ -0,0 +1,18 @@ +```javascript +import { Client, Console, QuerySuggestionResource } from "@appwrite.io/console"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const xconsole = new Console(client); + +const result = await xconsole.suggestQueries({ + resource: QuerySuggestionResource.Activities, + input: '', + databaseId: '', // optional + tableId: '' // optional +}); + +console.log(result); +``` diff --git a/docs/examples/console/variables.md b/docs/examples/console/variables.md index d8c4077..3eafec1 100644 --- a/docs/examples/console/variables.md +++ b/docs/examples/console/variables.md @@ -5,9 +5,9 @@ const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const console = new Console(client); +const xconsole = new Console(client); -const result = await console.variables(); +const result = await xconsole.variables(); console.log(result); ``` diff --git a/package-lock.json b/package-lock.json index a88f332..c78c321 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@appwrite.io/console", - "version": "12.0.0", + "version": "12.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@appwrite.io/console", - "version": "12.0.0", + "version": "12.1.0", "license": "BSD-3-Clause", "dependencies": { "json-bigint": "1.0.0" diff --git a/package.json b/package.json index a03c30b..17dec57 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@appwrite.io/console", "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": "12.0.0", + "version": "12.1.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index b138f10..7ba9033 100644 --- a/src/client.ts +++ b/src/client.ts @@ -359,12 +359,13 @@ class Client { locale: string; mode: string; cookie: string; + session: string; + devkey: string; impersonateuserid: string; impersonateuseremail: string; impersonateuserphone: string; platform: string; selfSigned: boolean; - session?: string; } = { endpoint: 'https://cloud.appwrite.io/v1', endpointRealtime: '', @@ -374,12 +375,13 @@ class Client { locale: '', mode: '', cookie: '', + session: '', + devkey: '', impersonateuserid: '', impersonateuseremail: '', impersonateuserphone: '', platform: '', selfSigned: false, - session: undefined, }; /** * Custom headers for API requests. @@ -388,7 +390,7 @@ class Client { 'x-sdk-name': 'Console', 'x-sdk-platform': 'console', 'x-sdk-language': 'web', - 'x-sdk-version': '12.0.0', + 'x-sdk-version': '12.1.0', 'X-Appwrite-Response-Format': '1.9.3', }; @@ -529,7 +531,7 @@ class Client { /** * Set Cookie * - * The user cookie to authenticate with + * The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes. * * @param value string * @@ -540,6 +542,34 @@ class Client { this.config.cookie = value; return this; } + /** + * Set Session + * + * The user session to authenticate with + * + * @param value string + * + * @return {this} + */ + setSession(value: string): this { + this.headers['X-Appwrite-Session'] = value; + this.config.session = value; + return this; + } + /** + * Set DevKey + * + * Your secret dev API key + * + * @param value string + * + * @return {this} + */ + setDevKey(value: string): this { + this.headers['X-Appwrite-Dev-Key'] = value; + this.config.devkey = value; + return this; + } /** * Set ImpersonateUserId * diff --git a/src/enums/query-suggestion-resource.ts b/src/enums/query-suggestion-resource.ts new file mode 100644 index 0000000..5663198 --- /dev/null +++ b/src/enums/query-suggestion-resource.ts @@ -0,0 +1,74 @@ +export enum QuerySuggestionResource { + Activities = 'activities', + ActivityEvents = 'activityevents', + Archives = 'archives', + Credits = 'credits', + DnsRecords = 'dnsrecords', + Domains = 'domains', + Invoices = 'invoices', + PaymentMethods = 'paymentmethods', + Policies = 'policies', + Projects = 'projects', + Restorations = 'restorations', + TeamAggregations = 'teamaggregations', + Teams = 'teams', + Databases = 'databases', + Tables = 'tables', + Rows = 'rows', + Schedules = 'schedules', + Platforms = 'platforms', + Keys = 'keys', + DevKeys = 'devkeys', + Webhooks = 'webhooks', + Certificates = 'certificates', + Realtime = 'realtime', + Rules = 'rules', + Installations = 'installations', + Repositories = 'repositories', + VcsComments = 'vcscomments', + VcsCommentLocks = 'vcscommentlocks', + Users = 'users', + Cache = 'cache', + Tokens = 'tokens', + Authenticators = 'authenticators', + Challenges = 'challenges', + Sessions = 'sessions', + Identities = 'identities', + Memberships = 'memberships', + Buckets = 'buckets', + Providers = 'providers', + Messages = 'messages', + Topics = 'topics', + Subscribers = 'subscribers', + Targets = 'targets', + Companies = 'companies', + BillingAddresses = 'billingaddresses', + BillingAggregations = 'billingaggregations', + BillingAggregationResources = 'billingaggregationresources', + BillingTeamProjectAggregations = 'billingteamprojectaggregations', + BillingTeamAggregationsV2 = 'billingteamaggregations_v2', + BillingTeamAggregationResources = 'billingteamaggregationresources', + BillingInvoicesV2 = 'billinginvoices_v2', + BillingAddons = 'billingaddons', + Alerts = 'alerts', + Payments = 'payments', + BillingDiscounts = 'billingdiscounts', + Sources = 'sources', + Deals = 'deals', + Blocks = 'blocks', + Threats = 'threats', + Feedbacks = 'feedbacks', + ShInstallations = 'sh_installations', + Attributes = 'attributes', + Indexes = 'indexes', + Functions = 'functions', + Sites = 'sites', + Deployments = 'deployments', + Executions = 'executions', + Variables = 'variables', + Migrations = 'migrations', + ResourceTokens = 'resourcetokens', + Transactions = 'transactions', + TransactionLogs = 'transactionlogs', + Stats = 'stats', +} \ No newline at end of file diff --git a/src/enums/scopes.ts b/src/enums/scopes.ts index a63d6c9..71badb4 100644 --- a/src/enums/scopes.ts +++ b/src/enums/scopes.ts @@ -12,6 +12,8 @@ export enum Scopes { MocksWrite = 'mocks.write', PoliciesRead = 'policies.read', PoliciesWrite = 'policies.write', + ProjectPoliciesRead = 'project.policies.read', + ProjectPoliciesWrite = 'project.policies.write', TemplatesRead = 'templates.read', TemplatesWrite = 'templates.write', Oauth2Read = 'oauth2.read', @@ -76,6 +78,8 @@ export enum Scopes { VcsWrite = 'vcs.write', RulesRead = 'rules.read', RulesWrite = 'rules.write', + BackupsPoliciesRead = 'backups.policies.read', + BackupsPoliciesWrite = 'backups.policies.write', ArchivesRead = 'archives.read', ArchivesWrite = 'archives.write', RestorationsRead = 'restorations.read', diff --git a/src/index.ts b/src/index.ts index 5bbf61e..afd9a36 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,6 +58,7 @@ export { ImageFormat } from './enums/image-format'; export { BackupServices } from './enums/backup-services'; export { Platform } from './enums/platform'; export { ConsoleResourceType } from './enums/console-resource-type'; +export { QuerySuggestionResource } from './enums/query-suggestion-resource'; export { UsageRange } from './enums/usage-range'; export { RelationshipType } from './enums/relationship-type'; export { RelationMutate } from './enums/relation-mutate'; diff --git a/src/services/console.ts b/src/services/console.ts index 6648e35..8e26188 100644 --- a/src/services/console.ts +++ b/src/services/console.ts @@ -4,6 +4,7 @@ import type { Models } from '../models'; import { Platform } from '../enums/platform'; import { ConsoleResourceType } from '../enums/console-resource-type'; +import { QuerySuggestionResource } from '../enums/query-suggestion-resource'; export class Console { client: Client; @@ -699,6 +700,87 @@ export class Console { ); } + /** + * Suggest valid Appwrite query JSON objects for a supported list resource from free-text user intent. The endpoint picks a validator based on `resource` — for system resources it uses the static validator and its allowed attributes, and for user-owned table rows it loads the table schema and validates against those attributes at request time. The returned queries are guaranteed to parse and pass the relevant queries validator. + * + * + * @param {QuerySuggestionResource} params.resource - Resource to generate queries for. + * @param {string} params.input - Natural language query intent used to generate filters/sorting/pagination. + * @param {string} params.databaseId - Database ID. Required when resource is `tables` or `rows`. + * @param {string} params.tableId - Table ID. Required when resource is `rows`. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + suggestQueries(params: { resource: QuerySuggestionResource, input: string, databaseId?: string, tableId?: string }): Promise<{}>; + /** + * Suggest valid Appwrite query JSON objects for a supported list resource from free-text user intent. The endpoint picks a validator based on `resource` — for system resources it uses the static validator and its allowed attributes, and for user-owned table rows it loads the table schema and validates against those attributes at request time. The returned queries are guaranteed to parse and pass the relevant queries validator. + * + * + * @param {QuerySuggestionResource} resource - Resource to generate queries for. + * @param {string} input - Natural language query intent used to generate filters/sorting/pagination. + * @param {string} databaseId - Database ID. Required when resource is `tables` or `rows`. + * @param {string} tableId - Table ID. Required when resource is `rows`. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + suggestQueries(resource: QuerySuggestionResource, input: string, databaseId?: string, tableId?: string): Promise<{}>; + suggestQueries( + paramsOrFirst: { resource: QuerySuggestionResource, input: string, databaseId?: string, tableId?: string } | QuerySuggestionResource, + ...rest: [(string)?, (string)?, (string)?] + ): Promise<{}> { + let params: { resource: QuerySuggestionResource, input: string, databaseId?: string, tableId?: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('resource' in paramsOrFirst || 'input' in paramsOrFirst || 'databaseId' in paramsOrFirst || 'tableId' in paramsOrFirst))) { + params = (paramsOrFirst || {}) as { resource: QuerySuggestionResource, input: string, databaseId?: string, tableId?: string }; + } else { + params = { + resource: paramsOrFirst as QuerySuggestionResource, + input: rest[0] as string, + databaseId: rest[1] as string, + tableId: rest[2] as string + }; + } + + const resource = params.resource; + const input = params.input; + const databaseId = params.databaseId; + const tableId = params.tableId; + + if (typeof resource === 'undefined') { + throw new AppwriteException('Missing required parameter: "resource"'); + } + if (typeof input === 'undefined') { + throw new AppwriteException('Missing required parameter: "input"'); + } + + const apiPath = '/console/suggestions/queries'; + const payload: Payload = {}; + if (typeof resource !== 'undefined') { + payload['resource'] = resource; + } + if (typeof input !== 'undefined') { + payload['input'] = input; + } + if (typeof databaseId !== 'undefined') { + payload['databaseId'] = databaseId; + } + if (typeof tableId !== 'undefined') { + payload['tableId'] = tableId; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + } + + return this.client.call( + 'get', + uri, + apiHeaders, + payload + ); + } + /** * Get all Environment Variables that are relevant for the console. *