@limrun/ui 0.14.0-rc.4 → 0.14.0-rc.5

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 (31) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.d.ts +108 -4
  3. package/dist/app-store-relay/index.js +353 -160
  4. package/dist/app-store-relay/react.cjs +1 -1
  5. package/dist/app-store-relay/react.js +1 -1
  6. package/dist/apple-credentials/index.cjs +1 -1
  7. package/dist/apple-credentials/index.d.ts +59 -8
  8. package/dist/apple-credentials/index.js +197 -133
  9. package/dist/client-C9z_sgOf.js +1 -0
  10. package/dist/{client-DSuNtWDv.mjs → client-CFDB4mX5.mjs} +37 -30
  11. package/dist/core/device-install/apple/provisioning.d.ts +25 -0
  12. package/dist/core/device-install/apple/relay.d.ts +13 -0
  13. package/dist/core/device-install/storage/secret-store.d.ts +24 -1
  14. package/dist/device-build/index.cjs +1 -1
  15. package/dist/device-build/index.js +1 -1
  16. package/dist/device-install/index.cjs +1 -1
  17. package/dist/device-install/index.js +175 -172
  18. package/dist/{provisioning-B_DefBEp.mjs → provisioning-CDPvxd1h.mjs} +63 -32
  19. package/dist/provisioning-CbC4h--7.js +1 -0
  20. package/package.json +1 -1
  21. package/src/app-store-relay/index.ts +358 -23
  22. package/src/apple-credentials/index.test.ts +22 -0
  23. package/src/apple-credentials/index.ts +161 -14
  24. package/src/core/device-install/apple/client.ts +13 -6
  25. package/src/core/device-install/apple/provisioning.test.ts +30 -0
  26. package/src/core/device-install/apple/provisioning.ts +39 -0
  27. package/src/core/device-install/apple/relay.ts +20 -0
  28. package/src/core/device-install/operations/operations.ts +6 -1
  29. package/src/core/device-install/storage/secret-store.ts +36 -2
  30. package/dist/client-D1drDXxE.js +0 -1
  31. package/dist/provisioning-BlQMccX_.js +0 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),y=require("../client-D1drDXxE.js");require("../index-ChhtuQ7e.js");require("../gsa-srp-CCIfUz7Y.js");const w=require("../errors-BSkqS7U-.js");function m({registryApiUrl:i,token:u,organizationId:l}){const[g,o]=t.useState("idle"),[h,a]=t.useState(),[v,d]=t.useState(),[f,p]=t.useState(),[S,n]=t.useState(),r=t.useRef(void 0),b=t.useCallback(async()=>{await r.current?.close().catch(()=>{}),r.current=void 0,a(void 0),d(void 0),p(void 0),n(void 0),o("idle")},[]);t.useEffect(()=>()=>{r.current?.close(),r.current=void 0},[]);const C=t.useCallback(async({accountName:s,password:c})=>{o("authenticating"),n(void 0),await r.current?.close().catch(()=>{});try{const e=await y.startBrowserOwnedAppleIDLogin({registryApiUrl:i,token:u,organizationId:l,accountName:s,password:c});return r.current=e,a(e),d(e.completeResponse),p(e.twoFactorChallengeResponse),o(e.requiresTwoFactor?"two-factor-required":"authenticated"),e}catch(e){a(void 0),r.current=void 0,n(w.errorMessage(e)),o("error");return}},[i,l,u]),R=t.useCallback(async s=>{const c=r.current;if(!c)throw new Error("Start Apple ID login before submitting a two-factor code.");o("authenticating"),n(void 0);try{const e=await c.finishTwoFactor(s);return o("authenticated"),e}catch(e){n(w.errorMessage(e)),o("error");return}},[]),q=t.useCallback(async()=>{const s=r.current;if(!s)throw new Error("Start Apple ID login before finalizing the Apple session.");return s.finalize()},[]);return{status:g,session:h,completeResponse:v,twoFactorChallengeResponse:f,error:S,startLogin:C,submitTwoFactorCode:R,finalize:q,close:b}}exports.useAppleIDLogin=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),y=require("../client-C9z_sgOf.js");require("../index-ChhtuQ7e.js");require("../gsa-srp-CCIfUz7Y.js");const w=require("../errors-BSkqS7U-.js");function m({registryApiUrl:i,token:u,organizationId:l}){const[g,o]=t.useState("idle"),[h,a]=t.useState(),[v,d]=t.useState(),[f,p]=t.useState(),[S,n]=t.useState(),r=t.useRef(void 0),b=t.useCallback(async()=>{await r.current?.close().catch(()=>{}),r.current=void 0,a(void 0),d(void 0),p(void 0),n(void 0),o("idle")},[]);t.useEffect(()=>()=>{r.current?.close(),r.current=void 0},[]);const C=t.useCallback(async({accountName:s,password:c})=>{o("authenticating"),n(void 0),await r.current?.close().catch(()=>{});try{const e=await y.startBrowserOwnedAppleIDLogin({registryApiUrl:i,token:u,organizationId:l,accountName:s,password:c});return r.current=e,a(e),d(e.completeResponse),p(e.twoFactorChallengeResponse),o(e.requiresTwoFactor?"two-factor-required":"authenticated"),e}catch(e){a(void 0),r.current=void 0,n(w.errorMessage(e)),o("error");return}},[i,l,u]),R=t.useCallback(async s=>{const c=r.current;if(!c)throw new Error("Start Apple ID login before submitting a two-factor code.");o("authenticating"),n(void 0);try{const e=await c.finishTwoFactor(s);return o("authenticated"),e}catch(e){n(w.errorMessage(e)),o("error");return}},[]),q=t.useCallback(async()=>{const s=r.current;if(!s)throw new Error("Start Apple ID login before finalizing the Apple session.");return s.finalize()},[]);return{status:g,session:h,completeResponse:v,twoFactorChallengeResponse:f,error:S,startLogin:C,submitTwoFactorCode:R,finalize:q,close:b}}exports.useAppleIDLogin=m;
@@ -1,5 +1,5 @@
1
1
  import { useState as n, useRef as S, useCallback as i, useEffect as A } from "react";
2
- import { s as D } from "../client-DSuNtWDv.mjs";
2
+ import { s as D } from "../client-CFDB4mX5.mjs";
3
3
  import "../index-YDu8K9a4.mjs";
4
4
  import "../gsa-srp-Bme3JLEi.mjs";
