palbase 0.18.6 → 0.19.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 (53) hide show
  1. package/README.md +14 -0
  2. package/dist/ai/index.js +2 -2
  3. package/dist/backend/engine.js +2 -2
  4. package/dist/backend/env.js +1 -1
  5. package/dist/backend/index.js +3 -3
  6. package/dist/backend/stack.js +1 -1
  7. package/dist/backend/test.js +2 -2
  8. package/dist/chunks/{L4SDE4IC.js → 26R7KNH7.js} +2 -2
  9. package/dist/chunks/{S76H65KW.js → 2XM3DQXS.js} +2 -2
  10. package/dist/chunks/{E4CPOSFA.js → 424IEUQX.js} +2 -2
  11. package/dist/chunks/{NIDBDL7O.js → 43RXGTTL.js} +1 -1
  12. package/dist/chunks/{OL33SRTB.js → B6OLQP6W.js} +2 -2
  13. package/dist/chunks/{U6UXSVEZ.js → EDIQ4SAO.js} +2 -2
  14. package/dist/chunks/{6HESVOSN.js → F5CWCOSS.js} +1 -1
  15. package/dist/chunks/{6IHNI2FC.js → HM7G4WGJ.js} +2 -2
  16. package/dist/chunks/{7HE22VDH.js → KE4DEYSH.js} +1 -1
  17. package/dist/chunks/{Y76SPW2M.js → LCBMI6UP.js} +1 -1
  18. package/dist/chunks/{OGP5DLL6.js → LRWWDIJZ.js} +2 -2
  19. package/dist/chunks/{C53PUTQR.js → MI3PAKT3.js} +2 -2
  20. package/dist/chunks/{BDD3FVHP.js → PRIISRPI.js} +2 -2
  21. package/dist/chunks/{Q2O72MGS.js → QOUBSZM4.js} +1 -1
  22. package/dist/chunks/{U4R3KQT6.js → RIQJUVZK.js} +1 -1
  23. package/dist/chunks/{RUE6N2T6.js → SGASB5G4.js} +2 -2
  24. package/dist/chunks/{6JA355QW.js → TOPRHPT6.js} +1 -1
  25. package/dist/chunks/{ARDQJVIP.js → V2GWROU3.js} +2 -2
  26. package/dist/chunks/{RHLHSALC.js → V6TFL4HC.js} +2 -2
  27. package/dist/chunks/{5N36M3Y3.js → WHKAPZX7.js} +2 -2
  28. package/dist/chunks/{4HYASQT5.js → Y4THIE6E.js} +2 -2
  29. package/dist/chunks/Z4YKS2EK.js +2 -0
  30. package/dist/chunks/{IO3G5VIC.js → ZW57VOIW.js} +2 -2
  31. package/dist/cli.js +3 -3
  32. package/dist/cloud/index.js +2 -0
  33. package/dist/refuse/ai.js +1 -1
  34. package/dist/refuse/backend.js +1 -1
  35. package/dist/refuse/cloud.js +2 -0
  36. package/dist/refuse/server.js +1 -1
  37. package/dist/server/index.js +2 -2
  38. package/dist/server/testing.js +2 -2
  39. package/dist/web/index.js +2 -2
  40. package/dist/web/message.js +2 -2
  41. package/dist/web/palbe.js +2 -2
  42. package/dist/web/paywall.js +2 -2
  43. package/dist/web/push-sw.js +1 -1
  44. package/dist/web/ssr.js +2 -2
  45. package/dist/web/vite.js +2 -2
  46. package/package.json +18 -4
  47. package/types/cloud/src/cloud.d.ts +23 -0
  48. package/types/cloud/src/generated/project.d.ts +19 -0
  49. package/types/cloud/src/generated/studio.d.ts +1765 -0
  50. package/types/cloud/src/index.d.ts +7 -0
  51. package/types/cloud/src/token.d.ts +6 -0
  52. package/types/internal/src/transport.d.ts +10 -1
  53. package/dist/chunks/RGZZCQMZ.js +0 -2
