@scaleway/sdk-file 1.2.0 → 2.1.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 ADDED
@@ -0,0 +1,96 @@
1
+ # @scaleway/sdk-file
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@scaleway/sdk-file.svg)](https://www.npmjs.com/package/@scaleway/sdk-file)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@scaleway/sdk-file.svg)](https://www.npmjs.com/package/@scaleway/sdk-file)
5
+ [![license](https://img.shields.io/npm/l/@scaleway/sdk-file.svg)](https://github.com/scaleway/scaleway-sdk-js/blob/master/LICENSE)
6
+
7
+ Scaleway SDK for File API.
8
+
9
+ > **Note**
10
+ > This is an automatically generated package that is part of the [Scaleway SDK for JavaScript](https://github.com/scaleway/scaleway-sdk-js).
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @scaleway/sdk-file @scaleway/sdk-client
16
+ ```
17
+
18
+ or with pnpm:
19
+
20
+ ```bash
21
+ pnpm add @scaleway/sdk-file @scaleway/sdk-client
22
+ ```
23
+
24
+ or with yarn:
25
+
26
+ ```bash
27
+ yarn add @scaleway/sdk-file @scaleway/sdk-client
28
+ ```
29
+
30
+ ## Getting Started
31
+
32
+ You'll need a pair of access and secret keys to connect to Scaleway API. Please check the [documentation](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/) on how to retrieve them.
33
+
34
+ ### Basic Usage
35
+
36
+ ```typescript
37
+ import { createClient } from '@scaleway/sdk-client'
38
+ import { File } from '@scaleway/sdk-file'
39
+
40
+ const client = createClient({
41
+ accessKey: 'SCWXXXXXXXXXXXXXXXXX',
42
+ secretKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
43
+ defaultProjectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
44
+ defaultRegion: 'fr-par',
45
+ defaultZone: 'fr-par-1',
46
+ })
47
+
48
+ const api = new File.v1.API(client)
49
+
50
+ // Use the API
51
+ // Example: await api.listServers()
52
+ ```
53
+
54
+ ### Using Configuration Loader
55
+
56
+ For a simpler setup, you can load credentials from the configuration file or environment variables:
57
+
58
+ ```typescript
59
+ import { createClient } from '@scaleway/sdk-client'
60
+ import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader'
61
+ import { File } from '@scaleway/sdk-file'
62
+
63
+ const profile = loadProfileFromConfigurationFile()
64
+ const client = createClient(profile)
65
+ const api = new File.v1.API(client)
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ - 📚 [Scaleway SDK Reference Documentation](https://scaleway.github.io/scaleway-sdk-js)
71
+ - 🌐 [Scaleway File API Documentation](https://www.scaleway.com/en/developers/api/file/)
72
+ - 📖 [Main Repository](https://github.com/scaleway/scaleway-sdk-js)
73
+ - 💡 [Example Projects](https://github.com/scaleway/scaleway-sdk-js/tree/master/examples)
74
+
75
+ ## Features
76
+
77
+ - ✅ Full TypeScript support with complete type definitions
78
+ - ✅ Promise-based API
79
+ - ✅ Automatic pagination helpers
80
+ - ✅ Built-in error handling
81
+ - ✅ Compatible with Node.js ≥ 20
82
+
83
+ ## Support
84
+
85
+ We love feedback! Feel free to reach us on:
86
+ - [Scaleway Slack community](https://slack.scaleway.com/) - Join us on [#opensource](https://scaleway-community.slack.com/app_redirect?channel=opensource)
87
+ - [GitHub Issues](https://github.com/scaleway/scaleway-sdk-js/issues)
88
+
89
+ ## Contributing
90
+
91
+ This repository is at its early stage and is still in active development. If you are looking for a way to contribute, please read [CONTRIBUTING.md](https://github.com/scaleway/scaleway-sdk-js/blob/master/CONTRIBUTING.md).
92
+
93
+ ## License
94
+
95
+ This project is Apache 2.0 licensed. See the [LICENSE](https://github.com/scaleway/scaleway-sdk-js/blob/master/LICENSE) file for details.
96
+
@@ -1,5 +1,5 @@
1
- import { API as ParentAPI } from '@scaleway/sdk-client';
2
1
  import type { ApiLocality, WaitForOptions } from '@scaleway/sdk-client';
2
+ import { API as ParentAPI } from '@scaleway/sdk-client';
3
3
  import type { CreateFileSystemRequest, DeleteFileSystemRequest, FileSystem, GetFileSystemRequest, ListAttachmentsRequest, ListAttachmentsResponse, ListFileSystemsRequest, ListFileSystemsResponse, UpdateFileSystemRequest } from './types.gen.js';
4
4
  /**
5
5
  * File Storage API.
@@ -10,7 +10,9 @@ class API extends API$1 {
10
10
  * type ∈ {'zone','region','global','unspecified'}
11
11
  */
12
12
  static LOCALITY = toApiLocality({
13
- regions: ["fr-par"]
13
+ regions: [
14
+ "fr-par"
15
+ ]
14
16
  });
15
17
  /**
16
18
  * Get filesystem details. Retrieve all properties and current status of a specific filesystem identified by its ID.
@@ -33,9 +35,7 @@ class API extends API$1 {
33
35
  * @returns A Promise of FileSystem
34
36
  */
35
37
  waitForFileSystem = (request, options) => waitForResource(
36
- options?.stop ?? ((res) => Promise.resolve(
37
- !FILE_SYSTEM_TRANSIENT_STATUSES.includes(res.status)
38
- )),
38
+ options?.stop ?? ((res) => Promise.resolve(!FILE_SYSTEM_TRANSIENT_STATUSES.includes(res.status))),
39
39
  this.getFileSystem,
40
40
  request,
41
41
  options
@@ -49,10 +49,7 @@ class API extends API$1 {
49
49
  ["order_by", request.orderBy],
50
50
  ["organization_id", request.organizationId],
51
51
  ["page", request.page],
52
- [
53
- "page_size",
54
- request.pageSize ?? this.client.settings.defaultPageSize
55
- ],
52
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize],
56
53
  ["project_id", request.projectId],
57
54
  ["tags", request.tags]
58
55
  )
@@ -73,10 +70,7 @@ class API extends API$1 {
73
70
  urlParams: urlParams(
74
71
  ["filesystem_id", request.filesystemId],
75
72
  ["page", request.page],
76
- [
77
- "page_size",
78
- request.pageSize ?? this.client.settings.defaultPageSize
79
- ],
73
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize],
80
74
  ["resource_id", request.resourceId],
81
75
  ["resource_type", request.resourceType],
82
76
  ["zone", request.zone]
@@ -114,10 +108,12 @@ class API extends API$1 {
114
108
  *
115
109
  * @param request - The request {@link DeleteFileSystemRequest}
116
110
  */
117
- deleteFileSystem = (request) => this.client.fetch({
118
- method: "DELETE",
119
- path: `/file/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems/${validatePathParam("filesystemId", request.filesystemId)}`
120
- });
111
+ deleteFileSystem = (request) => this.client.fetch(
112
+ {
113
+ method: "DELETE",
114
+ path: `/file/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems/${validatePathParam("filesystemId", request.filesystemId)}`
115
+ }
116
+ );
121
117
  /**
122
118
  * Update filesystem properties. Update the technical details of a filesystem, such as its name, tags or its new size.
123
119
  *
@@ -1,4 +1,4 @@
1
- export { API } from './api.gen.js';
1
+ export { API, } from './api.gen.js';
2
2
  export * from './content.gen.js';
3
3
  export * from './marshalling.gen.js';
4
4
  export type { Attachment, AttachmentResourceType, CreateFileSystemRequest, DeleteFileSystemRequest, FileSystem, FileSystemStatus, GetFileSystemRequest, ListAttachmentsRequest, ListAttachmentsResponse, ListFileSystemsRequest, ListFileSystemsRequestOrderBy, ListFileSystemsResponse, UpdateFileSystemRequest, } from './types.gen.js';
package/package.json CHANGED
@@ -1,23 +1,20 @@
1
1
  {
2
2
  "name": "@scaleway/sdk-file",
3
- "version": "1.2.0",
3
+ "version": "2.1.1",
4
4
  "description": "Scaleway SDK file",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
+ "README.md",
7
8
  "dist"
8
9
  ],
9
10
  "type": "module",
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/index.gen.d.ts",
13
- "import": "./dist/index.gen.js",
14
- "require": "./dist/index.gen.cjs",
15
14
  "default": "./dist/index.gen.js"
16
15
  },
17
16
  "./*": {
18
17
  "types": "./dist/*/index.gen.d.ts",
19
- "import": "./dist/*/index.gen.js",
20
- "require": "./dist/*/index.gen.cjs",
21
18
  "default": "./dist/*/index.gen.js"
22
19
  }
23
20
  },
@@ -26,17 +23,17 @@
26
23
  "directory": "packages_generated/file"
27
24
  },
28
25
  "engines": {
29
- "node": ">=20.19.4"
26
+ "node": ">=20.19.6"
30
27
  },
31
28
  "dependencies": {
32
29
  "@scaleway/random-name": "5.1.2",
33
- "@scaleway/sdk-std": "1.1.0"
30
+ "@scaleway/sdk-std": "2.1.0"
34
31
  },
35
32
  "peerDependencies": {
36
- "@scaleway/sdk-client": "^1.3.2"
33
+ "@scaleway/sdk-client": "^2.1.0"
37
34
  },
38
35
  "devDependencies": {
39
- "@scaleway/sdk-client": "^1.3.2"
36
+ "@scaleway/sdk-client": "^2.1.0"
40
37
  },
41
38
  "scripts": {
42
39
  "package:check": "pnpm publint",
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index_gen = require("./v1alpha1/index.gen.cjs");
4
- exports.Filev1alpha1 = index_gen;
@@ -1,141 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const sdkClient = require("@scaleway/sdk-client");
4
- const content_gen = require("./content.gen.cjs");
5
- const marshalling_gen = require("./marshalling.gen.cjs");
6
- const jsonContentHeaders = {
7
- "Content-Type": "application/json; charset=utf-8"
8
- };
9
- class API extends sdkClient.API {
10
- /**
11
- * Locality of this API.
12
- * type ∈ {'zone','region','global','unspecified'}
13
- */
14
- static LOCALITY = sdkClient.toApiLocality({
15
- regions: ["fr-par"]
16
- });
17
- /**
18
- * Get filesystem details. Retrieve all properties and current status of a specific filesystem identified by its ID.
19
- *
20
- * @param request - The request {@link GetFileSystemRequest}
21
- * @returns A Promise of FileSystem
22
- */
23
- getFileSystem = (request) => this.client.fetch(
24
- {
25
- method: "GET",
26
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems/${sdkClient.validatePathParam("filesystemId", request.filesystemId)}`
27
- },
28
- marshalling_gen.unmarshalFileSystem
29
- );
30
- /**
31
- * Waits for {@link FileSystem} to be in a final state.
32
- *
33
- * @param request - The request {@link GetFileSystemRequest}
34
- * @param options - The waiting options
35
- * @returns A Promise of FileSystem
36
- */
37
- waitForFileSystem = (request, options) => sdkClient.waitForResource(
38
- options?.stop ?? ((res) => Promise.resolve(
39
- !content_gen.FILE_SYSTEM_TRANSIENT_STATUSES.includes(res.status)
40
- )),
41
- this.getFileSystem,
42
- request,
43
- options
44
- );
45
- pageOfListFileSystems = (request = {}) => this.client.fetch(
46
- {
47
- method: "GET",
48
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems`,
49
- urlParams: sdkClient.urlParams(
50
- ["name", request.name],
51
- ["order_by", request.orderBy],
52
- ["organization_id", request.organizationId],
53
- ["page", request.page],
54
- [
55
- "page_size",
56
- request.pageSize ?? this.client.settings.defaultPageSize
57
- ],
58
- ["project_id", request.projectId],
59
- ["tags", request.tags]
60
- )
61
- },
62
- marshalling_gen.unmarshalListFileSystemsResponse
63
- );
64
- /**
65
- * List all filesystems. Retrieve all filesystems in the specified region. By default, the filesystems listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.
66
- *
67
- * @param request - The request {@link ListFileSystemsRequest}
68
- * @returns A Promise of ListFileSystemsResponse
69
- */
70
- listFileSystems = (request = {}) => sdkClient.enrichForPagination("filesystems", this.pageOfListFileSystems, request);
71
- pageOfListAttachments = (request = {}) => this.client.fetch(
72
- {
73
- method: "GET",
74
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/attachments`,
75
- urlParams: sdkClient.urlParams(
76
- ["filesystem_id", request.filesystemId],
77
- ["page", request.page],
78
- [
79
- "page_size",
80
- request.pageSize ?? this.client.settings.defaultPageSize
81
- ],
82
- ["resource_id", request.resourceId],
83
- ["resource_type", request.resourceType],
84
- ["zone", request.zone]
85
- )
86
- },
87
- marshalling_gen.unmarshalListAttachmentsResponse
88
- );
89
- /**
90
- * List filesystems attachments. List all existing attachments in a specified region.
91
- By default, the attachments listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.
92
- *
93
- * @param request - The request {@link ListAttachmentsRequest}
94
- * @returns A Promise of ListAttachmentsResponse
95
- */
96
- listAttachments = (request = {}) => sdkClient.enrichForPagination("attachments", this.pageOfListAttachments, request);
97
- /**
98
- * Create a new filesystem. To create a new filesystem, you must specify a name, a size, and a project ID.
99
- *
100
- * @param request - The request {@link CreateFileSystemRequest}
101
- * @returns A Promise of FileSystem
102
- */
103
- createFileSystem = (request) => this.client.fetch(
104
- {
105
- body: JSON.stringify(
106
- marshalling_gen.marshalCreateFileSystemRequest(request, this.client.settings)
107
- ),
108
- headers: jsonContentHeaders,
109
- method: "POST",
110
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems`
111
- },
112
- marshalling_gen.unmarshalFileSystem
113
- );
114
- /**
115
- * Delete a detached filesystem. You must specify the `filesystem_id` of the filesystem you want to delete.
116
- *
117
- * @param request - The request {@link DeleteFileSystemRequest}
118
- */
119
- deleteFileSystem = (request) => this.client.fetch({
120
- method: "DELETE",
121
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems/${sdkClient.validatePathParam("filesystemId", request.filesystemId)}`
122
- });
123
- /**
124
- * Update filesystem properties. Update the technical details of a filesystem, such as its name, tags or its new size.
125
- *
126
- * @param request - The request {@link UpdateFileSystemRequest}
127
- * @returns A Promise of FileSystem
128
- */
129
- updateFileSystem = (request) => this.client.fetch(
130
- {
131
- body: JSON.stringify(
132
- marshalling_gen.marshalUpdateFileSystemRequest(request, this.client.settings)
133
- ),
134
- headers: jsonContentHeaders,
135
- method: "PATCH",
136
- path: `/file/v1alpha1/regions/${sdkClient.validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/filesystems/${sdkClient.validatePathParam("filesystemId", request.filesystemId)}`
137
- },
138
- marshalling_gen.unmarshalFileSystem
139
- );
140
- }
141
- exports.API = API;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const FILE_SYSTEM_TRANSIENT_STATUSES = [
4
- "creating",
5
- "updating"
6
- ];
7
- exports.FILE_SYSTEM_TRANSIENT_STATUSES = FILE_SYSTEM_TRANSIENT_STATUSES;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const api_gen = require("./api.gen.cjs");
4
- const content_gen = require("./content.gen.cjs");
5
- const marshalling_gen = require("./marshalling.gen.cjs");
6
- const validationRules_gen = require("./validation-rules.gen.cjs");
7
- exports.API = api_gen.API;
8
- exports.FILE_SYSTEM_TRANSIENT_STATUSES = content_gen.FILE_SYSTEM_TRANSIENT_STATUSES;
9
- exports.marshalCreateFileSystemRequest = marshalling_gen.marshalCreateFileSystemRequest;
10
- exports.marshalUpdateFileSystemRequest = marshalling_gen.marshalUpdateFileSystemRequest;
11
- exports.unmarshalFileSystem = marshalling_gen.unmarshalFileSystem;
12
- exports.unmarshalListAttachmentsResponse = marshalling_gen.unmarshalListAttachmentsResponse;
13
- exports.unmarshalListFileSystemsResponse = marshalling_gen.unmarshalListFileSystemsResponse;
14
- exports.ValidationRules = validationRules_gen;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const sdkClient = require("@scaleway/sdk-client");
4
- const unmarshalFileSystem = (data) => {
5
- if (!sdkClient.isJSONObject(data)) {
6
- throw new TypeError(
7
- `Unmarshalling the type 'FileSystem' failed as data isn't a dictionary.`
8
- );
9
- }
10
- return {
11
- createdAt: sdkClient.unmarshalDate(data.created_at),
12
- id: data.id,
13
- name: data.name,
14
- numberOfAttachments: data.number_of_attachments,
15
- organizationId: data.organization_id,
16
- projectId: data.project_id,
17
- region: data.region,
18
- size: data.size,
19
- status: data.status,
20
- tags: data.tags,
21
- updatedAt: sdkClient.unmarshalDate(data.updated_at)
22
- };
23
- };
24
- const unmarshalAttachment = (data) => {
25
- if (!sdkClient.isJSONObject(data)) {
26
- throw new TypeError(
27
- `Unmarshalling the type 'Attachment' failed as data isn't a dictionary.`
28
- );
29
- }
30
- return {
31
- filesystemId: data.filesystem_id,
32
- id: data.id,
33
- resourceId: data.resource_id,
34
- resourceType: data.resource_type,
35
- zone: data.zone
36
- };
37
- };
38
- const unmarshalListAttachmentsResponse = (data) => {
39
- if (!sdkClient.isJSONObject(data)) {
40
- throw new TypeError(
41
- `Unmarshalling the type 'ListAttachmentsResponse' failed as data isn't a dictionary.`
42
- );
43
- }
44
- return {
45
- attachments: sdkClient.unmarshalArrayOfObject(data.attachments, unmarshalAttachment),
46
- totalCount: data.total_count
47
- };
48
- };
49
- const unmarshalListFileSystemsResponse = (data) => {
50
- if (!sdkClient.isJSONObject(data)) {
51
- throw new TypeError(
52
- `Unmarshalling the type 'ListFileSystemsResponse' failed as data isn't a dictionary.`
53
- );
54
- }
55
- return {
56
- filesystems: sdkClient.unmarshalArrayOfObject(data.filesystems, unmarshalFileSystem),
57
- totalCount: data.total_count
58
- };
59
- };
60
- const marshalCreateFileSystemRequest = (request, defaults) => ({
61
- name: request.name,
62
- project_id: request.projectId ?? defaults.defaultProjectId,
63
- size: request.size,
64
- tags: request.tags
65
- });
66
- const marshalUpdateFileSystemRequest = (request, defaults) => ({
67
- name: request.name,
68
- size: request.size,
69
- tags: request.tags
70
- });
71
- exports.marshalCreateFileSystemRequest = marshalCreateFileSystemRequest;
72
- exports.marshalUpdateFileSystemRequest = marshalUpdateFileSystemRequest;
73
- exports.unmarshalFileSystem = unmarshalFileSystem;
74
- exports.unmarshalListAttachmentsResponse = unmarshalListAttachmentsResponse;
75
- exports.unmarshalListFileSystemsResponse = unmarshalListFileSystemsResponse;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const CreateFileSystemRequest = {
4
- name: {
5
- minLength: 1
6
- },
7
- size: {
8
- greaterThan: 0
9
- }
10
- };
11
- const ListAttachmentsRequest = {
12
- page: {
13
- greaterThan: 0
14
- },
15
- pageSize: {
16
- greaterThan: 0,
17
- lessThanOrEqual: 100
18
- }
19
- };
20
- const ListFileSystemsRequest = {
21
- page: {
22
- greaterThan: 0
23
- },
24
- pageSize: {
25
- greaterThan: 0,
26
- lessThanOrEqual: 100
27
- }
28
- };
29
- const UpdateFileSystemRequest = {
30
- name: {
31
- minLength: 1
32
- },
33
- size: {
34
- greaterThan: 0
35
- }
36
- };
37
- exports.CreateFileSystemRequest = CreateFileSystemRequest;
38
- exports.ListAttachmentsRequest = ListAttachmentsRequest;
39
- exports.ListFileSystemsRequest = ListFileSystemsRequest;
40
- exports.UpdateFileSystemRequest = UpdateFileSystemRequest;