5
5
  import { e as w } from "../errors-gy8yQJos.mjs";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../app-store-relay/index.cjs"),E=require("../browser-storage-DLxIqZk5.js"),A="appleCertificate",P="appleProvisioningProfile";function b(r){const e={};for(const[o,i]of Object.entries(r))i&&(e[o]=i);return e}async function T(r,e,o){return r.put(A,e,b(o))}async function I(r,e,o){return r.put(P,e,b(o))}function R(r){const e=r.fetch??fetch.bind(globalThis),o=r.apiUrl.replace(/\/+$/,""),i=(t,s)=>`${o}/v1/organizations/${encodeURIComponent(r.organizationId)}/secrets/${encodeURIComponent(t)}/${encodeURIComponent(s)}`,c={Authorization:`Bearer ${r.token}`,"Content-Type":"application/json"};async function a(t,s){let n=`${t.status}`;try{const d=await t.json();d.message&&(n=d.message)}catch{}throw new Error(`Failed to ${s} secret: ${n}`)}return{async put(t,s,n){const d=await e(i(t,s),{method:"PUT",headers:c,body:JSON.stringify({data:n,replace:!0})});d.ok||await a(d,"store");const f=await d.json();return{type:f.type,name:f.name,createdAt:f.createdAt,data:f.data}},async get(t,s){const n=await e(i(t,s),{method:"GET",headers:c});if(n.status===404)return;n.ok||await a(n,"fetch");const d=await n.json();return{type:d.type,name:d.name,createdAt:d.createdAt,data:d.data}},async list(){const t=await e(`${o}/v1/organizations/${encodeURIComponent(r.organizationId)}/secrets`,{method:"GET",headers:c});return t.ok||await a(t,"list"),(await t.json()).filter(n=>n.type===A||n.type===P).map(n=>({type:n.type,name:n.name,createdAt:n.createdAt}))},async delete(t,s){const n=await e(i(t,s),{method:"DELETE",headers:c});n.status!==404&&(n.ok||await a(n,"delete"))}}}const B="limrun-signing-secrets",$=1,p="secrets";function _(){const r=(i,c)=>`${i}:${c}`;function e(){return new Promise((i,c)=>{const a=indexedDB.open(B,$);a.onupgradeneeded=()=>{const t=a.result;t.objectStoreNames.contains(p)||t.createObjectStore(p,{keyPath:"id"})},a.onsuccess=()=>i(a.result),a.onerror=()=>c(a.error??new Error("Open IndexedDB failed"))})}function o(i){return new Promise((c,a)=>{i.onsuccess=()=>c(i.result),i.onerror=()=>a(i.error??new Error("IndexedDB request failed"))})}return{async put(i,c,a){const t=await e(),s=await o(t.transaction(p,"readonly").objectStore(p).get(r(i,c))),n={id:r(i,c),type:i,name:c,data:a,createdAt:s?.createdAt??new Date().toISOString()};return await o(t.transaction(p,"readwrite").objectStore(p).put(n)),{type:i,name:c,createdAt:n.createdAt,data:a}},async get(i,c){const a=await e(),t=await o(a.transaction(p,"readonly").objectStore(p).get(r(i,c)));if(t)return{type:t.type,name:t.name,createdAt:t.createdAt,data:t.data}},async list(){const i=await e();return(await o(i.transaction(p,"readonly").objectStore(p).getAll())).map(a=>({type:a.type,name:a.name,createdAt:a.createdAt}))},async delete(i,c){const a=await e();await o(a.transaction(p,"readwrite").objectStore(p).delete(r(i,c)))}}}function h(r,e){return`${r}/${e}`}async function N({relay:r,teamId:e,secretStore:o,commonName:i,log:c=()=>{}}){const a="DEVELOPMENT",t=h(e,a),s=await S.listAppleCertificates({relay:r,teamId:e,certificateKind:"development"}),n=u=>u===void 0?void 0:s.find(m=>l(m,"certificateId")===u||l(m,"certRequestId")===u),d=await o.get(A,t),f=l(d?.data,"certificateID");if(d&&f&&d.data.certificateP12Base64){const u=n(f);if(u){const m=l(u,"certificateId")??f;return c("Reusing stored Apple certificate",m),{secret:d,certificateId:m,created:!1}}c("Stored certificate is no longer on the team","Minting a new one.")}const g=await S.generateAppleSigningKeyAndCSR({commonName:i??`Limrun ${e}`}),y=await S.createAppleCertificate({relay:r,teamId:e,certificateKind:"development",csrPEM:g.csrPEM}),w=l(y,"certificateId")??l(y,"certRequestId");if(!w)throw new Error("Apple certificate creation did not return a certificate ID.");const v=await S.downloadAppleCertificate({relay:r,teamId:e,certificateKind:"development",certificateId:w});if(!v.rawBodyBase64)throw new Error("Apple certificate download returned no bytes.");const D={certificateP12Base64:S.exportAppleCertificateP12({privateKeyPKCS8Base64:g.privateKeyPKCS8Base64,certificateBase64:v.rawBodyBase64,password:"",friendlyName:`Apple Development ${e}`}),certificateType:a,teamID:e,certificateID:w,serialNumber:E.normalizeCertificateSerial(l(y,"serialNum")),expirationDate:l(y,"expirationDateString")};let C;try{C=await T(o,t,D)}catch(u){throw new Error(`Certificate ${w} was created on the Apple Developer portal but saving its private key to the secret store failed: ${O(u)}. The key cannot be recovered; revoke certificate ${w} at developer.apple.com before retrying, or the retry will mint another certificate against Apple's limit.`)}return c("Apple certificate stored",w),{secret:C,certificateId:w,created:!0}}function O(r){return r instanceof Error?r.message:String(r)}async function j({relay:r,teamId:e,profileId:o,secretStore:i,log:c=()=>{}}){const t=(await S.downloadAppleProfile({relay:r,teamId:e,profileId:o})).rawBodyBase64;if(!t)throw new Error("Apple provisioning profile download returned no bytes.");const s=E.parseProvisioningProfileBase64(t),n=`${e}/${s.uuid??o}`,d=await I(i,n,{provisioningProfileBase64:t,certificateSerialNumbers:s.certificateSerialNumbers.join(","),bundleIDs:s.bundleID,deviceIDs:s.provisionedDevices.join(","),teamID:s.teamID??e,profileName:s.name,uuid:s.uuid,expirationDate:s.expirationDate});return c("Apple provisioning profile stored",n),d}async function k({relay:r,teamId:e}){return S.listAppleProfiles({relay:r,teamId:e,profileKind:"development"})}function l(r,e){const o=r?.[e];if(typeof o=="string")return o;if(typeof o=="number"||typeof o=="boolean")return String(o)}exports.normalizeCertificateSerial=E.normalizeCertificateSerial;exports.APPLE_CERTIFICATE_SECRET_TYPE=A;exports.APPLE_PROVISIONING_PROFILE_SECRET_TYPE=P;exports.appleCertificateSecretName=h;exports.createBrowserSecretStore=_;exports.createLimrunSecretStore=R;exports.ensureAppleCertificateSecret=N;exports.listTeamAppleProfiles=k;exports.putAppleCertificateSecret=T;exports.putAppleProvisioningProfileSecret=I;exports.saveAppleProfileSecret=j;exports.stringField=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../app-store-relay/index.cjs"),T=require("../browser-storage-DLxIqZk5.js"),v="appleCertificate",b="appleProvisioningProfile",I="appStoreConnectApiKey";function h(e){const t={};for(const[o,r]of Object.entries(e))r&&(t[o]=r);return t}async function _(e,t,o){return e.put(v,t,h(o))}async function R(e,t,o){return e.put(b,t,h(o))}async function D(e,t,o){return e.put(I,t,h(o))}function B(e){const t=e.fetch??fetch.bind(globalThis),o=e.apiUrl.replace(/\/+$/,""),r=(n,s)=>`${o}/v1/organizations/${encodeURIComponent(e.organizationId)}/secrets/${encodeURIComponent(n)}/${encodeURIComponent(s)}`,c={Authorization:`Bearer ${e.token}`,"Content-Type":"application/json"};async function a(n,s){let i=`${n.status}`;try{const p=await n.json();p.message&&(i=p.message)}catch{}throw new Error(`Failed to ${s} secret: ${i}`)}return{async put(n,s,i){const p=await t(r(n,s),{method:"PUT",headers:c,body:JSON.stringify({data:i,replace:!0})});p.ok||await a(p,"store");const d=await p.json();return{type:d.type,name:d.name,createdAt:d.createdAt,data:d.data}},async get(n,s){const i=await t(r(n,s),{method:"GET",headers:c});if(i.status===404)return;i.ok||await a(i,"fetch");const p=await i.json();return{type:p.type,name:p.name,createdAt:p.createdAt,data:p.data}},async list(){const n=await t(`${o}/v1/organizations/${encodeURIComponent(e.organizationId)}/secrets`,{method:"GET",headers:c});return n.ok||await a(n,"list"),(await n.json()).filter(i=>i.type===v||i.type===b||i.type===I).map(i=>({type:i.type,name:i.name,createdAt:i.createdAt}))},async delete(n,s){const i=await t(r(n,s),{method:"DELETE",headers:c});i.status!==404&&(i.ok||await a(i,"delete"))}}}const O="limrun-signing-secrets",K=1,l="secrets";function j(){const e=(r,c)=>`${r}:${c}`;function t(){return new Promise((r,c)=>{const a=indexedDB.open(O,K);a.onupgradeneeded=()=>{const n=a.result;n.objectStoreNames.contains(l)||n.createObjectStore(l,{keyPath:"id"})},a.onsuccess=()=>r(a.result),a.onerror=()=>c(a.error??new Error("Open IndexedDB failed"))})}function o(r){return new Promise((c,a)=>{r.onsuccess=()=>c(r.result),r.onerror=()=>a(r.error??new Error("IndexedDB request failed"))})}return{async put(r,c,a){const n=await t(),s=await o(n.transaction(l,"readonly").objectStore(l).get(e(r,c))),i={id:e(r,c),type:r,name:c,data:a,createdAt:s?.createdAt??new Date().toISOString()};return await o(n.transaction(l,"readwrite").objectStore(l).put(i)),{type:r,name:c,createdAt:i.createdAt,data:a}},async get(r,c){const a=await t(),n=await o(a.transaction(l,"readonly").objectStore(l).get(e(r,c)));if(n)return{type:n.type,name:n.name,createdAt:n.createdAt,data:n.data}},async list(){const r=await t();return(await o(r.transaction(l,"readonly").objectStore(l).getAll())).map(a=>({type:a.type,name:a.name,createdAt:a.createdAt}))},async delete(r,c){const a=await t();await o(a.transaction(l,"readwrite").objectStore(l).delete(e(r,c)))}}}function N(e,t){return`${e}/${t}`}async function x({relay:e,teamId:t,secretStore:o,certificateKind:r="development",commonName:c,log:a=()=>{}}){const n=r==="distribution"?"DISTRIBUTION":"DEVELOPMENT",s=N(t,n),i=await u.listAppleCertificates({relay:e,teamId:t,certificateKind:r}),p=S=>S===void 0?void 0:i.find(C=>f(C,"certificateId")===S||f(C,"certRequestId")===S),d=await o.get(v,s),m=f(d?.data,"certificateID");if(d&&m&&d.data.certificateP12Base64){const S=p(m);if(S){const C=f(S,"certificateId")??m;return a("Reusing stored Apple certificate",C),{secret:d,certificateId:C,created:!1}}a("Stored certificate is no longer on the team","Minting a new one.")}const y=await u.generateAppleSigningKeyAndCSR({commonName:c??`Limrun ${t}`}),w=await u.createAppleCertificate({relay:e,teamId:t,certificateKind:r,csrPEM:y.csrPEM}),A=f(w,"certificateId")??f(w,"certRequestId");if(!A)throw new Error("Apple certificate creation did not return a certificate ID.");const E=await u.downloadAppleCertificate({relay:e,teamId:t,certificateKind:r,certificateId:A});if(!E.rawBodyBase64)throw new Error("Apple certificate download returned no bytes.");const g={certificateP12Base64:u.exportAppleCertificateP12({privateKeyPKCS8Base64:y.privateKeyPKCS8Base64,certificateBase64:E.rawBodyBase64,password:"",friendlyName:`Apple ${r==="distribution"?"Distribution":"Development"} ${t}`}),certificateType:n,teamID:t,certificateID:A,serialNumber:T.normalizeCertificateSerial(f(w,"serialNum")),expirationDate:f(w,"expirationDateString")};let P;try{P=await _(o,s,g)}catch(S){throw new Error(`Certificate ${A} was created on the Apple Developer portal but saving its private key to the secret store failed: ${k(S)}. The key cannot be recovered; revoke certificate ${A} at developer.apple.com before retrying, or the retry will mint another certificate against Apple's limit.`)}return a("Apple certificate stored",A),{secret:P,certificateId:A,created:!0}}function k(e){return e instanceof Error?e.message:String(e)}async function L({relay:e,teamId:t,profileId:o,secretStore:r,log:c=()=>{}}){const n=(await u.downloadAppleProfile({relay:e,teamId:t,profileId:o})).rawBodyBase64;if(!n)throw new Error("Apple provisioning profile download returned no bytes.");const s=T.parseProvisioningProfileBase64(n),i=`${t}/${s.uuid??o}`,p=await R(r,i,{provisioningProfileBase64:n,certificateSerialNumbers:s.certificateSerialNumbers.join(","),bundleIDs:s.bundleID,deviceIDs:s.provisionedDevices.join(","),teamID:s.teamID??t,profileName:s.name,uuid:s.uuid,expirationDate:s.expirationDate});return c("Apple provisioning profile stored",i),p}function $(e){return`${e}/APP_STORE_CONNECT_API_KEY`}async function F({relay:e,teamId:t,providerId:o,secretStore:r,nickname:c,roles:a,log:n=()=>{}}){if(!c)throw new Error("A nickname is required to ensure an App Store Connect API key.");o!==void 0&&await u.switchAppStoreConnectProvider({relay:e,providerId:o});const s=$(t),i=await u.listAppStoreConnectApiKeys({relay:e}),p=await r.get(I,s),d=f(p?.data,"keyId");if(p&&d&&p.data.privateKeyP8Base64){if(i.find(P=>P.id===d&&!Y(P.attributes)))return n("Reusing stored App Store Connect API key",d),{secret:p,keyId:d,created:!1};n("Stored App Store Connect API key is no longer active","Minting a new one.")}const y=(await u.createAppStoreConnectApiKey({relay:e,nickname:c,roles:a})).id,w=await u.downloadAppStoreConnectApiKeyPrivateKey({relay:e,keyId:y}),A={privateKeyP8Base64:z(w.privateKeyPem),keyId:y,issuerId:w.issuerId,nickname:c,teamID:t};let E;try{E=await D(r,s,A)}catch(g){throw new Error(`App Store Connect API key ${y} was created but saving its private key to the secret store failed: ${k(g)}. The key cannot be downloaded again; revoke key ${y} in App Store Connect before retrying, or the retry will mint another key.`)}return n("App Store Connect API key stored",y),{secret:E,keyId:y,created:!0}}function Y(e){if(!e)return!1;if(e.isActive===!1)return!0;const t=e.revokingDate??e.revocationDate;return typeof t=="string"&&t!==""}function z(e){const t=new TextEncoder().encode(e);let o="";for(const r of t)o+=String.fromCharCode(r);return btoa(o)}async function M({relay:e,teamId:t,profileKind:o="development"}){return u.listAppleProfiles({relay:e,teamId:t,profileKind:o})}function f(e,t){const o=e?.[t];if(typeof o=="string")return o;if(typeof o=="number"||typeof o=="boolean")return String(o)}exports.normalizeCertificateSerial=T.normalizeCertificateSerial;exports.APPLE_CERTIFICATE_SECRET_TYPE=v;exports.APPLE_PROVISIONING_PROFILE_SECRET_TYPE=b;exports.APP_STORE_CONNECT_API_KEY_SECRET_TYPE=I;exports.appStoreConnectApiKeySecretName=$;exports.appleCertificateSecretName=N;exports.createBrowserSecretStore=j;exports.createLimrunSecretStore=B;exports.ensureAppStoreConnectApiKeySecret=F;exports.ensureAppleCertificateSecret=x;exports.listTeamAppleProfiles=M;exports.putAppStoreConnectApiKeySecret=D;exports.putAppleCertificateSecret=_;exports.putAppleProvisioningProfileSecret=R;exports.saveAppleProfileSecret=L;exports.stringField=f;