@@ -0,0 +1,7 @@
1
+ export { PalbaseCloud, DEFAULT_DOMAIN, type CloudOptions } from './cloud.js';
2
+ export { tokenIsWellFormed } from './token.js';
3
+ export type { Project } from './generated/project.js';
4
+ export type { Client as Studio } from './generated/studio.js';
5
+ export { PalbaseError } from '../../internal/src/transport.js';
6
+ export type { RetryPolicy } from '../../internal/src/retry.js';
7
+ export type * as types from '../../internal/src/modules/index.js';
@@ -0,0 +1,6 @@
1
+ /** What is wrong with `token` as an access token, or undefined when it is well formed. The token itself is never in it. */
2
+ export declare function tokenProblem(token: unknown): string | undefined;
3
+ /** Whether `token` is an access token as Palbase makes one: its prefix, its length and its checksum. Nothing is sent. */
4
+ export declare function tokenIsWellFormed(token: unknown): token is string;
5
+ /** Throws a TypeError naming what is wrong with `token` (never the token). */
6
+ export declare function checkToken(token: unknown): asserts token is string;
@@ -1,4 +1,4 @@
1
- export type Scheme = 'ApiKeyAuth' | 'SecretKeyAuth' | 'AdminAuth' | 'userJWT' | 'OAuthClient' | 'OAuthAccessToken';
1
+ export type Scheme = 'ApiKeyAuth' | 'SecretKeyAuth' | 'AdminAuth' | 'userJWT' | 'OAuthClient' | 'OAuthAccessToken' | 'PalbaseBearer';
2
2
  export interface Credentials {
3
3
  /** pb_<ref>_c…: ships in apps. */
4
4
  publishableKey?: string;
@@ -6,6 +6,13 @@ export interface Credentials {
6
6
  secretKey?: string;
7
7
  /** The signed-in user's access token, asked for on every call that takes one. */
8
8
  accessToken?: () => string | undefined | Promise<string | undefined>;
9
+ /**
10
+ * An access token of an organization (pbo_…) or an environment (pbe_…):
11
+ * servers only. It stands where a server's credential does — the secret
12
+ * key's AdminAuth and SecretKeyAuth, Studio's PalbaseBearer — and goes as
13
+ * Authorization: Bearer, with no apikey.
14
+ */
15
+ token?: string;
9
16
  }
10
17
  export type AnswerKind = 'json' | 'empty' | 'raw' | 'redirect';
11
18
  export interface CallSpec {
@@ -23,6 +30,8 @@ export interface CallSpec {
23
30
  };
24
31
  /** The contract takes an Idempotency-Key on this write. */
25
32
  idempotent?: boolean;
33
+ /** The handler answers with its own Response (the contract declares no answer but its default): any 2xx is the answer, read as it is. */
34
+ ownResponse?: boolean;
26
35
  signal?: AbortSignal;
27
36
  /** The request outlives the page that sends it (fetch keepalive: 64 KiB of body at most) — what a page sends as it closes. */
28
37
  keepalive?: boolean;
@@ -1,2 +0,0 @@
1
- /*! palbase 0.18.6 — Palbase SDK License (see LICENSE) */
2
- import{a as g,b}from"./NIDBDL7O.js";var A=Symbol.for("palbase.data"),T=globalThis,m=T[A]??=new WeakSet;function S(t){return t instanceof Date||ArrayBuffer.isView(t)||t instanceof ArrayBuffer}function k(t){let e=[t];for(;e.length>0;){let n=e.pop();if(!(typeof n!="object"||n===null||m.has(n)||S(n))){m.add(n);for(let a of Array.isArray(n)?n:Object.values(n))e.push(a)}}return t}var l=class extends Error{status;code;requestId;retryAfter;body;op;get isNetworkError(){return this.code==="network_error"}constructor(e){super(e.message,e.cause===void 0?void 0:{cause:e.cause}),this.name="PalbaseError",this.op=e.op,this.status=e.status,this.code=e.code,this.requestId=e.requestId,this.retryAfter=e.retryAfter,this.body=e.body}};function C(t,e,n){let a=String(n);if(a===""||a==="."||a==="..")throw new l({op:t,status:0,code:"invalid_path_parameter",message:`${t}: ${e} cannot be ${a===""?"empty":JSON.stringify(a)}`});return encodeURIComponent(a)}var x=new Set(["apikey","authorization"]),q=64*1024;function W(t){let e=E(t.baseUrl),n=t.fetch??globalThis.fetch,a=t.solveProofOfWork??!0,u=async(r,o)=>{let d=v(e,r),s=new Headers;for(let[h,y]of Object.entries(r.headers??{}))y!=null&&!x.has(h.toLowerCase())&&s.set(h,String(y));for(let[h,y]of Object.entries(o))s.set(h,y);await j(r,t.credentials,s),s.has("accept")||s.set("accept","application/json");let f={method:r.method,headers:s,redirect:"manual",signal:r.signal,...r.keepalive?{keepalive:!0}:{}};r.body&&r.body.value!==void 0&&(s.set("content-type",r.body.contentType),f.body=L(r.body.kind,r.body.value),R(f.body)||(f.duplex="half"));let i;try{i=r.onUploadProgress&&t.xmlHttpRequest?await U(t.xmlHttpRequest,r.op,d,f,r.onUploadProgress):await n(d,f)}catch(h){throw r.signal?.aborted||h instanceof l?h:new l({op:r.op,status:0,code:"network_error",message:`${r.op}: the request did not reach ${e.origin}`,cause:h})}let c=r.answers[i.status];if(c===void 0)throw i.status>=200&&i.status<300?(await i.body?.cancel(),new l({op:r.op,status:i.status,code:"undeclared_answer",message:`${r.op}: the server answered ${i.status}, which its contract does not declare; the request may have taken effect`})):await P(r.op,i);let p;switch(c){case"json":try{p=k(await i.json())}catch(h){throw new l({op:r.op,status:i.status,code:"invalid_json",message:`${r.op}: the answer is not JSON`,cause:h})}break;case"raw":p=i;break;default:await i.body?.cancel(),p=void 0}return{status:i.status,data:p,headers:i.headers}};return{async send(r){try{return await u(r,{})}catch(o){let d=a&&o instanceof l&&o.status===403?g(o.body):null,s=r.body?.value;if(!d||r.body?.kind==="raw"&&!R(s))throw o;let f=o,i;try{i=await b(d,{signal:r.signal})}catch(c){throw r.signal?.aborted?c:new l({op:r.op,status:403,code:"pow_unsolved",message:`${r.op}: ${c instanceof Error?c.message:String(c)}`,requestId:f.requestId,body:f.body,cause:c})}return u(r,i)}}}}function U(t,e,n,a,u){return new Promise((r,o)=>{let d=a.signal;if(d?.aborted)return o(d.reason);let s=new t,f=()=>s.abort();d?.addEventListener("abort",f,{once:!0});let i=c=>{d?.removeEventListener("abort",f),c()};s.open(a.method??"GET",n.href),s.responseType="arraybuffer",new Headers(a.headers).forEach((c,p)=>s.setRequestHeader(p,c)),s.upload&&(s.upload.onprogress=c=>{c.lengthComputable&&u(c.loaded,c.total)}),s.onload=()=>i(()=>{if(s.responseURL!==""&&s.responseURL!==n.href){o(new l({op:e,status:0,code:"undeclared_redirect",message:`${e}: the server redirected; the answer is another address's, and was not read`}));return}if(s.status<200||s.status>599)return o(new TypeError(`${e}: answered ${s.status}`));let c=s.status===204||s.status===205||s.status===304;r(new Response(c?null:s.response,{status:s.status,statusText:s.statusText,headers:$(s.getAllResponseHeaders())}))}),s.onerror=()=>i(()=>o(new TypeError(`${e}: the request failed`))),s.onabort=()=>i(()=>o(d?.reason??new DOMException("The request was aborted","AbortError"))),s.send(a.body)})}function $(t){let e=new Headers;for(let n of t.split(/\r?\n/)){let a=n.indexOf(":");if(!(a<=0))try{e.append(n.slice(0,a).trim(),n.slice(a+1).trim())}catch{}}return e}function E(t){let e;try{e=new URL(t)}catch{throw new TypeError(`baseUrl ${JSON.stringify(t)} is not an absolute URL`)}let n=e.hostname==="localhost"||e.hostname.endsWith(".localhost")||e.hostname==="127.0.0.1"||e.hostname==="[::1]";if(e.protocol!=="https:"&&!(e.protocol==="http:"&&n))throw new TypeError(`baseUrl must be https (http only for a loopback address): ${e.origin}`);if(e.username||e.password||e.search||e.hash)throw new TypeError("baseUrl carries no user, query or fragment");if(e.pathname!=="/"&&e.pathname!=="")throw new TypeError("baseUrl is the project origin alone, with no path");return e}function v(t,e){if(!e.path.startsWith("/")||e.path.startsWith("//"))throw new l({op:e.op,status:0,code:"invalid_path",message:`${e.op}: path ${JSON.stringify(e.path)} is not absolute`});let n=new URL(e.path+O(e.query),t);if(n.origin!==t.origin)throw new l({op:e.op,status:0,code:"invalid_path",message:`${e.op}: path leaves the project's origin`});return n}async function j(t,e,n){if(t.auth.length===0)return;let a=t.auth.some(o=>o.includes("userJWT"))?await e.accessToken?.():void 0,u=o=>{switch(o){case"ApiKeyAuth":return!!(e.publishableKey??e.secretKey);case"SecretKeyAuth":case"AdminAuth":return!!e.secretKey;case"userJWT":return!!a;default:return!1}},r=t.auth.filter(o=>o.every(u)).reduce((o,d)=>o===void 0||d.length>o.length?d:o,void 0);if(!r)throw new l({op:t.op,status:0,code:"missing_credential",message:`${t.op} needs one of: ${t.auth.map(o=>o.length===0?"nothing":o.join(" + ")).join(" | ")}`});for(let o of r)o==="ApiKeyAuth"?n.set("apikey",e.publishableKey??e.secretKey):o==="SecretKeyAuth"||o==="AdminAuth"?n.set("apikey",e.secretKey):o==="userJWT"&&n.set("authorization",`Bearer ${a}`)}function L(t,e){switch(t){case"json":return JSON.stringify(e);case"form":{let n=new URLSearchParams;for(let[a,u]of Object.entries(e))w(n,a,u);return n}case"raw":return e}}function R(t){return!!(t==null||typeof t=="string"||t instanceof URLSearchParams||t instanceof Blob||t instanceof FormData||t instanceof ArrayBuffer||ArrayBuffer.isView(t))}function O(t){if(!t)return"";let e=new URLSearchParams;for(let[a,u]of Object.entries(t))w(e,a,u);let n=e.toString();return n===""?"":`?${n}`}function w(t,e,n){if(n!=null){if(Array.isArray(n)){for(let a of n)w(t,e,a);return}if(n instanceof Date){t.append(e,n.toISOString());return}t.append(e,typeof n=="object"?JSON.stringify(n):String(n))}}async function P(t,e){let n=await _(e,q).catch(()=>""),a;try{a=n===""?void 0:JSON.parse(n)}catch{a=n}let u=B(a)?a:void 0,r=Number(e.headers.get("retry-after")),o=e.status>=300&&e.status<400;return new l({op:t,status:e.status,code:u?.error??(o?"undeclared_redirect":`http_${e.status}`),message:u?.error_description??(o?`${t}: the server redirected (${e.status}); the request was not followed, its credentials stay here`:`${t}: ${e.status} ${e.statusText}`.trim()),requestId:u?.request_id??e.headers.get("x-request-id")??void 0,retryAfter:u?.retry_after??(Number.isFinite(r)&&r>0?r:void 0),body:a})}async function _(t,e){if(!t.body)return"";let n=t.body.getReader(),a=[],u=0;for(;u<e;){let{done:d,value:s}=await n.read();if(d)break;a.push(s),u+=s.byteLength}await n.cancel().catch(()=>{});let r=new Uint8Array(Math.min(u,e)),o=0;for(let d of a){let s=Math.min(d.byteLength,r.byteLength-o);if(r.set(d.subarray(0,s),o),o+=s,o>=r.byteLength)break}return new TextDecoder().decode(r)}function B(t){return typeof t=="object"&&t!==null&&typeof t.error=="string"}export{k as a,l as b,C as c,W as d,E as e,R as f};