@picked/delivery-api-client 0.0.97-next.2 → 0.0.97-next.3
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/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`Picked-Client`,t=`Picked-Version`;function n(n,r){return{[e]:n,[t]:r}}function r(){return`0.0.97-next.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`Picked-Client`,t=`Picked-Version`;function n(n,r){return{[e]:n,[t]:r}}function r(){return`0.0.97-next.3`}var i=`v1`,a=1e4;function o(e,t){let n=AbortSignal.timeout(t);return e?AbortSignal.any([e,n]):n}function s(e,t){return new URL(`/api/${i}/${t}`,e).toString()}function c(e,t){return{...n(e,r()),...t}}async function l(e,t,n,r,i,l=a){let u=s(e,t);return fetch(u,{headers:c(n,r),signal:o(i,l)})}async function u(e,t,n,r,i,l){let u=s(e,t);return fetch(u,{method:`POST`,headers:{"Content-Type":`application/json`,...c(r,i)},body:JSON.stringify(n),signal:o(l,a)})}function d(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function f(e){if(typeof e!=`object`||!e||!(`cause`in e))return!1;let{cause:t}=e;return typeof t!=`object`||!t||!(`code`in t)?!1:t.code===`ECONNREFUSED`}function p(e,t,n){e?.onWarn?.(t,n)}async function m(e){try{let t=await e.json();if(typeof t==`object`&&t&&`error`in t){let{error:e}=t;return typeof e==`string`&&e.length>0?e:null}}catch{return null}return null}async function h(e){let{apiUrl:t,path:n,options:r,failureMessage:i,parseFailureMessage:a,invalidShapeMessage:o,isValid:s}=e,c;try{c=await l(t,n,`sdk`,r?.headers,r?.signal)}catch(e){return d(t)&&f(e)||p(r,i,e),null}if(r?.onResponse?.(c.status),!c.ok){let e=await m(c),t=`status ${c.status.toString()}`;return p(r,`${i} (${e===null?t:`${t}: ${e}`})`),null}let u;try{u=await c.json()}catch{return p(r,a),null}return s(u)?u:(p(r,o),null)}function g(e){if(typeof e!=`object`||!e||!(`$defs`in e)||!(`x-picked-step-content-models`in e))return!1;let t=e.$defs;return typeof t!=`object`||!t?!1:`contentModels`in t}function _(e){return typeof e==`object`&&!!e&&`features`in e&&Array.isArray(e.features)}function v(e){return typeof e!=`object`||!e||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}async function y(e,t,n){return h({apiUrl:e,path:n?.previewToken?`projects/${t}?preview_token=${encodeURIComponent(n.previewToken)}`:`projects/${t}`,options:n,failureMessage:`Failed to fetch project config`,parseFailureMessage:`Failed to parse project config response`,invalidShapeMessage:`Invalid project config response shape`,isValid:_})}async function b(e,t,n,r){return h({apiUrl:e,path:r?.previewToken?`projects/${t}/experiences/${n}/content?preview_token=${encodeURIComponent(r.previewToken)}`:`projects/${t}/experiences/${n}/content`,options:r,failureMessage:`Failed to fetch experience content for ${n}`,parseFailureMessage:`Failed to parse experience content response for ${n}`,invalidShapeMessage:`Invalid experience content response shape for ${n}`,isValid:v})}async function x(e,t,n){return h({apiUrl:e,path:n?.previewToken?`projects/${t}/schema?preview_token=${encodeURIComponent(n.previewToken)}`:`projects/${t}/schema`,options:n,failureMessage:`Failed to fetch workspace schema`,parseFailureMessage:`Failed to parse schema response`,invalidShapeMessage:`Invalid schema response shape`,isValid:g})}var S=[`succeeded`,`pending`,`no_response`];async function C(e,t,n){let{key:r,...i}=t,a=`action/${encodeURIComponent(r)}/run`,o=await u(e,n?.previewToken?`${a}?preview_token=${encodeURIComponent(n.previewToken)}`:a,i,`sdk`,n?.headers,n?.signal);if(!o.ok)throw Error(`Action '${t.key}' failed: ${o.status} ${o.statusText}`);let s=await o.json();if(typeof s!=`object`||!s)return{actionRunId:``,workflowRunId:null,status:`no_response`};let c=`actionRunId`in s?String(s.actionRunId):``,l=`workflowRunId`in s&&typeof s.workflowRunId==`string`?s.workflowRunId:null,d=S.find(e=>`status`in s&&e===s.status)??`no_response`;return d===`succeeded`&&`response`in s?{actionRunId:c,workflowRunId:l,status:d,response:s.response}:{actionRunId:c,workflowRunId:l,status:d}}var w=35e3,T=1e3,E=3e4,D=14,O=36e5,k=class extends Error{workflowRunId;constructor(e){super(`No response from run '${e}' within the time allowed`),this.workflowRunId=e,this.name=`ActionResponseTimeoutError`}},A=class extends Error{workflowRunId;constructor(e){super(`Run '${e}' failed before it responded`),this.workflowRunId=e,this.name=`ActionRunFailedError`}};async function j(e,t,n,r){let i=new URLSearchParams({projectId:t.projectId,session:t.sessionId}),a=`action/run/${encodeURIComponent(t.workflowRunId)}/response?${i.toString()}`,o;try{o=await l(e,a,`sdk`,r?.headers,r?.signal,n)}catch(e){if(r?.signal?.aborted)throw e;return{kind:`retry`,error:e instanceof Error?e:Error(String(e))}}if(!o.ok){let e=Error(`Action response for '${t.workflowRunId}' failed: ${o.status} ${o.statusText}`);if(o.status>=500)return{kind:`retry`,error:e};throw e}let s=await o.json().catch(e=>{if(r?.signal?.aborted)throw e;return null}),c=typeof s==`object`&&!!s;switch(c&&`status`in s?s.status:void 0){case`succeeded`:return{kind:`settled`,result:{status:`succeeded`,response:c&&`response`in s?s.response:null}};case`no_response`:return{kind:`settled`,result:{status:`no_response`}};case`failed`:return{kind:`failed`};case`pending`:return{kind:`pending`};default:return{kind:`retry`,error:Error(`Action response for '${t.workflowRunId}' could not be read`)}}}function M(e,t){return new Promise(n=>{let r=()=>{t?.removeEventListener(`abort`,r),n()};setTimeout(r,e),t?.addEventListener(`abort`,r,{once:!0})})}async function N(e,t,n){let r=n?.signal,i=Date.now()+(n?.timeoutMs??36e5),a=0;for(;Date.now()<i;){r?.throwIfAborted();let o=await j(e,t,Math.max(1,Math.min(w,i-Date.now())),n);if(o.kind===`settled`)return o.result;if(o.kind===`failed`)throw new A(t.workflowRunId);if(o.kind===`pending`){a=0;continue}if(a+=1,a>D)throw o.error;r?.throwIfAborted();let s=Math.min(T*2**(a-1),E);await M(Math.max(0,Math.min(s,i-Date.now())),r),r?.throwIfAborted()}throw new k(t.workflowRunId)}exports.ActionResponseTimeoutError=k,exports.ActionRunFailedError=A,exports.DEFAULT_ACTION_RESPONSE_TIMEOUT_MS=O,exports.createClientHeaders=n,exports.fetchExperienceContent=b,exports.fetchProject=y,exports.fetchSchema=x,exports.getPackageVersion=r,exports.isWorkspaceSchema=g,exports.runAction=C,exports.waitForActionResponse=N;
|
package/dist/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/delivery-api-client",
|
|
3
3
|
"description": "Browser-safe Picked delivery API client for project config, experience content, and workspace schema",
|
|
4
|
-
"version": "0.0.97-next.
|
|
4
|
+
"version": "0.0.97-next.3",
|
|
5
5
|
"dependencies": {},
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@repo/eslint-config": "workspace:*",
|