@@ -1,6 +1,7 @@
1
+ import { AppleCertificateKind, AppleProfileKind, AppStoreConnectApiKeyRole } from '../app-store-relay';
1
2
  import { AppleRelayWebSocketClient } from '../core/device-install/apple';
2
3
  import { AppleCertificateType, SigningSecret, SigningSecretStore } from '../core/device-install/storage/secret-store';
3
- export { APPLE_CERTIFICATE_SECRET_TYPE, APPLE_PROVISIONING_PROFILE_SECRET_TYPE, createBrowserSecretStore, createLimrunSecretStore, putAppleCertificateSecret, putAppleProvisioningProfileSecret, type AppleCertificateSecretData, type AppleCertificateType, type AppleProvisioningProfileSecretData, type LimrunSecretStoreOptions, type SigningSecret, type SigningSecretData, type SigningSecretMetadata, type SigningSecretStore, type SigningSecretType, } from '../core/device-install/storage/secret-store';
4
+ export { APP_STORE_CONNECT_API_KEY_SECRET_TYPE, APPLE_CERTIFICATE_SECRET_TYPE, APPLE_PROVISIONING_PROFILE_SECRET_TYPE, createBrowserSecretStore, createLimrunSecretStore, putAppleCertificateSecret, putAppleProvisioningProfileSecret, putAppStoreConnectApiKeySecret, type AppleCertificateSecretData, type AppleCertificateType, type AppleProvisioningProfileSecretData, type AppStoreConnectApiKeySecretData, type LimrunSecretStoreOptions, type SigningSecret, type SigningSecretData, type SigningSecretMetadata, type SigningSecretStore, type SigningSecretType, } from '../core/device-install/storage/secret-store';
4
5
  export { normalizeCertificateSerial } from '../core/device-install/storage/browser-storage';
