@productcraft/core 0.0.2 → 0.0.4

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 ADDED
@@ -0,0 +1,25 @@
1
+ # @productcraft/core
2
+
3
+ Shared transport + auth primitives for the ProductCraft Node.js SDKs.
4
+
5
+ You **don't install this directly**. It's a runtime dependency of every product SDK (`@productcraft/heimdall`, `@productcraft/envoi`, `@productcraft/rally`, `@productcraft/agora`, `@productcraft/platform-auth`) plus the `productcraft` umbrella. Installing one of those pulls `@productcraft/core` along automatically.
6
+
7
+ ## What it provides
8
+
9
+ - `PCAuth` — discriminated union covering the three credential shapes the SDKs accept:
10
+ ```ts
11
+ | { type: "apiKey"; key: string } // pcft_live_*
12
+ | { type: "bearer"; token: string } // pre-resolved JWT
13
+ | { type: "cookie"; value: string } // captured auth_token
14
+ ```
15
+ - `PCClientConfig` — `{ auth?, baseUrl?, fetch? }`, the input shape every surface constructor takes.
16
+ - `PC_BASE_URL` — the per-surface prod base URLs, used as defaults.
17
+ - `makeClient<paths>(baseUrl, config)` — internal helper that wires an `openapi-fetch` client with the auth-header middleware.
18
+
19
+ ## When you'd touch it directly
20
+
21
+ Only if you're writing a new ProductCraft SDK surface package. Authoring custom backend integrations against ProductCraft APIs is what the per-product packages are for — start with one of those.
22
+
23
+ ## License
24
+
25
+ [MIT](https://github.com/clauderanelagh/productcraft-node/blob/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -9,10 +9,10 @@ var createClient__default = /*#__PURE__*/_interopDefault(createClient);
9
9
  // src/index.ts
10
10
  var PC_BASE_URL = {
11
11
  platformAuth: "https://api.auth.productcraft.co",
12
- heimdall: "https://api.heimdall.productcraft.co",
12
+ heimdall: "https://api.users.productcraft.co",
13
13
  envoi: "https://api.mail.productcraft.co",
14
- rally: "https://api.rally.productcraft.co",
15
- agora: "https://agora.productcraft.co"
14
+ rally: "https://api.waitlist.productcraft.co",
15
+ agora: "https://feed.productcraft.co"
16
16
  };
17
17
  function authMiddleware(auth) {
18
18
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["createClient"],"mappings":";;;;;;;;;AAyCO,IAAM,WAAA,GAAc;AAAA,EACzB,YAAA,EAAc,kCAAA;AAAA,EACd,QAAA,EAAU,sCAAA;AAAA,EACV,KAAA,EAAO,kCAAA;AAAA,EACP,KAAA,EAAO,mCAAA;AAAA,EACP,KAAA,EAAO;AACT;AAMO,SAAS,eAAe,IAAA,EAAsC;AACnE,EAAA,OAAO;AAAA,IACL,MAAM,SAAA,CAAU,EAAE,OAAA,EAAQ,EAAG;AAC3B,MAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,MAAA,QAAQ,KAAK,IAAA;AAAM,QACjB,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,GAAG,CAAA,CAAE,CAAA;AACzD,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAC3D,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,QAAA,EAAU,CAAA,WAAA,EAAc,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AACxD,UAAA;AAAA;AAEJ,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF;AAQO,SAAS,UAAA,CACd,cAAA,EACA,MAAA,GAAyB,EAAC,EACV;AAChB,EAAA,MAAM,SAASA,6BAAA,CAAqB;AAAA,IAClC,OAAA,EAAS,OAAO,OAAA,IAAW,cAAA;AAAA,IAC3B,OAAO,MAAA,CAAO;AAAA,GACf,CAAA;AACD,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,CAAe,MAAA,CAAO,IAAI,CAAC,CAAA;AACtC,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Shared transport + auth plumbing used by every surface client.\n *\n * Each surface package (`@productcraft/heimdall`, `@productcraft/envoi`,\n * ...) defines a thin class around `openapi-fetch` plus the generated\n * `paths` types from its own `_generated.d.ts`. The class delegates\n * wire I/O to `openapi-fetch`, but exposes a Stripe-style ergonomic\n * surface where callers reach for `pc.envoi.messages.send(...)` rather\n * than the underlying `client.POST(\"/v1/...\")` shape.\n *\n * v0 ships only the underlying `client` (named `client` on each\n * surface) — every endpoint is reachable through it. Ergonomic\n * resource surfaces land in v0.1+ as we hand-roll them.\n */\n\nimport createClient, { type Client, type Middleware } from \"openapi-fetch\";\n\n/**\n * The auth credential the SDK presents to ProductCraft APIs.\n *\n * - `apiKey` — Platform API Key (`pcft_live_*`). Server-side only;\n * never embed in a shipped browser bundle.\n * - `bearer` — pre-resolved JWT (e.g. a Heimdall app-scoped EndUser\n * token your backend minted and shipped to the device).\n * - `cookie` — captured `auth_token` cookie value. Mostly useful in\n * dev / E2E tests where you've already signed in.\n */\nexport type PCAuth =\n | { type: \"apiKey\"; key: string }\n | { type: \"bearer\"; token: string }\n | { type: \"cookie\"; value: string };\n\nexport interface PCClientConfig {\n auth?: PCAuth;\n /** Override the prod base URL — useful for dev / staging. */\n baseUrl?: string;\n /** Custom fetch (e.g. node-fetch with retries, undici, ...). */\n fetch?: typeof fetch;\n}\n\n/** Default prod base URL per surface. */\nexport const PC_BASE_URL = {\n platformAuth: \"https://api.auth.productcraft.co\",\n heimdall: \"https://api.heimdall.productcraft.co\",\n envoi: \"https://api.mail.productcraft.co\",\n rally: \"https://api.rally.productcraft.co\",\n agora: \"https://agora.productcraft.co\",\n} as const;\n\n/**\n * Build an `openapi-fetch` middleware that adds the configured auth\n * credential as a header on every outbound request.\n */\nexport function authMiddleware(auth: PCAuth | undefined): Middleware {\n return {\n async onRequest({ request }) {\n if (!auth) return undefined;\n switch (auth.type) {\n case \"apiKey\":\n request.headers.set(\"Authorization\", `Bearer ${auth.key}`);\n break;\n case \"bearer\":\n request.headers.set(\"Authorization\", `Bearer ${auth.token}`);\n break;\n case \"cookie\":\n request.headers.set(\"Cookie\", `auth_token=${auth.value}`);\n break;\n }\n return request;\n },\n };\n}\n\n/**\n * Construct an `openapi-fetch` client for a surface. Each surface\n * package calls this with its own generated `paths` type and default\n * base URL. The returned client is the v0 surface — every endpoint is\n * reachable through `client.GET(...)`, `client.POST(...)`, etc.\n */\nexport function makeClient<TPaths extends object>(\n defaultBaseUrl: string,\n config: PCClientConfig = {},\n): Client<TPaths> {\n const client = createClient<TPaths>({\n baseUrl: config.baseUrl ?? defaultBaseUrl,\n fetch: config.fetch,\n });\n client.use(authMiddleware(config.auth));\n return client;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["createClient"],"mappings":";;;;;;;;;AAiDO,IAAM,WAAA,GAAc;AAAA,EACzB,YAAA,EAAc,kCAAA;AAAA,EACd,QAAA,EAAU,mCAAA;AAAA,EACV,KAAA,EAAO,kCAAA;AAAA,EACP,KAAA,EAAO,sCAAA;AAAA,EACP,KAAA,EAAO;AACT;AAMO,SAAS,eAAe,IAAA,EAAsC;AACnE,EAAA,OAAO;AAAA,IACL,MAAM,SAAA,CAAU,EAAE,OAAA,EAAQ,EAAG;AAC3B,MAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,MAAA,QAAQ,KAAK,IAAA;AAAM,QACjB,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,GAAG,CAAA,CAAE,CAAA;AACzD,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAC3D,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,QAAA,EAAU,CAAA,WAAA,EAAc,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AACxD,UAAA;AAAA;AAEJ,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF;AAQO,SAAS,UAAA,CACd,cAAA,EACA,MAAA,GAAyB,EAAC,EACV;AAChB,EAAA,MAAM,SAASA,6BAAA,CAAqB;AAAA,IAClC,OAAA,EAAS,OAAO,OAAA,IAAW,cAAA;AAAA,IAC3B,OAAO,MAAA,CAAO;AAAA,GACf,CAAA;AACD,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,CAAe,MAAA,CAAO,IAAI,CAAC,CAAA;AACtC,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Shared transport + auth plumbing used by every surface client.\n *\n * Each surface package (`@productcraft/heimdall`, `@productcraft/envoi`,\n * ...) defines a thin class around `openapi-fetch` plus the generated\n * `paths` types from its own `_generated.d.ts`. The class delegates\n * wire I/O to `openapi-fetch`, but exposes a Stripe-style ergonomic\n * surface where callers reach for `pc.envoi.messages.send(...)` rather\n * than the underlying `client.POST(\"/v1/...\")` shape.\n *\n * v0 ships only the underlying `client` (named `client` on each\n * surface) — every endpoint is reachable through it. Ergonomic\n * resource surfaces land in v0.1+ as we hand-roll them.\n */\n\nimport createClient, { type Client, type Middleware } from \"openapi-fetch\";\n\n/**\n * The auth credential the SDK presents to ProductCraft APIs.\n *\n * - `apiKey` — Platform API Key (`pcft_live_*`). Server-side only;\n * never embed in a shipped browser bundle.\n * - `bearer` — pre-resolved JWT (e.g. a Heimdall app-scoped EndUser\n * token your backend minted and shipped to the device).\n * - `cookie` — captured `auth_token` cookie value. Mostly useful in\n * dev / E2E tests where you've already signed in.\n */\nexport type PCAuth =\n | { type: \"apiKey\"; key: string }\n | { type: \"bearer\"; token: string }\n | { type: \"cookie\"; value: string };\n\nexport interface PCClientConfig {\n auth?: PCAuth;\n /** Override the prod base URL — useful for dev / staging. */\n baseUrl?: string;\n /** Custom fetch (e.g. node-fetch with retries, undici, ...). */\n fetch?: typeof fetch;\n}\n\n/**\n * Default prod base URL per surface.\n *\n * Pointed at the renamed services (Rally→Waitlist, Agora→Feed,\n * Heimdall→users) so the SDK targets the canonical new domains and the\n * old aliases (api.rally, agora.*, api.heimdall) can eventually retire.\n * The surface KEYS (rally/agora/heimdall) are intentionally kept until\n * the v1.0.0 public-API rename, so this stays a non-breaking retarget.\n */\nexport const PC_BASE_URL = {\n platformAuth: \"https://api.auth.productcraft.co\",\n heimdall: \"https://api.users.productcraft.co\",\n envoi: \"https://api.mail.productcraft.co\",\n rally: \"https://api.waitlist.productcraft.co\",\n agora: \"https://feed.productcraft.co\",\n} as const;\n\n/**\n * Build an `openapi-fetch` middleware that adds the configured auth\n * credential as a header on every outbound request.\n */\nexport function authMiddleware(auth: PCAuth | undefined): Middleware {\n return {\n async onRequest({ request }) {\n if (!auth) return undefined;\n switch (auth.type) {\n case \"apiKey\":\n request.headers.set(\"Authorization\", `Bearer ${auth.key}`);\n break;\n case \"bearer\":\n request.headers.set(\"Authorization\", `Bearer ${auth.token}`);\n break;\n case \"cookie\":\n request.headers.set(\"Cookie\", `auth_token=${auth.value}`);\n break;\n }\n return request;\n },\n };\n}\n\n/**\n * Construct an `openapi-fetch` client for a surface. Each surface\n * package calls this with its own generated `paths` type and default\n * base URL. The returned client is the v0 surface — every endpoint is\n * reachable through `client.GET(...)`, `client.POST(...)`, etc.\n */\nexport function makeClient<TPaths extends object>(\n defaultBaseUrl: string,\n config: PCClientConfig = {},\n): Client<TPaths> {\n const client = createClient<TPaths>({\n baseUrl: config.baseUrl ?? defaultBaseUrl,\n fetch: config.fetch,\n });\n client.use(authMiddleware(config.auth));\n return client;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -42,13 +42,21 @@ interface PCClientConfig {
42
42
  /** Custom fetch (e.g. node-fetch with retries, undici, ...). */
43
43
  fetch?: typeof fetch;
44
44
  }
45
- /** Default prod base URL per surface. */
45
+ /**
46
+ * Default prod base URL per surface.
47
+ *
48
+ * Pointed at the renamed services (Rally→Waitlist, Agora→Feed,
49
+ * Heimdall→users) so the SDK targets the canonical new domains and the
50
+ * old aliases (api.rally, agora.*, api.heimdall) can eventually retire.
51
+ * The surface KEYS (rally/agora/heimdall) are intentionally kept until
52
+ * the v1.0.0 public-API rename, so this stays a non-breaking retarget.
53
+ */
46
54
  declare const PC_BASE_URL: {
47
55
  readonly platformAuth: "https://api.auth.productcraft.co";
48
- readonly heimdall: "https://api.heimdall.productcraft.co";
56
+ readonly heimdall: "https://api.users.productcraft.co";
49
57
  readonly envoi: "https://api.mail.productcraft.co";
50
- readonly rally: "https://api.rally.productcraft.co";
51
- readonly agora: "https://agora.productcraft.co";
58
+ readonly rally: "https://api.waitlist.productcraft.co";
59
+ readonly agora: "https://feed.productcraft.co";
52
60
  };
53
61
  /**
54
62
  * Build an `openapi-fetch` middleware that adds the configured auth
package/dist/index.d.ts CHANGED
@@ -42,13 +42,21 @@ interface PCClientConfig {
42
42
  /** Custom fetch (e.g. node-fetch with retries, undici, ...). */
43
43
  fetch?: typeof fetch;
44
44
  }
