@postrun/js 0.1.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.
@@ -0,0 +1,34 @@
1
+ import { cD as TokensMintData, f5 as PostrunClient, fo as TokensMintResponse } from './types.gen-DGCs7eB8.cjs';
2
+
3
+ /**
4
+ * The body for minting a scoped token — the generated request shape (snake_case,
5
+ * the exact wire contract). `scopes` is the closed `resource:action` union and
6
+ * `profile_scope` the `{ type, values }` selector, both derived from the spec so
7
+ * they can never drift. Money/structural writes are NOT scopes: those endpoints
8
+ * are secret-key-only and a browser token simply cannot reach them, by design.
9
+ */
10
+ type MintTokenInput = TokensMintData['body'];
11
+ interface PostrunServerOptions {
12
+ /** Your secret `pr_` API key. NEVER expose this to a browser. */
13
+ secretKey: string;
14
+ /** Override the API base URL (defaults to the production gateway). */
15
+ baseUrl?: string;
16
+ }
17
+ interface PostrunServer {
18
+ /** A typed client authenticated with the secret key — for any server-side call. */
19
+ readonly client: PostrunClient;
20
+ readonly tokens: {
21
+ /** Mint a short-lived, scoped frontend token from the secret key. */
22
+ mint(input: MintTokenInput): Promise<TokensMintResponse>;
23
+ };
24
+ }
25
+ /**
26
+ * Create a server-side Postrun client from a secret `pr_` key. Its primary job
27
+ * is `tokens.mint` — issue a short-lived, scoped token your frontend hands to
28
+ * `createPostrunClient`, so the secret key never reaches the browser. The raw
29
+ * `client` is exposed for any other server-side call (e.g. the generated SDK
30
+ * functions: `postsCreate({ client })`).
31
+ */
32
+ declare function createPostrunServer(options: PostrunServerOptions): PostrunServer;
33
+
34
+ export { type MintTokenInput, type PostrunServer, type PostrunServerOptions, createPostrunServer };
@@ -0,0 +1,34 @@
1
+ import { cD as TokensMintData, f5 as PostrunClient, fo as TokensMintResponse } from './types.gen-DGCs7eB8.js';
2
+
3
+ /**
4
+ * The body for minting a scoped token — the generated request shape (snake_case,
5
+ * the exact wire contract). `scopes` is the closed `resource:action` union and
6
+ * `profile_scope` the `{ type, values }` selector, both derived from the spec so
7
+ * they can never drift. Money/structural writes are NOT scopes: those endpoints
8
+ * are secret-key-only and a browser token simply cannot reach them, by design.
9
+ */
10
+ type MintTokenInput = TokensMintData['body'];
11
+ interface PostrunServerOptions {
12
+ /** Your secret `pr_` API key. NEVER expose this to a browser. */
13
+ secretKey: string;
14
+ /** Override the API base URL (defaults to the production gateway). */
15
+ baseUrl?: string;
16
+ }
17
+ interface PostrunServer {
18
+ /** A typed client authenticated with the secret key — for any server-side call. */
19
+ readonly client: PostrunClient;
20
+ readonly tokens: {
21
+ /** Mint a short-lived, scoped frontend token from the secret key. */
22
+ mint(input: MintTokenInput): Promise<TokensMintResponse>;
23
+ };
24
+ }
25
+ /**
26
+ * Create a server-side Postrun client from a secret `pr_` key. Its primary job
27
+ * is `tokens.mint` — issue a short-lived, scoped token your frontend hands to
28
+ * `createPostrunClient`, so the secret key never reaches the browser. The raw
29
+ * `client` is exposed for any other server-side call (e.g. the generated SDK
30
+ * functions: `postsCreate({ client })`).
31
+ */
32
+ declare function createPostrunServer(options: PostrunServerOptions): PostrunServer;
33
+
34
+ export { type MintTokenInput, type PostrunServer, type PostrunServerOptions, createPostrunServer };
package/dist/server.js ADDED
@@ -0,0 +1,30 @@
1
+ import { createPostrunClient, tokensMint } from './chunk-A545VJ5X.js';
2
+ import './chunk-IMU3SG45.js';
3
+
4
+ // src/server.ts
5
+ function assertServerOnly() {
6
+ if (typeof window !== "undefined" && typeof window.document !== "undefined") {
7
+ throw new Error(
8
+ "createPostrunServer must run only on a server \u2014 it holds your secret pr_ key. In the browser, use createPostrunClient with a minted scoped token instead."
9
+ );
10
+ }
11
+ }
12
+ function createPostrunServer(options) {
13
+ assertServerOnly();
14
+ if (!options.secretKey) {
15
+ throw new Error("createPostrunServer requires a secret `pr_` key (secretKey).");
16
+ }
17
+ const client = createPostrunClient({
18
+ baseUrl: options.baseUrl,
19
+ getToken: () => options.secretKey
20
+ });
21
+ async function mint(input) {
22
+ const { data } = await tokensMint({ client, body: input });
23
+ return data;
24
+ }
25
+ return { client, tokens: { mint } };
26
+ }
27
+
28
+ export { createPostrunServer };
29
+ //# sourceMappingURL=server.js.map
30
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts"],"names":[],"mappings":";;;;AA+BA,SAAS,gBAAA,GAAyB;AAChC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,aAAa,WAAA,EAAa;AAC3E,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACF;AASO,SAAS,oBAAoB,OAAA,EAA8C;AAChF,EAAA,gBAAA,EAAiB;AACjB,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AACtB,IAAA,MAAM,IAAI,MAAM,8DAA8D,CAAA;AAAA,EAChF;AAEA,EAAA,MAAM,SAAS,mBAAA,CAAoB;AAAA,IACjC,SAAS,OAAA,CAAQ,OAAA;AAAA,IACjB,QAAA,EAAU,MAAM,OAAA,CAAQ;AAAA,GACzB,CAAA;AAED,EAAA,eAAe,KAAK,KAAA,EAAoD;AACtE,IAAA,MAAM,EAAE,MAAK,GAAI,MAAM,WAAW,EAAE,MAAA,EAAQ,IAAA,EAAM,KAAA,EAAO,CAAA;AACzD,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,MAAA,EAAQ,EAAE,MAAK,EAAE;AACpC","file":"server.js","sourcesContent":["import { createPostrunClient } from './client';\nimport type { PostrunClient } from './client';\nimport { tokensMint } from './client/sdk.gen';\nimport type { TokensMintData, TokensMintResponse } from './client/types.gen';\n\n/**\n * The body for minting a scoped token — the generated request shape (snake_case,\n * the exact wire contract). `scopes` is the closed `resource:action` union and\n * `profile_scope` the `{ type, values }` selector, both derived from the spec so\n * they can never drift. Money/structural writes are NOT scopes: those endpoints\n * are secret-key-only and a browser token simply cannot reach them, by design.\n */\nexport type MintTokenInput = TokensMintData['body'];\n\nexport interface PostrunServerOptions {\n /** Your secret `pr_` API key. NEVER expose this to a browser. */\n secretKey: string;\n /** Override the API base URL (defaults to the production gateway). */\n baseUrl?: string;\n}\n\nexport interface PostrunServer {\n /** A typed client authenticated with the secret key — for any server-side call. */\n readonly client: PostrunClient;\n readonly tokens: {\n /** Mint a short-lived, scoped frontend token from the secret key. */\n mint(input: MintTokenInput): Promise<TokensMintResponse>;\n };\n}\n\n/** The secret key must never reach a browser — fail loudly if it would. */\nfunction assertServerOnly(): void {\n if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {\n throw new Error(\n 'createPostrunServer must run only on a server — it holds your secret pr_ key. ' +\n 'In the browser, use createPostrunClient with a minted scoped token instead.',\n );\n }\n}\n\n/**\n * Create a server-side Postrun client from a secret `pr_` key. Its primary job\n * is `tokens.mint` — issue a short-lived, scoped token your frontend hands to\n * `createPostrunClient`, so the secret key never reaches the browser. The raw\n * `client` is exposed for any other server-side call (e.g. the generated SDK\n * functions: `postsCreate({ client })`).\n */\nexport function createPostrunServer(options: PostrunServerOptions): PostrunServer {\n assertServerOnly();\n if (!options.secretKey) {\n throw new Error('createPostrunServer requires a secret `pr_` key (secretKey).');\n }\n\n const client = createPostrunClient({\n baseUrl: options.baseUrl,\n getToken: () => options.secretKey,\n });\n\n async function mint(input: MintTokenInput): Promise<TokensMintResponse> {\n const { data } = await tokensMint({ client, body: input });\n return data;\n }\n\n return { client, tokens: { mint } };\n}\n"]}