5
6
  /**
6
7
  * Conventional secret name of a team's certificate bundle. One bundle per
@@ -12,6 +13,11 @@ export type EnsureAppleCertificateInput = {
12
13
  relay: AppleRelayWebSocketClient;
13
14
  teamId: string;
14
15
  secretStore: SigningSecretStore;
16
+ /**
17
+ * Which portal certificate kind to ensure. Ad-hoc and App Store signing
18
+ * both use the distribution certificate. Defaults to development.
19
+ */
20
+ certificateKind?: AppleCertificateKind;
15
21
  /** Common name used when minting a new certificate. */
16
22
  commonName?: string;
17
23
  log?: (message: string, detail?: string) => void;
@@ -23,16 +29,17 @@ export type EnsureAppleCertificateResult = {
23
29
  created: boolean;
24
30
  };
25
31
  /**
26
- * Returns a usable development certificate secret for the team, reusing the
27
- * stored one when its certificate is still on the team and minting a new
28
- * one otherwise. Apple caps development certificates at 2 and never returns
29
- * private keys, so reuse of the stored p12 is strongly preferred.
32
+ * Returns a usable certificate secret of the requested kind for the team,
33
+ * reusing the stored one when its certificate is still on the team and
34
+ * minting a new one otherwise. Apple caps certificates per kind (2 for
35
+ * development, 3 for distribution) and never returns private keys, so
36
+ * reuse of the stored p12 is strongly preferred.
30
37
  *
31
38
  * Durability of the stored material is the secret store's concern:
32
39
  * implementors who want retries or fallbacks build them into their
33
40
  * SigningSecretStore.
34
41
  */
