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

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 (71) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.js +5 -5
  3. package/dist/app-store-relay/react.cjs +1 -1
  4. package/dist/app-store-relay/react.d.ts +1 -1
  5. package/dist/app-store-relay/react.js +34 -31
  6. package/dist/apple-credentials/index.cjs +1 -0
  7. package/dist/apple-credentials/index.d.ts +59 -0
  8. package/dist/apple-credentials/index.js +227 -0
  9. package/dist/browser-storage-BnO-Ma-e.mjs +219 -0
  10. package/dist/browser-storage-DLxIqZk5.js +1 -0
  11. package/dist/client-D1drDXxE.js +1 -0
  12. package/dist/{client-CBX-hLnL.mjs → client-DSuNtWDv.mjs} +2 -7
  13. package/dist/core/device-install/operations/operations.d.ts +1 -1
  14. package/dist/core/device-install/storage/browser-storage.d.ts +8 -0
  15. package/dist/core/device-install/storage/index.d.ts +1 -0
  16. package/dist/core/device-install/storage/secret-store.d.ts +101 -0
  17. package/dist/core/device-install/types.d.ts +6 -0
  18. package/dist/core/errors.d.ts +1 -0
  19. package/dist/core/play-publish/google.d.ts +13 -0
  20. package/dist/core/play-publish/publish.d.ts +34 -0
  21. package/dist/device-build/index.cjs +1 -1
  22. package/dist/device-build/index.js +25 -24
  23. package/dist/device-build/react.cjs +1 -1
  24. package/dist/device-build/react.js +42 -43
  25. package/dist/device-install/index.cjs +1 -1
  26. package/dist/device-install/index.js +164 -160
  27. package/dist/device-install/react.cjs +1 -1
  28. package/dist/device-install/react.js +61 -60
  29. package/dist/errors-BSkqS7U-.js +1 -0
  30. package/dist/errors-gy8yQJos.mjs +6 -0
  31. package/dist/gsa-srp-Bme3JLEi.mjs +266 -0
  32. package/dist/gsa-srp-CCIfUz7Y.js +1 -0
  33. package/dist/index-ChhtuQ7e.js +22 -0
  34. package/dist/index-YDu8K9a4.mjs +11279 -0
  35. package/dist/play-publish/index.cjs +1 -0
  36. package/dist/play-publish/index.d.ts +2 -0
  37. package/dist/play-publish/index.js +109 -0
  38. package/dist/play-publish/react.cjs +1 -0
  39. package/dist/play-publish/react.d.ts +31 -0
  40. package/dist/play-publish/react.js +91 -0
  41. package/dist/{provisioning-DKbkBO-p.mjs → provisioning-B_DefBEp.mjs} +9 -9
  42. package/dist/{provisioning-Va0PH4Kk.js → provisioning-BlQMccX_.js} +1 -1
  43. package/package.json +18 -2
  44. package/src/app-store-relay/index.test.ts +6 -6
  45. package/src/app-store-relay/react.ts +6 -5
  46. package/src/apple-credentials/index.test.ts +158 -0
  47. package/src/apple-credentials/index.ts +241 -0
  48. package/src/core/device-install/apple/client.ts +1 -6
  49. package/src/core/device-install/apple/relay.ts +1 -4
  50. package/src/core/device-install/operations/operations.ts +8 -5
  51. package/src/core/device-install/storage/browser-storage.test.ts +65 -0
  52. package/src/core/device-install/storage/browser-storage.ts +33 -0
  53. package/src/core/device-install/storage/index.ts +1 -0
  54. package/src/core/device-install/storage/secret-store.ts +298 -0
  55. package/src/core/device-install/types.ts +6 -0
  56. package/src/core/errors.ts +3 -0
  57. package/src/core/play-publish/google.ts +113 -0
  58. package/src/core/play-publish/publish.test.ts +68 -0
  59. package/src/core/play-publish/publish.ts +89 -0
  60. package/src/device-build/react.ts +1 -4
  61. package/src/device-install/demo/demo.tsx +2 -8
  62. package/src/device-install/react.ts +31 -31
  63. package/src/play-publish/README.md +66 -0
  64. package/src/play-publish/index.ts +12 -0
  65. package/src/play-publish/react.ts +208 -0
  66. package/vite.config.ts +3 -0
  67. package/dist/browser-storage-Cx9eW-bm.mjs +0 -205
  68. package/dist/browser-storage-jJaIht4K.js +0 -1
  69. package/dist/client-BtC4n_qf.js +0 -1
  70. package/dist/index-CMeQfhYy.js +0 -22
  71. package/dist/index-DFdCvi2_.mjs +0 -11543
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../client-BtC4n_qf.js"),c=require("../index-CMeQfhYy.js"),p=require("../provisioning-Va0PH4Kk.js"),P={name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-256"};async function I(e){if(!crypto.subtle)throw new Error("WebCrypto is not available in this browser.");const t=await crypto.subtle.generateKey(P,!0,["sign","verify"]),r=new Uint8Array(await crypto.subtle.exportKey("spki",t.publicKey)),n=d(C(0),h(e),r,B(0,new Uint8Array)),i=new Uint8Array(await crypto.subtle.sign("RSASSA-PKCS1-v1_5",t.privateKey,N(n))),o=d(n,d(b("1.2.840.113549.1.1.11"),R()),E(i)),s=new Uint8Array(await crypto.subtle.exportKey("pkcs8",t.privateKey));return{privateKey:t.privateKey,privateKeyPKCS8Base64:y(s),publicKeySPKIBase64:y(r),csrPEM:U("CERTIFICATE REQUEST",o),csrBase64:y(o)}}function S(e){if(!e.certificateBase64&&!e.certificatePEM)throw new Error("certificateBase64 or certificatePEM is required.");const t=c.forge.pki.privateKeyFromPem(k("PRIVATE KEY",e.privateKeyPKCS8Base64)),r=e.certificatePEM?c.forge.pki.certificateFromPem(e.certificatePEM):c.forge.pki.certificateFromAsn1(c.forge.asn1.fromDer(c.forge.util.createBuffer(O(e.certificateBase64)))),n=c.forge.pkcs12.toPkcs12Asn1(t,[r],e.password,{algorithm:"3des",friendlyName:e.friendlyName}),i=c.forge.asn1.toDer(n).getBytes();return F(i)}function h(e){const t=[v("2.5.4.3",T(e.commonName))];return e.emailAddress&&t.push(v("1.2.840.113549.1.9.1",K(e.emailAddress))),d(...t)}function v(e,t){return q(d(b(e),t))}function d(...e){return u(48,A(...e))}function q(...e){return u(49,A(...e))}function B(e,t){return u(160+e,t)}function C(e){return u(2,new Uint8Array([e]))}function R(){return new Uint8Array([5,0])}function T(e){return u(12,new TextEncoder().encode(e))}function K(e){return u(22,new TextEncoder().encode(e))}function E(e){return u(3,A(new Uint8Array([0]),e))}function b(e){const t=e.split(".").map(n=>parseInt(n,10));if(t.length<2||t.some(n=>!Number.isFinite(n)))throw new Error(`Invalid OID: ${e}`);const r=[t[0]*40+t[1]];for(const n of t.slice(2)){const i=[n&127];let o=n>>7;for(;o>0;)i.unshift(o&127|128),o>>=7;r.push(...i)}return u(6,new Uint8Array(r))}function u(e,t){return A(new Uint8Array([e]),x(t.byteLength),t)}function x(e){if(e<128)return new Uint8Array([e]);const t=[];let r=e;for(;r>0;)t.unshift(r&255),r>>=8;return new Uint8Array([128|t.length,...t])}function A(...e){const t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.byteLength;return r}function U(e,t){const n=y(t).match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../client-D1drDXxE.js"),u=require("../index-ChhtuQ7e.js"),P=require("../gsa-srp-CCIfUz7Y.js"),p=require("../provisioning-BlQMccX_.js"),I={name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-256"};async function S(e){if(!crypto.subtle)throw new Error("WebCrypto is not available in this browser.");const t=await crypto.subtle.generateKey(I,!0,["sign","verify"]),r=new Uint8Array(await crypto.subtle.exportKey("spki",t.publicKey)),n=d(R(0),h(e),r,C(0,new Uint8Array)),i=new Uint8Array(await crypto.subtle.sign("RSASSA-PKCS1-v1_5",t.privateKey,L(n))),o=d(n,d(b("1.2.840.113549.1.1.11"),T()),x(i)),l=new Uint8Array(await crypto.subtle.exportKey("pkcs8",t.privateKey));return{privateKey:t.privateKey,privateKeyPKCS8Base64:y(l),publicKeySPKIBase64:y(r),csrPEM:k("CERTIFICATE REQUEST",o),csrBase64:y(o)}}function q(e){if(!e.certificateBase64&&!e.certificatePEM)throw new Error("certificateBase64 or certificatePEM is required.");const t=u.forge.pki.privateKeyFromPem(F("PRIVATE KEY",e.privateKeyPKCS8Base64)),r=e.certificatePEM?u.forge.pki.certificateFromPem(e.certificatePEM):u.forge.pki.certificateFromAsn1(u.forge.asn1.fromDer(u.forge.util.createBuffer(N(e.certificateBase64)))),n=u.forge.pkcs12.toPkcs12Asn1(t,[r],e.password,{algorithm:"3des",friendlyName:e.friendlyName}),i=u.forge.asn1.toDer(n).getBytes();return O(i)}function h(e){const t=[v("2.5.4.3",K(e.commonName))];return e.emailAddress&&t.push(v("1.2.840.113549.1.9.1",E(e.emailAddress))),d(...t)}function v(e,t){return B(d(b(e),t))}function d(...e){return c(48,A(...e))}function B(...e){return c(49,A(...e))}function C(e,t){return c(160+e,t)}function R(e){return c(2,new Uint8Array([e]))}function T(){return new Uint8Array([5,0])}function K(e){return c(12,new TextEncoder().encode(e))}function E(e){return c(22,new TextEncoder().encode(e))}function x(e){return c(3,A(new Uint8Array([0]),e))}function b(e){const t=e.split(".").map(n=>parseInt(n,10));if(t.length<2||t.some(n=>!Number.isFinite(n)))throw new Error(`Invalid OID: ${e}`);const r=[t[0]*40+t[1]];for(const n of t.slice(2)){const i=[n&127];let o=n>>7;for(;o>0;)i.unshift(o&127|128),o>>=7;r.push(...i)}return c(6,new Uint8Array(r))}function c(e,t){return A(new Uint8Array([e]),U(t.byteLength),t)}function U(e){if(e<128)return new Uint8Array([e]);const t=[];let r=e;for(;r>0;)t.unshift(r&255),r>>=8;return new Uint8Array([128|t.length,...t])}function A(...e){const t=e.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.byteLength;return r}function k(e,t){const n=y(t).match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
2
2
  ${n.join(`
3
3
  `)}
4
4
  -----END ${e}-----
5
- `}function k(e,t){const r=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
5
+ `}function F(e,t){const r=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
6
6
  ${r.join(`
7
7
  `)}
8
8
  -----END ${e}-----
9
- `}function y(e){let t="";for(const r of e)t+=String.fromCharCode(r);return btoa(t)}function F(e){return btoa(e)}function O(e){return atob(e)}function N(e){const t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}async function a({relay:e,request:t,label:r="Apple Developer Portal request",validatePortalResponse:n=!0,mapBody:i}){const o=await l.proxyProvisioningRequest(e,t);return n&&g(o.body,r),i?i(o.body,o):o}async function L(e){return a({...e,request:p.listTeamsRequest(),label:"Apple Developer team list",mapBody:t=>re([...t?.teams??[],...t?.availableProviders??[],...t?.provider?[t.provider]:[]])})}async function $({certificateKind:e="development",teamId:t="",...r}){return a({...r,request:e==="distribution"?p.findDistributionCertificatesRequest(t):p.findDevelopmentCertificatesRequest(t),label:"Apple Developer certificate list",mapBody:n=>n?.certRequests??[]})}async function W({certificateKind:e="development",teamId:t="",csrPEM:r,...n}){return a({...n,request:e==="distribution"?p.submitDistributionCSRRequest({csrPEM:r,teamID:t}):p.submitDevelopmentCSRRequest({csrPEM:r,teamID:t}),label:e==="distribution"?"Apple Distribution certificate creation":"Apple Development certificate creation",mapBody:i=>i?.certRequest})}async function G({certificateKind:e="development",certificateId:t,teamId:r="",...n}){return a({...n,request:e==="distribution"?p.downloadDistributionCertificateRequest(t,r):p.downloadCertificateRequest(t,r),label:"Apple certificate download",validatePortalResponse:!1,mapBody:(i,o)=>o})}async function H({certificateKind:e="development",certificateId:t,teamId:r="",...n}){return a({...n,request:{method:"POST",path:"/account/ios/certificate/revokeCertificate.action",payload:{teamId:r,certificateId:t,type:e==="distribution"?"WXV89964HE":"83Q87W3TGH"}},label:"Apple certificate deletion",mapBody:i=>i})}async function M({teamId:e="",search:t="",...r}){const n=t.trim().toLowerCase();return a({...r,request:p.findBundleIDRequest({bundleID:t,teamID:e}),label:"Apple bundle ID list",mapBody:i=>{const o=i?.appIds??[];return n?o.filter(s=>[s.identifier,s.bundleId,s.name].some(f=>typeof f=="string"&&f.toLowerCase().includes(n))):o}})}async function _({teamId:e="",bundleId:t,name:r,...n}){return a({...n,request:p.createBundleIDRequest({bundleID:t,teamID:e,name:r}),label:"Apple bundle ID creation",mapBody:i=>i?.appId})}async function j({teamId:e="",appIdId:t,bundleId:r,name:n,...i}){return a({...i,request:{method:"POST",path:"/account/ios/identifiers/updateAppId.action",payload:{teamId:e,appIdId:t,...r?{identifier:r}:{},...n?{name:n}:{}}},label:"Apple bundle ID update",mapBody:o=>o?.appId})}async function V({teamId:e="",appIdId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/identifiers/deleteAppId.action",payload:{teamId:e,appIdId:t}},label:"Apple bundle ID deletion",mapBody:n=>n})}async function Q({teamId:e="",deviceUDID:t="",...r}){const n=D(t);return a({...r,request:p.findDeviceRequest({deviceUDID:t,teamID:e}),label:"Apple device list",mapBody:i=>{const o=i?.devices??[];return n?o.filter(s=>D(s.deviceNumber)===n):o}})}function D(e){return(e??"").replace(/-/g,"").replace(/[^a-fA-F0-9]/g,"").toUpperCase()}async function z({teamId:e="",deviceUDID:t,name:r,...n}){return a({...n,request:p.registerDeviceRequest({deviceUDID:t,teamID:e,name:r}),label:"Apple device registration",mapBody:i=>i?.device})}async function J({teamId:e="",deviceId:t,name:r,...n}){return a({...n,request:{method:"POST",path:"/account/ios/device/updateDevice.action",payload:{teamId:e,deviceId:t,...r?{name:r}:{}}},label:"Apple device update",mapBody:i=>i?.device})}async function X({teamId:e="",deviceId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/device/deleteDevice.action",payload:{teamId:e,deviceId:t}},label:"Apple device deletion",mapBody:n=>n})}async function Y({profileKind:e="development",teamId:t="",bundleId:r="",...n}){return a({...n,request:e==="adhoc"?p.findAdHocProfilesRequest({bundleID:r,teamID:t}):p.findDevelopmentProfilesRequest({bundleID:r,teamID:t}),label:"Apple provisioning profile list",mapBody:i=>i?.provisioningProfiles??[]})}async function Z({profileKind:e="development",teamId:t="",bundleId:r,appIdId:n,certificateIds:i,deviceIds:o,name:s,...f}){const[m]=i;if(!m)throw new Error("At least one certificate ID is required to create an Apple provisioning profile.");return a({...f,request:e==="adhoc"?p.createAdHocProfileRequest({bundleID:r,teamID:t,appIDID:n,certificateID:m,deviceIDs:o,name:s}):p.createDevelopmentProfileRequest({bundleID:r,teamID:t,appIDID:n,certificateID:m,deviceIDs:o,name:s}),label:"Apple provisioning profile creation",mapBody:w=>w?.provisioningProfile})}async function ee({teamId:e="",profileId:t,...r}){return a({...r,request:p.downloadProfileRequest(t,e),label:"Apple provisioning profile download",validatePortalResponse:!1,mapBody:(n,i)=>i})}async function te({teamId:e="",profileId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/profile/deleteProvisioningProfile.action",payload:{teamId:e,provisioningProfileId:t}},label:"Apple provisioning profile deletion",mapBody:n=>n})}function g(e,t){if(!e)throw new Error(`${t} returned an empty response.`);if(e.resultCode!==void 0&&e.resultCode!==0)throw new Error(`${t} failed: ${e.userString??e.resultString??e.resultCode}`)}function re(e){const t=new Set,r=[];for(const n of e){const i=String(n.teamId??n.providerId??n.publicProviderId??n.name??JSON.stringify(n));t.has(i)||(t.add(i),r.push(n))}return r}exports.AppleRelayWebSocketClient=l.AppleRelayWebSocketClient;exports.fetchAppleAccountSession=l.fetchAppleAccountSession;exports.openAppleRelayWebSocket=l.openAppleRelayWebSocket;exports.proxyPhoneTwoFactorCode=l.proxyPhoneTwoFactorCode;exports.proxySrpComplete=l.proxySrpComplete;exports.proxySrpInit=l.proxySrpInit;exports.proxyTwoFactorCode=l.proxyTwoFactorCode;exports.startBrowserOwnedAppleIDLogin=l.startBrowserOwnedAppleIDLogin;exports.triggerPhoneTwoFactor=l.triggerPhoneTwoFactor;exports.triggerTrustedDeviceTwoFactor=l.triggerTrustedDeviceTwoFactor;exports.AppleGsaSrpClient=c.AppleGsaSrpClient;exports.assertAppleDeveloperPortalResponseOK=g;exports.createAppleBundleID=_;exports.createAppleCertificate=W;exports.createAppleProfile=Z;exports.deleteAppleBundleID=V;exports.deleteAppleCertificate=H;exports.deleteAppleDevice=X;exports.deleteAppleProfile=te;exports.downloadAppleCertificate=G;exports.downloadAppleProfile=ee;exports.exportAppleCertificateP12=S;exports.generateAppleSigningKeyAndCSR=I;exports.listAppleBundleIDs=M;exports.listAppleCertificates=$;exports.listAppleDevices=Q;exports.listAppleProfiles=Y;exports.listAppleTeams=L;exports.registerAppleDevice=z;exports.requestAppleProvisioning=a;exports.updateAppleBundleID=j;exports.updateAppleDevice=J;
9
+ `}function y(e){let t="";for(const r of e)t+=String.fromCharCode(r);return btoa(t)}function O(e){return btoa(e)}function N(e){return atob(e)}function L(e){const t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}async function a({relay:e,request:t,label:r="Apple Developer Portal request",validatePortalResponse:n=!0,mapBody:i}){const o=await s.proxyProvisioningRequest(e,t);return n&&g(o.body,r),i?i(o.body,o):o}async function $(e){return a({...e,request:p.listTeamsRequest(),label:"Apple Developer team list",mapBody:t=>ne([...t?.teams??[],...t?.availableProviders??[],...t?.provider?[t.provider]:[]])})}async function W({certificateKind:e="development",teamId:t="",...r}){return a({...r,request:e==="distribution"?p.findDistributionCertificatesRequest(t):p.findDevelopmentCertificatesRequest(t),label:"Apple Developer certificate list",mapBody:n=>n?.certRequests??[]})}async function G({certificateKind:e="development",teamId:t="",csrPEM:r,...n}){return a({...n,request:e==="distribution"?p.submitDistributionCSRRequest({csrPEM:r,teamID:t}):p.submitDevelopmentCSRRequest({csrPEM:r,teamID:t}),label:e==="distribution"?"Apple Distribution certificate creation":"Apple Development certificate creation",mapBody:i=>i?.certRequest})}async function H({certificateKind:e="development",certificateId:t,teamId:r="",...n}){return a({...n,request:e==="distribution"?p.downloadDistributionCertificateRequest(t,r):p.downloadCertificateRequest(t,r),label:"Apple certificate download",validatePortalResponse:!1,mapBody:(i,o)=>o})}async function M({certificateKind:e="development",certificateId:t,teamId:r="",...n}){return a({...n,request:{method:"POST",path:"/account/ios/certificate/revokeCertificate.action",payload:{teamId:r,certificateId:t,type:e==="distribution"?"WXV89964HE":"83Q87W3TGH"}},label:"Apple certificate deletion",mapBody:i=>i})}async function _({teamId:e="",search:t="",...r}){const n=t.trim().toLowerCase();return a({...r,request:p.findBundleIDRequest({bundleID:t,teamID:e}),label:"Apple bundle ID list",mapBody:i=>{const o=i?.appIds??[];return n?o.filter(l=>[l.identifier,l.bundleId,l.name].some(f=>typeof f=="string"&&f.toLowerCase().includes(n))):o}})}async function j({teamId:e="",bundleId:t,name:r,...n}){return a({...n,request:p.createBundleIDRequest({bundleID:t,teamID:e,name:r}),label:"Apple bundle ID creation",mapBody:i=>i?.appId})}async function V({teamId:e="",appIdId:t,bundleId:r,name:n,...i}){return a({...i,request:{method:"POST",path:"/account/ios/identifiers/updateAppId.action",payload:{teamId:e,appIdId:t,...r?{identifier:r}:{},...n?{name:n}:{}}},label:"Apple bundle ID update",mapBody:o=>o?.appId})}async function Q({teamId:e="",appIdId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/identifiers/deleteAppId.action",payload:{teamId:e,appIdId:t}},label:"Apple bundle ID deletion",mapBody:n=>n})}async function z({teamId:e="",deviceUDID:t="",...r}){const n=D(t);return a({...r,request:p.findDeviceRequest({deviceUDID:t,teamID:e}),label:"Apple device list",mapBody:i=>{const o=i?.devices??[];return n?o.filter(l=>D(l.deviceNumber)===n):o}})}function D(e){return(e??"").replace(/-/g,"").replace(/[^a-fA-F0-9]/g,"").toUpperCase()}async function J({teamId:e="",deviceUDID:t,name:r,...n}){return a({...n,request:p.registerDeviceRequest({deviceUDID:t,teamID:e,name:r}),label:"Apple device registration",mapBody:i=>i?.device})}async function X({teamId:e="",deviceId:t,name:r,...n}){return a({...n,request:{method:"POST",path:"/account/ios/device/updateDevice.action",payload:{teamId:e,deviceId:t,...r?{name:r}:{}}},label:"Apple device update",mapBody:i=>i?.device})}async function Y({teamId:e="",deviceId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/device/deleteDevice.action",payload:{teamId:e,deviceId:t}},label:"Apple device deletion",mapBody:n=>n})}async function Z({profileKind:e="development",teamId:t="",bundleId:r="",...n}){return a({...n,request:e==="adhoc"?p.findAdHocProfilesRequest({bundleID:r,teamID:t}):p.findDevelopmentProfilesRequest({bundleID:r,teamID:t}),label:"Apple provisioning profile list",mapBody:i=>i?.provisioningProfiles??[]})}async function ee({profileKind:e="development",teamId:t="",bundleId:r,appIdId:n,certificateIds:i,deviceIds:o,name:l,...f}){const[m]=i;if(!m)throw new Error("At least one certificate ID is required to create an Apple provisioning profile.");return a({...f,request:e==="adhoc"?p.createAdHocProfileRequest({bundleID:r,teamID:t,appIDID:n,certificateID:m,deviceIDs:o,name:l}):p.createDevelopmentProfileRequest({bundleID:r,teamID:t,appIDID:n,certificateID:m,deviceIDs:o,name:l}),label:"Apple provisioning profile creation",mapBody:w=>w?.provisioningProfile})}async function te({teamId:e="",profileId:t,...r}){return a({...r,request:p.downloadProfileRequest(t,e),label:"Apple provisioning profile download",validatePortalResponse:!1,mapBody:(n,i)=>i})}async function re({teamId:e="",profileId:t,...r}){return a({...r,request:{method:"POST",path:"/account/ios/profile/deleteProvisioningProfile.action",payload:{teamId:e,provisioningProfileId:t}},label:"Apple provisioning profile deletion",mapBody:n=>n})}function g(e,t){if(!e)throw new Error(`${t} returned an empty response.`);if(e.resultCode!==void 0&&e.resultCode!==0)throw new Error(`${t} failed: ${e.userString??e.resultString??e.resultCode}`)}function ne(e){const t=new Set,r=[];for(const n of e){const i=String(n.teamId??n.providerId??n.publicProviderId??n.name??JSON.stringify(n));t.has(i)||(t.add(i),r.push(n))}return r}exports.AppleRelayWebSocketClient=s.AppleRelayWebSocketClient;exports.fetchAppleAccountSession=s.fetchAppleAccountSession;exports.openAppleRelayWebSocket=s.openAppleRelayWebSocket;exports.proxyPhoneTwoFactorCode=s.proxyPhoneTwoFactorCode;exports.proxySrpComplete=s.proxySrpComplete;exports.proxySrpInit=s.proxySrpInit;exports.proxyTwoFactorCode=s.proxyTwoFactorCode;exports.startBrowserOwnedAppleIDLogin=s.startBrowserOwnedAppleIDLogin;exports.triggerPhoneTwoFactor=s.triggerPhoneTwoFactor;exports.triggerTrustedDeviceTwoFactor=s.triggerTrustedDeviceTwoFactor;exports.AppleGsaSrpClient=P.AppleGsaSrpClient;exports.assertAppleDeveloperPortalResponseOK=g;exports.createAppleBundleID=j;exports.createAppleCertificate=G;exports.createAppleProfile=ee;exports.deleteAppleBundleID=Q;exports.deleteAppleCertificate=M;exports.deleteAppleDevice=Y;exports.deleteAppleProfile=re;exports.downloadAppleCertificate=H;exports.downloadAppleProfile=te;exports.exportAppleCertificateP12=q;exports.generateAppleSigningKeyAndCSR=S;exports.listAppleBundleIDs=_;exports.listAppleCertificates=W;exports.listAppleDevices=z;exports.listAppleProfiles=Z;exports.listAppleTeams=$;exports.registerAppleDevice=J;exports.requestAppleProvisioning=a;exports.updateAppleBundleID=V;exports.updateAppleDevice=X;
@@ -1,8 +1,8 @@
1
- import { p as D } from "../client-CBX-hLnL.mjs";
2
- import { A as Pe, f as he, o as qe, a as Be, b as Se, c as Ce, d as Re, s as Te, t as Ee, e as Ke } from "../client-CBX-hLnL.mjs";
3
- import { f as p } from "../index-DFdCvi2_.mjs";
4
- import { A as ke } from "../index-DFdCvi2_.mjs";
5
- import { l as w, f as g, a as I, s as P, b as h, d as q, c as B, e as S, g as C, h as R, r as T, i as E, j as K, k as U, m as k, n as x } from "../provisioning-DKbkBO-p.mjs";
1
+ import { p as D } from "../client-DSuNtWDv.mjs";
2
+ import { A as Pe, f as he, o as qe, a as Be, b as Se, c as Ce, d as Re, s as Te, t as Ee, e as Ke } from "../client-DSuNtWDv.mjs";
3
+ import { f as p } from "../index-YDu8K9a4.mjs";
4
+ import { A as ke } from "../gsa-srp-Bme3JLEi.mjs";
5
+ import { l as w, f as g, a as I, s as P, b as h, d as q, c as B, e as S, h as C, i as R, r as T, j as E, k as K, m as U, n as k, o as x } from "../provisioning-B_DefBEp.mjs";
6
6
  const F = {
7
7
  name: "RSASSA-PKCS1-v1_5",
8
8
  modulusLength: 2048,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),y=require("../client-BtC4n_qf.js");require("../index-CMeQfhYy.js");function F({registryApiUrl:s,token:u,organizationId:l}){const[g,r]=t.useState("idle"),[w,i]=t.useState(),[h,d]=t.useState(),[v,p]=t.useState(),[S,c]=t.useState(),o=t.useRef(void 0),b=t.useCallback(async()=>{await o.current?.close().catch(()=>{}),o.current=void 0,i(void 0),d(void 0),p(void 0),c(void 0),r("idle")},[]);t.useEffect(()=>()=>{o.current?.close(),o.current=void 0},[]);const C=t.useCallback(async({accountName:n,password:a})=>{r("authenticating"),c(void 0),await o.current?.close().catch(()=>{});try{const e=await y.startBrowserOwnedAppleIDLogin({registryApiUrl:s,token:u,organizationId:l,accountName:n,password:a});return o.current=e,i(e),d(e.completeResponse),p(e.twoFactorChallengeResponse),r(e.requiresTwoFactor?"two-factor-required":"authenticated"),e}catch(e){i(void 0),o.current=void 0,c(f(e)),r("error");return}},[s,l,u]),R=t.useCallback(async n=>{const a=o.current;if(!a)throw new Error("Start Apple ID login before submitting a two-factor code.");r("authenticating"),c(void 0);try{const e=await a.finishTwoFactor(n);return r("authenticated"),e}catch(e){c(f(e)),r("error");return}},[]),m=t.useCallback(async()=>{const n=o.current;if(!n)throw new Error("Start Apple ID login before finalizing the Apple session.");return n.finalize()},[]);return{status:g,session:w,completeResponse:h,twoFactorChallengeResponse:v,error:S,startLogin:C,submitTwoFactorCode:R,finalize:m,close:b}}function f(s){return s instanceof Error?s.message:String(s)}exports.useAppleIDLogin=F;
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;
@@ -12,4 +12,4 @@ export type UseAppleIDLoginResult = {
12
12
  finalize: () => Promise<AppleRelayResponse | undefined>;
13
13
  close: () => Promise<void>;
14
14
  };
