adapty 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/bin/dev.js +2 -2
- package/bin/run.js +2 -2
- package/dist/cli/base/adapty/adapty-command.d.ts +21 -0
- package/dist/cli/base/adapty/adapty-command.js +47 -0
- package/dist/cli/base/adapty/build.d.ts +11 -0
- package/dist/cli/base/adapty/build.js +13 -0
- package/dist/cli/base/adapty/index.d.ts +5 -0
- package/dist/cli/base/adapty/index.js +3 -0
- package/dist/cli/base/adapty/openSession.d.ts +22 -0
- package/dist/cli/base/adapty/openSession.js +25 -0
- package/dist/cli/base/base-command.d.ts +30 -0
- package/dist/cli/base/base-command.js +64 -0
- package/dist/cli/commands/apps/create.d.ts +19 -0
- package/dist/cli/commands/apps/create.js +68 -0
- package/dist/cli/commands/apps/get.d.ts +10 -0
- package/dist/cli/commands/apps/get.js +14 -0
- package/dist/cli/commands/apps/list.d.ts +11 -0
- package/dist/cli/commands/apps/list.js +14 -0
- package/dist/cli/commands/apps/update.d.ts +15 -0
- package/dist/cli/commands/apps/update.js +30 -0
- package/dist/cli/commands/auth/login.d.ts +11 -0
- package/dist/cli/commands/auth/login.js +68 -0
- package/dist/cli/commands/auth/logout.d.ts +12 -0
- package/dist/cli/commands/auth/logout.js +28 -0
- package/dist/cli/commands/auth/revoke.d.ts +13 -0
- package/dist/cli/commands/auth/revoke.js +32 -0
- package/dist/cli/commands/auth/status/index.d.ts +7 -0
- package/dist/cli/commands/auth/status/index.js +22 -0
- package/dist/cli/commands/auth/status/lib/render.d.ts +3 -0
- package/dist/cli/commands/auth/status/lib/render.js +14 -0
- package/dist/cli/commands/auth/status/lib/result.d.ts +15 -0
- package/dist/cli/commands/auth/status/lib/result.js +1 -0
- package/dist/cli/commands/auth/whoami.d.ts +10 -0
- package/dist/cli/commands/auth/whoami.js +16 -0
- package/dist/cli/errors.d.ts +39 -0
- package/dist/cli/errors.js +92 -0
- package/dist/cli/flags.d.ts +16 -0
- package/dist/cli/flags.js +27 -0
- package/dist/cli/views/list.d.ts +6 -0
- package/dist/cli/views/list.js +10 -0
- package/dist/cli/views/record.d.ts +9 -0
- package/dist/cli/views/record.js +14 -0
- package/dist/commands/access-levels/create.js +1 -1
- package/dist/commands/access-levels/list.d.ts +1 -1
- package/dist/commands/apps/create.d.ts +1 -14
- package/dist/commands/apps/create.js +2 -54
- package/dist/commands/apps/get.d.ts +1 -11
- package/dist/commands/apps/get.js +2 -22
- package/dist/commands/apps/list.d.ts +1 -13
- package/dist/commands/apps/list.js +2 -19
- package/dist/commands/apps/update.d.ts +1 -16
- package/dist/commands/apps/update.js +2 -38
- package/dist/commands/asa/ad-groups/create.js +9 -7
- package/dist/commands/asa/ad-groups/get.js +3 -2
- package/dist/commands/asa/ad-groups/list.d.ts +1 -1
- package/dist/commands/asa/ad-groups/list.js +1 -1
- package/dist/commands/asa/ad-groups/update.js +22 -12
- package/dist/commands/asa/ads/create.js +7 -5
- package/dist/commands/asa/ads/get.js +3 -2
- package/dist/commands/asa/ads/list.d.ts +1 -1
- package/dist/commands/asa/ads/list.js +1 -1
- package/dist/commands/asa/ads/update.js +9 -5
- package/dist/commands/asa/apps/list.d.ts +1 -1
- package/dist/commands/asa/apps/list.js +1 -1
- package/dist/commands/asa/automations/create.js +9 -6
- package/dist/commands/asa/automations/get.js +3 -2
- package/dist/commands/asa/automations/list.d.ts +1 -1
- package/dist/commands/asa/automations/list.js +1 -1
- package/dist/commands/asa/automations/run.js +5 -3
- package/dist/commands/asa/automations/runs.d.ts +1 -1
- package/dist/commands/asa/automations/runs.js +4 -4
- package/dist/commands/asa/automations/update.js +17 -9
- package/dist/commands/asa/campaigns/bulk-create.js +31 -18
- package/dist/commands/asa/campaigns/bulk-list.js +7 -5
- package/dist/commands/asa/campaigns/bulk-status.js +3 -2
- package/dist/commands/asa/campaigns/create.js +10 -8
- package/dist/commands/asa/campaigns/get.js +3 -2
- package/dist/commands/asa/campaigns/list.d.ts +1 -1
- package/dist/commands/asa/campaigns/list.js +1 -1
- package/dist/commands/asa/campaigns/update.js +25 -15
- package/dist/commands/asa/competitors/summary.js +5 -5
- package/dist/commands/asa/connect.js +5 -3
- package/dist/commands/asa/creatives/list.d.ts +1 -1
- package/dist/commands/asa/creatives/list.js +1 -1
- package/dist/commands/asa/keywords/add.js +13 -10
- package/dist/commands/asa/keywords/list.d.ts +1 -1
- package/dist/commands/asa/keywords/list.js +1 -1
- package/dist/commands/asa/keywords/update.js +15 -10
- package/dist/commands/asa/metrics/index.d.ts +2 -2
- package/dist/commands/asa/metrics/index.js +22 -8
- package/dist/commands/asa/metrics/overview.js +3 -3
- package/dist/commands/asa/negative-keywords/add.js +10 -7
- package/dist/commands/asa/negative-keywords/list.d.ts +1 -1
- package/dist/commands/asa/negative-keywords/list.js +1 -1
- package/dist/commands/asa/orgs/list.d.ts +1 -1
- package/dist/commands/asa/orgs/list.js +1 -1
- package/dist/commands/asa/product-pages/list.d.ts +1 -1
- package/dist/commands/asa/product-pages/list.js +1 -1
- package/dist/commands/asa/product-pages/sync.js +1 -1
- package/dist/commands/asa/search-terms/list.d.ts +1 -1
- package/dist/commands/asa/search-terms/list.js +1 -1
- package/dist/commands/asa/whoami.js +13 -4
- package/dist/commands/auth/login.d.ts +1 -8
- package/dist/commands/auth/login.js +2 -120
- package/dist/commands/auth/logout.d.ts +1 -9
- package/dist/commands/auth/logout.js +2 -18
- package/dist/commands/auth/revoke.d.ts +1 -9
- package/dist/commands/auth/revoke.js +2 -21
- package/dist/commands/auth/status.d.ts +1 -7
- package/dist/commands/auth/status.js +2 -26
- package/dist/commands/auth/whoami.d.ts +1 -7
- package/dist/commands/auth/whoami.js +2 -15
- package/dist/commands/flows/config/get.js +2 -2
- package/dist/commands/flows/config/preview.d.ts +2 -2
- package/dist/commands/flows/config/preview.js +6 -4
- package/dist/commands/flows/config/update.js +5 -3
- package/dist/commands/flows/config/validate.js +5 -3
- package/dist/commands/flows/list.d.ts +1 -1
- package/dist/commands/flows/media/upload.js +1 -1
- package/dist/commands/flows/publish.js +5 -5
- package/dist/commands/paywalls/create.js +1 -1
- package/dist/commands/paywalls/list.d.ts +1 -1
- package/dist/commands/paywalls/placements.d.ts +2 -2
- package/dist/commands/paywalls/update.js +1 -1
- package/dist/commands/placements/create.js +17 -12
- package/dist/commands/placements/list.d.ts +1 -1
- package/dist/commands/placements/update.js +20 -15
- package/dist/commands/products/create.js +20 -13
- package/dist/commands/products/list.d.ts +1 -1
- package/dist/commands/products/update.js +1 -1
- package/dist/commands/segments/list.d.ts +1 -1
- package/dist/lib/api-client.d.ts +10 -6
- package/dist/lib/api-client.js +56 -35
- package/dist/lib/api-schemas.d.ts +63 -59
- package/dist/lib/app-url.js +2 -1
- package/dist/lib/asa-client.d.ts +13 -8
- package/dist/lib/asa-client.js +9 -4
- package/dist/lib/asa-flags.d.ts +19 -19
- package/dist/lib/asa-flags.js +38 -25
- package/dist/lib/asa-keyword-action.d.ts +10 -10
- package/dist/lib/asa-keyword-action.js +40 -25
- package/dist/lib/asa-schemas.d.ts +101 -81
- package/dist/lib/auth.js +2 -1
- package/dist/lib/client-from-config.d.ts +1 -1
- package/dist/lib/client-from-config.js +2 -1
- package/dist/lib/config.d.ts +2 -2
- package/dist/lib/confirm.d.ts +4 -4
- package/dist/lib/confirm.js +12 -7
- package/dist/lib/errors.d.ts +18 -18
- package/dist/lib/errors.js +12 -9
- package/dist/lib/flags.d.ts +3 -3
- package/dist/lib/flags.js +2 -1
- package/dist/lib/flow-help.js +11 -6
- package/dist/lib/output.js +23 -12
- package/dist/lib/preview.d.ts +5 -5
- package/dist/lib/preview.js +2 -1
- package/dist/sdk/adapty/access-levels.d.ts +15 -0
- package/dist/sdk/adapty/access-levels.js +4 -0
- package/dist/sdk/adapty/apps/create.d.ts +26 -0
- package/dist/sdk/adapty/apps/create.js +36 -0
- package/dist/sdk/adapty/apps/index.d.ts +13 -0
- package/dist/sdk/adapty/apps/index.js +9 -0
- package/dist/sdk/adapty/apps/model.d.ts +24 -0
- package/dist/sdk/adapty/apps/model.js +10 -0
- package/dist/sdk/adapty/apps/resource.d.ts +19 -0
- package/dist/sdk/adapty/apps/resource.js +23 -0
- package/dist/sdk/adapty/apps/update.d.ts +16 -0
- package/dist/sdk/adapty/apps/update.js +25 -0
- package/dist/sdk/adapty/auth/device-code.d.ts +8 -0
- package/dist/sdk/adapty/auth/device-code.js +19 -0
- package/dist/sdk/adapty/auth/index.d.ts +7 -0
- package/dist/sdk/adapty/auth/index.js +5 -0
- package/dist/sdk/adapty/auth/model.d.ts +15 -0
- package/dist/sdk/adapty/auth/model.js +6 -0
- package/dist/sdk/adapty/auth/poll-token.d.ts +8 -0
- package/dist/sdk/adapty/auth/poll-token.js +58 -0
- package/dist/sdk/adapty/auth/resource.d.ts +17 -0
- package/dist/sdk/adapty/auth/resource.js +21 -0
- package/dist/sdk/adapty/errors.d.ts +10 -0
- package/dist/sdk/adapty/errors.js +38 -0
- package/dist/sdk/adapty/index.d.ts +36 -0
- package/dist/sdk/adapty/index.js +27 -0
- package/dist/sdk/adapty/pagination.d.ts +23 -0
- package/dist/sdk/adapty/pagination.js +1 -0
- package/dist/sdk/core/auth/device-flow.d.ts +46 -0
- package/dist/sdk/core/auth/device-flow.js +62 -0
- package/dist/sdk/core/clock.d.ts +7 -0
- package/dist/sdk/core/clock.js +21 -0
- package/dist/sdk/core/errors.d.ts +81 -0
- package/dist/sdk/core/errors.js +84 -0
- package/dist/sdk/core/http/client.d.ts +46 -0
- package/dist/sdk/core/http/client.js +127 -0
- package/dist/sdk/core/http/index.d.ts +11 -0
- package/dist/sdk/core/http/index.js +7 -0
- package/dist/sdk/core/http/policies.d.ts +14 -0
- package/dist/sdk/core/http/policies.js +29 -0
- package/dist/sdk/core/http/retry.d.ts +27 -0
- package/dist/sdk/core/http/retry.js +22 -0
- package/dist/sdk/core/http/url.d.ts +3 -0
- package/dist/sdk/core/http/url.js +19 -0
- package/dist/sdk/core/session.d.ts +20 -0
- package/dist/sdk/core/session.js +69 -0
- package/dist/sdk/core/testing.d.ts +25 -0
- package/dist/sdk/core/testing.js +46 -0
- package/dist/sdk/core/validation.d.ts +10 -0
- package/dist/sdk/core/validation.js +14 -0
- package/oclif.manifest.json +766 -766
- package/package.json +19 -9
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const buildUrl = (baseUrl, path, query, trailingSlash) => {
|
|
2
|
+
// A relative path against a base ending in a slash keeps a prefix like /api/v1/developer
|
|
3
|
+
const base = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
|
|
4
|
+
let relative = path.replace(/^\/+/, '');
|
|
5
|
+
if (trailingSlash && relative !== '' && !relative.endsWith('/')) {
|
|
6
|
+
relative += '/';
|
|
7
|
+
}
|
|
8
|
+
const url = new URL(relative, base);
|
|
9
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const items = typeof value === 'object' ? value : [value];
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
url.searchParams.append(key, String(item));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return url.toString();
|
|
19
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type SessionUser = {
|
|
2
|
+
email: string;
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
export type Session = {
|
|
6
|
+
token: string;
|
|
7
|
+
user?: SessionUser | undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Where the session lives is a port, not a path: a keychain, a CI secret store or an in-memory
|
|
11
|
+
* store for an MCP server plug into this same type without touching a command.
|
|
12
|
+
*/
|
|
13
|
+
export type SessionStore = {
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
load(): Promise<Session | undefined>;
|
|
16
|
+
readonly path: string;
|
|
17
|
+
save(session: Session): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/** A file under a directory the adapter picks: the sdk touches neither HOME nor process.env. */
|
|
20
|
+
export declare const createFileSessionStore: (dir: string) => SessionStore;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { chmod, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { StorageError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* The file and field names the published CLI already writes. A rename would log every existing
|
|
6
|
+
* user out, so the on-disk contract stays `{ "access_token", "user": { "email", "name" } }`.
|
|
7
|
+
*/
|
|
8
|
+
const FILE_NAME = 'config.json';
|
|
9
|
+
/** A file under a directory the adapter picks: the sdk touches neither HOME nor process.env. */
|
|
10
|
+
export const createFileSessionStore = (dir) => {
|
|
11
|
+
const path = join(dir, FILE_NAME);
|
|
12
|
+
return {
|
|
13
|
+
path,
|
|
14
|
+
clear: async () => {
|
|
15
|
+
await rm(path, { force: true });
|
|
16
|
+
},
|
|
17
|
+
load: async () => {
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = await readFile(path, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (isErrno(error, 'ENOENT')) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// No permission, a broken disk: not ours to paper over as "not logged in"
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = JSON.parse(raw);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new StorageError(`Session file is corrupted: ${path}`, path, { cause: error });
|
|
35
|
+
}
|
|
36
|
+
// An unknown shape is most likely a file from another version: asking for a fresh
|
|
37
|
+
// login beats failing every command.
|
|
38
|
+
return toSession(parsed);
|
|
39
|
+
},
|
|
40
|
+
save: async (session) => {
|
|
41
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
42
|
+
await writeFile(path, `${JSON.stringify(toStored(session), null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
43
|
+
// `mode` above applies only when the file is created; an existing 0644 one (a hand
|
|
44
|
+
// edit, a restored backup) would leave the token readable for everyone on the machine.
|
|
45
|
+
await chmod(path, 0o600);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const toStored = (session) => (session.user === undefined
|
|
50
|
+
? { access_token: session.token }
|
|
51
|
+
: { access_token: session.token, user: session.user });
|
|
52
|
+
/** Not a full schema check: only the minimum the rest of the code leans on. */
|
|
53
|
+
const toSession = (parsed) => {
|
|
54
|
+
const record = asRecord(parsed);
|
|
55
|
+
if (record === undefined || typeof record.access_token !== 'string' || record.access_token === '') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const user = toUser(record.user);
|
|
59
|
+
return user === undefined ? { token: record.access_token } : { token: record.access_token, user };
|
|
60
|
+
};
|
|
61
|
+
const toUser = (value) => {
|
|
62
|
+
const record = asRecord(value);
|
|
63
|
+
if (record === undefined || typeof record.email !== 'string' || typeof record.name !== 'string') {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return { email: record.email, name: record.name };
|
|
67
|
+
};
|
|
68
|
+
const asRecord = (value) => (typeof value === 'object' && value !== null ? value : undefined);
|
|
69
|
+
const isErrno = (error, code) => error instanceof Error && 'code' in error && error.code === code;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Clock } from './clock.js';
|
|
2
|
+
export type FakeClock = {
|
|
3
|
+
advance(ms: number): void;
|
|
4
|
+
/** Durations of every sleep, in order. */
|
|
5
|
+
readonly sleeps: number[];
|
|
6
|
+
} & Clock;
|
|
7
|
+
/** A clock whose sleep moves time forward instantly. */
|
|
8
|
+
export declare const createFakeClock: (start?: number) => FakeClock;
|
|
9
|
+
export type ScriptedResponse = {
|
|
10
|
+
body?: unknown;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
status?: number;
|
|
13
|
+
};
|
|
14
|
+
export type RecordedCall = {
|
|
15
|
+
body: string | undefined;
|
|
16
|
+
headers: Headers;
|
|
17
|
+
method: string;
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
export type ScriptedFetch = {
|
|
21
|
+
calls: RecordedCall[];
|
|
22
|
+
fetch: typeof globalThis.fetch;
|
|
23
|
+
};
|
|
24
|
+
/** Answers with the scripted responses in order; an Error in the script is thrown, as fetch would. */
|
|
25
|
+
export declare const createScriptedFetch: (script: readonly (Error | ScriptedResponse)[]) => ScriptedFetch;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Fakes for the sdk and its consumers: cli, MCP and any other adapter test with the same tools. */
|
|
2
|
+
import { throwIfAborted } from './clock.js';
|
|
3
|
+
/** A clock whose sleep moves time forward instantly. */
|
|
4
|
+
export const createFakeClock = (start = 0) => {
|
|
5
|
+
let time = start;
|
|
6
|
+
const sleeps = [];
|
|
7
|
+
return {
|
|
8
|
+
sleeps,
|
|
9
|
+
now: () => time,
|
|
10
|
+
advance: (ms) => {
|
|
11
|
+
time += ms;
|
|
12
|
+
},
|
|
13
|
+
sleep: (ms, signal) => {
|
|
14
|
+
throwIfAborted(signal);
|
|
15
|
+
sleeps.push(ms);
|
|
16
|
+
time += ms;
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** Answers with the scripted responses in order; an Error in the script is thrown, as fetch would. */
|
|
22
|
+
export const createScriptedFetch = (script) => {
|
|
23
|
+
const queue = [...script];
|
|
24
|
+
const calls = [];
|
|
25
|
+
const fetch = (input, init) => {
|
|
26
|
+
calls.push({
|
|
27
|
+
body: typeof init?.body === 'string' ? init.body : undefined,
|
|
28
|
+
headers: new Headers(init?.headers),
|
|
29
|
+
method: init?.method ?? 'GET',
|
|
30
|
+
url: String(input instanceof Request ? input.url : input),
|
|
31
|
+
});
|
|
32
|
+
const next = queue.shift();
|
|
33
|
+
if (next === undefined) {
|
|
34
|
+
return Promise.reject(new Error(`scripted fetch: no response for call #${calls.length}`));
|
|
35
|
+
}
|
|
36
|
+
if (next instanceof Error) {
|
|
37
|
+
return Promise.reject(next);
|
|
38
|
+
}
|
|
39
|
+
// ResponseInit.headers is readonly in @types/node, so the init is built in one go
|
|
40
|
+
const status = next.status ?? 200;
|
|
41
|
+
const responseInit = next.headers ? { headers: next.headers, status } : { status };
|
|
42
|
+
const body = next.body === undefined ? null : JSON.stringify(next.body);
|
|
43
|
+
return Promise.resolve(new Response(body, responseInit));
|
|
44
|
+
};
|
|
45
|
+
return { calls, fetch };
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Issue } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turns a rule's problems into a throw — the only place that does. Rules return lists instead of
|
|
4
|
+
* throwing, so a table test walks them without an environment and the user sees every problem at
|
|
5
|
+
* once.
|
|
6
|
+
*
|
|
7
|
+
* Call it from an `async` method: a broken rule then arrives as a rejected promise, like a network
|
|
8
|
+
* failure, instead of a throw the caller has to handle separately.
|
|
9
|
+
*/
|
|
10
|
+
export declare const assertValid: (issues: readonly Issue[]) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ValidationError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turns a rule's problems into a throw — the only place that does. Rules return lists instead of
|
|
4
|
+
* throwing, so a table test walks them without an environment and the user sees every problem at
|
|
5
|
+
* once.
|
|
6
|
+
*
|
|
7
|
+
* Call it from an `async` method: a broken rule then arrives as a rejected promise, like a network
|
|
8
|
+
* failure, instead of a throw the caller has to handle separately.
|
|
9
|
+
*/
|
|
10
|
+
export const assertValid = (issues) => {
|
|
11
|
+
if (issues.length > 0) {
|
|
12
|
+
throw new ValidationError(issues);
|
|
13
|
+
}
|
|
14
|
+
};
|