pcific 0.0.0-stage → 0.2.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/SKILL.md +127 -0
  4. package/dist/api/catalog.js +637 -0
  5. package/dist/api/run.js +960 -0
  6. package/dist/api/search.js +171 -0
  7. package/dist/api/shortcuts.js +799 -0
  8. package/dist/bin.js +648 -0
  9. package/dist/commands/auth.js +513 -0
  10. package/dist/commands/doctor.js +410 -0
  11. package/dist/commands/init.js +306 -0
  12. package/dist/commands/sync.js +214 -0
  13. package/dist/detect.js +214 -0
  14. package/dist/env.js +339 -0
  15. package/dist/goLive.js +629 -0
  16. package/dist/keyLink.js +305 -0
  17. package/dist/mcp/server.js +206 -0
  18. package/dist/mcp/tools.js +689 -0
  19. package/dist/python/template.js +793 -0
  20. package/dist/schema/discover.js +324 -0
  21. package/dist/schema/helpers.js +396 -0
  22. package/dist/schema/prismaToJsonSchema.js +197 -0
  23. package/dist/schema/push.js +570 -0
  24. package/dist/schema/tsToJsonSchema.js +405 -0
  25. package/dist/schema/zodToJsonSchema.js +442 -0
  26. package/dist/templates/openapi.json +1 -0
  27. package/dist/templates/sdk/auth.ts +139 -0
  28. package/dist/templates/sdk/client.ts +1059 -0
  29. package/dist/templates/sdk/errors.ts +76 -0
  30. package/dist/templates/sdk/generated-types.ts +5746 -0
  31. package/dist/templates/sdk/http.ts +359 -0
  32. package/dist/templates/sdk/index.ts +84 -0
  33. package/dist/templates/sdk/json.ts +24 -0
  34. package/dist/templates/sdk/kit.ts +516 -0
  35. package/dist/templates/sdk/multipart.ts +99 -0
  36. package/dist/templates/sdk/sse.ts +131 -0
  37. package/dist/templates/sdk/verify.ts +766 -0
  38. package/dist/templates/sdk-js/auth.d.ts +20 -0
  39. package/dist/templates/sdk-js/auth.js +85 -0
  40. package/dist/templates/sdk-js/client.d.ts +324 -0
  41. package/dist/templates/sdk-js/client.js +607 -0
  42. package/dist/templates/sdk-js/errors.d.ts +51 -0
  43. package/dist/templates/sdk-js/errors.js +48 -0
  44. package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
  45. package/dist/templates/sdk-js/generated-types.js +5 -0
  46. package/dist/templates/sdk-js/http.d.ts +50 -0
  47. package/dist/templates/sdk-js/http.js +263 -0
  48. package/dist/templates/sdk-js/index.d.ts +9 -0
  49. package/dist/templates/sdk-js/index.js +7 -0
  50. package/dist/templates/sdk-js/json.d.ts +11 -0
  51. package/dist/templates/sdk-js/json.js +16 -0
  52. package/dist/templates/sdk-js/kit.d.ts +220 -0
  53. package/dist/templates/sdk-js/kit.js +208 -0
  54. package/dist/templates/sdk-js/multipart.d.ts +23 -0
  55. package/dist/templates/sdk-js/multipart.js +61 -0
  56. package/dist/templates/sdk-js/sse.d.ts +12 -0
  57. package/dist/templates/sdk-js/sse.js +99 -0
  58. package/dist/templates/sdk-js/verify.d.ts +114 -0
  59. package/dist/templates/sdk-js/verify.js +506 -0
  60. package/dist/templates.js +925 -0
  61. package/dist/ui.js +399 -0
  62. package/dist/webhooks/events.js +171 -0
  63. package/dist/webhooks/listen.js +772 -0
  64. package/package.json +32 -4
