@degallery/sdk 0.1.0 → 0.2.0
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/dist/index.cjs +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var g=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},y=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of d(t))!c.call(r,s)&&s!==e&&a(r,s,{get:()=>t[s],enumerable:!(i=u(t,s))||i.enumerable});return r};var h=r=>y(a({},"__esModule",{value:!0}),r);var m={};g(m,{GalleryClient:()=>o});module.exports=h(m);var o=class{constructor(t){this.options=t}options;assets={complete:t=>this.post("/api/v1/assets",t),list:(t={})=>this.getList("/api/v1/assets",t),retrieve:t=>this.get(`/api/v1/assets/${encodeURIComponent(t)}`),update:(t,e)=>this.patch(`/api/v1/assets/${encodeURIComponent(t)}`,e),uploadImage:t=>this.createUpload(t)};galleries={attachAssets:(t,e)=>this.post(`/api/v1/galleries/${encodeURIComponent(t)}/assets`,{assetIds:e}),create:t=>this.post("/api/v1/galleries",t),link:t=>this.get(`/api/v1/galleries/${encodeURIComponent(t)}/link`),list:(t={})=>this.getList("/api/v1/galleries",t),retrieve:(t,e={})=>this.get(`/api/v1/galleries/${encodeURIComponent(t)}`,{...e,include:e.includeAssets?"assets":void 0,includeAssets:void 0}),update:(t,e)=>this.patch(`/api/v1/galleries/${encodeURIComponent(t)}`,e)};async createUpload(t){let e=await this.post("/api/v1/uploads",t);return{...e.upload,asset:e.asset,contentType:e.upload.contentType,expiresAt:e.upload.expiresAt,intentId:e.upload.intentId,uploadUrl:e.upload.uploadUrl}}async completeUpload(t){return this.assets.complete({uploadIntentId:t})}async getGallery(t){let e=await this.galleries.retrieve(t,{includeAssets:!0});return{access:e.visibility==="public"?"public":"private",description:e.description,id:e.id,items:e.items?.map(i=>({alt:i.asset.alt,downloadUrl:i.asset.delivery.downloadUrl,id:i.asset.id,src:i.asset.delivery.src}))??[],layout:e.layout,name:e.name,slug:e.slug}}async track(t){let e=await this.rawRequest("/api/v1/events",{body:JSON.stringify({...t,occurredAt:t.occurredAt??new Date().toISOString()}),keepalive:!0,method:"POST"});if(!e.ok)throw new Error(`Event ingestion failed: ${e.status}`)}get(t,e){return this.requestData(t,{method:"GET"},e)}getList(t,e){return this.requestList(t,{method:"GET"},e)}patch(t,e){return this.requestData(t,{body:JSON.stringify(e),method:"PATCH"})}post(t,e){return this.requestData(t,{body:JSON.stringify(e),method:"POST"})}async requestData(t,e={},i){let s=await this.rawRequest(t,e,i);if(!s.ok)throw await this.toError(s);return(await s.json()).data}async requestList(t,e={},i){let s=await this.rawRequest(t,e,i);if(!s.ok)throw await this.toError(s);return await s.json()}rawRequest(t,e={},i){let s=this.options.fetch??fetch,l=new URL(t,this.options.apiUrl);for(let[p,n]of Object.entries(i??{}))n!=null&&l.searchParams.set(p,String(n));return s(l,{...e,headers:{"content-type":"application/json",...this.authToken?{authorization:`Bearer ${this.authToken}`}:{},...e.headers}})}get authToken(){return this.options.apiKey??this.options.readToken??this.options.publishableKey}async toError(t){let e=await t.json().catch(()=>{}),i=e?.error?.message??`The Gallery API request failed: ${t.status}`,s=new Error(i);return s.name=e?.error?.code??"GalleryApiError",s}};0&&(module.exports={GalleryClient});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=class{constructor(t){this.options=t}options;assets={complete:t=>this.post("/api/v1/assets",t),list:(t={})=>this.getList("/api/v1/assets",t),retrieve:t=>this.get(`/api/v1/assets/${encodeURIComponent(t)}`),update:(t,e)=>this.patch(`/api/v1/assets/${encodeURIComponent(t)}`,e),uploadImage:t=>this.createUpload(t)};galleries={attachAssets:(t,e)=>this.post(`/api/v1/galleries/${encodeURIComponent(t)}/assets`,{assetIds:e}),create:t=>this.post("/api/v1/galleries",t),link:t=>this.get(`/api/v1/galleries/${encodeURIComponent(t)}/link`),list:(t={})=>this.getList("/api/v1/galleries",t),retrieve:(t,e={})=>this.get(`/api/v1/galleries/${encodeURIComponent(t)}`,{...e,include:e.includeAssets?"assets":void 0,includeAssets:void 0}),update:(t,e)=>this.patch(`/api/v1/galleries/${encodeURIComponent(t)}`,e)};async createUpload(t){let e=await this.post("/api/v1/uploads",t);return{...e.upload,asset:e.asset,contentType:e.upload.contentType,expiresAt:e.upload.expiresAt,intentId:e.upload.intentId,uploadUrl:e.upload.uploadUrl}}async completeUpload(t){return this.assets.complete({uploadIntentId:t})}async getGallery(t){let e=await this.galleries.retrieve(t,{includeAssets:!0});return{access:e.visibility==="public"?"public":"private",description:e.description,id:e.id,items:e.items?.map(s=>({alt:s.asset.alt,downloadUrl:s.asset.delivery.downloadUrl,id:s.asset.id,src:s.asset.delivery.src}))??[],layout:e.layout,name:e.name,slug:e.slug}}async track(t){let e=await this.rawRequest("/api/v1/events",{body:JSON.stringify({...t,occurredAt:t.occurredAt??new Date().toISOString()}),keepalive:!0,method:"POST"});if(!e.ok)throw new Error(`Event ingestion failed: ${e.status}`)}get(t,e){return this.requestData(t,{method:"GET"},e)}getList(t,e){return this.requestList(t,{method:"GET"},e)}patch(t,e){return this.requestData(t,{body:JSON.stringify(e),method:"PATCH"})}post(t,e){return this.requestData(t,{body:JSON.stringify(e),method:"POST"})}async requestData(t,e={},s){let i=await this.rawRequest(t,e,s);if(!i.ok)throw await this.toError(i);return(await i.json()).data}async requestList(t,e={},s){let i=await this.rawRequest(t,e,s);if(!i.ok)throw await this.toError(i);return await i.json()}rawRequest(t,e={},s){let i=this.options.fetch??fetch,n=new URL(t,this.options.apiUrl);for(let[o,r]of Object.entries(s??{}))r!=null&&n.searchParams.set(o,String(r));return i(n,{...e,headers:{"content-type":"application/json",...this.authToken?{authorization:`Bearer ${this.authToken}`}:{},...e.headers}})}get authToken(){return this.options.apiKey??this.options.readToken??this.options.publishableKey}async toError(t){let e=await t.json().catch(()=>{}),s=e?.error?.message??`The Gallery API request failed: ${t.status}`,i=new Error(s);return i.name=e?.error?.code??"GalleryApiError",i}};export{a as GalleryClient};
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degallery/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"lib:publish": "npm publish --access public"
|
|
10
|
+
},
|
|
8
11
|
"exports": {
|
|
9
12
|
"./package.json": "./package.json",
|
|
10
13
|
".": {
|
|
@@ -53,4 +56,4 @@
|
|
|
53
56
|
"dependencies": {
|
|
54
57
|
"tslib": "^2.3.0"
|
|
55
58
|
}
|
|
56
|
-
}
|
|
59
|
+
}
|