reply-cli 0.1.2 → 0.3.0

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.
Files changed (94) hide show
  1. package/README.md +99 -393
  2. package/dist/api/headers.d.ts +4 -0
  3. package/dist/api/headers.js +13 -0
  4. package/dist/api/headers.js.map +1 -0
  5. package/dist/auth/oauth-flow.d.ts +38 -0
  6. package/dist/auth/oauth-flow.js +193 -0
  7. package/dist/auth/oauth-flow.js.map +1 -0
  8. package/dist/auth/pkce.d.ts +9 -0
  9. package/dist/auth/pkce.js +19 -0
  10. package/dist/auth/pkce.js.map +1 -0
  11. package/dist/auth/request-identity.d.ts +16 -0
  12. package/dist/auth/request-identity.js +67 -0
  13. package/dist/auth/request-identity.js.map +1 -0
  14. package/dist/auth/resolve.d.ts +23 -0
  15. package/dist/auth/resolve.js +55 -0
  16. package/dist/auth/resolve.js.map +1 -0
  17. package/dist/auth/status.d.ts +19 -0
  18. package/dist/auth/status.js +27 -0
  19. package/dist/auth/status.js.map +1 -0
  20. package/dist/auth/token.d.ts +29 -0
  21. package/dist/auth/token.js +39 -0
  22. package/dist/auth/token.js.map +1 -0
  23. package/dist/commands/api.d.ts +19 -0
  24. package/dist/commands/api.js +137 -0
  25. package/dist/commands/api.js.map +1 -0
  26. package/dist/commands/auth.d.ts +21 -0
  27. package/dist/commands/auth.js +266 -0
  28. package/dist/commands/auth.js.map +1 -0
  29. package/dist/commands/authed.d.ts +13 -0
  30. package/dist/commands/authed.js +20 -0
  31. package/dist/commands/authed.js.map +1 -0
  32. package/dist/commands/profile.d.ts +31 -0
  33. package/dist/commands/profile.js +348 -0
  34. package/dist/commands/profile.js.map +1 -0
  35. package/dist/commands/team.d.ts +17 -0
  36. package/dist/commands/team.js +146 -0
  37. package/dist/commands/team.js.map +1 -0
  38. package/dist/config.d.ts +14 -0
  39. package/dist/config.js +80 -0
  40. package/dist/config.js.map +1 -0
  41. package/dist/context.d.ts +15 -0
  42. package/dist/context.js +17 -0
  43. package/dist/context.js.map +1 -0
  44. package/dist/credentials/file-store.d.ts +13 -0
  45. package/dist/credentials/file-store.js +88 -0
  46. package/dist/credentials/file-store.js.map +1 -0
  47. package/dist/credentials/types.d.ts +25 -0
  48. package/dist/credentials/types.js +3 -0
  49. package/dist/credentials/types.js.map +1 -0
  50. package/dist/index.js +104 -41
  51. package/dist/index.js.map +1 -1
  52. package/dist/profile.d.ts +51 -0
  53. package/dist/profile.js +295 -0
  54. package/dist/profile.js.map +1 -0
  55. package/dist/teams.d.ts +14 -0
  56. package/dist/teams.js +103 -0
  57. package/dist/teams.js.map +1 -0
  58. package/dist/utils/client.d.ts +21 -9
  59. package/dist/utils/client.js +136 -88
  60. package/dist/utils/client.js.map +1 -1
  61. package/dist/utils/errors.d.ts +47 -0
  62. package/dist/utils/errors.js +86 -0
  63. package/dist/utils/errors.js.map +1 -0
  64. package/dist/utils/output.d.ts +7 -10
  65. package/dist/utils/output.js +39 -71
  66. package/dist/utils/output.js.map +1 -1
  67. package/package.json +10 -25
  68. package/dist/commands/accounts.d.ts +0 -6
  69. package/dist/commands/accounts.js +0 -62
  70. package/dist/commands/accounts.js.map +0 -1
  71. package/dist/commands/contacts.d.ts +0 -20
  72. package/dist/commands/contacts.js +0 -321
  73. package/dist/commands/contacts.js.map +0 -1
  74. package/dist/commands/import.d.ts +0 -6
  75. package/dist/commands/import.js +0 -137
  76. package/dist/commands/import.js.map +0 -1
  77. package/dist/commands/schedules.d.ts +0 -9
  78. package/dist/commands/schedules.js +0 -119
  79. package/dist/commands/schedules.js.map +0 -1
  80. package/dist/commands/sequence-contacts.d.ts +0 -8
  81. package/dist/commands/sequence-contacts.js +0 -141
  82. package/dist/commands/sequence-contacts.js.map +0 -1
  83. package/dist/commands/sequences-stats.d.ts +0 -7
  84. package/dist/commands/sequences-stats.js +0 -183
  85. package/dist/commands/sequences-stats.js.map +0 -1
  86. package/dist/commands/sequences.d.ts +0 -12
  87. package/dist/commands/sequences.js +0 -225
  88. package/dist/commands/sequences.js.map +0 -1
  89. package/dist/utils/auth.d.ts +0 -2
  90. package/dist/utils/auth.js +0 -33
  91. package/dist/utils/auth.js.map +0 -1
  92. package/dist/utils/command.d.ts +0 -11
  93. package/dist/utils/command.js +0 -20
  94. package/dist/utils/command.js.map +0 -1
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PROD = exports.EMBEDDED = exports.describe_profile = exports.unset_profile_field = exports.delete_profile_def = exports.rename_profile_def = exports.set_profile = exports.add_profile = exports.set_current_profile = exports.list_profiles = exports.current_profile_name = exports.resolve_profile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const config_1 = require("./config");
10
+ const errors_1 = require("./utils/errors");
11
+ const DEFAULT_NAME = 'default';
12
+ // The embedded default profile: prod. Everything inherits from this. The
13
+ // api_base is the HOST only — the /v3 version prefix lives in the request path
14
+ // (so a raw `api` call's URL matches the docs), not in the profile.
15
+ const EMBEDDED = {
16
+ authority: 'https://oauth.reply.io',
17
+ api_base: 'https://api.reply.io',
18
+ };
19
+ exports.EMBEDDED = EMBEDDED;
20
+ // Back-compat alias for callers/tests referencing the prod target.
21
+ const PROD = EMBEDDED;
22
+ exports.PROD = PROD;
23
+ const strip_trailing_slash = (url) => url.replace(/\/+$/, '');
24
+ // team_id is account-specific and NOT inherited from the embedded default.
25
+ // Accept a number, or a numeric string from hand-edited config.
26
+ const read_team_id = (v) => {
27
+ if (typeof v === 'number' && Number.isInteger(v)) {
28
+ return v;
29
+ }
30
+ if (typeof v === 'string' && /^\d+$/.test(v.trim())) {
31
+ return parseInt(v.trim(), 10);
32
+ }
33
+ return undefined;
34
+ };
35
+ const read_config = (env) => {
36
+ const file = (0, config_1.config_file)(env);
37
+ let raw;
38
+ try {
39
+ raw = fs_1.default.readFileSync(file, 'utf8');
40
+ }
41
+ catch (e) {
42
+ if (e.code === 'ENOENT') {
43
+ return {};
44
+ }
45
+ throw new errors_1.RuntimeError('Could not read the config file.', {
46
+ code: 'config.read', detail: file, hint: e.message,
47
+ });
48
+ }
49
+ if (!raw.trim()) {
50
+ return {};
51
+ }
52
+ let parsed;
53
+ try {
54
+ parsed = JSON.parse(raw);
55
+ }
56
+ catch {
57
+ throw new errors_1.RuntimeError('Config file is corrupt (invalid JSON).', {
58
+ code: 'config.corrupt', detail: file, hint: 'Fix or delete the file.',
59
+ });
60
+ }
61
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
62
+ throw new errors_1.RuntimeError('Config file is corrupt (unexpected shape).', {
63
+ code: 'config.corrupt', detail: file, hint: 'Fix or delete the file.',
64
+ });
65
+ }
66
+ return parsed;
67
+ };
68
+ const get_profiles = (cfg, env) => {
69
+ const { profiles } = cfg;
70
+ if (profiles === undefined || profiles === null) {
71
+ return {};
72
+ }
73
+ if (typeof profiles !== 'object' || Array.isArray(profiles)) {
74
+ throw new errors_1.RuntimeError('Config "profiles" must be an object.', {
75
+ code: 'config.corrupt', detail: (0, config_1.config_file)(env), hint: 'Fix or delete the file.',
76
+ });
77
+ }
78
+ return profiles;
79
+ };
80
+ const persisted_current = (cfg) => typeof cfg.current_profile === 'string' && cfg.current_profile.trim()
81
+ ? cfg.current_profile
82
+ : undefined;
83
+ const inherit = (value, fallback) => typeof value === 'string' && value.trim() ? value : fallback;
84
+ // Selection precedence: --profile flag -> REPLY_PROFILE env -> persisted
85
+ // current_profile -> built-in default. Each field inherits from the embedded
86
+ // default unless the named profile overrides it. An unknown name is a usage
87
+ // error (typo-safe) — create profiles with `profile add`.
88
+ const resolve_profile = (flag, env = process.env) => {
89
+ const cfg = read_config(env);
90
+ const profiles = get_profiles(cfg, env);
91
+ const name = flag || (0, config_1.get_env)('PROFILE', env) || persisted_current(cfg) || DEFAULT_NAME;
92
+ const declared = profiles[name];
93
+ if (!declared && name !== DEFAULT_NAME) {
94
+ throw new errors_1.UsageError(`Unknown profile '${name}'.`, {
95
+ code: 'usage.profile',
96
+ hint: `Create it with \`profile add ${name}\`, or omit --profile for the default.`,
97
+ });
98
+ }
99
+ const over = declared ?? {};
100
+ const team_id = read_team_id(over.team_id);
101
+ return {
102
+ name,
103
+ authority: strip_trailing_slash(inherit(over.authority, EMBEDDED.authority)),
104
+ api_base: strip_trailing_slash(inherit(over.api_base, EMBEDDED.api_base)),
105
+ ...(team_id !== undefined ? { team_id } : {}),
106
+ };
107
+ };
108
+ exports.resolve_profile = resolve_profile;
109
+ const current_profile_name = (env = process.env) => persisted_current(read_config(env)) || DEFAULT_NAME;
110
+ exports.current_profile_name = current_profile_name;
111
+ // Resolved view of a profile for `profile show`: resolved values plus flags for
112
+ // which URLs are inherited (not explicitly set) and whether it's current. No
113
+ // credentials/secrets — the command layer adds a redacted credential summary.
114
+ const describe_profile = (name, env = process.env) => {
115
+ const resolved = resolve_profile(name, env); // throws UsageError if unknown
116
+ const cfg = read_config(env);
117
+ const raw = get_profiles(cfg, env)[name] ?? {};
118
+ const explicit = (v) => typeof v === 'string' && v.trim().length > 0;
119
+ return {
120
+ name: resolved.name,
121
+ authority: resolved.authority,
122
+ api_base: resolved.api_base,
123
+ ...(resolved.team_id !== undefined ? { team_id: resolved.team_id } : {}),
124
+ is_current: (persisted_current(cfg) || DEFAULT_NAME) === name,
125
+ inherited: { authority: !explicit(raw.authority), api_base: !explicit(raw.api_base) },
126
+ };
127
+ };
128
+ exports.describe_profile = describe_profile;
129
+ const list_profiles = (env = process.env) => {
130
+ const cfg = read_config(env);
131
+ const names = new Set([DEFAULT_NAME, ...Object.keys(get_profiles(cfg, env))]);
132
+ return { current: persisted_current(cfg) || DEFAULT_NAME, available: [...names] };
133
+ };
134
+ exports.list_profiles = list_profiles;
135
+ const write_config = (cfg, env) => {
136
+ const file = (0, config_1.config_file)(env);
137
+ fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
138
+ fs_1.default.writeFileSync(file, JSON.stringify(cfg, null, 2) + '\n', 'utf8');
139
+ };
140
+ const CLEARABLE_FIELDS = ['authority', 'api_base', 'team_id'];
141
+ // Apply the given fields onto a profile def, in place (only fields actually
142
+ // provided are written, so merges are non-destructive).
143
+ const apply_fields = (def, fields) => {
144
+ if (fields.authority && fields.authority.trim()) {
145
+ def.authority = fields.authority;
146
+ }
147
+ if (fields.api_base && fields.api_base.trim()) {
148
+ def.api_base = fields.api_base;
149
+ }
150
+ if (fields.team_id !== undefined) {
151
+ def.team_id = fields.team_id;
152
+ }
153
+ };
154
+ // Create a profile. URLs are optional — anything omitted is inherited from the
155
+ // embedded default (prod). team_id is optional and account-specific.
156
+ const add_profile = (name, fields, env = process.env) => {
157
+ if (!name.trim()) {
158
+ throw new errors_1.UsageError('A profile name is required.', { code: 'usage.profile' });
159
+ }
160
+ if (name === DEFAULT_NAME) {
161
+ throw new errors_1.UsageError('`default` is the built-in profile and cannot be added.', {
162
+ code: 'usage.profile',
163
+ hint: 'Pick another name, e.g. your account email.',
164
+ });
165
+ }
166
+ const cfg = read_config(env);
167
+ const profiles = get_profiles(cfg, env);
168
+ const def = {};
169
+ apply_fields(def, fields);
170
+ profiles[name] = def;
171
+ cfg.profiles = profiles;
172
+ write_config(cfg, env);
173
+ };
174
+ exports.add_profile = add_profile;
175
+ // Edit an existing profile in place (merge-safe). Unlike add, `default` is
176
+ // allowed — it's the natural way for a no-profile user to pin a team without
177
+ // creating a named profile. A named profile must already exist.
178
+ const set_profile = (name, fields, env = process.env) => {
179
+ if (!name.trim()) {
180
+ throw new errors_1.UsageError('A profile name is required.', { code: 'usage.profile' });
181
+ }
182
+ const cfg = read_config(env);
183
+ const profiles = get_profiles(cfg, env);
184
+ if (name !== DEFAULT_NAME && !profiles[name]) {
185
+ throw new errors_1.UsageError(`Unknown profile '${name}'.`, {
186
+ code: 'usage.profile',
187
+ hint: `Create it first with \`profile add ${name}\`.`,
188
+ });
189
+ }
190
+ const def = { ...(profiles[name] ?? {}) };
191
+ apply_fields(def, fields);
192
+ profiles[name] = def;
193
+ cfg.profiles = profiles;
194
+ write_config(cfg, env);
195
+ };
196
+ exports.set_profile = set_profile;
197
+ // Rename a profile's config entry. Config-only — the credential move is done by
198
+ // the command layer (see commands/profile.ts handle_rename), which also guards
199
+ // against clobbering a login. `default` is the built-in slot: neither source nor
200
+ // target. Validation order matches the spec.
201
+ const rename_profile_def = (old_name, new_name, env = process.env) => {
202
+ if (old_name === DEFAULT_NAME) {
203
+ throw new errors_1.UsageError('The built-in default profile can\'t be renamed.', { code: 'usage.profile' });
204
+ }
205
+ const cfg = read_config(env);
206
+ const profiles = get_profiles(cfg, env);
207
+ if (!profiles[old_name]) {
208
+ throw new errors_1.UsageError(`Unknown profile '${old_name}'.`, {
209
+ code: 'usage.profile', hint: 'List profiles with `profile list`.',
210
+ });
211
+ }
212
+ if (!new_name.trim()) {
213
+ throw new errors_1.UsageError('A profile name is required.', { code: 'usage.profile' });
214
+ }
215
+ if (new_name === DEFAULT_NAME) {
216
+ throw new errors_1.UsageError('Can\'t rename to the built-in default.', { code: 'usage.profile' });
217
+ }
218
+ if (new_name === old_name) {
219
+ throw new errors_1.UsageError('New name is the same as the old name.', { code: 'usage.profile' });
220
+ }
221
+ if (profiles[new_name]) {
222
+ throw new errors_1.UsageError(`Profile '${new_name}' already exists.`, {
223
+ code: 'usage.profile', hint: 'Delete or rename it first, or pick another name.',
224
+ });
225
+ }
226
+ profiles[new_name] = profiles[old_name];
227
+ delete profiles[old_name];
228
+ cfg.profiles = profiles;
229
+ if (persisted_current(cfg) === old_name) {
230
+ cfg.current_profile = new_name;
231
+ }
232
+ write_config(cfg, env);
233
+ };
234
+ exports.rename_profile_def = rename_profile_def;
235
+ // Remove a profile's config entry. Config-only — the credential removal is done
236
+ // by the command layer (handle_delete). Returns whether the deleted profile was
237
+ // current so the caller can report the reset to default.
238
+ const delete_profile_def = (name, env = process.env) => {
239
+ if (name === DEFAULT_NAME) {
240
+ throw new errors_1.UsageError('The built-in default profile can\'t be deleted.', { code: 'usage.profile' });
241
+ }
242
+ const cfg = read_config(env);
243
+ const profiles = get_profiles(cfg, env);
244
+ if (!profiles[name]) {
245
+ throw new errors_1.UsageError(`Unknown profile '${name}'.`, {
246
+ code: 'usage.profile', hint: 'List profiles with `profile list`.',
247
+ });
248
+ }
249
+ delete profiles[name];
250
+ cfg.profiles = profiles;
251
+ const was_current = persisted_current(cfg) === name;
252
+ if (was_current) {
253
+ delete cfg.current_profile; // revert to the built-in default
254
+ }
255
+ write_config(cfg, env);
256
+ return { was_current };
257
+ };
258
+ exports.delete_profile_def = delete_profile_def;
259
+ // Clear one config field on a profile, reverting it to inherited (URLs) or unset
260
+ // (team_id). `default` is allowed (to clear an override / team pin). Never touches
261
+ // the profile name or credentials. Idempotent — a no-op returns {changed:false}.
262
+ const unset_profile_field = (name, field, env = process.env) => {
263
+ if (!CLEARABLE_FIELDS.includes(field)) {
264
+ throw new errors_1.UsageError(`Can't clear '${field}'.`, {
265
+ code: 'usage.profile', hint: `Clearable fields: ${CLEARABLE_FIELDS.join(', ')}.`,
266
+ });
267
+ }
268
+ const cfg = read_config(env);
269
+ const profiles = get_profiles(cfg, env);
270
+ if (name !== DEFAULT_NAME && !profiles[name]) {
271
+ throw new errors_1.UsageError(`Unknown profile '${name}'.`, {
272
+ code: 'usage.profile', hint: 'List profiles with `profile list`.',
273
+ });
274
+ }
275
+ const def = { ...(profiles[name] ?? {}) };
276
+ if (!(field in def)) {
277
+ return { changed: false };
278
+ }
279
+ delete def[field];
280
+ profiles[name] = def;
281
+ cfg.profiles = profiles;
282
+ write_config(cfg, env);
283
+ return { changed: true };
284
+ };
285
+ exports.unset_profile_field = unset_profile_field;
286
+ // Persist the current profile. Validates the name resolves first (so you can't
287
+ // set current to an unknown profile), then writes current_profile.
288
+ const set_current_profile = (name, env = process.env) => {
289
+ resolve_profile(name, env); // throws UsageError if the name is not valid
290
+ const cfg = read_config(env);
291
+ cfg.current_profile = name;
292
+ write_config(cfg, env);
293
+ };
294
+ exports.set_current_profile = set_current_profile;
295
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,qCAAwD;AACxD,2CAAwD;AAcxD,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,yEAAyE;AACzE,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,QAAQ,GAAG;IACb,SAAS,EAAE,wBAAwB;IACnC,QAAQ,EAAE,sBAAsB;CACnC,CAAC;AA0V0L,4BAAQ;AAzVpM,mEAAmE;AACnE,MAAM,IAAI,GAAG,QAAQ,CAAC;AAwVgL,oBAAI;AAnV1M,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAS,EAAE,CAAA,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAE5E,2EAA2E;AAC3E,gEAAgE;AAChE,MAAM,YAAY,GAAG,CAAC,CAAU,EAAqB,EAAE;IACnD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAChD,CAAC;QACG,OAAO,CAAC,CAAC;IACb,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EACnD,CAAC;QACG,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAS,EAAE;IACpC,MAAM,IAAI,GAAG,IAAA,oBAAW,EAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACD,GAAG,GAAG,YAAE,CAA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C,GAAG,GAAG,CAAC;IACrB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvB,OAAO,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;AAC3B,CAAC,CAAC;AAWmJ,kDAAmB;AATxK,+EAA+E;AAC/E,mEAAmE;AACnE,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,MAAW,OAAO,CAAC,GAAG,EAAO,EAAE;IACtE,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAG,6CAA6C;IAC3E,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAA4B,CAAC;IACxD,GAAG,CAAC,eAAe,GAAG,IAAI,CAAC;IAC3B,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC3B,CAAC,CAAC;AAE4D,kDAAmB"}
@@ -0,0 +1,14 @@
1
+ type Team = {
2
+ team_id: number;
3
+ team_name: string;
4
+ };
5
+ declare const parse_teams: (raw: unknown) => Team[];
6
+ type Teams_deps = {
7
+ api_base: string;
8
+ token: string;
9
+ headers?: Record<string, string>;
10
+ };
11
+ declare const resolve_my_teams: (deps: Teams_deps) => Promise<Team[]>;
12
+ declare const team_error_guidance: (status: number, data: unknown) => string | undefined;
13
+ export { parse_teams, resolve_my_teams, team_error_guidance };
14
+ export type { Team, Teams_deps };
package/dist/teams.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.team_error_guidance = exports.resolve_my_teams = exports.parse_teams = void 0;
4
+ const client_1 = require("./utils/client");
5
+ const errors_1 = require("./utils/errors");
6
+ const TEAM_USERS_ENDPOINT = '/v3/whoami/team-users';
7
+ const WHOAMI_ENDPOINT = '/v3/whoami';
8
+ const TEAMS_IN_BODY_CODES = ['TEAM_REQUIRED', 'TEAM_NOT_ACCESSIBLE'];
9
+ // team-users is organization-only; a personal account has just its own team.
10
+ const ORG_ONLY_CODE = 'workspace.organizationRequired';
11
+ const read_team = (item) => {
12
+ if (typeof item !== 'object' || item === null) {
13
+ return undefined;
14
+ }
15
+ const rec = item;
16
+ const id = rec.teamId ?? rec.TeamId;
17
+ const name = rec.teamName ?? rec.TeamName;
18
+ if (typeof id !== 'number' || !Number.isInteger(id)) {
19
+ return undefined;
20
+ }
21
+ return { team_id: id, team_name: typeof name === 'string' ? name : '' };
22
+ };
23
+ // Reduce an array of team-ish objects to distinct teams (by id), dropping malformed.
24
+ const parse_teams = (raw) => {
25
+ if (!Array.isArray(raw)) {
26
+ return [];
27
+ }
28
+ const seen = new Set();
29
+ const out = [];
30
+ for (const item of raw) {
31
+ const t = read_team(item);
32
+ if (t && !seen.has(t.team_id)) {
33
+ seen.add(t.team_id);
34
+ out.push(t);
35
+ }
36
+ }
37
+ return out;
38
+ };
39
+ exports.parse_teams = parse_teams;
40
+ // A personal (non-org) account has exactly one team — its own — which team-users
41
+ // won't list but whoami reports. Return that single team ({team_name} unknown).
42
+ const single_team_from_whoami = async (deps) => {
43
+ const { status, data } = await (0, client_1.request_raw)(deps.api_base, deps.token, 'GET', WHOAMI_ENDPOINT, undefined, { headers: deps.headers });
44
+ if (status >= 200 && status < 300 && typeof data === 'object' && data !== null) {
45
+ const id = data.teamId;
46
+ if (typeof id === 'number' && Number.isInteger(id)) {
47
+ return [{ team_id: id, team_name: '' }];
48
+ }
49
+ }
50
+ return [];
51
+ };
52
+ // The teams the caller can act in. Resilient: the list is the same whether
53
+ // /whoami/team-users returns 200, or a TEAM_REQUIRED/TEAM_NOT_ACCESSIBLE 403
54
+ // (whose body carries the same teams[]). When team-users is organization-only,
55
+ // fall back to the single whoami team. Any other outcome throws — the caller
56
+ // decides how to degrade.
57
+ const resolve_my_teams = async (deps) => {
58
+ const { status, data } = await (0, client_1.request_raw)(deps.api_base, deps.token, 'GET', TEAM_USERS_ENDPOINT, undefined, { headers: deps.headers });
59
+ if (status >= 200 && status < 300) {
60
+ return parse_teams(data);
61
+ }
62
+ const body = typeof data === 'object' && data !== null ? data : {};
63
+ const code = typeof body.code === 'string' ? body.code : undefined;
64
+ if (status === 403 && code && TEAMS_IN_BODY_CODES.includes(code)) {
65
+ return parse_teams(body.teams);
66
+ }
67
+ if (status === 403 && code === ORG_ONLY_CODE) {
68
+ return single_team_from_whoami(deps);
69
+ }
70
+ throw new errors_1.RuntimeError('Could not list your teams.', {
71
+ code: 'teams.unavailable',
72
+ detail: code ? `HTTP ${status}: ${code}` : `HTTP ${status}`,
73
+ hint: 'Make sure you are logged in.',
74
+ });
75
+ };
76
+ exports.resolve_my_teams = resolve_my_teams;
77
+ const RESOLUTION_CODES = ['TEAM_REQUIRED', 'TEAM_NOT_ACCESSIBLE', 'USER_REQUIRED', 'USER_NOT_FOUND'];
78
+ const render_teams = (teams) => teams.map(t => ` ${t.team_id} ${t.team_name}`).join('\n');
79
+ // Tailored guidance for a WORKLOAD team/user-resolution conflict (used by `api`).
80
+ // Returns undefined when the body is not a recognized resolution error.
81
+ const team_error_guidance = (status, data) => {
82
+ const body = typeof data === 'object' && data !== null ? data : {};
83
+ const code = typeof body.code === 'string' ? body.code : undefined;
84
+ if (!code || !RESOLUTION_CODES.includes(code)) {
85
+ return undefined;
86
+ }
87
+ const teams = parse_teams(body.teams);
88
+ const list = teams.length ? `\n${render_teams(teams)}` : '';
89
+ switch (code) {
90
+ case 'TEAM_REQUIRED':
91
+ return 'You belong to multiple teams. Choose one:\n'
92
+ + ' reply team use <id> (or --team-id <id>, REPLY_TEAM_ID, or profile set <name> --team-id <id>)'
93
+ + list;
94
+ case 'TEAM_NOT_ACCESSIBLE':
95
+ return `That team isn't one you can act in. Your teams:${list}`;
96
+ case 'USER_REQUIRED':
97
+ return 'This organization API key needs an acting user — pass --user-id <id> or --user-email <email>.';
98
+ default: // USER_NOT_FOUND
99
+ return "No Reply user maps to this credential — check you're logged in with the right account.";
100
+ }
101
+ };
102
+ exports.team_error_guidance = team_error_guidance;
103
+ //# sourceM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request: <T = unknown>(api_key: string, method: string, endpoint: string, body?: unknown, opts?: Request_opts) => Promise<T>;
5
- declare const get: <T = unknown>(api_key: string, endpoint: string, opts?: Request_opts) => Promise<T>;
6
- declare const post: <T = unknown>(api_key: string, endpoint: string, body?: unknown, opts?: Request_opts) => Promise<T>;
7
- declare const patch: <T = unknown>(api_key: string, endpoint: string, body: unknown, opts?: Request_opts) => Promise<T>;
8
- declare const del: <T = unknown>(api_key: string, endpoint: string, body?: unknown, opts?: Request_opts) => Promise<T>;
9
- declare const post_form_data: <T = unknown>(api_key: string, endpoint: string, form_data: FormData, opts?: Request_opts) => Promise<T>;
10
- export { get, post, patch, del, post_form_data, request };
11
- export type { Request_opts };
4
+ declare const request: <T = unknown>(base_url: string, token: string, method: string, endpoint: string, body?: unknown, opts?: Request_opts) => Promise<T>;
5
+ declare const get: <T = unknown>(base_url: string, token: string, endpoint: string, opts?: Request_opts) => Promise<T>;
6
+ type Raw_response = {
7
+ status: number;
8
+ data: unknown;
9
+ response_headers: Record<string, string>;
10
+ request: {
11
+ method: string;
12
+ url: string;
13
+ headers: Record<string, string>;
14
+ body?: string;
15
+ };
16
+ };
17
+ declare const request_raw: (base_url: string, token: string, method: string, endpoint: string, body?: unknown, opts?: Request_opts) => Promise<Raw_response>;
18
+ type Client = {
19
+ get<T = unknown>(endpoint: string, opts?: Request_opts): Promise<T>;
20
+ };
21
+ declare const create_client: (base_url: string, token: string, headers?: Record<string, string>) => Client;
22
+ export { request, get, request_raw, create_client };
23
+ export type { Request_opts, Client, Raw_response };