15
- export declare function useAppleIDLogin({ registryApiUrl, token, organizationId }: UseAppleIDLoginOptions): UseAppleIDLoginResult;
15
+ export declare function useAppleIDLogin({ registryApiUrl, token, organizationId, }: UseAppleIDLoginOptions): UseAppleIDLoginResult;
@@ -1,50 +1,56 @@
1
- import { useState as c, useRef as y, useCallback as a, useEffect as E } from "react";
2
- import { s as A } from "../client-CBX-hLnL.mjs";
3
- import "../index-DFdCvi2_.mjs";
4
- function L({ registryApiUrl: r, token: l, organizationId: d }) {
5
- const [h, o] = c("idle"), [v, u] = c(), [g, p] = c(), [m, f] = c(), [R, s] = c(), t = y(void 0), C = a(async () => {
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";
3
+ import "../index-YDu8K9a4.mjs";
4
+ import "../gsa-srp-Bme3JLEi.mjs";
5
+ import { e as w } from "../errors-gy8yQJos.mjs";
6
+ function x({
7
+ registryApiUrl: u,
8
+ token: l,
9
+ organizationId: p
10
+ }) {
11
+ const [h, o] = n("idle"), [v, a] = n(), [g, d] = n(), [m, f] = n(), [R, s] = n(), t = S(void 0), C = i(async () => {
6
12
  await t.current?.close().catch(() => {
7
- }), t.current = void 0, u(void 0), p(void 0), f(void 0), s(void 0), o("idle");
13
+ }), t.current = void 0, a(void 0), d(void 0), f(void 0), s(void 0), o("idle");
8
14
  }, []);
9
- E(() => () => {
15
+ A(() => () => {
10
16
  t.current?.close(), t.current = void 0;
11
17
  }, []);
12
- const F = a(
13
- async ({ accountName: n, password: i }) => {
18
+ const F = i(
19
+ async ({ accountName: r, password: c }) => {
14
20
  o("authenticating"), s(void 0), await t.current?.close().catch(() => {
15
21
  });
16
22
  try {
17
- const e = await A({
18
- registryApiUrl: r,
23
+ const e = await D({
24
+ registryApiUrl: u,
19
25
  token: l,
20
- organizationId: d,
21
- accountName: n,
22
- password: i
26
+ organizationId: p,
27
+ accountName: r,
28
+ password: c
23
29
  });
24
- return t.current = e, u(e), p(e.completeResponse), f(e.twoFactorChallengeResponse), o(e.requiresTwoFactor ? "two-factor-required" : "authenticated"), e;
30
+ return t.current = e, a(e), d(e.completeResponse), f(e.twoFactorChallengeResponse), o(e.requiresTwoFactor ? "two-factor-required" : "authenticated"), e;
25
31
  } catch (e) {
26
- u(void 0), t.current = void 0, s(w(e)), o("error");
32
+ a(void 0), t.current = void 0, s(w(e)), o("error");
27
33
  return;
28
34
  }
29
35
  },
30
- [r, d, l]
31
- ), S = a(async (n) => {
32
- const i = t.current;
33
- if (!i)
36
+ [u, p, l]
37
+ ), b = i(async (r) => {
38
+ const c = t.current;
39
+ if (!c)
34
40
  throw new Error("Start Apple ID login before submitting a two-factor code.");
35
41
  o("authenticating"), s(void 0);
36
42
  try {
37
- const e = await i.finishTwoFactor(n);
43
+ const e = await c.finishTwoFactor(r);
38
44
  return o("authenticated"), e;
39
45
  } catch (e) {
40
46
  s(w(e)), o("error");
41
47
  return;
42
48
  }
43
- }, []), b = a(async () => {
44
- const n = t.current;
45
- if (!n)
49
+ }, []), y = i(async () => {
50
+ const r = t.current;
51
+ if (!r)
46
52
  throw new Error("Start Apple ID login before finalizing the Apple session.");
47
- return n.finalize();
53
+ return r.finalize();
48
54
  }, []);
49
55
  return {
50
56
  status: h,
@@ -53,14 +59,11 @@ function L({ registryApiUrl: r, token: l, organizationId: d }) {
53
59
  twoFactorChallengeResponse: m,
54
60
  error: R,
55
61
  startLogin: F,
56
- submitTwoFactorCode: S,
57
- finalize: b,
62
+ submitTwoFactorCode: b,
63
+ finalize: y,
58
64
  close: C
59
65
  };
60
66
  }
61
- function w(r) {
62
- return r instanceof Error ? r.message : String(r);
63
- }
64
67
  export {
65
- L as useAppleIDLogin
68
+ x as useAppleIDLogin
66
69
  };
@@ -0,0 +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;
@@ -0,0 +1,59 @@
1
+ import { AppleRelayWebSocketClient } from '../core/device-install/apple';
2
+ 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 { normalizeCertificateSerial } from '../core/device-install/storage/browser-storage';
5
+ /**
6
+ * Conventional secret name of a team's certificate bundle. One bundle per
7
+ * team and Apple certificate type; the type is in the name so development
8
+ * and distribution material never collide.
9
+ */
10
+ export declare function appleCertificateSecretName(teamId: string, certificateType: AppleCertificateType): string;
11
+ export type EnsureAppleCertificateInput = {
12
+ relay: AppleRelayWebSocketClient;
13
+ teamId: string;
14
+ secretStore: SigningSecretStore;
15
+ /** Common name used when minting a new certificate. */
16
+ commonName?: string;
17
+ log?: (message: string, detail?: string) => void;
18
+ };
19
+ export type EnsureAppleCertificateResult = {
20
+ secret: SigningSecret;
21
+ certificateId: string;
22
+ /** True when a new certificate was minted instead of reusing the stored one. */
23
+ created: boolean;
24
+ };
25
+ /**
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.
30
+ *
31
+ * Durability of the stored material is the secret store's concern:
32
+ * implementors who want retries or fallbacks build them into their
33
+ * SigningSecretStore.
34
+ */
35
+ export declare function ensureAppleCertificateSecret({ relay, teamId, secretStore, commonName, log, }: EnsureAppleCertificateInput): Promise<EnsureAppleCertificateResult>;
36
+ export type SaveAppleProfileInput = {
37
+ relay: AppleRelayWebSocketClient;
38
+ teamId: string;
39
+ profileId: string;
40
+ secretStore: SigningSecretStore;
41
+ log?: (message: string, detail?: string) => void;
42
+ };
43
+ /**
44
+ * Downloads the provisioning profile and stores it as an
45
+ * appleProvisioningProfile secret named `${teamId}/${uuid}`. The UUID is
46
+ * unique per profile, so a team can hold many profiles for the same
47
+ * bundle ID and certificate set; the reference fields (certificate
48
+ * serials, bundle IDs, device IDs parsed out of the profile) are what
49
+ * consumers filter on.
50
+ */
51
+ export declare function saveAppleProfileSecret({ relay, teamId, profileId, secretStore, log, }: SaveAppleProfileInput): Promise<SigningSecret>;
52
+ export type ListTeamProfilesInput = {
53
+ relay: AppleRelayWebSocketClient;
54
+ teamId: string;
55
+ };
56
+ /** Lists the team's development provisioning profiles from the portal. */
57
+ export declare function listTeamAppleProfiles({ relay, teamId }: ListTeamProfilesInput): Promise<Record<string, unknown>[]>;
58
+ /** Read a string-ish value from a loosely typed portal record. */
59
+ export declare function stringField(record: Record<string, unknown> | undefined, key: string): string | undefined;
@@ -0,0 +1,227 @@
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
19
+ )}/${encodeURIComponent(s)}`, c = {
20
+ Authorization: `Bearer ${r.token}`,
21
+ "Content-Type": "application/json"
22
+ };
23
+ async function a(t, s) {
24
+ let i = `${t.status}`;
25
+ try {
26
+ const d = await t.json();
27
+ d.message && (i = d.message);
28
+ } catch {
29
+ }
30
+ throw new Error(`Failed to ${s} secret: ${i}`);
31
+ }
32
+ return {
33
+ async put(t, s, i) {
34
+ const d = await e(n(t, s), {
35
+ method: "PUT",
36
+ headers: c,
37
+ body: JSON.stringify({ data: i, replace: !0 })
38
+ });
39
+ 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 };
42
+ },
43
+ async get(t, s) {
44
+ const i = await e(n(t, s), { method: "GET", headers: c });
45
+ if (i.status === 404) return;
46
+ i.ok || await a(i, "fetch");
47
+ const d = await i.json();
48
+ return { type: d.type, name: d.name, createdAt: d.createdAt, data: d.data };
49
+ },
50
+ async list() {
51
+ const t = await e(
52
+ `${o}/v1/organizations/${encodeURIComponent(r.organizationId)}/secrets`,
53
+ { method: "GET", headers: c }
54
+ );
55
+ return t.ok || await a(t, "list"), (await t.json()).filter(
56
+ (i) => i.type === A || i.type === v
57
+ ).map((i) => ({ type: i.type, name: i.name, createdAt: i.createdAt }));
58
+ },
59
+ async delete(t, s) {
60
+ const i = await e(n(t, s), { method: "DELETE", headers: c });
61
+ i.status !== 404 && (i.ok || await a(i, "delete"));
62
+ }
63
+ };
64
+ }
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);
71
+ 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
+ });
76
+ }
77
+ function o(n) {
78
+ return new Promise((c, a) => {
79
+ n.onsuccess = () => c(n.result), n.onerror = () => a(n.error ?? new Error("IndexedDB request failed"));
80
+ });
81
+ }
82
+ 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
+ ), i = {
87
+ id: r(n, c),
88
+ type: n,
89
+ name: c,
90
+ data: a,
91
+ createdAt: s?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
92
+ };
93
+ return await o(
94
+ t.transaction(p, "readwrite").objectStore(p).put(i)
95
+ ), { type: n, name: c, createdAt: i.createdAt, data: a };
96
+ },
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
+ );
101
+ if (t)
102
+ return { type: t.type, name: t.name, createdAt: t.createdAt, data: t.data };
103
+ },
104
+ async list() {
105
+ const n = await e();
106
+ return (await o(
107
+ n.transaction(p, "readonly").objectStore(p).getAll()
108
+ )).map((a) => ({ type: a.type, name: a.name, createdAt: a.createdAt }));
109
+ },
110
+ async delete(n, c) {
111
+ const a = await e();
112
+ await o(
113
+ a.transaction(p, "readwrite").objectStore(p).delete(r(n, c))
114
+ );
115
+ }
116
+ };
117
+ }
118
+ function x(r, e) {
119
+ return `${r}/${e}`;
120
+ }
121
+ async function F({
122
+ relay: r,
123
+ teamId: e,
124
+ secretStore: o,
125
+ commonName: n,
126
+ log: c = () => {
127
+ }
128
+ }) {
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 };
137
+ }
138
+ c("Stored certificate is no longer on the team", "Minting a new one.");
139
+ }
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)
147
+ 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
153
+ });
154
+ if (!g.rawBodyBase64)
155
+ throw new Error("Apple certificate download returned no bytes.");
156
+ const b = {
157
+ certificateP12Base64: T({
158
+ privateKeyPKCS8Base64: S.privateKeyPKCS8Base64,
159
+ certificateBase64: g.rawBodyBase64,
160
+ password: "",
161
+ friendlyName: `Apple Development ${e}`
162
+ }),
163
+ certificateType: a,
164
+ teamID: e,
165
+ certificateID: w,
166
+ // Normalized so it equals the serials profiles reference.
167
+ serialNumber: R(u(y, "serialNum")),
168
+ expirationDate: u(y, "expirationDateString")
169
+ };
170
+ let E;
171
+ try {
172
+ E = await j(o, t, b);
173
+ } catch (f) {
174
+ 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.`
176
+ );
177
+ }
178
+ return c("Apple certificate stored", w), { secret: E, certificateId: w, created: !0 };
179
+ }
180
+ function K(r) {
181
+ return r instanceof Error ? r.message : String(r);
182
+ }
183
+ async function G({
184
+ relay: r,
185
+ teamId: e,
186
+ profileId: o,
187
+ secretStore: n,
188
+ log: c = () => {
189
+ }
190
+ }) {
191
+ const t = (await $({ relay: r, teamId: e, profileId: o })).rawBodyBase64;
192
+ if (!t)
193
+ 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,
196
+ certificateSerialNumbers: s.certificateSerialNumbers.join(","),
197
+ bundleIDs: s.bundleID,
198
+ deviceIDs: s.provisionedDevices.join(","),
199
+ teamID: s.teamID ?? e,
200
+ profileName: s.name,
201
+ uuid: s.uuid,
202
+ expirationDate: s.expirationDate
203
+ });
204
+ return c("Apple provisioning profile stored", i), d;
205
+ }
206
+ async function V({ relay: r, teamId: e }) {
207
+ return B({ relay: r, teamId: e, profileKind: "development" });
208
+ }
209
+ function u(r, e) {
210
+ const o = r?.[e];
211
+ if (typeof o == "string") return o;
212
+ if (typeof o == "number" || typeof o == "boolean") return String(o);
213
+ }
214
+ 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
227
+ };