Skip to content

Commit e916d44

Browse files
committed
set backend url
1 parent 48d01fb commit e916d44

6 files changed

Lines changed: 57 additions & 52 deletions

File tree

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# ASO_SIRP_USE_RUBY_PROOF=0
88
# Optional override for auto-generated anonymous backend client id
99
# ASO_CLIENT_ID=
10-
# Optional backend API base URL
10+
# Optional backend API base URL override.
11+
# Default: https://aso-difficulty-api.umitsemihcihan.workers.dev
1112
# ASO_BACKEND_BASE_URL=
1213

1314
# Optional ASO resilience tuning

cli/services/backend/aso-backend-client.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { AsoBackendClient } from "./aso-backend-client";
88
jest.mock("axios");
99

1010
describe("aso-backend-client", () => {
11+
const defaultBackendUrl =
12+
"https://aso-difficulty-api.umitsemihcihan.workers.dev";
1113
const mockedAxios = jest.mocked(axios);
1214
const originalEnv = process.env;
1315
const testHome = path.join(
@@ -36,7 +38,13 @@ describe("aso-backend-client", () => {
3638
expect(context.entitlements.topApps).toBe(true);
3739
});
3840

39-
it("returns paywalled result when backend is not configured", async () => {
41+
it("uses default backend when backend url env is not configured", async () => {
42+
mockedAxios.post.mockResolvedValueOnce({
43+
data: {
44+
difficultyScore: 37,
45+
},
46+
} as any);
47+
4048
const service = new AsoBackendClient();
4149
const score = await service.scoreDifficulty({
4250
keyword: "term",
@@ -48,13 +56,14 @@ describe("aso-backend-client", () => {
4856
});
4957

5058
expect(score).toEqual({
51-
difficultyScore: null,
52-
difficultyState: "paywalled",
53-
code: "ENTITLEMENT_UNAVAILABLE",
54-
feature: "difficulty",
55-
message: "Difficulty scoring backend is not configured.",
56-
upgradeUrl: null,
59+
difficultyScore: 37,
60+
difficultyState: "ready",
5761
});
62+
expect(mockedAxios.post).toHaveBeenCalledWith(
63+
`${defaultBackendUrl}/v1/aso/difficulty/score`,
64+
expect.any(Object),
65+
expect.any(Object)
66+
);
5867
});
5968

6069
it("maps backend plan-required errors to paywalled result", async () => {

cli/services/backend/aso-backend-client.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type {
1414
} from "./aso-backend-types";
1515

1616
const DEFAULT_CONTEXT_TTL_SECONDS = 86400;
17+
const DEFAULT_ASO_BACKEND_BASE_URL =
18+
"https://aso-difficulty-api.umitsemihcihan.workers.dev";
1719

1820
type CachedContextEnvelope = {
1921
context: AsoBackendContext;
@@ -159,11 +161,12 @@ export class AsoBackendClient {
159161
return headers;
160162
}
161163

162-
private get baseUrl(): string | null {
164+
private get baseUrl(): string {
163165
const raw = process.env.ASO_BACKEND_BASE_URL;
164-
if (!raw) return null;
165-
const trimmed = raw.trim();
166-
return trimmed === "" ? null : trimmed.replace(/\/+$/, "");
166+
const trimmed = typeof raw === "string" ? raw.trim() : "";
167+
const resolved =
168+
trimmed === "" ? DEFAULT_ASO_BACKEND_BASE_URL : trimmed;
169+
return resolved.replace(/\/+$/, "");
167170
}
168171

169172
private get cacheTtlSeconds(): number {
@@ -218,9 +221,6 @@ export class AsoBackendClient {
218221
}
219222

220223
private async fetchContextFromBackend(): Promise<AsoBackendContext> {
221-
if (!this.baseUrl) {
222-
return buildDefaultContext();
223-
}
224224
const response = await axios.get(`${this.baseUrl}/v1/client/context`, {
225225
headers: this.buildBackendHeaders(),
226226
timeout: 15000,
@@ -354,13 +354,6 @@ export class AsoBackendClient {
354354
}
355355

356356
async scoreDifficulty(payload: DifficultyScorePayload): Promise<DifficultyScoreResult> {
357-
if (!this.baseUrl) {
358-
return this.buildPaywalledDifficultyResult({
359-
code: "ENTITLEMENT_UNAVAILABLE",
360-
message: "Difficulty scoring backend is not configured.",
361-
});
362-
}
363-
364357
try {
365358
const response = await axios.post(
366359
`${this.baseUrl}/v1/aso/difficulty/score`,

docs/aso-runtime-flows.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Runtime flow contracts across CLI commands, local dashboard API, and ASO service
99

1010
## Operational Prerequisite
1111
- Apple Search Ads setup is required only for ASO command flows (`aso ...`).
12+
- Difficulty/context backend defaults to `https://aso-difficulty-api.umitsemihcihan.workers.dev`.
13+
- `ASO_BACKEND_BASE_URL` is an optional override for non-production backends.
1214
- Required setup items:
1315
- Apple Search Ads account
1416
- Linked App Store Connect account in Apple Search Ads

package-lock.json

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aso-cli",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Local App Store Optimization CLI",
55
"main": "cli/dist/cli.js",
66
"bin": {

0 commit comments

Comments
 (0)