35
- export declare function ensureAppleCertificateSecret({ relay, teamId, secretStore, commonName, log, }: EnsureAppleCertificateInput): Promise<EnsureAppleCertificateResult>;
42
+ export declare function ensureAppleCertificateSecret({ relay, teamId, secretStore, certificateKind, commonName, log, }: EnsureAppleCertificateInput): Promise<EnsureAppleCertificateResult>;
36
43
  export type SaveAppleProfileInput = {
37
44
  relay: AppleRelayWebSocketClient;
38
45
  teamId: string;
@@ -49,11 +56,55 @@ export type SaveAppleProfileInput = {
49
56
  * consumers filter on.
50
57
  */
51
58
  export declare function saveAppleProfileSecret({ relay, teamId, profileId, secretStore, log, }: SaveAppleProfileInput): Promise<SigningSecret>;
59
+ /**
60
+ * Conventional secret name of a team's App Store Connect API key: one
61
+ * shared key per team.
62
+ */
63
+ export declare function appStoreConnectApiKeySecretName(teamId: string): string;
64
+ export type EnsureAppStoreConnectApiKeyInput = {
65
+ relay: AppleRelayWebSocketClient;
66
+ teamId: string;
67
+ /**
68
+ * Numeric provider ID of the team from the Apple team list. When given,
69
+ * the App Store Connect session is switched to this provider first;
70
+ * required for accounts that belong to multiple teams.
71
+ */
72
+ providerId?: string | number;
73
+ secretStore: SigningSecretStore;
74
+ /** Display name for a newly minted key. Required; there is no default. */
75
+ nickname: string;
76
+ /** Roles of a newly minted key. Defaults to APP_MANAGER. */
77
+ roles?: AppStoreConnectApiKeyRole[];
78
+ log?: (message: string, detail?: string) => void;
79
+ };
80
+ export type EnsureAppStoreConnectApiKeyResult = {
81
+ secret: SigningSecret;
82
+ keyId: string;
83
+ /** True when a new key was minted instead of reusing the stored one. */
84
+ created: boolean;
85
+ };
86
+ /**
87
+ * Returns a usable App Store Connect API key secret for the team, reusing
88
+ * the stored one when its key is still active and minting a new one
89
+ * otherwise. Apple serves a key's private half exactly once (at creation
90
+ * time through the sparse fieldset download), so reuse of the stored .p8
91
+ * is strongly preferred.
92
+ *
93
+ * The session user must be a team Admin to list or create keys.
94
+ */
95
+ export declare function ensureAppStoreConnectApiKeySecret({ relay, teamId, providerId, secretStore, nickname, roles, log, }: EnsureAppStoreConnectApiKeyInput): Promise<EnsureAppStoreConnectApiKeyResult>;
52
96
  export type ListTeamProfilesInput = {
53
97
  relay: AppleRelayWebSocketClient;
54
98
  teamId: string;
99
+ /**
100
+ * Which portal profile listing to use. The development listing is
101
+ * unfiltered on the portal side and returns profiles of every
102
+ * distribution method; adhoc narrows to ad-hoc profiles. Defaults to
103
+ * development.
104
+ */
105
+ profileKind?: AppleProfileKind;
55
106
  };
56
- /** Lists the team's development provisioning profiles from the portal. */
57
- export declare function listTeamAppleProfiles({ relay, teamId }: ListTeamProfilesInput): Promise<Record<string, unknown>[]>;
107
+ /** Lists the team's provisioning profiles from the portal. */
108
+ export declare function listTeamAppleProfiles({ relay, teamId, profileKind, }: ListTeamProfilesInput): Promise<Record<string, unknown>[]>;
58
109
  /** Read a string-ish value from a loosely typed portal record. */
59
110
  export declare function stringField(record: Record<string, unknown> | undefined, key: string): string | undefined;
@@ -1,227 +1,291 @@
1
- import { listAppleCertificates as h, generateAppleSigningKeyAndCSR as C, createAppleCertificate as D, downloadAppleCertificate as I, exportAppleCertificateP12 as T, downloadAppleProfile as $, listAppleProfiles as B } from "../app-store-relay/index.js";
2
- import { l as R, f as N } from "../browser-storage-BnO-Ma-e.mjs";
3
- const A = "appleCertificate", v = "appleProvisioningProfile";
4
- function P(r) {
5
- const e = {};
6
- for (const [o, n] of Object.entries(r))
7
- n && (e[o] = n);
8
- return e;
9
- }
10
- async function j(r, e, o) {
11
- return r.put(A, e, P(o));
12
- }
13
- async function O(r, e, o) {
14
- return r.put(v, e, P(o));
15
- }
16
- function z(r) {
17
- const e = r.fetch ?? fetch.bind(globalThis), o = r.apiUrl.replace(/\/+$/, ""), n = (t, s) => `${o}/v1/organizations/${encodeURIComponent(r.organizationId)}/secrets/${encodeURIComponent(
18
- t
1
+ import { listAppleCertificates as T, generateAppleSigningKeyAndCSR as D, createAppleCertificate as k, downloadAppleCertificate as $, exportAppleCertificateP12 as B, downloadAppleProfile as N, switchAppStoreConnectProvider as R, listAppStoreConnectApiKeys as _, createAppStoreConnectApiKey as O, downloadAppStoreConnectApiKeyPrivateKey as j, listAppleProfiles as K } from "../app-store-relay/index.js";
2
+ import { l as x, f as U } from "../browser-storage-BnO-Ma-e.mjs";
3
+ const C = "appleCertificate", I = "appleProvisioningProfile", v = "appStoreConnectApiKey";
4
+ function b(e) {
5
+ const t = {};
6
+ for (const [o, r] of Object.entries(e))
7
+ r && (t[o] = r);
8
+ return t;
9
+ }
10
+ async function L(e, t, o) {
11
+ return e.put(C, t, b(o));
12
+ }
13
+ async function M(e, t, o) {
14
+ return e.put(I, t, b(o));
15
+ }
16
+ async function z(e, t, o) {
17
+ return e.put(v, t, b(o));
18
+ }
19
+ function W(e) {
20
+ const t = e.fetch ?? fetch.bind(globalThis), o = e.apiUrl.replace(/\/+$/, ""), r = (n, s) => `${o}/v1/organizations/${encodeURIComponent(e.organizationId)}/secrets/${encodeURIComponent(
21
+ n
19
22
  )}/${encodeURIComponent(s)}`, c = {
20
- Authorization: `Bearer ${r.token}`,
23
+ Authorization: `Bearer ${e.token}`,
21
24
  "Content-Type": "application/json"
22
25
  };
23
- async function a(t, s) {
24
- let i = `${t.status}`;
26
+ async function a(n, s) {
27
+ let i = `${n.status}`;
25
28
  try {
26
- const d = await t.json();
29
+ const d = await n.json();
27
30
  d.message && (i = d.message);
28
31
  } catch {
29
32
  }
30
33
  throw new Error(`Failed to ${s} secret: ${i}`);
31
34
  }
32
35
  return {
33
- async put(t, s, i) {
34
- const d = await e(n(t, s), {
36
+ async put(n, s, i) {
37
+ const d = await t(r(n, s), {
35
38
  method: "PUT",
36
39
  headers: c,
37
40
  body: JSON.stringify({ data: i, replace: !0 })
38
41
  });
39
42
  d.ok || await a(d, "store");
40
- const l = await d.json();
41
- return { type: l.type, name: l.name, createdAt: l.createdAt, data: l.data };
43
+ const p = await d.json();
44
+ return { type: p.type, name: p.name, createdAt: p.createdAt, data: p.data };
42
45
  },
43
- async get(t, s) {
44
- const i = await e(n(t, s), { method: "GET", headers: c });
46
+ async get(n, s) {
47
+ const i = await t(r(n, s), { method: "GET", headers: c });
45
48
  if (i.status === 404) return;
46
49
  i.ok || await a(i, "fetch");
47
50
  const d = await i.json();
48
51
  return { type: d.type, name: d.name, createdAt: d.createdAt, data: d.data };
49
52
  },
50
53
  async list() {
51
- const t = await e(
52
- `${o}/v1/organizations/${encodeURIComponent(r.organizationId)}/secrets`,
54
+ const n = await t(
55
+ `${o}/v1/organizations/${encodeURIComponent(e.organizationId)}/secrets`,
53
56
  { method: "GET", headers: c }
54
57
  );
55
- return t.ok || await a(t, "list"), (await t.json()).filter(
56
- (i) => i.type === A || i.type === v
58
+ return n.ok || await a(n, "list"), (await n.json()).filter(
59
+ (i) => i.type === C || i.type === I || i.type === v
57
60
  ).map((i) => ({ type: i.type, name: i.name, createdAt: i.createdAt }));
58
61
  },
59
- async delete(t, s) {
60
- const i = await e(n(t, s), { method: "DELETE", headers: c });
62
+ async delete(n, s) {
63
+ const i = await t(r(n, s), { method: "DELETE", headers: c });
61
64
  i.status !== 404 && (i.ok || await a(i, "delete"));
62
65
  }
63
66
  };
64
67
  }
65
- const _ = "limrun-signing-secrets", k = 1, p = "secrets";
66
- function M() {
67
- const r = (n, c) => `${n}:${c}`;
68
- function e() {
69
- return new Promise((n, c) => {
70
- const a = indexedDB.open(_, k);
68
+ const F = "limrun-signing-secrets", Y = 1, f = "secrets";
69
+ function X() {
70
+ const e = (r, c) => `${r}:${c}`;
71
+ function t() {
72
+ return new Promise((r, c) => {
73
+ const a = indexedDB.open(F, Y);
71
74
  a.onupgradeneeded = () => {
72
- const t = a.result;
73
- t.objectStoreNames.contains(p) || t.createObjectStore(p, { keyPath: "id" });
74
- }, a.onsuccess = () => n(a.result), a.onerror = () => c(a.error ?? new Error("Open IndexedDB failed"));
75
+ const n = a.result;
76
+ n.objectStoreNames.contains(f) || n.createObjectStore(f, { keyPath: "id" });
77
+ }, a.onsuccess = () => r(a.result), a.onerror = () => c(a.error ?? new Error("Open IndexedDB failed"));
75
78
  });
76
79
  }
77
- function o(n) {
80
+ function o(r) {
78
81
  return new Promise((c, a) => {
79
- n.onsuccess = () => c(n.result), n.onerror = () => a(n.error ?? new Error("IndexedDB request failed"));
82
+ r.onsuccess = () => c(r.result), r.onerror = () => a(r.error ?? new Error("IndexedDB request failed"));
80
83
  });
81
84
  }
82
85
  return {
83
- async put(n, c, a) {
84
- const t = await e(), s = await o(
85
- t.transaction(p, "readonly").objectStore(p).get(r(n, c))
86
+ async put(r, c, a) {
87
+ const n = await t(), s = await o(
88
+ n.transaction(f, "readonly").objectStore(f).get(e(r, c))
86
89
  ), i = {
87
- id: r(n, c),
88
- type: n,
90
+ id: e(r, c),
91
+ type: r,
89
92
  name: c,
90
93
  data: a,
91
94
  createdAt: s?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
92
95
  };
93
96
  return await o(
94
- t.transaction(p, "readwrite").objectStore(p).put(i)
95
- ), { type: n, name: c, createdAt: i.createdAt, data: a };
97
+ n.transaction(f, "readwrite").objectStore(f).put(i)
98
+ ), { type: r, name: c, createdAt: i.createdAt, data: a };
96
99
  },
97
- async get(n, c) {
98
- const a = await e(), t = await o(
99
- a.transaction(p, "readonly").objectStore(p).get(r(n, c))
100
+ async get(r, c) {
101
+ const a = await t(), n = await o(
102
+ a.transaction(f, "readonly").objectStore(f).get(e(r, c))
100
103
  );
101
- if (t)
102
- return { type: t.type, name: t.name, createdAt: t.createdAt, data: t.data };
104
+ if (n)
105
+ return { type: n.type, name: n.name, createdAt: n.createdAt, data: n.data };
103
106
  },
104
107
  async list() {
105
- const n = await e();
108
+ const r = await t();
106
109
  return (await o(
107
- n.transaction(p, "readonly").objectStore(p).getAll()
110
+ r.transaction(f, "readonly").objectStore(f).getAll()
108
111
  )).map((a) => ({ type: a.type, name: a.name, createdAt: a.createdAt }));
109
112
  },
110
- async delete(n, c) {
111
- const a = await e();
113
+ async delete(r, c) {
114
+ const a = await t();
112
115
  await o(
113
- a.transaction(p, "readwrite").objectStore(p).delete(r(n, c))
116
+ a.transaction(f, "readwrite").objectStore(f).delete(e(r, c))
114
117
  );
115
118
  }
116
119
  };
117
120
  }
118
- function x(r, e) {
119
- return `${r}/${e}`;
121
+ function G(e, t) {
122
+ return `${e}/${t}`;
120
123
  }
121
- async function F({
122
- relay: r,
123
- teamId: e,
124
+ async function Z({
125
+ relay: e,
126
+ teamId: t,
124
127
  secretStore: o,
125
- commonName: n,
126
- log: c = () => {
128
+ certificateKind: r = "development",
129
+ commonName: c,
130
+ log: a = () => {
127
131
  }
128
132
  }) {
129
- const a = "DEVELOPMENT", t = x(e, a), s = await h({ relay: r, teamId: e, certificateKind: "development" }), i = (f) => f === void 0 ? void 0 : s.find(
130
- (m) => u(m, "certificateId") === f || u(m, "certRequestId") === f
131
- ), d = await o.get(A, t), l = u(d?.data, "certificateID");
132
- if (d && l && d.data.certificateP12Base64) {
133
- const f = i(l);
134
- if (f) {
135
- const m = u(f, "certificateId") ?? l;
136
- return c("Reusing stored Apple certificate", m), { secret: d, certificateId: m, created: !1 };
133
+ const n = r === "distribution" ? "DISTRIBUTION" : "DEVELOPMENT", s = G(t, n), i = await T({ relay: e, teamId: t, certificateKind: r }), d = (w) => w === void 0 ? void 0 : i.find(
134
+ (E) => y(E, "certificateId") === w || y(E, "certRequestId") === w
135
+ ), p = await o.get(C, s), P = y(p?.data, "certificateID");
136
+ if (p && P && p.data.certificateP12Base64) {
137
+ const w = d(P);
138
+ if (w) {
139
+ const E = y(w, "certificateId") ?? P;
140
+ return a("Reusing stored Apple certificate", E), { secret: p, certificateId: E, created: !1 };
137
141
  }
138
- c("Stored certificate is no longer on the team", "Minting a new one.");
142
+ a("Stored certificate is no longer on the team", "Minting a new one.");
139
143
  }
140
- const S = await C({ commonName: n ?? `Limrun ${e}` }), y = await D({
141
- relay: r,
142
- teamId: e,
143
- certificateKind: "development",
144
- csrPEM: S.csrPEM
145
- }), w = u(y, "certificateId") ?? u(y, "certRequestId");
146
- if (!w)
144
+ const l = await D({ commonName: c ?? `Limrun ${t}` }), A = await k({
145
+ relay: e,
146
+ teamId: t,
147
+ certificateKind: r,
148
+ csrPEM: l.csrPEM
149
+ }), u = y(A, "certificateId") ?? y(A, "certRequestId");
150
+ if (!u)
147
151
  throw new Error("Apple certificate creation did not return a certificate ID.");
148
- const g = await I({
149
- relay: r,
150
- teamId: e,
151
- certificateKind: "development",
152
- certificateId: w
152
+ const S = await $({
153
+ relay: e,
154
+ teamId: t,
155
+ certificateKind: r,
156
+ certificateId: u
153
157
  });
154
- if (!g.rawBodyBase64)
158
+ if (!S.rawBodyBase64)
155
159
  throw new Error("Apple certificate download returned no bytes.");
156
- const b = {
157
- certificateP12Base64: T({
158
- privateKeyPKCS8Base64: S.privateKeyPKCS8Base64,
159
- certificateBase64: g.rawBodyBase64,
160
+ const g = {
161
+ certificateP12Base64: B({
162
+ privateKeyPKCS8Base64: l.privateKeyPKCS8Base64,
163
+ certificateBase64: S.rawBodyBase64,
160
164
  password: "",
161
- friendlyName: `Apple Development ${e}`
165
+ friendlyName: `Apple ${r === "distribution" ? "Distribution" : "Development"} ${t}`
162
166
  }),
163
- certificateType: a,
164
- teamID: e,
165
- certificateID: w,
167
+ certificateType: n,
168
+ teamID: t,
169
+ certificateID: u,
166
170
  // Normalized so it equals the serials profiles reference.
167
- serialNumber: R(u(y, "serialNum")),
168
- expirationDate: u(y, "expirationDateString")
171
+ serialNumber: x(y(A, "serialNum")),
172
+ expirationDate: y(A, "expirationDateString")
169
173
  };
170
- let E;
174
+ let m;
171
175
  try {
172
- E = await j(o, t, b);
173
- } catch (f) {
176
+ m = await L(o, s, g);
177
+ } catch (w) {
174
178
  throw new Error(
175
- `Certificate ${w} was created on the Apple Developer portal but saving its private key to the secret store failed: ${K(f)}. The key cannot be recovered; revoke certificate ${w} at developer.apple.com before retrying, or the retry will mint another certificate against Apple's limit.`
179
+ `Certificate ${u} was created on the Apple Developer portal but saving its private key to the secret store failed: ${h(w)}. The key cannot be recovered; revoke certificate ${u} at developer.apple.com before retrying, or the retry will mint another certificate against Apple's limit.`
176
180
  );
177
181
  }
178
- return c("Apple certificate stored", w), { secret: E, certificateId: w, created: !0 };
182
+ return a("Apple certificate stored", u), { secret: m, certificateId: u, created: !0 };
179
183
  }
