@ionite/devtools 0.0.24-beta.20260917.4 → 0.0.24-beta.20260918.6
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/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -107,13 +107,13 @@ declare function completeLoginFlow(config: OidcLoginConfig, fetch: PathFetch): P
|
|
|
107
107
|
error?: string;
|
|
108
108
|
}>;
|
|
109
109
|
type TenantProvisioningProfile = "tenantManager" | "creation";
|
|
110
|
-
type
|
|
110
|
+
type TenantManagementControl = {
|
|
111
111
|
configLocator: unknown;
|
|
112
112
|
getTenantManagementToken(): Promise<string>;
|
|
113
113
|
webhookUrl?: string;
|
|
114
114
|
};
|
|
115
115
|
type ProvisionTenantOptions = {
|
|
116
|
-
control:
|
|
116
|
+
control: TenantManagementControl;
|
|
117
117
|
/** Root Tenant Management App URL. */
|
|
118
118
|
baseUrl: string;
|
|
119
119
|
/** @default "/api/tenants" */
|
|
@@ -318,4 +318,4 @@ type SeededWorkforce = {
|
|
|
318
318
|
* duplicating them.
|
|
319
319
|
*/
|
|
320
320
|
declare function seedWorkforce(options: SeedWorkforceOptions): Promise<SeededWorkforce>;
|
|
321
|
-
export { AppUnderTest, DevControlModule, DevIntegrationIntent, DevProductRegistration,
|
|
321
|
+
export { AppUnderTest, DevControlModule, DevIntegrationIntent, DevProductRegistration, FetchLike, HttpSession, IoniteTenantSelection, LinkAppToIoniteOptions, LinkedIoniteTenant, OidcLoginConfig, PathFetch, ProvisionTenantOptions, ProvisionedTenant, RegisteredDevProduct, RequestJsonOptions, SeedAppOwnerOptions, SeedIoniteTenantOptions, SeedWorkforceOptions, SeededAppOwner, SeededIoniteTenant, SeededWorkforce, StartAppOptions, TenantManagementControl, TenantProvisioningProfile, WaitForReadyOptions, WorkforceFixtureV1, WorkforceGroupFixture, WorkforceMembershipFixture, WorkforceUserFixture, completeLoginFlow, linkAppToIonite, provisionTenant, requestJson, resolveReadyPath, runLoginToCallback, seedAppOwner, seedIoniteTenant, seedWorkforce, startAppUnderTest, waitForReady };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as A}from"node:child_process";function g(e){return e.replace(/\/+$/,"")}async function y(e,t,r={}){let n=await(r.fetch??globalThis.fetch)(e,{...t,signal:t.signal??AbortSignal.timeout(r.timeoutMs??30000)});if(!n.ok){let i=await n.text();throw Error(`${r.label??`${t.method??"GET"} ${e}`} failed (${n.status}): ${i}`)}if(n.status===204)return;return await n.json()}var F="/api/ionite",N=5000,_=2000;function W(e){return new Promise((t)=>setTimeout(t,e))}function R(e,t){if(e.exitCode!==null||e.signalCode!==null)return Promise.resolve(!0);return new Promise((r)=>{let n=!1,i=()=>{if(n)return;n=!0,clearTimeout(o),r(!0)},o=setTimeout(()=>{if(n)return;n=!0,e.removeListener("exit",i),r(!1)},t);e.once("exit",i)})}function L(e){if(e.readyPath)return e.readyPath;return`${g(e.basePath??F)}/readyz`}async function T(e,t={}){let{livenessPath:r,maxRetries:n=30,retryDelayMs:i=1000,requestTimeoutMs:o=3000}=t,d=L(t),c;for(let p=0;p<n;p++){try{if(r){let l=await fetch(new URL(r,e),{signal:AbortSignal.timeout(o)});if(!l.ok)throw Error(`liveness returned ${l.status}`)}let a=await fetch(new URL(d,e),{signal:AbortSignal.timeout(o)});if(a.ok)return;c=Error(`readiness returned ${a.status}`)}catch(a){c=a}if(p<n-1)await W(i)}let s=c instanceof Error?c.message:String(c);throw Error(`App not ready at ${new URL(d,e)} after ${n} attempts: ${s}`)}async function q(e){let{command:t,args:r=[],cwd:n,env:i,baseUrl:o,...d}=e,c=process.platform!=="win32",s=A(t,r,{cwd:n,env:{...process.env,...i},stdio:"inherit",detached:c});s.on("error",(u)=>{console.error(`Failed to start app under test (${t}):`,u)});let p=(u)=>{try{if(c&&s.pid!==void 0)process.kill(-s.pid,u);else s.kill(u)}catch{}},a=()=>p("SIGKILL");process.once("exit",a);let l=async()=>{if(s.exitCode===null&&s.signalCode===null){if(p("SIGTERM"),!await R(s,N))p("SIGKILL"),await R(s,_)}p("SIGKILL"),process.removeListener("exit",a)};try{await T(o,d)}catch(u){throw await l(),u}return{baseUrl:o,...s.pid===void 0?{}:{pid:s.pid},stop:l}}function z(e){if(typeof e.getSetCookie==="function")return e.getSetCookie();let t=e.get("set-cookie");return t?[t]:[]}function D(e){let t=e.split(";",1)[0],r=t?.indexOf("=")??-1;if(!t||r<=0)return;return[t.slice(0,r).trim(),t.slice(r+1).trim()]}class f{#e;#t;constructor(e=globalThis.fetch){this.#e=new Map;this.#t=e}cookies(e){if(e)return new Map(this.#e.get(new URL(e).origin));let t=new Map;for(let r of this.#e.values())for(let[n,i]of r)t.set(n,i);return t}async fetch(e,t={}){let r=new URL(e),n=t.method??"GET",i=t.body;for(let o=0;o<=10;o++){let d=new Headers(t.headers),c=this.#e.get(r.origin);if(c?.size&&!d.has("Cookie"))d.set("Cookie",[...c].map(([a,l])=>`${a}=${l}`).join("; "));let s=await this.#t(r,{...t,method:n,body:i,headers:d,redirect:"manual"});if(this.#n(r.origin,s.headers),![301,302,303,307,308].includes(s.status))return s;let p=s.headers.get("location");if(!p)return s;if(r=new URL(p,r),s.status===303||(s.status===301||s.status===302)&&n==="POST")n="GET",i=void 0}throw Error(`Too many redirects while requesting ${e}`)}#n(e,t){let r=this.#e.get(e)??new Map;for(let n of z(t)){let i=D(n);if(!i)continue;let[o,d]=i;if(d===""||/(?:^|;)\s*Max-Age=0(?:;|$)/i.test(n)||/expires=Thu, 01 Jan 1970/i.test(n))r.delete(o);else r.set(o,d)}this.#e.set(e,r)}}async function b(e,t){if(!e.ok)throw Error(`${t} failed (${e.status}): ${await e.text()}`);return await e.json()}async function B(e){let t=g(e.appBaseUrl),r=g(e.ioniteBaseUrl),n=e.appSession??new f,i=e.ioniteSession??new f,o=()=>AbortSignal.timeout(e.timeoutMs??30000),d=await n.fetch(new URL(e.startPath??"/api/integrations/ionite/start",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenantId:e.appTenantId,ioniteBaseUrl:r}),signal:o()}),c=await b(d,"Connect start"),p=new URL(c.connectUrl).searchParams,a;if("create"in e.ioniteTenant){let w=await i.fetch(new URL(e.tenantPath??"/api/connect/tenants",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.ioniteTenant.create),signal:o()});a=(await b(w,"ionite console tenant creation")).tenantId}else a=e.ioniteTenant.pick.tenantId;let l=await i.fetch(new URL(e.confirmPath??"/api/connect/confirm",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ioniteTenantId:a,product:p.get("product")??e.product??"",appUrl:p.get("app_url")??t,appTenantId:p.get("app_tenant")??e.appTenantId,state:p.get("state")??c.state,code:p.get("code")??"",returnUrl:p.get("return_url")??""}),signal:o()}),u=await b(l,"Connect confirmation");if(u.redirectTo?.includes("result=error")||u.error)throw Error(u.error??"Connect confirmation returned an error result");let m=p.get("return_url");if(m){let w=new URL(m);w.searchParams.set("state",c.state),w.searchParams.set("result","success"),w.searchParams.set("ionite_tenant",a);let x=await n.fetch(w,{signal:o()});if(!x.ok)throw Error(`Connect completion failed (${x.status}): ${await x.text()}`)}let k=new URL(e.statusPath??"/api/integrations/ionite",t);k.searchParams.set("tenant",e.appTenantId);let P=await n.fetch(k,{signal:o()}),U=await b(P,"Connect status");if(U.status!=="active"||!U.ioniteTenantId)throw Error(`Connect link is not active: ${JSON.stringify(U)}`);return{status:"active",ioniteTenantId:U.ioniteTenantId}}function j(e){return typeof e.getSetCookie==="function"?e.getSetCookie():e.get("set-cookie")?[e.get("set-cookie")]:[]}function v(e){let t=new Map;for(let r of j(e)){let n=r.split(";",1)[0],i=n?.indexOf("=")??-1;if(!n||i<=0)continue;t.set(n.slice(0,i).trim(),n.slice(i+1).trim())}return t}function I(e){return[...e].map(([t,r])=>`${t}=${r}`).join("; ")}async function O(e,t,r={}){if(!e.loginPath)throw Error("Login path not configured");let n=r.redirectParam?`?redirect=${encodeURIComponent(r.redirectParam)}`:"",i=await t(`${e.loginPath}${n}`);if(i.status!==302)throw Error(`Login did not redirect: ${i.status}`);let o=i.headers.get("location");if(!o)throw Error("No redirect location from login");let d=v(i.headers),c=new URL(o).searchParams.get("state");if(r.bogusCode){let l=new URL(o).searchParams.get("redirect_uri");if(!l||!c)throw Error("Missing redirect_uri/state on authorization URL");let u=new URL(l).pathname;return{callback:await t(`${u}?code=bogus-code&state=${encodeURIComponent(c)}`,{headers:{Cookie:I(d)}}),state:c}}let s=await(r.externalFetch??globalThis.fetch)(o,{redirect:"manual"});if(s.status!==302)throw Error(`Auth did not redirect: ${s.status}`);let p=s.headers.get("location");if(!p)throw Error("No redirect location from auth");return{callback:await t(`${new URL(p).pathname}${new URL(p).search}`,{headers:{Cookie:I(d)}}),state:c}}async function G(e,t){try{let{callback:r}=await O(e,t);if(r.status!==302)return{cookies:new Map,success:!1,error:`Callback did not redirect: ${r.status}`};return{cookies:v(r.headers),success:!0}}catch(r){return{cookies:new Map,success:!1,error:r instanceof Error?r.message:String(r)}}}function h(e,t){if(!e)throw Error(t)}async function J(e){let t=g(e.tenantPath??"/api/tenants"),r=e.profile??"tenantManager",n=await e.control.getTenantManagementToken(),i={...e.tenant,configLocator:e.tenant.configLocator??e.control.configLocator,webhookUrl:e.tenant.webhookUrl??e.control.webhookUrl},o=await fetch(new URL(t,e.baseUrl),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(i),signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)}),d=await o.json().catch(()=>({}));if(o.status===409||d.status==="failed")throw Error(`Tenant ${i.id} provisioning failed: ${d.error??o.statusText}`);if(d.status==="action_required")throw Error(`Tenant ${i.id} provisioning requires action at ${d.actionUrl}`);if(h(o.status===200||o.status===201||o.status===202,`Expected tenant create to return 200, 201, or 202, got ${o.status}`),h(typeof d.tenantUrl==="string",`Tenant ${i.id} response must include tenantUrl`),r==="creation"){let u=g(d.tenantUrl),m=e.basePath??"/api/ionite";return await T(u,{...e.readiness,basePath:m}),{id:i.id,baseUrl:u,basePath:m,tenantUrl:d.tenantUrl}}let c=await fetch(new URL(`${t}/${encodeURIComponent(i.id)}`,e.baseUrl),{headers:{Authorization:`Bearer ${n}`},signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)});h(c.status===200,`Expected tenant GET to return 200, got ${c.status}`);let s=await c.json();h(s.id===i.id,`Expected tenant GET id ${i.id}`),h(typeof s.ionUrls?.capabilitiezUrl==="string","Tenant GET must include ionUrls.capabilitiezUrl"),h(typeof s.ionUrls.readyzUrl==="string","Tenant GET must include ionUrls.readyzUrl");let p=new URL(s.ionUrls.capabilitiezUrl);h(p.pathname.endsWith("/capabilitiez"),"Tenant capabilitiezUrl must end in /capabilitiez");let a=p.pathname.slice(0,-13)||"/",l=new URL(s.ionUrls.readyzUrl);return await T(p.origin,{...e.readiness,readyPath:`${l.pathname}${l.search}`}),{id:i.id,baseUrl:p.origin,basePath:a,tenantUrl:typeof s.tenantUrl==="string"?s.tenantUrl:d.tenantUrl}}async function C(e,t){if(!e.ok)throw Error(`${t} failed (${e.status}): ${await e.text()}`);return await e.json()}async function H(e){let t=g(e.appBaseUrl),r=new f(e.fetch),n=()=>AbortSignal.timeout(e.timeoutMs??30000),i=await r.fetch(new URL(e.magicLinkPath??"/api/onboard/magic-link",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.magicLinkBody?.(e.owner)??{email:e.owner.email}),signal:n()}),o=await C(i,"App owner magic-link creation"),d=e.readMagicLink?.(o)??(typeof o==="object"&&o!==null&&typeof o.magicLink==="string"?o.magicLink:void 0);if(!d)throw Error("App owner magic-link response did not include magicLink");let c=await r.fetch(new URL(d,t),{signal:n()});if(!c.ok)throw Error(`App owner magic-link login failed (${c.status}): ${await c.text()}`);let s=await r.fetch(new URL(e.tenantCreatePath??"/api/onboard",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.tenantBody?.(e.tenant)??{slug:e.tenant.id,companyName:e.tenant.name}),signal:n()}),p=await C(s,"App tenant creation");return{tenantId:e.tenant.id,owner:e.owner,tenant:p,session:r}}async function K(e,t,r){let n=Date.now();while(Date.now()-n<r){try{if((await t(`${e}/api/readyz`,{signal:AbortSignal.timeout(2000)})).ok)return}catch{}await new Promise((i)=>setTimeout(i,500))}throw Error(`Timed out waiting for the ECI at ${e}/api/readyz`)}async function V(e){let t=g(e.eciBaseUrl??"http://localhost:3500"),r=e.fetch??globalThis.fetch,n={fetch:r,timeoutMs:e.requestTimeoutMs??120000};if(await K(t,r,e.readyTimeoutMs??300000),await y(`${t}/api/bootstrap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({companies:[e.company]})},{...n,label:"ECI company bootstrap"}),e.oem)await y(`${t}/api/oems`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.oem)},{...n,label:"ECI OEM registration"});let i=await y(`${t}/api/products`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.product)},{...n,label:"ECI product registration"});await e.onProductRegistered?.(i);let o=await y(`${t}/api/companies/${encodeURIComponent(e.company.id)}/products/${encodeURIComponent(i.product.id)}/integration`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.integration)},{...n,label:"ECI tenant integration"});if(o.tenant.status==="error")throw Error(o.tenant.error??`Tenant ${e.company.id} failed to integrate`);return{registration:i,integration:o}}var Q="urn:ietf:params:scim:schemas:core:2.0:User",E="urn:ietf:params:scim:schemas:core:2.0:Group";function X(e){return e.replaceAll("\\","\\\\").replaceAll('"',"\\\"")}function Y(e){if(e.version!==1)throw Error(`Unsupported workforce fixture version: ${e.version}`);let t=new Set,r=new Set;for(let n of e.users){if(!n.key||!n.userName)throw Error("Every workforce user requires key and userName");if(t.has(n.key))throw Error(`Duplicate workforce user key: ${n.key}`);t.add(n.key)}for(let n of e.groups){if(!n.key||!n.displayName)throw Error("Every workforce group requires key and displayName");if(r.has(n.key))throw Error(`Duplicate workforce group key: ${n.key}`);r.add(n.key)}for(let n of e.memberships??[]){if(!r.has(n.group))throw Error(`Unknown workforce group key: ${n.group}`);for(let i of n.users)if(!t.has(i))throw Error(`Unknown workforce user key: ${i}`)}}async function M(e,t,r,n,i){let o=await e(t,{...n,headers:{Authorization:r,Accept:"application/scim+json",...n.body?{"Content-Type":"application/scim+json"}:{},...n.headers},signal:n.signal??AbortSignal.timeout(i)});if(!o.ok)throw Error(`SCIM ${n.method??"GET"} ${t.pathname} failed (${o.status}): ${await o.text()}`);return o}async function S(e,t,r,n,i,o,d){let c=new URL(`${t.pathname.replace(/\/$/,"")}/${r}`,t);c.searchParams.set("filter",`externalId eq "${X(n)}"`);let p=(await(await M(e,c,o,{},d)).json()).Resources?.[0]?.id,a=typeof p==="string"?new URL(`${c.pathname}/${encodeURIComponent(p)}`,c):c,u=await(await M(e,a,o,{method:typeof p==="string"?"PUT":"POST",body:JSON.stringify(i)},d)).json();if(typeof u.id!=="string")throw Error(`SCIM ${r} upsert response did not include id`);return u.id}async function Z(e){Y(e.fixture);let t=e.fetch??globalThis.fetch,r=e.timeoutMs??30000,n=typeof e.authorization==="string"?e.authorization:await e.authorization(),i=n.startsWith("Bearer ")?n:`Bearer ${n}`,o=e.scimPath??"/api/ionite/iam",d=new URL(`${g(o)}/`,e.appBaseUrl),c=new Map,s=new Map;await e.prepareUsers?.(e.fixture.users),await Promise.all(e.fixture.users.map(async(a)=>{let l=a.externalId??a.key,u=await S(t,d,"Users",l,{schemas:[Q],externalId:l,userName:a.userName,displayName:a.displayName,active:a.active??!0,emails:a.emails,name:a.name,...a.attributes},i,r);c.set(a.key,u)})),await Promise.all(e.fixture.groups.map(async(a)=>{let l=a.externalId??a.key,u=await S(t,d,"Groups",l,{schemas:[E],externalId:l,displayName:a.displayName,members:[],...a.attributes},i,r);s.set(a.key,u)}));let p=new Map;for(let a of e.fixture.memberships??[]){let l=p.get(a.group)??new Set;for(let u of a.users)l.add(u);p.set(a.group,l)}return await Promise.all(e.fixture.groups.map(async(a)=>{if(!s.get(a.key))throw Error(`Missing seeded group id for ${a.key}`);let m=[...p.get(a.key)??new Set].map((k)=>{let P=c.get(k);if(!P)throw Error(`Missing seeded user id for ${k}`);return{value:P,type:"User"}});await S(t,d,"Groups",a.externalId??a.key,{schemas:[E],externalId:a.externalId??a.key,displayName:a.displayName,members:m,...a.attributes},i,r)})),{users:c,groups:s}}export{f as HttpSession,G as completeLoginFlow,B as linkAppToIonite,J as provisionTenant,y as requestJson,L as resolveReadyPath,O as runLoginToCallback,H as seedAppOwner,V as seedIoniteTenant,Z as seedWorkforce,q as startAppUnderTest,T as waitForReady};
|
|
1
|
+
import{spawn as F}from"node:child_process";function g(e){return e.replace(/\/+$/,"")}async function f(e,t){if(!e.ok)throw Error(`${t} failed (${e.status}): ${await e.text()}`);return await e.json()}async function k(e,t,r={}){let n=await(r.fetch??globalThis.fetch)(e,{...t,signal:t.signal??AbortSignal.timeout(r.timeoutMs??30000)});if(!n.ok){let i=await n.text();throw Error(`${r.label??`${t.method??"GET"} ${e}`} failed (${n.status}): ${i}`)}if(n.status===204)return;return await n.json()}var N="/api/ionite",_=5000,W=2000;function z(e){return new Promise((t)=>setTimeout(t,e))}function I(e,t){if(e.exitCode!==null||e.signalCode!==null)return Promise.resolve(!0);return new Promise((r)=>{let n=!1,i=()=>{if(n)return;n=!0,clearTimeout(o),r(!0)},o=setTimeout(()=>{if(n)return;n=!0,e.removeListener("exit",i),r(!1)},t);e.once("exit",i)})}function v(e){if(e.readyPath)return e.readyPath;return`${g(e.basePath??N)}/readyz`}async function P(e,t={}){let{livenessPath:r,maxRetries:n=30,retryDelayMs:i=1000,requestTimeoutMs:o=3000}=t,d=v(t),c;for(let p=0;p<n;p++){try{if(r){let u=await fetch(new URL(r,e),{signal:AbortSignal.timeout(o)});if(!u.ok)throw Error(`liveness returned ${u.status}`)}let a=await fetch(new URL(d,e),{signal:AbortSignal.timeout(o)});if(a.ok)return;c=Error(`readiness returned ${a.status}`)}catch(a){c=a}if(p<n-1)await z(i)}let s=c instanceof Error?c.message:String(c);throw Error(`App not ready at ${new URL(d,e)} after ${n} attempts: ${s}`)}async function q(e){let{command:t,args:r=[],cwd:n,env:i,baseUrl:o,...d}=e,c=process.platform!=="win32",s=F(t,r,{cwd:n,env:{...process.env,...i},stdio:"inherit",detached:c});s.on("error",(l)=>{console.error(`Failed to start app under test (${t}):`,l)});let p=(l)=>{try{if(c&&s.pid!==void 0)process.kill(-s.pid,l);else s.kill(l)}catch{}},a=()=>p("SIGKILL");process.once("exit",a);let u=async()=>{if(s.exitCode===null&&s.signalCode===null){if(p("SIGTERM"),!await I(s,_))p("SIGKILL"),await I(s,W)}p("SIGKILL"),process.removeListener("exit",a)};try{await P(o,d)}catch(l){throw await u(),l}return{baseUrl:o,...s.pid===void 0?{}:{pid:s.pid},stop:u}}function S(e){if(typeof e.getSetCookie==="function")return e.getSetCookie();let t=e.get("set-cookie");return t?[t]:[]}function R(e){let t=e.split(";",1)[0],r=t?.indexOf("=")??-1;if(!t||r<=0)return;return[t.slice(0,r).trim(),t.slice(r+1).trim()]}class h{#e;#t;constructor(e=globalThis.fetch){this.#e=new Map;this.#t=e}cookies(e){if(e)return new Map(this.#e.get(new URL(e).origin));let t=new Map;for(let r of this.#e.values())for(let[n,i]of r)t.set(n,i);return t}async fetch(e,t={}){let r=new URL(e),n=t.method??"GET",i=t.body;for(let o=0;o<=10;o++){let d=new Headers(t.headers),c=this.#e.get(r.origin);if(c?.size&&!d.has("Cookie"))d.set("Cookie",[...c].map(([a,u])=>`${a}=${u}`).join("; "));let s=await this.#t(r,{...t,method:n,body:i,headers:d,redirect:"manual"});if(this.#n(r.origin,s.headers),![301,302,303,307,308].includes(s.status))return s;let p=s.headers.get("location");if(!p)return s;if(r=new URL(p,r),s.status===303||(s.status===301||s.status===302)&&n==="POST")n="GET",i=void 0}throw Error(`Too many redirects while requesting ${e}`)}#n(e,t){let r=this.#e.get(e)??new Map;for(let n of S(t)){let i=R(n);if(!i)continue;let[o,d]=i;if(d===""||/(?:^|;)\s*Max-Age=0(?:;|$)/i.test(n)||/expires=Thu, 01 Jan 1970/i.test(n))r.delete(o);else r.set(o,d)}this.#e.set(e,r)}}async function B(e){let t=g(e.appBaseUrl),r=g(e.ioniteBaseUrl),n=e.appSession??new h,i=e.ioniteSession??new h,o=()=>AbortSignal.timeout(e.timeoutMs??30000),d=await n.fetch(new URL(e.startPath??"/api/integrations/ionite/start",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenantId:e.appTenantId,ioniteBaseUrl:r}),signal:o()}),c=await f(d,"Connect start"),p=new URL(c.connectUrl).searchParams,a;if("create"in e.ioniteTenant){let y=await i.fetch(new URL(e.tenantPath??"/api/connect/tenants",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.ioniteTenant.create),signal:o()});a=(await f(y,"ionite console tenant creation")).tenantId}else a=e.ioniteTenant.pick.tenantId;let u=await i.fetch(new URL(e.confirmPath??"/api/connect/confirm",r),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ioniteTenantId:a,product:p.get("product")??e.product??"",appUrl:p.get("app_url")??t,appTenantId:p.get("app_tenant")??e.appTenantId,state:p.get("state")??c.state,code:p.get("code")??"",returnUrl:p.get("return_url")??""}),signal:o()}),l=await f(u,"Connect confirmation");if(l.redirectTo?.includes("result=error")||l.error)throw Error(l.error??"Connect confirmation returned an error result");let m=p.get("return_url");if(m){let y=new URL(m);y.searchParams.set("state",c.state),y.searchParams.set("result","success"),y.searchParams.set("ionite_tenant",a);let x=await n.fetch(y,{signal:o()});if(!x.ok)throw Error(`Connect completion failed (${x.status}): ${await x.text()}`)}let T=new URL(e.statusPath??"/api/integrations/ionite",t);T.searchParams.set("tenant",e.appTenantId);let U=await n.fetch(T,{signal:o()}),b=await f(U,"Connect status");if(b.status!=="active"||!b.ioniteTenantId)throw Error(`Connect link is not active: ${JSON.stringify(b)}`);return{status:"active",ioniteTenantId:b.ioniteTenantId}}function C(e){let t=new Map;for(let r of S(e)){let n=R(r);if(n)t.set(n[0],n[1])}return t}function O(e){return[...e].map(([t,r])=>`${t}=${r}`).join("; ")}async function E(e,t,r={}){if(!e.loginPath)throw Error("Login path not configured");let n=r.redirectParam?`?redirect=${encodeURIComponent(r.redirectParam)}`:"",i=await t(`${e.loginPath}${n}`);if(i.status!==302)throw Error(`Login did not redirect: ${i.status}`);let o=i.headers.get("location");if(!o)throw Error("No redirect location from login");let d=C(i.headers),c=new URL(o).searchParams.get("state");if(r.bogusCode){let u=new URL(o).searchParams.get("redirect_uri");if(!u||!c)throw Error("Missing redirect_uri/state on authorization URL");let l=new URL(u).pathname;return{callback:await t(`${l}?code=bogus-code&state=${encodeURIComponent(c)}`,{headers:{Cookie:O(d)}}),state:c}}let s=await(r.externalFetch??globalThis.fetch)(o,{redirect:"manual"});if(s.status!==302)throw Error(`Auth did not redirect: ${s.status}`);let p=s.headers.get("location");if(!p)throw Error("No redirect location from auth");return{callback:await t(`${new URL(p).pathname}${new URL(p).search}`,{headers:{Cookie:O(d)}}),state:c}}async function D(e,t){try{let{callback:r}=await E(e,t);if(r.status!==302)return{cookies:new Map,success:!1,error:`Callback did not redirect: ${r.status}`};return{cookies:C(r.headers),success:!0}}catch(r){return{cookies:new Map,success:!1,error:r instanceof Error?r.message:String(r)}}}function w(e,t){if(!e)throw Error(t)}async function G(e){let t=g(e.tenantPath??"/api/tenants"),r=e.profile??"tenantManager",n=await e.control.getTenantManagementToken(),i={...e.tenant,configLocator:e.tenant.configLocator??e.control.configLocator,webhookUrl:e.tenant.webhookUrl??e.control.webhookUrl},o=await fetch(new URL(t,e.baseUrl),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(i),signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)}),d=await o.json().catch(()=>({}));if(o.status===409||d.status==="failed")throw Error(`Tenant ${i.id} provisioning failed: ${d.error??o.statusText}`);if(d.status==="action_required")throw Error(`Tenant ${i.id} provisioning requires action at ${d.actionUrl}`);if(w(o.status===200||o.status===201||o.status===202,`Expected tenant create to return 200, 201, or 202, got ${o.status}`),w(typeof d.tenantUrl==="string",`Tenant ${i.id} response must include tenantUrl`),r==="creation"){let l=g(d.tenantUrl),m=e.basePath??"/api/ionite";return await P(l,{...e.readiness,basePath:m}),{id:i.id,baseUrl:l,basePath:m,tenantUrl:d.tenantUrl}}let c=await fetch(new URL(`${t}/${encodeURIComponent(i.id)}`,e.baseUrl),{headers:{Authorization:`Bearer ${n}`},signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)});w(c.status===200,`Expected tenant GET to return 200, got ${c.status}`);let s=await c.json();w(s.id===i.id,`Expected tenant GET id ${i.id}`),w(typeof s.ionUrls?.capabilitiezUrl==="string","Tenant GET must include ionUrls.capabilitiezUrl"),w(typeof s.ionUrls.readyzUrl==="string","Tenant GET must include ionUrls.readyzUrl");let p=new URL(s.ionUrls.capabilitiezUrl);w(p.pathname.endsWith("/capabilitiez"),"Tenant capabilitiezUrl must end in /capabilitiez");let a=p.pathname.slice(0,-13)||"/",u=new URL(s.ionUrls.readyzUrl);return await P(p.origin,{...e.readiness,readyPath:`${u.pathname}${u.search}`}),{id:i.id,baseUrl:p.origin,basePath:a,tenantUrl:typeof s.tenantUrl==="string"?s.tenantUrl:d.tenantUrl}}async function J(e){let t=g(e.appBaseUrl),r=new h(e.fetch),n=()=>AbortSignal.timeout(e.timeoutMs??30000),i=await r.fetch(new URL(e.magicLinkPath??"/api/onboard/magic-link",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.magicLinkBody?.(e.owner)??{email:e.owner.email}),signal:n()}),o=await f(i,"App owner magic-link creation"),d=e.readMagicLink?.(o)??(typeof o==="object"&&o!==null&&typeof o.magicLink==="string"?o.magicLink:void 0);if(!d)throw Error("App owner magic-link response did not include magicLink");let c=await r.fetch(new URL(d,t),{signal:n()});if(!c.ok)throw Error(`App owner magic-link login failed (${c.status}): ${await c.text()}`);let s=await r.fetch(new URL(e.tenantCreatePath??"/api/onboard",t),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.tenantBody?.(e.tenant)??{slug:e.tenant.id,companyName:e.tenant.name}),signal:n()}),p=await f(s,"App tenant creation");return{tenantId:e.tenant.id,owner:e.owner,tenant:p,session:r}}async function j(e,t,r){let n=Date.now();while(Date.now()-n<r){try{if((await t(`${e}/api/readyz`,{signal:AbortSignal.timeout(2000)})).ok)return}catch{}await new Promise((i)=>setTimeout(i,500))}throw Error(`Timed out waiting for the ECI at ${e}/api/readyz`)}async function H(e){let t=g(e.eciBaseUrl??"http://localhost:3500"),r=e.fetch??globalThis.fetch,n={fetch:r,timeoutMs:e.requestTimeoutMs??120000};if(await j(t,r,e.readyTimeoutMs??300000),await k(`${t}/api/bootstrap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({companies:[e.company]})},{...n,label:"ECI company bootstrap"}),e.oem)await k(`${t}/api/oems`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.oem)},{...n,label:"ECI OEM registration"});let i=await k(`${t}/api/products`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.product)},{...n,label:"ECI product registration"});await e.onProductRegistered?.(i);let o=await k(`${t}/api/companies/${encodeURIComponent(e.company.id)}/products/${encodeURIComponent(i.product.id)}/integration`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.integration)},{...n,label:"ECI tenant integration"});if(o.tenant.status==="error")throw Error(o.tenant.error??`Tenant ${e.company.id} failed to integrate`);return{registration:i,integration:o}}var K="urn:ietf:params:scim:schemas:core:2.0:User",M="urn:ietf:params:scim:schemas:core:2.0:Group";function V(e){return e.replaceAll("\\","\\\\").replaceAll('"',"\\\"")}function Q(e){if(e.version!==1)throw Error(`Unsupported workforce fixture version: ${e.version}`);let t=new Set,r=new Set;for(let n of e.users){if(!n.key||!n.userName)throw Error("Every workforce user requires key and userName");if(t.has(n.key))throw Error(`Duplicate workforce user key: ${n.key}`);t.add(n.key)}for(let n of e.groups){if(!n.key||!n.displayName)throw Error("Every workforce group requires key and displayName");if(r.has(n.key))throw Error(`Duplicate workforce group key: ${n.key}`);r.add(n.key)}for(let n of e.memberships??[]){if(!r.has(n.group))throw Error(`Unknown workforce group key: ${n.group}`);for(let i of n.users)if(!t.has(i))throw Error(`Unknown workforce user key: ${i}`)}}async function A(e,t,r,n,i){let o=await e(t,{...n,headers:{Authorization:r,Accept:"application/scim+json",...n.body?{"Content-Type":"application/scim+json"}:{},...n.headers},signal:n.signal??AbortSignal.timeout(i)});if(!o.ok)throw Error(`SCIM ${n.method??"GET"} ${t.pathname} failed (${o.status}): ${await o.text()}`);return o}async function L(e,t,r,n,i,o,d){let c=new URL(`${t.pathname.replace(/\/$/,"")}/${r}`,t);c.searchParams.set("filter",`externalId eq "${V(n)}"`);let p=(await(await A(e,c,o,{},d)).json()).Resources?.[0]?.id,a=typeof p==="string"?new URL(`${c.pathname}/${encodeURIComponent(p)}`,c):c,l=await(await A(e,a,o,{method:typeof p==="string"?"PUT":"POST",body:JSON.stringify(i)},d)).json();if(typeof l.id!=="string")throw Error(`SCIM ${r} upsert response did not include id`);return l.id}async function X(e){Q(e.fixture);let t=e.fetch??globalThis.fetch,r=e.timeoutMs??30000,n=typeof e.authorization==="string"?e.authorization:await e.authorization(),i=n.startsWith("Bearer ")?n:`Bearer ${n}`,o=e.scimPath??"/api/ionite/iam",d=new URL(`${g(o)}/`,e.appBaseUrl),c=new Map,s=new Map;await e.prepareUsers?.(e.fixture.users),await Promise.all(e.fixture.users.map(async(a)=>{let u=a.externalId??a.key,l=await L(t,d,"Users",u,{schemas:[K],externalId:u,userName:a.userName,displayName:a.displayName,active:a.active??!0,emails:a.emails,name:a.name,...a.attributes},i,r);c.set(a.key,l)})),await Promise.all(e.fixture.groups.map(async(a)=>{let u=a.externalId??a.key,l=await L(t,d,"Groups",u,{schemas:[M],externalId:u,displayName:a.displayName,members:[],...a.attributes},i,r);s.set(a.key,l)}));let p=new Map;for(let a of e.fixture.memberships??[]){let u=p.get(a.group)??new Set;for(let l of a.users)u.add(l);p.set(a.group,u)}return await Promise.all(e.fixture.groups.map(async(a)=>{if(!s.get(a.key))throw Error(`Missing seeded group id for ${a.key}`);let l=p.get(a.key);if(!l?.size)return;let m=[...l].map((T)=>{let U=c.get(T);if(!U)throw Error(`Missing seeded user id for ${T}`);return{value:U,type:"User"}});await L(t,d,"Groups",a.externalId??a.key,{schemas:[M],externalId:a.externalId??a.key,displayName:a.displayName,members:m,...a.attributes},i,r)})),{users:c,groups:s}}export{h as HttpSession,D as completeLoginFlow,B as linkAppToIonite,G as provisionTenant,k as requestJson,v as resolveReadyPath,E as runLoginToCallback,J as seedAppOwner,H as seedIoniteTenant,X as seedWorkforce,q as startAppUnderTest,P as waitForReady};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ionite/devtools",
|
|
3
|
-
"version": "0.0.24-beta.
|
|
3
|
+
"version": "0.0.24-beta.20260918.6",
|
|
4
4
|
"description": "Lightweight ionite seeding drivers and journey helpers for local development and end-to-end testing.",
|
|
5
5
|
"author": "ionite",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ionite/core": "0.0.24-beta.
|
|
32
|
+
"@ionite/core": "0.0.24-beta.20260918.6"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@playwright/test": "^1.50.0"
|