@hotcodepush/node 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,6 +37,19 @@ Uploads stream their body, a `Blob` or a `ReadableStream` with its `contentLengt
37
37
  Creating calls send an `Idempotency-Key` and are retried. Pass `idempotencyKey` to reuse one across your own retries.
38
38
  A failed request throws a `HotCodePushError` with the API's `code`, `message`, `details` and the HTTP `status`.
39
39
 
40
+ `request` sends one request to any path of the API, for an endpoint newer than this client or for the status and the headers of an answer. It returns the `Response` with its body already received:
41
+
42
+ ```ts
43
+ const response = await hotCodePush.request({
44
+ method: 'GET',
45
+ path: '/v1/organizations?limit=1',
46
+ });
47
+ console.log(response.status, response.headers.get('Content-Type'));
48
+ const organizations = await response.json();
49
+ ```
50
+
51
+ The path starts with a slash and carries its own query string, and a `body` is sent as JSON. A `POST` or a `PATCH` sent this way carries no `Idempotency-Key` and is not retried.
52
+
40
53
  ## Documentation
41
54
 
42
55
  See [hotcodepush.com/docs/api/node](https://hotcodepush.com/docs/api/node) for this client and [hotcodepush.com/docs](https://hotcodepush.com/docs) for HotCodePush.
package/dist/index.d.mts CHANGED
@@ -17921,10 +17921,12 @@ declare class HttpClient {
17921
17921
  private readonly timeoutMs;
17922
17922
  constructor(options: HttpClientOptions);
17923
17923
  fetchBlob(options: FetchJsonOptions): Promise<Blob>;
17924
+ fetchBufferedResponse(options: FetchJsonOptions): Promise<Response>;
17924
17925
  fetchCreatingPost<T>(options: FetchCreatingPostOptions): Promise<T>;
17925
17926
  fetchJson<T>(options: FetchJsonOptions): Promise<T>;
17926
17927
  fetchStatus(options: FetchJsonOptions): Promise<void>;
17927
17928
  fetchUpload<T>(options: FetchUploadOptions): Promise<T>;
17929
+ private fetchOkResponse;
17928
17930
  private fetchResponse;
17929
17931
  private resolveRequestInit;
17930
17932
  private resolveRouteUrl;
@@ -19251,6 +19253,14 @@ declare class UsersResource {
19251
19253
  //#endregion
19252
19254
  //#region src/client.d.ts
19253
19255
  type HotCodePushOptions = HttpClientOptions;
19256
+ interface RequestOptions {
19257
+ /** The body, an object or an array, sent as JSON. A `GET` takes none. */
19258
+ body?: unknown;
19259
+ /** A `DELETE`, a `GET` and a `PUT` are retried, a `PATCH` and a `POST` are sent once and carry no `Idempotency-Key`. */
19260
+ method: FetchJsonOptions['method'];
19261
+ /** The path below the base URL with its query string, starting with a slash, such as `/v1/apps?limit=10`. */
19262
+ path: string;
19263
+ }
19254
19264
  /**
19255
19265
  * The client for the HotCodePush REST API.
19256
19266
  * Resources mirror the API paths, so `/v1/apps/{appId}/channels` is `apps.channels`.
@@ -19264,7 +19274,14 @@ export declare class HotCodePush {
19264
19274
  readonly organizations: OrganizationsResource;
19265
19275
  readonly qrCodes: QrCodesResource;
19266
19276
  readonly users: UsersResource;
19277
+ private readonly httpClient;
19267
19278
  constructor(options?: HotCodePushOptions);
19279
+ /**
19280
+ * Sends one request to a path of the API, for what no resource method covers.
19281
+ * Returns the response with its status, its headers and its body already received.
19282
+ * Throws a `HotCodePushError` on a status outside 2xx.
19283
+ */
19284
+ request({ body, method, path }: RequestOptions): Promise<Response>;
19268
19285
  }
19269
19286
  //#endregion
19270
19287
  //#region src/errors.d.ts
@@ -19293,4 +19310,4 @@ export declare const PART_SIZE_BYTES: number;
19293
19310
  */
19294
19311
  export declare const SINGLE_UPLOAD_LIMIT_BYTES: number;
19295
19312
  //#endregion
19296
- export type { AcceptInvitationOptions, App, AppFile, AppUsageMonth, AppsResource, Audience, AuditLog, AuditLogsResource, BinariesResource, Binary, BlobUploadBody, Bundle, BundleDelta, BundleDeltasResource, BundleFile, BundleFilesResource, BundlePackResource, BundlePackUpload, BundlePackUploadPartsResource, BundlePackUploadsResource, BundlesResource, CancelSubscriptionOptions, Channel, ChannelAudienceResource, ChannelQrCodeResource, ChannelReleasesResource, ChannelsResource, Checkout, CheckoutsResource, CompleteBundleOptions, CompleteBundlePackUploadOptions, CompleteFileUploadOptions, Count, CountAppsOptions, CountAuditLogsOptions, CountBinariesOptions, CountBundleDeltasOptions, CountBundleFilesOptions, CountBundlesOptions, CountChannelsOptions, CountDeviceEventsOptions, CountDevicesOptions, CountInvitationsOptions, CountMembersOptions, CountNotificationsOptions, CountReleasesOptions, CountSigningKeysOptions, CountTelemetryExportDeliveriesOptions, CountUsageAppsOptions, CountWebhookDeliveriesOptions, CountWebhooksOptions, CreateAppOptions, CreateBinaryOptions, CreateBundleOptions, CreateBundlePackUploadOptions, CreateChannelOptions, CreateCheckoutOptions, CreateCustomerPortalSessionOptions, CreateFileUploadOptions, CreateInvitationOptions, CreateOrganizationOptions, CreateReleaseOptions, CreateRollbackOptions, CreateSigningKeyOptions, CreateSsoProviderVerificationOptions, CreateUserPasswordOptions, CreateWebhookOptions, CreatedWebhook, CustomerPortalSession, CustomerPortalSessionsResource, DeleteAppOptions, DeleteBundleOptions, DeleteBundlePackUploadOptions, DeleteChannelOptions, DeleteDeviceOptions, DeleteFileUploadOptions, DeleteInvitationOptions, DeleteManyChannelsOptions, DeleteManyDevicesOptions, DeleteManyInvitationsOptions, DeleteManyMembersOptions, DeleteManySessionsOptions, DeleteManyTokensOptions, DeleteMemberOptions, DeleteOrganizationOptions, DeleteSigningKeyOptions, DeleteSsoProviderOptions, DeleteTelemetryExportOptions, DeleteUserOptions, DeleteWebhookOptions, Device, DeviceEventsResource, DevicesResource, DownloadAuditLogsCsvOptions, DownloadUsageAppsCsvOptions, FileUpload, FileUploadPartsResource, FileUploadsResource, FilesResource, FleetStatistics, GetAppOptions, GetAudienceOptions, GetBinaryOptions, GetBundleOptions, GetChannelOptions, GetChannelQrCodeOptions, GetDeviceOptions, GetFleetStatisticsOptions, GetLimitsOptions, GetMemberOptions, GetOrganizationOptions, GetQrCodeOptions, GetReleaseAudienceOptions, GetReleaseOptions, GetSsoProviderOptions, GetTelemetryExportOptions, GetUpdateStatisticsOptions, GetUsageOptions, GetUsageStatisticsOptions, GetUserOptions, GetWebhookOptions, HealthResource, HotCodePushErrorCode, HotCodePushOptions, IdempotencyOptions, Invitation, InvitationRow, InvitationsResource, Limits, LimitsResource, ListAppsOptions, ListAuditLogsOptions, ListBinariesOptions, ListBundleDeltasOptions, ListBundleFilesOptions, ListBundlesOptions, ListCallerInvitationsOptions, ListChannelsOptions, ListDeviceEventsOptions, ListDevicesOptions, ListInvitationsOptions, ListMembersOptions, ListNotificationPreferencesOptions, ListNotificationsOptions, ListOrganizationsOptions, ListReleasesOptions, ListSigningKeysOptions, ListTelemetryExportDeliveriesOptions, ListUsageAppsOptions, ListWebhookDeliveriesOptions, ListWebhooksOptions, Member, MemberRow, MembersResource, Notification, NotificationPreference, NotificationPreferencesResource, NotificationRow, NotificationsResource, Organization, OrganizationAppsResource, OrganizationInvitationsResource, OrganizationsResource, PauseChannelOptions, PauseReleaseOptions, QrCodesResource, RedeliverTelemetryExportDeliveryOptions, RedeliverWebhookDeliveryOptions, Release, ReleaseAudience, ReleaseAudienceResource, ReleaseDeviceEvent, ReleaseRow, ReleasesResource, ResumeChannelOptions, ResumeReleaseOptions, RevokeChannelReleasesOptions, RevokeReleaseOptions, RollbacksResource, SetSsoProviderOptions, SetTelemetryExportOptions, SigningKey, SigningKeysResource, SsoProvider, SsoProviderResource, SsoProviderVerificationsResource, StatisticsFleetResource, StatisticsResource, StatisticsUpdatesResource, StatisticsUsageResource, StreamUploadBody, SubscriptionResource, TelemetryExport, TelemetryExportDeliveriesResource, TelemetryExportDelivery, TelemetryExportResource, TestTelemetryExportOptions, TestWebhookOptions, TransferAppOptions, UncancelSubscriptionOptions, UpdateAppOptions, UpdateChannelOptions, UpdateManyNotificationsOptions, UpdateMemberOptions, UpdateNotificationOptions, UpdateNotificationPreferenceOptions, UpdateOrganizationOptions, UpdateReleaseOptions, UpdateStatistics, UpdateTelemetryExportOptions, UpdateWebhookOptions, UploadBody, UploadBundlePackOptions, UploadBundlePackPartOptions, UploadFileOptions, UploadPartOptions, UploadedBundlePack, UploadedPart, Usage, UsageAppsResource, UsageResource, UsageStatistics, User, UserPasswordResource, UserSessionsResource, UserTokensResource, UsersResource, Webhook, WebhookDeliveriesResource, WebhookDelivery, WebhooksResource };
19313
+ export type { AcceptInvitationOptions, App, AppFile, AppUsageMonth, AppsResource, Audience, AuditLog, AuditLogsResource, BinariesResource, Binary, BlobUploadBody, Bundle, BundleDelta, BundleDeltasResource, BundleFile, BundleFilesResource, BundlePackResource, BundlePackUpload, BundlePackUploadPartsResource, BundlePackUploadsResource, BundlesResource, CancelSubscriptionOptions, Channel, ChannelAudienceResource, ChannelQrCodeResource, ChannelReleasesResource, ChannelsResource, Checkout, CheckoutsResource, CompleteBundleOptions, CompleteBundlePackUploadOptions, CompleteFileUploadOptions, Count, CountAppsOptions, CountAuditLogsOptions, CountBinariesOptions, CountBundleDeltasOptions, CountBundleFilesOptions, CountBundlesOptions, CountChannelsOptions, CountDeviceEventsOptions, CountDevicesOptions, CountInvitationsOptions, CountMembersOptions, CountNotificationsOptions, CountReleasesOptions, CountSigningKeysOptions, CountTelemetryExportDeliveriesOptions, CountUsageAppsOptions, CountWebhookDeliveriesOptions, CountWebhooksOptions, CreateAppOptions, CreateBinaryOptions, CreateBundleOptions, CreateBundlePackUploadOptions, CreateChannelOptions, CreateCheckoutOptions, CreateCustomerPortalSessionOptions, CreateFileUploadOptions, CreateInvitationOptions, CreateOrganizationOptions, CreateReleaseOptions, CreateRollbackOptions, CreateSigningKeyOptions, CreateSsoProviderVerificationOptions, CreateUserPasswordOptions, CreateWebhookOptions, CreatedWebhook, CustomerPortalSession, CustomerPortalSessionsResource, DeleteAppOptions, DeleteBundleOptions, DeleteBundlePackUploadOptions, DeleteChannelOptions, DeleteDeviceOptions, DeleteFileUploadOptions, DeleteInvitationOptions, DeleteManyChannelsOptions, DeleteManyDevicesOptions, DeleteManyInvitationsOptions, DeleteManyMembersOptions, DeleteManySessionsOptions, DeleteManyTokensOptions, DeleteMemberOptions, DeleteOrganizationOptions, DeleteSigningKeyOptions, DeleteSsoProviderOptions, DeleteTelemetryExportOptions, DeleteUserOptions, DeleteWebhookOptions, Device, DeviceEventsResource, DevicesResource, DownloadAuditLogsCsvOptions, DownloadUsageAppsCsvOptions, FileUpload, FileUploadPartsResource, FileUploadsResource, FilesResource, FleetStatistics, GetAppOptions, GetAudienceOptions, GetBinaryOptions, GetBundleOptions, GetChannelOptions, GetChannelQrCodeOptions, GetDeviceOptions, GetFleetStatisticsOptions, GetLimitsOptions, GetMemberOptions, GetOrganizationOptions, GetQrCodeOptions, GetReleaseAudienceOptions, GetReleaseOptions, GetSsoProviderOptions, GetTelemetryExportOptions, GetUpdateStatisticsOptions, GetUsageOptions, GetUsageStatisticsOptions, GetUserOptions, GetWebhookOptions, HealthResource, HotCodePushErrorCode, HotCodePushOptions, IdempotencyOptions, Invitation, InvitationRow, InvitationsResource, Limits, LimitsResource, ListAppsOptions, ListAuditLogsOptions, ListBinariesOptions, ListBundleDeltasOptions, ListBundleFilesOptions, ListBundlesOptions, ListCallerInvitationsOptions, ListChannelsOptions, ListDeviceEventsOptions, ListDevicesOptions, ListInvitationsOptions, ListMembersOptions, ListNotificationPreferencesOptions, ListNotificationsOptions, ListOrganizationsOptions, ListReleasesOptions, ListSigningKeysOptions, ListTelemetryExportDeliveriesOptions, ListUsageAppsOptions, ListWebhookDeliveriesOptions, ListWebhooksOptions, Member, MemberRow, MembersResource, Notification, NotificationPreference, NotificationPreferencesResource, NotificationRow, NotificationsResource, Organization, OrganizationAppsResource, OrganizationInvitationsResource, OrganizationsResource, PauseChannelOptions, PauseReleaseOptions, QrCodesResource, RedeliverTelemetryExportDeliveryOptions, RedeliverWebhookDeliveryOptions, Release, ReleaseAudience, ReleaseAudienceResource, ReleaseDeviceEvent, ReleaseRow, ReleasesResource, RequestOptions, ResumeChannelOptions, ResumeReleaseOptions, RevokeChannelReleasesOptions, RevokeReleaseOptions, RollbacksResource, SetSsoProviderOptions, SetTelemetryExportOptions, SigningKey, SigningKeysResource, SsoProvider, SsoProviderResource, SsoProviderVerificationsResource, StatisticsFleetResource, StatisticsResource, StatisticsUpdatesResource, StatisticsUsageResource, StreamUploadBody, SubscriptionResource, TelemetryExport, TelemetryExportDeliveriesResource, TelemetryExportDelivery, TelemetryExportResource, TestTelemetryExportOptions, TestWebhookOptions, TransferAppOptions, UncancelSubscriptionOptions, UpdateAppOptions, UpdateChannelOptions, UpdateManyNotificationsOptions, UpdateMemberOptions, UpdateNotificationOptions, UpdateNotificationPreferenceOptions, UpdateOrganizationOptions, UpdateReleaseOptions, UpdateStatistics, UpdateTelemetryExportOptions, UpdateWebhookOptions, UploadBody, UploadBundlePackOptions, UploadBundlePackPartOptions, UploadFileOptions, UploadPartOptions, UploadedBundlePack, UploadedPart, Usage, UsageAppsResource, UsageResource, UsageStatistics, User, UserPasswordResource, UserSessionsResource, UserTokensResource, UsersResource, Webhook, WebhookDeliveriesResource, WebhookDelivery, WebhooksResource };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.2.0";
2
+ var version = "0.2.1";
3
3
  //#endregion
4
4
  //#region src/errors.ts
5
5
  /**
@@ -64,9 +64,16 @@ var HttpClient = class {
64
64
  this.timeoutMs = options.timeout ?? JSON_TIMEOUT_MS;
65
65
  }
66
66
  async fetchBlob(options) {
67
- const response = await this.fetchResponse(options);
68
- await assertResponseOk(response);
69
- return response.blob();
67
+ return (await this.fetchOkResponse(options)).blob();
68
+ }
69
+ async fetchBufferedResponse(options) {
70
+ const response = await this.fetchOkResponse(options);
71
+ const body = response.body === null ? null : await response.arrayBuffer();
72
+ return new Response(body, {
73
+ headers: response.headers,
74
+ status: response.status,
75
+ statusText: response.statusText
76
+ });
70
77
  }
71
78
  async fetchCreatingPost(options) {
72
79
  return this.fetchJson({
@@ -81,9 +88,7 @@ var HttpClient = class {
81
88
  return parseResponseBody(await this.fetchResponse(options));
82
89
  }
83
90
  async fetchStatus(options) {
84
- const response = await this.fetchResponse(options);
85
- await assertResponseOk(response);
86
- await response.body?.cancel();
91
+ await (await this.fetchOkResponse(options)).body?.cancel();
87
92
  }
88
93
  async fetchUpload(options) {
89
94
  const fetchWithTimeout = withTimeout(fetch, { timeoutMs: UPLOAD_TIMEOUT_MS });
@@ -100,6 +105,11 @@ var HttpClient = class {
100
105
  method: "PUT"
101
106
  }));
102
107
  }
108
+ async fetchOkResponse(options) {
109
+ const response = await this.fetchResponse(options);
110
+ await assertResponseOk(response);
111
+ return response;
112
+ }
103
113
  async fetchResponse(options) {
104
114
  const fetchWithTimeout = withTimeout(fetch, { timeoutMs: this.timeoutMs });
105
115
  return (options.isRetryable ?? IDEMPOTENT_METHODS.has(options.method) ? withRetry(fetchWithTimeout) : fetchWithTimeout)(this.resolveUrl(options), this.resolveRequestInit(options));
@@ -123,7 +133,10 @@ var HttpClient = class {
123
133
  };
124
134
  }
125
135
  resolveRouteUrl(path) {
126
- return new URL(this.baseUrl + path);
136
+ if (!path.startsWith("/")) throw new Error(`The path ${path} does not start with a slash.`);
137
+ const url = new URL(this.baseUrl + path);
138
+ if (!url.href.startsWith(new URL(`${this.baseUrl}/`).href)) throw new Error(`The path ${path} leaves the base URL.`);
139
+ return url;
127
140
  }
128
141
  resolveUrl(options) {
129
142
  const url = this.resolveRouteUrl(options.path);
@@ -2400,16 +2413,29 @@ var HotCodePush = class {
2400
2413
  organizations;
2401
2414
  qrCodes;
2402
2415
  users;
2416
+ httpClient;
2403
2417
  constructor(options = {}) {
2404
- const httpClient = new HttpClient(options);
2405
- this.apps = new AppsResource(httpClient);
2406
- this.health = new HealthResource(httpClient);
2407
- this.invitations = new InvitationsResource(httpClient);
2408
- this.notificationPreferences = new NotificationPreferencesResource(httpClient);
2409
- this.notifications = new NotificationsResource(httpClient);
2410
- this.organizations = new OrganizationsResource(httpClient);
2411
- this.qrCodes = new QrCodesResource(httpClient);
2412
- this.users = new UsersResource(httpClient);
2418
+ this.httpClient = new HttpClient(options);
2419
+ this.apps = new AppsResource(this.httpClient);
2420
+ this.health = new HealthResource(this.httpClient);
2421
+ this.invitations = new InvitationsResource(this.httpClient);
2422
+ this.notificationPreferences = new NotificationPreferencesResource(this.httpClient);
2423
+ this.notifications = new NotificationsResource(this.httpClient);
2424
+ this.organizations = new OrganizationsResource(this.httpClient);
2425
+ this.qrCodes = new QrCodesResource(this.httpClient);
2426
+ this.users = new UsersResource(this.httpClient);
2427
+ }
2428
+ /**
2429
+ * Sends one request to a path of the API, for what no resource method covers.
2430
+ * Returns the response with its status, its headers and its body already received.
2431
+ * Throws a `HotCodePushError` on a status outside 2xx.
2432
+ */
2433
+ request({ body, method, path }) {
2434
+ return this.httpClient.fetchBufferedResponse({
2435
+ body,
2436
+ method,
2437
+ path
2438
+ });
2413
2439
  }
2414
2440
  };
2415
2441
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hotcodepush/node",
3
3
  "description": "The typed Node client for the HotCodePush REST API",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "keywords": [
7
7
  "hotcodepush",