180
- function K(r) {
181
- return r instanceof Error ? r.message : String(r);
184
+ function h(e) {
185
+ return e instanceof Error ? e.message : String(e);
182
186
  }
183
- async function G({
184
- relay: r,
185
- teamId: e,
187
+ async function ee({
188
+ relay: e,
189
+ teamId: t,
186
190
  profileId: o,
187
- secretStore: n,
191
+ secretStore: r,
188
192
  log: c = () => {
189
193
  }
190
194
  }) {
191
- const t = (await $({ relay: r, teamId: e, profileId: o })).rawBodyBase64;
192
- if (!t)
195
+ const n = (await N({ relay: e, teamId: t, profileId: o })).rawBodyBase64;
196
+ if (!n)
193
197
  throw new Error("Apple provisioning profile download returned no bytes.");
194
- const s = N(t), i = `${e}/${s.uuid ?? o}`, d = await O(n, i, {
195
- provisioningProfileBase64: t,
198
+ const s = U(n), i = `${t}/${s.uuid ?? o}`, d = await M(r, i, {
199
+ provisioningProfileBase64: n,
196
200
  certificateSerialNumbers: s.certificateSerialNumbers.join(","),
197
201
  bundleIDs: s.bundleID,
198
202
  deviceIDs: s.provisionedDevices.join(","),
199
- teamID: s.teamID ?? e,
203
+ teamID: s.teamID ?? t,
200
204
  profileName: s.name,
201
205
  uuid: s.uuid,
202
206
  expirationDate: s.expirationDate
203
207
  });
204
208
  return c("Apple provisioning profile stored", i), d;
205
209
  }
206
- async function V({ relay: r, teamId: e }) {
207
- return B({ relay: r, teamId: e, profileKind: "development" });
210
+ function V(e) {
211
+ return `${e}/APP_STORE_CONNECT_API_KEY`;
212
+ }
213
+ async function te({
214
+ relay: e,
215
+ teamId: t,
216
+ providerId: o,
217
+ secretStore: r,
218
+ nickname: c,
219
+ roles: a,
220
+ log: n = () => {
221
+ }
222
+ }) {
223
+ if (!c)
224
+ throw new Error("A nickname is required to ensure an App Store Connect API key.");
225
+ o !== void 0 && await R({ relay: e, providerId: o });
226
+ const s = V(t), i = await _({ relay: e }), d = await r.get(v, s), p = y(d?.data, "keyId");
227
+ if (d && p && d.data.privateKeyP8Base64) {
228
+ if (i.find((m) => m.id === p && !q(m.attributes)))
229
+ return n("Reusing stored App Store Connect API key", p), { secret: d, keyId: p, created: !1 };
230
+ n("Stored App Store Connect API key is no longer active", "Minting a new one.");
231
+ }
232
+ const l = (await O({ relay: e, nickname: c, roles: a })).id, A = await j({ relay: e, keyId: l }), u = {
233
+ privateKeyP8Base64: J(A.privateKeyPem),
234
+ keyId: l,
235
+ issuerId: A.issuerId,
236
+ nickname: c,
237
+ teamID: t
238
+ };
239
+ let S;
240
+ try {
241
+ S = await z(r, s, u);
242
+ } catch (g) {
243
+ throw new Error(
244
+ `App Store Connect API key ${l} was created but saving its private key to the secret store failed: ${h(g)}. The key cannot be downloaded again; revoke key ${l} in App Store Connect before retrying, or the retry will mint another key.`
245
+ );
246
+ }
247
+ return n("App Store Connect API key stored", l), { secret: S, keyId: l, created: !0 };
248
+ }
249
+ function q(e) {
250
+ if (!e) return !1;
251
+ if (e.isActive === !1) return !0;
252
+ const t = e.revokingDate ?? e.revocationDate;
253
+ return typeof t == "string" && t !== "";
254
+ }
255
+ function J(e) {
256
+ const t = new TextEncoder().encode(e);
257
+ let o = "";
258
+ for (const r of t)
259
+ o += String.fromCharCode(r);
260
+ return btoa(o);
261
+ }
262
+ async function re({
263
+ relay: e,
264
+ teamId: t,
265
+ profileKind: o = "development"
266
+ }) {
267
+ return K({ relay: e, teamId: t, profileKind: o });
208
268
  }
209
- function u(r, e) {
210
- const o = r?.[e];
269
+ function y(e, t) {
270
+ const o = e?.[t];
211
271
  if (typeof o == "string") return o;
212
272
  if (typeof o == "number" || typeof o == "boolean") return String(o);
213
273
  }
214
274
  export {
215
- A as APPLE_CERTIFICATE_SECRET_TYPE,
216
- v as APPLE_PROVISIONING_PROFILE_SECRET_TYPE,
217
- x as appleCertificateSecretName,
218
- M as createBrowserSecretStore,
219
- z as createLimrunSecretStore,
220
- F as ensureAppleCertificateSecret,
221
- V as listTeamAppleProfiles,
222
- R as normalizeCertificateSerial,
223
- j as putAppleCertificateSecret,
224
- O as putAppleProvisioningProfileSecret,
225
- G as saveAppleProfileSecret,
226
- u as stringField
275
+ C as APPLE_CERTIFICATE_SECRET_TYPE,
276
+ I as APPLE_PROVISIONING_PROFILE_SECRET_TYPE,
277
+ v as APP_STORE_CONNECT_API_KEY_SECRET_TYPE,
278
+ V as appStoreConnectApiKeySecretName,
279
+ G as appleCertificateSecretName,
280
+ X as createBrowserSecretStore,
281
+ W as createLimrunSecretStore,
282
+ te as ensureAppStoreConnectApiKeySecret,
283
+ Z as ensureAppleCertificateSecret,
284
+ re as listTeamAppleProfiles,
285
+ x as normalizeCertificateSerial,
286
+ z as putAppStoreConnectApiKeySecret,
287
+ L as putAppleCertificateSecret,
288
+ M as putAppleProvisioningProfileSecret,
289
+ ee as saveAppleProfileSecret,
290
+ y as stringField
227
291
  };
@@ -0,0 +1 @@
1
+ "use strict";const R=require("./gsa-srp-CCIfUz7Y.js");class g{constructor(t,r,o){this.apiUrl=t,this.token=r,this.organizationId=o}socket;nextId=1;pending=new Map;async connect(){if(this.socket&&this.socket.readyState===WebSocket.OPEN)return;const t=new WebSocket(E(this.apiUrl,this.token,this.organizationId));this.socket=t,t.onmessage=r=>this.handleMessage(r),t.onclose=()=>this.rejectPending(new Error("Apple relay WebSocket closed")),t.onerror=()=>this.rejectPending(new Error("Apple relay WebSocket failed")),await new Promise((r,o)=>{t.onopen=()=>r(),t.onerror=()=>o(new Error("Apple relay WebSocket connection failed"))})}request(t,r){const o=this.socket;if(!o||o.readyState!==WebSocket.OPEN)throw new Error("Apple relay WebSocket is not connected.");const a=String(this.nextId++),n=new Promise((p,i)=>{this.pending.set(a,{resolve:w=>p(x(w)),reject:i})});return o.send(JSON.stringify({id:a,type:t,...r===void 0?{}:{payload:r}})),n}close(){this.rejectPending(new Error("Apple relay WebSocket closed")),this.socket?.close(),this.socket=void 0}handleMessage(t){const r=JSON.parse(String(t.data)),o=this.pending.get(r.id);if(o){if(this.pending.delete(r.id),!r.ok){o.reject(new Error(r.error||"Apple relay request failed"));return}if(!r.response){o.reject(new Error("Apple relay response was empty."));return}o.resolve(r.response)}}rejectPending(t){for(const r of this.pending.values())r.reject(t);this.pending.clear()}}async function m(e,t,r){const o=new g(e,t,r);return await o.connect(),o}async function S(e,t){return e.request("srpInit",t)}async function A(e,t){return e.request("srpComplete",t)}async function P(e){return e.request("triggerTrustedDevice2FA")}async function b(e,t,r="sms"){return e.request("triggerPhone2FA",{phoneNumberId:t,mode:r})}async function k(e,t){return e.request("submitTrustedDevice2FA",{code:t})}async function T(e,t,r,o="sms"){return e.request("submitPhone2FA",{phoneNumberId:t,mode:o,code:r})}async function v(e){return e.request("finalize")}async function q(e,t){return e.request("provisioning",t)}async function F(e,t){return e.request("appstoreconnect",t)}function x(e){if(e.body!==void 0||!e.rawBody)return e;try{return{...e,body:JSON.parse(e.rawBody)}}catch{return e}}function E(e,t,r){const o=new URL(e);return o.protocol=o.protocol==="https:"?"wss:":"ws:",o.pathname=`${o.pathname.replace(/\/$/,"")}/ios/appstoreconnect/ws`,t&&o.searchParams.set("token",t),r&&o.searchParams.set("organization",r),o.toString()}async function N({registryApiUrl:e,accountName:t,password:r,token:o,organizationId:a}){const n=await m(e,o,a);try{const p=new R.AppleGsaSrpClient(t),i=await S(n,await p.init());if(i.status<200||i.status>=300)throw new Error(`Apple SRP init failed: HTTP ${i.status} ${i.rawBody??""}`.trim());if(!i.body)throw new Error("Apple SRP init response did not include a body.");const w=await p.complete(r,i.body),u=await A(n,{...w,rememberMe:!1,trustTokens:[]}),y=u.status===409;let s,d={type:"trustedDevice"};if(y){s=await P(n);const c=W(s.body);if(s.status===412||C(s.body)){if(!c)throw new Error("Apple requested phone verification but did not include a trusted phone number.");d={type:"phone",phoneNumberId:c.id,mode:c.pushMode??"sms"},s=await b(n,c.id,c.pushMode??"sms")}if(s.status<200||s.status>=300)throw new Error(`Apple two-factor challenge failed: HTTP ${s.status} ${s.rawBody??""}`.trim())}else if(u.status<200||u.status>=300)throw new Error(`Apple SRP complete failed: HTTP ${u.status} ${u.rawBody??""}`.trim());return{relay:n,completeResponse:u,twoFactorChallengeResponse:s,requiresTwoFactor:y,finishTwoFactor:async c=>{const l=d.type==="phone"?await T(n,d.phoneNumberId,c,d.mode):await k(n,c);if(l.status<200||l.status>=300)throw new Error(`Apple two-factor code failed: HTTP ${l.status} ${l.rawBody??""}`.trim());return l},finalize:async()=>v(n),close:async()=>n.close()}}catch(p){throw n.close(),p}}function C(e){return h(e)&&e.noTrustedDevices===!0}function W(e){if(!h(e))return;const t=h(e.phoneNumberVerification)?e.phoneNumberVerification:void 0,r=f(t?.trustedPhoneNumber)??f(e.trustedPhoneNumber)??f(e.phoneNumber);if(!r)return;const o=r.id;if(typeof o!="number")return;const a=typeof r.pushMode=="string"?r.pushMode:typeof e.mode=="string"?e.mode:void 0;return{id:o,pushMode:a}}function f(e){return h(e)?e:void 0}function h(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}exports.AppleRelayWebSocketClient=g;exports.fetchAppleAccountSession=v;exports.openAppleRelayWebSocket=m;exports.proxyAppStoreConnectRequest=F;exports.proxyPhoneTwoFactorCode=T;exports.proxyProvisioningRequest=q;exports.proxySrpComplete=A;exports.proxySrpInit=S;exports.proxyTwoFactorCode=k;exports.startBrowserOwnedAppleIDLogin=N;exports.triggerPhoneTwoFactor=b;exports.triggerTrustedDeviceTwoFactor=P;