Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(sdk): expose scoped on the key validation response
Yudhi Armyndharis1e58f40dbb6f
diff --git a/sdk/go/auth_validate_test.go b/sdk/go/auth_validate_test.gonew file mode 100644index 000000000..f7a5dd916--- /dev/null+++ b/sdk/go/auth_validate_test.go@@ -0,0 +1,17 @@+package openwa++import (+ "encoding/json"+ "testing"+)++// The validate route reports whether the key is restricted to selected sessions.+func TestAuthValidateResponseDecodesScoped(t *testing.T) {+ var out AuthValidateResponse+ if err := json.Unmarshal([]byte(`{"valid":true,"role":"viewer","scoped":true}`), &out); err != nil {+ t.Fatal(err)+ }+ if !out.Scoped {+ t.Errorf("Scoped = false, want true")+ }+}diff --git a/sdk/go/types_misc.go b/sdk/go/types_misc.goindex 24e05df8c..ea34ee75c 100644--- a/sdk/go/types_misc.go+++ b/sdk/go/types_misc.go@@ -24,12 +24,14 @@ type HealthReadyResponse struct {// ── Auth ─────────────────────────────────────────────────-// AuthValidateResponse reports whether the API key is valid, its role, and the-// engine the gateway runs.+// AuthValidateResponse reports whether the API key is valid, its role, the+// engine the gateway runs, and whether the key is restricted to selected+// sessions.type AuthValidateResponse struct {Valid bool `json:"valid"`Role string `json:"role,omitempty"`EngineType string `json:"engineType,omitempty"`+ Scoped bool `json:"scoped,omitempty"`}// ── Template ───────────────────────────────────────────diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/AuthValidateResponse.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/AuthValidateResponse.javaindex bd7041d9c..398dcdb3c 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/AuthValidateResponse.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/AuthValidateResponse.java@@ -1,4 +1,4 @@package com.rmyndharis.openwa.model;/** Result of validating the configured API key. */-public record AuthValidateResponse(boolean valid, String role, String engineType) {}+public record AuthValidateResponse(boolean valid, String role, String engineType, Boolean scoped) {}diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/ClientTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/ClientTest.javaindex 27c7fcd0b..7538e6629 100644--- a/sdk/java/src/test/java/com/rmyndharis/openwa/ClientTest.java+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/ClientTest.java@@ -126,8 +126,8 @@ class ClientTest {@Testvoid authPostsToValidatePath() {- tx.respond(200, "{\"valid\":true,\"role\":\"OPERATOR\"}");- client.auth();+ tx.respond(200, "{\"valid\":true,\"role\":\"OPERATOR\",\"scoped\":true}");+ assertEquals(Boolean.TRUE, client.auth().scoped());assertEquals("http://h:2785/api/auth/validate", tx.lastRequest().url());assertEquals(HttpMethod.POST, tx.lastRequest().method());}diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex c83179d52..4c99c06c8 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -1235,6 +1235,7 @@ export interface AuthValidateResponse {valid: boolean;role?: string;engineType?: string;+ scoped?: boolean;}// ── Template ──────────────────────────────────────────────────────diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.tsindex 0a60d28dc..51f23299c 100644--- a/sdk/javascript/test/resources.test.ts+++ b/sdk/javascript/test/resources.test.ts@@ -461,13 +461,13 @@ describe('HealthResource + auth — exact paths', () => {.on('GET', /\/health$/, { body: { status: 'ok', version: '0.7.2' } }).on('GET', /\/health\/live$/, { body: { status: 'ok' } }).on('GET', /\/health\/ready$/, { body: { status: 'ok', details: {} } })- .on('POST', /\/auth\/validate$/, { body: { valid: true, role: 'admin' } });+ .on('POST', /\/auth\/validate$/, { body: { valid: true, role: 'admin', scoped: true } });const c = client(t);await c.health.check();expect(t.lastCall!.url).toBe('http://x/api/health');await c.health.live();await c.health.ready();- await c.auth();+ expect((await c.auth()).scoped).toBe(true);expect(t.lastCall!.method).toBe('POST');expect(t.lastCall!.url).toBe('http://x/api/auth/validate');});diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.pyindex b81d615ed..1d7e3d16d 100644--- a/sdk/python/openwa/types.py+++ b/sdk/python/openwa/types.py@@ -1250,6 +1250,7 @@ class AuthValidateResponse(TypedDict, total=False):valid: boolrole: strengineType: str+ scoped: bool# ── Template ──────────────────────────────────────────────────────diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.pyindex 8f535e81b..b478a49b3 100644--- a/sdk/python/tests/test_sdk.py+++ b/sdk/python/tests/test_sdk.py@@ -15,6 +15,7 @@ from openwa.errors import OpenWAServiceUnavailableErrorfrom openwa.resources.catalog import CatalogResourcefrom openwa.resources.messages import MessagesResourcefrom openwa.types import (+ AuthValidateResponse,BatchCancelResponse,HealthReadyResponse,WebhookDelivery,@@ -900,6 +901,9 @@ class TestChatsAndHealth:# The readiness route always sends details, on the 200 and on the 503.assert HealthReadyResponse.__required_keys__ == frozenset({"status", "details"})+ def test_auth_validate_response_carries_scoped(self):+ assert "scoped" in AuthValidateResponse.__optional_keys__+class TestLabelsChannelsCatalog:def test_labels(self):