@@ -0,0 +1,171 @@
1
+ import { loadOpenApiCatalog, searchOperations } from "./catalog.js";
2
+ function isStreamTty(stream) {
3
+ return Boolean(stream.isTTY);
4
+ }
5
+ function writeLine(stream, text) {
6
+ stream.write(`${text}\n`);
7
+ }
8
+ function buildRunHint(op) {
9
+ const parts = ["pcific", "api", op.operationId];
10
+ for (const param of op.parameters) {
11
+ if (param.in === "path") {
12
+ parts.push("--param", `${param.name}=<${param.name}>`);
13
+ }
14
+ }
15
+ if (op.method !== "GET" && op.requestBodySchema) {
16
+ parts.push("--data", "'{}'", "--dry-run");
17
+ }
18
+ return parts.join(" ");
19
+ }
20
+ const SEARCH_HELP = [
21
+ "Usage: pcific search <query> [--limit N] [--tag <tag>] [--json] [--plain]",
22
+ "",
23
+ "Search all PCIFIC OpenAPI operations locally with zero network calls.",
24
+ "",
25
+ "Examples:",
26
+ ' pcific search "safeguard settings"',
27
+ ' pcific search "embed branding" --limit 5',
28
+ ' pcific search "spend limits" --json',
29
+ ].join("\n");
30
+ export async function runSearchCommand(args, options = {}) {
31
+ const stdout = options.stdout ?? process.stdout;
32
+ const stderr = options.stderr ?? process.stderr;
33
+ let jsonFlag = Boolean(options.json);
34
+ let plainFlag = Boolean(options.plain);
35
+ let limit = 10;
36
+ let tagFilter;
37
+ let showHelp = false;
38
+ const queryParts = [];
39
+ for (let i = 0; i < args.length; i += 1) {
40
+ const arg = args[i];
41
+ if (arg === "--help" || arg === "-h") {
42
+ showHelp = true;
43
+ continue;
44
+ }
45
+ if (arg === "--json") {
46
+ jsonFlag = true;
47
+ continue;
48
+ }
49
+ if (arg === "--plain") {
50
+ plainFlag = true;
51
+ continue;
52
+ }
53
+ if (arg === "--limit" || arg === "-n" || arg.startsWith("--limit=")) {
54
+ const rawValue = arg.startsWith("--limit=") ? arg.slice("--limit=".length) : args[i + 1];
55
+ if (!arg.startsWith("--limit=")) {
56
+ if (!rawValue || rawValue.startsWith("-")) {
57
+ writeLine(stderr, JSON.stringify({
58
+ ok: false,
59
+ error: "Missing value for --limit.",
60
+ code: "MISSING_FLAG_VALUE",
61
+ tryThis: "Pass a whole number between 1 and 200, for example --limit 10.",
62
+ }));
63
+ return 1;
64
+ }
65
+ i += 1;
66
+ }
67
+ const parsed = Number.parseInt(rawValue ?? "", 10);
68
+ if (!Number.isFinite(parsed) || parsed < 1 || parsed > 200) {
69
+ writeLine(stderr, JSON.stringify({
70
+ ok: false,
71
+ error: `Invalid --limit value "${rawValue ?? ""}".`,
72
+ code: "INVALID_LIMIT",
73
+ tryThis: "Pass a whole number between 1 and 200, for example --limit 10.",
74
+ }));
75
+ return 1;
76
+ }
77
+ limit = parsed;
78
+ continue;
79
+ }
80
+ if (arg === "--tag" || arg.startsWith("--tag=")) {
81
+ const rawValue = arg.startsWith("--tag=") ? arg.slice("--tag=".length) : args[i + 1];
82
+ if (!rawValue || (!arg.startsWith("--tag=") && rawValue.startsWith("-"))) {
83
+ writeLine(stderr, JSON.stringify({
84
+ ok: false,
85
+ error: "Missing value for --tag.",
86
+ code: "MISSING_FLAG_VALUE",
87
+ tryThis: "Pass a tag name, for example --tag Safeguard.",
88
+ }));
89
+ return 1;
90
+ }
91
+ if (!arg.startsWith("--tag=")) {
92
+ i += 1;
93
+ }
94
+ tagFilter = rawValue;
95
+ continue;
96
+ }
97
+ if (arg.startsWith("-")) {
98
+ writeLine(stderr, JSON.stringify({
99
+ ok: false,
100
+ error: `Unknown flag "${arg}" for pcific search.`,
101
+ code: "UNKNOWN_FLAG",
102
+ tryThis: 'Run pcific search --help or pcific search "safeguard settings".',
103
+ }));
104
+ return 1;
105
+ }
106
+ queryParts.push(arg);
107
+ }
108
+ if (showHelp) {
109
+ writeLine(stdout, SEARCH_HELP);
110
+ return 0;
111
+ }
112
+ const query = queryParts.join(" ").trim();
113
+ const useJson = jsonFlag || (!plainFlag && !isStreamTty(stdout));
114
+ if (!query && !tagFilter) {
115
+ const errPayload = {
116
+ ok: false,
117
+ error: "Missing search query.",
118
+ code: "MISSING_QUERY",
119
+ tryThis: 'Pass a keyword or phrase, for example: pcific search "safeguard settings".',
120
+ };
121
+ if (useJson) {
122
+ writeLine(stderr, JSON.stringify(errPayload));
123
+ }
124
+ else {
125
+ writeLine(stderr, `Error [${errPayload.code}]: ${errPayload.error}`);
126
+ writeLine(stderr, `Next: ${errPayload.tryThis}`);
127
+ }
128
+ return 1;
129
+ }
130
+ const catalog = loadOpenApiCatalog({ openapiPath: options.openapiPath });
131
+ const rawResults = searchOperations(catalog, query, tagFilter ? catalog.operations.length : limit);
132
+ const filtered = tagFilter
133
+ ? rawResults
134
+ .filter((entry) => entry.operation.tags.some((tag) => tag.toLowerCase() === tagFilter.toLowerCase()))
135
+ .slice(0, limit)
136
+ : rawResults;
137
+ const items = filtered.map((entry) => ({
138
+ operationId: entry.operation.operationId,
139
+ method: entry.operation.method,
140
+ path: entry.operation.path,
141
+ tags: entry.operation.tags,
142
+ summary: entry.operation.summary,
143
+ describe: `pcific api describe ${entry.operation.operationId}`,
144
+ run: buildRunHint(entry.operation),
145
+ }));
146
+ if (useJson) {
147
+ writeLine(stdout, JSON.stringify({
148
+ query,
149
+ total: items.length,
150
+ results: items,
151
+ }));
152
+ return 0;
153
+ }
154
+ if (items.length === 0) {
155
+ writeLine(stdout, `No PCIFIC operations matched "${query}".`);
156
+ writeLine(stdout, "Try broader keywords or run: pcific api list");
157
+ return 0;
158
+ }
159
+ writeLine(stdout, `Found ${items.length} operation${items.length === 1 ? "" : "s"} for "${query}":`);
160
+ writeLine(stdout, "");
161
+ for (const item of items) {
162
+ writeLine(stdout, `${item.operationId} ${item.method} ${item.path}`);
163
+ if (item.summary) {
164
+ writeLine(stdout, ` ${item.summary}`);
165
+ }
166
+ writeLine(stdout, ` Next: ${item.describe}`);
167
+ writeLine(stdout, ` Run: ${item.run}`);
168
+ writeLine(stdout, "");
169
+ }
170
+ return 0;
171
+ }