Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ test("test upload test.zip artifact", async () => {
const key = JSON.parse(await readFile("key.json", "utf8")) as Options

const client = new EdgeAddonsAPI(key)
const resp = await client.submit({
const operationId = await client.submit({
filePath: "test.zip",
notes: "Test upload test.zip artifact"
})

const publishStatus = await client.getPublishStatus(resp)
const publishStatus = await client.getPublishStatus(operationId)

expect(publishStatus.id).toBe(resp)
expect(publishStatus.id).toBe(operationId)
expect(publishStatus.status).toBe("Succeeded")
})
33 changes: 32 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class EdgeAddonsAPI {
return
}

return this.publish(notes)
const publishOperationId = await this.publish(notes)
await this.waitForPublish(publishOperationId)
return publishOperationId
}

async publish(notes = "") {
Expand Down Expand Up @@ -134,6 +136,35 @@ export class EdgeAddonsAPI {
.json<OperationResponse>()
}

async waitForPublish(
operationId: string,
retryCount = 10,
pollTime = 5000
) {
let status: OperationResponse["status"]
let attempts = 0

while (status !== "Succeeded" && attempts < retryCount) {
const statusResp = await this.getPublishStatus(operationId)

if (statusResp.status === "Failed") {
throw new Error(
statusResp.message ||
statusResp.errorCode + ":" + (statusResp.errors || []).join(",")
)
} else if (statusResp.status === "InProgress") {
await wait(pollTime)
}

status = statusResp.status
attempts++
}

if (status !== "Succeeded") {
throw new Error("Publish operation timed out")
}
}

async waitForUpload(
operationId: string,
retryCount = 5,
Expand Down