@liqhtworks/sophon-sdk 0.1.2 → 0.1.3
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.
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: Open Generated SDK PR
|
|
2
|
+
|
|
3
|
+
# The sophon-api Sync SDK Update PRs workflow pushes generated branches into
|
|
4
|
+
# this repo. This workflow uses the repo-local GITHUB_TOKEN to open or update
|
|
5
|
+
# the PR, so the cross-repo token only needs contents:write.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches:
|
|
10
|
+
- "generated/sophon-api-*"
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
pull-requests: write
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
open:
|
|
18
|
+
name: Open or update PR
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 1
|
|
24
|
+
|
|
25
|
+
- name: Open or update generated SDK PR
|
|
26
|
+
env:
|
|
27
|
+
GH_TOKEN: ${{ github.token }}
|
|
28
|
+
BRANCH: ${{ github.ref_name }}
|
|
29
|
+
shell: bash
|
|
30
|
+
run: |
|
|
31
|
+
set -euo pipefail
|
|
32
|
+
|
|
33
|
+
title="$(git log -1 --format=%s)"
|
|
34
|
+
body="$(git log -1 --format=%B | sed '1d')"
|
|
35
|
+
if [ -z "${body}" ]; then
|
|
36
|
+
body="Generated SDK update from sophon-api."
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
existing="$(
|
|
40
|
+
gh api --method GET "repos/${GITHUB_REPOSITORY}/pulls" \
|
|
41
|
+
-f state=open \
|
|
42
|
+
-f head="${GITHUB_REPOSITORY_OWNER}:${BRANCH}" \
|
|
43
|
+
-f base=main \
|
|
44
|
+
--jq '.[0].number // empty'
|
|
45
|
+
)"
|
|
46
|
+
|
|
47
|
+
body_file="$(mktemp)"
|
|
48
|
+
printf '%s\n' "${body}" > "${body_file}"
|
|
49
|
+
|
|
50
|
+
if [ -n "${existing}" ]; then
|
|
51
|
+
gh pr edit "${existing}" \
|
|
52
|
+
--repo "${GITHUB_REPOSITORY}" \
|
|
53
|
+
--title "${title}" \
|
|
54
|
+
--body-file "${body_file}"
|
|
55
|
+
echo "Updated PR #${existing}"
|
|
56
|
+
else
|
|
57
|
+
gh pr create \
|
|
58
|
+
--repo "${GITHUB_REPOSITORY}" \
|
|
59
|
+
--base main \
|
|
60
|
+
--head "${BRANCH}" \
|
|
61
|
+
--title "${title}" \
|
|
62
|
+
--body-file "${body_file}"
|
|
63
|
+
fi
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: TypeScript SDK CI
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# this workflow installs, builds, and publishes to npm.
|
|
3
|
+
# PRs and main pushes validate the generated package natively in the SDK repo.
|
|
4
|
+
# v<version> tags additionally publish the already-generated SDK to npm.
|
|
6
5
|
|
|
7
6
|
on:
|
|
8
7
|
push:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
9
10
|
tags:
|
|
10
11
|
- "v*"
|
|
12
|
+
pull_request:
|
|
11
13
|
workflow_dispatch:
|
|
12
14
|
inputs:
|
|
13
15
|
tag:
|
|
@@ -19,8 +21,33 @@ permissions:
|
|
|
19
21
|
id-token: write
|
|
20
22
|
|
|
21
23
|
jobs:
|
|
24
|
+
validate:
|
|
25
|
+
name: install + build + pack
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
steps:
|
|
28
|
+
- name: Checkout package
|
|
29
|
+
uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
ref: ${{ github.event.inputs.tag || github.ref }}
|
|
32
|
+
fetch-depth: 1
|
|
33
|
+
|
|
34
|
+
- name: Set up Node
|
|
35
|
+
uses: actions/setup-node@v4
|
|
36
|
+
with:
|
|
37
|
+
node-version: "20"
|
|
38
|
+
|
|
39
|
+
- name: Install + build
|
|
40
|
+
run: |
|
|
41
|
+
if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
42
|
+
npm run build
|
|
43
|
+
|
|
44
|
+
- name: Validate npm package contents
|
|
45
|
+
run: npm pack --dry-run
|
|
46
|
+
|
|
22
47
|
publish:
|
|
23
48
|
name: npm publish
|
|
49
|
+
needs: validate
|
|
50
|
+
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '')
|
|
24
51
|
runs-on: ubuntu-latest
|
|
25
52
|
steps:
|
|
26
53
|
- name: Checkout tag
|
|
@@ -43,15 +70,11 @@ jobs:
|
|
|
43
70
|
- name: Verify tag matches package.json
|
|
44
71
|
shell: bash
|
|
45
72
|
env:
|
|
46
|
-
# `GITHUB_REF_NAME` is the *dispatched* ref (often `main`), not the
|
|
47
|
-
# checked-out tag. Prefer the explicit workflow_dispatch input,
|
|
48
|
-
# then fall back to GITHUB_REF_NAME for the tag-push trigger.
|
|
49
73
|
INPUT_TAG: ${{ github.event.inputs.tag }}
|
|
50
74
|
run: |
|
|
51
|
-
tag="${INPUT_TAG
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fi
|
|
75
|
+
tag="${INPUT_TAG:-${GITHUB_REF_NAME}}"
|
|
76
|
+
tag="${tag#refs/tags/}"
|
|
77
|
+
tag="${tag#v}"
|
|
55
78
|
pkg="$(node -p "require('./package.json').version")"
|
|
56
79
|
if [ "${tag}" != "${pkg}" ]; then
|
|
57
80
|
echo "::error::tag v${tag} does not match package.json version ${pkg}" >&2
|
|
@@ -60,7 +83,7 @@ jobs:
|
|
|
60
83
|
|
|
61
84
|
- name: Install + build
|
|
62
85
|
run: |
|
|
63
|
-
npm ci
|
|
86
|
+
if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
64
87
|
npm run build
|
|
65
88
|
|
|
66
89
|
- name: Publish
|
|
@@ -10,7 +10,6 @@ export interface UploadsApiLike {
|
|
|
10
10
|
id: string;
|
|
11
11
|
chunk_size: number;
|
|
12
12
|
total_chunks: number;
|
|
13
|
-
expires_at: string;
|
|
14
13
|
}>;
|
|
15
14
|
uploadPart(params: {
|
|
16
15
|
id: string;
|
|
@@ -25,7 +24,6 @@ export interface UploadsApiLike {
|
|
|
25
24
|
idempotencyKey: string;
|
|
26
25
|
}): Promise<{
|
|
27
26
|
id: string;
|
|
28
|
-
status: string;
|
|
29
27
|
sha256: string;
|
|
30
28
|
bytes: number;
|
|
31
29
|
}>;
|
|
@@ -33,7 +31,6 @@ export interface UploadsApiLike {
|
|
|
33
31
|
id: string;
|
|
34
32
|
}): Promise<{
|
|
35
33
|
id: string;
|
|
36
|
-
status: string;
|
|
37
34
|
total_chunks: number;
|
|
38
35
|
received_chunks: number[];
|
|
39
36
|
}>;
|
|
@@ -10,7 +10,6 @@ export interface UploadsApiLike {
|
|
|
10
10
|
id: string;
|
|
11
11
|
chunk_size: number;
|
|
12
12
|
total_chunks: number;
|
|
13
|
-
expires_at: string;
|
|
14
13
|
}>;
|
|
15
14
|
uploadPart(params: {
|
|
16
15
|
id: string;
|
|
@@ -25,7 +24,6 @@ export interface UploadsApiLike {
|
|
|
25
24
|
idempotencyKey: string;
|
|
26
25
|
}): Promise<{
|
|
27
26
|
id: string;
|
|
28
|
-
status: string;
|
|
29
27
|
sha256: string;
|
|
30
28
|
bytes: number;
|
|
31
29
|
}>;
|
|
@@ -33,7 +31,6 @@ export interface UploadsApiLike {
|
|
|
33
31
|
id: string;
|
|
34
32
|
}): Promise<{
|
|
35
33
|
id: string;
|
|
36
|
-
status: string;
|
|
37
34
|
total_chunks: number;
|
|
38
35
|
received_chunks: number[];
|
|
39
36
|
}>;
|
package/package.json
CHANGED
package/src/helpers/uploads.ts
CHANGED
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
// separate calls; this wrapper handles chunk slicing, bounded concurrency,
|
|
5
5
|
// per-part retry, resume against existing sessions, and progress reporting.
|
|
6
6
|
|
|
7
|
+
// Narrow structural type — only the fields the helper actually reads.
|
|
8
|
+
// Keeping it tight lets the generated UploadsApi (which carries Date /
|
|
9
|
+
// nullable / extra metadata fields) satisfy this interface without
|
|
10
|
+
// explicit casts at the call site.
|
|
7
11
|
export interface UploadsApiLike {
|
|
8
12
|
createUpload(params: {
|
|
9
13
|
createUploadRequest: { file_name: string; file_size: number; mime_type: string };
|
|
10
14
|
idempotencyKey: string;
|
|
11
|
-
}): Promise<{ id: string; chunk_size: number; total_chunks: number
|
|
15
|
+
}): Promise<{ id: string; chunk_size: number; total_chunks: number }>;
|
|
12
16
|
|
|
13
17
|
uploadPart(params: {
|
|
14
18
|
id: string;
|
|
@@ -19,11 +23,10 @@ export interface UploadsApiLike {
|
|
|
19
23
|
completeUpload(params: {
|
|
20
24
|
id: string;
|
|
21
25
|
idempotencyKey: string;
|
|
22
|
-
}): Promise<{ id: string;
|
|
26
|
+
}): Promise<{ id: string; sha256: string; bytes: number }>;
|
|
23
27
|
|
|
24
28
|
getUpload(params: { id: string }): Promise<{
|
|
25
29
|
id: string;
|
|
26
|
-
status: string;
|
|
27
30
|
total_chunks: number;
|
|
28
31
|
received_chunks: number[];
|
|
29
32
|
}>;
|