@ionite/devtools 0.0.24-beta.20260922.11 → 0.0.24-beta.20260927.12
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 +1 -1
- package/dist/index.js +1 -1
- package/dist/playwright.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -305,7 +305,7 @@ type SeedWorkforceOptions = {
|
|
|
305
305
|
authorization: string | (() => Promise<string>);
|
|
306
306
|
/**
|
|
307
307
|
* Materialize App-owned employee records before SCIM adds IAM metadata. Required when the App,
|
|
308
|
-
* like
|
|
308
|
+
* like LEO, is the workforce system of record and deliberately rejects SCIM-created users.
|
|
309
309
|
*/
|
|
310
310
|
prepareUsers?: (users: readonly WorkforceUserFixture[]) => Promise<void>;
|
|
311
311
|
fetch?: FetchLike;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as E}from"node:child_process";function u(e){return e.replace(/\/+$/,"")}async function m(e,t){if(!e.ok)throw Error(`${t} failed (${e.status}): ${await e.text()}`);return await e.json()}async function h(e,t,r={}){let n=await(r.fetch??globalThis.fetch)(e,{...t,signal:t.signal??AbortSignal.timeout(r.timeoutMs??30000)});if(!n.ok){let o=await n.text();throw Error(`${r.label??`${t.method??"GET"} ${e}`} failed (${n.status}): ${o}`)}if(n.status===204)return;return await n.json()}var C="/api/ionite",F=5000,A=2000;function z(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,o=()=>{if(n)return;n=!0,clearTimeout(i),r(!0)},i=setTimeout(()=>{if(n)return;n=!0,e.removeListener("exit",o),r(!1)},t);e.once("exit",o)})}function S(e){if(e.readyPath)return e.readyPath;return`${u(e.basePath??C)}/readyz`}async function y(e,t={}){let{livenessPath:r,maxRetries:n=30,retryDelayMs:o=1000,requestTimeoutMs:i=3000}=t,s=S(t),d;for(let p=0;p<n;p++){try{if(r){let g=await fetch(new URL(r,e),{signal:AbortSignal.timeout(i)});if(!g.ok)throw Error(`liveness returned ${g.status}`)}let a=await fetch(new URL(s,e),{signal:AbortSignal.timeout(i)});if(a.ok)return;d=Error(`readiness returned ${a.status}`)}catch(a){d=a}if(p<n-1)await z(o)}let c=d instanceof Error?d.message:String(d);throw Error(`App not ready at ${new URL(s,e)} after ${n} attempts: ${c}`)}async function N(e){let{command:t,args:r=[],cwd:n,env:o,baseUrl:i,...s}=e,d=process.platform!=="win32",c=E(t,r,{cwd:n,env:{...process.env,...o},stdio:"inherit",detached:d});c.on("error",(l)=>{console.error(`Failed to start app under test (${t}):`,l)});let p=(l)=>{try{if(d&&c.pid!==void 0)process.kill(-c.pid,l);else c.kill(l)}catch{}},a=()=>p("SIGKILL");process.once("exit",a);let g=async()=>{if(c.exitCode===null&&c.signalCode===null){if(p("SIGTERM"),!await R(c,F))p("SIGKILL"),await R(c,A)}p("SIGKILL"),process.removeListener("exit",a)};try{await y(i,s)}catch(l){throw await g(),l}return{baseUrl:i,...c.pid===void 0?{}:{pid:c.pid},stop:g}}async function D(e){let t=new URL(`${u(e.integratorBaseUrl)}/api/tm/stage`),r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audience:e.audience,integratorTenantId:e.integratorTenantId,productId:e.productId,applicationId:e.applicationId,tenantHint:e.tenantHint,ttlSeconds:e.ttlSeconds})});return m(r,"TM stage")}function W(e){let t=new URL(u(e.tenantPath??"/api/tenants"),e.appBaseUrl),r=()=>AbortSignal.timeout(e.timeoutMs??15000),n=(i)=>new URL(`${t.pathname}/integrations/${i}`,t),o=(i,s)=>fetch(n(i),{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(s),signal:r()});return{authorizeUrl(){let i=n("authorize");return i.searchParams.set("handle",e.handle),i.toString()},async redeem(){let i=await o("redeem",{handle:e.handle});if(![200,202,410,429].includes(i.status))throw Error(`TM redeem failed (${i.status}): ${await i.text()}`);return m(i,"TM redeem")},async exportConfig(i){let s=await o("config-export",{handle:e.handle,authorization:i});return m(s,"TM config export")}}}function T(e){if(typeof e.getSetCookie==="function")return e.getSetCookie();let t=e.get("set-cookie");return t?[t]:[]}function b(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 k{#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,o]of r)t.set(n,o);return t}async fetch(e,t={}){let r=new URL(e),n=t.method??"GET",o=t.body;for(let i=0;i<=10;i++){let s=new Headers(t.headers),d=this.#e.get(r.origin);if(d?.size&&!s.has("Cookie"))s.set("Cookie",[...d].map(([a,g])=>`${a}=${g}`).join("; "));let c=await this.#t(r,{...t,method:n,body:o,headers:s,redirect:"manual"});if(this.#r(r.origin,c.headers),![301,302,303,307,308].includes(c.status))return c;let p=c.headers.get("location");if(!p)return c;if(r=new URL(p,r),c.status===303||(c.status===301||c.status===302)&&n==="POST")n="GET",o=void 0}throw Error(`Too many redirects while requesting ${e}`)}#r(e,t){let r=this.#e.get(e)??new Map;for(let n of T(t)){let o=b(n);if(!o)continue;let[i,s]=o;if(s===""||/(?:^|;)\s*Max-Age=0(?:;|$)/i.test(n)||/expires=Thu, 01 Jan 1970/i.test(n))r.delete(i);else r.set(i,s)}this.#e.set(e,r)}}function v(e){let t=new Map;for(let r of T(e)){let n=b(r);if(n)t.set(n[0],n[1])}return t}function L(e){return[...e].map(([t,r])=>`${t}=${r}`).join("; ")}async function I(e,t,r={}){if(!e.loginPath)throw Error("Login path not configured");let n=r.redirectParam?`?redirect=${encodeURIComponent(r.redirectParam)}`:"",o=await t(`${e.loginPath}${n}`);if(o.status!==302)throw Error(`Login did not redirect: ${o.status}`);let i=o.headers.get("location");if(!i)throw Error("No redirect location from login");let s=v(o.headers),d=new URL(i).searchParams.get("state");if(r.bogusCode){let g=new URL(i).searchParams.get("redirect_uri");if(!g||!d)throw Error("Missing redirect_uri/state on authorization URL");let l=new URL(g).pathname;return{callback:await t(`${l}?code=bogus-code&state=${encodeURIComponent(d)}`,{headers:{Cookie:L(s)}}),state:d}}let c=await(r.externalFetch??globalThis.fetch)(i,{redirect:"manual"});if(c.status!==302)throw Error(`Auth did not redirect: ${c.status}`);let p=c.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:L(s)}}),state:d}}async function _(e,t){try{let{callback:r}=await I(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 f(e,t){if(!e)throw Error(t)}async function q(e){let t=u(e.tenantPath??"/api/tenants"),r=e.profile??"tenantManager",n=await e.control.getTenantManagementToken(),o={...e.tenant,configLocator:e.tenant.configLocator??e.control.configLocator,webhookUrl:e.tenant.webhookUrl??e.control.webhookUrl},i=await fetch(new URL(t,e.baseUrl),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(o),signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)}),s=await i.json().catch(()=>({}));if(i.status===409||s.status==="failed")throw Error(`Tenant ${o.id} provisioning failed: ${s.error??i.statusText}`);if(s.status==="action_required")throw Error(`Tenant ${o.id} provisioning requires action at ${s.actionUrl}`);if(f(i.status===200||i.status===201||i.status===202,`Expected tenant create to return 200, 201, or 202, got ${i.status}`),f(typeof s.tenantUrl==="string",`Tenant ${o.id} response must include tenantUrl`),r==="creation"){let l=u(s.tenantUrl),w=e.basePath??"/api/ionite";return await y(l,{...e.readiness,basePath:w}),{id:o.id,baseUrl:l,basePath:w,tenantUrl:s.tenantUrl}}let d=await fetch(new URL(`${t}/${encodeURIComponent(o.id)}`,e.baseUrl),{headers:{Authorization:`Bearer ${n}`},signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)});f(d.status===200,`Expected tenant GET to return 200, got ${d.status}`);let c=await d.json();f(c.id===o.id,`Expected tenant GET id ${o.id}`),f(typeof c.ionUrls?.capabilitiezUrl==="string","Tenant GET must include ionUrls.capabilitiezUrl"),f(typeof c.ionUrls.readyzUrl==="string","Tenant GET must include ionUrls.readyzUrl");let p=new URL(c.ionUrls.capabilitiezUrl);f(p.pathname.endsWith("/capabilitiez"),"Tenant capabilitiezUrl must end in /capabilitiez");let a=p.pathname.slice(0,-13)||"/",g=new URL(c.ionUrls.readyzUrl);return await y(p.origin,{...e.readiness,readyPath:`${g.pathname}${g.search}`}),{id:o.id,baseUrl:p.origin,basePath:a,tenantUrl:typeof c.tenantUrl==="string"?c.tenantUrl:s.tenantUrl}}async function B(e){let t=u(e.appBaseUrl),r=new k(e.fetch),n=()=>AbortSignal.timeout(e.timeoutMs??30000),o=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()}),i=await m(o,"App owner magic-link creation"),s=e.readMagicLink?.(i)??(typeof i==="object"&&i!==null&&typeof i.magicLink==="string"?i.magicLink:void 0);if(!s)throw Error("App owner magic-link response did not include magicLink");let d=await r.fetch(new URL(s,t),{signal:n()});if(!d.ok)throw Error(`App owner magic-link login failed (${d.status}): ${await d.text()}`);let c=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 m(c,"App tenant creation");return{tenantId:e.tenant.id,owner:e.owner,tenant:p,session:r}}async function G(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((o)=>setTimeout(o,500))}throw Error(`Timed out waiting for the ECI at ${e}/api/readyz`)}async function J(e){let t=process.env.ION_CONTROLS_PORT?.trim()||"3700",r=u(e.eciBaseUrl??`http://localhost:${t}/ionite`),n=e.fetch??globalThis.fetch,o={fetch:n,timeoutMs:e.requestTimeoutMs??120000};if(await G(r,n,e.readyTimeoutMs??300000),await h(`${r}/api/bootstrap`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({companies:[e.company]})},{...o,label:"ECI company bootstrap"}),e.oem)await h(`${r}/api/oems`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.oem)},{...o,label:"ECI OEM registration"});let i=await h(`${r}/api/products`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.product)},{...o,label:"ECI product registration"});await e.onProductRegistered?.(i);let s=await h(`${r}/api/companies/${encodeURIComponent(e.company.id)}/products/${encodeURIComponent(i.product.id)}/integration`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.integration)},{...o,label:"ECI tenant integration"});if(s.tenant.status==="error")throw Error(s.tenant.error??`Tenant ${e.company.id} failed to integrate`);return{registration:i,integration:s}}var j="urn:ietf:params:scim:schemas:core:2.0:User",O="urn:ietf:params:scim:schemas:core:2.0:Group";function H(e){return e.replaceAll("\\","\\\\").replaceAll('"',"\\\"")}function K(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 o of n.users)if(!t.has(o))throw Error(`Unknown workforce user key: ${o}`)}}async function M(e,t,r,n,o){let i=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(o)});if(!i.ok)throw Error(`SCIM ${n.method??"GET"} ${t.pathname} failed (${i.status}): ${await i.text()}`);return i}async function P(e,t,r,n,o,i,s){let d=new URL(`${t.pathname.replace(/\/$/,"")}/${r}`,t);d.searchParams.set("filter",`externalId eq "${H(n)}"`);let p=(await(await M(e,d,i,{},s)).json()).Resources?.[0]?.id,a=typeof p==="string"?new URL(`${d.pathname}/${encodeURIComponent(p)}`,d):d,l=await(await M(e,a,i,{method:typeof p==="string"?"PUT":"POST",body:JSON.stringify(o)},s)).json();if(typeof l.id!=="string")throw Error(`SCIM ${r} upsert response did not include id`);return l.id}async function V(e){K(e.fixture);let t=e.fetch??globalThis.fetch,r=e.timeoutMs??30000,n=typeof e.authorization==="string"?e.authorization:await e.authorization(),o=n.startsWith("Bearer ")?n:`Bearer ${n}`,i=e.scimPath??"/api/ionite/iam",s=new URL(`${u(i)}/`,e.appBaseUrl),d=new Map,c=new Map;await e.prepareUsers?.(e.fixture.users),await Promise.all(e.fixture.users.map(async(a)=>{let g=a.externalId??a.key,l=await P(t,s,"Users",g,{schemas:[j],externalId:g,userName:a.userName,displayName:a.displayName,active:a.active??!0,emails:a.emails,name:a.name,...a.attributes},o,r);d.set(a.key,l)})),await Promise.all(e.fixture.groups.map(async(a)=>{let g=a.externalId??a.key,l=await P(t,s,"Groups",g,{schemas:[O],externalId:g,displayName:a.displayName,members:[],...a.attributes},o,r);c.set(a.key,l)}));let p=new Map;for(let a of e.fixture.memberships??[]){let g=p.get(a.group)??new Set;for(let l of a.users)g.add(l);p.set(a.group,g)}return await Promise.all(e.fixture.groups.map(async(a)=>{if(!c.get(a.key))throw Error(`Missing seeded group id for ${a.key}`);let l=p.get(a.key);if(!l?.size)return;let w=[...l].map((x)=>{let U=d.get(x);if(!U)throw Error(`Missing seeded user id for ${x}`);return{value:U,type:"User"}});await P(t,s,"Groups",a.externalId??a.key,{schemas:[O],externalId:a.externalId??a.key,displayName:a.displayName,members:w,...a.attributes},o,r)})),{users:d,groups:c}}export{k as HttpSession,_ as completeLoginFlow,q as provisionTenant,h as requestJson,S as resolveReadyPath,I as runLoginToCallback,B as seedAppOwner,J as seedIoniteTenant,V as seedWorkforce,D as stageTmIntegration,N as startAppUnderTest,W as tmIntegratorDriver,y as waitForReady};
|
|
1
|
+
import{spawn as B}from"node:child_process";import{ACCEPT_JSON as G}from"@ionite/core";import{JSON_MEDIA_TYPE as q,readJsonResponse as S,unexpectedBodySummary as O}from"@ionite/core";function l(e){return e.replace(/\/+$/,"")}async function m(e,r){if(!e.ok){let t=await O(e);throw Error(`${r} failed (${e.status})${t.excerpt?`: ${t.excerpt}`:""}`)}return await S(e)}async function h(e,r,t={}){let n=new Headers(r.headers);if(!n.has("Accept"))n.set("Accept",q);let o=await(t.fetch??globalThis.fetch)(e,{...r,headers:n,signal:r.signal??AbortSignal.timeout(t.timeoutMs??30000)});if(!o.ok){let i=await O(o);throw Error(`${t.label??`${r.method??"GET"} ${e}`} failed (${o.status})${i.excerpt?`: ${i.excerpt}`:""}`)}if(o.status===204)return;return await S(o)}var H="/api/ionite",K=5000,V=2000;function Y(e){return new Promise((r)=>setTimeout(r,e))}function I(e,r){if(e.exitCode!==null||e.signalCode!==null)return Promise.resolve(!0);return new Promise((t)=>{let n=!1,o=()=>{if(n)return;n=!0,clearTimeout(i),t(!0)},i=setTimeout(()=>{if(n)return;n=!0,e.removeListener("exit",o),t(!1)},r);e.once("exit",o)})}function L(e){if(e.readyPath)return e.readyPath;return`${l(e.basePath??H)}/readyz`}async function y(e,r={}){let{livenessPath:t,maxRetries:n=30,retryDelayMs:o=1000,requestTimeoutMs:i=3000}=r,s=L(r),d;for(let p=0;p<n;p++){try{if(t){let g=await fetch(new URL(t,e),{signal:AbortSignal.timeout(i)});if(!g.ok)throw Error(`liveness returned ${g.status}`)}let a=await fetch(new URL(s,e),{headers:G,signal:AbortSignal.timeout(i)});if(a.ok)return;d=Error(`readiness returned ${a.status}`)}catch(a){d=a}if(p<n-1)await Y(o)}let c=d instanceof Error?d.message:String(d);throw Error(`App not ready at ${new URL(s,e)} after ${n} attempts: ${c}`)}async function j(e){let{command:r,args:t=[],cwd:n,env:o,baseUrl:i,...s}=e,d=process.platform!=="win32",c=B(r,t,{cwd:n,env:{...process.env,...o},stdio:"inherit",detached:d});c.on("error",(u)=>{console.error(`Failed to start app under test (${r}):`,u)});let p=(u)=>{try{if(d&&c.pid!==void 0)process.kill(-c.pid,u);else c.kill(u)}catch{}},a=()=>p("SIGKILL");process.once("exit",a);let g=async()=>{if(c.exitCode===null&&c.signalCode===null){if(p("SIGTERM"),!await I(c,K))p("SIGKILL"),await I(c,V)}p("SIGKILL"),process.removeListener("exit",a)};try{await y(i,s)}catch(u){throw await g(),u}return{baseUrl:i,...c.pid===void 0?{}:{pid:c.pid},stop:g}}import{ACCEPT_JSON as v,CONTENT_TYPE_JSON as E}from"@ionite/core";async function Q(e){let r=new URL(`${l(e.integratorBaseUrl)}/api/tm/stage`),t=await fetch(r,{method:"POST",headers:{...v,...E},body:JSON.stringify({audience:e.audience,integratorTenantId:e.integratorTenantId,productId:e.productId,applicationId:e.applicationId,tenantHint:e.tenantHint,ttlSeconds:e.ttlSeconds})});return m(t,"TM stage")}function X(e){let r=new URL(l(e.tenantPath??"/api/tenants"),e.appBaseUrl),t=()=>AbortSignal.timeout(e.timeoutMs??15000),n=(i)=>new URL(`${r.pathname}/integrations/${i}`,r),o=(i,s)=>fetch(n(i),{method:"POST",headers:{...v,Authorization:`Bearer ${e.accessToken}`,...E},body:JSON.stringify(s),signal:t()});return{authorizeUrl(){let i=n("authorize");return i.searchParams.set("handle",e.handle),i.toString()},async redeem(){let i=await o("redeem",{handle:e.handle});if(![200,202,410,429].includes(i.status))throw Error(`TM redeem failed (${i.status}): ${await i.text()}`);return m(i,"TM redeem")},async exportConfig(i){let s=await o("config-export",{handle:e.handle,authorization:i});return m(s,"TM config export")}}}function P(e){if(typeof e.getSetCookie==="function")return e.getSetCookie();let r=e.get("set-cookie");return r?[r]:[]}function b(e){let r=e.split(";",1)[0],t=r?.indexOf("=")??-1;if(!r||t<=0)return;return[r.slice(0,t).trim(),r.slice(t+1).trim()]}class T{#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 r=new Map;for(let t of this.#e.values())for(let[n,o]of t)r.set(n,o);return r}async fetch(e,r={}){let t=new URL(e),n=r.method??"GET",o=r.body;for(let i=0;i<=10;i++){let s=new Headers(r.headers),d=this.#e.get(t.origin);if(d?.size&&!s.has("Cookie"))s.set("Cookie",[...d].map(([a,g])=>`${a}=${g}`).join("; "));let c=await this.#t(t,{...r,method:n,body:o,headers:s,redirect:"manual"});if(this.#r(t.origin,c.headers),![301,302,303,307,308].includes(c.status))return c;let p=c.headers.get("location");if(!p)return c;if(t=new URL(p,t),c.status===303||(c.status===301||c.status===302)&&n==="POST")n="GET",o=void 0}throw Error(`Too many redirects while requesting ${e}`)}#r(e,r){let t=this.#e.get(e)??new Map;for(let n of P(r)){let o=b(n);if(!o)continue;let[i,s]=o;if(s===""||/(?:^|;)\s*Max-Age=0(?:;|$)/i.test(n)||/expires=Thu, 01 Jan 1970/i.test(n))t.delete(i);else t.set(i,s)}this.#e.set(e,t)}}function M(e){let r=new Map;for(let t of P(e)){let n=b(t);if(n)r.set(n[0],n[1])}return r}function C(e){return[...e].map(([r,t])=>`${r}=${t}`).join("; ")}async function A(e,r,t={}){if(!e.loginPath)throw Error("Login path not configured");let n=t.redirectParam?`?redirect=${encodeURIComponent(t.redirectParam)}`:"",o=await r(`${e.loginPath}${n}`);if(o.status!==302)throw Error(`Login did not redirect: ${o.status}`);let i=o.headers.get("location");if(!i)throw Error("No redirect location from login");let s=M(o.headers),d=new URL(i).searchParams.get("state");if(t.bogusCode){let g=new URL(i).searchParams.get("redirect_uri");if(!g||!d)throw Error("Missing redirect_uri/state on authorization URL");let u=new URL(g).pathname;return{callback:await r(`${u}?code=bogus-code&state=${encodeURIComponent(d)}`,{headers:{Cookie:C(s)}}),state:d}}let c=await(t.externalFetch??globalThis.fetch)(i,{redirect:"manual"});if(c.status!==302)throw Error(`Auth did not redirect: ${c.status}`);let p=c.headers.get("location");if(!p)throw Error("No redirect location from auth");return{callback:await r(`${new URL(p).pathname}${new URL(p).search}`,{headers:{Cookie:C(s)}}),state:d}}async function Z(e,r){try{let{callback:t}=await A(e,r);if(t.status!==302)return{cookies:new Map,success:!1,error:`Callback did not redirect: ${t.status}`};return{cookies:M(t.headers),success:!0}}catch(t){return{cookies:new Map,success:!1,error:t instanceof Error?t.message:String(t)}}}import{ACCEPT_JSON as F,CONTENT_TYPE_JSON as ee,readJsonResponse as N}from"@ionite/core";function f(e,r){if(!e)throw Error(r)}async function te(e){let r=l(e.tenantPath??"/api/tenants"),t=e.profile??"tenantManager",n=await e.control.getTenantManagementToken(),o={...e.tenant,configLocator:e.tenant.configLocator??e.control.configLocator,webhookUrl:e.tenant.webhookUrl??e.control.webhookUrl},i=await fetch(new URL(r,e.baseUrl),{method:"POST",headers:{...F,Authorization:`Bearer ${n}`,...ee},body:JSON.stringify(o),signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)}),s=await N(i).catch(()=>({}));if(i.status===409||s.status==="failed")throw Error(`Tenant ${o.id} provisioning failed: ${s.error??i.statusText}`);if(s.status==="action_required")throw Error(`Tenant ${o.id} provisioning requires action at ${s.actionUrl}`);if(f(i.status===200||i.status===201||i.status===202,`Expected tenant create to return 200, 201, or 202, got ${i.status}`),f(typeof s.tenantUrl==="string",`Tenant ${o.id} response must include tenantUrl`),t==="creation"){let u=l(s.tenantUrl),w=e.basePath??"/api/ionite";return await y(u,{...e.readiness,basePath:w}),{id:o.id,baseUrl:u,basePath:w,tenantUrl:s.tenantUrl}}let d=await fetch(new URL(`${r}/${encodeURIComponent(o.id)}`,e.baseUrl),{headers:{...F,Authorization:`Bearer ${n}`},signal:AbortSignal.timeout(e.readiness?.requestTimeoutMs??15000)});f(d.status===200,`Expected tenant GET to return 200, got ${d.status}`);let c=await N(d);f(c.id===o.id,`Expected tenant GET id ${o.id}`),f(typeof c.ionUrls?.capabilitiezUrl==="string","Tenant GET must include ionUrls.capabilitiezUrl"),f(typeof c.ionUrls.readyzUrl==="string","Tenant GET must include ionUrls.readyzUrl");let p=new URL(c.ionUrls.capabilitiezUrl);f(p.pathname.endsWith("/capabilitiez"),"Tenant capabilitiezUrl must end in /capabilitiez");let a=p.pathname.slice(0,-13)||"/",g=new URL(c.ionUrls.readyzUrl);return await y(p.origin,{...e.readiness,readyPath:`${g.pathname}${g.search}`}),{id:o.id,baseUrl:p.origin,basePath:a,tenantUrl:typeof c.tenantUrl==="string"?c.tenantUrl:s.tenantUrl}}import{ACCEPT_JSON as _,CONTENT_TYPE_JSON as z}from"@ionite/core";async function re(e){let r=l(e.appBaseUrl),t=new T(e.fetch),n=()=>AbortSignal.timeout(e.timeoutMs??30000),o=await t.fetch(new URL(e.magicLinkPath??"/api/onboard/magic-link",r),{method:"POST",headers:{..._,...z},body:JSON.stringify(e.magicLinkBody?.(e.owner)??{email:e.owner.email}),signal:n()}),i=await m(o,"App owner magic-link creation"),s=e.readMagicLink?.(i)??(typeof i==="object"&&i!==null&&typeof i.magicLink==="string"?i.magicLink:void 0);if(!s)throw Error("App owner magic-link response did not include magicLink");let d=await t.fetch(new URL(s,r),{signal:n()});if(!d.ok)throw Error(`App owner magic-link login failed (${d.status}): ${await d.text()}`);let c=await t.fetch(new URL(e.tenantCreatePath??"/api/onboard",r),{method:"POST",headers:{..._,...z},body:JSON.stringify(e.tenantBody?.(e.tenant)??{slug:e.tenant.id,companyName:e.tenant.name}),signal:n()}),p=await m(c,"App tenant creation");return{tenantId:e.tenant.id,owner:e.owner,tenant:p,session:t}}import{ACCEPT_JSON as ne,CONTENT_TYPE_JSON as k}from"@ionite/core";async function ie(e,r,t){let n=Date.now();while(Date.now()-n<t){try{if((await r(`${e}/api/readyz`,{headers:ne,signal:AbortSignal.timeout(2000)})).ok)return}catch{}await new Promise((o)=>setTimeout(o,500))}throw Error(`Timed out waiting for the ECI at ${e}/api/readyz`)}async function oe(e){let r=process.env.ION_CONTROLS_PORT?.trim()||"3700",t=l(e.eciBaseUrl??`http://localhost:${r}/ionite`),n=e.fetch??globalThis.fetch,o={fetch:n,timeoutMs:e.requestTimeoutMs??120000};if(await ie(t,n,e.readyTimeoutMs??300000),await h(`${t}/api/bootstrap`,{method:"POST",headers:k,body:JSON.stringify({companies:[e.company]})},{...o,label:"ECI company bootstrap"}),e.oem)await h(`${t}/api/oems`,{method:"POST",headers:k,body:JSON.stringify(e.oem)},{...o,label:"ECI OEM registration"});let i=await h(`${t}/api/products`,{method:"POST",headers:k,body:JSON.stringify(e.product)},{...o,label:"ECI product registration"});await e.onProductRegistered?.(i);let s=await h(`${t}/api/companies/${encodeURIComponent(e.company.id)}/products/${encodeURIComponent(i.product.id)}/integration`,{method:"POST",headers:k,body:JSON.stringify(e.integration)},{...o,label:"ECI tenant integration"});if(s.tenant.status==="error")throw Error(s.tenant.error??`Tenant ${e.company.id} failed to integrate`);return{registration:i,integration:s}}import{ACCEPT_SCIM as se,CONTENT_TYPE_SCIM as ae,readJsonResponse as J,unexpectedBodySummary as ce}from"@ionite/core";var de="urn:ietf:params:scim:schemas:core:2.0:User",D="urn:ietf:params:scim:schemas:core:2.0:Group";function pe(e){return e.replaceAll("\\","\\\\").replaceAll('"',"\\\"")}function ge(e){if(e.version!==1)throw Error(`Unsupported workforce fixture version: ${e.version}`);let r=new Set,t=new Set;for(let n of e.users){if(!n.key||!n.userName)throw Error("Every workforce user requires key and userName");if(r.has(n.key))throw Error(`Duplicate workforce user key: ${n.key}`);r.add(n.key)}for(let n of e.groups){if(!n.key||!n.displayName)throw Error("Every workforce group requires key and displayName");if(t.has(n.key))throw Error(`Duplicate workforce group key: ${n.key}`);t.add(n.key)}for(let n of e.memberships??[]){if(!t.has(n.group))throw Error(`Unknown workforce group key: ${n.group}`);for(let o of n.users)if(!r.has(o))throw Error(`Unknown workforce user key: ${o}`)}}async function W(e,r,t,n,o){let i=await e(r,{...n,headers:{Authorization:t,...se,...n.body?ae:{},...n.headers},signal:n.signal??AbortSignal.timeout(o)});if(!i.ok){let s=await ce(i);throw Error(`SCIM ${n.method??"GET"} ${r.pathname} failed (${i.status})${s.excerpt?`: ${s.excerpt}`:""}`)}return i}async function x(e,r,t,n,o,i,s){let d=new URL(`${r.pathname.replace(/\/$/,"")}/${t}`,r);d.searchParams.set("filter",`externalId eq "${pe(n)}"`);let p=(await J(await W(e,d,i,{},s))).Resources?.[0]?.id,a=typeof p==="string"?new URL(`${d.pathname}/${encodeURIComponent(p)}`,d):d,g=await W(e,a,i,{method:typeof p==="string"?"PUT":"POST",body:JSON.stringify(o)},s),u=await J(g);if(typeof u.id!=="string")throw Error(`SCIM ${t} upsert response did not include id`);return u.id}async function ue(e){ge(e.fixture);let r=e.fetch??globalThis.fetch,t=e.timeoutMs??30000,n=typeof e.authorization==="string"?e.authorization:await e.authorization(),o=n.startsWith("Bearer ")?n:`Bearer ${n}`,i=e.scimPath??"/api/ionite/iam",s=new URL(`${l(i)}/`,e.appBaseUrl),d=new Map,c=new Map;await e.prepareUsers?.(e.fixture.users),await Promise.all(e.fixture.users.map(async(a)=>{let g=a.externalId??a.key,u=await x(r,s,"Users",g,{schemas:[de],externalId:g,userName:a.userName,displayName:a.displayName,active:a.active??!0,emails:a.emails,name:a.name,...a.attributes},o,t);d.set(a.key,u)})),await Promise.all(e.fixture.groups.map(async(a)=>{let g=a.externalId??a.key,u=await x(r,s,"Groups",g,{schemas:[D],externalId:g,displayName:a.displayName,members:[],...a.attributes},o,t);c.set(a.key,u)}));let p=new Map;for(let a of e.fixture.memberships??[]){let g=p.get(a.group)??new Set;for(let u of a.users)g.add(u);p.set(a.group,g)}return await Promise.all(e.fixture.groups.map(async(a)=>{if(!c.get(a.key))throw Error(`Missing seeded group id for ${a.key}`);let u=p.get(a.key);if(!u?.size)return;let w=[...u].map((U)=>{let R=d.get(U);if(!R)throw Error(`Missing seeded user id for ${U}`);return{value:R,type:"User"}});await x(r,s,"Groups",a.externalId??a.key,{schemas:[D],externalId:a.externalId??a.key,displayName:a.displayName,members:w,...a.attributes},o,t)})),{users:d,groups:c}}export{T as HttpSession,Z as completeLoginFlow,te as provisionTenant,h as requestJson,L as resolveReadyPath,A as runLoginToCallback,re as seedAppOwner,oe as seedIoniteTenant,ue as seedWorkforce,Q as stageTmIntegration,j as startAppUnderTest,X as tmIntegratorDriver,y as waitForReady};
|
package/dist/playwright.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function a(
|
|
1
|
+
import{ACCEPT_JSON as p}from"@ionite/core";async function a(e,t){if(!e.ok())throw Error(`${t} failed (${e.status()}): ${await e.text()}`)}async function d(e,t){let r=t.timeoutMs??30000;await e.goto(t.loginUrl),await e.getByRole("combobox",{name:/email/i}).fill(t.email);let i=e.getByRole("option").filter({hasText:t.email}).first();if(await i.waitFor({state:"visible",timeout:r}),await i.click(),await e.getByRole("button",{name:/sign in/i}).click(),t.expectedUrl)await e.waitForURL(t.expectedUrl,{timeout:r})}async function x(e,t){let r=await e.get(new URL(t.providersPath??"/api/ionite/auth/customer/providers",t.appBaseUrl).toString(),{headers:p});await a(r,"CIAM provider discovery");let n=r.headers()["content-type"];if(!n?.toLowerCase().includes("json")){let o=await r.text(),l=/<title(?:\s[^>]*)?>([\s\S]*?)<\/title>/i.exec(o)?.[1]?.replace(/\s+/g," ").trim();throw Error(`CIAM provider discovery expected JSON, received ${n??"no content type"}${l?`: ${l.slice(0,300)}`:""}`)}let i=await r.json(),s=(t.provider?i.providers?.find((o)=>o.id===t.provider||o.name===t.provider):i.providers?.[0])?.loginUrl;if(!s)throw Error("CIAM provider discovery returned no loginUrl");let c=await e.post(new URL("/api/customers/login",t.ciamBaseUrl).toString(),{form:{email:t.email}});await a(c,"CIAM control login");let g=await e.get(s);return await a(g,"App customer login"),{loginUrl:s}}function C(e,t={}){return e.newContext({...t,storageState:t.storageState??{cookies:[],origins:[]}})}export{C as createIsolatedBrowserContext,x as loginWithCiamControl,d as loginWithSsoControl};
|
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.20260927.12",
|
|
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.20260927.12"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@playwright/test": "^1.50.0"
|