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.
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/SKILL.md +127 -0
- package/dist/api/catalog.js +637 -0
- package/dist/api/run.js +960 -0
- package/dist/api/search.js +171 -0
- package/dist/api/shortcuts.js +799 -0
- package/dist/bin.js +648 -0
- package/dist/commands/auth.js +513 -0
- package/dist/commands/doctor.js +410 -0
- package/dist/commands/init.js +306 -0
- package/dist/commands/sync.js +214 -0
- package/dist/detect.js +214 -0
- package/dist/env.js +339 -0
- package/dist/goLive.js +629 -0
- package/dist/keyLink.js +305 -0
- package/dist/mcp/server.js +206 -0
- package/dist/mcp/tools.js +689 -0
- package/dist/python/template.js +793 -0
- package/dist/schema/discover.js +324 -0
- package/dist/schema/helpers.js +396 -0
- package/dist/schema/prismaToJsonSchema.js +197 -0
- package/dist/schema/push.js +570 -0
- package/dist/schema/tsToJsonSchema.js +405 -0
- package/dist/schema/zodToJsonSchema.js +442 -0
- package/dist/templates/openapi.json +1 -0
- package/dist/templates/sdk/auth.ts +139 -0
- package/dist/templates/sdk/client.ts +1059 -0
- package/dist/templates/sdk/errors.ts +76 -0
- package/dist/templates/sdk/generated-types.ts +5746 -0
- package/dist/templates/sdk/http.ts +359 -0
- package/dist/templates/sdk/index.ts +84 -0
- package/dist/templates/sdk/json.ts +24 -0
- package/dist/templates/sdk/kit.ts +516 -0
- package/dist/templates/sdk/multipart.ts +99 -0
- package/dist/templates/sdk/sse.ts +131 -0
- package/dist/templates/sdk/verify.ts +766 -0
- package/dist/templates/sdk-js/auth.d.ts +20 -0
- package/dist/templates/sdk-js/auth.js +85 -0
- package/dist/templates/sdk-js/client.d.ts +324 -0
- package/dist/templates/sdk-js/client.js +607 -0
- package/dist/templates/sdk-js/errors.d.ts +51 -0
- package/dist/templates/sdk-js/errors.js +48 -0
- package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
- package/dist/templates/sdk-js/generated-types.js +5 -0
- package/dist/templates/sdk-js/http.d.ts +50 -0
- package/dist/templates/sdk-js/http.js +263 -0
- package/dist/templates/sdk-js/index.d.ts +9 -0
- package/dist/templates/sdk-js/index.js +7 -0
- package/dist/templates/sdk-js/json.d.ts +11 -0
- package/dist/templates/sdk-js/json.js +16 -0
- package/dist/templates/sdk-js/kit.d.ts +220 -0
- package/dist/templates/sdk-js/kit.js +208 -0
- package/dist/templates/sdk-js/multipart.d.ts +23 -0
- package/dist/templates/sdk-js/multipart.js +61 -0
- package/dist/templates/sdk-js/sse.d.ts +12 -0
- package/dist/templates/sdk-js/sse.js +99 -0
- package/dist/templates/sdk-js/verify.d.ts +114 -0
- package/dist/templates/sdk-js/verify.js +506 -0
- package/dist/templates.js +925 -0
- package/dist/ui.js +399 -0
- package/dist/webhooks/events.js +171 -0
- package/dist/webhooks/listen.js +772 -0
- package/package.json +32 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { PcificConfigError } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
export type PcificMode = "test" | "live";
|
|
4
|
+
|
|
5
|
+
export interface ResolvePcificAuthOptions {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
liveKey?: string;
|
|
8
|
+
testKey?: string;
|
|
9
|
+
mode?: PcificMode | string;
|
|
10
|
+
env?: Record<string, string | undefined>;
|
|
11
|
+
warn?: (message: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ResolvedPcificAuth {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
mode: PcificMode;
|
|
17
|
+
source: "apiKey" | "liveKey" | "testKey" | "PCIFIC_LIVE_KEY" | "PCIFIC_TEST_KEY";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface NodeLikeGlobal {
|
|
21
|
+
process?: { env?: Record<string, string | undefined> };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readDefaultEnv(): Record<string, string | undefined> {
|
|
25
|
+
if (typeof globalThis !== "undefined" && "process" in globalThis) {
|
|
26
|
+
// SAFETY: We just verified "process" exists on globalThis; reading optional process.env is safe in Node and edge runtimes.
|
|
27
|
+
const proc = (globalThis as NodeLikeGlobal).process;
|
|
28
|
+
|
|
29
|
+
if (proc?.env) return proc.env;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function nonEmpty(value: string | undefined): string | undefined {
|
|
36
|
+
if (value === undefined) return undefined;
|
|
37
|
+
const trimmed = value.trim();
|
|
38
|
+
|
|
39
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveMode(
|
|
43
|
+
explicitMode: string | undefined,
|
|
44
|
+
envMode: string | undefined,
|
|
45
|
+
nodeEnv: string | undefined,
|
|
46
|
+
): PcificMode {
|
|
47
|
+
const raw = nonEmpty(explicitMode) ?? nonEmpty(envMode);
|
|
48
|
+
|
|
49
|
+
if (raw === undefined) {
|
|
50
|
+
return nodeEnv === "production" ? "live" : "test";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (raw === "live" || raw === "test") {
|
|
54
|
+
return raw;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new PcificConfigError(
|
|
58
|
+
`Invalid PCIFIC_MODE "${raw}". Expected "test" or "live".`,
|
|
59
|
+
{
|
|
60
|
+
code: "INVALID_PCIFIC_MODE",
|
|
61
|
+
tryThis: 'Set PCIFIC_MODE to "test" or "live", or leave it unset to default to "live" in production and "test" elsewhere.',
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the PCIFIC API key using explicit PCIFIC_MODE selection.
|
|
68
|
+
* Defaults to "live" when NODE_ENV === "production" and "test" otherwise.
|
|
69
|
+
* Empty PCIFIC_MODE ("") is treated as unset.
|
|
70
|
+
*/
|
|
71
|
+
export function resolvePcificAuth(options: ResolvePcificAuthOptions = {}): ResolvedPcificAuth {
|
|
72
|
+
const env = options.env ?? readDefaultEnv();
|
|
73
|
+
const warn = options.warn ?? ((message: string) => console.warn(message));
|
|
74
|
+
const isProduction = env.NODE_ENV === "production";
|
|
75
|
+
|
|
76
|
+
const directKey = nonEmpty(options.apiKey);
|
|
77
|
+
|
|
78
|
+
if (directKey !== undefined) {
|
|
79
|
+
const inferredMode: PcificMode = directKey.startsWith("pcific_live_")
|
|
80
|
+
? "live"
|
|
81
|
+
: directKey.startsWith("pcific_test_")
|
|
82
|
+
? "test"
|
|
83
|
+
: resolveMode(options.mode, env.PCIFIC_MODE, env.NODE_ENV);
|
|
84
|
+
|
|
85
|
+
if (inferredMode === "live" && !isProduction) {
|
|
86
|
+
warn('[pcific] Using a live API key outside production (NODE_ENV !== "production").');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { apiKey: directKey, mode: inferredMode, source: "apiKey" };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const mode = resolveMode(options.mode, env.PCIFIC_MODE, env.NODE_ENV);
|
|
93
|
+
|
|
94
|
+
if (mode === "live") {
|
|
95
|
+
const explicitLive = nonEmpty(options.liveKey);
|
|
96
|
+
const envLive = nonEmpty(env.PCIFIC_LIVE_KEY);
|
|
97
|
+
const key = explicitLive ?? envLive;
|
|
98
|
+
|
|
99
|
+
if (!key) {
|
|
100
|
+
throw new PcificConfigError(
|
|
101
|
+
'Missing PCIFIC live API key for mode "live". Set PCIFIC_LIVE_KEY or pass liveKey.',
|
|
102
|
+
{
|
|
103
|
+
code: "MISSING_LIVE_KEY",
|
|
104
|
+
tryThis: 'Set the PCIFIC_LIVE_KEY environment variable, or set PCIFIC_MODE="test" to use PCIFIC_TEST_KEY.',
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!isProduction) {
|
|
110
|
+
warn("[pcific] Using PCIFIC_LIVE_KEY outside production (PCIFIC_MODE=live).");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
apiKey: key,
|
|
115
|
+
mode: "live",
|
|
116
|
+
source: explicitLive ? "liveKey" : "PCIFIC_LIVE_KEY",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const explicitTest = nonEmpty(options.testKey);
|
|
121
|
+
const envTest = nonEmpty(env.PCIFIC_TEST_KEY);
|
|
122
|
+
const key = explicitTest ?? envTest;
|
|
123
|
+
|
|
124
|
+
if (!key) {
|
|
125
|
+
throw new PcificConfigError(
|
|
126
|
+
'Missing PCIFIC test API key for mode "test". Set PCIFIC_TEST_KEY or pass testKey.',
|
|
127
|
+
{
|
|
128
|
+
code: "MISSING_TEST_KEY",
|
|
129
|
+
tryThis: "Set the PCIFIC_TEST_KEY environment variable, or pass testKey / apiKey when constructing the client.",
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
apiKey: key,
|
|
136
|
+
mode: "test",
|
|
137
|
+
source: explicitTest ? "testKey" : "PCIFIC_TEST_KEY",
|
|
138
|
+
};
|
|
139
|
+
}
|