45
- /** Default prod base URL per surface. */
45
+ /**
46
+ * Default prod base URL per surface.
47
+ *
48
+ * Pointed at the renamed services (Rally→Waitlist, Agora→Feed,
49
+ * Heimdall→users) so the SDK targets the canonical new domains and the
50
+ * old aliases (api.rally, agora.*, api.heimdall) can eventually retire.
51
+ * The surface KEYS (rally/agora/heimdall) are intentionally kept until
52
+ * the v1.0.0 public-API rename, so this stays a non-breaking retarget.
53
+ */
46
54
  declare const PC_BASE_URL: {
47
55
  readonly platformAuth: "https://api.auth.productcraft.co";
48
- readonly heimdall: "https://api.heimdall.productcraft.co";
56
+ readonly heimdall: "https://api.users.productcraft.co";
49
57
  readonly envoi: "https://api.mail.productcraft.co";
50
- readonly rally: "https://api.rally.productcraft.co";
51
- readonly agora: "https://agora.productcraft.co";
58
+ readonly rally: "https://api.waitlist.productcraft.co";
59
+ readonly agora: "https://feed.productcraft.co";
52
60
  };
53
61
  /**
54
62
  * Build an `openapi-fetch` middleware that adds the configured auth
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@ import createClient from 'openapi-fetch';
3
3
  // src/index.ts
4
4
  var PC_BASE_URL = {
5
5
  platformAuth: "https://api.auth.productcraft.co",
6
- heimdall: "https://api.heimdall.productcraft.co",
6
+ heimdall: "https://api.users.productcraft.co",
7
7
  envoi: "https://api.mail.productcraft.co",
8
- rally: "https://api.rally.productcraft.co",
9
- agora: "https://agora.productcraft.co"
8
+ rally: "https://api.waitlist.productcraft.co",
9
+ agora: "https://feed.productcraft.co"
10
10
  };
11
11
  function authMiddleware(auth) {
12
12
  return {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAyCO,IAAM,WAAA,GAAc;AAAA,EACzB,YAAA,EAAc,kCAAA;AAAA,EACd,QAAA,EAAU,sCAAA;AAAA,EACV,KAAA,EAAO,kCAAA;AAAA,EACP,KAAA,EAAO,mCAAA;AAAA,EACP,KAAA,EAAO;AACT;AAMO,SAAS,eAAe,IAAA,EAAsC;AACnE,EAAA,OAAO;AAAA,IACL,MAAM,SAAA,CAAU,EAAE,OAAA,EAAQ,EAAG;AAC3B,MAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,MAAA,QAAQ,KAAK,IAAA;AAAM,QACjB,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,GAAG,CAAA,CAAE,CAAA;AACzD,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAC3D,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,QAAA,EAAU,CAAA,WAAA,EAAc,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AACxD,UAAA;AAAA;AAEJ,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF;AAQO,SAAS,UAAA,CACd,cAAA,EACA,MAAA,GAAyB,EAAC,EACV;AAChB,EAAA,MAAM,SAAS,YAAA,CAAqB;AAAA,IAClC,OAAA,EAAS,OAAO,OAAA,IAAW,cAAA;AAAA,IAC3B,OAAO,MAAA,CAAO;AAAA,GACf,CAAA;AACD,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,CAAe,MAAA,CAAO,IAAI,CAAC,CAAA;AACtC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * Shared transport + auth plumbing used by every surface client.\n *\n * Each surface package (`@productcraft/heimdall`, `@productcraft/envoi`,\n * ...) defines a thin class around `openapi-fetch` plus the generated\n * `paths` types from its own `_generated.d.ts`. The class delegates\n * wire I/O to `openapi-fetch`, but exposes a Stripe-style ergonomic\n * surface where callers reach for `pc.envoi.messages.send(...)` rather\n * than the underlying `client.POST(\"/v1/...\")` shape.\n *\n * v0 ships only the underlying `client` (named `client` on each\n * surface) — every endpoint is reachable through it. Ergonomic\n * resource surfaces land in v0.1+ as we hand-roll them.\n */\n\nimport createClient, { type Client, type Middleware } from \"openapi-fetch\";\n\n/**\n * The auth credential the SDK presents to ProductCraft APIs.\n *\n * - `apiKey` — Platform API Key (`pcft_live_*`). Server-side only;\n * never embed in a shipped browser bundle.\n * - `bearer` — pre-resolved JWT (e.g. a Heimdall app-scoped EndUser\n * token your backend minted and shipped to the device).\n * - `cookie` — captured `auth_token` cookie value. Mostly useful in\n * dev / E2E tests where you've already signed in.\n */\nexport type PCAuth =\n | { type: \"apiKey\"; key: string }\n | { type: \"bearer\"; token: string }\n | { type: \"cookie\"; value: string };\n\nexport interface PCClientConfig {\n auth?: PCAuth;\n /** Override the prod base URL — useful for dev / staging. */\n baseUrl?: string;\n /** Custom fetch (e.g. node-fetch with retries, undici, ...). */\n fetch?: typeof fetch;\n}\n\n/** Default prod base URL per surface. */\nexport const PC_BASE_URL = {\n platformAuth: \"https://api.auth.productcraft.co\",\n heimdall: \"https://api.heimdall.productcraft.co\",\n envoi: \"https://api.mail.productcraft.co\",\n rally: \"https://api.rally.productcraft.co\",\n agora: \"https://agora.productcraft.co\",\n} as const;\n\n/**\n * Build an `openapi-fetch` middleware that adds the configured auth\n * credential as a header on every outbound request.\n */\nexport function authMiddleware(auth: PCAuth | undefined): Middleware {\n return {\n async onRequest({ request }) {\n if (!auth) return undefined;\n switch (auth.type) {\n case \"apiKey\":\n request.headers.set(\"Authorization\", `Bearer ${auth.key}`);\n break;\n case \"bearer\":\n request.headers.set(\"Authorization\", `Bearer ${auth.token}`);\n break;\n case \"cookie\":\n request.headers.set(\"Cookie\", `auth_token=${auth.value}`);\n break;\n }\n return request;\n },\n };\n}\n\n/**\n * Construct an `openapi-fetch` client for a surface. Each surface\n * package calls this with its own generated `paths` type and default\n * base URL. The returned client is the v0 surface — every endpoint is\n * reachable through `client.GET(...)`, `client.POST(...)`, etc.\n */\nexport function makeClient<TPaths extends object>(\n defaultBaseUrl: string,\n config: PCClientConfig = {},\n): Client<TPaths> {\n const client = createClient<TPaths>({\n baseUrl: config.baseUrl ?? defaultBaseUrl,\n fetch: config.fetch,\n });\n client.use(authMiddleware(config.auth));\n return client;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAiDO,IAAM,WAAA,GAAc;AAAA,EACzB,YAAA,EAAc,kCAAA;AAAA,EACd,QAAA,EAAU,mCAAA;AAAA,EACV,KAAA,EAAO,kCAAA;AAAA,EACP,KAAA,EAAO,sCAAA;AAAA,EACP,KAAA,EAAO;AACT;AAMO,SAAS,eAAe,IAAA,EAAsC;AACnE,EAAA,OAAO;AAAA,IACL,MAAM,SAAA,CAAU,EAAE,OAAA,EAAQ,EAAG;AAC3B,MAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,MAAA,QAAQ,KAAK,IAAA;AAAM,QACjB,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,GAAG,CAAA,CAAE,CAAA;AACzD,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAC3D,UAAA;AAAA,QACF,KAAK,QAAA;AACH,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,QAAA,EAAU,CAAA,WAAA,EAAc,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AACxD,UAAA;AAAA;AAEJ,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF;AAQO,SAAS,UAAA,CACd,cAAA,EACA,MAAA,GAAyB,EAAC,EACV;AAChB,EAAA,MAAM,SAAS,YAAA,CAAqB;AAAA,IAClC,OAAA,EAAS,OAAO,OAAA,IAAW,cAAA;AAAA,IAC3B,OAAO,MAAA,CAAO;AAAA,GACf,CAAA;AACD,EAAA,MAAA,CAAO,GAAA,CAAI,cAAA,CAAe,MAAA,CAAO,IAAI,CAAC,CAAA;AACtC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * Shared transport + auth plumbing used by every surface client.\n *\n * Each surface package (`@productcraft/heimdall`, `@productcraft/envoi`,\n * ...) defines a thin class around `openapi-fetch` plus the generated\n * `paths` types from its own `_generated.d.ts`. The class delegates\n * wire I/O to `openapi-fetch`, but exposes a Stripe-style ergonomic\n * surface where callers reach for `pc.envoi.messages.send(...)` rather\n * than the underlying `client.POST(\"/v1/...\")` shape.\n *\n * v0 ships only the underlying `client` (named `client` on each\n * surface) — every endpoint is reachable through it. Ergonomic\n * resource surfaces land in v0.1+ as we hand-roll them.\n */\n\nimport createClient, { type Client, type Middleware } from \"openapi-fetch\";\n\n/**\n * The auth credential the SDK presents to ProductCraft APIs.\n *\n * - `apiKey` — Platform API Key (`pcft_live_*`). Server-side only;\n * never embed in a shipped browser bundle.\n * - `bearer` — pre-resolved JWT (e.g. a Heimdall app-scoped EndUser\n * token your backend minted and shipped to the device).\n * - `cookie` — captured `auth_token` cookie value. Mostly useful in\n * dev / E2E tests where you've already signed in.\n */\nexport type PCAuth =\n | { type: \"apiKey\"; key: string }\n | { type: \"bearer\"; token: string }\n | { type: \"cookie\"; value: string };\n\nexport interface PCClientConfig {\n auth?: PCAuth;\n /** Override the prod base URL — useful for dev / staging. */\n baseUrl?: string;\n /** Custom fetch (e.g. node-fetch with retries, undici, ...). */\n fetch?: typeof fetch;\n}\n\n/**\n * Default prod base URL per surface.\n *\n * Pointed at the renamed services (Rally→Waitlist, Agora→Feed,\n * Heimdall→users) so the SDK targets the canonical new domains and the\n * old aliases (api.rally, agora.*, api.heimdall) can eventually retire.\n * The surface KEYS (rally/agora/heimdall) are intentionally kept until\n * the v1.0.0 public-API rename, so this stays a non-breaking retarget.\n */\nexport const PC_BASE_URL = {\n platformAuth: \"https://api.auth.productcraft.co\",\n heimdall: \"https://api.users.productcraft.co\",\n envoi: \"https://api.mail.productcraft.co\",\n rally: \"https://api.waitlist.productcraft.co\",\n agora: \"https://feed.productcraft.co\",\n} as const;\n\n/**\n * Build an `openapi-fetch` middleware that adds the configured auth\n * credential as a header on every outbound request.\n */\nexport function authMiddleware(auth: PCAuth | undefined): Middleware {\n return {\n async onRequest({ request }) {\n if (!auth) return undefined;\n switch (auth.type) {\n case \"apiKey\":\n request.headers.set(\"Authorization\", `Bearer ${auth.key}`);\n break;\n case \"bearer\":\n request.headers.set(\"Authorization\", `Bearer ${auth.token}`);\n break;\n case \"cookie\":\n request.headers.set(\"Cookie\", `auth_token=${auth.value}`);\n break;\n }\n return request;\n },\n };\n}\n\n/**\n * Construct an `openapi-fetch` client for a surface. Each surface\n * package calls this with its own generated `paths` type and default\n * base URL. The returned client is the v0 surface — every endpoint is\n * reachable through `client.GET(...)`, `client.POST(...)`, etc.\n */\nexport function makeClient<TPaths extends object>(\n defaultBaseUrl: string,\n config: PCClientConfig = {},\n): Client<TPaths> {\n const client = createClient<TPaths>({\n baseUrl: config.baseUrl ?? defaultBaseUrl,\n fetch: config.fetch,\n });\n client.use(authMiddleware(config.auth));\n return client;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@productcraft/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Shared transport, auth, and config primitives for the ProductCraft SDKs. Depended on by every per-surface package.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",